1 /*
2 * bcmevent read-only data shared by kernel or app layers
3 *
4 * Copyright (C) 1999-2019, 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
16 * of the license of that module. An independent module is a module which is
17 * not derived from this software. The special exception does not apply to any
18 * modifications of the software.
19 *
20 * Notwithstanding the above, under no circumstances may you combine this
21 * software in any way with any other Broadcom software provided under a license
22 * other than the GPL, without Broadcom's express prior written consent.
23 *
24 *
25 * <<Broadcom-WL-IPTag/Open:>>
26 *
27 * $Id: bcmevent.c 807989 2019-03-05 07:57:42Z $
28 */
29
30 #include <typedefs.h>
31 #include <bcmutils.h>
32 #include <bcmendian.h>
33 #include <ethernet.h>
34 #include <bcmeth.h>
35 #include <bcmevent.h>
36 #include <802.11.h>
37
38 /* Table of event name strings for UIs and debugging dumps */
39 typedef struct {
40 uint event;
41 const char *name;
42 } bcmevent_name_str_t;
43
44 /* Use the actual name for event tracing */
45 #define BCMEVENT_NAME(_event) \
46 { \
47 (_event), #_event \
48 }
49
50 static const bcmevent_name_str_t bcmevent_names[] = {
51 BCMEVENT_NAME(WLC_E_SET_SSID),
52 BCMEVENT_NAME(WLC_E_JOIN),
53 BCMEVENT_NAME(WLC_E_START),
54 BCMEVENT_NAME(WLC_E_AUTH),
55 BCMEVENT_NAME(WLC_E_AUTH_IND),
56 BCMEVENT_NAME(WLC_E_DEAUTH),
57 BCMEVENT_NAME(WLC_E_DEAUTH_IND),
58 BCMEVENT_NAME(WLC_E_ASSOC),
59 BCMEVENT_NAME(WLC_E_ASSOC_IND),
60 BCMEVENT_NAME(WLC_E_REASSOC),
61 BCMEVENT_NAME(WLC_E_REASSOC_IND),
62 BCMEVENT_NAME(WLC_E_DISASSOC),
63 BCMEVENT_NAME(WLC_E_DISASSOC_IND),
64 BCMEVENT_NAME(WLC_E_QUIET_START),
65 BCMEVENT_NAME(WLC_E_QUIET_END),
66 BCMEVENT_NAME(WLC_E_BEACON_RX),
67 BCMEVENT_NAME(WLC_E_LINK),
68 BCMEVENT_NAME(WLC_E_MIC_ERROR),
69 BCMEVENT_NAME(WLC_E_NDIS_LINK),
70 BCMEVENT_NAME(WLC_E_ROAM),
71 BCMEVENT_NAME(WLC_E_TXFAIL),
72 BCMEVENT_NAME(WLC_E_PMKID_CACHE),
73 BCMEVENT_NAME(WLC_E_RETROGRADE_TSF),
74 BCMEVENT_NAME(WLC_E_PRUNE),
75 BCMEVENT_NAME(WLC_E_AUTOAUTH),
76 BCMEVENT_NAME(WLC_E_EAPOL_MSG),
77 BCMEVENT_NAME(WLC_E_SCAN_COMPLETE),
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 GSCAN_SUPPORT
166 BCMEVENT_NAME(WLC_E_PFN_GSCAN_FULL_RESULT),
167 BCMEVENT_NAME(WLC_E_PFN_SSID_EXT),
168 #endif /* GSCAN_SUPPORT */
169 #ifdef WLBSSLOAD_REPORT
170 BCMEVENT_NAME(WLC_E_BSS_LOAD),
171 #endif // endif
172 #if defined(BT_WIFI_HANDOVER) || defined(WL_TBOW)
173 BCMEVENT_NAME(WLC_E_BT_WIFI_HANDOVER_REQ),
174 #endif // endif
175 #ifdef WLFBT
176 BCMEVENT_NAME(WLC_E_FBT),
177 #endif /* WLFBT */
178 BCMEVENT_NAME(WLC_E_AUTHORIZED),
179 BCMEVENT_NAME(WLC_E_PROBREQ_MSG_RX),
180 BCMEVENT_NAME(WLC_E_CSA_START_IND),
181 BCMEVENT_NAME(WLC_E_CSA_DONE_IND),
182 BCMEVENT_NAME(WLC_E_CSA_FAILURE_IND),
183 BCMEVENT_NAME(WLC_E_RMC_EVENT),
184 BCMEVENT_NAME(WLC_E_DPSTA_INTF_IND),
185 BCMEVENT_NAME(WLC_E_ALLOW_CREDIT_BORROW),
186 BCMEVENT_NAME(WLC_E_MSCH),
187 BCMEVENT_NAME(WLC_E_ULP),
188 BCMEVENT_NAME(WLC_E_NAN),
189 BCMEVENT_NAME(WLC_E_PKT_FILTER),
190 BCMEVENT_NAME(WLC_E_DMA_TXFLUSH_COMPLETE),
191 BCMEVENT_NAME(WLC_E_PSK_AUTH),
192 BCMEVENT_NAME(WLC_E_SDB_TRANSITION),
193 BCMEVENT_NAME(WLC_E_PFN_SCAN_BACKOFF),
194 BCMEVENT_NAME(WLC_E_PFN_BSSID_SCAN_BACKOFF),
195 BCMEVENT_NAME(WLC_E_AGGR_EVENT),
196 BCMEVENT_NAME(WLC_E_TVPM_MITIGATION),
197 #ifdef WL_NAN
198 BCMEVENT_NAME(WLC_E_NAN_CRITICAL),
199 BCMEVENT_NAME(WLC_E_NAN_NON_CRITICAL),
200 BCMEVENT_NAME(WLC_E_NAN),
201 #endif /* WL_NAN */
202 BCMEVENT_NAME(WLC_E_RPSNOA),
203 BCMEVENT_NAME(WLC_E_PHY_CAL),
204 BCMEVENT_NAME(WLC_E_WA_LQM),
205 };
206
bcmevent_get_name(uint event_type)207 const char *bcmevent_get_name(uint event_type)
208 {
209 /* note: first coded this as a static const but some
210 * ROMs already have something called event_name so
211 * changed it so we don't have a variable for the
212 * 'unknown string
213 */
214 const char *event_name = NULL;
215
216 uint idx;
217 for (idx = 0; idx < (uint)ARRAYSIZE(bcmevent_names); idx++) {
218 if (bcmevent_names[idx].event == event_type) {
219 event_name = bcmevent_names[idx].name;
220 break;
221 }
222 }
223
224 /* if we find an event name in the array, return it.
225 * otherwise return unknown string.
226 */
227 return ((event_name) ? event_name : "Unknown Event");
228 }
229
wl_event_to_host_order(wl_event_msg_t * evt)230 void wl_event_to_host_order(wl_event_msg_t *evt)
231 {
232 /* Event struct members passed from dongle to host are stored in network
233 * byte order. Convert all members to host-order.
234 */
235 evt->event_type = ntoh32(evt->event_type);
236 evt->flags = ntoh16(evt->flags);
237 evt->status = ntoh32(evt->status);
238 evt->reason = ntoh32(evt->reason);
239 evt->auth_type = ntoh32(evt->auth_type);
240 evt->datalen = ntoh32(evt->datalen);
241 evt->version = ntoh16(evt->version);
242 }
243
wl_event_to_network_order(wl_event_msg_t * evt)244 void wl_event_to_network_order(wl_event_msg_t *evt)
245 {
246 /* Event struct members passed from dongle to host are stored in network
247 * byte order. Convert all members to host-order.
248 */
249 evt->event_type = hton32(evt->event_type);
250 evt->flags = hton16(evt->flags);
251 evt->status = hton32(evt->status);
252 evt->reason = hton32(evt->reason);
253 evt->auth_type = hton32(evt->auth_type);
254 evt->datalen = hton32(evt->datalen);
255 evt->version = hton16(evt->version);
256 }
257
258 /*
259 * Validate if the event is proper and if valid copy event header to event.
260 * If proper event pointer is passed, to just validate, pass NULL to event.
261 *
262 * Return values are
263 * BCME_OK - It is a BRCM event or BRCM dongle event
264 * BCME_NOTFOUND - Not BRCM, not an event, may be okay
265 * BCME_BADLEN - Bad length, should not process, just drop
266 */
is_wlc_event_frame(void * pktdata,uint pktlen,uint16 exp_usr_subtype,bcm_event_msg_u_t * out_event)267 int is_wlc_event_frame(void *pktdata, uint pktlen, uint16 exp_usr_subtype,
268 bcm_event_msg_u_t *out_event)
269 {
270 uint16 evlen = 0; /* length in bcmeth_hdr */
271 uint16 subtype;
272 uint16 usr_subtype;
273 bcm_event_t *bcm_event;
274 uint8 *pktend;
275 uint8 *evend;
276 int err = BCME_OK;
277 uint32 data_len = 0; /* data length in bcm_event */
278
279 pktend = (uint8 *)pktdata + pktlen;
280 bcm_event = (bcm_event_t *)pktdata;
281
282 /* only care about 16-bit subtype / length versions */
283 if ((uint8 *)&bcm_event->bcm_hdr < pktend) {
284 uint8 short_subtype = *(uint8 *)&bcm_event->bcm_hdr;
285 if (!(short_subtype & 0x80)) {
286 err = BCME_NOTFOUND;
287 goto done;
288 }
289 }
290
291 /* must have both ether_header and bcmeth_hdr */
292 if (pktlen < OFFSETOF(bcm_event_t, event)) {
293 err = BCME_BADLEN;
294 goto done;
295 }
296
297 /* check length in bcmeth_hdr */
298
299 /* temporary - header length not always set properly. When the below
300 * !BCMDONGLEHOST is in all branches that use trunk DHD, the code
301 * under BCMDONGLEHOST can be removed.
302 */
303 evlen = (uint16)(pktend - (uint8 *)&bcm_event->bcm_hdr.version);
304 evend = (uint8 *)&bcm_event->bcm_hdr.version + evlen;
305 if (evend != pktend) {
306 err = BCME_BADLEN;
307 goto done;
308 }
309
310 /* match on subtype, oui and usr subtype for BRCM events */
311 subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.subtype);
312 if (subtype != BCMILCP_SUBTYPE_VENDOR_LONG) {
313 err = BCME_NOTFOUND;
314 goto done;
315 }
316
317 if (bcmp(BRCM_OUI, &bcm_event->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
318 err = BCME_NOTFOUND;
319 goto done;
320 }
321
322 /* if it is a bcm_event or bcm_dngl_event_t, validate it */
323 usr_subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.usr_subtype);
324 switch (usr_subtype) {
325 case BCMILCP_BCM_SUBTYPE_EVENT:
326 /* check that header length and pkt length are sufficient */
327 if ((pktlen < sizeof(bcm_event_t)) ||
328 (evend < ((uint8 *)bcm_event + sizeof(bcm_event_t)))) {
329 err = BCME_BADLEN;
330 goto done;
331 }
332
333 /* ensure data length in event is not beyond the packet. */
334 data_len = ntoh32_ua((void *)&bcm_event->event.datalen);
335 if ((sizeof(bcm_event_t) + data_len +
336 BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
337 err = BCME_BADLEN;
338 goto done;
339 }
340
341 if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
342 err = BCME_NOTFOUND;
343 goto done;
344 }
345
346 if (out_event) {
347 /* ensure BRCM event pkt aligned */
348 memcpy(&out_event->event, &bcm_event->event,
349 sizeof(wl_event_msg_t));
350 }
351
352 break;
353
354 case BCMILCP_BCM_SUBTYPE_DNGLEVENT:
355 #if defined(DNGL_EVENT_SUPPORT)
356 if ((pktlen < sizeof(bcm_dngl_event_t)) ||
357 (evend < ((uint8 *)bcm_event + sizeof(bcm_dngl_event_t)))) {
358 err = BCME_BADLEN;
359 goto done;
360 }
361
362 /* ensure data length in event is not beyond the packet. */
363 data_len = ntoh16_ua(
364 (void *)&((bcm_dngl_event_t *)pktdata)->dngl_event.datalen);
365 if ((sizeof(bcm_dngl_event_t) + data_len +
366 BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
367 err = BCME_BADLEN;
368 goto done;
369 }
370
371 if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
372 err = BCME_NOTFOUND;
373 goto done;
374 }
375
376 if (out_event) {
377 /* ensure BRCM dngl event pkt aligned */
378 memcpy(&out_event->dngl_event,
379 &((bcm_dngl_event_t *)pktdata)->dngl_event,
380 sizeof(bcm_dngl_event_msg_t));
381 }
382
383 break;
384 #else
385 err = BCME_UNSUPPORTED;
386 break;
387 #endif // endif
388
389 default:
390 err = BCME_NOTFOUND;
391 goto done;
392 }
393
394 BCM_REFERENCE(data_len);
395 done:
396 return err;
397 }
398