2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/sched.h>
19 #include <linux/netdevice.h>
20 #include <asm/unaligned.h>
22 #include <brcmu_wifi.h>
23 #include <brcmu_utils.h>
26 #include "dhd_proto.h"
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 */
35 #define MSGTRACE_VERSION 1
37 #define BRCMF_PKT_FILTER_FIXED_LEN offsetof(struct brcmf_pkt_filter_le, u)
38 #define BRCMF_PKT_FILTER_PATTERN_FIXED_LEN \
39 offsetof(struct brcmf_pkt_filter_pattern_le, mask_and_pattern)
42 static const char brcmf_version
[] =
43 "Dongle Host Driver, version " BRCMF_VERSION_STR
"\nCompiled on "
44 __DATE__
" at " __TIME__
;
46 static const char brcmf_version
[] =
47 "Dongle Host Driver, version " BRCMF_VERSION_STR
;
50 /* Message trace header */
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
60 __be32 discarded_bytes
; /* Number of discarded bytes because of
62 __be32 discarded_printf
; /* Number of discarded printf
63 because of trace overflow */
68 brcmf_c_mkiovar(char *name
, char *data
, uint datalen
, char *buf
, uint buflen
)
72 len
= strlen(name
) + 1;
74 if ((len
+ datalen
) > buflen
)
77 strncpy(buf
, name
, buflen
);
79 /* append data onto the end of the name string */
80 memcpy(&buf
[len
], data
, datalen
);
86 bool brcmf_c_prec_enq(struct device
*dev
, struct pktq
*q
,
87 struct sk_buff
*pkt
, int prec
)
90 int eprec
= -1; /* precedence to evict from */
92 struct brcmf_bus
*bus_if
= dev_get_drvdata(dev
);
93 struct brcmf_pub
*drvr
= bus_if
->drvr
;
95 /* Fast case, precedence queue is not full and we are also not
96 * exceeding total queue length
98 if (!pktq_pfull(q
, prec
) && !pktq_full(q
)) {
99 brcmu_pktq_penq(q
, prec
, pkt
);
103 /* Determine precedence from which to evict packet, if any */
104 if (pktq_pfull(q
, prec
))
106 else if (pktq_full(q
)) {
107 p
= brcmu_pktq_peek_tail(q
, &eprec
);
112 /* Evict if needed */
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
);
122 brcmf_dbg(ERROR
, "brcmu_pktq_penq() failed, oldest %d\n",
125 brcmu_pkt_buf_free_skb(p
);
129 p
= brcmu_pktq_penq(q
, prec
, pkt
);
131 brcmf_dbg(ERROR
, "brcmu_pktq_penq() failed\n");
138 brcmf_c_show_host_event(struct brcmf_event_msg
*event
, void *event_data
)
140 uint i
, status
, reason
;
141 bool group
= false, flush_txq
= false, link
= false;
142 char *auth_str
, *event_name
;
144 char err_msg
[256], eabuf
[ETHER_ADDR_STR_LEN
];
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"}, {
204 BRCMF_E_RSSI
, "RSSI"}, {
205 BRCMF_E_PFN_SCAN_COMPLETE
, "SCAN_COMPLETE"}
207 uint event_type
, flags
, auth_type
, datalen
;
208 static u32 seqnum_prev
;
209 struct msgtrace_hdr hdr
;
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
);
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
;
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
);
232 if (flags
& BRCMF_EVENT_MSG_LINK
)
234 if (flags
& BRCMF_EVENT_MSG_GROUP
)
236 if (flags
& BRCMF_EVENT_MSG_FLUSHTXQ
)
239 switch (event_type
) {
242 case BRCMF_E_DISASSOC
:
243 brcmf_dbg(EVENT
, "MACEVENT: %s, MAC %s\n", event_name
, eabuf
);
246 case BRCMF_E_ASSOC_IND
:
247 case BRCMF_E_REASSOC_IND
:
248 brcmf_dbg(EVENT
, "MACEVENT: %s, MAC %s\n", event_name
, eabuf
);
252 case BRCMF_E_REASSOC
:
253 if (status
== BRCMF_E_STATUS_SUCCESS
)
254 brcmf_dbg(EVENT
, "MACEVENT: %s, MAC %s, SUCCESS\n",
256 else if (status
== BRCMF_E_STATUS_TIMEOUT
)
257 brcmf_dbg(EVENT
, "MACEVENT: %s, MAC %s, TIMEOUT\n",
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
);
263 brcmf_dbg(EVENT
, "MACEVENT: %s, MAC %s, unexpected status %d\n",
264 event_name
, eabuf
, (int)status
);
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
);
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";
280 sprintf(err_msg
, "AUTH unknown: %d", (int)auth_type
);
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
);
301 case BRCMF_E_SET_SSID
:
302 if (status
== BRCMF_E_STATUS_SUCCESS
)
303 brcmf_dbg(EVENT
, "MACEVENT: %s, MAC %s\n",
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",
311 brcmf_dbg(EVENT
, "MACEVENT: %s, unexpected status %d\n",
312 event_name
, (int)status
);
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
);
321 brcmf_dbg(EVENT
, "MACEVENT: %s, status %d\n",
326 brcmf_dbg(EVENT
, "MACEVENT: %s %s\n",
327 event_name
, link
? "UP" : "DOWN");
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
);
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
);
342 brcmf_dbg(EVENT
, "MACEVENT: %s, RA %s\n", event_name
, eabuf
);
345 case BRCMF_E_SCAN_COMPLETE
:
346 case BRCMF_E_PMKID_CACHE
:
347 brcmf_dbg(EVENT
, "MACEVENT: %s\n", event_name
);
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
);
356 case BRCMF_E_PSK_SUP
:
358 brcmf_dbg(EVENT
, "MACEVENT: %s, status %d, reason %d\n",
359 event_name
, (int)status
, (int)reason
);
363 buf
= (unsigned char *) event_data
;
364 memcpy(&hdr
, buf
, sizeof(struct msgtrace_hdr
));
366 if (hdr
.version
!= MSGTRACE_VERSION
) {
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 */
376 /* There are 2 bytes available at the end of data */
377 *(buf
+ sizeof(struct msgtrace_hdr
)
378 + be16_to_cpu(hdr
.len
)) = '\0';
380 if (be32_to_cpu(hdr
.discarded_bytes
)
381 || be32_to_cpu(hdr
.discarded_printf
))
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
));
388 nblost
= be32_to_cpu(hdr
.seqnum
) - seqnum_prev
- 1;
390 brcmf_dbg(ERROR
, "WLC_E_TRACE: [Event lost --> seqnum "
391 " %d nblost %d\n", be32_to_cpu(hdr
.seqnum
),
393 seqnum_prev
= be32_to_cpu(hdr
.seqnum
);
395 /* Display the trace buffer. Advance from \n to \n to
397 * printf (issue with Linux printk )
399 p
= (char *)&buf
[sizeof(struct msgtrace_hdr
)];
400 while ((s
= strstr(p
, "\n")) != NULL
) {
402 printk(KERN_DEBUG
"%s\n", p
);
405 printk(KERN_DEBUG
"%s\n", p
);
407 /* Reset datalen to avoid display below */
412 brcmf_dbg(EVENT
, "MACEVENT: %s %d\n",
413 event_name
, be32_to_cpu(*((__be32
*)event_data
)));
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
);
424 /* show any appended data */
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");
436 brcmf_c_host_event(struct brcmf_pub
*drvr
, int *ifidx
, void *pktdata
,
437 struct brcmf_event_msg
*event
, void **data_ptr
)
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
;
447 if (memcmp(BRCM_OUI
, &pvt_data
->hdr
.oui
[0], DOT11_OUI_LEN
)) {
448 brcmf_dbg(ERROR
, "mismatched OUI, bailing\n");
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");
459 *data_ptr
= &pvt_data
[1];
460 event_data
= *data_ptr
;
462 /* memcpy since BRCM event pkt may be unaligned. */
463 memcpy(event
, &pvt_data
->msg
, sizeof(struct brcmf_event_msg
));
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
);
473 ifevent
= (struct brcmf_if_event
*) event_data
;
474 brcmf_dbg(TRACE
, "if event\n");
476 if (ifevent
->ifidx
> 0 && ifevent
->ifidx
< BRCMF_MAX_IFS
) {
477 if (ifevent
->action
== BRCMF_E_IF_ADD
)
478 brcmf_add_if(drvr
->dev
, ifevent
->ifidx
,
480 pvt_data
->eth
.h_dest
);
482 brcmf_del_if(drvr
, ifevent
->ifidx
);
484 brcmf_dbg(ERROR
, "Invalid ifidx %d for %s\n",
485 ifevent
->ifidx
, event
->ifname
);
488 /* send up the if event: btamp user needs it */
489 *ifidx
= brcmf_ifname2idx(drvr
, event
->ifname
);
492 /* These are what external supplicant/authenticator wants */
494 case BRCMF_E_ASSOC_IND
:
495 case BRCMF_E_REASSOC_IND
:
496 case BRCMF_E_DISASSOC_IND
:
497 case BRCMF_E_MIC_ERROR
:
499 /* Fall through: this should get _everything_ */
501 *ifidx
= brcmf_ifname2idx(drvr
, event
->ifname
);
502 brcmf_dbg(TRACE
, "MAC event %d, flags %x, status %x\n",
503 type
, flags
, status
);
505 /* put it back to BRCMF_E_NDIS_LINK */
506 if (type
== BRCMF_E_NDIS_LINK
) {
510 temp1
= get_unaligned_be32(&event
->event_type
);
511 brcmf_dbg(TRACE
, "Converted to WLC_E_LINK type %d\n",
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
));
522 brcmf_c_show_host_event(event
, event_data
);
528 /* Convert user's input in hex pattern to byte-size mask */
529 static int brcmf_c_pattern_atoh(char *src
, char *dst
)
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");
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");
541 for (i
= 0; *src
!= '\0'; i
++) {
544 strncpy(num
, src
, 2);
546 if (kstrtoul(num
, 16, &res
))
555 brcmf_c_pktfilter_offload_enable(struct brcmf_pub
*drvr
, char *arg
, int enable
,
564 char *arg_save
= NULL
, *arg_org
= NULL
;
567 struct brcmf_pkt_filter_enable_le enable_parm
;
568 struct brcmf_pkt_filter_enable_le
*pkt_filterp
;
571 arg_save
= kmalloc(strlen(arg
) + 1, GFP_ATOMIC
);
576 memcpy(arg_save
, arg
, strlen(arg
) + 1);
578 argv
[i
] = strsep(&arg_save
, " ");
581 if (NULL
== argv
[i
]) {
582 brcmf_dbg(ERROR
, "No args provided\n");
586 str
= "pkt_filter_enable";
587 str_len
= strlen(str
);
588 strncpy(buf
, str
, str_len
);
590 buf_len
= str_len
+ 1;
592 pkt_filterp
= (struct brcmf_pkt_filter_enable_le
*) (buf
+ str_len
+ 1);
594 /* Parse packet filter id. */
596 if (!kstrtoul(argv
[i
], 0, &res
))
597 enable_parm
.id
= cpu_to_le32((u32
)res
);
599 /* Parse enable/disable value. */
600 enable_parm
.enable
= cpu_to_le32(enable
);
602 buf_len
+= sizeof(enable_parm
);
603 memcpy((char *)pkt_filterp
, &enable_parm
, sizeof(enable_parm
));
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
;
609 brcmf_dbg(TRACE
, "failed to add pktfilter %s, retcode = %d\n",
612 brcmf_dbg(TRACE
, "successfully added pktfilter %s\n", arg
);
614 /* Contorl the master mode */
615 mmode_le
= cpu_to_le32(master_mode
);
616 brcmf_c_mkiovar("pkt_filter_mode", (char *)&mmode_le
, 4, buf
,
618 rc
= brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
, buf
,
620 rc
= rc
>= 0 ? 0 : rc
;
622 brcmf_dbg(TRACE
, "failed to add pktfilter %s, retcode = %d\n",
629 void brcmf_c_pktfilter_offload_set(struct brcmf_pub
*drvr
, char *arg
)
632 struct brcmf_pkt_filter_le pkt_filter
;
633 struct brcmf_pkt_filter_le
*pkt_filterp
;
640 char *argv
[8], *buf
= NULL
;
642 char *arg_save
= NULL
, *arg_org
= NULL
;
644 arg_save
= kstrdup(arg
, GFP_ATOMIC
);
650 buf
= kmalloc(PKTFILTER_BUF_SIZE
, GFP_ATOMIC
);
654 argv
[i
] = strsep(&arg_save
, " ");
656 argv
[i
] = strsep(&arg_save
, " ");
659 if (NULL
== argv
[i
]) {
660 brcmf_dbg(ERROR
, "No args provided\n");
664 str
= "pkt_filter_add";
666 str_len
= strlen(str
);
667 buf_len
= str_len
+ 1;
669 pkt_filterp
= (struct brcmf_pkt_filter_le
*) (buf
+ str_len
+ 1);
671 /* Parse packet filter id. */
673 if (!kstrtoul(argv
[i
], 0, &res
))
674 pkt_filter
.id
= cpu_to_le32((u32
)res
);
676 if (NULL
== argv
[++i
]) {
677 brcmf_dbg(ERROR
, "Polarity not provided\n");
681 /* Parse filter polarity. */
682 pkt_filter
.negate_match
= 0;
683 if (!kstrtoul(argv
[i
], 0, &res
))
684 pkt_filter
.negate_match
= cpu_to_le32((u32
)res
);
686 if (NULL
== argv
[++i
]) {
687 brcmf_dbg(ERROR
, "Filter type not provided\n");
691 /* Parse filter type. */
693 if (!kstrtoul(argv
[i
], 0, &res
))
694 pkt_filter
.type
= cpu_to_le32((u32
)res
);
696 if (NULL
== argv
[++i
]) {
697 brcmf_dbg(ERROR
, "Offset not provided\n");
701 /* Parse pattern filter offset. */
702 pkt_filter
.u
.pattern
.offset
= 0;
703 if (!kstrtoul(argv
[i
], 0, &res
))
704 pkt_filter
.u
.pattern
.offset
= cpu_to_le32((u32
)res
);
706 if (NULL
== argv
[++i
]) {
707 brcmf_dbg(ERROR
, "Bitmask not provided\n");
711 /* Parse pattern filter mask. */
714 (argv
[i
], (char *)pkt_filterp
->u
.pattern
.mask_and_pattern
);
716 if (NULL
== argv
[++i
]) {
717 brcmf_dbg(ERROR
, "Pattern not provided\n");
721 /* Parse pattern filter pattern. */
723 brcmf_c_pattern_atoh(argv
[i
],
724 (char *)&pkt_filterp
->u
.pattern
.
725 mask_and_pattern
[mask_size
]);
727 if (mask_size
!= pattern_size
) {
728 brcmf_dbg(ERROR
, "Mask and pattern not the same size\n");
732 pkt_filter
.u
.pattern
.size_bytes
= cpu_to_le32(mask_size
);
733 buf_len
+= BRCMF_PKT_FILTER_FIXED_LEN
;
734 buf_len
+= (BRCMF_PKT_FILTER_PATTERN_FIXED_LEN
+ 2 * mask_size
);
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.
741 memcpy((char *)pkt_filterp
,
743 BRCMF_PKT_FILTER_FIXED_LEN
+ BRCMF_PKT_FILTER_PATTERN_FIXED_LEN
);
745 rc
= brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
, buf
, buf_len
);
746 rc
= rc
>= 0 ? 0 : rc
;
749 brcmf_dbg(TRACE
, "failed to add pktfilter %s, retcode = %d\n",
752 brcmf_dbg(TRACE
, "successfully added pktfilter %s\n", arg
);
760 static void brcmf_c_arp_offload_set(struct brcmf_pub
*drvr
, int arp_mode
)
765 brcmf_c_mkiovar("arp_ol", (char *)&arp_mode
, 4, iovbuf
, sizeof(iovbuf
));
766 retcode
= brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
,
767 iovbuf
, sizeof(iovbuf
));
768 retcode
= retcode
>= 0 ? 0 : retcode
;
770 brcmf_dbg(TRACE
, "failed to set ARP offload mode to 0x%x, retcode = %d\n",
773 brcmf_dbg(TRACE
, "successfully set ARP offload mode to 0x%x\n",
777 static void brcmf_c_arp_offload_enable(struct brcmf_pub
*drvr
, int arp_enable
)
782 brcmf_c_mkiovar("arpoe", (char *)&arp_enable
, 4,
783 iovbuf
, sizeof(iovbuf
));
784 retcode
= brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
,
785 iovbuf
, sizeof(iovbuf
));
786 retcode
= retcode
>= 0 ? 0 : retcode
;
788 brcmf_dbg(TRACE
, "failed to enable ARP offload to %d, retcode = %d\n",
789 arp_enable
, retcode
);
791 brcmf_dbg(TRACE
, "successfully enabled ARP offload to %d\n",
795 int brcmf_c_preinit_dcmds(struct brcmf_pub
*drvr
)
797 char iovbuf
[BRCMF_EVENTING_MASK_LEN
+ 12]; /* Room for
798 "event_msgs" + '\0' + bitvec */
801 u32 dongle_align
= drvr
->bus_if
->align
;
804 uint bcn_timeout
= 3;
805 int scan_assoc_time
= 40;
806 int scan_unassoc_time
= 40;
809 mutex_lock(&drvr
->proto_block
);
811 /* Set Country code */
812 if (drvr
->country_code
[0] != 0) {
813 if (brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_COUNTRY
,
815 sizeof(drvr
->country_code
)) < 0)
816 brcmf_dbg(ERROR
, "country code setting failed\n");
819 /* query for 'ver' to get version info from firmware */
820 memset(buf
, 0, sizeof(buf
));
822 brcmf_c_mkiovar("ver", NULL
, 0, buf
, sizeof(buf
));
823 brcmf_proto_cdc_query_dcmd(drvr
, 0, BRCMF_C_GET_VAR
, buf
, sizeof(buf
));
825 /* Print fw version info */
826 brcmf_dbg(ERROR
, "Firmware version = %s\n", buf
);
828 /* Match Host and Dongle rx alignment */
829 brcmf_c_mkiovar("bus:txglomalign", (char *)&dongle_align
, 4, iovbuf
,
831 brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
, iovbuf
,
834 /* disable glom option per default */
835 brcmf_c_mkiovar("bus:txglom", (char *)&glom
, 4, iovbuf
, sizeof(iovbuf
));
836 brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
, iovbuf
,
839 /* Setup timeout if Beacons are lost and roam is off to report
841 brcmf_c_mkiovar("bcn_timeout", (char *)&bcn_timeout
, 4, iovbuf
,
843 brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
, iovbuf
,
846 /* Enable/Disable build-in roaming to allowed ext supplicant to take
848 brcmf_c_mkiovar("roam_off", (char *)&roaming
, 4,
849 iovbuf
, sizeof(iovbuf
));
850 brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
, iovbuf
,
854 brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_UP
, (char *)&up
, sizeof(up
));
856 /* Setup event_msgs */
857 brcmf_c_mkiovar("event_msgs", drvr
->eventmask
, BRCMF_EVENTING_MASK_LEN
,
858 iovbuf
, sizeof(iovbuf
));
859 brcmf_proto_cdc_set_dcmd(drvr
, 0, BRCMF_C_SET_VAR
, iovbuf
,
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
));
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);
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
],
878 mutex_unlock(&drvr
->proto_block
);