• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * bcmevent read-only data shared by kernel or app layers
3  *
4  * Copyright (C) 1999-2017, Broadcom Corporation
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  *      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 707287 2017-06-27 06:44:29Z $
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) {(_event), #_event}
46 
47 static const bcmevent_name_str_t bcmevent_names[] = {
48     BCMEVENT_NAME(WLC_E_SET_SSID),
49     BCMEVENT_NAME(WLC_E_JOIN),
50     BCMEVENT_NAME(WLC_E_START),
51     BCMEVENT_NAME(WLC_E_AUTH),
52     BCMEVENT_NAME(WLC_E_AUTH_IND),
53     BCMEVENT_NAME(WLC_E_DEAUTH),
54     BCMEVENT_NAME(WLC_E_DEAUTH_IND),
55     BCMEVENT_NAME(WLC_E_ASSOC),
56     BCMEVENT_NAME(WLC_E_ASSOC_IND),
57     BCMEVENT_NAME(WLC_E_REASSOC),
58     BCMEVENT_NAME(WLC_E_REASSOC_IND),
59     BCMEVENT_NAME(WLC_E_DISASSOC),
60     BCMEVENT_NAME(WLC_E_DISASSOC_IND),
61     BCMEVENT_NAME(WLC_E_QUIET_START),
62     BCMEVENT_NAME(WLC_E_QUIET_END),
63     BCMEVENT_NAME(WLC_E_BEACON_RX),
64     BCMEVENT_NAME(WLC_E_LINK),
65     BCMEVENT_NAME(WLC_E_MIC_ERROR),
66     BCMEVENT_NAME(WLC_E_NDIS_LINK),
67     BCMEVENT_NAME(WLC_E_ROAM),
68     BCMEVENT_NAME(WLC_E_TXFAIL),
69     BCMEVENT_NAME(WLC_E_PMKID_CACHE),
70     BCMEVENT_NAME(WLC_E_RETROGRADE_TSF),
71     BCMEVENT_NAME(WLC_E_PRUNE),
72     BCMEVENT_NAME(WLC_E_AUTOAUTH),
73     BCMEVENT_NAME(WLC_E_EAPOL_MSG),
74     BCMEVENT_NAME(WLC_E_SCAN_COMPLETE),
75     BCMEVENT_NAME(WLC_E_ADDTS_IND),
76     BCMEVENT_NAME(WLC_E_DELTS_IND),
77     BCMEVENT_NAME(WLC_E_BCNSENT_IND),
78     BCMEVENT_NAME(WLC_E_BCNRX_MSG),
79     BCMEVENT_NAME(WLC_E_BCNLOST_MSG),
80     BCMEVENT_NAME(WLC_E_ROAM_PREP),
81     BCMEVENT_NAME(WLC_E_PFN_NET_FOUND),
82     BCMEVENT_NAME(WLC_E_PFN_SCAN_ALLGONE),
83     BCMEVENT_NAME(WLC_E_PFN_NET_LOST),
84     BCMEVENT_NAME(WLC_E_JOIN_START),
85     BCMEVENT_NAME(WLC_E_ROAM_START),
86     BCMEVENT_NAME(WLC_E_ASSOC_START),
87 #if defined(IBSS_PEER_DISCOVERY_EVENT)
88     BCMEVENT_NAME(WLC_E_IBSS_ASSOC),
89 #endif /* defined(IBSS_PEER_DISCOVERY_EVENT) */
90     BCMEVENT_NAME(WLC_E_RADIO),
91     BCMEVENT_NAME(WLC_E_PSM_WATCHDOG),
92     BCMEVENT_NAME(WLC_E_PROBREQ_MSG),
93     BCMEVENT_NAME(WLC_E_SCAN_CONFIRM_IND),
94     BCMEVENT_NAME(WLC_E_PSK_SUP),
95     BCMEVENT_NAME(WLC_E_COUNTRY_CODE_CHANGED),
96     BCMEVENT_NAME(WLC_E_EXCEEDED_MEDIUM_TIME),
97     BCMEVENT_NAME(WLC_E_ICV_ERROR),
98     BCMEVENT_NAME(WLC_E_UNICAST_DECODE_ERROR),
99     BCMEVENT_NAME(WLC_E_MULTICAST_DECODE_ERROR),
100     BCMEVENT_NAME(WLC_E_TRACE),
101     BCMEVENT_NAME(WLC_E_IF),
102 #ifdef WLP2P
103     BCMEVENT_NAME(WLC_E_P2P_DISC_LISTEN_COMPLETE),
104 #endif
105     BCMEVENT_NAME(WLC_E_RSSI),
106     BCMEVENT_NAME(WLC_E_PFN_SCAN_COMPLETE),
107     BCMEVENT_NAME(WLC_E_EXTLOG_MSG),
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
121 #ifdef PROP_TXSTATUS
122     BCMEVENT_NAME(WLC_E_FIFO_CREDIT_MAP),
123 #endif
124     BCMEVENT_NAME(WLC_E_WAKE_EVENT),
125     BCMEVENT_NAME(WLC_E_DCS_REQUEST),
126     BCMEVENT_NAME(WLC_E_RM_COMPLETE),
127 #ifdef WLMEDIA_HTSF
128     BCMEVENT_NAME(WLC_E_HTSFSYNC),
129 #endif
130     BCMEVENT_NAME(WLC_E_OVERLAY_REQ),
131     BCMEVENT_NAME(WLC_E_CSA_COMPLETE_IND),
132     BCMEVENT_NAME(WLC_E_EXCESS_PM_WAKE_EVENT),
133     BCMEVENT_NAME(WLC_E_PFN_SCAN_NONE),
134     BCMEVENT_NAME(WLC_E_PFN_SCAN_ALLGONE),
135 #ifdef SOFTAP
136     BCMEVENT_NAME(WLC_E_GTK_PLUMBED),
137 #endif
138     BCMEVENT_NAME(WLC_E_ASSOC_REQ_IE),
139     BCMEVENT_NAME(WLC_E_ASSOC_RESP_IE),
140     BCMEVENT_NAME(WLC_E_BEACON_FRAME_RX),
141 #ifdef WLTDLS
142     BCMEVENT_NAME(WLC_E_TDLS_PEER_EVENT),
143 #endif /* WLTDLS */
144     BCMEVENT_NAME(WLC_E_NATIVE),
145 #ifdef WLPKTDLYSTAT
146     BCMEVENT_NAME(WLC_E_PKTDELAY_IND),
147 #endif /* WLPKTDLYSTAT */
148     BCMEVENT_NAME(WLC_E_SERVICE_FOUND),
149     BCMEVENT_NAME(WLC_E_GAS_FRAGMENT_RX),
150     BCMEVENT_NAME(WLC_E_GAS_COMPLETE),
151     BCMEVENT_NAME(WLC_E_P2PO_ADD_DEVICE),
152     BCMEVENT_NAME(WLC_E_P2PO_DEL_DEVICE),
153 #ifdef WLWNM
154     BCMEVENT_NAME(WLC_E_WNM_STA_SLEEP),
155 #endif /* WLWNM */
156 #if defined(WL_PROXDETECT)
157     BCMEVENT_NAME(WLC_E_PROXD),
158 #endif
159     BCMEVENT_NAME(WLC_E_CCA_CHAN_QUAL),
160     BCMEVENT_NAME(WLC_E_BSSID),
161 #ifdef PROP_TXSTATUS
162     BCMEVENT_NAME(WLC_E_BCMC_CREDIT_SUPPORT),
163 #endif
164     BCMEVENT_NAME(WLC_E_PSTA_PRIMARY_INTF_IND),
165     BCMEVENT_NAME(WLC_E_TXFAIL_THRESH),
166 #ifdef GSCAN_SUPPORT
167     BCMEVENT_NAME(WLC_E_PFN_GSCAN_FULL_RESULT),
168     BCMEVENT_NAME(WLC_E_PFN_SSID_EXT),
169 #endif /* GSCAN_SUPPORT */
170 #ifdef WLBSSLOAD_REPORT
171     BCMEVENT_NAME(WLC_E_BSS_LOAD),
172 #endif
173 #if defined(BT_WIFI_HANDOVER) || defined(WL_TBOW)
174     BCMEVENT_NAME(WLC_E_BT_WIFI_HANDOVER_REQ),
175 #endif
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_PSK_AUTH),
187     BCMEVENT_NAME(WLC_E_SDB_TRANSITION),
188 };
189 
190 
bcmevent_get_name(uint event_type)191 const char *bcmevent_get_name(uint event_type)
192 {
193     /* note:  first coded this as a static const but some
194      * ROMs already have something called event_name so
195      * changed it so we don't have a variable for the
196      * 'unknown string
197      */
198     const char *event_name = NULL;
199 
200     uint idx;
201     for (idx = 0; idx < (uint)ARRAYSIZE(bcmevent_names); idx++) {
202         if (bcmevent_names[idx].event == event_type) {
203             event_name = bcmevent_names[idx].name;
204             break;
205         }
206     }
207 
208     /* if we find an event name in the array, return it.
209      * otherwise return unknown string.
210      */
211     return ((event_name) ? event_name : "Unknown Event");
212 }
213 
214 void
wl_event_to_host_order(wl_event_msg_t * evt)215 wl_event_to_host_order(wl_event_msg_t * evt)
216 {
217     /* Event struct members passed from dongle to host are stored in network
218     * byte order. Convert all members to host-order.
219     */
220     evt->event_type = ntoh32(evt->event_type);
221     evt->flags = ntoh16(evt->flags);
222     evt->status = ntoh32(evt->status);
223     evt->reason = ntoh32(evt->reason);
224     evt->auth_type = ntoh32(evt->auth_type);
225     evt->datalen = ntoh32(evt->datalen);
226     evt->version = ntoh16(evt->version);
227 }
228 
229 void
wl_event_to_network_order(wl_event_msg_t * evt)230 wl_event_to_network_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 = hton32(evt->event_type);
236     evt->flags = hton16(evt->flags);
237     evt->status = hton32(evt->status);
238     evt->reason = hton32(evt->reason);
239     evt->auth_type = hton32(evt->auth_type);
240     evt->datalen = hton32(evt->datalen);
241     evt->version = hton16(evt->version);
242 }
243 
244 /*
245  * Validate if the event is proper and if valid copy event header to event.
246  * If proper event pointer is passed, to just validate, pass NULL to event.
247  *
248  * Return values are
249  *    BCME_OK - It is a BRCM event or BRCM dongle event
250  *    BCME_NOTFOUND - Not BRCM, not an event, may be okay
251  *    BCME_BADLEN - Bad length, should not process, just drop
252  */
253 int
is_wlc_event_frame(void * pktdata,uint pktlen,uint16 exp_usr_subtype,bcm_event_msg_u_t * out_event)254 is_wlc_event_frame(void *pktdata, uint pktlen, uint16 exp_usr_subtype,
255     bcm_event_msg_u_t *out_event)
256 {
257     uint16 evlen = 0;    /* length in bcmeth_hdr */
258     uint16 subtype;
259     uint16 usr_subtype;
260     bcm_event_t *bcm_event;
261     uint8 *pktend;
262     uint8 *evend;
263     int err = BCME_OK;
264     uint32 data_len = 0; /* data length in bcm_event */
265 
266     pktend = (uint8 *)pktdata + pktlen;
267     bcm_event = (bcm_event_t *)pktdata;
268 
269     /* only care about 16-bit subtype / length versions */
270     if ((uint8 *)&bcm_event->bcm_hdr < pktend) {
271         uint8 short_subtype = *(uint8 *)&bcm_event->bcm_hdr;
272         if (!(short_subtype & 0x80)) {
273             err = BCME_NOTFOUND;
274             goto done;
275         }
276     }
277 
278     /* must have both ether_header and bcmeth_hdr */
279     if (pktlen < OFFSETOF(bcm_event_t, event)) {
280         err = BCME_BADLEN;
281         goto done;
282     }
283 
284     /* check length in bcmeth_hdr */
285 
286     /* temporary - header length not always set properly. When the below
287      * !BCMDONGLEHOST is in all branches that use trunk DHD, the code
288      * under BCMDONGLEHOST can be removed.
289      */
290     evlen = (uint16)(pktend - (uint8 *)&bcm_event->bcm_hdr.version);
291     evend = (uint8 *)&bcm_event->bcm_hdr.version + evlen;
292     if (evend != pktend) {
293         err = BCME_BADLEN;
294         goto done;
295     }
296 
297     /* match on subtype, oui and usr subtype for BRCM events */
298     subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.subtype);
299     if (subtype != BCMILCP_SUBTYPE_VENDOR_LONG) {
300         err = BCME_NOTFOUND;
301         goto done;
302     }
303 
304     if (bcmp(BRCM_OUI, &bcm_event->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
305         err = BCME_NOTFOUND;
306         goto done;
307     }
308 
309     /* if it is a bcm_event or bcm_dngl_event_t, validate it */
310     usr_subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.usr_subtype);
311     switch (usr_subtype) {
312     case BCMILCP_BCM_SUBTYPE_EVENT:
313         /* check that header length and pkt length are sufficient */
314         if ((pktlen < sizeof(bcm_event_t)) ||
315             (evend < ((uint8 *)bcm_event + sizeof(bcm_event_t)))) {
316             err = BCME_BADLEN;
317             goto done;
318         }
319 
320         /* ensure data length in event is not beyond the packet. */
321         data_len = ntoh32_ua((void *)&bcm_event->event.datalen);
322         if ((sizeof(bcm_event_t) + data_len +
323             BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
324             err = BCME_BADLEN;
325             goto done;
326         }
327 
328         if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
329             err = BCME_NOTFOUND;
330             goto done;
331         }
332 
333         if (out_event) {
334             /* ensure BRCM event pkt aligned */
335             memcpy(&out_event->event, &bcm_event->event, sizeof(wl_event_msg_t));
336         }
337 
338         break;
339 
340     case BCMILCP_BCM_SUBTYPE_DNGLEVENT:
341 #if defined(DNGL_EVENT_SUPPORT)
342         if ((pktlen < sizeof(bcm_dngl_event_t)) ||
343             (evend < ((uint8 *)bcm_event + sizeof(bcm_dngl_event_t)))) {
344             err = BCME_BADLEN;
345             goto done;
346         }
347 
348         /* ensure data length in event is not beyond the packet. */
349         data_len = ntoh16_ua((void *)&((bcm_dngl_event_t *)pktdata)->dngl_event.datalen);
350         if ((sizeof(bcm_dngl_event_t) + data_len +
351             BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
352             err = BCME_BADLEN;
353             goto done;
354         }
355 
356         if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
357             err = BCME_NOTFOUND;
358             goto done;
359         }
360 
361         if (out_event) {
362             /* ensure BRCM dngl event pkt aligned */
363             memcpy(&out_event->dngl_event, &((bcm_dngl_event_t *)pktdata)->dngl_event,
364                 sizeof(bcm_dngl_event_msg_t));
365         }
366 
367         break;
368 #else
369         err = BCME_UNSUPPORTED;
370         break;
371 #endif
372 
373     default:
374         err = BCME_NOTFOUND;
375         goto done;
376     }
377 
378     BCM_REFERENCE(data_len);
379 done:
380     return err;
381 }
382