]>
Commit | Line | Data |
---|---|---|
cf2b4488 HP |
1 | /* |
2 | * Copyright (c) 2010 Broadcom Corporation | |
3 | * | |
4 | * Permission to use, copy, modify, and/or distribute this software for any | |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
7 | * | |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
11 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | |
13 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | |
14 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
15 | */ | |
16 | ||
17 | #include <wlioctl.h> | |
18 | ||
19 | #include <typedefs.h> | |
20 | #include <linuxver.h> | |
21 | #include <osl.h> | |
22 | ||
23 | #include <bcmutils.h> | |
24 | #include <bcmendian.h> | |
25 | #include <proto/ethernet.h> | |
26 | ||
27 | #include <linux/if_arp.h> | |
28 | #include <asm/uaccess.h> | |
29 | ||
30 | #include <dngl_stats.h> | |
31 | #include <dhd.h> | |
32 | #include <dhdioctl.h> | |
33 | ||
34 | typedef void wlc_info_t; | |
35 | typedef void wl_info_t; | |
36 | typedef const struct si_pub si_t; | |
37 | #include <wlioctl.h> | |
38 | ||
39 | #include <proto/ethernet.h> | |
40 | #include <dngl_stats.h> | |
41 | #include <dhd.h> | |
42 | #define WL_ERROR(x) printf x | |
43 | #define WL_TRACE(x) | |
44 | #define WL_ASSOC(x) | |
45 | #define WL_INFORM(x) | |
46 | #define WL_WSEC(x) | |
47 | #define WL_SCAN(x) | |
48 | ||
49 | #include <wl_iw.h> | |
50 | ||
51 | #define IW_WSEC_ENABLED(wsec) ((wsec) & (WEP_ENABLED | \ | |
52 | TKIP_ENABLED | AES_ENABLED)) | |
53 | ||
54 | #include <linux/rtnetlink.h> | |
55 | ||
56 | #define WL_IW_USE_ISCAN 1 | |
57 | #define ENABLE_ACTIVE_PASSIVE_SCAN_SUPPRESS 1 | |
58 | ||
59 | bool g_set_essid_before_scan = TRUE; | |
60 | ||
61 | #define WL_IW_IOCTL_CALL(func_call) \ | |
62 | do { \ | |
63 | func_call; \ | |
64 | } while (0) | |
65 | ||
66 | static int g_onoff = G_WLAN_SET_ON; | |
67 | wl_iw_extra_params_t g_wl_iw_params; | |
68 | ||
69 | extern bool wl_iw_conn_status_str(uint32 event_type, uint32 status, | |
70 | uint32 reason, char *stringBuf, uint buflen); | |
71 | ||
72 | uint wl_msg_level = WL_ERROR_VAL; | |
73 | ||
74 | #define MAX_WLIW_IOCTL_LEN 1024 | |
75 | ||
76 | #if defined(IL_BIGENDIAN) | |
77 | #include <bcmendian.h> | |
78 | #define htod32(i) (bcmswap32(i)) | |
79 | #define htod16(i) (bcmswap16(i)) | |
80 | #define dtoh32(i) (bcmswap32(i)) | |
81 | #define dtoh16(i) (bcmswap16(i)) | |
82 | #define htodchanspec(i) htod16(i) | |
83 | #define dtohchanspec(i) dtoh16(i) | |
84 | #else | |
85 | #define htod32(i) i | |
86 | #define htod16(i) i | |
87 | #define dtoh32(i) i | |
88 | #define dtoh16(i) i | |
89 | #define htodchanspec(i) i | |
90 | #define dtohchanspec(i) i | |
91 | #endif | |
92 | ||
93 | #ifdef CONFIG_WIRELESS_EXT | |
94 | ||
95 | extern struct iw_statistics *dhd_get_wireless_stats(struct net_device *dev); | |
96 | extern int dhd_wait_pend8021x(struct net_device *dev); | |
97 | #endif | |
98 | ||
99 | #if WIRELESS_EXT < 19 | |
100 | #define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST) | |
101 | #define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST) | |
102 | #endif | |
103 | ||
5f782dee | 104 | static void *g_scan; |
cf2b4488 HP |
105 | static volatile uint g_scan_specified_ssid; |
106 | static wlc_ssid_t g_specific_ssid; | |
107 | ||
108 | static wlc_ssid_t g_ssid; | |
109 | ||
5a505da9 JC |
110 | #define DAEMONIZE(a) \ |
111 | do { \ | |
112 | daemonize(a); \ | |
113 | allow_signal(SIGKILL); \ | |
114 | allow_signal(SIGTERM); \ | |
960ea740 | 115 | } while (0) |
cf2b4488 HP |
116 | |
117 | #if defined(WL_IW_USE_ISCAN) | |
118 | #define ISCAN_STATE_IDLE 0 | |
119 | #define ISCAN_STATE_SCANING 1 | |
120 | ||
121 | #define WLC_IW_ISCAN_MAXLEN 2048 | |
122 | typedef struct iscan_buf { | |
123 | struct iscan_buf *next; | |
124 | char iscan_buf[WLC_IW_ISCAN_MAXLEN]; | |
125 | } iscan_buf_t; | |
126 | ||
127 | typedef struct iscan_info { | |
128 | struct net_device *dev; | |
129 | struct timer_list timer; | |
130 | uint32 timer_ms; | |
131 | uint32 timer_on; | |
132 | int iscan_state; | |
133 | iscan_buf_t *list_hdr; | |
134 | iscan_buf_t *list_cur; | |
135 | ||
136 | long sysioc_pid; | |
137 | struct semaphore sysioc_sem; | |
138 | struct completion sysioc_exited; | |
139 | ||
140 | #if defined CSCAN | |
141 | char ioctlbuf[WLC_IOCTL_MEDLEN]; | |
142 | #else | |
143 | char ioctlbuf[WLC_IOCTL_SMLEN]; | |
144 | #endif | |
145 | wl_iscan_params_t *iscan_ex_params_p; | |
146 | int iscan_ex_param_size; | |
147 | } iscan_info_t; | |
6998d337 | 148 | iscan_info_t *g_iscan; |
3deea904 | 149 | static void wl_iw_timerfunc(unsigned long data); |
cf2b4488 | 150 | static void wl_iw_set_event_mask(struct net_device *dev); |
7d4df48e | 151 | static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, u16 action); |
cf2b4488 HP |
152 | #endif /* defined(WL_IW_USE_ISCAN) */ |
153 | ||
154 | static int | |
155 | wl_iw_set_scan(struct net_device *dev, | |
156 | struct iw_request_info *info, | |
157 | union iwreq_data *wrqu, char *extra); | |
158 | ||
159 | static int | |
160 | wl_iw_get_scan(struct net_device *dev, | |
161 | struct iw_request_info *info, | |
162 | struct iw_point *dwrq, char *extra); | |
163 | ||
164 | static uint | |
165 | wl_iw_get_scan_prep(wl_scan_results_t *list, | |
166 | struct iw_request_info *info, char *extra, short max_size); | |
167 | ||
168 | static void swap_key_from_BE(wl_wsec_key_t *key) | |
169 | { | |
170 | key->index = htod32(key->index); | |
171 | key->len = htod32(key->len); | |
172 | key->algo = htod32(key->algo); | |
173 | key->flags = htod32(key->flags); | |
174 | key->rxiv.hi = htod32(key->rxiv.hi); | |
175 | key->rxiv.lo = htod16(key->rxiv.lo); | |
176 | key->iv_initialized = htod32(key->iv_initialized); | |
177 | } | |
178 | ||
179 | static void swap_key_to_BE(wl_wsec_key_t *key) | |
180 | { | |
181 | key->index = dtoh32(key->index); | |
182 | key->len = dtoh32(key->len); | |
183 | key->algo = dtoh32(key->algo); | |
184 | key->flags = dtoh32(key->flags); | |
185 | key->rxiv.hi = dtoh32(key->rxiv.hi); | |
186 | key->rxiv.lo = dtoh16(key->rxiv.lo); | |
187 | key->iv_initialized = dtoh32(key->iv_initialized); | |
188 | } | |
189 | ||
190 | static int dev_wlc_ioctl(struct net_device *dev, int cmd, void *arg, int len) | |
191 | { | |
192 | struct ifreq ifr; | |
193 | wl_ioctl_t ioc; | |
194 | mm_segment_t fs; | |
195 | int ret = -EINVAL; | |
196 | ||
197 | if (!dev) { | |
198 | WL_ERROR(("%s: dev is null\n", __func__)); | |
199 | return ret; | |
200 | } | |
201 | ||
202 | WL_INFORM(("\n%s, PID:%x: send Local IOCTL -> dhd: cmd:0x%x, buf:%p, " | |
203 | "len:%d ,\n", __func__, current->pid, cmd, arg, len)); | |
204 | ||
205 | if (g_onoff == G_WLAN_SET_ON) { | |
206 | memset(&ioc, 0, sizeof(ioc)); | |
207 | ioc.cmd = cmd; | |
208 | ioc.buf = arg; | |
209 | ioc.len = len; | |
210 | ||
211 | strcpy(ifr.ifr_name, dev->name); | |
212 | ifr.ifr_data = (caddr_t)&ioc; | |
213 | ||
214 | ret = dev_open(dev); | |
215 | if (ret) { | |
216 | WL_ERROR(("%s: Error dev_open: %d\n", __func__, ret)); | |
217 | return ret; | |
218 | } | |
219 | ||
220 | fs = get_fs(); | |
221 | set_fs(get_ds()); | |
222 | ret = dev->netdev_ops->ndo_do_ioctl(dev, &ifr, SIOCDEVPRIVATE); | |
223 | set_fs(fs); | |
224 | } else { | |
225 | WL_TRACE(("%s: call after driver stop : ignored\n", __func__)); | |
226 | } | |
227 | return ret; | |
228 | } | |
229 | ||
230 | static int dev_wlc_intvar_set(struct net_device *dev, char *name, int val) | |
231 | { | |
232 | char buf[WLC_IOCTL_SMLEN]; | |
233 | uint len; | |
234 | ||
235 | val = htod32(val); | |
236 | len = bcm_mkiovar(name, (char *)(&val), sizeof(val), buf, sizeof(buf)); | |
237 | ASSERT(len); | |
238 | ||
239 | return dev_wlc_ioctl(dev, WLC_SET_VAR, buf, len); | |
240 | } | |
241 | ||
242 | #if defined(WL_IW_USE_ISCAN) | |
243 | static int | |
244 | dev_iw_iovar_setbuf(struct net_device *dev, | |
245 | char *iovar, | |
246 | void *param, int paramlen, void *bufptr, int buflen) | |
247 | { | |
248 | int iolen; | |
249 | ||
250 | iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen); | |
251 | ASSERT(iolen); | |
252 | ||
253 | if (iolen == 0) | |
254 | return 0; | |
255 | ||
256 | return dev_wlc_ioctl(dev, WLC_SET_VAR, bufptr, iolen); | |
257 | } | |
258 | ||
259 | static int | |
260 | dev_iw_iovar_getbuf(struct net_device *dev, | |
261 | char *iovar, | |
262 | void *param, int paramlen, void *bufptr, int buflen) | |
263 | { | |
264 | int iolen; | |
265 | ||
266 | iolen = bcm_mkiovar(iovar, param, paramlen, bufptr, buflen); | |
267 | ASSERT(iolen); | |
268 | ||
269 | return dev_wlc_ioctl(dev, WLC_GET_VAR, bufptr, buflen); | |
270 | } | |
271 | #endif /* defined(WL_IW_USE_ISCAN) */ | |
272 | ||
273 | #if WIRELESS_EXT > 17 | |
274 | static int | |
275 | dev_wlc_bufvar_set(struct net_device *dev, char *name, char *buf, int len) | |
276 | { | |
277 | static char ioctlbuf[MAX_WLIW_IOCTL_LEN]; | |
278 | uint buflen; | |
279 | ||
280 | buflen = bcm_mkiovar(name, buf, len, ioctlbuf, sizeof(ioctlbuf)); | |
281 | ASSERT(buflen); | |
282 | ||
283 | return dev_wlc_ioctl(dev, WLC_SET_VAR, ioctlbuf, buflen); | |
284 | } | |
285 | #endif /* WIRELESS_EXT > 17 */ | |
286 | ||
287 | static int | |
288 | dev_wlc_bufvar_get(struct net_device *dev, char *name, char *buf, int buflen) | |
289 | { | |
290 | static char ioctlbuf[MAX_WLIW_IOCTL_LEN]; | |
291 | int error; | |
292 | uint len; | |
293 | ||
294 | len = bcm_mkiovar(name, NULL, 0, ioctlbuf, sizeof(ioctlbuf)); | |
295 | ASSERT(len); | |
296 | error = | |
297 | dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)ioctlbuf, | |
298 | MAX_WLIW_IOCTL_LEN); | |
299 | if (!error) | |
300 | bcopy(ioctlbuf, buf, buflen); | |
301 | ||
302 | return error; | |
303 | } | |
304 | ||
305 | static int dev_wlc_intvar_get(struct net_device *dev, char *name, int *retval) | |
306 | { | |
307 | union { | |
308 | char buf[WLC_IOCTL_SMLEN]; | |
309 | int val; | |
310 | } var; | |
311 | int error; | |
312 | ||
313 | uint len; | |
314 | uint data_null; | |
315 | ||
316 | len = | |
317 | bcm_mkiovar(name, (char *)(&data_null), 0, (char *)(&var), | |
318 | sizeof(var.buf)); | |
319 | ASSERT(len); | |
320 | error = dev_wlc_ioctl(dev, WLC_GET_VAR, (void *)&var, len); | |
321 | ||
322 | *retval = dtoh32(var.val); | |
323 | ||
324 | return error; | |
325 | } | |
326 | ||
327 | #if WIRELESS_EXT < 13 | |
328 | struct iw_request_info { | |
329 | __u16 cmd; | |
330 | __u16 flags; | |
331 | }; | |
332 | ||
333 | typedef int (*iw_handler) (struct net_device *dev, | |
334 | struct iw_request_info *info, | |
335 | void *wrqu, char *extra); | |
336 | #endif | |
337 | ||
338 | static int | |
339 | wl_iw_config_commit(struct net_device *dev, | |
340 | struct iw_request_info *info, void *zwrq, char *extra) | |
341 | { | |
342 | wlc_ssid_t ssid; | |
343 | int error; | |
344 | struct sockaddr bssid; | |
345 | ||
346 | WL_TRACE(("%s: SIOCSIWCOMMIT\n", dev->name)); | |
347 | ||
59334c2f JC |
348 | error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid)); |
349 | if (error) | |
cf2b4488 HP |
350 | return error; |
351 | ||
352 | ssid.SSID_len = dtoh32(ssid.SSID_len); | |
353 | ||
354 | if (!ssid.SSID_len) | |
355 | return 0; | |
356 | ||
357 | bzero(&bssid, sizeof(struct sockaddr)); | |
59334c2f JC |
358 | error = dev_wlc_ioctl(dev, WLC_REASSOC, &bssid, ETHER_ADDR_LEN); |
359 | if (error) { | |
cf2b4488 HP |
360 | WL_ERROR(("%s: WLC_REASSOC to %s failed \n", __func__, |
361 | ssid.SSID)); | |
362 | return error; | |
363 | } | |
364 | ||
365 | return 0; | |
366 | } | |
367 | ||
368 | static int | |
369 | wl_iw_get_name(struct net_device *dev, | |
370 | struct iw_request_info *info, char *cwrq, char *extra) | |
371 | { | |
372 | WL_TRACE(("%s: SIOCGIWNAME\n", dev->name)); | |
373 | ||
374 | strcpy(cwrq, "IEEE 802.11-DS"); | |
375 | ||
376 | return 0; | |
377 | } | |
378 | ||
379 | static int | |
380 | wl_iw_set_freq(struct net_device *dev, | |
381 | struct iw_request_info *info, struct iw_freq *fwrq, char *extra) | |
382 | { | |
383 | int error, chan; | |
384 | uint sf = 0; | |
385 | ||
386 | WL_TRACE(("\n %s %s: SIOCSIWFREQ\n", __func__, dev->name)); | |
387 | ||
388 | if (fwrq->e == 0 && fwrq->m < MAXCHANNEL) { | |
389 | chan = fwrq->m; | |
390 | } else { | |
391 | if (fwrq->e >= 6) { | |
392 | fwrq->e -= 6; | |
393 | while (fwrq->e--) | |
394 | fwrq->m *= 10; | |
395 | } else if (fwrq->e < 6) { | |
396 | while (fwrq->e++ < 6) | |
397 | fwrq->m /= 10; | |
398 | } | |
399 | if (fwrq->m > 4000 && fwrq->m < 5000) | |
400 | sf = WF_CHAN_FACTOR_4_G; | |
401 | ||
402 | chan = wf_mhz2channel(fwrq->m, sf); | |
403 | } | |
404 | chan = htod32(chan); | |
405 | ||
59334c2f JC |
406 | error = dev_wlc_ioctl(dev, WLC_SET_CHANNEL, &chan, sizeof(chan)); |
407 | if (error) | |
cf2b4488 HP |
408 | return error; |
409 | ||
410 | g_wl_iw_params.target_channel = chan; | |
411 | return -EINPROGRESS; | |
412 | } | |
413 | ||
414 | static int | |
415 | wl_iw_get_freq(struct net_device *dev, | |
416 | struct iw_request_info *info, struct iw_freq *fwrq, char *extra) | |
417 | { | |
418 | channel_info_t ci; | |
419 | int error; | |
420 | ||
421 | WL_TRACE(("%s: SIOCGIWFREQ\n", dev->name)); | |
422 | ||
59334c2f JC |
423 | error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci)); |
424 | if (error) | |
cf2b4488 HP |
425 | return error; |
426 | ||
427 | fwrq->m = dtoh32(ci.hw_channel); | |
428 | fwrq->e = dtoh32(0); | |
429 | return 0; | |
430 | } | |
431 | ||
432 | static int | |
433 | wl_iw_set_mode(struct net_device *dev, | |
434 | struct iw_request_info *info, __u32 *uwrq, char *extra) | |
435 | { | |
436 | int infra = 0, ap = 0, error = 0; | |
437 | ||
438 | WL_TRACE(("%s: SIOCSIWMODE\n", dev->name)); | |
439 | ||
440 | switch (*uwrq) { | |
441 | case IW_MODE_MASTER: | |
442 | infra = ap = 1; | |
443 | break; | |
444 | case IW_MODE_ADHOC: | |
445 | case IW_MODE_AUTO: | |
446 | break; | |
447 | case IW_MODE_INFRA: | |
448 | infra = 1; | |
449 | break; | |
450 | default: | |
451 | return -EINVAL; | |
452 | } | |
453 | infra = htod32(infra); | |
454 | ap = htod32(ap); | |
455 | ||
59334c2f JC |
456 | error = dev_wlc_ioctl(dev, WLC_SET_INFRA, &infra, sizeof(infra)); |
457 | if (error) | |
458 | return error; | |
459 | ||
460 | error = dev_wlc_ioctl(dev, WLC_SET_AP, &ap, sizeof(ap)); | |
461 | if (error) | |
cf2b4488 HP |
462 | return error; |
463 | ||
464 | return -EINPROGRESS; | |
465 | } | |
466 | ||
467 | static int | |
468 | wl_iw_get_mode(struct net_device *dev, | |
469 | struct iw_request_info *info, __u32 *uwrq, char *extra) | |
470 | { | |
471 | int error, infra = 0, ap = 0; | |
472 | ||
473 | WL_TRACE(("%s: SIOCGIWMODE\n", dev->name)); | |
474 | ||
59334c2f JC |
475 | error = dev_wlc_ioctl(dev, WLC_GET_INFRA, &infra, sizeof(infra)); |
476 | if (error) | |
477 | return error; | |
478 | ||
479 | error = dev_wlc_ioctl(dev, WLC_GET_AP, &ap, sizeof(ap)); | |
480 | if (error) | |
cf2b4488 HP |
481 | return error; |
482 | ||
483 | infra = dtoh32(infra); | |
484 | ap = dtoh32(ap); | |
485 | *uwrq = infra ? ap ? IW_MODE_MASTER : IW_MODE_INFRA : IW_MODE_ADHOC; | |
486 | ||
487 | return 0; | |
488 | } | |
489 | ||
490 | static int | |
491 | wl_iw_get_range(struct net_device *dev, | |
492 | struct iw_request_info *info, | |
493 | struct iw_point *dwrq, char *extra) | |
494 | { | |
495 | struct iw_range *range = (struct iw_range *)extra; | |
496 | wl_uint32_list_t *list; | |
497 | wl_rateset_t rateset; | |
562c8850 | 498 | s8 *channels; |
cf2b4488 HP |
499 | int error, i, k; |
500 | uint sf, ch; | |
501 | ||
502 | int phytype; | |
503 | int bw_cap = 0, sgi_tx = 0, nmode = 0; | |
504 | channel_info_t ci; | |
3fd79f7c | 505 | u8 nrate_list2copy = 0; |
7d4df48e | 506 | u16 nrate_list[4][8] = { {13, 26, 39, 52, 78, 104, 117, 130}, |
cf2b4488 HP |
507 | {14, 29, 43, 58, 87, 116, 130, 144}, |
508 | {27, 54, 81, 108, 162, 216, 243, 270}, | |
509 | {30, 60, 90, 120, 180, 240, 270, 300} | |
510 | }; | |
511 | ||
512 | WL_TRACE(("%s: SIOCGIWRANGE\n", dev->name)); | |
513 | ||
514 | if (!extra) | |
515 | return -EINVAL; | |
516 | ||
517 | channels = kmalloc((MAXCHANNEL + 1) * 4, GFP_KERNEL); | |
518 | if (!channels) { | |
519 | WL_ERROR(("Could not alloc channels\n")); | |
520 | return -ENOMEM; | |
521 | } | |
522 | list = (wl_uint32_list_t *) channels; | |
523 | ||
524 | dwrq->length = sizeof(struct iw_range); | |
525 | memset(range, 0, sizeof(range)); | |
526 | ||
527 | range->min_nwid = range->max_nwid = 0; | |
528 | ||
529 | list->count = htod32(MAXCHANNEL); | |
59334c2f JC |
530 | error = dev_wlc_ioctl(dev, WLC_GET_VALID_CHANNELS, channels, |
531 | (MAXCHANNEL + 1) * 4); | |
532 | if (error) { | |
cf2b4488 HP |
533 | kfree(channels); |
534 | return error; | |
535 | } | |
536 | for (i = 0; i < dtoh32(list->count) && i < IW_MAX_FREQUENCIES; i++) { | |
537 | range->freq[i].i = dtoh32(list->element[i]); | |
538 | ||
539 | ch = dtoh32(list->element[i]); | |
540 | if (ch <= CH_MAX_2G_CHANNEL) | |
541 | sf = WF_CHAN_FACTOR_2_4_G; | |
542 | else | |
543 | sf = WF_CHAN_FACTOR_5_G; | |
544 | ||
545 | range->freq[i].m = wf_channel2mhz(ch, sf); | |
546 | range->freq[i].e = 6; | |
547 | } | |
548 | range->num_frequency = range->num_channels = i; | |
549 | ||
550 | range->max_qual.qual = 5; | |
551 | range->max_qual.level = 0x100 - 200; | |
552 | range->max_qual.noise = 0x100 - 200; | |
553 | range->sensitivity = 65535; | |
554 | ||
555 | #if WIRELESS_EXT > 11 | |
556 | range->avg_qual.qual = 3; | |
557 | range->avg_qual.level = 0x100 + WL_IW_RSSI_GOOD; | |
558 | range->avg_qual.noise = 0x100 - 75; | |
559 | #endif | |
560 | ||
59334c2f JC |
561 | error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, |
562 | sizeof(rateset)); | |
563 | if (error) { | |
cf2b4488 HP |
564 | kfree(channels); |
565 | return error; | |
566 | } | |
567 | rateset.count = dtoh32(rateset.count); | |
568 | range->num_bitrates = rateset.count; | |
569 | for (i = 0; i < rateset.count && i < IW_MAX_BITRATES; i++) | |
570 | range->bitrate[i] = (rateset.rates[i] & 0x7f) * 500000; | |
571 | dev_wlc_intvar_get(dev, "nmode", &nmode); | |
572 | dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &phytype, sizeof(phytype)); | |
573 | ||
574 | if (nmode == 1 && phytype == WLC_PHY_TYPE_SSN) { | |
575 | dev_wlc_intvar_get(dev, "mimo_bw_cap", &bw_cap); | |
576 | dev_wlc_intvar_get(dev, "sgi_tx", &sgi_tx); | |
577 | dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, | |
578 | sizeof(channel_info_t)); | |
579 | ci.hw_channel = dtoh32(ci.hw_channel); | |
580 | ||
581 | if (bw_cap == 0 || (bw_cap == 2 && ci.hw_channel <= 14)) { | |
582 | if (sgi_tx == 0) | |
583 | nrate_list2copy = 0; | |
584 | else | |
585 | nrate_list2copy = 1; | |
586 | } | |
587 | if (bw_cap == 1 || (bw_cap == 2 && ci.hw_channel >= 36)) { | |
588 | if (sgi_tx == 0) | |
589 | nrate_list2copy = 2; | |
590 | else | |
591 | nrate_list2copy = 3; | |
592 | } | |
593 | range->num_bitrates += 8; | |
594 | for (k = 0; i < range->num_bitrates; k++, i++) { | |
595 | range->bitrate[i] = | |
596 | (nrate_list[nrate_list2copy][k]) * 500000; | |
597 | } | |
598 | } | |
599 | ||
59334c2f JC |
600 | error = dev_wlc_ioctl(dev, WLC_GET_PHYTYPE, &i, sizeof(i)); |
601 | if (error) { | |
cf2b4488 HP |
602 | kfree(channels); |
603 | return error; | |
604 | } | |
605 | i = dtoh32(i); | |
606 | if (i == WLC_PHY_TYPE_A) | |
607 | range->throughput = 24000000; | |
608 | else | |
609 | range->throughput = 1500000; | |
610 | ||
611 | range->min_rts = 0; | |
612 | range->max_rts = 2347; | |
613 | range->min_frag = 256; | |
614 | range->max_frag = 2346; | |
615 | ||
616 | range->max_encoding_tokens = DOT11_MAX_DEFAULT_KEYS; | |
617 | range->num_encoding_sizes = 4; | |
618 | range->encoding_size[0] = WEP1_KEY_SIZE; | |
619 | range->encoding_size[1] = WEP128_KEY_SIZE; | |
620 | #if WIRELESS_EXT > 17 | |
621 | range->encoding_size[2] = TKIP_KEY_SIZE; | |
622 | #else | |
623 | range->encoding_size[2] = 0; | |
624 | #endif | |
625 | range->encoding_size[3] = AES_KEY_SIZE; | |
626 | ||
627 | range->min_pmp = 0; | |
628 | range->max_pmp = 0; | |
629 | range->min_pmt = 0; | |
630 | range->max_pmt = 0; | |
631 | range->pmp_flags = 0; | |
632 | range->pm_capa = 0; | |
633 | ||
634 | range->num_txpower = 2; | |
635 | range->txpower[0] = 1; | |
636 | range->txpower[1] = 255; | |
637 | range->txpower_capa = IW_TXPOW_MWATT; | |
638 | ||
639 | #if WIRELESS_EXT > 10 | |
640 | range->we_version_compiled = WIRELESS_EXT; | |
641 | range->we_version_source = 19; | |
642 | ||
643 | range->retry_capa = IW_RETRY_LIMIT; | |
644 | range->retry_flags = IW_RETRY_LIMIT; | |
645 | range->r_time_flags = 0; | |
646 | range->min_retry = 1; | |
647 | range->max_retry = 255; | |
648 | range->min_r_time = 0; | |
649 | range->max_r_time = 0; | |
650 | #endif | |
651 | ||
652 | #if WIRELESS_EXT > 17 | |
653 | range->enc_capa = IW_ENC_CAPA_WPA; | |
654 | range->enc_capa |= IW_ENC_CAPA_CIPHER_TKIP; | |
655 | range->enc_capa |= IW_ENC_CAPA_CIPHER_CCMP; | |
656 | #ifdef BCMWPA2 | |
657 | range->enc_capa |= IW_ENC_CAPA_WPA2; | |
658 | #endif | |
659 | ||
660 | IW_EVENT_CAPA_SET_KERNEL(range->event_capa); | |
661 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP); | |
662 | IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN); | |
663 | IW_EVENT_CAPA_SET(range->event_capa, IWEVTXDROP); | |
664 | IW_EVENT_CAPA_SET(range->event_capa, IWEVMICHAELMICFAILURE); | |
665 | #ifdef BCMWPA2 | |
666 | IW_EVENT_CAPA_SET(range->event_capa, IWEVPMKIDCAND); | |
667 | #endif | |
668 | #endif /* WIRELESS_EXT > 17 */ | |
669 | ||
670 | kfree(channels); | |
671 | ||
672 | return 0; | |
673 | } | |
674 | ||
675 | static int rssi_to_qual(int rssi) | |
676 | { | |
677 | if (rssi <= WL_IW_RSSI_NO_SIGNAL) | |
678 | return 0; | |
679 | else if (rssi <= WL_IW_RSSI_VERY_LOW) | |
680 | return 1; | |
681 | else if (rssi <= WL_IW_RSSI_LOW) | |
682 | return 2; | |
683 | else if (rssi <= WL_IW_RSSI_GOOD) | |
684 | return 3; | |
685 | else if (rssi <= WL_IW_RSSI_VERY_GOOD) | |
686 | return 4; | |
687 | else | |
688 | return 5; | |
689 | } | |
690 | ||
691 | static int | |
692 | wl_iw_set_spy(struct net_device *dev, | |
693 | struct iw_request_info *info, struct iw_point *dwrq, char *extra) | |
694 | { | |
695 | wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); | |
696 | struct sockaddr *addr = (struct sockaddr *)extra; | |
697 | int i; | |
698 | ||
699 | WL_TRACE(("%s: SIOCSIWSPY\n", dev->name)); | |
700 | ||
701 | if (!extra) | |
702 | return -EINVAL; | |
703 | ||
704 | iw->spy_num = MIN(ARRAYSIZE(iw->spy_addr), dwrq->length); | |
705 | for (i = 0; i < iw->spy_num; i++) | |
706 | memcpy(&iw->spy_addr[i], addr[i].sa_data, ETHER_ADDR_LEN); | |
707 | memset(iw->spy_qual, 0, sizeof(iw->spy_qual)); | |
708 | ||
709 | return 0; | |
710 | } | |
711 | ||
712 | static int | |
713 | wl_iw_get_spy(struct net_device *dev, | |
714 | struct iw_request_info *info, struct iw_point *dwrq, char *extra) | |
715 | { | |
716 | wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); | |
717 | struct sockaddr *addr = (struct sockaddr *)extra; | |
718 | struct iw_quality *qual = (struct iw_quality *)&addr[iw->spy_num]; | |
719 | int i; | |
720 | ||
721 | WL_TRACE(("%s: SIOCGIWSPY\n", dev->name)); | |
722 | ||
723 | if (!extra) | |
724 | return -EINVAL; | |
725 | ||
726 | dwrq->length = iw->spy_num; | |
727 | for (i = 0; i < iw->spy_num; i++) { | |
728 | memcpy(addr[i].sa_data, &iw->spy_addr[i], ETHER_ADDR_LEN); | |
729 | addr[i].sa_family = AF_UNIX; | |
730 | memcpy(&qual[i], &iw->spy_qual[i], sizeof(struct iw_quality)); | |
731 | iw->spy_qual[i].updated = 0; | |
732 | } | |
733 | ||
734 | return 0; | |
735 | } | |
736 | ||
737 | static int | |
738 | wl_iw_ch_to_chanspec(int ch, wl_join_params_t *join_params, | |
739 | int *join_params_size) | |
740 | { | |
741 | chanspec_t chanspec = 0; | |
742 | ||
743 | if (ch != 0) { | |
744 | join_params->params.chanspec_num = 1; | |
745 | join_params->params.chanspec_list[0] = ch; | |
746 | ||
747 | if (join_params->params.chanspec_list[0]) | |
748 | chanspec |= WL_CHANSPEC_BAND_2G; | |
749 | else | |
750 | chanspec |= WL_CHANSPEC_BAND_5G; | |
751 | ||
752 | chanspec |= WL_CHANSPEC_BW_20; | |
753 | chanspec |= WL_CHANSPEC_CTL_SB_NONE; | |
754 | ||
755 | *join_params_size += WL_ASSOC_PARAMS_FIXED_SIZE + | |
756 | join_params->params.chanspec_num * sizeof(chanspec_t); | |
757 | ||
758 | join_params->params.chanspec_list[0] &= WL_CHANSPEC_CHAN_MASK; | |
759 | join_params->params.chanspec_list[0] |= chanspec; | |
760 | join_params->params.chanspec_list[0] = | |
761 | htodchanspec(join_params->params.chanspec_list[0]); | |
762 | ||
763 | join_params->params.chanspec_num = | |
764 | htod32(join_params->params.chanspec_num); | |
765 | ||
766 | WL_TRACE(("%s join_params->params.chanspec_list[0]= %X\n", | |
767 | __func__, join_params->params.chanspec_list[0])); | |
768 | } | |
769 | return 1; | |
770 | } | |
771 | ||
772 | static int | |
773 | wl_iw_set_wap(struct net_device *dev, | |
774 | struct iw_request_info *info, struct sockaddr *awrq, char *extra) | |
775 | { | |
776 | int error = -EINVAL; | |
777 | wl_join_params_t join_params; | |
778 | int join_params_size; | |
779 | ||
780 | WL_TRACE(("%s: SIOCSIWAP\n", dev->name)); | |
781 | ||
782 | if (awrq->sa_family != ARPHRD_ETHER) { | |
783 | WL_ERROR(("Invalid Header...sa_family\n")); | |
784 | return -EINVAL; | |
785 | } | |
786 | ||
787 | if (ETHER_ISBCAST(awrq->sa_data) || ETHER_ISNULLADDR(awrq->sa_data)) { | |
788 | scb_val_t scbval; | |
789 | bzero(&scbval, sizeof(scb_val_t)); | |
790 | (void)dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, | |
791 | sizeof(scb_val_t)); | |
792 | return 0; | |
793 | } | |
794 | ||
795 | memset(&join_params, 0, sizeof(join_params)); | |
796 | join_params_size = sizeof(join_params.ssid); | |
797 | ||
798 | memcpy(join_params.ssid.SSID, g_ssid.SSID, g_ssid.SSID_len); | |
799 | join_params.ssid.SSID_len = htod32(g_ssid.SSID_len); | |
800 | memcpy(&join_params.params.bssid, awrq->sa_data, ETHER_ADDR_LEN); | |
801 | ||
802 | WL_TRACE(("%s target_channel=%d\n", __func__, | |
803 | g_wl_iw_params.target_channel)); | |
804 | wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params, | |
805 | &join_params_size); | |
806 | ||
59334c2f JC |
807 | error = dev_wlc_ioctl(dev, WLC_SET_SSID, &join_params, |
808 | join_params_size); | |
809 | if (error) { | |
cf2b4488 HP |
810 | WL_ERROR(("%s Invalid ioctl data=%d\n", __func__, error)); |
811 | } | |
812 | ||
813 | if (g_ssid.SSID_len) { | |
814 | WL_TRACE(("%s: join SSID=%s BSSID=" MACSTR " ch=%d\n", | |
815 | __func__, g_ssid.SSID, | |
816 | MAC2STR((u8 *) awrq->sa_data), | |
817 | g_wl_iw_params.target_channel)); | |
818 | } | |
819 | ||
820 | memset(&g_ssid, 0, sizeof(g_ssid)); | |
821 | return 0; | |
822 | } | |
823 | ||
824 | static int | |
825 | wl_iw_get_wap(struct net_device *dev, | |
826 | struct iw_request_info *info, struct sockaddr *awrq, char *extra) | |
827 | { | |
828 | WL_TRACE(("%s: SIOCGIWAP\n", dev->name)); | |
829 | ||
830 | awrq->sa_family = ARPHRD_ETHER; | |
831 | memset(awrq->sa_data, 0, ETHER_ADDR_LEN); | |
832 | ||
833 | (void)dev_wlc_ioctl(dev, WLC_GET_BSSID, awrq->sa_data, ETHER_ADDR_LEN); | |
834 | ||
835 | return 0; | |
836 | } | |
837 | ||
838 | #if WIRELESS_EXT > 17 | |
839 | static int | |
840 | wl_iw_mlme(struct net_device *dev, | |
841 | struct iw_request_info *info, struct sockaddr *awrq, char *extra) | |
842 | { | |
843 | struct iw_mlme *mlme; | |
844 | scb_val_t scbval; | |
845 | int error = -EINVAL; | |
846 | ||
847 | WL_TRACE(("%s: SIOCSIWMLME DISASSOC/DEAUTH\n", dev->name)); | |
848 | ||
849 | mlme = (struct iw_mlme *)extra; | |
850 | if (mlme == NULL) { | |
851 | WL_ERROR(("Invalid ioctl data.\n")); | |
852 | return error; | |
853 | } | |
854 | ||
855 | scbval.val = mlme->reason_code; | |
856 | bcopy(&mlme->addr.sa_data, &scbval.ea, ETHER_ADDR_LEN); | |
857 | ||
858 | if (mlme->cmd == IW_MLME_DISASSOC) { | |
859 | scbval.val = htod32(scbval.val); | |
860 | error = | |
861 | dev_wlc_ioctl(dev, WLC_DISASSOC, &scbval, | |
862 | sizeof(scb_val_t)); | |
863 | } else if (mlme->cmd == IW_MLME_DEAUTH) { | |
864 | scbval.val = htod32(scbval.val); | |
865 | error = | |
866 | dev_wlc_ioctl(dev, WLC_SCB_DEAUTHENTICATE_FOR_REASON, | |
867 | &scbval, sizeof(scb_val_t)); | |
868 | } else { | |
869 | WL_ERROR(("Invalid ioctl data.\n")); | |
870 | return error; | |
871 | } | |
872 | ||
873 | return error; | |
874 | } | |
875 | #endif /* WIRELESS_EXT > 17 */ | |
876 | ||
877 | #ifndef WL_IW_USE_ISCAN | |
878 | static int | |
879 | wl_iw_get_aplist(struct net_device *dev, | |
880 | struct iw_request_info *info, | |
881 | struct iw_point *dwrq, char *extra) | |
882 | { | |
883 | wl_scan_results_t *list; | |
884 | struct sockaddr *addr = (struct sockaddr *)extra; | |
885 | struct iw_quality qual[IW_MAX_AP]; | |
886 | wl_bss_info_t *bi = NULL; | |
887 | int error, i; | |
888 | uint buflen = dwrq->length; | |
889 | ||
890 | WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name)); | |
891 | ||
892 | if (!extra) | |
893 | return -EINVAL; | |
894 | ||
895 | list = kmalloc(buflen, GFP_KERNEL); | |
896 | if (!list) | |
897 | return -ENOMEM; | |
898 | memset(list, 0, buflen); | |
899 | list->buflen = htod32(buflen); | |
59334c2f JC |
900 | error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, buflen); |
901 | if (error) { | |
cf2b4488 HP |
902 | WL_ERROR(("%d: Scan results error %d\n", __LINE__, error)); |
903 | kfree(list); | |
904 | return error; | |
905 | } | |
906 | list->buflen = dtoh32(list->buflen); | |
907 | list->version = dtoh32(list->version); | |
908 | list->count = dtoh32(list->count); | |
909 | if (list->version != WL_BSS_INFO_VERSION) { | |
910 | WL_ERROR(("%s : list->version %d != WL_BSS_INFO_VERSION\n", | |
911 | __func__, list->version)); | |
912 | kfree(list); | |
913 | return -EINVAL; | |
914 | } | |
915 | ||
916 | for (i = 0, dwrq->length = 0; | |
917 | i < list->count && dwrq->length < IW_MAX_AP; i++) { | |
918 | bi = bi ? (wl_bss_info_t *) ((uintptr) bi + | |
919 | dtoh32(bi->length)) : list-> | |
920 | bss_info; | |
921 | ASSERT(((uintptr) bi + dtoh32(bi->length)) <= | |
922 | ((uintptr) list + buflen)); | |
923 | ||
924 | if (!(dtoh16(bi->capability) & DOT11_CAP_ESS)) | |
925 | continue; | |
926 | ||
927 | memcpy(addr[dwrq->length].sa_data, &bi->BSSID, ETHER_ADDR_LEN); | |
928 | addr[dwrq->length].sa_family = ARPHRD_ETHER; | |
929 | qual[dwrq->length].qual = rssi_to_qual(dtoh16(bi->RSSI)); | |
930 | qual[dwrq->length].level = 0x100 + dtoh16(bi->RSSI); | |
931 | qual[dwrq->length].noise = 0x100 + bi->phy_noise; | |
932 | ||
933 | #if WIRELESS_EXT > 18 | |
934 | qual[dwrq->length].updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; | |
935 | #else | |
936 | qual[dwrq->length].updated = 7; | |
937 | #endif | |
938 | dwrq->length++; | |
939 | } | |
940 | ||
941 | kfree(list); | |
942 | ||
943 | if (dwrq->length) { | |
944 | memcpy(&addr[dwrq->length], qual, | |
945 | sizeof(struct iw_quality) * dwrq->length); | |
946 | dwrq->flags = 1; | |
947 | } | |
948 | ||
949 | return 0; | |
950 | } | |
951 | #endif /* WL_IW_USE_ISCAN */ | |
952 | ||
953 | #ifdef WL_IW_USE_ISCAN | |
954 | static int | |
955 | wl_iw_iscan_get_aplist(struct net_device *dev, | |
956 | struct iw_request_info *info, | |
957 | struct iw_point *dwrq, char *extra) | |
958 | { | |
959 | wl_scan_results_t *list; | |
960 | iscan_buf_t *buf; | |
961 | iscan_info_t *iscan = g_iscan; | |
962 | ||
963 | struct sockaddr *addr = (struct sockaddr *)extra; | |
964 | struct iw_quality qual[IW_MAX_AP]; | |
965 | wl_bss_info_t *bi = NULL; | |
966 | int i; | |
967 | ||
968 | WL_TRACE(("%s: SIOCGIWAPLIST\n", dev->name)); | |
969 | ||
970 | if (!extra) | |
971 | return -EINVAL; | |
972 | ||
973 | if ((!iscan) || (iscan->sysioc_pid < 0)) { | |
974 | WL_ERROR(("%s error\n", __func__)); | |
975 | return 0; | |
976 | } | |
977 | ||
978 | buf = iscan->list_hdr; | |
979 | while (buf) { | |
980 | list = &((wl_iscan_results_t *) buf->iscan_buf)->results; | |
981 | if (list->version != WL_BSS_INFO_VERSION) { | |
982 | WL_ERROR(("%s : list->version %d != " | |
983 | "WL_BSS_INFO_VERSION\n", | |
984 | __func__, list->version)); | |
985 | return -EINVAL; | |
986 | } | |
987 | ||
988 | bi = NULL; | |
989 | for (i = 0, dwrq->length = 0; | |
990 | i < list->count && dwrq->length < IW_MAX_AP; i++) { | |
991 | bi = bi ? (wl_bss_info_t *) ((uintptr) bi + | |
992 | dtoh32(bi->length)) : | |
993 | list->bss_info; | |
994 | ASSERT(((uintptr) bi + dtoh32(bi->length)) <= | |
995 | ((uintptr) list + WLC_IW_ISCAN_MAXLEN)); | |
996 | ||
997 | if (!(dtoh16(bi->capability) & DOT11_CAP_ESS)) | |
998 | continue; | |
999 | ||
1000 | memcpy(addr[dwrq->length].sa_data, &bi->BSSID, | |
1001 | ETHER_ADDR_LEN); | |
1002 | addr[dwrq->length].sa_family = ARPHRD_ETHER; | |
1003 | qual[dwrq->length].qual = | |
1004 | rssi_to_qual(dtoh16(bi->RSSI)); | |
1005 | qual[dwrq->length].level = 0x100 + dtoh16(bi->RSSI); | |
1006 | qual[dwrq->length].noise = 0x100 + bi->phy_noise; | |
1007 | ||
1008 | #if WIRELESS_EXT > 18 | |
1009 | qual[dwrq->length].updated = | |
1010 | IW_QUAL_ALL_UPDATED | IW_QUAL_DBM; | |
1011 | #else | |
1012 | qual[dwrq->length].updated = 7; | |
1013 | #endif | |
1014 | ||
1015 | dwrq->length++; | |
1016 | } | |
1017 | buf = buf->next; | |
1018 | } | |
1019 | if (dwrq->length) { | |
1020 | memcpy(&addr[dwrq->length], qual, | |
1021 | sizeof(struct iw_quality) * dwrq->length); | |
1022 | dwrq->flags = 1; | |
1023 | } | |
1024 | ||
1025 | return 0; | |
1026 | } | |
1027 | ||
1028 | static int wl_iw_iscan_prep(wl_scan_params_t *params, wlc_ssid_t *ssid) | |
1029 | { | |
1030 | int err = 0; | |
1031 | ||
1032 | memcpy(¶ms->bssid, ðer_bcast, ETHER_ADDR_LEN); | |
1033 | params->bss_type = DOT11_BSSTYPE_ANY; | |
1034 | params->scan_type = 0; | |
1035 | params->nprobes = -1; | |
1036 | params->active_time = -1; | |
1037 | params->passive_time = -1; | |
1038 | params->home_time = -1; | |
1039 | params->channel_num = 0; | |
1040 | ||
1041 | params->nprobes = htod32(params->nprobes); | |
1042 | params->active_time = htod32(params->active_time); | |
1043 | params->passive_time = htod32(params->passive_time); | |
1044 | params->home_time = htod32(params->home_time); | |
1045 | if (ssid && ssid->SSID_len) | |
1046 | memcpy(¶ms->ssid, ssid, sizeof(wlc_ssid_t)); | |
1047 | ||
1048 | return err; | |
1049 | } | |
1050 | ||
7d4df48e | 1051 | static int wl_iw_iscan(iscan_info_t *iscan, wlc_ssid_t *ssid, u16 action) |
cf2b4488 HP |
1052 | { |
1053 | int err = 0; | |
1054 | ||
1055 | iscan->iscan_ex_params_p->version = htod32(ISCAN_REQ_VERSION); | |
1056 | iscan->iscan_ex_params_p->action = htod16(action); | |
1057 | iscan->iscan_ex_params_p->scan_duration = htod16(0); | |
1058 | ||
1059 | WL_SCAN(("%s : nprobes=%d\n", __func__, | |
1060 | iscan->iscan_ex_params_p->params.nprobes)); | |
1061 | WL_SCAN(("active_time=%d\n", | |
1062 | iscan->iscan_ex_params_p->params.active_time)); | |
1063 | WL_SCAN(("passive_time=%d\n", | |
1064 | iscan->iscan_ex_params_p->params.passive_time)); | |
1065 | WL_SCAN(("home_time=%d\n", iscan->iscan_ex_params_p->params.home_time)); | |
1066 | WL_SCAN(("scan_type=%d\n", iscan->iscan_ex_params_p->params.scan_type)); | |
1067 | WL_SCAN(("bss_type=%d\n", iscan->iscan_ex_params_p->params.bss_type)); | |
1068 | ||
1069 | (void)dev_iw_iovar_setbuf(iscan->dev, "iscan", iscan->iscan_ex_params_p, | |
1070 | iscan->iscan_ex_param_size, iscan->ioctlbuf, | |
1071 | sizeof(iscan->ioctlbuf)); | |
1072 | ||
1073 | return err; | |
1074 | } | |
1075 | ||
3deea904 | 1076 | static void wl_iw_timerfunc(unsigned long data) |
cf2b4488 HP |
1077 | { |
1078 | iscan_info_t *iscan = (iscan_info_t *) data; | |
1079 | if (iscan) { | |
1080 | iscan->timer_on = 0; | |
1081 | if (iscan->iscan_state != ISCAN_STATE_IDLE) { | |
1082 | WL_TRACE(("timer trigger\n")); | |
1083 | up(&iscan->sysioc_sem); | |
1084 | } | |
1085 | } | |
1086 | } | |
1087 | ||
1088 | static void wl_iw_set_event_mask(struct net_device *dev) | |
1089 | { | |
1090 | char eventmask[WL_EVENTING_MASK_LEN]; | |
1091 | char iovbuf[WL_EVENTING_MASK_LEN + 12]; | |
1092 | ||
1093 | dev_iw_iovar_getbuf(dev, "event_msgs", "", 0, iovbuf, sizeof(iovbuf)); | |
1094 | bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN); | |
1095 | setbit(eventmask, WLC_E_SCAN_COMPLETE); | |
1096 | dev_iw_iovar_setbuf(dev, "event_msgs", eventmask, WL_EVENTING_MASK_LEN, | |
1097 | iovbuf, sizeof(iovbuf)); | |
1098 | } | |
1099 | ||
1100 | static uint32 wl_iw_iscan_get(iscan_info_t *iscan) | |
1101 | { | |
1102 | iscan_buf_t *buf; | |
1103 | iscan_buf_t *ptr; | |
1104 | wl_iscan_results_t *list_buf; | |
1105 | wl_iscan_results_t list; | |
1106 | wl_scan_results_t *results; | |
1107 | uint32 status; | |
1108 | int res = 0; | |
1109 | ||
1110 | MUTEX_LOCK_WL_SCAN_SET(); | |
1111 | if (iscan->list_cur) { | |
1112 | buf = iscan->list_cur; | |
1113 | iscan->list_cur = buf->next; | |
1114 | } else { | |
1115 | buf = kmalloc(sizeof(iscan_buf_t), GFP_KERNEL); | |
1116 | if (!buf) { | |
1117 | WL_ERROR(("%s can't alloc iscan_buf_t : going to abort " | |
1118 | "currect iscan\n", __func__)); | |
1119 | MUTEX_UNLOCK_WL_SCAN_SET(); | |
1120 | return WL_SCAN_RESULTS_NO_MEM; | |
1121 | } | |
1122 | buf->next = NULL; | |
1123 | if (!iscan->list_hdr) | |
1124 | iscan->list_hdr = buf; | |
1125 | else { | |
1126 | ptr = iscan->list_hdr; | |
1127 | while (ptr->next) { | |
1128 | ptr = ptr->next; | |
1129 | } | |
1130 | ptr->next = buf; | |
1131 | } | |
1132 | } | |
1133 | memset(buf->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN); | |
1134 | list_buf = (wl_iscan_results_t *) buf->iscan_buf; | |
1135 | results = &list_buf->results; | |
1136 | results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE; | |
1137 | results->version = 0; | |
1138 | results->count = 0; | |
1139 | ||
1140 | memset(&list, 0, sizeof(list)); | |
1141 | list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN); | |
1142 | res = dev_iw_iovar_getbuf(iscan->dev, | |
1143 | "iscanresults", | |
1144 | &list, | |
1145 | WL_ISCAN_RESULTS_FIXED_SIZE, | |
1146 | buf->iscan_buf, WLC_IW_ISCAN_MAXLEN); | |
1147 | if (res == 0) { | |
1148 | results->buflen = dtoh32(results->buflen); | |
1149 | results->version = dtoh32(results->version); | |
1150 | results->count = dtoh32(results->count); | |
1151 | WL_TRACE(("results->count = %d\n", results->count)); | |
1152 | WL_TRACE(("results->buflen = %d\n", results->buflen)); | |
1153 | status = dtoh32(list_buf->status); | |
1154 | } else { | |
1155 | WL_ERROR(("%s returns error %d\n", __func__, res)); | |
1156 | status = WL_SCAN_RESULTS_NO_MEM; | |
1157 | } | |
1158 | MUTEX_UNLOCK_WL_SCAN_SET(); | |
1159 | return status; | |
1160 | } | |
1161 | ||
1162 | static void wl_iw_force_specific_scan(iscan_info_t *iscan) | |
1163 | { | |
1164 | WL_TRACE(("%s force Specific SCAN for %s\n", __func__, | |
1165 | g_specific_ssid.SSID)); | |
1166 | rtnl_lock(); | |
1167 | ||
1168 | (void)dev_wlc_ioctl(iscan->dev, WLC_SCAN, &g_specific_ssid, | |
1169 | sizeof(g_specific_ssid)); | |
1170 | ||
1171 | rtnl_unlock(); | |
1172 | } | |
1173 | ||
1174 | static void wl_iw_send_scan_complete(iscan_info_t *iscan) | |
1175 | { | |
1176 | #ifndef SANDGATE2G | |
1177 | union iwreq_data wrqu; | |
1178 | ||
1179 | memset(&wrqu, 0, sizeof(wrqu)); | |
1180 | ||
1181 | wireless_send_event(iscan->dev, SIOCGIWSCAN, &wrqu, NULL); | |
1182 | WL_TRACE(("Send Event ISCAN complete\n")); | |
1183 | #endif | |
1184 | } | |
1185 | ||
1186 | static int _iscan_sysioc_thread(void *data) | |
1187 | { | |
1188 | uint32 status; | |
1189 | iscan_info_t *iscan = (iscan_info_t *) data; | |
1190 | static bool iscan_pass_abort = FALSE; | |
1191 | DAEMONIZE("iscan_sysioc"); | |
1192 | ||
1193 | status = WL_SCAN_RESULTS_PARTIAL; | |
1194 | while (down_interruptible(&iscan->sysioc_sem) == 0) { | |
1195 | ||
1196 | if (iscan->timer_on) { | |
1197 | del_timer_sync(&iscan->timer); | |
1198 | iscan->timer_on = 0; | |
1199 | } | |
1200 | rtnl_lock(); | |
1201 | status = wl_iw_iscan_get(iscan); | |
1202 | rtnl_unlock(); | |
1203 | if (g_scan_specified_ssid && (iscan_pass_abort == TRUE)) { | |
1204 | WL_TRACE(("%s Get results from specific scan " | |
1205 | "status = %d\n", __func__, status)); | |
1206 | wl_iw_send_scan_complete(iscan); | |
1207 | iscan_pass_abort = FALSE; | |
1208 | status = -1; | |
1209 | } | |
1210 | ||
1211 | switch (status) { | |
1212 | case WL_SCAN_RESULTS_PARTIAL: | |
1213 | WL_TRACE(("iscanresults incomplete\n")); | |
1214 | rtnl_lock(); | |
1215 | wl_iw_iscan(iscan, NULL, WL_SCAN_ACTION_CONTINUE); | |
1216 | rtnl_unlock(); | |
1217 | mod_timer(&iscan->timer, | |
1218 | jiffies + iscan->timer_ms * HZ / 1000); | |
1219 | iscan->timer_on = 1; | |
1220 | break; | |
1221 | case WL_SCAN_RESULTS_SUCCESS: | |
1222 | WL_TRACE(("iscanresults complete\n")); | |
1223 | iscan->iscan_state = ISCAN_STATE_IDLE; | |
1224 | wl_iw_send_scan_complete(iscan); | |
1225 | break; | |
1226 | case WL_SCAN_RESULTS_PENDING: | |
1227 | WL_TRACE(("iscanresults pending\n")); | |
1228 | mod_timer(&iscan->timer, | |
1229 | jiffies + iscan->timer_ms * HZ / 1000); | |
1230 | iscan->timer_on = 1; | |
1231 | break; | |
1232 | case WL_SCAN_RESULTS_ABORTED: | |
1233 | WL_TRACE(("iscanresults aborted\n")); | |
1234 | iscan->iscan_state = ISCAN_STATE_IDLE; | |
1235 | if (g_scan_specified_ssid == 0) | |
1236 | wl_iw_send_scan_complete(iscan); | |
1237 | else { | |
1238 | iscan_pass_abort = TRUE; | |
1239 | wl_iw_force_specific_scan(iscan); | |
1240 | } | |
1241 | break; | |
1242 | case WL_SCAN_RESULTS_NO_MEM: | |
1243 | WL_TRACE(("iscanresults can't alloc memory: skip\n")); | |
1244 | iscan->iscan_state = ISCAN_STATE_IDLE; | |
1245 | break; | |
1246 | default: | |
1247 | WL_TRACE(("iscanresults returned unknown status %d\n", | |
1248 | status)); | |
1249 | break; | |
1250 | } | |
1251 | } | |
1252 | ||
1253 | if (iscan->timer_on) { | |
1254 | del_timer_sync(&iscan->timer); | |
1255 | iscan->timer_on = 0; | |
1256 | } | |
1257 | complete_and_exit(&iscan->sysioc_exited, 0); | |
1258 | } | |
1259 | #endif /* WL_IW_USE_ISCAN */ | |
1260 | ||
1261 | static int | |
1262 | wl_iw_set_scan(struct net_device *dev, | |
1263 | struct iw_request_info *info, | |
1264 | union iwreq_data *wrqu, char *extra) | |
1265 | { | |
1266 | int error; | |
1267 | WL_TRACE(("\n:%s dev:%s: SIOCSIWSCAN : SCAN\n", __func__, dev->name)); | |
1268 | ||
1269 | g_set_essid_before_scan = FALSE; | |
1270 | #if defined(CSCAN) | |
1271 | WL_ERROR(("%s: Scan from SIOCGIWSCAN not supported\n", __func__)); | |
1272 | return -EINVAL; | |
1273 | #endif | |
1274 | ||
1275 | if (g_onoff == G_WLAN_SET_OFF) | |
1276 | return 0; | |
1277 | ||
1278 | memset(&g_specific_ssid, 0, sizeof(g_specific_ssid)); | |
1279 | #ifndef WL_IW_USE_ISCAN | |
1280 | g_scan_specified_ssid = 0; | |
1281 | #endif | |
1282 | ||
1283 | #if WIRELESS_EXT > 17 | |
1284 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { | |
1285 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { | |
1286 | struct iw_scan_req *req = (struct iw_scan_req *)extra; | |
1287 | if (g_scan_specified_ssid) { | |
1288 | WL_TRACE(("%s Specific SCAN is not done ignore " | |
1289 | "scan for = %s\n", | |
1290 | __func__, req->essid)); | |
1291 | return -EBUSY; | |
1292 | } else { | |
1293 | g_specific_ssid.SSID_len = | |
1294 | MIN(sizeof(g_specific_ssid.SSID), | |
1295 | req->essid_len); | |
1296 | memcpy(g_specific_ssid.SSID, req->essid, | |
1297 | g_specific_ssid.SSID_len); | |
1298 | g_specific_ssid.SSID_len = | |
1299 | htod32(g_specific_ssid.SSID_len); | |
1300 | g_scan_specified_ssid = 1; | |
1301 | WL_TRACE(("### Specific scan ssid=%s len=%d\n", | |
1302 | g_specific_ssid.SSID, | |
1303 | g_specific_ssid.SSID_len)); | |
1304 | } | |
1305 | } | |
1306 | } | |
1307 | #endif /* WIRELESS_EXT > 17 */ | |
59334c2f JC |
1308 | error = dev_wlc_ioctl(dev, WLC_SCAN, &g_specific_ssid, |
1309 | sizeof(g_specific_ssid)); | |
1310 | if (error) { | |
cf2b4488 HP |
1311 | WL_TRACE(("#### Set SCAN for %s failed with %d\n", |
1312 | g_specific_ssid.SSID, error)); | |
1313 | g_scan_specified_ssid = 0; | |
1314 | return -EBUSY; | |
1315 | } | |
1316 | ||
1317 | return 0; | |
1318 | } | |
1319 | ||
1320 | #ifdef WL_IW_USE_ISCAN | |
1321 | int wl_iw_iscan_set_scan_broadcast_prep(struct net_device *dev, uint flag) | |
1322 | { | |
1323 | wlc_ssid_t ssid; | |
1324 | iscan_info_t *iscan = g_iscan; | |
1325 | ||
1326 | if (flag) | |
1327 | rtnl_lock(); | |
1328 | ||
1329 | wl_iw_set_event_mask(dev); | |
1330 | ||
1331 | WL_TRACE(("+++: Set Broadcast ISCAN\n")); | |
1332 | memset(&ssid, 0, sizeof(ssid)); | |
1333 | ||
1334 | iscan->list_cur = iscan->list_hdr; | |
1335 | iscan->iscan_state = ISCAN_STATE_SCANING; | |
1336 | ||
1337 | memset(&iscan->iscan_ex_params_p->params, 0, | |
1338 | iscan->iscan_ex_param_size); | |
1339 | wl_iw_iscan_prep(&iscan->iscan_ex_params_p->params, &ssid); | |
1340 | wl_iw_iscan(iscan, &ssid, WL_SCAN_ACTION_START); | |
1341 | ||
1342 | if (flag) | |
1343 | rtnl_unlock(); | |
1344 | ||
1345 | mod_timer(&iscan->timer, jiffies + iscan->timer_ms * HZ / 1000); | |
1346 | ||
1347 | iscan->timer_on = 1; | |
1348 | ||
1349 | return 0; | |
1350 | } | |
1351 | ||
1352 | static int | |
1353 | wl_iw_iscan_set_scan(struct net_device *dev, | |
1354 | struct iw_request_info *info, | |
1355 | union iwreq_data *wrqu, char *extra) | |
1356 | { | |
1357 | wlc_ssid_t ssid; | |
1358 | iscan_info_t *iscan = g_iscan; | |
1359 | ||
1360 | WL_TRACE(("%s: SIOCSIWSCAN : ISCAN\n", dev->name)); | |
1361 | ||
1362 | #if defined(CSCAN) | |
1363 | WL_ERROR(("%s: Scan from SIOCGIWSCAN not supported\n", __func__)); | |
1364 | return -EINVAL; | |
1365 | #endif | |
1366 | ||
1367 | if (g_onoff == G_WLAN_SET_OFF) { | |
1368 | WL_TRACE(("%s: driver is not up yet after START\n", __func__)); | |
1369 | return 0; | |
1370 | } | |
1371 | #ifdef PNO_SUPPORT | |
1372 | if (dhd_dev_get_pno_status(dev)) { | |
1373 | WL_ERROR(("%s: Scan called when PNO is active\n", __func__)); | |
1374 | } | |
1375 | #endif | |
1376 | ||
1377 | if ((!iscan) || (iscan->sysioc_pid < 0)) | |
1378 | return wl_iw_set_scan(dev, info, wrqu, extra); | |
1379 | ||
1380 | if (g_scan_specified_ssid) { | |
1381 | WL_TRACE(("%s Specific SCAN already running ignoring BC scan\n", | |
1382 | __func__)); | |
1383 | return EBUSY; | |
1384 | } | |
1385 | ||
1386 | memset(&ssid, 0, sizeof(ssid)); | |
1387 | ||
1388 | #if WIRELESS_EXT > 17 | |
1389 | if (wrqu->data.length == sizeof(struct iw_scan_req)) { | |
1390 | if (wrqu->data.flags & IW_SCAN_THIS_ESSID) { | |
1391 | struct iw_scan_req *req = (struct iw_scan_req *)extra; | |
1392 | ssid.SSID_len = MIN(sizeof(ssid.SSID), req->essid_len); | |
1393 | memcpy(ssid.SSID, req->essid, ssid.SSID_len); | |
1394 | ssid.SSID_len = htod32(ssid.SSID_len); | |
1395 | } else { | |
1396 | g_scan_specified_ssid = 0; | |
1397 | ||
1398 | if (iscan->iscan_state == ISCAN_STATE_SCANING) { | |
1399 | WL_TRACE(("%s ISCAN already in progress \n", | |
1400 | __func__)); | |
1401 | return 0; | |
1402 | } | |
1403 | } | |
1404 | } | |
1405 | #endif /* WIRELESS_EXT > 17 */ | |
1406 | wl_iw_iscan_set_scan_broadcast_prep(dev, 0); | |
1407 | ||
1408 | return 0; | |
1409 | } | |
1410 | #endif /* WL_IW_USE_ISCAN */ | |
1411 | ||
1412 | #if WIRELESS_EXT > 17 | |
3fd79f7c | 1413 | static bool ie_is_wpa_ie(u8 **wpaie, u8 **tlvs, int *tlvs_len) |
cf2b4488 HP |
1414 | { |
1415 | ||
3fd79f7c | 1416 | u8 *ie = *wpaie; |
cf2b4488 HP |
1417 | |
1418 | if ((ie[1] >= 6) && | |
1419 | !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x01"), 4)) { | |
1420 | return TRUE; | |
1421 | } | |
1422 | ||
1423 | ie += ie[1] + 2; | |
1424 | *tlvs_len -= (int)(ie - *tlvs); | |
1425 | *tlvs = ie; | |
1426 | return FALSE; | |
1427 | } | |
1428 | ||
3fd79f7c | 1429 | static bool ie_is_wps_ie(u8 **wpsie, u8 **tlvs, int *tlvs_len) |
cf2b4488 HP |
1430 | { |
1431 | ||
3fd79f7c | 1432 | u8 *ie = *wpsie; |
cf2b4488 HP |
1433 | |
1434 | if ((ie[1] >= 4) && | |
1435 | !bcmp((const void *)&ie[2], (const void *)(WPA_OUI "\x04"), 4)) { | |
1436 | return TRUE; | |
1437 | } | |
1438 | ||
1439 | ie += ie[1] + 2; | |
1440 | *tlvs_len -= (int)(ie - *tlvs); | |
1441 | *tlvs = ie; | |
1442 | return FALSE; | |
1443 | } | |
1444 | #endif /* WIRELESS_EXT > 17 */ | |
1445 | ||
1446 | static int | |
1447 | wl_iw_handle_scanresults_ies(char **event_p, char *end, | |
1448 | struct iw_request_info *info, wl_bss_info_t *bi) | |
1449 | { | |
1450 | #if WIRELESS_EXT > 17 | |
1451 | struct iw_event iwe; | |
1452 | char *event; | |
1453 | ||
1454 | event = *event_p; | |
1455 | if (bi->ie_length) { | |
1456 | bcm_tlv_t *ie; | |
3fd79f7c | 1457 | u8 *ptr = ((u8 *) bi) + sizeof(wl_bss_info_t); |
cf2b4488 HP |
1458 | int ptr_len = bi->ie_length; |
1459 | ||
1460 | #ifdef BCMWPA2 | |
59334c2f JC |
1461 | ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_RSN_ID); |
1462 | if (ie) { | |
cf2b4488 HP |
1463 | iwe.cmd = IWEVGENIE; |
1464 | iwe.u.data.length = ie->len + 2; | |
1465 | event = | |
1466 | IWE_STREAM_ADD_POINT(info, event, end, &iwe, | |
1467 | (char *)ie); | |
1468 | } | |
3fd79f7c | 1469 | ptr = ((u8 *) bi) + sizeof(wl_bss_info_t); |
cf2b4488 HP |
1470 | #endif |
1471 | ||
1472 | while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) { | |
3fd79f7c | 1473 | if (ie_is_wps_ie(((u8 **)&ie), &ptr, &ptr_len)) { |
cf2b4488 HP |
1474 | iwe.cmd = IWEVGENIE; |
1475 | iwe.u.data.length = ie->len + 2; | |
1476 | event = | |
1477 | IWE_STREAM_ADD_POINT(info, event, end, &iwe, | |
1478 | (char *)ie); | |
1479 | break; | |
1480 | } | |
1481 | } | |
1482 | ||
3fd79f7c | 1483 | ptr = ((u8 *) bi) + sizeof(wl_bss_info_t); |
cf2b4488 HP |
1484 | ptr_len = bi->ie_length; |
1485 | while ((ie = bcm_parse_tlvs(ptr, ptr_len, DOT11_MNG_WPA_ID))) { | |
3fd79f7c | 1486 | if (ie_is_wpa_ie(((u8 **)&ie), &ptr, &ptr_len)) { |
cf2b4488 HP |
1487 | iwe.cmd = IWEVGENIE; |
1488 | iwe.u.data.length = ie->len + 2; | |
1489 | event = | |
1490 | IWE_STREAM_ADD_POINT(info, event, end, &iwe, | |
1491 | (char *)ie); | |
1492 | break; | |
1493 | } | |
1494 | } | |
1495 | ||
1496 | *event_p = event; | |
1497 | } | |
1498 | #endif /* WIRELESS_EXT > 17 */ | |
1499 | return 0; | |
1500 | } | |
1501 | ||
1502 | static uint | |
1503 | wl_iw_get_scan_prep(wl_scan_results_t *list, | |
1504 | struct iw_request_info *info, char *extra, short max_size) | |
1505 | { | |
1506 | int i, j; | |
1507 | struct iw_event iwe; | |
1508 | wl_bss_info_t *bi = NULL; | |
1509 | char *event = extra, *end = extra + max_size - WE_ADD_EVENT_FIX, *value; | |
1510 | int ret = 0; | |
1511 | ||
1512 | ASSERT(list); | |
1513 | ||
1514 | for (i = 0; i < list->count && i < IW_MAX_AP; i++) { | |
1515 | if (list->version != WL_BSS_INFO_VERSION) { | |
1516 | WL_ERROR(("%s : list->version %d != " | |
1517 | "WL_BSS_INFO_VERSION\n", | |
1518 | __func__, list->version)); | |
1519 | return ret; | |
1520 | } | |
1521 | ||
1522 | bi = bi ? (wl_bss_info_t *) ((uintptr) bi + | |
1523 | dtoh32(bi->length)) : list-> | |
1524 | bss_info; | |
1525 | ||
1526 | WL_TRACE(("%s : %s\n", __func__, bi->SSID)); | |
1527 | ||
1528 | iwe.cmd = SIOCGIWAP; | |
1529 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
1530 | memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, ETHER_ADDR_LEN); | |
1531 | event = | |
1532 | IWE_STREAM_ADD_EVENT(info, event, end, &iwe, | |
1533 | IW_EV_ADDR_LEN); | |
1534 | iwe.u.data.length = dtoh32(bi->SSID_len); | |
1535 | iwe.cmd = SIOCGIWESSID; | |
1536 | iwe.u.data.flags = 1; | |
1537 | event = IWE_STREAM_ADD_POINT(info, event, end, &iwe, bi->SSID); | |
1538 | ||
1539 | if (dtoh16(bi->capability) & (DOT11_CAP_ESS | DOT11_CAP_IBSS)) { | |
1540 | iwe.cmd = SIOCGIWMODE; | |
1541 | if (dtoh16(bi->capability) & DOT11_CAP_ESS) | |
1542 | iwe.u.mode = IW_MODE_INFRA; | |
1543 | else | |
1544 | iwe.u.mode = IW_MODE_ADHOC; | |
1545 | event = | |
1546 | IWE_STREAM_ADD_EVENT(info, event, end, &iwe, | |
1547 | IW_EV_UINT_LEN); | |
1548 | } | |
1549 | ||
1550 | iwe.cmd = SIOCGIWFREQ; | |
1551 | iwe.u.freq.m = wf_channel2mhz(CHSPEC_CHANNEL(bi->chanspec), | |
1552 | CHSPEC_CHANNEL(bi->chanspec) <= | |
1553 | CH_MAX_2G_CHANNEL ? | |
1554 | WF_CHAN_FACTOR_2_4_G : | |
1555 | WF_CHAN_FACTOR_5_G); | |
1556 | iwe.u.freq.e = 6; | |
1557 | event = | |
1558 | IWE_STREAM_ADD_EVENT(info, event, end, &iwe, | |
1559 | IW_EV_FREQ_LEN); | |
1560 | ||
1561 | iwe.cmd = IWEVQUAL; | |
1562 | iwe.u.qual.qual = rssi_to_qual(dtoh16(bi->RSSI)); | |
1563 | iwe.u.qual.level = 0x100 + dtoh16(bi->RSSI); | |
1564 | iwe.u.qual.noise = 0x100 + bi->phy_noise; | |
1565 | event = | |
1566 | IWE_STREAM_ADD_EVENT(info, event, end, &iwe, | |
1567 | IW_EV_QUAL_LEN); | |
1568 | ||
1569 | wl_iw_handle_scanresults_ies(&event, end, info, bi); | |
1570 | ||
1571 | iwe.cmd = SIOCGIWENCODE; | |
1572 | if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY) | |
1573 | iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | |
1574 | else | |
1575 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
1576 | iwe.u.data.length = 0; | |
1577 | event = | |
1578 | IWE_STREAM_ADD_POINT(info, event, end, &iwe, (char *)event); | |
1579 | ||
1580 | if (bi->rateset.count) { | |
1581 | if (((event - extra) + | |
1582 | IW_EV_LCP_LEN) <= (uintptr) end) { | |
1583 | value = event + IW_EV_LCP_LEN; | |
1584 | iwe.cmd = SIOCGIWRATE; | |
1585 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = | |
1586 | 0; | |
1587 | for (j = 0; | |
1588 | j < bi->rateset.count | |
1589 | && j < IW_MAX_BITRATES; j++) { | |
1590 | iwe.u.bitrate.value = | |
1591 | (bi->rateset.rates[j] & 0x7f) * | |
1592 | 500000; | |
1593 | value = | |
1594 | IWE_STREAM_ADD_VALUE(info, event, | |
1595 | value, end, &iwe, | |
1596 | IW_EV_PARAM_LEN); | |
1597 | } | |
1598 | event = value; | |
1599 | } | |
1600 | } | |
1601 | } | |
1602 | ||
59334c2f JC |
1603 | ret = event - extra; |
1604 | if (ret < 0) { | |
cf2b4488 HP |
1605 | WL_ERROR(("==> Wrong size\n")); |
1606 | ret = 0; | |
1607 | } | |
1608 | WL_TRACE(("%s: size=%d bytes prepared\n", __func__, | |
1609 | (unsigned int)(event - extra))); | |
1610 | return (uint)ret; | |
1611 | } | |
1612 | ||
1613 | static int | |
1614 | wl_iw_get_scan(struct net_device *dev, | |
1615 | struct iw_request_info *info, struct iw_point *dwrq, char *extra) | |
1616 | { | |
1617 | channel_info_t ci; | |
1618 | wl_scan_results_t *list_merge; | |
1619 | wl_scan_results_t *list = (wl_scan_results_t *) g_scan; | |
1620 | int error; | |
1621 | uint buflen_from_user = dwrq->length; | |
1622 | uint len = G_SCAN_RESULTS; | |
1623 | __u16 len_ret = 0; | |
1624 | #if defined(WL_IW_USE_ISCAN) | |
1625 | iscan_info_t *iscan = g_iscan; | |
1626 | iscan_buf_t *p_buf; | |
1627 | #endif | |
1628 | ||
1629 | WL_TRACE(("%s: buflen_from_user %d: \n", dev->name, buflen_from_user)); | |
1630 | ||
1631 | if (!extra) { | |
1632 | WL_TRACE(("%s: wl_iw_get_scan return -EINVAL\n", dev->name)); | |
1633 | return -EINVAL; | |
1634 | } | |
1635 | ||
59334c2f JC |
1636 | error = dev_wlc_ioctl(dev, WLC_GET_CHANNEL, &ci, sizeof(ci)); |
1637 | if (error) | |
cf2b4488 HP |
1638 | return error; |
1639 | ci.scan_channel = dtoh32(ci.scan_channel); | |
1640 | if (ci.scan_channel) | |
1641 | return -EAGAIN; | |
1642 | ||
1643 | if (g_scan_specified_ssid) { | |
1644 | list = kmalloc(len, GFP_KERNEL); | |
1645 | if (!list) { | |
1646 | WL_TRACE(("%s: wl_iw_get_scan return -ENOMEM\n", | |
1647 | dev->name)); | |
1648 | g_scan_specified_ssid = 0; | |
1649 | return -ENOMEM; | |
1650 | } | |
1651 | } | |
1652 | ||
1653 | memset(list, 0, len); | |
1654 | list->buflen = htod32(len); | |
59334c2f JC |
1655 | error = dev_wlc_ioctl(dev, WLC_SCAN_RESULTS, list, len); |
1656 | if (error) { | |
cf2b4488 HP |
1657 | WL_ERROR(("%s: %s : Scan_results ERROR %d\n", dev->name, |
1658 | __func__, error)); | |
1659 | dwrq->length = len; | |
1660 | if (g_scan_specified_ssid) { | |
1661 | g_scan_specified_ssid = 0; | |
1662 | kfree(list); | |
1663 | } | |
1664 | return 0; | |
1665 | } | |
1666 | list->buflen = dtoh32(list->buflen); | |
1667 | list->version = dtoh32(list->version); | |
1668 | list->count = dtoh32(list->count); | |
1669 | ||
1670 | if (list->version != WL_BSS_INFO_VERSION) { | |
1671 | WL_ERROR(("%s : list->version %d != WL_BSS_INFO_VERSION\n", | |
1672 | __func__, list->version)); | |
1673 | if (g_scan_specified_ssid) { | |
1674 | g_scan_specified_ssid = 0; | |
1675 | kfree(list); | |
1676 | } | |
1677 | return -EINVAL; | |
1678 | } | |
1679 | ||
1680 | if (g_scan_specified_ssid) { | |
1681 | WL_TRACE(("%s: Specified scan APs in the list =%d\n", | |
1682 | __func__, list->count)); | |
1683 | len_ret = | |
1684 | (__u16) wl_iw_get_scan_prep(list, info, extra, | |
1685 | buflen_from_user); | |
1686 | kfree(list); | |
1687 | ||
1688 | #if defined(WL_IW_USE_ISCAN) | |
1689 | p_buf = iscan->list_hdr; | |
1690 | while (p_buf != iscan->list_cur) { | |
1691 | list_merge = | |
1692 | &((wl_iscan_results_t *) p_buf->iscan_buf)->results; | |
1693 | WL_TRACE(("%s: Bcast APs list=%d\n", __func__, | |
1694 | list_merge->count)); | |
1695 | if (list_merge->count > 0) | |
1696 | len_ret += | |
1697 | (__u16) wl_iw_get_scan_prep(list_merge, | |
1698 | info, extra + len_ret, | |
1699 | buflen_from_user - len_ret); | |
1700 | p_buf = p_buf->next; | |
1701 | } | |
1702 | #else | |
1703 | list_merge = (wl_scan_results_t *) g_scan; | |
1704 | WL_TRACE(("%s: Bcast APs list=%d\n", __func__, | |
1705 | list_merge->count)); | |
1706 | if (list_merge->count > 0) | |
1707 | len_ret += | |
1708 | (__u16) wl_iw_get_scan_prep(list_merge, info, | |
1709 | extra + len_ret, | |
1710 | buflen_from_user - | |
1711 | len_ret); | |
1712 | #endif /* defined(WL_IW_USE_ISCAN) */ | |
1713 | } else { | |
1714 | list = (wl_scan_results_t *) g_scan; | |
1715 | len_ret = | |
1716 | (__u16) wl_iw_get_scan_prep(list, info, extra, | |
1717 | buflen_from_user); | |
1718 | } | |
1719 | ||
1720 | #if defined(WL_IW_USE_ISCAN) | |
1721 | g_scan_specified_ssid = 0; | |
1722 | #endif | |
1723 | if ((len_ret + WE_ADD_EVENT_FIX) < buflen_from_user) | |
1724 | len = len_ret; | |
1725 | ||
1726 | dwrq->length = len; | |
1727 | dwrq->flags = 0; | |
1728 | ||
1729 | WL_TRACE(("%s return to WE %d bytes APs=%d\n", __func__, | |
1730 | dwrq->length, list->count)); | |
1731 | return 0; | |
1732 | } | |
1733 | ||
1734 | #if defined(WL_IW_USE_ISCAN) | |
1735 | static int | |
1736 | wl_iw_iscan_get_scan(struct net_device *dev, | |
1737 | struct iw_request_info *info, | |
1738 | struct iw_point *dwrq, char *extra) | |
1739 | { | |
1740 | wl_scan_results_t *list; | |
1741 | struct iw_event iwe; | |
1742 | wl_bss_info_t *bi = NULL; | |
1743 | int ii, j; | |
1744 | int apcnt; | |
1745 | char *event = extra, *end = extra + dwrq->length, *value; | |
1746 | iscan_info_t *iscan = g_iscan; | |
1747 | iscan_buf_t *p_buf; | |
1748 | uint32 counter = 0; | |
3fd79f7c | 1749 | u8 channel; |
cf2b4488 HP |
1750 | |
1751 | WL_TRACE(("%s %s buflen_from_user %d:\n", dev->name, __func__, | |
1752 | dwrq->length)); | |
1753 | ||
1754 | if (!extra) { | |
1755 | WL_TRACE(("%s: INVALID SIOCGIWSCAN GET bad parameter\n", | |
1756 | dev->name)); | |
1757 | return -EINVAL; | |
1758 | } | |
1759 | ||
1760 | if ((!iscan) || (iscan->sysioc_pid < 0)) { | |
1761 | WL_ERROR(("%ssysioc_pid\n", __func__)); | |
1762 | return wl_iw_get_scan(dev, info, dwrq, extra); | |
1763 | } | |
1764 | ||
1765 | if (iscan->iscan_state == ISCAN_STATE_SCANING) { | |
1766 | WL_TRACE(("%s: SIOCGIWSCAN GET still scanning\n", dev->name)); | |
1767 | return -EAGAIN; | |
1768 | } | |
1769 | ||
1770 | WL_TRACE(("%s: SIOCGIWSCAN GET broadcast results\n", dev->name)); | |
1771 | apcnt = 0; | |
1772 | p_buf = iscan->list_hdr; | |
1773 | while (p_buf != iscan->list_cur) { | |
1774 | list = &((wl_iscan_results_t *) p_buf->iscan_buf)->results; | |
1775 | ||
1776 | counter += list->count; | |
1777 | ||
1778 | if (list->version != WL_BSS_INFO_VERSION) { | |
1779 | WL_ERROR(("%s : list->version %d != " | |
1780 | "WL_BSS_INFO_VERSION\n", | |
1781 | __func__, list->version)); | |
1782 | return -EINVAL; | |
1783 | } | |
1784 | ||
1785 | bi = NULL; | |
1786 | for (ii = 0; ii < list->count && apcnt < IW_MAX_AP; | |
1787 | apcnt++, ii++) { | |
1788 | bi = bi ? (wl_bss_info_t *) ((uintptr) bi + | |
1789 | dtoh32(bi->length)) : | |
1790 | list->bss_info; | |
1791 | ASSERT(((uintptr) bi + dtoh32(bi->length)) <= | |
1792 | ((uintptr) list + WLC_IW_ISCAN_MAXLEN)); | |
1793 | ||
1794 | if (event + ETHER_ADDR_LEN + bi->SSID_len + | |
1795 | IW_EV_UINT_LEN + IW_EV_FREQ_LEN + IW_EV_QUAL_LEN >= | |
1796 | end) | |
1797 | return -E2BIG; | |
1798 | iwe.cmd = SIOCGIWAP; | |
1799 | iwe.u.ap_addr.sa_family = ARPHRD_ETHER; | |
1800 | memcpy(iwe.u.ap_addr.sa_data, &bi->BSSID, | |
1801 | ETHER_ADDR_LEN); | |
1802 | event = | |
1803 | IWE_STREAM_ADD_EVENT(info, event, end, &iwe, | |
1804 | IW_EV_ADDR_LEN); | |
1805 | ||
1806 | iwe.u.data.length = dtoh32(bi->SSID_len); | |
1807 | iwe.cmd = SIOCGIWESSID; | |
1808 | iwe.u.data.flags = 1; | |
1809 | event = | |
1810 | IWE_STREAM_ADD_POINT(info, event, end, &iwe, | |
1811 | bi->SSID); | |
1812 | ||
1813 | if (dtoh16(bi->capability) & | |
1814 | (DOT11_CAP_ESS | DOT11_CAP_IBSS)) { | |
1815 | iwe.cmd = SIOCGIWMODE; | |
1816 | if (dtoh16(bi->capability) & DOT11_CAP_ESS) | |
1817 | iwe.u.mode = IW_MODE_INFRA; | |
1818 | else | |
1819 | iwe.u.mode = IW_MODE_ADHOC; | |
1820 | event = | |
1821 | IWE_STREAM_ADD_EVENT(info, event, end, &iwe, | |
1822 | IW_EV_UINT_LEN); | |
1823 | } | |
1824 | ||
1825 | iwe.cmd = SIOCGIWFREQ; | |
1826 | channel = | |
1827 | (bi->ctl_ch == | |
1828 | 0) ? CHSPEC_CHANNEL(bi->chanspec) : bi->ctl_ch; | |
1829 | iwe.u.freq.m = | |
1830 | wf_channel2mhz(channel, | |
1831 | channel <= | |
1832 | CH_MAX_2G_CHANNEL ? | |
1833 | WF_CHAN_FACTOR_2_4_G : | |
1834 | WF_CHAN_FACTOR_5_G); | |
1835 | iwe.u.freq.e = 6; | |
1836 | event = | |
1837 | IWE_STREAM_ADD_EVENT(info, event, end, &iwe, | |
1838 | IW_EV_FREQ_LEN); | |
1839 | ||
1840 | iwe.cmd = IWEVQUAL; | |
1841 | iwe.u.qual.qual = rssi_to_qual(dtoh16(bi->RSSI)); | |
1842 | iwe.u.qual.level = 0x100 + dtoh16(bi->RSSI); | |
1843 | iwe.u.qual.noise = 0x100 + bi->phy_noise; | |
1844 | event = | |
1845 | IWE_STREAM_ADD_EVENT(info, event, end, &iwe, | |
1846 | IW_EV_QUAL_LEN); | |
1847 | ||
1848 | wl_iw_handle_scanresults_ies(&event, end, info, bi); | |
1849 | ||
1850 | iwe.cmd = SIOCGIWENCODE; | |
1851 | if (dtoh16(bi->capability) & DOT11_CAP_PRIVACY) | |
1852 | iwe.u.data.flags = | |
1853 | IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; | |
1854 | else | |
1855 | iwe.u.data.flags = IW_ENCODE_DISABLED; | |
1856 | iwe.u.data.length = 0; | |
1857 | event = | |
1858 | IWE_STREAM_ADD_POINT(info, event, end, &iwe, | |
1859 | (char *)event); | |
1860 | ||
1861 | if (bi->rateset.count) { | |
1862 | if (event + IW_MAX_BITRATES * IW_EV_PARAM_LEN >= | |
1863 | end) | |
1864 | return -E2BIG; | |
1865 | ||
1866 | value = event + IW_EV_LCP_LEN; | |
1867 | iwe.cmd = SIOCGIWRATE; | |
1868 | iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = | |
1869 | 0; | |
1870 | for (j = 0; | |
1871 | j < bi->rateset.count | |
1872 | && j < IW_MAX_BITRATES; j++) { | |
1873 | iwe.u.bitrate.value = | |
1874 | (bi->rateset.rates[j] & 0x7f) * | |
1875 | 500000; | |
1876 | value = | |
1877 | IWE_STREAM_ADD_VALUE(info, event, | |
1878 | value, end, | |
1879 | &iwe, | |
1880 | IW_EV_PARAM_LEN); | |
1881 | } | |
1882 | event = value; | |
1883 | } | |
1884 | } | |
1885 | p_buf = p_buf->next; | |
1886 | } | |
1887 | ||
1888 | dwrq->length = event - extra; | |
1889 | dwrq->flags = 0; | |
1890 | ||
1891 | WL_TRACE(("%s return to WE %d bytes APs=%d\n", __func__, | |
1892 | dwrq->length, counter)); | |
1893 | ||
1894 | if (!dwrq->length) | |
1895 | return -EAGAIN; | |
1896 | ||
1897 | return 0; | |
1898 | } | |
1899 | #endif /* defined(WL_IW_USE_ISCAN) */ | |
1900 | ||
1901 | static int | |
1902 | wl_iw_set_essid(struct net_device *dev, | |
1903 | struct iw_request_info *info, | |
1904 | struct iw_point *dwrq, char *extra) | |
1905 | { | |
1906 | int error; | |
1907 | wl_join_params_t join_params; | |
1908 | int join_params_size; | |
1909 | ||
1910 | WL_TRACE(("%s: SIOCSIWESSID\n", dev->name)); | |
1911 | ||
1912 | if (g_set_essid_before_scan) | |
1913 | return -EAGAIN; | |
1914 | ||
1915 | memset(&g_ssid, 0, sizeof(g_ssid)); | |
1916 | ||
1917 | CHECK_EXTRA_FOR_NULL(extra); | |
1918 | ||
1919 | if (dwrq->length && extra) { | |
1920 | #if WIRELESS_EXT > 20 | |
1921 | g_ssid.SSID_len = MIN(sizeof(g_ssid.SSID), dwrq->length); | |
1922 | #else | |
1923 | g_ssid.SSID_len = MIN(sizeof(g_ssid.SSID), dwrq->length - 1); | |
1924 | #endif | |
1925 | memcpy(g_ssid.SSID, extra, g_ssid.SSID_len); | |
1926 | } else { | |
1927 | g_ssid.SSID_len = 0; | |
1928 | } | |
1929 | g_ssid.SSID_len = htod32(g_ssid.SSID_len); | |
1930 | ||
1931 | memset(&join_params, 0, sizeof(join_params)); | |
1932 | join_params_size = sizeof(join_params.ssid); | |
1933 | ||
1934 | memcpy(&join_params.ssid.SSID, g_ssid.SSID, g_ssid.SSID_len); | |
1935 | join_params.ssid.SSID_len = htod32(g_ssid.SSID_len); | |
1936 | memcpy(&join_params.params.bssid, ðer_bcast, ETHER_ADDR_LEN); | |
1937 | ||
1938 | wl_iw_ch_to_chanspec(g_wl_iw_params.target_channel, &join_params, | |
1939 | &join_params_size); | |
1940 | ||
59334c2f JC |
1941 | error = dev_wlc_ioctl(dev, WLC_SET_SSID, &join_params, |
1942 | join_params_size); | |
1943 | if (error) | |
cf2b4488 HP |
1944 | WL_ERROR(("Invalid ioctl data=%d\n", error)); |
1945 | ||
1946 | if (g_ssid.SSID_len) { | |
1947 | WL_TRACE(("%s: join SSID=%s ch=%d\n", __func__, | |
1948 | g_ssid.SSID, g_wl_iw_params.target_channel)); | |
1949 | } | |
1950 | return 0; | |
1951 | } | |
1952 | ||
1953 | static int | |
1954 | wl_iw_get_essid(struct net_device *dev, | |
1955 | struct iw_request_info *info, | |
1956 | struct iw_point *dwrq, char *extra) | |
1957 | { | |
1958 | wlc_ssid_t ssid; | |
1959 | int error; | |
1960 | ||
1961 | WL_TRACE(("%s: SIOCGIWESSID\n", dev->name)); | |
1962 | ||
1963 | if (!extra) | |
1964 | return -EINVAL; | |
1965 | ||
59334c2f JC |
1966 | error = dev_wlc_ioctl(dev, WLC_GET_SSID, &ssid, sizeof(ssid)); |
1967 | if (error) { | |
cf2b4488 HP |
1968 | WL_ERROR(("Error getting the SSID\n")); |
1969 | return error; | |
1970 | } | |
1971 | ||
1972 | ssid.SSID_len = dtoh32(ssid.SSID_len); | |
1973 | ||
1974 | memcpy(extra, ssid.SSID, ssid.SSID_len); | |
1975 | ||
1976 | dwrq->length = ssid.SSID_len; | |
1977 | ||
1978 | dwrq->flags = 1; | |
1979 | ||
1980 | return 0; | |
1981 | } | |
1982 | ||
1983 | static int | |
1984 | wl_iw_set_nick(struct net_device *dev, | |
1985 | struct iw_request_info *info, struct iw_point *dwrq, char *extra) | |
1986 | { | |
1987 | wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); | |
1988 | ||
1989 | WL_TRACE(("%s: SIOCSIWNICKN\n", dev->name)); | |
1990 | ||
1991 | if (!extra) | |
1992 | return -EINVAL; | |
1993 | ||
1994 | if (dwrq->length > sizeof(iw->nickname)) | |
1995 | return -E2BIG; | |
1996 | ||
1997 | memcpy(iw->nickname, extra, dwrq->length); | |
1998 | iw->nickname[dwrq->length - 1] = '\0'; | |
1999 | ||
2000 | return 0; | |
2001 | } | |
2002 | ||
2003 | static int | |
2004 | wl_iw_get_nick(struct net_device *dev, | |
2005 | struct iw_request_info *info, struct iw_point *dwrq, char *extra) | |
2006 | { | |
2007 | wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); | |
2008 | ||
2009 | WL_TRACE(("%s: SIOCGIWNICKN\n", dev->name)); | |
2010 | ||
2011 | if (!extra) | |
2012 | return -EINVAL; | |
2013 | ||
2014 | strcpy(extra, iw->nickname); | |
2015 | dwrq->length = strlen(extra) + 1; | |
2016 | ||
2017 | return 0; | |
2018 | } | |
2019 | ||
2020 | static int | |
2021 | wl_iw_set_rate(struct net_device *dev, | |
2022 | struct iw_request_info *info, struct iw_param *vwrq, char *extra) | |
2023 | { | |
2024 | wl_rateset_t rateset; | |
2025 | int error, rate, i, error_bg, error_a; | |
2026 | ||
2027 | WL_TRACE(("%s: SIOCSIWRATE\n", dev->name)); | |
2028 | ||
59334c2f JC |
2029 | error = dev_wlc_ioctl(dev, WLC_GET_CURR_RATESET, &rateset, |
2030 | sizeof(rateset)); | |
2031 | if (error) | |
cf2b4488 HP |
2032 | return error; |
2033 | ||
2034 | rateset.count = dtoh32(rateset.count); | |
2035 | ||
2036 | if (vwrq->value < 0) | |
2037 | rate = rateset.rates[rateset.count - 1] & 0x7f; | |
2038 | else if (vwrq->value < rateset.count) | |
2039 | rate = rateset.rates[vwrq->value] & 0x7f; | |
2040 | else | |
2041 | rate = vwrq->value / 500000; | |
2042 | ||
2043 | if (vwrq->fixed) { | |
2044 | error_bg = dev_wlc_intvar_set(dev, "bg_rate", rate); | |
2045 | error_a = dev_wlc_intvar_set(dev, "a_rate", rate); | |
2046 | ||
2047 | if (error_bg && error_a) | |
2048 | return error_bg | error_a; | |
2049 | } else { | |
2050 | error_bg = dev_wlc_intvar_set(dev, "bg_rate", 0); | |
2051 | error_a = dev_wlc_intvar_set(dev, "a_rate", 0); | |
2052 | ||
2053 | if (error_bg && error_a) | |
2054 | return error_bg | error_a; | |
2055 | ||
2056 | for (i = 0; i < rateset.count; i++) | |
2057 | if ((rateset.rates[i] & 0x7f) > rate) | |
2058 | break; | |
2059 | rateset.count = htod32(i); | |
2060 | ||
59334c2f JC |
2061 | error = dev_wlc_ioctl(dev, WLC_SET_RATESET, &rateset, |
2062 | sizeof(rateset)); | |
2063 | if (error) | |
cf2b4488 HP |
2064 | return error; |
2065 | } | |
2066 | ||
2067 | return 0; | |
2068 | } | |
2069 | ||
2070 | static int | |
2071 | wl_iw_get_rate(struct net_device *dev, | |
2072 | struct iw_request_info *info, struct iw_param *vwrq, char *extra) | |
2073 | { | |
2074 | int error, rate; | |
2075 | ||
2076 | WL_TRACE(("%s: SIOCGIWRATE\n", dev->name)); | |
2077 | ||
59334c2f JC |
2078 | error = dev_wlc_ioctl(dev, WLC_GET_RATE, &rate, sizeof(rate)); |
2079 | if (error) | |
cf2b4488 HP |
2080 | return error; |
2081 | rate = dtoh32(rate); | |
2082 | vwrq->value = rate * 500000; | |
2083 | ||
2084 | return 0; | |
2085 | } | |
2086 | ||
2087 | static int | |
2088 | wl_iw_set_rts(struct net_device *dev, | |
2089 | struct iw_request_info *info, struct iw_param *vwrq, char *extra) | |
2090 | { | |
2091 | int error, rts; | |
2092 | ||
2093 | WL_TRACE(("%s: SIOCSIWRTS\n", dev->name)); | |
2094 | ||
2095 | if (vwrq->disabled) | |
2096 | rts = DOT11_DEFAULT_RTS_LEN; | |
2097 | else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_RTS_LEN) | |
2098 | return -EINVAL; | |
2099 | else | |
2100 | rts = vwrq->value; | |
2101 | ||
59334c2f JC |
2102 | error = dev_wlc_intvar_set(dev, "rtsthresh", rts); |
2103 | if (error) | |
cf2b4488 HP |
2104 | return error; |
2105 | ||
2106 | return 0; | |
2107 | } | |
2108 | ||
2109 | static int | |
2110 | wl_iw_get_rts(struct net_device *dev, | |
2111 | struct iw_request_info *info, struct iw_param *vwrq, char *extra) | |
2112 | { | |
2113 | int error, rts; | |
2114 | ||
2115 | WL_TRACE(("%s: SIOCGIWRTS\n", dev->name)); | |
2116 | ||
59334c2f JC |
2117 | error = dev_wlc_intvar_get(dev, "rtsthresh", &rts); |
2118 | if (error) | |
cf2b4488 HP |
2119 | return error; |
2120 | ||
2121 | vwrq->value = rts; | |
2122 | vwrq->disabled = (rts >= DOT11_DEFAULT_RTS_LEN); | |
2123 | vwrq->fixed = 1; | |
2124 | ||
2125 | return 0; | |
2126 | } | |
2127 | ||
2128 | static int | |
2129 | wl_iw_set_frag(struct net_device *dev, | |
2130 | struct iw_request_info *info, struct iw_param *vwrq, char *extra) | |
2131 | { | |
2132 | int error, frag; | |
2133 | ||
2134 | WL_TRACE(("%s: SIOCSIWFRAG\n", dev->name)); | |
2135 | ||
2136 | if (vwrq->disabled) | |
2137 | frag = DOT11_DEFAULT_FRAG_LEN; | |
2138 | else if (vwrq->value < 0 || vwrq->value > DOT11_DEFAULT_FRAG_LEN) | |
2139 | return -EINVAL; | |
2140 | else | |
2141 | frag = vwrq->value; | |
2142 | ||
59334c2f JC |
2143 | error = dev_wlc_intvar_set(dev, "fragthresh", frag); |
2144 | if (error) | |
cf2b4488 HP |
2145 | return error; |
2146 | ||
2147 | return 0; | |
2148 | } | |
2149 | ||
2150 | static int | |
2151 | wl_iw_get_frag(struct net_device *dev, | |
2152 | struct iw_request_info *info, struct iw_param *vwrq, char *extra) | |
2153 | { | |
2154 | int error, fragthreshold; | |
2155 | ||
2156 | WL_TRACE(("%s: SIOCGIWFRAG\n", dev->name)); | |
2157 | ||
59334c2f JC |
2158 | error = dev_wlc_intvar_get(dev, "fragthresh", &fragthreshold); |
2159 | if (error) | |
cf2b4488 HP |
2160 | return error; |
2161 | ||
2162 | vwrq->value = fragthreshold; | |
2163 | vwrq->disabled = (fragthreshold >= DOT11_DEFAULT_FRAG_LEN); | |
2164 | vwrq->fixed = 1; | |
2165 | ||
2166 | return 0; | |
2167 | } | |
2168 | ||
2169 | static int | |
2170 | wl_iw_set_txpow(struct net_device *dev, | |
2171 | struct iw_request_info *info, | |
2172 | struct iw_param *vwrq, char *extra) | |
2173 | { | |
2174 | int error, disable; | |
7d4df48e | 2175 | u16 txpwrmw; |
cf2b4488 HP |
2176 | WL_TRACE(("%s: SIOCSIWTXPOW\n", dev->name)); |
2177 | ||
2178 | disable = vwrq->disabled ? WL_RADIO_SW_DISABLE : 0; | |
2179 | disable += WL_RADIO_SW_DISABLE << 16; | |
2180 | ||
2181 | disable = htod32(disable); | |
59334c2f JC |
2182 | error = dev_wlc_ioctl(dev, WLC_SET_RADIO, &disable, sizeof(disable)); |
2183 | if (error) | |
cf2b4488 HP |
2184 | return error; |
2185 | ||
2186 | if (disable & WL_RADIO_SW_DISABLE) | |
2187 | return 0; | |
2188 | ||
2189 | if (!(vwrq->flags & IW_TXPOW_MWATT)) | |
2190 | return -EINVAL; | |
2191 | ||
2192 | if (vwrq->value < 0) | |
2193 | return 0; | |
2194 | ||
2195 | if (vwrq->value > 0xffff) | |
2196 | txpwrmw = 0xffff; | |
2197 | else | |
7d4df48e | 2198 | txpwrmw = (u16) vwrq->value; |
cf2b4488 HP |
2199 | |
2200 | error = | |
2201 | dev_wlc_intvar_set(dev, "qtxpower", (int)(bcm_mw_to_qdbm(txpwrmw))); | |
2202 | return error; | |
2203 | } | |
2204 | ||
2205 | static int | |
2206 | wl_iw_get_txpow(struct net_device *dev, | |
2207 | struct iw_request_info *info, | |
2208 | struct iw_param *vwrq, char *extra) | |
2209 | { | |
2210 | int error, disable, txpwrdbm; | |
3fd79f7c | 2211 | u8 result; |
cf2b4488 HP |
2212 | |
2213 | WL_TRACE(("%s: SIOCGIWTXPOW\n", dev->name)); | |
2214 | ||
59334c2f JC |
2215 | error = dev_wlc_ioctl(dev, WLC_GET_RADIO, &disable, sizeof(disable)); |
2216 | if (error) | |
2217 | return error; | |
2218 | ||
2219 | error = dev_wlc_intvar_get(dev, "qtxpower", &txpwrdbm); | |
2220 | if (error) | |
cf2b4488 HP |
2221 | return error; |
2222 | ||
2223 | disable = dtoh32(disable); | |
3fd79f7c | 2224 | result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE); |
cf2b4488 HP |
2225 | vwrq->value = (int32) bcm_qdbm_to_mw(result); |
2226 | vwrq->fixed = 0; | |
2227 | vwrq->disabled = | |
2228 | (disable & (WL_RADIO_SW_DISABLE | WL_RADIO_HW_DISABLE)) ? 1 : 0; | |
2229 | vwrq->flags = IW_TXPOW_MWATT; | |
2230 | ||
2231 | return 0; | |
2232 | } | |
2233 | ||
2234 | #if WIRELESS_EXT > 10 | |
2235 | static int | |
2236 | wl_iw_set_retry(struct net_device *dev, | |
2237 | struct iw_request_info *info, | |
2238 | struct iw_param *vwrq, char *extra) | |
2239 | { | |
2240 | int error, lrl, srl; | |
2241 | ||
2242 | WL_TRACE(("%s: SIOCSIWRETRY\n", dev->name)); | |
2243 | ||
2244 | if (vwrq->disabled || (vwrq->flags & IW_RETRY_LIFETIME)) | |
2245 | return -EINVAL; | |
2246 | ||
2247 | if (vwrq->flags & IW_RETRY_LIMIT) { | |
2248 | ||
2249 | #if WIRELESS_EXT > 20 | |
2250 | if ((vwrq->flags & IW_RETRY_LONG) | |
2251 | || (vwrq->flags & IW_RETRY_MAX) | |
2252 | || !((vwrq->flags & IW_RETRY_SHORT) | |
2253 | || (vwrq->flags & IW_RETRY_MIN))) { | |
2254 | #else | |
2255 | if ((vwrq->flags & IW_RETRY_MAX) | |
2256 | || !(vwrq->flags & IW_RETRY_MIN)) { | |
2257 | #endif | |
2258 | lrl = htod32(vwrq->value); | |
59334c2f JC |
2259 | error = dev_wlc_ioctl(dev, WLC_SET_LRL, &lrl, |
2260 | sizeof(lrl)); | |
2261 | if (error) | |
cf2b4488 HP |
2262 | return error; |
2263 | } | |
2264 | #if WIRELESS_EXT > 20 | |
2265 | if ((vwrq->flags & IW_RETRY_SHORT) | |
2266 | || (vwrq->flags & IW_RETRY_MIN) | |
2267 | || !((vwrq->flags & IW_RETRY_LONG) | |
2268 | || (vwrq->flags & IW_RETRY_MAX))) { | |
2269 | #else | |
2270 | if ((vwrq->flags & IW_RETRY_MIN) | |
2271 | || !(vwrq->flags & IW_RETRY_MAX)) { | |
2272 | #endif | |
2273 | srl = htod32(vwrq->value); | |
59334c2f JC |
2274 | error = dev_wlc_ioctl(dev, WLC_SET_SRL, &srl, |
2275 | sizeof(srl)); | |
2276 | if (error) | |
cf2b4488 HP |
2277 | return error; |
2278 | } | |
2279 | } | |
2280 | return 0; | |
2281 | } | |
2282 | ||
2283 | static int | |
2284 | wl_iw_get_retry(struct net_device *dev, | |
2285 | struct iw_request_info *info, | |
2286 | struct iw_param *vwrq, char *extra) | |
2287 | { | |
2288 | int error, lrl, srl; | |
2289 | ||
2290 | WL_TRACE(("%s: SIOCGIWRETRY\n", dev->name)); | |
2291 | ||
2292 | vwrq->disabled = 0; | |
2293 | ||
2294 | if ((vwrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) | |
2295 | return -EINVAL; | |
2296 | ||
59334c2f JC |
2297 | error = dev_wlc_ioctl(dev, WLC_GET_LRL, &lrl, sizeof(lrl)); |
2298 | if (error) | |
2299 | return error; | |
2300 | ||
2301 | error = dev_wlc_ioctl(dev, WLC_GET_SRL, &srl, sizeof(srl)); | |
2302 | if (error) | |
cf2b4488 HP |
2303 | return error; |
2304 | ||
2305 | lrl = dtoh32(lrl); | |
2306 | srl = dtoh32(srl); | |
2307 | ||
2308 | if (vwrq->flags & IW_RETRY_MAX) { | |
2309 | vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX; | |
2310 | vwrq->value = lrl; | |
2311 | } else { | |
2312 | vwrq->flags = IW_RETRY_LIMIT; | |
2313 | vwrq->value = srl; | |
2314 | if (srl != lrl) | |
2315 | vwrq->flags |= IW_RETRY_MIN; | |
2316 | } | |
2317 | ||
2318 | return 0; | |
2319 | } | |
2320 | #endif /* WIRELESS_EXT > 10 */ | |
2321 | ||
2322 | static int | |
2323 | wl_iw_set_encode(struct net_device *dev, | |
2324 | struct iw_request_info *info, | |
2325 | struct iw_point *dwrq, char *extra) | |
2326 | { | |
2327 | wl_wsec_key_t key; | |
2328 | int error, val, wsec; | |
2329 | ||
2330 | WL_TRACE(("%s: SIOCSIWENCODE\n", dev->name)); | |
2331 | ||
2332 | memset(&key, 0, sizeof(key)); | |
2333 | ||
2334 | if ((dwrq->flags & IW_ENCODE_INDEX) == 0) { | |
2335 | for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; | |
2336 | key.index++) { | |
2337 | val = htod32(key.index); | |
59334c2f JC |
2338 | error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, |
2339 | sizeof(val)); | |
2340 | if (error) | |
cf2b4488 HP |
2341 | return error; |
2342 | val = dtoh32(val); | |
2343 | if (val) | |
2344 | break; | |
2345 | } | |
2346 | if (key.index == DOT11_MAX_DEFAULT_KEYS) | |
2347 | key.index = 0; | |
2348 | } else { | |
2349 | key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | |
2350 | if (key.index >= DOT11_MAX_DEFAULT_KEYS) | |
2351 | return -EINVAL; | |
2352 | } | |
2353 | ||
2354 | if (!extra || !dwrq->length || (dwrq->flags & IW_ENCODE_NOKEY)) { | |
2355 | val = htod32(key.index); | |
59334c2f JC |
2356 | error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, &val, |
2357 | sizeof(val)); | |
2358 | if (error) | |
cf2b4488 HP |
2359 | return error; |
2360 | } else { | |
2361 | key.len = dwrq->length; | |
2362 | ||
2363 | if (dwrq->length > sizeof(key.data)) | |
2364 | return -EINVAL; | |
2365 | ||
2366 | memcpy(key.data, extra, dwrq->length); | |
2367 | ||
2368 | key.flags = WL_PRIMARY_KEY; | |
2369 | switch (key.len) { | |
2370 | case WEP1_KEY_SIZE: | |
2371 | key.algo = CRYPTO_ALGO_WEP1; | |
2372 | break; | |
2373 | case WEP128_KEY_SIZE: | |
2374 | key.algo = CRYPTO_ALGO_WEP128; | |
2375 | break; | |
2376 | case TKIP_KEY_SIZE: | |
2377 | key.algo = CRYPTO_ALGO_TKIP; | |
2378 | break; | |
2379 | case AES_KEY_SIZE: | |
2380 | key.algo = CRYPTO_ALGO_AES_CCM; | |
2381 | break; | |
2382 | default: | |
2383 | return -EINVAL; | |
2384 | } | |
2385 | ||
2386 | swap_key_from_BE(&key); | |
59334c2f JC |
2387 | error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)); |
2388 | if (error) | |
cf2b4488 HP |
2389 | return error; |
2390 | } | |
2391 | ||
2392 | val = (dwrq->flags & IW_ENCODE_DISABLED) ? 0 : WEP_ENABLED; | |
2393 | ||
59334c2f JC |
2394 | error = dev_wlc_intvar_get(dev, "wsec", &wsec); |
2395 | if (error) | |
cf2b4488 HP |
2396 | return error; |
2397 | ||
2398 | wsec &= ~(WEP_ENABLED); | |
2399 | wsec |= val; | |
2400 | ||
59334c2f JC |
2401 | error = dev_wlc_intvar_set(dev, "wsec", wsec); |
2402 | if (error) | |
cf2b4488 HP |
2403 | return error; |
2404 | ||
2405 | val = (dwrq->flags & IW_ENCODE_RESTRICTED) ? 1 : 0; | |
2406 | val = htod32(val); | |
59334c2f JC |
2407 | error = dev_wlc_ioctl(dev, WLC_SET_AUTH, &val, sizeof(val)); |
2408 | if (error) | |
cf2b4488 HP |
2409 | return error; |
2410 | ||
2411 | return 0; | |
2412 | } | |
2413 | ||
2414 | static int | |
2415 | wl_iw_get_encode(struct net_device *dev, | |
2416 | struct iw_request_info *info, | |
2417 | struct iw_point *dwrq, char *extra) | |
2418 | { | |
2419 | wl_wsec_key_t key; | |
2420 | int error, val, wsec, auth; | |
2421 | ||
2422 | WL_TRACE(("%s: SIOCGIWENCODE\n", dev->name)); | |
2423 | ||
2424 | bzero(&key, sizeof(wl_wsec_key_t)); | |
2425 | ||
2426 | if ((dwrq->flags & IW_ENCODE_INDEX) == 0) { | |
2427 | for (key.index = 0; key.index < DOT11_MAX_DEFAULT_KEYS; | |
2428 | key.index++) { | |
2429 | val = key.index; | |
59334c2f JC |
2430 | error = dev_wlc_ioctl(dev, WLC_GET_KEY_PRIMARY, &val, |
2431 | sizeof(val)); | |
2432 | if (error) | |
cf2b4488 HP |
2433 | return error; |
2434 | val = dtoh32(val); | |
2435 | if (val) | |
2436 | break; | |
2437 | } | |
2438 | } else | |
2439 | key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | |
2440 | ||
2441 | if (key.index >= DOT11_MAX_DEFAULT_KEYS) | |
2442 | key.index = 0; | |
2443 | ||
59334c2f JC |
2444 | error = dev_wlc_ioctl(dev, WLC_GET_WSEC, &wsec, sizeof(wsec)); |
2445 | if (error) | |
2446 | return error; | |
2447 | ||
2448 | error = dev_wlc_ioctl(dev, WLC_GET_AUTH, &auth, sizeof(auth)); | |
2449 | if (error) | |
cf2b4488 HP |
2450 | return error; |
2451 | ||
2452 | swap_key_to_BE(&key); | |
2453 | ||
2454 | wsec = dtoh32(wsec); | |
2455 | auth = dtoh32(auth); | |
2456 | dwrq->length = MIN(DOT11_MAX_KEY_SIZE, key.len); | |
2457 | ||
2458 | dwrq->flags = key.index + 1; | |
2459 | if (!(wsec & (WEP_ENABLED | TKIP_ENABLED | AES_ENABLED))) | |
2460 | dwrq->flags |= IW_ENCODE_DISABLED; | |
2461 | ||
2462 | if (auth) | |
2463 | dwrq->flags |= IW_ENCODE_RESTRICTED; | |
2464 | ||
2465 | if (dwrq->length && extra) | |
2466 | memcpy(extra, key.data, dwrq->length); | |
2467 | ||
2468 | return 0; | |
2469 | } | |
2470 | ||
2471 | static int | |
2472 | wl_iw_set_power(struct net_device *dev, | |
2473 | struct iw_request_info *info, | |
2474 | struct iw_param *vwrq, char *extra) | |
2475 | { | |
2476 | int error, pm; | |
2477 | ||
2478 | WL_TRACE(("%s: SIOCSIWPOWER\n", dev->name)); | |
2479 | ||
2480 | pm = vwrq->disabled ? PM_OFF : PM_MAX; | |
2481 | ||
2482 | pm = htod32(pm); | |
59334c2f JC |
2483 | error = dev_wlc_ioctl(dev, WLC_SET_PM, &pm, sizeof(pm)); |
2484 | if (error) | |
cf2b4488 HP |
2485 | return error; |
2486 | ||
2487 | return 0; | |
2488 | } | |
2489 | ||
2490 | static int | |
2491 | wl_iw_get_power(struct net_device *dev, | |
2492 | struct iw_request_info *info, | |
2493 | struct iw_param *vwrq, char *extra) | |
2494 | { | |
2495 | int error, pm; | |
2496 | ||
2497 | WL_TRACE(("%s: SIOCGIWPOWER\n", dev->name)); | |
2498 | ||
59334c2f JC |
2499 | error = dev_wlc_ioctl(dev, WLC_GET_PM, &pm, sizeof(pm)); |
2500 | if (error) | |
cf2b4488 HP |
2501 | return error; |
2502 | ||
2503 | pm = dtoh32(pm); | |
2504 | vwrq->disabled = pm ? 0 : 1; | |
2505 | vwrq->flags = IW_POWER_ALL_R; | |
2506 | ||
2507 | return 0; | |
2508 | } | |
2509 | ||
2510 | #if WIRELESS_EXT > 17 | |
2511 | static int | |
2512 | wl_iw_set_wpaie(struct net_device *dev, | |
2513 | struct iw_request_info *info, struct iw_point *iwp, char *extra) | |
2514 | { | |
2515 | ||
2516 | WL_TRACE(("%s: SIOCSIWGENIE\n", dev->name)); | |
2517 | ||
2518 | CHECK_EXTRA_FOR_NULL(extra); | |
2519 | ||
2520 | dev_wlc_bufvar_set(dev, "wpaie", extra, iwp->length); | |
2521 | ||
2522 | return 0; | |
2523 | } | |
2524 | ||
2525 | static int | |
2526 | wl_iw_get_wpaie(struct net_device *dev, | |
2527 | struct iw_request_info *info, struct iw_point *iwp, char *extra) | |
2528 | { | |
2529 | WL_TRACE(("%s: SIOCGIWGENIE\n", dev->name)); | |
2530 | iwp->length = 64; | |
2531 | dev_wlc_bufvar_get(dev, "wpaie", extra, iwp->length); | |
2532 | return 0; | |
2533 | } | |
2534 | ||
2535 | static int | |
2536 | wl_iw_set_encodeext(struct net_device *dev, | |
2537 | struct iw_request_info *info, | |
2538 | struct iw_point *dwrq, char *extra) | |
2539 | { | |
2540 | wl_wsec_key_t key; | |
2541 | int error; | |
2542 | struct iw_encode_ext *iwe; | |
2543 | ||
2544 | WL_TRACE(("%s: SIOCSIWENCODEEXT\n", dev->name)); | |
2545 | ||
2546 | CHECK_EXTRA_FOR_NULL(extra); | |
2547 | ||
2548 | memset(&key, 0, sizeof(key)); | |
2549 | iwe = (struct iw_encode_ext *)extra; | |
2550 | ||
2551 | if (dwrq->flags & IW_ENCODE_DISABLED) { | |
2552 | ||
2553 | } | |
2554 | ||
2555 | key.index = 0; | |
2556 | if (dwrq->flags & IW_ENCODE_INDEX) | |
2557 | key.index = (dwrq->flags & IW_ENCODE_INDEX) - 1; | |
2558 | ||
2559 | key.len = iwe->key_len; | |
2560 | ||
2561 | if (!ETHER_ISMULTI(iwe->addr.sa_data)) | |
2562 | bcopy((void *)&iwe->addr.sa_data, (char *)&key.ea, | |
2563 | ETHER_ADDR_LEN); | |
2564 | ||
2565 | if (key.len == 0) { | |
2566 | if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { | |
2567 | WL_WSEC(("Changing the the primary Key to %d\n", | |
2568 | key.index)); | |
2569 | key.index = htod32(key.index); | |
2570 | error = dev_wlc_ioctl(dev, WLC_SET_KEY_PRIMARY, | |
2571 | &key.index, sizeof(key.index)); | |
2572 | if (error) | |
2573 | return error; | |
2574 | } else { | |
2575 | swap_key_from_BE(&key); | |
2576 | dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)); | |
2577 | } | |
2578 | } else { | |
2579 | if (iwe->key_len > sizeof(key.data)) | |
2580 | return -EINVAL; | |
2581 | ||
2582 | WL_WSEC(("Setting the key index %d\n", key.index)); | |
2583 | if (iwe->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { | |
2584 | WL_WSEC(("key is a Primary Key\n")); | |
2585 | key.flags = WL_PRIMARY_KEY; | |
2586 | } | |
2587 | ||
2588 | bcopy((void *)iwe->key, key.data, iwe->key_len); | |
2589 | ||
2590 | if (iwe->alg == IW_ENCODE_ALG_TKIP) { | |
3fd79f7c | 2591 | u8 keybuf[8]; |
cf2b4488 HP |
2592 | bcopy(&key.data[24], keybuf, sizeof(keybuf)); |
2593 | bcopy(&key.data[16], &key.data[24], sizeof(keybuf)); | |
2594 | bcopy(keybuf, &key.data[16], sizeof(keybuf)); | |
2595 | } | |
2596 | ||
2597 | if (iwe->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { | |
580a0bd9 GKH |
2598 | unsigned char *ivptr; |
2599 | ivptr = (unsigned char *) iwe->rx_seq; | |
cf2b4488 HP |
2600 | key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) | |
2601 | (ivptr[3] << 8) | ivptr[2]; | |
2602 | key.rxiv.lo = (ivptr[1] << 8) | ivptr[0]; | |
2603 | key.iv_initialized = TRUE; | |
2604 | } | |
2605 | ||
2606 | switch (iwe->alg) { | |
2607 | case IW_ENCODE_ALG_NONE: | |
2608 | key.algo = CRYPTO_ALGO_OFF; | |
2609 | break; | |
2610 | case IW_ENCODE_ALG_WEP: | |
2611 | if (iwe->key_len == WEP1_KEY_SIZE) | |
2612 | key.algo = CRYPTO_ALGO_WEP1; | |
2613 | else | |
2614 | key.algo = CRYPTO_ALGO_WEP128; | |
2615 | break; | |
2616 | case IW_ENCODE_ALG_TKIP: | |
2617 | key.algo = CRYPTO_ALGO_TKIP; | |
2618 | break; | |
2619 | case IW_ENCODE_ALG_CCMP: | |
2620 | key.algo = CRYPTO_ALGO_AES_CCM; | |
2621 | break; | |
2622 | default: | |
2623 | break; | |
2624 | } | |
2625 | swap_key_from_BE(&key); | |
2626 | ||
2627 | dhd_wait_pend8021x(dev); | |
2628 | ||
2629 | error = dev_wlc_ioctl(dev, WLC_SET_KEY, &key, sizeof(key)); | |
2630 | if (error) | |
2631 | return error; | |
2632 | } | |
2633 | return 0; | |
2634 | } | |
2635 | ||
2636 | #if WIRELESS_EXT > 17 | |
2637 | #ifdef BCMWPA2 | |
2638 | struct { | |
2639 | pmkid_list_t pmkids; | |
2640 | pmkid_t foo[MAXPMKID - 1]; | |
2641 | } pmkid_list; | |
2642 | ||
2643 | static int | |
2644 | wl_iw_set_pmksa(struct net_device *dev, | |
2645 | struct iw_request_info *info, | |
2646 | struct iw_param *vwrq, char *extra) | |
2647 | { | |
2648 | struct iw_pmksa *iwpmksa; | |
2649 | uint i; | |
2650 | int ret = 0; | |
2651 | char eabuf[ETHER_ADDR_STR_LEN]; | |
2652 | ||
2653 | WL_WSEC(("%s: SIOCSIWPMKSA\n", dev->name)); | |
2654 | ||
2655 | CHECK_EXTRA_FOR_NULL(extra); | |
2656 | ||
2657 | iwpmksa = (struct iw_pmksa *)extra; | |
2658 | bzero((char *)eabuf, ETHER_ADDR_STR_LEN); | |
2659 | ||
2660 | if (iwpmksa->cmd == IW_PMKSA_FLUSH) { | |
2661 | WL_WSEC(("wl_iw_set_pmksa - IW_PMKSA_FLUSH\n")); | |
2662 | bzero((char *)&pmkid_list, sizeof(pmkid_list)); | |
2663 | } | |
2664 | ||
2665 | else if (iwpmksa->cmd == IW_PMKSA_REMOVE) { | |
2666 | { | |
2667 | pmkid_list_t pmkid, *pmkidptr; | |
2668 | uint j; | |
2669 | pmkidptr = &pmkid; | |
2670 | ||
2671 | bcopy(&iwpmksa->bssid.sa_data[0], | |
2672 | &pmkidptr->pmkid[0].BSSID, ETHER_ADDR_LEN); | |
2673 | bcopy(&iwpmksa->pmkid[0], &pmkidptr->pmkid[0].PMKID, | |
2674 | WPA2_PMKID_LEN); | |
2675 | ||
2676 | WL_WSEC(("wl_iw_set_pmksa:IW_PMKSA_REMOVE:PMKID: %s = ", | |
2677 | bcm_ether_ntoa(&pmkidptr->pmkid[0].BSSID, eabuf))); | |
2678 | for (j = 0; j < WPA2_PMKID_LEN; j++) | |
2679 | WL_WSEC(("%02x ", pmkidptr->pmkid[0].PMKID[j])); | |
2680 | WL_WSEC(("\n")); | |
2681 | } | |
2682 | ||
2683 | for (i = 0; i < pmkid_list.pmkids.npmkid; i++) | |
2684 | if (!bcmp | |
2685 | (&iwpmksa->bssid.sa_data[0], | |
2686 | &pmkid_list.pmkids.pmkid[i].BSSID, ETHER_ADDR_LEN)) | |
2687 | break; | |
2688 | ||
2689 | if ((pmkid_list.pmkids.npmkid > 0) | |
2690 | && (i < pmkid_list.pmkids.npmkid)) { | |
2691 | bzero(&pmkid_list.pmkids.pmkid[i], sizeof(pmkid_t)); | |
2692 | for (; i < (pmkid_list.pmkids.npmkid - 1); i++) { | |
2693 | bcopy(&pmkid_list.pmkids.pmkid[i + 1].BSSID, | |
2694 | &pmkid_list.pmkids.pmkid[i].BSSID, | |
2695 | ETHER_ADDR_LEN); | |
2696 | bcopy(&pmkid_list.pmkids.pmkid[i + 1].PMKID, | |
2697 | &pmkid_list.pmkids.pmkid[i].PMKID, | |
2698 | WPA2_PMKID_LEN); | |
2699 | } | |
2700 | pmkid_list.pmkids.npmkid--; | |
2701 | } else | |
2702 | ret = -EINVAL; | |
2703 | } | |
2704 | ||
2705 | else if (iwpmksa->cmd == IW_PMKSA_ADD) { | |
2706 | for (i = 0; i < pmkid_list.pmkids.npmkid; i++) | |
2707 | if (!bcmp | |
2708 | (&iwpmksa->bssid.sa_data[0], | |
2709 | &pmkid_list.pmkids.pmkid[i].BSSID, ETHER_ADDR_LEN)) | |
2710 | break; | |
2711 | if (i < MAXPMKID) { | |
2712 | bcopy(&iwpmksa->bssid.sa_data[0], | |
2713 | &pmkid_list.pmkids.pmkid[i].BSSID, | |
2714 | ETHER_ADDR_LEN); | |
2715 | bcopy(&iwpmksa->pmkid[0], | |
2716 | &pmkid_list.pmkids.pmkid[i].PMKID, | |
2717 | WPA2_PMKID_LEN); | |
2718 | if (i == pmkid_list.pmkids.npmkid) | |
2719 | pmkid_list.pmkids.npmkid++; | |
2720 | } else | |
2721 | ret = -EINVAL; | |
2722 | { | |
2723 | uint j; | |
2724 | uint k; | |
2725 | k = pmkid_list.pmkids.npmkid; | |
2726 | WL_WSEC(("wl_iw_set_pmksa,IW_PMKSA_ADD - PMKID: %s = ", | |
2727 | bcm_ether_ntoa(&pmkid_list.pmkids.pmkid[k]. | |
2728 | BSSID, eabuf))); | |
2729 | for (j = 0; j < WPA2_PMKID_LEN; j++) | |
2730 | WL_WSEC(("%02x ", | |
2731 | pmkid_list.pmkids.pmkid[k].PMKID[j])); | |
2732 | WL_WSEC(("\n")); | |
2733 | } | |
2734 | } | |
2735 | WL_WSEC(("PRINTING pmkid LIST - No of elements %d\n", | |
2736 | pmkid_list.pmkids.npmkid)); | |
2737 | for (i = 0; i < pmkid_list.pmkids.npmkid; i++) { | |
2738 | uint j; | |
2739 | WL_WSEC(("PMKID[%d]: %s = ", i, | |
2740 | bcm_ether_ntoa(&pmkid_list.pmkids.pmkid[i].BSSID, | |
2741 | eabuf))); | |
2742 | for (j = 0; j < WPA2_PMKID_LEN; j++) | |
2743 | WL_WSEC(("%02x ", pmkid_list.pmkids.pmkid[i].PMKID[j])); | |
2744 | WL_WSEC(("\n")); | |
2745 | } | |
2746 | WL_WSEC(("\n")); | |
2747 | ||
2748 | if (!ret) | |
2749 | ret = dev_wlc_bufvar_set(dev, "pmkid_info", (char *)&pmkid_list, | |
2750 | sizeof(pmkid_list)); | |
2751 | return ret; | |
2752 | } | |
2753 | #endif /* BCMWPA2 */ | |
2754 | #endif /* WIRELESS_EXT > 17 */ | |
2755 | ||
2756 | static int | |
2757 | wl_iw_get_encodeext(struct net_device *dev, | |
2758 | struct iw_request_info *info, | |
2759 | struct iw_param *vwrq, char *extra) | |
2760 | { | |
2761 | WL_TRACE(("%s: SIOCGIWENCODEEXT\n", dev->name)); | |
2762 | return 0; | |
2763 | } | |
2764 | ||
2765 | static int | |
2766 | wl_iw_set_wpaauth(struct net_device *dev, | |
2767 | struct iw_request_info *info, | |
2768 | struct iw_param *vwrq, char *extra) | |
2769 | { | |
2770 | int error = 0; | |
2771 | int paramid; | |
2772 | int paramval; | |
2773 | int val = 0; | |
2774 | wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); | |
2775 | ||
2776 | WL_TRACE(("%s: SIOCSIWAUTH\n", dev->name)); | |
2777 | ||
2778 | paramid = vwrq->flags & IW_AUTH_INDEX; | |
2779 | paramval = vwrq->value; | |
2780 | ||
2781 | WL_TRACE(("%s: SIOCSIWAUTH, paramid = 0x%0x, paramval = 0x%0x\n", | |
2782 | dev->name, paramid, paramval)); | |
2783 | ||
2784 | switch (paramid) { | |
2785 | case IW_AUTH_WPA_VERSION: | |
2786 | if (paramval & IW_AUTH_WPA_VERSION_DISABLED) | |
2787 | val = WPA_AUTH_DISABLED; | |
2788 | else if (paramval & (IW_AUTH_WPA_VERSION_WPA)) | |
2789 | val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED; | |
2790 | #ifdef BCMWPA2 | |
2791 | else if (paramval & IW_AUTH_WPA_VERSION_WPA2) | |
2792 | val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED; | |
2793 | #endif | |
2794 | WL_INFORM(("%s: %d: setting wpa_auth to 0x%0x\n", __func__, | |
2795 | __LINE__, val)); | |
59334c2f JC |
2796 | error = dev_wlc_intvar_set(dev, "wpa_auth", val); |
2797 | if (error) | |
cf2b4488 HP |
2798 | return error; |
2799 | break; | |
2800 | case IW_AUTH_CIPHER_PAIRWISE: | |
2801 | case IW_AUTH_CIPHER_GROUP: | |
2802 | if (paramval & (IW_AUTH_CIPHER_WEP40 | IW_AUTH_CIPHER_WEP104)) | |
2803 | val = WEP_ENABLED; | |
2804 | if (paramval & IW_AUTH_CIPHER_TKIP) | |
2805 | val = TKIP_ENABLED; | |
2806 | if (paramval & IW_AUTH_CIPHER_CCMP) | |
2807 | val = AES_ENABLED; | |
2808 | ||
2809 | if (paramid == IW_AUTH_CIPHER_PAIRWISE) { | |
2810 | iw->pwsec = val; | |
2811 | val |= iw->gwsec; | |
2812 | } else { | |
2813 | iw->gwsec = val; | |
2814 | val |= iw->pwsec; | |
2815 | } | |
2816 | ||
2817 | if (iw->privacy_invoked && !val) { | |
2818 | WL_WSEC(("%s: %s: 'Privacy invoked' TRUE but clearing " | |
2819 | "wsec, assuming " "we're a WPS enrollee\n", | |
2820 | dev->name, __func__)); | |
59334c2f JC |
2821 | error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", |
2822 | TRUE); | |
2823 | if (error) { | |
cf2b4488 HP |
2824 | WL_WSEC(("Failed to set is_WPS_enrollee\n")); |
2825 | return error; | |
2826 | } | |
2827 | } else if (val) { | |
59334c2f JC |
2828 | error = dev_wlc_intvar_set(dev, "is_WPS_enrollee", |
2829 | FALSE); | |
2830 | if (error) { | |
cf2b4488 HP |
2831 | WL_WSEC(("Failed to clear is_WPS_enrollee\n")); |
2832 | return error; | |
2833 | } | |
2834 | } | |
2835 | ||
59334c2f JC |
2836 | error = dev_wlc_intvar_set(dev, "wsec", val); |
2837 | if (error) | |
cf2b4488 HP |
2838 | return error; |
2839 | ||
2840 | break; | |
2841 | ||
2842 | case IW_AUTH_KEY_MGMT: | |
59334c2f JC |
2843 | error = dev_wlc_intvar_get(dev, "wpa_auth", &val); |
2844 | if (error) | |
cf2b4488 HP |
2845 | return error; |
2846 | ||
2847 | if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) { | |
2848 | if (paramval & IW_AUTH_KEY_MGMT_PSK) | |
2849 | val = WPA_AUTH_PSK; | |
2850 | else | |
2851 | val = WPA_AUTH_UNSPECIFIED; | |
2852 | } | |
2853 | #ifdef BCMWPA2 | |
2854 | else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) { | |
2855 | if (paramval & IW_AUTH_KEY_MGMT_PSK) | |
2856 | val = WPA2_AUTH_PSK; | |
2857 | else | |
2858 | val = WPA2_AUTH_UNSPECIFIED; | |
2859 | } | |
2860 | #endif | |
2861 | WL_INFORM(("%s: %d: setting wpa_auth to %d\n", __func__, | |
2862 | __LINE__, val)); | |
59334c2f JC |
2863 | error = dev_wlc_intvar_set(dev, "wpa_auth", val); |
2864 | if (error) | |
cf2b4488 HP |
2865 | return error; |
2866 | ||
2867 | break; | |
2868 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
2869 | dev_wlc_bufvar_set(dev, "tkip_countermeasures", | |
2870 | (char *)¶mval, 1); | |
2871 | break; | |
2872 | ||
2873 | case IW_AUTH_80211_AUTH_ALG: | |
2874 | WL_INFORM(("Setting the D11auth %d\n", paramval)); | |
2875 | if (paramval == IW_AUTH_ALG_OPEN_SYSTEM) | |
2876 | val = 0; | |
2877 | else if (paramval == IW_AUTH_ALG_SHARED_KEY) | |
2878 | val = 1; | |
2879 | else if (paramval == | |
2880 | (IW_AUTH_ALG_OPEN_SYSTEM | IW_AUTH_ALG_SHARED_KEY)) | |
2881 | val = 2; | |
2882 | else | |
2883 | error = 1; | |
59334c2f JC |
2884 | if (!error) { |
2885 | error = dev_wlc_intvar_set(dev, "auth", val); | |
2886 | if (error) | |
2887 | return error; | |
2888 | } | |
cf2b4488 HP |
2889 | break; |
2890 | ||
2891 | case IW_AUTH_WPA_ENABLED: | |
2892 | if (paramval == 0) { | |
2893 | iw->pwsec = 0; | |
2894 | iw->gwsec = 0; | |
59334c2f JC |
2895 | error = dev_wlc_intvar_get(dev, "wsec", &val); |
2896 | if (error) | |
cf2b4488 HP |
2897 | return error; |
2898 | if (val & (TKIP_ENABLED | AES_ENABLED)) { | |
2899 | val &= ~(TKIP_ENABLED | AES_ENABLED); | |
2900 | dev_wlc_intvar_set(dev, "wsec", val); | |
2901 | } | |
2902 | val = 0; | |
2903 | WL_INFORM(("%s: %d: setting wpa_auth to %d\n", | |
2904 | __func__, __LINE__, val)); | |
2905 | dev_wlc_intvar_set(dev, "wpa_auth", 0); | |
2906 | return error; | |
2907 | } | |
2908 | break; | |
2909 | ||
2910 | case IW_AUTH_DROP_UNENCRYPTED: | |
2911 | dev_wlc_bufvar_set(dev, "wsec_restrict", (char *)¶mval, 1); | |
2912 | break; | |
2913 | ||
2914 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
2915 | dev_wlc_bufvar_set(dev, "rx_unencrypted_eapol", | |
2916 | (char *)¶mval, 1); | |
2917 | break; | |
2918 | ||
2919 | #if WIRELESS_EXT > 17 | |
2920 | case IW_AUTH_ROAMING_CONTROL: | |
2921 | WL_INFORM(("%s: IW_AUTH_ROAMING_CONTROL\n", __func__)); | |
2922 | break; | |
2923 | case IW_AUTH_PRIVACY_INVOKED: | |
2924 | { | |
2925 | int wsec; | |
2926 | ||
2927 | if (paramval == 0) { | |
2928 | iw->privacy_invoked = FALSE; | |
59334c2f JC |
2929 | error = dev_wlc_intvar_set(dev, |
2930 | "is_WPS_enrollee", FALSE); | |
2931 | if (error) { | |
cf2b4488 HP |
2932 | WL_WSEC(("Failed to clear iovar " |
2933 | "is_WPS_enrollee\n")); | |
2934 | return error; | |
2935 | } | |
2936 | } else { | |
2937 | iw->privacy_invoked = TRUE; | |
59334c2f JC |
2938 | error = dev_wlc_intvar_get(dev, "wsec", &wsec); |
2939 | if (error) | |
cf2b4488 HP |
2940 | return error; |
2941 | ||
2942 | if (!(IW_WSEC_ENABLED(wsec))) { | |
59334c2f JC |
2943 | error = dev_wlc_intvar_set(dev, |
2944 | "is_WPS_enrollee", | |
2945 | TRUE); | |
2946 | if (error) { | |
cf2b4488 HP |
2947 | WL_WSEC(("Failed to set iovar " |
2948 | "is_WPS_enrollee\n")); | |
2949 | return error; | |
2950 | } | |
2951 | } else { | |
59334c2f JC |
2952 | error = dev_wlc_intvar_set(dev, |
2953 | "is_WPS_enrollee", | |
2954 | FALSE); | |
2955 | if (error) { | |
cf2b4488 HP |
2956 | WL_WSEC(("Failed to clear " |
2957 | "is_WPS_enrollee\n")); | |
2958 | return error; | |
2959 | } | |
2960 | } | |
2961 | } | |
2962 | break; | |
2963 | } | |
2964 | #endif /* WIRELESS_EXT > 17 */ | |
2965 | default: | |
2966 | break; | |
2967 | } | |
2968 | return 0; | |
2969 | } | |
2970 | ||
2971 | #ifdef BCMWPA2 | |
2972 | #define VAL_PSK(_val) (((_val) & WPA_AUTH_PSK) || ((_val) & WPA2_AUTH_PSK)) | |
2973 | #else | |
2974 | #define VAL_PSK(_val) (((_val) & WPA_AUTH_PSK)) | |
2975 | #endif | |
2976 | ||
2977 | static int | |
2978 | wl_iw_get_wpaauth(struct net_device *dev, | |
2979 | struct iw_request_info *info, | |
2980 | struct iw_param *vwrq, char *extra) | |
2981 | { | |
2982 | int error; | |
2983 | int paramid; | |
2984 | int paramval = 0; | |
2985 | int val; | |
2986 | wl_iw_t *iw = *(wl_iw_t **) netdev_priv(dev); | |
2987 | ||
2988 | WL_TRACE(("%s: SIOCGIWAUTH\n", dev->name)); | |
2989 | ||
2990 | paramid = vwrq->flags & IW_AUTH_INDEX; | |
2991 | ||
2992 | switch (paramid) { | |
2993 | case IW_AUTH_WPA_VERSION: | |
59334c2f JC |
2994 | error = dev_wlc_intvar_get(dev, "wpa_auth", &val); |
2995 | if (error) | |
cf2b4488 HP |
2996 | return error; |
2997 | if (val & (WPA_AUTH_NONE | WPA_AUTH_DISABLED)) | |
2998 | paramval = IW_AUTH_WPA_VERSION_DISABLED; | |
2999 | else if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) | |
3000 | paramval = IW_AUTH_WPA_VERSION_WPA; | |
3001 | #ifdef BCMWPA2 | |
3002 | else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) | |
3003 | paramval = IW_AUTH_WPA_VERSION_WPA2; | |
3004 | #endif | |
3005 | break; | |
3006 | case IW_AUTH_CIPHER_PAIRWISE: | |
3007 | case IW_AUTH_CIPHER_GROUP: | |
3008 | if (paramid == IW_AUTH_CIPHER_PAIRWISE) | |
3009 | val = iw->pwsec; | |
3010 | else | |
3011 | val = iw->gwsec; | |
3012 | ||
3013 | paramval = 0; | |
3014 | if (val) { | |
3015 | if (val & WEP_ENABLED) | |
3016 | paramval |= | |
3017 | (IW_AUTH_CIPHER_WEP40 | | |
3018 | IW_AUTH_CIPHER_WEP104); | |
3019 | if (val & TKIP_ENABLED) | |
3020 | paramval |= (IW_AUTH_CIPHER_TKIP); | |
3021 | if (val & AES_ENABLED) | |
3022 | paramval |= (IW_AUTH_CIPHER_CCMP); | |
3023 | } else | |
3024 | paramval = IW_AUTH_CIPHER_NONE; | |
3025 | break; | |
3026 | case IW_AUTH_KEY_MGMT: | |
59334c2f JC |
3027 | error = dev_wlc_intvar_get(dev, "wpa_auth", &val); |
3028 | if (error) | |
cf2b4488 HP |
3029 | return error; |
3030 | if (VAL_PSK(val)) | |
3031 | paramval = IW_AUTH_KEY_MGMT_PSK; | |
3032 | else | |
3033 | paramval = IW_AUTH_KEY_MGMT_802_1X; | |
3034 | ||
3035 | break; | |
3036 | case IW_AUTH_TKIP_COUNTERMEASURES: | |
3037 | dev_wlc_bufvar_get(dev, "tkip_countermeasures", | |
3038 | (char *)¶mval, 1); | |
3039 | break; | |
3040 | ||
3041 | case IW_AUTH_DROP_UNENCRYPTED: | |
3042 | dev_wlc_bufvar_get(dev, "wsec_restrict", (char *)¶mval, 1); | |
3043 | break; | |
3044 | ||
3045 | case IW_AUTH_RX_UNENCRYPTED_EAPOL: | |
3046 | dev_wlc_bufvar_get(dev, "rx_unencrypted_eapol", | |
3047 | (char *)¶mval, 1); | |
3048 | break; | |
3049 | ||
3050 | case IW_AUTH_80211_AUTH_ALG: | |
59334c2f JC |
3051 | error = dev_wlc_intvar_get(dev, "auth", &val); |
3052 | if (error) | |
cf2b4488 HP |
3053 | return error; |
3054 | if (!val) | |
3055 | paramval = IW_AUTH_ALG_OPEN_SYSTEM; | |
3056 | else | |
3057 | paramval = IW_AUTH_ALG_SHARED_KEY; | |
3058 | break; | |
3059 | case IW_AUTH_WPA_ENABLED: | |
59334c2f JC |
3060 | error = dev_wlc_intvar_get(dev, "wpa_auth", &val); |
3061 | if (error) | |
cf2b4488 HP |
3062 | return error; |
3063 | if (val) | |
3064 | paramval = TRUE; | |
3065 | else | |
3066 | paramval = FALSE; | |
3067 | break; | |
3068 | #if WIRELESS_EXT > 17 | |
3069 | case IW_AUTH_ROAMING_CONTROL: | |
3070 | WL_ERROR(("%s: IW_AUTH_ROAMING_CONTROL\n", __func__)); | |
3071 | break; | |
3072 | case IW_AUTH_PRIVACY_INVOKED: | |
3073 | paramval = iw->privacy_invoked; | |
3074 | break; | |
3075 | ||
3076 | #endif | |
3077 | } | |
3078 | vwrq->value = paramval; | |
3079 | return 0; | |
3080 | } | |
3081 | #endif /* WIRELESS_EXT > 17 */ | |
3082 | ||
3083 | static const iw_handler wl_iw_handler[] = { | |
3084 | (iw_handler) wl_iw_config_commit, | |
3085 | (iw_handler) wl_iw_get_name, | |
3086 | (iw_handler) NULL, | |
3087 | (iw_handler) NULL, | |
3088 | (iw_handler) wl_iw_set_freq, | |
3089 | (iw_handler) wl_iw_get_freq, | |
3090 | (iw_handler) wl_iw_set_mode, | |
3091 | (iw_handler) wl_iw_get_mode, | |
3092 | (iw_handler) NULL, | |
3093 | (iw_handler) NULL, | |
3094 | (iw_handler) NULL, | |
3095 | (iw_handler) wl_iw_get_range, | |
3096 | (iw_handler) NULL, | |
3097 | (iw_handler) NULL, | |
3098 | (iw_handler) NULL, | |
3099 | (iw_handler) NULL, | |
3100 | (iw_handler) wl_iw_set_spy, | |
3101 | (iw_handler) wl_iw_get_spy, | |
3102 | (iw_handler) NULL, | |
3103 | (iw_handler) NULL, | |
3104 | (iw_handler) wl_iw_set_wap, | |
3105 | (iw_handler) wl_iw_get_wap, | |
3106 | #if WIRELESS_EXT > 17 | |
3107 | (iw_handler) wl_iw_mlme, | |
3108 | #else | |
3109 | (iw_handler) NULL, | |
3110 | #endif | |
3111 | #if defined(WL_IW_USE_ISCAN) | |
3112 | (iw_handler) wl_iw_iscan_get_aplist, | |
3113 | #else | |
3114 | (iw_handler) wl_iw_get_aplist, | |
3115 | #endif | |
3116 | #if WIRELESS_EXT > 13 | |
3117 | #if defined(WL_IW_USE_ISCAN) | |
3118 | (iw_handler) wl_iw_iscan_set_scan, | |
3119 | (iw_handler) wl_iw_iscan_get_scan, | |
3120 | #else | |
3121 | (iw_handler) wl_iw_set_scan, | |
3122 | (iw_handler) wl_iw_get_scan, | |
3123 | #endif | |
3124 | #else | |
3125 | (iw_handler) NULL, | |
3126 | (iw_handler) NULL, | |
3127 | #endif /* WIRELESS_EXT > 13 */ | |
3128 | (iw_handler) wl_iw_set_essid, | |
3129 | (iw_handler) wl_iw_get_essid, | |
3130 | (iw_handler) wl_iw_set_nick, | |
3131 | (iw_handler) wl_iw_get_nick, | |
3132 | (iw_handler) NULL, | |
3133 | (iw_handler) NULL, | |
3134 | (iw_handler) wl_iw_set_rate, | |
3135 | (iw_handler) wl_iw_get_rate, | |
3136 | (iw_handler) wl_iw_set_rts, | |
3137 | (iw_handler) wl_iw_get_rts, | |
3138 | (iw_handler) wl_iw_set_frag, | |
3139 | (iw_handler) wl_iw_get_frag, | |
3140 | (iw_handler) wl_iw_set_txpow, | |
3141 | (iw_handler) wl_iw_get_txpow, | |
3142 | #if WIRELESS_EXT > 10 | |
3143 | (iw_handler) wl_iw_set_retry, | |
3144 | (iw_handler) wl_iw_get_retry, | |
3145 | #endif | |
3146 | (iw_handler) wl_iw_set_encode, | |
3147 | (iw_handler) wl_iw_get_encode, | |
3148 | (iw_handler) wl_iw_set_power, | |
3149 | (iw_handler) wl_iw_get_power, | |
3150 | #if WIRELESS_EXT > 17 | |
3151 | (iw_handler) NULL, | |
3152 | (iw_handler) NULL, | |
3153 | (iw_handler) wl_iw_set_wpaie, | |
3154 | (iw_handler) wl_iw_get_wpaie, | |
3155 | (iw_handler) wl_iw_set_wpaauth, | |
3156 | (iw_handler) wl_iw_get_wpaauth, | |
3157 | (iw_handler) wl_iw_set_encodeext, | |
3158 | (iw_handler) wl_iw_get_encodeext, | |
3159 | #ifdef BCMWPA2 | |
3160 | (iw_handler) wl_iw_set_pmksa, | |
3161 | #endif | |
3162 | #endif /* WIRELESS_EXT > 17 */ | |
3163 | }; | |
3164 | ||
3165 | #if WIRELESS_EXT > 12 | |
3166 | ||
3167 | const struct iw_handler_def wl_iw_handler_def = { | |
3168 | .num_standard = ARRAYSIZE(wl_iw_handler), | |
3169 | .standard = (iw_handler *) wl_iw_handler, | |
3170 | .num_private = 0, | |
3171 | .num_private_args = 0, | |
3172 | .private = 0, | |
3173 | .private_args = 0, | |
3174 | ||
3175 | #if WIRELESS_EXT >= 19 | |
3176 | .get_wireless_stats = dhd_get_wireless_stats, | |
3177 | #endif | |
3178 | }; | |
3179 | #endif /* WIRELESS_EXT > 12 */ | |
3180 | ||
3181 | int wl_iw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | |
3182 | { | |
3183 | struct iwreq *wrq = (struct iwreq *)rq; | |
3184 | struct iw_request_info info; | |
3185 | iw_handler handler; | |
3186 | char *extra = NULL; | |
3187 | int token_size = 1, max_tokens = 0, ret = 0; | |
3188 | ||
3189 | WL_TRACE(("\n%s, cmd:%x alled via dhd->do_ioctl()entry point\n", | |
3190 | __func__, cmd)); | |
59334c2f JC |
3191 | if (cmd < SIOCIWFIRST || |
3192 | IW_IOCTL_IDX(cmd) >= ARRAYSIZE(wl_iw_handler)) { | |
3193 | WL_ERROR(("%s: error in cmd=%x : out of range\n", __func__, | |
3194 | cmd)); | |
3195 | return -EOPNOTSUPP; | |
3196 | } | |
3197 | ||
3198 | handler = wl_iw_handler[IW_IOCTL_IDX(cmd)]; | |
3199 | if (!handler) { | |
3200 | WL_ERROR(("%s: error in cmd=%x : not supported\n", | |
3201 | __func__, cmd)); | |
cf2b4488 HP |
3202 | return -EOPNOTSUPP; |
3203 | } | |
3204 | ||
3205 | switch (cmd) { | |
3206 | ||
3207 | case SIOCSIWESSID: | |
3208 | case SIOCGIWESSID: | |
3209 | case SIOCSIWNICKN: | |
3210 | case SIOCGIWNICKN: | |
3211 | max_tokens = IW_ESSID_MAX_SIZE + 1; | |
3212 | break; | |
3213 | ||
3214 | case SIOCSIWENCODE: | |
3215 | case SIOCGIWENCODE: | |
3216 | #if WIRELESS_EXT > 17 | |
3217 | case SIOCSIWENCODEEXT: | |
3218 | case SIOCGIWENCODEEXT: | |
3219 | #endif | |
3220 | max_tokens = wrq->u.data.length; | |
3221 | break; | |
3222 | ||
3223 | case SIOCGIWRANGE: | |
3224 | max_tokens = sizeof(struct iw_range) + 500; | |
3225 | break; | |
3226 | ||
3227 | case SIOCGIWAPLIST: | |
3228 | token_size = | |
3229 | sizeof(struct sockaddr) + sizeof(struct iw_quality); | |
3230 | max_tokens = IW_MAX_AP; | |
3231 | break; | |
3232 | ||
3233 | #if WIRELESS_EXT > 13 | |
3234 | case SIOCGIWSCAN: | |
3235 | #if defined(WL_IW_USE_ISCAN) | |
3236 | if (g_iscan) | |
3237 | max_tokens = wrq->u.data.length; | |
3238 | else | |
3239 | #endif | |
3240 | max_tokens = IW_SCAN_MAX_DATA; | |
3241 | break; | |
3242 | #endif /* WIRELESS_EXT > 13 */ | |
3243 | ||
3244 | case SIOCSIWSPY: | |
3245 | token_size = sizeof(struct sockaddr); | |
3246 | max_tokens = IW_MAX_SPY; | |
3247 | break; | |
3248 | ||
3249 | case SIOCGIWSPY: | |
3250 | token_size = | |
3251 | sizeof(struct sockaddr) + sizeof(struct iw_quality); | |
3252 | max_tokens = IW_MAX_SPY; | |
3253 | break; | |
3254 | ||
3255 | #if WIRELESS_EXT > 17 | |
3256 | case SIOCSIWPMKSA: | |
3257 | case SIOCSIWGENIE: | |
3258 | #endif | |
3259 | case SIOCSIWPRIV: | |
3260 | max_tokens = wrq->u.data.length; | |
3261 | break; | |
3262 | } | |
3263 | ||
3264 | if (max_tokens && wrq->u.data.pointer) { | |
3265 | if (wrq->u.data.length > max_tokens) { | |
3266 | WL_ERROR(("%s: error in cmd=%x wrq->u.data.length=%d " | |
3267 | "> max_tokens=%d\n", | |
3268 | __func__, cmd, wrq->u.data.length, max_tokens)); | |
3269 | return -E2BIG; | |
3270 | } | |
59334c2f JC |
3271 | extra = kmalloc(max_tokens * token_size, GFP_KERNEL); |
3272 | if (!extra) | |
cf2b4488 HP |
3273 | return -ENOMEM; |
3274 | ||
3275 | if (copy_from_user | |
3276 | (extra, wrq->u.data.pointer, | |
3277 | wrq->u.data.length * token_size)) { | |
3278 | kfree(extra); | |
3279 | return -EFAULT; | |
3280 | } | |
3281 | } | |
3282 | ||
3283 | info.cmd = cmd; | |
3284 | info.flags = 0; | |
3285 | ||
3286 | ret = handler(dev, &info, &wrq->u, extra); | |
3287 | ||
3288 | if (extra) { | |
3289 | if (copy_to_user | |
3290 | (wrq->u.data.pointer, extra, | |
3291 | wrq->u.data.length * token_size)) { | |
3292 | kfree(extra); | |
3293 | return -EFAULT; | |
3294 | } | |
3295 | ||
3296 | kfree(extra); | |
3297 | } | |
3298 | ||
3299 | return ret; | |
3300 | } | |
3301 | ||
3302 | bool | |
3303 | wl_iw_conn_status_str(uint32 event_type, uint32 status, uint32 reason, | |
3304 | char *stringBuf, uint buflen) | |
3305 | { | |
3306 | typedef struct conn_fail_event_map_t { | |
3307 | uint32 inEvent; | |
3308 | uint32 inStatus; | |
3309 | uint32 inReason; | |
3310 | const char *outName; | |
3311 | const char *outCause; | |
3312 | } conn_fail_event_map_t; | |
3313 | ||
3314 | #define WL_IW_DONT_CARE 9999 | |
3315 | const conn_fail_event_map_t event_map[] = { | |
3316 | {WLC_E_SET_SSID, WLC_E_STATUS_SUCCESS, WL_IW_DONT_CARE, | |
3317 | "Conn", "Success"}, | |
3318 | {WLC_E_SET_SSID, WLC_E_STATUS_NO_NETWORKS, WL_IW_DONT_CARE, | |
3319 | "Conn", "NoNetworks"}, | |
3320 | {WLC_E_SET_SSID, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE, | |
3321 | "Conn", "ConfigMismatch"}, | |
3322 | {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_PRUNE_ENCR_MISMATCH, | |
3323 | "Conn", "EncrypMismatch"}, | |
3324 | {WLC_E_PRUNE, WL_IW_DONT_CARE, WLC_E_RSN_MISMATCH, | |
3325 | "Conn", "RsnMismatch"}, | |
3326 | {WLC_E_AUTH, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE, | |
3327 | "Conn", "AuthTimeout"}, | |
3328 | {WLC_E_AUTH, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE, | |
3329 | "Conn", "AuthFail"}, | |
3330 | {WLC_E_AUTH, WLC_E_STATUS_NO_ACK, WL_IW_DONT_CARE, | |
3331 | "Conn", "AuthNoAck"}, | |
3332 | {WLC_E_REASSOC, WLC_E_STATUS_FAIL, WL_IW_DONT_CARE, | |
3333 | "Conn", "ReassocFail"}, | |
3334 | {WLC_E_REASSOC, WLC_E_STATUS_TIMEOUT, WL_IW_DONT_CARE, | |
3335 | "Conn", "ReassocTimeout"}, | |
3336 | {WLC_E_REASSOC, WLC_E_STATUS_ABORT, WL_IW_DONT_CARE, | |
3337 | "Conn", "ReassocAbort"}, | |
3338 | {WLC_E_PSK_SUP, WLC_SUP_KEYED, WL_IW_DONT_CARE, | |
3339 | "Sup", "ConnSuccess"}, | |
3340 | {WLC_E_PSK_SUP, WL_IW_DONT_CARE, WL_IW_DONT_CARE, | |
3341 | "Sup", "WpaHandshakeFail"}, | |
3342 | {WLC_E_DEAUTH_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE, | |
3343 | "Conn", "Deauth"}, | |
3344 | {WLC_E_DISASSOC_IND, WL_IW_DONT_CARE, WL_IW_DONT_CARE, | |
3345 | "Conn", "DisassocInd"}, | |
3346 | {WLC_E_DISASSOC, WL_IW_DONT_CARE, WL_IW_DONT_CARE, | |
3347 | "Conn", "Disassoc"} | |
3348 | }; | |
3349 | ||
3350 | const char *name = ""; | |
3351 | const char *cause = NULL; | |
3352 | int i; | |
3353 | ||
3354 | for (i = 0; i < sizeof(event_map) / sizeof(event_map[0]); i++) { | |
3355 | const conn_fail_event_map_t *row = &event_map[i]; | |
3356 | if (row->inEvent == event_type && | |
3357 | (row->inStatus == status | |
3358 | || row->inStatus == WL_IW_DONT_CARE) | |
3359 | && (row->inReason == reason | |
3360 | || row->inReason == WL_IW_DONT_CARE)) { | |
3361 | name = row->outName; | |
3362 | cause = row->outCause; | |
3363 | break; | |
3364 | } | |
3365 | } | |
3366 | ||
3367 | if (cause) { | |
3368 | memset(stringBuf, 0, buflen); | |
3369 | snprintf(stringBuf, buflen, "%s %s %02d %02d", | |
3370 | name, cause, status, reason); | |
3371 | WL_INFORM(("Connection status: %s\n", stringBuf)); | |
3372 | return TRUE; | |
3373 | } else { | |
3374 | return FALSE; | |
3375 | } | |
3376 | } | |
3377 | ||
3378 | #if WIRELESS_EXT > 14 | |
3379 | ||
3380 | static bool | |
3381 | wl_iw_check_conn_fail(wl_event_msg_t *e, char *stringBuf, uint buflen) | |
3382 | { | |
3383 | uint32 event = ntoh32(e->event_type); | |
3384 | uint32 status = ntoh32(e->status); | |
3385 | uint32 reason = ntoh32(e->reason); | |
3386 | ||
3387 | if (wl_iw_conn_status_str(event, status, reason, stringBuf, buflen)) { | |
3388 | return TRUE; | |
3389 | } else | |
3390 | return FALSE; | |
3391 | } | |
3392 | #endif | |
3393 | ||
3394 | #ifndef IW_CUSTOM_MAX | |
3395 | #define IW_CUSTOM_MAX 256 | |
3396 | #endif | |
3397 | ||
3398 | void wl_iw_event(struct net_device *dev, wl_event_msg_t *e, void *data) | |
3399 | { | |
3400 | #if WIRELESS_EXT > 13 | |
3401 | union iwreq_data wrqu; | |
3402 | char extra[IW_CUSTOM_MAX + 1]; | |
3403 | int cmd = 0; | |
3404 | uint32 event_type = ntoh32(e->event_type); | |
7d4df48e | 3405 | u16 flags = ntoh16(e->flags); |
cf2b4488 HP |
3406 | uint32 datalen = ntoh32(e->datalen); |
3407 | uint32 status = ntoh32(e->status); | |
3408 | wl_iw_t *iw; | |
3409 | uint32 toto; | |
3410 | memset(&wrqu, 0, sizeof(wrqu)); | |
3411 | memset(extra, 0, sizeof(extra)); | |
3412 | iw = 0; | |
3413 | ||
3414 | if (!dev) { | |
3415 | WL_ERROR(("%s: dev is null\n", __func__)); | |
3416 | return; | |
3417 | } | |
3418 | ||
3419 | iw = *(wl_iw_t **) netdev_priv(dev); | |
3420 | ||
3421 | WL_TRACE(("%s: dev=%s event=%d\n", __func__, dev->name, event_type)); | |
3422 | ||
3423 | switch (event_type) { | |
3424 | case WLC_E_TXFAIL: | |
3425 | cmd = IWEVTXDROP; | |
3426 | memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN); | |
3427 | wrqu.addr.sa_family = ARPHRD_ETHER; | |
3428 | break; | |
3429 | #if WIRELESS_EXT > 14 | |
3430 | case WLC_E_JOIN: | |
3431 | case WLC_E_ASSOC_IND: | |
3432 | case WLC_E_REASSOC_IND: | |
3433 | memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN); | |
3434 | wrqu.addr.sa_family = ARPHRD_ETHER; | |
3435 | cmd = IWEVREGISTERED; | |
3436 | break; | |
3437 | case WLC_E_DEAUTH_IND: | |
3438 | case WLC_E_DISASSOC_IND: | |
3439 | cmd = SIOCGIWAP; | |
3440 | bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN); | |
3441 | wrqu.addr.sa_family = ARPHRD_ETHER; | |
3442 | bzero(&extra, ETHER_ADDR_LEN); | |
3443 | break; | |
3444 | case WLC_E_LINK: | |
3445 | case WLC_E_NDIS_LINK: | |
3446 | cmd = SIOCGIWAP; | |
3447 | if (!(flags & WLC_EVENT_MSG_LINK)) { | |
3448 | bzero(wrqu.addr.sa_data, ETHER_ADDR_LEN); | |
3449 | bzero(&extra, ETHER_ADDR_LEN); | |
3450 | WAKE_LOCK_TIMEOUT(iw->pub, WAKE_LOCK_LINK_DOWN_TMOUT, | |
3451 | 20 * HZ); | |
3452 | } else { | |
3453 | memcpy(wrqu.addr.sa_data, &e->addr, ETHER_ADDR_LEN); | |
3454 | WL_TRACE(("Link UP\n")); | |
3455 | ||
3456 | } | |
3457 | wrqu.addr.sa_family = ARPHRD_ETHER; | |
3458 | break; | |
3459 | case WLC_E_ACTION_FRAME: | |
3460 | cmd = IWEVCUSTOM; | |
3461 | if (datalen + 1 <= sizeof(extra)) { | |
3462 | wrqu.data.length = datalen + 1; | |
3463 | extra[0] = WLC_E_ACTION_FRAME; | |
3464 | memcpy(&extra[1], data, datalen); | |
3465 | WL_TRACE(("WLC_E_ACTION_FRAME len %d \n", | |
3466 | wrqu.data.length)); | |
3467 | } | |
3468 | break; | |
3469 | ||
3470 | case WLC_E_ACTION_FRAME_COMPLETE: | |
3471 | cmd = IWEVCUSTOM; | |
3472 | memcpy(&toto, data, 4); | |
3473 | if (sizeof(status) + 1 <= sizeof(extra)) { | |
3474 | wrqu.data.length = sizeof(status) + 1; | |
3475 | extra[0] = WLC_E_ACTION_FRAME_COMPLETE; | |
3476 | memcpy(&extra[1], &status, sizeof(status)); | |
3477 | printf("wl_iw_event status %d PacketId %d\n", status, | |
3478 | toto); | |
3479 | printf("WLC_E_ACTION_FRAME_COMPLETE len %d\n", | |
3480 | wrqu.data.length); | |
3481 | } | |
3482 | break; | |
3483 | #endif /* WIRELESS_EXT > 14 */ | |
3484 | #if WIRELESS_EXT > 17 | |
3485 | case WLC_E_MIC_ERROR: | |
3486 | { | |
3487 | struct iw_michaelmicfailure *micerrevt = | |
3488 | (struct iw_michaelmicfailure *)&extra; | |
3489 | cmd = IWEVMICHAELMICFAILURE; | |
3490 | wrqu.data.length = sizeof(struct iw_michaelmicfailure); | |
3491 | if (flags & WLC_EVENT_MSG_GROUP) | |
3492 | micerrevt->flags |= IW_MICFAILURE_GROUP; | |
3493 | else | |
3494 | micerrevt->flags |= IW_MICFAILURE_PAIRWISE; | |
3495 | memcpy(micerrevt->src_addr.sa_data, &e->addr, | |
3496 | ETHER_ADDR_LEN); | |
3497 | micerrevt->src_addr.sa_family = ARPHRD_ETHER; | |
3498 | ||
3499 | break; | |
3500 | } | |
3501 | #ifdef BCMWPA2 | |
3502 | case WLC_E_PMKID_CACHE: | |
3503 | { | |
3504 | if (data) { | |
3505 | struct iw_pmkid_cand *iwpmkidcand = | |
3506 | (struct iw_pmkid_cand *)&extra; | |
3507 | pmkid_cand_list_t *pmkcandlist; | |
3508 | pmkid_cand_t *pmkidcand; | |
3509 | int count; | |
3510 | ||
3511 | cmd = IWEVPMKIDCAND; | |
3512 | pmkcandlist = data; | |
3513 | count = | |
3fd79f7c | 3514 | ntoh32_ua((u8 *) & |
cf2b4488 HP |
3515 | pmkcandlist->npmkid_cand); |
3516 | ASSERT(count >= 0); | |
3517 | wrqu.data.length = sizeof(struct iw_pmkid_cand); | |
3518 | pmkidcand = pmkcandlist->pmkid_cand; | |
3519 | while (count) { | |
3520 | bzero(iwpmkidcand, | |
3521 | sizeof(struct iw_pmkid_cand)); | |
3522 | if (pmkidcand->preauth) | |
3523 | iwpmkidcand->flags |= | |
3524 | IW_PMKID_CAND_PREAUTH; | |
3525 | bcopy(&pmkidcand->BSSID, | |
3526 | &iwpmkidcand->bssid.sa_data, | |
3527 | ETHER_ADDR_LEN); | |
3528 | #ifndef SANDGATE2G | |
3529 | wireless_send_event(dev, cmd, &wrqu, | |
3530 | extra); | |
3531 | #endif | |
3532 | pmkidcand++; | |
3533 | count--; | |
3534 | } | |
3535 | } | |
3536 | return; | |
3537 | } | |
3538 | #endif /* BCMWPA2 */ | |
3539 | #endif /* WIRELESS_EXT > 17 */ | |
3540 | ||
3541 | case WLC_E_SCAN_COMPLETE: | |
3542 | #if defined(WL_IW_USE_ISCAN) | |
3543 | if ((g_iscan) && (g_iscan->sysioc_pid > 0) && | |
3544 | (g_iscan->iscan_state != ISCAN_STATE_IDLE)) { | |
3545 | up(&g_iscan->sysioc_sem); | |
3546 | } else { | |
3547 | cmd = SIOCGIWSCAN; | |
3548 | wrqu.data.length = strlen(extra); | |
3549 | WL_TRACE(("Event WLC_E_SCAN_COMPLETE from specific " | |
3550 | "scan %d\n", g_iscan->iscan_state)); | |
3551 | } | |
3552 | #else | |
3553 | cmd = SIOCGIWSCAN; | |
3554 | wrqu.data.length = strlen(extra); | |
3555 | WL_TRACE(("Event WLC_E_SCAN_COMPLETE\n")); | |
3556 | #endif | |
3557 | break; | |
3558 | ||
3559 | case WLC_E_PFN_NET_FOUND: | |
3560 | { | |
3561 | wlc_ssid_t *ssid; | |
3562 | ssid = (wlc_ssid_t *) data; | |
3563 | WL_ERROR(("%s Event WLC_E_PFN_NET_FOUND, send %s up : " | |
3564 | "find %s len=%d\n", __func__, PNO_EVENT_UP, | |
3565 | ssid->SSID, ssid->SSID_len)); | |
3566 | WAKE_LOCK_TIMEOUT(iw->pub, WAKE_LOCK_PNO_FIND_TMOUT, | |
3567 | 20 * HZ); | |
3568 | cmd = IWEVCUSTOM; | |
3569 | memset(&wrqu, 0, sizeof(wrqu)); | |
3570 | strcpy(extra, PNO_EVENT_UP); | |
3571 | wrqu.data.length = strlen(extra); | |
3572 | } | |
3573 | break; | |
3574 | ||
3575 | default: | |
3576 | WL_TRACE(("Unknown Event %d: ignoring\n", event_type)); | |
3577 | break; | |
3578 | } | |
3579 | #ifndef SANDGATE2G | |
3580 | if (cmd) { | |
3581 | if (cmd == SIOCGIWSCAN) | |
3582 | wireless_send_event(dev, cmd, &wrqu, NULL); | |
3583 | else | |
3584 | wireless_send_event(dev, cmd, &wrqu, extra); | |
3585 | } | |
3586 | #endif | |
3587 | ||
3588 | #if WIRELESS_EXT > 14 | |
3589 | memset(extra, 0, sizeof(extra)); | |
3590 | if (wl_iw_check_conn_fail(e, extra, sizeof(extra))) { | |
3591 | cmd = IWEVCUSTOM; | |
3592 | wrqu.data.length = strlen(extra); | |
3593 | #ifndef SANDGATE2G | |
3594 | wireless_send_event(dev, cmd, &wrqu, extra); | |
3595 | #endif | |
3596 | } | |
3597 | #endif /* WIRELESS_EXT > 14 */ | |
3598 | #endif /* WIRELESS_EXT > 13 */ | |
3599 | } | |
3600 | ||
3601 | int | |
3602 | wl_iw_get_wireless_stats(struct net_device *dev, struct iw_statistics *wstats) | |
3603 | { | |
3604 | int res = 0; | |
3605 | wl_cnt_t cnt; | |
3606 | int phy_noise; | |
3607 | int rssi; | |
3608 | scb_val_t scb_val; | |
3609 | ||
3610 | phy_noise = 0; | |
59334c2f JC |
3611 | res = dev_wlc_ioctl(dev, WLC_GET_PHY_NOISE, &phy_noise, |
3612 | sizeof(phy_noise)); | |
3613 | if (res) | |
cf2b4488 HP |
3614 | goto done; |
3615 | ||
3616 | phy_noise = dtoh32(phy_noise); | |
3617 | WL_TRACE(("wl_iw_get_wireless_stats phy noise=%d\n", phy_noise)); | |
3618 | ||
3619 | bzero(&scb_val, sizeof(scb_val_t)); | |
59334c2f JC |
3620 | res = dev_wlc_ioctl(dev, WLC_GET_RSSI, &scb_val, sizeof(scb_val_t)); |
3621 | if (res) | |
cf2b4488 HP |
3622 | goto done; |
3623 | ||
3624 | rssi = dtoh32(scb_val.val); | |
3625 | WL_TRACE(("wl_iw_get_wireless_stats rssi=%d\n", rssi)); | |
3626 | if (rssi <= WL_IW_RSSI_NO_SIGNAL) | |
3627 | wstats->qual.qual = 0; | |
3628 | else if (rssi <= WL_IW_RSSI_VERY_LOW) | |
3629 | wstats->qual.qual = 1; | |
3630 | else if (rssi <= WL_IW_RSSI_LOW) | |
3631 | wstats->qual.qual = 2; | |
3632 | else if (rssi <= WL_IW_RSSI_GOOD) | |
3633 | wstats->qual.qual = 3; | |
3634 | else if (rssi <= WL_IW_RSSI_VERY_GOOD) | |
3635 | wstats->qual.qual = 4; | |
3636 | else | |
3637 | wstats->qual.qual = 5; | |
3638 | ||
3639 | wstats->qual.level = 0x100 + rssi; | |
3640 | wstats->qual.noise = 0x100 + phy_noise; | |
3641 | #if WIRELESS_EXT > 18 | |
3642 | wstats->qual.updated |= (IW_QUAL_ALL_UPDATED | IW_QUAL_DBM); | |
3643 | #else | |
3644 | wstats->qual.updated |= 7; | |
3645 | #endif | |
3646 | ||
3647 | #if WIRELESS_EXT > 11 | |
3648 | WL_TRACE(("wl_iw_get_wireless_stats counters=%d\n", | |
3649 | (int)sizeof(wl_cnt_t))); | |
3650 | ||
3651 | memset(&cnt, 0, sizeof(wl_cnt_t)); | |
3652 | res = | |
3653 | dev_wlc_bufvar_get(dev, "counters", (char *)&cnt, sizeof(wl_cnt_t)); | |
3654 | if (res) { | |
3655 | WL_ERROR(("wl_iw_get_wireless_stats counters failed error=%d\n", | |
3656 | res)); | |
3657 | goto done; | |
3658 | } | |
3659 | ||
3660 | cnt.version = dtoh16(cnt.version); | |
3661 | if (cnt.version != WL_CNT_T_VERSION) { | |
3662 | WL_TRACE(("\tIncorrect version of counters struct: expected " | |
3663 | "%d; got %d\n", | |
3664 | WL_CNT_T_VERSION, cnt.version)); | |
3665 | goto done; | |
3666 | } | |
3667 | ||
3668 | wstats->discard.nwid = 0; | |
3669 | wstats->discard.code = dtoh32(cnt.rxundec); | |
3670 | wstats->discard.fragment = dtoh32(cnt.rxfragerr); | |
3671 | wstats->discard.retries = dtoh32(cnt.txfail); | |
3672 | wstats->discard.misc = dtoh32(cnt.rxrunt) + dtoh32(cnt.rxgiant); | |
3673 | wstats->miss.beacon = 0; | |
3674 | ||
3675 | WL_TRACE(("wl_iw_get_wireless_stats counters txframe=%d txbyte=%d\n", | |
3676 | dtoh32(cnt.txframe), dtoh32(cnt.txbyte))); | |
3677 | WL_TRACE(("wl_iw_get_wireless_stats counters rxfrmtoolong=%d\n", | |
3678 | dtoh32(cnt.rxfrmtoolong))); | |
3679 | WL_TRACE(("wl_iw_get_wireless_stats counters rxbadplcp=%d\n", | |
3680 | dtoh32(cnt.rxbadplcp))); | |
3681 | WL_TRACE(("wl_iw_get_wireless_stats counters rxundec=%d\n", | |
3682 | dtoh32(cnt.rxundec))); | |
3683 | WL_TRACE(("wl_iw_get_wireless_stats counters rxfragerr=%d\n", | |
3684 | dtoh32(cnt.rxfragerr))); | |
3685 | WL_TRACE(("wl_iw_get_wireless_stats counters txfail=%d\n", | |
3686 | dtoh32(cnt.txfail))); | |
3687 | WL_TRACE(("wl_iw_get_wireless_stats counters rxrunt=%d\n", | |
3688 | dtoh32(cnt.rxrunt))); | |
3689 | WL_TRACE(("wl_iw_get_wireless_stats counters rxgiant=%d\n", | |
3690 | dtoh32(cnt.rxgiant))); | |
3691 | #endif /* WIRELESS_EXT > 11 */ | |
3692 | ||
3693 | done: | |
3694 | return res; | |
3695 | } | |
3696 | ||
3697 | int wl_iw_attach(struct net_device *dev, void *dhdp) | |
3698 | { | |
3699 | int params_size; | |
3700 | wl_iw_t *iw; | |
3701 | #if defined(WL_IW_USE_ISCAN) | |
3702 | iscan_info_t *iscan = NULL; | |
3703 | ||
3704 | if (!dev) | |
3705 | return 0; | |
3706 | ||
3707 | memset(&g_wl_iw_params, 0, sizeof(wl_iw_extra_params_t)); | |
3708 | ||
3709 | #ifdef CSCAN | |
3710 | params_size = | |
3711 | (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_iscan_params_t, params)) + | |
7d4df48e | 3712 | (WL_NUMCHANNELS * sizeof(u16)) + |
cf2b4488 HP |
3713 | WL_SCAN_PARAMS_SSID_MAX * sizeof(wlc_ssid_t); |
3714 | #else | |
3715 | params_size = | |
3716 | (WL_SCAN_PARAMS_FIXED_SIZE + OFFSETOF(wl_iscan_params_t, params)); | |
3717 | #endif | |
3718 | iscan = kmalloc(sizeof(iscan_info_t), GFP_KERNEL); | |
3719 | ||
3720 | if (!iscan) | |
3721 | return -ENOMEM; | |
3722 | memset(iscan, 0, sizeof(iscan_info_t)); | |
3723 | ||
3724 | iscan->iscan_ex_params_p = | |
3725 | (wl_iscan_params_t *) kmalloc(params_size, GFP_KERNEL); | |
3726 | if (!iscan->iscan_ex_params_p) | |
3727 | return -ENOMEM; | |
3728 | iscan->iscan_ex_param_size = params_size; | |
3729 | iscan->sysioc_pid = -1; | |
3730 | ||
3731 | g_iscan = iscan; | |
3732 | iscan->dev = dev; | |
3733 | iscan->iscan_state = ISCAN_STATE_IDLE; | |
3734 | ||
3735 | iscan->timer_ms = 3000; | |
3736 | init_timer(&iscan->timer); | |
3deea904 | 3737 | iscan->timer.data = (unsigned long) iscan; |
cf2b4488 HP |
3738 | iscan->timer.function = wl_iw_timerfunc; |
3739 | ||
3740 | sema_init(&iscan->sysioc_sem, 0); | |
3741 | init_completion(&iscan->sysioc_exited); | |
3742 | iscan->sysioc_pid = kernel_thread(_iscan_sysioc_thread, iscan, 0); | |
3743 | if (iscan->sysioc_pid < 0) | |
3744 | return -ENOMEM; | |
3745 | #endif /* defined(WL_IW_USE_ISCAN) */ | |
3746 | ||
3747 | iw = *(wl_iw_t **) netdev_priv(dev); | |
3748 | iw->pub = (dhd_pub_t *) dhdp; | |
3749 | MUTEX_LOCK_INIT(iw->pub); | |
3750 | MUTEX_LOCK_WL_SCAN_SET_INIT(); | |
3751 | #ifdef SOFTAP | |
3752 | priv_dev = dev; | |
3753 | MUTEX_LOCK_SOFTAP_SET_INIT(iw->pub); | |
3754 | #endif | |
3755 | g_scan = NULL; | |
3756 | ||
3757 | g_scan = (void *)kmalloc(G_SCAN_RESULTS, GFP_KERNEL); | |
3758 | if (!g_scan) | |
3759 | return -ENOMEM; | |
3760 | ||
3761 | memset(g_scan, 0, G_SCAN_RESULTS); | |
3762 | g_scan_specified_ssid = 0; | |
3763 | ||
3764 | return 0; | |
3765 | } | |
3766 | ||
3767 | void wl_iw_detach(void) | |
3768 | { | |
3769 | #if defined(WL_IW_USE_ISCAN) | |
3770 | iscan_buf_t *buf; | |
3771 | iscan_info_t *iscan = g_iscan; | |
3772 | ||
3773 | if (!iscan) | |
3774 | return; | |
3775 | if (iscan->sysioc_pid >= 0) { | |
3776 | KILL_PROC(iscan->sysioc_pid, SIGTERM); | |
3777 | wait_for_completion(&iscan->sysioc_exited); | |
3778 | } | |
3779 | MUTEX_LOCK_WL_SCAN_SET(); | |
3780 | while (iscan->list_hdr) { | |
3781 | buf = iscan->list_hdr->next; | |
3782 | kfree(iscan->list_hdr); | |
3783 | iscan->list_hdr = buf; | |
3784 | } | |
3785 | MUTEX_UNLOCK_WL_SCAN_SET(); | |
3786 | kfree(iscan->iscan_ex_params_p); | |
3787 | kfree(iscan); | |
3788 | g_iscan = NULL; | |
3789 | #endif /* WL_IW_USE_ISCAN */ | |
3790 | ||
3791 | kfree(g_scan); | |
3792 | ||
3793 | g_scan = NULL; | |
3794 | } |