2 * Linux Wireless Extensions support
4 * $Copyright Open Broadcom Corporation$
6 * $Id: wl_iw.c 467328 2014-04-03 01:23:40Z $
17 #include <bcmendian.h>
18 #include <proto/ethernet.h>
20 #include <linux/if_arp.h>
21 #include <asm/uaccess.h>
23 typedef const struct si_pub si_t;
25 #include <wl_android.h>
29 #define WL_ERROR_LEVEL 0x0001
30 #define WL_SCAN_LEVEL 0x0002
31 #define WL_ASSOC_LEVEL 0x0004
32 #define WL_INFORM_LEVEL 0x0008
33 #define WL_WSEC_LEVEL 0x0010
34 #define WL_PNO_LEVEL 0x0020
35 #define WL_COEX_LEVEL 0x0040
36 #define WL_SOFTAP_LEVEL 0x0080
37 #define WL_TRACE_LEVEL 0x0100
39 uint iw_msg_level = WL_ERROR_LEVEL;
41 #define WL_ERROR(x) do {if (iw_msg_level & WL_ERROR_LEVEL) printf x;} while (0)
42 #define WL_SCAN(x) do {if (iw_msg_level & WL_SCAN_LEVEL) printf x;} while (0)
43 #define WL_ASSOC(x) do {if (iw_msg_level & WL_ASSOC_LEVEL) printf x;} while (0)
44 #define WL_INFORM(x) do {if (iw_msg_level & WL_INFORM_LEVEL) printf x;} while (0)
45 #define WL_WSEC(x) do {if (iw_msg_level & WL_WSEC_LEVEL) printf x;} while (0)
46 #define WL_PNO(x) do {if (iw_msg_level & WL_PNO_LEVEL) printf x;} while (0)
47 #define WL_COEX(x) do {if (iw_msg_level & WL_COEX_LEVEL) printf x;} while (0)
48 #define WL_SOFTAP(x) do {if (iw_msg_level & WL_SOFTAP_LEVEL) printf x;} while (0)
49 #define WL_TRACE(x) do {if (iw_msg_level & WL_TRACE_LEVEL) printf x;} while (0)
54 /* these items should evetually go into wireless.h of the linux system headfile dir */
55 #ifndef IW_ENCODE_ALG_SM4
56 #define IW_ENCODE_ALG_SM4 0x20
59 #ifndef IW_AUTH_WAPI_ENABLED
60 #define IW_AUTH_WAPI_ENABLED 0x20
63 #ifndef IW_AUTH_WAPI_VERSION_1
64 #define IW_AUTH_WAPI_VERSION_1 0x00000008
67 #ifndef IW_AUTH_CIPHER_SMS4
68 #define IW_AUTH_CIPHER_SMS4 0x00000020
71 #ifndef IW_AUTH_KEY_MGMT_WAPI_PSK
72 #define IW_AUTH_KEY_MGMT_WAPI_PSK 4
75 #ifndef IW_AUTH_KEY_MGMT_WAPI_CERT
76 #define IW_AUTH_KEY_MGMT_WAPI_CERT 8
78 #endif /* BCMWAPI_WPI */
80 /* Broadcom extensions to WEXT, linux upstream has obsoleted WEXT */
81 #ifndef IW_AUTH_KEY_MGMT_FT_802_1X
82 #define IW_AUTH_KEY_MGMT_FT_802_1X 0x04
85 #ifndef IW_AUTH_KEY_MGMT_FT_PSK
86 #define IW_AUTH_KEY_MGMT_FT_PSK 0x08
89 #ifndef IW_ENC_CAPA_FW_ROAM_ENABLE
90 #define IW_ENC_CAPA_FW_ROAM_ENABLE 0x00000020
94 /* FC9: wireless.h 2.6.25-14.fc9.i686 is missing these, even though WIRELESS_EXT is set to latest
97 #ifndef IW_ENCODE_ALG_PMK
98 #define IW_ENCODE_ALG_PMK 4
100 #ifndef IW_ENC_CAPA_4WAY_HANDSHAKE
101 #define IW_ENC_CAPA_4WAY_HANDSHAKE 0x00000010
105 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
106 #include <linux/rtnetlink.h>
109 struct net_device *ap_net_dev = NULL;
110 tsk_ctl_t ap_eth_ctl; /* apsta AP netdev waiter thread */
113 extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status,
114 uint32 reason, char* stringBuf, uint buflen);
116 #define MAX_WLIW_IOCTL_LEN 1024
118 /* IOCTL swapping mode for Big Endian host with Little Endian dongle. Default to off */
119 #define htod32(i) (i)
120 #define htod16(i) (i)
121 #define dtoh32(i) (i)
122 #define dtoh16(i) (i)
123 #define htodchanspec(i) (i)
124 #define dtohchanspec(i) (i)
126 extern struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
127 extern int dhd_wait_pend8021x(struct net_device *dev);
129 #if WIRELESS_EXT < 19
130 #define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST)
131 #define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST)
132 #endif /* WIRELESS_EXT < 19 */
135 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
136 #define DAEMONIZE(a) do { \
137 allow_signal(SIGKILL); \
138 allow_signal(SIGTERM); \
140 #elif ((LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)) && \
141 (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)))
142 #define DAEMONIZE(a) daemonize(a); \
143 allow_signal(SIGKILL); \
144 allow_signal(SIGTERM);
145 #else /* Linux 2.4 (w/o preemption patch) */
146 #define RAISE_RX_SOFTIRQ() \
147 cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
148 #define DAEMONIZE(a) daemonize(); \
150 strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
152 #endif /* LINUX_VERSION_CODE */
154 #define ISCAN_STATE_IDLE 0
155 #define ISCAN_STATE_SCANING 1
157 /* the buf lengh can be WLC_IOCTL_MAXLEN (8K) to reduce iteration */
158 #define WLC_IW_ISCAN_MAXLEN 2048
159 typedef struct iscan_buf {
160 struct iscan_buf * next;
161 char iscan_buf[WLC_IW_ISCAN_MAXLEN];
164 typedef struct iscan_info {
165 struct net_device *dev;
166 struct timer_list timer;
170 iscan_buf_t * list_hdr;
171 iscan_buf_t * list_cur;
173 /* Thread to work on iscan */
174 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
175 struct task_struct *kthread;
178 struct semaphore sysioc_sem;
179 struct completion sysioc_exited;
182 char ioctlbuf[WLC_IOCTL_SMLEN];
184 iscan_info_t *g_iscan = NULL;
185 static void wl_iw_timerfunc(ulong data);
186 static void wl_iw_set_event_mask(struct net_device *dev);
187 static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action);
189 /* priv_link becomes netdev->priv and is the link between netdev and wlif struct */
190 typedef struct priv_link {
194 /* dev to priv_link */
195 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
196 #define WL_DEV_LINK(dev) (priv_link_t*)(dev->priv)
198 #define WL_DEV_LINK(dev) (priv_link_t*)netdev_priv(dev)
202 #define IW_DEV_IF(dev) ((wl_iw_t*)(WL_DEV_LINK(dev))->wliw)
204 static void swap_key_from_BE(
208 key->index = htod32(key->index);
209 key->len = htod32(key->len);
210 key->algo = htod32(key->algo);
211 key->flags = htod32(key->flags);
212 key->rxiv.hi = htod32(key->rxiv.hi);
213 key->rxiv.lo = htod16(key->rxiv.lo);
214 key->iv_initialized = htod32(key->iv_initialized);
217 static void swap_key_to_BE(
221 key->index = dtoh32(key->index);
222 key->len = dtoh32(key->len);
223 key->algo = dtoh32(key->algo);
224 key->flags = dtoh32(key->flags);
225 key->rxiv.hi = dtoh32(key->rxiv.hi);
226 key->rxiv.lo = dtoh16(key->rxiv.lo);
227 key->iv_initialized = dtoh32(key->iv_initialized);
232 struct net_device *dev,
243 memset(&ioc, 0, sizeof(ioc));
248 strcpy(ifr.ifr_name, dev->name);
249 ifr.ifr_data = (caddr_t) &ioc;
253 #if defined(WL_USE_NETDEV_OPS)
254 ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
256 ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
264 set named driver variable to int value and return error indication
265 calling example: dev_wlc_intvar_set(dev, "arate", rate)
270 struct net_device *dev,
274 char buf[WLC_IOCTL_SMLEN];
278 len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf));
281 return (dev_wlc_ioctl(dev, WLC_SET_VAR, buf, len));
286 struct net_device *dev,
295 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
297 BCM_REFERENCE(iolen);
299 return (dev_wlc_ioctl(dev, WLC_SET_VAR, bufptr, iolen));
304 struct net_device *dev,
313 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
315 BCM_REFERENCE(iolen);
317 return (dev_wlc_ioctl(dev, WLC_GET_VAR, bufptr, buflen));
320 #if WIRELESS_EXT > 17
323 struct net_device *dev,
331 ioctlbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
335 buflen = bcm_mkiovar(name, buf, len, ioctlbuf, MAX_WLIW_IOCTL_LEN);
337 error = dev_wlc_ioctl(dev, WLC_SET_VAR, ioctlbuf, buflen);
342 #endif /* WIRELESS_EXT > 17 */
345 get named driver variable to int value and return error indication
346 calling example: dev_wlc_bufvar_get(dev, "arate", &rate)
351 struct net_device *dev,
353 char *buf, int buflen)
360 ioctlbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
363 len = bcm_mkiovar(name, NULL, 0, ioctlbuf, MAX_WLIW_IOCTL_LEN);
366 error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)ioctlbuf, MAX_WLIW_IOCTL_LEN);
368 bcopy(ioctlbuf, buf, buflen);
375 get named driver variable to int value and return error indication
376 calling example: dev_wlc_intvar_get(dev, "arate", &rate)
381 struct net_device *dev,
386 char buf[WLC_IOCTL_SMLEN];
394 len = bcm_mkiovar(name, (char *)(&data_null), 0, (char *)(&var), sizeof(var.buf));
396 error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)&var, len);
398 *retval = dtoh32(var.val);
403 /* Maintain backward compatibility */
404 #if WIRELESS_EXT < 13
405 struct iw_request_info
407 __u16 cmd; /* Wireless Extension command */
408 __u16 flags; /* More to come ;-) */
411 typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
412 void *wrqu, char *extra);
413 #endif /* WIRELESS_EXT < 13 */
415 #if WIRELESS_EXT > 12
418 struct net_device *dev,
419 struct iw_request_info *info,
420 union iwreq_data *wrqu,
424 int dc = *(int *)extra;
427 error = dev_wlc_intvar_set(dev, "leddc", dc);
433 struct net_device *dev,
434 struct iw_request_info *info,
435 union iwreq_data *wrqu,
439 int mode = *(int *)extra;
443 error = dev_wlc_intvar_set(dev, "vlan_mode", mode);
449 struct net_device *dev,
450 struct iw_request_info *info,
451 union iwreq_data *wrqu,
455 int pm = *(int *)extra;
459 error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
463 #if WIRELESS_EXT > 17
464 #endif /* WIRELESS_EXT > 17 */
465 #endif /* WIRELESS_EXT > 12 */
468 wl_iw_send_priv_event(
469 struct net_device *dev,
473 union iwreq_data wrqu;
474 char extra[IW_CUSTOM_MAX + 1];
478 memset(&wrqu, 0, sizeof(wrqu));
479 if (strlen(flag) > sizeof(extra))
483 wrqu.data.length = strlen(extra);
484 wireless_send_event(dev, cmd, &wrqu, extra);
485 WL_TRACE(("Send IWEVCUSTOM Event as %s\n", extra));
492 struct net_device *dev,
493 struct iw_request_info *info,
500 struct sockaddr bssid;
502 WL_TRACE(("%s: SIOCSIWCOMMIT\n", dev->name));
504 if ((error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid))))
507 ssid.SSID_len = dtoh32(ssid.SSID_len);
512 bzero(&bssid, sizeof(struct sockaddr));
513 if ((error = dev_wlc_ioctl(dev, WLC_REASSOC, &bssid, ETHER_ADDR_LEN))) {
514 WL_ERROR(("%s: WLC_REASSOC failed (%d)\n", __FUNCTION__, error));
523 struct net_device *dev,
524 struct iw_request_info *info,
525 union iwreq_data *cwrq,
533 WL_TRACE(("%s: SIOCGIWNAME\n", dev->name));
536 if ((err = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype))) < 0)
538 if ((err = dev_wlc_ioctl(dev, WLC_GET_BANDLIST, band, sizeof(band))) < 0)
541 band[0] = dtoh32(band[0]);
549 case WLC_PHY_TYPE_LP:
564 snprintf(cwrq->name, IFNAMSIZ, "IEEE 802.11%s", cap);
570 struct net_device *dev,
571 struct iw_request_info *info,
572 struct iw_freq *fwrq,
579 WL_TRACE(("%s: SIOCSIWFREQ\n", dev->name));
581 /* Setting by channel number */
582 if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) {
586 /* Setting by frequency */
588 /* Convert to MHz as best we can */
593 } else if (fwrq->e < 6) {
594 while (fwrq->e++ < 6)
597 /* handle 4.9GHz frequencies as Japan 4 GHz based channelization */
598 if (fwrq->m > 4000 && fwrq->m < 5000)
599 sf = WF_CHAN_FACTOR_4_G; /* start factor for 4 GHz */
601 chan = wf_mhz2channel(fwrq->m, sf);
603 WL_ERROR(("%s: chan=%d\n", __FUNCTION__, chan));
605 if ((error = dev_wlc_ioctl(dev, WLC_SET_CHANNEL, &chan, sizeof(chan)))) {
606 WL_ERROR(("%s: WLC_DISASSOC failed (%d).\n", __FUNCTION__, error));
610 /* -EINPROGRESS: Call commit handler */
616 struct net_device *dev,
617 struct iw_request_info *info,
618 struct iw_freq *fwrq,
625 WL_TRACE(("%s: SIOCGIWFREQ\n", dev->name));
627 if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
630 /* Return radio channel in channel form */
631 fwrq->m = dtoh32(ci.hw_channel);
638 struct net_device *dev,
639 struct iw_request_info *info,
644 int infra = 0, ap = 0, error = 0;
646 WL_TRACE(("%s: SIOCSIWMODE\n", dev->name));
661 infra = htod32(infra);
664 if ((error = dev_wlc_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra))) ||
665 (error = dev_wlc_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap))))
668 /* -EINPROGRESS: Call commit handler */
674 struct net_device *dev,
675 struct iw_request_info *info,
680 int error, infra = 0, ap = 0;
682 WL_TRACE(("%s: SIOCGIWMODE\n", dev->name));
684 if ((error = dev_wlc_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra))) ||
685 (error = dev_wlc_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap))))
688 infra = dtoh32(infra);
690 *uwrq = infra ? ap ? IW_MODE_MASTER : IW_MODE_INFRA : IW_MODE_ADHOC;
697 struct net_device *dev,
698 struct iw_request_info *info,
699 struct iw_point *dwrq,
703 struct iw_range *range = (struct iw_range *) extra;
704 static int channels[MAXCHANNEL+1];
705 wl_uint32_list_t *list = (wl_uint32_list_t *) channels;
706 wl_rateset_t rateset;
711 int bw_cap = 0, sgi_tx = 0, nmode = 0;
713 uint8 nrate_list2copy = 0;
714 uint16 nrate_list[4][8] = { {13, 26, 39, 52, 78, 104, 117, 130},
715 {14, 29, 43, 58, 87, 116, 130, 144},
716 {27, 54, 81, 108, 162, 216, 243, 270},
717 {30, 60, 90, 120, 180, 240, 270, 300}};
720 WL_TRACE(("%s: SIOCGIWRANGE\n", dev->name));
725 dwrq->length = sizeof(struct iw_range);
726 memset(range, 0, sizeof(*range));
728 /* We don't use nwids */
729 range->min_nwid = range->max_nwid = 0;
731 /* Set available channels/frequencies */
732 list->count = htod32(MAXCHANNEL);
733 if ((error = dev_wlc_ioctl(dev, WLC_GET_VALID_CHANNELS, channels, sizeof(channels))))
735 for (i = 0; i < dtoh32(list->count) && i < IW_MAX_FREQUENCIES; i++) {
736 range->freq[i].i = dtoh32(list->element[i]);
738 ch = dtoh32(list->element[i]);
739 if (ch <= CH_MAX_2G_CHANNEL)
740 sf = WF_CHAN_FACTOR_2_4_G;
742 sf = WF_CHAN_FACTOR_5_G;
744 range->freq[i].m = wf_channel2mhz(ch, sf);
745 range->freq[i].e = 6;
747 range->num_frequency = range->num_channels = i;
749 /* Link quality (use NDIS cutoffs) */
750 range->max_qual.qual = 5;
751 /* Signal level (use RSSI) */
752 range->max_qual.level = 0x100 - 200; /* -200 dBm */
753 /* Noise level (use noise) */
754 range->max_qual.noise = 0x100 - 200; /* -200 dBm */
755 /* Signal level threshold range (?) */
756 range->sensitivity = 65535;
758 #if WIRELESS_EXT > 11
759 /* Link quality (use NDIS cutoffs) */
760 range->avg_qual.qual = 3;
761 /* Signal level (use RSSI) */
762 range->avg_qual.level = 0x100 + WL_IW_RSSI_GOOD;
763 /* Noise level (use noise) */
764 range->avg_qual.noise = 0x100 - 75; /* -75 dBm */
765 #endif /* WIRELESS_EXT > 11 */
767 /* Set available bitrates */
768 if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
770 rateset.count = dtoh32(rateset.count);
771 range->num_bitrates = rateset.count;
772 for (i = 0; i < rateset.count && i < IW_MAX_BITRATES; i++)
773 range->bitrate[i] = (rateset.rates[i] & 0x7f) * 500000; /* convert to bps */
774 if ((error = dev_wlc_intvar_get(dev, "nmode", &nmode)))
776 if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype))))
778 if (nmode == 1 && ((phytype == WLC_PHY_TYPE_SSN) || (phytype == WLC_PHY_TYPE_LCN) ||
779 (phytype == WLC_PHY_TYPE_LCN40))) {
780 if ((error = dev_wlc_intvar_get(dev, "mimo_bw_cap", &bw_cap)))
782 if ((error = dev_wlc_intvar_get(dev, "sgi_tx", &sgi_tx)))
784 if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(channel_info_t))))
786 ci.hw_channel = dtoh32(ci.hw_channel);
789 (bw_cap == 2 && ci.hw_channel <= 14)) {
796 (bw_cap == 2 && ci.hw_channel >= 36)) {
802 range->num_bitrates += 8;
803 ASSERT(range->num_bitrates < IW_MAX_BITRATES);
804 for (k = 0; i < range->num_bitrates; k++, i++) {
806 range->bitrate[i] = (nrate_list[nrate_list2copy][k]) * 500000;
810 /* Set an indication of the max TCP throughput
811 * in bit/s that we can expect using this interface.
812 * May be use for QoS stuff... Jean II
814 if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &i, sizeof(i))))
817 if (i == WLC_PHY_TYPE_A)
818 range->throughput = 24000000; /* 24 Mbits/s */
820 range->throughput = 1500000; /* 1.5 Mbits/s */
822 /* RTS and fragmentation thresholds */
824 range->max_rts = 2347;
825 range->min_frag = 256;
826 range->max_frag = 2346;
828 range->max_encoding_tokens = DOT11_MAX_DEFAULT_KEYS;
829 range->num_encoding_sizes = 4;
830 range->encoding_size[0] = WEP1_KEY_SIZE;
831 range->encoding_size[1] = WEP128_KEY_SIZE;
832 #if WIRELESS_EXT > 17
833 range->encoding_size[2] = TKIP_KEY_SIZE;
835 range->encoding_size[2] = 0;
837 range->encoding_size[3] = AES_KEY_SIZE;
839 /* Do not support power micro-management */
844 range->pmp_flags = 0;
847 /* Transmit Power - values are in mW */
848 range->num_txpower = 2;
849 range->txpower[0] = 1;
850 range->txpower[1] = 255;
851 range->txpower_capa = IW_TXPOW_MWATT;
853 #if WIRELESS_EXT > 10
854 range->we_version_compiled = WIRELESS_EXT;
855 range->we_version_source = 19;
857 /* Only support retry limits */
858 range->retry_capa = IW_RETRY_LIMIT;
859 range->retry_flags = IW_RETRY_LIMIT;
860 range->r_time_flags = 0;
861 /* SRL and LRL limits */
862 range->min_retry = 1;
863 range->max_retry = 255;
864 /* Retry lifetime limits unsupported */
865 range->min_r_time = 0;
866 range->max_r_time = 0;
867 #endif /* WIRELESS_EXT > 10 */
869 #if WIRELESS_EXT > 17
870 range->enc_capa = IW_ENC_CAPA_WPA;
871 range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP;
872 range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP;
873 range->enc_capa |= IW_ENC_CAPA_WPA2;
875 /* Determine driver FBT capability. */
876 if (dev_wlc_intvar_get(dev, "fbt_cap", &fbt_cap) == 0) {
877 if (fbt_cap == WLC_FBT_CAP_DRV_4WAY_AND_REASSOC) {
878 /* Tell the host (e.g. wpa_supplicant) to let driver do the handshake */
879 range->enc_capa |= IW_ENC_CAPA_4WAY_HANDSHAKE;
883 #ifdef BCMFW_ROAM_ENABLE_WEXT
884 /* Advertise firmware roam capability to the external supplicant */
885 range->enc_capa |= IW_ENC_CAPA_FW_ROAM_ENABLE;
886 #endif /* BCMFW_ROAM_ENABLE_WEXT */
888 /* Event capability (kernel) */
889 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
890 /* Event capability (driver) */
891 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
892 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
893 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
894 IW_EVENT_CAPA_SET(range->event_capa, IWEVMICHAELMICFAILURE);
895 IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCREQIE);
896 IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCRESPIE);
897 IW_EVENT_CAPA_SET(range->event_capa, IWEVPMKIDCAND);
899 #if WIRELESS_EXT >= 22 && defined(IW_SCAN_CAPA_ESSID)
900 /* FC7 wireless.h defines EXT 22 but doesn't define scan_capa bits */
901 range->scan_capa = IW_SCAN_CAPA_ESSID;
903 #endif /* WIRELESS_EXT > 17 */
909 rssi_to_qual(int rssi)
911 if (rssi <= WL_IW_RSSI_NO_SIGNAL)
913 else if (rssi <= WL_IW_RSSI_VERY_LOW)
915 else if (rssi <= WL_IW_RSSI_LOW)
917 else if (rssi <= WL_IW_RSSI_GOOD)
919 else if (rssi <= WL_IW_RSSI_VERY_GOOD)
927 struct net_device *dev,
928 struct iw_request_info *info,
929 struct iw_point *dwrq,
933 wl_iw_t *iw = IW_DEV_IF(dev);
934 struct sockaddr *addr = (struct sockaddr *) extra;
937 WL_TRACE(("%s: SIOCSIWSPY\n", dev->name));
942 iw->spy_num = MIN(ARRAYSIZE(iw->spy_addr), dwrq->length);
943 for (i = 0; i < iw->spy_num; i++)
944 memcpy(&iw->spy_addr[i], addr[i].sa_data, ETHER_ADDR_LEN);
945 memset(iw->spy_qual, 0, sizeof(iw->spy_qual));
952 struct net_device *dev,
953 struct iw_request_info *info,
954 struct iw_point *dwrq,
958 wl_iw_t *iw = IW_DEV_IF(dev);
959 struct sockaddr *addr = (struct sockaddr *) extra;
960 struct iw_quality *qual = (struct iw_quality *) &addr[iw->spy_num];
963 WL_TRACE(("%s: SIOCGIWSPY\n", dev->name));
968 dwrq->length = iw->spy_num;
969 for (i = 0; i < iw->spy_num; i++) {
970 memcpy(addr[i].sa_data, &iw->spy_addr[i], ETHER_ADDR_LEN);
971 addr[i].sa_family = AF_UNIX;
972 memcpy(&qual[i], &iw->spy_qual[i], sizeof(struct iw_quality));
973 iw->spy_qual[i].updated = 0;
981 struct net_device *dev,
982 struct iw_request_info *info,
983 struct sockaddr *awrq,
989 WL_TRACE(("%s: SIOCSIWAP\n", dev->name));
991 if (awrq->sa_family != ARPHRD_ETHER) {
992 WL_ERROR(("%s: Invalid Header...sa_family\n", __FUNCTION__));
996 /* Ignore "auto" or "off" */
997 if (ETHER_ISBCAST(awrq->sa_data) || ETHER_ISNULLADDR(awrq->sa_data)) {
999 bzero(&scbval, sizeof(scb_val_t));
1000 WL_ERROR(("%s: WLC_DISASSOC\n", __FUNCTION__));
1001 if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
1002 WL_ERROR(("%s: WLC_DISASSOC failed (%d).\n", __FUNCTION__, error));
1006 /* WL_ASSOC(("Assoc to %s\n", bcm_ether_ntoa((struct ether_addr *)&(awrq->sa_data),
1009 /* Reassociate to the specified AP */
1010 if ((error = dev_wlc_ioctl(dev, WLC_REASSOC, awrq->sa_data, ETHER_ADDR_LEN))) {
1011 WL_ERROR(("%s: WLC_REASSOC failed (%d).\n", __FUNCTION__, error));
1014 WL_ERROR(("%s: join BSSID="MACSTR"\n", __FUNCTION__, MAC2STR((u8 *)awrq->sa_data)));
1021 struct net_device *dev,
1022 struct iw_request_info *info,
1023 struct sockaddr *awrq,
1027 WL_TRACE(("%s: SIOCGIWAP\n", dev->name));
1029 awrq->sa_family = ARPHRD_ETHER;
1030 memset(awrq->sa_data, 0, ETHER_ADDR_LEN);
1032 /* Ignore error (may be down or disassociated) */
1033 (void) dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETHER_ADDR_LEN);
1038 #if WIRELESS_EXT > 17
1041 struct net_device *dev,
1042 struct iw_request_info *info,
1043 struct sockaddr *awrq,
1047 struct iw_mlme *mlme;
1049 int error = -EINVAL;
1051 WL_TRACE(("%s: SIOCSIWMLME\n", dev->name));
1053 mlme = (struct iw_mlme *)extra;
1055 WL_ERROR(("Invalid ioctl data.\n"));
1059 scbval.val = mlme->reason_code;
1060 bcopy(&mlme->addr.sa_data, &scbval.ea, ETHER_ADDR_LEN);
1062 if (mlme->cmd == IW_MLME_DISASSOC) {
1063 scbval.val = htod32(scbval.val);
1064 error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t));
1066 else if (mlme->cmd == IW_MLME_DEAUTH) {
1067 scbval.val = htod32(scbval.val);
1068 error = dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scbval,
1072 WL_ERROR(("%s: Invalid ioctl data.\n", __FUNCTION__));
1078 #endif /* WIRELESS_EXT > 17 */
1082 struct net_device *dev,
1083 struct iw_request_info *info,
1084 struct iw_point *dwrq,
1088 wl_scan_results_t *list;
1089 struct sockaddr *addr = (struct sockaddr *) extra;
1090 struct iw_quality qual[IW_MAX_AP];
1091 wl_bss_info_t *bi = NULL;
1093 uint buflen = dwrq->length;
1096 WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name));
1101 /* Get scan results (too large to put on the stack) */
1102 list = kmalloc(buflen, GFP_KERNEL);
1105 memset(list, 0, buflen);
1106 list->buflen = htod32(buflen);
1107 if ((error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen))) {
1108 WL_ERROR(("%d: Scan results error %d\n", __LINE__, error));
1112 list->buflen = dtoh32(list->buflen);
1113 list->version = dtoh32(list->version);
1114 list->count = dtoh32(list->count);
1115 ASSERT(list->version == WL_BSS_INFO_VERSION);
1117 for (i = 0, dwrq->length = 0; i < list->count && dwrq->length < IW_MAX_AP; i++) {
1118 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1119 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1122 /* Infrastructure only */
1123 if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
1127 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1128 addr[dwrq->length].sa_family = ARPHRD_ETHER;
1129 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1130 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1131 qual[dwrq->length].qual = rssi_to_qual(rssi);
1132 qual[dwrq->length].level = 0x100 + rssi;
1133 qual[dwrq->length].noise = 0x100 + bi->phy_noise;
1135 /* Updated qual, level, and noise */
1136 #if WIRELESS_EXT > 18
1137 qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1139 qual[dwrq->length].updated = 7;
1140 #endif /* WIRELESS_EXT > 18 */
1148 memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
1157 wl_iw_iscan_get_aplist(
1158 struct net_device *dev,
1159 struct iw_request_info *info,
1160 struct iw_point *dwrq,
1164 wl_scan_results_t *list;
1166 iscan_info_t *iscan = g_iscan;
1168 struct sockaddr *addr = (struct sockaddr *) extra;
1169 struct iw_quality qual[IW_MAX_AP];
1170 wl_bss_info_t *bi = NULL;
1174 WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name));
1179 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1180 return wl_iw_get_aplist(dev, info, dwrq, extra);
1183 buf = iscan->list_hdr;
1184 /* Get scan results (too large to put on the stack) */
1186 list = &((wl_iscan_results_t*)buf->iscan_buf)->results;
1187 ASSERT(list->version == WL_BSS_INFO_VERSION);
1190 for (i = 0, dwrq->length = 0; i < list->count && dwrq->length < IW_MAX_AP; i++) {
1191 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1192 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1193 WLC_IW_ISCAN_MAXLEN));
1195 /* Infrastructure only */
1196 if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
1200 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1201 addr[dwrq->length].sa_family = ARPHRD_ETHER;
1202 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1203 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1204 qual[dwrq->length].qual = rssi_to_qual(rssi);
1205 qual[dwrq->length].level = 0x100 + rssi;
1206 qual[dwrq->length].noise = 0x100 + bi->phy_noise;
1208 /* Updated qual, level, and noise */
1209 #if WIRELESS_EXT > 18
1210 qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1212 qual[dwrq->length].updated = 7;
1213 #endif /* WIRELESS_EXT > 18 */
1220 memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
1228 #if WIRELESS_EXT > 13
1231 struct net_device *dev,
1232 struct iw_request_info *info,
1233 union iwreq_data *wrqu,
1239 WL_TRACE(("%s: SIOCSIWSCAN\n", dev->name));
1241 /* default Broadcast scan */
1242 memset(&ssid, 0, sizeof(ssid));
1244 #if WIRELESS_EXT > 17
1245 /* check for given essid */
1246 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1247 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1248 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1249 ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
1250 memcpy(ssid.SSID, req->essid, ssid.SSID_len);
1251 ssid.SSID_len = htod32(ssid.SSID_len);
1255 /* Ignore error (most likely scan in progress) */
1256 (void) dev_wlc_ioctl(dev, WLC_SCAN, &ssid, sizeof(ssid));
1262 wl_iw_iscan_set_scan(
1263 struct net_device *dev,
1264 struct iw_request_info *info,
1265 union iwreq_data *wrqu,
1270 iscan_info_t *iscan = g_iscan;
1272 WL_TRACE(("%s: SIOCSIWSCAN iscan=%p\n", dev->name, iscan));
1274 /* use backup if our thread is not successful */
1275 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1276 return wl_iw_set_scan(dev, info, wrqu, extra);
1278 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1282 /* default Broadcast scan */
1283 memset(&ssid, 0, sizeof(ssid));
1285 #if WIRELESS_EXT > 17
1286 /* check for given essid */
1287 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1288 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1289 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1290 ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
1291 memcpy(ssid.SSID, req->essid, ssid.SSID_len);
1292 ssid.SSID_len = htod32(ssid.SSID_len);
1297 iscan->list_cur = iscan->list_hdr;
1298 iscan->iscan_state = ISCAN_STATE_SCANING;
1301 wl_iw_set_event_mask(dev);
1302 wl_iw_iscan(iscan, &ssid, WL_SCAN_ACTION_START);
1304 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
1305 add_timer(&iscan->timer);
1306 iscan->timer_on = 1;
1311 #if WIRELESS_EXT > 17
1313 ie_is_wpa_ie(uint8 **wpaie, uint8 **tlvs, int *tlvs_len)
1315 /* Is this body of this tlvs entry a WPA entry? If */
1316 /* not update the tlvs buffer pointer/length */
1319 /* If the contents match the WPA_OUI and type=1 */
1321 !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) {
1325 /* point to the next ie */
1327 /* calculate the length of the rest of the buffer */
1328 *tlvs_len -= (int)(ie - *tlvs);
1329 /* update the pointer to the start of the buffer */
1335 ie_is_wps_ie(uint8 **wpsie, uint8 **tlvs, int *tlvs_len)
1337 /* Is this body of this tlvs entry a WPS entry? If */
1338 /* not update the tlvs buffer pointer/length */
1341 /* If the contents match the WPA_OUI and type=4 */
1343 !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) {
1347 /* point to the next ie */
1349 /* calculate the length of the rest of the buffer */
1350 *tlvs_len -= (int)(ie - *tlvs);
1351 /* update the pointer to the start of the buffer */
1355 #endif /* WIRELESS_EXT > 17 */
1358 static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data,
1359 size_t len, int uppercase)
1362 char *pos = buf, *end = buf + buf_size;
1366 for (i = 0; i < len; i++) {
1367 ret = snprintf(pos, end - pos, uppercase ? "%02X" : "%02x",
1369 if (ret < 0 || ret >= end - pos) {
1380 * wpa_snprintf_hex - Print data as a hex string into a buffer
1381 * @buf: Memory area to use as the output buffer
1382 * @buf_size: Maximum buffer size in bytes (should be at least 2 * len + 1)
1383 * @data: Data to be printed
1384 * @len: Length of data in bytes
1385 * Returns: Number of bytes written
1388 wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len)
1390 return _wpa_snprintf_hex(buf, buf_size, data, len, 0);
1392 #endif /* BCMWAPI_WPI */
1395 wl_iw_handle_scanresults_ies(char **event_p, char *end,
1396 struct iw_request_info *info, wl_bss_info_t *bi)
1398 #if WIRELESS_EXT > 17
1399 struct iw_event iwe;
1403 int custom_event_len;
1407 if (bi->ie_length) {
1408 /* look for wpa/rsn ies in the ie list... */
1410 uint8 *ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
1411 int ptr_len = bi->ie_length;
1414 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_VS_ID)) &&
1415 ie->len > WFA_OUI_LEN + 1 &&
1416 !bcmp((const void *)&ie->data[0], (const void *)WFA_OUI, WFA_OUI_LEN) &&
1417 ie->data[WFA_OUI_LEN] == WFA_OUI_TYPE_OSEN) {
1418 iwe.cmd = IWEVGENIE;
1419 iwe.u.data.length = ie->len + 2;
1420 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1422 ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
1424 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_RSN_ID))) {
1425 iwe.cmd = IWEVGENIE;
1426 iwe.u.data.length = ie->len + 2;
1427 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1429 ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
1431 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_MDIE_ID))) {
1432 iwe.cmd = IWEVGENIE;
1433 iwe.u.data.length = ie->len + 2;
1434 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1436 ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
1438 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
1439 /* look for WPS IE */
1440 if (ie_is_wps_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
1441 iwe.cmd = IWEVGENIE;
1442 iwe.u.data.length = ie->len + 2;
1443 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1448 ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
1449 ptr_len = bi->ie_length;
1450 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
1451 if (ie_is_wpa_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
1452 iwe.cmd = IWEVGENIE;
1453 iwe.u.data.length = ie->len + 2;
1454 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1460 ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
1461 ptr_len = bi->ie_length;
1463 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WAPI_ID))) {
1464 WL_TRACE(("%s: found a WAPI IE...\n", __FUNCTION__));
1465 #ifdef WAPI_IE_USE_GENIE
1466 iwe.cmd = IWEVGENIE;
1467 iwe.u.data.length = ie->len + 2;
1468 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1469 #else /* using CUSTOM event */
1470 iwe.cmd = IWEVCUSTOM;
1471 custom_event_len = strlen("wapi_ie=") + 2*(ie->len + 2);
1472 iwe.u.data.length = custom_event_len;
1474 buf = kmalloc(custom_event_len+1, GFP_KERNEL);
1477 WL_ERROR(("malloc(%d) returned NULL...\n", custom_event_len));
1481 memcpy(buf, "wapi_ie=", 8);
1482 wpa_snprintf_hex(buf + 8, 2+1, &(ie->id), 1);
1483 wpa_snprintf_hex(buf + 10, 2+1, &(ie->len), 1);
1484 wpa_snprintf_hex(buf + 12, 2*ie->len+1, ie->data, ie->len);
1485 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, buf);
1487 #endif /* WAPI_IE_USE_GENIE */
1490 #endif /* BCMWAPI_WPI */
1494 #endif /* WIRELESS_EXT > 17 */
1499 struct net_device *dev,
1500 struct iw_request_info *info,
1501 struct iw_point *dwrq,
1506 wl_scan_results_t *list;
1507 struct iw_event iwe;
1508 wl_bss_info_t *bi = NULL;
1510 char *event = extra, *end = extra + dwrq->length, *value;
1511 uint buflen = dwrq->length;
1515 WL_TRACE(("%s: %s SIOCGIWSCAN\n", __FUNCTION__, dev->name));
1520 /* Check for scan in progress */
1521 if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
1523 ci.scan_channel = dtoh32(ci.scan_channel);
1524 if (ci.scan_channel)
1527 /* Get scan results (too large to put on the stack) */
1528 list = kmalloc(buflen, GFP_KERNEL);
1531 memset(list, 0, buflen);
1532 list->buflen = htod32(buflen);
1533 if ((error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen))) {
1537 list->buflen = dtoh32(list->buflen);
1538 list->version = dtoh32(list->version);
1539 list->count = dtoh32(list->count);
1541 ASSERT(list->version == WL_BSS_INFO_VERSION);
1543 for (i = 0; i < list->count && i < IW_MAX_AP; i++) {
1544 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1545 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1548 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1549 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1550 channel = (bi->ctl_ch == 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch;
1551 WL_SCAN(("%s: BSSID="MACSTR", channel=%d, RSSI=%d, merge broadcast SSID=\"%s\"\n",
1552 __FUNCTION__, MAC2STR(bi->BSSID.octet), channel, rssi, bi->SSID));
1554 /* First entry must be the BSSID */
1555 iwe.cmd = SIOCGIWAP;
1556 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1557 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1558 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
1561 iwe.u.data.length = dtoh32(bi->SSID_len);
1562 iwe.cmd = SIOCGIWESSID;
1563 iwe.u.data.flags = 1;
1564 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
1567 if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
1568 iwe.cmd = SIOCGIWMODE;
1569 if (dtoh16(bi->capability) & DOT11_CAP_ESS)
1570 iwe.u.mode = IW_MODE_INFRA;
1572 iwe.u.mode = IW_MODE_ADHOC;
1573 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
1577 iwe.cmd = SIOCGIWFREQ;
1578 iwe.u.freq.m = wf_channel2mhz(channel,
1579 (CHSPEC_IS2G(bi->chanspec)) ?
1580 WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G);
1582 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
1584 /* Channel quality */
1586 iwe.u.qual.qual = rssi_to_qual(rssi);
1587 iwe.u.qual.level = 0x100 + rssi;
1588 iwe.u.qual.noise = 0x100 + bi->phy_noise;
1589 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
1591 /* WPA, WPA2, WPS, WAPI IEs */
1592 wl_iw_handle_scanresults_ies(&event, end, info, bi);
1595 iwe.cmd = SIOCGIWENCODE;
1596 if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
1597 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1599 iwe.u.data.flags = IW_ENCODE_DISABLED;
1600 iwe.u.data.length = 0;
1601 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
1604 if (bi->rateset.count) {
1605 value = event + IW_EV_LCP_LEN;
1606 iwe.cmd = SIOCGIWRATE;
1607 /* Those two flags are ignored... */
1608 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1609 for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
1610 iwe.u.bitrate.value = (bi->rateset.rates[j] & 0x7f) * 500000;
1611 value = IWE_STREAM_ADD_VALUE(info, event, value, end, &iwe,
1620 dwrq->length = event - extra;
1621 dwrq->flags = 0; /* todo */
1627 wl_iw_iscan_get_scan(
1628 struct net_device *dev,
1629 struct iw_request_info *info,
1630 struct iw_point *dwrq,
1634 wl_scan_results_t *list;
1635 struct iw_event iwe;
1636 wl_bss_info_t *bi = NULL;
1639 char *event = extra, *end = extra + dwrq->length, *value;
1640 iscan_info_t *iscan = g_iscan;
1641 iscan_buf_t * p_buf;
1645 WL_TRACE(("%s: %s SIOCGIWSCAN\n", __FUNCTION__, dev->name));
1650 /* use backup if our thread is not successful */
1651 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1652 return wl_iw_get_scan(dev, info, dwrq, extra);
1655 /* Check for scan in progress */
1656 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1657 WL_TRACE(("%s: SIOCGIWSCAN GET still scanning\n", dev->name));
1662 p_buf = iscan->list_hdr;
1663 /* Get scan results */
1664 while (p_buf != iscan->list_cur) {
1665 list = &((wl_iscan_results_t*)p_buf->iscan_buf)->results;
1667 if (list->version != WL_BSS_INFO_VERSION) {
1668 WL_ERROR(("list->version %d != WL_BSS_INFO_VERSION\n", list->version));
1672 for (ii = 0; ii < list->count && apcnt < IW_MAX_AP; apcnt++, ii++) {
1673 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1674 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1675 WLC_IW_ISCAN_MAXLEN));
1677 /* overflow check cover fields before wpa IEs */
1678 if (event + ETHER_ADDR_LEN + bi->SSID_len + IW_EV_UINT_LEN + IW_EV_FREQ_LEN +
1679 IW_EV_QUAL_LEN >= end)
1682 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1683 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1684 channel = (bi->ctl_ch == 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch;
1685 WL_SCAN(("%s: BSSID="MACSTR", channel=%d, RSSI=%d, merge broadcast SSID=\"%s\"\n",
1686 __FUNCTION__, MAC2STR(bi->BSSID.octet), channel, rssi, bi->SSID));
1688 /* First entry must be the BSSID */
1689 iwe.cmd = SIOCGIWAP;
1690 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1691 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1692 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
1695 iwe.u.data.length = dtoh32(bi->SSID_len);
1696 iwe.cmd = SIOCGIWESSID;
1697 iwe.u.data.flags = 1;
1698 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
1701 if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
1702 iwe.cmd = SIOCGIWMODE;
1703 if (dtoh16(bi->capability) & DOT11_CAP_ESS)
1704 iwe.u.mode = IW_MODE_INFRA;
1706 iwe.u.mode = IW_MODE_ADHOC;
1707 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
1711 iwe.cmd = SIOCGIWFREQ;
1712 iwe.u.freq.m = wf_channel2mhz(channel,
1713 (CHSPEC_IS2G(bi->chanspec)) ?
1714 WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G);
1716 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
1718 /* Channel quality */
1720 iwe.u.qual.qual = rssi_to_qual(rssi);
1721 iwe.u.qual.level = 0x100 + rssi;
1722 iwe.u.qual.noise = 0x100 + bi->phy_noise;
1723 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
1725 /* WPA, WPA2, WPS, WAPI IEs */
1726 wl_iw_handle_scanresults_ies(&event, end, info, bi);
1729 iwe.cmd = SIOCGIWENCODE;
1730 if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
1731 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1733 iwe.u.data.flags = IW_ENCODE_DISABLED;
1734 iwe.u.data.length = 0;
1735 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
1738 if (bi->rateset.count <= sizeof(bi->rateset.rates)) {
1739 if (event + IW_MAX_BITRATES*IW_EV_PARAM_LEN >= end)
1742 value = event + IW_EV_LCP_LEN;
1743 iwe.cmd = SIOCGIWRATE;
1744 /* Those two flags are ignored... */
1745 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1746 for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
1747 iwe.u.bitrate.value = (bi->rateset.rates[j] & 0x7f) * 500000;
1748 value = IWE_STREAM_ADD_VALUE(info, event, value, end, &iwe,
1754 p_buf = p_buf->next;
1755 } /* while (p_buf) */
1757 dwrq->length = event - extra;
1758 dwrq->flags = 0; /* todo */
1763 #endif /* WIRELESS_EXT > 13 */
1768 struct net_device *dev,
1769 struct iw_request_info *info,
1770 struct iw_point *dwrq,
1777 WL_TRACE(("%s: SIOCSIWESSID\n", dev->name));
1779 /* default Broadcast SSID */
1780 memset(&ssid, 0, sizeof(ssid));
1781 if (dwrq->length && extra) {
1782 #if WIRELESS_EXT > 20
1783 ssid.SSID_len = MIN(sizeof(ssid.SSID), dwrq->length);
1785 ssid.SSID_len = MIN(sizeof(ssid.SSID), dwrq->length-1);
1787 memcpy(ssid.SSID, extra, ssid.SSID_len);
1788 ssid.SSID_len = htod32(ssid.SSID_len);
1790 if ((error = dev_wlc_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid)))) {
1791 WL_ERROR(("%s: WLC_SET_SSID failed (%d).\n", __FUNCTION__, error));
1794 WL_ERROR(("%s: join SSID=%s\n", __FUNCTION__, ssid.SSID));
1796 /* If essid null then it is "iwconfig <interface> essid off" command */
1799 bzero(&scbval, sizeof(scb_val_t));
1800 WL_ERROR(("%s: WLC_DISASSOC\n", __FUNCTION__));
1801 if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
1802 WL_ERROR(("%s: WLC_DISASSOC failed (%d).\n", __FUNCTION__, error));
1811 struct net_device *dev,
1812 struct iw_request_info *info,
1813 struct iw_point *dwrq,
1820 WL_TRACE(("%s: SIOCGIWESSID\n", dev->name));
1825 if ((error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid)))) {
1826 WL_ERROR(("Error getting the SSID\n"));
1830 ssid.SSID_len = dtoh32(ssid.SSID_len);
1832 /* Get the current SSID */
1833 memcpy(extra, ssid.SSID, ssid.SSID_len);
1835 dwrq->length = ssid.SSID_len;
1837 dwrq->flags = 1; /* active */
1844 struct net_device *dev,
1845 struct iw_request_info *info,
1846 struct iw_point *dwrq,
1850 wl_iw_t *iw = IW_DEV_IF(dev);
1851 WL_TRACE(("%s: SIOCSIWNICKN\n", dev->name));
1856 /* Check the size of the string */
1857 if (dwrq->length > sizeof(iw->nickname))
1860 memcpy(iw->nickname, extra, dwrq->length);
1861 iw->nickname[dwrq->length - 1] = '\0';
1868 struct net_device *dev,
1869 struct iw_request_info *info,
1870 struct iw_point *dwrq,
1874 wl_iw_t *iw = IW_DEV_IF(dev);
1875 WL_TRACE(("%s: SIOCGIWNICKN\n", dev->name));
1880 strcpy(extra, iw->nickname);
1881 dwrq->length = strlen(extra) + 1;
1886 static int wl_iw_set_rate(
1887 struct net_device *dev,
1888 struct iw_request_info *info,
1889 struct iw_param *vwrq,
1893 wl_rateset_t rateset;
1894 int error, rate, i, error_bg, error_a;
1896 WL_TRACE(("%s: SIOCSIWRATE\n", dev->name));
1898 /* Get current rateset */
1899 if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
1902 rateset.count = dtoh32(rateset.count);
1904 if (vwrq->value < 0) {
1905 /* Select maximum rate */
1906 rate = rateset.rates[rateset.count - 1] & 0x7f;
1907 } else if (vwrq->value < rateset.count) {
1908 /* Select rate by rateset index */
1909 rate = rateset.rates[vwrq->value] & 0x7f;
1911 /* Specified rate in bps */
1912 rate = vwrq->value / 500000;
1918 Since the is a/b/g-blind, both a/bg_rate are enforced.
1920 error_bg = dev_wlc_intvar_set(dev, "bg_rate", rate);
1921 error_a = dev_wlc_intvar_set(dev, "a_rate", rate);
1923 if (error_bg && error_a)
1924 return (error_bg | error_a);
1928 Since the is a/b/g-blind, both a/bg_rate are enforced.
1930 /* 0 is for clearing rate override */
1931 error_bg = dev_wlc_intvar_set(dev, "bg_rate", 0);
1932 /* 0 is for clearing rate override */
1933 error_a = dev_wlc_intvar_set(dev, "a_rate", 0);
1935 if (error_bg && error_a)
1936 return (error_bg | error_a);
1938 /* Remove rates above selected rate */
1939 for (i = 0; i < rateset.count; i++)
1940 if ((rateset.rates[i] & 0x7f) > rate)
1942 rateset.count = htod32(i);
1944 /* Set current rateset */
1945 if ((error = dev_wlc_ioctl(dev, WLC_SET_RATESET, &rateset, sizeof(rateset))))
1952 static int wl_iw_get_rate(
1953 struct net_device *dev,
1954 struct iw_request_info *info,
1955 struct iw_param *vwrq,
1961 WL_TRACE(("%s: SIOCGIWRATE\n", dev->name));
1963 /* Report the current tx rate */
1964 if ((error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate))))
1966 rate = dtoh32(rate);
1967 vwrq->value = rate * 500000;
1974 struct net_device *dev,
1975 struct iw_request_info *info,
1976 struct iw_param *vwrq,
1982 WL_TRACE(("%s: SIOCSIWRTS\n", dev->name));
1985 rts = DOT11_DEFAULT_RTS_LEN;
1986 else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_RTS_LEN)
1991 if ((error = dev_wlc_intvar_set(dev, "rtsthresh", rts)))
1999 struct net_device *dev,
2000 struct iw_request_info *info,
2001 struct iw_param *vwrq,
2007 WL_TRACE(("%s: SIOCGIWRTS\n", dev->name));
2009 if ((error = dev_wlc_intvar_get(dev, "rtsthresh", &rts)))
2013 vwrq->disabled = (rts >= DOT11_DEFAULT_RTS_LEN);
2021 struct net_device *dev,
2022 struct iw_request_info *info,
2023 struct iw_param *vwrq,
2029 WL_TRACE(("%s: SIOCSIWFRAG\n", dev->name));
2032 frag = DOT11_DEFAULT_FRAG_LEN;
2033 else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_FRAG_LEN)
2038 if ((error = dev_wlc_intvar_set(dev, "fragthresh", frag)))
2046 struct net_device *dev,
2047 struct iw_request_info *info,
2048 struct iw_param *vwrq,
2052 int error, fragthreshold;
2054 WL_TRACE(("%s: SIOCGIWFRAG\n", dev->name));
2056 if ((error = dev_wlc_intvar_get(dev, "fragthresh", &fragthreshold)))
2059 vwrq->value = fragthreshold;
2060 vwrq->disabled = (fragthreshold >= DOT11_DEFAULT_FRAG_LEN);
2068 struct net_device *dev,
2069 struct iw_request_info *info,
2070 struct iw_param *vwrq,
2076 WL_TRACE(("%s: SIOCSIWTXPOW\n", dev->name));
2078 /* Make sure radio is off or on as far as software is concerned */
2079 disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0;
2080 disable += WL_RADIO_SW_DISABLE << 16;
2082 disable = htod32(disable);
2083 if ((error = dev_wlc_ioctl(dev, WLC_SET_RADIO, &disable, sizeof(disable))))
2086 /* If Radio is off, nothing more to do */
2087 if (disable & WL_RADIO_SW_DISABLE)
2090 /* Only handle mW */
2091 if (!(vwrq->flags & IW_TXPOW_MWATT))
2094 /* Value < 0 means just "on" or "off" */
2095 if (vwrq->value < 0)
2098 if (vwrq->value > 0xffff) txpwrmw = 0xffff;
2099 else txpwrmw = (uint16)vwrq->value;
2102 error = dev_wlc_intvar_set(dev, "qtxpower", (int)(bcm_mw_to_qdbm(txpwrmw)));
2108 struct net_device *dev,
2109 struct iw_request_info *info,
2110 struct iw_param *vwrq,
2114 int error, disable, txpwrdbm;
2117 WL_TRACE(("%s: SIOCGIWTXPOW\n", dev->name));
2119 if ((error = dev_wlc_ioctl(dev, WLC_GET_RADIO, &disable, sizeof(disable))) ||
2120 (error = dev_wlc_intvar_get(dev, "qtxpower", &txpwrdbm)))
2123 disable = dtoh32(disable);
2124 result = (uint8)(txpwrdbm & ~WL_TXPWR_OVERRIDE);
2125 vwrq->value = (int32)bcm_qdbm_to_mw(result);
2127 vwrq->disabled = (disable & (WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE)) ? 1 : 0;
2128 vwrq->flags = IW_TXPOW_MWATT;
2133 #if WIRELESS_EXT > 10
2136 struct net_device *dev,
2137 struct iw_request_info *info,
2138 struct iw_param *vwrq,
2142 int error, lrl, srl;
2144 WL_TRACE(("%s: SIOCSIWRETRY\n", dev->name));
2146 /* Do not handle "off" or "lifetime" */
2147 if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME))
2150 /* Handle "[min|max] limit" */
2151 if (vwrq->flags & IW_RETRY_LIMIT) {
2152 /* "max limit" or just "limit" */
2153 #if WIRELESS_EXT > 20
2154 if ((vwrq->flags & IW_RETRY_LONG) ||(vwrq->flags & IW_RETRY_MAX) ||
2155 !((vwrq->flags & IW_RETRY_SHORT) || (vwrq->flags & IW_RETRY_MIN)))
2157 if ((vwrq->flags & IW_RETRY_MAX) || !(vwrq->flags & IW_RETRY_MIN))
2158 #endif /* WIRELESS_EXT > 20 */
2160 lrl = htod32(vwrq->value);
2161 if ((error = dev_wlc_ioctl(dev, WLC_SET_LRL, &lrl, sizeof(lrl))))
2164 /* "min limit" or just "limit" */
2165 #if WIRELESS_EXT > 20
2166 if ((vwrq->flags & IW_RETRY_SHORT) ||(vwrq->flags & IW_RETRY_MIN) ||
2167 !((vwrq->flags & IW_RETRY_LONG) || (vwrq->flags & IW_RETRY_MAX)))
2169 if ((vwrq->flags & IW_RETRY_MIN) || !(vwrq->flags & IW_RETRY_MAX))
2170 #endif /* WIRELESS_EXT > 20 */
2172 srl = htod32(vwrq->value);
2173 if ((error = dev_wlc_ioctl(dev, WLC_SET_SRL, &srl, sizeof(srl))))
2183 struct net_device *dev,
2184 struct iw_request_info *info,
2185 struct iw_param *vwrq,
2189 int error, lrl, srl;
2191 WL_TRACE(("%s: SIOCGIWRETRY\n", dev->name));
2193 vwrq->disabled = 0; /* Can't be disabled */
2195 /* Do not handle lifetime queries */
2196 if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
2199 /* Get retry limits */
2200 if ((error = dev_wlc_ioctl(dev, WLC_GET_LRL, &lrl, sizeof(lrl))) ||
2201 (error = dev_wlc_ioctl(dev, WLC_GET_SRL, &srl, sizeof(srl))))
2207 /* Note : by default, display the min retry number */
2208 if (vwrq->flags & IW_RETRY_MAX) {
2209 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
2212 vwrq->flags = IW_RETRY_LIMIT;
2215 vwrq->flags |= IW_RETRY_MIN;
2220 #endif /* WIRELESS_EXT > 10 */
2224 struct net_device *dev,
2225 struct iw_request_info *info,
2226 struct iw_point *dwrq,
2231 int error, val, wsec;
2233 WL_TRACE(("%s: SIOCSIWENCODE\n", dev->name));
2235 memset(&key, 0, sizeof(key));
2237 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2238 /* Find the current key */
2239 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
2240 val = htod32(key.index);
2241 if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
2248 if (key.index == DOT11_MAX_DEFAULT_KEYS)
2251 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2252 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
2256 /* Interpret "off" to mean no encryption */
2257 wsec = (dwrq->flags & IW_ENCODE_DISABLED) ? 0 : WEP_ENABLED;
2259 if ((error = dev_wlc_intvar_set(dev, "wsec", wsec)))
2262 /* Old API used to pass a NULL pointer instead of IW_ENCODE_NOKEY */
2263 if (!extra || !dwrq->length || (dwrq->flags & IW_ENCODE_NOKEY)) {
2264 /* Just select a new current key */
2265 val = htod32(key.index);
2266 if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, &val, sizeof(val))))
2269 key.len = dwrq->length;
2271 if (dwrq->length > sizeof(key.data))
2274 memcpy(key.data, extra, dwrq->length);
2276 key.flags = WL_PRIMARY_KEY;
2279 key.algo = CRYPTO_ALGO_WEP1;
2281 case WEP128_KEY_SIZE:
2282 key.algo = CRYPTO_ALGO_WEP128;
2284 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
2286 key.algo = CRYPTO_ALGO_TKIP;
2290 key.algo = CRYPTO_ALGO_AES_CCM;
2296 /* Set the new key/index */
2297 swap_key_from_BE(&key);
2298 if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key))))
2302 /* Interpret "restricted" to mean shared key authentication */
2303 val = (dwrq->flags & IW_ENCODE_RESTRICTED) ? 1 : 0;
2305 if ((error = dev_wlc_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val))))
2313 struct net_device *dev,
2314 struct iw_request_info *info,
2315 struct iw_point *dwrq,
2320 int error, val, wsec, auth;
2322 WL_TRACE(("%s: SIOCGIWENCODE\n", dev->name));
2324 /* assure default values of zero for things we don't touch */
2325 bzero(&key, sizeof(wl_wsec_key_t));
2327 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2328 /* Find the current key */
2329 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
2331 if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
2338 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2340 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
2345 if ((error = dev_wlc_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec))) ||
2346 (error = dev_wlc_ioctl(dev, WLC_GET_AUTH, &auth, sizeof(auth))))
2349 swap_key_to_BE(&key);
2351 wsec = dtoh32(wsec);
2352 auth = dtoh32(auth);
2353 /* Get key length */
2354 dwrq->length = MIN(IW_ENCODING_TOKEN_MAX, key.len);
2357 dwrq->flags = key.index + 1;
2358 if (!(wsec & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))) {
2359 /* Interpret "off" to mean no encryption */
2360 dwrq->flags |= IW_ENCODE_DISABLED;
2363 /* Interpret "restricted" to mean shared key authentication */
2364 dwrq->flags |= IW_ENCODE_RESTRICTED;
2368 if (dwrq->length && extra)
2369 memcpy(extra, key.data, dwrq->length);
2376 struct net_device *dev,
2377 struct iw_request_info *info,
2378 struct iw_param *vwrq,
2384 WL_TRACE(("%s: SIOCSIWPOWER\n", dev->name));
2386 pm = vwrq->disabled ? PM_OFF : PM_MAX;
2389 if ((error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm))))
2397 struct net_device *dev,
2398 struct iw_request_info *info,
2399 struct iw_param *vwrq,
2405 WL_TRACE(("%s: SIOCGIWPOWER\n", dev->name));
2407 if ((error = dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm))))
2411 vwrq->disabled = pm ? 0 : 1;
2412 vwrq->flags = IW_POWER_ALL_R;
2417 #if WIRELESS_EXT > 17
2420 struct net_device *dev,
2421 struct iw_request_info *info,
2422 struct iw_point *iwp,
2426 #if defined(BCMWAPI_WPI)
2427 uchar buf[WLC_IOCTL_SMLEN] = {0};
2431 WL_TRACE(("%s: SIOCSIWGENIE\n", dev->name));
2433 if (extra[0] == DOT11_MNG_WAPI_ID)
2435 wapi_ie_size = iwp->length;
2436 memcpy(p, extra, iwp->length);
2437 dev_wlc_bufvar_set(dev, "wapiie", buf, wapi_ie_size);
2441 dev_wlc_bufvar_set(dev, "wpaie", extra, iwp->length);
2448 struct net_device *dev,
2449 struct iw_request_info *info,
2450 struct iw_point *iwp,
2454 WL_TRACE(("%s: SIOCGIWGENIE\n", dev->name));
2456 dev_wlc_bufvar_get(dev, "wpaie", extra, iwp->length);
2461 wl_iw_set_encodeext(
2462 struct net_device *dev,
2463 struct iw_request_info *info,
2464 struct iw_point *dwrq,
2470 struct iw_encode_ext *iwe;
2472 WL_TRACE(("%s: SIOCSIWENCODEEXT\n", dev->name));
2474 memset(&key, 0, sizeof(key));
2475 iwe = (struct iw_encode_ext *)extra;
2477 /* disable encryption completely */
2478 if (dwrq->flags & IW_ENCODE_DISABLED) {
2482 /* get the key index */
2484 if (dwrq->flags & IW_ENCODE_INDEX)
2485 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2487 key.len = iwe->key_len;
2489 /* Instead of bcast for ea address for default wep keys, driver needs it to be Null */
2490 if (!ETHER_ISMULTI(iwe->addr.sa_data))
2491 bcopy((void *)&iwe->addr.sa_data, (char *)&key.ea, ETHER_ADDR_LEN);
2493 /* check for key index change */
2495 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2496 WL_WSEC(("Changing the the primary Key to %d\n", key.index));
2497 /* change the key index .... */
2498 key.index = htod32(key.index);
2499 error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY,
2500 &key.index, sizeof(key.index));
2506 swap_key_from_BE(&key);
2507 error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2512 /* This case is used to allow an external 802.1x supplicant
2513 * to pass the PMK to the in-driver supplicant for use in
2514 * the 4-way handshake.
2516 else if (iwe->alg == IW_ENCODE_ALG_PMK) {
2519 char keystring[WSEC_MAX_PSK_LEN + 1];
2520 char* charptr = keystring;
2523 /* copy the raw hex key to the appropriate format */
2524 for (j = 0; j < (WSEC_MAX_PSK_LEN / 2); j++) {
2525 sprintf(charptr, "%02x", iwe->key[j]);
2528 len = strlen(keystring);
2529 pmk.key_len = htod16(len);
2530 bcopy(keystring, pmk.key, len);
2531 pmk.flags = htod16(WSEC_PASSPHRASE);
2533 error = dev_wlc_ioctl(dev, WLC_SET_WSEC_PMK, &pmk, sizeof(pmk));
2539 if (iwe->key_len > sizeof(key.data))
2542 WL_WSEC(("Setting the key index %d\n", key.index));
2543 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2544 WL_WSEC(("key is a Primary Key\n"));
2545 key.flags = WL_PRIMARY_KEY;
2548 bcopy((void *)iwe->key, key.data, iwe->key_len);
2550 if (iwe->alg == IW_ENCODE_ALG_TKIP) {
2552 bcopy(&key.data[24], keybuf, sizeof(keybuf));
2553 bcopy(&key.data[16], &key.data[24], sizeof(keybuf));
2554 bcopy(keybuf, &key.data[16], sizeof(keybuf));
2558 if (iwe->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
2560 ivptr = (uchar *)iwe->rx_seq;
2561 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
2562 (ivptr[3] << 8) | ivptr[2];
2563 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
2564 key.iv_initialized = TRUE;
2568 case IW_ENCODE_ALG_NONE:
2569 key.algo = CRYPTO_ALGO_OFF;
2571 case IW_ENCODE_ALG_WEP:
2572 if (iwe->key_len == WEP1_KEY_SIZE)
2573 key.algo = CRYPTO_ALGO_WEP1;
2575 key.algo = CRYPTO_ALGO_WEP128;
2577 case IW_ENCODE_ALG_TKIP:
2578 key.algo = CRYPTO_ALGO_TKIP;
2580 case IW_ENCODE_ALG_CCMP:
2581 key.algo = CRYPTO_ALGO_AES_CCM;
2584 case IW_ENCODE_ALG_SM4:
2585 key.algo = CRYPTO_ALGO_SMS4;
2586 if (iwe->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
2587 key.flags &= ~WL_PRIMARY_KEY;
2594 swap_key_from_BE(&key);
2596 dhd_wait_pend8021x(dev);
2598 error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2606 #if WIRELESS_EXT > 17
2608 pmkid_list_t pmkids;
2609 pmkid_t foo[MAXPMKID-1];
2613 struct net_device *dev,
2614 struct iw_request_info *info,
2615 struct iw_param *vwrq,
2619 struct iw_pmksa *iwpmksa;
2621 char eabuf[ETHER_ADDR_STR_LEN];
2622 pmkid_t * pmkid_array = pmkid_list.pmkids.pmkid;
2624 WL_TRACE(("%s: SIOCSIWPMKSA\n", dev->name));
2625 iwpmksa = (struct iw_pmksa *)extra;
2626 bzero((char *)eabuf, ETHER_ADDR_STR_LEN);
2627 if (iwpmksa->cmd == IW_PMKSA_FLUSH) {
2628 WL_TRACE(("wl_iw_set_pmksa - IW_PMKSA_FLUSH\n"));
2629 bzero((char *)&pmkid_list, sizeof(pmkid_list));
2631 if (iwpmksa->cmd == IW_PMKSA_REMOVE) {
2632 pmkid_list_t pmkid, *pmkidptr;
2634 bcopy(&iwpmksa->bssid.sa_data[0], &pmkidptr->pmkid[0].BSSID, ETHER_ADDR_LEN);
2635 bcopy(&iwpmksa->pmkid[0], &pmkidptr->pmkid[0].PMKID, WPA2_PMKID_LEN);
2638 WL_TRACE(("wl_iw_set_pmksa,IW_PMKSA_REMOVE - PMKID: %s = ",
2639 bcm_ether_ntoa(&pmkidptr->pmkid[0].BSSID,
2641 for (j = 0; j < WPA2_PMKID_LEN; j++)
2642 WL_TRACE(("%02x ", pmkidptr->pmkid[0].PMKID[j]));
2645 for (i = 0; i < pmkid_list.pmkids.npmkid; i++)
2646 if (!bcmp(&iwpmksa->bssid.sa_data[0], &pmkid_array[i].BSSID,
2649 for (; i < pmkid_list.pmkids.npmkid; i++) {
2650 bcopy(&pmkid_array[i+1].BSSID,
2651 &pmkid_array[i].BSSID,
2653 bcopy(&pmkid_array[i+1].PMKID,
2654 &pmkid_array[i].PMKID,
2657 pmkid_list.pmkids.npmkid--;
2659 if (iwpmksa->cmd == IW_PMKSA_ADD) {
2660 bcopy(&iwpmksa->bssid.sa_data[0],
2661 &pmkid_array[pmkid_list.pmkids.npmkid].BSSID,
2663 bcopy(&iwpmksa->pmkid[0], &pmkid_array[pmkid_list.pmkids.npmkid].PMKID,
2668 k = pmkid_list.pmkids.npmkid;
2670 WL_TRACE(("wl_iw_set_pmksa,IW_PMKSA_ADD - PMKID: %s = ",
2671 bcm_ether_ntoa(&pmkid_array[k].BSSID,
2673 for (j = 0; j < WPA2_PMKID_LEN; j++)
2674 WL_TRACE(("%02x ", pmkid_array[k].PMKID[j]));
2677 pmkid_list.pmkids.npmkid++;
2679 WL_TRACE(("PRINTING pmkid LIST - No of elements %d\n", pmkid_list.pmkids.npmkid));
2680 for (i = 0; i < pmkid_list.pmkids.npmkid; i++) {
2682 WL_TRACE(("PMKID[%d]: %s = ", i,
2683 bcm_ether_ntoa(&pmkid_array[i].BSSID,
2685 for (j = 0; j < WPA2_PMKID_LEN; j++)
2686 WL_TRACE(("%02x ", pmkid_array[i].PMKID[j]));
2690 dev_wlc_bufvar_set(dev, "pmkid_info", (char *)&pmkid_list, sizeof(pmkid_list));
2693 #endif /* WIRELESS_EXT > 17 */
2696 wl_iw_get_encodeext(
2697 struct net_device *dev,
2698 struct iw_request_info *info,
2699 struct iw_param *vwrq,
2703 WL_TRACE(("%s: SIOCGIWENCODEEXT\n", dev->name));
2709 struct net_device *dev,
2710 struct iw_request_info *info,
2711 struct iw_param *vwrq,
2718 uint32 cipher_combined;
2720 wl_iw_t *iw = IW_DEV_IF(dev);
2722 WL_TRACE(("%s: SIOCSIWAUTH\n", dev->name));
2724 paramid = vwrq->flags & IW_AUTH_INDEX;
2725 paramval = vwrq->value;
2727 WL_TRACE(("%s: SIOCSIWAUTH, paramid = 0x%0x, paramval = 0x%0x\n",
2728 dev->name, paramid, paramval));
2732 case IW_AUTH_WPA_VERSION:
2733 /* supported wpa version disabled or wpa or wpa2 */
2734 if (paramval & IW_AUTH_WPA_VERSION_DISABLED)
2735 val = WPA_AUTH_DISABLED;
2736 else if (paramval & (IW_AUTH_WPA_VERSION_WPA))
2737 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
2738 else if (paramval & IW_AUTH_WPA_VERSION_WPA2)
2739 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
2741 else if (paramval & IW_AUTH_WAPI_VERSION_1)
2742 val = WAPI_AUTH_UNSPECIFIED;
2744 WL_TRACE(("%s: %d: setting wpa_auth to 0x%0x\n", __FUNCTION__, __LINE__, val));
2745 if ((error = dev_wlc_intvar_set(dev, "wpa_auth", val)))
2749 case IW_AUTH_CIPHER_PAIRWISE:
2750 case IW_AUTH_CIPHER_GROUP: {
2753 if (paramid == IW_AUTH_CIPHER_PAIRWISE) {
2754 iw->pwsec = paramval;
2757 iw->gwsec = paramval;
2760 if ((error = dev_wlc_intvar_get(dev, "wsec", &val)))
2763 cipher_combined = iw->gwsec | iw->pwsec;
2764 val &= ~(WEP_ENABLED | TKIP_ENABLED | AES_ENABLED);
2765 if (cipher_combined & (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
2767 if (cipher_combined & IW_AUTH_CIPHER_TKIP)
2768 val |= TKIP_ENABLED;
2769 if (cipher_combined & IW_AUTH_CIPHER_CCMP)
2772 val &= ~SMS4_ENABLED;
2773 if (cipher_combined & IW_AUTH_CIPHER_SMS4)
2774 val |= SMS4_ENABLED;
2777 if (iw->privacy_invoked && !val) {
2778 WL_WSEC(("%s: %s: 'Privacy invoked' TRUE but clearing wsec, assuming "
2779 "we're a WPS enrollee\n", dev->name, __FUNCTION__));
2780 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", TRUE))) {
2781 WL_WSEC(("Failed to set iovar is_WPS_enrollee\n"));
2785 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
2786 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
2791 if ((error = dev_wlc_intvar_set(dev, "wsec", val)))
2794 /* Ensure in-dongle supplicant is turned on when FBT wants to do the 4-way
2797 if (dev_wlc_intvar_get(dev, "fbt_cap", &fbt_cap) == 0) {
2798 if (fbt_cap == WLC_FBT_CAP_DRV_4WAY_AND_REASSOC) {
2799 if ((paramid == IW_AUTH_CIPHER_PAIRWISE) && (val & AES_ENABLED)) {
2800 if ((error = dev_wlc_intvar_set(dev, "sup_wpa", 1)))
2803 else if (val == 0) {
2804 if ((error = dev_wlc_intvar_set(dev, "sup_wpa", 0)))
2812 case IW_AUTH_KEY_MGMT:
2813 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
2816 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
2817 if (paramval & (IW_AUTH_KEY_MGMT_FT_PSK | IW_AUTH_KEY_MGMT_PSK))
2820 val = WPA_AUTH_UNSPECIFIED;
2821 if (paramval & (IW_AUTH_KEY_MGMT_FT_802_1X | IW_AUTH_KEY_MGMT_FT_PSK))
2822 val |= WPA2_AUTH_FT;
2824 else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
2825 if (paramval & (IW_AUTH_KEY_MGMT_FT_PSK | IW_AUTH_KEY_MGMT_PSK))
2826 val = WPA2_AUTH_PSK;
2828 val = WPA2_AUTH_UNSPECIFIED;
2829 if (paramval & (IW_AUTH_KEY_MGMT_FT_802_1X | IW_AUTH_KEY_MGMT_FT_PSK))
2830 val |= WPA2_AUTH_FT;
2833 if (paramval & (IW_AUTH_KEY_MGMT_WAPI_PSK | IW_AUTH_KEY_MGMT_WAPI_CERT))
2834 val = WAPI_AUTH_UNSPECIFIED;
2836 WL_TRACE(("%s: %d: setting wpa_auth to %d\n", __FUNCTION__, __LINE__, val));
2837 if ((error = dev_wlc_intvar_set(dev, "wpa_auth", val)))
2841 case IW_AUTH_TKIP_COUNTERMEASURES:
2842 dev_wlc_bufvar_set(dev, "tkip_countermeasures", (char *)¶mval, 1);
2845 case IW_AUTH_80211_AUTH_ALG:
2847 WL_ERROR(("Setting the D11auth %d\n", paramval));
2848 if (paramval & IW_AUTH_ALG_OPEN_SYSTEM)
2850 else if (paramval & IW_AUTH_ALG_SHARED_KEY)
2854 if (!error && (error = dev_wlc_intvar_set(dev, "auth", val)))
2858 case IW_AUTH_WPA_ENABLED:
2859 if (paramval == 0) {
2861 WL_TRACE(("%s: %d: setting wpa_auth to %d\n", __FUNCTION__, __LINE__, val));
2862 error = dev_wlc_intvar_set(dev, "wpa_auth", val);
2866 /* If WPA is enabled, wpa_auth is set elsewhere */
2870 case IW_AUTH_DROP_UNENCRYPTED:
2871 dev_wlc_bufvar_set(dev, "wsec_restrict", (char *)¶mval, 1);
2874 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2875 dev_wlc_bufvar_set(dev, "rx_unencrypted_eapol", (char *)¶mval, 1);
2878 #if WIRELESS_EXT > 17
2880 case IW_AUTH_ROAMING_CONTROL:
2881 WL_TRACE(("%s: IW_AUTH_ROAMING_CONTROL\n", __FUNCTION__));
2882 /* driver control or user space app control */
2885 case IW_AUTH_PRIVACY_INVOKED: {
2888 if (paramval == 0) {
2889 iw->privacy_invoked = FALSE;
2890 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
2891 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
2895 iw->privacy_invoked = TRUE;
2896 if ((error = dev_wlc_intvar_get(dev, "wsec", &wsec)))
2899 if (!WSEC_ENABLED(wsec)) {
2900 /* if privacy is true, but wsec is false, we are a WPS enrollee */
2901 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", TRUE))) {
2902 WL_WSEC(("Failed to set iovar is_WPS_enrollee\n"));
2906 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
2907 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
2916 #endif /* WIRELESS_EXT > 17 */
2920 case IW_AUTH_WAPI_ENABLED:
2921 if ((error = dev_wlc_intvar_get(dev, "wsec", &val)))
2924 val |= SMS4_ENABLED;
2925 if ((error = dev_wlc_intvar_set(dev, "wsec", val))) {
2926 WL_ERROR(("%s: setting wsec to 0x%0x returned error %d\n",
2927 __FUNCTION__, val, error));
2930 if ((error = dev_wlc_intvar_set(dev, "wpa_auth", WAPI_AUTH_UNSPECIFIED))) {
2931 WL_ERROR(("%s: setting wpa_auth(%d) returned %d\n",
2932 __FUNCTION__, WAPI_AUTH_UNSPECIFIED,
2940 #endif /* BCMWAPI_WPI */
2947 #define VAL_PSK(_val) (((_val) & WPA_AUTH_PSK) || ((_val) & WPA2_AUTH_PSK))
2951 struct net_device *dev,
2952 struct iw_request_info *info,
2953 struct iw_param *vwrq,
2961 wl_iw_t *iw = IW_DEV_IF(dev);
2963 WL_TRACE(("%s: SIOCGIWAUTH\n", dev->name));
2965 paramid = vwrq->flags & IW_AUTH_INDEX;
2968 case IW_AUTH_WPA_VERSION:
2969 /* supported wpa version disabled or wpa or wpa2 */
2970 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
2972 if (val & (WPA_AUTH_NONE | WPA_AUTH_DISABLED))
2973 paramval = IW_AUTH_WPA_VERSION_DISABLED;
2974 else if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED))
2975 paramval = IW_AUTH_WPA_VERSION_WPA;
2976 else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED))
2977 paramval = IW_AUTH_WPA_VERSION_WPA2;
2980 case IW_AUTH_CIPHER_PAIRWISE:
2981 paramval = iw->pwsec;
2984 case IW_AUTH_CIPHER_GROUP:
2985 paramval = iw->gwsec;
2988 case IW_AUTH_KEY_MGMT:
2990 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
2993 paramval = IW_AUTH_KEY_MGMT_PSK;
2995 paramval = IW_AUTH_KEY_MGMT_802_1X;
2998 case IW_AUTH_TKIP_COUNTERMEASURES:
2999 dev_wlc_bufvar_get(dev, "tkip_countermeasures", (char *)¶mval, 1);
3002 case IW_AUTH_DROP_UNENCRYPTED:
3003 dev_wlc_bufvar_get(dev, "wsec_restrict", (char *)¶mval, 1);
3006 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3007 dev_wlc_bufvar_get(dev, "rx_unencrypted_eapol", (char *)¶mval, 1);
3010 case IW_AUTH_80211_AUTH_ALG:
3011 /* open, shared, leap */
3012 if ((error = dev_wlc_intvar_get(dev, "auth", &val)))
3015 paramval = IW_AUTH_ALG_OPEN_SYSTEM;
3017 paramval = IW_AUTH_ALG_SHARED_KEY;
3019 case IW_AUTH_WPA_ENABLED:
3020 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
3028 #if WIRELESS_EXT > 17
3030 case IW_AUTH_ROAMING_CONTROL:
3031 WL_ERROR(("%s: IW_AUTH_ROAMING_CONTROL\n", __FUNCTION__));
3032 /* driver control or user space app control */
3035 case IW_AUTH_PRIVACY_INVOKED:
3036 paramval = iw->privacy_invoked;
3039 #endif /* WIRELESS_EXT > 17 */
3041 vwrq->value = paramval;
3044 #endif /* WIRELESS_EXT > 17 */
3046 static const iw_handler wl_iw_handler[] =
3048 (iw_handler) wl_iw_config_commit, /* SIOCSIWCOMMIT */
3049 (iw_handler) wl_iw_get_name, /* SIOCGIWNAME */
3050 (iw_handler) NULL, /* SIOCSIWNWID */
3051 (iw_handler) NULL, /* SIOCGIWNWID */
3052 (iw_handler) wl_iw_set_freq, /* SIOCSIWFREQ */
3053 (iw_handler) wl_iw_get_freq, /* SIOCGIWFREQ */
3054 (iw_handler) wl_iw_set_mode, /* SIOCSIWMODE */
3055 (iw_handler) wl_iw_get_mode, /* SIOCGIWMODE */
3056 (iw_handler) NULL, /* SIOCSIWSENS */
3057 (iw_handler) NULL, /* SIOCGIWSENS */
3058 (iw_handler) NULL, /* SIOCSIWRANGE */
3059 (iw_handler) wl_iw_get_range, /* SIOCGIWRANGE */
3060 (iw_handler) NULL, /* SIOCSIWPRIV */
3061 (iw_handler) NULL, /* SIOCGIWPRIV */
3062 (iw_handler) NULL, /* SIOCSIWSTATS */
3063 (iw_handler) NULL, /* SIOCGIWSTATS */
3064 (iw_handler) wl_iw_set_spy, /* SIOCSIWSPY */
3065 (iw_handler) wl_iw_get_spy, /* SIOCGIWSPY */
3066 (iw_handler) NULL, /* -- hole -- */
3067 (iw_handler) NULL, /* -- hole -- */
3068 (iw_handler) wl_iw_set_wap, /* SIOCSIWAP */
3069 (iw_handler) wl_iw_get_wap, /* SIOCGIWAP */
3070 #if WIRELESS_EXT > 17
3071 (iw_handler) wl_iw_mlme, /* SIOCSIWMLME */
3073 (iw_handler) NULL, /* -- hole -- */
3075 (iw_handler) wl_iw_iscan_get_aplist, /* SIOCGIWAPLIST */
3076 #if WIRELESS_EXT > 13
3077 (iw_handler) wl_iw_iscan_set_scan, /* SIOCSIWSCAN */
3078 (iw_handler) wl_iw_iscan_get_scan, /* SIOCGIWSCAN */
3079 #else /* WIRELESS_EXT > 13 */
3080 (iw_handler) NULL, /* SIOCSIWSCAN */
3081 (iw_handler) NULL, /* SIOCGIWSCAN */
3082 #endif /* WIRELESS_EXT > 13 */
3083 (iw_handler) wl_iw_set_essid, /* SIOCSIWESSID */
3084 (iw_handler) wl_iw_get_essid, /* SIOCGIWESSID */
3085 (iw_handler) wl_iw_set_nick, /* SIOCSIWNICKN */
3086 (iw_handler) wl_iw_get_nick, /* SIOCGIWNICKN */
3087 (iw_handler) NULL, /* -- hole -- */
3088 (iw_handler) NULL, /* -- hole -- */
3089 (iw_handler) wl_iw_set_rate, /* SIOCSIWRATE */
3090 (iw_handler) wl_iw_get_rate, /* SIOCGIWRATE */
3091 (iw_handler) wl_iw_set_rts, /* SIOCSIWRTS */
3092 (iw_handler) wl_iw_get_rts, /* SIOCGIWRTS */
3093 (iw_handler) wl_iw_set_frag, /* SIOCSIWFRAG */
3094 (iw_handler) wl_iw_get_frag, /* SIOCGIWFRAG */
3095 (iw_handler) wl_iw_set_txpow, /* SIOCSIWTXPOW */
3096 (iw_handler) wl_iw_get_txpow, /* SIOCGIWTXPOW */
3097 #if WIRELESS_EXT > 10
3098 (iw_handler) wl_iw_set_retry, /* SIOCSIWRETRY */
3099 (iw_handler) wl_iw_get_retry, /* SIOCGIWRETRY */
3100 #endif /* WIRELESS_EXT > 10 */
3101 (iw_handler) wl_iw_set_encode, /* SIOCSIWENCODE */
3102 (iw_handler) wl_iw_get_encode, /* SIOCGIWENCODE */
3103 (iw_handler) wl_iw_set_power, /* SIOCSIWPOWER */
3104 (iw_handler) wl_iw_get_power, /* SIOCGIWPOWER */
3105 #if WIRELESS_EXT > 17
3106 (iw_handler) NULL, /* -- hole -- */
3107 (iw_handler) NULL, /* -- hole -- */
3108 (iw_handler) wl_iw_set_wpaie, /* SIOCSIWGENIE */
3109 (iw_handler) wl_iw_get_wpaie, /* SIOCGIWGENIE */
3110 (iw_handler) wl_iw_set_wpaauth, /* SIOCSIWAUTH */
3111 (iw_handler) wl_iw_get_wpaauth, /* SIOCGIWAUTH */
3112 (iw_handler) wl_iw_set_encodeext, /* SIOCSIWENCODEEXT */
3113 (iw_handler) wl_iw_get_encodeext, /* SIOCGIWENCODEEXT */
3114 (iw_handler) wl_iw_set_pmksa, /* SIOCSIWPMKSA */
3115 #endif /* WIRELESS_EXT > 17 */
3118 #if WIRELESS_EXT > 12
3120 WL_IW_SET_LEDDC = SIOCIWFIRSTPRIV,
3123 #if WIRELESS_EXT > 17
3124 #endif /* WIRELESS_EXT > 17 */
3128 static iw_handler wl_iw_priv_handler[] = {
3132 #if WIRELESS_EXT > 17
3133 #endif /* WIRELESS_EXT > 17 */
3137 static struct iw_priv_args wl_iw_priv_args[] = {
3140 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3146 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3152 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3156 #if WIRELESS_EXT > 17
3157 #endif /* WIRELESS_EXT > 17 */
3161 const struct iw_handler_def wl_iw_handler_def =
3163 .num_standard = ARRAYSIZE(wl_iw_handler),
3164 .num_private = ARRAY_SIZE(wl_iw_priv_handler),
3165 .num_private_args = ARRAY_SIZE(wl_iw_priv_args),
3166 .standard = (iw_handler *) wl_iw_handler,
3167 .private = wl_iw_priv_handler,
3168 .private_args = wl_iw_priv_args,
3169 #if WIRELESS_EXT >= 19
3170 get_wireless_stats: dhd_get_wireless_stats,
3171 #endif /* WIRELESS_EXT >= 19 */
3173 #endif /* WIRELESS_EXT > 12 */
3177 struct net_device *dev,
3182 struct iwreq *wrq = (struct iwreq *) rq;
3183 struct iw_request_info info;
3186 size_t token_size = 1;
3187 int max_tokens = 0, ret = 0;
3189 if (cmd < SIOCIWFIRST ||
3190 IW_IOCTL_IDX(cmd) >= ARRAYSIZE(wl_iw_handler) ||
3191 !(handler = wl_iw_handler[IW_IOCTL_IDX(cmd)]))
3200 max_tokens = IW_ESSID_MAX_SIZE + 1;
3205 #if WIRELESS_EXT > 17
3206 case SIOCSIWENCODEEXT:
3207 case SIOCGIWENCODEEXT:
3209 max_tokens = IW_ENCODING_TOKEN_MAX;
3213 max_tokens = sizeof(struct iw_range);
3217 token_size = sizeof(struct sockaddr) + sizeof(struct iw_quality);
3218 max_tokens = IW_MAX_AP;
3221 #if WIRELESS_EXT > 13
3224 max_tokens = wrq->u.data.length;
3226 max_tokens = IW_SCAN_MAX_DATA;
3228 #endif /* WIRELESS_EXT > 13 */
3231 token_size = sizeof(struct sockaddr);
3232 max_tokens = IW_MAX_SPY;
3236 token_size = sizeof(struct sockaddr) + sizeof(struct iw_quality);
3237 max_tokens = IW_MAX_SPY;
3243 if (max_tokens && wrq->u.data.pointer) {
3244 if (wrq->u.data.length > max_tokens)
3247 if (!(extra = kmalloc(max_tokens * token_size, GFP_KERNEL)))
3250 if (copy_from_user(extra, wrq->u.data.pointer, wrq->u.data.length * token_size)) {
3259 ret = handler(dev, &info, &wrq->u, extra);
3262 if (copy_to_user(wrq->u.data.pointer, extra, wrq->u.data.length * token_size)) {
3273 /* Convert a connection status event into a connection status string.
3274 * Returns TRUE if a matching connection status string was found.
3277 wl_iw_conn_status_str(uint32 event_type, uint32 status, uint32 reason,
3278 char* stringBuf, uint buflen)
3280 typedef struct conn_fail_event_map_t {
3281 uint32 inEvent; /* input: event type to match */
3282 uint32 inStatus; /* input: event status code to match */
3283 uint32 inReason; /* input: event reason code to match */
3284 const char* outName; /* output: failure type */
3285 const char* outCause; /* output: failure cause */
3286 } conn_fail_event_map_t;
3288 /* Map of WLC_E events to connection failure strings */
3289 # define WL_IW_DONT_CARE 9999
3290 const conn_fail_event_map_t event_map [] = {
3291 /* inEvent inStatus inReason */
3292 /* outName outCause */
3293 {WLC_E_SET_SSID, WLC_E_STATUS_SUCCESS, WL_IW_DONT_CARE,
3295 {WLC_E_SET_SSID, WLC_E_STATUS_NO_NETWORKS, WL_IW_DONT_CARE,
3296 "Conn", "NoNetworks"},
3297 {WLC_E_SET_SSID, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3298 "Conn", "ConfigMismatch"},
3299 {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_PRUNE_ENCR_MISMATCH,
3300 "Conn", "EncrypMismatch"},
3301 {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_RSN_MISMATCH,
3302 "Conn", "RsnMismatch"},
3303 {WLC_E_AUTH, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
3304 "Conn", "AuthTimeout"},
3305 {WLC_E_AUTH, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3306 "Conn", "AuthFail"},
3307 {WLC_E_AUTH, WLC_E_STATUS_NO_ACK, WL_IW_DONT_CARE,
3308 "Conn", "AuthNoAck"},
3309 {WLC_E_REASSOC, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3310 "Conn", "ReassocFail"},
3311 {WLC_E_REASSOC, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
3312 "Conn", "ReassocTimeout"},
3313 {WLC_E_REASSOC, WLC_E_STATUS_ABORT, WL_IW_DONT_CARE,
3314 "Conn", "ReassocAbort"},
3315 {WLC_E_PSK_SUP, WLC_SUP_KEYED, WL_IW_DONT_CARE,
3316 "Sup", "ConnSuccess"},
3317 {WLC_E_PSK_SUP, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3318 "Sup", "WpaHandshakeFail"},
3319 {WLC_E_DEAUTH_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3321 {WLC_E_DISASSOC_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3322 "Conn", "DisassocInd"},
3323 {WLC_E_DISASSOC, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3327 const char* name = "";
3328 const char* cause = NULL;
3331 /* Search the event map table for a matching event */
3332 for (i = 0; i < sizeof(event_map)/sizeof(event_map[0]); i++) {
3333 const conn_fail_event_map_t* row = &event_map[i];
3334 if (row->inEvent == event_type &&
3335 (row->inStatus == status || row->inStatus == WL_IW_DONT_CARE) &&
3336 (row->inReason == reason || row->inReason == WL_IW_DONT_CARE)) {
3337 name = row->outName;
3338 cause = row->outCause;
3343 /* If found, generate a connection failure string and return TRUE */
3345 memset(stringBuf, 0, buflen);
3346 snprintf(stringBuf, buflen, "%s %s %02d %02d",
3347 name, cause, status, reason);
3348 WL_TRACE(("Connection status: %s\n", stringBuf));
3355 #if (WIRELESS_EXT > 14)
3356 /* Check if we have received an event that indicates connection failure
3357 * If so, generate a connection failure report string.
3358 * The caller supplies a buffer to hold the generated string.
3361 wl_iw_check_conn_fail(wl_event_msg_t *e, char* stringBuf, uint buflen)
3363 uint32 event = ntoh32(e->event_type);
3364 uint32 status = ntoh32(e->status);
3365 uint32 reason = ntoh32(e->reason);
3367 if (wl_iw_conn_status_str(event, status, reason, stringBuf, buflen)) {
3374 #endif /* WIRELESS_EXT > 14 */
3376 #ifndef IW_CUSTOM_MAX
3377 #define IW_CUSTOM_MAX 256 /* size of extra buffer used for translation of events */
3378 #endif /* IW_CUSTOM_MAX */
3381 wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void* data)
3383 #if WIRELESS_EXT > 13
3384 union iwreq_data wrqu;
3385 char extra[IW_CUSTOM_MAX + 1];
3387 uint32 event_type = ntoh32(e->event_type);
3388 uint16 flags = ntoh16(e->flags);
3389 uint32 datalen = ntoh32(e->datalen);
3390 uint32 status = ntoh32(e->status);
3392 memset(&wrqu, 0, sizeof(wrqu));
3393 memset(extra, 0, sizeof(extra));
3395 memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN);
3396 wrqu.addr.sa_family = ARPHRD_ETHER;
3398 switch (event_type) {
3402 #if WIRELESS_EXT > 14
3404 case WLC_E_ASSOC_IND:
3405 case WLC_E_REASSOC_IND:
3406 cmd = IWEVREGISTERED;
3408 case WLC_E_DEAUTH_IND:
3409 case WLC_E_DISASSOC_IND:
3411 wrqu.data.length = strlen(extra);
3412 bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
3413 bzero(&extra, ETHER_ADDR_LEN);
3417 case WLC_E_NDIS_LINK:
3419 wrqu.data.length = strlen(extra);
3420 if (!(flags & WLC_EVENT_MSG_LINK)) {
3421 printf("%s: Link Down with BSSID="MACSTR"\n", __FUNCTION__,
3422 MAC2STR((u8 *)wrqu.addr.sa_data));
3423 bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
3424 bzero(&extra, ETHER_ADDR_LEN);
3426 printf("%s: Link UP with BSSID="MACSTR"\n", __FUNCTION__,
3427 MAC2STR((u8 *)wrqu.addr.sa_data));
3430 case WLC_E_ACTION_FRAME:
3432 if (datalen + 1 <= sizeof(extra)) {
3433 wrqu.data.length = datalen + 1;
3434 extra[0] = WLC_E_ACTION_FRAME;
3435 memcpy(&extra[1], data, datalen);
3436 WL_TRACE(("WLC_E_ACTION_FRAME len %d \n", wrqu.data.length));
3440 case WLC_E_ACTION_FRAME_COMPLETE:
3442 if (sizeof(status) + 1 <= sizeof(extra)) {
3443 wrqu.data.length = sizeof(status) + 1;
3444 extra[0] = WLC_E_ACTION_FRAME_COMPLETE;
3445 memcpy(&extra[1], &status, sizeof(status));
3446 WL_TRACE(("wl_iw_event status %d \n", status));
3449 #endif /* WIRELESS_EXT > 14 */
3450 #if WIRELESS_EXT > 17
3451 case WLC_E_MIC_ERROR: {
3452 struct iw_michaelmicfailure *micerrevt = (struct iw_michaelmicfailure *)&extra;
3453 cmd = IWEVMICHAELMICFAILURE;
3454 wrqu.data.length = sizeof(struct iw_michaelmicfailure);
3455 if (flags & WLC_EVENT_MSG_GROUP)
3456 micerrevt->flags |= IW_MICFAILURE_GROUP;
3458 micerrevt->flags |= IW_MICFAILURE_PAIRWISE;
3459 memcpy(micerrevt->src_addr.sa_data, &e->addr, ETHER_ADDR_LEN);
3460 micerrevt->src_addr.sa_family = ARPHRD_ETHER;
3465 case WLC_E_ASSOC_REQ_IE:
3466 cmd = IWEVASSOCREQIE;
3467 wrqu.data.length = datalen;
3468 if (datalen < sizeof(extra))
3469 memcpy(extra, data, datalen);
3472 case WLC_E_ASSOC_RESP_IE:
3473 cmd = IWEVASSOCRESPIE;
3474 wrqu.data.length = datalen;
3475 if (datalen < sizeof(extra))
3476 memcpy(extra, data, datalen);
3479 case WLC_E_PMKID_CACHE: {
3480 struct iw_pmkid_cand *iwpmkidcand = (struct iw_pmkid_cand *)&extra;
3481 pmkid_cand_list_t *pmkcandlist;
3482 pmkid_cand_t *pmkidcand;
3488 cmd = IWEVPMKIDCAND;
3490 count = ntoh32_ua((uint8 *)&pmkcandlist->npmkid_cand);
3491 wrqu.data.length = sizeof(struct iw_pmkid_cand);
3492 pmkidcand = pmkcandlist->pmkid_cand;
3494 bzero(iwpmkidcand, sizeof(struct iw_pmkid_cand));
3495 if (pmkidcand->preauth)
3496 iwpmkidcand->flags |= IW_PMKID_CAND_PREAUTH;
3497 bcopy(&pmkidcand->BSSID, &iwpmkidcand->bssid.sa_data,
3499 wireless_send_event(dev, cmd, &wrqu, extra);
3505 #endif /* WIRELESS_EXT > 17 */
3507 case WLC_E_SCAN_COMPLETE:
3508 #if WIRELESS_EXT > 14
3511 WL_TRACE(("event WLC_E_SCAN_COMPLETE\n"));
3512 // terence 20150224: fix "wlan0: (WE) : Wireless Event too big (65306)"
3513 memset(&wrqu, 0, sizeof(wrqu));
3514 if ((g_iscan) && (g_iscan->sysioc_pid >= 0) &&
3515 (g_iscan->iscan_state != ISCAN_STATE_IDLE))
3516 up(&g_iscan->sysioc_sem);
3520 /* Cannot translate event */
3525 if (cmd == SIOCGIWSCAN) {
3526 if ((!g_iscan) || (g_iscan->sysioc_pid < 0)) {
3527 wireless_send_event(dev, cmd, &wrqu, NULL);
3530 wireless_send_event(dev, cmd, &wrqu, extra);
3533 #if WIRELESS_EXT > 14
3534 /* Look for WLC events that indicate a connection failure.
3535 * If found, generate an IWEVCUSTOM event.
3537 memset(extra, 0, sizeof(extra));
3538 if (wl_iw_check_conn_fail(e, extra, sizeof(extra))) {
3540 wrqu.data.length = strlen(extra);
3541 wireless_send_event(dev, cmd, &wrqu, extra);
3543 #endif /* WIRELESS_EXT > 14 */
3545 #endif /* WIRELESS_EXT > 13 */
3548 int wl_iw_get_wireless_stats(struct net_device *dev, struct iw_statistics *wstats)
3557 if ((res = dev_wlc_ioctl(dev, WLC_GET_PHY_NOISE, &phy_noise, sizeof(phy_noise))))
3560 phy_noise = dtoh32(phy_noise);
3561 WL_TRACE(("wl_iw_get_wireless_stats phy noise=%d\n *****", phy_noise));
3564 if ((res = dev_wlc_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t))))
3567 rssi = dtoh32(scb_val.val);
3568 WL_TRACE(("wl_iw_get_wireless_stats rssi=%d ****** \n", rssi));
3569 if (rssi <= WL_IW_RSSI_NO_SIGNAL)
3570 wstats->qual.qual = 0;
3571 else if (rssi <= WL_IW_RSSI_VERY_LOW)
3572 wstats->qual.qual = 1;
3573 else if (rssi <= WL_IW_RSSI_LOW)
3574 wstats->qual.qual = 2;
3575 else if (rssi <= WL_IW_RSSI_GOOD)
3576 wstats->qual.qual = 3;
3577 else if (rssi <= WL_IW_RSSI_VERY_GOOD)
3578 wstats->qual.qual = 4;
3580 wstats->qual.qual = 5;
3582 /* Wraps to 0 if RSSI is 0 */
3583 wstats->qual.level = 0x100 + rssi;
3584 wstats->qual.noise = 0x100 + phy_noise;
3585 #if WIRELESS_EXT > 18
3586 wstats->qual.updated |= (IW_QUAL_ALL_UPDATED | IW_QUAL_DBM);
3588 wstats->qual.updated |= 7;
3589 #endif /* WIRELESS_EXT > 18 */
3591 #if WIRELESS_EXT > 11
3592 WL_TRACE(("wl_iw_get_wireless_stats counters=%d\n *****", (int)sizeof(wl_cnt_t)));
3594 memset(&cnt, 0, sizeof(wl_cnt_t));
3595 res = dev_wlc_bufvar_get(dev, "counters", (char *)&cnt, sizeof(wl_cnt_t));
3598 WL_ERROR(("wl_iw_get_wireless_stats counters failed error=%d ****** \n", res));
3602 cnt.version = dtoh16(cnt.version);
3603 if (cnt.version != WL_CNT_T_VERSION) {
3604 WL_TRACE(("\tIncorrect version of counters struct: expected %d; got %d\n",
3605 WL_CNT_T_VERSION, cnt.version));
3609 wstats->discard.nwid = 0;
3610 wstats->discard.code = dtoh32(cnt.rxundec);
3611 wstats->discard.fragment = dtoh32(cnt.rxfragerr);
3612 wstats->discard.retries = dtoh32(cnt.txfail);
3613 wstats->discard.misc = dtoh32(cnt.rxrunt) + dtoh32(cnt.rxgiant);
3614 wstats->miss.beacon = 0;
3616 WL_TRACE(("wl_iw_get_wireless_stats counters txframe=%d txbyte=%d\n",
3617 dtoh32(cnt.txframe), dtoh32(cnt.txbyte)));
3618 WL_TRACE(("wl_iw_get_wireless_stats counters rxfrmtoolong=%d\n", dtoh32(cnt.rxfrmtoolong)));
3619 WL_TRACE(("wl_iw_get_wireless_stats counters rxbadplcp=%d\n", dtoh32(cnt.rxbadplcp)));
3620 WL_TRACE(("wl_iw_get_wireless_stats counters rxundec=%d\n", dtoh32(cnt.rxundec)));
3621 WL_TRACE(("wl_iw_get_wireless_stats counters rxfragerr=%d\n", dtoh32(cnt.rxfragerr)));
3622 WL_TRACE(("wl_iw_get_wireless_stats counters txfail=%d\n", dtoh32(cnt.txfail)));
3623 WL_TRACE(("wl_iw_get_wireless_stats counters rxrunt=%d\n", dtoh32(cnt.rxrunt)));
3624 WL_TRACE(("wl_iw_get_wireless_stats counters rxgiant=%d\n", dtoh32(cnt.rxgiant)));
3626 #endif /* WIRELESS_EXT > 11 */
3633 wl_iw_timerfunc(ulong data)
3635 iscan_info_t *iscan = (iscan_info_t *)data;
3636 iscan->timer_on = 0;
3637 if (iscan->iscan_state != ISCAN_STATE_IDLE) {
3638 WL_TRACE(("timer trigger\n"));
3639 up(&iscan->sysioc_sem);
3644 wl_iw_set_event_mask(struct net_device *dev)
3646 char eventmask[WL_EVENTING_MASK_LEN];
3647 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
3649 dev_iw_iovar_getbuf(dev, "event_msgs", "", 0, iovbuf, sizeof(iovbuf));
3650 bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
3651 setbit(eventmask, WLC_E_SCAN_COMPLETE);
3652 dev_iw_iovar_setbuf(dev, "event_msgs", eventmask, WL_EVENTING_MASK_LEN,
3653 iovbuf, sizeof(iovbuf));
3658 wl_iw_iscan_prep(wl_scan_params_t *params, wlc_ssid_t *ssid)
3662 memcpy(¶ms->bssid, ðer_bcast, ETHER_ADDR_LEN);
3663 params->bss_type = DOT11_BSSTYPE_ANY;
3664 params->scan_type = 0;
3665 params->nprobes = -1;
3666 params->active_time = -1;
3667 params->passive_time = -1;
3668 params->home_time = -1;
3669 params->channel_num = 0;
3671 params->nprobes = htod32(params->nprobes);
3672 params->active_time = htod32(params->active_time);
3673 params->passive_time = htod32(params->passive_time);
3674 params->home_time = htod32(params->home_time);
3675 if (ssid && ssid->SSID_len)
3676 memcpy(¶ms->ssid, ssid, sizeof(wlc_ssid_t));
3682 wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action)
3684 int params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_iscan_params_t, params));
3685 wl_iscan_params_t *params;
3688 if (ssid && ssid->SSID_len) {
3689 params_size += sizeof(wlc_ssid_t);
3691 params = (wl_iscan_params_t*)kmalloc(params_size, GFP_KERNEL);
3692 if (params == NULL) {
3695 memset(params, 0, params_size);
3696 ASSERT(params_size < WLC_IOCTL_SMLEN);
3698 err = wl_iw_iscan_prep(¶ms->params, ssid);
3701 params->version = htod32(ISCAN_REQ_VERSION);
3702 params->action = htod16(action);
3703 params->scan_duration = htod16(0);
3705 /* params_size += OFFSETOF(wl_iscan_params_t, params); */
3706 (void) dev_iw_iovar_setbuf(iscan->dev, "iscan", params, params_size,
3707 iscan->ioctlbuf, WLC_IOCTL_SMLEN);
3715 wl_iw_iscan_get(iscan_info_t *iscan)
3719 wl_iscan_results_t * list_buf;
3720 wl_iscan_results_t list;
3721 wl_scan_results_t *results;
3724 /* buffers are allocated on demand */
3725 if (iscan->list_cur) {
3726 buf = iscan->list_cur;
3727 iscan->list_cur = buf->next;
3730 buf = kmalloc(sizeof(iscan_buf_t), GFP_KERNEL);
3732 return WL_SCAN_RESULTS_ABORTED;
3734 if (!iscan->list_hdr)
3735 iscan->list_hdr = buf;
3737 ptr = iscan->list_hdr;
3744 memset(buf->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
3745 list_buf = (wl_iscan_results_t*)buf->iscan_buf;
3746 results = &list_buf->results;
3747 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
3748 results->version = 0;
3751 memset(&list, 0, sizeof(list));
3752 list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN);
3753 (void) dev_iw_iovar_getbuf(
3757 WL_ISCAN_RESULTS_FIXED_SIZE,
3759 WLC_IW_ISCAN_MAXLEN);
3760 results->buflen = dtoh32(results->buflen);
3761 results->version = dtoh32(results->version);
3762 results->count = dtoh32(results->count);
3763 WL_TRACE(("results->count = %d\n", results->count));
3765 WL_TRACE(("results->buflen = %d\n", results->buflen));
3766 status = dtoh32(list_buf->status);
3770 static void wl_iw_send_scan_complete(iscan_info_t *iscan)
3772 union iwreq_data wrqu;
3774 memset(&wrqu, 0, sizeof(wrqu));
3776 /* wext expects to get no data for SIOCGIWSCAN Event */
3777 wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL);
3781 _iscan_sysioc_thread(void *data)
3784 iscan_info_t *iscan = (iscan_info_t *)data;
3786 printf("%s: thread Enter\n", __FUNCTION__);
3787 DAEMONIZE("iscan_sysioc");
3789 status = WL_SCAN_RESULTS_PARTIAL;
3790 while (down_interruptible(&iscan->sysioc_sem) == 0) {
3791 if (iscan->timer_on) {
3792 del_timer(&iscan->timer);
3793 iscan->timer_on = 0;
3796 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3799 status = wl_iw_iscan_get(iscan);
3800 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3805 case WL_SCAN_RESULTS_PARTIAL:
3806 WL_TRACE(("iscanresults incomplete\n"));
3807 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3810 /* make sure our buffer size is enough before going next round */
3811 wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
3812 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3815 /* Reschedule the timer */
3816 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
3817 add_timer(&iscan->timer);
3818 iscan->timer_on = 1;
3820 case WL_SCAN_RESULTS_SUCCESS:
3821 WL_TRACE(("iscanresults complete\n"));
3822 iscan->iscan_state = ISCAN_STATE_IDLE;
3823 wl_iw_send_scan_complete(iscan);
3825 case WL_SCAN_RESULTS_PENDING:
3826 WL_TRACE(("iscanresults pending\n"));
3827 /* Reschedule the timer */
3828 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
3829 add_timer(&iscan->timer);
3830 iscan->timer_on = 1;
3832 case WL_SCAN_RESULTS_ABORTED:
3833 WL_TRACE(("iscanresults aborted\n"));
3834 iscan->iscan_state = ISCAN_STATE_IDLE;
3835 wl_iw_send_scan_complete(iscan);
3838 WL_TRACE(("iscanresults returned unknown status %d\n", status));
3842 printf("%s: was terminated\n", __FUNCTION__);
3843 complete_and_exit(&iscan->sysioc_exited, 0);
3847 wl_iw_attach(struct net_device *dev, void * dhdp)
3849 iscan_info_t *iscan = NULL;
3851 printf("%s: Enter\n", __FUNCTION__);
3856 iscan = kmalloc(sizeof(iscan_info_t), GFP_KERNEL);
3859 memset(iscan, 0, sizeof(iscan_info_t));
3860 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
3861 iscan->kthread = NULL;
3863 iscan->sysioc_pid = -1;
3864 /* we only care about main interface so save a global here */
3867 iscan->iscan_state = ISCAN_STATE_IDLE;
3870 /* Set up the timer */
3871 iscan->timer_ms = 2000;
3872 init_timer(&iscan->timer);
3873 iscan->timer.data = (ulong)iscan;
3874 iscan->timer.function = wl_iw_timerfunc;
3876 sema_init(&iscan->sysioc_sem, 0);
3877 init_completion(&iscan->sysioc_exited);
3878 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
3879 iscan->kthread = kthread_run(_iscan_sysioc_thread, iscan, "iscan_sysioc");
3880 iscan->sysioc_pid = iscan->kthread->pid;
3882 iscan->sysioc_pid = kernel_thread(_iscan_sysioc_thread, iscan, 0);
3884 if (iscan->sysioc_pid < 0)
3889 void wl_iw_detach(void)
3892 iscan_info_t *iscan = g_iscan;
3895 if (iscan->sysioc_pid >= 0) {
3896 KILL_PROC(iscan->sysioc_pid, SIGTERM);
3897 wait_for_completion(&iscan->sysioc_exited);
3900 while (iscan->list_hdr) {
3901 buf = iscan->list_hdr->next;
3902 kfree(iscan->list_hdr);
3903 iscan->list_hdr = buf;