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