whd_events.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * Copyright 2024, Cypress Semiconductor Corporation (an Infineon company)
  3. * SPDX-License-Identifier: Apache-2.0
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /** @file whd_events.h
  18. * Header for Event detection
  19. *
  20. * Provides constants and prototypes for functions that allow
  21. * user applications to receive event callbacks and set event handlers
  22. */
  23. #ifndef INCLUDED_WHD_EVENTS_API_H
  24. #define INCLUDED_WHD_EVENTS_API_H
  25. #include "whd.h"
  26. #ifdef __cplusplus
  27. extern "C"
  28. {
  29. #endif
  30. /* List of events */
  31. #define WLC_E_NONE (0x7FFFFFFE) /**< Indicates the end of the event array list */
  32. #define WLC_E_SET_SSID 0 /**< Indicates status of set SSID. This event occurs when STA tries to join the AP*/
  33. #define WLC_E_AUTH 3 /**< 802.11 AUTH request event occurs when STA tries to get authenticated with the AP */
  34. #define WLC_E_DEAUTH 5 /**< 802.11 DEAUTH request event occurs when the the SOFTAP is stopped to deuthenticate the connected stations*/
  35. #define WLC_E_DEAUTH_IND 6 /**< 802.11 DEAUTH indication event occurs when the STA gets deauthenticated by the AP */
  36. #define WLC_E_ASSOC 7 /**< 802.11 ASSOC request event occurs when STA joins the AP */
  37. #define WLC_E_ASSOC_IND 8 /**< 802.11 ASSOC indication occurs when a station joins the SOFTAP that is started */
  38. #define WLC_E_REASSOC 9 /**< 802.11 REASSOC request event when the STA again gets associated with the AP */
  39. #define WLC_E_REASSOC_IND 10 /**< 802.11 REASSOC indication occurs when a station again reassociates with the SOFTAP*/
  40. #define WLC_E_DISASSOC 11 /**< 802.11 DISASSOC request occurs when the STA the tries to leave the AP*/
  41. #define WLC_E_DISASSOC_IND 12 /**< 802.11 DISASSOC indication occurs when the connected station gets disassociates from SOFTAP,
  42. also when STA gets diassociated by the AP*/
  43. #define WLC_E_LINK 16 /**< generic link indication */
  44. #define WLC_E_PROBREQ_MSG 44 /**< Indicates probe request received for the SOFTAP started*/
  45. #define WLC_E_PSK_SUP 46 /**< WPA Handshake fail during association*/
  46. #define WLC_E_ACTION_FRAME 59 /**< Indicates Action frame Rx */
  47. #define WLC_E_ACTION_FRAME_COMPLETE 60 /**< Indicates Action frame Tx complete */
  48. #define WLC_E_ESCAN_RESULT 69 /**< escan result event occurs when we scan for the networks */
  49. #define WLC_E_EXT_AUTH_REQ 187 /**< authentication request received */
  50. #define WLC_E_EXT_AUTH_FRAME_RX 188 /**< authentication request received */
  51. #define WLC_E_MGMT_FRAME_TXSTATUS 189 /**< mgmt frame Tx complete */
  52. /* List of status codes - Applicable for any event type */
  53. #define WLC_E_STATUS_SUCCESS 0 /**< operation was successful */
  54. #define WLC_E_STATUS_FAIL 1 /**< operation failed */
  55. #define WLC_E_STATUS_TIMEOUT 2 /**< operation timed out */
  56. #define WLC_E_STATUS_NO_NETWORKS 3 /**< failed due to no matching network found */
  57. #define WLC_E_STATUS_ABORT 4 /**< operation was aborted */
  58. #define WLC_E_STATUS_NO_ACK 5 /**< protocol failure: packet not ack'd */
  59. #define WLC_E_STATUS_UNSOLICITED 6 /**< AUTH or ASSOC packet was unsolicited */
  60. #define WLC_E_STATUS_ATTEMPT 7 /**< attempt to assoc to an auto auth configuration */
  61. #define WLC_E_STATUS_PARTIAL 8 /**< scan results are incomplete */
  62. #define WLC_E_STATUS_NEWSCAN 9 /**< scan aborted by another scan */
  63. #define WLC_E_STATUS_NEWASSOC 10 /**< scan aborted due to assoc in progress */
  64. #define WLC_E_STATUS_11HQUIET 11 /**< 802.11h quiet period started */
  65. #define WLC_E_STATUS_SUPPRESS 12 /**< user disabled scanning (WLC_SET_SCANSUPPRESS) */
  66. #define WLC_E_STATUS_NOCHANS 13 /**< no allowable channels to scan */
  67. #define WLC_E_STATUS_CCXFASTRM 14 /**< scan aborted due to CCX fast roam */
  68. #define WLC_E_STATUS_CS_ABORT 15 /**< abort channel select */
  69. #define WLC_E_STATUS_ERROR 16 /**< request failed due to error */
  70. #define WLC_E_STATUS_INVALID 0xff /**< Invalid status code to init variables. */
  71. #define WLC_SUP_STATUS_OFFSET (256) /**< Status offset added to the status codes to match the values from firmware. */
  72. /**
  73. * @brief Status code for event WLC_E_PSK_SUP
  74. *
  75. * -Basic supplicant authentication states
  76. *
  77. * + WLC_SUP_DISCONNECTED
  78. * + WLC_SUP_CONNECTING
  79. * + WLC_SUP_IDREQUIRED
  80. * + WLC_SUP_AUTHENTICATING
  81. * + WLC_SUP_AUTHENTICATED
  82. * + WLC_SUP_KEYXCHANGE
  83. * + WLC_SUP_KEYED
  84. * + WLC_SUP_TIMEOUT
  85. * + WLC_SUP_LAST_BASIC_STATE
  86. *
  87. * -Extended supplicant authentication states
  88. *
  89. * + WLC_SUP_KEYXCHANGE_WAIT_M1
  90. * + WLC_SUP_KEYXCHANGE_PREP_M2
  91. * + WLC_SUP_KEYXCHANGE_WAIT_M3
  92. * + WLC_SUP_KEYXCHANGE_PREP_M4
  93. * + WLC_SUP_KEYXCHANGE_WAIT_G1
  94. * + WLC_SUP_KEYXCHANGE_PREP_G2
  95. */
  96. typedef enum sup_auth_status
  97. {
  98. WLC_SUP_DISCONNECTED = 0 + WLC_SUP_STATUS_OFFSET, /**< Disconnected */
  99. WLC_SUP_CONNECTING = 1 + WLC_SUP_STATUS_OFFSET, /**< Connecting */
  100. WLC_SUP_IDREQUIRED = 2 + WLC_SUP_STATUS_OFFSET, /**< ID Required */
  101. WLC_SUP_AUTHENTICATING = 3 + WLC_SUP_STATUS_OFFSET, /**< Authenticating */
  102. WLC_SUP_AUTHENTICATED = 4 + WLC_SUP_STATUS_OFFSET, /**< Authenticated */
  103. WLC_SUP_KEYXCHANGE = 5 + WLC_SUP_STATUS_OFFSET, /**< Key Exchange */
  104. WLC_SUP_KEYED = 6 + WLC_SUP_STATUS_OFFSET, /**< Key Exchanged */
  105. WLC_SUP_TIMEOUT = 7 + WLC_SUP_STATUS_OFFSET, /**< Timeout */
  106. WLC_SUP_LAST_BASIC_STATE = 8 + WLC_SUP_STATUS_OFFSET, /**< Last Basic State */
  107. WLC_SUP_KEYXCHANGE_WAIT_M1 = WLC_SUP_AUTHENTICATED, /**< Waiting to receive handshake msg M1 */
  108. WLC_SUP_KEYXCHANGE_PREP_M2 = WLC_SUP_KEYXCHANGE, /**< Preparing to send handshake msg M2 */
  109. WLC_SUP_KEYXCHANGE_WAIT_M3 = WLC_SUP_LAST_BASIC_STATE, /**< Waiting to receive handshake msg M3 */
  110. WLC_SUP_KEYXCHANGE_PREP_M4 = 9 + WLC_SUP_STATUS_OFFSET, /**< Preparing to send handshake msg M4 */
  111. WLC_SUP_KEYXCHANGE_WAIT_G1 = 10 + WLC_SUP_STATUS_OFFSET, /**< Waiting to receive handshake msg G1 */
  112. WLC_SUP_KEYXCHANGE_PREP_G2 = 11 + WLC_SUP_STATUS_OFFSET /**< Preparing to send handshake msg G2 */
  113. } sup_auth_status_t;
  114. #define WHD_MSG_IFNAME_MAX 16 /**< Max length of Interface name */
  115. /* Reason codes for LINK */
  116. #define WLC_E_LINK_BCN_LOSS 1 /**< Link down because of beacon loss */
  117. #define WLC_E_LINK_DISASSOC 2 /**< Link down because of disassoc */
  118. #define WLC_E_LINK_ASSOC_REC 3 /**< Link down because assoc recreate failed */
  119. #define WLC_E_LINK_BSSCFG_DIS 4 /**< Link down due to bsscfg down */
  120. #pragma pack(1)
  121. /**
  122. * Structure to store ethernet header fields in event packets
  123. */
  124. typedef struct whd_event_eth_hdr
  125. {
  126. uint16_t subtype; /**< Vendor specific..32769 */
  127. uint16_t length; /**< Length of ethernet header*/
  128. uint8_t version; /**< Version is 0 */
  129. uint8_t oui[3]; /**< Organizationally Unique Identifier */
  130. uint16_t usr_subtype; /**< User specific data */
  131. } whd_event_eth_hdr_t;
  132. /**
  133. * Structure to store ethernet destination, source and ethertype in event packets
  134. */
  135. typedef struct whd_event_ether_header
  136. {
  137. whd_mac_t destination_address; /**< Ethernet destination address */
  138. whd_mac_t source_address; /**< Ethernet source address */
  139. uint16_t ethertype; /**< Ethertype for identifying event packets */
  140. } whd_event_ether_header_t;
  141. /**
  142. * Structure to store fields after ethernet header in event message
  143. */
  144. struct whd_event_msg
  145. {
  146. uint16_t version; /**< Version */
  147. uint16_t flags; /**< see flags below */
  148. uint32_t event_type; /**< Event type indicating a response from firmware for IOCTLs/IOVARs sent */
  149. uint32_t status; /**< Status code corresponding to any event type */
  150. uint32_t reason; /**< Reason code associated with the event occurred */
  151. uint32_t auth_type; /**< WLC_E_AUTH: 802.11 AUTH request */
  152. uint32_t datalen; /**< Length of data in event message */
  153. whd_mac_t addr; /**< Station address (if applicable) */
  154. char ifname[WHD_MSG_IFNAME_MAX]; /**< name of the incoming packet interface */
  155. uint8_t ifidx; /**< destination OS i/f index */
  156. uint8_t bsscfgidx; /**< source bsscfg index */
  157. };
  158. /**
  159. * Event structure used by driver msgs
  160. */
  161. typedef struct whd_event
  162. {
  163. whd_event_ether_header_t eth; /**< Variable to store ethernet destination, source and ethertype in event packets */
  164. whd_event_eth_hdr_t eth_evt_hdr; /**< Variable to store ethernet header fields in event message */
  165. whd_event_header_t whd_event; /**< Variable to store rest of the event packet fields after ethernet header */
  166. /* data portion follows */
  167. } whd_event_t;
  168. #pragma pack()
  169. /** @addtogroup event WHD Event handling API
  170. * Functions that allow user applications to receive event callbacks and set event handlers
  171. * @{
  172. */
  173. /** Event handler prototype definition
  174. *
  175. * @param ifp Pointer to handle instance of whd interface
  176. * @param event_header whd event header
  177. * @param event_data event data
  178. * @param handler_user_data semaphore data
  179. */
  180. typedef void *(*whd_event_handler_t)(whd_interface_t ifp, const whd_event_header_t *event_header,
  181. const uint8_t *event_data, void *handler_user_data);
  182. /** Error handler prototype definition
  183. *
  184. * @param whd_driver Pointer to handle instance of whd driver
  185. * @param error_type whd error type
  186. * @param event_data event data
  187. * @param handler_user_data semaphore data
  188. */
  189. typedef void *(*whd_error_handler_t)(whd_driver_t whd_driver, const uint8_t *error_type,
  190. const uint8_t *event_data, void *handler_user_data);
  191. /* @} */
  192. /** Registers a handler to receive event callbacks.
  193. *
  194. * This function registers a callback handler to be notified when
  195. * a particular event is received.
  196. *
  197. *
  198. * @note Currently each event may only be registered to one handler and there is a limit to the number of simultaneously
  199. * registered events. Maximum of 5 event handlers can registered simultaneously, this also includes the internal
  200. * event handler registration which happens during scan, join and starting an AP.
  201. *
  202. * @param ifp Pointer to handle instance of whd interface
  203. * @param event_type Pointer to the event list array
  204. * @param handler_func A function pointer to the handler callback
  205. * @param handler_user_data A pointer value which will be passed to the event handler function
  206. * at the time an event is triggered (NULL is allowed)
  207. * @param event_index Entry where the event handler is registered in the list
  208. *
  209. * @return WHD_SUCCESS or Error code
  210. */
  211. whd_result_t whd_wifi_set_event_handler(whd_interface_t ifp, const uint32_t *event_type, whd_event_handler_t handler_func,
  212. void *handler_user_data, uint16_t *event_index);
  213. /** Registers a handler to receive error callbacks.
  214. *
  215. * This function registers a callback handler to be notified when
  216. * a particular event is received.
  217. *
  218. *
  219. * @note Currently each event may only be registered to one handler and there is a limit to the number of simultaneously
  220. * registered events. Maximum of 5 event handlers can registered simultaneously, this also includes the internal
  221. * event handler registration which happens during scan, join and starting an AP.
  222. *
  223. * @param ifp Pointer to handle instance of whd interface
  224. * @param error_nums Pointer to the event list as WLC_ERR_BUS and WLC_ERR_FW
  225. * @param handler_func A function pointer to the handler callback
  226. * @param handler_user_data A pointer value which will be passed to the event handler function
  227. * at the time an event is triggered (NULL is allowed)
  228. * @param error_index Entry where the error handler is registered in the list
  229. *
  230. * @return WHD_SUCCESS or Error code
  231. */
  232. whd_result_t whd_wifi_set_error_handler(whd_interface_t ifp, const uint8_t *error_nums, whd_error_handler_t handler_func,
  233. void *handler_user_data, uint16_t *error_index);
  234. /** Delete/Deregister the event entry where callback is registered
  235. *
  236. * @param ifp Pointer to handle instance of whd interface
  237. * @param event_index Event index obtained during registration by whd_wifi_set_event_handler
  238. *
  239. * @return WHD_SUCCESS or Error code
  240. */
  241. whd_result_t whd_wifi_deregister_event_handler(whd_interface_t ifp, uint16_t event_index);
  242. /** Delete/Deregister the error entry where callback is registered
  243. *
  244. * @param ifp Pointer to handle instance of whd interface
  245. * @param error_index Error index obtained during registration by whd_wifi_set_error_handler
  246. *
  247. * @return WHD_SUCCESS or Error code
  248. */
  249. whd_result_t whd_wifi_deregister_error_handler(whd_interface_t ifp, uint16_t error_index);
  250. #ifdef __cplusplus
  251. } /* extern "C" */
  252. #endif
  253. #endif /* ifndef */