1 /*
2 * DHD Protocol Module for CDC and BDC.
3 *
4 * Copyright (C) 1999-2009, Broadcom Corporation
5 *
6 * Unless you and Broadcom execute a separate written software license
7 * agreement governing use of this software, this software is licensed to you
8 * under the terms of the GNU General Public License version 2 (the "GPL"),
9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10 * following added to such license:
11 *
12 * As a special exception, the copyright holders of this software give you
13 * permission to link this software with independent modules, and to copy and
14 * distribute the resulting executable under terms of your choice, provided that
15 * you also meet, for each linked independent module, the terms and conditions of
16 * the license of that module. An independent module is a module which is not
17 * derived from this software. The special exception does not apply to any
18 * modifications of the software.
19 *
20 * Notwithstanding the above, under no circumstances may you combine this
21 * software in any way with any other Broadcom software provided under a license
22 * other than the GPL, without Broadcom's express prior written consent.
23 *
24 * $Id: dhd_cdc.c,v 1.22.4.2.4.7.2.30 2009/10/28 21:38:04 Exp $
25 *
26 * BDC is like CDC, except it includes a header for data packets to convey
27 * packet priority over the bus, and flags (e.g. to indicate checksum status
28 * for dongle offload).
29 */
30
31 #include <typedefs.h>
32 #include <osl.h>
33
34 #include <bcmutils.h>
35 #include <bcmcdc.h>
36 #include <bcmendian.h>
37
38 #include <dngl_stats.h>
39 #include <dhd.h>
40 #include <dhd_proto.h>
41 #include <dhd_bus.h>
42 #include <dhd_dbg.h>
43
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 RETRIES 2 /* # of retries to retrieve matching ioctl response */
54 #define BUS_HEADER_LEN (16+DHD_SDALIGN) /* Must be atleast SDPCM_RESERVE
55 * defined in dhd_sdio.c (amount of header tha might be added)
56 * plus any space that might be needed for alignment padding.
57 */
58 #define ROUND_UP_MARGIN 2048 /* Biggest SDIO block size possible for
59 * round off at the end of buffer
60 */
61
62 typedef struct dhd_prot {
63 uint16 reqid;
64 uint8 pending;
65 uint32 lastcmd;
66 uint8 bus_header[BUS_HEADER_LEN];
67 cdc_ioctl_t msg;
68 unsigned char buf[WLC_IOCTL_MAXLEN + ROUND_UP_MARGIN];
69 } dhd_prot_t;
70
71 static int
dhdcdc_msg(dhd_pub_t * dhd)72 dhdcdc_msg(dhd_pub_t *dhd)
73 {
74 dhd_prot_t *prot = dhd->prot;
75 int len = ltoh32(prot->msg.len) + sizeof(cdc_ioctl_t);
76 int ret;
77
78 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
79
80 dhd_os_wake_lock(dhd);
81
82 /* NOTE : cdc->msg.len holds the desired length of the buffer to be
83 * returned. Only up to CDC_MAX_MSG_SIZE of this buffer area
84 * is actually sent to the dongle
85 */
86 if (len > CDC_MAX_MSG_SIZE)
87 len = CDC_MAX_MSG_SIZE;
88
89 /* Send request */
90 ret = dhd_bus_txctl(dhd->bus, (uchar*)&prot->msg, len);
91 dhd_os_wake_unlock(dhd);
92 return ret;
93 }
94
95 static int
dhdcdc_cmplt(dhd_pub_t * dhd,uint32 id,uint32 len)96 dhdcdc_cmplt(dhd_pub_t *dhd, uint32 id, uint32 len)
97 {
98 int ret;
99 dhd_prot_t *prot = dhd->prot;
100
101 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
102
103 do {
104 ret = dhd_bus_rxctl(dhd->bus, (uchar*)&prot->msg, len+sizeof(cdc_ioctl_t));
105 if (ret < 0)
106 break;
107 } while (CDC_IOC_ID(ltoh32(prot->msg.flags)) != id);
108
109 return ret;
110 }
111
112 int
dhdcdc_query_ioctl(dhd_pub_t * dhd,int ifidx,uint cmd,void * buf,uint len)113 dhdcdc_query_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len)
114 {
115 dhd_prot_t *prot = dhd->prot;
116 cdc_ioctl_t *msg = &prot->msg;
117 void *info;
118 int ret = 0, retries = 0;
119 uint32 id, flags = 0;
120
121 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
122 DHD_CTL(("%s: cmd %d len %d\n", __FUNCTION__, cmd, len));
123
124
125 /* Respond "bcmerror" and "bcmerrorstr" with local cache */
126 if (cmd == WLC_GET_VAR && buf)
127 {
128 if (!strcmp((char *)buf, "bcmerrorstr"))
129 {
130 strncpy((char *)buf, bcmerrorstr(dhd->dongle_error), BCME_STRLEN);
131 goto done;
132 }
133 else if (!strcmp((char *)buf, "bcmerror"))
134 {
135 *(int *)buf = dhd->dongle_error;
136 goto done;
137 }
138 }
139
140 memset(msg, 0, sizeof(cdc_ioctl_t));
141
142 msg->cmd = htol32(cmd);
143 msg->len = htol32(len);
144 flags = (++prot->reqid << CDCF_IOC_ID_SHIFT);
145 msg->flags = htol32(flags);
146 CDC_SET_IF_IDX(msg, ifidx);
147
148 if (buf)
149 memcpy(prot->buf, buf, len);
150
151 if ((ret = dhdcdc_msg(dhd)) < 0) {
152 DHD_ERROR(("dhdcdc_query_ioctl: dhdcdc_msg failed w/status %d\n", ret));
153 goto done;
154 }
155
156 retry:
157 /* wait for interrupt and get first fragment */
158 if ((ret = dhdcdc_cmplt(dhd, prot->reqid, len)) < 0)
159 goto done;
160
161 flags = ltoh32(msg->flags);
162 id = (flags & CDCF_IOC_ID_MASK) >> CDCF_IOC_ID_SHIFT;
163
164 if ((id < prot->reqid) && (++retries < RETRIES))
165 goto retry;
166 if (id != prot->reqid) {
167 DHD_ERROR(("%s: %s: unexpected request id %d (expected %d)\n",
168 dhd_ifname(dhd, ifidx), __FUNCTION__, id, prot->reqid));
169 ret = -EINVAL;
170 goto done;
171 }
172
173 /* Check info buffer */
174 info = (void*)&msg[1];
175
176 /* Copy info buffer */
177 if (buf)
178 {
179 if (ret < (int)len)
180 len = ret;
181 memcpy(buf, info, len);
182 }
183
184 /* Check the ERROR flag */
185 if (flags & CDCF_IOC_ERROR)
186 {
187 ret = ltoh32(msg->status);
188 /* Cache error from dongle */
189 dhd->dongle_error = ret;
190 }
191
192 done:
193 return ret;
194 }
195
196 static int
dhdcdc_set_ioctl(dhd_pub_t * dhd,int ifidx,uint cmd,void * buf,uint len)197 dhdcdc_set_ioctl(dhd_pub_t *dhd, int ifidx, uint cmd, void *buf, uint len)
198 {
199 dhd_prot_t *prot = dhd->prot;
200 cdc_ioctl_t *msg = &prot->msg;
201 int ret = 0;
202 uint32 flags, id;
203
204 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
205 DHD_CTL(("%s: cmd %d len %d\n", __FUNCTION__, cmd, len));
206
207 memset(msg, 0, sizeof(cdc_ioctl_t));
208
209 msg->cmd = htol32(cmd);
210 msg->len = htol32(len);
211 flags = (++prot->reqid << CDCF_IOC_ID_SHIFT) | CDCF_IOC_SET;
212 msg->flags |= htol32(flags);
213 CDC_SET_IF_IDX(msg, ifidx);
214
215 if (buf)
216 memcpy(prot->buf, buf, len);
217
218 if ((ret = dhdcdc_msg(dhd)) < 0)
219 goto done;
220
221 if ((ret = dhdcdc_cmplt(dhd, prot->reqid, len)) < 0)
222 goto done;
223
224 flags = ltoh32(msg->flags);
225 id = (flags & CDCF_IOC_ID_MASK) >> CDCF_IOC_ID_SHIFT;
226
227 if (id != prot->reqid) {
228 DHD_ERROR(("%s: %s: unexpected request id %d (expected %d)\n",
229 dhd_ifname(dhd, ifidx), __FUNCTION__, id, prot->reqid));
230 ret = -EINVAL;
231 goto done;
232 }
233
234 /* Check the ERROR flag */
235 if (flags & CDCF_IOC_ERROR)
236 {
237 ret = ltoh32(msg->status);
238 /* Cache error from dongle */
239 dhd->dongle_error = ret;
240 }
241
242 done:
243 return ret;
244 }
245
246 extern int dhd_bus_interface(struct dhd_bus *bus, uint arg, void* arg2);
247 int
dhd_prot_ioctl(dhd_pub_t * dhd,int ifidx,wl_ioctl_t * ioc,void * buf,int len)248 dhd_prot_ioctl(dhd_pub_t *dhd, int ifidx, wl_ioctl_t * ioc, void * buf, int len)
249 {
250 dhd_prot_t *prot = dhd->prot;
251 int ret = -1;
252
253 if (dhd->busstate == DHD_BUS_DOWN) {
254 DHD_ERROR(("%s : bus is down. we have nothing to do\n", __FUNCTION__));
255 return ret;
256 }
257 dhd_os_proto_block(dhd);
258
259 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
260
261 ASSERT(len <= WLC_IOCTL_MAXLEN);
262
263 if (len > WLC_IOCTL_MAXLEN)
264 goto done;
265
266 if (prot->pending == TRUE) {
267 DHD_TRACE(("CDC packet is pending!!!! cmd=0x%x (%lu) lastcmd=0x%x (%lu)\n",
268 ioc->cmd, (unsigned long)ioc->cmd, prot->lastcmd,
269 (unsigned long)prot->lastcmd));
270 if ((ioc->cmd == WLC_SET_VAR) || (ioc->cmd == WLC_GET_VAR)) {
271 DHD_TRACE(("iovar cmd=%s\n", (char*)buf));
272 }
273 goto done;
274 }
275
276 prot->pending = TRUE;
277 prot->lastcmd = ioc->cmd;
278 if (ioc->set)
279 ret = dhdcdc_set_ioctl(dhd, ifidx, ioc->cmd, buf, len);
280 else {
281 ret = dhdcdc_query_ioctl(dhd, ifidx, ioc->cmd, buf, len);
282 if (ret > 0)
283 ioc->used = ret - sizeof(cdc_ioctl_t);
284 }
285
286 /* Too many programs assume ioctl() returns 0 on success */
287 if (ret >= 0)
288 ret = 0;
289 else {
290 cdc_ioctl_t *msg = &prot->msg;
291 CDC_SET_IF_IDX(msg, ifidx);
292 ioc->needed = ltoh32(msg->len); /* len == needed when set/query fails from dongle */
293 }
294
295 /* Intercept the wme_dp ioctl here */
296 if ((!ret) && (ioc->cmd == WLC_SET_VAR) && (!strcmp(buf, "wme_dp"))) {
297 int slen, val = 0;
298
299 slen = strlen("wme_dp") + 1;
300 if (len >= (int)(slen + sizeof(int)))
301 bcopy(((char *)buf + slen), &val, sizeof(int));
302 dhd->wme_dp = (uint8) ltoh32(val);
303 }
304
305 prot->pending = FALSE;
306
307 done:
308 dhd_os_proto_unblock(dhd);
309
310 return ret;
311 }
312
313 int
dhd_prot_iovar_op(dhd_pub_t * dhdp,const char * name,void * params,int plen,void * arg,int len,bool set)314 dhd_prot_iovar_op(dhd_pub_t *dhdp, const char *name,
315 void *params, int plen, void *arg, int len, bool set)
316 {
317 return BCME_UNSUPPORTED;
318 }
319
320 void
dhd_prot_dump(dhd_pub_t * dhdp,struct bcmstrbuf * strbuf)321 dhd_prot_dump(dhd_pub_t *dhdp, struct bcmstrbuf *strbuf)
322 {
323 bcm_bprintf(strbuf, "Protocol CDC: reqid %d\n", dhdp->prot->reqid);
324 }
325
326 #ifdef APSTA_PINGTEST
327 extern struct ether_addr guest_eas[MAX_GUEST];
328 #endif
329
330 void
dhd_prot_hdrpush(dhd_pub_t * dhd,int ifidx,void * pktbuf)331 dhd_prot_hdrpush(dhd_pub_t *dhd, int ifidx, void *pktbuf)
332 {
333 #ifdef BDC
334 struct bdc_header *h;
335 #ifdef APSTA_PINGTEST
336 struct ether_header *eh;
337 int i;
338 #ifdef DHD_DEBUG
339 char eabuf1[ETHER_ADDR_STR_LEN];
340 char eabuf2[ETHER_ADDR_STR_LEN];
341 #endif /* DHD_DEBUG */
342 #endif /* APSTA_PINGTEST */
343 #endif /* BDC */
344
345 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
346
347 #ifdef BDC
348 /* Push BDC header used to convey priority for buses that don't */
349
350 #ifdef APSTA_PINGTEST
351 eh = (struct ether_header *)PKTDATA(dhd->osh, pktbuf);
352 #endif
353
354 PKTPUSH(dhd->osh, pktbuf, BDC_HEADER_LEN);
355
356 h = (struct bdc_header *)PKTDATA(dhd->osh, pktbuf);
357
358 h->flags = (BDC_PROTO_VER << BDC_FLAG_VER_SHIFT);
359 if (PKTSUMNEEDED(pktbuf))
360 h->flags |= BDC_FLAG_SUM_NEEDED;
361
362
363 h->priority = (PKTPRIO(pktbuf) & BDC_PRIORITY_MASK);
364 h->flags2 = 0;
365 #ifdef APSTA_PINGTEST
366 for (i = 0; i < MAX_GUEST; ++i) {
367 if (!ETHER_ISNULLADDR(eh->ether_dhost) &&
368 bcmp(eh->ether_dhost, guest_eas[i].octet, ETHER_ADDR_LEN) == 0) {
369 DHD_TRACE(("send on if 1; sa %s, da %s\n",
370 bcm_ether_ntoa((struct ether_addr *)(eh->ether_shost), eabuf1),
371 bcm_ether_ntoa((struct ether_addr *)(eh->ether_dhost), eabuf2)));
372 /* assume all guest STAs are on interface 1 */
373 h->flags2 = 1;
374 break;
375 }
376 }
377 #endif /* APSTA_PINGTEST */
378 h->rssi = 0;
379 #endif /* BDC */
380 BDC_SET_IF_IDX(h, ifidx);
381 }
382
383
384 bool
dhd_proto_fcinfo(dhd_pub_t * dhd,void * pktbuf,uint8 * fcbits)385 dhd_proto_fcinfo(dhd_pub_t *dhd, void *pktbuf, uint8 *fcbits)
386 {
387 #ifdef BDC
388 struct bdc_header *h;
389
390 if (PKTLEN(dhd->osh, pktbuf) < BDC_HEADER_LEN) {
391 DHD_ERROR(("%s: rx data too short (%d < %d)\n",
392 __FUNCTION__, PKTLEN(dhd->osh, pktbuf), BDC_HEADER_LEN));
393 return BCME_ERROR;
394 }
395
396 h = (struct bdc_header *)PKTDATA(dhd->osh, pktbuf);
397
398 *fcbits = h->priority >> BDC_PRIORITY_FC_SHIFT;
399 if ((h->flags2 & BDC_FLAG2_FC_FLAG) == BDC_FLAG2_FC_FLAG)
400 return TRUE;
401 #endif
402 return FALSE;
403 }
404
405
406 int
dhd_prot_hdrpull(dhd_pub_t * dhd,int * ifidx,void * pktbuf)407 dhd_prot_hdrpull(dhd_pub_t *dhd, int *ifidx, void *pktbuf)
408 {
409 #ifdef BDC
410 struct bdc_header *h;
411 #endif
412
413 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
414
415 #ifdef BDC
416 /* Pop BDC header used to convey priority for buses that don't */
417
418 if (PKTLEN(dhd->osh, pktbuf) < BDC_HEADER_LEN) {
419 DHD_ERROR(("%s: rx data too short (%d < %d)\n", __FUNCTION__,
420 PKTLEN(dhd->osh, pktbuf), BDC_HEADER_LEN));
421 return BCME_ERROR;
422 }
423
424 h = (struct bdc_header *)PKTDATA(dhd->osh, pktbuf);
425
426 if ((*ifidx = BDC_GET_IF_IDX(h)) >= DHD_MAX_IFS) {
427 DHD_ERROR(("%s: rx data ifnum out of range (%d)\n",
428 __FUNCTION__, *ifidx));
429 return BCME_ERROR;
430 }
431
432 if (((h->flags & BDC_FLAG_VER_MASK) >> BDC_FLAG_VER_SHIFT) != BDC_PROTO_VER) {
433 DHD_ERROR(("%s: non-BDC packet received, flags 0x%x\n",
434 dhd_ifname(dhd, *ifidx), h->flags));
435 return BCME_ERROR;
436 }
437
438 if (h->flags & BDC_FLAG_SUM_GOOD) {
439 DHD_INFO(("%s: BDC packet received with good rx-csum, flags 0x%x\n",
440 dhd_ifname(dhd, *ifidx), h->flags));
441 PKTSETSUMGOOD(pktbuf, TRUE);
442 }
443
444 PKTSETPRIO(pktbuf, (h->priority & BDC_PRIORITY_MASK));
445
446 PKTPULL(dhd->osh, pktbuf, BDC_HEADER_LEN);
447 #endif /* BDC */
448
449 return 0;
450 }
451
452 int
dhd_prot_attach(dhd_pub_t * dhd)453 dhd_prot_attach(dhd_pub_t *dhd)
454 {
455 dhd_prot_t *cdc;
456
457 #ifndef DHD_USE_STATIC_BUF
458 if (!(cdc = (dhd_prot_t *)MALLOC(dhd->osh, sizeof(dhd_prot_t)))) {
459 DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__));
460 goto fail;
461 }
462 #else
463 if (!(cdc = (dhd_prot_t *)dhd_os_prealloc(DHD_PREALLOC_PROT, sizeof(dhd_prot_t)))) {
464 DHD_ERROR(("%s: kmalloc failed\n", __FUNCTION__));
465 goto fail;
466 }
467 #endif /* DHD_USE_STATIC_BUF */
468 memset(cdc, 0, sizeof(dhd_prot_t));
469
470 /* ensure that the msg buf directly follows the cdc msg struct */
471 if ((uintptr)(&cdc->msg + 1) != (uintptr)cdc->buf) {
472 DHD_ERROR(("dhd_prot_t is not correctly defined\n"));
473 goto fail;
474 }
475
476 dhd->prot = cdc;
477 #ifdef BDC
478 dhd->hdrlen += BDC_HEADER_LEN;
479 #endif
480 dhd->maxctl = WLC_IOCTL_MAXLEN + sizeof(cdc_ioctl_t) + ROUND_UP_MARGIN;
481 return 0;
482
483 fail:
484 #ifndef DHD_USE_STATIC_BUF
485 if (cdc != NULL)
486 MFREE(dhd->osh, cdc, sizeof(dhd_prot_t));
487 #endif
488 return BCME_NOMEM;
489 }
490
491 /* ~NOTE~ What if another thread is waiting on the semaphore? Holding it? */
492 void
dhd_prot_detach(dhd_pub_t * dhd)493 dhd_prot_detach(dhd_pub_t *dhd)
494 {
495 #ifndef DHD_USE_STATIC_BUF
496 MFREE(dhd->osh, dhd->prot, sizeof(dhd_prot_t));
497 #endif
498 dhd->prot = NULL;
499 }
500
501 void
dhd_prot_dstats(dhd_pub_t * dhd)502 dhd_prot_dstats(dhd_pub_t *dhd)
503 {
504 /* No stats from dongle added yet, copy bus stats */
505 dhd->dstats.tx_packets = dhd->tx_packets;
506 dhd->dstats.tx_errors = dhd->tx_errors;
507 dhd->dstats.rx_packets = dhd->rx_packets;
508 dhd->dstats.rx_errors = dhd->rx_errors;
509 dhd->dstats.rx_dropped = dhd->rx_dropped;
510 dhd->dstats.multicast = dhd->rx_multicast;
511 return;
512 }
513
dhd_set_suspend(int value,dhd_pub_t * dhd)514 int dhd_set_suspend(int value, dhd_pub_t *dhd)
515 {
516 int power_mode = PM_MAX;
517 wl_pkt_filter_enable_t enable_parm;
518 char iovbuf[32];
519 int bcn_li_dtim = 3;
520 #ifdef CUSTOMER_HW2
521 uint roamvar = 1;
522 #endif /* CUSTOMER_HW2 */
523
524 #define htod32(i) i
525
526 if (dhd && dhd->up) {
527 if (value) {
528 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM,
529 (char *)&power_mode, sizeof(power_mode));
530 /* Enable packet filter, only allow unicast packet to send up */
531 enable_parm.id = htod32(100);
532 enable_parm.enable = htod32(1);
533 bcm_mkiovar("pkt_filter_enable", (char *)&enable_parm,
534 sizeof(wl_pkt_filter_enable_t), iovbuf, sizeof(iovbuf));
535 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
536 /* set bcn_li_dtim */
537 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
538 4, iovbuf, sizeof(iovbuf));
539 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
540 #ifdef CUSTOMER_HW2
541 /* Disable build-in roaming to allowed ext supplicant to take of romaing */
542 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
543 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
544 #endif /* CUSTOMER_HW2 */
545 } else {
546 power_mode = PM_FAST;
547 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode,
548 sizeof(power_mode));
549 /* disable pkt filter */
550 enable_parm.id = htod32(100);
551 enable_parm.enable = htod32(0);
552 bcm_mkiovar("pkt_filter_enable", (char *)&enable_parm,
553 sizeof(wl_pkt_filter_enable_t), iovbuf, sizeof(iovbuf));
554 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
555 /* set bcn_li_dtim */
556 bcn_li_dtim = 0;
557 bcm_mkiovar("bcn_li_dtim", (char *)&bcn_li_dtim,
558 4, iovbuf, sizeof(iovbuf));
559 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
560 #ifdef CUSTOMER_HW2
561 roamvar = 0;
562 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
563 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
564 #endif /* CUSTOMER_HW2 */
565 }
566 }
567
568 return 0;
569 }
570
571 #define strtoul(nptr, endptr, base) bcm_strtoul((nptr), (endptr), (base))
572
573 /* Convert user's input in hex pattern to byte-size mask */
574 static int
wl_pattern_atoh(char * src,char * dst)575 wl_pattern_atoh(char *src, char *dst)
576 {
577 int i;
578 if (strncmp(src, "0x", 2) != 0 &&
579 strncmp(src, "0X", 2) != 0) {
580 printf("Mask invalid format. Needs to start with 0x\n");
581 return -1;
582 }
583 src = src + 2; /* Skip past 0x */
584 if (strlen(src) % 2 != 0) {
585 printf("Mask invalid format. Needs to be of even length\n");
586 return -1;
587 }
588 for (i = 0; *src != '\0'; i++) {
589 char num[3];
590 strncpy(num, src, 2);
591 num[2] = '\0';
592 dst[i] = (uint8)strtoul(num, NULL, 16);
593 src += 2;
594 }
595 return i;
596 }
597
598 int
dhd_preinit_ioctls(dhd_pub_t * dhd)599 dhd_preinit_ioctls(dhd_pub_t *dhd)
600 {
601 char eventmask[WL_EVENTING_MASK_LEN];
602 char iovbuf[WL_EVENTING_MASK_LEN + 12]; /* Room for "event_msgs" + '\0' + bitvec */
603 int ret;
604 uint up = 0;
605 #ifdef CUSTOMER_HW2
606 uint roamvar = 0;
607 #else
608 uint roamvar = 1;
609 #endif
610 uint power_mode = PM_FAST;
611 uint32 dongle_align = DHD_SDALIGN;
612 uint32 glom = 0;
613
614 uint bcn_timeout = 3;
615 int arpoe = 1;
616 int arp_ol = 0xf;
617 int scan_assoc_time = 40;
618 int scan_unassoc_time = 80;
619 const char *str;
620 wl_pkt_filter_t pkt_filter;
621 wl_pkt_filter_t *pkt_filterp;
622 int buf_len;
623 int str_len;
624 uint32 mask_size;
625 uint32 pattern_size;
626 char buf[256];
627 uint filter_mode = 1;
628
629 /* Get the device MAC address */
630 strcpy(iovbuf, "cur_etheraddr");
631 if ((ret = dhdcdc_query_ioctl(dhd, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf))) < 0) {
632 DHD_ERROR(("%s: can't get MAC address , error=%d\n", __FUNCTION__, ret));
633 return BCME_NOTUP;
634 }
635 memcpy(dhd->mac.octet, iovbuf, ETHER_ADDR_LEN);
636
637 /* Set Country code */
638 if (dhd->country_code[0] != 0) {
639 if (dhdcdc_set_ioctl(dhd, 0, WLC_SET_COUNTRY,
640 dhd->country_code, sizeof(dhd->country_code)) < 0) {
641 DHD_ERROR(("%s: country code setting failed\n", __FUNCTION__));
642 }
643 }
644
645 /* Set PowerSave mode */
646 dhdcdc_set_ioctl(dhd, 0, WLC_SET_PM, (char *)&power_mode, sizeof(power_mode));
647
648 /* Match Host and Dongle rx alignment */
649 bcm_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf, sizeof(iovbuf));
650 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
651
652 /* disable glom option per default */
653 bcm_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
654 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
655 /* Setup timeout if Beacons are lost and roam is off to report link down */
656 if (roamvar) {
657 bcm_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf, sizeof(iovbuf));
658 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
659 }
660
661 /* Enable/Disable build-in roaming to allowed ext supplicant to take of romaing */
662 bcm_mkiovar("roam_off", (char *)&roamvar, 4, iovbuf, sizeof(iovbuf));
663 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
664
665 /* Force STA UP */
666 dhdcdc_set_ioctl(dhd, 0, WLC_UP, (char *)&up, sizeof(up));
667
668 /* Setup event_msgs */
669 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
670 dhdcdc_query_ioctl(dhd, 0, WLC_GET_VAR, iovbuf, sizeof(iovbuf));
671 bcopy(iovbuf, eventmask, WL_EVENTING_MASK_LEN);
672
673 setbit(eventmask, WLC_E_SET_SSID);
674 setbit(eventmask, WLC_E_PRUNE);
675 setbit(eventmask, WLC_E_AUTH);
676 setbit(eventmask, WLC_E_REASSOC);
677 setbit(eventmask, WLC_E_REASSOC_IND);
678 setbit(eventmask, WLC_E_DEAUTH_IND);
679 setbit(eventmask, WLC_E_DISASSOC_IND);
680 setbit(eventmask, WLC_E_DISASSOC);
681 setbit(eventmask, WLC_E_JOIN);
682 setbit(eventmask, WLC_E_ASSOC_IND);
683 setbit(eventmask, WLC_E_PSK_SUP);
684 setbit(eventmask, WLC_E_LINK);
685 setbit(eventmask, WLC_E_NDIS_LINK);
686 setbit(eventmask, WLC_E_MIC_ERROR);
687 setbit(eventmask, WLC_E_PMKID_CACHE);
688 setbit(eventmask, WLC_E_TXFAIL);
689 setbit(eventmask, WLC_E_JOIN_START);
690 setbit(eventmask, WLC_E_SCAN_COMPLETE);
691
692 bcm_mkiovar("event_msgs", eventmask, WL_EVENTING_MASK_LEN, iovbuf, sizeof(iovbuf));
693 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
694
695 dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_CHANNEL_TIME, (char *)&scan_assoc_time,
696 sizeof(scan_assoc_time));
697 dhdcdc_set_ioctl(dhd, 0, WLC_SET_SCAN_UNASSOC_TIME, (char *)&scan_unassoc_time,
698 sizeof(scan_unassoc_time));
699
700 /* Set ARP offload */
701 bcm_mkiovar("arpoe", (char *)&arpoe, 4, iovbuf, sizeof(iovbuf));
702 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
703 bcm_mkiovar("arp_ol", (char *)&arp_ol, 4, iovbuf, sizeof(iovbuf));
704 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
705
706 /* add a default packet filter pattern */
707 str = "pkt_filter_add";
708 str_len = strlen(str);
709 strncpy(buf, str, str_len);
710 buf[ str_len ] = '\0';
711 buf_len = str_len + 1;
712
713 pkt_filterp = (wl_pkt_filter_t *) (buf + str_len + 1);
714
715 /* Parse packet filter id. */
716 pkt_filter.id = htod32(100);
717
718 /* Parse filter polarity. */
719 pkt_filter.negate_match = htod32(0);
720
721 /* Parse filter type. */
722 pkt_filter.type = htod32(0);
723
724 /* Parse pattern filter offset. */
725 pkt_filter.u.pattern.offset = htod32(0);
726
727 /* Parse pattern filter mask. */
728 mask_size = htod32(wl_pattern_atoh("0xff",
729 (char *) pkt_filterp->u.pattern.mask_and_pattern));
730
731 /* Parse pattern filter pattern. */
732 pattern_size = htod32(wl_pattern_atoh("0x00",
733 (char *) &pkt_filterp->u.pattern.mask_and_pattern[mask_size]));
734
735 if (mask_size != pattern_size) {
736 printk("Mask and pattern not the same size\n");
737 return -1;
738 }
739
740 pkt_filter.u.pattern.size_bytes = mask_size;
741 buf_len += WL_PKT_FILTER_FIXED_LEN;
742 buf_len += (WL_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
743
744 /* Keep-alive attributes are set in local variable (keep_alive_pkt), and
745 ** then memcpy'ed into buffer (keep_alive_pktp) since there is no
746 ** guarantee that the buffer is properly aligned.
747 */
748 memcpy((char *)pkt_filterp, &pkt_filter,
749 WL_PKT_FILTER_FIXED_LEN + WL_PKT_FILTER_PATTERN_FIXED_LEN);
750
751 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, buf, buf_len);
752
753 /* set mode to allow pattern */
754 bcm_mkiovar("pkt_filter_mode", (char *)&filter_mode, 4, iovbuf, sizeof(iovbuf));
755 dhdcdc_set_ioctl(dhd, 0, WLC_SET_VAR, iovbuf, sizeof(iovbuf));
756
757 return 0;
758 }
759
760 int
dhd_prot_init(dhd_pub_t * dhd)761 dhd_prot_init(dhd_pub_t *dhd)
762 {
763 int ret = 0;
764 DHD_TRACE(("%s: Enter\n", __FUNCTION__));
765
766
767 ret = dhd_preinit_ioctls(dhd);
768
769 /* Always assumes wl for now */
770 dhd->iswl = TRUE;
771
772 return ret;
773 }
774
775 void
dhd_prot_stop(dhd_pub_t * dhd)776 dhd_prot_stop(dhd_pub_t *dhd)
777 {
778 /* Nothing to do for CDC */
779 }
780