2 * wlc - Broadcom Wireless Driver Control Utility
4 * Copyright (C) 2006 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.
17 #include <sys/types.h>
29 #include <proto/802.11.h>
33 #define PTABLE_MAGIC 0xbadc0ded
38 #define PTABLE_END 0xffffffff
41 * Copy each token in wordlist delimited by space into word
42 * Taken from Broadcom shutils.h
44 #define foreach(word, wordlist, next) \
45 for (next = &wordlist[strspn(wordlist, " ")], \
46 strncpy(word, next, sizeof(word)), \
47 word[strcspn(word, " ")] = '\0', \
48 word[sizeof(word) - 1] = '\0', \
49 next = strchr(next, ' '); \
51 next = next ? &next[strspn(next, " ")] : "", \
52 strncpy(word, next, sizeof(word)), \
53 word[strcspn(word, " ")] = '\0', \
54 word[sizeof(word) - 1] = '\0', \
55 next = strchr(next, ' '))
57 static char wlbuf[8192];
58 static char interface[16] = "wl0";
59 static unsigned long ptable[128];
60 static unsigned long kmem_offset = 0;
61 static int vif = 0, debug = 1, fromstdin = 0;
72 PARAM_OPTIONS = 0x0f0,
84 int (*handler)(wlc_param param, void *data, void *value);
93 /* can't use the system include because of the stupid broadcom header files */
94 extern struct ether_addr *ether_aton(const char *asc);
95 static inline int my_ether_ntoa(unsigned char *ea, char *buf)
97 return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
98 ea[0], ea[1], ea[2], ea[3], ea[4], ea[5]);
102 * find the starting point of wl.o in memory
103 * by reading /proc/ksyms
105 static inline void wlc_get_mem_offset(void)
110 /* yes, i'm lazy ;) */
111 f = popen("grep '\\[wl]' /proc/ksyms | sort", "r");
112 if (fgets(s, 64, f) == 0)
118 kmem_offset = strtoul(s, NULL, 16);
121 if (kmem_offset < 0xc0000000)
126 static int ptable_init(void)
132 if (ptable[0] == PTABLE_MAGIC)
135 glob("/lib/modules/2.4.*/wl.o.patch", 0, NULL, &globbuf);
137 if (globbuf.gl_pathv[0] == NULL)
140 if ((fd = open(globbuf.gl_pathv[0], O_RDONLY)) < 0)
143 if (fstat(fd, &statbuf) < 0)
146 if (statbuf.st_size < 512)
149 if (read(fd, ptable, 512) < 512)
152 if (ptable[0] != PTABLE_MAGIC)
157 wlc_get_mem_offset();
158 if (kmem_offset == 0)
169 static inline unsigned long wlc_kmem_read(unsigned long offset)
174 if ((fd = open("/dev/kmem", O_RDONLY )) < 0)
177 lseek(fd, 0x70000000, SEEK_SET);
178 lseek(fd, (kmem_offset - 0x70000000) + offset, SEEK_CUR);
185 static inline void wlc_kmem_write(unsigned long offset, unsigned long value)
189 if ((fd = open("/dev/kmem", O_WRONLY )) < 0)
192 lseek(fd, 0x70000000, SEEK_SET);
193 lseek(fd, (kmem_offset - 0x70000000) + offset, SEEK_CUR);
194 write(fd, &value, 4);
198 static int wlc_patcher_getval(unsigned long key, unsigned long *val)
200 unsigned long *pt = &ptable[1];
203 if (ptable_init() < 0) {
204 fprintf(stderr, "Could not load the ptable\n");
208 while (*pt != PTABLE_END) {
210 tmp = wlc_kmem_read(pt[1]);
225 static int wlc_patcher_setval(unsigned long key, unsigned long val)
227 unsigned long *pt = &ptable[1];
229 if (ptable_init() < 0) {
230 fprintf(stderr, "Could not load the ptable\n");
234 if (val != 0xffffffff)
235 val = (pt[2] & ~(0xffff)) | (val & 0xffff);
237 while (*pt != PTABLE_END) {
239 if (val == 0xffffffff) /* default */
242 wlc_kmem_write(pt[1], val);
250 static int wlc_slottime(wlc_param param, void *data, void *value)
252 int *val = (int *) value;
255 if ((param & PARAM_MODE) == SET) {
256 wlc_patcher_setval(PTABLE_SLT1, *val);
257 wlc_patcher_setval(PTABLE_SLT2, ((*val == -1) ? *val : *val + 510));
258 } else if ((param & PARAM_MODE) == GET) {
259 ret = wlc_patcher_getval(PTABLE_SLT1, (unsigned long *) val);
260 if (*val != 0xffffffff)
267 static int wlc_noack(wlc_param param, void *data, void *value)
269 int *val = (int *) value;
272 if ((param & PARAM_MODE) == SET) {
273 wlc_patcher_setval(PTABLE_ACKW, ((*val) ? 1 : 0));
274 } else if ((param & PARAM_MODE) == GET) {
275 ret = wlc_patcher_getval(PTABLE_ACKW, (unsigned long *) val);
277 *val = (*val ? 1 : 0);
283 static int wlc_ibss_merge(wlc_param param, void *data, void *value)
285 int *val = (int *) value;
288 if ((param & PARAM_MODE) == SET) {
289 /* overwrite the instruction with 'lui v0,0x0' - fake a return
290 * status of 0 for wlc_bcn_tsf_later */
291 wlc_patcher_setval(PTABLE_ACKW, ((*val) ? -1 : 0x3c020000));
292 } else if ((param & PARAM_MODE) == GET) {
293 ret = wlc_patcher_getval(PTABLE_ACKW, (unsigned long *) val);
294 *val = ((*val == -1) ? 1 : 0);
300 static int wlc_ioctl(wlc_param param, void *data, void *value)
302 unsigned int *var = ((unsigned int *) data);
303 unsigned int ioc = *var;
306 return wl_ioctl(interface, ioc, NULL, 0);
308 switch(param & PARAM_TYPE) {
310 return wl_ioctl(interface, ((param & SET) ? (ioc) : (ioc >> 16)) & 0xffff, value, sizeof(int));
312 return wl_ioctl(interface, ((param & SET) ? (ioc) : (ioc >> 16)) & 0xffff, value, BUFSIZE);
317 static int wlc_iovar(wlc_param param, void *data, void *value)
319 int *val = (int *) value;
320 char *iov = *((char **) data);
324 switch(param & PARAM_TYPE) {
326 ret = wl_iovar_setint(interface, iov, *val);
330 switch(param & PARAM_TYPE) {
332 ret = wl_iovar_getint(interface, iov, val);
339 static int wlc_bssiovar(wlc_param param, void *data, void *value)
341 int *val = (int *) value;
342 char *iov = *((char **) data);
346 switch(param & PARAM_TYPE) {
348 ret = wl_bssiovar_setint(interface, iov, vif, *val);
352 switch(param & PARAM_TYPE) {
354 ret = wl_bssiovar_getint(interface, iov, vif, val);
361 static int wlc_vif_enabled(wlc_param param, void *data, void *value)
363 int *val = (int *) value;
367 sprintf((char *) buf, "bss");
370 buf[2] = (*val ? 1 : 0);
371 ret = wl_ioctl(interface, WLC_SET_VAR, buf, sizeof(buf));
372 } else if (param & GET) {
373 ret = wl_ioctl(interface, WLC_GET_VAR, buf, sizeof(buf));
380 static int wlc_ssid(wlc_param param, void *data, void *value)
382 int ret = -1, ret2 = -1;
383 char *dest = (char *) value;
386 if ((param & PARAM_MODE) == GET) {
387 ret = wl_bssiovar_get(interface, "ssid", vif, &ssid, sizeof(ssid));
390 /* if we can't get the ssid through the bssiovar, try WLC_GET_SSID */
391 ret = wl_ioctl(interface, WLC_GET_SSID, &ssid, sizeof(ssid));
394 memcpy(dest, ssid.SSID, ssid.SSID_len);
395 dest[ssid.SSID_len] = 0;
397 } else if ((param & PARAM_MODE) == SET) {
398 strncpy(ssid.SSID, value, 32);
399 ssid.SSID_len = strlen(value);
401 if (ssid.SSID_len > 32)
405 /* for the main interface, also try the WLC_SET_SSID call */
406 ret2 = wl_ioctl(interface, WLC_SET_SSID, &ssid, sizeof(ssid));
409 ret = wl_bssiovar_set(interface, "ssid", vif, &ssid, sizeof(ssid));
410 ret = (!ret2 ? 0 : ret);
416 static int wlc_int(wlc_param param, void *data, void *value)
418 int *var = *((int **) data);
419 int *val = (int *) value;
421 if ((param & PARAM_MODE) == SET) {
423 } else if ((param & PARAM_MODE) == GET) {
430 static int wlc_flag(wlc_param param, void *data, void *value)
432 int *var = *((int **) data);
439 static int wlc_string(wlc_param param, void *data, void *value)
441 char *var = *((char **) data);
443 if ((param & PARAM_MODE) == GET) {
450 static int wlc_afterburner(wlc_param param, void *data, void *value)
452 int *val = (int *) value;
455 if ((param & PARAM_MODE) == GET) {
456 ret = wl_iovar_getint(interface, "afterburner", val);
458 wl_iovar_setint(interface, "wlfeatureflag", (*val ? 3 : 0));
459 ret = wl_iovar_setint(interface, "afterburner", (*val ? 1 : 0));
460 wl_iovar_setint(interface, "afterburner_override", *val);
466 static int wlc_maclist(wlc_param param, void *data, void *value)
468 unsigned int *var = ((unsigned int *) data);
469 unsigned int ioc = *var;
470 int limit = (sizeof(wlbuf) - 4) / sizeof(struct ether_addr);
471 struct maclist *list = (struct maclist *) wlbuf;
472 char *str = (char *) value;
474 struct ether_addr *addr;
478 if ((param & PARAM_MODE) == GET) {
480 ret = wl_ioctl(interface, (ioc >> 16) & 0xffff, wlbuf, sizeof(wlbuf));
483 while (list->count) {
484 str += sprintf(str, "%s", ((((char *) value) == str) ? "" : " "));
485 str += my_ether_ntoa((unsigned char *) &list->ea[list->count-- - 1], str);
490 while (*str && isspace(*str))
497 if (wl_ioctl(interface, (ioc >> 16) & 0xffff, wlbuf, sizeof(wlbuf)) == 0)
500 while (*str && isspace(*str))
505 memset(wlbuf, 0, sizeof(wlbuf));
507 foreach(astr, str, p) {
508 if (list->count >= limit)
511 if ((addr = ether_aton(astr)) != NULL)
512 memcpy(&list->ea[list->count++], addr, sizeof(struct ether_addr));
515 return wl_ioctl(interface, ioc & 0xffff, wlbuf, sizeof(wlbuf));
519 static int wlc_radio(wlc_param param, void *data, void *value)
521 int *val = (int *) value;
524 if ((param & PARAM_MODE) == GET) {
525 ret = wl_ioctl(interface, WLC_GET_RADIO, val, sizeof(int));
526 *val = ((*val & 1) ? 0 : 1);
528 *val = (1 << 16) | (*val ? 0 : 1);
529 ret = wl_ioctl(interface, WLC_SET_RADIO, val, sizeof(int));
535 static int wlc_wsec_key(wlc_param param, void *null, void *value)
537 wl_wsec_key_t wsec_key;
538 unsigned char *index = value;
541 unsigned char hex[3];
543 if ((param & PARAM_MODE) != SET)
546 memset(&wsec_key, 0, sizeof(wsec_key));
547 if (index[0] == '=') {
548 wsec_key.flags = WL_PRIMARY_KEY;
552 if ((index[0] < '1') || (index[0] > '4') || (index[1] != ','))
556 if (strncmp(key, "d:", 2) == 0) { /* delete key */
557 } else if (strncmp(key, "s:", 2) == 0) { /* ascii key */
559 wsec_key.len = strlen(key);
561 if ((wsec_key.len != 5) && (wsec_key.len != 13))
564 strcpy(wsec_key.data, key);
565 } else { /* hex key */
566 wsec_key.len = strlen(key);
567 if ((wsec_key.len != 10) && (wsec_key.len != 26))
571 data = wsec_key.data;
576 *(data++) = (unsigned char) strtoul(hex, NULL, 16);
580 return wl_bssiovar_set(interface, "wsec_key", vif, &wsec_key, sizeof(wsec_key));
583 static inline int cw2ecw(int cw)
586 for (cw++, i = 0; cw; i++) cw >>=1;
590 static int wlc_wme_ac(wlc_param param, void *data, void *value)
592 char *type = *((char **) data);
593 char *settings = (char *) value;
594 char cmd[100], *p, *val;
595 edcf_acparam_t params[AC_COUNT];
601 if ((param & PARAM_MODE) != SET)
604 memset(params, 0, sizeof(params));
605 ret = wl_iovar_get(interface, type, params, sizeof(params));
606 memset(buf, 0, BUFSIZE);
608 buf += strlen(buf) + 1;
610 foreach(cmd, settings, p) {
611 val = strchr(cmd, '=');
613 if (strcmp(cmd, "be") == 0)
615 else if (strcmp(cmd, "bk") == 0)
617 else if (strcmp(cmd, "vi") == 0)
619 else if (strcmp(cmd, "vo") == 0)
625 params[cur].ACI = (params[cur].ACI & (0x3 << 5)) | (cur << 5);
629 intval = strtoul(val, NULL, 10);
630 if (strcmp(cmd, "cwmin") == 0)
631 params[cur].ECW = (params[cur].ECW & ~(0xf)) | cw2ecw(intval);
632 else if (strcmp(cmd, "ecwmin") == 0)
633 params[cur].ECW = (params[cur].ECW & ~(0xf)) | (intval & 0xf);
634 else if (strcmp(cmd, "cwmax") == 0)
635 params[cur].ECW = (params[cur].ECW & ~(0xf << 4)) | (cw2ecw(intval) << 4);
636 else if (strcmp(cmd, "ecwmax") == 0)
637 params[cur].ECW = (params[cur].ECW & ~(0xf << 4)) | ((intval & 0xf) << 4);
638 else if (strcmp(cmd, "aifsn") == 0)
639 params[cur].ACI = (params[cur].ACI & ~(0xf)) | (intval & 0xf);
640 else if (strcmp(cmd, "txop") == 0)
641 params[cur].TXOP = intval >> 5;
642 else if (strcmp(cmd, "force") == 0)
643 params[cur].ACI = (params[cur].ACI & ~(1 << 4)) | ((intval) ? (1 << 4) : 0);
646 memcpy(buf, ¶ms[cur], sizeof(edcf_acparam_t));
647 wl_ioctl(interface, WLC_SET_VAR, wlbuf, BUFSIZE);
653 static int wlc_ifname(wlc_param param, void *data, void *value)
655 char *val = (char *) value;
659 if (strlen(val) < 16)
660 strcpy(interface, val);
664 strcpy(val, interface);
670 static int wlc_wdsmac(wlc_param param, void *data, void *value)
672 unsigned char mac[6];
675 ret = wl_ioctl(interface, WLC_WDS_GET_REMOTE_HWADDR, &mac, 6);
677 my_ether_ntoa(mac, value);
682 static int wlc_pmk(wlc_param param, void *data, void *value)
685 char *str = (char *) value;
688 /* driver doesn't support GET */
690 if ((param & PARAM_MODE) == SET) {
691 strncpy(pmk.key, value, WSEC_MAX_PSK_LEN);
692 pmk.key_len = strlen(value);
694 if (pmk.key_len > WSEC_MAX_PSK_LEN)
695 pmk.key_len = WSEC_MAX_PSK_LEN;
697 pmk.flags = WSEC_PASSPHRASE;
699 ret = wl_ioctl(interface, WLC_SET_WSEC_PMK, &pmk, sizeof(pmk));
705 static const struct wlc_call wlc_calls[] = {
708 .param = STRING|NOARG,
709 .handler = wlc_string,
711 .desc = "Version of this program"
718 .desc = "wlc debug level"
724 .data.ptr = &fromstdin,
725 .desc = "Accept input from stdin"
730 .handler = wlc_ifname,
731 .desc = "interface to send commands to"
736 .handler = wlc_ioctl,
738 .desc = "Bring the interface up"
743 .handler = wlc_ioctl,
744 .data.num = WLC_DOWN,
745 .desc = "Bring the interface down"
750 .handler = wlc_radio,
751 .desc = "Radio enabled flag"
756 .handler = wlc_ioctl,
757 .data.num = ((WLC_GET_AP << 16) | WLC_SET_AP),
758 .desc = "Access Point mode"
763 .handler = wlc_iovar,
765 .desc = "Multi-ssid mode"
770 .handler = wlc_iovar,
772 .desc = "AP+STA mode"
777 .handler = wlc_ioctl,
778 .data.num = ((WLC_GET_INFRA << 16) | WLC_SET_INFRA),
779 .desc = "Infrastructure mode"
784 .handler = wlc_ioctl,
785 .data.num = ((WLC_GET_WET << 16) | WLC_SET_WET),
786 .desc = "Wireless repeater mode",
789 .name = "statimeout",
791 .handler = wlc_iovar,
792 .data.str = "sta_retry_time",
793 .desc = "STA connection timeout"
798 .handler = wlc_ioctl,
799 .data.num = ((WLC_GET_COUNTRY << 16) | WLC_SET_COUNTRY),
800 .desc = "Country code"
805 .handler = wlc_ioctl,
806 .data.num = ((WLC_GET_CHANNEL << 16) | WLC_SET_CHANNEL),
812 .handler = wlc_bssiovar,
813 .data.str = "vlan_mode",
814 .desc = "Parse 802.1Q tags",
821 .desc = "Current vif index"
826 .handler = wlc_vif_enabled,
827 .desc = "vif enabled flag"
833 .desc = "Interface ESSID"
838 .handler = wlc_bssiovar,
839 .data.str = "closednet",
840 .desc = "Hidden ESSID flag"
845 .handler = wlc_bssiovar,
847 .desc = "Security mode flags"
852 .handler = wlc_wsec_key,
853 .desc = "Set/Remove WEP keys"
856 .name = "wsec_restrict",
858 .handler = wlc_bssiovar,
859 .data.str = "wsec_restrict",
860 .desc = "Drop unencrypted traffic"
863 .name = "eap_restrict",
865 .handler = wlc_bssiovar,
866 .data.str = "eap_restrict",
867 .desc = "Only allow 802.1X traffic until 802.1X authorized"
872 .handler = wlc_bssiovar,
873 .data.str = "wpa_auth",
874 .desc = "WPA authentication modes"
877 .name = "ap_isolate",
879 .handler = wlc_bssiovar,
880 .data.str = "ap_isolate",
881 .desc = "Isolate connected clients"
884 .name = "supplicant",
886 .handler = wlc_iovar,
887 .data.str = "sup_wpa",
888 .desc = "Built-in WPA supplicant"
891 .name = "passphrase",
894 .desc = "Passphrase for built-in WPA supplicant",
899 .handler = wlc_iovar,
900 .data.str = "maxassoc",
901 .desc = "Max. number of associated clients",
906 .handler = wlc_iovar,
908 .desc = "WME enabled"
913 .handler = wlc_wme_ac,
914 .data.str = "wme_ac_ap",
915 .desc = "Set WME AC options for AP mode",
918 .name = "wme_ac_sta",
920 .handler = wlc_wme_ac,
921 .data.str = "wme_ac_sta",
922 .desc = "Set WME AC options for STA mode",
927 .handler = wlc_iovar,
928 .data.str = "wme_noack",
929 .desc = "WME ACK disable request",
934 .handler = wlc_ioctl,
935 .data.num = ((WLC_GET_REGULATORY << 16) | WLC_SET_REGULATORY),
936 .desc = "Enable/disable 802.11d regulatory management",
941 .handler = wlc_ioctl,
942 .data.num = ((WLC_GET_SPECT_MANAGMENT << 16) | WLC_SET_SPECT_MANAGMENT),
943 .desc = "Enable/disable 802.11h spectrum management",
946 .name = "fragthresh",
948 .handler = wlc_iovar,
949 .data.str = "fragthresh",
950 .desc = "Fragmentation threshold",
955 .handler = wlc_iovar,
956 .data.str = "rtsthresh",
957 .desc = "RTS threshold"
962 .handler = wlc_ioctl,
963 .data.num = ((WLC_GET_ANTDIV << 16) | WLC_SET_ANTDIV),
964 .desc = "Rx antenna selection"
969 .handler = wlc_ioctl,
970 .data.num = ((WLC_GET_TXANT << 16) | WLC_SET_TXANT),
971 .desc = "Tx antenna selection"
976 .handler = wlc_ioctl,
977 .data.num = ((WLC_GET_DTIMPRD << 16) | WLC_SET_DTIMPRD),
978 .desc = "DTIM period",
983 .handler = wlc_ioctl,
984 .data.num = ((WLC_GET_BCNPRD << 16) | WLC_SET_BCNPRD),
985 .desc = "Beacon interval"
988 .name = "frameburst",
990 .handler = wlc_ioctl,
991 .data.num = ((WLC_GET_FAKEFRAG << 16) | WLC_SET_FAKEFRAG),
992 .desc = "Framebursting"
997 .handler = wlc_ioctl,
998 .data.num = ((WLC_GET_MONITOR << 16) | WLC_SET_MONITOR),
999 .desc = "Monitor mode"
1004 .handler = wlc_ioctl,
1005 .data.num = ((WLC_GET_PASSIVE << 16) | WLC_SET_PASSIVE),
1006 .desc = "Passive mode"
1009 .name = "macfilter",
1011 .handler = wlc_ioctl,
1012 .data.num = ((WLC_GET_MACMODE << 16) | WLC_SET_MACMODE),
1013 .desc = "MAC filter mode (0:disabled, 1:deny, 2:allow)"
1018 .data.num = ((WLC_GET_MACLIST << 16) | WLC_SET_MACLIST),
1019 .handler = wlc_maclist,
1020 .desc = "MAC filter list"
1025 .handler = wlc_ioctl,
1026 .data.num = ((WLC_GET_LAZYWDS << 16) | WLC_SET_LAZYWDS),
1027 .desc = "Automatic WDS"
1032 .data.num = ((WLC_GET_WDSLIST << 16) | WLC_SET_WDSLIST),
1033 .handler = wlc_maclist,
1034 .desc = "WDS connection list"
1037 .name = "wdstimeout",
1039 .handler = wlc_iovar,
1040 .data.str = "wdstimeout",
1041 .desc = "WDS link detection timeout"
1045 .param = STRING|NOARG,
1046 .handler = wlc_wdsmac,
1047 .desc = "MAC of the remote WDS endpoint (only with wds0.* interfaces)"
1050 .name = "afterburner",
1052 .handler = wlc_afterburner,
1053 .desc = "Broadcom Afterburner"
1058 .handler = wlc_slottime,
1059 .desc = "Slot time (-1 = auto)"
1064 .handler = wlc_noack,
1065 .desc = "Tx ACK enabled flag"
1068 .name = "ibss_merge",
1070 .handler = wlc_ibss_merge,
1071 .desc = "Allow IBSS merge in Ad-Hoc mode"
1074 #define wlc_calls_size (sizeof(wlc_calls) / sizeof(struct wlc_call))
1076 static void usage(char *cmd)
1079 fprintf(stderr, "Usage: %s <command> [<argument> ...]\n"
1081 "Available commands:\n", cmd);
1082 for (i = 0; i < wlc_calls_size; i++) {
1083 fprintf(stderr, "\t%-16s\t%s\n", wlc_calls[i].name ?: "", wlc_calls[i].desc ?: "");
1085 fprintf(stderr, "\n");
1089 static int do_command(const struct wlc_call *cmd, char *arg)
1091 static char buf[BUFSIZE];
1098 fprintf(stderr, "do_command %-16s\t'%s'\n", cmd->name, arg);
1101 if ((arg == NULL) && ((cmd->param & PARAM_TYPE) != NONE)) {
1103 ret = cmd->handler(cmd->param | GET, (void *) &cmd->data, (void *) buf);
1105 switch(cmd->param & PARAM_TYPE) {
1107 intval = *((int *) buf);
1110 format = "0x%08x\n";
1111 else if (intval > 255)
1112 format = "0x%04x\n";
1116 fprintf(stdout, format, intval);
1119 fprintf(stdout, "%s\n", buf);
1124 switch(cmd->param & PARAM_TYPE) {
1126 intval = strtoul(arg, &end, 10);
1127 if (end && !(*end)) {
1128 memcpy(buf, &intval, sizeof(intval));
1130 fprintf(stderr, "%s: Invalid argument\n", cmd->name);
1135 strncpy(buf, arg, BUFSIZE);
1136 buf[BUFSIZE - 1] = 0;
1139 ret = cmd->handler(cmd->param | SET, (void *) &cmd->data, (void *) buf);
1142 if ((debug > 0) && (ret != 0))
1143 fprintf(stderr, "Command '%s %s' failed: %d\n", (set == 1 ? "set" : "get"), cmd->name, ret);
1148 static struct wlc_call *find_cmd(char *name)
1150 int found = 0, i = 0;
1152 while (!found && (i < wlc_calls_size)) {
1153 if (strcmp(name, wlc_calls[i].name) == 0)
1159 return (struct wlc_call *) (found ? &wlc_calls[i] : NULL);
1162 int main(int argc, char **argv)
1164 static char buf[BUFSIZE];
1166 char *cmd = argv[0];
1167 struct wlc_call *call;
1173 for(interface[2] = '0'; (interface[2] < '3') && (wl_probe(interface) != 0); interface[2]++);
1174 if (interface[2] == '3') {
1175 fprintf(stderr, "No Broadcom wl interface found!\n");
1181 while ((argc > 0) && (argv[0] != NULL)) {
1182 if ((call = find_cmd(argv[0])) == NULL) {
1183 fprintf(stderr, "Invalid command: %s\n\n", argv[0]);
1186 if ((argc > 1) && (!(call->param & NOARG))) {
1187 ret = do_command(call, argv[1]);
1191 ret = do_command(call, NULL);
1197 while (fromstdin && !feof(stdin)) {
1199 fgets(buf, BUFSIZE - 1, stdin);
1204 if ((s = strchr(buf, '\r')) != NULL)
1206 if ((s = strchr(buf, '\n')) != NULL)
1216 if ((s2 = strchr(buf, ' ')) != NULL)
1219 while (s2 && isspace(*s2))
1222 if ((call = find_cmd(buf)) == NULL) {
1223 fprintf(stderr, "Invalid command: %s\n", buf);
1226 ret = do_command(call, ((call->param & NOARG) ? NULL : s2));