1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Linux Wireless Extensions support
4 *
5 * Copyright (C) 1999-2017, Broadcom Corporation
6 *
7 * Unless you and Broadcom execute a separate written software license
8 * agreement governing use of this software, this software is licensed to you
9 * under the terms of the GNU General Public License version 2 (the "GPL"),
10 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11 * following added to such license:
12 *
13 * As a special exception, the copyright holders of this software give you
14 * permission to link this software with independent modules, and to copy and
15 * distribute the resulting executable under terms of your choice, provided that
16 * you also meet, for each linked independent module, the terms and conditions of
17 * the license of that module. An independent module is a module which is not
18 * derived from this software. The special exception does not apply to any
19 * modifications of the software.
20 *
21 * Notwithstanding the above, under no circumstances may you combine this
22 * software in any way with any other Broadcom software provided under a license
23 * other than the GPL, without Broadcom's express prior written consent.
24 *
25 *
26 * <<Broadcom-WL-IPTag/Open:>>
27 *
28 * $Id: wl_iw.c 616333 2016-02-01 05:30:29Z $
29 */
30
31 #if defined(USE_IW)
32 #define LINUX_PORT
33
34 #include <typedefs.h>
35 #include <linuxver.h>
36 #include <osl.h>
37
38 #include <bcmutils.h>
39 #include <bcmendian.h>
40 #include <ethernet.h>
41
42 #include <linux/if_arp.h>
43 #include <linux/uaccess.h>
44 #include <wlioctl.h>
45 #ifdef WL_NAN
46 #include <wlioctl_utils.h>
47 #endif
48 #include <wl_iw.h>
49 #include <wl_android.h>
50 #ifdef WL_ESCAN
51 #include <wl_escan.h>
52 #endif
53 #include <dhd_config.h>
54
55 uint iw_msg_level = WL_ERROR_LEVEL;
56
57 #define WL_ERROR_MSG(x, args...) \
58 do { \
59 if (iw_msg_level & WL_ERROR_LEVEL) { \
60 printk(KERN_ERR DHD_LOG_PREFIXS "WEXT-ERROR) %s : " x, __func__, ## args); \
61 } \
62 } while (0)
63 #define WL_TRACE_MSG(x, args...) \
64 do { \
65 if (iw_msg_level & WL_TRACE_LEVEL) { \
66 printk(KERN_INFO DHD_LOG_PREFIXS "WEXT-TRACE) %s : " x, __func__, ## args); \
67 } \
68 } while (0)
69 #define WL_SCAN_MSG(x, args...) \
70 do { \
71 if (iw_msg_level & WL_SCAN_LEVEL) { \
72 printk(KERN_INFO DHD_LOG_PREFIXS "WEXT-SCAN) %s : " x, __func__, ## args); \
73 } \
74 } while (0)
75 #define WL_WSEC_MSG(x, args...) \
76 do { \
77 if (iw_msg_level & WL_WSEC_LEVEL) { \
78 printk(KERN_INFO DHD_LOG_PREFIXS "WEXT-WSEC) %s : " x, __func__, ## args); \
79 } \
80 } while (0)
81 #define WL_ERROR(x) WL_ERROR_MSG x
82 #define WL_TRACE(x) WL_TRACE_MSG x
83 #define WL_SCAN(x) WL_SCAN_MSG x
84 #define WL_WSEC(x) WL_WSEC_MSG x
85
86 #ifdef BCMWAPI_WPI
87 /* these items should evetually go into wireless.h of the linux system headfile dir */
88 #ifndef IW_ENCODE_ALG_SM4
89 #define IW_ENCODE_ALG_SM4 0x20
90 #endif
91
92 #ifndef IW_AUTH_WAPI_ENABLED
93 #define IW_AUTH_WAPI_ENABLED 0x20
94 #endif
95
96 #ifndef IW_AUTH_WAPI_VERSION_1
97 #define IW_AUTH_WAPI_VERSION_1 0x00000008
98 #endif
99
100 #ifndef IW_AUTH_CIPHER_SMS4
101 #define IW_AUTH_CIPHER_SMS4 0x00000020
102 #endif
103
104 #ifndef IW_AUTH_KEY_MGMT_WAPI_PSK
105 #define IW_AUTH_KEY_MGMT_WAPI_PSK 4
106 #endif
107
108 #ifndef IW_AUTH_KEY_MGMT_WAPI_CERT
109 #define IW_AUTH_KEY_MGMT_WAPI_CERT 8
110 #endif
111 #endif /* BCMWAPI_WPI */
112
113 /* Broadcom extensions to WEXT, linux upstream has obsoleted WEXT */
114 #ifndef IW_AUTH_KEY_MGMT_FT_802_1X
115 #define IW_AUTH_KEY_MGMT_FT_802_1X 0x04
116 #endif
117
118 #ifndef IW_AUTH_KEY_MGMT_FT_PSK
119 #define IW_AUTH_KEY_MGMT_FT_PSK 0x08
120 #endif
121
122 #ifndef IW_ENC_CAPA_FW_ROAM_ENABLE
123 #define IW_ENC_CAPA_FW_ROAM_ENABLE 0x00000020
124 #endif
125
126
127 /* FC9: wireless.h 2.6.25-14.fc9.i686 is missing these, even though WIRELESS_EXT is set to latest
128 * version 22.
129 */
130 #ifndef IW_ENCODE_ALG_PMK
131 #define IW_ENCODE_ALG_PMK 4
132 #endif
133 #ifndef IW_ENC_CAPA_4WAY_HANDSHAKE
134 #define IW_ENC_CAPA_4WAY_HANDSHAKE 0x00000010
135 #endif
136 /* End FC9. */
137
138 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
139 #include <linux/rtnetlink.h>
140 #endif
141
142 extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status,
143 uint32 reason, char* stringBuf, uint buflen);
144
145 uint wl_msg_level = WL_ERROR_VAL;
146
147 #define MAX_WLIW_IOCTL_LEN WLC_IOCTL_MEDLEN
148
149 /* IOCTL swapping mode for Big Endian host with Little Endian dongle. Default to off */
150 #define htod32(i) (i)
151 #define htod16(i) (i)
152 #define dtoh32(i) (i)
153 #define dtoh16(i) (i)
154 #define htodchanspec(i) (i)
155 #define dtohchanspec(i) (i)
156
157 extern struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev);
158 extern int dhd_wait_pend8021x(struct net_device *dev);
159
160 #if WIRELESS_EXT < 19
161 #define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST)
162 #define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST)
163 #endif /* WIRELESS_EXT < 19 */
164
165
166 #ifndef WL_ESCAN
167 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
168 #define DAEMONIZE(a) do { \
169 allow_signal(SIGKILL); \
170 allow_signal(SIGTERM); \
171 } while (0)
172 #elif ((LINUX_VERSION_CODE < KERNEL_VERSION(3, 8, 0)) && \
173 (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)))
174 #define DAEMONIZE(a) daemonize(a); \
175 allow_signal(SIGKILL); \
176 allow_signal(SIGTERM);
177 #else /* Linux 2.4 (w/o preemption patch) */
178 #define RAISE_RX_SOFTIRQ() \
179 cpu_raise_softirq(smp_processor_id(), NET_RX_SOFTIRQ)
180 #define DAEMONIZE(a) daemonize(); \
181 do { if (a) \
182 strncpy(current->comm, a, MIN(sizeof(current->comm), (strlen(a) + 1))); \
183 } while (0);
184 #endif /* LINUX_VERSION_CODE */
185
186 #define ISCAN_STATE_IDLE 0
187 #define ISCAN_STATE_SCANING 1
188
189 /* the buf lengh can be WLC_IOCTL_MAXLEN (8K) to reduce iteration */
190 #define WLC_IW_ISCAN_MAXLEN 2048
191 typedef struct iscan_buf {
192 struct iscan_buf * next;
193 char iscan_buf[WLC_IW_ISCAN_MAXLEN];
194 } iscan_buf_t;
195
196 typedef struct iscan_info {
197 struct net_device *dev;
198 timer_list_compat_t timer;
199 uint32 timer_ms;
200 uint32 timer_on;
201 int iscan_state;
202 iscan_buf_t * list_hdr;
203 iscan_buf_t * list_cur;
204
205 /* Thread to work on iscan */
206 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
207 struct task_struct *kthread;
208 #endif
209 long sysioc_pid;
210 struct semaphore sysioc_sem;
211 struct completion sysioc_exited;
212 char ioctlbuf[WLC_IOCTL_SMLEN];
213 } iscan_info_t;
214 static void wl_iw_timerfunc(ulong data);
215 static void wl_iw_set_event_mask(struct net_device *dev);
216 static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action);
217 #endif /* !WL_ESCAN */
218
219 struct pmk_list {
220 pmkid_list_t pmkids;
221 pmkid_t foo[MAXPMKID - 1];
222 };
223
224 typedef struct wl_wext_info {
225 struct net_device *dev;
226 dhd_pub_t *dhd;
227 struct delayed_work pm_enable_work;
228 struct mutex pm_sync;
229 struct wl_conn_info conn_info;
230 struct pmk_list pmk_list;
231 #ifndef WL_ESCAN
232 struct iscan_info iscan;
233 #endif
234 } wl_wext_info_t;
235
236 /* priv_link becomes netdev->priv and is the link between netdev and wlif struct */
237 typedef struct priv_link {
238 wl_iw_t *wliw;
239 } priv_link_t;
240
241 /* dev to priv_link */
242 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24))
243 #define WL_DEV_LINK(dev) (priv_link_t*)(dev->priv)
244 #else
245 #ifdef CONFIG_AP6XXX_WIFI6_HDF
246 void * VOID_DEV_PRIV(struct net_device *dev);
247 #define WL_DEV_LINK(dev) (priv_link_t*)VOID_DEV_PRIV(dev)
248 #else
249 #define WL_DEV_LINK(dev) (priv_link_t*)netdev_priv(dev)
250 #endif
251 #endif
252
253 /* dev to wl_iw_t */
254 #define IW_DEV_IF(dev) ((wl_iw_t*)(WL_DEV_LINK(dev))->wliw)
255
swap_key_from_BE(wl_wsec_key_t * key)256 static void swap_key_from_BE(
257 wl_wsec_key_t *key
258 )
259 {
260 key->index = htod32(key->index);
261 key->len = htod32(key->len);
262 key->algo = htod32(key->algo);
263 key->flags = htod32(key->flags);
264 key->rxiv.hi = htod32(key->rxiv.hi);
265 key->rxiv.lo = htod16(key->rxiv.lo);
266 key->iv_initialized = htod32(key->iv_initialized);
267 }
268
swap_key_to_BE(wl_wsec_key_t * key)269 static void swap_key_to_BE(
270 wl_wsec_key_t *key
271 )
272 {
273 key->index = dtoh32(key->index);
274 key->len = dtoh32(key->len);
275 key->algo = dtoh32(key->algo);
276 key->flags = dtoh32(key->flags);
277 key->rxiv.hi = dtoh32(key->rxiv.hi);
278 key->rxiv.lo = dtoh16(key->rxiv.lo);
279 key->iv_initialized = dtoh32(key->iv_initialized);
280 }
281
282 static int
dev_wlc_ioctl(struct net_device * dev,int cmd,void * arg,int len)283 dev_wlc_ioctl(
284 struct net_device *dev,
285 int cmd,
286 void *arg,
287 int len
288 )
289 {
290 struct ifreq ifr;
291 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
292 wl_ioctl_t ioc;
293 mm_segment_t fs;
294 #else
295 dhd_ioctl_t ioc;
296 int8 index;
297 struct dhd_pub *dhd = dhd_get_pub(dev);
298 #endif
299 int ret;
300
301 memset(&ioc, 0, sizeof(ioc));
302 #if defined(CONFIG_COMPAT) && (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
303 ioc.cmd = cmd | WLC_SPEC_FLAG;
304 #else
305 ioc.cmd = cmd;
306 #endif
307 ioc.buf = arg;
308 ioc.len = len;
309
310 strncpy(ifr.ifr_name, dev->name, sizeof(ifr.ifr_name));
311 ifr.ifr_name[sizeof(ifr.ifr_name) - 1] = '\0';
312 ifr.ifr_data = (caddr_t) &ioc;
313
314 #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0))
315 fs = get_fs();
316 set_fs(KERNEL_DS);
317 #if defined(WL_USE_NETDEV_OPS)
318 ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
319 #else
320 ret = dev->do_ioctl(dev, &ifr, SIOCDEVPRIVATE);
321 #endif
322 set_fs(fs);
323 #else
324 index = dhd_net2idx(dhd->info, dev);
325 if (index == DHD_BAD_IF) {
326 WL_ERROR(("Bad ifidx from dev:%p\n", dev));
327 return -ENODEV;
328 }
329 ret = dhd_ioctl_process(dhd, index, &ioc, arg);
330 #endif
331
332 return ret;
333 }
334
335 /*
336 set named driver variable to int value and return error indication
337 calling example: dev_wlc_intvar_set(dev, "arate", rate)
338 */
339
340 static int
dev_wlc_intvar_set(struct net_device * dev,char * name,int val)341 dev_wlc_intvar_set(
342 struct net_device *dev,
343 char *name,
344 int val)
345 {
346 char buf[WLC_IOCTL_SMLEN];
347 uint len;
348
349 val = htod32(val);
350 len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf));
351 ASSERT(len);
352
353 return (dev_wlc_ioctl(dev, WLC_SET_VAR, buf, len));
354 }
355
356 #ifndef WL_ESCAN
357 static int
dev_iw_iovar_setbuf(struct net_device * dev,char * iovar,void * param,int paramlen,void * bufptr,int buflen)358 dev_iw_iovar_setbuf(
359 struct net_device *dev,
360 char *iovar,
361 void *param,
362 int paramlen,
363 void *bufptr,
364 int buflen)
365 {
366 int iolen;
367
368 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
369 ASSERT(iolen);
370 BCM_REFERENCE(iolen);
371
372 return (dev_wlc_ioctl(dev, WLC_SET_VAR, bufptr, iolen));
373 }
374
375 static int
dev_iw_iovar_getbuf(struct net_device * dev,char * iovar,void * param,int paramlen,void * bufptr,int buflen)376 dev_iw_iovar_getbuf(
377 struct net_device *dev,
378 char *iovar,
379 void *param,
380 int paramlen,
381 void *bufptr,
382 int buflen)
383 {
384 int iolen;
385
386 iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen);
387 ASSERT(iolen);
388 BCM_REFERENCE(iolen);
389
390 return (dev_wlc_ioctl(dev, WLC_GET_VAR, bufptr, buflen));
391 }
392 #endif
393
394 #if WIRELESS_EXT > 17
395 static int
dev_wlc_bufvar_set(struct net_device * dev,char * name,char * buf,int len)396 dev_wlc_bufvar_set(
397 struct net_device *dev,
398 char *name,
399 char *buf, int len)
400 {
401 char *ioctlbuf;
402 uint buflen;
403 int error;
404
405 ioctlbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
406 if (!ioctlbuf)
407 return -ENOMEM;
408
409 buflen = bcm_mkiovar(name, buf, len, ioctlbuf, MAX_WLIW_IOCTL_LEN);
410 ASSERT(buflen);
411 error = dev_wlc_ioctl(dev, WLC_SET_VAR, ioctlbuf, buflen);
412
413 kfree(ioctlbuf);
414 return error;
415 }
416 #endif /* WIRELESS_EXT > 17 */
417
418 /*
419 get named driver variable to int value and return error indication
420 calling example: dev_wlc_bufvar_get(dev, "arate", &rate)
421 */
422
423 static int
dev_wlc_bufvar_get(struct net_device * dev,char * name,char * buf,int buflen)424 dev_wlc_bufvar_get(
425 struct net_device *dev,
426 char *name,
427 char *buf, int buflen)
428 {
429 char *ioctlbuf;
430 int error;
431
432 uint len;
433
434 ioctlbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
435 if (!ioctlbuf)
436 return -ENOMEM;
437 len = bcm_mkiovar(name, NULL, 0, ioctlbuf, MAX_WLIW_IOCTL_LEN);
438 ASSERT(len);
439 BCM_REFERENCE(len);
440 error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)ioctlbuf, MAX_WLIW_IOCTL_LEN);
441 if (!error)
442 bcopy(ioctlbuf, buf, buflen);
443
444 kfree(ioctlbuf);
445 return (error);
446 }
447
448 /*
449 get named driver variable to int value and return error indication
450 calling example: dev_wlc_intvar_get(dev, "arate", &rate)
451 */
452
453 static int
dev_wlc_intvar_get(struct net_device * dev,char * name,int * retval)454 dev_wlc_intvar_get(
455 struct net_device *dev,
456 char *name,
457 int *retval)
458 {
459 union {
460 char buf[WLC_IOCTL_SMLEN];
461 int val;
462 } var;
463 int error;
464
465 uint len;
466 uint data_null;
467
468 len = bcm_mkiovar(name, (char *)(&data_null), 0, (char *)(&var), sizeof(var.buf));
469 ASSERT(len);
470 error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)&var, len);
471
472 *retval = dtoh32(var.val);
473
474 return (error);
475 }
476
477 /* Maintain backward compatibility */
478 #if WIRELESS_EXT < 13
479 struct iw_request_info
480 {
481 __u16 cmd; /* Wireless Extension command */
482 __u16 flags; /* More to come ;-) */
483 };
484
485 typedef int (*iw_handler)(struct net_device *dev, struct iw_request_info *info,
486 void *wrqu, char *extra);
487 #endif /* WIRELESS_EXT < 13 */
488
489 #if WIRELESS_EXT > 12
490 static int
wl_iw_set_leddc(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)491 wl_iw_set_leddc(
492 struct net_device *dev,
493 struct iw_request_info *info,
494 union iwreq_data *wrqu,
495 char *extra
496 )
497 {
498 int dc = *(int *)extra;
499 int error;
500
501 error = dev_wlc_intvar_set(dev, "leddc", dc);
502 return error;
503 }
504
505 static int
wl_iw_set_vlanmode(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)506 wl_iw_set_vlanmode(
507 struct net_device *dev,
508 struct iw_request_info *info,
509 union iwreq_data *wrqu,
510 char *extra
511 )
512 {
513 int mode = *(int *)extra;
514 int error;
515
516 mode = htod32(mode);
517 error = dev_wlc_intvar_set(dev, "vlan_mode", mode);
518 return error;
519 }
520
521 static int
wl_iw_set_pm(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)522 wl_iw_set_pm(
523 struct net_device *dev,
524 struct iw_request_info *info,
525 union iwreq_data *wrqu,
526 char *extra
527 )
528 {
529 int pm = *(int *)extra;
530 int error;
531
532 pm = htod32(pm);
533 error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm));
534 return error;
535 }
536 #endif /* WIRELESS_EXT > 12 */
537
538 int
wl_iw_send_priv_event(struct net_device * dev,char * flag)539 wl_iw_send_priv_event(
540 struct net_device *dev,
541 char *flag
542 )
543 {
544 union iwreq_data wrqu;
545 char extra[IW_CUSTOM_MAX + 1];
546 int cmd;
547
548 cmd = IWEVCUSTOM;
549 memset(&wrqu, 0, sizeof(wrqu));
550 if (strlen(flag) > sizeof(extra))
551 return -1;
552
553 strncpy(extra, flag, sizeof(extra));
554 extra[sizeof(extra) - 1] = '\0';
555 wrqu.data.length = strlen(extra);
556 wireless_send_event(dev, cmd, &wrqu, extra);
557 WL_TRACE(("Send IWEVCUSTOM Event as %s\n", extra));
558
559 return 0;
560 }
561
562 static int
wl_iw_config_commit(struct net_device * dev,struct iw_request_info * info,void * zwrq,char * extra)563 wl_iw_config_commit(
564 struct net_device *dev,
565 struct iw_request_info *info,
566 void *zwrq,
567 char *extra
568 )
569 {
570 wlc_ssid_t ssid;
571 int error;
572 struct sockaddr bssid;
573
574 WL_TRACE(("%s: SIOCSIWCOMMIT\n", dev->name));
575
576 if ((error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid))))
577 return error;
578
579 ssid.SSID_len = dtoh32(ssid.SSID_len);
580
581 if (!ssid.SSID_len)
582 return 0;
583
584 bzero(&bssid, sizeof(struct sockaddr));
585 if ((error = dev_wlc_ioctl(dev, WLC_REASSOC, &bssid, ETHER_ADDR_LEN))) {
586 WL_ERROR(("WLC_REASSOC failed (%d)\n", error));
587 return error;
588 }
589
590 return 0;
591 }
592
593 static int
wl_iw_get_name(struct net_device * dev,struct iw_request_info * info,union iwreq_data * cwrq,char * extra)594 wl_iw_get_name(
595 struct net_device *dev,
596 struct iw_request_info *info,
597 union iwreq_data *cwrq,
598 char *extra
599 )
600 {
601 int phytype, err;
602 uint band[3];
603 char cap[5];
604
605 WL_TRACE(("%s: SIOCGIWNAME\n", dev->name));
606
607 cap[0] = 0;
608 if ((err = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype))) < 0)
609 goto done;
610 if ((err = dev_wlc_ioctl(dev, WLC_GET_BANDLIST, band, sizeof(band))) < 0)
611 goto done;
612
613 band[0] = dtoh32(band[0]);
614 switch (phytype) {
615 case WLC_PHY_TYPE_A:
616 strncpy(cap, "a", sizeof(cap));
617 break;
618 case WLC_PHY_TYPE_B:
619 strncpy(cap, "b", sizeof(cap));
620 break;
621 case WLC_PHY_TYPE_G:
622 if (band[0] >= 2)
623 strncpy(cap, "abg", sizeof(cap));
624 else
625 strncpy(cap, "bg", sizeof(cap));
626 break;
627 case WLC_PHY_TYPE_N:
628 if (band[0] >= 2)
629 strncpy(cap, "abgn", sizeof(cap));
630 else
631 strncpy(cap, "bgn", sizeof(cap));
632 break;
633 }
634 done:
635 (void)snprintf(cwrq->name, IFNAMSIZ, "IEEE 802.11%s", cap);
636
637 return 0;
638 }
639
640 #define DHD_CHECK(dhd, dev) \
641 if (!dhd) { \
642 WL_ERROR (("[%s] dhd is NULL\n", dev->name)); \
643 return -ENODEV; \
644 } \
645
646 static int
wl_iw_set_freq(struct net_device * dev,struct iw_request_info * info,struct iw_freq * fwrq,char * extra)647 wl_iw_set_freq(
648 struct net_device *dev,
649 struct iw_request_info *info,
650 struct iw_freq *fwrq,
651 char *extra
652 )
653 {
654 int error, chan;
655 uint sf = 0;
656 struct dhd_pub *dhd = dhd_get_pub(dev);
657 wl_wext_info_t *wext_info = NULL;
658
659 WL_TRACE(("%s: SIOCSIWFREQ\n", dev->name));
660 DHD_CHECK(dhd, dev);
661 wext_info = dhd->wext_info;
662
663 /* Setting by channel number */
664 if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) {
665 chan = fwrq->m;
666 }
667
668 /* Setting by frequency */
669 else {
670 /* Convert to MHz as best we can */
671 if (fwrq->e >= 6) {
672 fwrq->e -= 6;
673 while (fwrq->e--)
674 fwrq->m *= 10;
675 } else if (fwrq->e < 6) {
676 while (fwrq->e++ < 6)
677 fwrq->m /= 10;
678 }
679 /* handle 4.9GHz frequencies as Japan 4 GHz based channelization */
680 if (fwrq->m > 4000 && fwrq->m < 5000) {
681 sf = WF_CHAN_FACTOR_4_G; /* start factor for 4 GHz */
682 }
683 chan = wf_mhz2channel(fwrq->m, sf);
684 }
685 if (wext_info)
686 wext_info->conn_info.channel = chan;
687 WL_MSG(dev->name, "chan=%d\n", chan);
688 chan = htod32(chan);
689 if ((error = dev_wlc_ioctl(dev, WLC_SET_CHANNEL, &chan, sizeof(chan)))) {
690 WL_ERROR(("WLC_SET_CHANNEL failed (%d).\n", error));
691 return error;
692 }
693
694 /* -EINPROGRESS: Call commit handler */
695 return -EINPROGRESS;
696 }
697
698 static int
wl_iw_get_freq(struct net_device * dev,struct iw_request_info * info,struct iw_freq * fwrq,char * extra)699 wl_iw_get_freq(
700 struct net_device *dev,
701 struct iw_request_info *info,
702 struct iw_freq *fwrq,
703 char *extra
704 )
705 {
706 int error;
707 u32 chanspec = 0;
708 int ctl_chan;
709
710 WL_TRACE(("%s: SIOCGIWFREQ\n", dev->name));
711
712 if ((error = dev_wlc_intvar_get(dev, "chanspec", &chanspec)))
713 return error;
714 ctl_chan = wf_chspec_ctlchan(chanspec);
715
716 /* Return radio channel in channel form */
717 fwrq->m = ctl_chan;
718 fwrq->e = dtoh32(0);
719 return 0;
720 }
721
722 static int
wl_iw_set_mode(struct net_device * dev,struct iw_request_info * info,__u32 * uwrq,char * extra)723 wl_iw_set_mode(
724 struct net_device *dev,
725 struct iw_request_info *info,
726 __u32 *uwrq,
727 char *extra
728 )
729 {
730 int infra = 0, ap = 0, error = 0;
731 struct dhd_pub *dhd = dhd_get_pub(dev);
732 wl_wext_info_t *wext_info = NULL;
733
734 WL_TRACE(("%s: SIOCSIWMODE\n", dev->name));
735 DHD_CHECK(dhd, dev);
736 wext_info = dhd->wext_info;
737 if (wext_info) {
738 memset(&wext_info->conn_info.ssid, 0, sizeof(wlc_ssid_t));
739 memset(&wext_info->conn_info.bssid, 0, sizeof(struct ether_addr));
740 wext_info->conn_info.channel = 0;
741 }
742
743 switch (*uwrq) {
744 case IW_MODE_MASTER:
745 infra = ap = 1;
746 break;
747 case IW_MODE_ADHOC:
748 case IW_MODE_AUTO:
749 break;
750 case IW_MODE_INFRA:
751 infra = 1;
752 break;
753 default:
754 return -EINVAL;
755 }
756 infra = htod32(infra);
757 ap = htod32(ap);
758
759 if ((error = dev_wlc_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra))) ||
760 (error = dev_wlc_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap))))
761 return error;
762
763 /* -EINPROGRESS: Call commit handler */
764 return -EINPROGRESS;
765 }
766
767 static int
wl_iw_get_mode(struct net_device * dev,struct iw_request_info * info,__u32 * uwrq,char * extra)768 wl_iw_get_mode(
769 struct net_device *dev,
770 struct iw_request_info *info,
771 __u32 *uwrq,
772 char *extra
773 )
774 {
775 int error, infra = 0, ap = 0;
776
777 WL_TRACE(("%s: SIOCGIWMODE\n", dev->name));
778
779 if ((error = dev_wlc_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra))) ||
780 (error = dev_wlc_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap))))
781 return error;
782
783 infra = dtoh32(infra);
784 ap = dtoh32(ap);
785 *uwrq = infra ? ap ? IW_MODE_MASTER : IW_MODE_INFRA : IW_MODE_ADHOC;
786
787 return 0;
788 }
789
790 static int
wl_iw_get_range(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)791 wl_iw_get_range(
792 struct net_device *dev,
793 struct iw_request_info *info,
794 struct iw_point *dwrq,
795 char *extra
796 )
797 {
798 struct iw_range *range = (struct iw_range *) extra;
799 static int channels[MAXCHANNEL+1];
800 wl_uint32_list_t *list = (wl_uint32_list_t *) channels;
801 wl_rateset_t rateset;
802 int error, i, k;
803 uint sf, ch;
804
805 int phytype;
806 int bw_cap = 0, sgi_tx = 0, nmode = 0;
807 channel_info_t ci;
808 uint8 nrate_list2copy = 0;
809 uint16 nrate_list[4][8] = { {13, 26, 39, 52, 78, 104, 117, 130},
810 {14, 29, 43, 58, 87, 116, 130, 144},
811 {27, 54, 81, 108, 162, 216, 243, 270},
812 {30, 60, 90, 120, 180, 240, 270, 300}};
813 int fbt_cap = 0;
814
815 WL_TRACE(("%s: SIOCGIWRANGE\n", dev->name));
816
817 if (!extra)
818 return -EINVAL;
819
820 dwrq->length = sizeof(struct iw_range);
821 memset(range, 0, sizeof(*range));
822
823 /* We don't use nwids */
824 range->min_nwid = range->max_nwid = 0;
825
826 /* Set available channels/frequencies */
827 list->count = htod32(MAXCHANNEL);
828 if ((error = dev_wlc_ioctl(dev, WLC_GET_VALID_CHANNELS, channels, sizeof(channels))))
829 return error;
830 for (i = 0; i < dtoh32(list->count) && i < IW_MAX_FREQUENCIES; i++) {
831 range->freq[i].i = dtoh32(list->element[i]);
832
833 ch = dtoh32(list->element[i]);
834 if (ch <= CH_MAX_2G_CHANNEL)
835 sf = WF_CHAN_FACTOR_2_4_G;
836 else
837 sf = WF_CHAN_FACTOR_5_G;
838
839 range->freq[i].m = wf_channel2mhz(ch, sf);
840 range->freq[i].e = 6;
841 }
842 range->num_frequency = range->num_channels = i;
843
844 /* Link quality (use NDIS cutoffs) */
845 range->max_qual.qual = 5;
846 /* Signal level (use RSSI) */
847 range->max_qual.level = 0x100 - 200; /* -200 dBm */
848 /* Noise level (use noise) */
849 range->max_qual.noise = 0x100 - 200; /* -200 dBm */
850 /* Signal level threshold range (?) */
851 range->sensitivity = 65535;
852
853 #if WIRELESS_EXT > 11
854 /* Link quality (use NDIS cutoffs) */
855 range->avg_qual.qual = 3;
856 /* Signal level (use RSSI) */
857 range->avg_qual.level = 0x100 + WL_IW_RSSI_GOOD;
858 /* Noise level (use noise) */
859 range->avg_qual.noise = 0x100 - 75; /* -75 dBm */
860 #endif /* WIRELESS_EXT > 11 */
861
862 /* Set available bitrates */
863 if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
864 return error;
865 rateset.count = dtoh32(rateset.count);
866 range->num_bitrates = rateset.count;
867 for (i = 0; i < rateset.count && i < IW_MAX_BITRATES; i++)
868 range->bitrate[i] = (rateset.rates[i] & 0x7f) * 500000; /* convert to bps */
869 if ((error = dev_wlc_intvar_get(dev, "nmode", &nmode)))
870 return error;
871 if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype))))
872 return error;
873 if (nmode == 1 && (((phytype == WLC_PHY_TYPE_LCN) ||
874 (phytype == WLC_PHY_TYPE_LCN40)))) {
875 if ((error = dev_wlc_intvar_get(dev, "mimo_bw_cap", &bw_cap)))
876 return error;
877 if ((error = dev_wlc_intvar_get(dev, "sgi_tx", &sgi_tx)))
878 return error;
879 if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(channel_info_t))))
880 return error;
881 ci.hw_channel = dtoh32(ci.hw_channel);
882
883 if (bw_cap == 0 ||
884 (bw_cap == 2 && ci.hw_channel <= 14)) {
885 if (sgi_tx == 0)
886 nrate_list2copy = 0;
887 else
888 nrate_list2copy = 1;
889 }
890 if (bw_cap == 1 ||
891 (bw_cap == 2 && ci.hw_channel >= 36)) {
892 if (sgi_tx == 0)
893 nrate_list2copy = 2;
894 else
895 nrate_list2copy = 3;
896 }
897 range->num_bitrates += 8;
898 ASSERT(range->num_bitrates < IW_MAX_BITRATES);
899 for (k = 0; i < range->num_bitrates; k++, i++) {
900 /* convert to bps */
901 range->bitrate[i] = (nrate_list[nrate_list2copy][k]) * 500000;
902 }
903 }
904
905 /* Set an indication of the max TCP throughput
906 * in bit/s that we can expect using this interface.
907 * May be use for QoS stuff... Jean II
908 */
909 if ((error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &i, sizeof(i))))
910 return error;
911 i = dtoh32(i);
912 if (i == WLC_PHY_TYPE_A)
913 range->throughput = 24000000; /* 24 Mbits/s */
914 else
915 range->throughput = 1500000; /* 1.5 Mbits/s */
916
917 /* RTS and fragmentation thresholds */
918 range->min_rts = 0;
919 range->max_rts = 2347;
920 range->min_frag = 256;
921 range->max_frag = 2346;
922
923 range->max_encoding_tokens = DOT11_MAX_DEFAULT_KEYS;
924 range->num_encoding_sizes = 4;
925 range->encoding_size[0] = WEP1_KEY_SIZE;
926 range->encoding_size[1] = WEP128_KEY_SIZE;
927 #if WIRELESS_EXT > 17
928 range->encoding_size[2] = TKIP_KEY_SIZE;
929 #else
930 range->encoding_size[2] = 0;
931 #endif
932 range->encoding_size[3] = AES_KEY_SIZE;
933
934 /* Do not support power micro-management */
935 range->min_pmp = 0;
936 range->max_pmp = 0;
937 range->min_pmt = 0;
938 range->max_pmt = 0;
939 range->pmp_flags = 0;
940 range->pm_capa = 0;
941
942 /* Transmit Power - values are in mW */
943 range->num_txpower = 2;
944 range->txpower[0] = 1;
945 range->txpower[1] = 255;
946 range->txpower_capa = IW_TXPOW_MWATT;
947
948 #if WIRELESS_EXT > 10
949 range->we_version_compiled = WIRELESS_EXT;
950 range->we_version_source = 19;
951
952 /* Only support retry limits */
953 range->retry_capa = IW_RETRY_LIMIT;
954 range->retry_flags = IW_RETRY_LIMIT;
955 range->r_time_flags = 0;
956 /* SRL and LRL limits */
957 range->min_retry = 1;
958 range->max_retry = 255;
959 /* Retry lifetime limits unsupported */
960 range->min_r_time = 0;
961 range->max_r_time = 0;
962 #endif /* WIRELESS_EXT > 10 */
963
964 #if WIRELESS_EXT > 17
965 range->enc_capa = IW_ENC_CAPA_WPA;
966 range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP;
967 range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP;
968 range->enc_capa |= IW_ENC_CAPA_WPA2;
969
970 /* Determine driver FBT capability. */
971 if (dev_wlc_intvar_get(dev, "fbt_cap", &fbt_cap) == 0) {
972 if (fbt_cap == WLC_FBT_CAP_DRV_4WAY_AND_REASSOC) {
973 /* Tell the host (e.g. wpa_supplicant) to let driver do the handshake */
974 // range->enc_capa |= IW_ENC_CAPA_4WAY_HANDSHAKE;
975 }
976 }
977
978 #ifdef BCMFW_ROAM_ENABLE_WEXT
979 /* Advertise firmware roam capability to the external supplicant */
980 range->enc_capa |= IW_ENC_CAPA_FW_ROAM_ENABLE;
981 #endif /* BCMFW_ROAM_ENABLE_WEXT */
982
983 /* Event capability (kernel) */
984 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
985 /* Event capability (driver) */
986 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
987 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
988 IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP);
989 IW_EVENT_CAPA_SET(range->event_capa, IWEVMICHAELMICFAILURE);
990 IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCREQIE);
991 IW_EVENT_CAPA_SET(range->event_capa, IWEVASSOCRESPIE);
992 IW_EVENT_CAPA_SET(range->event_capa, IWEVPMKIDCAND);
993
994 #if WIRELESS_EXT >= 22 && defined(IW_SCAN_CAPA_ESSID)
995 /* FC7 wireless.h defines EXT 22 but doesn't define scan_capa bits */
996 range->scan_capa = IW_SCAN_CAPA_ESSID;
997 #endif
998 #endif /* WIRELESS_EXT > 17 */
999
1000 return 0;
1001 }
1002
1003 #ifndef WL_ESCAN
1004 static int
rssi_to_qual(int rssi)1005 rssi_to_qual(int rssi)
1006 {
1007 if (rssi <= WL_IW_RSSI_NO_SIGNAL)
1008 return 0;
1009 else if (rssi <= WL_IW_RSSI_VERY_LOW)
1010 return 1;
1011 else if (rssi <= WL_IW_RSSI_LOW)
1012 return 2;
1013 else if (rssi <= WL_IW_RSSI_GOOD)
1014 return 3;
1015 else if (rssi <= WL_IW_RSSI_VERY_GOOD)
1016 return 4;
1017 else
1018 return 5;
1019 }
1020 #endif /* WL_ESCAN */
1021
1022 static int
wl_iw_set_spy(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)1023 wl_iw_set_spy(
1024 struct net_device *dev,
1025 struct iw_request_info *info,
1026 struct iw_point *dwrq,
1027 char *extra
1028 )
1029 {
1030 wl_iw_t *iw = IW_DEV_IF(dev);
1031 struct sockaddr *addr = (struct sockaddr *) extra;
1032 int i;
1033
1034 WL_TRACE(("%s: SIOCSIWSPY\n", dev->name));
1035
1036 if (!extra)
1037 return -EINVAL;
1038
1039 iw->spy_num = MIN(ARRAYSIZE(iw->spy_addr), dwrq->length);
1040 for (i = 0; i < iw->spy_num; i++)
1041 memcpy(&iw->spy_addr[i], addr[i].sa_data, ETHER_ADDR_LEN);
1042 memset(iw->spy_qual, 0, sizeof(iw->spy_qual));
1043
1044 return 0;
1045 }
1046
1047 static int
wl_iw_get_spy(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)1048 wl_iw_get_spy(
1049 struct net_device *dev,
1050 struct iw_request_info *info,
1051 struct iw_point *dwrq,
1052 char *extra
1053 )
1054 {
1055 wl_iw_t *iw = IW_DEV_IF(dev);
1056 struct sockaddr *addr = (struct sockaddr *) extra;
1057 struct iw_quality *qual = (struct iw_quality *) &addr[iw->spy_num];
1058 int i;
1059
1060 WL_TRACE(("%s: SIOCGIWSPY\n", dev->name));
1061
1062 if (!extra)
1063 return -EINVAL;
1064
1065 dwrq->length = iw->spy_num;
1066 for (i = 0; i < iw->spy_num; i++) {
1067 memcpy(addr[i].sa_data, &iw->spy_addr[i], ETHER_ADDR_LEN);
1068 addr[i].sa_family = AF_UNIX;
1069 memcpy(&qual[i], &iw->spy_qual[i], sizeof(struct iw_quality));
1070 iw->spy_qual[i].updated = 0;
1071 }
1072
1073 return 0;
1074 }
1075
1076 static int
wl_iw_set_wap(struct net_device * dev,struct iw_request_info * info,struct sockaddr * awrq,char * extra)1077 wl_iw_set_wap(
1078 struct net_device *dev,
1079 struct iw_request_info *info,
1080 struct sockaddr *awrq,
1081 char *extra
1082 )
1083 {
1084 int error = -EINVAL;
1085 struct dhd_pub *dhd = dhd_get_pub(dev);
1086 wl_wext_info_t *wext_info = NULL;
1087
1088 WL_TRACE(("%s: SIOCSIWAP\n", dev->name));
1089 DHD_CHECK(dhd, dev);
1090 wext_info = dhd->wext_info;
1091 if (awrq->sa_family != ARPHRD_ETHER) {
1092 WL_ERROR(("Invalid Header...sa_family\n"));
1093 return -EINVAL;
1094 }
1095
1096 /* Ignore "auto" or "off" */
1097 if (ETHER_ISBCAST(awrq->sa_data) || ETHER_ISNULLADDR(awrq->sa_data)) {
1098 scb_val_t scbval;
1099 bzero(&scbval, sizeof(scb_val_t));
1100 WL_MSG(dev->name, "WLC_DISASSOC\n");
1101 if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
1102 WL_ERROR(("WLC_DISASSOC failed (%d).\n", error));
1103 }
1104 wl_ext_in4way_sync_wext(dev,
1105 STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY|STA_WAIT_DISCONNECTED,
1106 WL_EXT_STATUS_DISCONNECTING, NULL);
1107 return 0;
1108 }
1109 /* WL_ASSOC(("Assoc to %s\n", bcm_ether_ntoa((struct ether_addr *)&(awrq->sa_data),
1110 * eabuf)));
1111 */
1112 /* Reassociate to the specified AP */
1113 if (wext_info)
1114 memcpy(&wext_info->conn_info.bssid, awrq->sa_data, ETHER_ADDR_LEN);
1115 if (wext_info && wext_info->conn_info.ssid.SSID_len) {
1116 if ((error = wl_ext_connect(dev, &wext_info->conn_info)))
1117 return error;
1118 } else {
1119 if ((error = dev_wlc_ioctl(dev, WLC_REASSOC, awrq->sa_data, ETHER_ADDR_LEN))) {
1120 WL_ERROR(("WLC_REASSOC failed (%d).\n", error));
1121 return error;
1122 }
1123 WL_MSG(dev->name, "join BSSID="MACSTR"\n", MAC2STR((u8 *)awrq->sa_data));
1124 }
1125 wl_ext_in4way_sync_wext(dev, STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY,
1126 WL_EXT_STATUS_CONNECTING, NULL);
1127
1128 return 0;
1129 }
1130
1131 static int
wl_iw_get_wap(struct net_device * dev,struct iw_request_info * info,struct sockaddr * awrq,char * extra)1132 wl_iw_get_wap(
1133 struct net_device *dev,
1134 struct iw_request_info *info,
1135 struct sockaddr *awrq,
1136 char *extra
1137 )
1138 {
1139 WL_TRACE(("%s: SIOCGIWAP\n", dev->name));
1140
1141 awrq->sa_family = ARPHRD_ETHER;
1142 memset(awrq->sa_data, 0, ETHER_ADDR_LEN);
1143
1144 /* Ignore error (may be down or disassociated) */
1145 (void) dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETHER_ADDR_LEN);
1146
1147 return 0;
1148 }
1149
1150 #if WIRELESS_EXT > 17
1151 static int
wl_iw_mlme(struct net_device * dev,struct iw_request_info * info,struct sockaddr * awrq,char * extra)1152 wl_iw_mlme(
1153 struct net_device *dev,
1154 struct iw_request_info *info,
1155 struct sockaddr *awrq,
1156 char *extra
1157 )
1158 {
1159 struct iw_mlme *mlme;
1160 scb_val_t scbval;
1161 int error = -EINVAL;
1162
1163 WL_TRACE(("%s: SIOCSIWMLME\n", dev->name));
1164
1165 mlme = (struct iw_mlme *)extra;
1166 if (mlme == NULL) {
1167 WL_ERROR(("Invalid ioctl data.\n"));
1168 return error;
1169 }
1170
1171 scbval.val = mlme->reason_code;
1172 bcopy(&mlme->addr.sa_data, &scbval.ea, ETHER_ADDR_LEN);
1173
1174 if (mlme->cmd == IW_MLME_DISASSOC) {
1175 scbval.val = htod32(scbval.val);
1176 WL_MSG(dev->name, "WLC_DISASSOC\n");
1177 error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t));
1178 }
1179 else if (mlme->cmd == IW_MLME_DEAUTH) {
1180 scbval.val = htod32(scbval.val);
1181 WL_MSG(dev->name, "WLC_SCB_DEAUTHENTICATE_FOR_REASON\n");
1182 error = dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, &scbval,
1183 sizeof(scb_val_t));
1184 }
1185 else {
1186 WL_ERROR(("Invalid ioctl data.\n"));
1187 return error;
1188 }
1189 wl_ext_in4way_sync_wext(dev,
1190 STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY|STA_WAIT_DISCONNECTED,
1191 WL_EXT_STATUS_DISCONNECTING, NULL);
1192
1193 return error;
1194 }
1195 #endif /* WIRELESS_EXT > 17 */
1196
1197 #ifndef WL_ESCAN
1198 static int
wl_iw_get_aplist(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)1199 wl_iw_get_aplist(
1200 struct net_device *dev,
1201 struct iw_request_info *info,
1202 struct iw_point *dwrq,
1203 char *extra
1204 )
1205 {
1206 wl_scan_results_t *list;
1207 struct sockaddr *addr = (struct sockaddr *) extra;
1208 struct iw_quality qual[IW_MAX_AP];
1209 wl_bss_info_t *bi = NULL;
1210 int error, i;
1211 uint buflen = dwrq->length;
1212 int16 rssi;
1213
1214 WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name));
1215
1216 if (!extra)
1217 return -EINVAL;
1218
1219 /* Get scan results (too large to put on the stack) */
1220 list = kmalloc(buflen, GFP_KERNEL);
1221 if (!list)
1222 return -ENOMEM;
1223 memset(list, 0, buflen);
1224 list->buflen = htod32(buflen);
1225 if ((error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen))) {
1226 WL_ERROR(("%d: Scan results error %d\n", __LINE__, error));
1227 kfree(list);
1228 return error;
1229 }
1230 list->buflen = dtoh32(list->buflen);
1231 list->version = dtoh32(list->version);
1232 list->count = dtoh32(list->count);
1233 ASSERT(list->version == WL_BSS_INFO_VERSION);
1234
1235 for (i = 0, dwrq->length = 0; i < list->count && dwrq->length < IW_MAX_AP; i++) {
1236 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1237 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1238 buflen));
1239
1240 /* Infrastructure only */
1241 if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
1242 continue;
1243
1244 /* BSSID */
1245 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1246 addr[dwrq->length].sa_family = ARPHRD_ETHER;
1247 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1248 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1249 qual[dwrq->length].qual = rssi_to_qual(rssi);
1250 qual[dwrq->length].level = 0x100 + rssi;
1251 qual[dwrq->length].noise = 0x100 + bi->phy_noise;
1252
1253 /* Updated qual, level, and noise */
1254 #if WIRELESS_EXT > 18
1255 qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1256 #else
1257 qual[dwrq->length].updated = 7;
1258 #endif /* WIRELESS_EXT > 18 */
1259
1260 dwrq->length++;
1261 }
1262
1263 kfree(list);
1264
1265 if (dwrq->length) {
1266 memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
1267 /* Provided qual */
1268 dwrq->flags = 1;
1269 }
1270
1271 return 0;
1272 }
1273
1274 static int
wl_iw_iscan_get_aplist(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)1275 wl_iw_iscan_get_aplist(
1276 struct net_device *dev,
1277 struct iw_request_info *info,
1278 struct iw_point *dwrq,
1279 char *extra
1280 )
1281 {
1282 wl_scan_results_t *list;
1283 iscan_buf_t * buf;
1284 iscan_info_t *iscan;
1285
1286 struct sockaddr *addr = (struct sockaddr *) extra;
1287 struct iw_quality qual[IW_MAX_AP];
1288 wl_bss_info_t *bi = NULL;
1289 int i;
1290 int16 rssi;
1291 struct dhd_pub *dhd = dhd_get_pub(dev);
1292 wl_wext_info_t *wext_info = NULL;
1293
1294 WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name));
1295 DHD_CHECK(dhd, dev);
1296 wext_info = dhd->wext_info;
1297 iscan = &wext_info->iscan;
1298
1299 if (!extra)
1300 return -EINVAL;
1301
1302 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1303 return wl_iw_get_aplist(dev, info, dwrq, extra);
1304 }
1305
1306 buf = iscan->list_hdr;
1307 /* Get scan results (too large to put on the stack) */
1308 while (buf) {
1309 list = &((wl_iscan_results_t*)buf->iscan_buf)->results;
1310 ASSERT(list->version == WL_BSS_INFO_VERSION);
1311
1312 bi = NULL;
1313 for (i = 0, dwrq->length = 0; i < list->count && dwrq->length < IW_MAX_AP; i++) {
1314 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1315 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1316 WLC_IW_ISCAN_MAXLEN));
1317
1318 /* Infrastructure only */
1319 if (!(dtoh16(bi->capability) & DOT11_CAP_ESS))
1320 continue;
1321
1322 /* BSSID */
1323 memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1324 addr[dwrq->length].sa_family = ARPHRD_ETHER;
1325 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1326 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1327 qual[dwrq->length].qual = rssi_to_qual(rssi);
1328 qual[dwrq->length].level = 0x100 + rssi;
1329 qual[dwrq->length].noise = 0x100 + bi->phy_noise;
1330
1331 /* Updated qual, level, and noise */
1332 #if WIRELESS_EXT > 18
1333 qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1334 #else
1335 qual[dwrq->length].updated = 7;
1336 #endif /* WIRELESS_EXT > 18 */
1337
1338 dwrq->length++;
1339 }
1340 buf = buf->next;
1341 }
1342 if (dwrq->length) {
1343 memcpy(&addr[dwrq->length], qual, sizeof(struct iw_quality) * dwrq->length);
1344 /* Provided qual */
1345 dwrq->flags = 1;
1346 }
1347
1348 return 0;
1349 }
1350 #endif
1351
1352 #if WIRELESS_EXT > 13
1353 #ifndef WL_ESCAN
1354 static int
wl_iw_set_scan(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1355 wl_iw_set_scan(
1356 struct net_device *dev,
1357 struct iw_request_info *info,
1358 union iwreq_data *wrqu,
1359 char *extra
1360 )
1361 {
1362 wlc_ssid_t ssid;
1363
1364 WL_TRACE(("%s: SIOCSIWSCAN\n", dev->name));
1365
1366 /* default Broadcast scan */
1367 memset(&ssid, 0, sizeof(ssid));
1368
1369 #if WIRELESS_EXT > 17
1370 /* check for given essid */
1371 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1372 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1373 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1374 ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
1375 memcpy(ssid.SSID, req->essid, ssid.SSID_len);
1376 ssid.SSID_len = htod32(ssid.SSID_len);
1377 }
1378 }
1379 #endif
1380 /* Ignore error (most likely scan in progress) */
1381 (void) dev_wlc_ioctl(dev, WLC_SCAN, &ssid, sizeof(ssid));
1382
1383 return 0;
1384 }
1385 #endif
1386
1387 static int
wl_iw_iscan_set_scan(struct net_device * dev,struct iw_request_info * info,union iwreq_data * wrqu,char * extra)1388 wl_iw_iscan_set_scan(
1389 struct net_device *dev,
1390 struct iw_request_info *info,
1391 union iwreq_data *wrqu,
1392 char *extra
1393 )
1394 {
1395 struct dhd_pub *dhd = dhd_get_pub(dev);
1396 wl_wext_info_t *wext_info = NULL;
1397 wlc_ssid_t ssid;
1398 int err;
1399 #ifndef WL_ESCAN
1400 iscan_info_t *iscan;
1401 #endif
1402
1403 DHD_CHECK(dhd, dev);
1404 wext_info = dhd->wext_info;
1405 err = wl_ext_in4way_sync_wext(dev, STA_NO_SCAN_IN4WAY, WL_EXT_STATUS_SCAN, NULL);
1406 if (err)
1407 return err;
1408 #ifdef WL_ESCAN
1409 /* default Broadcast scan */
1410 memset(&ssid, 0, sizeof(ssid));
1411 #if WIRELESS_EXT > 17
1412 /* check for given essid */
1413 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1414 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1415 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1416 ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
1417 memcpy(ssid.SSID, req->essid, ssid.SSID_len);
1418 ssid.SSID_len = htod32(ssid.SSID_len);
1419 }
1420 }
1421 #endif
1422 return wl_escan_set_scan(dev, dhd, &ssid, 0, TRUE);
1423 #else
1424 iscan = &wext_info->iscan;
1425 WL_TRACE(("%s: SIOCSIWSCAN iscan=%p\n", dev->name, iscan));
1426
1427 /* use backup if our thread is not successful */
1428 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1429 return wl_iw_set_scan(dev, info, wrqu, extra);
1430 }
1431 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1432 return 0;
1433 }
1434
1435 /* default Broadcast scan */
1436 memset(&ssid, 0, sizeof(ssid));
1437
1438 #if WIRELESS_EXT > 17
1439 /* check for given essid */
1440 if (wrqu->data.length == sizeof(struct iw_scan_req)) {
1441 if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
1442 struct iw_scan_req *req = (struct iw_scan_req *)extra;
1443 ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len);
1444 memcpy(ssid.SSID, req->essid, ssid.SSID_len);
1445 ssid.SSID_len = htod32(ssid.SSID_len);
1446 }
1447 }
1448 #endif
1449
1450 iscan->list_cur = iscan->list_hdr;
1451 iscan->iscan_state = ISCAN_STATE_SCANING;
1452
1453
1454 wl_iw_set_event_mask(dev);
1455 wl_iw_iscan(iscan, &ssid, WL_SCAN_ACTION_START);
1456
1457 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
1458 add_timer(&iscan->timer);
1459 iscan->timer_on = 1;
1460
1461 return 0;
1462 #endif
1463 }
1464
1465 #if WIRELESS_EXT > 17
1466 static bool
ie_is_wpa_ie(uint8 ** wpaie,uint8 ** tlvs,int * tlvs_len)1467 ie_is_wpa_ie(uint8 **wpaie, uint8 **tlvs, int *tlvs_len)
1468 {
1469 /* Is this body of this tlvs entry a WPA entry? If */
1470 /* not update the tlvs buffer pointer/length */
1471 uint8 *ie = *wpaie;
1472
1473 /* If the contents match the WPA_OUI and type=1 */
1474 if ((ie[1] >= 6) &&
1475 !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) {
1476 return TRUE;
1477 }
1478
1479 /* point to the next ie */
1480 ie += ie[1] + 2;
1481 /* calculate the length of the rest of the buffer */
1482 *tlvs_len -= (int)(ie - *tlvs);
1483 /* update the pointer to the start of the buffer */
1484 *tlvs = ie;
1485 return FALSE;
1486 }
1487
1488 static bool
ie_is_wps_ie(uint8 ** wpsie,uint8 ** tlvs,int * tlvs_len)1489 ie_is_wps_ie(uint8 **wpsie, uint8 **tlvs, int *tlvs_len)
1490 {
1491 /* Is this body of this tlvs entry a WPS entry? If */
1492 /* not update the tlvs buffer pointer/length */
1493 uint8 *ie = *wpsie;
1494
1495 /* If the contents match the WPA_OUI and type=4 */
1496 if ((ie[1] >= 4) &&
1497 !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) {
1498 return TRUE;
1499 }
1500
1501 /* point to the next ie */
1502 ie += ie[1] + 2;
1503 /* calculate the length of the rest of the buffer */
1504 *tlvs_len -= (int)(ie - *tlvs);
1505 /* update the pointer to the start of the buffer */
1506 *tlvs = ie;
1507 return FALSE;
1508 }
1509 #endif /* WIRELESS_EXT > 17 */
1510
1511 #ifdef BCMWAPI_WPI
_wpa_snprintf_hex(char * buf,size_t buf_size,const u8 * data,size_t len,int uppercase)1512 static inline int _wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data,
1513 size_t len, int uppercase)
1514 {
1515 size_t i;
1516 char *pos = buf, *end = buf + buf_size;
1517 int ret;
1518 if (buf_size == 0)
1519 return 0;
1520 for (i = 0; i < len; i++) {
1521 ret = snprintf(pos, end - pos, uppercase ? "%02X" : "%02x",
1522 data[i]);
1523 if (ret < 0 || ret >= end - pos) {
1524 end[-1] = '\0';
1525 return pos - buf;
1526 }
1527 pos += ret;
1528 }
1529 end[-1] = '\0';
1530 return pos - buf;
1531 }
1532
1533 /**
1534 * wpa_snprintf_hex - Print data as a hex string into a buffer
1535 * @buf: Memory area to use as the output buffer
1536 * @buf_size: Maximum buffer size in bytes (should be at least 2 * len + 1)
1537 * @data: Data to be printed
1538 * @len: Length of data in bytes
1539 * Returns: Number of bytes written
1540 */
1541 static int
wpa_snprintf_hex(char * buf,size_t buf_size,const u8 * data,size_t len)1542 wpa_snprintf_hex(char *buf, size_t buf_size, const u8 *data, size_t len)
1543 {
1544 return _wpa_snprintf_hex(buf, buf_size, data, len, 0);
1545 }
1546 #endif /* BCMWAPI_WPI */
1547
1548 #ifndef WL_ESCAN
1549 static
1550 #endif
1551 int
wl_iw_handle_scanresults_ies(char ** event_p,char * end,struct iw_request_info * info,wl_bss_info_t * bi)1552 wl_iw_handle_scanresults_ies(char **event_p, char *end,
1553 struct iw_request_info *info, wl_bss_info_t *bi)
1554 {
1555 #if WIRELESS_EXT > 17
1556 struct iw_event iwe;
1557 char *event;
1558 #ifdef BCMWAPI_WPI
1559 char *buf;
1560 int custom_event_len;
1561 #endif
1562
1563 event = *event_p;
1564 if (bi->ie_length) {
1565 /* look for wpa/rsn ies in the ie list... */
1566 bcm_tlv_t *ie;
1567 uint8 *ptr = ((uint8 *)bi) + bi->ie_offset;
1568 int ptr_len = bi->ie_length;
1569
1570 /* OSEN IE */
1571 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_VS_ID)) &&
1572 ie->len > WFA_OUI_LEN + 1 &&
1573 !bcmp((const void *)&ie->data[0], (const void *)WFA_OUI, WFA_OUI_LEN) &&
1574 ie->data[WFA_OUI_LEN] == WFA_OUI_TYPE_OSEN) {
1575 iwe.cmd = IWEVGENIE;
1576 iwe.u.data.length = ie->len + 2;
1577 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1578 }
1579 ptr = ((uint8 *)bi) + bi->ie_offset;
1580
1581 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_RSN_ID))) {
1582 iwe.cmd = IWEVGENIE;
1583 iwe.u.data.length = ie->len + 2;
1584 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1585 }
1586 ptr = ((uint8 *)bi) + bi->ie_offset;
1587
1588 if ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_MDIE_ID))) {
1589 iwe.cmd = IWEVGENIE;
1590 iwe.u.data.length = ie->len + 2;
1591 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1592 }
1593 ptr = ((uint8 *)bi) + bi->ie_offset;
1594
1595 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
1596 /* look for WPS IE */
1597 if (ie_is_wps_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
1598 iwe.cmd = IWEVGENIE;
1599 iwe.u.data.length = ie->len + 2;
1600 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1601 break;
1602 }
1603 }
1604
1605 ptr = ((uint8 *)bi) + bi->ie_offset;
1606 ptr_len = bi->ie_length;
1607 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) {
1608 if (ie_is_wpa_ie(((uint8 **)&ie), &ptr, &ptr_len)) {
1609 iwe.cmd = IWEVGENIE;
1610 iwe.u.data.length = ie->len + 2;
1611 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1612 break;
1613 }
1614 }
1615
1616 #ifdef BCMWAPI_WPI
1617 ptr = ((uint8 *)bi) + sizeof(wl_bss_info_t);
1618 ptr_len = bi->ie_length;
1619
1620 while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WAPI_ID))) {
1621 WL_TRACE(("found a WAPI IE...\n"));
1622 #ifdef WAPI_IE_USE_GENIE
1623 iwe.cmd = IWEVGENIE;
1624 iwe.u.data.length = ie->len + 2;
1625 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)ie);
1626 #else /* using CUSTOM event */
1627 iwe.cmd = IWEVCUSTOM;
1628 custom_event_len = strlen("wapi_ie=") + 2*(ie->len + 2);
1629 iwe.u.data.length = custom_event_len;
1630
1631 buf = kmalloc(custom_event_len+1, GFP_KERNEL);
1632 if (buf == NULL)
1633 {
1634 WL_ERROR(("malloc(%d) returned NULL...\n", custom_event_len));
1635 break;
1636 }
1637
1638 memcpy(buf, "wapi_ie=", 8);
1639 wpa_snprintf_hex(buf + 8, 2+1, &(ie->id), 1);
1640 wpa_snprintf_hex(buf + 10, 2+1, &(ie->len), 1);
1641 wpa_snprintf_hex(buf + 12, 2*ie->len+1, ie->data, ie->len);
1642 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, buf);
1643 kfree(buf);
1644 #endif /* WAPI_IE_USE_GENIE */
1645 break;
1646 }
1647 #endif /* BCMWAPI_WPI */
1648 *event_p = event;
1649 }
1650
1651 #endif /* WIRELESS_EXT > 17 */
1652 return 0;
1653 }
1654
1655 #ifndef WL_ESCAN
1656 static int
wl_iw_get_scan(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)1657 wl_iw_get_scan(
1658 struct net_device *dev,
1659 struct iw_request_info *info,
1660 struct iw_point *dwrq,
1661 char *extra
1662 )
1663 {
1664 channel_info_t ci;
1665 wl_scan_results_t *list;
1666 struct iw_event iwe;
1667 wl_bss_info_t *bi = NULL;
1668 int error, i, j;
1669 char *event = extra, *end = extra + dwrq->length, *value;
1670 uint buflen = dwrq->length;
1671 int16 rssi;
1672 int channel;
1673
1674 WL_TRACE(("%s SIOCGIWSCAN\n", dev->name));
1675
1676 if (!extra)
1677 return -EINVAL;
1678
1679 /* Check for scan in progress */
1680 if ((error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci))))
1681 return error;
1682 ci.scan_channel = dtoh32(ci.scan_channel);
1683 if (ci.scan_channel)
1684 return -EAGAIN;
1685
1686 /* Get scan results (too large to put on the stack) */
1687 list = kmalloc(buflen, GFP_KERNEL);
1688 if (!list)
1689 return -ENOMEM;
1690 memset(list, 0, buflen);
1691 list->buflen = htod32(buflen);
1692 if ((error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen))) {
1693 kfree(list);
1694 return error;
1695 }
1696 list->buflen = dtoh32(list->buflen);
1697 list->version = dtoh32(list->version);
1698 list->count = dtoh32(list->count);
1699
1700 ASSERT(list->version == WL_BSS_INFO_VERSION);
1701
1702 for (i = 0; i < list->count && i < IW_MAX_AP; i++) {
1703 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1704 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1705 buflen));
1706
1707 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1708 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1709 channel = (bi->ctl_ch == 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch;
1710 WL_SCAN(("BSSID="MACSTR", channel=%d, RSSI=%d, SSID=\"%s\"\n",
1711 MAC2STR(bi->BSSID.octet), channel, rssi, bi->SSID));
1712
1713 /* First entry must be the BSSID */
1714 iwe.cmd = SIOCGIWAP;
1715 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1716 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1717 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
1718
1719 /* SSID */
1720 iwe.u.data.length = dtoh32(bi->SSID_len);
1721 iwe.cmd = SIOCGIWESSID;
1722 iwe.u.data.flags = 1;
1723 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
1724
1725 /* Mode */
1726 if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
1727 iwe.cmd = SIOCGIWMODE;
1728 if (dtoh16(bi->capability) & DOT11_CAP_ESS)
1729 iwe.u.mode = IW_MODE_INFRA;
1730 else
1731 iwe.u.mode = IW_MODE_ADHOC;
1732 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
1733 }
1734
1735 /* Channel */
1736 iwe.cmd = SIOCGIWFREQ;
1737
1738 iwe.u.freq.m = wf_channel2mhz(CHSPEC_CHANNEL(bi->chanspec),
1739 (CHSPEC_IS2G(bi->chanspec)) ?
1740 WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G);
1741 iwe.u.freq.e = 6;
1742 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
1743
1744 /* Channel quality */
1745 iwe.cmd = IWEVQUAL;
1746 iwe.u.qual.qual = rssi_to_qual(rssi);
1747 iwe.u.qual.level = 0x100 + rssi;
1748 iwe.u.qual.noise = 0x100 + bi->phy_noise;
1749 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
1750
1751 wl_iw_handle_scanresults_ies(&event, end, info, bi);
1752
1753 /* Encryption */
1754 iwe.cmd = SIOCGIWENCODE;
1755 if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
1756 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1757 else
1758 iwe.u.data.flags = IW_ENCODE_DISABLED;
1759 iwe.u.data.length = 0;
1760 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
1761
1762 /* Rates */
1763 if (bi->rateset.count) {
1764 value = event + IW_EV_LCP_LEN;
1765 iwe.cmd = SIOCGIWRATE;
1766 /* Those two flags are ignored... */
1767 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1768 for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
1769 iwe.u.bitrate.value = (bi->rateset.rates[j] & 0x7f) * 500000;
1770 value = IWE_STREAM_ADD_VALUE(info, event, value, end, &iwe,
1771 IW_EV_PARAM_LEN);
1772 }
1773 event = value;
1774 }
1775 }
1776
1777 kfree(list);
1778
1779 dwrq->length = event - extra;
1780 dwrq->flags = 0; /* todo */
1781
1782 return 0;
1783 }
1784 #endif /* WL_ESCAN */
1785
1786 static int
wl_iw_iscan_get_scan(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)1787 wl_iw_iscan_get_scan(
1788 struct net_device *dev,
1789 struct iw_request_info *info,
1790 struct iw_point *dwrq,
1791 char *extra
1792 )
1793 {
1794 struct dhd_pub *dhd = dhd_get_pub(dev);
1795 wl_wext_info_t *wext_info = NULL;
1796 #ifndef WL_ESCAN
1797 wl_scan_results_t *list;
1798 struct iw_event iwe;
1799 wl_bss_info_t *bi = NULL;
1800 int ii, j;
1801 int apcnt;
1802 char *event = extra, *end = extra + dwrq->length, *value;
1803 iscan_buf_t * p_buf;
1804 int16 rssi;
1805 int channel;
1806 iscan_info_t *iscan;
1807 #endif
1808
1809 DHD_CHECK(dhd, dev);
1810 wext_info = dhd->wext_info;
1811 #ifdef WL_ESCAN
1812 return wl_escan_get_scan(dev, dhd, info, dwrq, extra);
1813 #else
1814 WL_TRACE(("%s SIOCGIWSCAN\n", dev->name));
1815
1816 if (!extra)
1817 return -EINVAL;
1818
1819 /* use backup if our thread is not successful */
1820 iscan = &wext_info->iscan;
1821 if ((!iscan) || (iscan->sysioc_pid < 0)) {
1822 return wl_iw_get_scan(dev, info, dwrq, extra);
1823 }
1824
1825 /* Check for scan in progress */
1826 if (iscan->iscan_state == ISCAN_STATE_SCANING) {
1827 WL_TRACE(("%s: SIOCGIWSCAN GET still scanning\n", dev->name));
1828 return -EAGAIN;
1829 }
1830
1831 apcnt = 0;
1832 p_buf = iscan->list_hdr;
1833 /* Get scan results */
1834 while (p_buf != iscan->list_cur) {
1835 list = &((wl_iscan_results_t*)p_buf->iscan_buf)->results;
1836
1837 if (list->version != WL_BSS_INFO_VERSION) {
1838 WL_ERROR(("list->version %d != WL_BSS_INFO_VERSION\n", list->version));
1839 }
1840
1841 bi = NULL;
1842 for (ii = 0; ii < list->count && apcnt < IW_MAX_AP; apcnt++, ii++) {
1843 bi = bi ? (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)) : list->bss_info;
1844 ASSERT(((uintptr)bi + dtoh32(bi->length)) <= ((uintptr)list +
1845 WLC_IW_ISCAN_MAXLEN));
1846
1847 /* overflow check cover fields before wpa IEs */
1848 if (event + ETHER_ADDR_LEN + bi->SSID_len + IW_EV_UINT_LEN + IW_EV_FREQ_LEN +
1849 IW_EV_QUAL_LEN >= end)
1850 return -E2BIG;
1851
1852 // terence 20150419: limit the max. rssi to -2 or the bss will be filtered out in android OS
1853 rssi = MIN(dtoh16(bi->RSSI), RSSI_MAXVAL);
1854 channel = (bi->ctl_ch == 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch;
1855 WL_SCAN(("BSSID="MACSTR", channel=%d, RSSI=%d, SSID=\"%s\"\n",
1856 MAC2STR(bi->BSSID.octet), channel, rssi, bi->SSID));
1857
1858 /* First entry must be the BSSID */
1859 iwe.cmd = SIOCGIWAP;
1860 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1861 memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN);
1862 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_ADDR_LEN);
1863
1864 /* SSID */
1865 iwe.u.data.length = dtoh32(bi->SSID_len);
1866 iwe.cmd = SIOCGIWESSID;
1867 iwe.u.data.flags = 1;
1868 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID);
1869
1870 /* Mode */
1871 if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) {
1872 iwe.cmd = SIOCGIWMODE;
1873 if (dtoh16(bi->capability) & DOT11_CAP_ESS)
1874 iwe.u.mode = IW_MODE_INFRA;
1875 else
1876 iwe.u.mode = IW_MODE_ADHOC;
1877 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_UINT_LEN);
1878 }
1879
1880 /* Channel */
1881 iwe.cmd = SIOCGIWFREQ;
1882 iwe.u.freq.m = wf_channel2mhz(CHSPEC_CHANNEL(bi->chanspec),
1883 (CHSPEC_IS2G(bi->chanspec)) ?
1884 WF_CHAN_FACTOR_2_4_G : WF_CHAN_FACTOR_5_G);
1885 iwe.u.freq.e = 6;
1886 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_FREQ_LEN);
1887
1888 /* Channel quality */
1889 iwe.cmd = IWEVQUAL;
1890 iwe.u.qual.qual = rssi_to_qual(rssi);
1891 iwe.u.qual.level = 0x100 + rssi;
1892 iwe.u.qual.noise = 0x100 + bi->phy_noise;
1893 event = IWE_STREAM_ADD_EVENT(info, event, end, &iwe, IW_EV_QUAL_LEN);
1894
1895 wl_iw_handle_scanresults_ies(&event, end, info, bi);
1896
1897 /* Encryption */
1898 iwe.cmd = SIOCGIWENCODE;
1899 if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY)
1900 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1901 else
1902 iwe.u.data.flags = IW_ENCODE_DISABLED;
1903 iwe.u.data.length = 0;
1904 event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event);
1905
1906 /* Rates */
1907 if (bi->rateset.count <= sizeof(bi->rateset.rates)) {
1908 if (event + IW_MAX_BITRATES*IW_EV_PARAM_LEN >= end)
1909 return -E2BIG;
1910
1911 value = event + IW_EV_LCP_LEN;
1912 iwe.cmd = SIOCGIWRATE;
1913 /* Those two flags are ignored... */
1914 iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
1915 for (j = 0; j < bi->rateset.count && j < IW_MAX_BITRATES; j++) {
1916 iwe.u.bitrate.value = (bi->rateset.rates[j] & 0x7f) * 500000;
1917 value = IWE_STREAM_ADD_VALUE(info, event, value, end, &iwe,
1918 IW_EV_PARAM_LEN);
1919 }
1920 event = value;
1921 }
1922 }
1923 p_buf = p_buf->next;
1924 } /* while (p_buf) */
1925
1926 dwrq->length = event - extra;
1927 dwrq->flags = 0; /* todo */
1928 WL_SCAN(("apcnt=%d\n", apcnt));
1929
1930 return 0;
1931 #endif
1932 }
1933 #endif /* WIRELESS_EXT > 13 */
1934
1935
1936 static int
wl_iw_set_essid(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)1937 wl_iw_set_essid(
1938 struct net_device *dev,
1939 struct iw_request_info *info,
1940 struct iw_point *dwrq,
1941 char *extra
1942 )
1943 {
1944 wlc_ssid_t ssid;
1945 int error;
1946 struct dhd_pub *dhd = dhd_get_pub(dev);
1947 wl_wext_info_t *wext_info = NULL;
1948
1949 WL_TRACE(("%s: SIOCSIWESSID\n", dev->name));
1950 DHD_CHECK(dhd, dev);
1951 wext_info = dhd->wext_info;
1952
1953 /* default Broadcast SSID */
1954 memset(&ssid, 0, sizeof(ssid));
1955 if (dwrq->length && extra) {
1956 #if WIRELESS_EXT > 20
1957 ssid.SSID_len = MIN(sizeof(ssid.SSID), dwrq->length);
1958 #else
1959 ssid.SSID_len = MIN(sizeof(ssid.SSID), dwrq->length-1);
1960 #endif
1961 memcpy(ssid.SSID, extra, ssid.SSID_len);
1962 ssid.SSID_len = htod32(ssid.SSID_len);
1963
1964 if (wext_info) {
1965 memcpy(wext_info->conn_info.ssid.SSID, ssid.SSID, ssid.SSID_len);
1966 wext_info->conn_info.ssid.SSID_len = ssid.SSID_len;
1967 }
1968 if (wext_info && memcmp(ðer_null, &wext_info->conn_info.bssid, ETHER_ADDR_LEN)) {
1969 if ((error = wl_ext_connect(dev, &wext_info->conn_info)))
1970 return error;
1971 } else {
1972 if ((error = dev_wlc_ioctl(dev, WLC_SET_SSID, &ssid, sizeof(ssid)))) {
1973 WL_ERROR(("WLC_SET_SSID failed (%d).\n", error));
1974 return error;
1975 }
1976 WL_MSG(dev->name, "join SSID=\"%s\"\n", ssid.SSID);
1977 }
1978 wl_ext_in4way_sync_wext(dev, STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY,
1979 WL_EXT_STATUS_CONNECTING, NULL);
1980 }
1981 /* If essid null then it is "iwconfig <interface> essid off" command */
1982 else {
1983 scb_val_t scbval;
1984 bzero(&scbval, sizeof(scb_val_t));
1985 WL_MSG(dev->name, "WLC_DISASSOC\n");
1986 if ((error = dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, sizeof(scb_val_t)))) {
1987 WL_ERROR(("WLC_DISASSOC failed (%d).\n", error));
1988 return error;
1989 }
1990 wl_ext_in4way_sync_wext(dev,
1991 STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY|STA_WAIT_DISCONNECTED,
1992 WL_EXT_STATUS_DISCONNECTING, NULL);
1993 }
1994 return 0;
1995 }
1996
1997 static int
wl_iw_get_essid(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)1998 wl_iw_get_essid(
1999 struct net_device *dev,
2000 struct iw_request_info *info,
2001 struct iw_point *dwrq,
2002 char *extra
2003 )
2004 {
2005 wlc_ssid_t ssid;
2006 int error;
2007
2008 WL_TRACE(("%s: SIOCGIWESSID\n", dev->name));
2009
2010 if (!extra)
2011 return -EINVAL;
2012
2013 if ((error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid)))) {
2014 WL_ERROR(("Error getting the SSID %d\n", error));
2015 return error;
2016 }
2017
2018 ssid.SSID_len = dtoh32(ssid.SSID_len);
2019
2020 /* Max SSID length check */
2021 if (ssid.SSID_len > IW_ESSID_MAX_SIZE) {
2022 ssid.SSID_len = IW_ESSID_MAX_SIZE;
2023 }
2024
2025 /* Get the current SSID */
2026 memcpy(extra, ssid.SSID, ssid.SSID_len);
2027
2028 /* NULL terminating as length of extra buffer is IW_ESSID_MAX_SIZE ie 32 */
2029 extra[IW_ESSID_MAX_SIZE] = '\0';
2030
2031 dwrq->length = ssid.SSID_len;
2032
2033 dwrq->flags = 1; /* active */
2034
2035 return 0;
2036 }
2037
2038 static int
wl_iw_set_nick(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)2039 wl_iw_set_nick(
2040 struct net_device *dev,
2041 struct iw_request_info *info,
2042 struct iw_point *dwrq,
2043 char *extra
2044 )
2045 {
2046 wl_iw_t *iw = IW_DEV_IF(dev);
2047 WL_TRACE(("%s: SIOCSIWNICKN\n", dev->name));
2048
2049 if (!extra)
2050 return -EINVAL;
2051
2052 /* Check the size of the string */
2053 if (dwrq->length > sizeof(iw->nickname))
2054 return -E2BIG;
2055
2056 memcpy(iw->nickname, extra, dwrq->length);
2057 iw->nickname[dwrq->length - 1] = '\0';
2058
2059 return 0;
2060 }
2061
2062 static int
wl_iw_get_nick(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)2063 wl_iw_get_nick(
2064 struct net_device *dev,
2065 struct iw_request_info *info,
2066 struct iw_point *dwrq,
2067 char *extra
2068 )
2069 {
2070 wl_iw_t *iw = IW_DEV_IF(dev);
2071 WL_TRACE(("%s: SIOCGIWNICKN\n", dev->name));
2072
2073 if (!extra)
2074 return -EINVAL;
2075
2076 strcpy(extra, iw->nickname);
2077 dwrq->length = strlen(extra) + 1;
2078
2079 return 0;
2080 }
2081
wl_iw_set_rate(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2082 static int wl_iw_set_rate(
2083 struct net_device *dev,
2084 struct iw_request_info *info,
2085 struct iw_param *vwrq,
2086 char *extra
2087 )
2088 {
2089 wl_rateset_t rateset;
2090 int error, rate, i, error_bg, error_a;
2091
2092 WL_TRACE(("%s: SIOCSIWRATE\n", dev->name));
2093
2094 /* Get current rateset */
2095 if ((error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, sizeof(rateset))))
2096 return error;
2097
2098 rateset.count = dtoh32(rateset.count);
2099
2100 if (vwrq->value < 0) {
2101 /* Select maximum rate */
2102 rate = rateset.rates[rateset.count - 1] & 0x7f;
2103 } else if (vwrq->value < rateset.count) {
2104 /* Select rate by rateset index */
2105 rate = rateset.rates[vwrq->value] & 0x7f;
2106 } else {
2107 /* Specified rate in bps */
2108 rate = vwrq->value / 500000;
2109 }
2110
2111 if (vwrq->fixed) {
2112 /*
2113 Set rate override,
2114 Since the is a/b/g-blind, both a/bg_rate are enforced.
2115 */
2116 error_bg = dev_wlc_intvar_set(dev, "bg_rate", rate);
2117 error_a = dev_wlc_intvar_set(dev, "a_rate", rate);
2118
2119 if (error_bg && error_a)
2120 return (error_bg | error_a);
2121 } else {
2122 /*
2123 clear rate override
2124 Since the is a/b/g-blind, both a/bg_rate are enforced.
2125 */
2126 /* 0 is for clearing rate override */
2127 error_bg = dev_wlc_intvar_set(dev, "bg_rate", 0);
2128 /* 0 is for clearing rate override */
2129 error_a = dev_wlc_intvar_set(dev, "a_rate", 0);
2130
2131 if (error_bg && error_a)
2132 return (error_bg | error_a);
2133
2134 /* Remove rates above selected rate */
2135 for (i = 0; i < rateset.count; i++)
2136 if ((rateset.rates[i] & 0x7f) > rate)
2137 break;
2138 rateset.count = htod32(i);
2139
2140 /* Set current rateset */
2141 if ((error = dev_wlc_ioctl(dev, WLC_SET_RATESET, &rateset, sizeof(rateset))))
2142 return error;
2143 }
2144
2145 return 0;
2146 }
2147
wl_iw_get_rate(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2148 static int wl_iw_get_rate(
2149 struct net_device *dev,
2150 struct iw_request_info *info,
2151 struct iw_param *vwrq,
2152 char *extra
2153 )
2154 {
2155 int error, rate;
2156
2157 WL_TRACE(("%s: SIOCGIWRATE\n", dev->name));
2158
2159 /* Report the current tx rate */
2160 if ((error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate))))
2161 return error;
2162 rate = dtoh32(rate);
2163 vwrq->value = rate * 500000;
2164
2165 return 0;
2166 }
2167
2168 static int
wl_iw_set_rts(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2169 wl_iw_set_rts(
2170 struct net_device *dev,
2171 struct iw_request_info *info,
2172 struct iw_param *vwrq,
2173 char *extra
2174 )
2175 {
2176 int error, rts;
2177
2178 WL_TRACE(("%s: SIOCSIWRTS\n", dev->name));
2179
2180 if (vwrq->disabled)
2181 rts = DOT11_DEFAULT_RTS_LEN;
2182 else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_RTS_LEN)
2183 return -EINVAL;
2184 else
2185 rts = vwrq->value;
2186
2187 if ((error = dev_wlc_intvar_set(dev, "rtsthresh", rts)))
2188 return error;
2189
2190 return 0;
2191 }
2192
2193 static int
wl_iw_get_rts(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2194 wl_iw_get_rts(
2195 struct net_device *dev,
2196 struct iw_request_info *info,
2197 struct iw_param *vwrq,
2198 char *extra
2199 )
2200 {
2201 int error, rts;
2202
2203 WL_TRACE(("%s: SIOCGIWRTS\n", dev->name));
2204
2205 if ((error = dev_wlc_intvar_get(dev, "rtsthresh", &rts)))
2206 return error;
2207
2208 vwrq->value = rts;
2209 vwrq->disabled = (rts >= DOT11_DEFAULT_RTS_LEN);
2210 vwrq->fixed = 1;
2211
2212 return 0;
2213 }
2214
2215 static int
wl_iw_set_frag(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2216 wl_iw_set_frag(
2217 struct net_device *dev,
2218 struct iw_request_info *info,
2219 struct iw_param *vwrq,
2220 char *extra
2221 )
2222 {
2223 int error, frag;
2224
2225 WL_TRACE(("%s: SIOCSIWFRAG\n", dev->name));
2226
2227 if (vwrq->disabled)
2228 frag = DOT11_DEFAULT_FRAG_LEN;
2229 else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_FRAG_LEN)
2230 return -EINVAL;
2231 else
2232 frag = vwrq->value;
2233
2234 if ((error = dev_wlc_intvar_set(dev, "fragthresh", frag)))
2235 return error;
2236
2237 return 0;
2238 }
2239
2240 static int
wl_iw_get_frag(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2241 wl_iw_get_frag(
2242 struct net_device *dev,
2243 struct iw_request_info *info,
2244 struct iw_param *vwrq,
2245 char *extra
2246 )
2247 {
2248 int error, fragthreshold;
2249
2250 WL_TRACE(("%s: SIOCGIWFRAG\n", dev->name));
2251
2252 if ((error = dev_wlc_intvar_get(dev, "fragthresh", &fragthreshold)))
2253 return error;
2254
2255 vwrq->value = fragthreshold;
2256 vwrq->disabled = (fragthreshold >= DOT11_DEFAULT_FRAG_LEN);
2257 vwrq->fixed = 1;
2258
2259 return 0;
2260 }
2261
2262 static int
wl_iw_set_txpow(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2263 wl_iw_set_txpow(
2264 struct net_device *dev,
2265 struct iw_request_info *info,
2266 struct iw_param *vwrq,
2267 char *extra
2268 )
2269 {
2270 int error, disable;
2271 uint16 txpwrmw;
2272 WL_TRACE(("%s: SIOCSIWTXPOW\n", dev->name));
2273
2274 /* Make sure radio is off or on as far as software is concerned */
2275 disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0;
2276 disable += WL_RADIO_SW_DISABLE << 16;
2277
2278 disable = htod32(disable);
2279 if ((error = dev_wlc_ioctl(dev, WLC_SET_RADIO, &disable, sizeof(disable))))
2280 return error;
2281
2282 /* If Radio is off, nothing more to do */
2283 if (disable & WL_RADIO_SW_DISABLE)
2284 return 0;
2285
2286 /* Only handle mW */
2287 if (!(vwrq->flags & IW_TXPOW_MWATT))
2288 return -EINVAL;
2289
2290 /* Value < 0 means just "on" or "off" */
2291 if (vwrq->value < 0)
2292 return 0;
2293
2294 if (vwrq->value > 0xffff) txpwrmw = 0xffff;
2295 else txpwrmw = (uint16)vwrq->value;
2296
2297
2298 error = dev_wlc_intvar_set(dev, "qtxpower", (int)(bcm_mw_to_qdbm(txpwrmw)));
2299 return error;
2300 }
2301
2302 static int
wl_iw_get_txpow(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2303 wl_iw_get_txpow(
2304 struct net_device *dev,
2305 struct iw_request_info *info,
2306 struct iw_param *vwrq,
2307 char *extra
2308 )
2309 {
2310 int error, disable, txpwrdbm;
2311 uint8 result;
2312
2313 WL_TRACE(("%s: SIOCGIWTXPOW\n", dev->name));
2314
2315 if ((error = dev_wlc_ioctl(dev, WLC_GET_RADIO, &disable, sizeof(disable))) ||
2316 (error = dev_wlc_intvar_get(dev, "qtxpower", &txpwrdbm)))
2317 return error;
2318
2319 disable = dtoh32(disable);
2320 result = (uint8)(txpwrdbm & ~WL_TXPWR_OVERRIDE);
2321 vwrq->value = (int32)bcm_qdbm_to_mw(result);
2322 vwrq->fixed = 0;
2323 vwrq->disabled = (disable & (WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE)) ? 1 : 0;
2324 vwrq->flags = IW_TXPOW_MWATT;
2325
2326 return 0;
2327 }
2328
2329 #if WIRELESS_EXT > 10
2330 static int
wl_iw_set_retry(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2331 wl_iw_set_retry(
2332 struct net_device *dev,
2333 struct iw_request_info *info,
2334 struct iw_param *vwrq,
2335 char *extra
2336 )
2337 {
2338 int error, lrl, srl;
2339
2340 WL_TRACE(("%s: SIOCSIWRETRY\n", dev->name));
2341
2342 /* Do not handle "off" or "lifetime" */
2343 if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME))
2344 return -EINVAL;
2345
2346 /* Handle "[min|max] limit" */
2347 if (vwrq->flags & IW_RETRY_LIMIT) {
2348 /* "max limit" or just "limit" */
2349 #if WIRELESS_EXT > 20
2350 if ((vwrq->flags & IW_RETRY_LONG) ||(vwrq->flags & IW_RETRY_MAX) ||
2351 !((vwrq->flags & IW_RETRY_SHORT) || (vwrq->flags & IW_RETRY_MIN)))
2352 #else
2353 if ((vwrq->flags & IW_RETRY_MAX) || !(vwrq->flags & IW_RETRY_MIN))
2354 #endif /* WIRELESS_EXT > 20 */
2355 {
2356 lrl = htod32(vwrq->value);
2357 if ((error = dev_wlc_ioctl(dev, WLC_SET_LRL, &lrl, sizeof(lrl))))
2358 return error;
2359 }
2360 /* "min limit" or just "limit" */
2361 #if WIRELESS_EXT > 20
2362 if ((vwrq->flags & IW_RETRY_SHORT) ||(vwrq->flags & IW_RETRY_MIN) ||
2363 !((vwrq->flags & IW_RETRY_LONG) || (vwrq->flags & IW_RETRY_MAX)))
2364 #else
2365 if ((vwrq->flags & IW_RETRY_MIN) || !(vwrq->flags & IW_RETRY_MAX))
2366 #endif /* WIRELESS_EXT > 20 */
2367 {
2368 srl = htod32(vwrq->value);
2369 if ((error = dev_wlc_ioctl(dev, WLC_SET_SRL, &srl, sizeof(srl))))
2370 return error;
2371 }
2372 }
2373
2374 return 0;
2375 }
2376
2377 static int
wl_iw_get_retry(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2378 wl_iw_get_retry(
2379 struct net_device *dev,
2380 struct iw_request_info *info,
2381 struct iw_param *vwrq,
2382 char *extra
2383 )
2384 {
2385 int error, lrl, srl;
2386
2387 WL_TRACE(("%s: SIOCGIWRETRY\n", dev->name));
2388
2389 vwrq->disabled = 0; /* Can't be disabled */
2390
2391 /* Do not handle lifetime queries */
2392 if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME)
2393 return -EINVAL;
2394
2395 /* Get retry limits */
2396 if ((error = dev_wlc_ioctl(dev, WLC_GET_LRL, &lrl, sizeof(lrl))) ||
2397 (error = dev_wlc_ioctl(dev, WLC_GET_SRL, &srl, sizeof(srl))))
2398 return error;
2399
2400 lrl = dtoh32(lrl);
2401 srl = dtoh32(srl);
2402
2403 /* Note : by default, display the min retry number */
2404 if (vwrq->flags & IW_RETRY_MAX) {
2405 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
2406 vwrq->value = lrl;
2407 } else {
2408 vwrq->flags = IW_RETRY_LIMIT;
2409 vwrq->value = srl;
2410 if (srl != lrl)
2411 vwrq->flags |= IW_RETRY_MIN;
2412 }
2413
2414 return 0;
2415 }
2416 #endif /* WIRELESS_EXT > 10 */
2417
2418 static int
wl_iw_set_encode(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)2419 wl_iw_set_encode(
2420 struct net_device *dev,
2421 struct iw_request_info *info,
2422 struct iw_point *dwrq,
2423 char *extra
2424 )
2425 {
2426 wl_wsec_key_t key;
2427 int error, val, wsec;
2428
2429 WL_TRACE(("%s: SIOCSIWENCODE\n", dev->name));
2430
2431 memset(&key, 0, sizeof(key));
2432
2433 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2434 /* Find the current key */
2435 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
2436 val = htod32(key.index);
2437 if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
2438 return error;
2439 val = dtoh32(val);
2440 if (val)
2441 break;
2442 }
2443 /* Default to 0 */
2444 if (key.index == DOT11_MAX_DEFAULT_KEYS)
2445 key.index = 0;
2446 } else {
2447 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2448 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
2449 return -EINVAL;
2450 }
2451
2452 /* Interpret "off" to mean no encryption */
2453 wsec = (dwrq->flags & IW_ENCODE_DISABLED) ? 0 : WEP_ENABLED;
2454
2455 if ((error = dev_wlc_intvar_set(dev, "wsec", wsec)))
2456 return error;
2457
2458 /* Old API used to pass a NULL pointer instead of IW_ENCODE_NOKEY */
2459 if (!extra || !dwrq->length || (dwrq->flags & IW_ENCODE_NOKEY)) {
2460 /* Just select a new current key */
2461 val = htod32(key.index);
2462 if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, &val, sizeof(val))))
2463 return error;
2464 } else {
2465 key.len = dwrq->length;
2466
2467 if (dwrq->length > sizeof(key.data))
2468 return -EINVAL;
2469
2470 memcpy(key.data, extra, dwrq->length);
2471
2472 key.flags = WL_PRIMARY_KEY;
2473 switch (key.len) {
2474 case WEP1_KEY_SIZE:
2475 key.algo = CRYPTO_ALGO_WEP1;
2476 break;
2477 case WEP128_KEY_SIZE:
2478 key.algo = CRYPTO_ALGO_WEP128;
2479 break;
2480 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 14)
2481 case TKIP_KEY_SIZE:
2482 key.algo = CRYPTO_ALGO_TKIP;
2483 break;
2484 #endif
2485 case AES_KEY_SIZE:
2486 key.algo = CRYPTO_ALGO_AES_CCM;
2487 break;
2488 default:
2489 return -EINVAL;
2490 }
2491
2492 /* Set the new key/index */
2493 swap_key_from_BE(&key);
2494 if ((error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key))))
2495 return error;
2496 }
2497
2498 /* Interpret "restricted" to mean shared key authentication */
2499 val = (dwrq->flags & IW_ENCODE_RESTRICTED) ? 1 : 0;
2500 val = htod32(val);
2501 if ((error = dev_wlc_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val))))
2502 return error;
2503
2504 return 0;
2505 }
2506
2507 static int
wl_iw_get_encode(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)2508 wl_iw_get_encode(
2509 struct net_device *dev,
2510 struct iw_request_info *info,
2511 struct iw_point *dwrq,
2512 char *extra
2513 )
2514 {
2515 wl_wsec_key_t key;
2516 int error, val, wsec, auth;
2517
2518 WL_TRACE(("%s: SIOCGIWENCODE\n", dev->name));
2519
2520 /* assure default values of zero for things we don't touch */
2521 bzero(&key, sizeof(wl_wsec_key_t));
2522
2523 if ((dwrq->flags & IW_ENCODE_INDEX) == 0) {
2524 /* Find the current key */
2525 for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; key.index++) {
2526 val = key.index;
2527 if ((error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, sizeof(val))))
2528 return error;
2529 val = dtoh32(val);
2530 if (val)
2531 break;
2532 }
2533 } else
2534 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2535
2536 if (key.index >= DOT11_MAX_DEFAULT_KEYS)
2537 key.index = 0;
2538
2539 /* Get info */
2540
2541 if ((error = dev_wlc_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec))) ||
2542 (error = dev_wlc_ioctl(dev, WLC_GET_AUTH, &auth, sizeof(auth))))
2543 return error;
2544
2545 swap_key_to_BE(&key);
2546
2547 wsec = dtoh32(wsec);
2548 auth = dtoh32(auth);
2549 /* Get key length */
2550 dwrq->length = MIN(IW_ENCODING_TOKEN_MAX, key.len);
2551
2552 /* Get flags */
2553 dwrq->flags = key.index + 1;
2554 if (!(wsec & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))) {
2555 /* Interpret "off" to mean no encryption */
2556 dwrq->flags |= IW_ENCODE_DISABLED;
2557 }
2558 if (auth) {
2559 /* Interpret "restricted" to mean shared key authentication */
2560 dwrq->flags |= IW_ENCODE_RESTRICTED;
2561 }
2562
2563 /* Get key */
2564 if (dwrq->length && extra)
2565 memcpy(extra, key.data, dwrq->length);
2566
2567 return 0;
2568 }
2569
2570 static int
wl_iw_set_power(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2571 wl_iw_set_power(
2572 struct net_device *dev,
2573 struct iw_request_info *info,
2574 struct iw_param *vwrq,
2575 char *extra
2576 )
2577 {
2578 int error, pm;
2579
2580 WL_TRACE(("%s: SIOCSIWPOWER\n", dev->name));
2581
2582 pm = vwrq->disabled ? PM_OFF : PM_MAX;
2583
2584 pm = htod32(pm);
2585 if ((error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm))))
2586 return error;
2587
2588 return 0;
2589 }
2590
2591 static int
wl_iw_get_power(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2592 wl_iw_get_power(
2593 struct net_device *dev,
2594 struct iw_request_info *info,
2595 struct iw_param *vwrq,
2596 char *extra
2597 )
2598 {
2599 int error, pm;
2600
2601 WL_TRACE(("%s: SIOCGIWPOWER\n", dev->name));
2602
2603 if ((error = dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm))))
2604 return error;
2605
2606 pm = dtoh32(pm);
2607 vwrq->disabled = pm ? 0 : 1;
2608 vwrq->flags = IW_POWER_ALL_R;
2609
2610 return 0;
2611 }
2612
2613 #if WIRELESS_EXT > 17
2614 static int
wl_iw_set_wpaie(struct net_device * dev,struct iw_request_info * info,struct iw_point * iwp,char * extra)2615 wl_iw_set_wpaie(
2616 struct net_device *dev,
2617 struct iw_request_info *info,
2618 struct iw_point *iwp,
2619 char *extra
2620 )
2621 {
2622 #if defined(BCMWAPI_WPI)
2623 uchar buf[WLC_IOCTL_SMLEN] = {0};
2624 uchar *p = buf;
2625 int wapi_ie_size;
2626
2627 WL_TRACE(("%s: SIOCSIWGENIE\n", dev->name));
2628
2629 if (extra[0] == DOT11_MNG_WAPI_ID)
2630 {
2631 wapi_ie_size = iwp->length;
2632 memcpy(p, extra, iwp->length);
2633 dev_wlc_bufvar_set(dev, "wapiie", buf, wapi_ie_size);
2634 }
2635 else
2636 #endif
2637 dev_wlc_bufvar_set(dev, "wpaie", extra, iwp->length);
2638
2639 return 0;
2640 }
2641
2642 static int
wl_iw_get_wpaie(struct net_device * dev,struct iw_request_info * info,struct iw_point * iwp,char * extra)2643 wl_iw_get_wpaie(
2644 struct net_device *dev,
2645 struct iw_request_info *info,
2646 struct iw_point *iwp,
2647 char *extra
2648 )
2649 {
2650 WL_TRACE(("%s: SIOCGIWGENIE\n", dev->name));
2651 iwp->length = 64;
2652 dev_wlc_bufvar_get(dev, "wpaie", extra, iwp->length);
2653 return 0;
2654 }
2655
2656 static int
wl_iw_set_encodeext(struct net_device * dev,struct iw_request_info * info,struct iw_point * dwrq,char * extra)2657 wl_iw_set_encodeext(
2658 struct net_device *dev,
2659 struct iw_request_info *info,
2660 struct iw_point *dwrq,
2661 char *extra
2662 )
2663 {
2664 wl_wsec_key_t key;
2665 int error;
2666 struct iw_encode_ext *iwe;
2667
2668 WL_TRACE(("%s: SIOCSIWENCODEEXT\n", dev->name));
2669
2670 memset(&key, 0, sizeof(key));
2671 iwe = (struct iw_encode_ext *)extra;
2672
2673 /* disable encryption completely */
2674 if (dwrq->flags & IW_ENCODE_DISABLED) {
2675
2676 }
2677
2678 /* get the key index */
2679 key.index = 0;
2680 if (dwrq->flags & IW_ENCODE_INDEX)
2681 key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
2682
2683 key.len = iwe->key_len;
2684
2685 /* Instead of bcast for ea address for default wep keys, driver needs it to be Null */
2686 if (!ETHER_ISMULTI(iwe->addr.sa_data))
2687 bcopy((void *)&iwe->addr.sa_data, (char *)&key.ea, ETHER_ADDR_LEN);
2688
2689 /* check for key index change */
2690 if (key.len == 0) {
2691 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2692 WL_WSEC(("Changing the the primary Key to %d\n", key.index));
2693 /* change the key index .... */
2694 key.index = htod32(key.index);
2695 error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY,
2696 &key.index, sizeof(key.index));
2697 if (error)
2698 return error;
2699 }
2700 /* key delete */
2701 else {
2702 swap_key_from_BE(&key);
2703 error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2704 if (error)
2705 return error;
2706 }
2707 }
2708 /* This case is used to allow an external 802.1x supplicant
2709 * to pass the PMK to the in-driver supplicant for use in
2710 * the 4-way handshake.
2711 */
2712 else if (iwe->alg == IW_ENCODE_ALG_PMK) {
2713 int j;
2714 wsec_pmk_t pmk;
2715 char keystring[WSEC_MAX_PSK_LEN + 1];
2716 char* charptr = keystring;
2717 uint len;
2718
2719 /* copy the raw hex key to the appropriate format */
2720 for (j = 0; j < (WSEC_MAX_PSK_LEN / 2); j++) {
2721 (void)snprintf(charptr, 3, "%02x", iwe->key[j]);
2722 charptr += 2;
2723 }
2724 len = strlen(keystring);
2725 pmk.key_len = htod16(len);
2726 bcopy(keystring, pmk.key, len);
2727 pmk.flags = htod16(WSEC_PASSPHRASE);
2728
2729 WL_WSEC(("set key %s\n", keystring));
2730 error = dev_wlc_ioctl(dev, WLC_SET_WSEC_PMK, &pmk, sizeof(pmk));
2731 if (error) {
2732 WL_ERROR(("WLC_SET_WSEC_PMK error %d\n", error));
2733 return error;
2734 }
2735 }
2736
2737 else {
2738 if (iwe->key_len > sizeof(key.data))
2739 return -EINVAL;
2740
2741 WL_WSEC(("Setting the key index %d\n", key.index));
2742 if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
2743 WL_WSEC(("key is a Primary Key\n"));
2744 key.flags = WL_PRIMARY_KEY;
2745 }
2746
2747 bcopy((void *)iwe->key, key.data, iwe->key_len);
2748
2749 if (iwe->alg == IW_ENCODE_ALG_TKIP) {
2750 uint8 keybuf[8];
2751 bcopy(&key.data[24], keybuf, sizeof(keybuf));
2752 bcopy(&key.data[16], &key.data[24], sizeof(keybuf));
2753 bcopy(keybuf, &key.data[16], sizeof(keybuf));
2754 }
2755
2756 /* rx iv */
2757 if (iwe->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) {
2758 uchar *ivptr;
2759 ivptr = (uchar *)iwe->rx_seq;
2760 key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
2761 (ivptr[3] << 8) | ivptr[2];
2762 key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
2763 key.iv_initialized = TRUE;
2764 }
2765
2766 switch (iwe->alg) {
2767 case IW_ENCODE_ALG_NONE:
2768 key.algo = CRYPTO_ALGO_OFF;
2769 break;
2770 case IW_ENCODE_ALG_WEP:
2771 if (iwe->key_len == WEP1_KEY_SIZE)
2772 key.algo = CRYPTO_ALGO_WEP1;
2773 else
2774 key.algo = CRYPTO_ALGO_WEP128;
2775 break;
2776 case IW_ENCODE_ALG_TKIP:
2777 key.algo = CRYPTO_ALGO_TKIP;
2778 break;
2779 case IW_ENCODE_ALG_CCMP:
2780 key.algo = CRYPTO_ALGO_AES_CCM;
2781 break;
2782 #ifdef BCMWAPI_WPI
2783 case IW_ENCODE_ALG_SM4:
2784 key.algo = CRYPTO_ALGO_SMS4;
2785 if (iwe->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
2786 key.flags &= ~WL_PRIMARY_KEY;
2787 }
2788 break;
2789 #endif
2790 default:
2791 break;
2792 }
2793 swap_key_from_BE(&key);
2794
2795 dhd_wait_pend8021x(dev);
2796
2797 error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key));
2798 if (error)
2799 return error;
2800 wl_ext_in4way_sync_wext(dev, STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY,
2801 WL_EXT_STATUS_ADD_KEY, NULL);
2802 }
2803 return 0;
2804 }
2805
2806 /* wpa2 pmk list */
2807 static int
wl_iw_set_pmksa(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2808 wl_iw_set_pmksa(
2809 struct net_device *dev,
2810 struct iw_request_info *info,
2811 struct iw_param *vwrq,
2812 char *extra
2813 )
2814 {
2815 struct pmk_list *pmk_list = NULL;
2816 struct iw_pmksa *iwpmksa;
2817 uint i;
2818 char eabuf[ETHER_ADDR_STR_LEN];
2819 pmkid_t *pmkid_array = NULL;
2820 struct dhd_pub *dhd = dhd_get_pub(dev);
2821 wl_wext_info_t *wext_info = NULL;
2822
2823 WL_TRACE(("%s: SIOCSIWPMKSA\n", dev->name));
2824 DHD_CHECK(dhd, dev);
2825 wext_info = dhd->wext_info;
2826 pmk_list = &wext_info->pmk_list;
2827 if (pmk_list)
2828 pmkid_array = pmk_list->pmkids.pmkid;
2829 iwpmksa = (struct iw_pmksa *)extra;
2830 bzero((char *)eabuf, ETHER_ADDR_STR_LEN);
2831 if (iwpmksa->cmd == IW_PMKSA_FLUSH) {
2832 WL_TRACE(("wl_iw_set_pmksa - IW_PMKSA_FLUSH\n"));
2833 bzero((char *)pmk_list, sizeof(struct pmk_list));
2834 }
2835 if (iwpmksa->cmd == IW_PMKSA_REMOVE) {
2836 pmkid_list_t pmkid, *pmkidptr;
2837 pmkidptr = &pmkid;
2838 bcopy(&iwpmksa->bssid.sa_data[0], &pmkidptr->pmkid[0].BSSID, ETHER_ADDR_LEN);
2839 bcopy(&iwpmksa->pmkid[0], &pmkidptr->pmkid[0].PMKID, WPA2_PMKID_LEN);
2840 {
2841 uint j;
2842 WL_TRACE(("wl_iw_set_pmksa,IW_PMKSA_REMOVE - PMKID: %s = ",
2843 bcm_ether_ntoa(&pmkidptr->pmkid[0].BSSID,
2844 eabuf)));
2845 for (j = 0; j < WPA2_PMKID_LEN; j++)
2846 WL_TRACE(("%02x ", pmkidptr->pmkid[0].PMKID[j]));
2847 WL_TRACE(("\n"));
2848 }
2849 for (i = 0; i < pmk_list->pmkids.npmkid; i++)
2850 if (!bcmp(&iwpmksa->bssid.sa_data[0], &pmkid_array[i].BSSID,
2851 ETHER_ADDR_LEN))
2852 break;
2853 for (; i < pmk_list->pmkids.npmkid; i++) {
2854 bcopy(&pmkid_array[i+1].BSSID,
2855 &pmkid_array[i].BSSID,
2856 ETHER_ADDR_LEN);
2857 bcopy(&pmkid_array[i+1].PMKID,
2858 &pmkid_array[i].PMKID,
2859 WPA2_PMKID_LEN);
2860 }
2861 pmk_list->pmkids.npmkid--;
2862 }
2863 if (iwpmksa->cmd == IW_PMKSA_ADD) {
2864 bcopy(&iwpmksa->bssid.sa_data[0],
2865 &pmkid_array[pmk_list->pmkids.npmkid].BSSID,
2866 ETHER_ADDR_LEN);
2867 bcopy(&iwpmksa->pmkid[0], &pmkid_array[pmk_list->pmkids.npmkid].PMKID,
2868 WPA2_PMKID_LEN);
2869 {
2870 uint j;
2871 uint k;
2872 k = pmk_list->pmkids.npmkid;
2873 BCM_REFERENCE(k);
2874 WL_TRACE(("wl_iw_set_pmksa,IW_PMKSA_ADD - PMKID: %s = ",
2875 bcm_ether_ntoa(&pmkid_array[k].BSSID,
2876 eabuf)));
2877 for (j = 0; j < WPA2_PMKID_LEN; j++)
2878 WL_TRACE(("%02x ", pmkid_array[k].PMKID[j]));
2879 WL_TRACE(("\n"));
2880 }
2881 pmk_list->pmkids.npmkid++;
2882 }
2883 WL_TRACE(("PRINTING pmkid LIST - No of elements %d\n", pmk_list->pmkids.npmkid));
2884 for (i = 0; i < pmk_list->pmkids.npmkid; i++) {
2885 uint j;
2886 WL_TRACE(("PMKID[%d]: %s = ", i,
2887 bcm_ether_ntoa(&pmkid_array[i].BSSID,
2888 eabuf)));
2889 for (j = 0; j < WPA2_PMKID_LEN; j++)
2890 WL_TRACE(("%02x ", pmkid_array[i].PMKID[j]));
2891 printf("\n");
2892 }
2893 dev_wlc_bufvar_set(dev, "pmkid_info", (char *)pmk_list, sizeof(struct pmk_list));
2894 return 0;
2895 }
2896
2897 static int
wl_iw_get_encodeext(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2898 wl_iw_get_encodeext(
2899 struct net_device *dev,
2900 struct iw_request_info *info,
2901 struct iw_param *vwrq,
2902 char *extra
2903 )
2904 {
2905 WL_TRACE(("%s: SIOCGIWENCODEEXT\n", dev->name));
2906 return 0;
2907 }
2908
2909 static int
wl_iw_set_wpaauth(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)2910 wl_iw_set_wpaauth(
2911 struct net_device *dev,
2912 struct iw_request_info *info,
2913 struct iw_param *vwrq,
2914 char *extra
2915 )
2916 {
2917 int error = 0;
2918 int paramid;
2919 int paramval;
2920 uint32 cipher_combined;
2921 int val = 0;
2922 wl_iw_t *iw = IW_DEV_IF(dev);
2923
2924 WL_TRACE(("%s: SIOCSIWAUTH\n", dev->name));
2925
2926 paramid = vwrq->flags & IW_AUTH_INDEX;
2927 paramval = vwrq->value;
2928
2929 WL_TRACE(("%s: SIOCSIWAUTH, paramid = 0x%0x, paramval = 0x%0x\n",
2930 dev->name, paramid, paramval));
2931
2932 switch (paramid) {
2933
2934 case IW_AUTH_WPA_VERSION:
2935 /* supported wpa version disabled or wpa or wpa2 */
2936 if (paramval & IW_AUTH_WPA_VERSION_DISABLED)
2937 val = WPA_AUTH_DISABLED;
2938 else if (paramval & (IW_AUTH_WPA_VERSION_WPA))
2939 val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
2940 else if (paramval & IW_AUTH_WPA_VERSION_WPA2)
2941 val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
2942 #ifdef BCMWAPI_WPI
2943 else if (paramval & IW_AUTH_WAPI_VERSION_1)
2944 val = WAPI_AUTH_UNSPECIFIED;
2945 #endif
2946 WL_TRACE(("%d: setting wpa_auth to 0x%0x\n", __LINE__, val));
2947 if ((error = dev_wlc_intvar_set(dev, "wpa_auth", val)))
2948 return error;
2949 break;
2950
2951 case IW_AUTH_CIPHER_PAIRWISE:
2952 case IW_AUTH_CIPHER_GROUP: {
2953 int fbt_cap = 0;
2954
2955 if (paramid == IW_AUTH_CIPHER_PAIRWISE) {
2956 iw->pwsec = paramval;
2957 }
2958 else {
2959 iw->gwsec = paramval;
2960 }
2961
2962 if ((error = dev_wlc_intvar_get(dev, "wsec", &val))) {
2963 WL_ERROR(("wsec error %d\n", error));
2964 return error;
2965 }
2966 WL_WSEC(("get wsec=0x%x\n", val));
2967
2968 cipher_combined = iw->gwsec | iw->pwsec;
2969 val &= ~(WEP_ENABLED | TKIP_ENABLED | AES_ENABLED);
2970 if (cipher_combined & (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104))
2971 val |= WEP_ENABLED;
2972 if (cipher_combined & IW_AUTH_CIPHER_TKIP)
2973 val |= TKIP_ENABLED;
2974 if (cipher_combined & IW_AUTH_CIPHER_CCMP)
2975 val |= AES_ENABLED;
2976 #ifdef BCMWAPI_WPI
2977 val &= ~SMS4_ENABLED;
2978 if (cipher_combined & IW_AUTH_CIPHER_SMS4)
2979 val |= SMS4_ENABLED;
2980 #endif
2981
2982 if (iw->privacy_invoked && !val) {
2983 WL_WSEC(("%s: 'Privacy invoked' TRUE but clearing wsec, assuming "
2984 "we're a WPS enrollee\n", dev->name));
2985 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", TRUE))) {
2986 WL_WSEC(("Failed to set iovar is_WPS_enrollee\n"));
2987 return error;
2988 }
2989 } else if (val) {
2990 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
2991 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
2992 return error;
2993 }
2994 }
2995
2996 WL_WSEC(("set wsec=0x%x\n", val));
2997 if ((error = dev_wlc_intvar_set(dev, "wsec", val))) {
2998 WL_ERROR(("wsec error %d\n", error));
2999 return error;
3000 }
3001
3002 /* Ensure in-dongle supplicant is turned on when FBT wants to do the 4-way
3003 * handshake.
3004 */
3005 if (dev_wlc_intvar_get(dev, "fbt_cap", &fbt_cap) == 0) {
3006 WL_WSEC(("get fbt_cap=0x%x\n", fbt_cap));
3007 if (fbt_cap == WLC_FBT_CAP_DRV_4WAY_AND_REASSOC) {
3008 if ((paramid == IW_AUTH_CIPHER_PAIRWISE) && (val & AES_ENABLED)) {
3009 if ((error = dev_wlc_intvar_set(dev, "sup_wpa", 1))) {
3010 WL_ERROR(("sup_wpa 1 error %d\n", error));
3011 return error;
3012 }
3013 }
3014 else if (val == 0) {
3015 if ((error = dev_wlc_intvar_set(dev, "sup_wpa", 0))) {
3016 WL_ERROR(("sup_wpa 0 error %d\n", error));
3017 return error;
3018 }
3019 }
3020 }
3021 }
3022 break;
3023 }
3024
3025 case IW_AUTH_KEY_MGMT:
3026 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val))) {
3027 WL_ERROR(("wpa_auth error %d\n", error));
3028 return error;
3029 }
3030 WL_WSEC(("get wpa_auth to %d\n", val));
3031
3032 if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
3033 if (paramval & (IW_AUTH_KEY_MGMT_FT_PSK | IW_AUTH_KEY_MGMT_PSK))
3034 val = WPA_AUTH_PSK;
3035 else
3036 val = WPA_AUTH_UNSPECIFIED;
3037 if (paramval & (IW_AUTH_KEY_MGMT_FT_802_1X | IW_AUTH_KEY_MGMT_FT_PSK))
3038 val |= WPA2_AUTH_FT;
3039 }
3040 else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
3041 if (paramval & (IW_AUTH_KEY_MGMT_FT_PSK | IW_AUTH_KEY_MGMT_PSK))
3042 val = WPA2_AUTH_PSK;
3043 else
3044 val = WPA2_AUTH_UNSPECIFIED;
3045 if (paramval & (IW_AUTH_KEY_MGMT_FT_802_1X | IW_AUTH_KEY_MGMT_FT_PSK))
3046 val |= WPA2_AUTH_FT;
3047 }
3048 #ifdef BCMWAPI_WPI
3049 if (paramval & (IW_AUTH_KEY_MGMT_WAPI_PSK | IW_AUTH_KEY_MGMT_WAPI_CERT))
3050 val = WAPI_AUTH_UNSPECIFIED;
3051 #endif
3052 WL_TRACE(("%d: setting wpa_auth to %d\n", __LINE__, val));
3053 if ((error = dev_wlc_intvar_set(dev, "wpa_auth", val)))
3054 return error;
3055 break;
3056
3057 case IW_AUTH_TKIP_COUNTERMEASURES:
3058 dev_wlc_bufvar_set(dev, "tkip_countermeasures", (char *)¶mval, 1);
3059 break;
3060
3061 case IW_AUTH_80211_AUTH_ALG:
3062 /* open shared */
3063 WL_MSG(dev->name, "Setting the D11auth %d\n", paramval);
3064 if (paramval & IW_AUTH_ALG_OPEN_SYSTEM)
3065 val = 0;
3066 else if (paramval & IW_AUTH_ALG_SHARED_KEY)
3067 val = 1;
3068 else
3069 error = 1;
3070 if (!error && (error = dev_wlc_intvar_set(dev, "auth", val)))
3071 return error;
3072 break;
3073
3074 case IW_AUTH_WPA_ENABLED:
3075 if (paramval == 0) {
3076 val = 0;
3077 WL_TRACE(("%d: setting wpa_auth to %d\n", __LINE__, val));
3078 error = dev_wlc_intvar_set(dev, "wpa_auth", val);
3079 return error;
3080 }
3081 else {
3082 /* If WPA is enabled, wpa_auth is set elsewhere */
3083 }
3084 break;
3085
3086 case IW_AUTH_DROP_UNENCRYPTED:
3087 dev_wlc_bufvar_set(dev, "wsec_restrict", (char *)¶mval, 1);
3088 break;
3089
3090 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3091 dev_wlc_bufvar_set(dev, "rx_unencrypted_eapol", (char *)¶mval, 1);
3092 break;
3093
3094 #if WIRELESS_EXT > 17
3095
3096 case IW_AUTH_ROAMING_CONTROL:
3097 WL_TRACE(("IW_AUTH_ROAMING_CONTROL\n"));
3098 /* driver control or user space app control */
3099 break;
3100
3101 case IW_AUTH_PRIVACY_INVOKED: {
3102 int wsec;
3103
3104 if (paramval == 0) {
3105 iw->privacy_invoked = FALSE;
3106 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
3107 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
3108 return error;
3109 }
3110 } else {
3111 iw->privacy_invoked = TRUE;
3112 if ((error = dev_wlc_intvar_get(dev, "wsec", &wsec)))
3113 return error;
3114
3115 if (!WSEC_ENABLED(wsec)) {
3116 /* if privacy is true, but wsec is false, we are a WPS enrollee */
3117 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", TRUE))) {
3118 WL_WSEC(("Failed to set iovar is_WPS_enrollee\n"));
3119 return error;
3120 }
3121 } else {
3122 if ((error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", FALSE))) {
3123 WL_WSEC(("Failed to clear iovar is_WPS_enrollee\n"));
3124 return error;
3125 }
3126 }
3127 }
3128 break;
3129 }
3130
3131
3132 #endif /* WIRELESS_EXT > 17 */
3133
3134 #ifdef BCMWAPI_WPI
3135
3136 case IW_AUTH_WAPI_ENABLED:
3137 if ((error = dev_wlc_intvar_get(dev, "wsec", &val)))
3138 return error;
3139 if (paramval) {
3140 val |= SMS4_ENABLED;
3141 if ((error = dev_wlc_intvar_set(dev, "wsec", val))) {
3142 WL_ERROR(("setting wsec to 0x%0x returned error %d\n",
3143 val, error));
3144 return error;
3145 }
3146 if ((error = dev_wlc_intvar_set(dev, "wpa_auth", WAPI_AUTH_UNSPECIFIED))) {
3147 WL_ERROR(("setting wpa_auth(%d) returned %d\n",
3148 WAPI_AUTH_UNSPECIFIED,
3149 error));
3150 return error;
3151 }
3152 }
3153
3154 break;
3155
3156 #endif /* BCMWAPI_WPI */
3157
3158 default:
3159 break;
3160 }
3161 return 0;
3162 }
3163 #define VAL_PSK(_val) (((_val) & WPA_AUTH_PSK) || ((_val) & WPA2_AUTH_PSK))
3164
3165 static int
wl_iw_get_wpaauth(struct net_device * dev,struct iw_request_info * info,struct iw_param * vwrq,char * extra)3166 wl_iw_get_wpaauth(
3167 struct net_device *dev,
3168 struct iw_request_info *info,
3169 struct iw_param *vwrq,
3170 char *extra
3171 )
3172 {
3173 int error;
3174 int paramid;
3175 int paramval = 0;
3176 int val;
3177 wl_iw_t *iw = IW_DEV_IF(dev);
3178
3179 WL_TRACE(("%s: SIOCGIWAUTH\n", dev->name));
3180
3181 paramid = vwrq->flags & IW_AUTH_INDEX;
3182
3183 switch (paramid) {
3184 case IW_AUTH_WPA_VERSION:
3185 /* supported wpa version disabled or wpa or wpa2 */
3186 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
3187 return error;
3188 if (val & (WPA_AUTH_NONE | WPA_AUTH_DISABLED))
3189 paramval = IW_AUTH_WPA_VERSION_DISABLED;
3190 else if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED))
3191 paramval = IW_AUTH_WPA_VERSION_WPA;
3192 else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED))
3193 paramval = IW_AUTH_WPA_VERSION_WPA2;
3194 break;
3195
3196 case IW_AUTH_CIPHER_PAIRWISE:
3197 paramval = iw->pwsec;
3198 break;
3199
3200 case IW_AUTH_CIPHER_GROUP:
3201 paramval = iw->gwsec;
3202 break;
3203
3204 case IW_AUTH_KEY_MGMT:
3205 /* psk, 1x */
3206 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
3207 return error;
3208 if (VAL_PSK(val))
3209 paramval = IW_AUTH_KEY_MGMT_PSK;
3210 else
3211 paramval = IW_AUTH_KEY_MGMT_802_1X;
3212
3213 break;
3214 case IW_AUTH_TKIP_COUNTERMEASURES:
3215 dev_wlc_bufvar_get(dev, "tkip_countermeasures", (char *)¶mval, 1);
3216 break;
3217
3218 case IW_AUTH_DROP_UNENCRYPTED:
3219 dev_wlc_bufvar_get(dev, "wsec_restrict", (char *)¶mval, 1);
3220 break;
3221
3222 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3223 dev_wlc_bufvar_get(dev, "rx_unencrypted_eapol", (char *)¶mval, 1);
3224 break;
3225
3226 case IW_AUTH_80211_AUTH_ALG:
3227 /* open, shared, leap */
3228 if ((error = dev_wlc_intvar_get(dev, "auth", &val)))
3229 return error;
3230 if (!val)
3231 paramval = IW_AUTH_ALG_OPEN_SYSTEM;
3232 else
3233 paramval = IW_AUTH_ALG_SHARED_KEY;
3234 break;
3235 case IW_AUTH_WPA_ENABLED:
3236 if ((error = dev_wlc_intvar_get(dev, "wpa_auth", &val)))
3237 return error;
3238 if (val)
3239 paramval = TRUE;
3240 else
3241 paramval = FALSE;
3242 break;
3243
3244 #if WIRELESS_EXT > 17
3245
3246 case IW_AUTH_ROAMING_CONTROL:
3247 WL_ERROR(("IW_AUTH_ROAMING_CONTROL\n"));
3248 /* driver control or user space app control */
3249 break;
3250
3251 case IW_AUTH_PRIVACY_INVOKED:
3252 paramval = iw->privacy_invoked;
3253 break;
3254
3255 #endif /* WIRELESS_EXT > 17 */
3256 }
3257 vwrq->value = paramval;
3258 return 0;
3259 }
3260 #endif /* WIRELESS_EXT > 17 */
3261
3262 static const iw_handler wl_iw_handler[] =
3263 {
3264 (iw_handler) wl_iw_config_commit, /* SIOCSIWCOMMIT */
3265 (iw_handler) wl_iw_get_name, /* SIOCGIWNAME */
3266 (iw_handler) NULL, /* SIOCSIWNWID */
3267 (iw_handler) NULL, /* SIOCGIWNWID */
3268 (iw_handler) wl_iw_set_freq, /* SIOCSIWFREQ */
3269 (iw_handler) wl_iw_get_freq, /* SIOCGIWFREQ */
3270 (iw_handler) wl_iw_set_mode, /* SIOCSIWMODE */
3271 (iw_handler) wl_iw_get_mode, /* SIOCGIWMODE */
3272 (iw_handler) NULL, /* SIOCSIWSENS */
3273 (iw_handler) NULL, /* SIOCGIWSENS */
3274 (iw_handler) NULL, /* SIOCSIWRANGE */
3275 (iw_handler) wl_iw_get_range, /* SIOCGIWRANGE */
3276 (iw_handler) NULL, /* SIOCSIWPRIV */
3277 (iw_handler) NULL, /* SIOCGIWPRIV */
3278 (iw_handler) NULL, /* SIOCSIWSTATS */
3279 (iw_handler) NULL, /* SIOCGIWSTATS */
3280 (iw_handler) wl_iw_set_spy, /* SIOCSIWSPY */
3281 (iw_handler) wl_iw_get_spy, /* SIOCGIWSPY */
3282 (iw_handler) NULL, /* -- hole -- */
3283 (iw_handler) NULL, /* -- hole -- */
3284 (iw_handler) wl_iw_set_wap, /* SIOCSIWAP */
3285 (iw_handler) wl_iw_get_wap, /* SIOCGIWAP */
3286 #if WIRELESS_EXT > 17
3287 (iw_handler) wl_iw_mlme, /* SIOCSIWMLME */
3288 #else
3289 (iw_handler) NULL, /* -- hole -- */
3290 #endif
3291 #ifdef WL_ESCAN
3292 (iw_handler) NULL, /* SIOCGIWAPLIST */
3293 #else
3294 (iw_handler) wl_iw_iscan_get_aplist, /* SIOCGIWAPLIST */
3295 #endif
3296 #if WIRELESS_EXT > 13
3297 (iw_handler) wl_iw_iscan_set_scan, /* SIOCSIWSCAN */
3298 (iw_handler) wl_iw_iscan_get_scan, /* SIOCGIWSCAN */
3299 #else /* WIRELESS_EXT > 13 */
3300 (iw_handler) NULL, /* SIOCSIWSCAN */
3301 (iw_handler) NULL, /* SIOCGIWSCAN */
3302 #endif /* WIRELESS_EXT > 13 */
3303 (iw_handler) wl_iw_set_essid, /* SIOCSIWESSID */
3304 (iw_handler) wl_iw_get_essid, /* SIOCGIWESSID */
3305 (iw_handler) wl_iw_set_nick, /* SIOCSIWNICKN */
3306 (iw_handler) wl_iw_get_nick, /* SIOCGIWNICKN */
3307 (iw_handler) NULL, /* -- hole -- */
3308 (iw_handler) NULL, /* -- hole -- */
3309 (iw_handler) wl_iw_set_rate, /* SIOCSIWRATE */
3310 (iw_handler) wl_iw_get_rate, /* SIOCGIWRATE */
3311 (iw_handler) wl_iw_set_rts, /* SIOCSIWRTS */
3312 (iw_handler) wl_iw_get_rts, /* SIOCGIWRTS */
3313 (iw_handler) wl_iw_set_frag, /* SIOCSIWFRAG */
3314 (iw_handler) wl_iw_get_frag, /* SIOCGIWFRAG */
3315 (iw_handler) wl_iw_set_txpow, /* SIOCSIWTXPOW */
3316 (iw_handler) wl_iw_get_txpow, /* SIOCGIWTXPOW */
3317 #if WIRELESS_EXT > 10
3318 (iw_handler) wl_iw_set_retry, /* SIOCSIWRETRY */
3319 (iw_handler) wl_iw_get_retry, /* SIOCGIWRETRY */
3320 #endif /* WIRELESS_EXT > 10 */
3321 (iw_handler) wl_iw_set_encode, /* SIOCSIWENCODE */
3322 (iw_handler) wl_iw_get_encode, /* SIOCGIWENCODE */
3323 (iw_handler) wl_iw_set_power, /* SIOCSIWPOWER */
3324 (iw_handler) wl_iw_get_power, /* SIOCGIWPOWER */
3325 #if WIRELESS_EXT > 17
3326 (iw_handler) NULL, /* -- hole -- */
3327 (iw_handler) NULL, /* -- hole -- */
3328 (iw_handler) wl_iw_set_wpaie, /* SIOCSIWGENIE */
3329 (iw_handler) wl_iw_get_wpaie, /* SIOCGIWGENIE */
3330 (iw_handler) wl_iw_set_wpaauth, /* SIOCSIWAUTH */
3331 (iw_handler) wl_iw_get_wpaauth, /* SIOCGIWAUTH */
3332 (iw_handler) wl_iw_set_encodeext, /* SIOCSIWENCODEEXT */
3333 (iw_handler) wl_iw_get_encodeext, /* SIOCGIWENCODEEXT */
3334 (iw_handler) wl_iw_set_pmksa, /* SIOCSIWPMKSA */
3335 #endif /* WIRELESS_EXT > 17 */
3336 };
3337
3338 #if WIRELESS_EXT > 12
3339 enum {
3340 WL_IW_SET_LEDDC = SIOCIWFIRSTPRIV,
3341 WL_IW_SET_VLANMODE,
3342 WL_IW_SET_PM,
3343 WL_IW_SET_LAST
3344 };
3345
3346 static iw_handler wl_iw_priv_handler[] = {
3347 wl_iw_set_leddc,
3348 wl_iw_set_vlanmode,
3349 wl_iw_set_pm,
3350 NULL
3351 };
3352
3353 static struct iw_priv_args wl_iw_priv_args[] = {
3354 {
3355 WL_IW_SET_LEDDC,
3356 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3357 0,
3358 "set_leddc"
3359 },
3360 {
3361 WL_IW_SET_VLANMODE,
3362 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3363 0,
3364 "set_vlanmode"
3365 },
3366 {
3367 WL_IW_SET_PM,
3368 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
3369 0,
3370 "set_pm"
3371 },
3372 { 0, 0, 0, { 0 } }
3373 };
3374
3375 const struct iw_handler_def wl_iw_handler_def =
3376 {
3377 .num_standard = ARRAYSIZE(wl_iw_handler),
3378 .num_private = ARRAY_SIZE(wl_iw_priv_handler),
3379 .num_private_args = ARRAY_SIZE(wl_iw_priv_args),
3380 .standard = (const iw_handler *) wl_iw_handler,
3381 .private = wl_iw_priv_handler,
3382 .private_args = wl_iw_priv_args,
3383 #if WIRELESS_EXT >= 19
3384 get_wireless_stats: dhd_get_wireless_stats,
3385 #endif /* WIRELESS_EXT >= 19 */
3386 };
3387 #endif /* WIRELESS_EXT > 12 */
3388
3389 int
wl_iw_ioctl(struct net_device * dev,struct ifreq * rq,int cmd)3390 wl_iw_ioctl(
3391 struct net_device *dev,
3392 struct ifreq *rq,
3393 int cmd
3394 )
3395 {
3396 struct iwreq *wrq = (struct iwreq *) rq;
3397 struct iw_request_info info;
3398 iw_handler handler;
3399 char *extra = NULL;
3400 size_t token_size = 1;
3401 int max_tokens = 0, ret = 0;
3402 #ifndef WL_ESCAN
3403 struct dhd_pub *dhd = dhd_get_pub(dev);
3404 wl_wext_info_t *wext_info = NULL;
3405 iscan_info_t *iscan;
3406
3407 DHD_CHECK(dhd, dev);
3408 wext_info = dhd->wext_info;
3409 iscan = &wext_info->iscan;
3410 #endif
3411
3412 if (cmd < SIOCIWFIRST ||
3413 IW_IOCTL_IDX(cmd) >= ARRAYSIZE(wl_iw_handler) ||
3414 !(handler = wl_iw_handler[IW_IOCTL_IDX(cmd)]))
3415 return -EOPNOTSUPP;
3416
3417 switch (cmd) {
3418
3419 case SIOCSIWESSID:
3420 case SIOCGIWESSID:
3421 case SIOCSIWNICKN:
3422 case SIOCGIWNICKN:
3423 max_tokens = IW_ESSID_MAX_SIZE + 1;
3424 break;
3425
3426 case SIOCSIWENCODE:
3427 case SIOCGIWENCODE:
3428 #if WIRELESS_EXT > 17
3429 case SIOCSIWENCODEEXT:
3430 case SIOCGIWENCODEEXT:
3431 #endif
3432 max_tokens = IW_ENCODING_TOKEN_MAX;
3433 break;
3434
3435 case SIOCGIWRANGE:
3436 max_tokens = sizeof(struct iw_range);
3437 break;
3438
3439 case SIOCGIWAPLIST:
3440 token_size = sizeof(struct sockaddr) + sizeof(struct iw_quality);
3441 max_tokens = IW_MAX_AP;
3442 break;
3443
3444 #if WIRELESS_EXT > 13
3445 case SIOCGIWSCAN:
3446 #ifndef WL_ESCAN
3447 if (iscan)
3448 max_tokens = wrq->u.data.length;
3449 else
3450 #endif
3451 max_tokens = IW_SCAN_MAX_DATA;
3452 break;
3453 #endif /* WIRELESS_EXT > 13 */
3454
3455 case SIOCSIWSPY:
3456 token_size = sizeof(struct sockaddr);
3457 max_tokens = IW_MAX_SPY;
3458 break;
3459
3460 case SIOCGIWSPY:
3461 token_size = sizeof(struct sockaddr) + sizeof(struct iw_quality);
3462 max_tokens = IW_MAX_SPY;
3463 break;
3464 default:
3465 break;
3466 }
3467
3468 if (max_tokens && wrq->u.data.pointer) {
3469 if (wrq->u.data.length > max_tokens)
3470 return -E2BIG;
3471
3472 if (!(extra = kmalloc(max_tokens * token_size, GFP_KERNEL)))
3473 return -ENOMEM;
3474
3475 if (copy_from_user(extra, wrq->u.data.pointer, wrq->u.data.length * token_size)) {
3476 kfree(extra);
3477 return -EFAULT;
3478 }
3479 }
3480
3481 info.cmd = cmd;
3482 info.flags = 0;
3483
3484 ret = handler(dev, &info, &wrq->u, extra);
3485
3486 if (extra) {
3487 if (copy_to_user(wrq->u.data.pointer, extra, wrq->u.data.length * token_size)) {
3488 kfree(extra);
3489 return -EFAULT;
3490 }
3491
3492 kfree(extra);
3493 }
3494
3495 return ret;
3496 }
3497
3498 /* Convert a connection status event into a connection status string.
3499 * Returns TRUE if a matching connection status string was found.
3500 */
3501 bool
wl_iw_conn_status_str(uint32 event_type,uint32 status,uint32 reason,char * stringBuf,uint buflen)3502 wl_iw_conn_status_str(uint32 event_type, uint32 status, uint32 reason,
3503 char* stringBuf, uint buflen)
3504 {
3505 typedef struct conn_fail_event_map_t {
3506 uint32 inEvent; /* input: event type to match */
3507 uint32 inStatus; /* input: event status code to match */
3508 uint32 inReason; /* input: event reason code to match */
3509 const char* outName; /* output: failure type */
3510 const char* outCause; /* output: failure cause */
3511 } conn_fail_event_map_t;
3512
3513 /* Map of WLC_E events to connection failure strings */
3514 # define WL_IW_DONT_CARE 9999
3515 const conn_fail_event_map_t event_map [] = {
3516 /* inEvent inStatus inReason */
3517 /* outName outCause */
3518 {WLC_E_SET_SSID, WLC_E_STATUS_SUCCESS, WL_IW_DONT_CARE,
3519 "Conn", "Success"},
3520 {WLC_E_SET_SSID, WLC_E_STATUS_NO_NETWORKS, WL_IW_DONT_CARE,
3521 "Conn", "NoNetworks"},
3522 {WLC_E_SET_SSID, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3523 "Conn", "ConfigMismatch"},
3524 {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_PRUNE_ENCR_MISMATCH,
3525 "Conn", "EncrypMismatch"},
3526 {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_RSN_MISMATCH,
3527 "Conn", "RsnMismatch"},
3528 {WLC_E_AUTH, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
3529 "Conn", "AuthTimeout"},
3530 {WLC_E_AUTH, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3531 "Conn", "AuthFail"},
3532 {WLC_E_AUTH, WLC_E_STATUS_NO_ACK, WL_IW_DONT_CARE,
3533 "Conn", "AuthNoAck"},
3534 {WLC_E_REASSOC, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE,
3535 "Conn", "ReassocFail"},
3536 {WLC_E_REASSOC, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE,
3537 "Conn", "ReassocTimeout"},
3538 {WLC_E_REASSOC, WLC_E_STATUS_ABORT, WL_IW_DONT_CARE,
3539 "Conn", "ReassocAbort"},
3540 {WLC_E_PSK_SUP, WLC_SUP_KEYED, WL_IW_DONT_CARE,
3541 "Sup", "ConnSuccess"},
3542 {WLC_E_PSK_SUP, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3543 "Sup", "WpaHandshakeFail"},
3544 {WLC_E_DEAUTH_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3545 "Conn", "Deauth"},
3546 {WLC_E_DISASSOC_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3547 "Conn", "DisassocInd"},
3548 {WLC_E_DISASSOC, WL_IW_DONT_CARE, WL_IW_DONT_CARE,
3549 "Conn", "Disassoc"}
3550 };
3551
3552 const char* name = "";
3553 const char* cause = NULL;
3554 int i;
3555
3556 /* Search the event map table for a matching event */
3557 for (i = 0; i < sizeof(event_map)/sizeof(event_map[0]); i++) {
3558 const conn_fail_event_map_t* row = &event_map[i];
3559 if (row->inEvent == event_type &&
3560 (row->inStatus == status || row->inStatus == WL_IW_DONT_CARE) &&
3561 (row->inReason == reason || row->inReason == WL_IW_DONT_CARE)) {
3562 name = row->outName;
3563 cause = row->outCause;
3564 break;
3565 }
3566 }
3567
3568 /* If found, generate a connection failure string and return TRUE */
3569 if (cause) {
3570 memset(stringBuf, 0, buflen);
3571 (void)snprintf(stringBuf, buflen, "%s %s %02d %02d", name, cause, status, reason);
3572 WL_TRACE(("Connection status: %s\n", stringBuf));
3573 return TRUE;
3574 } else {
3575 return FALSE;
3576 }
3577 }
3578
3579 #if (WIRELESS_EXT > 14)
3580 /* Check if we have received an event that indicates connection failure
3581 * If so, generate a connection failure report string.
3582 * The caller supplies a buffer to hold the generated string.
3583 */
3584 static bool
wl_iw_check_conn_fail(const wl_event_msg_t * e,char * stringBuf,uint buflen)3585 wl_iw_check_conn_fail(const wl_event_msg_t *e, char* stringBuf, uint buflen)
3586 {
3587 uint32 event = ntoh32(e->event_type);
3588 uint32 status = ntoh32(e->status);
3589 uint32 reason = ntoh32(e->reason);
3590
3591 if (wl_iw_conn_status_str(event, status, reason, stringBuf, buflen)) {
3592 return TRUE;
3593 } else
3594 {
3595 return FALSE;
3596 }
3597 }
3598 #endif /* WIRELESS_EXT > 14 */
3599
3600 #ifndef IW_CUSTOM_MAX
3601 #define IW_CUSTOM_MAX 256 /* size of extra buffer used for translation of events */
3602 #endif /* IW_CUSTOM_MAX */
3603
3604 s32
wl_iw_event(struct net_device * dev,void * wext_info_void,const wl_event_msg_t * e,void * data)3605 wl_iw_event(struct net_device *dev, void *wext_info_void,
3606 const wl_event_msg_t *e, void* data)
3607 {
3608 #if WIRELESS_EXT > 13
3609 union iwreq_data wrqu;
3610 char extra[IW_CUSTOM_MAX + 1];
3611 int cmd = 0;
3612 uint32 event_type = ntoh32(e->event_type);
3613 uint16 flags = ntoh16(e->flags);
3614 uint32 datalen = ntoh32(e->datalen);
3615 uint32 status = ntoh32(e->status);
3616 uint32 reason = ntoh32(e->reason);
3617 #ifndef WL_ESCAN
3618 struct wl_wext_info *wext_info = (struct wl_wext_info *)wext_info_void;
3619 iscan_info_t *iscan = &wext_info->iscan;
3620 #endif
3621
3622 memset(&wrqu, 0, sizeof(wrqu));
3623 memset(extra, 0, sizeof(extra));
3624
3625 memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN);
3626 wrqu.addr.sa_family = ARPHRD_ETHER;
3627
3628 switch (event_type) {
3629 case WLC_E_TXFAIL:
3630 cmd = IWEVTXDROP;
3631 break;
3632 #if WIRELESS_EXT > 14
3633 case WLC_E_JOIN:
3634 case WLC_E_ASSOC_IND:
3635 case WLC_E_REASSOC_IND:
3636 cmd = IWEVREGISTERED;
3637 break;
3638 case WLC_E_DEAUTH:
3639 case WLC_E_DISASSOC:
3640 wl_ext_in4way_sync_wext(dev,
3641 STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY|STA_WAIT_DISCONNECTED,
3642 WL_EXT_STATUS_DISCONNECTED, NULL);
3643 WL_MSG_RLMT(dev->name, &e->addr, ETHER_ADDR_LEN,
3644 "disconnected with "MACSTR", event %d, reason %d\n",
3645 MAC2STR((u8 *)wrqu.addr.sa_data), event_type, reason);
3646 break;
3647 case WLC_E_DEAUTH_IND:
3648 case WLC_E_DISASSOC_IND:
3649 cmd = SIOCGIWAP;
3650 WL_MSG(dev->name, "disconnected with "MACSTR", event %d, reason %d\n",
3651 MAC2STR((u8 *)wrqu.addr.sa_data), event_type, reason);
3652 bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
3653 bzero(&extra, ETHER_ADDR_LEN);
3654 wl_ext_in4way_sync_wext(dev,
3655 STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY|STA_WAIT_DISCONNECTED,
3656 WL_EXT_STATUS_DISCONNECTED, NULL);
3657 break;
3658
3659 case WLC_E_LINK:
3660 cmd = SIOCGIWAP;
3661 if (!(flags & WLC_EVENT_MSG_LINK)) {
3662 WL_MSG(dev->name, "Link Down with "MACSTR", reason=%d\n",
3663 MAC2STR((u8 *)wrqu.addr.sa_data), reason);
3664 bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN);
3665 bzero(&extra, ETHER_ADDR_LEN);
3666 wl_ext_in4way_sync_wext(dev,
3667 STA_NO_SCAN_IN4WAY|STA_NO_BTC_IN4WAY|STA_WAIT_DISCONNECTED,
3668 WL_EXT_STATUS_DISCONNECTED, NULL);
3669 } else {
3670 WL_MSG(dev->name, "Link UP with "MACSTR"\n",
3671 MAC2STR((u8 *)wrqu.addr.sa_data));
3672 }
3673 break;
3674 case WLC_E_ACTION_FRAME:
3675 cmd = IWEVCUSTOM;
3676 if (datalen + 1 <= sizeof(extra)) {
3677 wrqu.data.length = datalen + 1;
3678 extra[0] = WLC_E_ACTION_FRAME;
3679 memcpy(&extra[1], data, datalen);
3680 WL_TRACE(("WLC_E_ACTION_FRAME len %d \n", wrqu.data.length));
3681 }
3682 break;
3683
3684 case WLC_E_ACTION_FRAME_COMPLETE:
3685 cmd = IWEVCUSTOM;
3686 if (sizeof(status) + 1 <= sizeof(extra)) {
3687 wrqu.data.length = sizeof(status) + 1;
3688 extra[0] = WLC_E_ACTION_FRAME_COMPLETE;
3689 memcpy(&extra[1], &status, sizeof(status));
3690 WL_TRACE(("wl_iw_event status %d \n", status));
3691 }
3692 break;
3693 #endif /* WIRELESS_EXT > 14 */
3694 #if WIRELESS_EXT > 17
3695 case WLC_E_MIC_ERROR: {
3696 struct iw_michaelmicfailure *micerrevt = (struct iw_michaelmicfailure *)&extra;
3697 cmd = IWEVMICHAELMICFAILURE;
3698 wrqu.data.length = sizeof(struct iw_michaelmicfailure);
3699 if (flags & WLC_EVENT_MSG_GROUP)
3700 micerrevt->flags |= IW_MICFAILURE_GROUP;
3701 else
3702 micerrevt->flags |= IW_MICFAILURE_PAIRWISE;
3703 memcpy(micerrevt->src_addr.sa_data, &e->addr, ETHER_ADDR_LEN);
3704 micerrevt->src_addr.sa_family = ARPHRD_ETHER;
3705
3706 break;
3707 }
3708
3709 case WLC_E_ASSOC_REQ_IE:
3710 cmd = IWEVASSOCREQIE;
3711 wrqu.data.length = datalen;
3712 if (datalen < sizeof(extra))
3713 memcpy(extra, data, datalen);
3714 break;
3715
3716 case WLC_E_ASSOC_RESP_IE:
3717 cmd = IWEVASSOCRESPIE;
3718 wrqu.data.length = datalen;
3719 if (datalen < sizeof(extra))
3720 memcpy(extra, data, datalen);
3721 break;
3722
3723 case WLC_E_PMKID_CACHE: {
3724 struct iw_pmkid_cand *iwpmkidcand = (struct iw_pmkid_cand *)&extra;
3725 pmkid_cand_list_t *pmkcandlist;
3726 pmkid_cand_t *pmkidcand;
3727 int count;
3728
3729 if (data == NULL)
3730 break;
3731
3732 cmd = IWEVPMKIDCAND;
3733 pmkcandlist = data;
3734 count = ntoh32_ua((uint8 *)&pmkcandlist->npmkid_cand);
3735 wrqu.data.length = sizeof(struct iw_pmkid_cand);
3736 pmkidcand = pmkcandlist->pmkid_cand;
3737 while (count) {
3738 bzero(iwpmkidcand, sizeof(struct iw_pmkid_cand));
3739 if (pmkidcand->preauth)
3740 iwpmkidcand->flags |= IW_PMKID_CAND_PREAUTH;
3741 bcopy(&pmkidcand->BSSID, &iwpmkidcand->bssid.sa_data,
3742 ETHER_ADDR_LEN);
3743 wireless_send_event(dev, cmd, &wrqu, extra);
3744 pmkidcand++;
3745 count--;
3746 }
3747 break;
3748 }
3749 #endif /* WIRELESS_EXT > 17 */
3750
3751 #ifndef WL_ESCAN
3752 case WLC_E_SCAN_COMPLETE:
3753 #if WIRELESS_EXT > 14
3754 cmd = SIOCGIWSCAN;
3755 #endif
3756 WL_TRACE(("event WLC_E_SCAN_COMPLETE\n"));
3757 // terence 20150224: fix "wlan0: (WE) : Wireless Event too big (65306)"
3758 memset(&wrqu, 0, sizeof(wrqu));
3759 if ((iscan) && (iscan->sysioc_pid >= 0) &&
3760 (iscan->iscan_state != ISCAN_STATE_IDLE))
3761 up(&iscan->sysioc_sem);
3762 break;
3763 #endif
3764
3765 default:
3766 /* Cannot translate event */
3767 break;
3768 }
3769
3770 if (cmd) {
3771 #ifndef WL_ESCAN
3772 if (cmd == SIOCGIWSCAN) {
3773 if ((!iscan) || (iscan->sysioc_pid < 0)) {
3774 wireless_send_event(dev, cmd, &wrqu, NULL);
3775 }
3776 } else
3777 #endif
3778 wireless_send_event(dev, cmd, &wrqu, extra);
3779 }
3780
3781 #if WIRELESS_EXT > 14
3782 /* Look for WLC events that indicate a connection failure.
3783 * If found, generate an IWEVCUSTOM event.
3784 */
3785 memset(extra, 0, sizeof(extra));
3786 if (wl_iw_check_conn_fail(e, extra, sizeof(extra))) {
3787 cmd = IWEVCUSTOM;
3788 wrqu.data.length = strlen(extra);
3789 wireless_send_event(dev, cmd, &wrqu, extra);
3790 }
3791 #endif /* WIRELESS_EXT > 14 */
3792
3793 #endif /* WIRELESS_EXT > 13 */
3794 return 0;
3795 }
3796
3797 #ifdef WL_NAN
wl_iw_get_wireless_stats_cbfn(void * ctx,uint8 * data,uint16 type,uint16 len)3798 static int wl_iw_get_wireless_stats_cbfn(void *ctx, uint8 *data, uint16 type, uint16 len)
3799 {
3800 struct iw_statistics *wstats = ctx;
3801 int res = BCME_OK;
3802
3803 switch (type) {
3804 case WL_CNT_XTLV_WLC: {
3805 wl_cnt_wlc_t *cnt = (wl_cnt_wlc_t *)data;
3806 if (len > sizeof(wl_cnt_wlc_t)) {
3807 printf("counter structure length invalid! %d > %d\n",
3808 len, (int)sizeof(wl_cnt_wlc_t));
3809 }
3810 wstats->discard.nwid = 0;
3811 wstats->discard.code = dtoh32(cnt->rxundec);
3812 wstats->discard.fragment = dtoh32(cnt->rxfragerr);
3813 wstats->discard.retries = dtoh32(cnt->txfail);
3814 wstats->discard.misc = dtoh32(cnt->rxrunt) + dtoh32(cnt->rxgiant);
3815 wstats->miss.beacon = 0;
3816 WL_TRACE(("wl_iw_get_wireless_stats counters txframe=%d txbyte=%d\n",
3817 dtoh32(cnt->txframe), dtoh32(cnt->txbyte)));
3818 WL_TRACE(("wl_iw_get_wireless_stats counters rxundec=%d\n",
3819 dtoh32(cnt->rxundec)));
3820 WL_TRACE(("wl_iw_get_wireless_stats counters txfail=%d\n",
3821 dtoh32(cnt->txfail)));
3822 WL_TRACE(("wl_iw_get_wireless_stats counters rxfragerr=%d\n",
3823 dtoh32(cnt->rxfragerr)));
3824 WL_TRACE(("wl_iw_get_wireless_stats counters rxrunt=%d\n",
3825 dtoh32(cnt->rxrunt)));
3826 WL_TRACE(("wl_iw_get_wireless_stats counters rxgiant=%d\n",
3827 dtoh32(cnt->rxgiant)));
3828 break;
3829 }
3830 case WL_CNT_XTLV_CNTV_LE10_UCODE:
3831 case WL_CNT_XTLV_LT40_UCODE_V1:
3832 case WL_CNT_XTLV_GE40_UCODE_V1:
3833 {
3834 /* Offsets of rxfrmtoolong and rxbadplcp are the same in
3835 * wl_cnt_v_le10_mcst_t, wl_cnt_lt40mcst_v1_t, and wl_cnt_ge40mcst_v1_t.
3836 * So we can just cast to wl_cnt_v_le10_mcst_t here.
3837 */
3838 wl_cnt_v_le10_mcst_t *cnt = (wl_cnt_v_le10_mcst_t *)data;
3839 if (len != WL_CNT_MCST_STRUCT_SZ) {
3840 printf("counter structure length mismatch! %d != %d\n",
3841 len, WL_CNT_MCST_STRUCT_SZ);
3842 }
3843 WL_TRACE(("wl_iw_get_wireless_stats counters rxfrmtoolong=%d\n",
3844 dtoh32(cnt->rxfrmtoolong)));
3845 WL_TRACE(("wl_iw_get_wireless_stats counters rxbadplcp=%d\n",
3846 dtoh32(cnt->rxbadplcp)));
3847 BCM_REFERENCE(cnt);
3848 break;
3849 }
3850 default:
3851 WL_ERROR(("%d: Unsupported type %d\n", __LINE__, type));
3852 break;
3853 }
3854 return res;
3855 }
3856 #endif
3857
wl_iw_get_wireless_stats(struct net_device * dev,struct iw_statistics * wstats)3858 int wl_iw_get_wireless_stats(struct net_device *dev, struct iw_statistics *wstats)
3859 {
3860 int res = 0;
3861 int phy_noise;
3862 int rssi;
3863 scb_val_t scb_val;
3864 #if WIRELESS_EXT > 11
3865 char *cntbuf = NULL;
3866 wl_cnt_info_t *cntinfo;
3867 uint16 ver;
3868 uint32 corerev = 0;
3869 #endif /* WIRELESS_EXT > 11 */
3870
3871 phy_noise = 0;
3872 if ((res = dev_wlc_ioctl(dev, WLC_GET_PHY_NOISE, &phy_noise, sizeof(phy_noise)))) {
3873 WL_TRACE(("WLC_GET_PHY_NOISE error=%d\n", res));
3874 goto done;
3875 }
3876
3877 phy_noise = dtoh32(phy_noise);
3878 WL_TRACE(("wl_iw_get_wireless_stats phy noise=%d\n *****", phy_noise));
3879
3880 memset(&scb_val, 0, sizeof(scb_val));
3881 if ((res = dev_wlc_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t)))) {
3882 WL_TRACE(("WLC_GET_RSSI error=%d\n", res));
3883 goto done;
3884 }
3885
3886 rssi = dtoh32(scb_val.val);
3887 rssi = MIN(rssi, RSSI_MAXVAL);
3888 WL_TRACE(("wl_iw_get_wireless_stats rssi=%d ****** \n", rssi));
3889 if (rssi <= WL_IW_RSSI_NO_SIGNAL)
3890 wstats->qual.qual = 0;
3891 else if (rssi <= WL_IW_RSSI_VERY_LOW)
3892 wstats->qual.qual = 1;
3893 else if (rssi <= WL_IW_RSSI_LOW)
3894 wstats->qual.qual = 2;
3895 else if (rssi <= WL_IW_RSSI_GOOD)
3896 wstats->qual.qual = 3;
3897 else if (rssi <= WL_IW_RSSI_VERY_GOOD)
3898 wstats->qual.qual = 4;
3899 else
3900 wstats->qual.qual = 5;
3901
3902 /* Wraps to 0 if RSSI is 0 */
3903 wstats->qual.level = 0x100 + rssi;
3904 wstats->qual.noise = 0x100 + phy_noise;
3905 #if WIRELESS_EXT > 18
3906 wstats->qual.updated |= (IW_QUAL_ALL_UPDATED | IW_QUAL_DBM);
3907 #else
3908 wstats->qual.updated |= 7;
3909 #endif /* WIRELESS_EXT > 18 */
3910
3911 #if WIRELESS_EXT > 11
3912 WL_TRACE(("wl_iw_get_wireless_stats counters\n *****"));
3913
3914 cntbuf = kmalloc(MAX_WLIW_IOCTL_LEN, GFP_KERNEL);
3915 if (!cntbuf) {
3916 res = BCME_NOMEM;
3917 goto done;
3918 }
3919
3920 memset(cntbuf, 0, MAX_WLIW_IOCTL_LEN);
3921 res = dev_wlc_bufvar_get(dev, "counters", cntbuf, MAX_WLIW_IOCTL_LEN);
3922 if (res)
3923 {
3924 WL_ERROR(("wl_iw_get_wireless_stats counters failed error=%d ****** \n", res));
3925 goto done;
3926 }
3927
3928 cntinfo = (wl_cnt_info_t *)cntbuf;
3929 cntinfo->version = dtoh16(cntinfo->version);
3930 cntinfo->datalen = dtoh16(cntinfo->datalen);
3931 ver = cntinfo->version;
3932 #ifdef WL_NAN
3933 CHK_CNTBUF_DATALEN(cntbuf, MAX_WLIW_IOCTL_LEN);
3934 #endif
3935 if (ver > WL_CNT_T_VERSION) {
3936 WL_TRACE(("\tIncorrect version of counters struct: expected %d; got %d\n",
3937 WL_CNT_T_VERSION, ver));
3938 res = BCME_VERSION;
3939 goto done;
3940 }
3941
3942 if (ver == WL_CNT_VERSION_11) {
3943 wlc_rev_info_t revinfo;
3944 memset(&revinfo, 0, sizeof(revinfo));
3945 res = dev_wlc_ioctl(dev, WLC_GET_REVINFO, &revinfo, sizeof(revinfo));
3946 if (res) {
3947 WL_ERROR(("WLC_GET_REVINFO failed %d\n", res));
3948 goto done;
3949 }
3950 corerev = dtoh32(revinfo.corerev);
3951 }
3952
3953 #ifdef WL_NAN
3954 res = wl_cntbuf_to_xtlv_format(NULL, cntinfo, MAX_WLIW_IOCTL_LEN, corerev);
3955 if (res) {
3956 WL_ERROR(("wl_cntbuf_to_xtlv_format failed %d\n", res));
3957 goto done;
3958 }
3959
3960 if ((res = bcm_unpack_xtlv_buf(wstats, cntinfo->data, cntinfo->datalen,
3961 BCM_XTLV_OPTION_ALIGN32, wl_iw_get_wireless_stats_cbfn))) {
3962 goto done;
3963 }
3964 #endif
3965 #endif /* WIRELESS_EXT > 11 */
3966
3967 done:
3968 #if WIRELESS_EXT > 11
3969 if (cntbuf) {
3970 kfree(cntbuf);
3971 }
3972 #endif /* WIRELESS_EXT > 11 */
3973 return res;
3974 }
3975
3976 #ifndef WL_ESCAN
3977 static void
wl_iw_timerfunc(ulong data)3978 wl_iw_timerfunc(ulong data)
3979 {
3980 iscan_info_t *iscan = (iscan_info_t *)data;
3981 iscan->timer_on = 0;
3982 if (iscan->iscan_state != ISCAN_STATE_IDLE) {
3983 WL_TRACE(("timer trigger\n"));
3984 up(&iscan->sysioc_sem);
3985 }
3986 }
3987
3988 static void
wl_iw_set_event_mask(struct net_device * dev)3989 wl_iw_set_event_mask(struct net_device *dev)
3990 {
3991 char eventmask[WL_EVENTING_MASK_LEN];
3992 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
3993
3994 dev_iw_iovar_getbuf(dev, "event_msgs", "", 0, iovbuf, sizeof(iovbuf));
3995 bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
3996 setbit(eventmask, WLC_E_SCAN_COMPLETE);
3997 dev_iw_iovar_setbuf(dev, "event_msgs", eventmask, WL_EVENTING_MASK_LEN,
3998 iovbuf, sizeof(iovbuf));
3999
4000 }
4001
4002 static int
wl_iw_iscan_prep(wl_scan_params_t * params,wlc_ssid_t * ssid)4003 wl_iw_iscan_prep(wl_scan_params_t *params, wlc_ssid_t *ssid)
4004 {
4005 int err = 0;
4006
4007 memcpy(¶ms->bssid, ðer_bcast, ETHER_ADDR_LEN);
4008 params->bss_type = DOT11_BSSTYPE_ANY;
4009 params->scan_type = 0;
4010 params->nprobes = -1;
4011 params->active_time = -1;
4012 params->passive_time = -1;
4013 params->home_time = -1;
4014 params->channel_num = 0;
4015
4016 params->nprobes = htod32(params->nprobes);
4017 params->active_time = htod32(params->active_time);
4018 params->passive_time = htod32(params->passive_time);
4019 params->home_time = htod32(params->home_time);
4020 if (ssid && ssid->SSID_len)
4021 memcpy(¶ms->ssid, ssid, sizeof(wlc_ssid_t));
4022
4023 return err;
4024 }
4025
4026 static int
wl_iw_iscan(iscan_info_t * iscan,wlc_ssid_t * ssid,uint16 action)4027 wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, uint16 action)
4028 {
4029 int params_size = (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_iscan_params_t, params));
4030 wl_iscan_params_t *params;
4031 int err = 0;
4032
4033 if (ssid && ssid->SSID_len) {
4034 params_size += sizeof(wlc_ssid_t);
4035 }
4036 params = (wl_iscan_params_t*)kmalloc(params_size, GFP_KERNEL);
4037 if (params == NULL) {
4038 return -ENOMEM;
4039 }
4040 memset(params, 0, params_size);
4041 ASSERT(params_size < WLC_IOCTL_SMLEN);
4042
4043 err = wl_iw_iscan_prep(¶ms->params, ssid);
4044
4045 if (!err) {
4046 params->version = htod32(ISCAN_REQ_VERSION);
4047 params->action = htod16(action);
4048 params->scan_duration = htod16(0);
4049
4050 /* params_size += OFFSETOF(wl_iscan_params_t, params); */
4051 (void) dev_iw_iovar_setbuf(iscan->dev, "iscan", params, params_size,
4052 iscan->ioctlbuf, WLC_IOCTL_SMLEN);
4053 }
4054
4055 kfree(params);
4056 return err;
4057 }
4058
4059 static uint32
wl_iw_iscan_get(iscan_info_t * iscan)4060 wl_iw_iscan_get(iscan_info_t *iscan)
4061 {
4062 iscan_buf_t * buf;
4063 iscan_buf_t * ptr;
4064 wl_iscan_results_t * list_buf;
4065 wl_iscan_results_t list;
4066 wl_scan_results_t *results;
4067 uint32 status;
4068
4069 /* buffers are allocated on demand */
4070 if (iscan->list_cur) {
4071 buf = iscan->list_cur;
4072 iscan->list_cur = buf->next;
4073 }
4074 else {
4075 buf = kmalloc(sizeof(iscan_buf_t), GFP_KERNEL);
4076 if (!buf)
4077 return WL_SCAN_RESULTS_ABORTED;
4078 buf->next = NULL;
4079 if (!iscan->list_hdr)
4080 iscan->list_hdr = buf;
4081 else {
4082 ptr = iscan->list_hdr;
4083 while (ptr->next) {
4084 ptr = ptr->next;
4085 }
4086 ptr->next = buf;
4087 }
4088 }
4089 memset(buf->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
4090 list_buf = (wl_iscan_results_t*)buf->iscan_buf;
4091 results = &list_buf->results;
4092 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
4093 results->version = 0;
4094 results->count = 0;
4095
4096 memset(&list, 0, sizeof(list));
4097 list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN);
4098 (void) dev_iw_iovar_getbuf(
4099 iscan->dev,
4100 "iscanresults",
4101 &list,
4102 WL_ISCAN_RESULTS_FIXED_SIZE,
4103 buf->iscan_buf,
4104 WLC_IW_ISCAN_MAXLEN);
4105 results->buflen = dtoh32(results->buflen);
4106 results->version = dtoh32(results->version);
4107 results->count = dtoh32(results->count);
4108 WL_TRACE(("results->count = %d\n", results->count));
4109
4110 WL_TRACE(("results->buflen = %d\n", results->buflen));
4111 status = dtoh32(list_buf->status);
4112 return status;
4113 }
4114
wl_iw_send_scan_complete(iscan_info_t * iscan)4115 static void wl_iw_send_scan_complete(iscan_info_t *iscan)
4116 {
4117 union iwreq_data wrqu;
4118
4119 memset(&wrqu, 0, sizeof(wrqu));
4120
4121 /* wext expects to get no data for SIOCGIWSCAN Event */
4122 wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL);
4123 }
4124
4125 static int
_iscan_sysioc_thread(void * data)4126 _iscan_sysioc_thread(void *data)
4127 {
4128 uint32 status;
4129 iscan_info_t *iscan = (iscan_info_t *)data;
4130
4131 WL_MSG("wlan", "thread Enter\n");
4132 DAEMONIZE("iscan_sysioc");
4133
4134 status = WL_SCAN_RESULTS_PARTIAL;
4135 while (down_interruptible(&iscan->sysioc_sem) == 0) {
4136 if (iscan->timer_on) {
4137 del_timer(&iscan->timer);
4138 iscan->timer_on = 0;
4139 }
4140
4141 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4142 rtnl_lock();
4143 #endif
4144 status = wl_iw_iscan_get(iscan);
4145 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4146 rtnl_unlock();
4147 #endif
4148
4149 switch (status) {
4150 case WL_SCAN_RESULTS_PARTIAL:
4151 WL_TRACE(("iscanresults incomplete\n"));
4152 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4153 rtnl_lock();
4154 #endif
4155 /* make sure our buffer size is enough before going next round */
4156 wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE);
4157 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27))
4158 rtnl_unlock();
4159 #endif
4160 /* Reschedule the timer */
4161 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
4162 add_timer(&iscan->timer);
4163 iscan->timer_on = 1;
4164 break;
4165 case WL_SCAN_RESULTS_SUCCESS:
4166 WL_TRACE(("iscanresults complete\n"));
4167 iscan->iscan_state = ISCAN_STATE_IDLE;
4168 wl_iw_send_scan_complete(iscan);
4169 break;
4170 case WL_SCAN_RESULTS_PENDING:
4171 WL_TRACE(("iscanresults pending\n"));
4172 /* Reschedule the timer */
4173 iscan->timer.expires = jiffies + msecs_to_jiffies(iscan->timer_ms);
4174 add_timer(&iscan->timer);
4175 iscan->timer_on = 1;
4176 break;
4177 case WL_SCAN_RESULTS_ABORTED:
4178 WL_TRACE(("iscanresults aborted\n"));
4179 iscan->iscan_state = ISCAN_STATE_IDLE;
4180 wl_iw_send_scan_complete(iscan);
4181 break;
4182 default:
4183 WL_TRACE(("iscanresults returned unknown status %d\n", status));
4184 break;
4185 }
4186 }
4187 WL_MSG("wlan", "was terminated\n");
4188 complete_and_exit(&iscan->sysioc_exited, 0);
4189 }
4190 #endif /* !WL_ESCAN */
4191
4192 void
wl_iw_detach(struct net_device * dev,dhd_pub_t * dhdp)4193 wl_iw_detach(struct net_device *dev, dhd_pub_t *dhdp)
4194 {
4195 wl_wext_info_t *wext_info = dhdp->wext_info;
4196 #ifndef WL_ESCAN
4197 iscan_buf_t *buf;
4198 iscan_info_t *iscan;
4199 #endif
4200 if (!wext_info)
4201 return;
4202
4203 #ifndef WL_ESCAN
4204 iscan = &wext_info->iscan;
4205 if (iscan->sysioc_pid >= 0) {
4206 KILL_PROC(iscan->sysioc_pid, SIGTERM);
4207 wait_for_completion(&iscan->sysioc_exited);
4208 }
4209
4210 while (iscan->list_hdr) {
4211 buf = iscan->list_hdr->next;
4212 kfree(iscan->list_hdr);
4213 iscan->list_hdr = buf;
4214 }
4215 #endif
4216 wl_ext_event_deregister(dev, dhdp, WLC_E_LAST, wl_iw_event);
4217 if (wext_info) {
4218 kfree(wext_info);
4219 dhdp->wext_info = NULL;
4220 }
4221 }
4222
4223 int
wl_iw_attach(struct net_device * dev,dhd_pub_t * dhdp)4224 wl_iw_attach(struct net_device *dev, dhd_pub_t *dhdp)
4225 {
4226 wl_wext_info_t *wext_info = NULL;
4227 int ret = 0;
4228 #ifndef WL_ESCAN
4229 iscan_info_t *iscan = NULL;
4230 #endif
4231
4232 if (!dev)
4233 return 0;
4234 WL_TRACE(("Enter\n"));
4235
4236 wext_info = (void *)kzalloc(sizeof(struct wl_wext_info), GFP_KERNEL);
4237 if (!wext_info)
4238 return -ENOMEM;
4239 memset(wext_info, 0, sizeof(wl_wext_info_t));
4240 wext_info->dev = dev;
4241 wext_info->dhd = dhdp;
4242 wext_info->conn_info.bssidx = 0;
4243 dhdp->wext_info = (void *)wext_info;
4244
4245 #ifndef WL_ESCAN
4246 iscan = &wext_info->iscan;
4247 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
4248 iscan->kthread = NULL;
4249 #endif
4250 iscan->sysioc_pid = -1;
4251 /* we only care about main interface so save a global here */
4252 iscan->dev = dev;
4253 iscan->iscan_state = ISCAN_STATE_IDLE;
4254
4255 /* Set up the timer */
4256 iscan->timer_ms = 2000;
4257 init_timer_compat(&iscan->timer, wl_iw_timerfunc, iscan);
4258
4259 sema_init(&iscan->sysioc_sem, 0);
4260 init_completion(&iscan->sysioc_exited);
4261 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0))
4262 iscan->kthread = kthread_run(_iscan_sysioc_thread, iscan, "iscan_sysioc");
4263 iscan->sysioc_pid = iscan->kthread->pid;
4264 #else
4265 iscan->sysioc_pid = kernel_thread(_iscan_sysioc_thread, iscan, 0);
4266 #endif
4267 if (iscan->sysioc_pid < 0) {
4268 ret = -ENOMEM;
4269 goto exit;
4270 }
4271 #endif
4272 ret = wl_ext_event_register(dev, dhdp, WLC_E_LAST, wl_iw_event, dhdp->wext_info,
4273 PRIO_EVENT_WEXT);
4274 if (ret) {
4275 WL_ERROR(("wl_ext_event_register err %d\n", ret));
4276 goto exit;
4277 }
4278
4279 return ret;
4280 exit:
4281 wl_iw_detach(dev, dhdp);
4282 return ret;
4283 }
4284
4285 void
wl_iw_down(struct net_device * dev,dhd_pub_t * dhdp)4286 wl_iw_down(struct net_device *dev, dhd_pub_t *dhdp)
4287 {
4288 wl_wext_info_t *wext_info = NULL;
4289
4290 if (dhdp) {
4291 wext_info = dhdp->wext_info;
4292 } else {
4293 WL_ERROR (("dhd is NULL\n"));
4294 return;
4295 }
4296 }
4297
4298 int
wl_iw_up(struct net_device * dev,dhd_pub_t * dhdp)4299 wl_iw_up(struct net_device *dev, dhd_pub_t *dhdp)
4300 {
4301 wl_wext_info_t *wext_info = NULL;
4302 int ret = 0;
4303
4304 if (dhdp) {
4305 wext_info = dhdp->wext_info;
4306 } else {
4307 WL_ERROR (("dhd is NULL\n"));
4308 return -ENODEV;
4309 }
4310
4311 return ret;
4312 }
4313
4314 s32
wl_iw_autochannel(struct net_device * dev,char * command,int total_len)4315 wl_iw_autochannel(struct net_device *dev, char* command, int total_len)
4316 {
4317 struct dhd_pub *dhd = dhd_get_pub(dev);
4318 wl_wext_info_t *wext_info = NULL;
4319 int ret = 0;
4320 #ifdef WL_ESCAN
4321 int bytes_written = -1;
4322 #endif
4323
4324 DHD_CHECK(dhd, dev);
4325 wext_info = dhd->wext_info;
4326 #ifdef WL_ESCAN
4327 sscanf(command, "%*s %d", &dhd->escan->autochannel);
4328 if (dhd->escan->autochannel == 0) {
4329 dhd->escan->best_2g_ch = 0;
4330 dhd->escan->best_5g_ch = 0;
4331 } else if (dhd->escan->autochannel == 2) {
4332 bytes_written = snprintf(command, total_len, "2g=%d 5g=%d",
4333 dhd->escan->best_2g_ch, dhd->escan->best_5g_ch);
4334 WL_TRACE(("command result is %s\n", command));
4335 ret = bytes_written;
4336 }
4337 #endif
4338
4339 return ret;
4340 }
4341
4342 #endif /* USE_IW */
4343