diff options
Diffstat (limited to 'drivers/net/wireless/bcm4329/dhd_common.c')
| -rw-r--r-- | drivers/net/wireless/bcm4329/dhd_common.c | 2432 |
1 files changed, 2432 insertions, 0 deletions
diff --git a/drivers/net/wireless/bcm4329/dhd_common.c b/drivers/net/wireless/bcm4329/dhd_common.c new file mode 100644 index 00000000000..f7cd372d68c --- /dev/null +++ b/drivers/net/wireless/bcm4329/dhd_common.c | |||
| @@ -0,0 +1,2432 @@ | |||
| 1 | /* | ||
| 2 | * Broadcom Dongle Host Driver (DHD), common DHD core. | ||
| 3 | * | ||
| 4 | * Copyright (C) 1999-2010, Broadcom Corporation | ||
| 5 | * | ||
| 6 | * Unless you and Broadcom execute a separate written software license | ||
| 7 | * agreement governing use of this software, this software is licensed to you | ||
| 8 | * under the terms of the GNU General Public License version 2 (the "GPL"), | ||
| 9 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the | ||
| 10 | * following added to such license: | ||
| 11 | * | ||
| 12 | * As a special exception, the copyright holders of this software give you | ||
| 13 | * permission to link this software with independent modules, and to copy and | ||
| 14 | * distribute the resulting executable under terms of your choice, provided that | ||
| 15 | * you also meet, for each linked independent module, the terms and conditions of | ||
| 16 | * the license of that module. An independent module is a module which is not | ||
| 17 | * derived from this software. The special exception does not apply to any | ||
| 18 | * modifications of the software. | ||
| 19 | * | ||
| 20 | * Notwithstanding the above, under no circumstances may you combine this | ||
| 21 | * software in any way with any other Broadcom software provided under a license | ||
| 22 | * other than the GPL, without Broadcom's express prior written consent. | ||
| 23 | * | ||
| 24 | * $Id: dhd_common.c,v 1.5.6.8.2.6.6.69.4.25 2011-02-11 21:16:02 Exp $ | ||
| 25 | */ | ||
| 26 | #include <typedefs.h> | ||
| 27 | #include <osl.h> | ||
| 28 | |||
| 29 | #include <epivers.h> | ||
| 30 | #include <bcmutils.h> | ||
| 31 | |||
| 32 | #include <bcmendian.h> | ||
| 33 | #include <dngl_stats.h> | ||
| 34 | #include <dhd.h> | ||
| 35 | #include <dhd_bus.h> | ||
| 36 | #include <dhd_proto.h> | ||
| 37 | #include <dhd_dbg.h> | ||
| 38 | #include <msgtrace.h> | ||
| 39 | |||
| 40 | #include <wlioctl.h> | ||
| 41 | |||
| 42 | #ifdef SET_RANDOM_MAC_SOFTAP | ||
| 43 | #include <linux/random.h> | ||
| 44 | #include <linux/jiffies.h> | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #ifdef GET_CUSTOM_MAC_ENABLE | ||
| 48 | int wifi_get_mac_addr(unsigned char *buf); | ||
| 49 | #endif /* GET_CUSTOM_MAC_ENABLE */ | ||
| 50 | |||
| 51 | int dhd_msg_level; | ||
| 52 | |||
| 53 | #include <wl_iw.h> | ||
| 54 | |||
| 55 | char fw_path[MOD_PARAM_PATHLEN]; | ||
| 56 | char nv_path[MOD_PARAM_PATHLEN]; | ||
| 57 | |||
| 58 | /* Last connection success/failure status */ | ||
| 59 | uint32 dhd_conn_event; | ||
| 60 | uint32 dhd_conn_status; | ||
| 61 | uint32 dhd_conn_reason; | ||
| 62 | |||
| 63 | #define htod32(i) i | ||
| 64 | #define htod16(i) i | ||
| 65 | #define dtoh32(i) i | ||
| 66 | #define dtoh16(i) i | ||
| 67 | |||
| 68 | extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len); | ||
| 69 | extern void dhd_ind_scan_confirm(void *h, bool status); | ||
| 70 | extern int dhd_wl_ioctl(dhd_pub_t *dhd, uint cmd, char *buf, uint buflen); | ||
| 71 | void dhd_iscan_lock(void); | ||
| 72 | void dhd_iscan_unlock(void); | ||
| 73 | |||
| 74 | #if defined(SOFTAP) | ||
| 75 | extern bool ap_fw_loaded; | ||
| 76 | #endif | ||
| 77 | #if defined(KEEP_ALIVE) | ||
| 78 | int dhd_keep_alive_onoff(dhd_pub_t *dhd, int ka_on); | ||
| 79 | #endif /* KEEP_ALIVE */ | ||
| 80 | |||
| 81 | /* Packet alignment for most efficient SDIO (can change based on platform) */ | ||
| 82 | #ifndef DHD_SDALIGN | ||
| 83 | #define DHD_SDALIGN 32 | ||
| 84 | #endif | ||
| 85 | #if !ISPOWEROF2(DHD_SDALIGN) | ||
| 86 | #error DHD_SDALIGN is not a power of 2! | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #ifdef DHD_DEBUG | ||
| 90 | const char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR "\nCompiled on " | ||
| 91 | __DATE__ " at " __TIME__; | ||
| 92 | #else | ||
| 93 | const char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR; | ||
| 94 | #endif | ||
| 95 | |||
| 96 | void dhd_set_timer(void *bus, uint wdtick); | ||
| 97 | |||
| 98 | /* IOVar table */ | ||
| 99 | enum { | ||
| 100 | IOV_VERSION = 1, | ||
| 101 | IOV_MSGLEVEL, | ||
| 102 | IOV_BCMERRORSTR, | ||
| 103 | IOV_BCMERROR, | ||
| 104 | IOV_WDTICK, | ||
| 105 | IOV_DUMP, | ||
| 106 | #ifdef DHD_DEBUG | ||
| 107 | IOV_CONS, | ||
| 108 | IOV_DCONSOLE_POLL, | ||
| 109 | #endif | ||
| 110 | IOV_CLEARCOUNTS, | ||
| 111 | IOV_LOGDUMP, | ||
| 112 | IOV_LOGCAL, | ||
| 113 | IOV_LOGSTAMP, | ||
| 114 | IOV_GPIOOB, | ||
| 115 | IOV_IOCTLTIMEOUT, | ||
| 116 | IOV_LAST | ||
| 117 | }; | ||
| 118 | |||
| 119 | const bcm_iovar_t dhd_iovars[] = { | ||
| 120 | {"version", IOV_VERSION, 0, IOVT_BUFFER, sizeof(dhd_version) }, | ||
| 121 | #ifdef DHD_DEBUG | ||
| 122 | {"msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0 }, | ||
| 123 | #endif /* DHD_DEBUG */ | ||
| 124 | {"bcmerrorstr", IOV_BCMERRORSTR, 0, IOVT_BUFFER, BCME_STRLEN }, | ||
| 125 | {"bcmerror", IOV_BCMERROR, 0, IOVT_INT8, 0 }, | ||
| 126 | {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0 }, | ||
| 127 | {"dump", IOV_DUMP, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN }, | ||
| 128 | #ifdef DHD_DEBUG | ||
| 129 | {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0 }, | ||
| 130 | {"cons", IOV_CONS, 0, IOVT_BUFFER, 0 }, | ||
| 131 | #endif | ||
| 132 | {"clearcounts", IOV_CLEARCOUNTS, 0, IOVT_VOID, 0 }, | ||
| 133 | {"gpioob", IOV_GPIOOB, 0, IOVT_UINT32, 0 }, | ||
| 134 | {"ioctl_timeout", IOV_IOCTLTIMEOUT, 0, IOVT_UINT32, 0 }, | ||
| 135 | {NULL, 0, 0, 0, 0 } | ||
| 136 | }; | ||
| 137 | |||
| 138 | void | ||
| 139 | dhd_common_init(void) | ||
| 140 | { | ||
| 141 | /* Init global variables at run-time, not as part of the declaration. | ||
| 142 | * This is required to support init/de-init of the driver. Initialization | ||
| 143 | * of globals as part of the declaration results in non-deterministic | ||
| 144 | * behaviour since the value of the globals may be different on the | ||
| 145 | * first time that the driver is initialized vs subsequent initializations. | ||
| 146 | */ | ||
| 147 | dhd_msg_level = DHD_ERROR_VAL; | ||
| 148 | #ifdef CONFIG_BCM4329_FW_PATH | ||
| 149 | strncpy(fw_path, CONFIG_BCM4329_FW_PATH, MOD_PARAM_PATHLEN-1); | ||
| 150 | #else | ||
| 151 | fw_path[0] = '\0'; | ||
| 152 | #endif | ||
| 153 | #ifdef CONFIG_BCM4329_NVRAM_PATH | ||
| 154 | strncpy(nv_path, CONFIG_BCM4329_NVRAM_PATH, MOD_PARAM_PATHLEN-1); | ||
| 155 | #else | ||
| 156 | nv_path[0] = '\0'; | ||
| 157 | #endif | ||
| 158 | } | ||
| 159 | |||
| 160 | static int | ||
| 161 | dhd_dump(dhd_pub_t *dhdp, char *buf, int buflen) | ||
| 162 | { | ||
| 163 | char eabuf[ETHER_ADDR_STR_LEN]; | ||
| 164 | |||
| 165 | struct bcmstrbuf b; | ||
| 166 | struct bcmstrbuf *strbuf = &b; | ||
| 167 | |||
| 168 | bcm_binit(strbuf, buf, buflen); | ||
| 169 | |||
| 170 | /* Base DHD info */ | ||
| 171 | bcm_bprintf(strbuf, "%s\n", dhd_version); | ||
| 172 | bcm_bprintf(strbuf, "\n"); | ||
| 173 | bcm_bprintf(strbuf, "pub.up %d pub.txoff %d pub.busstate %d\n", | ||
| 174 | dhdp->up, dhdp->txoff, dhdp->busstate); | ||
| 175 | bcm_bprintf(strbuf, "pub.hdrlen %d pub.maxctl %d pub.rxsz %d\n", | ||
| 176 | dhdp->hdrlen, dhdp->maxctl, dhdp->rxsz); | ||
| 177 | bcm_bprintf(strbuf, "pub.iswl %d pub.drv_version %ld pub.mac %s\n", | ||
| 178 | dhdp->iswl, dhdp->drv_version, bcm_ether_ntoa(&dhdp->mac, eabuf)); | ||
| 179 | bcm_bprintf(strbuf, "pub.bcmerror %d tickcnt %d\n", dhdp->bcmerror, dhdp->tickcnt); | ||
| 180 | |||
| 181 | bcm_bprintf(strbuf, "dongle stats:\n"); | ||
| 182 | bcm_bprintf(strbuf, "tx_packets %ld tx_bytes %ld tx_errors %ld tx_dropped %ld\n", | ||
| 183 | dhdp->dstats.tx_packets, dhdp->dstats.tx_bytes, | ||
| 184 | dhdp->dstats.tx_errors, dhdp->dstats.tx_dropped); | ||
| 185 | bcm_bprintf(strbuf, "rx_packets %ld rx_bytes %ld rx_errors %ld rx_dropped %ld\n", | ||
| 186 | dhdp->dstats.rx_packets, dhdp->dstats.rx_bytes, | ||
| 187 | dhdp->dstats.rx_errors, dhdp->dstats.rx_dropped); | ||
| 188 | bcm_bprintf(strbuf, "multicast %ld\n", dhdp->dstats.multicast); | ||
| 189 | |||
| 190 | bcm_bprintf(strbuf, "bus stats:\n"); | ||
| 191 | bcm_bprintf(strbuf, "tx_packets %ld tx_multicast %ld tx_errors %ld\n", | ||
| 192 | dhdp->tx_packets, dhdp->tx_multicast, dhdp->tx_errors); | ||
| 193 | bcm_bprintf(strbuf, "tx_ctlpkts %ld tx_ctlerrs %ld\n", | ||
| 194 | dhdp->tx_ctlpkts, dhdp->tx_ctlerrs); | ||
| 195 | bcm_bprintf(strbuf, "rx_packets %ld rx_multicast %ld rx_errors %ld \n", | ||
| 196 | dhdp->rx_packets, dhdp->rx_multicast, dhdp->rx_errors); | ||
| 197 | bcm_bprintf(strbuf, "rx_ctlpkts %ld rx_ctlerrs %ld rx_dropped %ld rx_flushed %ld\n", | ||
| 198 | dhdp->rx_ctlpkts, dhdp->rx_ctlerrs, dhdp->rx_dropped, dhdp->rx_flushed); | ||
| 199 | bcm_bprintf(strbuf, "rx_readahead_cnt %ld tx_realloc %ld fc_packets %ld\n", | ||
| 200 | dhdp->rx_readahead_cnt, dhdp->tx_realloc, dhdp->fc_packets); | ||
| 201 | bcm_bprintf(strbuf, "wd_dpc_sched %ld\n", dhdp->wd_dpc_sched); | ||
| 202 | bcm_bprintf(strbuf, "\n"); | ||
| 203 | |||
| 204 | /* Add any prot info */ | ||
| 205 | dhd_prot_dump(dhdp, strbuf); | ||
| 206 | bcm_bprintf(strbuf, "\n"); | ||
| 207 | |||
| 208 | /* Add any bus info */ | ||
| 209 | dhd_bus_dump(dhdp, strbuf); | ||
| 210 | |||
| 211 | return (!strbuf->size ? BCME_BUFTOOSHORT : 0); | ||
| 212 | } | ||
| 213 | |||
| 214 | static int | ||
| 215 | dhd_doiovar(dhd_pub_t *dhd_pub, const bcm_iovar_t *vi, uint32 actionid, const char *name, | ||
| 216 | void *params, int plen, void *arg, int len, int val_size) | ||
| 217 | { | ||
| 218 | int bcmerror = 0; | ||
| 219 | int32 int_val = 0; | ||
| 220 | |||
| 221 | DHD_TRACE(("%s: Enter\n", __FUNCTION__)); | ||
| 222 | |||
| 223 | if ((bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid))) != 0) | ||
| 224 | goto exit; | ||
| 225 | |||
| 226 | if (plen >= (int)sizeof(int_val)) | ||
| 227 | bcopy(params, &int_val, sizeof(int_val)); | ||
| 228 | |||
| 229 | switch (actionid) { | ||
| 230 | case IOV_GVAL(IOV_VERSION): | ||
| 231 | /* Need to have checked buffer length */ | ||
| 232 | strncpy((char*)arg, dhd_version, len); | ||
| 233 | break; | ||
| 234 | |||
| 235 | case IOV_GVAL(IOV_MSGLEVEL): | ||
| 236 | int_val = (int32)dhd_msg_level; | ||
| 237 | bcopy(&int_val, arg, val_size); | ||
| 238 | break; | ||
| 239 | |||
| 240 | case IOV_SVAL(IOV_MSGLEVEL): | ||
| 241 | dhd_msg_level = int_val; | ||
| 242 | break; | ||
| 243 | |||
| 244 | case IOV_GVAL(IOV_BCMERRORSTR): | ||
| 245 | strncpy((char *)arg, bcmerrorstr(dhd_pub->bcmerror), BCME_STRLEN); | ||
| 246 | ((char *)arg)[BCME_STRLEN - 1] = 0x00; | ||
| 247 | break; | ||
| 248 | |||
| 249 | case IOV_GVAL(IOV_BCMERROR): | ||
| 250 | int_val = (int32)dhd_pub->bcmerror; | ||
| 251 | bcopy(&int_val, arg, val_size); | ||
| 252 | break; | ||
| 253 | |||
| 254 | case IOV_GVAL(IOV_WDTICK): | ||
| 255 | int_val = (int32)dhd_watchdog_ms; | ||
| 256 | bcopy(&int_val, arg, val_size); | ||
| 257 | break; | ||
| 258 | |||
| 259 | case IOV_SVAL(IOV_WDTICK): | ||
| 260 | if (!dhd_pub->up) { | ||
| 261 | bcmerror = BCME_NOTUP; | ||
| 262 | break; | ||
| 263 | } | ||
| 264 | dhd_os_wd_timer(dhd_pub, (uint)int_val); | ||
| 265 | break; | ||
| 266 | |||
| 267 | case IOV_GVAL(IOV_DUMP): | ||
| 268 | bcmerror = dhd_dump(dhd_pub, arg, len); | ||
| 269 | break; | ||
| 270 | |||
| 271 | #ifdef DHD_DEBUG | ||
| 272 | case IOV_GVAL(IOV_DCONSOLE_POLL): | ||
| 273 | int_val = (int32)dhd_console_ms; | ||
| 274 | bcopy(&int_val, arg, val_size); | ||
| 275 | break; | ||
| 276 | |||
| 277 | case IOV_SVAL(IOV_DCONSOLE_POLL): | ||
| 278 | dhd_console_ms = (uint)int_val; | ||
| 279 | break; | ||
| 280 | |||
| 281 | case IOV_SVAL(IOV_CONS): | ||
| 282 | if (len > 0) | ||
| 283 | bcmerror = dhd_bus_console_in(dhd_pub, arg, len - 1); | ||
| 284 | break; | ||
| 285 | #endif | ||
| 286 | |||
| 287 | case IOV_SVAL(IOV_CLEARCOUNTS): | ||
| 288 | dhd_pub->tx_packets = dhd_pub->rx_packets = 0; | ||
| 289 | dhd_pub->tx_errors = dhd_pub->rx_errors = 0; | ||
| 290 | dhd_pub->tx_ctlpkts = dhd_pub->rx_ctlpkts = 0; | ||
| 291 | dhd_pub->tx_ctlerrs = dhd_pub->rx_ctlerrs = 0; | ||
| 292 | dhd_pub->rx_dropped = 0; | ||
| 293 | dhd_pub->rx_readahead_cnt = 0; | ||
| 294 | dhd_pub->tx_realloc = 0; | ||
| 295 | dhd_pub->wd_dpc_sched = 0; | ||
| 296 | memset(&dhd_pub->dstats, 0, sizeof(dhd_pub->dstats)); | ||
| 297 | dhd_bus_clearcounts(dhd_pub); | ||
| 298 | break; | ||
| 299 | |||
| 300 | |||
| 301 | case IOV_GVAL(IOV_IOCTLTIMEOUT): { | ||
| 302 | int_val = (int32)dhd_os_get_ioctl_resp_timeout(); | ||
| 303 | bcopy(&int_val, arg, sizeof(int_val)); | ||
| 304 | break; | ||
| 305 | } | ||
| 306 | |||
| 307 | case IOV_SVAL(IOV_IOCTLTIMEOUT): { | ||
| 308 | if (int_val <= 0) | ||
| 309 | bcmerror = BCME_BADARG; | ||
| 310 | else | ||
| 311 | dhd_os_set_ioctl_resp_timeout((unsigned int)int_val); | ||
| 312 | break; | ||
| 313 | } | ||
| 314 | |||
| 315 | |||
| 316 | default: | ||
| 317 | bcmerror = BCME_UNSUPPORTED; | ||
| 318 | break; | ||
| 319 | } | ||
| 320 | |||
| 321 | exit: | ||
| 322 | return bcmerror; | ||
| 323 | } | ||
| 324 | |||
| 325 | /* Store the status of a connection attempt for later retrieval by an iovar */ | ||
| 326 | void | ||
| 327 | dhd_store_conn_status(uint32 event, uint32 status, uint32 reason) | ||
| 328 | { | ||
| 329 | /* Do not overwrite a WLC_E_PRUNE with a WLC_E_SET_SSID | ||
| 330 | * because an encryption/rsn mismatch results in both events, and | ||
| 331 | * the important information is in the WLC_E_PRUNE. | ||
| 332 | */ | ||
| 333 | if (!(event == WLC_E_SET_SSID && status == WLC_E_STATUS_FAIL && | ||
| 334 | dhd_conn_event == WLC_E_PRUNE)) { | ||
| 335 | dhd_conn_event = event; | ||
| 336 | dhd_conn_status = status; | ||
| 337 | dhd_conn_reason = reason; | ||
| 338 | } | ||
| 339 | } | ||
| 340 | |||
| 341 | bool | ||
| 342 | dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec) | ||
| 343 | { | ||
| 344 | void *p; | ||
| 345 | int eprec = -1; /* precedence to evict from */ | ||
| 346 | bool discard_oldest; | ||
| 347 | |||
| 348 | /* Fast case, precedence queue is not full and we are also not | ||
| 349 | * exceeding total queue length | ||
| 350 | */ | ||
| 351 | if (!pktq_pfull(q, prec) && !pktq_full(q)) { | ||
| 352 | pktq_penq(q, prec, pkt); | ||
| 353 | return TRUE; | ||
| 354 | } | ||
| 355 | |||
| 356 | /* Determine precedence from which to evict packet, if any */ | ||
| 357 | if (pktq_pfull(q, prec)) | ||
| 358 | eprec = prec; | ||
| 359 | else if (pktq_full(q)) { | ||
| 360 | p = pktq_peek_tail(q, &eprec); | ||
| 361 | ASSERT(p); | ||
| 362 | if (eprec > prec) | ||
| 363 | return FALSE; | ||
| 364 | } | ||
| 365 | |||
| 366 | /* Evict if needed */ | ||
| 367 | if (eprec >= 0) { | ||
| 368 | /* Detect queueing to unconfigured precedence */ | ||
| 369 | ASSERT(!pktq_pempty(q, eprec)); | ||
| 370 | discard_oldest = AC_BITMAP_TST(dhdp->wme_dp, eprec); | ||
| 371 | if (eprec == prec && !discard_oldest) | ||
| 372 | return FALSE; /* refuse newer (incoming) packet */ | ||
| 373 | /* Evict packet according to discard policy */ | ||
| 374 | p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q, eprec); | ||
| 375 | if (p == NULL) { | ||
| 376 | DHD_ERROR(("%s: pktq_penq() failed, oldest %d.", | ||
| 377 | __FUNCTION__, discard_oldest)); | ||
| 378 | ASSERT(p); | ||
| 379 | } | ||
| 380 | |||
| 381 | PKTFREE(dhdp->osh, p, TRUE); | ||
| 382 | } | ||
| 383 | |||
| 384 | /* Enqueue */ | ||
| 385 | p = pktq_penq(q, prec, pkt); | ||
| 386 | if (p == NULL) { | ||
| 387 | DHD_ERROR(("%s: pktq_penq() failed.", __FUNCTION__)); | ||
| 388 | ASSERT(p); | ||
| 389 | } | ||
| 390 | |||
| 391 | return TRUE; | ||
| 392 | } | ||
| 393 | |||
| 394 | static int | ||
| 395 | dhd_iovar_op(dhd_pub_t *dhd_pub, const char *name, | ||
| 396 | void *params, int plen, void *arg, int len, bool set) | ||
| 397 | { | ||
| 398 | int bcmerror = 0; | ||
| 399 | int val_size; | ||
| 400 | const bcm_iovar_t *vi = NULL; | ||
| 401 | uint32 actionid; | ||
| 402 | |||
| 403 | DHD_TRACE(("%s: Enter\n", __FUNCTION__)); | ||
| 404 | |||
| 405 | ASSERT(name); | ||
| 406 | ASSERT(len >= 0); | ||
| 407 | |||
| 408 | /* Get MUST have return space */ | ||
| 409 | ASSERT(set || (arg && len)); | ||
| 410 | |||
| 411 | /* Set does NOT take qualifiers */ | ||
| 412 | ASSERT(!set || (!params && !plen)); | ||
| 413 | |||
| 414 | if ((vi = bcm_iovar_lookup(dhd_iovars, name)) == NULL) { | ||
| 415 | bcmerror = BCME_UNSUPPORTED; | ||
| 416 | goto exit; | ||
| 417 | } | ||
| 418 | |||
| 419 | DHD_CTL(("%s: %s %s, len %d plen %d\n", __FUNCTION__, | ||
| 420 | name, (set ? "set" : "get"), len, plen)); | ||
| 421 | |||
| 422 | /* set up 'params' pointer in case this is a set command so that | ||
| 423 | * the convenience int and bool code can be common to set and get | ||
| 424 | */ | ||
| 425 | if (params == NULL) { | ||
| 426 | params = arg; | ||
| 427 | plen = len; | ||
| 428 | } | ||
| 429 | |||
| 430 | if (vi->type == IOVT_VOID) | ||
| 431 | val_size = 0; | ||
| 432 | else if (vi->type == IOVT_BUFFER) | ||
| 433 | val_size = len; | ||
| 434 | else | ||
| 435 | /* all other types are integer sized */ | ||
| 436 | val_size = sizeof(int); | ||
| 437 | |||
| 438 | actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid); | ||
| 439 | bcmerror = dhd_doiovar(dhd_pub, vi, actionid, name, params, plen, arg, len, val_size); | ||
| 440 | |||
| 441 | exit: | ||
| 442 | return bcmerror; | ||
| 443 | } | ||
| 444 | |||
| 445 | int | ||
| 446 | dhd_ioctl(dhd_pub_t *dhd_pub, dhd_ioctl_t *ioc, void *buf, uint buflen) | ||
| 447 | { | ||
| 448 | int bcmerror = 0; | ||
| 449 | |||
| 450 | DHD_TRACE(("%s: Enter\n", __FUNCTION__)); | ||
| 451 | |||
| 452 | if (!buf) return BCME_BADARG; | ||
| 453 | |||
| 454 | switch (ioc->cmd) { | ||
| 455 | case DHD_GET_MAGIC: | ||
| 456 | if (buflen < sizeof(int)) | ||
| 457 | bcmerror = BCME_BUFTOOSHORT; | ||
| 458 | else | ||
| 459 | *(int*)buf = DHD_IOCTL_MAGIC; | ||
| 460 | break; | ||
| 461 | |||
| 462 | case DHD_GET_VERSION: | ||
| 463 | if (buflen < sizeof(int)) | ||
| 464 | bcmerror = -BCME_BUFTOOSHORT; | ||
| 465 | else | ||
| 466 | *(int*)buf = DHD_IOCTL_VERSION; | ||
| 467 | break; | ||
| 468 | |||
| 469 | case DHD_GET_VAR: | ||
| 470 | case DHD_SET_VAR: { | ||
| 471 | char *arg; | ||
| 472 | uint arglen; | ||
| 473 | |||
| 474 | /* scan past the name to any arguments */ | ||
| 475 | for (arg = buf, arglen = buflen; *arg && arglen; arg++, arglen--); | ||
| 476 | |||
| 477 | if (*arg) { | ||
| 478 | bcmerror = BCME_BUFTOOSHORT; | ||
| 479 | break; | ||
| 480 | } | ||
| 481 | |||
| 482 | /* account for the NUL terminator */ | ||
| 483 | arg++, arglen--; | ||
| 484 | |||
| 485 | /* call with the appropriate arguments */ | ||
| 486 | if (ioc->cmd == DHD_GET_VAR) | ||
| 487 | bcmerror = dhd_iovar_op(dhd_pub, buf, arg, arglen, | ||
| 488 | buf, buflen, IOV_GET); | ||
| 489 | else | ||
| 490 | bcmerror = dhd_iovar_op(dhd_pub, buf, NULL, 0, arg, arglen, IOV_SET); | ||
| 491 | if (bcmerror != BCME_UNSUPPORTED) | ||
| 492 | break; | ||
| 493 | |||
| 494 | /* not in generic table, try protocol module */ | ||
| 495 | if (ioc->cmd == DHD_GET_VAR) | ||
| 496 | bcmerror = dhd_prot_iovar_op(dhd_pub, buf, arg, | ||
| 497 | arglen, buf, buflen, IOV_GET); | ||
| 498 | else | ||
| 499 | bcmerror = dhd_prot_iovar_op(dhd_pub, buf, | ||
| 500 | NULL, 0, arg, arglen, IOV_SET); | ||
| 501 | if (bcmerror != BCME_UNSUPPORTED) | ||
| 502 | break; | ||
| 503 | |||
| 504 | /* if still not found, try bus module */ | ||
| 505 | if (ioc->cmd == DHD_GET_VAR) | ||
| 506 | bcmerror = dhd_bus_iovar_op(dhd_pub, buf, | ||
| 507 | arg, arglen, buf, buflen, IOV_GET); | ||
| 508 | else | ||
| 509 | bcmerror = dhd_bus_iovar_op(dhd_pub, buf, | ||
| 510 | NULL, 0, arg, arglen, IOV_SET); | ||
| 511 | |||
| 512 | break; | ||
| 513 | } | ||
| 514 | |||
| 515 | default: | ||
| 516 | bcmerror = BCME_UNSUPPORTED; | ||
| 517 | } | ||
| 518 | |||
| 519 | return bcmerror; | ||
| 520 | } | ||
| 521 | |||
| 522 | |||
| 523 | #ifdef SHOW_EVENTS | ||
| 524 | static void | ||
| 525 | wl_show_host_event(wl_event_msg_t *event, void *event_data) | ||
| 526 | { | ||
| 527 | uint i, status, reason; | ||
| 528 | bool group = FALSE, flush_txq = FALSE, link = FALSE; | ||
| 529 | char *auth_str, *event_name; | ||
| 530 | uchar *buf; | ||
| 531 | char err_msg[256], eabuf[ETHER_ADDR_STR_LEN]; | ||
| 532 | static struct {uint event; char *event_name;} event_names[] = { | ||
| 533 | {WLC_E_SET_SSID, "SET_SSID"}, | ||
| 534 | {WLC_E_JOIN, "JOIN"}, | ||
| 535 | {WLC_E_START, "START"}, | ||
| 536 | {WLC_E_AUTH, "AUTH"}, | ||
| 537 | {WLC_E_AUTH_IND, "AUTH_IND"}, | ||
| 538 | {WLC_E_DEAUTH, "DEAUTH"}, | ||
| 539 | {WLC_E_DEAUTH_IND, "DEAUTH_IND"}, | ||
| 540 | {WLC_E_ASSOC, "ASSOC"}, | ||
| 541 | {WLC_E_ASSOC_IND, "ASSOC_IND"}, | ||
| 542 | {WLC_E_REASSOC, "REASSOC"}, | ||
| 543 | {WLC_E_REASSOC_IND, "REASSOC_IND"}, | ||
| 544 | {WLC_E_DISASSOC, "DISASSOC"}, | ||
| 545 | {WLC_E_DISASSOC_IND, "DISASSOC_IND"}, | ||
| 546 | {WLC_E_QUIET_START, "START_QUIET"}, | ||
| 547 | {WLC_E_QUIET_END, "END_QUIET"}, | ||
| 548 | {WLC_E_BEACON_RX, "BEACON_RX"}, | ||
| 549 | {WLC_E_LINK, "LINK"}, | ||
| 550 | {WLC_E_MIC_ERROR, "MIC_ERROR"}, | ||
| 551 | {WLC_E_NDIS_LINK, "NDIS_LINK"}, | ||
| 552 | {WLC_E_ROAM, "ROAM"}, | ||
| 553 | {WLC_E_TXFAIL, "TXFAIL"}, | ||
| 554 | {WLC_E_PMKID_CACHE, "PMKID_CACHE"}, | ||
| 555 | {WLC_E_RETROGRADE_TSF, "RETROGRADE_TSF"}, | ||
| 556 | {WLC_E_PRUNE, "PRUNE"}, | ||
| 557 | {WLC_E_AUTOAUTH, "AUTOAUTH"}, | ||
| 558 | {WLC_E_EAPOL_MSG, "EAPOL_MSG"}, | ||
| 559 | {WLC_E_SCAN_COMPLETE, "SCAN_COMPLETE"}, | ||
| 560 | {WLC_E_ADDTS_IND, "ADDTS_IND"}, | ||
| 561 | {WLC_E_DELTS_IND, "DELTS_IND"}, | ||
| 562 | {WLC_E_BCNSENT_IND, "BCNSENT_IND"}, | ||
| 563 | {WLC_E_BCNRX_MSG, "BCNRX_MSG"}, | ||
| 564 | {WLC_E_BCNLOST_MSG, "BCNLOST_MSG"}, | ||
| 565 | {WLC_E_ROAM_PREP, "ROAM_PREP"}, | ||
| 566 | {WLC_E_PFN_NET_FOUND, "PNO_NET_FOUND"}, | ||
| 567 | {WLC_E_PFN_NET_LOST, "PNO_NET_LOST"}, | ||
| 568 | {WLC_E_RESET_COMPLETE, "RESET_COMPLETE"}, | ||
| 569 | {WLC_E_JOIN_START, "JOIN_START"}, | ||
| 570 | {WLC_E_ROAM_START, "ROAM_START"}, | ||
| 571 | {WLC_E_ASSOC_START, "ASSOC_START"}, | ||
| 572 | {WLC_E_IBSS_ASSOC, "IBSS_ASSOC"}, | ||
| 573 | {WLC_E_RADIO, "RADIO"}, | ||
| 574 | {WLC_E_PSM_WATCHDOG, "PSM_WATCHDOG"}, | ||
| 575 | {WLC_E_PROBREQ_MSG, "PROBREQ_MSG"}, | ||
| 576 | {WLC_E_SCAN_CONFIRM_IND, "SCAN_CONFIRM_IND"}, | ||
| 577 | {WLC_E_PSK_SUP, "PSK_SUP"}, | ||
| 578 | {WLC_E_COUNTRY_CODE_CHANGED, "COUNTRY_CODE_CHANGED"}, | ||
| 579 | {WLC_E_EXCEEDED_MEDIUM_TIME, "EXCEEDED_MEDIUM_TIME"}, | ||
| 580 | {WLC_E_ICV_ERROR, "ICV_ERROR"}, | ||
| 581 | {WLC_E_UNICAST_DECODE_ERROR, "UNICAST_DECODE_ERROR"}, | ||
| 582 | {WLC_E_MULTICAST_DECODE_ERROR, "MULTICAST_DECODE_ERROR"}, | ||
| 583 | {WLC_E_TRACE, "TRACE"}, | ||
| 584 | {WLC_E_ACTION_FRAME, "ACTION FRAME"}, | ||
| 585 | {WLC_E_ACTION_FRAME_COMPLETE, "ACTION FRAME TX COMPLETE"}, | ||
| 586 | {WLC_E_IF, "IF"}, | ||
| 587 | {WLC_E_RSSI, "RSSI"}, | ||
| 588 | {WLC_E_PFN_SCAN_COMPLETE, "SCAN_COMPLETE"} | ||
| 589 | }; | ||
| 590 | uint event_type, flags, auth_type, datalen; | ||
| 591 | event_type = ntoh32(event->event_type); | ||
| 592 | flags = ntoh16(event->flags); | ||
| 593 | status = ntoh32(event->status); | ||
| 594 | reason = ntoh32(event->reason); | ||
| 595 | auth_type = ntoh32(event->auth_type); | ||
| 596 | datalen = ntoh32(event->datalen); | ||
| 597 | /* debug dump of event messages */ | ||
| 598 | sprintf(eabuf, "%02x:%02x:%02x:%02x:%02x:%02x", | ||
| 599 | (uchar)event->addr.octet[0]&0xff, | ||
| 600 | (uchar)event->addr.octet[1]&0xff, | ||
| 601 | (uchar)event->addr.octet[2]&0xff, | ||
| 602 | (uchar)event->addr.octet[3]&0xff, | ||
| 603 | (uchar)event->addr.octet[4]&0xff, | ||
| 604 | (uchar)event->addr.octet[5]&0xff); | ||
| 605 | |||
| 606 | event_name = "UNKNOWN"; | ||
| 607 | for (i = 0; i < ARRAYSIZE(event_names); i++) { | ||
| 608 | if (event_names[i].event == event_type) | ||
| 609 | event_name = event_names[i].event_name; | ||
| 610 | } | ||
| 611 | |||
| 612 | DHD_EVENT(("EVENT: %s, event ID = %d\n", event_name, event_type)); | ||
| 613 | |||
| 614 | if (flags & WLC_EVENT_MSG_LINK) | ||
| 615 | link = TRUE; | ||
| 616 | if (flags & WLC_EVENT_MSG_GROUP) | ||
| 617 | group = TRUE; | ||
| 618 | if (flags & WLC_EVENT_MSG_FLUSHTXQ) | ||
| 619 | flush_txq = TRUE; | ||
| 620 | |||
| 621 | switch (event_type) { | ||
| 622 | case WLC_E_START: | ||
| 623 | case WLC_E_DEAUTH: | ||
| 624 | case WLC_E_DISASSOC: | ||
| 625 | DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf)); | ||
| 626 | break; | ||
| 627 | |||
| 628 | case WLC_E_ASSOC_IND: | ||
| 629 | case WLC_E_REASSOC_IND: | ||
| 630 | DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf)); | ||
| 631 | break; | ||
| 632 | |||
| 633 | case WLC_E_ASSOC: | ||
| 634 | case WLC_E_REASSOC: | ||
| 635 | if (status == WLC_E_STATUS_SUCCESS) { | ||
| 636 | DHD_EVENT(("MACEVENT: %s, MAC %s, SUCCESS\n", event_name, eabuf)); | ||
| 637 | } else if (status == WLC_E_STATUS_TIMEOUT) { | ||
| 638 | DHD_EVENT(("MACEVENT: %s, MAC %s, TIMEOUT\n", event_name, eabuf)); | ||
| 639 | } else if (status == WLC_E_STATUS_FAIL) { | ||
| 640 | DHD_EVENT(("MACEVENT: %s, MAC %s, FAILURE, reason %d\n", | ||
| 641 | event_name, eabuf, (int)reason)); | ||
| 642 | } else { | ||
| 643 | DHD_EVENT(("MACEVENT: %s, MAC %s, unexpected status %d\n", | ||
| 644 | event_name, eabuf, (int)status)); | ||
| 645 | } | ||
| 646 | break; | ||
| 647 | |||
| 648 | case WLC_E_DEAUTH_IND: | ||
| 649 | case WLC_E_DISASSOC_IND: | ||
| 650 | DHD_EVENT(("MACEVENT: %s, MAC %s, reason %d\n", event_name, eabuf, (int)reason)); | ||
| 651 | break; | ||
| 652 | |||
| 653 | case WLC_E_AUTH: | ||
| 654 | case WLC_E_AUTH_IND: | ||
| 655 | if (auth_type == DOT11_OPEN_SYSTEM) | ||
| 656 | auth_str = "Open System"; | ||
| 657 | else if (auth_type == DOT11_SHARED_KEY) | ||
| 658 | auth_str = "Shared Key"; | ||
| 659 | else { | ||
| 660 | sprintf(err_msg, "AUTH unknown: %d", (int)auth_type); | ||
| 661 | auth_str = err_msg; | ||
| 662 | } | ||
| 663 | if (event_type == WLC_E_AUTH_IND) { | ||
| 664 | DHD_EVENT(("MACEVENT: %s, MAC %s, %s\n", event_name, eabuf, auth_str)); | ||
| 665 | } else if (status == WLC_E_STATUS_SUCCESS) { | ||
| 666 | DHD_EVENT(("MACEVENT: %s, MAC %s, %s, SUCCESS\n", | ||
| 667 | event_name, eabuf, auth_str)); | ||
| 668 | } else if (status == WLC_E_STATUS_TIMEOUT) { | ||
| 669 | DHD_EVENT(("MACEVENT: %s, MAC %s, %s, TIMEOUT\n", | ||
| 670 | event_name, eabuf, auth_str)); | ||
| 671 | } else if (status == WLC_E_STATUS_FAIL) { | ||
| 672 | DHD_EVENT(("MACEVENT: %s, MAC %s, %s, FAILURE, reason %d\n", | ||
| 673 | event_name, eabuf, auth_str, (int)reason)); | ||
| 674 | } | ||
| 675 | |||
| 676 | break; | ||
| 677 | |||
| 678 | case WLC_E_JOIN: | ||
| 679 | case WLC_E_ROAM: | ||
| 680 | case WLC_E_SET_SSID: | ||
| 681 | if (status == WLC_E_STATUS_SUCCESS) { | ||
| 682 | DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf)); | ||
| 683 | } else if (status == WLC_E_STATUS_FAIL) { | ||
| 684 | DHD_EVENT(("MACEVENT: %s, failed\n", event_name)); | ||
| 685 | } else if (status == WLC_E_STATUS_NO_NETWORKS) { | ||
| 686 | DHD_EVENT(("MACEVENT: %s, no networks found\n", event_name)); | ||
| 687 | } else { | ||
| 688 | DHD_EVENT(("MACEVENT: %s, unexpected status %d\n", | ||
| 689 | event_name, (int)status)); | ||
| 690 | } | ||
| 691 | break; | ||
| 692 | |||
| 693 | case WLC_E_BEACON_RX: | ||
| 694 | if (status == WLC_E_STATUS_SUCCESS) { | ||
| 695 | DHD_EVENT(("MACEVENT: %s, SUCCESS\n", event_name)); | ||
| 696 | } else if (status == WLC_E_STATUS_FAIL) { | ||
| 697 | DHD_EVENT(("MACEVENT: %s, FAIL\n", event_name)); | ||
| 698 | } else { | ||
| 699 | DHD_EVENT(("MACEVENT: %s, status %d\n", event_name, status)); | ||
| 700 | } | ||
| 701 | break; | ||
| 702 | |||
| 703 | case WLC_E_LINK: | ||
| 704 | DHD_EVENT(("MACEVENT: %s %s\n", event_name, link?"UP":"DOWN")); | ||
| 705 | break; | ||
| 706 | |||
| 707 | case WLC_E_MIC_ERROR: | ||
| 708 | DHD_EVENT(("MACEVENT: %s, MAC %s, Group %d, Flush %d\n", | ||
| 709 | event_name, eabuf, group, flush_txq)); | ||
| 710 | break; | ||
| 711 | |||
| 712 | case WLC_E_ICV_ERROR: | ||
| 713 | case WLC_E_UNICAST_DECODE_ERROR: | ||
| 714 | case WLC_E_MULTICAST_DECODE_ERROR: | ||
| 715 | DHD_EVENT(("MACEVENT: %s, MAC %s\n", | ||
| 716 | event_name, eabuf)); | ||
| 717 | break; | ||
| 718 | |||
| 719 | case WLC_E_TXFAIL: | ||
| 720 | DHD_EVENT(("MACEVENT: %s, RA %s\n", event_name, eabuf)); | ||
| 721 | break; | ||
| 722 | |||
| 723 | case WLC_E_SCAN_COMPLETE: | ||
| 724 | case WLC_E_PMKID_CACHE: | ||
| 725 | DHD_EVENT(("MACEVENT: %s\n", event_name)); | ||
| 726 | break; | ||
| 727 | |||
| 728 | case WLC_E_PFN_NET_FOUND: | ||
| 729 | case WLC_E_PFN_NET_LOST: | ||
| 730 | case WLC_E_PFN_SCAN_COMPLETE: | ||
| 731 | DHD_EVENT(("PNOEVENT: %s\n", event_name)); | ||
| 732 | break; | ||
| 733 | |||
| 734 | case WLC_E_PSK_SUP: | ||
| 735 | case WLC_E_PRUNE: | ||
| 736 | DHD_EVENT(("MACEVENT: %s, status %d, reason %d\n", | ||
| 737 | event_name, (int)status, (int)reason)); | ||
| 738 | break; | ||
| 739 | |||
| 740 | case WLC_E_TRACE: | ||
| 741 | { | ||
| 742 | static uint32 seqnum_prev = 0; | ||
| 743 | msgtrace_hdr_t hdr; | ||
| 744 | uint32 nblost; | ||
| 745 | char *s, *p; | ||
| 746 | |||
| 747 | buf = (uchar *) event_data; | ||
| 748 | memcpy(&hdr, buf, MSGTRACE_HDRLEN); | ||
| 749 | |||
| 750 | if (hdr.version != MSGTRACE_VERSION) { | ||
| 751 | printf("\nMACEVENT: %s [unsupported version --> " | ||
| 752 | "dhd version:%d dongle version:%d]\n", | ||
| 753 | event_name, MSGTRACE_VERSION, hdr.version); | ||
| 754 | /* Reset datalen to avoid display below */ | ||
| 755 | datalen = 0; | ||
| 756 | break; | ||
| 757 | } | ||
| 758 | |||
| 759 | /* There are 2 bytes available at the end of data */ | ||
| 760 | buf[MSGTRACE_HDRLEN + ntoh16(hdr.len)] = '\0'; | ||
| 761 | |||
| 762 | if (ntoh32(hdr.discarded_bytes) || ntoh32(hdr.discarded_printf)) { | ||
| 763 | printf("\nWLC_E_TRACE: [Discarded traces in dongle -->" | ||
| 764 | "discarded_bytes %d discarded_printf %d]\n", | ||
| 765 | ntoh32(hdr.discarded_bytes), ntoh32(hdr.discarded_printf)); | ||
| 766 | } | ||
| 767 | |||
| 768 | nblost = ntoh32(hdr.seqnum) - seqnum_prev - 1; | ||
| 769 | if (nblost > 0) { | ||
| 770 | printf("\nWLC_E_TRACE: [Event lost --> seqnum %d nblost %d\n", | ||
| 771 | ntoh32(hdr.seqnum), nblost); | ||
| 772 | } | ||
| 773 | seqnum_prev = ntoh32(hdr.seqnum); | ||
| 774 | |||
| 775 | /* Display the trace buffer. Advance from \n to \n to avoid display big | ||
| 776 | * printf (issue with Linux printk ) | ||
| 777 | */ | ||
| 778 | p = (char *)&buf[MSGTRACE_HDRLEN]; | ||
| 779 | while ((s = strstr(p, "\n")) != NULL) { | ||
| 780 | *s = '\0'; | ||
| 781 | printf("%s\n", p); | ||
| 782 | p = s + 1; | ||
| 783 | } | ||
| 784 | printf("%s\n", p); | ||
| 785 | |||
| 786 | /* Reset datalen to avoid display below */ | ||
| 787 | datalen = 0; | ||
| 788 | } | ||
| 789 | break; | ||
| 790 | |||
| 791 | |||
| 792 | case WLC_E_RSSI: | ||
| 793 | DHD_EVENT(("MACEVENT: %s %d\n", event_name, ntoh32(*((int *)event_data)))); | ||
| 794 | break; | ||
| 795 | |||
| 796 | default: | ||
| 797 | DHD_EVENT(("MACEVENT: %s %d, MAC %s, status %d, reason %d, auth %d\n", | ||
| 798 | event_name, event_type, eabuf, (int)status, (int)reason, | ||
| 799 | (int)auth_type)); | ||
| 800 | break; | ||
| 801 | } | ||
| 802 | |||
| 803 | /* show any appended data */ | ||
| 804 | if (datalen) { | ||
| 805 | buf = (uchar *) event_data; | ||
| 806 | DHD_EVENT((" data (%d) : ", datalen)); | ||
| 807 | for (i = 0; i < datalen; i++) | ||
| 808 | DHD_EVENT((" 0x%02x ", *buf++)); | ||
| 809 | DHD_EVENT(("\n")); | ||
| 810 | } | ||
| 811 | } | ||
| 812 | #endif /* SHOW_EVENTS */ | ||
| 813 | |||
| 814 | int | ||
| 815 | wl_host_event(struct dhd_info *dhd, int *ifidx, void *pktdata, | ||
| 816 | wl_event_msg_t *event, void **data_ptr) | ||
| 817 | { | ||
| 818 | /* check whether packet is a BRCM event pkt */ | ||
| 819 | bcm_event_t *pvt_data = (bcm_event_t *)pktdata; | ||
| 820 | char *event_data; | ||
| 821 | uint32 type, status; | ||
| 822 | uint16 flags; | ||
| 823 | int evlen; | ||
| 824 | |||
| 825 | if (bcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) { | ||
| 826 | DHD_ERROR(("%s: mismatched OUI, bailing\n", __FUNCTION__)); | ||
| 827 | return (BCME_ERROR); | ||
| 828 | } | ||
| 829 | |||
| 830 | /* BRCM event pkt may be unaligned - use xxx_ua to load user_subtype. */ | ||
| 831 | if (ntoh16_ua((void *)&pvt_data->bcm_hdr.usr_subtype) != BCMILCP_BCM_SUBTYPE_EVENT) { | ||
| 832 | DHD_ERROR(("%s: mismatched subtype, bailing\n", __FUNCTION__)); | ||
| 833 | return (BCME_ERROR); | ||
| 834 | } | ||
| 835 | |||
| 836 | *data_ptr = &pvt_data[1]; | ||
| 837 | event_data = *data_ptr; | ||
| 838 | |||
| 839 | /* memcpy since BRCM event pkt may be unaligned. */ | ||
| 840 | memcpy(event, &pvt_data->event, sizeof(wl_event_msg_t)); | ||
| 841 | |||
| 842 | type = ntoh32_ua((void *)&event->event_type); | ||
| 843 | flags = ntoh16_ua((void *)&event->flags); | ||
| 844 | status = ntoh32_ua((void *)&event->status); | ||
| 845 | evlen = ntoh32_ua((void *)&event->datalen) + sizeof(bcm_event_t); | ||
| 846 | |||
| 847 | switch (type) { | ||
| 848 | case WLC_E_IF: | ||
| 849 | { | ||
| 850 | dhd_if_event_t *ifevent = (dhd_if_event_t *)event_data; | ||
| 851 | DHD_TRACE(("%s: if event\n", __FUNCTION__)); | ||
| 852 | |||
| 853 | if (ifevent->ifidx > 0 && ifevent->ifidx < DHD_MAX_IFS) | ||
| 854 | { | ||
| 855 | if (ifevent->action == WLC_E_IF_ADD) | ||
| 856 | dhd_add_if(dhd, ifevent->ifidx, | ||
| 857 | NULL, event->ifname, | ||
| 858 | pvt_data->eth.ether_dhost, | ||
| 859 | ifevent->flags, ifevent->bssidx); | ||
| 860 | else | ||
| 861 | dhd_del_if(dhd, ifevent->ifidx); | ||
| 862 | } else { | ||
| 863 | DHD_ERROR(("%s: Invalid ifidx %d for %s\n", | ||
| 864 | __FUNCTION__, ifevent->ifidx, event->ifname)); | ||
| 865 | } | ||
| 866 | } | ||
| 867 | /* send up the if event: btamp user needs it */ | ||
| 868 | *ifidx = dhd_ifname2idx(dhd, event->ifname); | ||
| 869 | /* push up to external supp/auth */ | ||
| 870 | dhd_event(dhd, (char *)pvt_data, evlen, *ifidx); | ||
| 871 | break; | ||
| 872 | |||
| 873 | |||
| 874 | #ifdef P2P | ||
| 875 | case WLC_E_NDIS_LINK: | ||
| 876 | break; | ||
| 877 | #endif | ||
| 878 | /* fall through */ | ||
| 879 | /* These are what external supplicant/authenticator wants */ | ||
| 880 | case WLC_E_LINK: | ||
| 881 | case WLC_E_ASSOC_IND: | ||
| 882 | case WLC_E_REASSOC_IND: | ||
| 883 | case WLC_E_DISASSOC_IND: | ||
| 884 | case WLC_E_MIC_ERROR: | ||
| 885 | default: | ||
| 886 | /* Fall through: this should get _everything_ */ | ||
| 887 | |||
| 888 | *ifidx = dhd_ifname2idx(dhd, event->ifname); | ||
| 889 | /* push up to external supp/auth */ | ||
| 890 | dhd_event(dhd, (char *)pvt_data, evlen, *ifidx); | ||
| 891 | DHD_TRACE(("%s: MAC event %d, flags %x, status %x\n", | ||
| 892 | __FUNCTION__, type, flags, status)); | ||
| 893 | |||
| 894 | /* put it back to WLC_E_NDIS_LINK */ | ||
| 895 | if (type == WLC_E_NDIS_LINK) { | ||
| 896 | uint32 temp; | ||
| 897 | |||
| 898 | temp = ntoh32_ua((void *)&event->event_type); | ||
| 899 | DHD_TRACE(("Converted to WLC_E_LINK type %d\n", temp)); | ||
| 900 | |||
| 901 | temp = ntoh32(WLC_E_NDIS_LINK); | ||
| 902 | memcpy((void *)(&pvt_data->event.event_type), &temp, | ||
| 903 | sizeof(pvt_data->event.event_type)); | ||
| 904 | } | ||
| 905 | break; | ||
| 906 | } | ||
| 907 | |||
| 908 | #ifdef SHOW_EVENTS | ||
| 909 | wl_show_host_event(event, event_data); | ||
| 910 | #endif /* SHOW_EVENTS */ | ||
| 911 | |||
| 912 | return (BCME_OK); | ||
| 913 | } | ||
| 914 | |||
| 915 | |||
| 916 | void | ||
| 917 | wl_event_to_host_order(wl_event_msg_t *evt) | ||
| 918 | { | ||
| 919 | /* Event struct members passed from dongle to host are stored in network | ||
| 920 | * byte order. Convert all members to host-order. | ||
| 921 | */ | ||
| 922 | evt->event_type = ntoh32(evt->event_type); | ||
| 923 | evt->flags = ntoh16(evt->flags); | ||
| 924 | evt->status = ntoh32(evt->status); | ||
| 925 | evt->reason = ntoh32(evt->reason); | ||
| 926 | evt->auth_type = ntoh32(evt->auth_type); | ||
| 927 | evt->datalen = ntoh32(evt->datalen); | ||
| 928 | evt->version = ntoh16(evt->version); | ||
| 929 | } | ||
| 930 | |||
| 931 | void print_buf(void *pbuf, int len, int bytes_per_line) | ||
| 932 | { | ||
| 933 | int i, j = 0; | ||
| 934 | unsigned char *buf = pbuf; | ||
| 935 | |||
| 936 | if (bytes_per_line == 0) { | ||
| 937 | bytes_per_line = len; | ||
| 938 | } | ||
| 939 | |||
| 940 | for (i = 0; i < len; i++) { | ||
| 941 | printf("%2.2x", *buf++); | ||
| 942 | j++; | ||
| 943 | if (j == bytes_per_line) { | ||
| 944 | printf("\n"); | ||
| 945 | j = 0; | ||
| 946 | } else { | ||
| 947 | printf(":"); | ||
| 948 | } | ||
| 949 | } | ||
| 950 | printf("\n"); | ||
| 951 | } | ||
| 952 | |||
| 953 | #define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base)) | ||
| 954 | |||
| 955 | #ifdef PKT_FILTER_SUPPORT | ||
| 956 | /* Convert user's input in hex pattern to byte-size mask */ | ||
| 957 | static int | ||
| 958 | wl_pattern_atoh(char *src, char *dst) | ||
| 959 | { | ||
| 960 | int i; | ||
| 961 | if (strncmp(src, "0x", 2) != 0 && | ||
| 962 | strncmp(src, "0X", 2) != 0) { | ||
| 963 | DHD_ERROR(("Mask invalid format. Needs to start with 0x\n")); | ||
| 964 | return -1; | ||
| 965 | } | ||
| 966 | src = src + 2; /* Skip past 0x */ | ||
| 967 | if (strlen(src) % 2 != 0) { | ||
| 968 | DHD_ERROR(("Mask invalid format. Needs to be of even length\n")); | ||
| 969 | return -1; | ||
| 970 | } | ||
| 971 | for (i = 0; *src != '\0'; i++) { | ||
| 972 | char num[3]; | ||
| 973 | strncpy(num, src, 2); | ||
| 974 | num[2] = '\0'; | ||
| 975 | dst[i] = (uint8)strtoul(num, NULL, 16); | ||
| 976 | src += 2; | ||
| 977 | } | ||
| 978 | return i; | ||
| 979 | } | ||
| 980 | |||
| 981 | void | ||
| 982 | dhd_pktfilter_offload_enable(dhd_pub_t * dhd, char *arg, int enable, int master_mode) | ||
| 983 | { | ||
| 984 | char *argv[8]; | ||
| 985 | int i = 0; | ||
| 986 | const char *str; | ||
| 987 | int buf_len; | ||
| 988 | int str_len; | ||
| 989 | char *arg_save = 0, *arg_org = 0; | ||
| 990 | int rc; | ||
| 991 | char buf[128]; | ||
| 992 | wl_pkt_filter_enable_t enable_parm; | ||
| 993 | wl_pkt_filter_enable_t * pkt_filterp; | ||
| 994 | |||
| 995 | if (!arg) | ||
| 996 | return; | ||
| 997 | |||
| 998 | if (!(arg_save = MALLOC(dhd->osh, strlen(arg) + 1))) { | ||
| 999 | DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__)); | ||
| 1000 | goto fail; | ||
| 1001 | } | ||
| 1002 | arg_org = arg_save; | ||
| 1003 | memcpy(arg_save, arg, strlen(arg) + 1); | ||
| 1004 | |||
| 1005 | argv[i] = bcmstrtok(&arg_save, " ", 0); | ||
| 1006 | |||
| 1007 | i = 0; | ||
| 1008 | if (NULL == argv[i]) { | ||
| 1009 | DHD_ERROR(("No args provided\n")); | ||
| 1010 | goto fail; | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | str = "pkt_filter_enable"; | ||
| 1014 | str_len = strlen(str); | ||
| 1015 | strncpy(buf, str, str_len); | ||
| 1016 | buf[str_len] = '\0'; | ||
| 1017 | buf_len = str_len + 1; | ||
| 1018 | |||
| 1019 | pkt_filterp = (wl_pkt_filter_enable_t *)(buf + str_len + 1); | ||
| 1020 | |||
| 1021 | /* Parse packet filter id. */ | ||
| 1022 | enable_parm.id = htod32(strtoul(argv[i], NULL, 0)); | ||
| 1023 | |||
| 1024 | /* Parse enable/disable value. */ | ||
| 1025 | enable_parm.enable = htod32(enable); | ||
| 1026 | |||
| 1027 | buf_len += sizeof(enable_parm); | ||
| 1028 | memcpy((char *)pkt_filterp, | ||
| 1029 | &enable_parm, | ||
| 1030 | sizeof(enable_parm)); | ||
| 1031 | |||
| 1032 | /* Enable/disable the specified filter. */ | ||
| 1033 | rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len); | ||
| 1034 | rc = rc >= 0 ? 0 : rc; | ||
| 1035 | if (rc) | ||
| 1036 | DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n", | ||
| 1037 | __FUNCTION__, arg, rc)); | ||
| 1038 | else | ||
| 1039 | DHD_TRACE(("%s: successfully added pktfilter %s\n", | ||
| 1040 | __FUNCTION__, arg)); | ||
| 1041 | |||
| 1042 | /* Contorl the master mode */ | ||
| 1043 | bcm_mkiovar("pkt_filter_mode", (char *)&master_mode, 4, buf, sizeof(buf)); | ||
| 1044 | rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf)); | ||
| 1045 | rc = rc >= 0 ? 0 : rc; | ||
| 1046 | if (rc) | ||
| 1047 | DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n", | ||
| 1048 | __FUNCTION__, arg, rc)); | ||
| 1049 | |||
| 1050 | fail: | ||
| 1051 | if (arg_org) | ||
| 1052 | MFREE(dhd->osh, arg_org, strlen(arg) + 1); | ||
| 1053 | } | ||
| 1054 | |||
| 1055 | void | ||
| 1056 | dhd_pktfilter_offload_set(dhd_pub_t * dhd, char *arg) | ||
| 1057 | { | ||
| 1058 | const char *str; | ||
| 1059 | wl_pkt_filter_t pkt_filter; | ||
| 1060 | wl_pkt_filter_t *pkt_filterp; | ||
| 1061 | int buf_len; | ||
| 1062 | int str_len; | ||
| 1063 | int rc; | ||
| 1064 | uint32 mask_size; | ||
| 1065 | uint32 pattern_size; | ||
| 1066 | char *argv[8], * buf = 0; | ||
| 1067 | int i = 0; | ||
| 1068 | char *arg_save = 0, *arg_org = 0; | ||
| 1069 | #define BUF_SIZE 2048 | ||
| 1070 | |||
| 1071 | if (!arg) | ||
| 1072 | return; | ||
| 1073 | |||
| 1074 | if (!(arg_save = MALLOC(dhd->osh, strlen(arg) + 1))) { | ||
| 1075 | DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__)); | ||
| 1076 | goto fail; | ||
| 1077 | } | ||
| 1078 | |||
| 1079 | arg_org = arg_save; | ||
| 1080 | |||
| 1081 | if (!(buf = MALLOC(dhd->osh, BUF_SIZE))) { | ||
| 1082 | DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__)); | ||
| 1083 | goto fail; | ||
| 1084 | } | ||
| 1085 | |||
| 1086 | memcpy(arg_save, arg, strlen(arg) + 1); | ||
| 1087 | |||
| 1088 | if (strlen(arg) > BUF_SIZE) { | ||
| 1089 | DHD_ERROR(("Not enough buffer %d < %d\n", (int)strlen(arg), (int)sizeof(buf))); | ||
| 1090 | goto fail; | ||
| 1091 | } | ||
| 1092 | |||
| 1093 | argv[i] = bcmstrtok(&arg_save, " ", 0); | ||
| 1094 | while (argv[i++]) | ||
| 1095 | argv[i] = bcmstrtok(&arg_save, " ", 0); | ||
| 1096 | |||
| 1097 | i = 0; | ||
| 1098 | if (NULL == argv[i]) { | ||
| 1099 | DHD_ERROR(("No args provided\n")); | ||
| 1100 | goto fail; | ||
| 1101 | } | ||
| 1102 | |||
| 1103 | str = "pkt_filter_add"; | ||
| 1104 | str_len = strlen(str); | ||
| 1105 | strncpy(buf, str, str_len); | ||
| 1106 | buf[ str_len ] = '\0'; | ||
| 1107 | buf_len = str_len + 1; | ||
| 1108 | |||
| 1109 | pkt_filterp = (wl_pkt_filter_t *) (buf + str_len + 1); | ||
| 1110 | |||
| 1111 | /* Parse packet filter id. */ | ||
| 1112 | pkt_filter.id = htod32(strtoul(argv[i], NULL, 0)); | ||
| 1113 | |||
| 1114 | if (NULL == argv[++i]) { | ||
| 1115 | DHD_ERROR(("Polarity not provided\n")); | ||
| 1116 | goto fail; | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | /* Parse filter polarity. */ | ||
| 1120 | pkt_filter.negate_match = htod32(strtoul(argv[i], NULL, 0)); | ||
| 1121 | |||
| 1122 | if (NULL == argv[++i]) { | ||
| 1123 | DHD_ERROR(("Filter type not provided\n")); | ||
| 1124 | goto fail; | ||
| 1125 | } | ||
| 1126 | |||
| 1127 | /* Parse filter type. */ | ||
| 1128 | pkt_filter.type = htod32(strtoul(argv[i], NULL, 0)); | ||
| 1129 | |||
| 1130 | if (NULL == argv[++i]) { | ||
| 1131 | DHD_ERROR(("Offset not provided\n")); | ||
| 1132 | goto fail; | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | /* Parse pattern filter offset. */ | ||
| 1136 | pkt_filter.u.pattern.offset = htod32(strtoul(argv[i], NULL, 0)); | ||
| 1137 | |||
| 1138 | if (NULL == argv[++i]) { | ||
| 1139 | DHD_ERROR(("Bitmask not provided\n")); | ||
| 1140 | goto fail; | ||
| 1141 | } | ||
| 1142 | |||
| 1143 | /* Parse pattern filter mask. */ | ||
| 1144 | mask_size = | ||
| 1145 | htod32(wl_pattern_atoh(argv[i], (char *) pkt_filterp->u.pattern.mask_and_pattern)); | ||
| 1146 | |||
| 1147 | if (NULL == argv[++i]) { | ||
| 1148 | DHD_ERROR(("Pattern not provided\n")); | ||
| 1149 | goto fail; | ||
| 1150 | } | ||
| 1151 | |||
| 1152 | /* Parse pattern filter pattern. */ | ||
| 1153 | pattern_size = | ||
| 1154 | htod32(wl_pattern_atoh(argv[i], | ||
| 1155 | (char *) &pkt_filterp->u.pattern.mask_and_pattern[mask_size])); | ||
| 1156 | |||
| 1157 | if (mask_size != pattern_size) { | ||
| 1158 | DHD_ERROR(("Mask and pattern not the same size\n")); | ||
| 1159 | goto fail; | ||
| 1160 | } | ||
| 1161 | |||
| 1162 | pkt_filter.u.pattern.size_bytes = mask_size; | ||
| 1163 | buf_len += WL_PKT_FILTER_FIXED_LEN; | ||
| 1164 | buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size); | ||
| 1165 | |||
| 1166 | /* Keep-alive attributes are set in local variable (keep_alive_pkt), and | ||
| 1167 | ** then memcpy'ed into buffer (keep_alive_pktp) since there is no | ||
| 1168 | ** guarantee that the buffer is properly aligned. | ||
| 1169 | */ | ||
| 1170 | memcpy((char *)pkt_filterp, | ||
| 1171 | &pkt_filter, | ||
| 1172 | WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN); | ||
| 1173 | |||
| 1174 | rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len); | ||
| 1175 | rc = rc >= 0 ? 0 : rc; | ||
| 1176 | |||
| 1177 | if (rc) | ||
| 1178 | DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n", | ||
| 1179 | __FUNCTION__, arg, rc)); | ||
| 1180 | else | ||
| 1181 | DHD_TRACE(("%s: successfully added pktfilter %s\n", | ||
| 1182 | __FUNCTION__, arg)); | ||
| 1183 | |||
| 1184 | fail: | ||
| 1185 | if (arg_org) | ||
| 1186 | MFREE(dhd->osh, arg_org, strlen(arg) + 1); | ||
| 1187 | |||
| 1188 | if (buf) | ||
| 1189 | MFREE(dhd->osh, buf, BUF_SIZE); | ||
| 1190 | } | ||
| 1191 | #endif | ||
| 1192 | |||
| 1193 | #ifdef ARP_OFFLOAD_SUPPORT | ||
| 1194 | void | ||
| 1195 | dhd_arp_offload_set(dhd_pub_t * dhd, int arp_mode) | ||
| 1196 | { | ||
| 1197 | char iovbuf[32]; | ||
| 1198 | int retcode; | ||
| 1199 | |||
| 1200 | bcm_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf)); | ||
| 1201 | retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); | ||
| 1202 | retcode = retcode >= 0 ? 0 : retcode; | ||
| 1203 | if (retcode) | ||
| 1204 | DHD_TRACE(("%s: failed to set ARP offload mode to 0x%x, retcode = %d\n", | ||
| 1205 | __FUNCTION__, arp_mode, retcode)); | ||
| 1206 | else | ||
| 1207 | DHD_TRACE(("%s: successfully set ARP offload mode to 0x%x\n", | ||
| 1208 | __FUNCTION__, arp_mode)); | ||
| 1209 | } | ||
| 1210 | |||
| 1211 | void | ||
| 1212 | dhd_arp_offload_enable(dhd_pub_t * dhd, int arp_enable) | ||
| 1213 | { | ||
| 1214 | char iovbuf[32]; | ||
| 1215 | int retcode; | ||
| 1216 | |||
| 1217 | bcm_mkiovar("arpoe", (char *)&arp_enable, 4, iovbuf, sizeof(iovbuf)); | ||
| 1218 | retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); | ||
| 1219 | retcode = retcode >= 0 ? 0 : retcode; | ||
| 1220 | if (retcode) | ||
| 1221 | DHD_TRACE(("%s: failed to enabe ARP offload to %d, retcode = %d\n", | ||
| 1222 | __FUNCTION__, arp_enable, retcode)); | ||
| 1223 | else | ||
| 1224 | DHD_TRACE(("%s: successfully enabed ARP offload to %d\n", | ||
| 1225 | __FUNCTION__, arp_enable)); | ||
| 1226 | } | ||
| 1227 | #endif | ||
| 1228 | |||
| 1229 | |||
| 1230 | void dhd_arp_cleanup(dhd_pub_t *dhd) | ||
| 1231 | { | ||
| 1232 | #ifdef ARP_OFFLOAD_SUPPORT | ||
| 1233 | int ret = 0; | ||
| 1234 | int iov_len = 0; | ||
| 1235 | char iovbuf[128]; | ||
| 1236 | |||
| 1237 | if (dhd == NULL) return; | ||
| 1238 | |||
| 1239 | dhd_os_proto_block(dhd); | ||
| 1240 | |||
| 1241 | iov_len = bcm_mkiovar("arp_hostip_clear", 0, 0, iovbuf, sizeof(iovbuf)); | ||
| 1242 | if ((ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, iov_len)) < 0) | ||
| 1243 | DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret)); | ||
| 1244 | |||
| 1245 | iov_len = bcm_mkiovar("arp_table_clear", 0, 0, iovbuf, sizeof(iovbuf)); | ||
| 1246 | if ((ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, iov_len)) < 0) | ||
| 1247 | DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret)); | ||
| 1248 | |||
| 1249 | dhd_os_proto_unblock(dhd); | ||
| 1250 | |||
| 1251 | #endif /* ARP_OFFLOAD_SUPPORT */ | ||
| 1252 | } | ||
| 1253 | |||
| 1254 | void dhd_arp_offload_add_ip(dhd_pub_t *dhd, u32 ipaddr) | ||
| 1255 | { | ||
| 1256 | #ifdef ARP_OFFLOAD_SUPPORT | ||
| 1257 | int iov_len = 0; | ||
| 1258 | char iovbuf[32]; | ||
| 1259 | int retcode; | ||
| 1260 | |||
| 1261 | dhd_os_proto_block(dhd); | ||
| 1262 | |||
| 1263 | iov_len = bcm_mkiovar("arp_hostip", (char *)&ipaddr, 4, iovbuf, sizeof(iovbuf)); | ||
| 1264 | retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, iov_len); | ||
| 1265 | |||
| 1266 | dhd_os_proto_unblock(dhd); | ||
| 1267 | |||
| 1268 | if (retcode) | ||
| 1269 | DHD_TRACE(("%s: ARP ip addr add failed, retcode = %d\n", | ||
| 1270 | __FUNCTION__, retcode)); | ||
| 1271 | else | ||
| 1272 | DHD_TRACE(("%s: ARP ipaddr entry added\n", | ||
| 1273 | __FUNCTION__)); | ||
| 1274 | #endif /* ARP_OFFLOAD_SUPPORT */ | ||
| 1275 | } | ||
| 1276 | |||
| 1277 | |||
| 1278 | int dhd_arp_get_arp_hostip_table(dhd_pub_t *dhd, void *buf, int buflen) | ||
| 1279 | { | ||
| 1280 | #ifdef ARP_OFFLOAD_SUPPORT | ||
| 1281 | int retcode; | ||
| 1282 | int iov_len = 0; | ||
| 1283 | |||
| 1284 | if (!buf) | ||
| 1285 | return -1; | ||
| 1286 | |||
| 1287 | dhd_os_proto_block(dhd); | ||
| 1288 | |||
| 1289 | iov_len = bcm_mkiovar("arp_hostip", 0, 0, buf, buflen); | ||
| 1290 | retcode = dhdcdc_query_ioctl(dhd, 0, WLC_GET_VAR, buf, buflen); | ||
| 1291 | |||
| 1292 | dhd_os_proto_unblock(dhd); | ||
| 1293 | |||
| 1294 | if (retcode) { | ||
| 1295 | DHD_TRACE(("%s: ioctl WLC_GET_VAR error %d\n", | ||
| 1296 | __FUNCTION__, retcode)); | ||
| 1297 | |||
| 1298 | return -1; | ||
| 1299 | } | ||
| 1300 | #endif /* ARP_OFFLOAD_SUPPORT */ | ||
| 1301 | return 0; | ||
| 1302 | } | ||
| 1303 | |||
| 1304 | |||
| 1305 | int | ||
| 1306 | dhd_preinit_ioctls(dhd_pub_t *dhd) | ||
| 1307 | { | ||
| 1308 | char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */ | ||
| 1309 | uint up = 0; | ||
| 1310 | char buf[128], *ptr; | ||
| 1311 | uint power_mode = PM_FAST; | ||
| 1312 | uint32 dongle_align = DHD_SDALIGN; | ||
| 1313 | uint32 glom = 0; | ||
| 1314 | uint bcn_timeout = 4; | ||
| 1315 | int scan_assoc_time = 40; | ||
| 1316 | int scan_unassoc_time = 40; | ||
| 1317 | uint32 listen_interval = LISTEN_INTERVAL; /* Default Listen Interval in Beacons */ | ||
| 1318 | #if defined(SOFTAP) | ||
| 1319 | uint dtim = 1; | ||
| 1320 | #endif | ||
| 1321 | int ret = 0; | ||
| 1322 | #ifdef GET_CUSTOM_MAC_ENABLE | ||
| 1323 | struct ether_addr ea_addr; | ||
| 1324 | #endif /* GET_CUSTOM_MAC_ENABLE */ | ||
| 1325 | |||
| 1326 | dhd_os_proto_block(dhd); | ||
| 1327 | |||
| 1328 | #ifdef GET_CUSTOM_MAC_ENABLE | ||
| 1329 | /* | ||
| 1330 | ** Read MAC address from external customer place | ||
| 1331 | ** NOTE that default mac address has to be present in otp or nvram file | ||
| 1332 | ** to bring up firmware but unique per board mac address maybe provided | ||
| 1333 | ** by customer code | ||
| 1334 | */ | ||
| 1335 | ret = dhd_custom_get_mac_address(ea_addr.octet); | ||
| 1336 | if (!ret) { | ||
| 1337 | bcm_mkiovar("cur_etheraddr", (void *)&ea_addr, ETHER_ADDR_LEN, buf, sizeof(buf)); | ||
| 1338 | ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf)); | ||
| 1339 | if (ret < 0) { | ||
| 1340 | DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret)); | ||
| 1341 | } else | ||
| 1342 | memcpy(dhd->mac.octet, (void *)&ea_addr, ETHER_ADDR_LEN); | ||
| 1343 | } | ||
| 1344 | #endif /* GET_CUSTOM_MAC_ENABLE */ | ||
| 1345 | |||
| 1346 | #ifdef SET_RANDOM_MAC_SOFTAP | ||
| 1347 | if (strstr(fw_path, "apsta") != NULL) { | ||
| 1348 | uint rand_mac; | ||
| 1349 | |||
| 1350 | srandom32((uint)jiffies); | ||
| 1351 | rand_mac = random32(); | ||
| 1352 | iovbuf[0] = 0x02; /* locally administered bit */ | ||
| 1353 | iovbuf[1] = 0x1A; | ||
| 1354 | iovbuf[2] = 0x11; | ||
| 1355 | iovbuf[3] = (unsigned char)(rand_mac & 0x0F) | 0xF0; | ||
| 1356 | iovbuf[4] = (unsigned char)(rand_mac >> 8); | ||
| 1357 | iovbuf[5] = (unsigned char)(rand_mac >> 16); | ||
| 1358 | |||
| 1359 | printk("Broadcom Dongle Host Driver mac=%02x:%02x:%02x:%02x:%02x:%02x\n", | ||
| 1360 | iovbuf[0], iovbuf[1], iovbuf[2], iovbuf[3], iovbuf[4], iovbuf[5]); | ||
| 1361 | |||
| 1362 | bcm_mkiovar("cur_etheraddr", (void *)iovbuf, ETHER_ADDR_LEN, buf, sizeof(buf)); | ||
| 1363 | ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf)); | ||
| 1364 | if (ret < 0) { | ||
| 1365 | DHD_ERROR(("%s: can't set MAC address , error=%d\n", __FUNCTION__, ret)); | ||
| 1366 | } else | ||
| 1367 | memcpy(dhd->mac.octet, iovbuf, ETHER_ADDR_LEN); | ||
| 1368 | } | ||
| 1369 | #endif /* SET_RANDOM_MAC_SOFTAP */ | ||
| 1370 | |||
| 1371 | /* Set Country code */ | ||
| 1372 | if (dhd->dhd_cspec.ccode[0] != 0) { | ||
| 1373 | bcm_mkiovar("country", (char *)&dhd->dhd_cspec, \ | ||
| 1374 | sizeof(wl_country_t), iovbuf, sizeof(iovbuf)); | ||
| 1375 | if ((ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf))) < 0) { | ||
| 1376 | DHD_ERROR(("%s: country code setting failed\n", __FUNCTION__)); | ||
| 1377 | } | ||
| 1378 | } | ||
| 1379 | |||
| 1380 | /* Set Listen Interval */ | ||
| 1381 | bcm_mkiovar("assoc_listen", (char *)&listen_interval, 4, iovbuf, sizeof(iovbuf)); | ||
| 1382 | if ((ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf))) < 0) | ||
| 1383 | DHD_ERROR(("%s assoc_listen failed %d\n", __FUNCTION__, ret)); | ||
| 1384 | |||
| 1385 | /* query for 'ver' to get version info from firmware */ | ||
| 1386 | memset(buf, 0, sizeof(buf)); | ||
| 1387 | ptr = buf; | ||
| 1388 | bcm_mkiovar("ver", 0, 0, buf, sizeof(buf)); | ||
| 1389 | dhdcdc_query_ioctl(dhd, 0, WLC_GET_VAR, buf, sizeof(buf)); | ||
| 1390 | bcmstrtok(&ptr, "\n", 0); | ||
| 1391 | /* Print fw version info */ | ||
| 1392 | DHD_ERROR(("Firmware version = %s\n", buf)); | ||
| 1393 | |||
| 1394 | /* Set PowerSave mode */ | ||
| 1395 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode, sizeof(power_mode)); | ||
| 1396 | |||
| 1397 | /* Match Host and Dongle rx alignment */ | ||
| 1398 | bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf, sizeof(iovbuf)); | ||
| 1399 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); | ||
| 1400 | |||
| 1401 | /* disable glom option per default */ | ||
| 1402 | bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf)); | ||
| 1403 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); | ||
| 1404 | |||
| 1405 | /* Setup timeout if Beacons are lost and roam is off to report link down */ | ||
| 1406 | bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf, sizeof(iovbuf)); | ||
| 1407 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); | ||
| 1408 | |||
| 1409 | /* Enable/Disable build-in roaming to allowed ext supplicant to take of romaing */ | ||
| 1410 | bcm_mkiovar("roam_off", (char *)&dhd_roam, 4, iovbuf, sizeof(iovbuf)); | ||
| 1411 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); | ||
| 1412 | |||
| 1413 | #if defined(SOFTAP) | ||
| 1414 | if (ap_fw_loaded == TRUE) { | ||
| 1415 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_DTIMPRD, (char *)&dtim, sizeof(dtim)); | ||
| 1416 | } | ||
| 1417 | #endif | ||
| 1418 | |||
| 1419 | if (dhd_roam == 0) | ||
| 1420 | { | ||
| 1421 | /* set internal roaming roaming parameters */ | ||
| 1422 | int roam_scan_period = 30; /* in sec */ | ||
| 1423 | int roam_fullscan_period = 120; /* in sec */ | ||
| 1424 | int roam_trigger = -85; | ||
| 1425 | int roam_delta = 15; | ||
| 1426 | int band; | ||
| 1427 | int band_temp_set = WLC_BAND_2G; | ||
| 1428 | |||
| 1429 | if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_ROAM_SCAN_PERIOD, \ | ||
| 1430 | (char *)&roam_scan_period, sizeof(roam_scan_period)) < 0) | ||
| 1431 | DHD_ERROR(("%s: roam scan setup failed\n", __FUNCTION__)); | ||
| 1432 | |||
| 1433 | bcm_mkiovar("fullroamperiod", (char *)&roam_fullscan_period, \ | ||
| 1434 | 4, iovbuf, sizeof(iovbuf)); | ||
| 1435 | if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, \ | ||
| 1436 | iovbuf, sizeof(iovbuf)) < 0) | ||
| 1437 | DHD_ERROR(("%s: roam fullscan setup failed\n", __FUNCTION__)); | ||
| 1438 | |||
| 1439 | if (dhdcdc_query_ioctl(dhd, 0, WLC_GET_BAND, \ | ||
| 1440 | (char *)&band, sizeof(band)) < 0) | ||
| 1441 | DHD_ERROR(("%s: roam delta setting failed\n", __FUNCTION__)); | ||
| 1442 | else { | ||
| 1443 | if ((band == WLC_BAND_AUTO) || (band == WLC_BAND_ALL)) | ||
| 1444 | { | ||
| 1445 | /* temp set band to insert new roams values */ | ||
| 1446 | if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_BAND, \ | ||
| 1447 | (char *)&band_temp_set, sizeof(band_temp_set)) < 0) | ||
| 1448 | DHD_ERROR(("%s: local band seting failed\n", __FUNCTION__)); | ||
| 1449 | } | ||
| 1450 | if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_ROAM_DELTA, \ | ||
| 1451 | (char *)&roam_delta, sizeof(roam_delta)) < 0) | ||
| 1452 | DHD_ERROR(("%s: roam delta setting failed\n", __FUNCTION__)); | ||
| 1453 | |||
| 1454 | if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_ROAM_TRIGGER, \ | ||
| 1455 | (char *)&roam_trigger, sizeof(roam_trigger)) < 0) | ||
| 1456 | DHD_ERROR(("%s: roam trigger setting failed\n", __FUNCTION__)); | ||
| 1457 | |||
| 1458 | /* Restore original band settinngs */ | ||
| 1459 | if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_BAND, \ | ||
| 1460 | (char *)&band, sizeof(band)) < 0) | ||
| 1461 | DHD_ERROR(("%s: Original band restore failed\n", __FUNCTION__)); | ||
| 1462 | } | ||
| 1463 | } | ||
| 1464 | |||
| 1465 | /* Force STA UP */ | ||
| 1466 | if (dhd_radio_up) | ||
| 1467 | dhdcdc_set_ioctl(dhd, 0, WLC_UP, (char *)&up, sizeof(up)); | ||
| 1468 | |||
| 1469 | /* Setup event_msgs */ | ||
| 1470 | bcm_mkiovar("event_msgs", dhd->eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf)); | ||
| 1471 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); | ||
| 1472 | |||
| 1473 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_CHANNEL_TIME, (char *)&scan_assoc_time, | ||
| 1474 | sizeof(scan_assoc_time)); | ||
| 1475 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_UNASSOC_TIME, (char *)&scan_unassoc_time, | ||
| 1476 | sizeof(scan_unassoc_time)); | ||
| 1477 | |||
| 1478 | #ifdef ARP_OFFLOAD_SUPPORT | ||
| 1479 | /* Set and enable ARP offload feature */ | ||
| 1480 | if (dhd_arp_enable) | ||
| 1481 | dhd_arp_offload_set(dhd, dhd_arp_mode); | ||
| 1482 | dhd_arp_offload_enable(dhd, dhd_arp_enable); | ||
| 1483 | #endif /* ARP_OFFLOAD_SUPPORT */ | ||
| 1484 | |||
| 1485 | #ifdef PKT_FILTER_SUPPORT | ||
| 1486 | { | ||
| 1487 | int i; | ||
| 1488 | /* Set up pkt filter */ | ||
| 1489 | if (dhd_pkt_filter_enable) { | ||
| 1490 | for (i = 0; i < dhd->pktfilter_count; i++) { | ||
| 1491 | dhd_pktfilter_offload_set(dhd, dhd->pktfilter[i]); | ||
| 1492 | dhd_pktfilter_offload_enable(dhd, dhd->pktfilter[i], | ||
| 1493 | dhd_pkt_filter_init, dhd_master_mode); | ||
| 1494 | } | ||
| 1495 | } | ||
| 1496 | } | ||
| 1497 | #endif /* PKT_FILTER_SUPPORT */ | ||
| 1498 | |||
| 1499 | #if defined(KEEP_ALIVE) | ||
| 1500 | { | ||
| 1501 | /* Set Keep Alive : be sure to use FW with -keepalive */ | ||
| 1502 | int res; | ||
| 1503 | |||
| 1504 | if (ap_fw_loaded == FALSE) { | ||
| 1505 | if ((res = dhd_keep_alive_onoff(dhd, 1)) < 0) | ||
| 1506 | DHD_ERROR(("%s set keeplive failed %d\n", \ | ||
| 1507 | __FUNCTION__, res)); | ||
| 1508 | } | ||
| 1509 | } | ||
| 1510 | #endif | ||
| 1511 | |||
| 1512 | dhd_os_proto_unblock(dhd); | ||
| 1513 | |||
| 1514 | return 0; | ||
| 1515 | } | ||
| 1516 | |||
| 1517 | #ifdef SIMPLE_ISCAN | ||
| 1518 | |||
| 1519 | uint iscan_thread_id; | ||
| 1520 | iscan_buf_t * iscan_chain = 0; | ||
| 1521 | |||
| 1522 | iscan_buf_t * | ||
| 1523 | dhd_iscan_allocate_buf(dhd_pub_t *dhd, iscan_buf_t **iscanbuf) | ||
| 1524 | { | ||
| 1525 | iscan_buf_t *iscanbuf_alloc = 0; | ||
| 1526 | iscan_buf_t *iscanbuf_head; | ||
| 1527 | |||
| 1528 | dhd_iscan_lock(); | ||
| 1529 | |||
| 1530 | iscanbuf_alloc = (iscan_buf_t*)MALLOC(dhd->osh, sizeof(iscan_buf_t)); | ||
| 1531 | if (iscanbuf_alloc == NULL) | ||
| 1532 | goto fail; | ||
| 1533 | |||
| 1534 | iscanbuf_alloc->next = NULL; | ||
| 1535 | iscanbuf_head = *iscanbuf; | ||
| 1536 | |||
| 1537 | DHD_ISCAN(("%s: addr of allocated node = 0x%X" | ||
| 1538 | "addr of iscanbuf_head = 0x%X dhd = 0x%X\n", | ||
| 1539 | __FUNCTION__, iscanbuf_alloc, iscanbuf_head, dhd)); | ||
| 1540 | |||
| 1541 | if (iscanbuf_head == NULL) { | ||
| 1542 | *iscanbuf = iscanbuf_alloc; | ||
| 1543 | DHD_ISCAN(("%s: Head is allocated\n", __FUNCTION__)); | ||
| 1544 | goto fail; | ||
| 1545 | } | ||
| 1546 | |||
| 1547 | while (iscanbuf_head->next) | ||
| 1548 | iscanbuf_head = iscanbuf_head->next; | ||
| 1549 | |||
| 1550 | iscanbuf_head->next = iscanbuf_alloc; | ||
| 1551 | |||
| 1552 | fail: | ||
| 1553 | dhd_iscan_unlock(); | ||
| 1554 | return iscanbuf_alloc; | ||
| 1555 | } | ||
| 1556 | |||
| 1557 | void | ||
| 1558 | dhd_iscan_free_buf(void *dhdp, iscan_buf_t *iscan_delete) | ||
| 1559 | { | ||
| 1560 | iscan_buf_t *iscanbuf_free = 0; | ||
| 1561 | iscan_buf_t *iscanbuf_prv = 0; | ||
| 1562 | iscan_buf_t *iscanbuf_cur = iscan_chain; | ||
| 1563 | dhd_pub_t *dhd = dhd_bus_pub(dhdp); | ||
| 1564 | |||
| 1565 | dhd_iscan_lock(); | ||
| 1566 | /* If iscan_delete is null then delete the entire | ||
| 1567 | * chain or else delete specific one provided | ||
| 1568 | */ | ||
| 1569 | if (!iscan_delete) { | ||
| 1570 | while (iscanbuf_cur) { | ||
| 1571 | iscanbuf_free = iscanbuf_cur; | ||
| 1572 | iscanbuf_cur = iscanbuf_cur->next; | ||
| 1573 | iscanbuf_free->next = 0; | ||
| 1574 | MFREE(dhd->osh, iscanbuf_free, sizeof(iscan_buf_t)); | ||
| 1575 | } | ||
| 1576 | iscan_chain = 0; | ||
| 1577 | } else { | ||
| 1578 | while (iscanbuf_cur) { | ||
| 1579 | if (iscanbuf_cur == iscan_delete) | ||
| 1580 | break; | ||
| 1581 | iscanbuf_prv = iscanbuf_cur; | ||
| 1582 | iscanbuf_cur = iscanbuf_cur->next; | ||
| 1583 | } | ||
| 1584 | if (iscanbuf_prv) | ||
| 1585 | iscanbuf_prv->next = iscan_delete->next; | ||
| 1586 | |||
| 1587 | iscan_delete->next = 0; | ||
| 1588 | MFREE(dhd->osh, iscan_delete, sizeof(iscan_buf_t)); | ||
| 1589 | |||
| 1590 | if (!iscanbuf_prv) | ||
| 1591 | iscan_chain = 0; | ||
| 1592 | } | ||
| 1593 | dhd_iscan_unlock(); | ||
| 1594 | } | ||
| 1595 | |||
| 1596 | iscan_buf_t * | ||
| 1597 | dhd_iscan_result_buf(void) | ||
| 1598 | { | ||
| 1599 | return iscan_chain; | ||
| 1600 | } | ||
| 1601 | |||
| 1602 | |||
| 1603 | |||
| 1604 | /* | ||
| 1605 | * print scan cache | ||
| 1606 | * print partial iscan_skip list differently | ||
| 1607 | */ | ||
| 1608 | int | ||
| 1609 | dhd_iscan_print_cache(iscan_buf_t *iscan_skip) | ||
| 1610 | { | ||
| 1611 | int i = 0, l = 0; | ||
| 1612 | iscan_buf_t *iscan_cur; | ||
| 1613 | wl_iscan_results_t *list; | ||
| 1614 | wl_scan_results_t *results; | ||
| 1615 | wl_bss_info_t UNALIGNED *bi; | ||
| 1616 | |||
| 1617 | dhd_iscan_lock(); | ||
| 1618 | |||
| 1619 | iscan_cur = dhd_iscan_result_buf(); | ||
| 1620 | |||
| 1621 | while (iscan_cur) { | ||
| 1622 | list = (wl_iscan_results_t *)iscan_cur->iscan_buf; | ||
| 1623 | if (!list) | ||
| 1624 | break; | ||
| 1625 | |||
| 1626 | results = (wl_scan_results_t *)&list->results; | ||
| 1627 | if (!results) | ||
| 1628 | break; | ||
| 1629 | |||
| 1630 | if (results->version != WL_BSS_INFO_VERSION) { | ||
| 1631 | DHD_ISCAN(("%s: results->version %d != WL_BSS_INFO_VERSION\n", | ||
| 1632 | __FUNCTION__, results->version)); | ||
| 1633 | goto done; | ||
| 1634 | } | ||
| 1635 | |||
| 1636 | bi = results->bss_info; | ||
| 1637 | for (i = 0; i < results->count; i++) { | ||
| 1638 | if (!bi) | ||
| 1639 | break; | ||
| 1640 | |||
| 1641 | DHD_ISCAN(("%s[%2.2d:%2.2d] %X:%X:%X:%X:%X:%X\n", | ||
| 1642 | iscan_cur != iscan_skip?"BSS":"bss", l, i, | ||
| 1643 | bi->BSSID.octet[0], bi->BSSID.octet[1], bi->BSSID.octet[2], | ||
| 1644 | bi->BSSID.octet[3], bi->BSSID.octet[4], bi->BSSID.octet[5])); | ||
| 1645 | |||
| 1646 | bi = (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)); | ||
| 1647 | } | ||
| 1648 | iscan_cur = iscan_cur->next; | ||
| 1649 | l++; | ||
| 1650 | } | ||
| 1651 | |||
| 1652 | done: | ||
| 1653 | dhd_iscan_unlock(); | ||
| 1654 | return 0; | ||
| 1655 | } | ||
| 1656 | |||
| 1657 | /* | ||
| 1658 | * delete disappeared AP from specific scan cache but skip partial list in iscan_skip | ||
| 1659 | */ | ||
| 1660 | int | ||
| 1661 | dhd_iscan_delete_bss(void *dhdp, void *addr, iscan_buf_t *iscan_skip) | ||
| 1662 | { | ||
| 1663 | int i = 0, j = 0, l = 0; | ||
| 1664 | iscan_buf_t *iscan_cur; | ||
| 1665 | wl_iscan_results_t *list; | ||
| 1666 | wl_scan_results_t *results; | ||
| 1667 | wl_bss_info_t UNALIGNED *bi, *bi_new, *bi_next; | ||
| 1668 | |||
| 1669 | uchar *s_addr = addr; | ||
| 1670 | |||
| 1671 | dhd_iscan_lock(); | ||
| 1672 | DHD_ISCAN(("%s: BSS to remove %X:%X:%X:%X:%X:%X\n", | ||
| 1673 | __FUNCTION__, s_addr[0], s_addr[1], s_addr[2], | ||
| 1674 | s_addr[3], s_addr[4], s_addr[5])); | ||
| 1675 | |||
| 1676 | iscan_cur = dhd_iscan_result_buf(); | ||
| 1677 | |||
| 1678 | while (iscan_cur) { | ||
| 1679 | if (iscan_cur != iscan_skip) { | ||
| 1680 | list = (wl_iscan_results_t *)iscan_cur->iscan_buf; | ||
| 1681 | if (!list) | ||
| 1682 | break; | ||
| 1683 | |||
| 1684 | results = (wl_scan_results_t *)&list->results; | ||
| 1685 | if (!results) | ||
| 1686 | break; | ||
| 1687 | |||
| 1688 | if (results->version != WL_BSS_INFO_VERSION) { | ||
| 1689 | DHD_ERROR(("%s: results->version %d != WL_BSS_INFO_VERSION\n", | ||
| 1690 | __FUNCTION__, results->version)); | ||
| 1691 | goto done; | ||
| 1692 | } | ||
| 1693 | |||
| 1694 | bi = results->bss_info; | ||
| 1695 | for (i = 0; i < results->count; i++) { | ||
| 1696 | if (!bi) | ||
| 1697 | break; | ||
| 1698 | |||
| 1699 | if (!memcmp(bi->BSSID.octet, addr, ETHER_ADDR_LEN)) { | ||
| 1700 | DHD_ISCAN(("%s: Del BSS[%2.2d:%2.2d] %X:%X:%X:%X:%X:%X\n", | ||
| 1701 | __FUNCTION__, l, i, bi->BSSID.octet[0], | ||
| 1702 | bi->BSSID.octet[1], bi->BSSID.octet[2], | ||
| 1703 | bi->BSSID.octet[3], bi->BSSID.octet[4], | ||
| 1704 | bi->BSSID.octet[5])); | ||
| 1705 | |||
| 1706 | bi_new = bi; | ||
| 1707 | bi = (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)); | ||
| 1708 | /* | ||
| 1709 | if(bi && bi_new) { | ||
| 1710 | bcopy(bi, bi_new, results->buflen - | ||
| 1711 | dtoh32(bi_new->length)); | ||
| 1712 | results->buflen -= dtoh32(bi_new->length); | ||
| 1713 | } | ||
| 1714 | */ | ||
| 1715 | results->buflen -= dtoh32(bi_new->length); | ||
| 1716 | results->count--; | ||
| 1717 | |||
| 1718 | for (j = i; j < results->count; j++) { | ||
| 1719 | if (bi && bi_new) { | ||
| 1720 | DHD_ISCAN(("%s: Moved up BSS[%2.2d:%2.2d]" | ||
| 1721 | "%X:%X:%X:%X:%X:%X\n", | ||
| 1722 | __FUNCTION__, l, j, bi->BSSID.octet[0], | ||
| 1723 | bi->BSSID.octet[1], bi->BSSID.octet[2], | ||
| 1724 | bi->BSSID.octet[3], bi->BSSID.octet[4], | ||
| 1725 | bi->BSSID.octet[5])); | ||
| 1726 | |||
| 1727 | bi_next = (wl_bss_info_t *)((uintptr)bi + | ||
| 1728 | dtoh32(bi->length)); | ||
| 1729 | bcopy(bi, bi_new, dtoh32(bi->length)); | ||
| 1730 | bi_new = (wl_bss_info_t *)((uintptr)bi_new + | ||
| 1731 | dtoh32(bi_new->length)); | ||
| 1732 | bi = bi_next; | ||
| 1733 | } | ||
| 1734 | } | ||
| 1735 | |||
| 1736 | if (results->count == 0) { | ||
| 1737 | /* Prune now empty partial scan list */ | ||
| 1738 | dhd_iscan_free_buf(dhdp, iscan_cur); | ||
| 1739 | goto done; | ||
| 1740 | } | ||
| 1741 | break; | ||
| 1742 | } | ||
| 1743 | bi = (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)); | ||
| 1744 | } | ||
| 1745 | } | ||
| 1746 | iscan_cur = iscan_cur->next; | ||
| 1747 | l++; | ||
| 1748 | } | ||
| 1749 | |||
| 1750 | done: | ||
| 1751 | dhd_iscan_unlock(); | ||
| 1752 | return 0; | ||
| 1753 | } | ||
| 1754 | |||
| 1755 | int | ||
| 1756 | dhd_iscan_remove_duplicates(void * dhdp, iscan_buf_t *iscan_cur) | ||
| 1757 | { | ||
| 1758 | int i = 0; | ||
| 1759 | wl_iscan_results_t *list; | ||
| 1760 | wl_scan_results_t *results; | ||
| 1761 | wl_bss_info_t UNALIGNED *bi, *bi_new, *bi_next; | ||
| 1762 | |||
| 1763 | dhd_iscan_lock(); | ||
| 1764 | |||
| 1765 | DHD_ISCAN(("%s: Scan cache before delete\n", | ||
| 1766 | __FUNCTION__)); | ||
| 1767 | dhd_iscan_print_cache(iscan_cur); | ||
| 1768 | |||
| 1769 | if (!iscan_cur) | ||
| 1770 | goto done; | ||
| 1771 | |||
| 1772 | list = (wl_iscan_results_t *)iscan_cur->iscan_buf; | ||
| 1773 | if (!list) | ||
| 1774 | goto done; | ||
| 1775 | |||
| 1776 | results = (wl_scan_results_t *)&list->results; | ||
| 1777 | if (!results) | ||
| 1778 | goto done; | ||
| 1779 | |||
| 1780 | if (results->version != WL_BSS_INFO_VERSION) { | ||
| 1781 | DHD_ERROR(("%s: results->version %d != WL_BSS_INFO_VERSION\n", | ||
| 1782 | __FUNCTION__, results->version)); | ||
| 1783 | goto done; | ||
| 1784 | } | ||
| 1785 | |||
| 1786 | bi = results->bss_info; | ||
| 1787 | for (i = 0; i < results->count; i++) { | ||
| 1788 | if (!bi) | ||
| 1789 | break; | ||
| 1790 | |||
| 1791 | DHD_ISCAN(("%s: Find dups for BSS[%2.2d] %X:%X:%X:%X:%X:%X\n", | ||
| 1792 | __FUNCTION__, i, bi->BSSID.octet[0], bi->BSSID.octet[1], bi->BSSID.octet[2], | ||
| 1793 | bi->BSSID.octet[3], bi->BSSID.octet[4], bi->BSSID.octet[5])); | ||
| 1794 | |||
| 1795 | dhd_iscan_delete_bss(dhdp, bi->BSSID.octet, iscan_cur); | ||
| 1796 | |||
| 1797 | bi = (wl_bss_info_t *)((uintptr)bi + dtoh32(bi->length)); | ||
| 1798 | } | ||
| 1799 | |||
| 1800 | done: | ||
| 1801 | DHD_ISCAN(("%s: Scan cache after delete\n", __FUNCTION__)); | ||
| 1802 | dhd_iscan_print_cache(iscan_cur); | ||
| 1803 | dhd_iscan_unlock(); | ||
| 1804 | return 0; | ||
| 1805 | } | ||
| 1806 | |||
| 1807 | void | ||
| 1808 | dhd_iscan_ind_scan_confirm(void *dhdp, bool status) | ||
| 1809 | { | ||
| 1810 | |||
| 1811 | dhd_ind_scan_confirm(dhdp, status); | ||
| 1812 | } | ||
| 1813 | |||
| 1814 | int | ||
| 1815 | dhd_iscan_request(void * dhdp, uint16 action) | ||
| 1816 | { | ||
| 1817 | int rc; | ||
| 1818 | wl_iscan_params_t params; | ||
| 1819 | dhd_pub_t *dhd = dhd_bus_pub(dhdp); | ||
| 1820 | char buf[WLC_IOCTL_SMLEN]; | ||
| 1821 | |||
| 1822 | |||
| 1823 | memset(¶ms, 0, sizeof(wl_iscan_params_t)); | ||
| 1824 | memcpy(¶ms.params.bssid, ðer_bcast, ETHER_ADDR_LEN); | ||
| 1825 | |||
| 1826 | params.params.bss_type = DOT11_BSSTYPE_ANY; | ||
| 1827 | params.params.scan_type = DOT11_SCANTYPE_ACTIVE; | ||
| 1828 | |||
| 1829 | params.params.nprobes = htod32(-1); | ||
| 1830 | params.params.active_time = htod32(-1); | ||
| 1831 | params.params.passive_time = htod32(-1); | ||
| 1832 | params.params.home_time = htod32(-1); | ||
| 1833 | params.params.channel_num = htod32(0); | ||
| 1834 | |||
| 1835 | params.version = htod32(ISCAN_REQ_VERSION); | ||
| 1836 | params.action = htod16(action); | ||
| 1837 | params.scan_duration = htod16(0); | ||
| 1838 | |||
| 1839 | bcm_mkiovar("iscan", (char *)¶ms, sizeof(wl_iscan_params_t), buf, WLC_IOCTL_SMLEN); | ||
| 1840 | rc = dhd_wl_ioctl(dhdp, WLC_SET_VAR, buf, WLC_IOCTL_SMLEN); | ||
| 1841 | |||
| 1842 | return rc; | ||
| 1843 | } | ||
| 1844 | |||
| 1845 | static int | ||
| 1846 | dhd_iscan_get_partial_result(void *dhdp, uint *scan_count) | ||
| 1847 | { | ||
| 1848 | wl_iscan_results_t *list_buf; | ||
| 1849 | wl_iscan_results_t list; | ||
| 1850 | wl_scan_results_t *results; | ||
| 1851 | iscan_buf_t *iscan_cur; | ||
| 1852 | int status = -1; | ||
| 1853 | dhd_pub_t *dhd = dhd_bus_pub(dhdp); | ||
| 1854 | int rc; | ||
| 1855 | |||
| 1856 | |||
| 1857 | iscan_cur = dhd_iscan_allocate_buf(dhd, &iscan_chain); | ||
| 1858 | if (!iscan_cur) { | ||
| 1859 | DHD_ERROR(("%s: Failed to allocate node\n", __FUNCTION__)); | ||
| 1860 | dhd_iscan_free_buf(dhdp, 0); | ||
| 1861 | dhd_iscan_request(dhdp, WL_SCAN_ACTION_ABORT); | ||
| 1862 | goto fail; | ||
| 1863 | } | ||
| 1864 | |||
| 1865 | dhd_iscan_lock(); | ||
| 1866 | |||
| 1867 | memset(iscan_cur->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN); | ||
| 1868 | list_buf = (wl_iscan_results_t*)iscan_cur->iscan_buf; | ||
| 1869 | results = &list_buf->results; | ||
| 1870 | results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE; | ||
| 1871 | results->version = 0; | ||
| 1872 | results->count = 0; | ||
| 1873 | |||
| 1874 | memset(&list, 0, sizeof(list)); | ||
| 1875 | list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN); | ||
| 1876 | bcm_mkiovar("iscanresults", (char *)&list, WL_ISCAN_RESULTS_FIXED_SIZE, | ||
| 1877 | iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN); | ||
| 1878 | rc = dhd_wl_ioctl(dhdp, WLC_GET_VAR, iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN); | ||
| 1879 | |||
| 1880 | results->buflen = dtoh32(results->buflen); | ||
| 1881 | results->version = dtoh32(results->version); | ||
| 1882 | *scan_count = results->count = dtoh32(results->count); | ||
| 1883 | status = dtoh32(list_buf->status); | ||
| 1884 | |||
| 1885 | dhd_iscan_unlock(); | ||
| 1886 | |||
| 1887 | if (!(*scan_count)) | ||
| 1888 | dhd_iscan_free_buf(dhdp, iscan_cur); | ||
| 1889 | else | ||
| 1890 | dhd_iscan_remove_duplicates(dhdp, iscan_cur); | ||
| 1891 | |||
| 1892 | |||
| 1893 | fail: | ||
| 1894 | return status; | ||
| 1895 | } | ||
| 1896 | |||
| 1897 | #endif | ||
| 1898 | |||
| 1899 | /* Function to estimate possible DTIM_SKIP value */ | ||
| 1900 | int dhd_get_dtim_skip(dhd_pub_t *dhd) | ||
| 1901 | { | ||
| 1902 | int bcn_li_dtim; | ||
| 1903 | char buf[128]; | ||
| 1904 | int ret; | ||
| 1905 | int dtim_assoc = 0; | ||
| 1906 | |||
| 1907 | if ((dhd->dtim_skip == 0) || (dhd->dtim_skip == 1)) | ||
| 1908 | bcn_li_dtim = 3; | ||
| 1909 | else | ||
| 1910 | bcn_li_dtim = dhd->dtim_skip; | ||
| 1911 | |||
| 1912 | /* Read DTIM value if associated */ | ||
| 1913 | memset(buf, 0, sizeof(buf)); | ||
| 1914 | bcm_mkiovar("dtim_assoc", 0, 0, buf, sizeof(buf)); | ||
| 1915 | if ((ret = dhdcdc_query_ioctl(dhd, 0, WLC_GET_VAR, buf, sizeof(buf))) < 0) { | ||
| 1916 | DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret)); | ||
| 1917 | bcn_li_dtim = 1; | ||
| 1918 | goto exit; | ||
| 1919 | } | ||
| 1920 | else | ||
| 1921 | dtim_assoc = dtoh32(*(int *)buf); | ||
| 1922 | |||
| 1923 | DHD_ERROR(("%s bcn_li_dtim=%d DTIM=%d Listen=%d\n", \ | ||
| 1924 | __FUNCTION__, bcn_li_dtim, dtim_assoc, LISTEN_INTERVAL)); | ||
| 1925 | |||
| 1926 | /* if not assocated just eixt */ | ||
| 1927 | if (dtim_assoc == 0) { | ||
| 1928 | goto exit; | ||
| 1929 | } | ||
| 1930 | |||
| 1931 | /* check if sta listen interval fits into AP dtim */ | ||
| 1932 | if (dtim_assoc > LISTEN_INTERVAL) { | ||
| 1933 | /* AP DTIM to big for our Listen Interval : no dtim skiping */ | ||
| 1934 | bcn_li_dtim = 1; | ||
| 1935 | DHD_ERROR(("%s DTIM=%d > Listen=%d : too big ...\n", \ | ||
| 1936 | __FUNCTION__, dtim_assoc, LISTEN_INTERVAL)); | ||
| 1937 | goto exit; | ||
| 1938 | } | ||
| 1939 | |||
| 1940 | if ((bcn_li_dtim * dtim_assoc) > LISTEN_INTERVAL) { | ||
| 1941 | /* Round up dtim_skip to fit into STAs Listen Interval */ | ||
| 1942 | bcn_li_dtim = (int)(LISTEN_INTERVAL / dtim_assoc); | ||
| 1943 | DHD_TRACE(("%s agjust dtim_skip as %d\n", __FUNCTION__, bcn_li_dtim)); | ||
| 1944 | } | ||
| 1945 | |||
| 1946 | exit: | ||
| 1947 | return bcn_li_dtim; | ||
| 1948 | } | ||
| 1949 | |||
| 1950 | #ifdef PNO_SUPPORT | ||
| 1951 | int dhd_pno_clean(dhd_pub_t *dhd) | ||
| 1952 | { | ||
| 1953 | char iovbuf[128]; | ||
| 1954 | int pfn_enabled = 0; | ||
| 1955 | int iov_len = 0; | ||
| 1956 | int ret; | ||
| 1957 | |||
| 1958 | /* Disable pfn */ | ||
| 1959 | iov_len = bcm_mkiovar("pfn", (char *)&pfn_enabled, 4, iovbuf, sizeof(iovbuf)); | ||
| 1960 | if ((ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf))) >= 0) { | ||
| 1961 | /* clear pfn */ | ||
| 1962 | iov_len = bcm_mkiovar("pfnclear", 0, 0, iovbuf, sizeof(iovbuf)); | ||
| 1963 | if (iov_len) { | ||
| 1964 | if ((ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, iov_len)) < 0) { | ||
| 1965 | DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret)); | ||
| 1966 | } | ||
| 1967 | } | ||
| 1968 | else { | ||
| 1969 | ret = -1; | ||
| 1970 | DHD_ERROR(("%s failed code %d\n", __FUNCTION__, iov_len)); | ||
| 1971 | } | ||
| 1972 | } | ||
| 1973 | else | ||
| 1974 | DHD_ERROR(("%s failed code %d\n", __FUNCTION__, ret)); | ||
| 1975 | |||
| 1976 | return ret; | ||
| 1977 | } | ||
| 1978 | |||
| 1979 | int dhd_pno_enable(dhd_pub_t *dhd, int pfn_enabled) | ||
| 1980 | { | ||
| 1981 | char iovbuf[128]; | ||
| 1982 | uint8 bssid[6]; | ||
| 1983 | int ret = -1; | ||
| 1984 | |||
| 1985 | if ((!dhd) && ((pfn_enabled != 0) || (pfn_enabled != 1))) { | ||
| 1986 | DHD_ERROR(("%s error exit\n", __FUNCTION__)); | ||
| 1987 | return ret; | ||
| 1988 | } | ||
| 1989 | |||
| 1990 | memset(iovbuf, 0, sizeof(iovbuf)); | ||
| 1991 | |||
| 1992 | /* Check if disassoc to enable pno */ | ||
| 1993 | if ((pfn_enabled) && \ | ||
| 1994 | ((ret = dhdcdc_set_ioctl(dhd, 0, WLC_GET_BSSID, \ | ||
| 1995 | (char *)&bssid, ETHER_ADDR_LEN)) == BCME_NOTASSOCIATED)) { | ||
| 1996 | DHD_TRACE(("%s pno enable called in disassoc mode\n", __FUNCTION__)); | ||
| 1997 | } | ||
| 1998 | else if (pfn_enabled) { | ||
| 1999 | DHD_ERROR(("%s pno enable called in assoc mode ret=%d\n", \ | ||
| 2000 | __FUNCTION__, ret)); | ||
| 2001 | return ret; | ||
| 2002 | } | ||
| 2003 | |||
| 2004 | /* Enable/disable PNO */ | ||
| 2005 | if ((ret = bcm_mkiovar("pfn", (char *)&pfn_enabled, 4, iovbuf, sizeof(iovbuf))) > 0) { | ||
| 2006 | if ((ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf))) < 0) { | ||
| 2007 | DHD_ERROR(("%s failed for error=%d\n", __FUNCTION__, ret)); | ||
| 2008 | return ret; | ||
| 2009 | } | ||
| 2010 | else { | ||
| 2011 | dhd->pno_enable = pfn_enabled; | ||
| 2012 | DHD_TRACE(("%s set pno as %d\n", __FUNCTION__, dhd->pno_enable)); | ||
| 2013 | } | ||
| 2014 | } | ||
| 2015 | else DHD_ERROR(("%s failed err=%d\n", __FUNCTION__, ret)); | ||
| 2016 | |||
| 2017 | return ret; | ||
| 2018 | } | ||
| 2019 | |||
| 2020 | /* Function to execute combined scan */ | ||
| 2021 | int | ||
| 2022 | dhd_pno_set(dhd_pub_t *dhd, wlc_ssid_t* ssids_local, int nssid, ushort scan_fr, \ | ||
| 2023 | int pno_repeat, int pno_freq_expo_max) | ||
| 2024 | { | ||
| 2025 | int err = -1; | ||
| 2026 | char iovbuf[128]; | ||
| 2027 | int k, i; | ||
| 2028 | wl_pfn_param_t pfn_param; | ||
| 2029 | wl_pfn_t pfn_element; | ||
| 2030 | |||
| 2031 | DHD_TRACE(("%s nssid=%d nchan=%d\n", __FUNCTION__, nssid, scan_fr)); | ||
| 2032 | |||
| 2033 | if ((!dhd) && (!ssids_local)) { | ||
| 2034 | DHD_ERROR(("%s error exit\n", __FUNCTION__)); | ||
| 2035 | err = -1; | ||
| 2036 | } | ||
| 2037 | |||
| 2038 | /* Check for broadcast ssid */ | ||
| 2039 | for (k = 0; k < nssid; k++) { | ||
| 2040 | if (!ssids_local[k].SSID_len) { | ||
| 2041 | DHD_ERROR(("%d: Broadcast SSID is ilegal for PNO setting\n", k)); | ||
| 2042 | return err; | ||
| 2043 | } | ||
| 2044 | } | ||
| 2045 | /* #define PNO_DUMP 1 */ | ||
| 2046 | #ifdef PNO_DUMP | ||
| 2047 | { | ||
| 2048 | int j; | ||
| 2049 | for (j = 0; j < nssid; j++) { | ||
| 2050 | DHD_ERROR(("%d: scan for %s size =%d\n", j, | ||
| 2051 | ssids_local[j].SSID, ssids_local[j].SSID_len)); | ||
| 2052 | } | ||
| 2053 | } | ||
| 2054 | #endif /* PNO_DUMP */ | ||
| 2055 | |||
| 2056 | /* clean up everything */ | ||
| 2057 | if ((err = dhd_pno_clean(dhd)) < 0) { | ||
| 2058 | DHD_ERROR(("%s failed error=%d\n", __FUNCTION__, err)); | ||
| 2059 | return err; | ||
| 2060 | } | ||
| 2061 | memset(&pfn_param, 0, sizeof(pfn_param)); | ||
| 2062 | memset(&pfn_element, 0, sizeof(pfn_element)); | ||
| 2063 | |||
| 2064 | /* set pfn parameters */ | ||
| 2065 | pfn_param.version = htod32(PFN_VERSION); | ||
| 2066 | pfn_param.flags = htod16((PFN_LIST_ORDER << SORT_CRITERIA_BIT)); | ||
| 2067 | |||
| 2068 | /* check and set extra pno params */ | ||
| 2069 | if ((pno_repeat != 0) || (pno_freq_expo_max != 0)) { | ||
| 2070 | pfn_param.flags |= htod16(ENABLE << ENABLE_ADAPTSCAN_BIT); | ||
| 2071 | pfn_param.repeat_scan = htod32(pno_repeat); | ||
| 2072 | pfn_param.max_freq_adjust = htod32(pno_freq_expo_max); | ||
| 2073 | } | ||
| 2074 | |||
| 2075 | /* set up pno scan fr */ | ||
| 2076 | if (scan_fr != 0) | ||
| 2077 | pfn_param.scan_freq = htod32(scan_fr); | ||
| 2078 | |||
| 2079 | if (pfn_param.scan_freq > PNO_SCAN_MAX_FW_SEC) { | ||
| 2080 | DHD_ERROR(("%s pno freq above %d sec\n", __FUNCTION__, PNO_SCAN_MAX_FW_SEC)); | ||
| 2081 | return err; | ||
| 2082 | } | ||
| 2083 | if (pfn_param.scan_freq < PNO_SCAN_MIN_FW_SEC) { | ||
| 2084 | DHD_ERROR(("%s pno freq less %d sec\n", __FUNCTION__, PNO_SCAN_MIN_FW_SEC)); | ||
| 2085 | return err; | ||
| 2086 | } | ||
| 2087 | |||
| 2088 | bcm_mkiovar("pfn_set", (char *)&pfn_param, sizeof(pfn_param), iovbuf, sizeof(iovbuf)); | ||
| 2089 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf)); | ||
| 2090 | |||
| 2091 | /* set all pfn ssid */ | ||
| 2092 | for (i = 0; i < nssid; i++) { | ||
| 2093 | |||
| 2094 | pfn_element.bss_type = htod32(DOT11_BSSTYPE_INFRASTRUCTURE); | ||
| 2095 | pfn_element.auth = (DOT11_OPEN_SYSTEM); | ||
| 2096 | pfn_element.infra = htod32(1); | ||
| 2097 | |||
| 2098 | memcpy((char *)pfn_element.ssid.SSID, ssids_local[i].SSID, ssids_local[i].SSID_len); | ||
| 2099 | pfn_element.ssid.SSID_len = ssids_local[i].SSID_len; | ||
| 2100 | |||
| 2101 | if ((err = | ||
| 2102 | bcm_mkiovar("pfn_add", (char *)&pfn_element, | ||
| 2103 | sizeof(pfn_element), iovbuf, sizeof(iovbuf))) > 0) { | ||
| 2104 | if ((err = | ||
| 2105 | dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf))) < 0) { | ||
| 2106 | DHD_ERROR(("%s failed for i=%d error=%d\n", | ||
| 2107 | __FUNCTION__, i, err)); | ||
| 2108 | return err; | ||
| 2109 | } | ||
| 2110 | else | ||
| 2111 | DHD_ERROR(("%s set OK with PNO time=%d repeat=%d max_adjust=%d\n", \ | ||
| 2112 | __FUNCTION__, pfn_param.scan_freq, \ | ||
| 2113 | pfn_param.repeat_scan, pfn_param.max_freq_adjust)); | ||
| 2114 | } | ||
| 2115 | else DHD_ERROR(("%s failed err=%d\n", __FUNCTION__, err)); | ||
| 2116 | } | ||
| 2117 | |||
| 2118 | /* Enable PNO */ | ||
| 2119 | /* dhd_pno_enable(dhd, 1); */ | ||
| 2120 | return err; | ||
| 2121 | } | ||
| 2122 | |||
| 2123 | int dhd_pno_get_status(dhd_pub_t *dhd) | ||
| 2124 | { | ||
| 2125 | int ret = -1; | ||
| 2126 | |||
| 2127 | if (!dhd) | ||
| 2128 | return ret; | ||
| 2129 | else | ||
| 2130 | return (dhd->pno_enable); | ||
| 2131 | } | ||
| 2132 | |||
| 2133 | #endif /* PNO_SUPPORT */ | ||
| 2134 | |||
| 2135 | #if defined(KEEP_ALIVE) | ||
| 2136 | int dhd_keep_alive_onoff(dhd_pub_t *dhd, int ka_on) | ||
| 2137 | { | ||
| 2138 | char buf[256]; | ||
| 2139 | char *buf_ptr = buf; | ||
| 2140 | wl_keep_alive_pkt_t keep_alive_pkt; | ||
| 2141 | char * str; | ||
| 2142 | int str_len, buf_len; | ||
| 2143 | int res = 0; | ||
| 2144 | int keep_alive_period = KEEP_ALIVE_PERIOD; /* in ms */ | ||
| 2145 | |||
| 2146 | DHD_TRACE(("%s: ka:%d\n", __FUNCTION__, ka_on)); | ||
| 2147 | |||
| 2148 | if (ka_on) { /* on suspend */ | ||
| 2149 | keep_alive_pkt.period_msec = keep_alive_period; | ||
| 2150 | |||
| 2151 | } else { | ||
| 2152 | /* on resume, turn off keep_alive packets */ | ||
| 2153 | keep_alive_pkt.period_msec = 0; | ||
| 2154 | } | ||
| 2155 | |||
| 2156 | /* IOC var name */ | ||
| 2157 | str = "keep_alive"; | ||
| 2158 | str_len = strlen(str); | ||
| 2159 | strncpy(buf, str, str_len); | ||
| 2160 | buf[str_len] = '\0'; | ||
| 2161 | buf_len = str_len + 1; | ||
| 2162 | |||
| 2163 | /* set ptr to IOCTL payload after the var name */ | ||
| 2164 | buf_ptr += buf_len; /* include term Z */ | ||
| 2165 | |||
| 2166 | /* copy Keep-alive attributes from local var keep_alive_pkt */ | ||
| 2167 | str = NULL_PKT_STR; | ||
| 2168 | keep_alive_pkt.len_bytes = strlen(str); | ||
| 2169 | |||
| 2170 | memcpy(buf_ptr, &keep_alive_pkt, WL_KEEP_ALIVE_FIXED_LEN); | ||
| 2171 | buf_ptr += WL_KEEP_ALIVE_FIXED_LEN; | ||
| 2172 | |||
| 2173 | /* copy packet data */ | ||
| 2174 | memcpy(buf_ptr, str, keep_alive_pkt.len_bytes); | ||
| 2175 | buf_len += (WL_KEEP_ALIVE_FIXED_LEN + keep_alive_pkt.len_bytes); | ||
| 2176 | |||
| 2177 | res = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len); | ||
| 2178 | return res; | ||
| 2179 | } | ||
| 2180 | #endif /* defined(KEEP_ALIVE) */ | ||
| 2181 | |||
| 2182 | #if defined(CSCAN) | ||
| 2183 | |||
| 2184 | /* Androd ComboSCAN support */ | ||
| 2185 | /* | ||
| 2186 | * data parsing from ComboScan tlv list | ||
| 2187 | */ | ||
| 2188 | int | ||
| 2189 | wl_iw_parse_data_tlv(char** list_str, void *dst, int dst_size, const char token, | ||
| 2190 | int input_size, int *bytes_left) | ||
| 2191 | { | ||
| 2192 | char* str = *list_str; | ||
| 2193 | uint16 short_temp; | ||
| 2194 | uint32 int_temp; | ||
| 2195 | |||
| 2196 | if ((list_str == NULL) || (*list_str == NULL) ||(bytes_left == NULL) || (*bytes_left < 0)) { | ||
| 2197 | DHD_ERROR(("%s error paramters\n", __FUNCTION__)); | ||
| 2198 | return -1; | ||
| 2199 | } | ||
| 2200 | |||
| 2201 | /* Clean all dest bytes */ | ||
| 2202 | memset(dst, 0, dst_size); | ||
| 2203 | while (*bytes_left > 0) { | ||
| 2204 | |||
| 2205 | if (str[0] != token) { | ||
| 2206 | DHD_TRACE(("%s NOT Type=%d get=%d left_parse=%d \n", | ||
| 2207 | __FUNCTION__, token, str[0], *bytes_left)); | ||
| 2208 | return -1; | ||
| 2209 | } | ||
| 2210 | |||
| 2211 | *bytes_left -= 1; | ||
| 2212 | str += 1; | ||
| 2213 | |||
| 2214 | if (input_size == 1) { | ||
| 2215 | memcpy(dst, str, input_size); | ||
| 2216 | } | ||
| 2217 | else if (input_size == 2) { | ||
| 2218 | memcpy(dst, (char *)htod16(memcpy(&short_temp, str, input_size)), | ||
| 2219 | input_size); | ||
| 2220 | } | ||
| 2221 | else if (input_size == 4) { | ||
| 2222 | memcpy(dst, (char *)htod32(memcpy(&int_temp, str, input_size)), | ||
| 2223 | input_size); | ||
| 2224 | } | ||
| 2225 | |||
| 2226 | *bytes_left -= input_size; | ||
| 2227 | str += input_size; | ||
| 2228 | *list_str = str; | ||
| 2229 | return 1; | ||
| 2230 | } | ||
| 2231 | return 1; | ||
| 2232 | } | ||
| 2233 | |||
| 2234 | /* | ||
| 2235 | * channel list parsing from cscan tlv list | ||
| 2236 | */ | ||
| 2237 | int | ||
| 2238 | wl_iw_parse_channel_list_tlv(char** list_str, uint16* channel_list, | ||
| 2239 | int channel_num, int *bytes_left) | ||
| 2240 | { | ||
| 2241 | char* str = *list_str; | ||
| 2242 | int idx = 0; | ||
| 2243 | |||
| 2244 | if ((list_str == NULL) || (*list_str == NULL) ||(bytes_left == NULL) || (*bytes_left < 0)) { | ||
| 2245 | DHD_ERROR(("%s error paramters\n", __FUNCTION__)); | ||
| 2246 | return -1; | ||
| 2247 | } | ||
| 2248 | |||
| 2249 | while (*bytes_left > 0) { | ||
| 2250 | |||
| 2251 | if (str[0] != CSCAN_TLV_TYPE_CHANNEL_IE) { | ||
| 2252 | *list_str = str; | ||
| 2253 | DHD_TRACE(("End channel=%d left_parse=%d %d\n", idx, *bytes_left, str[0])); | ||
| 2254 | return idx; | ||
| 2255 | } | ||
| 2256 | /* Get proper CSCAN_TLV_TYPE_CHANNEL_IE */ | ||
| 2257 | *bytes_left -= 1; | ||
| 2258 | str += 1; | ||
| 2259 | |||
| 2260 | if (str[0] == 0) { | ||
| 2261 | /* All channels */ | ||
| 2262 | channel_list[idx] = 0x0; | ||
| 2263 | } | ||
| 2264 | else { | ||
| 2265 | channel_list[idx] = (uint16)str[0]; | ||
| 2266 | DHD_TRACE(("%s channel=%d \n", __FUNCTION__, channel_list[idx])); | ||
| 2267 | } | ||
| 2268 | *bytes_left -= 1; | ||
| 2269 | str += 1; | ||
| 2270 | |||
| 2271 | if (idx++ > 255) { | ||
| 2272 | DHD_ERROR(("%s Too many channels \n", __FUNCTION__)); | ||
| 2273 | return -1; | ||
| 2274 | } | ||
| 2275 | } | ||
| 2276 | |||
| 2277 | *list_str = str; | ||
| 2278 | return idx; | ||
| 2279 | } | ||
| 2280 | |||
| 2281 | /* | ||
| 2282 | * SSIDs list parsing from cscan tlv list | ||
| 2283 | */ | ||
| 2284 | int | ||
| 2285 | wl_iw_parse_ssid_list_tlv(char** list_str, wlc_ssid_t* ssid, int max, int *bytes_left) | ||
| 2286 | { | ||
| 2287 | char* str = *list_str; | ||
| 2288 | int idx = 0; | ||
| 2289 | |||
| 2290 | if ((list_str == NULL) || (*list_str == NULL) || (*bytes_left < 0)) { | ||
| 2291 | DHD_ERROR(("%s error paramters\n", __FUNCTION__)); | ||
| 2292 | return -1; | ||
| 2293 | } | ||
| 2294 | |||
| 2295 | while (*bytes_left > 0) { | ||
| 2296 | |||
| 2297 | if (str[0] != CSCAN_TLV_TYPE_SSID_IE) { | ||
| 2298 | *list_str = str; | ||
| 2299 | DHD_TRACE(("nssid=%d left_parse=%d %d\n", idx, *bytes_left, str[0])); | ||
| 2300 | return idx; | ||
| 2301 | } | ||
| 2302 | |||
| 2303 | /* Get proper CSCAN_TLV_TYPE_SSID_IE */ | ||
| 2304 | *bytes_left -= 1; | ||
| 2305 | str += 1; | ||
| 2306 | |||
| 2307 | if (str[0] == 0) { | ||
| 2308 | /* Broadcast SSID */ | ||
| 2309 | ssid[idx].SSID_len = 0; | ||
| 2310 | memset((char*)ssid[idx].SSID, 0x0, DOT11_MAX_SSID_LEN); | ||
| 2311 | *bytes_left -= 1; | ||
| 2312 | str += 1; | ||
| 2313 | |||
| 2314 | DHD_TRACE(("BROADCAST SCAN left=%d\n", *bytes_left)); | ||
| 2315 | } | ||
| 2316 | else if (str[0] <= DOT11_MAX_SSID_LEN) { | ||
| 2317 | /* Get proper SSID size */ | ||
| 2318 | ssid[idx].SSID_len = str[0]; | ||
| 2319 | *bytes_left -= 1; | ||
| 2320 | str += 1; | ||
| 2321 | |||
| 2322 | /* Get SSID */ | ||
| 2323 | if (ssid[idx].SSID_len > *bytes_left) { | ||
| 2324 | DHD_ERROR(("%s out of memory range len=%d but left=%d\n", | ||
| 2325 | __FUNCTION__, ssid[idx].SSID_len, *bytes_left)); | ||
| 2326 | return -1; | ||
| 2327 | } | ||
| 2328 | |||
| 2329 | memcpy((char*)ssid[idx].SSID, str, ssid[idx].SSID_len); | ||
| 2330 | |||
| 2331 | *bytes_left -= ssid[idx].SSID_len; | ||
| 2332 | str += ssid[idx].SSID_len; | ||
| 2333 | |||
| 2334 | DHD_TRACE(("%s :size=%d left=%d\n", | ||
| 2335 | (char*)ssid[idx].SSID, ssid[idx].SSID_len, *bytes_left)); | ||
| 2336 | } | ||
| 2337 | else { | ||
| 2338 | DHD_ERROR(("### SSID size more that %d\n", str[0])); | ||
| 2339 | return -1; | ||
| 2340 | } | ||
| 2341 | |||
| 2342 | if (idx++ > max) { | ||
| 2343 | DHD_ERROR(("%s number of SSIDs more that %d\n", __FUNCTION__, idx)); | ||
| 2344 | return -1; | ||
| 2345 | } | ||
| 2346 | } | ||
| 2347 | |||
| 2348 | *list_str = str; | ||
| 2349 | return idx; | ||
| 2350 | } | ||
| 2351 | |||
| 2352 | /* Parse a comma-separated list from list_str into ssid array, starting | ||
| 2353 | * at index idx. Max specifies size of the ssid array. Parses ssids | ||
| 2354 | * and returns updated idx; if idx >= max not all fit, the excess have | ||
| 2355 | * not been copied. Returns -1 on empty string, or on ssid too long. | ||
| 2356 | */ | ||
| 2357 | int | ||
| 2358 | wl_iw_parse_ssid_list(char** list_str, wlc_ssid_t* ssid, int idx, int max) | ||
| 2359 | { | ||
| 2360 | char* str, *ptr; | ||
| 2361 | |||
| 2362 | if ((list_str == NULL) || (*list_str == NULL)) | ||
| 2363 | return -1; | ||
| 2364 | |||
| 2365 | for (str = *list_str; str != NULL; str = ptr) { | ||
| 2366 | |||
| 2367 | /* check for next TAG */ | ||
| 2368 | if (!strncmp(str, GET_CHANNEL, strlen(GET_CHANNEL))) { | ||
| 2369 | *list_str = str + strlen(GET_CHANNEL); | ||
| 2370 | return idx; | ||
| 2371 | } | ||
| 2372 | |||
| 2373 | if ((ptr = strchr(str, ',')) != NULL) { | ||
| 2374 | *ptr++ = '\0'; | ||
| 2375 | } | ||
| 2376 | |||
| 2377 | if (strlen(str) > DOT11_MAX_SSID_LEN) { | ||
| 2378 | DHD_ERROR(("ssid <%s> exceeds %d\n", str, DOT11_MAX_SSID_LEN)); | ||
| 2379 | return -1; | ||
| 2380 | } | ||
| 2381 | |||
| 2382 | if (strlen(str) == 0) | ||
| 2383 | ssid[idx].SSID_len = 0; | ||
| 2384 | |||
| 2385 | if (idx < max) { | ||
| 2386 | strcpy((char*)ssid[idx].SSID, str); | ||
| 2387 | ssid[idx].SSID_len = strlen(str); | ||
| 2388 | } | ||
| 2389 | idx++; | ||
| 2390 | } | ||
| 2391 | return idx; | ||
| 2392 | } | ||
| 2393 | |||
| 2394 | /* | ||
| 2395 | * Parse channel list from iwpriv CSCAN | ||
| 2396 | */ | ||
| 2397 | int | ||
| 2398 | wl_iw_parse_channel_list(char** list_str, uint16* channel_list, int channel_num) | ||
| 2399 | { | ||
| 2400 | int num; | ||
| 2401 | int val; | ||
| 2402 | char* str; | ||
| 2403 | char* endptr = NULL; | ||
| 2404 | |||
| 2405 | if ((list_str == NULL)||(*list_str == NULL)) | ||
| 2406 | return -1; | ||
| 2407 | |||
| 2408 | str = *list_str; | ||
| 2409 | num = 0; | ||
| 2410 | while (strncmp(str, GET_NPROBE, strlen(GET_NPROBE))) { | ||
| 2411 | val = (int)strtoul(str, &endptr, 0); | ||
| 2412 | if (endptr == str) { | ||
| 2413 | printf("could not parse channel number starting at" | ||
| 2414 | " substring \"%s\" in list:\n%s\n", | ||
| 2415 | str, *list_str); | ||
| 2416 | return -1; | ||
| 2417 | } | ||
| 2418 | str = endptr + strspn(endptr, " ,"); | ||
| 2419 | |||
| 2420 | if (num == channel_num) { | ||
| 2421 | DHD_ERROR(("too many channels (more than %d) in channel list:\n%s\n", | ||
| 2422 | channel_num, *list_str)); | ||
| 2423 | return -1; | ||
| 2424 | } | ||
| 2425 | |||
| 2426 | channel_list[num++] = (uint16)val; | ||
| 2427 | } | ||
| 2428 | *list_str = str; | ||
| 2429 | return num; | ||
| 2430 | } | ||
| 2431 | |||
| 2432 | #endif | ||
