1
/* Wireless support using iwlib for netcfg.
2
* (C) 2004 Joshua Kwan, Bastian Blank
4
* Licensed under the GNU General Public License
10
#include <debian-installer/log.h>
12
#include <sys/types.h>
15
#define ENTER_MANUALLY 10
18
int is_wireless_iface (const char* if_name)
21
return (iw_get_basic_config (wfd, (char*)if_name, &wc) == 0);
24
void free_network_list(wireless_scan **network_list)
26
wireless_scan *old, *network;
28
if (network_list == NULL) {
32
for (network = *network_list; network; ) {
34
network = network->next;
41
int netcfg_wireless_choose_essid_manually(struct debconfclient *client,
42
struct netcfg_interface *interface, char *question)
44
wireless_config wconf;
46
iw_get_basic_config (wfd, interface->name, &wconf);
48
debconf_subst(client, question, "iface", interface->name);
49
debconf_subst(client, "netcfg/wireless_adhoc_managed", "iface", interface->name);
51
if (debconf_go(client) == CMD_GOBACK) {
52
debconf_fset(client, question, "seen", "false");
56
debconf_get(client, "netcfg/wireless_adhoc_managed");
58
if (!strcmp(client->value, "Ad-hoc network (Peer to peer)")) {
59
interface->mode = ADHOC;
63
wconf.mode = interface->mode;
66
debconf_input(client, "high", question);
68
if (debconf_go(client) == CMD_GOBACK) {
72
debconf_get(client, question);
74
if (client->value && strlen(client->value) > IW_ESSID_MAX_SIZE) {
75
char max_len_string[5];
76
sprintf(max_len_string, "%d", IW_ESSID_MAX_SIZE);
77
debconf_capb(client, "");
78
debconf_subst(client, "netcfg/invalid_essid", "essid", client->value);
79
debconf_subst(client, "netcfg/invalid_essid", "max_essid_len",
81
debconf_input(client, "critical", "netcfg/invalid_essid");
84
debconf_fset(client, question, "seen", "false");
85
debconf_capb(client, "backup");
89
interface->essid = strdup(client->value);
91
memset(wconf.essid, 0, IW_ESSID_MAX_SIZE + 1);
92
snprintf(wconf.essid, IW_ESSID_MAX_SIZE + 1, "%s", interface->essid);
96
iw_set_basic_config(wfd, interface->name, &wconf);
98
di_info("Network chosen: %s. Proceeding to connect.", interface->essid);
103
int exists_in_network_list(wireless_scan_head list, wireless_scan *network)
107
for (it = list.result; it != network; it = it->next) {
108
if (strcmp(it->b.essid, network->b.essid) == 0) {
116
int netcfg_wireless_show_essids(struct debconfclient *client, struct netcfg_interface *interface)
118
wireless_scan_head network_list;
119
wireless_config wconf;
121
int essid_list_len = 1;
123
iw_get_basic_config (wfd, interface->name, &wconf);
124
netcfg_interface_up(interface);
126
if (iw_scan(wfd, interface->name, iw_get_kernel_we_version(),
127
&network_list) >= 0 ) {
128
wireless_scan *network;
130
di_info("Scan of wireless interface %s succeeded.", interface->name);
132
/* Determine the actual length of the buffer. */
133
for (network = network_list.result; network; network =
135
if (!exists_in_network_list(network_list, network)) {
136
essid_list_len += (strlen(network->b.essid) + 2);
139
/* Buffer initialization. */
140
buffer = malloc(essid_list_len * sizeof(char));
141
if (buffer == NULL) {
142
/* Error in memory allocation. */
143
di_warning("Unable to allocate memory for network list buffer.");
144
return ENTER_MANUALLY;
148
/* Create list of available ESSIDs. */
149
for (network = network_list.result; network; network = network->next) {
150
if (!exists_in_network_list(network_list, network)) {
151
strcat(buffer, network->b.essid);
152
strcat(buffer, ", ");
156
/* Asking the user. */
157
debconf_capb(client, "backup");
158
debconf_subst(client, "netcfg/wireless_show_essids", "essid_list", buffer);
159
debconf_fset(client, "netcfg/wireless_show_essids", "seen", "false");
160
debconf_input(client, "high", "netcfg/wireless_show_essids");
162
if (debconf_go(client) == CMD_GOBACK) {
163
debconf_fset(client, "netcfg/wireless_show_essids", "seen",
165
free_network_list(&network_list.result);
171
debconf_get(client, "netcfg/wireless_show_essids");
173
/* User wants to enter an ESSID manually. */
174
if (strcmp(client->value, "manual") == 0) {
175
free_network_list(&network_list.result);
178
return ENTER_MANUALLY;
181
/* User has chosen a network from the list, need to find which one and
182
* get its cofiguration. */
183
for (network = network_list.result; network; network = network->next) {
184
if (strcmp(network->b.essid, client->value) == 0) {
186
interface->essid = strdup(network->b.essid);
191
/* Free the network list. */
192
free_network_list(&network_list.result);
196
/* Go directly to choosing manually, use the wireless_essid_again
198
if (netcfg_wireless_choose_essid_manually(client, interface,
199
"netcfg/wireless_essid_again") == GO_BACK) {
207
iw_set_basic_config(wfd, interface->name, &wconf);
208
netcfg_interface_down(interface);
210
di_info("Network chosen: %s. Proceeding to connect.", interface->essid);
215
int netcfg_wireless_set_essid(struct debconfclient *client, struct netcfg_interface *interface)
217
wireless_config wconf;
221
iw_get_basic_config(wfd, interface->name, &wconf);
223
choose_ret = netcfg_wireless_show_essids(client, interface);
225
if (choose_ret == GO_BACK) {
229
if (choose_ret == ENTER_MANUALLY) {
230
if (netcfg_wireless_choose_essid_manually(client, interface,
231
"netcfg/wireless_essid") == GO_BACK) {
239
static void unset_wep_key (const char *if_name)
241
wireless_config wconf;
243
iw_get_basic_config(wfd, if_name, &wconf);
247
wconf.key_flags = IW_ENCODE_DISABLED | IW_ENCODE_NOKEY;
250
iw_set_basic_config (wfd, if_name, &wconf);
253
int netcfg_wireless_set_wep (struct debconfclient * client, struct netcfg_interface *interface)
255
wireless_config wconf;
257
int ret, keylen, err = 0;
258
unsigned char buf [IW_ENCODING_TOKEN_MAX + 1];
261
iw_get_basic_config (wfd, interface->name, &wconf);
263
debconf_subst(client, "netcfg/wireless_wep", "iface", interface->name);
264
debconf_input (client, "high", "netcfg/wireless_wep");
265
ret = debconf_go(client);
267
if (ret == CMD_GOBACK)
270
debconf_get(client, "netcfg/wireless_wep");
274
unset_wep_key (interface->name);
276
if (interface->wepkey != NULL) {
277
free(interface->wepkey);
278
interface->wepkey = NULL;
284
while ((keylen = iw_in_key (rv, buf)) == -1) {
285
debconf_subst(client, "netcfg/invalid_wep", "wepkey", rv);
286
debconf_input(client, "critical", "netcfg/invalid_wep");
289
debconf_input (client, "high", "netcfg/wireless_wep");
290
ret = debconf_go(client);
292
if (ret == CMD_GOBACK)
295
debconf_get(client, "netcfg/wireless_wep");
299
/* Now rv is safe to store since it parsed fine */
300
interface->wepkey = strdup(rv);
302
wrq.u.data.pointer = buf;
303
wrq.u.data.flags = 0;
304
wrq.u.data.length = keylen;
306
if ((err = iw_set_ext(skfd, interface->name, SIOCSIWENCODE, &wrq)) < 0) {
307
di_warning("setting WEP key on %s failed with code %d", interface->name, err);
316
int is_wireless_iface (const char *if_name)
322
int netcfg_wireless_set_essid (struct debconfclient *client, struct netcfg_interface *interface)
329
int netcfg_wireless_set_wep (struct debconfclient *client, struct netcfg_interface *interface)