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>
21 #include <bcmendian.h>
22 #include <dngl_stats.h>
25 #include <dhd_proto.h>
31 char fw_path[MOD_PARAM_PATHLEN];
32 char nv_path[MOD_PARAM_PATHLEN];
34 /* Last connection success/failure status */
44 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
46 extern void dhd_ind_scan_confirm(void *h, bool status);
47 extern int dhd_wl_ioctl(dhd_pub_t *dhd, uint cmd, char *buf, uint buflen);
48 void dhd_iscan_lock(void);
49 void dhd_iscan_unlock(void);
51 /* Packet alignment for most efficient SDIO (can change based on platform) */
53 #define DHD_SDALIGN 32
55 #if !ISPOWEROF2(DHD_SDALIGN)
56 #error DHD_SDALIGN is not a power of 2!
60 #define EPI_VERSION_STR "4.218.248.5"
61 const char dhd_version[] =
62 "Dongle Host Driver, version " EPI_VERSION_STR "\nCompiled on " __DATE__
65 const char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR;
68 void dhd_set_timer(void *bus, uint wdtick);
91 const bcm_iovar_t dhd_iovars[] = {
92 {"version", IOV_VERSION, 0, IOVT_BUFFER, sizeof(dhd_version)}
95 {"msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0}
97 #endif /* DHD_DEBUG */
98 {"bcmerrorstr", IOV_BCMERRORSTR, 0, IOVT_BUFFER, BCME_STRLEN}
100 {"bcmerror", IOV_BCMERROR, 0, IOVT_INT8, 0}
102 {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0}
104 {"dump", IOV_DUMP, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN}
107 {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0}
109 {"cons", IOV_CONS, 0, IOVT_BUFFER, 0}
112 {"clearcounts", IOV_CLEARCOUNTS, 0, IOVT_VOID, 0}
114 {"gpioob", IOV_GPIOOB, 0, IOVT_UINT32, 0}
116 {"ioctl_timeout", IOV_IOCTLTIMEOUT, 0, IOVT_UINT32, 0}
121 void dhd_common_init(void)
123 /* Init global variables at run-time, not as part of the declaration.
124 * This is required to support init/de-init of the driver.
126 * of globals as part of the declaration results in non-deterministic
127 * behaviour since the value of the globals may be different on the
128 * first time that the driver is initialized vs subsequent
131 dhd_msg_level = DHD_ERROR_VAL;
132 #ifdef CONFIG_BCM4329_FW_PATH
133 strncpy(fw_path, CONFIG_BCM4329_FW_PATH, MOD_PARAM_PATHLEN - 1);
137 #ifdef CONFIG_BCM4329_NVRAM_PATH
138 strncpy(nv_path, CONFIG_BCM4329_NVRAM_PATH, MOD_PARAM_PATHLEN - 1);
144 static int dhd_dump(dhd_pub_t *dhdp, char *buf, int buflen)
147 struct bcmstrbuf *strbuf = &b;
149 bcm_binit(strbuf, buf, buflen);
152 bcm_bprintf(strbuf, "%s\n", dhd_version);
153 bcm_bprintf(strbuf, "\n");
154 bcm_bprintf(strbuf, "pub.up %d pub.txoff %d pub.busstate %d\n",
155 dhdp->up, dhdp->txoff, dhdp->busstate);
156 bcm_bprintf(strbuf, "pub.hdrlen %d pub.maxctl %d pub.rxsz %d\n",
157 dhdp->hdrlen, dhdp->maxctl, dhdp->rxsz);
158 bcm_bprintf(strbuf, "pub.iswl %d pub.drv_version %ld pub.mac %pM\n",
159 dhdp->iswl, dhdp->drv_version, &dhdp->mac);
160 bcm_bprintf(strbuf, "pub.bcmerror %d tickcnt %d\n", dhdp->bcmerror,
163 bcm_bprintf(strbuf, "dongle stats:\n");
165 "tx_packets %ld tx_bytes %ld tx_errors %ld tx_dropped %ld\n",
166 dhdp->dstats.tx_packets, dhdp->dstats.tx_bytes,
167 dhdp->dstats.tx_errors, dhdp->dstats.tx_dropped);
169 "rx_packets %ld rx_bytes %ld rx_errors %ld rx_dropped %ld\n",
170 dhdp->dstats.rx_packets, dhdp->dstats.rx_bytes,
171 dhdp->dstats.rx_errors, dhdp->dstats.rx_dropped);
172 bcm_bprintf(strbuf, "multicast %ld\n", dhdp->dstats.multicast);
174 bcm_bprintf(strbuf, "bus stats:\n");
175 bcm_bprintf(strbuf, "tx_packets %ld tx_multicast %ld tx_errors %ld\n",
176 dhdp->tx_packets, dhdp->tx_multicast, dhdp->tx_errors);
177 bcm_bprintf(strbuf, "tx_ctlpkts %ld tx_ctlerrs %ld\n",
178 dhdp->tx_ctlpkts, dhdp->tx_ctlerrs);
179 bcm_bprintf(strbuf, "rx_packets %ld rx_multicast %ld rx_errors %ld\n",
180 dhdp->rx_packets, dhdp->rx_multicast, dhdp->rx_errors);
182 "rx_ctlpkts %ld rx_ctlerrs %ld rx_dropped %ld rx_flushed %ld\n",
183 dhdp->rx_ctlpkts, dhdp->rx_ctlerrs, dhdp->rx_dropped,
186 "rx_readahead_cnt %ld tx_realloc %ld fc_packets %ld\n",
187 dhdp->rx_readahead_cnt, dhdp->tx_realloc, dhdp->fc_packets);
188 bcm_bprintf(strbuf, "wd_dpc_sched %ld\n", dhdp->wd_dpc_sched);
189 bcm_bprintf(strbuf, "\n");
191 /* Add any prot info */
192 dhd_prot_dump(dhdp, strbuf);
193 bcm_bprintf(strbuf, "\n");
195 /* Add any bus info */
196 dhd_bus_dump(dhdp, strbuf);
198 return !strbuf->size ? BCME_BUFTOOSHORT : 0;
202 dhd_doiovar(dhd_pub_t *dhd_pub, const bcm_iovar_t *vi, u32 actionid,
203 const char *name, void *params, int plen, void *arg, int len,
209 DHD_TRACE(("%s: Enter\n", __func__));
211 bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid));
215 if (plen >= (int)sizeof(int_val))
216 bcopy(params, &int_val, sizeof(int_val));
219 case IOV_GVAL(IOV_VERSION):
220 /* Need to have checked buffer length */
221 strncpy((char *)arg, dhd_version, len);
224 case IOV_GVAL(IOV_MSGLEVEL):
225 int_val = (s32) dhd_msg_level;
226 bcopy(&int_val, arg, val_size);
229 case IOV_SVAL(IOV_MSGLEVEL):
230 dhd_msg_level = int_val;
233 case IOV_GVAL(IOV_BCMERRORSTR):
234 strncpy((char *)arg, bcmerrorstr(dhd_pub->bcmerror),
236 ((char *)arg)[BCME_STRLEN - 1] = 0x00;
239 case IOV_GVAL(IOV_BCMERROR):
240 int_val = (s32) dhd_pub->bcmerror;
241 bcopy(&int_val, arg, val_size);
244 case IOV_GVAL(IOV_WDTICK):
245 int_val = (s32) dhd_watchdog_ms;
246 bcopy(&int_val, arg, val_size);
249 case IOV_SVAL(IOV_WDTICK):
251 bcmerror = BCME_NOTUP;
254 dhd_os_wd_timer(dhd_pub, (uint) int_val);
257 case IOV_GVAL(IOV_DUMP):
258 bcmerror = dhd_dump(dhd_pub, arg, len);
262 case IOV_GVAL(IOV_DCONSOLE_POLL):
263 int_val = (s32) dhd_console_ms;
264 bcopy(&int_val, arg, val_size);
267 case IOV_SVAL(IOV_DCONSOLE_POLL):
268 dhd_console_ms = (uint) int_val;
271 case IOV_SVAL(IOV_CONS):
273 bcmerror = dhd_bus_console_in(dhd_pub, arg, len - 1);
277 case IOV_SVAL(IOV_CLEARCOUNTS):
278 dhd_pub->tx_packets = dhd_pub->rx_packets = 0;
279 dhd_pub->tx_errors = dhd_pub->rx_errors = 0;
280 dhd_pub->tx_ctlpkts = dhd_pub->rx_ctlpkts = 0;
281 dhd_pub->tx_ctlerrs = dhd_pub->rx_ctlerrs = 0;
282 dhd_pub->rx_dropped = 0;
283 dhd_pub->rx_readahead_cnt = 0;
284 dhd_pub->tx_realloc = 0;
285 dhd_pub->wd_dpc_sched = 0;
286 memset(&dhd_pub->dstats, 0, sizeof(dhd_pub->dstats));
287 dhd_bus_clearcounts(dhd_pub);
290 case IOV_GVAL(IOV_IOCTLTIMEOUT):{
291 int_val = (s32) dhd_os_get_ioctl_resp_timeout();
292 bcopy(&int_val, arg, sizeof(int_val));
296 case IOV_SVAL(IOV_IOCTLTIMEOUT):{
298 bcmerror = BCME_BADARG;
300 dhd_os_set_ioctl_resp_timeout((unsigned int)
306 bcmerror = BCME_UNSUPPORTED;
314 /* Store the status of a connection attempt for later retrieval by an iovar */
315 void dhd_store_conn_status(u32 event, u32 status, u32 reason)
317 /* Do not overwrite a WLC_E_PRUNE with a WLC_E_SET_SSID
318 * because an encryption/rsn mismatch results in both events, and
319 * the important information is in the WLC_E_PRUNE.
321 if (!(event == WLC_E_SET_SSID && status == WLC_E_STATUS_FAIL &&
322 dhd_conn_event == WLC_E_PRUNE)) {
323 dhd_conn_event = event;
324 dhd_conn_status = status;
325 dhd_conn_reason = reason;
329 bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, void *pkt, int prec)
332 int eprec = -1; /* precedence to evict from */
335 /* Fast case, precedence queue is not full and we are also not
336 * exceeding total queue length
338 if (!pktq_pfull(q, prec) && !pktq_full(q)) {
339 pktq_penq(q, prec, pkt);
343 /* Determine precedence from which to evict packet, if any */
344 if (pktq_pfull(q, prec))
346 else if (pktq_full(q)) {
347 p = pktq_peek_tail(q, &eprec);
353 /* Evict if needed */
355 /* Detect queueing to unconfigured precedence */
356 ASSERT(!pktq_pempty(q, eprec));
357 discard_oldest = AC_BITMAP_TST(dhdp->wme_dp, eprec);
358 if (eprec == prec && !discard_oldest)
359 return false; /* refuse newer (incoming) packet */
360 /* Evict packet according to discard policy */
361 p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q,
364 DHD_ERROR(("%s: pktq_penq() failed, oldest %d.",
365 __func__, discard_oldest));
369 PKTFREE(dhdp->osh, p, true);
373 p = pktq_penq(q, prec, pkt);
375 DHD_ERROR(("%s: pktq_penq() failed.", __func__));
383 dhd_iovar_op(dhd_pub_t *dhd_pub, const char *name,
384 void *params, int plen, void *arg, int len, bool set)
388 const bcm_iovar_t *vi = NULL;
391 DHD_TRACE(("%s: Enter\n", __func__));
396 /* Get MUST have return space */
397 ASSERT(set || (arg && len));
399 /* Set does NOT take qualifiers */
400 ASSERT(!set || (!params && !plen));
402 vi = bcm_iovar_lookup(dhd_iovars, name);
404 bcmerror = BCME_UNSUPPORTED;
408 DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__,
409 name, (set ? "set" : "get"), len, plen));
411 /* set up 'params' pointer in case this is a set command so that
412 * the convenience int and bool code can be common to set and get
414 if (params == NULL) {
419 if (vi->type == IOVT_VOID)
421 else if (vi->type == IOVT_BUFFER)
424 /* all other types are integer sized */
425 val_size = sizeof(int);
427 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
429 dhd_doiovar(dhd_pub, vi, actionid, name, params, plen, arg, len,
436 int dhd_ioctl(dhd_pub_t *dhd_pub, dhd_ioctl_t *ioc, void *buf, uint buflen)
440 DHD_TRACE(("%s: Enter\n", __func__));
447 if (buflen < sizeof(int))
448 bcmerror = BCME_BUFTOOSHORT;
450 *(int *)buf = DHD_IOCTL_MAGIC;
453 case DHD_GET_VERSION:
454 if (buflen < sizeof(int))
455 bcmerror = -BCME_BUFTOOSHORT;
457 *(int *)buf = DHD_IOCTL_VERSION;
465 /* scan past the name to any arguments */
466 for (arg = buf, arglen = buflen; *arg && arglen;
471 bcmerror = BCME_BUFTOOSHORT;
475 /* account for the NUL terminator */
478 /* call with the appropriate arguments */
479 if (ioc->cmd == DHD_GET_VAR)
481 dhd_iovar_op(dhd_pub, buf, arg, arglen, buf,
485 dhd_iovar_op(dhd_pub, buf, NULL, 0, arg,
487 if (bcmerror != BCME_UNSUPPORTED)
490 /* not in generic table, try protocol module */
491 if (ioc->cmd == DHD_GET_VAR)
492 bcmerror = dhd_prot_iovar_op(dhd_pub, buf, arg,
496 bcmerror = dhd_prot_iovar_op(dhd_pub, buf,
499 if (bcmerror != BCME_UNSUPPORTED)
502 /* if still not found, try bus module */
503 if (ioc->cmd == DHD_GET_VAR)
504 bcmerror = dhd_bus_iovar_op(dhd_pub, buf,
508 bcmerror = dhd_bus_iovar_op(dhd_pub, buf,
516 bcmerror = BCME_UNSUPPORTED;
523 static void wl_show_host_event(wl_event_msg_t *event, void *event_data)
525 uint i, status, reason;
526 bool group = false, flush_txq = false, link = false;
527 char *auth_str, *event_name;
529 char err_msg[256], eabuf[ETHER_ADDR_STR_LEN];
535 WLC_E_SET_SSID, "SET_SSID"}, {
536 WLC_E_JOIN, "JOIN"}, {
537 WLC_E_START, "START"}, {
538 WLC_E_AUTH, "AUTH"}, {
539 WLC_E_AUTH_IND, "AUTH_IND"}, {
540 WLC_E_DEAUTH, "DEAUTH"}, {
541 WLC_E_DEAUTH_IND, "DEAUTH_IND"}, {
542 WLC_E_ASSOC, "ASSOC"}, {
543 WLC_E_ASSOC_IND, "ASSOC_IND"}, {
544 WLC_E_REASSOC, "REASSOC"}, {
545 WLC_E_REASSOC_IND, "REASSOC_IND"}, {
546 WLC_E_DISASSOC, "DISASSOC"}, {
547 WLC_E_DISASSOC_IND, "DISASSOC_IND"}, {
548 WLC_E_QUIET_START, "START_QUIET"}, {
549 WLC_E_QUIET_END, "END_QUIET"}, {
550 WLC_E_BEACON_RX, "BEACON_RX"}, {
551 WLC_E_LINK, "LINK"}, {
552 WLC_E_MIC_ERROR, "MIC_ERROR"}, {
553 WLC_E_NDIS_LINK, "NDIS_LINK"}, {
554 WLC_E_ROAM, "ROAM"}, {
555 WLC_E_TXFAIL, "TXFAIL"}, {
556 WLC_E_PMKID_CACHE, "PMKID_CACHE"}, {
557 WLC_E_RETROGRADE_TSF, "RETROGRADE_TSF"}, {
558 WLC_E_PRUNE, "PRUNE"}, {
559 WLC_E_AUTOAUTH, "AUTOAUTH"}, {
560 WLC_E_EAPOL_MSG, "EAPOL_MSG"}, {
561 WLC_E_SCAN_COMPLETE, "SCAN_COMPLETE"}, {
562 WLC_E_ADDTS_IND, "ADDTS_IND"}, {
563 WLC_E_DELTS_IND, "DELTS_IND"}, {
564 WLC_E_BCNSENT_IND, "BCNSENT_IND"}, {
565 WLC_E_BCNRX_MSG, "BCNRX_MSG"}, {
566 WLC_E_BCNLOST_MSG, "BCNLOST_MSG"}, {
567 WLC_E_ROAM_PREP, "ROAM_PREP"}, {
568 WLC_E_PFN_NET_FOUND, "PNO_NET_FOUND"}, {
569 WLC_E_PFN_NET_LOST, "PNO_NET_LOST"}, {
570 WLC_E_RESET_COMPLETE, "RESET_COMPLETE"}, {
571 WLC_E_JOIN_START, "JOIN_START"}, {
572 WLC_E_ROAM_START, "ROAM_START"}, {
573 WLC_E_ASSOC_START, "ASSOC_START"}, {
574 WLC_E_IBSS_ASSOC, "IBSS_ASSOC"}, {
575 WLC_E_RADIO, "RADIO"}, {
576 WLC_E_PSM_WATCHDOG, "PSM_WATCHDOG"}, {
577 WLC_E_PROBREQ_MSG, "PROBREQ_MSG"}, {
578 WLC_E_SCAN_CONFIRM_IND, "SCAN_CONFIRM_IND"}, {
579 WLC_E_PSK_SUP, "PSK_SUP"}, {
580 WLC_E_COUNTRY_CODE_CHANGED, "COUNTRY_CODE_CHANGED"}, {
581 WLC_E_EXCEEDED_MEDIUM_TIME, "EXCEEDED_MEDIUM_TIME"}, {
582 WLC_E_ICV_ERROR, "ICV_ERROR"}, {
583 WLC_E_UNICAST_DECODE_ERROR, "UNICAST_DECODE_ERROR"}, {
584 WLC_E_MULTICAST_DECODE_ERROR, "MULTICAST_DECODE_ERROR"}, {
585 WLC_E_TRACE, "TRACE"}, {
586 WLC_E_ACTION_FRAME, "ACTION FRAME"}, {
587 WLC_E_ACTION_FRAME_COMPLETE, "ACTION FRAME TX COMPLETE"}, {
589 WLC_E_RSSI, "RSSI"}, {
590 WLC_E_PFN_SCAN_COMPLETE, "SCAN_COMPLETE"}
592 uint event_type, flags, auth_type, datalen;
593 event_type = ntoh32(event->event_type);
594 flags = ntoh16(event->flags);
595 status = ntoh32(event->status);
596 reason = ntoh32(event->reason);
597 auth_type = ntoh32(event->auth_type);
598 datalen = ntoh32(event->datalen);
599 /* debug dump of event messages */
600 sprintf(eabuf, "%pM", event->addr.octet);
602 event_name = "UNKNOWN";
603 for (i = 0; i < ARRAY_SIZE(event_names); i++) {
604 if (event_names[i].event == event_type)
605 event_name = event_names[i].event_name;
608 DHD_EVENT(("EVENT: %s, event ID = %d\n", event_name, event_type));
610 if (flags & WLC_EVENT_MSG_LINK)
612 if (flags & WLC_EVENT_MSG_GROUP)
614 if (flags & WLC_EVENT_MSG_FLUSHTXQ)
617 switch (event_type) {
621 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
624 case WLC_E_ASSOC_IND:
625 case WLC_E_REASSOC_IND:
626 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
631 if (status == WLC_E_STATUS_SUCCESS) {
632 DHD_EVENT(("MACEVENT: %s, MAC %s, SUCCESS\n",
634 } else if (status == WLC_E_STATUS_TIMEOUT) {
635 DHD_EVENT(("MACEVENT: %s, MAC %s, TIMEOUT\n",
637 } else if (status == WLC_E_STATUS_FAIL) {
638 DHD_EVENT(("MACEVENT: %s, MAC %s, FAILURE, reason %d\n",
639 event_name, eabuf, (int)reason));
641 DHD_EVENT(("MACEVENT: %s, MAC %s, unexpected status "
642 "%d\n", event_name, eabuf, (int)status));
646 case WLC_E_DEAUTH_IND:
647 case WLC_E_DISASSOC_IND:
648 DHD_EVENT(("MACEVENT: %s, MAC %s, reason %d\n", event_name,
649 eabuf, (int)reason));
654 if (auth_type == DOT11_OPEN_SYSTEM)
655 auth_str = "Open System";
656 else if (auth_type == DOT11_SHARED_KEY)
657 auth_str = "Shared Key";
659 sprintf(err_msg, "AUTH unknown: %d", (int)auth_type);
662 if (event_type == WLC_E_AUTH_IND) {
663 DHD_EVENT(("MACEVENT: %s, MAC %s, %s\n", event_name,
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, "
674 event_name, eabuf, auth_str, (int)reason));
682 if (status == WLC_E_STATUS_SUCCESS) {
683 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name,
685 } else if (status == WLC_E_STATUS_FAIL) {
686 DHD_EVENT(("MACEVENT: %s, failed\n", event_name));
687 } else if (status == WLC_E_STATUS_NO_NETWORKS) {
688 DHD_EVENT(("MACEVENT: %s, no networks found\n",
691 DHD_EVENT(("MACEVENT: %s, unexpected status %d\n",
692 event_name, (int)status));
696 case WLC_E_BEACON_RX:
697 if (status == WLC_E_STATUS_SUCCESS) {
698 DHD_EVENT(("MACEVENT: %s, SUCCESS\n", event_name));
699 } else if (status == WLC_E_STATUS_FAIL) {
700 DHD_EVENT(("MACEVENT: %s, FAIL\n", event_name));
702 DHD_EVENT(("MACEVENT: %s, status %d\n", event_name,
708 DHD_EVENT(("MACEVENT: %s %s\n", event_name,
709 link ? "UP" : "DOWN"));
712 case WLC_E_MIC_ERROR:
713 DHD_EVENT(("MACEVENT: %s, MAC %s, Group %d, Flush %d\n",
714 event_name, eabuf, group, flush_txq));
717 case WLC_E_ICV_ERROR:
718 case WLC_E_UNICAST_DECODE_ERROR:
719 case WLC_E_MULTICAST_DECODE_ERROR:
720 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
724 DHD_EVENT(("MACEVENT: %s, RA %s\n", event_name, eabuf));
727 case WLC_E_SCAN_COMPLETE:
728 case WLC_E_PMKID_CACHE:
729 DHD_EVENT(("MACEVENT: %s\n", event_name));
732 case WLC_E_PFN_NET_FOUND:
733 case WLC_E_PFN_NET_LOST:
734 case WLC_E_PFN_SCAN_COMPLETE:
735 DHD_EVENT(("PNOEVENT: %s\n", event_name));
740 DHD_EVENT(("MACEVENT: %s, status %d, reason %d\n",
741 event_name, (int)status, (int)reason));
746 static u32 seqnum_prev;
751 buf = (unsigned char *) event_data;
752 memcpy(&hdr, buf, MSGTRACE_HDRLEN);
754 if (hdr.version != MSGTRACE_VERSION) {
756 ("\nMACEVENT: %s [unsupported version --> "
757 "dhd version:%d dongle version:%d]\n",
758 event_name, MSGTRACE_VERSION, hdr.version);
759 /* Reset datalen to avoid display below */
764 /* There are 2 bytes available at the end of data */
765 buf[MSGTRACE_HDRLEN + ntoh16(hdr.len)] = '\0';
767 if (ntoh32(hdr.discarded_bytes)
768 || ntoh32(hdr.discarded_printf)) {
770 ("\nWLC_E_TRACE: [Discarded traces in dongle -->"
771 "discarded_bytes %d discarded_printf %d]\n",
772 ntoh32(hdr.discarded_bytes),
773 ntoh32(hdr.discarded_printf));
776 nblost = ntoh32(hdr.seqnum) - seqnum_prev - 1;
779 ("\nWLC_E_TRACE: [Event lost --> seqnum %d nblost %d\n",
780 ntoh32(hdr.seqnum), nblost);
782 seqnum_prev = ntoh32(hdr.seqnum);
784 /* Display the trace buffer. Advance from \n to \n to
786 * printf (issue with Linux printk )
788 p = (char *)&buf[MSGTRACE_HDRLEN];
789 while ((s = strstr(p, "\n")) != NULL) {
796 /* Reset datalen to avoid display below */
802 DHD_EVENT(("MACEVENT: %s %d\n", event_name,
803 ntoh32(*((int *)event_data))));
807 DHD_EVENT(("MACEVENT: %s %d, MAC %s, status %d, reason %d, "
808 "auth %d\n", event_name, event_type, eabuf,
809 (int)status, (int)reason, (int)auth_type));
813 /* show any appended data */
815 buf = (unsigned char *) event_data;
816 DHD_EVENT((" data (%d) : ", datalen));
817 for (i = 0; i < datalen; i++)
818 DHD_EVENT((" 0x%02x ", *buf++));
822 #endif /* SHOW_EVENTS */
825 wl_host_event(struct dhd_info *dhd, int *ifidx, void *pktdata,
826 wl_event_msg_t *event, void **data_ptr)
828 /* check whether packet is a BRCM event pkt */
829 bcm_event_t *pvt_data = (bcm_event_t *) pktdata;
835 if (bcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
836 DHD_ERROR(("%s: mismatched OUI, bailing\n", __func__));
840 /* BRCM event pkt may be unaligned - use xxx_ua to load user_subtype. */
841 if (ntoh16_ua((void *)&pvt_data->bcm_hdr.usr_subtype) !=
842 BCMILCP_BCM_SUBTYPE_EVENT) {
843 DHD_ERROR(("%s: mismatched subtype, bailing\n", __func__));
847 *data_ptr = &pvt_data[1];
848 event_data = *data_ptr;
850 /* memcpy since BRCM event pkt may be unaligned. */
851 memcpy(event, &pvt_data->event, sizeof(wl_event_msg_t));
853 type = ntoh32_ua((void *)&event->event_type);
854 flags = ntoh16_ua((void *)&event->flags);
855 status = ntoh32_ua((void *)&event->status);
856 evlen = ntoh32_ua((void *)&event->datalen) + sizeof(bcm_event_t);
861 dhd_if_event_t *ifevent = (dhd_if_event_t *) event_data;
862 DHD_TRACE(("%s: if event\n", __func__));
864 if (ifevent->ifidx > 0 &&
865 ifevent->ifidx < DHD_MAX_IFS) {
866 if (ifevent->action == WLC_E_IF_ADD)
867 dhd_add_if(dhd, ifevent->ifidx,
869 pvt_data->eth.ether_dhost,
873 dhd_del_if(dhd, ifevent->ifidx);
875 DHD_ERROR(("%s: Invalid ifidx %d for %s\n",
876 __func__, ifevent->ifidx,
880 /* send up the if event: btamp user needs it */
881 *ifidx = dhd_ifname2idx(dhd, event->ifname);
882 /* push up to external supp/auth */
883 dhd_event(dhd, (char *)pvt_data, evlen, *ifidx);
887 case WLC_E_NDIS_LINK:
891 /* These are what external supplicant/authenticator wants */
893 case WLC_E_ASSOC_IND:
894 case WLC_E_REASSOC_IND:
895 case WLC_E_DISASSOC_IND:
896 case WLC_E_MIC_ERROR:
898 /* Fall through: this should get _everything_ */
900 *ifidx = dhd_ifname2idx(dhd, event->ifname);
901 /* push up to external supp/auth */
902 dhd_event(dhd, (char *)pvt_data, evlen, *ifidx);
903 DHD_TRACE(("%s: MAC event %d, flags %x, status %x\n",
904 __func__, type, flags, status));
906 /* put it back to WLC_E_NDIS_LINK */
907 if (type == WLC_E_NDIS_LINK) {
910 temp = ntoh32_ua((void *)&event->event_type);
911 DHD_TRACE(("Converted to WLC_E_LINK type %d\n", temp));
913 temp = ntoh32(WLC_E_NDIS_LINK);
914 memcpy((void *)(&pvt_data->event.event_type), &temp,
915 sizeof(pvt_data->event.event_type));
921 wl_show_host_event(event, event_data);
922 #endif /* SHOW_EVENTS */
927 void wl_event_to_host_order(wl_event_msg_t *evt)
929 /* Event struct members passed from dongle to host are stored
931 * byte order. Convert all members to host-order.
933 evt->event_type = ntoh32(evt->event_type);
934 evt->flags = ntoh16(evt->flags);
935 evt->status = ntoh32(evt->status);
936 evt->reason = ntoh32(evt->reason);
937 evt->auth_type = ntoh32(evt->auth_type);
938 evt->datalen = ntoh32(evt->datalen);
939 evt->version = ntoh16(evt->version);
942 void print_buf(void *pbuf, int len, int bytes_per_line)
945 unsigned char *buf = pbuf;
947 if (bytes_per_line == 0)
948 bytes_per_line = len;
950 for (i = 0; i < len; i++) {
951 printf("%2.2x", *buf++);
953 if (j == bytes_per_line) {
963 /* Convert user's input in hex pattern to byte-size mask */
964 static int wl_pattern_atoh(char *src, char *dst)
967 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
968 DHD_ERROR(("Mask invalid format. Needs to start with 0x\n"));
971 src = src + 2; /* Skip past 0x */
972 if (strlen(src) % 2 != 0) {
973 DHD_ERROR(("Mask invalid format. Length must be even.\n"));
976 for (i = 0; *src != '\0'; i++) {
978 strncpy(num, src, 2);
980 dst[i] = (u8) simple_strtoul(num, NULL, 16);
987 dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
995 char *arg_save = 0, *arg_org = 0;
998 wl_pkt_filter_enable_t enable_parm;
999 wl_pkt_filter_enable_t *pkt_filterp;
1001 arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
1003 DHD_ERROR(("%s: kmalloc failed\n", __func__));
1007 memcpy(arg_save, arg, strlen(arg) + 1);
1009 argv[i] = strsep(&arg_save, " ");
1012 if (NULL == argv[i]) {
1013 DHD_ERROR(("No args provided\n"));
1017 str = "pkt_filter_enable";
1018 str_len = strlen(str);
1019 strncpy(buf, str, str_len);
1020 buf[str_len] = '\0';
1021 buf_len = str_len + 1;
1023 pkt_filterp = (wl_pkt_filter_enable_t *) (buf + str_len + 1);
1025 /* Parse packet filter id. */
1026 enable_parm.id = htod32(simple_strtoul(argv[i], NULL, 0));
1028 /* Parse enable/disable value. */
1029 enable_parm.enable = htod32(enable);
1031 buf_len += sizeof(enable_parm);
1032 memcpy((char *)pkt_filterp, &enable_parm, sizeof(enable_parm));
1034 /* Enable/disable the specified filter. */
1035 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len);
1036 rc = rc >= 0 ? 0 : rc;
1038 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
1039 __func__, arg, rc));
1041 DHD_TRACE(("%s: successfully added pktfilter %s\n",
1044 /* Contorl the master mode */
1045 bcm_mkiovar("pkt_filter_mode", (char *)&master_mode, 4, buf,
1047 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf));
1048 rc = rc >= 0 ? 0 : rc;
1050 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
1051 __func__, arg, rc));
1058 void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg)
1061 wl_pkt_filter_t pkt_filter;
1062 wl_pkt_filter_t *pkt_filterp;
1068 char *argv[8], *buf = 0;
1070 char *arg_save = 0, *arg_org = 0;
1071 #define BUF_SIZE 2048
1073 arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
1075 DHD_ERROR(("%s: kmalloc failed\n", __func__));
1081 buf = kmalloc(BUF_SIZE, GFP_ATOMIC);
1083 DHD_ERROR(("%s: kmalloc failed\n", __func__));
1087 memcpy(arg_save, arg, strlen(arg) + 1);
1089 if (strlen(arg) > BUF_SIZE) {
1090 DHD_ERROR(("Not enough buffer %d < %d\n", (int)strlen(arg),
1095 argv[i] = strsep(&arg_save, " ");
1097 argv[i] = strsep(&arg_save, " ");
1100 if (NULL == argv[i]) {
1101 DHD_ERROR(("No args provided\n"));
1105 str = "pkt_filter_add";
1106 str_len = strlen(str);
1107 strncpy(buf, str, str_len);
1108 buf[str_len] = '\0';
1109 buf_len = str_len + 1;
1111 pkt_filterp = (wl_pkt_filter_t *) (buf + str_len + 1);
1113 /* Parse packet filter id. */
1114 pkt_filter.id = htod32(simple_strtoul(argv[i], NULL, 0));
1116 if (NULL == argv[++i]) {
1117 DHD_ERROR(("Polarity not provided\n"));
1121 /* Parse filter polarity. */
1122 pkt_filter.negate_match = htod32(simple_strtoul(argv[i], NULL, 0));
1124 if (NULL == argv[++i]) {
1125 DHD_ERROR(("Filter type not provided\n"));
1129 /* Parse filter type. */
1130 pkt_filter.type = htod32(simple_strtoul(argv[i], NULL, 0));
1132 if (NULL == argv[++i]) {
1133 DHD_ERROR(("Offset not provided\n"));
1137 /* Parse pattern filter offset. */
1138 pkt_filter.u.pattern.offset = htod32(simple_strtoul(argv[i], NULL, 0));
1140 if (NULL == argv[++i]) {
1141 DHD_ERROR(("Bitmask not provided\n"));
1145 /* Parse pattern filter mask. */
1147 htod32(wl_pattern_atoh
1148 (argv[i], (char *)pkt_filterp->u.pattern.mask_and_pattern));
1150 if (NULL == argv[++i]) {
1151 DHD_ERROR(("Pattern not provided\n"));
1155 /* Parse pattern filter pattern. */
1157 htod32(wl_pattern_atoh(argv[i],
1158 (char *)&pkt_filterp->u.pattern.
1159 mask_and_pattern[mask_size]));
1161 if (mask_size != pattern_size) {
1162 DHD_ERROR(("Mask and pattern not the same size\n"));
1166 pkt_filter.u.pattern.size_bytes = mask_size;
1167 buf_len += WL_PKT_FILTER_FIXED_LEN;
1168 buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
1170 /* Keep-alive attributes are set in local
1171 * variable (keep_alive_pkt), and
1172 ** then memcpy'ed into buffer (keep_alive_pktp) since there is no
1173 ** guarantee that the buffer is properly aligned.
1175 memcpy((char *)pkt_filterp,
1177 WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
1179 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len);
1180 rc = rc >= 0 ? 0 : rc;
1183 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
1184 __func__, arg, rc));
1186 DHD_TRACE(("%s: successfully added pktfilter %s\n",
1197 void dhd_arp_offload_set(dhd_pub_t *dhd, int arp_mode)
1202 bcm_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf));
1203 retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1204 retcode = retcode >= 0 ? 0 : retcode;
1206 DHD_TRACE(("%s: failed to set ARP offload mode to 0x%x, "
1207 "retcode = %d\n", __func__, arp_mode, retcode));
1209 DHD_TRACE(("%s: successfully set ARP offload mode to 0x%x\n",
1210 __func__, arp_mode));
1213 void dhd_arp_offload_enable(dhd_pub_t *dhd, int arp_enable)
1218 bcm_mkiovar("arpoe", (char *)&arp_enable, 4, iovbuf, sizeof(iovbuf));
1219 retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1220 retcode = retcode >= 0 ? 0 : retcode;
1222 DHD_TRACE(("%s: failed to enabe ARP offload to %d, "
1223 "retcode = %d\n", __func__, arp_enable, retcode));
1225 DHD_TRACE(("%s: successfully enabed ARP offload to %d\n",
1226 __func__, arp_enable));
1229 int dhd_preinit_ioctls(dhd_pub_t *dhd)
1231 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for
1232 "event_msgs" + '\0' + bitvec */
1234 char buf[128], *ptr;
1235 uint power_mode = PM_FAST;
1236 u32 dongle_align = DHD_SDALIGN;
1238 uint bcn_timeout = 3;
1239 int scan_assoc_time = 40;
1240 int scan_unassoc_time = 40;
1241 #ifdef GET_CUSTOM_MAC_ENABLE
1243 struct ether_addr ea_addr;
1244 #endif /* GET_CUSTOM_MAC_ENABLE */
1246 dhd_os_proto_block(dhd);
1248 #ifdef GET_CUSTOM_MAC_ENABLE
1249 /* Read MAC address from external customer place
1250 ** NOTE that default mac address has to be present in
1251 ** otp or nvram file to bring up
1252 ** firmware but unique per board mac address maybe provided by
1255 ret = dhd_custom_get_mac_address(ea_addr.octet);
1257 bcm_mkiovar("cur_etheraddr", (void *)&ea_addr, ETHER_ADDR_LEN,
1259 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf));
1261 DHD_ERROR(("%s: can't set MAC address , error=%d\n",
1264 memcpy(dhd->mac.octet, (void *)&ea_addr,
1267 #endif /* GET_CUSTOM_MAC_ENABLE */
1269 /* Set Country code */
1270 if (dhd->country_code[0] != 0) {
1271 if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_COUNTRY,
1273 sizeof(dhd->country_code)) < 0) {
1274 DHD_ERROR(("%s: country code setting failed\n",
1279 /* query for 'ver' to get version info from firmware */
1280 memset(buf, 0, sizeof(buf));
1282 bcm_mkiovar("ver", 0, 0, buf, sizeof(buf));
1283 dhdcdc_query_ioctl(dhd, 0, WLC_GET_VAR, buf, sizeof(buf));
1285 /* Print fw version info */
1286 DHD_ERROR(("Firmware version = %s\n", buf));
1288 /* Set PowerSave mode */
1289 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode,
1290 sizeof(power_mode));
1292 /* Match Host and Dongle rx alignment */
1293 bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
1295 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1297 /* disable glom option per default */
1298 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
1299 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1301 /* Setup timeout if Beacons are lost and roam is off to report
1303 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf,
1305 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1307 /* Enable/Disable build-in roaming to allowed ext supplicant to take
1309 bcm_mkiovar("roam_off", (char *)&dhd_roam, 4, iovbuf, sizeof(iovbuf));
1310 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1314 dhdcdc_set_ioctl(dhd, 0, WLC_UP, (char *)&up, sizeof(up));
1316 /* Setup event_msgs */
1317 bcm_mkiovar("event_msgs", dhd->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
1319 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1321 dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_CHANNEL_TIME,
1322 (char *)&scan_assoc_time, sizeof(scan_assoc_time));
1323 dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_UNASSOC_TIME,
1324 (char *)&scan_unassoc_time, sizeof(scan_unassoc_time));
1326 #ifdef ARP_OFFLOAD_SUPPORT
1327 /* Set and enable ARP offload feature */
1329 dhd_arp_offload_set(dhd, dhd_arp_mode);
1330 dhd_arp_offload_enable(dhd, dhd_arp_enable);
1331 #endif /* ARP_OFFLOAD_SUPPORT */
1333 #ifdef PKT_FILTER_SUPPORT
1336 /* Set up pkt filter */
1337 if (dhd_pkt_filter_enable) {
1338 for (i = 0; i < dhd->pktfilter_count; i++) {
1339 dhd_pktfilter_offload_set(dhd,
1341 dhd_pktfilter_offload_enable(dhd,
1343 dhd_pkt_filter_init,
1348 #endif /* PKT_FILTER_SUPPORT */
1350 dhd_os_proto_unblock(dhd);
1356 uint iscan_thread_id;
1357 iscan_buf_t *iscan_chain;
1359 iscan_buf_t *dhd_iscan_allocate_buf(dhd_pub_t *dhd, iscan_buf_t **iscanbuf)
1361 iscan_buf_t *iscanbuf_alloc = 0;
1362 iscan_buf_t *iscanbuf_head;
1366 iscanbuf_alloc = kmalloc(sizeof(iscan_buf_t), GFP_ATOMIC);
1367 if (iscanbuf_alloc == NULL)
1370 iscanbuf_alloc->next = NULL;
1371 iscanbuf_head = *iscanbuf;
1373 DHD_ISCAN(("%s: addr of allocated node = 0x%X"
1374 "addr of iscanbuf_head = 0x%X dhd = 0x%X\n",
1375 __func__, iscanbuf_alloc, iscanbuf_head, dhd));
1377 if (iscanbuf_head == NULL) {
1378 *iscanbuf = iscanbuf_alloc;
1379 DHD_ISCAN(("%s: Head is allocated\n", __func__));
1383 while (iscanbuf_head->next)
1384 iscanbuf_head = iscanbuf_head->next;
1386 iscanbuf_head->next = iscanbuf_alloc;
1390 return iscanbuf_alloc;
1393 void dhd_iscan_free_buf(void *dhdp, iscan_buf_t *iscan_delete)
1395 iscan_buf_t *iscanbuf_free = 0;
1396 iscan_buf_t *iscanbuf_prv = 0;
1397 iscan_buf_t *iscanbuf_cur = iscan_chain;
1398 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1401 /* If iscan_delete is null then delete the entire
1402 * chain or else delete specific one provided
1404 if (!iscan_delete) {
1405 while (iscanbuf_cur) {
1406 iscanbuf_free = iscanbuf_cur;
1407 iscanbuf_cur = iscanbuf_cur->next;
1408 iscanbuf_free->next = 0;
1409 kfree(iscanbuf_free);
1413 while (iscanbuf_cur) {
1414 if (iscanbuf_cur == iscan_delete)
1416 iscanbuf_prv = iscanbuf_cur;
1417 iscanbuf_cur = iscanbuf_cur->next;
1420 iscanbuf_prv->next = iscan_delete->next;
1422 iscan_delete->next = 0;
1423 kfree(iscan_delete);
1431 iscan_buf_t *dhd_iscan_result_buf(void)
1438 * print partial iscan_skip list differently
1440 int dhd_iscan_print_cache(iscan_buf_t *iscan_skip)
1443 iscan_buf_t *iscan_cur;
1444 wl_iscan_results_t *list;
1445 wl_scan_results_t *results;
1446 wl_bss_info_t UNALIGNED *bi;
1450 iscan_cur = dhd_iscan_result_buf();
1453 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1457 results = (wl_scan_results_t *)&list->results;
1461 if (results->version != WL_BSS_INFO_VERSION) {
1462 DHD_ISCAN(("%s: results->version %d != "
1463 "WL_BSS_INFO_VERSION\n",
1464 __func__, results->version));
1468 bi = results->bss_info;
1469 for (i = 0; i < results->count; i++) {
1473 DHD_ISCAN(("%s[%2.2d:%2.2d] %X:%X:%X:%X:%X:%X\n",
1474 iscan_cur != iscan_skip ? "BSS" : "bss", l,
1475 i, bi->BSSID.octet[0], bi->BSSID.octet[1],
1476 bi->BSSID.octet[2], bi->BSSID.octet[3],
1477 bi->BSSID.octet[4], bi->BSSID.octet[5]));
1479 bi = (wl_bss_info_t *)((unsigned long)bi +
1480 dtoh32(bi->length));
1482 iscan_cur = iscan_cur->next;
1492 * delete disappeared AP from specific scan cache but skip partial
1493 * list in iscan_skip
1495 int dhd_iscan_delete_bss(void *dhdp, void *addr, iscan_buf_t *iscan_skip)
1497 int i = 0, j = 0, l = 0;
1498 iscan_buf_t *iscan_cur;
1499 wl_iscan_results_t *list;
1500 wl_scan_results_t *results;
1501 wl_bss_info_t UNALIGNED *bi, *bi_new, *bi_next;
1503 unsigned char *s_addr = addr;
1506 DHD_ISCAN(("%s: BSS to remove %X:%X:%X:%X:%X:%X\n",
1507 __func__, s_addr[0], s_addr[1], s_addr[2],
1508 s_addr[3], s_addr[4], s_addr[5]));
1510 iscan_cur = dhd_iscan_result_buf();
1513 if (iscan_cur != iscan_skip) {
1514 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1518 results = (wl_scan_results_t *)&list->results;
1522 if (results->version != WL_BSS_INFO_VERSION) {
1523 DHD_ERROR(("%s: results->version %d != "
1524 "WL_BSS_INFO_VERSION\n",
1525 __func__, results->version));
1529 bi = results->bss_info;
1530 for (i = 0; i < results->count; i++) {
1535 (bi->BSSID.octet, addr, ETHER_ADDR_LEN)) {
1536 DHD_ISCAN(("%s: Del BSS[%2.2d:%2.2d] "
1537 "%X:%X:%X:%X:%X:%X\n",
1538 __func__, l, i, bi->BSSID.octet[0],
1539 bi->BSSID.octet[1], bi->BSSID.octet[2],
1540 bi->BSSID.octet[3], bi->BSSID.octet[4],
1541 bi->BSSID.octet[5]));
1544 bi = (wl_bss_info_t *)((unsigned long)bi +
1549 bcopy(bi, bi_new, results->buflen -
1550 dtoh32(bi_new->length));
1551 results->buflen -= dtoh32(bi_new->length);
1555 dtoh32(bi_new->length);
1558 for (j = i; j < results->count; j++) {
1560 DHD_ISCAN(("%s: Moved up BSS[%2.2d:%2.2d]" "%X:%X:%X:%X:%X:%X\n",
1567 bi->BSSID.octet[5]));
1570 (wl_bss_info_t *)((unsigned long)bi +
1577 (wl_bss_info_t *)((unsigned long)bi_new +
1585 if (results->count == 0) {
1586 /* Prune now empty partial
1588 dhd_iscan_free_buf(dhdp,
1594 bi = (wl_bss_info_t *)((unsigned long)bi +
1595 dtoh32(bi->length));
1598 iscan_cur = iscan_cur->next;
1607 int dhd_iscan_remove_duplicates(void *dhdp, iscan_buf_t *iscan_cur)
1610 wl_iscan_results_t *list;
1611 wl_scan_results_t *results;
1612 wl_bss_info_t UNALIGNED *bi, *bi_new, *bi_next;
1616 DHD_ISCAN(("%s: Scan cache before delete\n", __func__));
1617 dhd_iscan_print_cache(iscan_cur);
1622 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1626 results = (wl_scan_results_t *)&list->results;
1630 if (results->version != WL_BSS_INFO_VERSION) {
1631 DHD_ERROR(("%s: results->version %d != WL_BSS_INFO_VERSION\n",
1632 __func__, results->version));
1636 bi = results->bss_info;
1637 for (i = 0; i < results->count; i++) {
1641 DHD_ISCAN(("%s: Find dups for BSS[%2.2d] %X:%X:%X:%X:%X:%X\n",
1642 __func__, i, bi->BSSID.octet[0],
1643 bi->BSSID.octet[1], bi->BSSID.octet[2],
1644 bi->BSSID.octet[3], bi->BSSID.octet[4],
1645 bi->BSSID.octet[5]));
1647 dhd_iscan_delete_bss(dhdp, bi->BSSID.octet, iscan_cur);
1649 bi = (wl_bss_info_t *)((unsigned long)bi + dtoh32(bi->length));
1653 DHD_ISCAN(("%s: Scan cache after delete\n", __func__));
1654 dhd_iscan_print_cache(iscan_cur);
1659 void dhd_iscan_ind_scan_confirm(void *dhdp, bool status)
1662 dhd_ind_scan_confirm(dhdp, status);
1665 int dhd_iscan_request(void *dhdp, u16 action)
1668 wl_iscan_params_t params;
1669 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1670 char buf[WLC_IOCTL_SMLEN];
1672 memset(¶ms, 0, sizeof(wl_iscan_params_t));
1673 memcpy(¶ms.params.bssid, ðer_bcast, ETHER_ADDR_LEN);
1675 params.params.bss_type = DOT11_BSSTYPE_ANY;
1676 params.params.scan_type = DOT11_SCANTYPE_ACTIVE;
1678 params.params.nprobes = htod32(-1);
1679 params.params.active_time = htod32(-1);
1680 params.params.passive_time = htod32(-1);
1681 params.params.home_time = htod32(-1);
1682 params.params.channel_num = htod32(0);
1684 params.version = htod32(ISCAN_REQ_VERSION);
1685 params.action = htod16(action);
1686 params.scan_duration = htod16(0);
1688 bcm_mkiovar("iscan", (char *)¶ms, sizeof(wl_iscan_params_t), buf,
1690 rc = dhd_wl_ioctl(dhdp, WLC_SET_VAR, buf, WLC_IOCTL_SMLEN);
1695 static int dhd_iscan_get_partial_result(void *dhdp, uint *scan_count)
1697 wl_iscan_results_t *list_buf;
1698 wl_iscan_results_t list;
1699 wl_scan_results_t *results;
1700 iscan_buf_t *iscan_cur;
1702 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1705 iscan_cur = dhd_iscan_allocate_buf(dhd, &iscan_chain);
1707 DHD_ERROR(("%s: Failed to allocate node\n", __func__));
1708 dhd_iscan_free_buf(dhdp, 0);
1709 dhd_iscan_request(dhdp, WL_SCAN_ACTION_ABORT);
1715 memset(iscan_cur->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
1716 list_buf = (wl_iscan_results_t *) iscan_cur->iscan_buf;
1717 results = &list_buf->results;
1718 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
1719 results->version = 0;
1722 memset(&list, 0, sizeof(list));
1723 list.results.buflen = htod32(WLC_IW_ISCAN_MAXLEN);
1724 bcm_mkiovar("iscanresults", (char *)&list, WL_ISCAN_RESULTS_FIXED_SIZE,
1725 iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN);
1726 rc = dhd_wl_ioctl(dhdp, WLC_GET_VAR, iscan_cur->iscan_buf,
1727 WLC_IW_ISCAN_MAXLEN);
1729 results->buflen = dtoh32(results->buflen);
1730 results->version = dtoh32(results->version);
1731 *scan_count = results->count = dtoh32(results->count);
1732 status = dtoh32(list_buf->status);
1737 dhd_iscan_free_buf(dhdp, iscan_cur);
1739 dhd_iscan_remove_duplicates(dhdp, iscan_cur);
1744 #endif /* SIMPLE_ISCAN */
1747 int dhd_pno_clean(dhd_pub_t *dhd)
1750 int pfn_enabled = 0;
1756 bcm_mkiovar("pfn", (char *)&pfn_enabled, 4, iovbuf, sizeof(iovbuf));
1757 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1760 iov_len = bcm_mkiovar("pfnclear", 0, 0, iovbuf, sizeof(iovbuf));
1762 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1765 DHD_ERROR(("%s failed code %d\n", __func__,
1770 DHD_ERROR(("%s failed code %d\n", __func__, iov_len));
1773 DHD_ERROR(("%s failed code %d\n", __func__, ret));
1778 int dhd_pno_enable(dhd_pub_t *dhd, int pfn_enabled)
1783 if ((!dhd) && ((pfn_enabled != 0) || (pfn_enabled != 1))) {
1784 DHD_ERROR(("%s error exit\n", __func__));
1788 /* Enable/disable PNO */
1789 ret = bcm_mkiovar("pfn", (char *)&pfn_enabled, 4, iovbuf,
1792 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1795 DHD_ERROR(("%s failed for error=%d\n", __func__, ret));
1798 dhd->pno_enable = pfn_enabled;
1799 DHD_TRACE(("%s set pno as %d\n", __func__,
1803 DHD_ERROR(("%s failed err=%d\n", __func__, ret));
1808 /* Function to execute combined scan */
1810 dhd_pno_set(dhd_pub_t *dhd, wlc_ssid_t *ssids_local, int nssid, unsigned char scan_fr)
1815 wl_pfn_param_t pfn_param;
1816 wl_pfn_t pfn_element;
1818 DHD_TRACE(("%s nssid=%d nchan=%d\n", __func__, nssid, scan_fr));
1820 if ((!dhd) && (!ssids_local)) {
1821 DHD_ERROR(("%s error exit\n", __func__));
1825 /* Check for broadcast ssid */
1826 for (k = 0; k < nssid; k++) {
1827 if (!ssids_local[k].SSID_len) {
1828 DHD_ERROR(("%d: Broadcast SSID is ilegal for PNO "
1833 /* #define PNO_DUMP 1 */
1837 for (j = 0; j < nssid; j++) {
1838 DHD_ERROR(("%d: scan for %s size =%d\n", j,
1839 ssids_local[j].SSID,
1840 ssids_local[j].SSID_len));
1843 #endif /* PNO_DUMP */
1845 /* clean up everything */
1846 err = dhd_pno_clean(dhd);
1848 DHD_ERROR(("%s failed error=%d\n", __func__, err));
1851 memset(&pfn_param, 0, sizeof(pfn_param));
1852 memset(&pfn_element, 0, sizeof(pfn_element));
1854 /* set pfn parameters */
1855 pfn_param.version = htod32(PFN_VERSION);
1856 pfn_param.flags = htod16((PFN_LIST_ORDER << SORT_CRITERIA_BIT));
1858 /* set up pno scan fr */
1860 pfn_param.scan_freq = htod32(scan_fr);
1862 bcm_mkiovar("pfn_set", (char *)&pfn_param, sizeof(pfn_param), iovbuf,
1864 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1866 /* set all pfn ssid */
1867 for (i = 0; i < nssid; i++) {
1869 pfn_element.bss_type = htod32(DOT11_BSSTYPE_INFRASTRUCTURE);
1870 pfn_element.auth = (DOT11_OPEN_SYSTEM);
1871 pfn_element.wpa_auth = htod32(WPA_AUTH_PFN_ANY);
1872 pfn_element.wsec = htod32(0);
1873 pfn_element.infra = htod32(1);
1875 memcpy((char *)pfn_element.ssid.SSID, ssids_local[i].SSID,
1876 ssids_local[i].SSID_len);
1877 pfn_element.ssid.SSID_len = ssids_local[i].SSID_len;
1879 err = bcm_mkiovar("pfn_add", (char *)&pfn_element,
1880 sizeof(pfn_element), iovbuf, sizeof(iovbuf));
1882 err = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1885 DHD_ERROR(("%s failed for i=%d error=%d\n",
1890 DHD_ERROR(("%s failed err=%d\n", __func__, err));
1894 /* dhd_pno_enable(dhd, 1); */
1898 int dhd_pno_get_status(dhd_pub_t *dhd)
1905 return dhd->pno_enable;
1908 #endif /* PNO_SUPPORT */
1910 /* Androd ComboSCAN support */