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