2 * Linux Wireless Extensions support
4 * Copyright (C) 1999-2016, Broadcom Corporation
6 * Unless you and Broadcom execute a separate written software license
7 * agreement governing use of this software, this software is licensed to you
8 * under the terms of the GNU General Public License version 2 (the "GPL"),
9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10 * following added to such license:
12 * As a special exception, the copyright holders of this software give you
13 * permission to link this software with independent modules, and to copy and
14 * distribute the resulting executable under terms of your choice, provided that
15 * you also meet, for each linked independent module, the terms and conditions of
16 * the license of that module. An independent module is a module which is not
17 * derived from this software. The special exception does not apply to any
18 * modifications of the software.
20 * Notwithstanding the above, under no circumstances may you combine this
21 * software in any way with any other Broadcom software provided under a license
22 * other than the GPL, without Broadcom's express prior written consent.
25 * <<Broadcom-WL-IPTag/Open:>>
27 * $Id: wl_iw.c 591286 2015-10-07 11:59:26Z $
38 #include <bcmendian.h>
39 #include <proto/ethernet.h>
41 #include <linux/if_arp.h>
42 #include <asm/uaccess.h>
46 #include <wlioctl_utils.h>
48 #include <wl_android.h>
50 typedef const struct si_pub si_t;
53 #define WL_ERROR_LEVEL 0x0001
54 #define WL_SCAN_LEVEL 0x0002
55 #define WL_ASSOC_LEVEL 0x0004
56 #define WL_INFORM_LEVEL 0x0008
57 #define WL_WSEC_LEVEL 0x0010
58 #define WL_PNO_LEVEL 0x0020
59 #define WL_COEX_LEVEL 0x0040
60 #define WL_SOFTAP_LEVEL 0x0080
61 #define WL_TRACE_LEVEL 0x0100
63 uint iw_msg_level = WL_ERROR_LEVEL;
65 #define WL_ERROR(x) do {if (iw_msg_level & WL_ERROR_LEVEL) printf x;} while (0)
66 #define WL_SCAN(x) do {if (iw_msg_level & WL_SCAN_LEVEL) printf x;} while (0)
67 #define WL_ASSOC(x) do {if (iw_msg_level & WL_ASSOC_LEVEL) printf x;} while (0)
68 #define WL_INFORM(x) do {if (iw_msg_level & WL_INFORM_LEVEL) printf x;} while (0)
69 #define WL_WSEC(x) do {if (iw_msg_level & WL_WSEC_LEVEL) printf x;} while (0)
70 #define WL_PNO(x) do {if (iw_msg_level & WL_PNO_LEVEL) printf x;} while (0)
71 #define WL_COEX(x) do {if (iw_msg_level & WL_COEX_LEVEL) printf x;} while (0)
72 #define WL_SOFTAP(x) do {if (iw_msg_level & WL_SOFTAP_LEVEL) printf x;} while (0)
73 #define WL_TRACE(x) do {if (iw_msg_level & WL_TRACE_LEVEL) printf x;} while (0)
78 /* Broadcom extensions to WEXT, linux upstream has obsoleted WEXT */
79 #ifndef IW_AUTH_KEY_MGMT_FT_802_1X
80 #define IW_AUTH_KEY_MGMT_FT_802_1X 0x04
83 #ifndef IW_AUTH_KEY_MGMT_FT_PSK
84 #define IW_AUTH_KEY_MGMT_FT_PSK 0x08
87 #ifndef IW_ENC_CAPA_FW_ROAM_ENABLE
88 #define IW_ENC_CAPA_FW_ROAM_ENABLE 0x00000020
92 /* FC9: wireless.h 2.6.25-14.fc9.i686 is missing these, even though WIRELESS_EXT is set to latest
95 #ifndef IW_ENCODE_ALG_PMK
96 #define IW_ENCODE_ALG_PMK 4
98 #ifndef IW_ENC_CAPA_4WAY_HANDSHAKE
99 #define IW_ENC_CAPA_4WAY_HANDSHAKE 0x00000010
103 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
104 #include <linux/rtnetlink.h>
107 struct net_device *ap_net_dev = NULL;
108 tsk_ctl_t ap_eth_ctl; /* apsta AP netdev waiter thread */
111 extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status,
112 uint32 reason, char* stringBuf, uint buflen);
114 #define MAX_WLIW_IOCTL_LEN 1024
116 /* IOCTL swapping mode for Big Endian host with Little Endian dongle. Default to off */
117 #define htod32(i) (i)
118 #define htod16(i) (i)
119 #define dtoh32(i) (i)
120 #define dtoh16(i) (i)
121 #define htodchanspec(i) (i)
122 #define dtohchanspec(i) (i)
124 extern struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
125 extern int dhd_wait_pend8021x(struct net_device *dev);
127 #if WIRELESS_EXT < 19
128 #define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST)
129 #define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST)
130 #endif /* WIRELESS_EXT < 19 */
133 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
134 #define DAEMONIZE(a) do { \
135 allow_signal(SIGKILL); \
136 allow_signal(SIGTERM); \
138 #elif ((LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)) && \
139 (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)))
140 #define DAEMONIZE(a) daemonize(a); \
141 allow_signal(SIGKILL); \
142 allow_signal(SIGTERM);
143 #else /* Linux 2.4 (w/o preemption patch) */
144 #define RAISE_RX_SOFTIRQ() \
145 cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
146 #define DAEMONIZE(a) daemonize(); \
148 strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
150 #endif /* LINUX_VERSION_CODE */
152 #define ISCAN_STATE_IDLE 0
153 #define ISCAN_STATE_SCANING 1
155 /* the buf lengh can be WLC_IOCTL_MAXLEN (8K) to reduce iteration */
156 #define WLC_IW_ISCAN_MAXLEN 2048
157 typedef struct iscan_buf {
158 struct iscan_buf * next;
159 char iscan_buf[WLC_IW_ISCAN_MAXLEN];
162 typedef struct iscan_info {
163 struct net_device *dev;
164 struct timer_list timer;
168 iscan_buf_t * list_hdr;
169 iscan_buf_t * list_cur;
171 /* Thread to work on iscan */
172 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
173 struct task_struct *kthread;
176 struct semaphore sysioc_sem;
177 struct completion sysioc_exited;
180 char ioctlbuf[WLC_IOCTL_SMLEN];
182 iscan_info_t *g_iscan = NULL;
183 static void wl_iw_timerfunc(ulong data);
184 static void wl_iw_set_event_mask(struct net_device *dev);
185 static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action);
187 /* priv_link becomes netdev->priv and is the link between netdev and wlif struct */
188 typedef struct priv_link {
192 /* dev to priv_link */
193 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
194 #define WL_DEV_LINK(dev) (priv_link_t*)(dev->priv)
196 #define WL_DEV_LINK(dev) (priv_link_t*)netdev_priv(dev)
200 #define IW_DEV_IF(dev) ((wl_iw_t*)(WL_DEV_LINK(dev))->wliw)
202 static void swap_key_from_BE(
206 key->index = htod32(key->index);
207 key->len = htod32(key->len);
208 key->algo = htod32(key->algo);
209 key->flags = htod32(key->flags);
210 key->rxiv.hi = htod32(key->rxiv.hi);
211 key->rxiv.lo = htod16(key->rxiv.lo);
212 key->iv_initialized = htod32(key->iv_initialized);
215 static void swap_key_to_BE(
219 key->index = dtoh32(key->index);
220 key->len = dtoh32(key->len);
221 key->algo = dtoh32(key->algo);
222 key->flags = dtoh32(key->flags);
223 key->rxiv.hi = dtoh32(key->rxiv.hi);
224 key->rxiv.lo = dtoh16(key->rxiv.lo);
225 key->iv_initialized = dtoh32(key->iv_initialized);
230 struct net_device *dev,
241 memset(&ioc, 0, sizeof(ioc));
246 strncpy(ifr.ifr_name, dev->name, sizeof(ifr.ifr_name));
247 ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
248 ifr.ifr_data = (caddr_t) &ioc;
252 #if defined(WL_USE_NETDEV_OPS)
253 ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
255 ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
263 set named driver variable to int value and return error indication
264 calling example: dev_wlc_intvar_set(dev, "arate", rate)
269 struct net_device *dev,
273 char buf[WLC_IOCTL_SMLEN];
277 len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf));
280 return (dev_wlc_ioctl(dev, WLC_SET_VAR, buf, len));
285 struct net_device *dev,
294 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
296 BCM_REFERENCE(iolen);
298 return (dev_wlc_ioctl(dev, WLC_SET_VAR, bufptr, iolen));
303 struct net_device *dev,
312 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
314 BCM_REFERENCE(iolen);
316 return (dev_wlc_ioctl(dev, WLC_GET_VAR, bufptr, buflen));
319 #if WIRELESS_EXT > 17
322 struct net_device *dev,
330 ioctlbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
334 buflen = bcm_mkiovar(name, buf, len, ioctlbuf, MAX_WLIW_IOCTL_LEN);
336 error = dev_wlc_ioctl(dev, WLC_SET_VAR, ioctlbuf, buflen);
341 #endif /* WIRELESS_EXT > 17 */
344 get named driver variable to int value and return error indication
345 calling example: dev_wlc_bufvar_get(dev, "arate", &rate)
350 struct net_device *dev,
352 char *buf, int buflen)
359 ioctlbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
362 len = bcm_mkiovar(name, NULL, 0, ioctlbuf, MAX_WLIW_IOCTL_LEN);
365 error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)ioctlbuf, MAX_WLIW_IOCTL_LEN);
367 bcopy(ioctlbuf, buf, buflen);
374 get named driver variable to int value and return error indication
375 calling example: dev_wlc_intvar_get(dev, "arate", &rate)
380 struct net_device *dev,
385 char buf[WLC_IOCTL_SMLEN];
393 len = bcm_mkiovar(name, (char *)(&data_null), 0, (char *)(&var), sizeof(var.buf));
395 error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)&var, len);
397 *retval = dtoh32(var.val);
402 /* Maintain backward compatibility */
403 #if WIRELESS_EXT < 13
404 struct iw_request_info
406 __u16 cmd; /* Wireless Extension command */
407 __u16 flags; /* More to come ;-) */
410 typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
411 void *wrqu, char *extra);
412 #endif /* WIRELESS_EXT < 13 */
414 #if WIRELESS_EXT > 12
417 struct net_device *dev,
418 struct iw_request_info *info,
419 union iwreq_data *wrqu,
423 int dc = *(int *)extra;
426 error = dev_wlc_intvar_set(dev, "leddc", dc);
432 struct net_device *dev,
433 struct iw_request_info *info,
434 union iwreq_data *wrqu,
438 int mode = *(int *)extra;
442 error = dev_wlc_intvar_set(dev, "vlan_mode", mode);
448 struct net_device *dev,
449 struct iw_request_info *info,
450 union iwreq_data *wrqu,
454 int pm = *(int *)extra;
458 error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
461 #endif /* WIRELESS_EXT > 12 */
464 wl_iw_send_priv_event(
465 struct net_device *dev,
469 union iwreq_data wrqu;
470 char extra[IW_CUSTOM_MAX + 1];
474 memset(&wrqu, 0, sizeof(wrqu));
475 if (strlen(flag) > sizeof(extra))
478 strncpy(extra, flag, sizeof(extra));
479 extra[sizeof(extra) - 1] = '\0';
480 wrqu.data.length = strlen(extra);
481 wireless_send_event(dev, cmd, &wrqu, extra);
482 WL_TRACE(("Send IWEVCUSTOM Event as %s\n", extra));
489 struct net_device *dev,
490 struct iw_request_info *info,
497 struct sockaddr bssid;
499 WL_TRACE(("%s: SIOCSIWCOMMIT\n", dev->name));
501 if ((error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid))))
504 ssid.SSID_len = dtoh32(ssid.SSID_len);
509 bzero(&bssid, sizeof(struct sockaddr));
510 if ((error = dev_wlc_ioctl(dev, WLC_REASSOC, &bssid, ETHER_ADDR_LEN))) {
511 WL_ERROR(("%s: WLC_REASSOC failed (%d)\n", __FUNCTION__, error));
520 struct net_device *dev,
521 struct iw_request_info *info,
522 union iwreq_data *cwrq,
530 WL_TRACE(("%s: SIOCGIWNAME\n", dev->name));
533 if ((err = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype))) < 0)
535 if ((err = dev_wlc_ioctl(dev, WLC_GET_BANDLIST, band, sizeof(band))) < 0)
538 band[0] = dtoh32(band[0]);
541 strncpy(cap, "a", sizeof(cap));
544 strncpy(cap, "b", sizeof(cap));
548 strncpy(cap, "abg", sizeof(cap));
550 strncpy(cap, "bg", sizeof(cap));
554 strncpy(cap, "abgn", sizeof(cap));
556 strncpy(cap, "bgn", sizeof(cap));
560 (void)snprintf(cwrq->name, IFNAMSIZ, "IEEE 802.11%s", cap);
567 struct net_device *dev,
568 struct iw_request_info *info,
569 struct iw_freq *fwrq,
576 WL_TRACE(("%s: SIOCSIWFREQ\n", dev->name));
578 /* Setting by channel number */
579 if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) {
583 /* Setting by frequency */
585 /* Convert to MHz as best we can */
590 } else if (fwrq->e < 6) {
591 while (fwrq->e++ < 6)
594 /* handle 4.9GHz frequencies as Japan 4 GHz based channelization */
595 if (fwrq->m > 4000 && fwrq->m < 5000)
596 sf = WF_CHAN_FACTOR_4_G; /* start factor for 4 GHz */
598 chan = wf_mhz2channel(fwrq->m, sf);
600 WL_ERROR(("%s: chan=%d\n", __FUNCTION__, chan));
602 if ((error = dev_wlc_ioctl(dev, WLC_SET_CHANNEL, &chan, sizeof(chan)))) {
603 WL_ERROR(("%s: WLC_DISASSOC failed (%d).\n", __FUNCTION__, error));
607 /* -EINPROGRESS: Call commit handler */
613 struct net_device *dev,
614 struct iw_request_info *info,
615 struct iw_freq *fwrq,
622 WL_TRACE(("%s: SIOCGIWFREQ\n", dev->name));
624 if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
627 /* Return radio channel in channel form */
628 fwrq->m = dtoh32(ci.hw_channel);
635 struct net_device *dev,
636 struct iw_request_info *info,
641 int infra = 0, ap = 0, error = 0;
643 WL_TRACE(("%s: SIOCSIWMODE\n", dev->name));
658 infra = htod32(infra);
661 if ((error = dev_wlc_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra))) ||
662 (error = dev_wlc_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap))))
665 /* -EINPROGRESS: Call commit handler */
671 struct net_device *dev,
672 struct iw_request_info *info,
677 int error, infra = 0, ap = 0;
679 WL_TRACE(("%s: SIOCGIWMODE\n", dev->name));
681 if ((error = dev_wlc_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra))) ||
682 (error = dev_wlc_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap))))
685 infra = dtoh32(infra);
687 *uwrq = infra ? ap ? IW_MODE_MASTER : IW_MODE_INFRA : IW_MODE_ADHOC;
694 struct net_device *dev,
695 struct iw_request_info *info,
696 struct iw_point *dwrq,
700 struct iw_range *range = (struct iw_range *) extra;
701 static int channels[MAXCHANNEL+1];
702 wl_uint32_list_t *list = (wl_uint32_list_t *) channels;
703 wl_rateset_t rateset;
708 int bw_cap = 0, sgi_tx = 0, nmode = 0;
710 uint8 nrate_list2copy = 0;
711 uint16 nrate_list[4][8] = { {13, 26, 39, 52, 78, 104, 117, 130},
712 {14, 29, 43, 58, 87, 116, 130, 144},
713 {27, 54, 81, 108, 162, 216, 243, 270},
714 {30, 60, 90, 120, 180, 240, 270, 300}};
717 WL_TRACE(("%s: SIOCGIWRANGE\n", dev->name));
722 dwrq->length = sizeof(struct iw_range);
723 memset(range, 0, sizeof(*range));
725 /* We don't use nwids */
726 range->min_nwid = range->max_nwid = 0;
728 /* Set available channels/frequencies */
729 list->count = htod32(MAXCHANNEL);
730 if ((error = dev_wlc_ioctl(dev, WLC_GET_VALID_CHANNELS, channels, sizeof(channels))))
732 for (i = 0; i < dtoh32(list->count) && i < IW_MAX_FREQUENCIES; i++) {
733 range->freq[i].i = dtoh32(list->element[i]);
735 ch = dtoh32(list->element[i]);
736 if (ch <= CH_MAX_2G_CHANNEL)
737 sf = WF_CHAN_FACTOR_2_4_G;
739 sf = WF_CHAN_FACTOR_5_G;
741 range->freq[i].m = wf_channel2mhz(ch, sf);
742 range->freq[i].e = 6;
744 range->num_frequency = range->num_channels = i;
746 /* Link quality (use NDIS cutoffs) */
747 range->max_qual.qual = 5;
748 /* Signal level (use RSSI) */
749 range->max_qual.level = 0x100 - 200; /* -200 dBm */
750 /* Noise level (use noise) */
751 range->max_qual.noise = 0x100 - 200; /* -200 dBm */
752 /* Signal level threshold range (?) */
753 range->sensitivity = 65535;
755 #if WIRELESS_EXT > 11
756 /* Link quality (use NDIS cutoffs) */
757 range->avg_qual.qual = 3;
758 /* Signal level (use RSSI) */
759 range->avg_qual.level = 0x100 + WL_IW_RSSI_GOOD;
760 /* Noise level (use noise) */
761 range->avg_qual.noise = 0x100 - 75; /* -75 dBm */
762 #endif /* WIRELESS_EXT > 11 */
764 /* Set available bitrates */
765 if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
767 rateset.count = dtoh32(rateset.count);
768 range->num_bitrates = rateset.count;
769 for (i = 0; i < rateset.count && i < IW_MAX_BITRATES; i++)
770 range->bitrate[i] = (rateset.rates[i] & 0x7f) * 500000; /* convert to bps */
771 if ((error = dev_wlc_intvar_get(dev, "nmode", &nmode)))
773 if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype))))
775 if (nmode == 1 && (((phytype == WLC_PHY_TYPE_LCN) ||
776 (phytype == WLC_PHY_TYPE_LCN40)))) {
777 if ((error = dev_wlc_intvar_get(dev, "mimo_bw_cap", &bw_cap)))
779 if ((error = dev_wlc_intvar_get(dev, "sgi_tx", &sgi_tx)))
781 if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(channel_info_t))))
783 ci.hw_channel = dtoh32(ci.hw_channel);
786 (bw_cap == 2 && ci.hw_channel <= 14)) {
793 (bw_cap == 2 && ci.hw_channel >= 36)) {
799 range->num_bitrates += 8;
800 ASSERT(range->num_bitrates < IW_MAX_BITRATES);
801 for (k = 0; i < range->num_bitrates; k++, i++) {
803 range->bitrate[i] = (nrate_list[nrate_list2copy][k]) * 500000;
807 /* Set an indication of the max TCP throughput
808 * in bit/s that we can expect using this interface.
809 * May be use for QoS stuff... Jean II
811 if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &i, sizeof(i))))
814 if (i == WLC_PHY_TYPE_A)
815 range->throughput = 24000000; /* 24 Mbits/s */
817 range->throughput = 1500000; /* 1.5 Mbits/s */
819 /* RTS and fragmentation thresholds */
821 range->max_rts = 2347;
822 range->min_frag = 256;
823 range->max_frag = 2346;
825 range->max_encoding_tokens = DOT11_MAX_DEFAULT_KEYS;
826 range->num_encoding_sizes = 4;
827 range->encoding_size[0] = WEP1_KEY_SIZE;
828 range->encoding_size[1] = WEP128_KEY_SIZE;
829 #if WIRELESS_EXT > 17
830 range->encoding_size[2] = TKIP_KEY_SIZE;
832 range->encoding_size[2] = 0;
834 range->encoding_size[3] = AES_KEY_SIZE;
836 /* Do not support power micro-management */
841 range->pmp_flags = 0;
844 /* Transmit Power - values are in mW */
845 range->num_txpower = 2;
846 range->txpower[0] = 1;
847 range->txpower[1] = 255;
848 range->txpower_capa = IW_TXPOW_MWATT;
850 #if WIRELESS_EXT > 10
851 range->we_version_compiled = WIRELESS_EXT;
852 range->we_version_source = 19;
854 /* Only support retry limits */
855 range->retry_capa = IW_RETRY_LIMIT;
856 range->retry_flags = IW_RETRY_LIMIT;
857 range->r_time_flags = 0;
858 /* SRL and LRL limits */
859 range->min_retry = 1;
860 range->max_retry = 255;
861 /* Retry lifetime limits unsupported */
862 range->min_r_time = 0;
863 range->max_r_time = 0;
864 #endif /* WIRELESS_EXT > 10 */
866 #if WIRELESS_EXT > 17
867 range->enc_capa = IW_ENC_CAPA_WPA;
868 range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP;
869 range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP;
870 range->enc_capa |= IW_ENC_CAPA_WPA2;
872 /* Determine driver FBT capability. */
873 if (dev_wlc_intvar_get(dev, "fbt_cap", &fbt_cap) == 0) {
874 if (fbt_cap == WLC_FBT_CAP_DRV_4WAY_AND_REASSOC) {
875 /* Tell the host (e.g. wpa_supplicant) to let driver do the handshake */
876 range->enc_capa |= IW_ENC_CAPA_4WAY_HANDSHAKE;
880 #ifdef BCMFW_ROAM_ENABLE_WEXT
881 /* Advertise firmware roam capability to the external supplicant */
882 range->enc_capa |= IW_ENC_CAPA_FW_ROAM_ENABLE;
883 #endif /* BCMFW_ROAM_ENABLE_WEXT */
885 /* Event capability (kernel) */
886 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
887 /* Event capability (driver) */
888 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
889 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
890 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
891 IW_EVENT_CAPA_SET(range->event_capa, IWEVMICHAELMICFAILURE);
892 IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCREQIE);
893 IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCRESPIE);
894 IW_EVENT_CAPA_SET(range->event_capa, IWEVPMKIDCAND);
896 #if WIRELESS_EXT >= 22 && defined(IW_SCAN_CAPA_ESSID)
897 /* FC7 wireless.h defines EXT 22 but doesn't define scan_capa bits */
898 range->scan_capa = IW_SCAN_CAPA_ESSID;
900 #endif /* WIRELESS_EXT > 17 */
906 rssi_to_qual(int rssi)
908 if (rssi <= WL_IW_RSSI_NO_SIGNAL)
910 else if (rssi <= WL_IW_RSSI_VERY_LOW)
912 else if (rssi <= WL_IW_RSSI_LOW)
914 else if (rssi <= WL_IW_RSSI_GOOD)
916 else if (rssi <= WL_IW_RSSI_VERY_GOOD)
924 struct net_device *dev,
925 struct iw_request_info *info,
926 struct iw_point *dwrq,
930 wl_iw_t *iw = IW_DEV_IF(dev);
931 struct sockaddr *addr = (struct sockaddr *) extra;
934 WL_TRACE(("%s: SIOCSIWSPY\n", dev->name));
939 iw->spy_num = MIN(ARRAYSIZE(iw->spy_addr), dwrq->length);
940 for (i = 0; i < iw->spy_num; i++)
941 memcpy(&iw->spy_addr[i], addr[i].sa_data, ETHER_ADDR_LEN);
942 memset(iw->spy_qual, 0, sizeof(iw->spy_qual));
949 struct net_device *dev,
950 struct iw_request_info *info,
951 struct iw_point *dwrq,
955 wl_iw_t *iw = IW_DEV_IF(dev);
956 struct sockaddr *addr = (struct sockaddr *) extra;
957 struct iw_quality *qual = (struct iw_quality *) &addr[iw->spy_num];
960 WL_TRACE(("%s: SIOCGIWSPY\n", dev->name));
965 dwrq->length = iw->spy_num;
966 for (i = 0; i < iw->spy_num; i++) {
967 memcpy(addr[i].sa_data, &iw->spy_addr[i], ETHER_ADDR_LEN);
968 addr[i].sa_family = AF_UNIX;
969 memcpy(&qual[i], &iw->spy_qual[i], sizeof(struct iw_quality));
970 iw->spy_qual[i].updated = 0;
978 struct net_device *dev,
979 struct iw_request_info *info,
980 struct sockaddr *awrq,
986 WL_TRACE(("%s: SIOCSIWAP\n", dev->name));
988 if (awrq->sa_family != ARPHRD_ETHER) {
989 WL_ERROR(("%s: Invalid Header...sa_family\n", __FUNCTION__));
993 /* Ignore "auto" or "off" */
994 if (ETHER_ISBCAST(awrq->sa_data) || ETHER_ISNULLADDR(awrq->sa_data)) {
996 bzero(&scbval, sizeof(scb_val_t));
997 WL_ERROR(("%s: WLC_DISASSOC\n", __FUNCTION__));
998 if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
999 WL_ERROR(("%s: WLC_DISASSOC failed (%d).\n", __FUNCTION__, error));
1003 /* WL_ASSOC(("Assoc to %s\n", bcm_ether_ntoa((struct ether_addr *)&(awrq->sa_data),
1006 /* Reassociate to the specified AP */
1007 if ((error = dev_wlc_ioctl(dev, WLC_REASSOC, awrq->sa_data, ETHER_ADDR_LEN))) {
1008 WL_ERROR(("%s: WLC_REASSOC failed (%d).\n", __FUNCTION__, error));
1011 WL_ERROR(("%s: join BSSID="MACSTR"\n", __FUNCTION__, MAC2STR((u8 *)awrq->sa_data)));
1018 struct net_device *dev,
1019 struct iw_request_info *info,
1020 struct sockaddr *awrq,
1024 WL_TRACE(("%s: SIOCGIWAP\n", dev->name));
1026 awrq->sa_family = ARPHRD_ETHER;
1027 memset(awrq->sa_data, 0, ETHER_ADDR_LEN);
1029 /* Ignore error (may be down or disassociated) */
1030 (void) dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETHER_ADDR_LEN);
1035 #if WIRELESS_EXT > 17
1038 struct net_device *dev,
1039 struct iw_request_info *info,
1040 struct sockaddr *awrq,
1044 struct iw_mlme *mlme;
1046 int error = -EINVAL;
1048 WL_TRACE(("%s: SIOCSIWMLME\n", dev->name));
1050 mlme = (struct iw_mlme *)extra;
1052 WL_ERROR(("Invalid ioctl data.\n"));
1056 scbval.val = mlme->reason_code;
1057 bcopy(&mlme->addr.sa_data, &scbval.ea, ETHER_ADDR_LEN);
1059 if (mlme->cmd == IW_MLME_DISASSOC) {
1060 scbval.val = htod32(scbval.val);
1061 error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t));
1063 else if (mlme->cmd == IW_MLME_DEAUTH) {
1064 scbval.val = htod32(scbval.val);
1065 error = dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scbval,
1069 WL_ERROR(("%s: Invalid ioctl data.\n", __FUNCTION__));
1075 #endif /* WIRELESS_EXT > 17 */
1079 struct net_device *dev,
1080 struct iw_request_info *info,
1081 struct iw_point *dwrq,
1085 wl_scan_results_t *list;
1086 struct sockaddr *addr = (struct sockaddr *) extra;
1087 struct iw_quality qual[IW_MAX_AP];
1088 wl_bss_info_t *bi = NULL;
1090 uint buflen = dwrq->length;
1093 WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name));
1098 /* Get scan results (too large to put on the stack) */
1099 list = kmalloc(buflen, GFP_KERNEL);
1102 memset(list, 0, buflen);
1103 list->buflen = htod32(buflen);
1104 if ((error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen))) {
1105 WL_ERROR(("%d: Scan results error %d\n", __LINE__, error));
1109 list->buflen = dtoh32(list->buflen);
1110 list->version = dtoh32(list->version);
1111 list->count = dtoh32(list->count);
1112 ASSERT(list->version == WL_BSS_INFO_VERSION);
1114 for (i = 0, dwrq->length = 0; i < list->count && dwrq->length < IW_MAX_AP; i++) {
1115 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1116 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1119 /* Infrastructure only */
1120 if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
1124 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1125 addr[dwrq->length].sa_family = ARPHRD_ETHER;
1126 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1127 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1128 qual[dwrq->length].qual = rssi_to_qual(rssi);
1129 qual[dwrq->length].level = 0x100 + rssi;
1130 qual[dwrq->length].noise = 0x100 + bi->phy_noise;
1132 /* Updated qual, level, and noise */
1133 #if WIRELESS_EXT > 18
1134 qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1136 qual[dwrq->length].updated = 7;
1137 #endif /* WIRELESS_EXT > 18 */
1145 memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
1154 wl_iw_iscan_get_aplist(
1155 struct net_device *dev,
1156 struct iw_request_info *info,
1157 struct iw_point *dwrq,
1161 wl_scan_results_t *list;
1163 iscan_info_t *iscan = g_iscan;
1165 struct sockaddr *addr = (struct sockaddr *) extra;
1166 struct iw_quality qual[IW_MAX_AP];
1167 wl_bss_info_t *bi = NULL;
1171 WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name));
1176 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1177 return wl_iw_get_aplist(dev, info, dwrq, extra);
1180 buf = iscan->list_hdr;
1181 /* Get scan results (too large to put on the stack) */
1183 list = &((wl_iscan_results_t*)buf->iscan_buf)->results;
1184 ASSERT(list->version == WL_BSS_INFO_VERSION);
1187 for (i = 0, dwrq->length = 0; i < list->count && dwrq->length < IW_MAX_AP; i++) {
1188 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1189 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1190 WLC_IW_ISCAN_MAXLEN));
1192 /* Infrastructure only */
1193 if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
1197 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1198 addr[dwrq->length].sa_family = ARPHRD_ETHER;
1199 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1200 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1201 qual[dwrq->length].qual = rssi_to_qual(rssi);
1202 qual[dwrq->length].level = 0x100 + rssi;
1203 qual[dwrq->length].noise = 0x100 + bi->phy_noise;
1205 /* Updated qual, level, and noise */
1206 #if WIRELESS_EXT > 18
1207 qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1209 qual[dwrq->length].updated = 7;
1210 #endif /* WIRELESS_EXT > 18 */
1217 memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
1225 #if WIRELESS_EXT > 13
1228 struct net_device *dev,
1229 struct iw_request_info *info,
1230 union iwreq_data *wrqu,
1236 WL_TRACE(("%s: SIOCSIWSCAN\n", dev->name));
1238 /* default Broadcast scan */
1239 memset(&ssid, 0, sizeof(ssid));
1241 #if WIRELESS_EXT > 17
1242 /* check for given essid */
1243 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1244 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1245 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1246 ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
1247 memcpy(ssid.SSID, req->essid, ssid.SSID_len);
1248 ssid.SSID_len = htod32(ssid.SSID_len);
1252 /* Ignore error (most likely scan in progress) */
1253 (void) dev_wlc_ioctl(dev, WLC_SCAN, &ssid, sizeof(ssid));
1259 wl_iw_iscan_set_scan(
1260 struct net_device *dev,
1261 struct iw_request_info *info,
1262 union iwreq_data *wrqu,
1267 iscan_info_t *iscan = g_iscan;
1269 WL_TRACE(("%s: SIOCSIWSCAN iscan=%p\n", dev->name, iscan));
1271 /* use backup if our thread is not successful */
1272 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1273 return wl_iw_set_scan(dev, info, wrqu, extra);
1275 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1279 /* default Broadcast scan */
1280 memset(&ssid, 0, sizeof(ssid));
1282 #if WIRELESS_EXT > 17
1283 /* check for given essid */
1284 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1285 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1286 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1287 ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
1288 memcpy(ssid.SSID, req->essid, ssid.SSID_len);
1289 ssid.SSID_len = htod32(ssid.SSID_len);
1294 iscan->list_cur = iscan->list_hdr;
1295 iscan->iscan_state = ISCAN_STATE_SCANING;
1298 wl_iw_set_event_mask(dev);
1299 wl_iw_iscan(iscan, &ssid, WL_SCAN_ACTION_START);
1301 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
1302 add_timer(&iscan->timer);
1303 iscan->timer_on = 1;
1308 #if WIRELESS_EXT > 17
1310 ie_is_wpa_ie(uint8 **wpaie, uint8 **tlvs, int *tlvs_len)
1312 /* Is this body of this tlvs entry a WPA entry? If */
1313 /* not update the tlvs buffer pointer/length */
1316 /* If the contents match the WPA_OUI and type=1 */
1318 !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) {
1322 /* point to the next ie */
1324 /* calculate the length of the rest of the buffer */
1325 *tlvs_len -= (int)(ie - *tlvs);
1326 /* update the pointer to the start of the buffer */
1332 ie_is_wps_ie(uint8 **wpsie, uint8 **tlvs, int *tlvs_len)
1334 /* Is this body of this tlvs entry a WPS entry? If */
1335 /* not update the tlvs buffer pointer/length */
1338 /* If the contents match the WPA_OUI and type=4 */
1340 !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) {
1344 /* point to the next ie */
1346 /* calculate the length of the rest of the buffer */
1347 *tlvs_len -= (int)(ie - *tlvs);
1348 /* update the pointer to the start of the buffer */
1352 #endif /* WIRELESS_EXT > 17 */
1356 wl_iw_handle_scanresults_ies(char **event_p, char *end,
1357 struct iw_request_info *info, wl_bss_info_t *bi)
1359 #if WIRELESS_EXT > 17
1360 struct iw_event iwe;
1364 if (bi->ie_length) {
1365 /* look for wpa/rsn ies in the ie list... */
1367 uint8 *ptr = ((uint8 *)bi) + bi->ie_offset;
1368 int ptr_len = bi->ie_length;
1371 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_VS_ID)) &&
1372 ie->len > WFA_OUI_LEN + 1 &&
1373 !bcmp((const void *)&ie->data[0], (const void *)WFA_OUI, WFA_OUI_LEN) &&
1374 ie->data[WFA_OUI_LEN] == WFA_OUI_TYPE_OSEN) {
1375 iwe.cmd = IWEVGENIE;
1376 iwe.u.data.length = ie->len + 2;
1377 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1379 ptr = ((uint8 *)bi) + bi->ie_offset;
1381 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_RSN_ID))) {
1382 iwe.cmd = IWEVGENIE;
1383 iwe.u.data.length = ie->len + 2;
1384 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1386 ptr = ((uint8 *)bi) + bi->ie_offset;
1388 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_MDIE_ID))) {
1389 iwe.cmd = IWEVGENIE;
1390 iwe.u.data.length = ie->len + 2;
1391 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1393 ptr = ((uint8 *)bi) + bi->ie_offset;
1395 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
1396 /* look for WPS IE */
1397 if (ie_is_wps_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
1398 iwe.cmd = IWEVGENIE;
1399 iwe.u.data.length = ie->len + 2;
1400 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1405 ptr = ((uint8 *)bi) + bi->ie_offset;
1406 ptr_len = bi->ie_length;
1407 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
1408 if (ie_is_wpa_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
1409 iwe.cmd = IWEVGENIE;
1410 iwe.u.data.length = ie->len + 2;
1411 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1419 #endif /* WIRELESS_EXT > 17 */
1425 struct net_device *dev,
1426 struct iw_request_info *info,
1427 struct iw_point *dwrq,
1432 wl_scan_results_t *list;
1433 struct iw_event iwe;
1434 wl_bss_info_t *bi = NULL;
1436 char *event = extra, *end = extra + dwrq->length, *value;
1437 uint buflen = dwrq->length;
1441 WL_TRACE(("%s: %s SIOCGIWSCAN\n", __FUNCTION__, dev->name));
1446 /* Check for scan in progress */
1447 if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
1449 ci.scan_channel = dtoh32(ci.scan_channel);
1450 if (ci.scan_channel)
1453 /* Get scan results (too large to put on the stack) */
1454 list = kmalloc(buflen, GFP_KERNEL);
1457 memset(list, 0, buflen);
1458 list->buflen = htod32(buflen);
1459 if ((error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen))) {
1463 list->buflen = dtoh32(list->buflen);
1464 list->version = dtoh32(list->version);
1465 list->count = dtoh32(list->count);
1467 ASSERT(list->version == WL_BSS_INFO_VERSION);
1469 for (i = 0; i < list->count && i < IW_MAX_AP; i++) {
1470 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1471 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1474 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1475 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1476 channel = (bi->ctl_ch == 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch;
1477 WL_SCAN(("%s: BSSID="MACSTR", channel=%d, RSSI=%d, merge broadcast SSID=\"%s\"\n",
1478 __FUNCTION__, MAC2STR(bi->BSSID.octet), channel, rssi, bi->SSID));
1480 /* First entry must be the BSSID */
1481 iwe.cmd = SIOCGIWAP;
1482 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1483 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1484 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
1487 iwe.u.data.length = dtoh32(bi->SSID_len);
1488 iwe.cmd = SIOCGIWESSID;
1489 iwe.u.data.flags = 1;
1490 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
1493 if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
1494 iwe.cmd = SIOCGIWMODE;
1495 if (dtoh16(bi->capability) & DOT11_CAP_ESS)
1496 iwe.u.mode = IW_MODE_INFRA;
1498 iwe.u.mode = IW_MODE_ADHOC;
1499 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
1503 iwe.cmd = SIOCGIWFREQ;
1505 iwe.u.freq.m = wf_channel2mhz(CHSPEC_CHANNEL(bi->chanspec),
1506 (CHSPEC_IS2G(bi->chanspec)) ?
1507 WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G);
1509 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
1511 /* Channel quality */
1513 iwe.u.qual.qual = rssi_to_qual(rssi);
1514 iwe.u.qual.level = 0x100 + rssi;
1515 iwe.u.qual.noise = 0x100 + bi->phy_noise;
1516 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
1518 wl_iw_handle_scanresults_ies(&event, end, info, bi);
1521 iwe.cmd = SIOCGIWENCODE;
1522 if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
1523 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1525 iwe.u.data.flags = IW_ENCODE_DISABLED;
1526 iwe.u.data.length = 0;
1527 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
1530 if (bi->rateset.count) {
1531 value = event + IW_EV_LCP_LEN;
1532 iwe.cmd = SIOCGIWRATE;
1533 /* Those two flags are ignored... */
1534 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1535 for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
1536 iwe.u.bitrate.value = (bi->rateset.rates[j] & 0x7f) * 500000;
1537 value = IWE_STREAM_ADD_VALUE(info, event, value, end, &iwe,
1546 dwrq->length = event - extra;
1547 dwrq->flags = 0; /* todo */
1553 wl_iw_iscan_get_scan(
1554 struct net_device *dev,
1555 struct iw_request_info *info,
1556 struct iw_point *dwrq,
1560 wl_scan_results_t *list;
1561 struct iw_event iwe;
1562 wl_bss_info_t *bi = NULL;
1565 char *event = extra, *end = extra + dwrq->length, *value;
1566 iscan_info_t *iscan = g_iscan;
1567 iscan_buf_t * p_buf;
1571 WL_TRACE(("%s: %s SIOCGIWSCAN\n", __FUNCTION__, dev->name));
1576 /* use backup if our thread is not successful */
1577 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1578 return wl_iw_get_scan(dev, info, dwrq, extra);
1581 /* Check for scan in progress */
1582 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1583 WL_TRACE(("%s: SIOCGIWSCAN GET still scanning\n", dev->name));
1588 p_buf = iscan->list_hdr;
1589 /* Get scan results */
1590 while (p_buf != iscan->list_cur) {
1591 list = &((wl_iscan_results_t*)p_buf->iscan_buf)->results;
1593 if (list->version != WL_BSS_INFO_VERSION) {
1594 WL_ERROR(("list->version %d != WL_BSS_INFO_VERSION\n", list->version));
1598 for (ii = 0; ii < list->count && apcnt < IW_MAX_AP; apcnt++, ii++) {
1599 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1600 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1601 WLC_IW_ISCAN_MAXLEN));
1603 /* overflow check cover fields before wpa IEs */
1604 if (event + ETHER_ADDR_LEN + bi->SSID_len + IW_EV_UINT_LEN + IW_EV_FREQ_LEN +
1605 IW_EV_QUAL_LEN >= end)
1608 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1609 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1610 channel = (bi->ctl_ch == 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch;
1611 WL_SCAN(("%s: BSSID="MACSTR", channel=%d, RSSI=%d, merge broadcast SSID=\"%s\"\n",
1612 __FUNCTION__, MAC2STR(bi->BSSID.octet), channel, rssi, bi->SSID));
1614 /* First entry must be the BSSID */
1615 iwe.cmd = SIOCGIWAP;
1616 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1617 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1618 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
1621 iwe.u.data.length = dtoh32(bi->SSID_len);
1622 iwe.cmd = SIOCGIWESSID;
1623 iwe.u.data.flags = 1;
1624 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
1627 if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
1628 iwe.cmd = SIOCGIWMODE;
1629 if (dtoh16(bi->capability) & DOT11_CAP_ESS)
1630 iwe.u.mode = IW_MODE_INFRA;
1632 iwe.u.mode = IW_MODE_ADHOC;
1633 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
1637 iwe.cmd = SIOCGIWFREQ;
1638 iwe.u.freq.m = wf_channel2mhz(CHSPEC_CHANNEL(bi->chanspec),
1639 (CHSPEC_IS2G(bi->chanspec)) ?
1640 WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G);
1642 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
1644 /* Channel quality */
1646 iwe.u.qual.qual = rssi_to_qual(rssi);
1647 iwe.u.qual.level = 0x100 + rssi;
1648 iwe.u.qual.noise = 0x100 + bi->phy_noise;
1649 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
1651 wl_iw_handle_scanresults_ies(&event, end, info, bi);
1654 iwe.cmd = SIOCGIWENCODE;
1655 if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
1656 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1658 iwe.u.data.flags = IW_ENCODE_DISABLED;
1659 iwe.u.data.length = 0;
1660 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
1663 if (bi->rateset.count <= sizeof(bi->rateset.rates)) {
1664 if (event + IW_MAX_BITRATES*IW_EV_PARAM_LEN >= end)
1667 value = event + IW_EV_LCP_LEN;
1668 iwe.cmd = SIOCGIWRATE;
1669 /* Those two flags are ignored... */
1670 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1671 for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
1672 iwe.u.bitrate.value = (bi->rateset.rates[j] & 0x7f) * 500000;
1673 value = IWE_STREAM_ADD_VALUE(info, event, value, end, &iwe,
1679 p_buf = p_buf->next;
1680 } /* while (p_buf) */
1682 dwrq->length = event - extra;
1683 dwrq->flags = 0; /* todo */
1688 #endif /* WIRELESS_EXT > 13 */
1693 struct net_device *dev,
1694 struct iw_request_info *info,
1695 struct iw_point *dwrq,
1702 WL_TRACE(("%s: SIOCSIWESSID\n", dev->name));
1704 /* default Broadcast SSID */
1705 memset(&ssid, 0, sizeof(ssid));
1706 if (dwrq->length && extra) {
1707 #if WIRELESS_EXT > 20
1708 ssid.SSID_len = MIN(sizeof(ssid.SSID), dwrq->length);
1710 ssid.SSID_len = MIN(sizeof(ssid.SSID), dwrq->length-1);
1712 memcpy(ssid.SSID, extra, ssid.SSID_len);
1713 ssid.SSID_len = htod32(ssid.SSID_len);
1715 if ((error = dev_wlc_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid)))) {
1716 WL_ERROR(("%s: WLC_SET_SSID failed (%d).\n", __FUNCTION__, error));
1719 WL_ERROR(("%s: join SSID=%s\n", __FUNCTION__, ssid.SSID));
1721 /* If essid null then it is "iwconfig <interface> essid off" command */
1724 bzero(&scbval, sizeof(scb_val_t));
1725 WL_ERROR(("%s: WLC_DISASSOC\n", __FUNCTION__));
1726 if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
1727 WL_ERROR(("%s: WLC_DISASSOC failed (%d).\n", __FUNCTION__, error));
1736 struct net_device *dev,
1737 struct iw_request_info *info,
1738 struct iw_point *dwrq,
1745 WL_TRACE(("%s: SIOCGIWESSID\n", dev->name));
1750 if ((error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid)))) {
1751 WL_ERROR(("Error getting the SSID\n"));
1755 ssid.SSID_len = dtoh32(ssid.SSID_len);
1757 /* Get the current SSID */
1758 memcpy(extra, ssid.SSID, ssid.SSID_len);
1760 dwrq->length = ssid.SSID_len;
1762 dwrq->flags = 1; /* active */
1769 struct net_device *dev,
1770 struct iw_request_info *info,
1771 struct iw_point *dwrq,
1775 wl_iw_t *iw = IW_DEV_IF(dev);
1776 WL_TRACE(("%s: SIOCSIWNICKN\n", dev->name));
1781 /* Check the size of the string */
1782 if (dwrq->length > sizeof(iw->nickname))
1785 memcpy(iw->nickname, extra, dwrq->length);
1786 iw->nickname[dwrq->length - 1] = '\0';
1793 struct net_device *dev,
1794 struct iw_request_info *info,
1795 struct iw_point *dwrq,
1799 wl_iw_t *iw = IW_DEV_IF(dev);
1800 WL_TRACE(("%s: SIOCGIWNICKN\n", dev->name));
1805 strcpy(extra, iw->nickname);
1806 dwrq->length = strlen(extra) + 1;
1811 static int wl_iw_set_rate(
1812 struct net_device *dev,
1813 struct iw_request_info *info,
1814 struct iw_param *vwrq,
1818 wl_rateset_t rateset;
1819 int error, rate, i, error_bg, error_a;
1821 WL_TRACE(("%s: SIOCSIWRATE\n", dev->name));
1823 /* Get current rateset */
1824 if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
1827 rateset.count = dtoh32(rateset.count);
1829 if (vwrq->value < 0) {
1830 /* Select maximum rate */
1831 rate = rateset.rates[rateset.count - 1] & 0x7f;
1832 } else if (vwrq->value < rateset.count) {
1833 /* Select rate by rateset index */
1834 rate = rateset.rates[vwrq->value] & 0x7f;
1836 /* Specified rate in bps */
1837 rate = vwrq->value / 500000;
1843 Since the is a/b/g-blind, both a/bg_rate are enforced.
1845 error_bg = dev_wlc_intvar_set(dev, "bg_rate", rate);
1846 error_a = dev_wlc_intvar_set(dev, "a_rate", rate);
1848 if (error_bg && error_a)
1849 return (error_bg | error_a);
1853 Since the is a/b/g-blind, both a/bg_rate are enforced.
1855 /* 0 is for clearing rate override */
1856 error_bg = dev_wlc_intvar_set(dev, "bg_rate", 0);
1857 /* 0 is for clearing rate override */
1858 error_a = dev_wlc_intvar_set(dev, "a_rate", 0);
1860 if (error_bg && error_a)
1861 return (error_bg | error_a);
1863 /* Remove rates above selected rate */
1864 for (i = 0; i < rateset.count; i++)
1865 if ((rateset.rates[i] & 0x7f) > rate)
1867 rateset.count = htod32(i);
1869 /* Set current rateset */
1870 if ((error = dev_wlc_ioctl(dev, WLC_SET_RATESET, &rateset, sizeof(rateset))))
1877 static int wl_iw_get_rate(
1878 struct net_device *dev,
1879 struct iw_request_info *info,
1880 struct iw_param *vwrq,
1886 WL_TRACE(("%s: SIOCGIWRATE\n", dev->name));
1888 /* Report the current tx rate */
1889 if ((error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate))))
1891 rate = dtoh32(rate);
1892 vwrq->value = rate * 500000;
1899 struct net_device *dev,
1900 struct iw_request_info *info,
1901 struct iw_param *vwrq,
1907 WL_TRACE(("%s: SIOCSIWRTS\n", dev->name));
1910 rts = DOT11_DEFAULT_RTS_LEN;
1911 else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_RTS_LEN)
1916 if ((error = dev_wlc_intvar_set(dev, "rtsthresh", rts)))
1924 struct net_device *dev,
1925 struct iw_request_info *info,
1926 struct iw_param *vwrq,
1932 WL_TRACE(("%s: SIOCGIWRTS\n", dev->name));
1934 if ((error = dev_wlc_intvar_get(dev, "rtsthresh", &rts)))
1938 vwrq->disabled = (rts >= DOT11_DEFAULT_RTS_LEN);
1946 struct net_device *dev,
1947 struct iw_request_info *info,
1948 struct iw_param *vwrq,
1954 WL_TRACE(("%s: SIOCSIWFRAG\n", dev->name));
1957 frag = DOT11_DEFAULT_FRAG_LEN;
1958 else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_FRAG_LEN)
1963 if ((error = dev_wlc_intvar_set(dev, "fragthresh", frag)))
1971 struct net_device *dev,
1972 struct iw_request_info *info,
1973 struct iw_param *vwrq,
1977 int error, fragthreshold;
1979 WL_TRACE(("%s: SIOCGIWFRAG\n", dev->name));
1981 if ((error = dev_wlc_intvar_get(dev, "fragthresh", &fragthreshold)))
1984 vwrq->value = fragthreshold;
1985 vwrq->disabled = (fragthreshold >= DOT11_DEFAULT_FRAG_LEN);
1993 struct net_device *dev,
1994 struct iw_request_info *info,
1995 struct iw_param *vwrq,
2001 WL_TRACE(("%s: SIOCSIWTXPOW\n", dev->name));
2003 /* Make sure radio is off or on as far as software is concerned */
2004 disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0;
2005 disable += WL_RADIO_SW_DISABLE << 16;
2007 disable = htod32(disable);
2008 if ((error = dev_wlc_ioctl(dev, WLC_SET_RADIO, &disable, sizeof(disable))))
2011 /* If Radio is off, nothing more to do */
2012 if (disable & WL_RADIO_SW_DISABLE)
2015 /* Only handle mW */
2016 if (!(vwrq->flags & IW_TXPOW_MWATT))
2019 /* Value < 0 means just "on" or "off" */
2020 if (vwrq->value < 0)
2023 if (vwrq->value > 0xffff) txpwrmw = 0xffff;
2024 else txpwrmw = (uint16)vwrq->value;
2027 error = dev_wlc_intvar_set(dev, "qtxpower", (int)(bcm_mw_to_qdbm(txpwrmw)));
2033 struct net_device *dev,
2034 struct iw_request_info *info,
2035 struct iw_param *vwrq,
2039 int error, disable, txpwrdbm;
2042 WL_TRACE(("%s: SIOCGIWTXPOW\n", dev->name));
2044 if ((error = dev_wlc_ioctl(dev, WLC_GET_RADIO, &disable, sizeof(disable))) ||
2045 (error = dev_wlc_intvar_get(dev, "qtxpower", &txpwrdbm)))
2048 disable = dtoh32(disable);
2049 result = (uint8)(txpwrdbm & ~WL_TXPWR_OVERRIDE);
2050 vwrq->value = (int32)bcm_qdbm_to_mw(result);
2052 vwrq->disabled = (disable & (WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE)) ? 1 : 0;
2053 vwrq->flags = IW_TXPOW_MWATT;
2058 #if WIRELESS_EXT > 10
2061 struct net_device *dev,
2062 struct iw_request_info *info,
2063 struct iw_param *vwrq,
2067 int error, lrl, srl;
2069 WL_TRACE(("%s: SIOCSIWRETRY\n", dev->name));
2071 /* Do not handle "off" or "lifetime" */
2072 if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME))
2075 /* Handle "[min|max] limit" */
2076 if (vwrq->flags & IW_RETRY_LIMIT) {
2077 /* "max limit" or just "limit" */
2078 #if WIRELESS_EXT > 20
2079 if ((vwrq->flags & IW_RETRY_LONG) ||(vwrq->flags & IW_RETRY_MAX) ||
2080 !((vwrq->flags & IW_RETRY_SHORT) || (vwrq->flags & IW_RETRY_MIN)))
2082 if ((vwrq->flags & IW_RETRY_MAX) || !(vwrq->flags & IW_RETRY_MIN))
2083 #endif /* WIRELESS_EXT > 20 */
2085 lrl = htod32(vwrq->value);
2086 if ((error = dev_wlc_ioctl(dev, WLC_SET_LRL, &lrl, sizeof(lrl))))
2089 /* "min limit" or just "limit" */
2090 #if WIRELESS_EXT > 20
2091 if ((vwrq->flags & IW_RETRY_SHORT) ||(vwrq->flags & IW_RETRY_MIN) ||
2092 !((vwrq->flags & IW_RETRY_LONG) || (vwrq->flags & IW_RETRY_MAX)))
2094 if ((vwrq->flags & IW_RETRY_MIN) || !(vwrq->flags & IW_RETRY_MAX))
2095 #endif /* WIRELESS_EXT > 20 */
2097 srl = htod32(vwrq->value);
2098 if ((error = dev_wlc_ioctl(dev, WLC_SET_SRL, &srl, sizeof(srl))))
2108 struct net_device *dev,
2109 struct iw_request_info *info,
2110 struct iw_param *vwrq,
2114 int error, lrl, srl;
2116 WL_TRACE(("%s: SIOCGIWRETRY\n", dev->name));
2118 vwrq->disabled = 0; /* Can't be disabled */
2120 /* Do not handle lifetime queries */
2121 if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
2124 /* Get retry limits */
2125 if ((error = dev_wlc_ioctl(dev, WLC_GET_LRL, &lrl, sizeof(lrl))) ||
2126 (error = dev_wlc_ioctl(dev, WLC_GET_SRL, &srl, sizeof(srl))))
2132 /* Note : by default, display the min retry number */
2133 if (vwrq->flags & IW_RETRY_MAX) {
2134 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
2137 vwrq->flags = IW_RETRY_LIMIT;
2140 vwrq->flags |= IW_RETRY_MIN;
2145 #endif /* WIRELESS_EXT > 10 */
2149 struct net_device *dev,
2150 struct iw_request_info *info,
2151 struct iw_point *dwrq,
2156 int error, val, wsec;
2158 WL_TRACE(("%s: SIOCSIWENCODE\n", dev->name));
2160 memset(&key, 0, sizeof(key));
2162 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2163 /* Find the current key */
2164 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
2165 val = htod32(key.index);
2166 if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
2173 if (key.index == DOT11_MAX_DEFAULT_KEYS)
2176 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2177 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
2181 /* Interpret "off" to mean no encryption */
2182 wsec = (dwrq->flags & IW_ENCODE_DISABLED) ? 0 : WEP_ENABLED;
2184 if ((error = dev_wlc_intvar_set(dev, "wsec", wsec)))
2187 /* Old API used to pass a NULL pointer instead of IW_ENCODE_NOKEY */
2188 if (!extra || !dwrq->length || (dwrq->flags & IW_ENCODE_NOKEY)) {
2189 /* Just select a new current key */
2190 val = htod32(key.index);
2191 if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, &val, sizeof(val))))
2194 key.len = dwrq->length;
2196 if (dwrq->length > sizeof(key.data))
2199 memcpy(key.data, extra, dwrq->length);
2201 key.flags = WL_PRIMARY_KEY;
2204 key.algo = CRYPTO_ALGO_WEP1;
2206 case WEP128_KEY_SIZE:
2207 key.algo = CRYPTO_ALGO_WEP128;
2209 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
2211 key.algo = CRYPTO_ALGO_TKIP;
2215 key.algo = CRYPTO_ALGO_AES_CCM;
2221 /* Set the new key/index */
2222 swap_key_from_BE(&key);
2223 if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key))))
2227 /* Interpret "restricted" to mean shared key authentication */
2228 val = (dwrq->flags & IW_ENCODE_RESTRICTED) ? 1 : 0;
2230 if ((error = dev_wlc_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val))))
2238 struct net_device *dev,
2239 struct iw_request_info *info,
2240 struct iw_point *dwrq,
2245 int error, val, wsec, auth;
2247 WL_TRACE(("%s: SIOCGIWENCODE\n", dev->name));
2249 /* assure default values of zero for things we don't touch */
2250 bzero(&key, sizeof(wl_wsec_key_t));
2252 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2253 /* Find the current key */
2254 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
2256 if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
2263 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2265 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
2270 if ((error = dev_wlc_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec))) ||
2271 (error = dev_wlc_ioctl(dev, WLC_GET_AUTH, &auth, sizeof(auth))))
2274 swap_key_to_BE(&key);
2276 wsec = dtoh32(wsec);
2277 auth = dtoh32(auth);
2278 /* Get key length */
2279 dwrq->length = MIN(IW_ENCODING_TOKEN_MAX, key.len);
2282 dwrq->flags = key.index + 1;
2283 if (!(wsec & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))) {
2284 /* Interpret "off" to mean no encryption */
2285 dwrq->flags |= IW_ENCODE_DISABLED;
2288 /* Interpret "restricted" to mean shared key authentication */
2289 dwrq->flags |= IW_ENCODE_RESTRICTED;
2293 if (dwrq->length && extra)
2294 memcpy(extra, key.data, dwrq->length);
2301 struct net_device *dev,
2302 struct iw_request_info *info,
2303 struct iw_param *vwrq,
2309 WL_TRACE(("%s: SIOCSIWPOWER\n", dev->name));
2311 pm = vwrq->disabled ? PM_OFF : PM_MAX;
2314 if ((error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm))))
2322 struct net_device *dev,
2323 struct iw_request_info *info,
2324 struct iw_param *vwrq,
2330 WL_TRACE(("%s: SIOCGIWPOWER\n", dev->name));
2332 if ((error = dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm))))
2336 vwrq->disabled = pm ? 0 : 1;
2337 vwrq->flags = IW_POWER_ALL_R;
2342 #if WIRELESS_EXT > 17
2345 struct net_device *dev,
2346 struct iw_request_info *info,
2347 struct iw_point *iwp,
2351 dev_wlc_bufvar_set(dev, "wpaie", extra, iwp->length);
2358 struct net_device *dev,
2359 struct iw_request_info *info,
2360 struct iw_point *iwp,
2364 WL_TRACE(("%s: SIOCGIWGENIE\n", dev->name));
2366 dev_wlc_bufvar_get(dev, "wpaie", extra, iwp->length);
2371 wl_iw_set_encodeext(
2372 struct net_device *dev,
2373 struct iw_request_info *info,
2374 struct iw_point *dwrq,
2380 struct iw_encode_ext *iwe;
2382 WL_TRACE(("%s: SIOCSIWENCODEEXT\n", dev->name));
2384 memset(&key, 0, sizeof(key));
2385 iwe = (struct iw_encode_ext *)extra;
2387 /* disable encryption completely */
2388 if (dwrq->flags & IW_ENCODE_DISABLED) {
2392 /* get the key index */
2394 if (dwrq->flags & IW_ENCODE_INDEX)
2395 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2397 key.len = iwe->key_len;
2399 /* Instead of bcast for ea address for default wep keys, driver needs it to be Null */
2400 if (!ETHER_ISMULTI(iwe->addr.sa_data))
2401 bcopy((void *)&iwe->addr.sa_data, (char *)&key.ea, ETHER_ADDR_LEN);
2403 /* check for key index change */
2405 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2406 WL_WSEC(("Changing the the primary Key to %d\n", key.index));
2407 /* change the key index .... */
2408 key.index = htod32(key.index);
2409 error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY,
2410 &key.index, sizeof(key.index));
2416 swap_key_from_BE(&key);
2417 error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2422 /* This case is used to allow an external 802.1x supplicant
2423 * to pass the PMK to the in-driver supplicant for use in
2424 * the 4-way handshake.
2426 else if (iwe->alg == IW_ENCODE_ALG_PMK) {
2429 char keystring[WSEC_MAX_PSK_LEN + 1];
2430 char* charptr = keystring;
2433 /* copy the raw hex key to the appropriate format */
2434 for (j = 0; j < (WSEC_MAX_PSK_LEN / 2); j++) {
2435 (void)snprintf(charptr, 3, "%02x", iwe->key[j]);
2438 len = strlen(keystring);
2439 pmk.key_len = htod16(len);
2440 bcopy(keystring, pmk.key, len);
2441 pmk.flags = htod16(WSEC_PASSPHRASE);
2443 WL_WSEC(("%s: set key %s\n", __FUNCTION__, keystring));
2444 error = dev_wlc_ioctl(dev, WLC_SET_WSEC_PMK, &pmk, sizeof(pmk));
2446 WL_ERROR(("%s: WLC_SET_WSEC_PMK error %d\n", __FUNCTION__, error));
2452 if (iwe->key_len > sizeof(key.data))
2455 WL_WSEC(("Setting the key index %d\n", key.index));
2456 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2457 WL_WSEC(("key is a Primary Key\n"));
2458 key.flags = WL_PRIMARY_KEY;
2461 bcopy((void *)iwe->key, key.data, iwe->key_len);
2463 if (iwe->alg == IW_ENCODE_ALG_TKIP) {
2465 bcopy(&key.data[24], keybuf, sizeof(keybuf));
2466 bcopy(&key.data[16], &key.data[24], sizeof(keybuf));
2467 bcopy(keybuf, &key.data[16], sizeof(keybuf));
2471 if (iwe->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
2473 ivptr = (uchar *)iwe->rx_seq;
2474 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
2475 (ivptr[3] << 8) | ivptr[2];
2476 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
2477 key.iv_initialized = TRUE;
2481 case IW_ENCODE_ALG_NONE:
2482 key.algo = CRYPTO_ALGO_OFF;
2484 case IW_ENCODE_ALG_WEP:
2485 if (iwe->key_len == WEP1_KEY_SIZE)
2486 key.algo = CRYPTO_ALGO_WEP1;
2488 key.algo = CRYPTO_ALGO_WEP128;
2490 case IW_ENCODE_ALG_TKIP:
2491 key.algo = CRYPTO_ALGO_TKIP;
2493 case IW_ENCODE_ALG_CCMP:
2494 key.algo = CRYPTO_ALGO_AES_CCM;
2499 swap_key_from_BE(&key);
2501 dhd_wait_pend8021x(dev);
2503 error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2512 pmkid_list_t pmkids;
2513 pmkid_t foo[MAXPMKID-1];
2517 struct net_device *dev,
2518 struct iw_request_info *info,
2519 struct iw_param *vwrq,
2523 struct iw_pmksa *iwpmksa;
2525 char eabuf[ETHER_ADDR_STR_LEN];
2526 pmkid_t * pmkid_array = pmkid_list.pmkids.pmkid;
2528 WL_TRACE(("%s: SIOCSIWPMKSA\n", dev->name));
2529 iwpmksa = (struct iw_pmksa *)extra;
2530 bzero((char *)eabuf, ETHER_ADDR_STR_LEN);
2531 if (iwpmksa->cmd == IW_PMKSA_FLUSH) {
2532 WL_TRACE(("wl_iw_set_pmksa - IW_PMKSA_FLUSH\n"));
2533 bzero((char *)&pmkid_list, sizeof(pmkid_list));
2535 if (iwpmksa->cmd == IW_PMKSA_REMOVE) {
2536 pmkid_list_t pmkid, *pmkidptr;
2538 bcopy(&iwpmksa->bssid.sa_data[0], &pmkidptr->pmkid[0].BSSID, ETHER_ADDR_LEN);
2539 bcopy(&iwpmksa->pmkid[0], &pmkidptr->pmkid[0].PMKID, WPA2_PMKID_LEN);
2542 WL_TRACE(("wl_iw_set_pmksa,IW_PMKSA_REMOVE - PMKID: %s = ",
2543 bcm_ether_ntoa(&pmkidptr->pmkid[0].BSSID,
2545 for (j = 0; j < WPA2_PMKID_LEN; j++)
2546 WL_TRACE(("%02x ", pmkidptr->pmkid[0].PMKID[j]));
2549 for (i = 0; i < pmkid_list.pmkids.npmkid; i++)
2550 if (!bcmp(&iwpmksa->bssid.sa_data[0], &pmkid_array[i].BSSID,
2553 for (; i < pmkid_list.pmkids.npmkid; i++) {
2554 bcopy(&pmkid_array[i+1].BSSID,
2555 &pmkid_array[i].BSSID,
2557 bcopy(&pmkid_array[i+1].PMKID,
2558 &pmkid_array[i].PMKID,
2561 pmkid_list.pmkids.npmkid--;
2563 if (iwpmksa->cmd == IW_PMKSA_ADD) {
2564 bcopy(&iwpmksa->bssid.sa_data[0],
2565 &pmkid_array[pmkid_list.pmkids.npmkid].BSSID,
2567 bcopy(&iwpmksa->pmkid[0], &pmkid_array[pmkid_list.pmkids.npmkid].PMKID,
2572 k = pmkid_list.pmkids.npmkid;
2574 WL_TRACE(("wl_iw_set_pmksa,IW_PMKSA_ADD - PMKID: %s = ",
2575 bcm_ether_ntoa(&pmkid_array[k].BSSID,
2577 for (j = 0; j < WPA2_PMKID_LEN; j++)
2578 WL_TRACE(("%02x ", pmkid_array[k].PMKID[j]));
2581 pmkid_list.pmkids.npmkid++;
2583 WL_TRACE(("PRINTING pmkid LIST - No of elements %d\n", pmkid_list.pmkids.npmkid));
2584 for (i = 0; i < pmkid_list.pmkids.npmkid; i++) {
2586 WL_TRACE(("PMKID[%d]: %s = ", i,
2587 bcm_ether_ntoa(&pmkid_array[i].BSSID,
2589 for (j = 0; j < WPA2_PMKID_LEN; j++)
2590 WL_TRACE(("%02x ", pmkid_array[i].PMKID[j]));
2594 dev_wlc_bufvar_set(dev, "pmkid_info", (char *)&pmkid_list, sizeof(pmkid_list));
2599 wl_iw_get_encodeext(
2600 struct net_device *dev,
2601 struct iw_request_info *info,
2602 struct iw_param *vwrq,
2606 WL_TRACE(("%s: SIOCGIWENCODEEXT\n", dev->name));
2612 struct net_device *dev,
2613 struct iw_request_info *info,
2614 struct iw_param *vwrq,
2621 uint32 cipher_combined;
2623 wl_iw_t *iw = IW_DEV_IF(dev);
2625 WL_TRACE(("%s: SIOCSIWAUTH\n", dev->name));
2627 paramid = vwrq->flags & IW_AUTH_INDEX;
2628 paramval = vwrq->value;
2630 WL_TRACE(("%s: SIOCSIWAUTH, paramid = 0x%0x, paramval = 0x%0x\n",
2631 dev->name, paramid, paramval));
2635 case IW_AUTH_WPA_VERSION:
2636 /* supported wpa version disabled or wpa or wpa2 */
2637 if (paramval & IW_AUTH_WPA_VERSION_DISABLED)
2638 val = WPA_AUTH_DISABLED;
2639 else if (paramval & (IW_AUTH_WPA_VERSION_WPA))
2640 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
2641 else if (paramval & IW_AUTH_WPA_VERSION_WPA2)
2642 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
2643 WL_TRACE(("%s: %d: setting wpa_auth to 0x%0x\n", __FUNCTION__, __LINE__, val));
2644 if ((error = dev_wlc_intvar_set(dev, "wpa_auth", val)))
2648 case IW_AUTH_CIPHER_PAIRWISE:
2649 case IW_AUTH_CIPHER_GROUP: {
2652 if (paramid == IW_AUTH_CIPHER_PAIRWISE) {
2653 iw->pwsec = paramval;
2656 iw->gwsec = paramval;
2659 if ((error = dev_wlc_intvar_get(dev, "wsec", &val))) {
2660 WL_ERROR(("%s: wsec error %d\n", __FUNCTION__, error));
2663 WL_WSEC(("%s: get wsec=0x%x\n", __FUNCTION__, val));
2665 cipher_combined = iw->gwsec | iw->pwsec;
2666 val &= ~(WEP_ENABLED | TKIP_ENABLED | AES_ENABLED);
2667 if (cipher_combined & (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
2669 if (cipher_combined & IW_AUTH_CIPHER_TKIP)
2670 val |= TKIP_ENABLED;
2671 if (cipher_combined & IW_AUTH_CIPHER_CCMP)
2674 if (iw->privacy_invoked && !val) {
2675 WL_WSEC(("%s: %s: 'Privacy invoked' TRUE but clearing wsec, assuming "
2676 "we're a WPS enrollee\n", dev->name, __FUNCTION__));
2677 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", TRUE))) {
2678 WL_WSEC(("Failed to set iovar is_WPS_enrollee\n"));
2682 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
2683 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
2688 WL_WSEC(("%s: set wsec=0x%x\n", __FUNCTION__, val));
2689 if ((error = dev_wlc_intvar_set(dev, "wsec", val))) {
2690 WL_ERROR(("%s: wsec error %d\n", __FUNCTION__, error));
2694 /* Ensure in-dongle supplicant is turned on when FBT wants to do the 4-way
2697 if (dev_wlc_intvar_get(dev, "fbt_cap", &fbt_cap) == 0) {
2698 WL_WSEC(("%s: get fbt_cap=0x%x\n", __FUNCTION__, fbt_cap));
2699 if (fbt_cap == WLC_FBT_CAP_DRV_4WAY_AND_REASSOC) {
2700 if ((paramid == IW_AUTH_CIPHER_PAIRWISE) && (val & AES_ENABLED)) {
2701 if ((error = dev_wlc_intvar_set(dev, "sup_wpa", 1))) {
2702 WL_ERROR(("%s: sup_wpa 1 error %d\n", __FUNCTION__, error));
2706 else if (val == 0) {
2707 if ((error = dev_wlc_intvar_set(dev, "sup_wpa", 0))) {
2708 WL_ERROR(("%s: sup_wpa 0 error %d\n", __FUNCTION__, error));
2717 case IW_AUTH_KEY_MGMT:
2718 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val))) {
2719 WL_ERROR(("%s: wpa_auth error %d\n", __FUNCTION__, error));
2722 WL_WSEC(("%s: get wpa_auth to %d\n", __FUNCTION__, val));
2724 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
2725 if (paramval & (IW_AUTH_KEY_MGMT_FT_PSK | IW_AUTH_KEY_MGMT_PSK))
2728 val = WPA_AUTH_UNSPECIFIED;
2729 if (paramval & (IW_AUTH_KEY_MGMT_FT_802_1X | IW_AUTH_KEY_MGMT_FT_PSK))
2730 val |= WPA2_AUTH_FT;
2732 else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
2733 if (paramval & (IW_AUTH_KEY_MGMT_FT_PSK | IW_AUTH_KEY_MGMT_PSK))
2734 val = WPA2_AUTH_PSK;
2736 val = WPA2_AUTH_UNSPECIFIED;
2737 if (paramval & (IW_AUTH_KEY_MGMT_FT_802_1X | IW_AUTH_KEY_MGMT_FT_PSK))
2738 val |= WPA2_AUTH_FT;
2740 WL_TRACE(("%s: %d: setting wpa_auth to %d\n", __FUNCTION__, __LINE__, val));
2741 if ((error = dev_wlc_intvar_set(dev, "wpa_auth", val)))
2745 case IW_AUTH_TKIP_COUNTERMEASURES:
2746 dev_wlc_bufvar_set(dev, "tkip_countermeasures", (char *)¶mval, 1);
2749 case IW_AUTH_80211_AUTH_ALG:
2751 WL_ERROR(("Setting the D11auth %d\n", paramval));
2752 if (paramval & IW_AUTH_ALG_OPEN_SYSTEM)
2754 else if (paramval & IW_AUTH_ALG_SHARED_KEY)
2758 if (!error && (error = dev_wlc_intvar_set(dev, "auth", val)))
2762 case IW_AUTH_WPA_ENABLED:
2763 if (paramval == 0) {
2765 WL_TRACE(("%s: %d: setting wpa_auth to %d\n", __FUNCTION__, __LINE__, val));
2766 error = dev_wlc_intvar_set(dev, "wpa_auth", val);
2770 /* If WPA is enabled, wpa_auth is set elsewhere */
2774 case IW_AUTH_DROP_UNENCRYPTED:
2775 dev_wlc_bufvar_set(dev, "wsec_restrict", (char *)¶mval, 1);
2778 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2779 dev_wlc_bufvar_set(dev, "rx_unencrypted_eapol", (char *)¶mval, 1);
2782 #if WIRELESS_EXT > 17
2784 case IW_AUTH_ROAMING_CONTROL:
2785 WL_TRACE(("%s: IW_AUTH_ROAMING_CONTROL\n", __FUNCTION__));
2786 /* driver control or user space app control */
2789 case IW_AUTH_PRIVACY_INVOKED: {
2792 if (paramval == 0) {
2793 iw->privacy_invoked = FALSE;
2794 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
2795 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
2799 iw->privacy_invoked = TRUE;
2800 if ((error = dev_wlc_intvar_get(dev, "wsec", &wsec)))
2803 if (!WSEC_ENABLED(wsec)) {
2804 /* if privacy is true, but wsec is false, we are a WPS enrollee */
2805 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", TRUE))) {
2806 WL_WSEC(("Failed to set iovar is_WPS_enrollee\n"));
2810 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
2811 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
2820 #endif /* WIRELESS_EXT > 17 */
2828 #define VAL_PSK(_val) (((_val) & WPA_AUTH_PSK) || ((_val) & WPA2_AUTH_PSK))
2832 struct net_device *dev,
2833 struct iw_request_info *info,
2834 struct iw_param *vwrq,
2842 wl_iw_t *iw = IW_DEV_IF(dev);
2844 WL_TRACE(("%s: SIOCGIWAUTH\n", dev->name));
2846 paramid = vwrq->flags & IW_AUTH_INDEX;
2849 case IW_AUTH_WPA_VERSION:
2850 /* supported wpa version disabled or wpa or wpa2 */
2851 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
2853 if (val & (WPA_AUTH_NONE | WPA_AUTH_DISABLED))
2854 paramval = IW_AUTH_WPA_VERSION_DISABLED;
2855 else if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED))
2856 paramval = IW_AUTH_WPA_VERSION_WPA;
2857 else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED))
2858 paramval = IW_AUTH_WPA_VERSION_WPA2;
2861 case IW_AUTH_CIPHER_PAIRWISE:
2862 paramval = iw->pwsec;
2865 case IW_AUTH_CIPHER_GROUP:
2866 paramval = iw->gwsec;
2869 case IW_AUTH_KEY_MGMT:
2871 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
2874 paramval = IW_AUTH_KEY_MGMT_PSK;
2876 paramval = IW_AUTH_KEY_MGMT_802_1X;
2879 case IW_AUTH_TKIP_COUNTERMEASURES:
2880 dev_wlc_bufvar_get(dev, "tkip_countermeasures", (char *)¶mval, 1);
2883 case IW_AUTH_DROP_UNENCRYPTED:
2884 dev_wlc_bufvar_get(dev, "wsec_restrict", (char *)¶mval, 1);
2887 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2888 dev_wlc_bufvar_get(dev, "rx_unencrypted_eapol", (char *)¶mval, 1);
2891 case IW_AUTH_80211_AUTH_ALG:
2892 /* open, shared, leap */
2893 if ((error = dev_wlc_intvar_get(dev, "auth", &val)))
2896 paramval = IW_AUTH_ALG_OPEN_SYSTEM;
2898 paramval = IW_AUTH_ALG_SHARED_KEY;
2900 case IW_AUTH_WPA_ENABLED:
2901 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
2909 #if WIRELESS_EXT > 17
2911 case IW_AUTH_ROAMING_CONTROL:
2912 WL_ERROR(("%s: IW_AUTH_ROAMING_CONTROL\n", __FUNCTION__));
2913 /* driver control or user space app control */
2916 case IW_AUTH_PRIVACY_INVOKED:
2917 paramval = iw->privacy_invoked;
2920 #endif /* WIRELESS_EXT > 17 */
2922 vwrq->value = paramval;
2925 #endif /* WIRELESS_EXT > 17 */
2927 static const iw_handler wl_iw_handler[] =
2929 (iw_handler) wl_iw_config_commit, /* SIOCSIWCOMMIT */
2930 (iw_handler) wl_iw_get_name, /* SIOCGIWNAME */
2931 (iw_handler) NULL, /* SIOCSIWNWID */
2932 (iw_handler) NULL, /* SIOCGIWNWID */
2933 (iw_handler) wl_iw_set_freq, /* SIOCSIWFREQ */
2934 (iw_handler) wl_iw_get_freq, /* SIOCGIWFREQ */
2935 (iw_handler) wl_iw_set_mode, /* SIOCSIWMODE */
2936 (iw_handler) wl_iw_get_mode, /* SIOCGIWMODE */
2937 (iw_handler) NULL, /* SIOCSIWSENS */
2938 (iw_handler) NULL, /* SIOCGIWSENS */
2939 (iw_handler) NULL, /* SIOCSIWRANGE */
2940 (iw_handler) wl_iw_get_range, /* SIOCGIWRANGE */
2941 (iw_handler) NULL, /* SIOCSIWPRIV */
2942 (iw_handler) NULL, /* SIOCGIWPRIV */
2943 (iw_handler) NULL, /* SIOCSIWSTATS */
2944 (iw_handler) NULL, /* SIOCGIWSTATS */
2945 (iw_handler) wl_iw_set_spy, /* SIOCSIWSPY */
2946 (iw_handler) wl_iw_get_spy, /* SIOCGIWSPY */
2947 (iw_handler) NULL, /* -- hole -- */
2948 (iw_handler) NULL, /* -- hole -- */
2949 (iw_handler) wl_iw_set_wap, /* SIOCSIWAP */
2950 (iw_handler) wl_iw_get_wap, /* SIOCGIWAP */
2951 #if WIRELESS_EXT > 17
2952 (iw_handler) wl_iw_mlme, /* SIOCSIWMLME */
2954 (iw_handler) NULL, /* -- hole -- */
2956 (iw_handler) wl_iw_iscan_get_aplist, /* SIOCGIWAPLIST */
2957 #if WIRELESS_EXT > 13
2958 (iw_handler) wl_iw_iscan_set_scan, /* SIOCSIWSCAN */
2959 (iw_handler) wl_iw_iscan_get_scan, /* SIOCGIWSCAN */
2960 #else /* WIRELESS_EXT > 13 */
2961 (iw_handler) NULL, /* SIOCSIWSCAN */
2962 (iw_handler) NULL, /* SIOCGIWSCAN */
2963 #endif /* WIRELESS_EXT > 13 */
2964 (iw_handler) wl_iw_set_essid, /* SIOCSIWESSID */
2965 (iw_handler) wl_iw_get_essid, /* SIOCGIWESSID */
2966 (iw_handler) wl_iw_set_nick, /* SIOCSIWNICKN */
2967 (iw_handler) wl_iw_get_nick, /* SIOCGIWNICKN */
2968 (iw_handler) NULL, /* -- hole -- */
2969 (iw_handler) NULL, /* -- hole -- */
2970 (iw_handler) wl_iw_set_rate, /* SIOCSIWRATE */
2971 (iw_handler) wl_iw_get_rate, /* SIOCGIWRATE */
2972 (iw_handler) wl_iw_set_rts, /* SIOCSIWRTS */
2973 (iw_handler) wl_iw_get_rts, /* SIOCGIWRTS */
2974 (iw_handler) wl_iw_set_frag, /* SIOCSIWFRAG */
2975 (iw_handler) wl_iw_get_frag, /* SIOCGIWFRAG */
2976 (iw_handler) wl_iw_set_txpow, /* SIOCSIWTXPOW */
2977 (iw_handler) wl_iw_get_txpow, /* SIOCGIWTXPOW */
2978 #if WIRELESS_EXT > 10
2979 (iw_handler) wl_iw_set_retry, /* SIOCSIWRETRY */
2980 (iw_handler) wl_iw_get_retry, /* SIOCGIWRETRY */
2981 #endif /* WIRELESS_EXT > 10 */
2982 (iw_handler) wl_iw_set_encode, /* SIOCSIWENCODE */
2983 (iw_handler) wl_iw_get_encode, /* SIOCGIWENCODE */
2984 (iw_handler) wl_iw_set_power, /* SIOCSIWPOWER */
2985 (iw_handler) wl_iw_get_power, /* SIOCGIWPOWER */
2986 #if WIRELESS_EXT > 17
2987 (iw_handler) NULL, /* -- hole -- */
2988 (iw_handler) NULL, /* -- hole -- */
2989 (iw_handler) wl_iw_set_wpaie, /* SIOCSIWGENIE */
2990 (iw_handler) wl_iw_get_wpaie, /* SIOCGIWGENIE */
2991 (iw_handler) wl_iw_set_wpaauth, /* SIOCSIWAUTH */
2992 (iw_handler) wl_iw_get_wpaauth, /* SIOCGIWAUTH */
2993 (iw_handler) wl_iw_set_encodeext, /* SIOCSIWENCODEEXT */
2994 (iw_handler) wl_iw_get_encodeext, /* SIOCGIWENCODEEXT */
2995 (iw_handler) wl_iw_set_pmksa, /* SIOCSIWPMKSA */
2996 #endif /* WIRELESS_EXT > 17 */
2999 #if WIRELESS_EXT > 12
3001 WL_IW_SET_LEDDC = SIOCIWFIRSTPRIV,
3007 static iw_handler wl_iw_priv_handler[] = {
3014 static struct iw_priv_args wl_iw_priv_args[] = {
3017 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3023 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3029 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3036 const struct iw_handler_def wl_iw_handler_def =
3038 .num_standard = ARRAYSIZE(wl_iw_handler),
3039 .num_private = ARRAY_SIZE(wl_iw_priv_handler),
3040 .num_private_args = ARRAY_SIZE(wl_iw_priv_args),
3041 .standard = (const iw_handler *) wl_iw_handler,
3042 .private = wl_iw_priv_handler,
3043 .private_args = wl_iw_priv_args,
3044 #if WIRELESS_EXT >= 19
3045 get_wireless_stats: dhd_get_wireless_stats,
3046 #endif /* WIRELESS_EXT >= 19 */
3048 #endif /* WIRELESS_EXT > 12 */
3052 struct net_device *dev,
3057 struct iwreq *wrq = (struct iwreq *) rq;
3058 struct iw_request_info info;
3061 size_t token_size = 1;
3062 int max_tokens = 0, ret = 0;
3064 if (cmd < SIOCIWFIRST ||
3065 IW_IOCTL_IDX(cmd) >= ARRAYSIZE(wl_iw_handler) ||
3066 !(handler = wl_iw_handler[IW_IOCTL_IDX(cmd)]))
3075 max_tokens = IW_ESSID_MAX_SIZE + 1;
3080 #if WIRELESS_EXT > 17
3081 case SIOCSIWENCODEEXT:
3082 case SIOCGIWENCODEEXT:
3084 max_tokens = IW_ENCODING_TOKEN_MAX;
3088 max_tokens = sizeof(struct iw_range);
3092 token_size = sizeof(struct sockaddr) + sizeof(struct iw_quality);
3093 max_tokens = IW_MAX_AP;
3096 #if WIRELESS_EXT > 13
3099 max_tokens = wrq->u.data.length;
3101 max_tokens = IW_SCAN_MAX_DATA;
3103 #endif /* WIRELESS_EXT > 13 */
3106 token_size = sizeof(struct sockaddr);
3107 max_tokens = IW_MAX_SPY;
3111 token_size = sizeof(struct sockaddr) + sizeof(struct iw_quality);
3112 max_tokens = IW_MAX_SPY;
3118 if (max_tokens && wrq->u.data.pointer) {
3119 if (wrq->u.data.length > max_tokens)
3122 if (!(extra = kmalloc(max_tokens * token_size, GFP_KERNEL)))
3125 if (copy_from_user(extra, wrq->u.data.pointer, wrq->u.data.length * token_size)) {
3134 ret = handler(dev, &info, &wrq->u, extra);
3137 if (copy_to_user(wrq->u.data.pointer, extra, wrq->u.data.length * token_size)) {
3148 /* Convert a connection status event into a connection status string.
3149 * Returns TRUE if a matching connection status string was found.
3152 wl_iw_conn_status_str(uint32 event_type, uint32 status, uint32 reason,
3153 char* stringBuf, uint buflen)
3155 typedef struct conn_fail_event_map_t {
3156 uint32 inEvent; /* input: event type to match */
3157 uint32 inStatus; /* input: event status code to match */
3158 uint32 inReason; /* input: event reason code to match */
3159 const char* outName; /* output: failure type */
3160 const char* outCause; /* output: failure cause */
3161 } conn_fail_event_map_t;
3163 /* Map of WLC_E events to connection failure strings */
3164 # define WL_IW_DONT_CARE 9999
3165 const conn_fail_event_map_t event_map [] = {
3166 /* inEvent inStatus inReason */
3167 /* outName outCause */
3168 {WLC_E_SET_SSID, WLC_E_STATUS_SUCCESS, WL_IW_DONT_CARE,
3170 {WLC_E_SET_SSID, WLC_E_STATUS_NO_NETWORKS, WL_IW_DONT_CARE,
3171 "Conn", "NoNetworks"},
3172 {WLC_E_SET_SSID, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3173 "Conn", "ConfigMismatch"},
3174 {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_PRUNE_ENCR_MISMATCH,
3175 "Conn", "EncrypMismatch"},
3176 {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_RSN_MISMATCH,
3177 "Conn", "RsnMismatch"},
3178 {WLC_E_AUTH, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
3179 "Conn", "AuthTimeout"},
3180 {WLC_E_AUTH, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3181 "Conn", "AuthFail"},
3182 {WLC_E_AUTH, WLC_E_STATUS_NO_ACK, WL_IW_DONT_CARE,
3183 "Conn", "AuthNoAck"},
3184 {WLC_E_REASSOC, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3185 "Conn", "ReassocFail"},
3186 {WLC_E_REASSOC, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
3187 "Conn", "ReassocTimeout"},
3188 {WLC_E_REASSOC, WLC_E_STATUS_ABORT, WL_IW_DONT_CARE,
3189 "Conn", "ReassocAbort"},
3190 {WLC_E_PSK_SUP, WLC_SUP_KEYED, WL_IW_DONT_CARE,
3191 "Sup", "ConnSuccess"},
3192 {WLC_E_PSK_SUP, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3193 "Sup", "WpaHandshakeFail"},
3194 {WLC_E_DEAUTH_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3196 {WLC_E_DISASSOC_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3197 "Conn", "DisassocInd"},
3198 {WLC_E_DISASSOC, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3202 const char* name = "";
3203 const char* cause = NULL;
3206 /* Search the event map table for a matching event */
3207 for (i = 0; i < sizeof(event_map)/sizeof(event_map[0]); i++) {
3208 const conn_fail_event_map_t* row = &event_map[i];
3209 if (row->inEvent == event_type &&
3210 (row->inStatus == status || row->inStatus == WL_IW_DONT_CARE) &&
3211 (row->inReason == reason || row->inReason == WL_IW_DONT_CARE)) {
3212 name = row->outName;
3213 cause = row->outCause;
3218 /* If found, generate a connection failure string and return TRUE */
3220 memset(stringBuf, 0, buflen);
3221 (void)snprintf(stringBuf, buflen, "%s %s %02d %02d", name, cause, status, reason);
3222 WL_TRACE(("Connection status: %s\n", stringBuf));
3229 #if (WIRELESS_EXT > 14)
3230 /* Check if we have received an event that indicates connection failure
3231 * If so, generate a connection failure report string.
3232 * The caller supplies a buffer to hold the generated string.
3235 wl_iw_check_conn_fail(wl_event_msg_t *e, char* stringBuf, uint buflen)
3237 uint32 event = ntoh32(e->event_type);
3238 uint32 status = ntoh32(e->status);
3239 uint32 reason = ntoh32(e->reason);
3241 if (wl_iw_conn_status_str(event, status, reason, stringBuf, buflen)) {
3248 #endif /* WIRELESS_EXT > 14 */
3250 #ifndef IW_CUSTOM_MAX
3251 #define IW_CUSTOM_MAX 256 /* size of extra buffer used for translation of events */
3252 #endif /* IW_CUSTOM_MAX */
3255 wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void* data)
3257 #if WIRELESS_EXT > 13
3258 union iwreq_data wrqu;
3259 char extra[IW_CUSTOM_MAX + 1];
3261 uint32 event_type = ntoh32(e->event_type);
3262 uint16 flags = ntoh16(e->flags);
3263 uint32 datalen = ntoh32(e->datalen);
3264 uint32 status = ntoh32(e->status);
3266 memset(&wrqu, 0, sizeof(wrqu));
3267 memset(extra, 0, sizeof(extra));
3269 memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN);
3270 wrqu.addr.sa_family = ARPHRD_ETHER;
3272 switch (event_type) {
3276 #if WIRELESS_EXT > 14
3278 case WLC_E_ASSOC_IND:
3279 case WLC_E_REASSOC_IND:
3280 cmd = IWEVREGISTERED;
3282 case WLC_E_DEAUTH_IND:
3283 case WLC_E_DISASSOC_IND:
3285 wrqu.data.length = strlen(extra);
3286 bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
3287 bzero(&extra, ETHER_ADDR_LEN);
3292 wrqu.data.length = strlen(extra);
3293 if (!(flags & WLC_EVENT_MSG_LINK)) {
3294 printf("%s: Link Down with BSSID="MACSTR"\n", __FUNCTION__,
3295 MAC2STR((u8 *)wrqu.addr.sa_data));
3296 bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
3297 bzero(&extra, ETHER_ADDR_LEN);
3299 printf("%s: Link UP with BSSID="MACSTR"\n", __FUNCTION__,
3300 MAC2STR((u8 *)wrqu.addr.sa_data));
3303 case WLC_E_ACTION_FRAME:
3305 if (datalen + 1 <= sizeof(extra)) {
3306 wrqu.data.length = datalen + 1;
3307 extra[0] = WLC_E_ACTION_FRAME;
3308 memcpy(&extra[1], data, datalen);
3309 WL_TRACE(("WLC_E_ACTION_FRAME len %d \n", wrqu.data.length));
3313 case WLC_E_ACTION_FRAME_COMPLETE:
3315 if (sizeof(status) + 1 <= sizeof(extra)) {
3316 wrqu.data.length = sizeof(status) + 1;
3317 extra[0] = WLC_E_ACTION_FRAME_COMPLETE;
3318 memcpy(&extra[1], &status, sizeof(status));
3319 WL_TRACE(("wl_iw_event status %d \n", status));
3322 #endif /* WIRELESS_EXT > 14 */
3323 #if WIRELESS_EXT > 17
3324 case WLC_E_MIC_ERROR: {
3325 struct iw_michaelmicfailure *micerrevt = (struct iw_michaelmicfailure *)&extra;
3326 cmd = IWEVMICHAELMICFAILURE;
3327 wrqu.data.length = sizeof(struct iw_michaelmicfailure);
3328 if (flags & WLC_EVENT_MSG_GROUP)
3329 micerrevt->flags |= IW_MICFAILURE_GROUP;
3331 micerrevt->flags |= IW_MICFAILURE_PAIRWISE;
3332 memcpy(micerrevt->src_addr.sa_data, &e->addr, ETHER_ADDR_LEN);
3333 micerrevt->src_addr.sa_family = ARPHRD_ETHER;
3338 case WLC_E_ASSOC_REQ_IE:
3339 cmd = IWEVASSOCREQIE;
3340 wrqu.data.length = datalen;
3341 if (datalen < sizeof(extra))
3342 memcpy(extra, data, datalen);
3345 case WLC_E_ASSOC_RESP_IE:
3346 cmd = IWEVASSOCRESPIE;
3347 wrqu.data.length = datalen;
3348 if (datalen < sizeof(extra))
3349 memcpy(extra, data, datalen);
3352 case WLC_E_PMKID_CACHE: {
3353 struct iw_pmkid_cand *iwpmkidcand = (struct iw_pmkid_cand *)&extra;
3354 pmkid_cand_list_t *pmkcandlist;
3355 pmkid_cand_t *pmkidcand;
3361 cmd = IWEVPMKIDCAND;
3363 count = ntoh32_ua((uint8 *)&pmkcandlist->npmkid_cand);
3364 wrqu.data.length = sizeof(struct iw_pmkid_cand);
3365 pmkidcand = pmkcandlist->pmkid_cand;
3367 bzero(iwpmkidcand, sizeof(struct iw_pmkid_cand));
3368 if (pmkidcand->preauth)
3369 iwpmkidcand->flags |= IW_PMKID_CAND_PREAUTH;
3370 bcopy(&pmkidcand->BSSID, &iwpmkidcand->bssid.sa_data,
3372 wireless_send_event(dev, cmd, &wrqu, extra);
3378 #endif /* WIRELESS_EXT > 17 */
3380 case WLC_E_SCAN_COMPLETE:
3381 #if WIRELESS_EXT > 14
3384 WL_TRACE(("event WLC_E_SCAN_COMPLETE\n"));
3385 // terence 20150224: fix "wlan0: (WE) : Wireless Event too big (65306)"
3386 memset(&wrqu, 0, sizeof(wrqu));
3387 if ((g_iscan) && (g_iscan->sysioc_pid >= 0) &&
3388 (g_iscan->iscan_state != ISCAN_STATE_IDLE))
3389 up(&g_iscan->sysioc_sem);
3393 /* Cannot translate event */
3398 if (cmd == SIOCGIWSCAN) {
3399 if ((!g_iscan) || (g_iscan->sysioc_pid < 0)) {
3400 wireless_send_event(dev, cmd, &wrqu, NULL);
3403 wireless_send_event(dev, cmd, &wrqu, extra);
3406 #if WIRELESS_EXT > 14
3407 /* Look for WLC events that indicate a connection failure.
3408 * If found, generate an IWEVCUSTOM event.
3410 memset(extra, 0, sizeof(extra));
3411 if (wl_iw_check_conn_fail(e, extra, sizeof(extra))) {
3413 wrqu.data.length = strlen(extra);
3414 wireless_send_event(dev, cmd, &wrqu, extra);
3416 #endif /* WIRELESS_EXT > 14 */
3418 #endif /* WIRELESS_EXT > 13 */
3422 static int wl_iw_get_wireless_stats_cbfn(void *ctx, uint8 *data, uint16 type, uint16 len)
3424 struct iw_statistics *wstats = ctx;
3428 case WL_CNT_XTLV_WLC: {
3429 wl_cnt_wlc_t *cnt = (wl_cnt_wlc_t *)data;
3430 if (len > sizeof(wl_cnt_wlc_t)) {
3431 printf("counter structure length invalid! %d > %d\n",
3432 len, (int)sizeof(wl_cnt_wlc_t));
3434 wstats->discard.nwid = 0;
3435 wstats->discard.code = dtoh32(cnt->rxundec);
3436 wstats->discard.fragment = dtoh32(cnt->rxfragerr);
3437 wstats->discard.retries = dtoh32(cnt->txfail);
3438 wstats->discard.misc = dtoh32(cnt->rxrunt) + dtoh32(cnt->rxgiant);
3439 wstats->miss.beacon = 0;
3440 WL_TRACE(("wl_iw_get_wireless_stats counters txframe=%d txbyte=%d\n",
3441 dtoh32(cnt->txframe), dtoh32(cnt->txbyte)));
3442 WL_TRACE(("wl_iw_get_wireless_stats counters rxundec=%d\n",
3443 dtoh32(cnt->rxundec)));
3444 WL_TRACE(("wl_iw_get_wireless_stats counters txfail=%d\n",
3445 dtoh32(cnt->txfail)));
3446 WL_TRACE(("wl_iw_get_wireless_stats counters rxfragerr=%d\n",
3447 dtoh32(cnt->rxfragerr)));
3448 WL_TRACE(("wl_iw_get_wireless_stats counters rxrunt=%d\n",
3449 dtoh32(cnt->rxrunt)));
3450 WL_TRACE(("wl_iw_get_wireless_stats counters rxgiant=%d\n",
3451 dtoh32(cnt->rxgiant)));
3454 case WL_CNT_XTLV_CNTV_LE10_UCODE:
3455 case WL_CNT_XTLV_LT40_UCODE_V1:
3456 case WL_CNT_XTLV_GE40_UCODE_V1:
3458 /* Offsets of rxfrmtoolong and rxbadplcp are the same in
3459 * wl_cnt_v_le10_mcst_t, wl_cnt_lt40mcst_v1_t, and wl_cnt_ge40mcst_v1_t.
3460 * So we can just cast to wl_cnt_v_le10_mcst_t here.
3462 wl_cnt_v_le10_mcst_t *cnt = (wl_cnt_v_le10_mcst_t *)data;
3463 if (len != WL_CNT_MCST_STRUCT_SZ) {
3464 printf("counter structure length mismatch! %d != %d\n",
3465 len, WL_CNT_MCST_STRUCT_SZ);
3467 WL_TRACE(("wl_iw_get_wireless_stats counters rxfrmtoolong=%d\n",
3468 dtoh32(cnt->rxfrmtoolong)));
3469 WL_TRACE(("wl_iw_get_wireless_stats counters rxbadplcp=%d\n",
3470 dtoh32(cnt->rxbadplcp)));
3475 WL_ERROR(("%s %d: Unsupported type %d\n", __FUNCTION__, __LINE__, type));
3482 int wl_iw_get_wireless_stats(struct net_device *dev, struct iw_statistics *wstats)
3488 #if WIRELESS_EXT > 11
3489 char *cntbuf = NULL;
3490 wl_cnt_info_t *cntinfo;
3493 #endif /* WIRELESS_EXT > 11 */
3496 if ((res = dev_wlc_ioctl(dev, WLC_GET_PHY_NOISE, &phy_noise, sizeof(phy_noise))))
3499 phy_noise = dtoh32(phy_noise);
3500 WL_TRACE(("wl_iw_get_wireless_stats phy noise=%d\n *****", phy_noise));
3503 if ((res = dev_wlc_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t))))
3506 rssi = dtoh32(scb_val.val);
3507 WL_TRACE(("wl_iw_get_wireless_stats rssi=%d ****** \n", rssi));
3508 if (rssi <= WL_IW_RSSI_NO_SIGNAL)
3509 wstats->qual.qual = 0;
3510 else if (rssi <= WL_IW_RSSI_VERY_LOW)
3511 wstats->qual.qual = 1;
3512 else if (rssi <= WL_IW_RSSI_LOW)
3513 wstats->qual.qual = 2;
3514 else if (rssi <= WL_IW_RSSI_GOOD)
3515 wstats->qual.qual = 3;
3516 else if (rssi <= WL_IW_RSSI_VERY_GOOD)
3517 wstats->qual.qual = 4;
3519 wstats->qual.qual = 5;
3521 /* Wraps to 0 if RSSI is 0 */
3522 wstats->qual.level = 0x100 + rssi;
3523 wstats->qual.noise = 0x100 + phy_noise;
3524 #if WIRELESS_EXT > 18
3525 wstats->qual.updated |= (IW_QUAL_ALL_UPDATED | IW_QUAL_DBM);
3527 wstats->qual.updated |= 7;
3528 #endif /* WIRELESS_EXT > 18 */
3530 #if WIRELESS_EXT > 11
3531 WL_TRACE(("wl_iw_get_wireless_stats counters=%d\n *****", WL_CNTBUF_MAX_SIZE));
3533 if (WL_CNTBUF_MAX_SIZE > MAX_WLIW_IOCTL_LEN)
3535 WL_ERROR(("wl_iw_get_wireless_stats buffer too short %d < %d\n",
3536 WL_CNTBUF_MAX_SIZE, MAX_WLIW_IOCTL_LEN));
3537 res = BCME_BUFTOOSHORT;
3541 cntbuf = kmalloc(WL_CNTBUF_MAX_SIZE, GFP_KERNEL);
3547 memset(cntbuf, 0, WL_CNTBUF_MAX_SIZE);
3548 res = dev_wlc_bufvar_get(dev, "counters", cntbuf, WL_CNTBUF_MAX_SIZE);
3551 WL_ERROR(("wl_iw_get_wireless_stats counters failed error=%d ****** \n", res));
3555 cntinfo = (wl_cnt_info_t *)cntbuf;
3556 cntinfo->version = dtoh16(cntinfo->version);
3557 cntinfo->datalen = dtoh16(cntinfo->datalen);
3558 ver = cntinfo->version;
3559 if (ver > WL_CNT_T_VERSION) {
3560 WL_TRACE(("\tIncorrect version of counters struct: expected %d; got %d\n",
3561 WL_CNT_T_VERSION, ver));
3566 if (ver == WL_CNT_VERSION_11) {
3567 wlc_rev_info_t revinfo;
3568 memset(&revinfo, 0, sizeof(revinfo));
3569 res = dev_wlc_ioctl(dev, WLC_GET_REVINFO, &revinfo, sizeof(revinfo));
3571 WL_ERROR(("%s: WLC_GET_REVINFO failed %d\n", __FUNCTION__, res));
3574 corerev = dtoh32(revinfo.corerev);
3578 res = wl_cntbuf_to_xtlv_format(NULL, cntinfo, WL_CNTBUF_MAX_SIZE, corerev);
3580 WL_ERROR(("%s: wl_cntbuf_to_xtlv_format failed %d\n", __FUNCTION__, res));
3584 if ((res = bcm_unpack_xtlv_buf(wstats, cntinfo->data, cntinfo->datalen,
3585 BCM_XTLV_OPTION_ALIGN32, wl_iw_get_wireless_stats_cbfn))) {
3589 #endif /* WIRELESS_EXT > 11 */
3592 #if WIRELESS_EXT > 11
3596 #endif /* WIRELESS_EXT > 11 */
3601 wl_iw_timerfunc(ulong data)
3603 iscan_info_t *iscan = (iscan_info_t *)data;
3604 iscan->timer_on = 0;
3605 if (iscan->iscan_state != ISCAN_STATE_IDLE) {
3606 WL_TRACE(("timer trigger\n"));
3607 up(&iscan->sysioc_sem);
3612 wl_iw_set_event_mask(struct net_device *dev)
3614 char eventmask[WL_EVENTING_MASK_LEN];
3615 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
3617 dev_iw_iovar_getbuf(dev, "event_msgs", "", 0, iovbuf, sizeof(iovbuf));
3618 bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
3619 setbit(eventmask, WLC_E_SCAN_COMPLETE);
3620 dev_iw_iovar_setbuf(dev, "event_msgs", eventmask, WL_EVENTING_MASK_LEN,
3621 iovbuf, sizeof(iovbuf));
3626 wl_iw_iscan_prep(wl_scan_params_t *params, wlc_ssid_t *ssid)
3630 memcpy(¶ms->bssid, ðer_bcast, ETHER_ADDR_LEN);
3631 params->bss_type = DOT11_BSSTYPE_ANY;
3632 params->scan_type = 0;
3633 params->nprobes = -1;
3634 params->active_time = -1;
3635 params->passive_time = -1;
3636 params->home_time = -1;
3637 params->channel_num = 0;
3639 params->nprobes = htod32(params->nprobes);
3640 params->active_time = htod32(params->active_time);
3641 params->passive_time = htod32(params->passive_time);
3642 params->home_time = htod32(params->home_time);
3643 if (ssid && ssid->SSID_len)
3644 memcpy(¶ms->ssid, ssid, sizeof(wlc_ssid_t));
3650 wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action)
3652 int params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_iscan_params_t, params));
3653 wl_iscan_params_t *params;
3656 if (ssid && ssid->SSID_len) {
3657 params_size += sizeof(wlc_ssid_t);
3659 params = (wl_iscan_params_t*)kmalloc(params_size, GFP_KERNEL);
3660 if (params == NULL) {
3663 memset(params, 0, params_size);
3664 ASSERT(params_size < WLC_IOCTL_SMLEN);
3666 err = wl_iw_iscan_prep(¶ms->params, ssid);
3669 params->version = htod32(ISCAN_REQ_VERSION);
3670 params->action = htod16(action);
3671 params->scan_duration = htod16(0);
3673 /* params_size += OFFSETOF(wl_iscan_params_t, params); */
3674 (void) dev_iw_iovar_setbuf(iscan->dev, "iscan", params, params_size,
3675 iscan->ioctlbuf, WLC_IOCTL_SMLEN);
3683 wl_iw_iscan_get(iscan_info_t *iscan)
3687 wl_iscan_results_t * list_buf;
3688 wl_iscan_results_t list;
3689 wl_scan_results_t *results;
3692 /* buffers are allocated on demand */
3693 if (iscan->list_cur) {
3694 buf = iscan->list_cur;
3695 iscan->list_cur = buf->next;
3698 buf = kmalloc(sizeof(iscan_buf_t), GFP_KERNEL);
3700 return WL_SCAN_RESULTS_ABORTED;
3702 if (!iscan->list_hdr)
3703 iscan->list_hdr = buf;
3705 ptr = iscan->list_hdr;
3712 memset(buf->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
3713 list_buf = (wl_iscan_results_t*)buf->iscan_buf;
3714 results = &list_buf->results;
3715 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
3716 results->version = 0;
3719 memset(&list, 0, sizeof(list));
3720 list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN);
3721 (void) dev_iw_iovar_getbuf(
3725 WL_ISCAN_RESULTS_FIXED_SIZE,
3727 WLC_IW_ISCAN_MAXLEN);
3728 results->buflen = dtoh32(results->buflen);
3729 results->version = dtoh32(results->version);
3730 results->count = dtoh32(results->count);
3731 WL_TRACE(("results->count = %d\n", results->count));
3733 WL_TRACE(("results->buflen = %d\n", results->buflen));
3734 status = dtoh32(list_buf->status);
3738 static void wl_iw_send_scan_complete(iscan_info_t *iscan)
3740 union iwreq_data wrqu;
3742 memset(&wrqu, 0, sizeof(wrqu));
3744 /* wext expects to get no data for SIOCGIWSCAN Event */
3745 wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL);
3749 _iscan_sysioc_thread(void *data)
3752 iscan_info_t *iscan = (iscan_info_t *)data;
3754 printf("%s: thread Enter\n", __FUNCTION__);
3755 DAEMONIZE("iscan_sysioc");
3757 status = WL_SCAN_RESULTS_PARTIAL;
3758 while (down_interruptible(&iscan->sysioc_sem) == 0) {
3759 if (iscan->timer_on) {
3760 del_timer(&iscan->timer);
3761 iscan->timer_on = 0;
3764 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3767 status = wl_iw_iscan_get(iscan);
3768 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3773 case WL_SCAN_RESULTS_PARTIAL:
3774 WL_TRACE(("iscanresults incomplete\n"));
3775 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3778 /* make sure our buffer size is enough before going next round */
3779 wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
3780 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
3783 /* Reschedule the timer */
3784 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
3785 add_timer(&iscan->timer);
3786 iscan->timer_on = 1;
3788 case WL_SCAN_RESULTS_SUCCESS:
3789 WL_TRACE(("iscanresults complete\n"));
3790 iscan->iscan_state = ISCAN_STATE_IDLE;
3791 wl_iw_send_scan_complete(iscan);
3793 case WL_SCAN_RESULTS_PENDING:
3794 WL_TRACE(("iscanresults pending\n"));
3795 /* Reschedule the timer */
3796 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
3797 add_timer(&iscan->timer);
3798 iscan->timer_on = 1;
3800 case WL_SCAN_RESULTS_ABORTED:
3801 WL_TRACE(("iscanresults aborted\n"));
3802 iscan->iscan_state = ISCAN_STATE_IDLE;
3803 wl_iw_send_scan_complete(iscan);
3806 WL_TRACE(("iscanresults returned unknown status %d\n", status));
3810 printf("%s: was terminated\n", __FUNCTION__);
3811 complete_and_exit(&iscan->sysioc_exited, 0);
3815 wl_iw_attach(struct net_device *dev, void * dhdp)
3817 iscan_info_t *iscan = NULL;
3819 printf("%s: Enter\n", __FUNCTION__);
3824 iscan = kmalloc(sizeof(iscan_info_t), GFP_KERNEL);
3827 memset(iscan, 0, sizeof(iscan_info_t));
3828 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
3829 iscan->kthread = NULL;
3831 iscan->sysioc_pid = -1;
3832 /* we only care about main interface so save a global here */
3835 iscan->iscan_state = ISCAN_STATE_IDLE;
3838 /* Set up the timer */
3839 iscan->timer_ms = 2000;
3840 init_timer(&iscan->timer);
3841 iscan->timer.data = (ulong)iscan;
3842 iscan->timer.function = wl_iw_timerfunc;
3844 sema_init(&iscan->sysioc_sem, 0);
3845 init_completion(&iscan->sysioc_exited);
3846 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
3847 iscan->kthread = kthread_run(_iscan_sysioc_thread, iscan, "iscan_sysioc");
3848 iscan->sysioc_pid = iscan->kthread->pid;
3850 iscan->sysioc_pid = kernel_thread(_iscan_sysioc_thread, iscan, 0);
3852 if (iscan->sysioc_pid < 0)
3857 void wl_iw_detach(void)
3860 iscan_info_t *iscan = g_iscan;
3863 if (iscan->sysioc_pid >= 0) {
3864 KILL_PROC(iscan->sysioc_pid, SIGTERM);
3865 wait_for_completion(&iscan->sysioc_exited);
3868 while (iscan->list_hdr) {
3869 buf = iscan->list_hdr->next;
3870 kfree(iscan->list_hdr);
3871 iscan->list_hdr = buf;