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