2 * Wireless Network Adapter configuration utility
4 * Copyright (C) 2005 Felix Fietkau <nbd@openwrt.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
25 #define ADD_VIF_RETRIES 5
28 /*------------------------------------------------------------------*/
30 * Macro to handle errors when setting WE
31 * Print a nice error message and exit...
32 * We define them as macro so that "return" do the right thing.
33 * The "do {...} while(0)" is a standard trick
35 #define ERR_SET_EXT(rname, request) \
36 fprintf(stderr, "Error for wireless request \"%s\" (%X) :\n", \
39 #define ABORT_ARG_NUM(rname, request) \
41 ERR_SET_EXT(rname, request); \
42 fprintf(stderr, " too few arguments.\n"); \
45 #define ABORT_ARG_TYPE(rname, request, arg) \
47 ERR_SET_EXT(rname, request); \
48 fprintf(stderr, " invalid argument \"%s\".\n", arg); \
51 #define ABORT_ARG_SIZE(rname, request, max) \
53 ERR_SET_EXT(rname, request); \
54 fprintf(stderr, " argument too big (max %d)\n", max); \
57 /*------------------------------------------------------------------*/
59 * Wrapper to push some Wireless Parameter in the driver
60 * Use standard wrapper and add pretty error message if fail...
62 #define IW_SET_EXT_ERR(skfd, ifname, request, wrq, rname) \
64 if(iw_set_ext(skfd, ifname, request, wrq) < 0) { \
65 ERR_SET_EXT(rname, request); \
66 fprintf(stderr, " SET failed on device %-1.16s ; %s.\n", \
67 ifname, strerror(errno)); \
70 /*------------------------------------------------------------------*/
72 * Wrapper to extract some Wireless Parameter out of the driver
73 * Use standard wrapper and add pretty error message if fail...
75 #define IW_GET_EXT_ERR(skfd, ifname, request, wrq, rname) \
77 if(iw_get_ext(skfd, ifname, request, wrq) < 0) { \
78 ERR_SET_EXT(rname, request); \
79 fprintf(stderr, " GET failed on device %-1.16s ; %s.\n", \
80 ifname, strerror(errno)); \
83 static void set_wext_ssid(int skfd
, char *ifname
);
86 static char buffer
[128];
87 static int wpa_enc
= 0;
89 static char *wl_var(char *name
)
91 sprintf(buffer
, "%s_%s", prefix
, name
);
95 static char *vif_var(int vif
, char *name
)
100 sprintf(buffer
, "%s.%d_%s", prefix
, vif
, name
);
104 static int nvram_enabled(char *name
)
106 return (nvram_match(name
, "1") || nvram_match(name
, "on") || nvram_match(name
, "enabled") || nvram_match(name
, "true") || nvram_match(name
, "yes") ? 1 : 0);
109 static int nvram_disabled(char *name
)
111 return (nvram_match(name
, "0") || nvram_match(name
, "off") || nvram_match(name
, "disabled") || nvram_match(name
, "false") || nvram_match(name
, "no") ? 1 : 0);
115 static int bcom_ioctl(int skfd
, char *ifname
, int cmd
, void *buf
, int len
)
125 ifr
.ifr_data
= (caddr_t
) &ioc
;
126 strncpy(ifr
.ifr_name
, ifname
, IFNAMSIZ
);
128 ret
= ioctl(skfd
, SIOCDEVPRIVATE
, &ifr
);
132 fprintf(stderr
, "IOCTL %d failed: %d\n", cmd
, ret
);
138 static int bcom_set_var(int skfd
, char *ifname
, char *var
, void *val
, int len
)
143 if (strlen(var
) + 1 > sizeof(buf
) || len
> sizeof(buf
))
146 bzero(buf
, sizeof(buf
));
148 memcpy(&buf
[strlen(var
) + 1], val
, len
);
150 ret
= bcom_ioctl(skfd
, ifname
, WLC_SET_VAR
, buf
, sizeof(buf
));
154 fprintf(stderr
, "SET_VAR %s failed: %d\n", var
, ret
);
160 static int bcom_get_var(int skfd
, char *ifname
, char *var
, void *buf
, int len
)
164 if (strlen(var
) + 1 > sizeof(buf
) || len
> sizeof(buf
))
167 bzero(buf
, sizeof(buf
));
170 ret
= bcom_ioctl(skfd
, ifname
, WLC_GET_VAR
, buf
, sizeof(buf
));
174 fprintf(stderr
, "GET_VAR %s failed: %d\n", var
, ret
);
180 static int bcom_set_bss_var(int skfd
, char *ifname
, int bss
, char *var
, void *val
, int len
)
185 bzero(buf
, sizeof(buf
));
186 if (strlen(var
) + len
+ 8 > sizeof(buf
) || len
> sizeof(buf
))
189 // "bsscfg:<name>\x00" <bss> <data>
190 i
= sprintf(buf
, "bsscfg:%s", var
);
193 memcpy(buf
+ i
, &bss
, sizeof(bss
));
196 memcpy(buf
+ i
, val
, len
);
199 ret
= bcom_ioctl(skfd
, ifname
, WLC_SET_VAR
, buf
, i
);
203 fprintf(stderr
, "SET_BSS_VAR %s failed: %d\n", var
, ret
);
209 static int bcom_set_int(int skfd
, char *ifname
, char *var
, int val
)
211 return bcom_set_var(skfd
, ifname
, var
, &val
, sizeof(val
));
214 static int bcom_set_bss_int(int skfd
, char *ifname
, int bss
, char *var
, int val
)
216 return bcom_set_bss_var(skfd
, ifname
, bss
, var
, &val
, sizeof(val
));
219 static int is_new_bcom(int skfd
, char *ifname
)
224 bcom_ioctl(skfd
, ifname
, WLC_DUMP
, buf
, 8192);
226 if (strstr(buf
, "3.130"))
232 static int bcom_get_wsec(int vif
)
236 if (nvram_match(vif_var(vif
, "crypto"), "tkip"))
238 else if (nvram_match(vif_var(vif
, "crypto"), "aes"))
240 else if (nvram_match(vif_var(vif
, "crypto"), "tkip+aes") || nvram_match(vif_var(vif
, "crypto"), "aes+tkip"))
241 val
= TKIP_ENABLED
| AES_ENABLED
;
248 static int bcom_get_wauth(int vif
)
250 char *v
, *next
, var
[80];
253 if (!(v
= nvram_get(vif_var(vif
, "akm"))))
254 v
= nvram_safe_get(vif_var(vif
, "auth_mode"));
256 foreach(var
, v
, next
) {
257 if (strcmp(var
, "psk") == 0)
259 else if (strcmp(var
, "psk2") == 0)
260 res
|= WPA2_AUTH_PSK
;
261 else if (strcmp(var
, "wpa") == 0)
262 res
|= WPA_AUTH_UNSPECIFIED
;
263 else if (strcmp(var
, "wpa2") == 0)
264 res
|= WPA2_AUTH_UNSPECIFIED
;
270 static void stop_bcom(int skfd
, char *ifname
)
275 if (bcom_ioctl(skfd
, ifname
, WLC_GET_MAGIC
, &val
, sizeof(val
)) < 0)
280 bcom_ioctl(skfd
, ifname
, WLC_SET_SSID
, &ssid
, sizeof(ssid
));
281 bcom_ioctl(skfd
, ifname
, WLC_DOWN
, NULL
, 0);
285 static void start_bcom(int skfd
, char *ifname
)
289 if (bcom_ioctl(skfd
, ifname
, WLC_GET_MAGIC
, &val
, sizeof(val
)) < 0)
292 bcom_ioctl(skfd
, ifname
, WLC_UP
, &val
, sizeof(val
));
295 static int setup_bcom_wds(int skfd
, char *ifname
)
302 if (v
= nvram_get(wl_var("wds"))) {
303 struct maclist
*wdslist
= (struct maclist
*) buf
;
304 struct ether_addr
*addr
= wdslist
->ea
;
307 memset(buf
, 0, 8192);
308 foreach(wbuf
, v
, next
) {
309 if (ether_atoe(wbuf
, addr
->ether_addr_octet
)) {
315 bcom_ioctl(skfd
, ifname
, WLC_SET_WDSLIST
, buf
, sizeof(buf
));
320 static void set_wext_mode(skfd
, ifname
)
323 int ap
= 0, infra
= 0, wet
= 0;
325 /* Set operation mode */
326 ap
= !nvram_match(wl_var("mode"), "sta") && !nvram_match(wl_var("mode"), "wet");
327 infra
= !nvram_disabled(wl_var("infra"));
328 wet
= !ap
&& nvram_match(wl_var("mode"), "wet");
330 wrq
.u
.mode
= (!infra
? IW_MODE_ADHOC
: (ap
? IW_MODE_MASTER
: (wet
? IW_MODE_REPEAT
: IW_MODE_INFRA
)));
331 IW_SET_EXT_ERR(skfd
, ifname
, SIOCSIWMODE
, &wrq
, "Set Mode");
335 void start_watchdog(int skfd
, char *ifname
)
339 unsigned char buf
[8192], buf2
[8192], wbuf
[80], *p
, *tmp
;
340 int wds
= 0, i
, restart_wds
;
345 system("kill $(cat /var/run/wifi.pid) 2>&- >&-");
346 f
= fopen("/var/run/wifi.pid", "w");
347 fprintf(f
, "%d\n", getpid());
350 v
= nvram_safe_get(wl_var("wds"));
351 memset(buf2
, 0, 8192);
353 foreach(wbuf
, v
, next
) {
354 if (ether_atoe(wbuf
, p
)) {
359 v
= nvram_safe_get(wl_var("ssid"));
363 if (bcom_ioctl(skfd
, ifname
, WLC_GET_BSSID
, buf
, 6) < 0)
364 bcom_ioctl(skfd
, ifname
, WLC_SET_SSID
, v
, strlen(v
));
367 for (i
= 0; i
< wds
; i
++) {
368 memset(buf
, 0, 8192);
369 strcpy(buf
, "sta_info");
370 memcpy(buf
+ strlen(buf
) + 1, p
, 6);
371 if (bcom_ioctl(skfd
, ifname
, WLC_GET_VAR
, buf
, 8192) < 0) {
373 sta_info_t
*sta
= (sta_info_t
*) (buf
+ 4);
374 if (!(sta
->flags
& 0x40)) {
383 setup_bcom_wds(skfd
, ifname
);
387 static void setup_bcom_vif_sec(int skfd
, char *ifname
, int vif
)
389 int val
, wep
, wsec
, i
;
392 wsec
= bcom_get_wsec(vif
);
394 val
= bcom_get_wauth(vif
);
398 bcom_set_bss_int(skfd
, ifname
, vif
, "wpa_auth", val
);
401 if (WPA_AUTH_PSK
| WPA2_AUTH_PSK
) {
402 v
= nvram_safe_get(wl_var("wpa_psk"));
403 if ((strlen(v
) >= 8) && (strlen(v
) < 63) && nvram_match(wl_var("mode"), "wet") && (vif
== 0)) {
404 /* Enable in-driver WPA supplicant */
407 pmk
.key_len
= (unsigned short) strlen(v
);
408 pmk
.flags
= WSEC_PASSPHRASE
;
410 bcom_ioctl(skfd
, ifname
, WLC_SET_WSEC_PMK
, &pmk
, sizeof(pmk
));
411 bcom_set_int(skfd
, ifname
, "sup_wpa", 1);
413 bcom_set_int(skfd
, ifname
, "sup_wpa", 0);
416 bcom_set_bss_int(skfd
, ifname
, vif
, "eap_restrict", 1);
417 bcom_set_bss_int(skfd
, ifname
, vif
, "wsec", wsec
);
418 bcom_set_bss_int(skfd
, ifname
, vif
, "wsec_restrict", 1);
420 bcom_set_bss_int(skfd
, ifname
, vif
, "eap_restrict", 0);
421 if (wep
= nvram_enabled(vif_var(vif
, "wep"))) {
422 wep
= atoi(nvram_safe_get(vif_var(vif
, "key")));
423 if ((wep
>= 1) && (wep
<= 4)) {
424 for (i
= 1; i
< 4; i
++) {
426 char name
[5] = "key0";
427 unsigned char *kdata
= k
.data
;
430 bzero(&k
, sizeof(k
));
432 kstr
= nvram_safe_get(vif_var(vif
, name
));
433 k
.len
= strlen(kstr
);
434 if ((k
.len
== 10) || (k
.len
== 26)) {
437 fprintf(stderr
, "Adding WEP key %d to VIF %d: ", i
, vif
);
441 strncpy(name
, kstr
, 2);
443 *kdata
= (unsigned char) strtoul(name
, NULL
, 16);
445 fprintf(stderr
, "%02x", *kdata
);
452 fprintf(stderr
, "\n");
457 if ((k
.len
> 0) && (i
== wep
))
458 k
.flags
= WL_PRIMARY_KEY
;
460 bcom_set_bss_var(skfd
, ifname
, vif
, "wsec_key", &k
, sizeof(k
));
463 bcom_set_bss_int(skfd
, ifname
, vif
, "wsec", WEP_ENABLED
);
464 bcom_set_bss_int(skfd
, ifname
, vif
, "wsec_restrict", 1);
465 bcom_set_bss_int(skfd
, ifname
, vif
, "auth", 1);
473 bcom_set_bss_int(skfd
, ifname
, vif
, "wsec", 0);
474 bcom_set_bss_int(skfd
, ifname
, vif
, "wsec_restrict", 0);
477 // bcom_set_bss_int(skfd, ifname, vif, "auth", atoi(nvram_safe_get(vif_var(vif, "auth"))));
480 static void setup_bcom_vif(int skfd
, char *ifname
, int vif
)
482 int val
, wep
, wsec
, i
;
486 s
= nvram_safe_get(vif_var(vif
, "ssid"));
487 strncpy(ssid
.SSID
, s
, sizeof(ssid
.SSID
));
488 ssid
.SSID_len
= strlen(ssid
.SSID
);
489 ssid
.SSID_len
= ((ssid
.SSID_len
> sizeof(ssid
.SSID
)) ? sizeof(ssid
.SSID
) : ssid
.SSID_len
);
490 bcom_set_bss_var(skfd
, ifname
, vif
, "ssid", &ssid
, sizeof(ssid
));
492 val
= nvram_enabled(vif_var(vif
, "closed"));
493 bcom_set_bss_int(skfd
, ifname
, vif
, "closednet", val
);
495 val
= nvram_enabled(wl_var("ap_isolate"));
496 bcom_set_bss_int(skfd
, ifname
, vif
, "ap_isolate", val
);
500 static void start_bcom_vif(int skfd
, char *ifname
, int vif
)
507 for (i
= 0; i
< ADD_VIF_RETRIES
; i
++) {
508 if (bcom_set_var(skfd
, ifname
, "bss" , cfg
, sizeof(cfg
)) == 0)
514 static void setup_bcom_common(int skfd
, char *ifname
)
517 char buf
[8192], wbuf
[80], *v
;
519 nvram_set(wl_var("ifname"), ifname
);
522 strncpy(buf
, nvram_safe_get(wl_var("country_code")), 4);
524 bcom_ioctl(skfd
, ifname
, WLC_SET_COUNTRY
, buf
, 4);
526 /* Set other options */
527 val
= nvram_enabled(wl_var("lazywds"));
528 bcom_ioctl(skfd
, ifname
, WLC_SET_LAZYWDS
, &val
, sizeof(val
));
530 if (v
= nvram_get(wl_var("dtim"))) {
532 bcom_ioctl(skfd
, ifname
, WLC_SET_DTIMPRD
, &val
, sizeof(val
));
534 if (v
= nvram_get(wl_var("bcn"))) {
536 bcom_ioctl(skfd
, ifname
, WLC_SET_BCNPRD
, &val
, sizeof(val
));
538 if (v
= nvram_get(wl_var("antdiv"))) {
540 bcom_ioctl(skfd
, ifname
, WLC_SET_ANTDIV
, &val
, sizeof(val
));
542 if (v
= nvram_get(wl_var("txant"))) {
544 bcom_ioctl(skfd
, ifname
, WLC_SET_TXANT
, &val
, sizeof(val
));
546 if (v
= nvram_get(wl_var("maxassoc"))) {
548 bcom_set_int(skfd
, ifname
, "maxassoc", val
);
551 val
= nvram_enabled(wl_var("frameburst"));
552 bcom_ioctl(skfd
, ifname
, WLC_SET_FAKEFRAG
, &val
, sizeof(val
));
554 ap
= !nvram_match(wl_var("mode"), "sta") && !nvram_match(wl_var("mode"), "wet");
557 val
= setup_bcom_wds(skfd
, ifname
);
559 if ((!ap
|| val
) && is_new_bcom(skfd
, ifname
))
560 start_watchdog(skfd
, ifname
);
562 /* Set up afterburner, disabled it if WDS is enabled */
563 if (val
|| nvram_enabled(wl_var("lazywds"))) {
567 if (nvram_enabled(wl_var("afterburner")))
569 if (nvram_disabled(wl_var("afterburner")))
573 bcom_set_var(skfd
, ifname
, "afterburner_override", &val
, sizeof(val
));
575 /* Set up MAC list */
576 if (nvram_match(wl_var("macmode"), "allow"))
577 val
= WLC_MACMODE_ALLOW
;
578 else if (nvram_match(wl_var("macmode"), "deny"))
579 val
= WLC_MACMODE_DENY
;
581 val
= WLC_MACMODE_DISABLED
;
583 if ((val
!= WLC_MACMODE_DISABLED
) && (v
= nvram_get(wl_var("maclist")))) {
584 struct maclist
*mac_list
;
585 struct ether_addr
*addr
;
588 memset(buf
, 0, 8192);
589 mac_list
= (struct maclist
*) buf
;
592 foreach(wbuf
, v
, next
) {
593 if (ether_atoe(wbuf
, addr
->ether_addr_octet
)) {
598 bcom_ioctl(skfd
, ifname
, WLC_SET_MACLIST
, buf
, sizeof(buf
));
600 val
= WLC_MACMODE_DISABLED
;
602 bcom_ioctl(skfd
, ifname
, WLC_SET_MACMODE
, &val
, sizeof(val
));
605 bcom_ioctl(skfd
, ifname
, WLC_GET_PHYTYPE
, &val
, sizeof(val
));
607 int override
= WLC_G_PROTECTION_OFF
;
608 int control
= WLC_G_PROTECTION_CTL_OFF
;
610 if (v
= nvram_get(wl_var("gmode")))
618 bcom_ioctl(skfd
, ifname
, WLC_SET_GMODE
, &val
, sizeof(val
));
620 if (nvram_match(wl_var("gmode_protection"), "auto")) {
621 override
= WLC_G_PROTECTION_AUTO
;
622 control
= WLC_G_PROTECTION_CTL_OVERLAP
;
624 if (nvram_enabled(wl_var("gmode_protection"))) {
625 override
= WLC_G_PROTECTION_ON
;
626 control
= WLC_G_PROTECTION_CTL_OVERLAP
;
628 bcom_ioctl(skfd
, ifname
, WLC_SET_GMODE_PROTECTION_CONTROL
, &override
, sizeof(control
));
629 bcom_ioctl(skfd
, ifname
, WLC_SET_GMODE_PROTECTION_OVERRIDE
, &override
, sizeof(override
));
632 if (nvram_match(wl_var("plcphdr"), "long"))
635 val
= WLC_PLCP_SHORT
;
637 bcom_ioctl(skfd
, ifname
, WLC_SET_PLCPHDR
, &val
, sizeof(val
));
642 static void setup_bcom_new(int skfd
, char *ifname
)
645 int iface
[16], ifaces
= 1;
646 int ap
, apsta
, sta
, wet
;
649 if (bcom_ioctl(skfd
, ifname
, WLC_GET_MAGIC
, &val
, sizeof(val
)) < 0)
654 for (i
= 0; i
< 16; i
++) {
655 int cfg
[2]; /* index, enabled */
660 bcom_set_var(skfd
, ifname
, "bss", cfg
, sizeof(cfg
));
662 if ((i
> 0) && nvram_enabled(vif_var(i
, "enabled")) && (i
== 0 || nvram_get(vif_var(i
, "ssid")))) {
668 set_wext_mode(skfd
, ifname
);
670 ap
= nvram_match(wl_var("mode"), "ap") || nvram_match(wl_var("mode"), "apsta");
671 apsta
= nvram_match(wl_var("mode"), "apsta");
672 sta
= nvram_match(wl_var("mode"), "sta");
674 bcom_set_int(skfd
, ifname
, "apsta", apsta
);
675 bcom_set_int(skfd
, ifname
, "mssid", (ifaces
> 1));
677 for (i
= 0; i
< (sta
? 0 : ifaces
); i
++) {
679 fprintf(stderr
, "setup_bcom_vif(%d) start\n", iface
[i
]);
681 setup_bcom_vif(skfd
, ifname
, iface
[i
]);
683 fprintf(stderr
, "setup_bcom_vif(%d) end\n", iface
[i
]);
688 if (v
= nvram_get(wl_var("rts"))) {
690 bcom_set_int(skfd
, ifname
, "rtsthresh", val
);
692 if (v
= nvram_get(wl_var("frag"))) {
694 bcom_set_int(skfd
, ifname
, "fragthresh", val
);
697 val
= (nvram_disabled(wl_var("radio")) ? (1 | (1 << 16)) : 0);
698 bcom_ioctl(skfd
, ifname
, WLC_SET_RADIO
, &val
, sizeof(val
));
700 setup_bcom_common(skfd
, ifname
);
701 start_bcom(skfd
, ifname
);
703 val
= atoi(nvram_safe_get(wl_var("channel")));
705 bcom_ioctl(skfd
, ifname
, WLC_SET_CHANNEL
, &val
, sizeof(val
));
708 bcom_ioctl(skfd
, ifname
, WLC_SET_CS_SCAN_TIMER
, &val
, sizeof(val
));
710 for (i
= 0; i
< (sta
? 0 : ifaces
); i
++) {
711 setup_bcom_vif_sec(skfd
, ifname
, iface
[i
]);
714 for (i
= 0; i
< (sta
? 0 : ifaces
); i
++) {
715 start_bcom_vif(skfd
, ifname
, iface
[i
]);
719 static void setup_bcom_old(int skfd
, char *ifname
)
726 if (bcom_ioctl(skfd
, ifname
, WLC_GET_MAGIC
, &val
, sizeof(val
)) < 0)
729 setup_bcom_common(skfd
, ifname
);
731 if (v
= nvram_get(wl_var("frag"))) {
733 bcom_ioctl(skfd
, ifname
, WLC_SET_FRAG
, &val
, sizeof(val
));
735 if (v
= nvram_get(wl_var("rts"))) {
737 bcom_ioctl(skfd
, ifname
, WLC_SET_RTS
, &val
, sizeof(val
));
740 val
= nvram_enabled(wl_var("closed"));
741 bcom_ioctl(skfd
, ifname
, WLC_SET_CLOSED
, &val
, sizeof(val
));
743 val
= nvram_enabled(wl_var("ap_isolate"));
744 bcom_set_int(skfd
, ifname
, "ap_isolate", val
);
746 start_bcom(skfd
, ifname
);
747 set_wext_ssid(skfd
, ifname
);
749 val
= bcom_get_wauth(0);
750 bcom_ioctl(skfd
, ifname
, WLC_SET_WPA_AUTH
, &val
, sizeof(val
));
752 if (val
& (WPA_AUTH_PSK
| WPA2_AUTH_PSK
)) {
753 v
= nvram_safe_get(wl_var("wpa_psk"));
754 if ((strlen(v
) >= 8) && (strlen(v
) < 63) && nvram_match(wl_var("mode"), "wet")) {
755 /* Enable in-driver WPA supplicant */
758 pmk
.key_len
= (unsigned short) strlen(v
);
759 pmk
.flags
= WSEC_PASSPHRASE
;
761 bcom_ioctl(skfd
, ifname
, WLC_SET_WSEC_PMK
, &pmk
, sizeof(pmk
));
762 bcom_set_int(skfd
, ifname
, "sup_wpa", 1);
767 bcom_ioctl(skfd
, ifname
, WLC_SET_EAP_RESTRICT
, &val
, sizeof(val
));
768 val
= bcom_get_wsec(0);
769 bcom_ioctl(skfd
, ifname
, WLC_SET_WSEC
, &val
, sizeof(val
));
772 bcom_ioctl(skfd
, ifname
, WLC_SET_WSEC
, &val
, sizeof(val
));
773 bcom_ioctl(skfd
, ifname
, WLC_SET_EAP_RESTRICT
, &val
, sizeof(val
));
774 bcom_set_int(skfd
, ifname
, "sup_wpa", 0);
778 static void set_wext_ssid(int skfd
, char *ifname
)
781 char essid
[IW_ESSID_MAX_SIZE
+ 1];
784 buffer
= nvram_get(wl_var("ssid"));
786 if (!buffer
|| (strlen(buffer
) > IW_ESSID_MAX_SIZE
))
789 wrq
.u
.essid
.flags
= 1;
790 strcpy(essid
, buffer
);
791 wrq
.u
.essid
.pointer
= (caddr_t
) essid
;
792 wrq
.u
.essid
.length
= strlen(essid
) + 1;
793 IW_SET_EXT_ERR(skfd
, ifname
, SIOCSIWESSID
, &wrq
, "Set ESSID");
796 static void setup_wext_wep(int skfd
, char *ifname
)
802 unsigned char key
[IW_ENCODING_TOKEN_MAX
];
804 memset(&wrq
, 0, sizeof(wrq
));
805 strcpy(keystr
, "key1");
806 for (i
= 1; i
<= 4; i
++) {
807 if (keyval
= nvram_get(wl_var(keystr
))) {
808 keylen
= iw_in_key(keyval
, key
);
811 wrq
.u
.data
.length
= keylen
;
812 wrq
.u
.data
.pointer
= (caddr_t
) key
;
813 wrq
.u
.data
.flags
= i
;
814 IW_SET_EXT_ERR(skfd
, ifname
, SIOCSIWENCODE
, &wrq
, "Set Encode");
820 memset(&wrq
, 0, sizeof(wrq
));
821 i
= atoi(nvram_safe_get(wl_var("key")));
822 if (i
> 0 && i
< 4) {
823 wrq
.u
.data
.flags
= i
| IW_ENCODE_RESTRICTED
;
824 IW_SET_EXT_ERR(skfd
, ifname
, SIOCSIWENCODE
, &wrq
, "Set Encode");
828 static void setup_wext(int skfd
, char *ifname
)
834 int channel
= atoi(nvram_safe_get(wl_var("channel")));
838 wrq
.u
.freq
.flags
= 0;
841 wrq
.u
.freq
.flags
= IW_FREQ_FIXED
;
842 wrq
.u
.freq
.m
= channel
;
843 IW_SET_EXT_ERR(skfd
, ifname
, SIOCSIWFREQ
, &wrq
, "Set Frequency");
846 /* Disable radio if wlX_radio is set and not enabled */
847 wrq
.u
.txpower
.disabled
= nvram_disabled(wl_var("radio"));
849 wrq
.u
.txpower
.value
= -1;
850 wrq
.u
.txpower
.fixed
= 1;
851 wrq
.u
.txpower
.flags
= IW_TXPOW_DBM
;
852 IW_SET_EXT_ERR(skfd
, ifname
, SIOCSIWTXPOW
, &wrq
, "Set Tx Power");
855 if (nvram_enabled(wl_var("wep")) && !wpa_enc
)
856 setup_wext_wep(skfd
, ifname
);
859 set_wext_ssid(skfd
, ifname
);
863 static int setup_interfaces(int skfd
, char *ifname
, char *args
[], int count
)
868 /* Avoid "Unused parameter" warning */
869 args
= args
; count
= count
;
871 if(iw_get_ext(skfd
, ifname
, SIOCGIWNAME
, &wrq
) < 0)
874 if (strncmp(ifname
, "ath", 3) == 0) {
875 set_wext_mode(skfd
, ifname
);
876 setup_wext(skfd
, ifname
);
878 if (is_new_bcom(skfd
, ifname
)) {
880 fprintf(stderr
, "New Broadcom driver detected.\n");
882 stop_bcom(skfd
, ifname
);
884 fprintf(stderr
, "Setup start.\n");
886 setup_bcom_new(skfd
, ifname
);
888 fprintf(stderr
, "Setup done.\n");
892 fprintf(stderr
, "Old Broadcom driver detected.\n");
894 stop_bcom(skfd
, ifname
);
895 set_wext_mode(skfd
, ifname
);
896 setup_bcom_old(skfd
, ifname
);
897 setup_wext(skfd
, ifname
);
904 int main(int argc
, char **argv
)
907 if((skfd
= iw_sockets_open()) < 0) {
912 prefix
= strdup("wl0");
913 iw_enum_devices(skfd
, &setup_interfaces
, NULL
, 0);