1 // SPDX-License-Identifier: ISC
2 /*
3 * Copyright (c) 2012 Broadcom Corporation
4 */
5
6
7 #ifndef FWEH_H_
8 #define FWEH_H_
9
10 #include <linux/unaligned.h>
11 #include <linux/skbuff.h>
12 #include <linux/if_ether.h>
13 #include <linux/if.h>
14
15 /* formward declarations */
16 struct brcmf_pub;
17 struct brcmf_if;
18 struct brcmf_cfg80211_info;
19
20 #define BRCMF_ABSTRACT_EVENT_BIT BIT(31)
21 #define BRCMF_ABSTRACT_ENUM_DEF(_id, _val) \
22 BRCMF_ENUM_DEF(_id, (BRCMF_ABSTRACT_EVENT_BIT | (_val)))
23
24 /* list of firmware events */
25 #define BRCMF_FWEH_EVENT_ENUM_DEFLIST \
26 BRCMF_ENUM_DEF(SET_SSID, 0) \
27 BRCMF_ENUM_DEF(JOIN, 1) \
28 BRCMF_ENUM_DEF(START, 2) \
29 BRCMF_ENUM_DEF(AUTH, 3) \
30 BRCMF_ENUM_DEF(AUTH_IND, 4) \
31 BRCMF_ENUM_DEF(DEAUTH, 5) \
32 BRCMF_ENUM_DEF(DEAUTH_IND, 6) \
33 BRCMF_ENUM_DEF(ASSOC, 7) \
34 BRCMF_ENUM_DEF(ASSOC_IND, 8) \
35 BRCMF_ENUM_DEF(REASSOC, 9) \
36 BRCMF_ENUM_DEF(REASSOC_IND, 10) \
37 BRCMF_ENUM_DEF(DISASSOC, 11) \
38 BRCMF_ENUM_DEF(DISASSOC_IND, 12) \
39 BRCMF_ENUM_DEF(QUIET_START, 13) \
40 BRCMF_ENUM_DEF(QUIET_END, 14) \
41 BRCMF_ENUM_DEF(BEACON_RX, 15) \
42 BRCMF_ENUM_DEF(LINK, 16) \
43 BRCMF_ENUM_DEF(MIC_ERROR, 17) \
44 BRCMF_ENUM_DEF(NDIS_LINK, 18) \
45 BRCMF_ENUM_DEF(ROAM, 19) \
46 BRCMF_ENUM_DEF(TXFAIL, 20) \
47 BRCMF_ENUM_DEF(PMKID_CACHE, 21) \
48 BRCMF_ENUM_DEF(RETROGRADE_TSF, 22) \
49 BRCMF_ENUM_DEF(PRUNE, 23) \
50 BRCMF_ENUM_DEF(AUTOAUTH, 24) \
51 BRCMF_ENUM_DEF(EAPOL_MSG, 25) \
52 BRCMF_ENUM_DEF(SCAN_COMPLETE, 26) \
53 BRCMF_ENUM_DEF(ADDTS_IND, 27) \
54 BRCMF_ENUM_DEF(DELTS_IND, 28) \
55 BRCMF_ENUM_DEF(BCNSENT_IND, 29) \
56 BRCMF_ENUM_DEF(BCNRX_MSG, 30) \
57 BRCMF_ENUM_DEF(BCNLOST_MSG, 31) \
58 BRCMF_ENUM_DEF(ROAM_PREP, 32) \
59 BRCMF_ENUM_DEF(PFN_NET_FOUND, 33) \
60 BRCMF_ENUM_DEF(PFN_NET_LOST, 34) \
61 BRCMF_ENUM_DEF(RESET_COMPLETE, 35) \
62 BRCMF_ENUM_DEF(JOIN_START, 36) \
63 BRCMF_ENUM_DEF(ROAM_START, 37) \
64 BRCMF_ENUM_DEF(ASSOC_START, 38) \
65 BRCMF_ENUM_DEF(IBSS_ASSOC, 39) \
66 BRCMF_ENUM_DEF(RADIO, 40) \
67 BRCMF_ENUM_DEF(PSM_WATCHDOG, 41) \
68 BRCMF_ENUM_DEF(PROBREQ_MSG, 44) \
69 BRCMF_ENUM_DEF(SCAN_CONFIRM_IND, 45) \
70 BRCMF_ENUM_DEF(PSK_SUP, 46) \
71 BRCMF_ENUM_DEF(COUNTRY_CODE_CHANGED, 47) \
72 BRCMF_ENUM_DEF(EXCEEDED_MEDIUM_TIME, 48) \
73 BRCMF_ENUM_DEF(ICV_ERROR, 49) \
74 BRCMF_ENUM_DEF(UNICAST_DECODE_ERROR, 50) \
75 BRCMF_ENUM_DEF(MULTICAST_DECODE_ERROR, 51) \
76 BRCMF_ENUM_DEF(TRACE, 52) \
77 BRCMF_ENUM_DEF(IF, 54) \
78 BRCMF_ENUM_DEF(P2P_DISC_LISTEN_COMPLETE, 55) \
79 BRCMF_ENUM_DEF(RSSI, 56) \
80 BRCMF_ENUM_DEF(EXTLOG_MSG, 58) \
81 BRCMF_ENUM_DEF(ACTION_FRAME, 59) \
82 BRCMF_ENUM_DEF(ACTION_FRAME_COMPLETE, 60) \
83 BRCMF_ENUM_DEF(PRE_ASSOC_IND, 61) \
84 BRCMF_ENUM_DEF(PRE_REASSOC_IND, 62) \
85 BRCMF_ENUM_DEF(CHANNEL_ADOPTED, 63) \
86 BRCMF_ENUM_DEF(AP_STARTED, 64) \
87 BRCMF_ENUM_DEF(DFS_AP_STOP, 65) \
88 BRCMF_ENUM_DEF(DFS_AP_RESUME, 66) \
89 BRCMF_ENUM_DEF(ESCAN_RESULT, 69) \
90 BRCMF_ENUM_DEF(ACTION_FRAME_OFF_CHAN_COMPLETE, 70) \
91 BRCMF_ENUM_DEF(PROBERESP_MSG, 71) \
92 BRCMF_ENUM_DEF(P2P_PROBEREQ_MSG, 72) \
93 BRCMF_ENUM_DEF(DCS_REQUEST, 73) \
94 BRCMF_ENUM_DEF(FIFO_CREDIT_MAP, 74) \
95 BRCMF_ENUM_DEF(ACTION_FRAME_RX, 75) \
96 BRCMF_ENUM_DEF(TDLS_PEER_EVENT, 92) \
97 BRCMF_ENUM_DEF(BCMC_CREDIT_SUPPORT, 127)
98
99 #define BRCMF_ENUM_DEF(id, val) \
100 BRCMF_E_##id = (val),
101
102 /* firmware event codes sent by the dongle */
103 enum brcmf_fweh_event_code {
104 BRCMF_FWEH_EVENT_ENUM_DEFLIST
105 };
106 #undef BRCMF_ENUM_DEF
107
108 /* flags field values in struct brcmf_event_msg */
109 #define BRCMF_EVENT_MSG_LINK 0x01
110 #define BRCMF_EVENT_MSG_FLUSHTXQ 0x02
111 #define BRCMF_EVENT_MSG_GROUP 0x04
112
113 /* status field values in struct brcmf_event_msg */
114 #define BRCMF_E_STATUS_SUCCESS 0
115 #define BRCMF_E_STATUS_FAIL 1
116 #define BRCMF_E_STATUS_TIMEOUT 2
117 #define BRCMF_E_STATUS_NO_NETWORKS 3
118 #define BRCMF_E_STATUS_ABORT 4
119 #define BRCMF_E_STATUS_NO_ACK 5
120 #define BRCMF_E_STATUS_UNSOLICITED 6
121 #define BRCMF_E_STATUS_ATTEMPT 7
122 #define BRCMF_E_STATUS_PARTIAL 8
123 #define BRCMF_E_STATUS_NEWSCAN 9
124 #define BRCMF_E_STATUS_NEWASSOC 10
125 #define BRCMF_E_STATUS_11HQUIET 11
126 #define BRCMF_E_STATUS_SUPPRESS 12
127 #define BRCMF_E_STATUS_NOCHANS 13
128 #define BRCMF_E_STATUS_CS_ABORT 15
129 #define BRCMF_E_STATUS_ERROR 16
130
131 /* status field values for PSK_SUP event */
132 #define BRCMF_E_STATUS_FWSUP_WAIT_M1 4
133 #define BRCMF_E_STATUS_FWSUP_PREP_M2 5
134 #define BRCMF_E_STATUS_FWSUP_COMPLETED 6
135 #define BRCMF_E_STATUS_FWSUP_TIMEOUT 7
136 #define BRCMF_E_STATUS_FWSUP_WAIT_M3 8
137 #define BRCMF_E_STATUS_FWSUP_PREP_M4 9
138 #define BRCMF_E_STATUS_FWSUP_WAIT_G1 10
139 #define BRCMF_E_STATUS_FWSUP_PREP_G2 11
140
141 /* reason field values in struct brcmf_event_msg */
142 #define BRCMF_E_REASON_INITIAL_ASSOC 0
143 #define BRCMF_E_REASON_LOW_RSSI 1
144 #define BRCMF_E_REASON_DEAUTH 2
145 #define BRCMF_E_REASON_DISASSOC 3
146 #define BRCMF_E_REASON_BCNS_LOST 4
147 #define BRCMF_E_REASON_MINTXRATE 9
148 #define BRCMF_E_REASON_TXFAIL 10
149
150 #define BRCMF_E_REASON_LINK_BSSCFG_DIS 4
151 #define BRCMF_E_REASON_FAST_ROAM_FAILED 5
152 #define BRCMF_E_REASON_DIRECTED_ROAM 6
153 #define BRCMF_E_REASON_TSPEC_REJECTED 7
154 #define BRCMF_E_REASON_BETTER_AP 8
155
156 #define BRCMF_E_REASON_TDLS_PEER_DISCOVERED 0
157 #define BRCMF_E_REASON_TDLS_PEER_CONNECTED 1
158 #define BRCMF_E_REASON_TDLS_PEER_DISCONNECTED 2
159
160 /* reason field values for PSK_SUP event */
161 #define BRCMF_E_REASON_FWSUP_OTHER 0
162 #define BRCMF_E_REASON_FWSUP_DECRYPT_KEY_DATA 1
163 #define BRCMF_E_REASON_FWSUP_BAD_UCAST_WEP128 2
164 #define BRCMF_E_REASON_FWSUP_BAD_UCAST_WEP40 3
165 #define BRCMF_E_REASON_FWSUP_UNSUP_KEY_LEN 4
166 #define BRCMF_E_REASON_FWSUP_PW_KEY_CIPHER 5
167 #define BRCMF_E_REASON_FWSUP_MSG3_TOO_MANY_IE 6
168 #define BRCMF_E_REASON_FWSUP_MSG3_IE_MISMATCH 7
169 #define BRCMF_E_REASON_FWSUP_NO_INSTALL_FLAG 8
170 #define BRCMF_E_REASON_FWSUP_MSG3_NO_GTK 9
171 #define BRCMF_E_REASON_FWSUP_GRP_KEY_CIPHER 10
172 #define BRCMF_E_REASON_FWSUP_GRP_MSG1_NO_GTK 11
173 #define BRCMF_E_REASON_FWSUP_GTK_DECRYPT_FAIL 12
174 #define BRCMF_E_REASON_FWSUP_SEND_FAIL 13
175 #define BRCMF_E_REASON_FWSUP_DEAUTH 14
176 #define BRCMF_E_REASON_FWSUP_WPA_PSK_TMO 15
177 #define BRCMF_E_REASON_FWSUP_WPA_PSK_M1_TMO 16
178 #define BRCMF_E_REASON_FWSUP_WPA_PSK_M3_TMO 17
179
180 /* action field values for brcmf_ifevent */
181 #define BRCMF_E_IF_ADD 1
182 #define BRCMF_E_IF_DEL 2
183 #define BRCMF_E_IF_CHANGE 3
184
185 /* flag field values for brcmf_ifevent */
186 #define BRCMF_E_IF_FLAG_NOIF 1
187
188 /* role field values for brcmf_ifevent */
189 #define BRCMF_E_IF_ROLE_STA 0
190 #define BRCMF_E_IF_ROLE_AP 1
191 #define BRCMF_E_IF_ROLE_WDS 2
192 #define BRCMF_E_IF_ROLE_P2P_GO 3
193 #define BRCMF_E_IF_ROLE_P2P_CLIENT 4
194
195 /**
196 * definitions for event packet validation.
197 */
198 #define BRCM_OUI "\x00\x10\x18"
199 #define BCMILCP_BCM_SUBTYPE_EVENT 1
200 #define BCMILCP_SUBTYPE_VENDOR_LONG 32769
201
202 /**
203 * struct brcm_ethhdr - broadcom specific ether header.
204 *
205 * @subtype: subtype for this packet.
206 * @length: TODO: length of appended data.
207 * @version: version indication.
208 * @oui: OUI of this packet.
209 * @usr_subtype: subtype for this OUI.
210 */
211 struct brcm_ethhdr {
212 __be16 subtype;
213 __be16 length;
214 u8 version;
215 u8 oui[3];
216 __be16 usr_subtype;
217 } __packed;
218
219 struct brcmf_event_msg_be {
220 __be16 version;
221 __be16 flags;
222 __be32 event_type;
223 __be32 status;
224 __be32 reason;
225 __be32 auth_type;
226 __be32 datalen;
227 u8 addr[ETH_ALEN];
228 char ifname[IFNAMSIZ];
229 u8 ifidx;
230 u8 bsscfgidx;
231 } __packed;
232
233 /**
234 * struct brcmf_event - contents of broadcom event packet.
235 *
236 * @eth: standard ether header.
237 * @hdr: broadcom specific ether header.
238 * @msg: common part of the actual event message.
239 */
240 struct brcmf_event {
241 struct ethhdr eth;
242 struct brcm_ethhdr hdr;
243 struct brcmf_event_msg_be msg;
244 } __packed;
245
246 /**
247 * struct brcmf_event_msg - firmware event message.
248 *
249 * @version: version information.
250 * @flags: event flags.
251 * @event_code: firmware event code.
252 * @status: status information.
253 * @reason: reason code.
254 * @auth_type: authentication type.
255 * @datalen: length of event data buffer.
256 * @addr: ether address.
257 * @ifname: interface name.
258 * @ifidx: interface index.
259 * @bsscfgidx: bsscfg index.
260 */
261 struct brcmf_event_msg {
262 u16 version;
263 u16 flags;
264 u32 event_code;
265 u32 status;
266 u32 reason;
267 s32 auth_type;
268 u32 datalen;
269 u8 addr[ETH_ALEN];
270 char ifname[IFNAMSIZ];
271 u8 ifidx;
272 u8 bsscfgidx;
273 };
274
275 struct brcmf_if_event {
276 u8 ifidx;
277 u8 action;
278 u8 flags;
279 u8 bsscfgidx;
280 u8 role;
281 };
282
283 typedef int (*brcmf_fweh_handler_t)(struct brcmf_if *ifp,
284 const struct brcmf_event_msg *evtmsg,
285 void *data);
286
287 /**
288 * struct brcmf_fweh_event_map_item - fweh event and firmware event pair.
289 *
290 * @code: fweh event code as used by higher layers.
291 * @fwevt_code: firmware event code as used by firmware.
292 *
293 * This mapping is needed when a functionally identical event has a
294 * different numerical definition between vendors. When such mapping
295 * is needed the higher layer event code should not collide with the
296 * firmware event.
297 */
298 struct brcmf_fweh_event_map_item {
299 enum brcmf_fweh_event_code code;
300 u32 fwevt_code;
301 };
302
303 /**
304 * struct brcmf_fweh_event_map - mapping between firmware event and fweh event.
305 *
306 * @n_items: number of mapping items.
307 * @items: array of fweh event and firmware event pairs.
308 */
309 struct brcmf_fweh_event_map {
310 u32 n_items;
311 const struct brcmf_fweh_event_map_item items[] __counted_by(n_items);
312 };
313
314 /**
315 * struct brcmf_fweh_info - firmware event handling information.
316 *
317 * @p2pdev_setup_ongoing: P2P device creation in progress.
318 * @event_work: event worker.
319 * @evt_q_lock: lock for event queue protection.
320 * @event_q: event queue.
321 * @event_mask_len: length of @event_mask used to enable firmware events.
322 * @event_mask: byte array used in 'event_msgs' iovar command.
323 * @event_map: mapping between fweh event and firmware event which
324 * may be provided by vendor-specific module for events that need
325 * mapping.
326 * @num_event_codes: number of firmware events supported by firmware which
327 * does a minimum length check for the @event_mask. This value is to
328 * be provided by vendor-specific module determining @event_mask_len
329 * and consequently the allocation size for @event_mask.
330 * @evt_handler: event handler registry indexed by firmware event code.
331 */
332 struct brcmf_fweh_info {
333 struct brcmf_pub *drvr;
334 bool p2pdev_setup_ongoing;
335 struct work_struct event_work;
336 spinlock_t evt_q_lock;
337 struct list_head event_q;
338 uint event_mask_len;
339 u8 *event_mask;
340 struct brcmf_fweh_event_map *event_map;
341 uint num_event_codes;
342 brcmf_fweh_handler_t evt_handler[] __counted_by(num_event_codes);
343 };
344
345 const char *brcmf_fweh_event_name(enum brcmf_fweh_event_code code);
346
347 int brcmf_fweh_attach(struct brcmf_pub *drvr);
348 void brcmf_fweh_detach(struct brcmf_pub *drvr);
349 int brcmf_fweh_register(struct brcmf_pub *drvr, enum brcmf_fweh_event_code code,
350 int (*handler)(struct brcmf_if *ifp,
351 const struct brcmf_event_msg *evtmsg,
352 void *data));
353 void brcmf_fweh_unregister(struct brcmf_pub *drvr,
354 enum brcmf_fweh_event_code code);
355 int brcmf_fweh_activate_events(struct brcmf_if *ifp);
356 void brcmf_fweh_process_event(struct brcmf_pub *drvr,
357 struct brcmf_event *event_packet,
358 u32 packet_len, gfp_t gfp);
359 void brcmf_fweh_p2pdev_setup(struct brcmf_if *ifp, bool ongoing);
360
brcmf_fweh_process_skb(struct brcmf_pub * drvr,struct sk_buff * skb,u16 stype,gfp_t gfp)361 static inline void brcmf_fweh_process_skb(struct brcmf_pub *drvr,
362 struct sk_buff *skb, u16 stype,
363 gfp_t gfp)
364 {
365 struct brcmf_event *event_packet;
366 u16 subtype, usr_stype;
367
368 /* only process events when protocol matches */
369 if (skb->protocol != cpu_to_be16(ETH_P_LINK_CTL))
370 return;
371
372 if ((skb->len + ETH_HLEN) < sizeof(*event_packet))
373 return;
374
375 event_packet = (struct brcmf_event *)skb_mac_header(skb);
376
377 /* check subtype if needed */
378 if (unlikely(stype)) {
379 subtype = get_unaligned_be16(&event_packet->hdr.subtype);
380 if (subtype != stype)
381 return;
382 }
383
384 /* check for BRCM oui match */
385 if (memcmp(BRCM_OUI, &event_packet->hdr.oui[0],
386 sizeof(event_packet->hdr.oui)))
387 return;
388
389 /* final match on usr_subtype */
390 usr_stype = get_unaligned_be16(&event_packet->hdr.usr_subtype);
391 if (usr_stype != BCMILCP_BCM_SUBTYPE_EVENT)
392 return;
393
394 brcmf_fweh_process_event(drvr, event_packet, skb->len + ETH_HLEN, gfp);
395 }
396
397 #endif /* FWEH_H_ */
398