bcmevent.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. /*
  2. * bcmevent read-only data shared by kernel or app layers
  3. *
  4. * Portions of this code are copyright (c) 2020 Cypress Semiconductor Corporation
  5. *
  6. * Copyright (C) 1999-2020, 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. #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. /* 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. /* Use the actual name for event tracing */
  44. #define BCMEVENT_NAME(_event) {(_event), #_event}
  45. static const bcmevent_name_str_t bcmevent_names[] = {
  46. BCMEVENT_NAME(WLC_E_SET_SSID),
  47. BCMEVENT_NAME(WLC_E_JOIN),
  48. BCMEVENT_NAME(WLC_E_START),
  49. BCMEVENT_NAME(WLC_E_AUTH),
  50. BCMEVENT_NAME(WLC_E_AUTH_IND),
  51. BCMEVENT_NAME(WLC_E_DEAUTH),
  52. BCMEVENT_NAME(WLC_E_DEAUTH_IND),
  53. BCMEVENT_NAME(WLC_E_ASSOC),
  54. BCMEVENT_NAME(WLC_E_ASSOC_IND),
  55. BCMEVENT_NAME(WLC_E_REASSOC),
  56. BCMEVENT_NAME(WLC_E_REASSOC_IND),
  57. BCMEVENT_NAME(WLC_E_DISASSOC),
  58. BCMEVENT_NAME(WLC_E_DISASSOC_IND),
  59. BCMEVENT_NAME(WLC_E_QUIET_START),
  60. BCMEVENT_NAME(WLC_E_QUIET_END),
  61. BCMEVENT_NAME(WLC_E_BEACON_RX),
  62. BCMEVENT_NAME(WLC_E_LINK),
  63. BCMEVENT_NAME(WLC_E_MIC_ERROR),
  64. BCMEVENT_NAME(WLC_E_NDIS_LINK),
  65. BCMEVENT_NAME(WLC_E_ROAM),
  66. BCMEVENT_NAME(WLC_E_TXFAIL),
  67. BCMEVENT_NAME(WLC_E_PMKID_CACHE),
  68. BCMEVENT_NAME(WLC_E_RETROGRADE_TSF),
  69. BCMEVENT_NAME(WLC_E_PRUNE),
  70. BCMEVENT_NAME(WLC_E_AUTOAUTH),
  71. BCMEVENT_NAME(WLC_E_EAPOL_MSG),
  72. BCMEVENT_NAME(WLC_E_SCAN_COMPLETE),
  73. BCMEVENT_NAME(WLC_E_IND_DOS_STATUS),
  74. BCMEVENT_NAME(WLC_E_ADDTS_IND),
  75. BCMEVENT_NAME(WLC_E_DELTS_IND),
  76. BCMEVENT_NAME(WLC_E_BCNSENT_IND),
  77. BCMEVENT_NAME(WLC_E_BCNRX_MSG),
  78. BCMEVENT_NAME(WLC_E_BCNLOST_MSG),
  79. BCMEVENT_NAME(WLC_E_ROAM_PREP),
  80. BCMEVENT_NAME(WLC_E_PFN_NET_FOUND),
  81. BCMEVENT_NAME(WLC_E_PFN_SCAN_ALLGONE),
  82. BCMEVENT_NAME(WLC_E_PFN_NET_LOST),
  83. BCMEVENT_NAME(WLC_E_JOIN_START),
  84. BCMEVENT_NAME(WLC_E_ROAM_START),
  85. BCMEVENT_NAME(WLC_E_ASSOC_START),
  86. #if defined(IBSS_PEER_DISCOVERY_EVENT)
  87. BCMEVENT_NAME(WLC_E_IBSS_ASSOC),
  88. #endif /* defined(IBSS_PEER_DISCOVERY_EVENT) */
  89. BCMEVENT_NAME(WLC_E_RADIO),
  90. BCMEVENT_NAME(WLC_E_PSM_WATCHDOG),
  91. BCMEVENT_NAME(WLC_E_PROBREQ_MSG),
  92. BCMEVENT_NAME(WLC_E_SCAN_CONFIRM_IND),
  93. BCMEVENT_NAME(WLC_E_PSK_SUP),
  94. BCMEVENT_NAME(WLC_E_COUNTRY_CODE_CHANGED),
  95. BCMEVENT_NAME(WLC_E_EXCEEDED_MEDIUM_TIME),
  96. BCMEVENT_NAME(WLC_E_ICV_ERROR),
  97. BCMEVENT_NAME(WLC_E_UNICAST_DECODE_ERROR),
  98. BCMEVENT_NAME(WLC_E_MULTICAST_DECODE_ERROR),
  99. BCMEVENT_NAME(WLC_E_TRACE),
  100. BCMEVENT_NAME(WLC_E_IF),
  101. #ifdef WLP2P
  102. BCMEVENT_NAME(WLC_E_P2P_DISC_LISTEN_COMPLETE),
  103. #endif // endif
  104. BCMEVENT_NAME(WLC_E_RSSI),
  105. BCMEVENT_NAME(WLC_E_PFN_SCAN_COMPLETE),
  106. BCMEVENT_NAME(WLC_E_ACTION_FRAME),
  107. BCMEVENT_NAME(WLC_E_ACTION_FRAME_RX),
  108. BCMEVENT_NAME(WLC_E_ACTION_FRAME_COMPLETE),
  109. #ifdef BCMWAPI_WAI
  110. BCMEVENT_NAME(WLC_E_WAI_STA_EVENT),
  111. BCMEVENT_NAME(WLC_E_WAI_MSG),
  112. #endif /* BCMWAPI_WAI */
  113. BCMEVENT_NAME(WLC_E_ESCAN_RESULT),
  114. BCMEVENT_NAME(WLC_E_ACTION_FRAME_OFF_CHAN_COMPLETE),
  115. #ifdef WLP2P
  116. BCMEVENT_NAME(WLC_E_PROBRESP_MSG),
  117. BCMEVENT_NAME(WLC_E_P2P_PROBREQ_MSG),
  118. #endif // endif
  119. #ifdef PROP_TXSTATUS
  120. BCMEVENT_NAME(WLC_E_FIFO_CREDIT_MAP),
  121. #endif // endif
  122. BCMEVENT_NAME(WLC_E_WAKE_EVENT),
  123. BCMEVENT_NAME(WLC_E_DCS_REQUEST),
  124. BCMEVENT_NAME(WLC_E_RM_COMPLETE),
  125. BCMEVENT_NAME(WLC_E_OVERLAY_REQ),
  126. BCMEVENT_NAME(WLC_E_CSA_COMPLETE_IND),
  127. BCMEVENT_NAME(WLC_E_EXCESS_PM_WAKE_EVENT),
  128. BCMEVENT_NAME(WLC_E_PFN_SCAN_NONE),
  129. BCMEVENT_NAME(WLC_E_PFN_SCAN_ALLGONE),
  130. #ifdef SOFTAP
  131. BCMEVENT_NAME(WLC_E_GTK_PLUMBED),
  132. #endif // endif
  133. BCMEVENT_NAME(WLC_E_ASSOC_REQ_IE),
  134. BCMEVENT_NAME(WLC_E_ASSOC_RESP_IE),
  135. BCMEVENT_NAME(WLC_E_BEACON_FRAME_RX),
  136. #ifdef WLTDLS
  137. BCMEVENT_NAME(WLC_E_TDLS_PEER_EVENT),
  138. #endif /* WLTDLS */
  139. BCMEVENT_NAME(WLC_E_NATIVE),
  140. #ifdef WLPKTDLYSTAT
  141. BCMEVENT_NAME(WLC_E_PKTDELAY_IND),
  142. #endif /* WLPKTDLYSTAT */
  143. BCMEVENT_NAME(WLC_E_SERVICE_FOUND),
  144. BCMEVENT_NAME(WLC_E_GAS_FRAGMENT_RX),
  145. BCMEVENT_NAME(WLC_E_GAS_COMPLETE),
  146. BCMEVENT_NAME(WLC_E_P2PO_ADD_DEVICE),
  147. BCMEVENT_NAME(WLC_E_P2PO_DEL_DEVICE),
  148. #ifdef WLWNM
  149. BCMEVENT_NAME(WLC_E_WNM_STA_SLEEP),
  150. #endif /* WLWNM */
  151. #if defined(WL_PROXDETECT) || defined(RTT_SUPPORT)
  152. BCMEVENT_NAME(WLC_E_PROXD),
  153. #endif // endif
  154. BCMEVENT_NAME(WLC_E_CCA_CHAN_QUAL),
  155. BCMEVENT_NAME(WLC_E_BSSID),
  156. #ifdef PROP_TXSTATUS
  157. BCMEVENT_NAME(WLC_E_BCMC_CREDIT_SUPPORT),
  158. #endif // endif
  159. BCMEVENT_NAME(WLC_E_PSTA_PRIMARY_INTF_IND),
  160. BCMEVENT_NAME(WLC_E_TXFAIL_THRESH),
  161. #ifdef WLAIBSS
  162. BCMEVENT_NAME(WLC_E_AIBSS_TXFAIL),
  163. #endif /* WLAIBSS */
  164. #ifdef GSCAN_SUPPORT
  165. BCMEVENT_NAME(WLC_E_PFN_GSCAN_FULL_RESULT),
  166. BCMEVENT_NAME(WLC_E_PFN_SSID_EXT),
  167. #endif /* GSCAN_SUPPORT */
  168. #ifdef WLBSSLOAD_REPORT
  169. BCMEVENT_NAME(WLC_E_BSS_LOAD),
  170. #endif // endif
  171. #if defined(BT_WIFI_HANDOVER) || defined(WL_TBOW)
  172. BCMEVENT_NAME(WLC_E_BT_WIFI_HANDOVER_REQ),
  173. #endif // endif
  174. #ifdef WLFBT
  175. BCMEVENT_NAME(WLC_E_FBT),
  176. #endif /* WLFBT */
  177. BCMEVENT_NAME(WLC_E_AUTHORIZED),
  178. BCMEVENT_NAME(WLC_E_PROBREQ_MSG_RX),
  179. BCMEVENT_NAME(WLC_E_CSA_START_IND),
  180. BCMEVENT_NAME(WLC_E_CSA_DONE_IND),
  181. BCMEVENT_NAME(WLC_E_CSA_FAILURE_IND),
  182. BCMEVENT_NAME(WLC_E_RMC_EVENT),
  183. BCMEVENT_NAME(WLC_E_DPSTA_INTF_IND),
  184. BCMEVENT_NAME(WLC_E_ALLOW_CREDIT_BORROW),
  185. BCMEVENT_NAME(WLC_E_MSCH),
  186. BCMEVENT_NAME(WLC_E_ULP),
  187. BCMEVENT_NAME(WLC_E_NAN),
  188. BCMEVENT_NAME(WLC_E_PKT_FILTER),
  189. BCMEVENT_NAME(WLC_E_DMA_TXFLUSH_COMPLETE),
  190. BCMEVENT_NAME(WLC_E_PSK_AUTH),
  191. BCMEVENT_NAME(WLC_E_SDB_TRANSITION),
  192. BCMEVENT_NAME(WLC_E_PFN_SCAN_BACKOFF),
  193. BCMEVENT_NAME(WLC_E_PFN_BSSID_SCAN_BACKOFF),
  194. BCMEVENT_NAME(WLC_E_AGGR_EVENT),
  195. BCMEVENT_NAME(WLC_E_TVPM_MITIGATION),
  196. #ifdef WL_NAN
  197. BCMEVENT_NAME(WLC_E_NAN_CRITICAL),
  198. BCMEVENT_NAME(WLC_E_NAN_NON_CRITICAL),
  199. BCMEVENT_NAME(WLC_E_NAN),
  200. #endif /* WL_NAN */
  201. BCMEVENT_NAME(WLC_E_RPSNOA),
  202. BCMEVENT_NAME(WLC_E_PHY_CAL),
  203. BCMEVENT_NAME(WLC_E_WA_LQM),
  204. };
  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. uint idx;
  214. for (idx = 0; idx < (uint)ARRAYSIZE(bcmevent_names); idx++) {
  215. if (bcmevent_names[idx].event == event_type) {
  216. event_name = bcmevent_names[idx].name;
  217. break;
  218. }
  219. }
  220. /* if we find an event name in the array, return it.
  221. * otherwise return unknown string.
  222. */
  223. return ((event_name) ? event_name : "Unknown Event");
  224. }
  225. void
  226. wl_event_to_host_order(wl_event_msg_t * evt)
  227. {
  228. /* Event struct members passed from dongle to host are stored in network
  229. * byte order. Convert all members to host-order.
  230. */
  231. evt->event_type = ntoh32(evt->event_type);
  232. evt->flags = ntoh16(evt->flags);
  233. evt->status = ntoh32(evt->status);
  234. evt->reason = ntoh32(evt->reason);
  235. evt->auth_type = ntoh32(evt->auth_type);
  236. evt->datalen = ntoh32(evt->datalen);
  237. evt->version = ntoh16(evt->version);
  238. }
  239. void
  240. wl_event_to_network_order(wl_event_msg_t * evt)
  241. {
  242. /* Event struct members passed from dongle to host are stored in network
  243. * byte order. Convert all members to host-order.
  244. */
  245. evt->event_type = hton32(evt->event_type);
  246. evt->flags = hton16(evt->flags);
  247. evt->status = hton32(evt->status);
  248. evt->reason = hton32(evt->reason);
  249. evt->auth_type = hton32(evt->auth_type);
  250. evt->datalen = hton32(evt->datalen);
  251. evt->version = hton16(evt->version);
  252. }
  253. /*
  254. * Validate if the event is proper and if valid copy event header to event.
  255. * If proper event pointer is passed, to just validate, pass NULL to event.
  256. *
  257. * Return values are
  258. * BCME_OK - It is a BRCM event or BRCM dongle event
  259. * BCME_NOTFOUND - Not BRCM, not an event, may be okay
  260. * BCME_BADLEN - Bad length, should not process, just drop
  261. */
  262. int
  263. is_wlc_event_frame(void *pktdata, uint pktlen, uint16 exp_usr_subtype,
  264. bcm_event_msg_u_t *out_event)
  265. {
  266. uint16 evlen = 0; /* length in bcmeth_hdr */
  267. uint16 subtype;
  268. uint16 usr_subtype;
  269. bcm_event_t *bcm_event;
  270. uint8 *pktend;
  271. uint8 *evend;
  272. int err = BCME_OK;
  273. uint32 data_len = 0; /* data length in bcm_event */
  274. pktend = (uint8 *)pktdata + pktlen;
  275. bcm_event = (bcm_event_t *)pktdata;
  276. /* only care about 16-bit subtype / length versions */
  277. if ((uint8 *)&bcm_event->bcm_hdr < pktend) {
  278. uint8 short_subtype = *(uint8 *)&bcm_event->bcm_hdr;
  279. if (!(short_subtype & 0x80)) {
  280. err = BCME_NOTFOUND;
  281. goto done;
  282. }
  283. }
  284. /* must have both ether_header and bcmeth_hdr */
  285. if (pktlen < OFFSETOF(bcm_event_t, event)) {
  286. err = BCME_BADLEN;
  287. goto done;
  288. }
  289. /* check length in bcmeth_hdr */
  290. /* temporary - header length not always set properly. When the below
  291. * !BCMDONGLEHOST is in all branches that use trunk DHD, the code
  292. * under BCMDONGLEHOST can be removed.
  293. */
  294. evlen = (uint16)(pktend - (uint8 *)&bcm_event->bcm_hdr.version);
  295. evend = (uint8 *)&bcm_event->bcm_hdr.version + evlen;
  296. if (evend != pktend) {
  297. err = BCME_BADLEN;
  298. goto done;
  299. }
  300. /* match on subtype, oui and usr subtype for BRCM events */
  301. subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.subtype);
  302. if (subtype != BCMILCP_SUBTYPE_VENDOR_LONG) {
  303. err = BCME_NOTFOUND;
  304. goto done;
  305. }
  306. if (bcmp(BRCM_OUI, &bcm_event->bcm_hdr.oui[0], DOT11_OUI_LEN)) {
  307. err = BCME_NOTFOUND;
  308. goto done;
  309. }
  310. /* if it is a bcm_event or bcm_dngl_event_t, validate it */
  311. usr_subtype = ntoh16_ua((void *)&bcm_event->bcm_hdr.usr_subtype);
  312. switch (usr_subtype) {
  313. case BCMILCP_BCM_SUBTYPE_EVENT:
  314. /* check that header length and pkt length are sufficient */
  315. if ((pktlen < sizeof(bcm_event_t)) ||
  316. (evend < ((uint8 *)bcm_event + sizeof(bcm_event_t)))) {
  317. err = BCME_BADLEN;
  318. goto done;
  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. if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
  328. err = BCME_NOTFOUND;
  329. goto done;
  330. }
  331. if (out_event) {
  332. /* ensure BRCM event pkt aligned */
  333. memcpy(&out_event->event, &bcm_event->event, sizeof(wl_event_msg_t));
  334. }
  335. break;
  336. case BCMILCP_BCM_SUBTYPE_DNGLEVENT:
  337. #if defined(DNGL_EVENT_SUPPORT)
  338. if ((pktlen < sizeof(bcm_dngl_event_t)) ||
  339. (evend < ((uint8 *)bcm_event + sizeof(bcm_dngl_event_t)))) {
  340. err = BCME_BADLEN;
  341. goto done;
  342. }
  343. /* ensure data length in event is not beyond the packet. */
  344. data_len = ntoh16_ua((void *)&((bcm_dngl_event_t *)pktdata)->dngl_event.datalen);
  345. if ((sizeof(bcm_dngl_event_t) + data_len +
  346. BCMILCP_BCM_SUBTYPE_EVENT_DATA_PAD) != pktlen) {
  347. err = BCME_BADLEN;
  348. goto done;
  349. }
  350. if (exp_usr_subtype && (exp_usr_subtype != usr_subtype)) {
  351. err = BCME_NOTFOUND;
  352. goto done;
  353. }
  354. if (out_event) {
  355. /* ensure BRCM dngl event pkt aligned */
  356. memcpy(&out_event->dngl_event, &((bcm_dngl_event_t *)pktdata)->dngl_event,
  357. sizeof(bcm_dngl_event_msg_t));
  358. }
  359. break;
  360. #else
  361. err = BCME_UNSUPPORTED;
  362. break;
  363. #endif // endif
  364. default:
  365. err = BCME_NOTFOUND;
  366. goto done;
  367. }
  368. BCM_REFERENCE(data_len);
  369. done:
  370. return err;
  371. }