blob: a51d8f5d36fcf843bf311e5e257d560bb134e134 [file] [log] [blame]
Arend van Spriel5b435de2011-10-05 13:19:03 +02001/*
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 <linux/sched.h>
19#include <linux/netdevice.h>
20#include <asm/unaligned.h>
21#include <defs.h>
22#include <brcmu_wifi.h>
23#include <brcmu_utils.h>
24#include "dhd.h"
25#include "dhd_bus.h"
26#include "dhd_proto.h"
27#include "dhd_dbg.h"
28
29#define BRCM_OUI "\x00\x10\x18"
30#define DOT11_OUI_LEN 3
31#define BCMILCP_BCM_SUBTYPE_EVENT 1
32#define PKTFILTER_BUF_SIZE 2048
33#define BRCMF_ARPOL_MODE 0xb /* agent|snoop|peer_autoreply */
34
Arend van Spriel5b435de2011-10-05 13:19:03 +020035#define MSGTRACE_VERSION 1
36
Arend van Sprielf7264ad2011-10-12 20:51:16 +020037#define BRCMF_PKT_FILTER_FIXED_LEN offsetof(struct brcmf_pkt_filter_le, u)
Arend van Spriel5b435de2011-10-05 13:19:03 +020038#define BRCMF_PKT_FILTER_PATTERN_FIXED_LEN \
Arend van Sprielf7264ad2011-10-12 20:51:16 +020039 offsetof(struct brcmf_pkt_filter_pattern_le, mask_and_pattern)
Arend van Spriel5b435de2011-10-05 13:19:03 +020040
41#ifdef BCMDBG
42static const char brcmf_version[] =
43 "Dongle Host Driver, version " BRCMF_VERSION_STR "\nCompiled on "
44 __DATE__ " at " __TIME__;
45#else
46static const char brcmf_version[] =
47 "Dongle Host Driver, version " BRCMF_VERSION_STR;
48#endif
49
50/* Message trace header */
51struct msgtrace_hdr {
52 u8 version;
53 u8 spare;
54 __be16 len; /* Len of the trace */
55 __be32 seqnum; /* Sequence number of message. Useful
56 * if the messsage has been lost
57 * because of DMA error or a bus reset
58 * (ex: SDIO Func2)
59 */
60 __be32 discarded_bytes; /* Number of discarded bytes because of
61 trace overflow */
62 __be32 discarded_printf; /* Number of discarded printf
63 because of trace overflow */
64} __packed;
65
Alwin Beukers53a22772011-10-12 20:51:30 +020066
67uint
68brcmf_c_mkiovar(char *name, char *data, uint datalen, char *buf, uint buflen)
69{
70 uint len;
71
72 len = strlen(name) + 1;
73
74 if ((len + datalen) > buflen)
75 return 0;
76
77 strncpy(buf, name, buflen);
78
79 /* append data onto the end of the name string */
80 memcpy(&buf[len], data, datalen);
81 len += datalen;
82
83 return len;
84}
85
Franky Linb63487e2011-12-16 18:36:59 -080086bool brcmf_c_prec_enq(struct device *dev, struct pktq *q,
Arend van Spriel5b435de2011-10-05 13:19:03 +020087 struct sk_buff *pkt, int prec)
88{
89 struct sk_buff *p;
90 int eprec = -1; /* precedence to evict from */
91 bool discard_oldest;
Franky Linb63487e2011-12-16 18:36:59 -080092 struct brcmf_bus *bus_if = dev_get_drvdata(dev);
93 struct brcmf_pub *drvr = bus_if->drvr;
Arend van Spriel5b435de2011-10-05 13:19:03 +020094
95 /* Fast case, precedence queue is not full and we are also not
96 * exceeding total queue length
97 */
98 if (!pktq_pfull(q, prec) && !pktq_full(q)) {
99 brcmu_pktq_penq(q, prec, pkt);
100 return true;
101 }
102
103 /* Determine precedence from which to evict packet, if any */
104 if (pktq_pfull(q, prec))
105 eprec = prec;
106 else if (pktq_full(q)) {
107 p = brcmu_pktq_peek_tail(q, &eprec);
108 if (eprec > prec)
109 return false;
110 }
111
112 /* Evict if needed */
113 if (eprec >= 0) {
114 /* Detect queueing to unconfigured precedence */
115 discard_oldest = ac_bitmap_tst(drvr->wme_dp, eprec);
116 if (eprec == prec && !discard_oldest)
117 return false; /* refuse newer (incoming) packet */
118 /* Evict packet according to discard policy */
119 p = discard_oldest ? brcmu_pktq_pdeq(q, eprec) :
120 brcmu_pktq_pdeq_tail(q, eprec);
121 if (p == NULL)
122 brcmf_dbg(ERROR, "brcmu_pktq_penq() failed, oldest %d\n",
123 discard_oldest);
124
125 brcmu_pkt_buf_free_skb(p);
126 }
127
128 /* Enqueue */
129 p = brcmu_pktq_penq(q, prec, pkt);
130 if (p == NULL)
131 brcmf_dbg(ERROR, "brcmu_pktq_penq() failed\n");
132
133 return p != NULL;
134}
135
136#ifdef BCMDBG
137static void
138brcmf_c_show_host_event(struct brcmf_event_msg *event, void *event_data)
139{
140 uint i, status, reason;
141 bool group = false, flush_txq = false, link = false;
142 char *auth_str, *event_name;
143 unsigned char *buf;
144 char err_msg[256], eabuf[ETHER_ADDR_STR_LEN];
145 static struct {
146 uint event;
147 char *event_name;
148 } event_names[] = {
149 {
150 BRCMF_E_SET_SSID, "SET_SSID"}, {
151 BRCMF_E_JOIN, "JOIN"}, {
152 BRCMF_E_START, "START"}, {
153 BRCMF_E_AUTH, "AUTH"}, {
154 BRCMF_E_AUTH_IND, "AUTH_IND"}, {
155 BRCMF_E_DEAUTH, "DEAUTH"}, {
156 BRCMF_E_DEAUTH_IND, "DEAUTH_IND"}, {
157 BRCMF_E_ASSOC, "ASSOC"}, {
158 BRCMF_E_ASSOC_IND, "ASSOC_IND"}, {
159 BRCMF_E_REASSOC, "REASSOC"}, {
160 BRCMF_E_REASSOC_IND, "REASSOC_IND"}, {
161 BRCMF_E_DISASSOC, "DISASSOC"}, {
162 BRCMF_E_DISASSOC_IND, "DISASSOC_IND"}, {
163 BRCMF_E_QUIET_START, "START_QUIET"}, {
164 BRCMF_E_QUIET_END, "END_QUIET"}, {
165 BRCMF_E_BEACON_RX, "BEACON_RX"}, {
166 BRCMF_E_LINK, "LINK"}, {
167 BRCMF_E_MIC_ERROR, "MIC_ERROR"}, {
168 BRCMF_E_NDIS_LINK, "NDIS_LINK"}, {
169 BRCMF_E_ROAM, "ROAM"}, {
170 BRCMF_E_TXFAIL, "TXFAIL"}, {
171 BRCMF_E_PMKID_CACHE, "PMKID_CACHE"}, {
172 BRCMF_E_RETROGRADE_TSF, "RETROGRADE_TSF"}, {
173 BRCMF_E_PRUNE, "PRUNE"}, {
174 BRCMF_E_AUTOAUTH, "AUTOAUTH"}, {
175 BRCMF_E_EAPOL_MSG, "EAPOL_MSG"}, {
176 BRCMF_E_SCAN_COMPLETE, "SCAN_COMPLETE"}, {
177 BRCMF_E_ADDTS_IND, "ADDTS_IND"}, {
178 BRCMF_E_DELTS_IND, "DELTS_IND"}, {
179 BRCMF_E_BCNSENT_IND, "BCNSENT_IND"}, {
180 BRCMF_E_BCNRX_MSG, "BCNRX_MSG"}, {
181 BRCMF_E_BCNLOST_MSG, "BCNLOST_MSG"}, {
182 BRCMF_E_ROAM_PREP, "ROAM_PREP"}, {
183 BRCMF_E_PFN_NET_FOUND, "PNO_NET_FOUND"}, {
184 BRCMF_E_PFN_NET_LOST, "PNO_NET_LOST"}, {
185 BRCMF_E_RESET_COMPLETE, "RESET_COMPLETE"}, {
186 BRCMF_E_JOIN_START, "JOIN_START"}, {
187 BRCMF_E_ROAM_START, "ROAM_START"}, {
188 BRCMF_E_ASSOC_START, "ASSOC_START"}, {
189 BRCMF_E_IBSS_ASSOC, "IBSS_ASSOC"}, {
190 BRCMF_E_RADIO, "RADIO"}, {
191 BRCMF_E_PSM_WATCHDOG, "PSM_WATCHDOG"}, {
192 BRCMF_E_PROBREQ_MSG, "PROBREQ_MSG"}, {
193 BRCMF_E_SCAN_CONFIRM_IND, "SCAN_CONFIRM_IND"}, {
194 BRCMF_E_PSK_SUP, "PSK_SUP"}, {
195 BRCMF_E_COUNTRY_CODE_CHANGED, "COUNTRY_CODE_CHANGED"}, {
196 BRCMF_E_EXCEEDED_MEDIUM_TIME, "EXCEEDED_MEDIUM_TIME"}, {
197 BRCMF_E_ICV_ERROR, "ICV_ERROR"}, {
198 BRCMF_E_UNICAST_DECODE_ERROR, "UNICAST_DECODE_ERROR"}, {
199 BRCMF_E_MULTICAST_DECODE_ERROR, "MULTICAST_DECODE_ERROR"}, {
200 BRCMF_E_TRACE, "TRACE"}, {
201 BRCMF_E_ACTION_FRAME, "ACTION FRAME"}, {
202 BRCMF_E_ACTION_FRAME_COMPLETE, "ACTION FRAME TX COMPLETE"}, {
203 BRCMF_E_IF, "IF"}, {
204 BRCMF_E_RSSI, "RSSI"}, {
205 BRCMF_E_PFN_SCAN_COMPLETE, "SCAN_COMPLETE"}
206 };
207 uint event_type, flags, auth_type, datalen;
208 static u32 seqnum_prev;
209 struct msgtrace_hdr hdr;
210 u32 nblost;
211 char *s, *p;
212
213 event_type = be32_to_cpu(event->event_type);
214 flags = be16_to_cpu(event->flags);
215 status = be32_to_cpu(event->status);
216 reason = be32_to_cpu(event->reason);
217 auth_type = be32_to_cpu(event->auth_type);
218 datalen = be32_to_cpu(event->datalen);
219 /* debug dump of event messages */
220 sprintf(eabuf, "%pM", event->addr);
221
222 event_name = "UNKNOWN";
223 for (i = 0; i < ARRAY_SIZE(event_names); i++) {
224 if (event_names[i].event == event_type)
225 event_name = event_names[i].event_name;
226 }
227
228 brcmf_dbg(EVENT, "EVENT: %s, event ID = %d\n", event_name, event_type);
229 brcmf_dbg(EVENT, "flags 0x%04x, status %d, reason %d, auth_type %d MAC %s\n",
230 flags, status, reason, auth_type, eabuf);
231
232 if (flags & BRCMF_EVENT_MSG_LINK)
233 link = true;
234 if (flags & BRCMF_EVENT_MSG_GROUP)
235 group = true;
236 if (flags & BRCMF_EVENT_MSG_FLUSHTXQ)
237 flush_txq = true;
238
239 switch (event_type) {
240 case BRCMF_E_START:
241 case BRCMF_E_DEAUTH:
242 case BRCMF_E_DISASSOC:
243 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf);
244 break;
245
246 case BRCMF_E_ASSOC_IND:
247 case BRCMF_E_REASSOC_IND:
248 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf);
249 break;
250
251 case BRCMF_E_ASSOC:
252 case BRCMF_E_REASSOC:
253 if (status == BRCMF_E_STATUS_SUCCESS)
254 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, SUCCESS\n",
255 event_name, eabuf);
256 else if (status == BRCMF_E_STATUS_TIMEOUT)
257 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, TIMEOUT\n",
258 event_name, eabuf);
259 else if (status == BRCMF_E_STATUS_FAIL)
260 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, FAILURE, reason %d\n",
261 event_name, eabuf, (int)reason);
262 else
263 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, unexpected status %d\n",
264 event_name, eabuf, (int)status);
265 break;
266
267 case BRCMF_E_DEAUTH_IND:
268 case BRCMF_E_DISASSOC_IND:
269 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, reason %d\n",
270 event_name, eabuf, (int)reason);
271 break;
272
273 case BRCMF_E_AUTH:
274 case BRCMF_E_AUTH_IND:
275 if (auth_type == WLAN_AUTH_OPEN)
276 auth_str = "Open System";
277 else if (auth_type == WLAN_AUTH_SHARED_KEY)
278 auth_str = "Shared Key";
279 else {
280 sprintf(err_msg, "AUTH unknown: %d", (int)auth_type);
281 auth_str = err_msg;
282 }
283 if (event_type == BRCMF_E_AUTH_IND)
284 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s\n",
285 event_name, eabuf, auth_str);
286 else if (status == BRCMF_E_STATUS_SUCCESS)
287 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, SUCCESS\n",
288 event_name, eabuf, auth_str);
289 else if (status == BRCMF_E_STATUS_TIMEOUT)
290 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, TIMEOUT\n",
291 event_name, eabuf, auth_str);
292 else if (status == BRCMF_E_STATUS_FAIL) {
293 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, %s, FAILURE, reason %d\n",
294 event_name, eabuf, auth_str, (int)reason);
295 }
296
297 break;
298
299 case BRCMF_E_JOIN:
300 case BRCMF_E_ROAM:
301 case BRCMF_E_SET_SSID:
302 if (status == BRCMF_E_STATUS_SUCCESS)
303 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n",
304 event_name, eabuf);
305 else if (status == BRCMF_E_STATUS_FAIL)
306 brcmf_dbg(EVENT, "MACEVENT: %s, failed\n", event_name);
307 else if (status == BRCMF_E_STATUS_NO_NETWORKS)
308 brcmf_dbg(EVENT, "MACEVENT: %s, no networks found\n",
309 event_name);
310 else
311 brcmf_dbg(EVENT, "MACEVENT: %s, unexpected status %d\n",
312 event_name, (int)status);
313 break;
314
315 case BRCMF_E_BEACON_RX:
316 if (status == BRCMF_E_STATUS_SUCCESS)
317 brcmf_dbg(EVENT, "MACEVENT: %s, SUCCESS\n", event_name);
318 else if (status == BRCMF_E_STATUS_FAIL)
319 brcmf_dbg(EVENT, "MACEVENT: %s, FAIL\n", event_name);
320 else
321 brcmf_dbg(EVENT, "MACEVENT: %s, status %d\n",
322 event_name, status);
323 break;
324
325 case BRCMF_E_LINK:
326 brcmf_dbg(EVENT, "MACEVENT: %s %s\n",
327 event_name, link ? "UP" : "DOWN");
328 break;
329
330 case BRCMF_E_MIC_ERROR:
331 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s, Group %d, Flush %d\n",
332 event_name, eabuf, group, flush_txq);
333 break;
334
335 case BRCMF_E_ICV_ERROR:
336 case BRCMF_E_UNICAST_DECODE_ERROR:
337 case BRCMF_E_MULTICAST_DECODE_ERROR:
338 brcmf_dbg(EVENT, "MACEVENT: %s, MAC %s\n", event_name, eabuf);
339 break;
340
341 case BRCMF_E_TXFAIL:
342 brcmf_dbg(EVENT, "MACEVENT: %s, RA %s\n", event_name, eabuf);
343 break;
344
345 case BRCMF_E_SCAN_COMPLETE:
346 case BRCMF_E_PMKID_CACHE:
347 brcmf_dbg(EVENT, "MACEVENT: %s\n", event_name);
348 break;
349
350 case BRCMF_E_PFN_NET_FOUND:
351 case BRCMF_E_PFN_NET_LOST:
352 case BRCMF_E_PFN_SCAN_COMPLETE:
353 brcmf_dbg(EVENT, "PNOEVENT: %s\n", event_name);
354 break;
355
356 case BRCMF_E_PSK_SUP:
357 case BRCMF_E_PRUNE:
358 brcmf_dbg(EVENT, "MACEVENT: %s, status %d, reason %d\n",
359 event_name, (int)status, (int)reason);
360 break;
361
362 case BRCMF_E_TRACE:
363 buf = (unsigned char *) event_data;
364 memcpy(&hdr, buf, sizeof(struct msgtrace_hdr));
365
366 if (hdr.version != MSGTRACE_VERSION) {
367 brcmf_dbg(ERROR,
368 "MACEVENT: %s [unsupported version --> brcmf"
369 " version:%d dongle version:%d]\n",
370 event_name, MSGTRACE_VERSION, hdr.version);
371 /* Reset datalen to avoid display below */
372 datalen = 0;
373 break;
374 }
375
376 /* There are 2 bytes available at the end of data */
377 *(buf + sizeof(struct msgtrace_hdr)
378 + be16_to_cpu(hdr.len)) = '\0';
379
380 if (be32_to_cpu(hdr.discarded_bytes)
381 || be32_to_cpu(hdr.discarded_printf))
382 brcmf_dbg(ERROR,
383 "WLC_E_TRACE: [Discarded traces in dongle -->"
384 " discarded_bytes %d discarded_printf %d]\n",
385 be32_to_cpu(hdr.discarded_bytes),
386 be32_to_cpu(hdr.discarded_printf));
387
388 nblost = be32_to_cpu(hdr.seqnum) - seqnum_prev - 1;
389 if (nblost > 0)
390 brcmf_dbg(ERROR, "WLC_E_TRACE: [Event lost --> seqnum "
391 " %d nblost %d\n", be32_to_cpu(hdr.seqnum),
392 nblost);
393 seqnum_prev = be32_to_cpu(hdr.seqnum);
394
395 /* Display the trace buffer. Advance from \n to \n to
396 * avoid display big
397 * printf (issue with Linux printk )
398 */
399 p = (char *)&buf[sizeof(struct msgtrace_hdr)];
400 while ((s = strstr(p, "\n")) != NULL) {
401 *s = '\0';
402 printk(KERN_DEBUG"%s\n", p);
403 p = s + 1;
404 }
405 printk(KERN_DEBUG "%s\n", p);
406
407 /* Reset datalen to avoid display below */
408 datalen = 0;
409 break;
410
411 case BRCMF_E_RSSI:
412 brcmf_dbg(EVENT, "MACEVENT: %s %d\n",
413 event_name, be32_to_cpu(*((__be32 *)event_data)));
414 break;
415
416 default:
417 brcmf_dbg(EVENT,
418 "MACEVENT: %s %d, MAC %s, status %d, reason %d, "
419 "auth %d\n", event_name, event_type, eabuf,
420 (int)status, (int)reason, (int)auth_type);
421 break;
422 }
423
424 /* show any appended data */
425 if (datalen) {
426 buf = (unsigned char *) event_data;
427 brcmf_dbg(EVENT, " data (%d) : ", datalen);
428 for (i = 0; i < datalen; i++)
429 brcmf_dbg(EVENT, " 0x%02x ", *buf++);
430 brcmf_dbg(EVENT, "\n");
431 }
432}
433#endif /* BCMDBG */
434
435int
Franky Lind08b6a32011-12-16 18:36:51 -0800436brcmf_c_host_event(struct brcmf_pub *drvr, int *ifidx, void *pktdata,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200437 struct brcmf_event_msg *event, void **data_ptr)
438{
439 /* check whether packet is a BRCM event pkt */
440 struct brcmf_event *pvt_data = (struct brcmf_event *) pktdata;
441 struct brcmf_if_event *ifevent;
442 char *event_data;
443 u32 type, status;
444 u16 flags;
445 int evlen;
446
447 if (memcmp(BRCM_OUI, &pvt_data->hdr.oui[0], DOT11_OUI_LEN)) {
448 brcmf_dbg(ERROR, "mismatched OUI, bailing\n");
449 return -EBADE;
450 }
451
452 /* BRCM event pkt may be unaligned - use xxx_ua to load user_subtype. */
453 if (get_unaligned_be16(&pvt_data->hdr.usr_subtype) !=
454 BCMILCP_BCM_SUBTYPE_EVENT) {
455 brcmf_dbg(ERROR, "mismatched subtype, bailing\n");
456 return -EBADE;
457 }
458
459 *data_ptr = &pvt_data[1];
460 event_data = *data_ptr;
461
462 /* memcpy since BRCM event pkt may be unaligned. */
463 memcpy(event, &pvt_data->msg, sizeof(struct brcmf_event_msg));
464
465 type = get_unaligned_be32(&event->event_type);
466 flags = get_unaligned_be16(&event->flags);
467 status = get_unaligned_be32(&event->status);
468 evlen = get_unaligned_be32(&event->datalen) +
469 sizeof(struct brcmf_event);
470
471 switch (type) {
472 case BRCMF_E_IF:
473 ifevent = (struct brcmf_if_event *) event_data;
474 brcmf_dbg(TRACE, "if event\n");
475
476 if (ifevent->ifidx > 0 && ifevent->ifidx < BRCMF_MAX_IFS) {
477 if (ifevent->action == BRCMF_E_IF_ADD)
Franky Lin55a63bc2011-12-16 18:36:54 -0800478 brcmf_add_if(drvr->dev, ifevent->ifidx,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200479 event->ifname,
Franky Lin15d45b62011-10-21 16:16:32 +0200480 pvt_data->eth.h_dest);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200481 else
Franky Lind08b6a32011-12-16 18:36:51 -0800482 brcmf_del_if(drvr, ifevent->ifidx);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200483 } else {
484 brcmf_dbg(ERROR, "Invalid ifidx %d for %s\n",
485 ifevent->ifidx, event->ifname);
486 }
487
488 /* send up the if event: btamp user needs it */
Franky Lind08b6a32011-12-16 18:36:51 -0800489 *ifidx = brcmf_ifname2idx(drvr, event->ifname);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200490 break;
491
492 /* These are what external supplicant/authenticator wants */
493 case BRCMF_E_LINK:
494 case BRCMF_E_ASSOC_IND:
495 case BRCMF_E_REASSOC_IND:
496 case BRCMF_E_DISASSOC_IND:
497 case BRCMF_E_MIC_ERROR:
498 default:
499 /* Fall through: this should get _everything_ */
500
Franky Lind08b6a32011-12-16 18:36:51 -0800501 *ifidx = brcmf_ifname2idx(drvr, event->ifname);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200502 brcmf_dbg(TRACE, "MAC event %d, flags %x, status %x\n",
503 type, flags, status);
504
505 /* put it back to BRCMF_E_NDIS_LINK */
506 if (type == BRCMF_E_NDIS_LINK) {
507 u32 temp1;
508 __be32 temp2;
509
510 temp1 = get_unaligned_be32(&event->event_type);
511 brcmf_dbg(TRACE, "Converted to WLC_E_LINK type %d\n",
512 temp1);
513
514 temp2 = cpu_to_be32(BRCMF_E_NDIS_LINK);
515 memcpy((void *)(&pvt_data->msg.event_type), &temp2,
516 sizeof(pvt_data->msg.event_type));
517 }
518 break;
519 }
520
521#ifdef BCMDBG
522 brcmf_c_show_host_event(event, event_data);
523#endif /* BCMDBG */
524
525 return 0;
526}
527
528/* Convert user's input in hex pattern to byte-size mask */
529static int brcmf_c_pattern_atoh(char *src, char *dst)
530{
531 int i;
532 if (strncmp(src, "0x", 2) != 0 && strncmp(src, "0X", 2) != 0) {
533 brcmf_dbg(ERROR, "Mask invalid format. Needs to start with 0x\n");
534 return -EINVAL;
535 }
536 src = src + 2; /* Skip past 0x */
537 if (strlen(src) % 2 != 0) {
538 brcmf_dbg(ERROR, "Mask invalid format. Length must be even.\n");
539 return -EINVAL;
540 }
541 for (i = 0; *src != '\0'; i++) {
542 unsigned long res;
543 char num[3];
544 strncpy(num, src, 2);
545 num[2] = '\0';
546 if (kstrtoul(num, 16, &res))
547 return -EINVAL;
548 dst[i] = (u8)res;
549 src += 2;
550 }
551 return i;
552}
553
554void
555brcmf_c_pktfilter_offload_enable(struct brcmf_pub *drvr, char *arg, int enable,
556 int master_mode)
557{
558 unsigned long res;
559 char *argv[8];
560 int i = 0;
561 const char *str;
562 int buf_len;
563 int str_len;
564 char *arg_save = NULL, *arg_org = NULL;
565 int rc;
566 char buf[128];
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200567 struct brcmf_pkt_filter_enable_le enable_parm;
568 struct brcmf_pkt_filter_enable_le *pkt_filterp;
569 __le32 mmode_le;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200570
571 arg_save = kmalloc(strlen(arg) + 1, GFP_ATOMIC);
572 if (!arg_save)
573 goto fail;
574
575 arg_org = arg_save;
576 memcpy(arg_save, arg, strlen(arg) + 1);
577
578 argv[i] = strsep(&arg_save, " ");
579
580 i = 0;
581 if (NULL == argv[i]) {
582 brcmf_dbg(ERROR, "No args provided\n");
583 goto fail;
584 }
585
586 str = "pkt_filter_enable";
587 str_len = strlen(str);
588 strncpy(buf, str, str_len);
589 buf[str_len] = '\0';
590 buf_len = str_len + 1;
591
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200592 pkt_filterp = (struct brcmf_pkt_filter_enable_le *) (buf + str_len + 1);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200593
594 /* Parse packet filter id. */
595 enable_parm.id = 0;
596 if (!kstrtoul(argv[i], 0, &res))
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200597 enable_parm.id = cpu_to_le32((u32)res);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200598
599 /* Parse enable/disable value. */
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200600 enable_parm.enable = cpu_to_le32(enable);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200601
602 buf_len += sizeof(enable_parm);
603 memcpy((char *)pkt_filterp, &enable_parm, sizeof(enable_parm));
604
605 /* Enable/disable the specified filter. */
606 rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf, buf_len);
607 rc = rc >= 0 ? 0 : rc;
608 if (rc)
609 brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n",
610 arg, rc);
611 else
612 brcmf_dbg(TRACE, "successfully added pktfilter %s\n", arg);
613
614 /* Contorl the master mode */
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200615 mmode_le = cpu_to_le32(master_mode);
Alwin Beukers53a22772011-10-12 20:51:30 +0200616 brcmf_c_mkiovar("pkt_filter_mode", (char *)&mmode_le, 4, buf,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200617 sizeof(buf));
618 rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf,
619 sizeof(buf));
620 rc = rc >= 0 ? 0 : rc;
621 if (rc)
622 brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n",
623 arg, rc);
624
625fail:
626 kfree(arg_org);
627}
628
629void brcmf_c_pktfilter_offload_set(struct brcmf_pub *drvr, char *arg)
630{
631 const char *str;
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200632 struct brcmf_pkt_filter_le pkt_filter;
633 struct brcmf_pkt_filter_le *pkt_filterp;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200634 unsigned long res;
635 int buf_len;
636 int str_len;
637 int rc;
638 u32 mask_size;
639 u32 pattern_size;
640 char *argv[8], *buf = NULL;
641 int i = 0;
642 char *arg_save = NULL, *arg_org = NULL;
643
644 arg_save = kstrdup(arg, GFP_ATOMIC);
645 if (!arg_save)
646 goto fail;
647
648 arg_org = arg_save;
649
650 buf = kmalloc(PKTFILTER_BUF_SIZE, GFP_ATOMIC);
651 if (!buf)
652 goto fail;
653
654 argv[i] = strsep(&arg_save, " ");
655 while (argv[i++])
656 argv[i] = strsep(&arg_save, " ");
657
658 i = 0;
659 if (NULL == argv[i]) {
660 brcmf_dbg(ERROR, "No args provided\n");
661 goto fail;
662 }
663
664 str = "pkt_filter_add";
665 strcpy(buf, str);
666 str_len = strlen(str);
667 buf_len = str_len + 1;
668
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200669 pkt_filterp = (struct brcmf_pkt_filter_le *) (buf + str_len + 1);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200670
671 /* Parse packet filter id. */
672 pkt_filter.id = 0;
673 if (!kstrtoul(argv[i], 0, &res))
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200674 pkt_filter.id = cpu_to_le32((u32)res);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200675
676 if (NULL == argv[++i]) {
677 brcmf_dbg(ERROR, "Polarity not provided\n");
678 goto fail;
679 }
680
681 /* Parse filter polarity. */
682 pkt_filter.negate_match = 0;
683 if (!kstrtoul(argv[i], 0, &res))
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200684 pkt_filter.negate_match = cpu_to_le32((u32)res);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200685
686 if (NULL == argv[++i]) {
687 brcmf_dbg(ERROR, "Filter type not provided\n");
688 goto fail;
689 }
690
691 /* Parse filter type. */
692 pkt_filter.type = 0;
693 if (!kstrtoul(argv[i], 0, &res))
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200694 pkt_filter.type = cpu_to_le32((u32)res);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200695
696 if (NULL == argv[++i]) {
697 brcmf_dbg(ERROR, "Offset not provided\n");
698 goto fail;
699 }
700
701 /* Parse pattern filter offset. */
702 pkt_filter.u.pattern.offset = 0;
703 if (!kstrtoul(argv[i], 0, &res))
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200704 pkt_filter.u.pattern.offset = cpu_to_le32((u32)res);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200705
706 if (NULL == argv[++i]) {
707 brcmf_dbg(ERROR, "Bitmask not provided\n");
708 goto fail;
709 }
710
711 /* Parse pattern filter mask. */
712 mask_size =
713 brcmf_c_pattern_atoh
714 (argv[i], (char *)pkt_filterp->u.pattern.mask_and_pattern);
715
716 if (NULL == argv[++i]) {
717 brcmf_dbg(ERROR, "Pattern not provided\n");
718 goto fail;
719 }
720
721 /* Parse pattern filter pattern. */
722 pattern_size =
723 brcmf_c_pattern_atoh(argv[i],
724 (char *)&pkt_filterp->u.pattern.
725 mask_and_pattern[mask_size]);
726
727 if (mask_size != pattern_size) {
728 brcmf_dbg(ERROR, "Mask and pattern not the same size\n");
729 goto fail;
730 }
731
Arend van Sprielf7264ad2011-10-12 20:51:16 +0200732 pkt_filter.u.pattern.size_bytes = cpu_to_le32(mask_size);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200733 buf_len += BRCMF_PKT_FILTER_FIXED_LEN;
734 buf_len += (BRCMF_PKT_FILTER_PATTERN_FIXED_LEN + 2 * mask_size);
735
736 /* Keep-alive attributes are set in local
737 * variable (keep_alive_pkt), and
738 ** then memcpy'ed into buffer (keep_alive_pktp) since there is no
739 ** guarantee that the buffer is properly aligned.
740 */
741 memcpy((char *)pkt_filterp,
742 &pkt_filter,
743 BRCMF_PKT_FILTER_FIXED_LEN + BRCMF_PKT_FILTER_PATTERN_FIXED_LEN);
744
745 rc = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, buf, buf_len);
746 rc = rc >= 0 ? 0 : rc;
747
748 if (rc)
749 brcmf_dbg(TRACE, "failed to add pktfilter %s, retcode = %d\n",
750 arg, rc);
751 else
752 brcmf_dbg(TRACE, "successfully added pktfilter %s\n", arg);
753
754fail:
755 kfree(arg_org);
756
757 kfree(buf);
758}
759
760static void brcmf_c_arp_offload_set(struct brcmf_pub *drvr, int arp_mode)
761{
762 char iovbuf[32];
763 int retcode;
764
Alwin Beukers53a22772011-10-12 20:51:30 +0200765 brcmf_c_mkiovar("arp_ol", (char *)&arp_mode, 4, iovbuf, sizeof(iovbuf));
Arend van Spriel5b435de2011-10-05 13:19:03 +0200766 retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR,
767 iovbuf, sizeof(iovbuf));
768 retcode = retcode >= 0 ? 0 : retcode;
769 if (retcode)
770 brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, retcode = %d\n",
771 arp_mode, retcode);
772 else
773 brcmf_dbg(TRACE, "successfully set ARP offload mode to 0x%x\n",
774 arp_mode);
775}
776
777static void brcmf_c_arp_offload_enable(struct brcmf_pub *drvr, int arp_enable)
778{
779 char iovbuf[32];
780 int retcode;
781
Alwin Beukers53a22772011-10-12 20:51:30 +0200782 brcmf_c_mkiovar("arpoe", (char *)&arp_enable, 4,
783 iovbuf, sizeof(iovbuf));
Arend van Spriel5b435de2011-10-05 13:19:03 +0200784 retcode = brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR,
785 iovbuf, sizeof(iovbuf));
786 retcode = retcode >= 0 ? 0 : retcode;
787 if (retcode)
788 brcmf_dbg(TRACE, "failed to enable ARP offload to %d, retcode = %d\n",
789 arp_enable, retcode);
790 else
791 brcmf_dbg(TRACE, "successfully enabled ARP offload to %d\n",
792 arp_enable);
793}
794
795int brcmf_c_preinit_dcmds(struct brcmf_pub *drvr)
796{
797 char iovbuf[BRCMF_EVENTING_MASK_LEN + 12]; /* Room for
798 "event_msgs" + '\0' + bitvec */
799 uint up = 0;
800 char buf[128], *ptr;
Franky Lin6e3c71282011-12-16 18:37:11 -0800801 u32 dongle_align = drvr->bus_if->align;
Arend van Spriel5b435de2011-10-05 13:19:03 +0200802 u32 glom = 0;
803 u32 roaming = 1;
804 uint bcn_timeout = 3;
805 int scan_assoc_time = 40;
806 int scan_unassoc_time = 40;
807 int i;
808
Franky Lin1ae00422011-12-16 18:36:52 -0800809 mutex_lock(&drvr->proto_block);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200810
811 /* Set Country code */
812 if (drvr->country_code[0] != 0) {
813 if (brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_COUNTRY,
814 drvr->country_code,
815 sizeof(drvr->country_code)) < 0)
816 brcmf_dbg(ERROR, "country code setting failed\n");
817 }
818
819 /* query for 'ver' to get version info from firmware */
820 memset(buf, 0, sizeof(buf));
821 ptr = buf;
Alwin Beukers53a22772011-10-12 20:51:30 +0200822 brcmf_c_mkiovar("ver", NULL, 0, buf, sizeof(buf));
Arend van Spriel5b435de2011-10-05 13:19:03 +0200823 brcmf_proto_cdc_query_dcmd(drvr, 0, BRCMF_C_GET_VAR, buf, sizeof(buf));
824 strsep(&ptr, "\n");
825 /* Print fw version info */
826 brcmf_dbg(ERROR, "Firmware version = %s\n", buf);
827
828 /* Match Host and Dongle rx alignment */
Alwin Beukers53a22772011-10-12 20:51:30 +0200829 brcmf_c_mkiovar("bus:txglomalign", (char *)&dongle_align, 4, iovbuf,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200830 sizeof(iovbuf));
831 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
832 sizeof(iovbuf));
833
834 /* disable glom option per default */
Alwin Beukers53a22772011-10-12 20:51:30 +0200835 brcmf_c_mkiovar("bus:txglom", (char *)&glom, 4, iovbuf, sizeof(iovbuf));
Arend van Spriel5b435de2011-10-05 13:19:03 +0200836 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
837 sizeof(iovbuf));
838
839 /* Setup timeout if Beacons are lost and roam is off to report
840 link down */
Alwin Beukers53a22772011-10-12 20:51:30 +0200841 brcmf_c_mkiovar("bcn_timeout", (char *)&bcn_timeout, 4, iovbuf,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200842 sizeof(iovbuf));
843 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
844 sizeof(iovbuf));
845
846 /* Enable/Disable build-in roaming to allowed ext supplicant to take
847 of romaing */
Alwin Beukers53a22772011-10-12 20:51:30 +0200848 brcmf_c_mkiovar("roam_off", (char *)&roaming, 4,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200849 iovbuf, sizeof(iovbuf));
850 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
851 sizeof(iovbuf));
852
853 /* Force STA UP */
854 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_UP, (char *)&up, sizeof(up));
855
856 /* Setup event_msgs */
Alwin Beukers53a22772011-10-12 20:51:30 +0200857 brcmf_c_mkiovar("event_msgs", drvr->eventmask, BRCMF_EVENTING_MASK_LEN,
Arend van Spriel5b435de2011-10-05 13:19:03 +0200858 iovbuf, sizeof(iovbuf));
859 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_VAR, iovbuf,
860 sizeof(iovbuf));
861
862 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_CHANNEL_TIME,
863 (char *)&scan_assoc_time, sizeof(scan_assoc_time));
864 brcmf_proto_cdc_set_dcmd(drvr, 0, BRCMF_C_SET_SCAN_UNASSOC_TIME,
865 (char *)&scan_unassoc_time, sizeof(scan_unassoc_time));
866
867 /* Set and enable ARP offload feature */
868 brcmf_c_arp_offload_set(drvr, BRCMF_ARPOL_MODE);
869 brcmf_c_arp_offload_enable(drvr, true);
870
871 /* Set up pkt filter */
872 for (i = 0; i < drvr->pktfilter_count; i++) {
873 brcmf_c_pktfilter_offload_set(drvr, drvr->pktfilter[i]);
874 brcmf_c_pktfilter_offload_enable(drvr, drvr->pktfilter[i],
875 0, true);
876 }
877
Franky Lin1ae00422011-12-16 18:36:52 -0800878 mutex_unlock(&drvr->proto_block);
Arend van Spriel5b435de2011-10-05 13:19:03 +0200879
880 return 0;
881}