1 /*
2 * Copyright (c) 2010 Broadcom Corporation
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <bcmdefs.h>
19 #include <linux/netdevice.h>
20 #include <bcmutils.h>
21 #include <dngl_stats.h>
22 #include <dhd.h>
23 #include <dhd_bus.h>
24 #include <dhd_proto.h>
25 #include <dhd_dbg.h>
26 #include <msgtrace.h>
27 #include <wlioctl.h>
28
29 int dhd_msg_level;
30 char fw_path[MOD_PARAM_PATHLEN];
31 char nv_path[MOD_PARAM_PATHLEN];
32
33 /* Last connection success/failure status */
34 u32 dhd_conn_event;
35 u32 dhd_conn_status;
36 u32 dhd_conn_reason;
37
38 extern int dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf,
39 uint len);
40 extern void dhd_ind_scan_confirm(void *h, bool status);
41 extern int dhd_wl_ioctl(dhd_pub_t *dhd, uint cmd, char *buf, uint buflen);
42 void dhd_iscan_lock(void);
43 void dhd_iscan_unlock(void);
44
45 /* Packet alignment for most efficient SDIO (can change based on platform) */
46 #ifndef DHD_SDALIGN
47 #define DHD_SDALIGN 32
48 #endif
49 #if !ISPOWEROF2(DHD_SDALIGN)
50 #error DHD_SDALIGN is not a power of 2!
51 #endif
52
53 #define EPI_VERSION_STR "4.218.248.5"
54 #ifdef DHD_DEBUG
55 const char dhd_version[] =
56 "Dongle Host Driver, version " EPI_VERSION_STR "\nCompiled on " __DATE__
57 " at " __TIME__;
58 #else
59 const char dhd_version[] = "Dongle Host Driver, version " EPI_VERSION_STR;
60 #endif
61
62 void dhd_set_timer(void *bus, uint wdtick);
63
64 /* IOVar table */
65 enum {
66 IOV_VERSION = 1,
67 IOV_MSGLEVEL,
68 IOV_BCMERRORSTR,
69 IOV_BCMERROR,
70 IOV_WDTICK,
71 IOV_DUMP,
72 #ifdef DHD_DEBUG
73 IOV_CONS,
74 IOV_DCONSOLE_POLL,
75 #endif
76 IOV_CLEARCOUNTS,
77 IOV_LOGDUMP,
78 IOV_LOGCAL,
79 IOV_LOGSTAMP,
80 IOV_GPIOOB,
81 IOV_IOCTLTIMEOUT,
82 IOV_LAST
83 };
84
85 const bcm_iovar_t dhd_iovars[] = {
86 {"version", IOV_VERSION, 0, IOVT_BUFFER, sizeof(dhd_version)}
87 ,
88 #ifdef DHD_DEBUG
89 {"msglevel", IOV_MSGLEVEL, 0, IOVT_UINT32, 0}
90 ,
91 #endif /* DHD_DEBUG */
92 {"bcmerrorstr", IOV_BCMERRORSTR, 0, IOVT_BUFFER, BCME_STRLEN}
93 ,
94 {"bcmerror", IOV_BCMERROR, 0, IOVT_INT8, 0}
95 ,
96 {"wdtick", IOV_WDTICK, 0, IOVT_UINT32, 0}
97 ,
98 {"dump", IOV_DUMP, 0, IOVT_BUFFER, DHD_IOCTL_MAXLEN}
99 ,
100 #ifdef DHD_DEBUG
101 {"dconpoll", IOV_DCONSOLE_POLL, 0, IOVT_UINT32, 0}
102 ,
103 {"cons", IOV_CONS, 0, IOVT_BUFFER, 0}
104 ,
105 #endif
106 {"clearcounts", IOV_CLEARCOUNTS, 0, IOVT_VOID, 0}
107 ,
108 {"gpioob", IOV_GPIOOB, 0, IOVT_UINT32, 0}
109 ,
110 {"ioctl_timeout", IOV_IOCTLTIMEOUT, 0, IOVT_UINT32, 0}
111 ,
112 {NULL, 0, 0, 0, 0}
113 };
114
dhd_common_init(void)115 void dhd_common_init(void)
116 {
117 /* Init global variables at run-time, not as part of the declaration.
118 * This is required to support init/de-init of the driver.
119 * Initialization
120 * of globals as part of the declaration results in non-deterministic
121 * behaviour since the value of the globals may be different on the
122 * first time that the driver is initialized vs subsequent
123 * initializations.
124 */
125 dhd_msg_level = DHD_ERROR_VAL;
126 #ifdef CONFIG_BCM4329_FW_PATH
127 strncpy(fw_path, CONFIG_BCM4329_FW_PATH, MOD_PARAM_PATHLEN - 1);
128 #else
129 fw_path[0] = '\0';
130 #endif
131 #ifdef CONFIG_BCM4329_NVRAM_PATH
132 strncpy(nv_path, CONFIG_BCM4329_NVRAM_PATH, MOD_PARAM_PATHLEN - 1);
133 #else
134 nv_path[0] = '\0';
135 #endif
136 }
137
dhd_dump(dhd_pub_t * dhdp,char * buf,int buflen)138 static int dhd_dump(dhd_pub_t *dhdp, char *buf, int buflen)
139 {
140 struct bcmstrbuf b;
141 struct bcmstrbuf *strbuf = &b;
142
143 bcm_binit(strbuf, buf, buflen);
144
145 /* Base DHD info */
146 bcm_bprintf(strbuf, "%s\n", dhd_version);
147 bcm_bprintf(strbuf, "\n");
148 bcm_bprintf(strbuf, "pub.up %d pub.txoff %d pub.busstate %d\n",
149 dhdp->up, dhdp->txoff, dhdp->busstate);
150 bcm_bprintf(strbuf, "pub.hdrlen %d pub.maxctl %d pub.rxsz %d\n",
151 dhdp->hdrlen, dhdp->maxctl, dhdp->rxsz);
152 bcm_bprintf(strbuf, "pub.iswl %d pub.drv_version %ld pub.mac %pM\n",
153 dhdp->iswl, dhdp->drv_version, &dhdp->mac);
154 bcm_bprintf(strbuf, "pub.bcmerror %d tickcnt %d\n", dhdp->bcmerror,
155 dhdp->tickcnt);
156
157 bcm_bprintf(strbuf, "dongle stats:\n");
158 bcm_bprintf(strbuf,
159 "tx_packets %ld tx_bytes %ld tx_errors %ld tx_dropped %ld\n",
160 dhdp->dstats.tx_packets, dhdp->dstats.tx_bytes,
161 dhdp->dstats.tx_errors, dhdp->dstats.tx_dropped);
162 bcm_bprintf(strbuf,
163 "rx_packets %ld rx_bytes %ld rx_errors %ld rx_dropped %ld\n",
164 dhdp->dstats.rx_packets, dhdp->dstats.rx_bytes,
165 dhdp->dstats.rx_errors, dhdp->dstats.rx_dropped);
166 bcm_bprintf(strbuf, "multicast %ld\n", dhdp->dstats.multicast);
167
168 bcm_bprintf(strbuf, "bus stats:\n");
169 bcm_bprintf(strbuf, "tx_packets %ld tx_multicast %ld tx_errors %ld\n",
170 dhdp->tx_packets, dhdp->tx_multicast, dhdp->tx_errors);
171 bcm_bprintf(strbuf, "tx_ctlpkts %ld tx_ctlerrs %ld\n",
172 dhdp->tx_ctlpkts, dhdp->tx_ctlerrs);
173 bcm_bprintf(strbuf, "rx_packets %ld rx_multicast %ld rx_errors %ld\n",
174 dhdp->rx_packets, dhdp->rx_multicast, dhdp->rx_errors);
175 bcm_bprintf(strbuf,
176 "rx_ctlpkts %ld rx_ctlerrs %ld rx_dropped %ld rx_flushed %ld\n",
177 dhdp->rx_ctlpkts, dhdp->rx_ctlerrs, dhdp->rx_dropped,
178 dhdp->rx_flushed);
179 bcm_bprintf(strbuf,
180 "rx_readahead_cnt %ld tx_realloc %ld fc_packets %ld\n",
181 dhdp->rx_readahead_cnt, dhdp->tx_realloc, dhdp->fc_packets);
182 bcm_bprintf(strbuf, "wd_dpc_sched %ld\n", dhdp->wd_dpc_sched);
183 bcm_bprintf(strbuf, "\n");
184
185 /* Add any prot info */
186 dhd_prot_dump(dhdp, strbuf);
187 bcm_bprintf(strbuf, "\n");
188
189 /* Add any bus info */
190 dhd_bus_dump(dhdp, strbuf);
191
192 return !strbuf->size ? BCME_BUFTOOSHORT : 0;
193 }
194
195 static int
dhd_doiovar(dhd_pub_t * dhd_pub,const bcm_iovar_t * vi,u32 actionid,const char * name,void * params,int plen,void * arg,int len,int val_size)196 dhd_doiovar(dhd_pub_t *dhd_pub, const bcm_iovar_t *vi, u32 actionid,
197 const char *name, void *params, int plen, void *arg, int len,
198 int val_size)
199 {
200 int bcmerror = 0;
201 s32 int_val = 0;
202
203 DHD_TRACE(("%s: Enter\n", __func__));
204
205 bcmerror = bcm_iovar_lencheck(vi, arg, len, IOV_ISSET(actionid));
206 if (bcmerror != 0)
207 goto exit;
208
209 if (plen >= (int)sizeof(int_val))
210 memcpy(&int_val, params, sizeof(int_val));
211
212 switch (actionid) {
213 case IOV_GVAL(IOV_VERSION):
214 /* Need to have checked buffer length */
215 strncpy((char *)arg, dhd_version, len);
216 break;
217
218 case IOV_GVAL(IOV_MSGLEVEL):
219 int_val = (s32) dhd_msg_level;
220 memcpy(arg, &int_val, val_size);
221 break;
222
223 case IOV_SVAL(IOV_MSGLEVEL):
224 dhd_msg_level = int_val;
225 break;
226
227 case IOV_GVAL(IOV_BCMERRORSTR):
228 strncpy((char *)arg, bcmerrorstr(dhd_pub->bcmerror),
229 BCME_STRLEN);
230 ((char *)arg)[BCME_STRLEN - 1] = 0x00;
231 break;
232
233 case IOV_GVAL(IOV_BCMERROR):
234 int_val = (s32) dhd_pub->bcmerror;
235 memcpy(arg, &int_val, val_size);
236 break;
237
238 case IOV_GVAL(IOV_WDTICK):
239 int_val = (s32) dhd_watchdog_ms;
240 memcpy(arg, &int_val, val_size);
241 break;
242
243 case IOV_SVAL(IOV_WDTICK):
244 if (!dhd_pub->up) {
245 bcmerror = BCME_NOTUP;
246 break;
247 }
248 dhd_os_wd_timer(dhd_pub, (uint) int_val);
249 break;
250
251 case IOV_GVAL(IOV_DUMP):
252 bcmerror = dhd_dump(dhd_pub, arg, len);
253 break;
254
255 #ifdef DHD_DEBUG
256 case IOV_GVAL(IOV_DCONSOLE_POLL):
257 int_val = (s32) dhd_console_ms;
258 memcpy(arg, &int_val, val_size);
259 break;
260
261 case IOV_SVAL(IOV_DCONSOLE_POLL):
262 dhd_console_ms = (uint) int_val;
263 break;
264
265 case IOV_SVAL(IOV_CONS):
266 if (len > 0)
267 bcmerror = dhd_bus_console_in(dhd_pub, arg, len - 1);
268 break;
269 #endif
270
271 case IOV_SVAL(IOV_CLEARCOUNTS):
272 dhd_pub->tx_packets = dhd_pub->rx_packets = 0;
273 dhd_pub->tx_errors = dhd_pub->rx_errors = 0;
274 dhd_pub->tx_ctlpkts = dhd_pub->rx_ctlpkts = 0;
275 dhd_pub->tx_ctlerrs = dhd_pub->rx_ctlerrs = 0;
276 dhd_pub->rx_dropped = 0;
277 dhd_pub->rx_readahead_cnt = 0;
278 dhd_pub->tx_realloc = 0;
279 dhd_pub->wd_dpc_sched = 0;
280 memset(&dhd_pub->dstats, 0, sizeof(dhd_pub->dstats));
281 dhd_bus_clearcounts(dhd_pub);
282 break;
283
284 case IOV_GVAL(IOV_IOCTLTIMEOUT):{
285 int_val = (s32) dhd_os_get_ioctl_resp_timeout();
286 memcpy(arg, &int_val, sizeof(int_val));
287 break;
288 }
289
290 case IOV_SVAL(IOV_IOCTLTIMEOUT):{
291 if (int_val <= 0)
292 bcmerror = BCME_BADARG;
293 else
294 dhd_os_set_ioctl_resp_timeout((unsigned int)
295 int_val);
296 break;
297 }
298
299 default:
300 bcmerror = BCME_UNSUPPORTED;
301 break;
302 }
303
304 exit:
305 return bcmerror;
306 }
307
dhd_prec_enq(dhd_pub_t * dhdp,struct pktq * q,struct sk_buff * pkt,int prec)308 bool dhd_prec_enq(dhd_pub_t *dhdp, struct pktq *q, struct sk_buff *pkt,
309 int prec)
310 {
311 struct sk_buff *p;
312 int eprec = -1; /* precedence to evict from */
313 bool discard_oldest;
314
315 /* Fast case, precedence queue is not full and we are also not
316 * exceeding total queue length
317 */
318 if (!pktq_pfull(q, prec) && !pktq_full(q)) {
319 pktq_penq(q, prec, pkt);
320 return true;
321 }
322
323 /* Determine precedence from which to evict packet, if any */
324 if (pktq_pfull(q, prec))
325 eprec = prec;
326 else if (pktq_full(q)) {
327 p = pktq_peek_tail(q, &eprec);
328 ASSERT(p);
329 if (eprec > prec)
330 return false;
331 }
332
333 /* Evict if needed */
334 if (eprec >= 0) {
335 /* Detect queueing to unconfigured precedence */
336 ASSERT(!pktq_pempty(q, eprec));
337 discard_oldest = AC_BITMAP_TST(dhdp->wme_dp, eprec);
338 if (eprec == prec && !discard_oldest)
339 return false; /* refuse newer (incoming) packet */
340 /* Evict packet according to discard policy */
341 p = discard_oldest ? pktq_pdeq(q, eprec) : pktq_pdeq_tail(q,
342 eprec);
343 if (p == NULL) {
344 DHD_ERROR(("%s: pktq_penq() failed, oldest %d.",
345 __func__, discard_oldest));
346 ASSERT(p);
347 }
348
349 pkt_buf_free_skb(p);
350 }
351
352 /* Enqueue */
353 p = pktq_penq(q, prec, pkt);
354 if (p == NULL) {
355 DHD_ERROR(("%s: pktq_penq() failed.", __func__));
356 ASSERT(p);
357 }
358
359 return true;
360 }
361
362 static int
dhd_iovar_op(dhd_pub_t * dhd_pub,const char * name,void * params,int plen,void * arg,int len,bool set)363 dhd_iovar_op(dhd_pub_t *dhd_pub, const char *name,
364 void *params, int plen, void *arg, int len, bool set)
365 {
366 int bcmerror = 0;
367 int val_size;
368 const bcm_iovar_t *vi = NULL;
369 u32 actionid;
370
371 DHD_TRACE(("%s: Enter\n", __func__));
372
373 ASSERT(name);
374 ASSERT(len >= 0);
375
376 /* Get MUST have return space */
377 ASSERT(set || (arg && len));
378
379 /* Set does NOT take qualifiers */
380 ASSERT(!set || (!params && !plen));
381
382 vi = bcm_iovar_lookup(dhd_iovars, name);
383 if (vi == NULL) {
384 bcmerror = BCME_UNSUPPORTED;
385 goto exit;
386 }
387
388 DHD_CTL(("%s: %s %s, len %d plen %d\n", __func__,
389 name, (set ? "set" : "get"), len, plen));
390
391 /* set up 'params' pointer in case this is a set command so that
392 * the convenience int and bool code can be common to set and get
393 */
394 if (params == NULL) {
395 params = arg;
396 plen = len;
397 }
398
399 if (vi->type == IOVT_VOID)
400 val_size = 0;
401 else if (vi->type == IOVT_BUFFER)
402 val_size = len;
403 else
404 /* all other types are integer sized */
405 val_size = sizeof(int);
406
407 actionid = set ? IOV_SVAL(vi->varid) : IOV_GVAL(vi->varid);
408 bcmerror =
409 dhd_doiovar(dhd_pub, vi, actionid, name, params, plen, arg, len,
410 val_size);
411
412 exit:
413 return bcmerror;
414 }
415
dhd_ioctl(dhd_pub_t * dhd_pub,dhd_ioctl_t * ioc,void * buf,uint buflen)416 int dhd_ioctl(dhd_pub_t *dhd_pub, dhd_ioctl_t *ioc, void *buf, uint buflen)
417 {
418 int bcmerror = 0;
419
420 DHD_TRACE(("%s: Enter\n", __func__));
421
422 if (!buf)
423 return BCME_BADARG;
424
425 switch (ioc->cmd) {
426 case DHD_GET_MAGIC:
427 if (buflen < sizeof(int))
428 bcmerror = BCME_BUFTOOSHORT;
429 else
430 *(int *)buf = DHD_IOCTL_MAGIC;
431 break;
432
433 case DHD_GET_VERSION:
434 if (buflen < sizeof(int))
435 bcmerror = -BCME_BUFTOOSHORT;
436 else
437 *(int *)buf = DHD_IOCTL_VERSION;
438 break;
439
440 case DHD_GET_VAR:
441 case DHD_SET_VAR:{
442 char *arg;
443 uint arglen;
444
445 /* scan past the name to any arguments */
446 for (arg = buf, arglen = buflen; *arg && arglen;
447 arg++, arglen--)
448 ;
449
450 if (*arg) {
451 bcmerror = BCME_BUFTOOSHORT;
452 break;
453 }
454
455 /* account for the NUL terminator */
456 arg++, arglen--;
457
458 /* call with the appropriate arguments */
459 if (ioc->cmd == DHD_GET_VAR)
460 bcmerror =
461 dhd_iovar_op(dhd_pub, buf, arg, arglen, buf,
462 buflen, IOV_GET);
463 else
464 bcmerror =
465 dhd_iovar_op(dhd_pub, buf, NULL, 0, arg,
466 arglen, IOV_SET);
467 if (bcmerror != BCME_UNSUPPORTED)
468 break;
469
470 /* not in generic table, try protocol module */
471 if (ioc->cmd == DHD_GET_VAR)
472 bcmerror = dhd_prot_iovar_op(dhd_pub, buf, arg,
473 arglen, buf,
474 buflen, IOV_GET);
475 else
476 bcmerror = dhd_prot_iovar_op(dhd_pub, buf,
477 NULL, 0, arg,
478 arglen, IOV_SET);
479 if (bcmerror != BCME_UNSUPPORTED)
480 break;
481
482 /* if still not found, try bus module */
483 if (ioc->cmd == DHD_GET_VAR)
484 bcmerror = dhd_bus_iovar_op(dhd_pub, buf,
485 arg, arglen, buf,
486 buflen, IOV_GET);
487 else
488 bcmerror = dhd_bus_iovar_op(dhd_pub, buf,
489 NULL, 0, arg,
490 arglen, IOV_SET);
491
492 break;
493 }
494
495 default:
496 bcmerror = BCME_UNSUPPORTED;
497 }
498
499 return bcmerror;
500 }
501
502 #ifdef SHOW_EVENTS
wl_show_host_event(wl_event_msg_t * event,void * event_data)503 static void wl_show_host_event(wl_event_msg_t *event, void *event_data)
504 {
505 uint i, status, reason;
506 bool group = false, flush_txq = false, link = false;
507 char *auth_str, *event_name;
508 unsigned char *buf;
509 char err_msg[256], eabuf[ETHER_ADDR_STR_LEN];
510 static struct {
511 uint event;
512 char *event_name;
513 } event_names[] = {
514 {
515 WLC_E_SET_SSID, "SET_SSID"}, {
516 WLC_E_JOIN, "JOIN"}, {
517 WLC_E_START, "START"}, {
518 WLC_E_AUTH, "AUTH"}, {
519 WLC_E_AUTH_IND, "AUTH_IND"}, {
520 WLC_E_DEAUTH, "DEAUTH"}, {
521 WLC_E_DEAUTH_IND, "DEAUTH_IND"}, {
522 WLC_E_ASSOC, "ASSOC"}, {
523 WLC_E_ASSOC_IND, "ASSOC_IND"}, {
524 WLC_E_REASSOC, "REASSOC"}, {
525 WLC_E_REASSOC_IND, "REASSOC_IND"}, {
526 WLC_E_DISASSOC, "DISASSOC"}, {
527 WLC_E_DISASSOC_IND, "DISASSOC_IND"}, {
528 WLC_E_QUIET_START, "START_QUIET"}, {
529 WLC_E_QUIET_END, "END_QUIET"}, {
530 WLC_E_BEACON_RX, "BEACON_RX"}, {
531 WLC_E_LINK, "LINK"}, {
532 WLC_E_MIC_ERROR, "MIC_ERROR"}, {
533 WLC_E_NDIS_LINK, "NDIS_LINK"}, {
534 WLC_E_ROAM, "ROAM"}, {
535 WLC_E_TXFAIL, "TXFAIL"}, {
536 WLC_E_PMKID_CACHE, "PMKID_CACHE"}, {
537 WLC_E_RETROGRADE_TSF, "RETROGRADE_TSF"}, {
538 WLC_E_PRUNE, "PRUNE"}, {
539 WLC_E_AUTOAUTH, "AUTOAUTH"}, {
540 WLC_E_EAPOL_MSG, "EAPOL_MSG"}, {
541 WLC_E_SCAN_COMPLETE, "SCAN_COMPLETE"}, {
542 WLC_E_ADDTS_IND, "ADDTS_IND"}, {
543 WLC_E_DELTS_IND, "DELTS_IND"}, {
544 WLC_E_BCNSENT_IND, "BCNSENT_IND"}, {
545 WLC_E_BCNRX_MSG, "BCNRX_MSG"}, {
546 WLC_E_BCNLOST_MSG, "BCNLOST_MSG"}, {
547 WLC_E_ROAM_PREP, "ROAM_PREP"}, {
548 WLC_E_PFN_NET_FOUND, "PNO_NET_FOUND"}, {
549 WLC_E_PFN_NET_LOST, "PNO_NET_LOST"}, {
550 WLC_E_RESET_COMPLETE, "RESET_COMPLETE"}, {
551 WLC_E_JOIN_START, "JOIN_START"}, {
552 WLC_E_ROAM_START, "ROAM_START"}, {
553 WLC_E_ASSOC_START, "ASSOC_START"}, {
554 WLC_E_IBSS_ASSOC, "IBSS_ASSOC"}, {
555 WLC_E_RADIO, "RADIO"}, {
556 WLC_E_PSM_WATCHDOG, "PSM_WATCHDOG"}, {
557 WLC_E_PROBREQ_MSG, "PROBREQ_MSG"}, {
558 WLC_E_SCAN_CONFIRM_IND, "SCAN_CONFIRM_IND"}, {
559 WLC_E_PSK_SUP, "PSK_SUP"}, {
560 WLC_E_COUNTRY_CODE_CHANGED, "COUNTRY_CODE_CHANGED"}, {
561 WLC_E_EXCEEDED_MEDIUM_TIME, "EXCEEDED_MEDIUM_TIME"}, {
562 WLC_E_ICV_ERROR, "ICV_ERROR"}, {
563 WLC_E_UNICAST_DECODE_ERROR, "UNICAST_DECODE_ERROR"}, {
564 WLC_E_MULTICAST_DECODE_ERROR, "MULTICAST_DECODE_ERROR"}, {
565 WLC_E_TRACE, "TRACE"}, {
566 WLC_E_ACTION_FRAME, "ACTION FRAME"}, {
567 WLC_E_ACTION_FRAME_COMPLETE, "ACTION FRAME TX COMPLETE"}, {
568 WLC_E_IF, "IF"}, {
569 WLC_E_RSSI, "RSSI"}, {
570 WLC_E_PFN_SCAN_COMPLETE, "SCAN_COMPLETE"}
571 };
572 uint event_type, flags, auth_type, datalen;
573 event_type = be32_to_cpu(event->event_type);
574 flags = be16_to_cpu(event->flags);
575 status = be32_to_cpu(event->status);
576 reason = be32_to_cpu(event->reason);
577 auth_type = be32_to_cpu(event->auth_type);
578 datalen = be32_to_cpu(event->datalen);
579 /* debug dump of event messages */
580 sprintf(eabuf, "%pM", event->addr);
581
582 event_name = "UNKNOWN";
583 for (i = 0; i < ARRAY_SIZE(event_names); i++) {
584 if (event_names[i].event == event_type)
585 event_name = event_names[i].event_name;
586 }
587
588 DHD_EVENT(("EVENT: %s, event ID = %d\n", event_name, event_type));
589
590 if (flags & WLC_EVENT_MSG_LINK)
591 link = true;
592 if (flags & WLC_EVENT_MSG_GROUP)
593 group = true;
594 if (flags & WLC_EVENT_MSG_FLUSHTXQ)
595 flush_txq = true;
596
597 switch (event_type) {
598 case WLC_E_START:
599 case WLC_E_DEAUTH:
600 case WLC_E_DISASSOC:
601 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
602 break;
603
604 case WLC_E_ASSOC_IND:
605 case WLC_E_REASSOC_IND:
606 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
607 break;
608
609 case WLC_E_ASSOC:
610 case WLC_E_REASSOC:
611 if (status == WLC_E_STATUS_SUCCESS) {
612 DHD_EVENT(("MACEVENT: %s, MAC %s, SUCCESS\n",
613 event_name, eabuf));
614 } else if (status == WLC_E_STATUS_TIMEOUT) {
615 DHD_EVENT(("MACEVENT: %s, MAC %s, TIMEOUT\n",
616 event_name, eabuf));
617 } else if (status == WLC_E_STATUS_FAIL) {
618 DHD_EVENT(("MACEVENT: %s, MAC %s, FAILURE, reason %d\n",
619 event_name, eabuf, (int)reason));
620 } else {
621 DHD_EVENT(("MACEVENT: %s, MAC %s, unexpected status "
622 "%d\n", event_name, eabuf, (int)status));
623 }
624 break;
625
626 case WLC_E_DEAUTH_IND:
627 case WLC_E_DISASSOC_IND:
628 DHD_EVENT(("MACEVENT: %s, MAC %s, reason %d\n", event_name,
629 eabuf, (int)reason));
630 break;
631
632 case WLC_E_AUTH:
633 case WLC_E_AUTH_IND:
634 if (auth_type == WLAN_AUTH_OPEN)
635 auth_str = "Open System";
636 else if (auth_type == WLAN_AUTH_SHARED_KEY)
637 auth_str = "Shared Key";
638 else {
639 sprintf(err_msg, "AUTH unknown: %d", (int)auth_type);
640 auth_str = err_msg;
641 }
642 if (event_type == WLC_E_AUTH_IND) {
643 DHD_EVENT(("MACEVENT: %s, MAC %s, %s\n", event_name,
644 eabuf, auth_str));
645 } else if (status == WLC_E_STATUS_SUCCESS) {
646 DHD_EVENT(("MACEVENT: %s, MAC %s, %s, SUCCESS\n",
647 event_name, eabuf, auth_str));
648 } else if (status == WLC_E_STATUS_TIMEOUT) {
649 DHD_EVENT(("MACEVENT: %s, MAC %s, %s, TIMEOUT\n",
650 event_name, eabuf, auth_str));
651 } else if (status == WLC_E_STATUS_FAIL) {
652 DHD_EVENT(("MACEVENT: %s, MAC %s, %s, FAILURE, "
653 "reason %d\n",
654 event_name, eabuf, auth_str, (int)reason));
655 }
656
657 break;
658
659 case WLC_E_JOIN:
660 case WLC_E_ROAM:
661 case WLC_E_SET_SSID:
662 if (status == WLC_E_STATUS_SUCCESS) {
663 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name,
664 eabuf));
665 } else if (status == WLC_E_STATUS_FAIL) {
666 DHD_EVENT(("MACEVENT: %s, failed\n", event_name));
667 } else if (status == WLC_E_STATUS_NO_NETWORKS) {
668 DHD_EVENT(("MACEVENT: %s, no networks found\n",
669 event_name));
670 } else {
671 DHD_EVENT(("MACEVENT: %s, unexpected status %d\n",
672 event_name, (int)status));
673 }
674 break;
675
676 case WLC_E_BEACON_RX:
677 if (status == WLC_E_STATUS_SUCCESS) {
678 DHD_EVENT(("MACEVENT: %s, SUCCESS\n", event_name));
679 } else if (status == WLC_E_STATUS_FAIL) {
680 DHD_EVENT(("MACEVENT: %s, FAIL\n", event_name));
681 } else {
682 DHD_EVENT(("MACEVENT: %s, status %d\n", event_name,
683 status));
684 }
685 break;
686
687 case WLC_E_LINK:
688 DHD_EVENT(("MACEVENT: %s %s\n", event_name,
689 link ? "UP" : "DOWN"));
690 break;
691
692 case WLC_E_MIC_ERROR:
693 DHD_EVENT(("MACEVENT: %s, MAC %s, Group %d, Flush %d\n",
694 event_name, eabuf, group, flush_txq));
695 break;
696
697 case WLC_E_ICV_ERROR:
698 case WLC_E_UNICAST_DECODE_ERROR:
699 case WLC_E_MULTICAST_DECODE_ERROR:
700 DHD_EVENT(("MACEVENT: %s, MAC %s\n", event_name, eabuf));
701 break;
702
703 case WLC_E_TXFAIL:
704 DHD_EVENT(("MACEVENT: %s, RA %s\n", event_name, eabuf));
705 break;
706
707 case WLC_E_SCAN_COMPLETE:
708 case WLC_E_PMKID_CACHE:
709 DHD_EVENT(("MACEVENT: %s\n", event_name));
710 break;
711
712 case WLC_E_PFN_NET_FOUND:
713 case WLC_E_PFN_NET_LOST:
714 case WLC_E_PFN_SCAN_COMPLETE:
715 DHD_EVENT(("PNOEVENT: %s\n", event_name));
716 break;
717
718 case WLC_E_PSK_SUP:
719 case WLC_E_PRUNE:
720 DHD_EVENT(("MACEVENT: %s, status %d, reason %d\n",
721 event_name, (int)status, (int)reason));
722 break;
723
724 case WLC_E_TRACE:
725 {
726 static u32 seqnum_prev;
727 msgtrace_hdr_t hdr;
728 u32 nblost;
729 char *s, *p;
730
731 buf = (unsigned char *) event_data;
732 memcpy(&hdr, buf, MSGTRACE_HDRLEN);
733
734 if (hdr.version != MSGTRACE_VERSION) {
735 DHD_ERROR(
736 ("\nMACEVENT: %s [unsupported version --> "
737 "dhd version:%d dongle version:%d]\n",
738 event_name, MSGTRACE_VERSION, hdr.version)
739 );
740 /* Reset datalen to avoid display below */
741 datalen = 0;
742 break;
743 }
744
745 /* There are 2 bytes available at the end of data */
746 buf[MSGTRACE_HDRLEN + be16_to_cpu(hdr.len)] = '\0';
747
748 if (be32_to_cpu(hdr.discarded_bytes)
749 || be32_to_cpu(hdr.discarded_printf)) {
750 DHD_ERROR(
751 ("\nWLC_E_TRACE: [Discarded traces in dongle -->"
752 "discarded_bytes %d discarded_printf %d]\n",
753 be32_to_cpu(hdr.discarded_bytes),
754 be32_to_cpu(hdr.discarded_printf)));
755 }
756
757 nblost = be32_to_cpu(hdr.seqnum) - seqnum_prev - 1;
758 if (nblost > 0) {
759 DHD_ERROR(
760 ("\nWLC_E_TRACE: [Event lost --> seqnum %d nblost %d\n",
761 be32_to_cpu(hdr.seqnum), nblost));
762 }
763 seqnum_prev = be32_to_cpu(hdr.seqnum);
764
765 /* Display the trace buffer. Advance from \n to \n to
766 * avoid display big
767 * printf (issue with Linux printk )
768 */
769 p = (char *)&buf[MSGTRACE_HDRLEN];
770 while ((s = strstr(p, "\n")) != NULL) {
771 *s = '\0';
772 printk(KERN_DEBUG"%s\n", p);
773 p = s + 1;
774 }
775 printk(KERN_DEBUG "%s\n", p);
776
777 /* Reset datalen to avoid display below */
778 datalen = 0;
779 }
780 break;
781
782 case WLC_E_RSSI:
783 DHD_EVENT(("MACEVENT: %s %d\n", event_name,
784 be32_to_cpu(*((int *)event_data))));
785 break;
786
787 default:
788 DHD_EVENT(("MACEVENT: %s %d, MAC %s, status %d, reason %d, "
789 "auth %d\n", event_name, event_type, eabuf,
790 (int)status, (int)reason, (int)auth_type));
791 break;
792 }
793
794 /* show any appended data */
795 if (datalen) {
796 buf = (unsigned char *) event_data;
797 DHD_EVENT((" data (%d) : ", datalen));
798 for (i = 0; i < datalen; i++)
799 DHD_EVENT((" 0x%02x ", *buf++));
800 DHD_EVENT(("\n"));
801 }
802 }
803 #endif /* SHOW_EVENTS */
804
805 int
wl_host_event(struct dhd_info * dhd,int * ifidx,void * pktdata,wl_event_msg_t * event,void ** data_ptr)806 wl_host_event(struct dhd_info *dhd, int *ifidx, void *pktdata,
807 wl_event_msg_t *event, void **data_ptr)
808 {
809 /* check whether packet is a BRCM event pkt */
810 bcm_event_t *pvt_data = (bcm_event_t *) pktdata;
811 char *event_data;
812 u32 type, status;
813 u16 flags;
814 int evlen;
815
816 if (memcmp(BRCM_OUI, &pvt_data->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
817 DHD_ERROR(("%s: mismatched OUI, bailing\n", __func__));
818 return BCME_ERROR;
819 }
820
821 /* BRCM event pkt may be unaligned - use xxx_ua to load user_subtype. */
822 if (get_unaligned_be16(&pvt_data->bcm_hdr.usr_subtype) !=
823 BCMILCP_BCM_SUBTYPE_EVENT) {
824 DHD_ERROR(("%s: mismatched subtype, bailing\n", __func__));
825 return BCME_ERROR;
826 }
827
828 *data_ptr = &pvt_data[1];
829 event_data = *data_ptr;
830
831 /* memcpy since BRCM event pkt may be unaligned. */
832 memcpy(event, &pvt_data->event, sizeof(wl_event_msg_t));
833
834 type = get_unaligned_be32(&event->event_type);
835 flags = get_unaligned_be16(&event->flags);
836 status = get_unaligned_be32(&event->status);
837 evlen = get_unaligned_be32(&event->datalen) + sizeof(bcm_event_t);
838
839 switch (type) {
840 case WLC_E_IF:
841 {
842 dhd_if_event_t *ifevent = (dhd_if_event_t *) event_data;
843 DHD_TRACE(("%s: if event\n", __func__));
844
845 if (ifevent->ifidx > 0 &&
846 ifevent->ifidx < DHD_MAX_IFS) {
847 if (ifevent->action == WLC_E_IF_ADD)
848 dhd_add_if(dhd, ifevent->ifidx,
849 NULL, event->ifname,
850 pvt_data->eth.h_dest,
851 ifevent->flags,
852 ifevent->bssidx);
853 else
854 dhd_del_if(dhd, ifevent->ifidx);
855 } else {
856 DHD_ERROR(("%s: Invalid ifidx %d for %s\n",
857 __func__, ifevent->ifidx,
858 event->ifname));
859 }
860 }
861 /* send up the if event: btamp user needs it */
862 *ifidx = dhd_ifname2idx(dhd, event->ifname);
863 /* push up to external supp/auth */
864 dhd_event(dhd, (char *)pvt_data, evlen, *ifidx);
865 break;
866
867 #ifdef P2P
868 case WLC_E_NDIS_LINK:
869 break;
870 #endif
871 /* fall through */
872 /* These are what external supplicant/authenticator wants */
873 case WLC_E_LINK:
874 case WLC_E_ASSOC_IND:
875 case WLC_E_REASSOC_IND:
876 case WLC_E_DISASSOC_IND:
877 case WLC_E_MIC_ERROR:
878 default:
879 /* Fall through: this should get _everything_ */
880
881 *ifidx = dhd_ifname2idx(dhd, event->ifname);
882 /* push up to external supp/auth */
883 dhd_event(dhd, (char *)pvt_data, evlen, *ifidx);
884 DHD_TRACE(("%s: MAC event %d, flags %x, status %x\n",
885 __func__, type, flags, status));
886
887 /* put it back to WLC_E_NDIS_LINK */
888 if (type == WLC_E_NDIS_LINK) {
889 u32 temp;
890
891 temp = get_unaligned_be32(&event->event_type);
892 DHD_TRACE(("Converted to WLC_E_LINK type %d\n", temp));
893
894 temp = be32_to_cpu(WLC_E_NDIS_LINK);
895 memcpy((void *)(&pvt_data->event.event_type), &temp,
896 sizeof(pvt_data->event.event_type));
897 }
898 break;
899 }
900
901 #ifdef SHOW_EVENTS
902 wl_show_host_event(event, event_data);
903 #endif /* SHOW_EVENTS */
904
905 return BCME_OK;
906 }
907
908 /* Convert user's input in hex pattern to byte-size mask */
wl_pattern_atoh(char * src,char * dst)909 static int wl_pattern_atoh(char *src, char *dst)
910 {
911 int i;
912 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
913 DHD_ERROR(("Mask invalid format. Needs to start with 0x\n"));
914 return -1;
915 }
916 src = src + 2; /* Skip past 0x */
917 if (strlen(src) % 2 != 0) {
918 DHD_ERROR(("Mask invalid format. Length must be even.\n"));
919 return -1;
920 }
921 for (i = 0; *src != '\0'; i++) {
922 char num[3];
923 strncpy(num, src, 2);
924 num[2] = '\0';
925 dst[i] = (u8) simple_strtoul(num, NULL, 16);
926 src += 2;
927 }
928 return i;
929 }
930
931 void
dhd_pktfilter_offload_enable(dhd_pub_t * dhd,char * arg,int enable,int master_mode)932 dhd_pktfilter_offload_enable(dhd_pub_t *dhd, char *arg, int enable,
933 int master_mode)
934 {
935 char *argv[8];
936 int i = 0;
937 const char *str;
938 int buf_len;
939 int str_len;
940 char *arg_save = 0, *arg_org = 0;
941 int rc;
942 char buf[128];
943 wl_pkt_filter_enable_t enable_parm;
944 wl_pkt_filter_enable_t *pkt_filterp;
945
946 arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
947 if (!arg_save) {
948 DHD_ERROR(("%s: kmalloc failed\n", __func__));
949 goto fail;
950 }
951 arg_org = arg_save;
952 memcpy(arg_save, arg, strlen(arg) + 1);
953
954 argv[i] = strsep(&arg_save, " ");
955
956 i = 0;
957 if (NULL == argv[i]) {
958 DHD_ERROR(("No args provided\n"));
959 goto fail;
960 }
961
962 str = "pkt_filter_enable";
963 str_len = strlen(str);
964 strncpy(buf, str, str_len);
965 buf[str_len] = '\0';
966 buf_len = str_len + 1;
967
968 pkt_filterp = (wl_pkt_filter_enable_t *) (buf + str_len + 1);
969
970 /* Parse packet filter id. */
971 enable_parm.id = simple_strtoul(argv[i], NULL, 0);
972
973 /* Parse enable/disable value. */
974 enable_parm.enable = enable;
975
976 buf_len += sizeof(enable_parm);
977 memcpy((char *)pkt_filterp, &enable_parm, sizeof(enable_parm));
978
979 /* Enable/disable the specified filter. */
980 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len);
981 rc = rc >= 0 ? 0 : rc;
982 if (rc)
983 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
984 __func__, arg, rc));
985 else
986 DHD_TRACE(("%s: successfully added pktfilter %s\n",
987 __func__, arg));
988
989 /* Contorl the master mode */
990 bcm_mkiovar("pkt_filter_mode", (char *)&master_mode, 4, buf,
991 sizeof(buf));
992 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf));
993 rc = rc >= 0 ? 0 : rc;
994 if (rc)
995 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
996 __func__, arg, rc));
997
998 fail:
999 kfree(arg_org);
1000 }
1001
dhd_pktfilter_offload_set(dhd_pub_t * dhd,char * arg)1002 void dhd_pktfilter_offload_set(dhd_pub_t *dhd, char *arg)
1003 {
1004 const char *str;
1005 wl_pkt_filter_t pkt_filter;
1006 wl_pkt_filter_t *pkt_filterp;
1007 int buf_len;
1008 int str_len;
1009 int rc;
1010 u32 mask_size;
1011 u32 pattern_size;
1012 char *argv[8], *buf = 0;
1013 int i = 0;
1014 char *arg_save = 0, *arg_org = 0;
1015 #define BUF_SIZE 2048
1016
1017 arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
1018 if (!arg_save) {
1019 DHD_ERROR(("%s: kmalloc failed\n", __func__));
1020 goto fail;
1021 }
1022
1023 arg_org = arg_save;
1024
1025 buf = kmalloc(BUF_SIZE, GFP_ATOMIC);
1026 if (!buf) {
1027 DHD_ERROR(("%s: kmalloc failed\n", __func__));
1028 goto fail;
1029 }
1030
1031 memcpy(arg_save, arg, strlen(arg) + 1);
1032
1033 if (strlen(arg) > BUF_SIZE) {
1034 DHD_ERROR(("Not enough buffer %d < %d\n", (int)strlen(arg),
1035 (int)sizeof(buf)));
1036 goto fail;
1037 }
1038
1039 argv[i] = strsep(&arg_save, " ");
1040 while (argv[i++])
1041 argv[i] = strsep(&arg_save, " ");
1042
1043 i = 0;
1044 if (NULL == argv[i]) {
1045 DHD_ERROR(("No args provided\n"));
1046 goto fail;
1047 }
1048
1049 str = "pkt_filter_add";
1050 str_len = strlen(str);
1051 strncpy(buf, str, str_len);
1052 buf[str_len] = '\0';
1053 buf_len = str_len + 1;
1054
1055 pkt_filterp = (wl_pkt_filter_t *) (buf + str_len + 1);
1056
1057 /* Parse packet filter id. */
1058 pkt_filter.id = simple_strtoul(argv[i], NULL, 0);
1059
1060 if (NULL == argv[++i]) {
1061 DHD_ERROR(("Polarity not provided\n"));
1062 goto fail;
1063 }
1064
1065 /* Parse filter polarity. */
1066 pkt_filter.negate_match = simple_strtoul(argv[i], NULL, 0);
1067
1068 if (NULL == argv[++i]) {
1069 DHD_ERROR(("Filter type not provided\n"));
1070 goto fail;
1071 }
1072
1073 /* Parse filter type. */
1074 pkt_filter.type = simple_strtoul(argv[i], NULL, 0);
1075
1076 if (NULL == argv[++i]) {
1077 DHD_ERROR(("Offset not provided\n"));
1078 goto fail;
1079 }
1080
1081 /* Parse pattern filter offset. */
1082 pkt_filter.u.pattern.offset = simple_strtoul(argv[i], NULL, 0);
1083
1084 if (NULL == argv[++i]) {
1085 DHD_ERROR(("Bitmask not provided\n"));
1086 goto fail;
1087 }
1088
1089 /* Parse pattern filter mask. */
1090 mask_size =
1091 wl_pattern_atoh
1092 (argv[i], (char *)pkt_filterp->u.pattern.mask_and_pattern);
1093
1094 if (NULL == argv[++i]) {
1095 DHD_ERROR(("Pattern not provided\n"));
1096 goto fail;
1097 }
1098
1099 /* Parse pattern filter pattern. */
1100 pattern_size =
1101 wl_pattern_atoh(argv[i],
1102 (char *)&pkt_filterp->u.pattern.
1103 mask_and_pattern[mask_size]);
1104
1105 if (mask_size != pattern_size) {
1106 DHD_ERROR(("Mask and pattern not the same size\n"));
1107 goto fail;
1108 }
1109
1110 pkt_filter.u.pattern.size_bytes = mask_size;
1111 buf_len += WL_PKT_FILTER_FIXED_LEN;
1112 buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
1113
1114 /* Keep-alive attributes are set in local
1115 * variable (keep_alive_pkt), and
1116 ** then memcpy'ed into buffer (keep_alive_pktp) since there is no
1117 ** guarantee that the buffer is properly aligned.
1118 */
1119 memcpy((char *)pkt_filterp,
1120 &pkt_filter,
1121 WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
1122
1123 rc = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len);
1124 rc = rc >= 0 ? 0 : rc;
1125
1126 if (rc)
1127 DHD_TRACE(("%s: failed to add pktfilter %s, retcode = %d\n",
1128 __func__, arg, rc));
1129 else
1130 DHD_TRACE(("%s: successfully added pktfilter %s\n",
1131 __func__, arg));
1132
1133 fail:
1134 kfree(arg_org);
1135
1136 kfree(buf);
1137 }
1138
dhd_arp_offload_set(dhd_pub_t * dhd,int arp_mode)1139 void dhd_arp_offload_set(dhd_pub_t *dhd, int arp_mode)
1140 {
1141 char iovbuf[32];
1142 int retcode;
1143
1144 bcm_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf));
1145 retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1146 retcode = retcode >= 0 ? 0 : retcode;
1147 if (retcode)
1148 DHD_TRACE(("%s: failed to set ARP offload mode to 0x%x, "
1149 "retcode = %d\n", __func__, arp_mode, retcode));
1150 else
1151 DHD_TRACE(("%s: successfully set ARP offload mode to 0x%x\n",
1152 __func__, arp_mode));
1153 }
1154
dhd_arp_offload_enable(dhd_pub_t * dhd,int arp_enable)1155 void dhd_arp_offload_enable(dhd_pub_t *dhd, int arp_enable)
1156 {
1157 char iovbuf[32];
1158 int retcode;
1159
1160 bcm_mkiovar("arpoe", (char *)&arp_enable, 4, iovbuf, sizeof(iovbuf));
1161 retcode = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1162 retcode = retcode >= 0 ? 0 : retcode;
1163 if (retcode)
1164 DHD_TRACE(("%s: failed to enabe ARP offload to %d, "
1165 "retcode = %d\n", __func__, arp_enable, retcode));
1166 else
1167 DHD_TRACE(("%s: successfully enabed ARP offload to %d\n",
1168 __func__, arp_enable));
1169 }
1170
dhd_preinit_ioctls(dhd_pub_t * dhd)1171 int dhd_preinit_ioctls(dhd_pub_t *dhd)
1172 {
1173 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for
1174 "event_msgs" + '\0' + bitvec */
1175 uint up = 0;
1176 char buf[128], *ptr;
1177 uint power_mode = PM_FAST;
1178 u32 dongle_align = DHD_SDALIGN;
1179 u32 glom = 0;
1180 uint bcn_timeout = 3;
1181 int scan_assoc_time = 40;
1182 int scan_unassoc_time = 40;
1183 #ifdef GET_CUSTOM_MAC_ENABLE
1184 int ret = 0;
1185 u8 ea_addr[ETH_ALEN];
1186 #endif /* GET_CUSTOM_MAC_ENABLE */
1187
1188 dhd_os_proto_block(dhd);
1189
1190 #ifdef GET_CUSTOM_MAC_ENABLE
1191 /* Read MAC address from external customer place
1192 ** NOTE that default mac address has to be present in
1193 ** otp or nvram file to bring up
1194 ** firmware but unique per board mac address maybe provided by
1195 ** customer code
1196 */
1197 ret = dhd_custom_get_mac_address(ea_addr);
1198 if (!ret) {
1199 bcm_mkiovar("cur_etheraddr", (void *)ea_addr, ETH_ALEN,
1200 buf, sizeof(buf));
1201 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, sizeof(buf));
1202 if (ret < 0) {
1203 DHD_ERROR(("%s: can't set MAC address , error=%d\n",
1204 __func__, ret));
1205 } else
1206 memcpy(dhd->mac.octet, (void *)&ea_addr,
1207 ETH_ALEN);
1208 }
1209 #endif /* GET_CUSTOM_MAC_ENABLE */
1210
1211 /* Set Country code */
1212 if (dhd->country_code[0] != 0) {
1213 if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_COUNTRY,
1214 dhd->country_code,
1215 sizeof(dhd->country_code)) < 0) {
1216 DHD_ERROR(("%s: country code setting failed\n",
1217 __func__));
1218 }
1219 }
1220
1221 /* query for 'ver' to get version info from firmware */
1222 memset(buf, 0, sizeof(buf));
1223 ptr = buf;
1224 bcm_mkiovar("ver", 0, 0, buf, sizeof(buf));
1225 dhdcdc_query_ioctl(dhd, 0, WLC_GET_VAR, buf, sizeof(buf));
1226 strsep(&ptr, "\n");
1227 /* Print fw version info */
1228 DHD_ERROR(("Firmware version = %s\n", buf));
1229
1230 /* Set PowerSave mode */
1231 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode,
1232 sizeof(power_mode));
1233
1234 /* Match Host and Dongle rx alignment */
1235 bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
1236 sizeof(iovbuf));
1237 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1238
1239 /* disable glom option per default */
1240 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
1241 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1242
1243 /* Setup timeout if Beacons are lost and roam is off to report
1244 link down */
1245 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf,
1246 sizeof(iovbuf));
1247 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1248
1249 /* Enable/Disable build-in roaming to allowed ext supplicant to take
1250 of romaing */
1251 bcm_mkiovar("roam_off", (char *)&dhd_roam, 4, iovbuf, sizeof(iovbuf));
1252 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1253
1254 /* Force STA UP */
1255 if (dhd_radio_up)
1256 dhdcdc_set_ioctl(dhd, 0, WLC_UP, (char *)&up, sizeof(up));
1257
1258 /* Setup event_msgs */
1259 bcm_mkiovar("event_msgs", dhd->eventmask, WL_EVENTING_MASK_LEN, iovbuf,
1260 sizeof(iovbuf));
1261 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1262
1263 dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_CHANNEL_TIME,
1264 (char *)&scan_assoc_time, sizeof(scan_assoc_time));
1265 dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_UNASSOC_TIME,
1266 (char *)&scan_unassoc_time, sizeof(scan_unassoc_time));
1267
1268 #ifdef ARP_OFFLOAD_SUPPORT
1269 /* Set and enable ARP offload feature */
1270 if (dhd_arp_enable)
1271 dhd_arp_offload_set(dhd, dhd_arp_mode);
1272 dhd_arp_offload_enable(dhd, dhd_arp_enable);
1273 #endif /* ARP_OFFLOAD_SUPPORT */
1274
1275 #ifdef PKT_FILTER_SUPPORT
1276 {
1277 int i;
1278 /* Set up pkt filter */
1279 if (dhd_pkt_filter_enable) {
1280 for (i = 0; i < dhd->pktfilter_count; i++) {
1281 dhd_pktfilter_offload_set(dhd,
1282 dhd->pktfilter[i]);
1283 dhd_pktfilter_offload_enable(dhd,
1284 dhd->pktfilter[i],
1285 dhd_pkt_filter_init,
1286 dhd_master_mode);
1287 }
1288 }
1289 }
1290 #endif /* PKT_FILTER_SUPPORT */
1291
1292 dhd_os_proto_unblock(dhd);
1293
1294 return 0;
1295 }
1296
1297 #ifdef SIMPLE_ISCAN
1298 uint iscan_thread_id;
1299 iscan_buf_t *iscan_chain;
1300
dhd_iscan_allocate_buf(dhd_pub_t * dhd,iscan_buf_t ** iscanbuf)1301 iscan_buf_t *dhd_iscan_allocate_buf(dhd_pub_t *dhd, iscan_buf_t **iscanbuf)
1302 {
1303 iscan_buf_t *iscanbuf_alloc = 0;
1304 iscan_buf_t *iscanbuf_head;
1305
1306 dhd_iscan_lock();
1307
1308 iscanbuf_alloc = kmalloc(sizeof(iscan_buf_t), GFP_ATOMIC);
1309 if (iscanbuf_alloc == NULL)
1310 goto fail;
1311
1312 iscanbuf_alloc->next = NULL;
1313 iscanbuf_head = *iscanbuf;
1314
1315 DHD_ISCAN(("%s: addr of allocated node = 0x%X"
1316 "addr of iscanbuf_head = 0x%X dhd = 0x%X\n",
1317 __func__, iscanbuf_alloc, iscanbuf_head, dhd));
1318
1319 if (iscanbuf_head == NULL) {
1320 *iscanbuf = iscanbuf_alloc;
1321 DHD_ISCAN(("%s: Head is allocated\n", __func__));
1322 goto fail;
1323 }
1324
1325 while (iscanbuf_head->next)
1326 iscanbuf_head = iscanbuf_head->next;
1327
1328 iscanbuf_head->next = iscanbuf_alloc;
1329
1330 fail:
1331 dhd_iscan_unlock();
1332 return iscanbuf_alloc;
1333 }
1334
dhd_iscan_free_buf(void * dhdp,iscan_buf_t * iscan_delete)1335 void dhd_iscan_free_buf(void *dhdp, iscan_buf_t *iscan_delete)
1336 {
1337 iscan_buf_t *iscanbuf_free = 0;
1338 iscan_buf_t *iscanbuf_prv = 0;
1339 iscan_buf_t *iscanbuf_cur = iscan_chain;
1340 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1341
1342 dhd_iscan_lock();
1343 /* If iscan_delete is null then delete the entire
1344 * chain or else delete specific one provided
1345 */
1346 if (!iscan_delete) {
1347 while (iscanbuf_cur) {
1348 iscanbuf_free = iscanbuf_cur;
1349 iscanbuf_cur = iscanbuf_cur->next;
1350 iscanbuf_free->next = 0;
1351 kfree(iscanbuf_free);
1352 }
1353 iscan_chain = 0;
1354 } else {
1355 while (iscanbuf_cur) {
1356 if (iscanbuf_cur == iscan_delete)
1357 break;
1358 iscanbuf_prv = iscanbuf_cur;
1359 iscanbuf_cur = iscanbuf_cur->next;
1360 }
1361 if (iscanbuf_prv)
1362 iscanbuf_prv->next = iscan_delete->next;
1363
1364 iscan_delete->next = 0;
1365 kfree(iscan_delete);
1366
1367 if (!iscanbuf_prv)
1368 iscan_chain = 0;
1369 }
1370 dhd_iscan_unlock();
1371 }
1372
dhd_iscan_result_buf(void)1373 iscan_buf_t *dhd_iscan_result_buf(void)
1374 {
1375 return iscan_chain;
1376 }
1377
1378 /*
1379 * print scan cache
1380 * print partial iscan_skip list differently
1381 */
dhd_iscan_print_cache(iscan_buf_t * iscan_skip)1382 int dhd_iscan_print_cache(iscan_buf_t *iscan_skip)
1383 {
1384 int i = 0, l = 0;
1385 iscan_buf_t *iscan_cur;
1386 wl_iscan_results_t *list;
1387 wl_scan_results_t *results;
1388 wl_bss_info_t UNALIGNED *bi;
1389
1390 dhd_iscan_lock();
1391
1392 iscan_cur = dhd_iscan_result_buf();
1393
1394 while (iscan_cur) {
1395 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1396 if (!list)
1397 break;
1398
1399 results = (wl_scan_results_t *)&list->results;
1400 if (!results)
1401 break;
1402
1403 if (results->version != WL_BSS_INFO_VERSION) {
1404 DHD_ISCAN(("%s: results->version %d != "
1405 "WL_BSS_INFO_VERSION\n",
1406 __func__, results->version));
1407 goto done;
1408 }
1409
1410 bi = results->bss_info;
1411 for (i = 0; i < results->count; i++) {
1412 if (!bi)
1413 break;
1414
1415 DHD_ISCAN(("%s[%2.2d:%2.2d] %X:%X:%X:%X:%X:%X\n",
1416 iscan_cur != iscan_skip ? "BSS" : "bss", l,
1417 i, bi->BSSID.octet[0], bi->BSSID.octet[1],
1418 bi->BSSID.octet[2], bi->BSSID.octet[3],
1419 bi->BSSID.octet[4], bi->BSSID.octet[5]));
1420
1421 bi = (wl_bss_info_t *)((unsigned long)bi + bi->length);
1422 }
1423 iscan_cur = iscan_cur->next;
1424 l++;
1425 }
1426
1427 done:
1428 dhd_iscan_unlock();
1429 return 0;
1430 }
1431
1432 /*
1433 * delete disappeared AP from specific scan cache but skip partial
1434 * list in iscan_skip
1435 */
dhd_iscan_delete_bss(void * dhdp,void * addr,iscan_buf_t * iscan_skip)1436 int dhd_iscan_delete_bss(void *dhdp, void *addr, iscan_buf_t *iscan_skip)
1437 {
1438 int i = 0, j = 0, l = 0;
1439 iscan_buf_t *iscan_cur;
1440 wl_iscan_results_t *list;
1441 wl_scan_results_t *results;
1442 wl_bss_info_t UNALIGNED *bi, *bi_new, *bi_next;
1443
1444 unsigned char *s_addr = addr;
1445
1446 dhd_iscan_lock();
1447 DHD_ISCAN(("%s: BSS to remove %X:%X:%X:%X:%X:%X\n",
1448 __func__, s_addr[0], s_addr[1], s_addr[2],
1449 s_addr[3], s_addr[4], s_addr[5]));
1450
1451 iscan_cur = dhd_iscan_result_buf();
1452
1453 while (iscan_cur) {
1454 if (iscan_cur != iscan_skip) {
1455 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1456 if (!list)
1457 break;
1458
1459 results = (wl_scan_results_t *)&list->results;
1460 if (!results)
1461 break;
1462
1463 if (results->version != WL_BSS_INFO_VERSION) {
1464 DHD_ERROR(("%s: results->version %d != "
1465 "WL_BSS_INFO_VERSION\n",
1466 __func__, results->version));
1467 goto done;
1468 }
1469
1470 bi = results->bss_info;
1471 for (i = 0; i < results->count; i++) {
1472 if (!bi)
1473 break;
1474
1475 if (!memcmp
1476 (bi->BSSID.octet, addr, ETH_ALEN)) {
1477 DHD_ISCAN(("%s: Del BSS[%2.2d:%2.2d] "
1478 "%X:%X:%X:%X:%X:%X\n",
1479 __func__, l, i, bi->BSSID.octet[0],
1480 bi->BSSID.octet[1], bi->BSSID.octet[2],
1481 bi->BSSID.octet[3], bi->BSSID.octet[4],
1482 bi->BSSID.octet[5]));
1483
1484 bi_new = bi;
1485 bi = (wl_bss_info_t *)((unsigned long)
1486 bi + bi->length);
1487 /*
1488 if(bi && bi_new) {
1489 memcpy(bi_new, bi, results->buflen -
1490 bi_new->length);
1491 results->buflen -= bi_new->length;
1492 }
1493 */
1494 results->buflen -= bi_new->length;
1495 results->count--;
1496
1497 for (j = i; j < results->count; j++) {
1498 if (bi && bi_new) {
1499 DHD_ISCAN(("%s: Moved up BSS[%2.2d:%2.2d]" "%X:%X:%X:%X:%X:%X\n",
1500 __func__, l, j,
1501 bi->BSSID.octet[0],
1502 bi->BSSID.octet[1],
1503 bi->BSSID.octet[2],
1504 bi->BSSID.octet[3],
1505 bi->BSSID.octet[4],
1506 bi->BSSID.octet[5]));
1507
1508 bi_next =
1509 (wl_bss_info_t *)((unsigned long)bi +
1510 bi->length);
1511 memcpy(bi_new, bi,
1512 bi->length);
1513 bi_new =
1514 (wl_bss_info_t *)((unsigned long)bi_new +
1515 bi_new->
1516 length);
1517 bi = bi_next;
1518 }
1519 }
1520
1521 if (results->count == 0) {
1522 /* Prune now empty partial
1523 scan list */
1524 dhd_iscan_free_buf(dhdp,
1525 iscan_cur);
1526 goto done;
1527 }
1528 break;
1529 }
1530 bi = (wl_bss_info_t *)((unsigned long)bi +
1531 bi->length);
1532 }
1533 }
1534 iscan_cur = iscan_cur->next;
1535 l++;
1536 }
1537
1538 done:
1539 dhd_iscan_unlock();
1540 return 0;
1541 }
1542
dhd_iscan_remove_duplicates(void * dhdp,iscan_buf_t * iscan_cur)1543 int dhd_iscan_remove_duplicates(void *dhdp, iscan_buf_t *iscan_cur)
1544 {
1545 int i = 0;
1546 wl_iscan_results_t *list;
1547 wl_scan_results_t *results;
1548 wl_bss_info_t UNALIGNED *bi, *bi_new, *bi_next;
1549
1550 dhd_iscan_lock();
1551
1552 DHD_ISCAN(("%s: Scan cache before delete\n", __func__));
1553 dhd_iscan_print_cache(iscan_cur);
1554
1555 if (!iscan_cur)
1556 goto done;
1557
1558 list = (wl_iscan_results_t *)iscan_cur->iscan_buf;
1559 if (!list)
1560 goto done;
1561
1562 results = (wl_scan_results_t *)&list->results;
1563 if (!results)
1564 goto done;
1565
1566 if (results->version != WL_BSS_INFO_VERSION) {
1567 DHD_ERROR(("%s: results->version %d != WL_BSS_INFO_VERSION\n",
1568 __func__, results->version));
1569 goto done;
1570 }
1571
1572 bi = results->bss_info;
1573 for (i = 0; i < results->count; i++) {
1574 if (!bi)
1575 break;
1576
1577 DHD_ISCAN(("%s: Find dups for BSS[%2.2d] %X:%X:%X:%X:%X:%X\n",
1578 __func__, i, bi->BSSID.octet[0],
1579 bi->BSSID.octet[1], bi->BSSID.octet[2],
1580 bi->BSSID.octet[3], bi->BSSID.octet[4],
1581 bi->BSSID.octet[5]));
1582
1583 dhd_iscan_delete_bss(dhdp, bi->BSSID.octet, iscan_cur);
1584
1585 bi = (wl_bss_info_t *)((unsigned long)bi + bi->length);
1586 }
1587
1588 done:
1589 DHD_ISCAN(("%s: Scan cache after delete\n", __func__));
1590 dhd_iscan_print_cache(iscan_cur);
1591 dhd_iscan_unlock();
1592 return 0;
1593 }
1594
dhd_iscan_ind_scan_confirm(void * dhdp,bool status)1595 void dhd_iscan_ind_scan_confirm(void *dhdp, bool status)
1596 {
1597
1598 dhd_ind_scan_confirm(dhdp, status);
1599 }
1600
dhd_iscan_request(void * dhdp,u16 action)1601 int dhd_iscan_request(void *dhdp, u16 action)
1602 {
1603 int rc;
1604 wl_iscan_params_t params;
1605 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1606 char buf[WLC_IOCTL_SMLEN];
1607
1608 memset(¶ms, 0, sizeof(wl_iscan_params_t));
1609 memcpy(¶ms.params.bssid, ðer_bcast, ETH_ALEN);
1610
1611 params.params.bss_type = DOT11_BSSTYPE_ANY;
1612 params.params.scan_type = DOT11_SCANTYPE_ACTIVE;
1613
1614 params.params.nprobes = -1;
1615 params.params.active_time = -1;
1616 params.params.passive_time = -1;
1617 params.params.home_time = -1;
1618 params.params.channel_num = 0;
1619
1620 params.version = ISCAN_REQ_VERSION;
1621 params.action = action;
1622 params.scan_duration = 0;
1623
1624 bcm_mkiovar("iscan", (char *)¶ms, sizeof(wl_iscan_params_t), buf,
1625 WLC_IOCTL_SMLEN);
1626 rc = dhd_wl_ioctl(dhdp, WLC_SET_VAR, buf, WLC_IOCTL_SMLEN);
1627
1628 return rc;
1629 }
1630
dhd_iscan_get_partial_result(void * dhdp,uint * scan_count)1631 static int dhd_iscan_get_partial_result(void *dhdp, uint *scan_count)
1632 {
1633 wl_iscan_results_t *list_buf;
1634 wl_iscan_results_t list;
1635 wl_scan_results_t *results;
1636 iscan_buf_t *iscan_cur;
1637 int status = -1;
1638 dhd_pub_t *dhd = dhd_bus_pub(dhdp);
1639 int rc;
1640
1641 iscan_cur = dhd_iscan_allocate_buf(dhd, &iscan_chain);
1642 if (!iscan_cur) {
1643 DHD_ERROR(("%s: Failed to allocate node\n", __func__));
1644 dhd_iscan_free_buf(dhdp, 0);
1645 dhd_iscan_request(dhdp, WL_SCAN_ACTION_ABORT);
1646 goto fail;
1647 }
1648
1649 dhd_iscan_lock();
1650
1651 memset(iscan_cur->iscan_buf, 0, WLC_IW_ISCAN_MAXLEN);
1652 list_buf = (wl_iscan_results_t *) iscan_cur->iscan_buf;
1653 results = &list_buf->results;
1654 results->buflen = WL_ISCAN_RESULTS_FIXED_SIZE;
1655 results->version = 0;
1656 results->count = 0;
1657
1658 memset(&list, 0, sizeof(list));
1659 list.results.buflen = WLC_IW_ISCAN_MAXLEN;
1660 bcm_mkiovar("iscanresults", (char *)&list, WL_ISCAN_RESULTS_FIXED_SIZE,
1661 iscan_cur->iscan_buf, WLC_IW_ISCAN_MAXLEN);
1662 rc = dhd_wl_ioctl(dhdp, WLC_GET_VAR, iscan_cur->iscan_buf,
1663 WLC_IW_ISCAN_MAXLEN);
1664
1665 results->buflen = results->buflen;
1666 results->version = results->version;
1667 *scan_count = results->count = results->count;
1668 status = list_buf->status;
1669
1670 dhd_iscan_unlock();
1671
1672 if (!(*scan_count))
1673 dhd_iscan_free_buf(dhdp, iscan_cur);
1674 else
1675 dhd_iscan_remove_duplicates(dhdp, iscan_cur);
1676
1677 fail:
1678 return status;
1679 }
1680 #endif /* SIMPLE_ISCAN */
1681
1682 #ifdef PNO_SUPPORT
dhd_pno_clean(dhd_pub_t * dhd)1683 int dhd_pno_clean(dhd_pub_t *dhd)
1684 {
1685 char iovbuf[128];
1686 int pfn_enabled = 0;
1687 int iov_len = 0;
1688 int ret;
1689
1690 /* Disable pfn */
1691 iov_len =
1692 bcm_mkiovar("pfn", (char *)&pfn_enabled, 4, iovbuf, sizeof(iovbuf));
1693 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1694 if (ret >= 0) {
1695 /* clear pfn */
1696 iov_len = bcm_mkiovar("pfnclear", 0, 0, iovbuf, sizeof(iovbuf));
1697 if (iov_len) {
1698 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1699 iov_len);
1700 if (ret < 0) {
1701 DHD_ERROR(("%s failed code %d\n", __func__,
1702 ret));
1703 }
1704 } else {
1705 ret = -1;
1706 DHD_ERROR(("%s failed code %d\n", __func__, iov_len));
1707 }
1708 } else
1709 DHD_ERROR(("%s failed code %d\n", __func__, ret));
1710
1711 return ret;
1712 }
1713
dhd_pno_enable(dhd_pub_t * dhd,int pfn_enabled)1714 int dhd_pno_enable(dhd_pub_t *dhd, int pfn_enabled)
1715 {
1716 char iovbuf[128];
1717 int ret = -1;
1718
1719 if ((!dhd) && ((pfn_enabled != 0) || (pfn_enabled != 1))) {
1720 DHD_ERROR(("%s error exit\n", __func__));
1721 return ret;
1722 }
1723
1724 /* Enable/disable PNO */
1725 ret = bcm_mkiovar("pfn", (char *)&pfn_enabled, 4, iovbuf,
1726 sizeof(iovbuf));
1727 if (ret > 0) {
1728 ret = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1729 sizeof(iovbuf));
1730 if (ret < 0) {
1731 DHD_ERROR(("%s failed for error=%d\n", __func__, ret));
1732 return ret;
1733 } else {
1734 dhd->pno_enable = pfn_enabled;
1735 DHD_TRACE(("%s set pno as %d\n", __func__,
1736 dhd->pno_enable));
1737 }
1738 } else
1739 DHD_ERROR(("%s failed err=%d\n", __func__, ret));
1740
1741 return ret;
1742 }
1743
1744 /* Function to execute combined scan */
1745 int
dhd_pno_set(dhd_pub_t * dhd,wlc_ssid_t * ssids_local,int nssid,unsigned char scan_fr)1746 dhd_pno_set(dhd_pub_t *dhd, wlc_ssid_t *ssids_local, int nssid, unsigned char scan_fr)
1747 {
1748 int err = -1;
1749 char iovbuf[128];
1750 int k, i;
1751 wl_pfn_param_t pfn_param;
1752 wl_pfn_t pfn_element;
1753
1754 DHD_TRACE(("%s nssid=%d nchan=%d\n", __func__, nssid, scan_fr));
1755
1756 if ((!dhd) && (!ssids_local)) {
1757 DHD_ERROR(("%s error exit\n", __func__));
1758 err = -1;
1759 }
1760
1761 /* Check for broadcast ssid */
1762 for (k = 0; k < nssid; k++) {
1763 if (!ssids_local[k].SSID_len) {
1764 DHD_ERROR(("%d: Broadcast SSID is ilegal for PNO "
1765 "setting\n", k));
1766 return err;
1767 }
1768 }
1769 /* #define PNO_DUMP 1 */
1770 #ifdef PNO_DUMP
1771 {
1772 int j;
1773 for (j = 0; j < nssid; j++) {
1774 DHD_ERROR(("%d: scan for %s size =%d\n", j,
1775 ssids_local[j].SSID,
1776 ssids_local[j].SSID_len));
1777 }
1778 }
1779 #endif /* PNO_DUMP */
1780
1781 /* clean up everything */
1782 err = dhd_pno_clean(dhd);
1783 if (err < 0) {
1784 DHD_ERROR(("%s failed error=%d\n", __func__, err));
1785 return err;
1786 }
1787 memset(&pfn_param, 0, sizeof(pfn_param));
1788 memset(&pfn_element, 0, sizeof(pfn_element));
1789
1790 /* set pfn parameters */
1791 pfn_param.version = PFN_VERSION;
1792 pfn_param.flags = (PFN_LIST_ORDER << SORT_CRITERIA_BIT);
1793
1794 /* set up pno scan fr */
1795 if (scan_fr != 0)
1796 pfn_param.scan_freq = scan_fr;
1797
1798 bcm_mkiovar("pfn_set", (char *)&pfn_param, sizeof(pfn_param), iovbuf,
1799 sizeof(iovbuf));
1800 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
1801
1802 /* set all pfn ssid */
1803 for (i = 0; i < nssid; i++) {
1804
1805 pfn_element.bss_type = DOT11_BSSTYPE_INFRASTRUCTURE;
1806 pfn_element.auth = WLAN_AUTH_OPEN;
1807 pfn_element.wpa_auth = WPA_AUTH_PFN_ANY;
1808 pfn_element.wsec = 0;
1809 pfn_element.infra = 1;
1810
1811 memcpy((char *)pfn_element.ssid.SSID, ssids_local[i].SSID,
1812 ssids_local[i].SSID_len);
1813 pfn_element.ssid.SSID_len = ssids_local[i].SSID_len;
1814
1815 err = bcm_mkiovar("pfn_add", (char *)&pfn_element,
1816 sizeof(pfn_element), iovbuf, sizeof(iovbuf));
1817 if (err > 0) {
1818 err = dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf,
1819 sizeof(iovbuf));
1820 if (err < 0) {
1821 DHD_ERROR(("%s failed for i=%d error=%d\n",
1822 __func__, i, err));
1823 return err;
1824 }
1825 } else
1826 DHD_ERROR(("%s failed err=%d\n", __func__, err));
1827 }
1828
1829 /* Enable PNO */
1830 /* dhd_pno_enable(dhd, 1); */
1831 return err;
1832 }
1833
dhd_pno_get_status(dhd_pub_t * dhd)1834 int dhd_pno_get_status(dhd_pub_t *dhd)
1835 {
1836 int ret = -1;
1837
1838 if (!dhd)
1839 return ret;
1840 else
1841 return dhd->pno_enable;
1842 }
1843
1844 #endif /* PNO_SUPPORT */
1845
1846 /* Androd ComboSCAN support */
1847