2 * Copyright (c) 2012 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.
21 #include <asm/unaligned.h>
22 #include <linux/skbuff.h>
23 #include <linux/if_ether.h>
26 /* formward declarations */
29 struct brcmf_cfg80211_info;
31 /* list of firmware events */
32 #define BRCMF_FWEH_EVENT_ENUM_DEFLIST \
33 BRCMF_ENUM_DEF(SET_SSID, 0) \
34 BRCMF_ENUM_DEF(JOIN, 1) \
35 BRCMF_ENUM_DEF(START, 2) \
36 BRCMF_ENUM_DEF(AUTH, 3) \
37 BRCMF_ENUM_DEF(AUTH_IND, 4) \
38 BRCMF_ENUM_DEF(DEAUTH, 5) \
39 BRCMF_ENUM_DEF(DEAUTH_IND, 6) \
40 BRCMF_ENUM_DEF(ASSOC, 7) \
41 BRCMF_ENUM_DEF(ASSOC_IND, 8) \
42 BRCMF_ENUM_DEF(REASSOC, 9) \
43 BRCMF_ENUM_DEF(REASSOC_IND, 10) \
44 BRCMF_ENUM_DEF(DISASSOC, 11) \
45 BRCMF_ENUM_DEF(DISASSOC_IND, 12) \
46 BRCMF_ENUM_DEF(QUIET_START, 13) \
47 BRCMF_ENUM_DEF(QUIET_END, 14) \
48 BRCMF_ENUM_DEF(BEACON_RX, 15) \
49 BRCMF_ENUM_DEF(LINK, 16) \
50 BRCMF_ENUM_DEF(MIC_ERROR, 17) \
51 BRCMF_ENUM_DEF(NDIS_LINK, 18) \
52 BRCMF_ENUM_DEF(ROAM, 19) \
53 BRCMF_ENUM_DEF(TXFAIL, 20) \
54 BRCMF_ENUM_DEF(PMKID_CACHE, 21) \
55 BRCMF_ENUM_DEF(RETROGRADE_TSF, 22) \
56 BRCMF_ENUM_DEF(PRUNE, 23) \
57 BRCMF_ENUM_DEF(AUTOAUTH, 24) \
58 BRCMF_ENUM_DEF(EAPOL_MSG, 25) \
59 BRCMF_ENUM_DEF(SCAN_COMPLETE, 26) \
60 BRCMF_ENUM_DEF(ADDTS_IND, 27) \
61 BRCMF_ENUM_DEF(DELTS_IND, 28) \
62 BRCMF_ENUM_DEF(BCNSENT_IND, 29) \
63 BRCMF_ENUM_DEF(BCNRX_MSG, 30) \
64 BRCMF_ENUM_DEF(BCNLOST_MSG, 31) \
65 BRCMF_ENUM_DEF(ROAM_PREP, 32) \
66 BRCMF_ENUM_DEF(PFN_NET_FOUND, 33) \
67 BRCMF_ENUM_DEF(PFN_NET_LOST, 34) \
68 BRCMF_ENUM_DEF(RESET_COMPLETE, 35) \
69 BRCMF_ENUM_DEF(JOIN_START, 36) \
70 BRCMF_ENUM_DEF(ROAM_START, 37) \
71 BRCMF_ENUM_DEF(ASSOC_START, 38) \
72 BRCMF_ENUM_DEF(IBSS_ASSOC, 39) \
73 BRCMF_ENUM_DEF(RADIO, 40) \
74 BRCMF_ENUM_DEF(PSM_WATCHDOG, 41) \
75 BRCMF_ENUM_DEF(PROBREQ_MSG, 44) \
76 BRCMF_ENUM_DEF(SCAN_CONFIRM_IND, 45) \
77 BRCMF_ENUM_DEF(PSK_SUP, 46) \
78 BRCMF_ENUM_DEF(COUNTRY_CODE_CHANGED, 47) \
79 BRCMF_ENUM_DEF(EXCEEDED_MEDIUM_TIME, 48) \
80 BRCMF_ENUM_DEF(ICV_ERROR, 49) \
81 BRCMF_ENUM_DEF(UNICAST_DECODE_ERROR, 50) \
82 BRCMF_ENUM_DEF(MULTICAST_DECODE_ERROR, 51) \
83 BRCMF_ENUM_DEF(TRACE, 52) \
84 BRCMF_ENUM_DEF(IF, 54) \
85 BRCMF_ENUM_DEF(P2P_DISC_LISTEN_COMPLETE, 55) \
86 BRCMF_ENUM_DEF(RSSI, 56) \
87 BRCMF_ENUM_DEF(EXTLOG_MSG, 58) \
88 BRCMF_ENUM_DEF(ACTION_FRAME, 59) \
89 BRCMF_ENUM_DEF(ACTION_FRAME_COMPLETE, 60) \
90 BRCMF_ENUM_DEF(PRE_ASSOC_IND, 61) \
91 BRCMF_ENUM_DEF(PRE_REASSOC_IND, 62) \
92 BRCMF_ENUM_DEF(CHANNEL_ADOPTED, 63) \
93 BRCMF_ENUM_DEF(AP_STARTED, 64) \
94 BRCMF_ENUM_DEF(DFS_AP_STOP, 65) \
95 BRCMF_ENUM_DEF(DFS_AP_RESUME, 66) \
96 BRCMF_ENUM_DEF(ESCAN_RESULT, 69) \
97 BRCMF_ENUM_DEF(ACTION_FRAME_OFF_CHAN_COMPLETE, 70) \
98 BRCMF_ENUM_DEF(PROBERESP_MSG, 71) \
99 BRCMF_ENUM_DEF(P2P_PROBEREQ_MSG, 72) \
100 BRCMF_ENUM_DEF(DCS_REQUEST, 73) \
101 BRCMF_ENUM_DEF(FIFO_CREDIT_MAP, 74) \
102 BRCMF_ENUM_DEF(ACTION_FRAME_RX, 75) \
103 BRCMF_ENUM_DEF(TDLS_PEER_EVENT, 92) \
104 BRCMF_ENUM_DEF(BCMC_CREDIT_SUPPORT, 127)
106 #define BRCMF_ENUM_DEF(id, val) \
107 BRCMF_E_##id = (val),
109 /* firmware event codes sent by the dongle */
110 enum brcmf_fweh_event_code {
111 BRCMF_FWEH_EVENT_ENUM_DEFLIST
112 /* this determines event mask length which must match
113 * minimum length check in device firmware so it is
118 #undef BRCMF_ENUM_DEF
120 #define BRCMF_EVENTING_MASK_LEN DIV_ROUND_UP(BRCMF_E_LAST, 8)
122 /* flags field values in struct brcmf_event_msg */
123 #define BRCMF_EVENT_MSG_LINK 0x01
124 #define BRCMF_EVENT_MSG_FLUSHTXQ 0x02
125 #define BRCMF_EVENT_MSG_GROUP 0x04
127 /* status field values in struct brcmf_event_msg */
128 #define BRCMF_E_STATUS_SUCCESS 0
129 #define BRCMF_E_STATUS_FAIL 1
130 #define BRCMF_E_STATUS_TIMEOUT 2
131 #define BRCMF_E_STATUS_NO_NETWORKS 3
132 #define BRCMF_E_STATUS_ABORT 4
133 #define BRCMF_E_STATUS_NO_ACK 5
134 #define BRCMF_E_STATUS_UNSOLICITED 6
135 #define BRCMF_E_STATUS_ATTEMPT 7
136 #define BRCMF_E_STATUS_PARTIAL 8
137 #define BRCMF_E_STATUS_NEWSCAN 9
138 #define BRCMF_E_STATUS_NEWASSOC 10
139 #define BRCMF_E_STATUS_11HQUIET 11
140 #define BRCMF_E_STATUS_SUPPRESS 12
141 #define BRCMF_E_STATUS_NOCHANS 13
142 #define BRCMF_E_STATUS_CS_ABORT 15
143 #define BRCMF_E_STATUS_ERROR 16
145 /* reason field values in struct brcmf_event_msg */
146 #define BRCMF_E_REASON_INITIAL_ASSOC 0
147 #define BRCMF_E_REASON_LOW_RSSI 1
148 #define BRCMF_E_REASON_DEAUTH 2
149 #define BRCMF_E_REASON_DISASSOC 3
150 #define BRCMF_E_REASON_BCNS_LOST 4
151 #define BRCMF_E_REASON_MINTXRATE 9
152 #define BRCMF_E_REASON_TXFAIL 10
154 #define BRCMF_E_REASON_LINK_BSSCFG_DIS 4
155 #define BRCMF_E_REASON_FAST_ROAM_FAILED 5
156 #define BRCMF_E_REASON_DIRECTED_ROAM 6
157 #define BRCMF_E_REASON_TSPEC_REJECTED 7
158 #define BRCMF_E_REASON_BETTER_AP 8
160 #define BRCMF_E_REASON_TDLS_PEER_DISCOVERED 0
161 #define BRCMF_E_REASON_TDLS_PEER_CONNECTED 1
162 #define BRCMF_E_REASON_TDLS_PEER_DISCONNECTED 2
164 /* action field values for brcmf_ifevent */
165 #define BRCMF_E_IF_ADD 1
166 #define BRCMF_E_IF_DEL 2
167 #define BRCMF_E_IF_CHANGE 3
169 /* flag field values for brcmf_ifevent */
170 #define BRCMF_E_IF_FLAG_NOIF 1
172 /* role field values for brcmf_ifevent */
173 #define BRCMF_E_IF_ROLE_STA 0
174 #define BRCMF_E_IF_ROLE_AP 1
175 #define BRCMF_E_IF_ROLE_WDS 2
176 #define BRCMF_E_IF_ROLE_P2P_GO 3
177 #define BRCMF_E_IF_ROLE_P2P_CLIENT 4
180 * definitions for event packet validation.
182 #define BRCM_OUI "\x00\x10\x18"
183 #define BCMILCP_BCM_SUBTYPE_EVENT 1
184 #define BCMILCP_SUBTYPE_VENDOR_LONG 32769
187 * struct brcm_ethhdr - broadcom specific ether header.
189 * @subtype: subtype for this packet.
190 * @length: TODO: length of appended data.
191 * @version: version indication.
192 * @oui: OUI of this packet.
193 * @usr_subtype: subtype for this OUI.
203 struct brcmf_event_msg_be {
212 char ifname[IFNAMSIZ];
218 * struct brcmf_event - contents of broadcom event packet.
220 * @eth: standard ether header.
221 * @hdr: broadcom specific ether header.
222 * @msg: common part of the actual event message.
226 struct brcm_ethhdr hdr;
227 struct brcmf_event_msg_be msg;
231 * struct brcmf_event_msg - firmware event message.
233 * @version: version information.
234 * @flags: event flags.
235 * @event_code: firmware event code.
236 * @status: status information.
237 * @reason: reason code.
238 * @auth_type: authentication type.
239 * @datalen: lenght of event data buffer.
240 * @addr: ether address.
241 * @ifname: interface name.
242 * @ifidx: interface index.
243 * @bsscfgidx: bsscfg index.
245 struct brcmf_event_msg {
254 char ifname[IFNAMSIZ];
259 struct brcmf_if_event {
267 typedef int (*brcmf_fweh_handler_t)(struct brcmf_if *ifp,
268 const struct brcmf_event_msg *evtmsg,
272 * struct brcmf_fweh_info - firmware event handling information.
274 * @p2pdev_setup_ongoing: P2P device creation in progress.
275 * @event_work: event worker.
276 * @evt_q_lock: lock for event queue protection.
277 * @event_q: event queue.
278 * @evt_handler: registered event handlers.
280 struct brcmf_fweh_info {
281 bool p2pdev_setup_ongoing;
282 struct work_struct event_work;
283 spinlock_t evt_q_lock;
284 struct list_head event_q;
285 int (*evt_handler[BRCMF_E_LAST])(struct brcmf_if *ifp,
286 const struct brcmf_event_msg *evtmsg,
290 void brcmf_fweh_attach(struct brcmf_pub *drvr);
291 void brcmf_fweh_detach(struct brcmf_pub *drvr);
292 int brcmf_fweh_register(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code,
293 int (*handler)(struct brcmf_if *ifp,
294 const struct brcmf_event_msg *evtmsg,
296 void brcmf_fweh_unregister(struct brcmf_pub *drvr,
297 enum brcmf_fweh_event_code code);
298 int brcmf_fweh_activate_events(struct brcmf_if *ifp);
299 void brcmf_fweh_process_event(struct brcmf_pub *drvr,
300 struct brcmf_event *event_packet,
302 void brcmf_fweh_p2pdev_setup(struct brcmf_if *ifp, bool ongoing);
304 static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr,
305 struct sk_buff *skb, u16 stype)
307 struct brcmf_event *event_packet;
308 u16 subtype, usr_stype;
310 /* only process events when protocol matches */
311 if (skb->protocol != cpu_to_be16(ETH_P_LINK_CTL))
314 if ((skb->len + ETH_HLEN) < sizeof(*event_packet))
317 event_packet = (struct brcmf_event *)skb_mac_header(skb);
319 /* check subtype if needed */
320 if (unlikely(stype)) {
321 subtype = get_unaligned_be16(&event_packet->hdr.subtype);
322 if (subtype != stype)
326 /* check for BRCM oui match */
327 if (memcmp(BRCM_OUI, &event_packet->hdr.oui[0],
328 sizeof(event_packet->hdr.oui)))
331 /* final match on usr_subtype */
332 usr_stype = get_unaligned_be16(&event_packet->hdr.usr_subtype);
333 if (usr_stype != BCMILCP_BCM_SUBTYPE_EVENT)
336 brcmf_fweh_process_event(drvr, event_packet, skb->len + ETH_HLEN);