1 /*
2 * bcmevent read-only data shared by kernel or app layers
3 *
4 * Copyright (C) 2020, Broadcom.
5 *
6 * Unless you and Broadcom execute a separate written software license
7 * agreement governing use of this software, this software is licensed to you
8 * under the terms of the GNU General Public License version 2 (the "GPL"),
9 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10 * following added to such license:
11 *
12 * As a special exception, the copyright holders of this software give you
13 * permission to link this software with independent modules, and to copy and
14 * distribute the resulting executable under terms of your choice, provided that
15 * you also meet, for each linked independent module, the terms and conditions of
16 * the license of that module. An independent module is a module which is not
17 * derived from this software. The special exception does not apply to any
18 * modifications of the software.
19 *
20 *
21 * <<Broadcom-WL-IPTag/Dual:>>
22 */
23
24 #include <typedefs.h>
25 #include <bcmutils.h>
26 #include <bcmendian.h>
27 #include <ethernet.h>
28 #include <bcmeth.h>
29 #include <bcmevent.h>
30 #include <802.11.h>
31
32 /* Table of event name strings for UIs and debugging dumps */
33 typedef struct {
34 uint event;
35 const char *name;
36 } bcmevent_name_str_t;
37
38 /* Use the actual name for event tracing */
39 #define BCMEVENT_NAME(_event) {(_event), #_event}
40
41 /* this becomes static data when all code is changed to use
42 * the bcmevent_get_name() API
43 */
44 static const bcmevent_name_str_t bcmevent_names[] = {
45 BCMEVENT_NAME(WLC_E_SET_SSID),
46 BCMEVENT_NAME(WLC_E_JOIN),
47 BCMEVENT_NAME(WLC_E_START),
48 BCMEVENT_NAME(WLC_E_AUTH),
49 BCMEVENT_NAME(WLC_E_AUTH_IND),
50 BCMEVENT_NAME(WLC_E_DEAUTH),
51 BCMEVENT_NAME(WLC_E_DEAUTH_IND),
52 BCMEVENT_NAME(WLC_E_ASSOC),
53 BCMEVENT_NAME(WLC_E_ASSOC_IND),
54 BCMEVENT_NAME(WLC_E_REASSOC),
55 BCMEVENT_NAME(WLC_E_REASSOC_IND),
56 BCMEVENT_NAME(WLC_E_DISASSOC),
57 BCMEVENT_NAME(WLC_E_DISASSOC_IND),
58 BCMEVENT_NAME(WLC_E_QUIET_START),
59 BCMEVENT_NAME(WLC_E_QUIET_END),
60 BCMEVENT_NAME(WLC_E_BEACON_RX),
61 BCMEVENT_NAME(WLC_E_LINK),
62 BCMEVENT_NAME(WLC_E_MIC_ERROR),
63 BCMEVENT_NAME(WLC_E_NDIS_LINK),
64 BCMEVENT_NAME(WLC_E_ROAM),
65 BCMEVENT_NAME(WLC_E_TXFAIL),
66 BCMEVENT_NAME(WLC_E_PMKID_CACHE),
67 BCMEVENT_NAME(WLC_E_RETROGRADE_TSF),
68 BCMEVENT_NAME(WLC_E_PRUNE),
69 BCMEVENT_NAME(WLC_E_AUTOAUTH),
70 BCMEVENT_NAME(WLC_E_EAPOL_MSG),
71 BCMEVENT_NAME(WLC_E_SCAN_COMPLETE),
72 BCMEVENT_NAME(WLC_E_ADDTS_IND),
73 BCMEVENT_NAME(WLC_E_DELTS_IND),
74 BCMEVENT_NAME(WLC_E_BCNSENT_IND),
75 BCMEVENT_NAME(WLC_E_BCNRX_MSG),
76 BCMEVENT_NAME(WLC_E_BCNLOST_MSG),
77 BCMEVENT_NAME(WLC_E_ROAM_PREP),
78 BCMEVENT_NAME(WLC_E_PFN_NET_FOUND),
79 BCMEVENT_NAME(WLC_E_PFN_SCAN_ALLGONE),
80 BCMEVENT_NAME(WLC_E_PFN_NET_LOST),
81 BCMEVENT_NAME(WLC_E_JOIN_START),
82 BCMEVENT_NAME(WLC_E_ROAM_START),
83 BCMEVENT_NAME(WLC_E_ASSOC_START),
84 #ifdef EXT_STA
85 BCMEVENT_NAME(WLC_E_RESET_COMPLETE),
86 BCMEVENT_NAME(WLC_E_JOIN_START),
87 BCMEVENT_NAME(WLC_E_ROAM_START),
88 BCMEVENT_NAME(WLC_E_ASSOC_START),
89 BCMEVENT_NAME(WLC_E_ASSOC_RECREATED),
90 BCMEVENT_NAME(WLC_E_SPEEDY_RECREATE_FAIL),
91 #endif /* EXT_STA */
92 #if defined(IBSS_PEER_DISCOVERY_EVENT)
93 BCMEVENT_NAME(WLC_E_IBSS_ASSOC),
94 #endif /* defined(IBSS_PEER_DISCOVERY_EVENT) */
95 BCMEVENT_NAME(WLC_E_RADIO),
96 BCMEVENT_NAME(WLC_E_PSM_WATCHDOG),
97 BCMEVENT_NAME(WLC_E_PROBREQ_MSG),
98 BCMEVENT_NAME(WLC_E_SCAN_CONFIRM_IND),
99 BCMEVENT_NAME(WLC_E_PSK_SUP),
100 BCMEVENT_NAME(WLC_E_COUNTRY_CODE_CHANGED),
101 BCMEVENT_NAME(WLC_E_EXCEEDED_MEDIUM_TIME),
102 BCMEVENT_NAME(WLC_E_ICV_ERROR),
103 BCMEVENT_NAME(WLC_E_UNICAST_DECODE_ERROR),
104 BCMEVENT_NAME(WLC_E_MULTICAST_DECODE_ERROR),
105 BCMEVENT_NAME(WLC_E_TRACE),
106 BCMEVENT_NAME(WLC_E_IF),
107 #ifdef WLP2P
108 BCMEVENT_NAME(WLC_E_P2P_DISC_LISTEN_COMPLETE),
109 #endif
110 BCMEVENT_NAME(WLC_E_RSSI),
111 BCMEVENT_NAME(WLC_E_PFN_SCAN_COMPLETE),
112 BCMEVENT_NAME(WLC_E_ACTION_FRAME),
113 BCMEVENT_NAME(WLC_E_ACTION_FRAME_RX),
114 BCMEVENT_NAME(WLC_E_ACTION_FRAME_COMPLETE),
115 #if defined(NDIS)
116 BCMEVENT_NAME(WLC_E_PRE_ASSOC_IND),
117 BCMEVENT_NAME(WLC_E_PRE_REASSOC_IND),
118 BCMEVENT_NAME(WLC_E_CHANNEL_ADOPTED),
119 BCMEVENT_NAME(WLC_E_AP_STARTED),
120 BCMEVENT_NAME(WLC_E_DFS_AP_STOP),
121 BCMEVENT_NAME(WLC_E_DFS_AP_RESUME),
122 BCMEVENT_NAME(WLC_E_ASSOC_IND_NDIS),
123 BCMEVENT_NAME(WLC_E_REASSOC_IND_NDIS),
124 BCMEVENT_NAME(WLC_E_ACTION_FRAME_RX_NDIS),
125 BCMEVENT_NAME(WLC_E_AUTH_REQ),
126 BCMEVENT_NAME(WLC_E_IBSS_COALESCE),
127 #endif /* #if defined(NDIS) */
128
129 #ifdef BCMWAPI_WAI
130 BCMEVENT_NAME(WLC_E_WAI_STA_EVENT),
131 BCMEVENT_NAME(WLC_E_WAI_MSG),
132 #endif /* BCMWAPI_WAI */
133
134 BCMEVENT_NAME(WLC_E_ESCAN_RESULT),
135 BCMEVENT_NAME(WLC_E_ACTION_FRAME_OFF_CHAN_COMPLETE),
136 #ifdef WLP2P
137 BCMEVENT_NAME(WLC_E_PROBRESP_MSG),
138 BCMEVENT_NAME(WLC_E_P2P_PROBREQ_MSG),
139 #endif
140 #ifdef PROP_TXSTATUS
141 BCMEVENT_NAME(WLC_E_FIFO_CREDIT_MAP),
142 #endif
143 BCMEVENT_NAME(WLC_E_WAKE_EVENT),
144 BCMEVENT_NAME(WLC_E_DCS_REQUEST),
145 BCMEVENT_NAME(WLC_E_RM_COMPLETE),
146 BCMEVENT_NAME(WLC_E_OVERLAY_REQ),
147 BCMEVENT_NAME(WLC_E_CSA_COMPLETE_IND),
148 BCMEVENT_NAME(WLC_E_EXCESS_PM_WAKE_EVENT),
149 BCMEVENT_NAME(WLC_E_PFN_SCAN_NONE),
150 BCMEVENT_NAME(WLC_E_PFN_SCAN_ALLGONE),
151 #ifdef SOFTAP
152 BCMEVENT_NAME(WLC_E_GTK_PLUMBED),
153 #endif
154 BCMEVENT_NAME(WLC_E_ASSOC_REQ_IE),
155 BCMEVENT_NAME(WLC_E_ASSOC_RESP_IE),
156 BCMEVENT_NAME(WLC_E_BEACON_FRAME_RX),
157 #ifdef WLTDLS
158 BCMEVENT_NAME(WLC_E_TDLS_PEER_EVENT),
159 #endif /* WLTDLS */
160 BCMEVENT_NAME(WLC_E_NATIVE),
161 #ifdef WLPKTDLYSTAT
162 BCMEVENT_NAME(WLC_E_PKTDELAY_IND),
163 #endif /* WLPKTDLYSTAT */
164 BCMEVENT_NAME(WLC_E_SERVICE_FOUND),
165 BCMEVENT_NAME(WLC_E_GAS_FRAGMENT_RX),
166 BCMEVENT_NAME(WLC_E_GAS_COMPLETE),
167 BCMEVENT_NAME(WLC_E_P2PO_ADD_DEVICE),
168 BCMEVENT_NAME(WLC_E_P2PO_DEL_DEVICE),
169 #ifdef WLWNM
170 BCMEVENT_NAME(WLC_E_WNM_STA_SLEEP),
171 #endif /* WLWNM */
172 #if defined(WL_PROXDETECT) || defined(RTT_SUPPORT)
173 BCMEVENT_NAME(WLC_E_PROXD),
174 #endif
175 BCMEVENT_NAME(WLC_E_CCA_CHAN_QUAL),
176 BCMEVENT_NAME(WLC_E_BSSID),
177 #ifdef PROP_TXSTATUS
178 BCMEVENT_NAME(WLC_E_BCMC_CREDIT_SUPPORT),
179 #endif
180 BCMEVENT_NAME(WLC_E_PSTA_PRIMARY_INTF_IND),
181 BCMEVENT_NAME(WLC_E_TXFAIL_THRESH),
182 #ifdef WLAIBSS
183 BCMEVENT_NAME(WLC_E_AIBSS_TXFAIL),
184 #endif /* WLAIBSS */
185 #ifdef GSCAN_SUPPORT
186 BCMEVENT_NAME(WLC_E_PFN_GSCAN_FULL_RESULT),
187 BCMEVENT_NAME(WLC_E_PFN_SSID_EXT),
188 #endif /* GSCAN_SUPPORT */
189 #ifdef WLBSSLOAD_REPORT
190 BCMEVENT_NAME(WLC_E_BSS_LOAD),
191 #endif
192 #if defined(BT_WIFI_HANDOVER) || defined(WL_TBOW)
193 BCMEVENT_NAME(WLC_E_BT_WIFI_HANDOVER_REQ),
194 #endif
195 #ifdef WLFBT
196 BCMEVENT_NAME(WLC_E_FBT),
197 #endif /* WLFBT */
198 BCMEVENT_NAME(WLC_E_AUTHORIZED),
199 BCMEVENT_NAME(WLC_E_PROBREQ_MSG_RX),
200
201 #ifdef WLAWDL
202 BCMEVENT_NAME(WLC_E_AWDL_AW),
203 BCMEVENT_NAME(WLC_E_AWDL_ROLE),
204 BCMEVENT_NAME(WLC_E_AWDL_EVENT),
205 #endif /* WLAWDL */
206
207 BCMEVENT_NAME(WLC_E_CSA_START_IND),
208 BCMEVENT_NAME(WLC_E_CSA_DONE_IND),
209 BCMEVENT_NAME(WLC_E_CSA_FAILURE_IND),
210 BCMEVENT_NAME(WLC_E_RMC_EVENT),
211 BCMEVENT_NAME(WLC_E_DPSTA_INTF_IND),
212 BCMEVENT_NAME(WLC_E_ALLOW_CREDIT_BORROW),
213 BCMEVENT_NAME(WLC_E_MSCH),
214 BCMEVENT_NAME(WLC_E_ULP),
215 BCMEVENT_NAME(WLC_E_NAN),
216 BCMEVENT_NAME(WLC_E_PKT_FILTER),
217 BCMEVENT_NAME(WLC_E_DMA_TXFLUSH_COMPLETE),
218 BCMEVENT_NAME(WLC_E_PSK_AUTH),
219 BCMEVENT_NAME(WLC_E_SDB_TRANSITION),
220 BCMEVENT_NAME(WLC_E_PFN_SCAN_BACKOFF),
221 BCMEVENT_NAME(WLC_E_PFN_BSSID_SCAN_BACKOFF),
222 BCMEVENT_NAME(WLC_E_AGGR_EVENT),
223 BCMEVENT_NAME(WLC_E_TVPM_MITIGATION),
224 BCMEVENT_NAME(WLC_E_SCAN),
225 BCMEVENT_NAME(WLC_E_SLOTTED_BSS_PEER_OP),
226 BCMEVENT_NAME(WLC_E_PHY_CAL),
227 #ifdef WL_NAN
228 BCMEVENT_NAME(WLC_E_NAN_CRITICAL),
229 BCMEVENT_NAME(WLC_E_NAN_NON_CRITICAL),
230 BCMEVENT_NAME(WLC_E_NAN),
231 #endif /* WL_NAN */
232 BCMEVENT_NAME(WLC_E_RPSNOA),
233 BCMEVENT_NAME(WLC_E_WA_LQM),
234 BCMEVENT_NAME(WLC_E_OBSS_DETECTION),
235 BCMEVENT_NAME(WLC_E_SC_CHAN_QUAL),
236 BCMEVENT_NAME(WLC_E_DYNSAR),
237 BCMEVENT_NAME(WLC_E_ROAM_CACHE_UPDATE),
238 BCMEVENT_NAME(WLC_E_AP_BCN_DRIFT),
239 BCMEVENT_NAME(WLC_E_PFN_SCAN_ALLGONE_EXT),
240 #ifdef WL_CLIENT_SAE
241 BCMEVENT_NAME(WLC_E_AUTH_START),
242 #endif /* WL_CLIENT_SAE */
243 #ifdef WL_TWT
244 BCMEVENT_NAME(WLC_E_TWT_SETUP),
245 BCMEVENT_NAME(WLC_E_TWT_TEARDOWN),
246 BCMEVENT_NAME(WLC_E_TWT_INFO_FRM)
247 #endif /* WL_TWT */
248 };
249
bcmevent_get_name(uint event_type)250 const char *bcmevent_get_name(uint event_type)
251 {
252 /* note: first coded this as a static const but some
253 * ROMs already have something called event_name so
254 * changed it so we don't have a variable for the
255 * 'unknown string
256 */
257 const char *event_name = NULL;
258
259 uint idx;
260 for (idx = 0; idx < (uint)ARRAYSIZE(bcmevent_names); idx++) {
261
262 if (bcmevent_names[idx].event == event_type) {
263 event_name = bcmevent_names[idx].name;
264 break;
265 }
266 }
267
268 /* if we find an event name in the array, return it.
269 * otherwise return unknown string.
270 */
271 return ((event_name) ? event_name : "Unknown Event");
272 }
273
274 void
wl_event_to_host_order(wl_event_msg_t * evt)275 wl_event_to_host_order(wl_event_msg_t * evt)
276 {
277 /* Event struct members passed from dongle to host are stored in network
278 * byte order. Convert all members to host-order.
279 */
280 evt->event_type = ntoh32(evt->event_type);
281 evt->flags = ntoh16(evt->flags);
282 evt->status = ntoh32(evt->status);
283 evt->reason = ntoh32(evt->reason);
284 evt->auth_type = ntoh32(evt->auth_type);
285 evt->datalen = ntoh32(evt->datalen);
286 evt->version = ntoh16(evt->version);
287 }
288
289 void
wl_event_to_network_order(wl_event_msg_t * evt)290 wl_event_to_network_order(wl_event_msg_t * evt)
291 {
292 /* Event struct members passed from dongle to host are stored in network
293 * byte order. Convert all members to host-order.
294 */
295 evt->event_type = hton32(evt->event_type);
296 evt->flags = hton16(evt->flags);
297 evt->status = hton32(evt->status);
298 evt->reason = hton32(evt->reason);
299 evt->auth_type = hton32(evt->auth_type);
300 evt->datalen = hton32(evt->datalen);
301 evt->version = hton16(evt->version);
302 }
303
304 /*
305 * Validate if the event is proper and if valid copy event header to event.
306 * If proper event pointer is passed, to just validate, pass NULL to event.
307 *
308 * Return values are
309 * BCME_OK - It is a BRCM event or BRCM dongle event
310 * BCME_NOTFOUND - Not BRCM, not an event, may be okay
311 * BCME_BADLEN - Bad length, should not process, just drop
312 */
313 int
is_wlc_event_frame(void * pktdata,uint pktlen,uint16 exp_usr_subtype,bcm_event_msg_u_t * out_event)314 is_wlc_event_frame(void *pktdata, uint pktlen, uint16 exp_usr_subtype,
315 bcm_event_msg_u_t *out_event)
316 {
317 uint16 evlen = 0; /* length in bcmeth_hdr */
318 uint16 subtype;
319 uint16 usr_subtype;
320 bcm_event_t *bcm_event;
321 uint8 *pktend;
322 uint8 *evend;
323 int err = BCME_OK;
324 uint32 data_len = 0; /* data length in bcm_event */
325
326 pktend = (uint8 *)pktdata + pktlen;
327 bcm_event = (bcm_event_t *)pktdata;
328
329 /* only care about 16-bit subtype / length versions */
330 if ((uint8 *)&bcm_event->bcm_hdr < pktend) {
331 uint8 short_subtype = *(uint8 *)&bcm_event->bcm_hdr;
332 if (!(short_subtype & 0x80)) {
333 err = BCME_NOTFOUND;
334 goto done;
335 }
336 }
337
338 /* must have both ether_header and bcmeth_hdr */
339 if (pktlen < OFFSETOF(bcm_event_t, event)) {
340 err = BCME_BADLEN;
341 goto done;
342 }
343
344 /* check length in bcmeth_hdr */
345
346 #ifdef BCMDONGLEHOST
347 /* temporary - header length not always set properly. When the below
348 * !BCMDONGLEHOST is in all branches that use trunk DHD, the code
349 * under BCMDONGLEHOST can be removed.
350 */
351 evlen = (uint16)(pktend - (uint8 *)&bcm_event->bcm_hdr.version);
352 #else
353 evlen = ntoh16_ua((void *)&bcm_event->bcm_hdr.length);
354 #endif /* BCMDONGLEHOST */
355 evend = (uint8 *)&bcm_event->bcm_hdr.version + evlen;
356 if (evend != pktend) {
357 err = BCME_BADLEN;
358 goto done;
359 }
360
361 /* match on subtype, oui and usr subtype for BRCM events */
362 subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.subtype);
363 if (subtype != BCMILCP_SUBTYPE_VENDOR_LONG) {
364 err = BCME_NOTFOUND;
365 goto done;
366 }
367
368 if (bcmp(BRCM_OUI, &bcm_event->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
369 err = BCME_NOTFOUND;
370 goto done;
371 }
372
373 /* if it is a bcm_event or bcm_dngl_event_t, validate it */
374 usr_subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.usr_subtype);
375 switch (usr_subtype) {
376 case BCMILCP_BCM_SUBTYPE_EVENT:
377 /* check that header length and pkt length are sufficient */
378 if ((pktlen < sizeof(bcm_event_t)) ||
379 (evend < ((uint8 *)bcm_event + sizeof(bcm_event_t)))) {
380 err = BCME_BADLEN;
381 goto done;
382 }
383
384 /* ensure data length in event is not beyond the packet. */
385 data_len = ntoh32_ua((void *)&bcm_event->event.datalen);
386 if ((sizeof(bcm_event_t) + data_len +
387 BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
388 err = BCME_BADLEN;
389 goto done;
390 }
391
392 if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
393 err = BCME_NOTFOUND;
394 goto done;
395 }
396
397 if (out_event) {
398 /* ensure BRCM event pkt aligned */
399 memcpy(&out_event->event, &bcm_event->event, sizeof(wl_event_msg_t));
400 }
401
402 break;
403
404 case BCMILCP_BCM_SUBTYPE_DNGLEVENT:
405 #if defined(HEALTH_CHECK) || defined(DNGL_EVENT_SUPPORT)
406 if ((pktlen < sizeof(bcm_dngl_event_t)) ||
407 (evend < ((uint8 *)bcm_event + sizeof(bcm_dngl_event_t)))) {
408 err = BCME_BADLEN;
409 goto done;
410 }
411
412 /* ensure data length in event is not beyond the packet. */
413 data_len = ntoh16_ua((void *)&((bcm_dngl_event_t *)pktdata)->dngl_event.datalen);
414 if ((sizeof(bcm_dngl_event_t) + data_len +
415 BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
416 err = BCME_BADLEN;
417 goto done;
418 }
419
420 if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
421 err = BCME_NOTFOUND;
422 goto done;
423 }
424
425 if (out_event) {
426 /* ensure BRCM dngl event pkt aligned */
427 memcpy(&out_event->dngl_event, &((bcm_dngl_event_t *)pktdata)->dngl_event,
428 sizeof(bcm_dngl_event_msg_t));
429 }
430
431 break;
432 #else
433 err = BCME_UNSUPPORTED;
434 break;
435 #endif /* HEALTH_CHECK || DNGL_EVENT_SUPPORT */
436
437 default:
438 err = BCME_NOTFOUND;
439 goto done;
440 }
441
442 BCM_REFERENCE(data_len);
443 done:
444 return err;
445 }
446