2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/kthread.h>
18 #include <linux/semaphore.h>
20 #include <linux/netdevice.h>
25 #include <linux/if_arp.h>
26 #include <asm/uaccess.h>
28 #include <dngl_stats.h>
31 #include <linux/ieee80211.h>
32 typedef const struct si_pub si_t;
35 #include <dngl_stats.h>
38 #define WL_ERROR(fmt, args...) printk(fmt, ##args)
39 #define WL_TRACE(fmt, args...) no_printk(fmt, ##args)
40 #define WL_INFORM(fmt, args...) no_printk(fmt, ##args)
41 #define WL_WSEC(fmt, args...) no_printk(fmt, ##args)
42 #define WL_SCAN(fmt, args...) no_printk(fmt, ##args)
46 #define IW_WSEC_ENABLED(wsec) ((wsec) & (WEP_ENABLED | \
47 TKIP_ENABLED | AES_ENABLED))
49 #include <linux/rtnetlink.h>
51 #define WL_IW_USE_ISCAN 1
52 #define ENABLE_ACTIVE_PASSIVE_SCAN_SUPPRESS 1
54 bool g_set_essid_before_scan = true;
56 #define WL_IW_IOCTL_CALL(func_call) \
61 static int g_onoff = G_WLAN_SET_ON;
62 wl_iw_extra_params_t g_wl_iw_params;
64 extern bool wl_iw_conn_status_str(u32 event_type, u32 status,
65 u32 reason, char *stringBuf, uint buflen);
67 #define MAX_WLIW_IOCTL_LEN 1024
69 #ifdef CONFIG_WIRELESS_EXT
70 extern int dhd_wait_pend8021x(struct net_device *dev);
74 #define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST)
75 #define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST)
79 static volatile uint g_scan_specified_ssid;
80 static wlc_ssid_t g_specific_ssid;
82 static wlc_ssid_t g_ssid;
84 #if defined(WL_IW_USE_ISCAN)
85 #define ISCAN_STATE_IDLE 0
86 #define ISCAN_STATE_SCANING 1
88 #define WLC_IW_ISCAN_MAXLEN 2048
89 typedef struct iscan_buf {
90 struct iscan_buf *next;
91 char iscan_buf[WLC_IW_ISCAN_MAXLEN];
94 typedef struct iscan_info {
95 struct net_device *dev;
96 struct timer_list timer;
100 iscan_buf_t *list_hdr;
101 iscan_buf_t *list_cur;
103 struct task_struct *sysioc_tsk;
104 struct semaphore sysioc_sem;
107 char ioctlbuf[WLC_IOCTL_MEDLEN];
109 char ioctlbuf[WLC_IOCTL_SMLEN];
111 wl_iscan_params_t *iscan_ex_params_p;
112 int iscan_ex_param_size;
114 iscan_info_t *g_iscan;
116 static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255};
118 /* Global ASSERT type flag */
121 static void wl_iw_timerfunc(unsigned long data);
122 static void wl_iw_set_event_mask(struct net_device *dev);
123 static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, u16 action);
124 #endif /* defined(WL_IW_USE_ISCAN) */
127 wl_iw_set_scan(struct net_device *dev,
128 struct iw_request_info *info,
129 union iwreq_data *wrqu, char *extra);
132 wl_iw_get_scan(struct net_device *dev,
133 struct iw_request_info *info,
134 struct iw_point *dwrq, char *extra);
137 wl_iw_get_scan_prep(wl_scan_results_t *list,
138 struct iw_request_info *info, char *extra, short max_size);
140 static void swap_key_from_BE(wl_wsec_key_t *key)
142 key->index = cpu_to_le32(key->index);
143 key->len = cpu_to_le32(key->len);
144 key->algo = cpu_to_le32(key->algo);
145 key->flags = cpu_to_le32(key->flags);
146 key->rxiv.hi = cpu_to_le32(key->rxiv.hi);
147 key->rxiv.lo = cpu_to_le16(key->rxiv.lo);
148 key->iv_initialized = cpu_to_le32(key->iv_initialized);
151 static void swap_key_to_BE(wl_wsec_key_t *key)
153 key->index = le32_to_cpu(key->index);
154 key->len = le32_to_cpu(key->len);
155 key->algo = le32_to_cpu(key->algo);
156 key->flags = le32_to_cpu(key->flags);
157 key->rxiv.hi = le32_to_cpu(key->rxiv.hi);
158 key->rxiv.lo = le16_to_cpu(key->rxiv.lo);
159 key->iv_initialized = le32_to_cpu(key->iv_initialized);
162 static int dev_wlc_ioctl(struct net_device *dev, int cmd, void *arg, int len)
170 WL_ERROR("%s: dev is null\n", __func__);
174 WL_INFORM("\n%s, PID:%x: send Local IOCTL -> dhd: cmd:0x%x, buf:%p, len:%d\n",
175 __func__, current->pid, cmd, arg, len);
177 if (g_onoff == G_WLAN_SET_ON) {
178 memset(&ioc, 0, sizeof(ioc));
183 strcpy(ifr.ifr_name, dev->name);
184 ifr.ifr_data = (caddr_t)&ioc;
188 WL_ERROR("%s: Error dev_open: %d\n", __func__, ret);
194 ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
197 WL_TRACE("%s: call after driver stop : ignored\n", __func__);
202 static int dev_wlc_intvar_set(struct net_device *dev, char *name, int val)
204 char buf[WLC_IOCTL_SMLEN];
207 val = cpu_to_le32(val);
208 len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf));
211 return dev_wlc_ioctl(dev, WLC_SET_VAR, buf, len);
214 #if defined(WL_IW_USE_ISCAN)
216 dev_iw_iovar_setbuf(struct net_device *dev,
218 void *param, int paramlen, void *bufptr, int buflen)
222 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
228 return dev_wlc_ioctl(dev, WLC_SET_VAR, bufptr, iolen);
232 dev_iw_iovar_getbuf(struct net_device *dev,
234 void *param, int paramlen, void *bufptr, int buflen)
238 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
241 return dev_wlc_ioctl(dev, WLC_GET_VAR, bufptr, buflen);
243 #endif /* defined(WL_IW_USE_ISCAN) */
245 #if WIRELESS_EXT > 17
247 dev_wlc_bufvar_set(struct net_device *dev, char *name, char *buf, int len)
249 static char ioctlbuf[MAX_WLIW_IOCTL_LEN];
252 buflen = bcm_mkiovar(name, buf, len, ioctlbuf, sizeof(ioctlbuf));
255 return dev_wlc_ioctl(dev, WLC_SET_VAR, ioctlbuf, buflen);
257 #endif /* WIRELESS_EXT > 17 */
260 dev_wlc_bufvar_get(struct net_device *dev, char *name, char *buf, int buflen)
262 static char ioctlbuf[MAX_WLIW_IOCTL_LEN];
266 len = bcm_mkiovar(name, NULL, 0, ioctlbuf, sizeof(ioctlbuf));
269 dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)ioctlbuf,
272 memcpy(buf, ioctlbuf, buflen);
277 static int dev_wlc_intvar_get(struct net_device *dev, char *name, int *retval)
280 char buf[WLC_IOCTL_SMLEN];
289 bcm_mkiovar(name, (char *)(&data_null), 0, (char *)(&var),
292 error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)&var, len);
294 *retval = le32_to_cpu(var.val);
299 #if WIRELESS_EXT < 13
300 struct iw_request_info {
305 typedef int (*iw_handler) (struct net_device *dev,
306 struct iw_request_info *info,
307 void *wrqu, char *extra);
311 wl_iw_config_commit(struct net_device *dev,
312 struct iw_request_info *info, void *zwrq, char *extra)
316 struct sockaddr bssid;
318 WL_TRACE("%s: SIOCSIWCOMMIT\n", dev->name);
320 error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid));
324 ssid.SSID_len = le32_to_cpu(ssid.SSID_len);
329 memset(&bssid, 0, sizeof(struct sockaddr));
330 error = dev_wlc_ioctl(dev, WLC_REASSOC, &bssid, ETH_ALEN);
332 WL_ERROR("%s: WLC_REASSOC to %s failed\n",
333 __func__, ssid.SSID);
341 wl_iw_get_name(struct net_device *dev,
342 struct iw_request_info *info, char *cwrq, char *extra)
344 WL_TRACE("%s: SIOCGIWNAME\n", dev->name);
346 strcpy(cwrq, "IEEE 802.11-DS");
352 wl_iw_set_freq(struct net_device *dev,
353 struct iw_request_info *info, struct iw_freq *fwrq, char *extra)
358 WL_TRACE("\n %s %s: SIOCSIWFREQ\n", __func__, dev->name);
360 if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) {
367 } else if (fwrq->e < 6) {
368 while (fwrq->e++ < 6)
371 if (fwrq->m > 4000 && fwrq->m < 5000)
372 sf = WF_CHAN_FACTOR_4_G;
374 chan = bcm_mhz2channel(fwrq->m, sf);
376 chan = cpu_to_le32(chan);
378 error = dev_wlc_ioctl(dev, WLC_SET_CHANNEL, &chan, sizeof(chan));
382 g_wl_iw_params.target_channel = chan;
387 wl_iw_get_freq(struct net_device *dev,
388 struct iw_request_info *info, struct iw_freq *fwrq, char *extra)
393 WL_TRACE("%s: SIOCGIWFREQ\n", dev->name);
395 error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci));
399 fwrq->m = le32_to_cpu(ci.hw_channel);
400 fwrq->e = le32_to_cpu(0);
405 wl_iw_set_mode(struct net_device *dev,
406 struct iw_request_info *info, __u32 *uwrq, char *extra)
408 int infra = 0, ap = 0, error = 0;
410 WL_TRACE("%s: SIOCSIWMODE\n", dev->name);
425 infra = cpu_to_le32(infra);
426 ap = cpu_to_le32(ap);
428 error = dev_wlc_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra));
432 error = dev_wlc_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap));
440 wl_iw_get_mode(struct net_device *dev,
441 struct iw_request_info *info, __u32 *uwrq, char *extra)
443 int error, infra = 0, ap = 0;
445 WL_TRACE("%s: SIOCGIWMODE\n", dev->name);
447 error = dev_wlc_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra));
451 error = dev_wlc_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap));
455 infra = le32_to_cpu(infra);
456 ap = le32_to_cpu(ap);
457 *uwrq = infra ? ap ? IW_MODE_MASTER : IW_MODE_INFRA : IW_MODE_ADHOC;
463 wl_iw_get_range(struct net_device *dev,
464 struct iw_request_info *info,
465 struct iw_point *dwrq, char *extra)
467 struct iw_range *range = (struct iw_range *)extra;
469 wl_rateset_t rateset;
475 int bw_cap = 0, sgi_tx = 0, nmode = 0;
477 u8 nrate_list2copy = 0;
478 u16 nrate_list[4][8] = { {13, 26, 39, 52, 78, 104, 117, 130},
479 {14, 29, 43, 58, 87, 116, 130, 144},
480 {27, 54, 81, 108, 162, 216, 243, 270},
481 {30, 60, 90, 120, 180, 240, 270, 300}
484 WL_TRACE("%s: SIOCGIWRANGE\n", dev->name);
489 channels = kmalloc((MAXCHANNEL + 1) * 4, GFP_KERNEL);
491 WL_ERROR("Could not alloc channels\n");
494 list = (wl_u32_list_t *) channels;
496 dwrq->length = sizeof(struct iw_range);
497 memset(range, 0, sizeof(*range));
499 list->count = cpu_to_le32(MAXCHANNEL);
500 error = dev_wlc_ioctl(dev, WLC_GET_VALID_CHANNELS, channels,
501 (MAXCHANNEL + 1) * 4);
506 for (i = 0; i < le32_to_cpu(list->count) && i < IW_MAX_FREQUENCIES;
508 range->freq[i].i = le32_to_cpu(list->element[i]);
510 ch = le32_to_cpu(list->element[i]);
511 if (ch <= CH_MAX_2G_CHANNEL) {
512 range->freq[i].m = ieee80211_dsss_chan_to_freq(ch);
514 range->freq[i].m = ieee80211_ofdm_chan_to_freq(
515 WF_CHAN_FACTOR_5_G/2, ch);
517 range->freq[i].e = 6;
519 range->num_frequency = range->num_channels = i;
521 range->max_qual.qual = 5;
522 range->max_qual.level = 0x100 - 200;
523 range->max_qual.noise = 0x100 - 200;
524 range->sensitivity = 65535;
526 #if WIRELESS_EXT > 11
527 range->avg_qual.qual = 3;
528 range->avg_qual.level = 0x100 + WL_IW_RSSI_GOOD;
529 range->avg_qual.noise = 0x100 - 75;
532 error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset,
538 rateset.count = le32_to_cpu(rateset.count);
539 range->num_bitrates = rateset.count;
540 for (i = 0; i < rateset.count && i < IW_MAX_BITRATES; i++)
541 range->bitrate[i] = (rateset.rates[i] & 0x7f) * 500000;
542 dev_wlc_intvar_get(dev, "nmode", &nmode);
543 dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype));
545 if (nmode == 1 && phytype == WLC_PHY_TYPE_SSN) {
546 dev_wlc_intvar_get(dev, "mimo_bw_cap", &bw_cap);
547 dev_wlc_intvar_get(dev, "sgi_tx", &sgi_tx);
548 dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci,
549 sizeof(channel_info_t));
550 ci.hw_channel = le32_to_cpu(ci.hw_channel);
552 if (bw_cap == 0 || (bw_cap == 2 && ci.hw_channel <= 14)) {
558 if (bw_cap == 1 || (bw_cap == 2 && ci.hw_channel >= 36)) {
564 range->num_bitrates += 8;
565 for (k = 0; i < range->num_bitrates; k++, i++) {
567 (nrate_list[nrate_list2copy][k]) * 500000;
571 error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &i, sizeof(i));
577 if (i == WLC_PHY_TYPE_A)
578 range->throughput = 24000000;
580 range->throughput = 1500000;
583 range->max_rts = 2347;
584 range->min_frag = 256;
585 range->max_frag = 2346;
587 range->max_encoding_tokens = DOT11_MAX_DEFAULT_KEYS;
588 range->num_encoding_sizes = 4;
589 range->encoding_size[0] = WLAN_KEY_LEN_WEP40;
590 range->encoding_size[1] = WLAN_KEY_LEN_WEP104;
591 #if WIRELESS_EXT > 17
592 range->encoding_size[2] = WLAN_KEY_LEN_TKIP;
594 range->encoding_size[2] = 0;
596 range->encoding_size[3] = WLAN_KEY_LEN_AES_CMAC;
602 range->pmp_flags = 0;
605 range->num_txpower = 2;
606 range->txpower[0] = 1;
607 range->txpower[1] = 255;
608 range->txpower_capa = IW_TXPOW_MWATT;
610 #if WIRELESS_EXT > 10
611 range->we_version_compiled = WIRELESS_EXT;
612 range->we_version_source = 19;
614 range->retry_capa = IW_RETRY_LIMIT;
615 range->retry_flags = IW_RETRY_LIMIT;
616 range->r_time_flags = 0;
617 range->min_retry = 1;
618 range->max_retry = 255;
619 range->min_r_time = 0;
620 range->max_r_time = 0;
623 #if WIRELESS_EXT > 17
624 range->enc_capa = IW_ENC_CAPA_WPA;
625 range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP;
626 range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP;
627 range->enc_capa |= IW_ENC_CAPA_WPA2;
629 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
630 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
631 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
632 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
633 IW_EVENT_CAPA_SET(range->event_capa, IWEVMICHAELMICFAILURE);
634 IW_EVENT_CAPA_SET(range->event_capa, IWEVPMKIDCAND);
635 #endif /* WIRELESS_EXT > 17 */
642 static int rssi_to_qual(int rssi)
644 if (rssi <= WL_IW_RSSI_NO_SIGNAL)
646 else if (rssi <= WL_IW_RSSI_VERY_LOW)
648 else if (rssi <= WL_IW_RSSI_LOW)
650 else if (rssi <= WL_IW_RSSI_GOOD)
652 else if (rssi <= WL_IW_RSSI_VERY_GOOD)
659 wl_iw_set_spy(struct net_device *dev,
660 struct iw_request_info *info, struct iw_point *dwrq, char *extra)
662 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
663 struct sockaddr *addr = (struct sockaddr *)extra;
666 WL_TRACE("%s: SIOCSIWSPY\n", dev->name);
671 iw->spy_num = min_t(int, ARRAY_SIZE(iw->spy_addr), dwrq->length);
672 for (i = 0; i < iw->spy_num; i++)
673 memcpy(iw->spy_addr[i], addr[i].sa_data, ETH_ALEN);
674 memset(iw->spy_qual, 0, sizeof(iw->spy_qual));
680 wl_iw_get_spy(struct net_device *dev,
681 struct iw_request_info *info, struct iw_point *dwrq, char *extra)
683 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
684 struct sockaddr *addr = (struct sockaddr *)extra;
685 struct iw_quality *qual = (struct iw_quality *)&addr[iw->spy_num];
688 WL_TRACE("%s: SIOCGIWSPY\n", dev->name);
693 dwrq->length = iw->spy_num;
694 for (i = 0; i < iw->spy_num; i++) {
695 memcpy(addr[i].sa_data, iw->spy_addr[i], ETH_ALEN);
696 addr[i].sa_family = AF_UNIX;
697 memcpy(&qual[i], &iw->spy_qual[i], sizeof(struct iw_quality));
698 iw->spy_qual[i].updated = 0;
705 wl_iw_ch_to_chanspec(int ch, wl_join_params_t *join_params,
706 int *join_params_size)
708 chanspec_t chanspec = 0;
711 join_params->params.chanspec_num = 1;
712 join_params->params.chanspec_list[0] = ch;
714 if (join_params->params.chanspec_list[0])
715 chanspec |= WL_CHANSPEC_BAND_2G;
717 chanspec |= WL_CHANSPEC_BAND_5G;
719 chanspec |= WL_CHANSPEC_BW_20;
720 chanspec |= WL_CHANSPEC_CTL_SB_NONE;
722 *join_params_size += WL_ASSOC_PARAMS_FIXED_SIZE +
723 join_params->params.chanspec_num * sizeof(chanspec_t);
725 join_params->params.chanspec_list[0] &= WL_CHANSPEC_CHAN_MASK;
726 join_params->params.chanspec_list[0] |= chanspec;
727 join_params->params.chanspec_list[0] =
728 cpu_to_le16(join_params->params.chanspec_list[0]);
730 join_params->params.chanspec_num =
731 cpu_to_le32(join_params->params.chanspec_num);
733 WL_TRACE("%s join_params->params.chanspec_list[0]= %X\n",
734 __func__, join_params->params.chanspec_list[0]);
740 wl_iw_set_wap(struct net_device *dev,
741 struct iw_request_info *info, struct sockaddr *awrq, char *extra)
744 wl_join_params_t join_params;
745 int join_params_size;
747 WL_TRACE("%s: SIOCSIWAP\n", dev->name);
749 if (awrq->sa_family != ARPHRD_ETHER) {
750 WL_ERROR("Invalid Header...sa_family\n");
754 if (is_broadcast_ether_addr(awrq->sa_data) ||
755 is_zero_ether_addr(awrq->sa_data)) {
757 memset(&scbval, 0, sizeof(scb_val_t));
758 (void)dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval,
763 memset(&join_params, 0, sizeof(join_params));
764 join_params_size = sizeof(join_params.ssid);
766 memcpy(join_params.ssid.SSID, g_ssid.SSID, g_ssid.SSID_len);
767 join_params.ssid.SSID_len = cpu_to_le32(g_ssid.SSID_len);
768 memcpy(&join_params.params.bssid, awrq->sa_data, ETH_ALEN);
770 WL_TRACE("%s target_channel=%d\n",
771 __func__, g_wl_iw_params.target_channel);
772 wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params,
775 error = dev_wlc_ioctl(dev, WLC_SET_SSID, &join_params,
778 WL_ERROR("%s Invalid ioctl data=%d\n", __func__, error);
781 if (g_ssid.SSID_len) {
782 WL_TRACE("%s: join SSID=%s BSSID=%pM ch=%d\n",
783 __func__, g_ssid.SSID, awrq->sa_data,
784 g_wl_iw_params.target_channel);
787 memset(&g_ssid, 0, sizeof(g_ssid));
792 wl_iw_get_wap(struct net_device *dev,
793 struct iw_request_info *info, struct sockaddr *awrq, char *extra)
795 WL_TRACE("%s: SIOCGIWAP\n", dev->name);
797 awrq->sa_family = ARPHRD_ETHER;
798 memset(awrq->sa_data, 0, ETH_ALEN);
800 (void)dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETH_ALEN);
805 #if WIRELESS_EXT > 17
807 wl_iw_mlme(struct net_device *dev,
808 struct iw_request_info *info, struct sockaddr *awrq, char *extra)
810 struct iw_mlme *mlme;
814 WL_TRACE("%s: SIOCSIWMLME DISASSOC/DEAUTH\n", dev->name);
816 mlme = (struct iw_mlme *)extra;
818 WL_ERROR("Invalid ioctl data\n");
822 scbval.val = mlme->reason_code;
823 memcpy(&scbval.ea, &mlme->addr.sa_data, ETH_ALEN);
825 if (mlme->cmd == IW_MLME_DISASSOC) {
826 scbval.val = cpu_to_le32(scbval.val);
828 dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval,
830 } else if (mlme->cmd == IW_MLME_DEAUTH) {
831 scbval.val = cpu_to_le32(scbval.val);
833 dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON,
834 &scbval, sizeof(scb_val_t));
836 WL_ERROR("Invalid ioctl data\n");
842 #endif /* WIRELESS_EXT > 17 */
844 #ifndef WL_IW_USE_ISCAN
846 wl_iw_get_aplist(struct net_device *dev,
847 struct iw_request_info *info,
848 struct iw_point *dwrq, char *extra)
850 wl_scan_results_t *list;
851 struct sockaddr *addr = (struct sockaddr *)extra;
852 struct iw_quality qual[IW_MAX_AP];
853 wl_bss_info_t *bi = NULL;
855 uint buflen = dwrq->length;
857 WL_TRACE("%s: SIOCGIWAPLIST\n", dev->name);
862 list = kzalloc(buflen, GFP_KERNEL);
865 list->buflen = cpu_to_le32(buflen);
866 error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen);
868 WL_ERROR("%d: Scan results error %d\n", __LINE__, error);
872 list->buflen = le32_to_cpu(list->buflen);
873 list->version = le32_to_cpu(list->version);
874 list->count = le32_to_cpu(list->count);
875 if (list->version != WL_BSS_INFO_VERSION) {
876 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
877 __func__, list->version);
882 for (i = 0, dwrq->length = 0;
883 i < list->count && dwrq->length < IW_MAX_AP; i++) {
884 bi = bi ? (wl_bss_info_t *) ((unsigned long)bi +
885 le32_to_cpu(bi->length)) : list->
887 ASSERT(((unsigned long)bi + le32_to_cpu(bi->length)) <=
888 ((unsigned long)list + buflen));
890 if (!(le16_to_cpu(bi->capability) & WLAN_CAPABILITY_ESS))
893 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETH_ALEN);
894 addr[dwrq->length].sa_family = ARPHRD_ETHER;
895 qual[dwrq->length].qual = rssi_to_qual(le16_to_cpu(bi->RSSI));
896 qual[dwrq->length].level = 0x100 + le16_to_cpu(bi->RSSI);
897 qual[dwrq->length].noise = 0x100 + bi->phy_noise;
899 #if WIRELESS_EXT > 18
900 qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
902 qual[dwrq->length].updated = 7;
910 memcpy(&addr[dwrq->length], qual,
911 sizeof(struct iw_quality) * dwrq->length);
917 #endif /* WL_IW_USE_ISCAN */
919 #ifdef WL_IW_USE_ISCAN
921 wl_iw_iscan_get_aplist(struct net_device *dev,
922 struct iw_request_info *info,
923 struct iw_point *dwrq, char *extra)
925 wl_scan_results_t *list;
927 iscan_info_t *iscan = g_iscan;
929 struct sockaddr *addr = (struct sockaddr *)extra;
930 struct iw_quality qual[IW_MAX_AP];
931 wl_bss_info_t *bi = NULL;
934 WL_TRACE("%s: SIOCGIWAPLIST\n", dev->name);
939 if ((!iscan) || (!iscan->sysioc_tsk)) {
940 WL_ERROR("%s error\n", __func__);
944 buf = iscan->list_hdr;
946 list = &((wl_iscan_results_t *) buf->iscan_buf)->results;
947 if (list->version != WL_BSS_INFO_VERSION) {
948 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
949 __func__, list->version);
954 for (i = 0, dwrq->length = 0;
955 i < list->count && dwrq->length < IW_MAX_AP; i++) {
956 bi = bi ? (wl_bss_info_t *) ((unsigned long)bi +
957 le32_to_cpu(bi->length)) :
959 ASSERT(((unsigned long)bi + le32_to_cpu(bi->length)) <=
960 ((unsigned long)list + WLC_IW_ISCAN_MAXLEN));
962 if (!(le16_to_cpu(bi->capability) &
963 WLAN_CAPABILITY_ESS))
966 memcpy(addr[dwrq->length].sa_data, &bi->BSSID,
968 addr[dwrq->length].sa_family = ARPHRD_ETHER;
969 qual[dwrq->length].qual =
970 rssi_to_qual(le16_to_cpu(bi->RSSI));
971 qual[dwrq->length].level = 0x100 +
972 le16_to_cpu(bi->RSSI);
973 qual[dwrq->length].noise = 0x100 + bi->phy_noise;
975 #if WIRELESS_EXT > 18
976 qual[dwrq->length].updated =
977 IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
979 qual[dwrq->length].updated = 7;
987 memcpy(&addr[dwrq->length], qual,
988 sizeof(struct iw_quality) * dwrq->length);
995 static int wl_iw_iscan_prep(wl_scan_params_t *params, wlc_ssid_t *ssid)
999 memcpy(params->bssid, ether_bcast, ETH_ALEN);
1000 params->bss_type = DOT11_BSSTYPE_ANY;
1001 params->scan_type = 0;
1002 params->nprobes = -1;
1003 params->active_time = -1;
1004 params->passive_time = -1;
1005 params->home_time = -1;
1006 params->channel_num = 0;
1008 params->nprobes = cpu_to_le32(params->nprobes);
1009 params->active_time = cpu_to_le32(params->active_time);
1010 params->passive_time = cpu_to_le32(params->passive_time);
1011 params->home_time = cpu_to_le32(params->home_time);
1012 if (ssid && ssid->SSID_len)
1013 memcpy(¶ms->ssid, ssid, sizeof(wlc_ssid_t));
1018 static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, u16 action)
1022 iscan->iscan_ex_params_p->version = cpu_to_le32(ISCAN_REQ_VERSION);
1023 iscan->iscan_ex_params_p->action = cpu_to_le16(action);
1024 iscan->iscan_ex_params_p->scan_duration = cpu_to_le16(0);
1026 WL_SCAN("%s : nprobes=%d\n",
1027 __func__, iscan->iscan_ex_params_p->params.nprobes);
1028 WL_SCAN("active_time=%d\n",
1029 iscan->iscan_ex_params_p->params.active_time);
1030 WL_SCAN("passive_time=%d\n",
1031 iscan->iscan_ex_params_p->params.passive_time);
1032 WL_SCAN("home_time=%d\n", iscan->iscan_ex_params_p->params.home_time);
1033 WL_SCAN("scan_type=%d\n", iscan->iscan_ex_params_p->params.scan_type);
1034 WL_SCAN("bss_type=%d\n", iscan->iscan_ex_params_p->params.bss_type);
1036 (void)dev_iw_iovar_setbuf(iscan->dev, "iscan", iscan->iscan_ex_params_p,
1037 iscan->iscan_ex_param_size, iscan->ioctlbuf,
1038 sizeof(iscan->ioctlbuf));
1043 static void wl_iw_timerfunc(unsigned long data)
1045 iscan_info_t *iscan = (iscan_info_t *) data;
1047 iscan->timer_on = 0;
1048 if (iscan->iscan_state != ISCAN_STATE_IDLE) {
1049 WL_TRACE("timer trigger\n");
1050 up(&iscan->sysioc_sem);
1055 static void wl_iw_set_event_mask(struct net_device *dev)
1057 char eventmask[WL_EVENTING_MASK_LEN];
1058 char iovbuf[WL_EVENTING_MASK_LEN + 12];
1060 dev_iw_iovar_getbuf(dev, "event_msgs", "", 0, iovbuf, sizeof(iovbuf));
1061 memcpy(eventmask, iovbuf, WL_EVENTING_MASK_LEN);
1062 setbit(eventmask, WLC_E_SCAN_COMPLETE);
1063 dev_iw_iovar_setbuf(dev, "event_msgs", eventmask, WL_EVENTING_MASK_LEN,
1064 iovbuf, sizeof(iovbuf));
1067 static u32 wl_iw_iscan_get(iscan_info_t *iscan)
1071 wl_iscan_results_t *list_buf;
1072 wl_iscan_results_t list;
1073 wl_scan_results_t *results;
1077 MUTEX_LOCK_WL_SCAN_SET();
1078 if (iscan->list_cur) {
1079 buf = iscan->list_cur;
1080 iscan->list_cur = buf->next;
1082 buf = kmalloc(sizeof(iscan_buf_t), GFP_KERNEL);
1084 WL_ERROR("%s can't alloc iscan_buf_t : going to abort current iscan\n",
1086 MUTEX_UNLOCK_WL_SCAN_SET();
1087 return WL_SCAN_RESULTS_NO_MEM;
1090 if (!iscan->list_hdr)
1091 iscan->list_hdr = buf;
1093 ptr = iscan->list_hdr;
1100 memset(buf->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
1101 list_buf = (wl_iscan_results_t *) buf->iscan_buf;
1102 results = &list_buf->results;
1103 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
1104 results->version = 0;
1107 memset(&list, 0, sizeof(list));
1108 list.results.buflen = cpu_to_le32(WLC_IW_ISCAN_MAXLEN);
1109 res = dev_iw_iovar_getbuf(iscan->dev,
1112 WL_ISCAN_RESULTS_FIXED_SIZE,
1113 buf->iscan_buf, WLC_IW_ISCAN_MAXLEN);
1115 results->buflen = le32_to_cpu(results->buflen);
1116 results->version = le32_to_cpu(results->version);
1117 results->count = le32_to_cpu(results->count);
1118 WL_TRACE("results->count = %d\n", results->count);
1119 WL_TRACE("results->buflen = %d\n", results->buflen);
1120 status = le32_to_cpu(list_buf->status);
1122 WL_ERROR("%s returns error %d\n", __func__, res);
1123 status = WL_SCAN_RESULTS_NO_MEM;
1125 MUTEX_UNLOCK_WL_SCAN_SET();
1129 static void wl_iw_force_specific_scan(iscan_info_t *iscan)
1131 WL_TRACE("%s force Specific SCAN for %s\n",
1132 __func__, g_specific_ssid.SSID);
1135 (void)dev_wlc_ioctl(iscan->dev, WLC_SCAN, &g_specific_ssid,
1136 sizeof(g_specific_ssid));
1141 static void wl_iw_send_scan_complete(iscan_info_t *iscan)
1144 union iwreq_data wrqu;
1146 memset(&wrqu, 0, sizeof(wrqu));
1148 wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL);
1149 WL_TRACE("Send Event ISCAN complete\n");
1153 static int _iscan_sysioc_thread(void *data)
1156 iscan_info_t *iscan = (iscan_info_t *) data;
1157 static bool iscan_pass_abort = false;
1159 allow_signal(SIGTERM);
1160 status = WL_SCAN_RESULTS_PARTIAL;
1161 while (down_interruptible(&iscan->sysioc_sem) == 0) {
1162 if (kthread_should_stop())
1165 if (iscan->timer_on) {
1166 del_timer_sync(&iscan->timer);
1167 iscan->timer_on = 0;
1170 status = wl_iw_iscan_get(iscan);
1172 if (g_scan_specified_ssid && (iscan_pass_abort == true)) {
1173 WL_TRACE("%s Get results from specific scan status = %d\n",
1175 wl_iw_send_scan_complete(iscan);
1176 iscan_pass_abort = false;
1181 case WL_SCAN_RESULTS_PARTIAL:
1182 WL_TRACE("iscanresults incomplete\n");
1184 wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
1186 mod_timer(&iscan->timer,
1187 jiffies + iscan->timer_ms * HZ / 1000);
1188 iscan->timer_on = 1;
1190 case WL_SCAN_RESULTS_SUCCESS:
1191 WL_TRACE("iscanresults complete\n");
1192 iscan->iscan_state = ISCAN_STATE_IDLE;
1193 wl_iw_send_scan_complete(iscan);
1195 case WL_SCAN_RESULTS_PENDING:
1196 WL_TRACE("iscanresults pending\n");
1197 mod_timer(&iscan->timer,
1198 jiffies + iscan->timer_ms * HZ / 1000);
1199 iscan->timer_on = 1;
1201 case WL_SCAN_RESULTS_ABORTED:
1202 WL_TRACE("iscanresults aborted\n");
1203 iscan->iscan_state = ISCAN_STATE_IDLE;
1204 if (g_scan_specified_ssid == 0)
1205 wl_iw_send_scan_complete(iscan);
1207 iscan_pass_abort = true;
1208 wl_iw_force_specific_scan(iscan);
1211 case WL_SCAN_RESULTS_NO_MEM:
1212 WL_TRACE("iscanresults can't alloc memory: skip\n");
1213 iscan->iscan_state = ISCAN_STATE_IDLE;
1216 WL_TRACE("iscanresults returned unknown status %d\n",
1222 if (iscan->timer_on) {
1223 del_timer_sync(&iscan->timer);
1224 iscan->timer_on = 0;
1228 #endif /* WL_IW_USE_ISCAN */
1231 wl_iw_set_scan(struct net_device *dev,
1232 struct iw_request_info *info,
1233 union iwreq_data *wrqu, char *extra)
1236 WL_TRACE("\n:%s dev:%s: SIOCSIWSCAN : SCAN\n", __func__, dev->name);
1238 g_set_essid_before_scan = false;
1240 WL_ERROR("%s: Scan from SIOCGIWSCAN not supported\n", __func__);
1244 if (g_onoff == G_WLAN_SET_OFF)
1247 memset(&g_specific_ssid, 0, sizeof(g_specific_ssid));
1248 #ifndef WL_IW_USE_ISCAN
1249 g_scan_specified_ssid = 0;
1252 #if WIRELESS_EXT > 17
1253 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1254 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1255 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1256 if (g_scan_specified_ssid) {
1257 WL_TRACE("%s Specific SCAN is not done ignore scan for = %s\n",
1258 __func__, req->essid);
1261 g_specific_ssid.SSID_len = min_t(size_t,
1262 sizeof(g_specific_ssid.SSID),
1264 memcpy(g_specific_ssid.SSID, req->essid,
1265 g_specific_ssid.SSID_len);
1266 g_specific_ssid.SSID_len =
1267 cpu_to_le32(g_specific_ssid.SSID_len);
1268 g_scan_specified_ssid = 1;
1269 WL_TRACE("### Specific scan ssid=%s len=%d\n",
1270 g_specific_ssid.SSID,
1271 g_specific_ssid.SSID_len);
1275 #endif /* WIRELESS_EXT > 17 */
1276 error = dev_wlc_ioctl(dev, WLC_SCAN, &g_specific_ssid,
1277 sizeof(g_specific_ssid));
1279 WL_TRACE("#### Set SCAN for %s failed with %d\n",
1280 g_specific_ssid.SSID, error);
1281 g_scan_specified_ssid = 0;
1288 #ifdef WL_IW_USE_ISCAN
1289 int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag)
1292 iscan_info_t *iscan = g_iscan;
1297 wl_iw_set_event_mask(dev);
1299 WL_TRACE("+++: Set Broadcast ISCAN\n");
1300 memset(&ssid, 0, sizeof(ssid));
1302 iscan->list_cur = iscan->list_hdr;
1303 iscan->iscan_state = ISCAN_STATE_SCANING;
1305 memset(&iscan->iscan_ex_params_p->params, 0,
1306 iscan->iscan_ex_param_size);
1307 wl_iw_iscan_prep(&iscan->iscan_ex_params_p->params, &ssid);
1308 wl_iw_iscan(iscan, &ssid, WL_SCAN_ACTION_START);
1313 mod_timer(&iscan->timer, jiffies + iscan->timer_ms * HZ / 1000);
1315 iscan->timer_on = 1;
1321 wl_iw_iscan_set_scan(struct net_device *dev,
1322 struct iw_request_info *info,
1323 union iwreq_data *wrqu, char *extra)
1326 iscan_info_t *iscan = g_iscan;
1328 WL_TRACE("%s: SIOCSIWSCAN : ISCAN\n", dev->name);
1331 WL_ERROR("%s: Scan from SIOCGIWSCAN not supported\n", __func__);
1335 if (g_onoff == G_WLAN_SET_OFF) {
1336 WL_TRACE("%s: driver is not up yet after START\n", __func__);
1340 if (dhd_dev_get_pno_status(dev)) {
1341 WL_ERROR("%s: Scan called when PNO is active\n", __func__);
1345 if ((!iscan) || (!iscan->sysioc_tsk))
1346 return wl_iw_set_scan(dev, info, wrqu, extra);
1348 if (g_scan_specified_ssid) {
1349 WL_TRACE("%s Specific SCAN already running ignoring BC scan\n",
1354 memset(&ssid, 0, sizeof(ssid));
1356 #if WIRELESS_EXT > 17
1357 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1358 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1359 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1360 ssid.SSID_len = min_t(size_t, sizeof(ssid.SSID),
1362 memcpy(ssid.SSID, req->essid, ssid.SSID_len);
1363 ssid.SSID_len = cpu_to_le32(ssid.SSID_len);
1365 g_scan_specified_ssid = 0;
1367 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1368 WL_TRACE("%s ISCAN already in progress\n",
1374 #endif /* WIRELESS_EXT > 17 */
1375 wl_iw_iscan_set_scan_broadcast_prep(dev, 0);
1379 #endif /* WL_IW_USE_ISCAN */
1381 #if WIRELESS_EXT > 17
1382 static bool ie_is_wpa_ie(u8 **wpaie, u8 **tlvs, int *tlvs_len)
1388 !memcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) {
1393 *tlvs_len -= (int)(ie - *tlvs);
1398 static bool ie_is_wps_ie(u8 **wpsie, u8 **tlvs, int *tlvs_len)
1404 !memcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) {
1409 *tlvs_len -= (int)(ie - *tlvs);
1413 #endif /* WIRELESS_EXT > 17 */
1416 wl_iw_handle_scanresults_ies(char **event_p, char *end,
1417 struct iw_request_info *info, wl_bss_info_t *bi)
1419 #if WIRELESS_EXT > 17
1420 struct iw_event iwe;
1424 if (bi->ie_length) {
1426 u8 *ptr = ((u8 *) bi) + sizeof(wl_bss_info_t);
1427 int ptr_len = bi->ie_length;
1429 ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_RSN_ID);
1431 iwe.cmd = IWEVGENIE;
1432 iwe.u.data.length = ie->len + 2;
1434 IWE_STREAM_ADD_POINT(info, event, end, &iwe,
1437 ptr = ((u8 *) bi) + sizeof(wl_bss_info_t);
1439 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
1440 if (ie_is_wps_ie(((u8 **)&ie), &ptr, &ptr_len)) {
1441 iwe.cmd = IWEVGENIE;
1442 iwe.u.data.length = ie->len + 2;
1444 IWE_STREAM_ADD_POINT(info, event, end, &iwe,
1450 ptr = ((u8 *) bi) + sizeof(wl_bss_info_t);
1451 ptr_len = bi->ie_length;
1452 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
1453 if (ie_is_wpa_ie(((u8 **)&ie), &ptr, &ptr_len)) {
1454 iwe.cmd = IWEVGENIE;
1455 iwe.u.data.length = ie->len + 2;
1457 IWE_STREAM_ADD_POINT(info, event, end, &iwe,
1465 #endif /* WIRELESS_EXT > 17 */
1470 wl_iw_get_scan_prep(wl_scan_results_t *list,
1471 struct iw_request_info *info, char *extra, short max_size)
1474 struct iw_event iwe;
1475 wl_bss_info_t *bi = NULL;
1476 char *event = extra, *end = extra + max_size - WE_ADD_EVENT_FIX, *value;
1481 for (i = 0; i < list->count && i < IW_MAX_AP; i++) {
1482 if (list->version != WL_BSS_INFO_VERSION) {
1483 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
1484 __func__, list->version);
1488 bi = bi ? (wl_bss_info_t *)((unsigned long)bi +
1489 le32_to_cpu(bi->length)) : list->
1492 WL_TRACE("%s : %s\n", __func__, bi->SSID);
1494 iwe.cmd = SIOCGIWAP;
1495 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1496 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETH_ALEN);
1498 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1500 iwe.u.data.length = le32_to_cpu(bi->SSID_len);
1501 iwe.cmd = SIOCGIWESSID;
1502 iwe.u.data.flags = 1;
1503 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
1505 if (le16_to_cpu(bi->capability) & (WLAN_CAPABILITY_ESS |
1506 WLAN_CAPABILITY_IBSS)) {
1507 iwe.cmd = SIOCGIWMODE;
1508 if (le16_to_cpu(bi->capability) & WLAN_CAPABILITY_ESS)
1509 iwe.u.mode = IW_MODE_INFRA;
1511 iwe.u.mode = IW_MODE_ADHOC;
1513 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1517 iwe.cmd = SIOCGIWFREQ;
1519 if (CHSPEC_CHANNEL(bi->chanspec) <= CH_MAX_2G_CHANNEL)
1520 iwe.u.freq.m = ieee80211_dsss_chan_to_freq(
1521 CHSPEC_CHANNEL(bi->chanspec));
1523 iwe.u.freq.m = ieee80211_ofdm_chan_to_freq(
1524 WF_CHAN_FACTOR_5_G/2,
1525 CHSPEC_CHANNEL(bi->chanspec));
1529 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1533 iwe.u.qual.qual = rssi_to_qual(le16_to_cpu(bi->RSSI));
1534 iwe.u.qual.level = 0x100 + le16_to_cpu(bi->RSSI);
1535 iwe.u.qual.noise = 0x100 + bi->phy_noise;
1537 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1540 wl_iw_handle_scanresults_ies(&event, end, info, bi);
1542 iwe.cmd = SIOCGIWENCODE;
1543 if (le16_to_cpu(bi->capability) & WLAN_CAPABILITY_PRIVACY)
1544 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1546 iwe.u.data.flags = IW_ENCODE_DISABLED;
1547 iwe.u.data.length = 0;
1549 IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
1551 if (bi->rateset.count) {
1552 if (((event - extra) +
1553 IW_EV_LCP_LEN) <= (unsigned long)end) {
1554 value = event + IW_EV_LCP_LEN;
1555 iwe.cmd = SIOCGIWRATE;
1556 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled =
1559 j < bi->rateset.count
1560 && j < IW_MAX_BITRATES; j++) {
1561 iwe.u.bitrate.value =
1562 (bi->rateset.rates[j] & 0x7f) *
1565 IWE_STREAM_ADD_VALUE(info, event,
1574 ret = event - extra;
1576 WL_ERROR("==> Wrong size\n");
1579 WL_TRACE("%s: size=%d bytes prepared\n",
1580 __func__, (unsigned int)(event - extra));
1585 wl_iw_get_scan(struct net_device *dev,
1586 struct iw_request_info *info, struct iw_point *dwrq, char *extra)
1589 wl_scan_results_t *list_merge;
1590 wl_scan_results_t *list = (wl_scan_results_t *) g_scan;
1592 uint buflen_from_user = dwrq->length;
1593 uint len = G_SCAN_RESULTS;
1595 #if defined(WL_IW_USE_ISCAN)
1596 iscan_info_t *iscan = g_iscan;
1600 WL_TRACE("%s: buflen_from_user %d:\n", dev->name, buflen_from_user);
1603 WL_TRACE("%s: wl_iw_get_scan return -EINVAL\n", dev->name);
1607 error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci));
1610 ci.scan_channel = le32_to_cpu(ci.scan_channel);
1611 if (ci.scan_channel)
1614 if (g_scan_specified_ssid) {
1615 list = kmalloc(len, GFP_KERNEL);
1617 WL_TRACE("%s: wl_iw_get_scan return -ENOMEM\n",
1619 g_scan_specified_ssid = 0;
1624 memset(list, 0, len);
1625 list->buflen = cpu_to_le32(len);
1626 error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, len);
1628 WL_ERROR("%s: %s : Scan_results ERROR %d\n",
1629 dev->name, __func__, error);
1631 if (g_scan_specified_ssid) {
1632 g_scan_specified_ssid = 0;
1637 list->buflen = le32_to_cpu(list->buflen);
1638 list->version = le32_to_cpu(list->version);
1639 list->count = le32_to_cpu(list->count);
1641 if (list->version != WL_BSS_INFO_VERSION) {
1642 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
1643 __func__, list->version);
1644 if (g_scan_specified_ssid) {
1645 g_scan_specified_ssid = 0;
1651 if (g_scan_specified_ssid) {
1652 WL_TRACE("%s: Specified scan APs in the list =%d\n",
1653 __func__, list->count);
1655 (__u16) wl_iw_get_scan_prep(list, info, extra,
1659 #if defined(WL_IW_USE_ISCAN)
1660 p_buf = iscan->list_hdr;
1661 while (p_buf != iscan->list_cur) {
1663 &((wl_iscan_results_t *) p_buf->iscan_buf)->results;
1664 WL_TRACE("%s: Bcast APs list=%d\n",
1665 __func__, list_merge->count);
1666 if (list_merge->count > 0)
1668 (__u16) wl_iw_get_scan_prep(list_merge,
1669 info, extra + len_ret,
1670 buflen_from_user - len_ret);
1671 p_buf = p_buf->next;
1674 list_merge = (wl_scan_results_t *) g_scan;
1675 WL_TRACE("%s: Bcast APs list=%d\n",
1676 __func__, list_merge->count);
1677 if (list_merge->count > 0)
1679 (__u16) wl_iw_get_scan_prep(list_merge, info,
1683 #endif /* defined(WL_IW_USE_ISCAN) */
1685 list = (wl_scan_results_t *) g_scan;
1687 (__u16) wl_iw_get_scan_prep(list, info, extra,
1691 #if defined(WL_IW_USE_ISCAN)
1692 g_scan_specified_ssid = 0;
1694 if ((len_ret + WE_ADD_EVENT_FIX) < buflen_from_user)
1700 WL_TRACE("%s return to WE %d bytes APs=%d\n",
1701 __func__, dwrq->length, list->count);
1705 #if defined(WL_IW_USE_ISCAN)
1707 wl_iw_iscan_get_scan(struct net_device *dev,
1708 struct iw_request_info *info,
1709 struct iw_point *dwrq, char *extra)
1711 wl_scan_results_t *list;
1712 struct iw_event iwe;
1713 wl_bss_info_t *bi = NULL;
1716 char *event = extra, *end = extra + dwrq->length, *value;
1717 iscan_info_t *iscan = g_iscan;
1722 WL_TRACE("%s %s buflen_from_user %d:\n",
1723 dev->name, __func__, dwrq->length);
1726 WL_TRACE("%s: INVALID SIOCGIWSCAN GET bad parameter\n",
1731 if ((!iscan) || (!iscan->sysioc_tsk)) {
1732 WL_ERROR("%ssysioc_tsk\n", __func__);
1733 return wl_iw_get_scan(dev, info, dwrq, extra);
1736 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1737 WL_TRACE("%s: SIOCGIWSCAN GET still scanning\n", dev->name);
1741 WL_TRACE("%s: SIOCGIWSCAN GET broadcast results\n", dev->name);
1743 p_buf = iscan->list_hdr;
1744 while (p_buf != iscan->list_cur) {
1745 list = &((wl_iscan_results_t *) p_buf->iscan_buf)->results;
1747 counter += list->count;
1749 if (list->version != WL_BSS_INFO_VERSION) {
1750 WL_ERROR("%s : list->version %d != WL_BSS_INFO_VERSION\n",
1751 __func__, list->version);
1756 for (ii = 0; ii < list->count && apcnt < IW_MAX_AP;
1758 bi = bi ? (wl_bss_info_t *)((unsigned long)bi +
1759 le32_to_cpu(bi->length)) :
1761 ASSERT(((unsigned long)bi + le32_to_cpu(bi->length)) <=
1762 ((unsigned long)list + WLC_IW_ISCAN_MAXLEN));
1764 if (event + ETH_ALEN + bi->SSID_len +
1765 IW_EV_UINT_LEN + IW_EV_FREQ_LEN + IW_EV_QUAL_LEN >=
1768 iwe.cmd = SIOCGIWAP;
1769 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1770 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID,
1773 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1776 iwe.u.data.length = le32_to_cpu(bi->SSID_len);
1777 iwe.cmd = SIOCGIWESSID;
1778 iwe.u.data.flags = 1;
1780 IWE_STREAM_ADD_POINT(info, event, end, &iwe,
1783 if (le16_to_cpu(bi->capability) &
1784 (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS)) {
1785 iwe.cmd = SIOCGIWMODE;
1786 if (le16_to_cpu(bi->capability) &
1787 WLAN_CAPABILITY_ESS)
1788 iwe.u.mode = IW_MODE_INFRA;
1790 iwe.u.mode = IW_MODE_ADHOC;
1792 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1796 iwe.cmd = SIOCGIWFREQ;
1799 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch;
1801 if (channel <= CH_MAX_2G_CHANNEL)
1803 ieee80211_dsss_chan_to_freq(channel);
1805 iwe.u.freq.m = ieee80211_ofdm_chan_to_freq(
1806 WF_CHAN_FACTOR_5_G/2,
1811 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1815 iwe.u.qual.qual = rssi_to_qual(le16_to_cpu(bi->RSSI));
1816 iwe.u.qual.level = 0x100 + le16_to_cpu(bi->RSSI);
1817 iwe.u.qual.noise = 0x100 + bi->phy_noise;
1819 IWE_STREAM_ADD_EVENT(info, event, end, &iwe,
1822 wl_iw_handle_scanresults_ies(&event, end, info, bi);
1824 iwe.cmd = SIOCGIWENCODE;
1825 if (le16_to_cpu(bi->capability) &
1826 WLAN_CAPABILITY_PRIVACY)
1828 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1830 iwe.u.data.flags = IW_ENCODE_DISABLED;
1831 iwe.u.data.length = 0;
1833 IWE_STREAM_ADD_POINT(info, event, end, &iwe,
1836 if (bi->rateset.count) {
1837 if (event + IW_MAX_BITRATES * IW_EV_PARAM_LEN >=
1841 value = event + IW_EV_LCP_LEN;
1842 iwe.cmd = SIOCGIWRATE;
1843 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled =
1846 j < bi->rateset.count
1847 && j < IW_MAX_BITRATES; j++) {
1848 iwe.u.bitrate.value =
1849 (bi->rateset.rates[j] & 0x7f) *
1852 IWE_STREAM_ADD_VALUE(info, event,
1860 p_buf = p_buf->next;
1863 dwrq->length = event - extra;
1866 WL_TRACE("%s return to WE %d bytes APs=%d\n",
1867 __func__, dwrq->length, counter);
1874 #endif /* defined(WL_IW_USE_ISCAN) */
1877 wl_iw_set_essid(struct net_device *dev,
1878 struct iw_request_info *info,
1879 struct iw_point *dwrq, char *extra)
1882 wl_join_params_t join_params;
1883 int join_params_size;
1885 WL_TRACE("%s: SIOCSIWESSID\n", dev->name);
1887 if (g_set_essid_before_scan)
1890 memset(&g_ssid, 0, sizeof(g_ssid));
1892 CHECK_EXTRA_FOR_NULL(extra);
1894 if (dwrq->length && extra) {
1895 #if WIRELESS_EXT > 20
1896 g_ssid.SSID_len = min_t(size_t, sizeof(g_ssid.SSID),
1899 g_ssid.SSID_len = min_t(size_t, sizeof(g_ssid.SSID),
1902 memcpy(g_ssid.SSID, extra, g_ssid.SSID_len);
1904 g_ssid.SSID_len = 0;
1906 g_ssid.SSID_len = cpu_to_le32(g_ssid.SSID_len);
1908 memset(&join_params, 0, sizeof(join_params));
1909 join_params_size = sizeof(join_params.ssid);
1911 memcpy(&join_params.ssid.SSID, g_ssid.SSID, g_ssid.SSID_len);
1912 join_params.ssid.SSID_len = cpu_to_le32(g_ssid.SSID_len);
1913 memcpy(join_params.params.bssid, ether_bcast, ETH_ALEN);
1915 wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params,
1918 error = dev_wlc_ioctl(dev, WLC_SET_SSID, &join_params,
1921 WL_ERROR("Invalid ioctl data=%d\n", error);
1923 if (g_ssid.SSID_len) {
1924 WL_TRACE("%s: join SSID=%s ch=%d\n",
1925 __func__, g_ssid.SSID, g_wl_iw_params.target_channel);
1931 wl_iw_get_essid(struct net_device *dev,
1932 struct iw_request_info *info,
1933 struct iw_point *dwrq, char *extra)
1938 WL_TRACE("%s: SIOCGIWESSID\n", dev->name);
1943 error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid));
1945 WL_ERROR("Error getting the SSID\n");
1949 ssid.SSID_len = le32_to_cpu(ssid.SSID_len);
1951 memcpy(extra, ssid.SSID, ssid.SSID_len);
1953 dwrq->length = ssid.SSID_len;
1961 wl_iw_set_nick(struct net_device *dev,
1962 struct iw_request_info *info, struct iw_point *dwrq, char *extra)
1964 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
1966 WL_TRACE("%s: SIOCSIWNICKN\n", dev->name);
1971 if (dwrq->length > sizeof(iw->nickname))
1974 memcpy(iw->nickname, extra, dwrq->length);
1975 iw->nickname[dwrq->length - 1] = '\0';
1981 wl_iw_get_nick(struct net_device *dev,
1982 struct iw_request_info *info, struct iw_point *dwrq, char *extra)
1984 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
1986 WL_TRACE("%s: SIOCGIWNICKN\n", dev->name);
1991 strcpy(extra, iw->nickname);
1992 dwrq->length = strlen(extra) + 1;
1998 wl_iw_set_rate(struct net_device *dev,
1999 struct iw_request_info *info, struct iw_param *vwrq, char *extra)
2001 wl_rateset_t rateset;
2002 int error, rate, i, error_bg, error_a;
2004 WL_TRACE("%s: SIOCSIWRATE\n", dev->name);
2006 error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset,
2011 rateset.count = le32_to_cpu(rateset.count);
2013 if (vwrq->value < 0)
2014 rate = rateset.rates[rateset.count - 1] & 0x7f;
2015 else if (vwrq->value < rateset.count)
2016 rate = rateset.rates[vwrq->value] & 0x7f;
2018 rate = vwrq->value / 500000;
2021 error_bg = dev_wlc_intvar_set(dev, "bg_rate", rate);
2022 error_a = dev_wlc_intvar_set(dev, "a_rate", rate);
2024 if (error_bg && error_a)
2025 return error_bg | error_a;
2027 error_bg = dev_wlc_intvar_set(dev, "bg_rate", 0);
2028 error_a = dev_wlc_intvar_set(dev, "a_rate", 0);
2030 if (error_bg && error_a)
2031 return error_bg | error_a;
2033 for (i = 0; i < rateset.count; i++)
2034 if ((rateset.rates[i] & 0x7f) > rate)
2036 rateset.count = cpu_to_le32(i);
2038 error = dev_wlc_ioctl(dev, WLC_SET_RATESET, &rateset,
2048 wl_iw_get_rate(struct net_device *dev,
2049 struct iw_request_info *info, struct iw_param *vwrq, char *extra)
2053 WL_TRACE("%s: SIOCGIWRATE\n", dev->name);
2055 error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate));
2058 rate = le32_to_cpu(rate);
2059 vwrq->value = rate * 500000;
2065 wl_iw_set_rts(struct net_device *dev,
2066 struct iw_request_info *info, struct iw_param *vwrq, char *extra)
2070 WL_TRACE("%s: SIOCSIWRTS\n", dev->name);
2073 rts = DOT11_DEFAULT_RTS_LEN;
2074 else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_RTS_LEN)
2079 error = dev_wlc_intvar_set(dev, "rtsthresh", rts);
2087 wl_iw_get_rts(struct net_device *dev,
2088 struct iw_request_info *info, struct iw_param *vwrq, char *extra)
2092 WL_TRACE("%s: SIOCGIWRTS\n", dev->name);
2094 error = dev_wlc_intvar_get(dev, "rtsthresh", &rts);
2099 vwrq->disabled = (rts >= DOT11_DEFAULT_RTS_LEN);
2106 wl_iw_set_frag(struct net_device *dev,
2107 struct iw_request_info *info, struct iw_param *vwrq, char *extra)
2111 WL_TRACE("%s: SIOCSIWFRAG\n", dev->name);
2114 frag = DOT11_DEFAULT_FRAG_LEN;
2115 else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_FRAG_LEN)
2120 error = dev_wlc_intvar_set(dev, "fragthresh", frag);
2128 wl_iw_get_frag(struct net_device *dev,
2129 struct iw_request_info *info, struct iw_param *vwrq, char *extra)
2131 int error, fragthreshold;
2133 WL_TRACE("%s: SIOCGIWFRAG\n", dev->name);
2135 error = dev_wlc_intvar_get(dev, "fragthresh", &fragthreshold);
2139 vwrq->value = fragthreshold;
2140 vwrq->disabled = (fragthreshold >= DOT11_DEFAULT_FRAG_LEN);
2147 wl_iw_set_txpow(struct net_device *dev,
2148 struct iw_request_info *info,
2149 struct iw_param *vwrq, char *extra)
2153 WL_TRACE("%s: SIOCSIWTXPOW\n", dev->name);
2155 disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0;
2156 disable += WL_RADIO_SW_DISABLE << 16;
2158 disable = cpu_to_le32(disable);
2159 error = dev_wlc_ioctl(dev, WLC_SET_RADIO, &disable, sizeof(disable));
2163 if (disable & WL_RADIO_SW_DISABLE)
2166 if (!(vwrq->flags & IW_TXPOW_MWATT))
2169 if (vwrq->value < 0)
2172 if (vwrq->value > 0xffff)
2175 txpwrmw = (u16) vwrq->value;
2178 dev_wlc_intvar_set(dev, "qtxpower", (int)(bcm_mw_to_qdbm(txpwrmw)));
2183 wl_iw_get_txpow(struct net_device *dev,
2184 struct iw_request_info *info,
2185 struct iw_param *vwrq, char *extra)
2187 int error, disable, txpwrdbm;
2190 WL_TRACE("%s: SIOCGIWTXPOW\n", dev->name);
2192 error = dev_wlc_ioctl(dev, WLC_GET_RADIO, &disable, sizeof(disable));
2196 error = dev_wlc_intvar_get(dev, "qtxpower", &txpwrdbm);
2200 disable = le32_to_cpu(disable);
2201 result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
2202 vwrq->value = (s32) bcm_qdbm_to_mw(result);
2205 (disable & (WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE)) ? 1 : 0;
2206 vwrq->flags = IW_TXPOW_MWATT;
2211 #if WIRELESS_EXT > 10
2213 wl_iw_set_retry(struct net_device *dev,
2214 struct iw_request_info *info,
2215 struct iw_param *vwrq, char *extra)
2217 int error, lrl, srl;
2219 WL_TRACE("%s: SIOCSIWRETRY\n", dev->name);
2221 if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME))
2224 if (vwrq->flags & IW_RETRY_LIMIT) {
2226 #if WIRELESS_EXT > 20
2227 if ((vwrq->flags & IW_RETRY_LONG)
2228 || (vwrq->flags & IW_RETRY_MAX)
2229 || !((vwrq->flags & IW_RETRY_SHORT)
2230 || (vwrq->flags & IW_RETRY_MIN))) {
2232 if ((vwrq->flags & IW_RETRY_MAX)
2233 || !(vwrq->flags & IW_RETRY_MIN)) {
2235 lrl = cpu_to_le32(vwrq->value);
2236 error = dev_wlc_ioctl(dev, WLC_SET_LRL, &lrl,
2241 #if WIRELESS_EXT > 20
2242 if ((vwrq->flags & IW_RETRY_SHORT)
2243 || (vwrq->flags & IW_RETRY_MIN)
2244 || !((vwrq->flags & IW_RETRY_LONG)
2245 || (vwrq->flags & IW_RETRY_MAX))) {
2247 if ((vwrq->flags & IW_RETRY_MIN)
2248 || !(vwrq->flags & IW_RETRY_MAX)) {
2250 srl = cpu_to_le32(vwrq->value);
2251 error = dev_wlc_ioctl(dev, WLC_SET_SRL, &srl,
2261 wl_iw_get_retry(struct net_device *dev,
2262 struct iw_request_info *info,
2263 struct iw_param *vwrq, char *extra)
2265 int error, lrl, srl;
2267 WL_TRACE("%s: SIOCGIWRETRY\n", dev->name);
2271 if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
2274 error = dev_wlc_ioctl(dev, WLC_GET_LRL, &lrl, sizeof(lrl));
2278 error = dev_wlc_ioctl(dev, WLC_GET_SRL, &srl, sizeof(srl));
2282 lrl = le32_to_cpu(lrl);
2283 srl = le32_to_cpu(srl);
2285 if (vwrq->flags & IW_RETRY_MAX) {
2286 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
2289 vwrq->flags = IW_RETRY_LIMIT;
2292 vwrq->flags |= IW_RETRY_MIN;
2297 #endif /* WIRELESS_EXT > 10 */
2300 wl_iw_set_encode(struct net_device *dev,
2301 struct iw_request_info *info,
2302 struct iw_point *dwrq, char *extra)
2305 int error, val, wsec;
2307 WL_TRACE("%s: SIOCSIWENCODE\n", dev->name);
2309 memset(&key, 0, sizeof(key));
2311 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2312 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS;
2314 val = cpu_to_le32(key.index);
2315 error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val,
2319 val = le32_to_cpu(val);
2323 if (key.index == DOT11_MAX_DEFAULT_KEYS)
2326 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2327 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
2331 if (!extra || !dwrq->length || (dwrq->flags & IW_ENCODE_NOKEY)) {
2332 val = cpu_to_le32(key.index);
2333 error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, &val,
2338 key.len = dwrq->length;
2340 if (dwrq->length > sizeof(key.data))
2343 memcpy(key.data, extra, dwrq->length);
2345 key.flags = WL_PRIMARY_KEY;
2347 case WLAN_KEY_LEN_WEP40:
2348 key.algo = CRYPTO_ALGO_WEP1;
2350 case WLAN_KEY_LEN_WEP104:
2351 key.algo = CRYPTO_ALGO_WEP128;
2353 case WLAN_KEY_LEN_TKIP:
2354 key.algo = CRYPTO_ALGO_TKIP;
2356 case WLAN_KEY_LEN_AES_CMAC:
2357 key.algo = CRYPTO_ALGO_AES_CCM;
2363 swap_key_from_BE(&key);
2364 error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2369 val = (dwrq->flags & IW_ENCODE_DISABLED) ? 0 : WEP_ENABLED;
2371 error = dev_wlc_intvar_get(dev, "wsec", &wsec);
2375 wsec &= ~(WEP_ENABLED);
2378 error = dev_wlc_intvar_set(dev, "wsec", wsec);
2382 val = (dwrq->flags & IW_ENCODE_RESTRICTED) ? 1 : 0;
2383 val = cpu_to_le32(val);
2384 error = dev_wlc_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val));
2392 wl_iw_get_encode(struct net_device *dev,
2393 struct iw_request_info *info,
2394 struct iw_point *dwrq, char *extra)
2397 int error, val, wsec, auth;
2399 WL_TRACE("%s: SIOCGIWENCODE\n", dev->name);
2401 memset(&key, 0, sizeof(wl_wsec_key_t));
2403 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2404 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS;
2407 error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val,
2411 val = le32_to_cpu(val);
2416 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2418 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
2421 error = dev_wlc_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec));
2425 error = dev_wlc_ioctl(dev, WLC_GET_AUTH, &auth, sizeof(auth));
2429 swap_key_to_BE(&key);
2431 wsec = le32_to_cpu(wsec);
2432 auth = le32_to_cpu(auth);
2433 dwrq->length = min_t(u16, WLAN_MAX_KEY_LEN, key.len);
2435 dwrq->flags = key.index + 1;
2436 if (!(wsec & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED)))
2437 dwrq->flags |= IW_ENCODE_DISABLED;
2440 dwrq->flags |= IW_ENCODE_RESTRICTED;
2442 if (dwrq->length && extra)
2443 memcpy(extra, key.data, dwrq->length);
2449 wl_iw_set_power(struct net_device *dev,
2450 struct iw_request_info *info,
2451 struct iw_param *vwrq, char *extra)
2455 WL_TRACE("%s: SIOCSIWPOWER\n", dev->name);
2457 pm = vwrq->disabled ? PM_OFF : PM_MAX;
2459 pm = cpu_to_le32(pm);
2460 error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
2468 wl_iw_get_power(struct net_device *dev,
2469 struct iw_request_info *info,
2470 struct iw_param *vwrq, char *extra)
2474 WL_TRACE("%s: SIOCGIWPOWER\n", dev->name);
2476 error = dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm));
2480 pm = le32_to_cpu(pm);
2481 vwrq->disabled = pm ? 0 : 1;
2482 vwrq->flags = IW_POWER_ALL_R;
2487 #if WIRELESS_EXT > 17
2489 wl_iw_set_wpaie(struct net_device *dev,
2490 struct iw_request_info *info, struct iw_point *iwp, char *extra)
2493 WL_TRACE("%s: SIOCSIWGENIE\n", dev->name);
2495 CHECK_EXTRA_FOR_NULL(extra);
2497 dev_wlc_bufvar_set(dev, "wpaie", extra, iwp->length);
2503 wl_iw_get_wpaie(struct net_device *dev,
2504 struct iw_request_info *info, struct iw_point *iwp, char *extra)
2506 WL_TRACE("%s: SIOCGIWGENIE\n", dev->name);
2508 dev_wlc_bufvar_get(dev, "wpaie", extra, iwp->length);
2513 wl_iw_set_encodeext(struct net_device *dev,
2514 struct iw_request_info *info,
2515 struct iw_point *dwrq, char *extra)
2519 struct iw_encode_ext *iwe;
2521 WL_TRACE("%s: SIOCSIWENCODEEXT\n", dev->name);
2523 CHECK_EXTRA_FOR_NULL(extra);
2525 memset(&key, 0, sizeof(key));
2526 iwe = (struct iw_encode_ext *)extra;
2528 if (dwrq->flags & IW_ENCODE_DISABLED) {
2533 if (dwrq->flags & IW_ENCODE_INDEX)
2534 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2536 key.len = iwe->key_len;
2538 if (!is_multicast_ether_addr(iwe->addr.sa_data))
2539 memcpy(&key.ea, &iwe->addr.sa_data, ETH_ALEN);
2542 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2543 WL_WSEC("Changing the the primary Key to %d\n",
2545 key.index = cpu_to_le32(key.index);
2546 error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY,
2547 &key.index, sizeof(key.index));
2551 swap_key_from_BE(&key);
2552 dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2555 if (iwe->key_len > sizeof(key.data))
2558 WL_WSEC("Setting the key index %d\n", key.index);
2559 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2560 WL_WSEC("key is a Primary Key\n");
2561 key.flags = WL_PRIMARY_KEY;
2564 memcpy(key.data, iwe->key, iwe->key_len);
2566 if (iwe->alg == IW_ENCODE_ALG_TKIP) {
2568 memcpy(keybuf, &key.data[24], sizeof(keybuf));
2569 memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
2570 memcpy(&key.data[16], keybuf, sizeof(keybuf));
2573 if (iwe->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
2574 unsigned char *ivptr;
2575 ivptr = (unsigned char *) iwe->rx_seq;
2576 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
2577 (ivptr[3] << 8) | ivptr[2];
2578 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
2579 key.iv_initialized = true;
2583 case IW_ENCODE_ALG_NONE:
2584 key.algo = CRYPTO_ALGO_OFF;
2586 case IW_ENCODE_ALG_WEP:
2587 if (iwe->key_len == WLAN_KEY_LEN_WEP40)
2588 key.algo = CRYPTO_ALGO_WEP1;
2590 key.algo = CRYPTO_ALGO_WEP128;
2592 case IW_ENCODE_ALG_TKIP:
2593 key.algo = CRYPTO_ALGO_TKIP;
2595 case IW_ENCODE_ALG_CCMP:
2596 key.algo = CRYPTO_ALGO_AES_CCM;
2601 swap_key_from_BE(&key);
2603 dhd_wait_pend8021x(dev);
2605 error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2612 #if WIRELESS_EXT > 17
2614 pmkid_list_t pmkids;
2615 pmkid_t foo[MAXPMKID - 1];
2619 wl_iw_set_pmksa(struct net_device *dev,
2620 struct iw_request_info *info,
2621 struct iw_param *vwrq, char *extra)
2623 struct iw_pmksa *iwpmksa;
2627 WL_WSEC("%s: SIOCSIWPMKSA\n", dev->name);
2629 CHECK_EXTRA_FOR_NULL(extra);
2631 iwpmksa = (struct iw_pmksa *)extra;
2633 if (iwpmksa->cmd == IW_PMKSA_FLUSH) {
2634 WL_WSEC("wl_iw_set_pmksa - IW_PMKSA_FLUSH\n");
2635 memset((char *)&pmkid_list, 0, sizeof(pmkid_list));
2638 else if (iwpmksa->cmd == IW_PMKSA_REMOVE) {
2640 pmkid_list_t pmkid, *pmkidptr;
2644 memcpy(&pmkidptr->pmkid[0].BSSID,
2645 &iwpmksa->bssid.sa_data[0],
2647 memcpy(&pmkidptr->pmkid[0].PMKID,
2651 WL_WSEC("wl_iw_set_pmksa:IW_PMKSA_REMOVE:PMKID: "
2652 "%pM = ", &pmkidptr->pmkid[0].BSSID);
2653 for (j = 0; j < WLAN_PMKID_LEN; j++)
2654 WL_WSEC("%02x ", pmkidptr->pmkid[0].PMKID[j]);
2658 for (i = 0; i < pmkid_list.pmkids.npmkid; i++)
2660 (&iwpmksa->bssid.sa_data[0],
2661 &pmkid_list.pmkids.pmkid[i].BSSID, ETH_ALEN))
2664 if ((pmkid_list.pmkids.npmkid > 0)
2665 && (i < pmkid_list.pmkids.npmkid)) {
2666 memset(&pmkid_list.pmkids.pmkid[i], 0, sizeof(pmkid_t));
2667 for (; i < (pmkid_list.pmkids.npmkid - 1); i++) {
2668 memcpy(&pmkid_list.pmkids.pmkid[i].BSSID,
2669 &pmkid_list.pmkids.pmkid[i + 1].BSSID,
2671 memcpy(&pmkid_list.pmkids.pmkid[i].PMKID,
2672 &pmkid_list.pmkids.pmkid[i + 1].PMKID,
2675 pmkid_list.pmkids.npmkid--;
2680 else if (iwpmksa->cmd == IW_PMKSA_ADD) {
2681 for (i = 0; i < pmkid_list.pmkids.npmkid; i++)
2683 (&iwpmksa->bssid.sa_data[0],
2684 &pmkid_list.pmkids.pmkid[i].BSSID, ETH_ALEN))
2687 memcpy(&pmkid_list.pmkids.pmkid[i].BSSID,
2688 &iwpmksa->bssid.sa_data[0],
2690 memcpy(&pmkid_list.pmkids.pmkid[i].PMKID,
2693 if (i == pmkid_list.pmkids.npmkid)
2694 pmkid_list.pmkids.npmkid++;
2700 k = pmkid_list.pmkids.npmkid;
2701 WL_WSEC("wl_iw_set_pmksa,IW_PMKSA_ADD - PMKID: %pM = ",
2702 &pmkid_list.pmkids.pmkid[k].BSSID);
2703 for (j = 0; j < WLAN_PMKID_LEN; j++)
2705 pmkid_list.pmkids.pmkid[k].PMKID[j]);
2709 WL_WSEC("PRINTING pmkid LIST - No of elements %d\n",
2710 pmkid_list.pmkids.npmkid);
2711 for (i = 0; i < pmkid_list.pmkids.npmkid; i++) {
2713 WL_WSEC("PMKID[%d]: %pM = ",
2714 i, &pmkid_list.pmkids.pmkid[i].BSSID);
2715 for (j = 0; j < WLAN_PMKID_LEN; j++)
2716 WL_WSEC("%02x ", pmkid_list.pmkids.pmkid[i].PMKID[j]);
2722 ret = dev_wlc_bufvar_set(dev, "pmkid_info", (char *)&pmkid_list,
2723 sizeof(pmkid_list));
2726 #endif /* WIRELESS_EXT > 17 */
2729 wl_iw_get_encodeext(struct net_device *dev,
2730 struct iw_request_info *info,
2731 struct iw_param *vwrq, char *extra)
2733 WL_TRACE("%s: SIOCGIWENCODEEXT\n", dev->name);
2738 wl_iw_set_wpaauth(struct net_device *dev,
2739 struct iw_request_info *info,
2740 struct iw_param *vwrq, char *extra)
2746 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
2748 WL_TRACE("%s: SIOCSIWAUTH\n", dev->name);
2750 paramid = vwrq->flags & IW_AUTH_INDEX;
2751 paramval = vwrq->value;
2753 WL_TRACE("%s: SIOCSIWAUTH, paramid = 0x%0x, paramval = 0x%0x\n",
2754 dev->name, paramid, paramval);
2757 case IW_AUTH_WPA_VERSION:
2758 if (paramval & IW_AUTH_WPA_VERSION_DISABLED)
2759 val = WPA_AUTH_DISABLED;
2760 else if (paramval & (IW_AUTH_WPA_VERSION_WPA))
2761 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
2762 else if (paramval & IW_AUTH_WPA_VERSION_WPA2)
2763 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
2764 WL_INFORM("%s: %d: setting wpa_auth to 0x%0x\n",
2765 __func__, __LINE__, val);
2766 error = dev_wlc_intvar_set(dev, "wpa_auth", val);
2770 case IW_AUTH_CIPHER_PAIRWISE:
2771 case IW_AUTH_CIPHER_GROUP:
2772 if (paramval & (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
2774 if (paramval & IW_AUTH_CIPHER_TKIP)
2776 if (paramval & IW_AUTH_CIPHER_CCMP)
2779 if (paramid == IW_AUTH_CIPHER_PAIRWISE) {
2787 if (iw->privacy_invoked && !val) {
2788 WL_WSEC("%s: %s: 'Privacy invoked' true but clearing wsec, assuming we're a WPS enrollee\n",
2789 dev->name, __func__);
2790 error = dev_wlc_intvar_set(dev, "is_WPS_enrollee",
2793 WL_WSEC("Failed to set is_WPS_enrollee\n");
2797 error = dev_wlc_intvar_set(dev, "is_WPS_enrollee",
2800 WL_WSEC("Failed to clear is_WPS_enrollee\n");
2805 error = dev_wlc_intvar_set(dev, "wsec", val);
2811 case IW_AUTH_KEY_MGMT:
2812 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_PSK)
2820 val = WPA_AUTH_UNSPECIFIED;
2821 } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
2822 if (paramval & IW_AUTH_KEY_MGMT_PSK)
2823 val = WPA2_AUTH_PSK;
2825 val = WPA2_AUTH_UNSPECIFIED;
2827 WL_INFORM("%s: %d: setting wpa_auth to %d\n",
2828 __func__, __LINE__, val);
2829 error = dev_wlc_intvar_set(dev, "wpa_auth", val);
2834 case IW_AUTH_TKIP_COUNTERMEASURES:
2835 dev_wlc_bufvar_set(dev, "tkip_countermeasures",
2836 (char *)¶mval, 1);
2839 case IW_AUTH_80211_AUTH_ALG:
2840 WL_INFORM("Setting the D11auth %d\n", paramval);
2841 if (paramval == IW_AUTH_ALG_OPEN_SYSTEM)
2843 else if (paramval == IW_AUTH_ALG_SHARED_KEY)
2845 else if (paramval ==
2846 (IW_AUTH_ALG_OPEN_SYSTEM | IW_AUTH_ALG_SHARED_KEY))
2851 error = dev_wlc_intvar_set(dev, "auth", val);
2857 case IW_AUTH_WPA_ENABLED:
2858 if (paramval == 0) {
2861 error = dev_wlc_intvar_get(dev, "wsec", &val);
2864 if (val & (TKIP_ENABLED | AES_ENABLED)) {
2865 val &= ~(TKIP_ENABLED | AES_ENABLED);
2866 dev_wlc_intvar_set(dev, "wsec", val);
2869 WL_INFORM("%s: %d: setting wpa_auth to %d\n",
2870 __func__, __LINE__, val);
2871 dev_wlc_intvar_set(dev, "wpa_auth", 0);
2876 case IW_AUTH_DROP_UNENCRYPTED:
2877 dev_wlc_bufvar_set(dev, "wsec_restrict", (char *)¶mval, 1);
2880 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
2881 dev_wlc_bufvar_set(dev, "rx_unencrypted_eapol",
2882 (char *)¶mval, 1);
2885 #if WIRELESS_EXT > 17
2886 case IW_AUTH_ROAMING_CONTROL:
2887 WL_INFORM("%s: IW_AUTH_ROAMING_CONTROL\n", __func__);
2889 case IW_AUTH_PRIVACY_INVOKED:
2893 if (paramval == 0) {
2894 iw->privacy_invoked = false;
2895 error = dev_wlc_intvar_set(dev,
2896 "is_WPS_enrollee", false);
2898 WL_WSEC("Failed to clear iovar is_WPS_enrollee\n");
2902 iw->privacy_invoked = true;
2903 error = dev_wlc_intvar_get(dev, "wsec", &wsec);
2907 if (!(IW_WSEC_ENABLED(wsec))) {
2908 error = dev_wlc_intvar_set(dev,
2912 WL_WSEC("Failed to set iovar is_WPS_enrollee\n");
2916 error = dev_wlc_intvar_set(dev,
2920 WL_WSEC("Failed to clear is_WPS_enrollee\n");
2927 #endif /* WIRELESS_EXT > 17 */
2934 #define VAL_PSK(_val) (((_val) & WPA_AUTH_PSK) || ((_val) & WPA2_AUTH_PSK))
2937 wl_iw_get_wpaauth(struct net_device *dev,
2938 struct iw_request_info *info,
2939 struct iw_param *vwrq, char *extra)
2945 wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev);
2947 WL_TRACE("%s: SIOCGIWAUTH\n", dev->name);
2949 paramid = vwrq->flags & IW_AUTH_INDEX;
2952 case IW_AUTH_WPA_VERSION:
2953 error = dev_wlc_intvar_get(dev, "wpa_auth", &val);
2956 if (val & (WPA_AUTH_NONE | WPA_AUTH_DISABLED))
2957 paramval = IW_AUTH_WPA_VERSION_DISABLED;
2958 else if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED))
2959 paramval = IW_AUTH_WPA_VERSION_WPA;
2960 else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED))
2961 paramval = IW_AUTH_WPA_VERSION_WPA2;
2963 case IW_AUTH_CIPHER_PAIRWISE:
2964 case IW_AUTH_CIPHER_GROUP:
2965 if (paramid == IW_AUTH_CIPHER_PAIRWISE)
2972 if (val & WEP_ENABLED)
2974 (IW_AUTH_CIPHER_WEP40 |
2975 IW_AUTH_CIPHER_WEP104);
2976 if (val & TKIP_ENABLED)
2977 paramval |= (IW_AUTH_CIPHER_TKIP);
2978 if (val & AES_ENABLED)
2979 paramval |= (IW_AUTH_CIPHER_CCMP);
2981 paramval = IW_AUTH_CIPHER_NONE;
2983 case IW_AUTH_KEY_MGMT:
2984 error = dev_wlc_intvar_get(dev, "wpa_auth", &val);
2988 paramval = IW_AUTH_KEY_MGMT_PSK;
2990 paramval = IW_AUTH_KEY_MGMT_802_1X;
2993 case IW_AUTH_TKIP_COUNTERMEASURES:
2994 dev_wlc_bufvar_get(dev, "tkip_countermeasures",
2995 (char *)¶mval, 1);
2998 case IW_AUTH_DROP_UNENCRYPTED:
2999 dev_wlc_bufvar_get(dev, "wsec_restrict", (char *)¶mval, 1);
3002 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3003 dev_wlc_bufvar_get(dev, "rx_unencrypted_eapol",
3004 (char *)¶mval, 1);
3007 case IW_AUTH_80211_AUTH_ALG:
3008 error = dev_wlc_intvar_get(dev, "auth", &val);
3012 paramval = IW_AUTH_ALG_OPEN_SYSTEM;
3014 paramval = IW_AUTH_ALG_SHARED_KEY;
3016 case IW_AUTH_WPA_ENABLED:
3017 error = dev_wlc_intvar_get(dev, "wpa_auth", &val);
3025 #if WIRELESS_EXT > 17
3026 case IW_AUTH_ROAMING_CONTROL:
3027 WL_ERROR("%s: IW_AUTH_ROAMING_CONTROL\n", __func__);
3029 case IW_AUTH_PRIVACY_INVOKED:
3030 paramval = iw->privacy_invoked;
3035 vwrq->value = paramval;
3038 #endif /* WIRELESS_EXT > 17 */
3040 static const iw_handler wl_iw_handler[] = {
3041 (iw_handler) wl_iw_config_commit,
3042 (iw_handler) wl_iw_get_name,
3045 (iw_handler) wl_iw_set_freq,
3046 (iw_handler) wl_iw_get_freq,
3047 (iw_handler) wl_iw_set_mode,
3048 (iw_handler) wl_iw_get_mode,
3052 (iw_handler) wl_iw_get_range,
3057 (iw_handler) wl_iw_set_spy,
3058 (iw_handler) wl_iw_get_spy,
3061 (iw_handler) wl_iw_set_wap,
3062 (iw_handler) wl_iw_get_wap,
3063 #if WIRELESS_EXT > 17
3064 (iw_handler) wl_iw_mlme,
3068 #if defined(WL_IW_USE_ISCAN)
3069 (iw_handler) wl_iw_iscan_get_aplist,
3071 (iw_handler) wl_iw_get_aplist,
3073 #if WIRELESS_EXT > 13
3074 #if defined(WL_IW_USE_ISCAN)
3075 (iw_handler) wl_iw_iscan_set_scan,
3076 (iw_handler) wl_iw_iscan_get_scan,
3078 (iw_handler) wl_iw_set_scan,
3079 (iw_handler) wl_iw_get_scan,
3084 #endif /* WIRELESS_EXT > 13 */
3085 (iw_handler) wl_iw_set_essid,
3086 (iw_handler) wl_iw_get_essid,
3087 (iw_handler) wl_iw_set_nick,
3088 (iw_handler) wl_iw_get_nick,
3091 (iw_handler) wl_iw_set_rate,
3092 (iw_handler) wl_iw_get_rate,
3093 (iw_handler) wl_iw_set_rts,
3094 (iw_handler) wl_iw_get_rts,
3095 (iw_handler) wl_iw_set_frag,
3096 (iw_handler) wl_iw_get_frag,
3097 (iw_handler) wl_iw_set_txpow,
3098 (iw_handler) wl_iw_get_txpow,
3099 #if WIRELESS_EXT > 10
3100 (iw_handler) wl_iw_set_retry,
3101 (iw_handler) wl_iw_get_retry,
3103 (iw_handler) wl_iw_set_encode,
3104 (iw_handler) wl_iw_get_encode,
3105 (iw_handler) wl_iw_set_power,
3106 (iw_handler) wl_iw_get_power,
3107 #if WIRELESS_EXT > 17
3110 (iw_handler) wl_iw_set_wpaie,
3111 (iw_handler) wl_iw_get_wpaie,
3112 (iw_handler) wl_iw_set_wpaauth,
3113 (iw_handler) wl_iw_get_wpaauth,
3114 (iw_handler) wl_iw_set_encodeext,
3115 (iw_handler) wl_iw_get_encodeext,
3116 (iw_handler) wl_iw_set_pmksa,
3117 #endif /* WIRELESS_EXT > 17 */
3120 #if WIRELESS_EXT > 12
3122 const struct iw_handler_def wl_iw_handler_def = {
3123 .num_standard = ARRAY_SIZE(wl_iw_handler),
3124 .standard = (iw_handler *) wl_iw_handler,
3126 .num_private_args = 0,
3130 #if WIRELESS_EXT >= 19
3131 .get_wireless_stats = NULL,
3134 #endif /* WIRELESS_EXT > 12 */
3136 int wl_iw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3138 struct iwreq *wrq = (struct iwreq *)rq;
3139 struct iw_request_info info;
3142 int token_size = 1, max_tokens = 0, ret = 0;
3144 WL_TRACE("\n%s, cmd:%x alled via dhd->do_ioctl()entry point\n",
3146 if (cmd < SIOCIWFIRST ||
3147 IW_IOCTL_IDX(cmd) >= ARRAY_SIZE(wl_iw_handler)) {
3148 WL_ERROR("%s: error in cmd=%x : out of range\n",
3153 handler = wl_iw_handler[IW_IOCTL_IDX(cmd)];
3155 WL_ERROR("%s: error in cmd=%x : not supported\n",
3166 max_tokens = IW_ESSID_MAX_SIZE + 1;
3171 #if WIRELESS_EXT > 17
3172 case SIOCSIWENCODEEXT:
3173 case SIOCGIWENCODEEXT:
3175 max_tokens = wrq->u.data.length;
3179 max_tokens = sizeof(struct iw_range) + 500;
3184 sizeof(struct sockaddr) + sizeof(struct iw_quality);
3185 max_tokens = IW_MAX_AP;
3188 #if WIRELESS_EXT > 13
3190 #if defined(WL_IW_USE_ISCAN)
3192 max_tokens = wrq->u.data.length;
3195 max_tokens = IW_SCAN_MAX_DATA;
3197 #endif /* WIRELESS_EXT > 13 */
3200 token_size = sizeof(struct sockaddr);
3201 max_tokens = IW_MAX_SPY;
3206 sizeof(struct sockaddr) + sizeof(struct iw_quality);
3207 max_tokens = IW_MAX_SPY;
3210 #if WIRELESS_EXT > 17
3215 max_tokens = wrq->u.data.length;
3219 if (max_tokens && wrq->u.data.pointer) {
3220 if (wrq->u.data.length > max_tokens) {
3221 WL_ERROR("%s: error in cmd=%x wrq->u.data.length=%d > max_tokens=%d\n",
3222 __func__, cmd, wrq->u.data.length, max_tokens);
3225 extra = kmalloc(max_tokens * token_size, GFP_KERNEL);
3230 (extra, wrq->u.data.pointer,
3231 wrq->u.data.length * token_size)) {
3240 ret = handler(dev, &info, &wrq->u, extra);
3244 (wrq->u.data.pointer, extra,
3245 wrq->u.data.length * token_size)) {
3257 wl_iw_conn_status_str(u32 event_type, u32 status, u32 reason,
3258 char *stringBuf, uint buflen)
3260 typedef struct conn_fail_event_map_t {
3264 const char *outName;
3265 const char *outCause;
3266 } conn_fail_event_map_t;
3268 #define WL_IW_DONT_CARE 9999
3269 const conn_fail_event_map_t event_map[] = {
3270 {WLC_E_SET_SSID, WLC_E_STATUS_SUCCESS, WL_IW_DONT_CARE,
3272 {WLC_E_SET_SSID, WLC_E_STATUS_NO_NETWORKS, WL_IW_DONT_CARE,
3273 "Conn", "NoNetworks"},
3274 {WLC_E_SET_SSID, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3275 "Conn", "ConfigMismatch"},
3276 {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_PRUNE_ENCR_MISMATCH,
3277 "Conn", "EncrypMismatch"},
3278 {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_RSN_MISMATCH,
3279 "Conn", "RsnMismatch"},
3280 {WLC_E_AUTH, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
3281 "Conn", "AuthTimeout"},
3282 {WLC_E_AUTH, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3283 "Conn", "AuthFail"},
3284 {WLC_E_AUTH, WLC_E_STATUS_NO_ACK, WL_IW_DONT_CARE,
3285 "Conn", "AuthNoAck"},
3286 {WLC_E_REASSOC, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3287 "Conn", "ReassocFail"},
3288 {WLC_E_REASSOC, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
3289 "Conn", "ReassocTimeout"},
3290 {WLC_E_REASSOC, WLC_E_STATUS_ABORT, WL_IW_DONT_CARE,
3291 "Conn", "ReassocAbort"},
3292 {WLC_E_PSK_SUP, WLC_SUP_KEYED, WL_IW_DONT_CARE,
3293 "Sup", "ConnSuccess"},
3294 {WLC_E_PSK_SUP, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3295 "Sup", "WpaHandshakeFail"},
3296 {WLC_E_DEAUTH_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3298 {WLC_E_DISASSOC_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3299 "Conn", "DisassocInd"},
3300 {WLC_E_DISASSOC, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3304 const char *name = "";
3305 const char *cause = NULL;
3308 for (i = 0; i < sizeof(event_map) / sizeof(event_map[0]); i++) {
3309 const conn_fail_event_map_t *row = &event_map[i];
3310 if (row->inEvent == event_type &&
3311 (row->inStatus == status
3312 || row->inStatus == WL_IW_DONT_CARE)
3313 && (row->inReason == reason
3314 || row->inReason == WL_IW_DONT_CARE)) {
3315 name = row->outName;
3316 cause = row->outCause;
3322 memset(stringBuf, 0, buflen);
3323 snprintf(stringBuf, buflen, "%s %s %02d %02d",
3324 name, cause, status, reason);
3325 WL_INFORM("Connection status: %s\n", stringBuf);
3332 #if WIRELESS_EXT > 14
3335 wl_iw_check_conn_fail(wl_event_msg_t *e, char *stringBuf, uint buflen)
3337 u32 event = be32_to_cpu(e->event_type);
3338 u32 status = be32_to_cpu(e->status);
3339 u32 reason = be32_to_cpu(e->reason);
3341 if (wl_iw_conn_status_str(event, status, reason, stringBuf, buflen)) {
3348 #ifndef IW_CUSTOM_MAX
3349 #define IW_CUSTOM_MAX 256
3352 void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data)
3354 #if WIRELESS_EXT > 13
3355 union iwreq_data wrqu;
3356 char extra[IW_CUSTOM_MAX + 1];
3358 u32 event_type = be32_to_cpu(e->event_type);
3359 u16 flags = be16_to_cpu(e->flags);
3360 u32 datalen = be32_to_cpu(e->datalen);
3361 u32 status = be32_to_cpu(e->status);
3364 memset(&wrqu, 0, sizeof(wrqu));
3365 memset(extra, 0, sizeof(extra));
3369 WL_ERROR("%s: dev is null\n", __func__);
3373 iw = *(wl_iw_t **) netdev_priv(dev);
3375 WL_TRACE("%s: dev=%s event=%d\n", __func__, dev->name, event_type);
3377 switch (event_type) {
3380 memcpy(wrqu.addr.sa_data, &e->addr, ETH_ALEN);
3381 wrqu.addr.sa_family = ARPHRD_ETHER;
3383 #if WIRELESS_EXT > 14
3385 case WLC_E_ASSOC_IND:
3386 case WLC_E_REASSOC_IND:
3387 memcpy(wrqu.addr.sa_data, &e->addr, ETH_ALEN);
3388 wrqu.addr.sa_family = ARPHRD_ETHER;
3389 cmd = IWEVREGISTERED;
3391 case WLC_E_DEAUTH_IND:
3392 case WLC_E_DISASSOC_IND:
3394 memset(wrqu.addr.sa_data, 0, ETH_ALEN);
3395 wrqu.addr.sa_family = ARPHRD_ETHER;
3396 memset(&extra, 0, ETH_ALEN);
3399 case WLC_E_NDIS_LINK:
3401 if (!(flags & WLC_EVENT_MSG_LINK)) {
3402 memset(wrqu.addr.sa_data, 0, ETH_ALEN);
3403 memset(&extra, 0, ETH_ALEN);
3405 memcpy(wrqu.addr.sa_data, &e->addr, ETH_ALEN);
3406 WL_TRACE("Link UP\n");
3409 wrqu.addr.sa_family = ARPHRD_ETHER;
3411 case WLC_E_ACTION_FRAME:
3413 if (datalen + 1 <= sizeof(extra)) {
3414 wrqu.data.length = datalen + 1;
3415 extra[0] = WLC_E_ACTION_FRAME;
3416 memcpy(&extra[1], data, datalen);
3417 WL_TRACE("WLC_E_ACTION_FRAME len %d\n",
3422 case WLC_E_ACTION_FRAME_COMPLETE:
3424 memcpy(&toto, data, 4);
3425 if (sizeof(status) + 1 <= sizeof(extra)) {
3426 wrqu.data.length = sizeof(status) + 1;
3427 extra[0] = WLC_E_ACTION_FRAME_COMPLETE;
3428 memcpy(&extra[1], &status, sizeof(status));
3429 WL_TRACE("wl_iw_event status %d PacketId %d\n", status,
3431 WL_TRACE("WLC_E_ACTION_FRAME_COMPLETE len %d\n",
3435 #endif /* WIRELESS_EXT > 14 */
3436 #if WIRELESS_EXT > 17
3437 case WLC_E_MIC_ERROR:
3439 struct iw_michaelmicfailure *micerrevt =
3440 (struct iw_michaelmicfailure *)&extra;
3441 cmd = IWEVMICHAELMICFAILURE;
3442 wrqu.data.length = sizeof(struct iw_michaelmicfailure);
3443 if (flags & WLC_EVENT_MSG_GROUP)
3444 micerrevt->flags |= IW_MICFAILURE_GROUP;
3446 micerrevt->flags |= IW_MICFAILURE_PAIRWISE;
3447 memcpy(micerrevt->src_addr.sa_data, &e->addr,
3449 micerrevt->src_addr.sa_family = ARPHRD_ETHER;
3453 case WLC_E_PMKID_CACHE:
3456 struct iw_pmkid_cand *iwpmkidcand =
3457 (struct iw_pmkid_cand *)&extra;
3458 pmkid_cand_list_t *pmkcandlist;
3459 pmkid_cand_t *pmkidcand;
3462 cmd = IWEVPMKIDCAND;
3464 count = get_unaligned_be32(&pmkcandlist->
3467 wrqu.data.length = sizeof(struct iw_pmkid_cand);
3468 pmkidcand = pmkcandlist->pmkid_cand;
3470 memset(iwpmkidcand, 0,
3471 sizeof(struct iw_pmkid_cand));
3472 if (pmkidcand->preauth)
3473 iwpmkidcand->flags |=
3474 IW_PMKID_CAND_PREAUTH;
3475 memcpy(&iwpmkidcand->bssid.sa_data,
3479 wireless_send_event(dev, cmd, &wrqu,
3488 #endif /* WIRELESS_EXT > 17 */
3490 case WLC_E_SCAN_COMPLETE:
3491 #if defined(WL_IW_USE_ISCAN)
3492 if ((g_iscan) && (g_iscan->sysioc_tsk) &&
3493 (g_iscan->iscan_state != ISCAN_STATE_IDLE)) {
3494 up(&g_iscan->sysioc_sem);
3497 wrqu.data.length = strlen(extra);
3498 WL_TRACE("Event WLC_E_SCAN_COMPLETE from specific scan %d\n",
3499 g_iscan->iscan_state);
3503 wrqu.data.length = strlen(extra);
3504 WL_TRACE("Event WLC_E_SCAN_COMPLETE\n");
3508 case WLC_E_PFN_NET_FOUND:
3511 ssid = (wlc_ssid_t *) data;
3512 WL_ERROR("%s Event WLC_E_PFN_NET_FOUND, send %s up : find %s len=%d\n",
3513 __func__, PNO_EVENT_UP,
3514 ssid->SSID, ssid->SSID_len);
3516 memset(&wrqu, 0, sizeof(wrqu));
3517 strcpy(extra, PNO_EVENT_UP);
3518 wrqu.data.length = strlen(extra);
3523 WL_TRACE("Unknown Event %d: ignoring\n", event_type);
3528 if (cmd == SIOCGIWSCAN)
3529 wireless_send_event(dev, cmd, &wrqu, NULL);
3531 wireless_send_event(dev, cmd, &wrqu, extra);
3535 #if WIRELESS_EXT > 14
3536 memset(extra, 0, sizeof(extra));
3537 if (wl_iw_check_conn_fail(e, extra, sizeof(extra))) {
3539 wrqu.data.length = strlen(extra);
3541 wireless_send_event(dev, cmd, &wrqu, extra);
3544 #endif /* WIRELESS_EXT > 14 */
3545 #endif /* WIRELESS_EXT > 13 */
3548 int wl_iw_attach(struct net_device *dev, void *dhdp)
3552 #if defined(WL_IW_USE_ISCAN)
3553 iscan_info_t *iscan = NULL;
3558 memset(&g_wl_iw_params, 0, sizeof(wl_iw_extra_params_t));
3562 (WL_SCAN_PARAMS_FIXED_SIZE + offsetof(wl_iscan_params_t, params)) +
3563 (WL_NUMCHANNELS * sizeof(u16)) +
3564 WL_SCAN_PARAMS_SSID_MAX * sizeof(wlc_ssid_t);
3567 (WL_SCAN_PARAMS_FIXED_SIZE + offsetof(wl_iscan_params_t, params));
3569 iscan = kzalloc(sizeof(iscan_info_t), GFP_KERNEL);
3574 iscan->iscan_ex_params_p = kmalloc(params_size, GFP_KERNEL);
3575 if (!iscan->iscan_ex_params_p) {
3579 iscan->iscan_ex_param_size = params_size;
3580 iscan->sysioc_tsk = NULL;
3584 iscan->iscan_state = ISCAN_STATE_IDLE;
3586 iscan->timer_ms = 3000;
3587 init_timer(&iscan->timer);
3588 iscan->timer.data = (unsigned long) iscan;
3589 iscan->timer.function = wl_iw_timerfunc;
3591 sema_init(&iscan->sysioc_sem, 0);
3592 iscan->sysioc_tsk = kthread_run(_iscan_sysioc_thread, iscan,
3594 if (IS_ERR(iscan->sysioc_tsk)) {
3595 iscan->sysioc_tsk = NULL;
3598 #endif /* defined(WL_IW_USE_ISCAN) */
3600 iw = *(wl_iw_t **) netdev_priv(dev);
3601 iw->pub = (dhd_pub_t *) dhdp;
3602 MUTEX_LOCK_INIT(iw->pub);
3603 MUTEX_LOCK_WL_SCAN_SET_INIT();
3606 MUTEX_LOCK_SOFTAP_SET_INIT(iw->pub);
3608 g_scan = kzalloc(G_SCAN_RESULTS, GFP_KERNEL);
3612 g_scan_specified_ssid = 0;
3617 void wl_iw_detach(void)
3619 #if defined(WL_IW_USE_ISCAN)
3621 iscan_info_t *iscan = g_iscan;
3625 if (iscan->sysioc_tsk) {
3626 send_sig(SIGTERM, iscan->sysioc_tsk, 1);
3627 kthread_stop(iscan->sysioc_tsk);
3628 iscan->sysioc_tsk = NULL;
3631 MUTEX_LOCK_WL_SCAN_SET();
3632 while (iscan->list_hdr) {
3633 buf = iscan->list_hdr->next;
3634 kfree(iscan->list_hdr);
3635 iscan->list_hdr = buf;
3637 MUTEX_UNLOCK_WL_SCAN_SET();
3638 kfree(iscan->iscan_ex_params_p);
3641 #endif /* WL_IW_USE_ISCAN */
3649 void osl_assert(char *exp, char *file, int line)
3654 basename = strrchr(file, '/');
3662 snprintf(tempbuf, 256,
3663 "assertion \"%s\" failed: file \"%s\", line %d\n", exp,
3667 * Print assert message and give it time to
3668 * be written to /var/log/messages
3670 if (!in_interrupt()) {
3671 const int delay = 3;
3672 printk(KERN_ERR "%s", tempbuf);
3673 printk(KERN_ERR "panic in %d seconds\n", delay);
3674 set_current_state(TASK_INTERRUPTIBLE);
3675 schedule_timeout(delay * HZ);
3678 switch (g_assert_type) {
3680 panic(KERN_ERR "%s", tempbuf);
3683 printk(KERN_ERR "%s", tempbuf);
3687 printk(KERN_ERR "%s", tempbuf);
3693 #endif /* defined(BCMDBG) */