2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/sched.h>
19 #include <linux/netdevice.h>
20 #include <asm/unaligned.h>
22 #include <brcmu_wifi.h>
23 #include <brcmu_utils.h>
24 #include "dngl_stats.h"
27 #include "dhd_proto.h"
30 #define BRCM_OUI "\x00\x10\x18"
31 #define DOT11_OUI_LEN 3
32 #define BCMILCP_BCM_SUBTYPE_EVENT 1
35 char fw_path[MOD_PARAM_PATHLEN];
36 char nv_path[MOD_PARAM_PATHLEN];
38 /* Last connection success/failure status */
43 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
45 extern void dhd_ind_scan_confirm(void *h, bool status);
46 extern int dhd_wl_ioctl(dhd_pub_t *dhd, uint cmd, char *buf, uint buflen);
47 void dhd_iscan_lock(void);
48 void dhd_iscan_unlock(void);
50 /* Packet alignment for most efficient SDIO (can change based on platform) */
52 #define DHD_SDALIGN 32
54 #if !ISPOWEROF2(DHD_SDALIGN)
55 #error DHD_SDALIGN is not a power of 2!
58 #define EPI_VERSION_STR "4.218.248.5"
59 #define MSGTRACE_VERSION 1
62 const char dhd_version[] =
63 "Dongle Host Driver, version " EPI_VERSION_STR "\nCompiled on " __DATE__
66 const char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR;
69 void dhd_set_timer(void *bus, uint wdtick);
92 const struct brcmu_iovar dhd_iovars[] = {
93 {"version", IOV_VERSION, 0, IOVT_BUFFER, sizeof(dhd_version)}
96 {"msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0}
98 #endif /* DHD_DEBUG */
99 {"bcmerrorstr", IOV_BCMERRORSTR, 0, IOVT_BUFFER, BCME_STRLEN}
101 {"bcmerror", IOV_BCMERROR, 0, IOVT_INT8, 0}
103 {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0}
105 {"dump", IOV_DUMP, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN}
108 {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0}
110 {"cons", IOV_CONS, 0, IOVT_BUFFER, 0}
113 {"clearcounts", IOV_CLEARCOUNTS, 0, IOVT_VOID, 0}
115 {"gpioob", IOV_GPIOOB, 0, IOVT_UINT32, 0}
117 {"ioctl_timeout", IOV_IOCTLTIMEOUT, 0, IOVT_UINT32, 0}
122 /* Message trace header */
123 struct msgtrace_hdr {
126 u16 len; /* Len of the trace */
127 u32 seqnum; /* Sequence number of message. Useful
128 * if the messsage has been lost
129 * because of DMA error or a bus reset
132 u32 discarded_bytes; /* Number of discarded bytes because of
134 u32 discarded_printf; /* Number of discarded printf
135 because of trace overflow */
138 void dhd_common_init(void)
140 /* Init global variables at run-time, not as part of the declaration.
141 * This is required to support init/de-init of the driver.
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
148 dhd_msg_level = DHD_ERROR_VAL;
149 #ifdef CONFIG_BCM4329_FW_PATH
150 strncpy(fw_path, CONFIG_BCM4329_FW_PATH, MOD_PARAM_PATHLEN - 1);
154 #ifdef CONFIG_BCM4329_NVRAM_PATH
155 strncpy(nv_path, CONFIG_BCM4329_NVRAM_PATH, MOD_PARAM_PATHLEN - 1);
161 static int dhd_dump(dhd_pub_t *dhdp, char *buf, int buflen)
163 struct brcmu_strbuf b;
164 struct brcmu_strbuf *strbuf = &b;
166 brcmu_binit(strbuf, buf, buflen);
169 brcmu_bprintf(strbuf, "%s\n", dhd_version);
170 brcmu_bprintf(strbuf, "\n");
171 brcmu_bprintf(strbuf, "pub.up %d pub.txoff %d pub.busstate %d\n",
172 dhdp->up, dhdp->txoff, dhdp->busstate);
173 brcmu_bprintf(strbuf, "pub.hdrlen %d pub.maxctl %d pub.rxsz %d\n",
174 dhdp->hdrlen, dhdp->maxctl, dhdp->rxsz);
175 brcmu_bprintf(strbuf, "pub.iswl %d pub.drv_version %ld pub.mac %pM\n",
176 dhdp->iswl, dhdp->drv_version, &dhdp->mac);
177 brcmu_bprintf(strbuf, "pub.bcmerror %d tickcnt %d\n", dhdp->bcmerror,
180 brcmu_bprintf(strbuf, "dongle stats:\n");
181 brcmu_bprintf(strbuf,
182 "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 brcmu_bprintf(strbuf,
186 "rx_packets %ld rx_bytes %ld rx_errors %ld rx_dropped %ld\n",
187 dhdp->dstats.rx_packets, dhdp->dstats.rx_bytes,
188 dhdp->dstats.rx_errors, dhdp->dstats.rx_dropped);
189 brcmu_bprintf(strbuf, "multicast %ld\n", dhdp->dstats.multicast);
191 brcmu_bprintf(strbuf, "bus stats:\n");
192 brcmu_bprintf(strbuf, "tx_packets %ld tx_multicast %ld tx_errors %ld\n",
193 dhdp->tx_packets, dhdp->tx_multicast, dhdp->tx_errors);
194 brcmu_bprintf(strbuf, "tx_ctlpkts %ld tx_ctlerrs %ld\n",
195 dhdp->tx_ctlpkts, dhdp->tx_ctlerrs);
196 brcmu_bprintf(strbuf, "rx_packets %ld rx_multicast %ld rx_errors %ld\n",
197 dhdp->rx_packets, dhdp->rx_multicast, dhdp->rx_errors);
198 brcmu_bprintf(strbuf,
199 "rx_ctlpkts %ld rx_ctlerrs %ld rx_dropped %ld rx_flushed %ld\n",
200 dhdp->rx_ctlpkts, dhdp->rx_ctlerrs, dhdp->rx_dropped,
202 brcmu_bprintf(strbuf,
203 "rx_readahead_cnt %ld tx_realloc %ld fc_packets %ld\n",
204 dhdp->rx_readahead_cnt, dhdp->tx_realloc, dhdp->fc_packets);
205 brcmu_bprintf(strbuf, "wd_dpc_sched %ld\n", dhdp->wd_dpc_sched);
206 brcmu_bprintf(strbuf, "\n");
208 /* Add any prot info */
209 dhd_prot_dump(dhdp, strbuf);
210 brcmu_bprintf(strbuf, "\n");
212 /* Add any bus info */
213 brcmf_sdbrcm_bus_dump(dhdp, strbuf);
215 return !strbuf->size ? -EOVERFLOW : 0;
219 dhd_doiovar(dhd_pub_t *dhd_pub, const struct brcmu_iovar *vi, u32 actionid,
220 const char *name, void *params, int plen, void *arg, int len,
226 DHD_TRACE(("%s: Enter\n", __func__));
228 bcmerror = brcmu_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid));
232 if (plen >= (int)sizeof(int_val))
233 memcpy(&int_val, params, sizeof(int_val));
236 case IOV_GVAL(IOV_VERSION):
237 /* Need to have checked buffer length */
238 strncpy((char *)arg, dhd_version, len);
241 case IOV_GVAL(IOV_MSGLEVEL):
242 int_val = (s32) dhd_msg_level;
243 memcpy(arg, &int_val, val_size);
246 case IOV_SVAL(IOV_MSGLEVEL):
247 dhd_msg_level = int_val;
250 case IOV_GVAL(IOV_BCMERRORSTR):
251 strncpy((char *)arg, "bcm_error",
253 ((char *)arg)[BCME_STRLEN - 1] = 0x00;
256 case IOV_GVAL(IOV_BCMERROR):
257 int_val = (s32) dhd_pub->bcmerror;
258 memcpy(arg, &int_val, val_size);
261 case IOV_GVAL(IOV_WDTICK):
262 int_val = (s32) dhd_watchdog_ms;
263 memcpy(arg, &int_val, val_size);
266 case IOV_SVAL(IOV_WDTICK):
271 dhd_os_wd_timer(dhd_pub, (uint) int_val);
274 case IOV_GVAL(IOV_DUMP):
275 bcmerror = dhd_dump(dhd_pub, arg, len);
279 case IOV_GVAL(IOV_DCONSOLE_POLL):
280 int_val = (s32) dhd_console_ms;
281 memcpy(arg, &int_val, val_size);
284 case IOV_SVAL(IOV_DCONSOLE_POLL):
285 dhd_console_ms = (uint) int_val;
288 case IOV_SVAL(IOV_CONS):
290 bcmerror = brcmf_sdbrcm_bus_console_in(dhd_pub, arg,
295 case IOV_SVAL(IOV_CLEARCOUNTS):
296 dhd_pub->tx_packets = dhd_pub->rx_packets = 0;
297 dhd_pub->tx_errors = dhd_pub->rx_errors = 0;
298 dhd_pub->tx_ctlpkts = dhd_pub->rx_ctlpkts = 0;
299 dhd_pub->tx_ctlerrs = dhd_pub->rx_ctlerrs = 0;
300 dhd_pub->rx_dropped = 0;
301 dhd_pub->rx_readahead_cnt = 0;
302 dhd_pub->tx_realloc = 0;
303 dhd_pub->wd_dpc_sched = 0;
304 memset(&dhd_pub->dstats, 0, sizeof(dhd_pub->dstats));
305 dhd_bus_clearcounts(dhd_pub);
308 case IOV_GVAL(IOV_IOCTLTIMEOUT):{
309 int_val = (s32) dhd_os_get_ioctl_resp_timeout();
310 memcpy(arg, &int_val, sizeof(int_val));
314 case IOV_SVAL(IOV_IOCTLTIMEOUT):{
318 dhd_os_set_ioctl_resp_timeout((unsigned int)
324 bcmerror = -ENOTSUPP;
332 bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, struct sk_buff *pkt,
336 int eprec = -1; /* precedence to evict from */
339 /* Fast case, precedence queue is not full and we are also not
340 * exceeding total queue length
342 if (!pktq_pfull(q, prec) && !pktq_full(q)) {
343 brcmu_pktq_penq(q, prec, pkt);
347 /* Determine precedence from which to evict packet, if any */
348 if (pktq_pfull(q, prec))
350 else if (pktq_full(q)) {
351 p = brcmu_pktq_peek_tail(q, &eprec);
357 /* Evict if needed */
359 /* Detect queueing to unconfigured precedence */
360 ASSERT(!pktq_pempty(q, eprec));
361 discard_oldest = AC_BITMAP_TST(dhdp->wme_dp, eprec);
362 if (eprec == prec && !discard_oldest)
363 return false; /* refuse newer (incoming) packet */
364 /* Evict packet according to discard policy */
365 p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) :
366 brcmu_pktq_pdeq_tail(q, eprec);
368 DHD_ERROR(("%s: brcmu_pktq_penq() failed, oldest %d.",
369 __func__, discard_oldest));
373 brcmu_pkt_buf_free_skb(p);
377 p = brcmu_pktq_penq(q, prec, pkt);
379 DHD_ERROR(("%s: brcmu_pktq_penq() failed.", __func__));
387 dhd_iovar_op(dhd_pub_t *dhd_pub, const char *name,
388 void *params, int plen, void *arg, int len, bool set)
392 const struct brcmu_iovar *vi = NULL;
395 DHD_TRACE(("%s: Enter\n", __func__));
400 /* Get MUST have return space */
401 ASSERT(set || (arg && len));
403 /* Set does NOT take qualifiers */
404 ASSERT(!set || (!params && !plen));
406 vi = brcmu_iovar_lookup(dhd_iovars, name);
408 bcmerror = -ENOTSUPP;
412 DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__,
413 name, (set ? "set" : "get"), len, plen));
415 /* set up 'params' pointer in case this is a set command so that
416 * the convenience int and bool code can be common to set and get
418 if (params == NULL) {
423 if (vi->type == IOVT_VOID)
425 else if (vi->type == IOVT_BUFFER)
428 /* all other types are integer sized */
429 val_size = sizeof(int);
431 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
433 dhd_doiovar(dhd_pub, vi, actionid, name, params, plen, arg, len,
440 int dhd_ioctl(dhd_pub_t *dhd_pub, dhd_ioctl_t *ioc, void *buf, uint buflen)
444 DHD_TRACE(("%s: Enter\n", __func__));
451 if (buflen < sizeof(int))
452 bcmerror = -EOVERFLOW;
454 *(int *)buf = DHD_IOCTL_MAGIC;
457 case DHD_GET_VERSION:
458 if (buflen < sizeof(int))
459 bcmerror = -EOVERFLOW;
461 *(int *)buf = DHD_IOCTL_VERSION;
469 /* scan past the name to any arguments */
470 for (arg = buf, arglen = buflen; *arg && arglen;
475 bcmerror = -EOVERFLOW;
479 /* account for the NUL terminator */
482 /* call with the appropriate arguments */
483 if (ioc->cmd == DHD_GET_VAR)
485 dhd_iovar_op(dhd_pub, buf, arg, arglen, buf,
489 dhd_iovar_op(dhd_pub, buf, NULL, 0, arg,
491 if (bcmerror != -ENOTSUPP)
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,
500 bcmerror = dhd_prot_iovar_op(dhd_pub, buf,
503 if (bcmerror != -ENOTSUPP)
506 /* if still not found, try bus module */
507 if (ioc->cmd == DHD_GET_VAR)
508 bcmerror = brcmf_sdbrcm_bus_iovar_op(dhd_pub,
509 buf, arg, arglen, buf, buflen,
512 bcmerror = brcmf_sdbrcm_bus_iovar_op(dhd_pub,
513 buf, NULL, 0, arg, arglen,
520 bcmerror = -ENOTSUPP;
527 static void wl_show_host_event(wl_event_msg_t *event, void *event_data)
529 uint i, status, reason;
530 bool group = false, flush_txq = false, link = false;
531 char *auth_str, *event_name;
533 char err_msg[256], eabuf[ETHER_ADDR_STR_LEN];
539 WLC_E_SET_SSID, "SET_SSID"}, {
540 WLC_E_JOIN, "JOIN"}, {
541 WLC_E_START, "START"}, {
542 WLC_E_AUTH, "AUTH"}, {
543 WLC_E_AUTH_IND, "AUTH_IND"}, {
544 WLC_E_DEAUTH, "DEAUTH"}, {
545 WLC_E_DEAUTH_IND, "DEAUTH_IND"}, {
546 WLC_E_ASSOC, "ASSOC"}, {
547 WLC_E_ASSOC_IND, "ASSOC_IND"}, {
548 WLC_E_REASSOC, "REASSOC"}, {
549 WLC_E_REASSOC_IND, "REASSOC_IND"}, {
550 WLC_E_DISASSOC, "DISASSOC"}, {
551 WLC_E_DISASSOC_IND, "DISASSOC_IND"}, {
552 WLC_E_QUIET_START, "START_QUIET"}, {
553 WLC_E_QUIET_END, "END_QUIET"}, {
554 WLC_E_BEACON_RX, "BEACON_RX"}, {
555 WLC_E_LINK, "LINK"}, {
556 WLC_E_MIC_ERROR, "MIC_ERROR"}, {
557 WLC_E_NDIS_LINK, "NDIS_LINK"}, {
558 WLC_E_ROAM, "ROAM"}, {
559 WLC_E_TXFAIL, "TXFAIL"}, {
560 WLC_E_PMKID_CACHE, "PMKID_CACHE"}, {
561 WLC_E_RETROGRADE_TSF, "RETROGRADE_TSF"}, {
562 WLC_E_PRUNE, "PRUNE"}, {
563 WLC_E_AUTOAUTH, "AUTOAUTH"}, {
564 WLC_E_EAPOL_MSG, "EAPOL_MSG"}, {
565 WLC_E_SCAN_COMPLETE, "SCAN_COMPLETE"}, {
566 WLC_E_ADDTS_IND, "ADDTS_IND"}, {
567 WLC_E_DELTS_IND, "DELTS_IND"}, {
568 WLC_E_BCNSENT_IND, "BCNSENT_IND"}, {
569 WLC_E_BCNRX_MSG, "BCNRX_MSG"}, {
570 WLC_E_BCNLOST_MSG, "BCNLOST_MSG"}, {
571 WLC_E_ROAM_PREP, "ROAM_PREP"}, {
572 WLC_E_PFN_NET_FOUND, "PNO_NET_FOUND"}, {
573 WLC_E_PFN_NET_LOST, "PNO_NET_LOST"}, {
574 WLC_E_RESET_COMPLETE, "RESET_COMPLETE"}, {
575 WLC_E_JOIN_START, "JOIN_START"}, {
576 WLC_E_ROAM_START, "ROAM_START"}, {
577 WLC_E_ASSOC_START, "ASSOC_START"}, {
578 WLC_E_IBSS_ASSOC, "IBSS_ASSOC"}, {
579 WLC_E_RADIO, "RADIO"}, {
580 WLC_E_PSM_WATCHDOG, "PSM_WATCHDOG"}, {
581 WLC_E_PROBREQ_MSG, "PROBREQ_MSG"}, {
582 WLC_E_SCAN_CONFIRM_IND, "SCAN_CONFIRM_IND"}, {
583 WLC_E_PSK_SUP, "PSK_SUP"}, {
584 WLC_E_COUNTRY_CODE_CHANGED, "COUNTRY_CODE_CHANGED"}, {
585 WLC_E_EXCEEDED_MEDIUM_TIME, "EXCEEDED_MEDIUM_TIME"}, {
586 WLC_E_ICV_ERROR, "ICV_ERROR"}, {
587 WLC_E_UNICAST_DECODE_ERROR, "UNICAST_DECODE_ERROR"}, {
588 WLC_E_MULTICAST_DECODE_ERROR, "MULTICAST_DECODE_ERROR"}, {
589 WLC_E_TRACE, "TRACE"}, {
590 WLC_E_ACTION_FRAME, "ACTION FRAME"}, {
591 WLC_E_ACTION_FRAME_COMPLETE, "ACTION FRAME TX COMPLETE"}, {
593 WLC_E_RSSI, "RSSI"}, {
594 WLC_E_PFN_SCAN_COMPLETE, "SCAN_COMPLETE"}
596 uint event_type, flags, auth_type, datalen;
597 event_type = be32_to_cpu(event->event_type);
598 flags = be16_to_cpu(event->flags);
599 status = be32_to_cpu(event->status);
600 reason = be32_to_cpu(event->reason);
601 auth_type = be32_to_cpu(event->auth_type);
602 datalen = be32_to_cpu(event->datalen);
603 /* debug dump of event messages */
604 sprintf(eabuf, "%pM", event->addr);
606 event_name = "UNKNOWN";
607 for (i = 0; i < ARRAY_SIZE(event_names); i++) {
608 if (event_names[i].event == event_type)
609 event_name = event_names[i].event_name;
612 DHD_EVENT(("EVENT: %s, event ID = %d\n", event_name, event_type));
613 DHD_EVENT(("flags 0x%04x, status %d, reason %d, auth_type %d MAC %s\n",
614 flags, status, reason, auth_type, eabuf));
616 if (flags & WLC_EVENT_MSG_LINK)
618 if (flags & WLC_EVENT_MSG_GROUP)
620 if (flags & WLC_EVENT_MSG_FLUSHTXQ)
623 switch (event_type) {
627 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
630 case WLC_E_ASSOC_IND:
631 case WLC_E_REASSOC_IND:
632 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
637 if (status == WLC_E_STATUS_SUCCESS) {
638 DHD_EVENT(("MACEVENT: %s, MAC %s, SUCCESS\n",
640 } else if (status == WLC_E_STATUS_TIMEOUT) {
641 DHD_EVENT(("MACEVENT: %s, MAC %s, TIMEOUT\n",
643 } else if (status == WLC_E_STATUS_FAIL) {
644 DHD_EVENT(("MACEVENT: %s, MAC %s, FAILURE, reason %d\n",
645 event_name, eabuf, (int)reason));
647 DHD_EVENT(("MACEVENT: %s, MAC %s, unexpected status "
648 "%d\n", event_name, eabuf, (int)status));
652 case WLC_E_DEAUTH_IND:
653 case WLC_E_DISASSOC_IND:
654 DHD_EVENT(("MACEVENT: %s, MAC %s, reason %d\n", event_name,
655 eabuf, (int)reason));
660 if (auth_type == WLAN_AUTH_OPEN)
661 auth_str = "Open System";
662 else if (auth_type == WLAN_AUTH_SHARED_KEY)
663 auth_str = "Shared Key";
665 sprintf(err_msg, "AUTH unknown: %d", (int)auth_type);
668 if (event_type == WLC_E_AUTH_IND) {
669 DHD_EVENT(("MACEVENT: %s, MAC %s, %s\n", event_name,
671 } else if (status == WLC_E_STATUS_SUCCESS) {
672 DHD_EVENT(("MACEVENT: %s, MAC %s, %s, SUCCESS\n",
673 event_name, eabuf, auth_str));
674 } else if (status == WLC_E_STATUS_TIMEOUT) {
675 DHD_EVENT(("MACEVENT: %s, MAC %s, %s, TIMEOUT\n",
676 event_name, eabuf, auth_str));
677 } else if (status == WLC_E_STATUS_FAIL) {
678 DHD_EVENT(("MACEVENT: %s, MAC %s, %s, FAILURE, "
680 event_name, eabuf, auth_str, (int)reason));
688 if (status == WLC_E_STATUS_SUCCESS) {
689 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name,
691 } else if (status == WLC_E_STATUS_FAIL) {
692 DHD_EVENT(("MACEVENT: %s, failed\n", event_name));
693 } else if (status == WLC_E_STATUS_NO_NETWORKS) {
694 DHD_EVENT(("MACEVENT: %s, no networks found\n",
697 DHD_EVENT(("MACEVENT: %s, unexpected status %d\n",
698 event_name, (int)status));
702 case WLC_E_BEACON_RX:
703 if (status == WLC_E_STATUS_SUCCESS) {
704 DHD_EVENT(("MACEVENT: %s, SUCCESS\n", event_name));
705 } else if (status == WLC_E_STATUS_FAIL) {
706 DHD_EVENT(("MACEVENT: %s, FAIL\n", event_name));
708 DHD_EVENT(("MACEVENT: %s, status %d\n", event_name,
714 DHD_EVENT(("MACEVENT: %s %s\n", event_name,
715 link ? "UP" : "DOWN"));
718 case WLC_E_MIC_ERROR:
719 DHD_EVENT(("MACEVENT: %s, MAC %s, Group %d, Flush %d\n",
720 event_name, eabuf, group, flush_txq));
723 case WLC_E_ICV_ERROR:
724 case WLC_E_UNICAST_DECODE_ERROR:
725 case WLC_E_MULTICAST_DECODE_ERROR:
726 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
730 DHD_EVENT(("MACEVENT: %s, RA %s\n", event_name, eabuf));
733 case WLC_E_SCAN_COMPLETE:
734 case WLC_E_PMKID_CACHE:
735 DHD_EVENT(("MACEVENT: %s\n", event_name));
738 case WLC_E_PFN_NET_FOUND:
739 case WLC_E_PFN_NET_LOST:
740 case WLC_E_PFN_SCAN_COMPLETE:
741 DHD_EVENT(("PNOEVENT: %s\n", event_name));
746 DHD_EVENT(("MACEVENT: %s, status %d, reason %d\n",
747 event_name, (int)status, (int)reason));
752 static u32 seqnum_prev;
753 struct msgtrace_hdr hdr;
757 buf = (unsigned char *) event_data;
758 memcpy(&hdr, buf, sizeof(struct msgtrace_hdr));
760 if (hdr.version != MSGTRACE_VERSION) {
762 ("\nMACEVENT: %s [unsupported version --> "
763 "dhd version:%d dongle version:%d]\n",
764 event_name, MSGTRACE_VERSION, hdr.version)
766 /* Reset datalen to avoid display below */
771 /* There are 2 bytes available at the end of data */
772 *(buf + sizeof(struct msgtrace_hdr)
773 + be16_to_cpu(hdr.len)) = '\0';
775 if (be32_to_cpu(hdr.discarded_bytes)
776 || be32_to_cpu(hdr.discarded_printf)) {
778 ("\nWLC_E_TRACE: [Discarded traces in dongle -->"
779 "discarded_bytes %d discarded_printf %d]\n",
780 be32_to_cpu(hdr.discarded_bytes),
781 be32_to_cpu(hdr.discarded_printf)));
784 nblost = be32_to_cpu(hdr.seqnum) - seqnum_prev - 1;
787 ("\nWLC_E_TRACE: [Event lost --> seqnum %d nblost %d\n",
788 be32_to_cpu(hdr.seqnum), nblost));
790 seqnum_prev = be32_to_cpu(hdr.seqnum);
792 /* Display the trace buffer. Advance from \n to \n to
794 * printf (issue with Linux printk )
796 p = (char *)&buf[sizeof(struct msgtrace_hdr)];
797 while ((s = strstr(p, "\n")) != NULL) {
799 printk(KERN_DEBUG"%s\n", p);
802 printk(KERN_DEBUG "%s\n", p);
804 /* Reset datalen to avoid display below */
810 DHD_EVENT(("MACEVENT: %s %d\n", event_name,
811 be32_to_cpu(*((int *)event_data))));
815 DHD_EVENT(("MACEVENT: %s %d, MAC %s, status %d, reason %d, "
816 "auth %d\n", event_name, event_type, eabuf,
817 (int)status, (int)reason, (int)auth_type));
821 /* show any appended data */
823 buf = (unsigned char *) event_data;
824 DHD_EVENT((" data (%d) : ", datalen));
825 for (i = 0; i < datalen; i++)
826 DHD_EVENT((" 0x%02x ", *buf++));
830 #endif /* SHOW_EVENTS */
833 wl_host_event(struct dhd_info *dhd, int *ifidx, void *pktdata,
834 wl_event_msg_t *event, void **data_ptr)
836 /* check whether packet is a BRCM event pkt */
837 bcm_event_t *pvt_data = (bcm_event_t *) pktdata;
843 if (memcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
844 DHD_ERROR(("%s: mismatched OUI, bailing\n", __func__));
848 /* BRCM event pkt may be unaligned - use xxx_ua to load user_subtype. */
849 if (get_unaligned_be16(&pvt_data->bcm_hdr.usr_subtype) !=
850 BCMILCP_BCM_SUBTYPE_EVENT) {
851 DHD_ERROR(("%s: mismatched subtype, bailing\n", __func__));
855 *data_ptr = &pvt_data[1];
856 event_data = *data_ptr;
858 /* memcpy since BRCM event pkt may be unaligned. */
859 memcpy(event, &pvt_data->event, sizeof(wl_event_msg_t));
861 type = get_unaligned_be32(&event->event_type);
862 flags = get_unaligned_be16(&event->flags);
863 status = get_unaligned_be32(&event->status);
864 evlen = get_unaligned_be32(&event->datalen) + sizeof(bcm_event_t);
869 dhd_if_event_t *ifevent = (dhd_if_event_t *) event_data;
870 DHD_TRACE(("%s: if event\n", __func__));
872 if (ifevent->ifidx > 0 &&
873 ifevent->ifidx < DHD_MAX_IFS) {
874 if (ifevent->action == WLC_E_IF_ADD)
875 dhd_add_if(dhd, ifevent->ifidx,
877 pvt_data->eth.h_dest,
881 dhd_del_if(dhd, ifevent->ifidx);
883 DHD_ERROR(("%s: Invalid ifidx %d for %s\n",
884 __func__, ifevent->ifidx,
888 /* send up the if event: btamp user needs it */
889 *ifidx = dhd_ifname2idx(dhd, event->ifname);
890 /* push up to external supp/auth */
891 dhd_event(dhd, (char *)pvt_data, evlen, *ifidx);
895 case WLC_E_NDIS_LINK:
899 /* These are what external supplicant/authenticator wants */
901 case WLC_E_ASSOC_IND:
902 case WLC_E_REASSOC_IND:
903 case WLC_E_DISASSOC_IND:
904 case WLC_E_MIC_ERROR:
906 /* Fall through: this should get _everything_ */
908 *ifidx = dhd_ifname2idx(dhd, event->ifname);
909 /* push up to external supp/auth */
910 dhd_event(dhd, (char *)pvt_data, evlen, *ifidx);
911 DHD_TRACE(("%s: MAC event %d, flags %x, status %x\n",
912 __func__, type, flags, status));
914 /* put it back to WLC_E_NDIS_LINK */
915 if (type == WLC_E_NDIS_LINK) {
918 temp = get_unaligned_be32(&event->event_type);
919 DHD_TRACE(("Converted to WLC_E_LINK type %d\n", temp));
921 temp = be32_to_cpu(WLC_E_NDIS_LINK);
922 memcpy((void *)(&pvt_data->event.event_type), &temp,
923 sizeof(pvt_data->event.event_type));
929 wl_show_host_event(event, event_data);
930 #endif /* SHOW_EVENTS */
935 /* Convert user's input in hex pattern to byte-size mask */
936 static int wl_pattern_atoh(char *src, char *dst)
939 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
940 DHD_ERROR(("Mask invalid format. Needs to start with 0x\n"));
943 src = src + 2; /* Skip past 0x */
944 if (strlen(src) % 2 != 0) {
945 DHD_ERROR(("Mask invalid format. Length must be even.\n"));
948 for (i = 0; *src != '\0'; i++) {
950 strncpy(num, src, 2);
952 dst[i] = (u8) simple_strtoul(num, NULL, 16);
959 dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
967 char *arg_save = 0, *arg_org = 0;
970 wl_pkt_filter_enable_t enable_parm;
971 wl_pkt_filter_enable_t *pkt_filterp;
973 arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
975 DHD_ERROR(("%s: kmalloc failed\n", __func__));
979 memcpy(arg_save, arg, strlen(arg) + 1);
981 argv[i] = strsep(&arg_save, " ");
984 if (NULL == argv[i]) {
985 DHD_ERROR(("No args provided\n"));
989 str = "pkt_filter_enable";
990 str_len = strlen(str);
991 strncpy(buf, str, str_len);
993 buf_len = str_len + 1;
995 pkt_filterp = (wl_pkt_filter_enable_t *) (buf + str_len + 1);
997 /* Parse packet filter id. */
998 enable_parm.id = simple_strtoul(argv[i], NULL, 0);
1000 /* Parse enable/disable value. */
1001 enable_parm.enable = enable;
1003 buf_len += sizeof(enable_parm);
1004 memcpy((char *)pkt_filterp, &enable_parm, sizeof(enable_parm));
1006 /* Enable/disable the specified filter. */
1007 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len);
1008 rc = rc >= 0 ? 0 : rc;
1010 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
1011 __func__, arg, rc));
1013 DHD_TRACE(("%s: successfully added pktfilter %s\n",
1016 /* Contorl the master mode */
1017 brcmu_mkiovar("pkt_filter_mode", (char *)&master_mode, 4, buf,
1019 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf));
1020 rc = rc >= 0 ? 0 : rc;
1022 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
1023 __func__, arg, rc));
1029 void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg)
1032 wl_pkt_filter_t pkt_filter;
1033 wl_pkt_filter_t *pkt_filterp;
1039 char *argv[8], *buf = 0;
1041 char *arg_save = 0, *arg_org = 0;
1042 #define BUF_SIZE 2048
1044 arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
1046 DHD_ERROR(("%s: kmalloc failed\n", __func__));
1052 buf = kmalloc(BUF_SIZE, GFP_ATOMIC);
1054 DHD_ERROR(("%s: kmalloc failed\n", __func__));
1058 memcpy(arg_save, arg, strlen(arg) + 1);
1060 if (strlen(arg) > BUF_SIZE) {
1061 DHD_ERROR(("Not enough buffer %d < %d\n", (int)strlen(arg),
1066 argv[i] = strsep(&arg_save, " ");
1068 argv[i] = strsep(&arg_save, " ");
1071 if (NULL == argv[i]) {
1072 DHD_ERROR(("No args provided\n"));
1076 str = "pkt_filter_add";
1077 str_len = strlen(str);
1078 strncpy(buf, str, str_len);
1079 buf[str_len] = '\0';
1080 buf_len = str_len + 1;
1082 pkt_filterp = (wl_pkt_filter_t *) (buf + str_len + 1);
1084 /* Parse packet filter id. */
1085 pkt_filter.id = simple_strtoul(argv[i], NULL, 0);
1087 if (NULL == argv[++i]) {
1088 DHD_ERROR(("Polarity not provided\n"));
1092 /* Parse filter polarity. */
1093 pkt_filter.negate_match = simple_strtoul(argv[i], NULL, 0);
1095 if (NULL == argv[++i]) {
1096 DHD_ERROR(("Filter type not provided\n"));
1100 /* Parse filter type. */
1101 pkt_filter.type = simple_strtoul(argv[i], NULL, 0);
1103 if (NULL == argv[++i]) {
1104 DHD_ERROR(("Offset not provided\n"));
1108 /* Parse pattern filter offset. */
1109 pkt_filter.u.pattern.offset = simple_strtoul(argv[i], NULL, 0);
1111 if (NULL == argv[++i]) {
1112 DHD_ERROR(("Bitmask not provided\n"));
1116 /* Parse pattern filter mask. */
1119 (argv[i], (char *)pkt_filterp->u.pattern.mask_and_pattern);
1121 if (NULL == argv[++i]) {
1122 DHD_ERROR(("Pattern not provided\n"));
1126 /* Parse pattern filter pattern. */
1128 wl_pattern_atoh(argv[i],
1129 (char *)&pkt_filterp->u.pattern.
1130 mask_and_pattern[mask_size]);
1132 if (mask_size != pattern_size) {
1133 DHD_ERROR(("Mask and pattern not the same size\n"));
1137 pkt_filter.u.pattern.size_bytes = mask_size;
1138 buf_len += WL_PKT_FILTER_FIXED_LEN;
1139 buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
1141 /* Keep-alive attributes are set in local
1142 * variable (keep_alive_pkt), and
1143 ** then memcpy'ed into buffer (keep_alive_pktp) since there is no
1144 ** guarantee that the buffer is properly aligned.
1146 memcpy((char *)pkt_filterp,
1148 WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
1150 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len);
1151 rc = rc >= 0 ? 0 : rc;
1154 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
1155 __func__, arg, rc));
1157 DHD_TRACE(("%s: successfully added pktfilter %s\n",
1166 void dhd_arp_offload_set(dhd_pub_t *dhd, int arp_mode)
1171 brcmu_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf));
1172 retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1174 retcode = retcode >= 0 ? 0 : retcode;
1176 DHD_TRACE(("%s: failed to set ARP offload mode to 0x%x, "
1177 "retcode = %d\n", __func__, arp_mode, retcode));
1179 DHD_TRACE(("%s: successfully set ARP offload mode to 0x%x\n",
1180 __func__, arp_mode));
1183 void dhd_arp_offload_enable(dhd_pub_t *dhd, int arp_enable)
1188 brcmu_mkiovar("arpoe", (char *)&arp_enable, 4, iovbuf, sizeof(iovbuf));
1189 retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1191 retcode = retcode >= 0 ? 0 : retcode;
1193 DHD_TRACE(("%s: failed to enabe ARP offload to %d, "
1194 "retcode = %d\n", __func__, arp_enable, retcode));
1196 DHD_TRACE(("%s: successfully enabed ARP offload to %d\n",
1197 __func__, arp_enable));
1200 int dhd_preinit_ioctls(dhd_pub_t *dhd)
1202 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for
1203 "event_msgs" + '\0' + bitvec */
1205 char buf[128], *ptr;
1206 uint power_mode = PM_FAST;
1207 u32 dongle_align = DHD_SDALIGN;
1209 uint bcn_timeout = 3;
1210 int scan_assoc_time = 40;
1211 int scan_unassoc_time = 40;
1212 #ifdef GET_CUSTOM_MAC_ENABLE
1214 u8 ea_addr[ETH_ALEN];
1215 #endif /* GET_CUSTOM_MAC_ENABLE */
1217 dhd_os_proto_block(dhd);
1219 #ifdef GET_CUSTOM_MAC_ENABLE
1220 /* Read MAC address from external customer place
1221 ** NOTE that default mac address has to be present in
1222 ** otp or nvram file to bring up
1223 ** firmware but unique per board mac address maybe provided by
1226 ret = dhd_custom_get_mac_address(ea_addr);
1228 brcmu_mkiovar("cur_etheraddr", (void *)ea_addr, ETH_ALEN,
1230 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf,
1233 DHD_ERROR(("%s: can't set MAC address , error=%d\n",
1236 memcpy(dhd->mac.octet, (void *)&ea_addr,
1239 #endif /* GET_CUSTOM_MAC_ENABLE */
1241 /* Set Country code */
1242 if (dhd->country_code[0] != 0) {
1243 if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_COUNTRY,
1245 sizeof(dhd->country_code)) < 0) {
1246 DHD_ERROR(("%s: country code setting failed\n",
1251 /* query for 'ver' to get version info from firmware */
1252 memset(buf, 0, sizeof(buf));
1254 brcmu_mkiovar("ver", 0, 0, buf, sizeof(buf));
1255 dhdcdc_query_ioctl(dhd, 0, WLC_GET_VAR, buf, sizeof(buf));
1257 /* Print fw version info */
1258 DHD_ERROR(("Firmware version = %s\n", buf));
1260 /* Set PowerSave mode */
1261 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode,
1262 sizeof(power_mode));
1264 /* Match Host and Dongle rx alignment */
1265 brcmu_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
1267 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1269 /* disable glom option per default */
1270 brcmu_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
1271 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1273 /* Setup timeout if Beacons are lost and roam is off to report
1275 brcmu_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf,
1277 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1279 /* Enable/Disable build-in roaming to allowed ext supplicant to take
1281 brcmu_mkiovar("roam_off", (char *)&dhd_roam, 4, iovbuf, sizeof(iovbuf));
1282 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1286 dhdcdc_set_ioctl(dhd, 0, WLC_UP, (char *)&up, sizeof(up));
1288 /* Setup event_msgs */
1289 brcmu_mkiovar("event_msgs", dhd->eventmask, WL_EVENTING_MASK_LEN,
1290 iovbuf, sizeof(iovbuf));
1291 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1293 dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_CHANNEL_TIME,
1294 (char *)&scan_assoc_time, sizeof(scan_assoc_time));
1295 dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_UNASSOC_TIME,
1296 (char *)&scan_unassoc_time, sizeof(scan_unassoc_time));
1298 #ifdef ARP_OFFLOAD_SUPPORT
1299 /* Set and enable ARP offload feature */
1301 dhd_arp_offload_set(dhd, dhd_arp_mode);
1302 dhd_arp_offload_enable(dhd, dhd_arp_enable);
1303 #endif /* ARP_OFFLOAD_SUPPORT */
1305 #ifdef PKT_FILTER_SUPPORT
1308 /* Set up pkt filter */
1309 if (dhd_pkt_filter_enable) {
1310 for (i = 0; i < dhd->pktfilter_count; i++) {
1311 dhd_pktfilter_offload_set(dhd,
1313 dhd_pktfilter_offload_enable(dhd,
1315 dhd_pkt_filter_init,
1320 #endif /* PKT_FILTER_SUPPORT */
1322 dhd_os_proto_unblock(dhd);
1328 uint iscan_thread_id;
1329 iscan_buf_t *iscan_chain;
1331 iscan_buf_t *dhd_iscan_allocate_buf(dhd_pub_t *dhd, iscan_buf_t **iscanbuf)
1333 iscan_buf_t *iscanbuf_alloc = 0;
1334 iscan_buf_t *iscanbuf_head;
1338 iscanbuf_alloc = kmalloc(sizeof(iscan_buf_t), GFP_ATOMIC);
1339 if (iscanbuf_alloc == NULL)
1342 iscanbuf_alloc->next = NULL;
1343 iscanbuf_head = *iscanbuf;
1345 DHD_ISCAN(("%s: addr of allocated node = 0x%X"
1346 "addr of iscanbuf_head = 0x%X dhd = 0x%X\n",
1347 __func__, iscanbuf_alloc, iscanbuf_head, dhd));
1349 if (iscanbuf_head == NULL) {
1350 *iscanbuf = iscanbuf_alloc;
1351 DHD_ISCAN(("%s: Head is allocated\n", __func__));
1355 while (iscanbuf_head->next)
1356 iscanbuf_head = iscanbuf_head->next;
1358 iscanbuf_head->next = iscanbuf_alloc;
1362 return iscanbuf_alloc;
1365 void dhd_iscan_free_buf(void *dhdp, iscan_buf_t *iscan_delete)
1367 iscan_buf_t *iscanbuf_free = 0;
1368 iscan_buf_t *iscanbuf_prv = 0;
1369 iscan_buf_t *iscanbuf_cur = iscan_chain;
1370 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1373 /* If iscan_delete is null then delete the entire
1374 * chain or else delete specific one provided
1376 if (!iscan_delete) {
1377 while (iscanbuf_cur) {
1378 iscanbuf_free = iscanbuf_cur;
1379 iscanbuf_cur = iscanbuf_cur->next;
1380 iscanbuf_free->next = 0;
1381 kfree(iscanbuf_free);
1385 while (iscanbuf_cur) {
1386 if (iscanbuf_cur == iscan_delete)
1388 iscanbuf_prv = iscanbuf_cur;
1389 iscanbuf_cur = iscanbuf_cur->next;
1392 iscanbuf_prv->next = iscan_delete->next;
1394 iscan_delete->next = 0;
1395 kfree(iscan_delete);
1403 iscan_buf_t *dhd_iscan_result_buf(void)
1410 * print partial iscan_skip list differently
1412 int dhd_iscan_print_cache(iscan_buf_t *iscan_skip)
1415 iscan_buf_t *iscan_cur;
1416 wl_iscan_results_t *list;
1417 wl_scan_results_t *results;
1418 wl_bss_info_t UNALIGNED *bi;
1422 iscan_cur = dhd_iscan_result_buf();
1425 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1429 results = (wl_scan_results_t *)&list->results;
1433 if (results->version != WL_BSS_INFO_VERSION) {
1434 DHD_ISCAN(("%s: results->version %d != "
1435 "WL_BSS_INFO_VERSION\n",
1436 __func__, results->version));
1440 bi = results->bss_info;
1441 for (i = 0; i < results->count; i++) {
1445 DHD_ISCAN(("%s[%2.2d:%2.2d] %X:%X:%X:%X:%X:%X\n",
1446 iscan_cur != iscan_skip ? "BSS" : "bss", l,
1447 i, bi->BSSID.octet[0], bi->BSSID.octet[1],
1448 bi->BSSID.octet[2], bi->BSSID.octet[3],
1449 bi->BSSID.octet[4], bi->BSSID.octet[5]));
1451 bi = (wl_bss_info_t *)((unsigned long)bi + bi->length);
1453 iscan_cur = iscan_cur->next;
1463 * delete disappeared AP from specific scan cache but skip partial
1464 * list in iscan_skip
1466 int dhd_iscan_delete_bss(void *dhdp, void *addr, iscan_buf_t *iscan_skip)
1468 int i = 0, j = 0, l = 0;
1469 iscan_buf_t *iscan_cur;
1470 wl_iscan_results_t *list;
1471 wl_scan_results_t *results;
1472 wl_bss_info_t UNALIGNED *bi, *bi_new, *bi_next;
1474 unsigned char *s_addr = addr;
1477 DHD_ISCAN(("%s: BSS to remove %X:%X:%X:%X:%X:%X\n",
1478 __func__, s_addr[0], s_addr[1], s_addr[2],
1479 s_addr[3], s_addr[4], s_addr[5]));
1481 iscan_cur = dhd_iscan_result_buf();
1484 if (iscan_cur != iscan_skip) {
1485 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1489 results = (wl_scan_results_t *)&list->results;
1493 if (results->version != WL_BSS_INFO_VERSION) {
1494 DHD_ERROR(("%s: results->version %d != "
1495 "WL_BSS_INFO_VERSION\n",
1496 __func__, results->version));
1500 bi = results->bss_info;
1501 for (i = 0; i < results->count; i++) {
1506 (bi->BSSID.octet, addr, ETH_ALEN)) {
1507 DHD_ISCAN(("%s: Del BSS[%2.2d:%2.2d] "
1508 "%X:%X:%X:%X:%X:%X\n",
1509 __func__, l, i, bi->BSSID.octet[0],
1510 bi->BSSID.octet[1], bi->BSSID.octet[2],
1511 bi->BSSID.octet[3], bi->BSSID.octet[4],
1512 bi->BSSID.octet[5]));
1515 bi = (wl_bss_info_t *)((unsigned long)
1519 memcpy(bi_new, bi, results->buflen -
1521 results->buflen -= bi_new->length;
1524 results->buflen -= bi_new->length;
1527 for (j = i; j < results->count; j++) {
1529 DHD_ISCAN(("%s: Moved up BSS[%2.2d:%2.2d]" "%X:%X:%X:%X:%X:%X\n",
1536 bi->BSSID.octet[5]));
1539 (wl_bss_info_t *)((unsigned long)bi +
1544 (wl_bss_info_t *)((unsigned long)bi_new +
1551 if (results->count == 0) {
1552 /* Prune now empty partial
1554 dhd_iscan_free_buf(dhdp,
1560 bi = (wl_bss_info_t *)((unsigned long)bi +
1564 iscan_cur = iscan_cur->next;
1573 int dhd_iscan_remove_duplicates(void *dhdp, iscan_buf_t *iscan_cur)
1576 wl_iscan_results_t *list;
1577 wl_scan_results_t *results;
1578 wl_bss_info_t UNALIGNED *bi, *bi_new, *bi_next;
1582 DHD_ISCAN(("%s: Scan cache before delete\n", __func__));
1583 dhd_iscan_print_cache(iscan_cur);
1588 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1592 results = (wl_scan_results_t *)&list->results;
1596 if (results->version != WL_BSS_INFO_VERSION) {
1597 DHD_ERROR(("%s: results->version %d != WL_BSS_INFO_VERSION\n",
1598 __func__, results->version));
1602 bi = results->bss_info;
1603 for (i = 0; i < results->count; i++) {
1607 DHD_ISCAN(("%s: Find dups for BSS[%2.2d] %X:%X:%X:%X:%X:%X\n",
1608 __func__, i, bi->BSSID.octet[0],
1609 bi->BSSID.octet[1], bi->BSSID.octet[2],
1610 bi->BSSID.octet[3], bi->BSSID.octet[4],
1611 bi->BSSID.octet[5]));
1613 dhd_iscan_delete_bss(dhdp, bi->BSSID.octet, iscan_cur);
1615 bi = (wl_bss_info_t *)((unsigned long)bi + bi->length);
1619 DHD_ISCAN(("%s: Scan cache after delete\n", __func__));
1620 dhd_iscan_print_cache(iscan_cur);
1625 void dhd_iscan_ind_scan_confirm(void *dhdp, bool status)
1628 dhd_ind_scan_confirm(dhdp, status);
1631 int dhd_iscan_request(void *dhdp, u16 action)
1634 wl_iscan_params_t params;
1635 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1636 char buf[WLC_IOCTL_SMLEN];
1638 memset(¶ms, 0, sizeof(wl_iscan_params_t));
1639 memcpy(¶ms.params.bssid, ðer_bcast, ETH_ALEN);
1641 params.params.bss_type = DOT11_BSSTYPE_ANY;
1642 params.params.scan_type = DOT11_SCANTYPE_ACTIVE;
1644 params.params.nprobes = -1;
1645 params.params.active_time = -1;
1646 params.params.passive_time = -1;
1647 params.params.home_time = -1;
1648 params.params.channel_num = 0;
1650 params.version = ISCAN_REQ_VERSION;
1651 params.action = action;
1652 params.scan_duration = 0;
1654 brcmu_mkiovar("iscan", (char *)¶ms, sizeof(wl_iscan_params_t), buf,
1656 rc = dhd_wl_ioctl(dhdp, WLC_SET_VAR, buf, WLC_IOCTL_SMLEN);
1661 static int dhd_iscan_get_partial_result(void *dhdp, uint *scan_count)
1663 wl_iscan_results_t *list_buf;
1664 wl_iscan_results_t list;
1665 wl_scan_results_t *results;
1666 iscan_buf_t *iscan_cur;
1668 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1671 iscan_cur = dhd_iscan_allocate_buf(dhd, &iscan_chain);
1673 DHD_ERROR(("%s: Failed to allocate node\n", __func__));
1674 dhd_iscan_free_buf(dhdp, 0);
1675 dhd_iscan_request(dhdp, WL_SCAN_ACTION_ABORT);
1681 memset(iscan_cur->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
1682 list_buf = (wl_iscan_results_t *) iscan_cur->iscan_buf;
1683 results = &list_buf->results;
1684 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
1685 results->version = 0;
1688 memset(&list, 0, sizeof(list));
1689 list.results.buflen = WLC_IW_ISCAN_MAXLEN;
1690 brcmu_mkiovar("iscanresults", (char *)&list,
1691 WL_ISCAN_RESULTS_FIXED_SIZE,
1692 iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN);
1693 rc = dhd_wl_ioctl(dhdp, WLC_GET_VAR, iscan_cur->iscan_buf,
1694 WLC_IW_ISCAN_MAXLEN);
1696 results->buflen = results->buflen;
1697 results->version = results->version;
1698 *scan_count = results->count = results->count;
1699 status = list_buf->status;
1704 dhd_iscan_free_buf(dhdp, iscan_cur);
1706 dhd_iscan_remove_duplicates(dhdp, iscan_cur);
1711 #endif /* SIMPLE_ISCAN */
1714 int dhd_pno_clean(dhd_pub_t *dhd)
1717 int pfn_enabled = 0;
1722 iov_len = brcmu_mkiovar("pfn", (char *)&pfn_enabled, 4, iovbuf,
1724 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1727 iov_len = brcmu_mkiovar("pfnclear", 0, 0, iovbuf,
1730 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1733 DHD_ERROR(("%s failed code %d\n", __func__,
1738 DHD_ERROR(("%s failed code %d\n", __func__, iov_len));
1741 DHD_ERROR(("%s failed code %d\n", __func__, ret));
1746 int dhd_pno_enable(dhd_pub_t *dhd, int pfn_enabled)
1751 if ((!dhd) && ((pfn_enabled != 0) || (pfn_enabled != 1))) {
1752 DHD_ERROR(("%s error exit\n", __func__));
1756 /* Enable/disable PNO */
1757 ret = brcmu_mkiovar("pfn", (char *)&pfn_enabled, 4, iovbuf,
1760 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1763 DHD_ERROR(("%s failed for error=%d\n", __func__, ret));
1766 dhd->pno_enable = pfn_enabled;
1767 DHD_TRACE(("%s set pno as %d\n", __func__,
1771 DHD_ERROR(("%s failed err=%d\n", __func__, ret));
1776 /* Function to execute combined scan */
1778 dhd_pno_set(dhd_pub_t *dhd, wlc_ssid_t *ssids_local, int nssid, unsigned char scan_fr)
1783 wl_pfn_param_t pfn_param;
1784 wl_pfn_t pfn_element;
1786 DHD_TRACE(("%s nssid=%d nchan=%d\n", __func__, nssid, scan_fr));
1788 if ((!dhd) && (!ssids_local)) {
1789 DHD_ERROR(("%s error exit\n", __func__));
1793 /* Check for broadcast ssid */
1794 for (k = 0; k < nssid; k++) {
1795 if (!ssids_local[k].SSID_len) {
1796 DHD_ERROR(("%d: Broadcast SSID is ilegal for PNO "
1801 /* #define PNO_DUMP 1 */
1805 for (j = 0; j < nssid; j++) {
1806 DHD_ERROR(("%d: scan for %s size =%d\n", j,
1807 ssids_local[j].SSID,
1808 ssids_local[j].SSID_len));
1811 #endif /* PNO_DUMP */
1813 /* clean up everything */
1814 err = dhd_pno_clean(dhd);
1816 DHD_ERROR(("%s failed error=%d\n", __func__, err));
1819 memset(&pfn_param, 0, sizeof(pfn_param));
1820 memset(&pfn_element, 0, sizeof(pfn_element));
1822 /* set pfn parameters */
1823 pfn_param.version = PFN_VERSION;
1824 pfn_param.flags = (PFN_LIST_ORDER << SORT_CRITERIA_BIT);
1826 /* set up pno scan fr */
1828 pfn_param.scan_freq = scan_fr;
1830 brcmu_mkiovar("pfn_set", (char *)&pfn_param, sizeof(pfn_param), iovbuf,
1832 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1834 /* set all pfn ssid */
1835 for (i = 0; i < nssid; i++) {
1837 pfn_element.bss_type = DOT11_BSSTYPE_INFRASTRUCTURE;
1838 pfn_element.auth = WLAN_AUTH_OPEN;
1839 pfn_element.wpa_auth = WPA_AUTH_PFN_ANY;
1840 pfn_element.wsec = 0;
1841 pfn_element.infra = 1;
1843 memcpy((char *)pfn_element.ssid.SSID, ssids_local[i].SSID,
1844 ssids_local[i].SSID_len);
1845 pfn_element.ssid.SSID_len = ssids_local[i].SSID_len;
1847 err = brcmu_mkiovar("pfn_add", (char *)&pfn_element,
1848 sizeof(pfn_element), iovbuf, sizeof(iovbuf));
1850 err = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1853 DHD_ERROR(("%s failed for i=%d error=%d\n",
1858 DHD_ERROR(("%s failed err=%d\n", __func__, err));
1862 /* dhd_pno_enable(dhd, 1); */
1866 int dhd_pno_get_status(dhd_pub_t *dhd)
1873 return dhd->pno_enable;
1876 #endif /* PNO_SUPPORT */
1878 /* Androd ComboSCAN support */