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),
245 #endif /* WL_TWT */
246 };
247
bcmevent_get_name(uint event_type)248 const char *bcmevent_get_name(uint event_type)
249 {
250 /* note: first coded this as a static const but some
251 * ROMs already have something called event_name so
252 * changed it so we don't have a variable for the
253 * 'unknown string
254 */
255 const char *event_name = NULL;
256
257 uint idx;
258 for (idx = 0; idx < (uint)ARRAYSIZE(bcmevent_names); idx++) {
259
260 if (bcmevent_names[idx].event == event_type) {
261 event_name = bcmevent_names[idx].name;
262 break;
263 }
264 }
265
266 /* if we find an event name in the array, return it.
267 * otherwise return unknown string.
268 */
269 return ((event_name) ? event_name : "Unknown Event");
270 }
271
272 void
wl_event_to_host_order(wl_event_msg_t * evt)273 wl_event_to_host_order(wl_event_msg_t * evt)
274 {
275 /* Event struct members passed from dongle to host are stored in network
276 * byte order. Convert all members to host-order.
277 */
278 evt->event_type = ntoh32(evt->event_type);
279 evt->flags = ntoh16(evt->flags);
280 evt->status = ntoh32(evt->status);
281 evt->reason = ntoh32(evt->reason);
282 evt->auth_type = ntoh32(evt->auth_type);
283 evt->datalen = ntoh32(evt->datalen);
284 evt->version = ntoh16(evt->version);
285 }
286
287 void
wl_event_to_network_order(wl_event_msg_t * evt)288 wl_event_to_network_order(wl_event_msg_t * evt)
289 {
290 /* Event struct members passed from dongle to host are stored in network
291 * byte order. Convert all members to host-order.
292 */
293 evt->event_type = hton32(evt->event_type);
294 evt->flags = hton16(evt->flags);
295 evt->status = hton32(evt->status);
296 evt->reason = hton32(evt->reason);
297 evt->auth_type = hton32(evt->auth_type);
298 evt->datalen = hton32(evt->datalen);
299 evt->version = hton16(evt->version);
300 }
301
302 /*
303 * Validate if the event is proper and if valid copy event header to event.
304 * If proper event pointer is passed, to just validate, pass NULL to event.
305 *
306 * Return values are
307 * BCME_OK - It is a BRCM event or BRCM dongle event
308 * BCME_NOTFOUND - Not BRCM, not an event, may be okay
309 * BCME_BADLEN - Bad length, should not process, just drop
310 */
311 int
is_wlc_event_frame(void * pktdata,uint pktlen,uint16 exp_usr_subtype,bcm_event_msg_u_t * out_event)312 is_wlc_event_frame(void *pktdata, uint pktlen, uint16 exp_usr_subtype,
313 bcm_event_msg_u_t *out_event)
314 {
315 uint16 evlen = 0; /* length in bcmeth_hdr */
316 uint16 subtype;
317 uint16 usr_subtype;
318 bcm_event_t *bcm_event;
319 uint8 *pktend;
320 uint8 *evend;
321 int err = BCME_OK;
322 uint32 data_len = 0; /* data length in bcm_event */
323
324 pktend = (uint8 *)pktdata + pktlen;
325 bcm_event = (bcm_event_t *)pktdata;
326
327 /* only care about 16-bit subtype / length versions */
328 if ((uint8 *)&bcm_event->bcm_hdr < pktend) {
329 uint8 short_subtype = *(uint8 *)&bcm_event->bcm_hdr;
330 if (!(short_subtype & 0x80)) {
331 err = BCME_NOTFOUND;
332 goto done;
333 }
334 }
335
336 /* must have both ether_header and bcmeth_hdr */
337 if (pktlen < OFFSETOF(bcm_event_t, event)) {
338 err = BCME_BADLEN;
339 goto done;
340 }
341
342 /* check length in bcmeth_hdr */
343
344 #ifdef BCMDONGLEHOST
345 /* temporary - header length not always set properly. When the below
346 * !BCMDONGLEHOST is in all branches that use trunk DHD, the code
347 * under BCMDONGLEHOST can be removed.
348 */
349 evlen = (uint16)(pktend - (uint8 *)&bcm_event->bcm_hdr.version);
350 #else
351 evlen = ntoh16_ua((void *)&bcm_event->bcm_hdr.length);
352 #endif /* BCMDONGLEHOST */
353 evend = (uint8 *)&bcm_event->bcm_hdr.version + evlen;
354 if (evend != pktend) {
355 err = BCME_BADLEN;
356 goto done;
357 }
358
359 /* match on subtype, oui and usr subtype for BRCM events */
360 subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.subtype);
361 if (subtype != BCMILCP_SUBTYPE_VENDOR_LONG) {
362 err = BCME_NOTFOUND;
363 goto done;
364 }
365
366 if (bcmp(BRCM_OUI, &bcm_event->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
367 err = BCME_NOTFOUND;
368 goto done;
369 }
370
371 /* if it is a bcm_event or bcm_dngl_event_t, validate it */
372 usr_subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.usr_subtype);
373 switch (usr_subtype) {
374 case BCMILCP_BCM_SUBTYPE_EVENT:
375 /* check that header length and pkt length are sufficient */
376 if ((pktlen < sizeof(bcm_event_t)) ||
377 (evend < ((uint8 *)bcm_event + sizeof(bcm_event_t)))) {
378 err = BCME_BADLEN;
379 goto done;
380 }
381
382 /* ensure data length in event is not beyond the packet. */
383 data_len = ntoh32_ua((void *)&bcm_event->event.datalen);
384 if ((sizeof(bcm_event_t) + data_len +
385 BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
386 err = BCME_BADLEN;
387 goto done;
388 }
389
390 if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
391 err = BCME_NOTFOUND;
392 goto done;
393 }
394
395 if (out_event) {
396 /* ensure BRCM event pkt aligned */
397 memcpy(&out_event->event, &bcm_event->event, sizeof(wl_event_msg_t));
398 }
399
400 break;
401
402 case BCMILCP_BCM_SUBTYPE_DNGLEVENT:
403 #if defined(HEALTH_CHECK) || defined(DNGL_EVENT_SUPPORT)
404 if ((pktlen < sizeof(bcm_dngl_event_t)) ||
405 (evend < ((uint8 *)bcm_event + sizeof(bcm_dngl_event_t)))) {
406 err = BCME_BADLEN;
407 goto done;
408 }
409
410 /* ensure data length in event is not beyond the packet. */
411 data_len = ntoh16_ua((void *)&((bcm_dngl_event_t *)pktdata)->dngl_event.datalen);
412 if ((sizeof(bcm_dngl_event_t) + data_len +
413 BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
414 err = BCME_BADLEN;
415 goto done;
416 }
417
418 if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
419 err = BCME_NOTFOUND;
420 goto done;
421 }
422
423 if (out_event) {
424 /* ensure BRCM dngl event pkt aligned */
425 memcpy(&out_event->dngl_event, &((bcm_dngl_event_t *)pktdata)->dngl_event,
426 sizeof(bcm_dngl_event_msg_t));
427 }
428
429 break;
430 #else
431 err = BCME_UNSUPPORTED;
432 break;
433 #endif /* HEALTH_CHECK || DNGL_EVENT_SUPPORT */
434
435 default:
436 err = BCME_NOTFOUND;
437 goto done;
438 }
439
440 BCM_REFERENCE(data_len);
441 done:
442 return err;
443 }
444