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