esp_event_legacy.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #pragma once
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #include "esp_wifi_types.h"
  19. #include "esp_netif.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /** System event types enumeration */
  24. typedef enum {
  25. SYSTEM_EVENT_WIFI_READY = 0, /*!< ESP32 WiFi ready */
  26. SYSTEM_EVENT_SCAN_DONE, /*!< ESP32 finish scanning AP */
  27. SYSTEM_EVENT_STA_START, /*!< ESP32 station start */
  28. SYSTEM_EVENT_STA_STOP, /*!< ESP32 station stop */
  29. SYSTEM_EVENT_STA_CONNECTED, /*!< ESP32 station connected to AP */
  30. SYSTEM_EVENT_STA_DISCONNECTED, /*!< ESP32 station disconnected from AP */
  31. SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /*!< the auth mode of AP connected by ESP32 station changed */
  32. SYSTEM_EVENT_STA_GOT_IP, /*!< ESP32 station got IP from connected AP */
  33. SYSTEM_EVENT_STA_LOST_IP, /*!< ESP32 station lost IP and the IP is reset to 0 */
  34. SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /*!< ESP32 station wps succeeds in enrollee mode */
  35. SYSTEM_EVENT_STA_WPS_ER_FAILED, /*!< ESP32 station wps fails in enrollee mode */
  36. SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /*!< ESP32 station wps timeout in enrollee mode */
  37. SYSTEM_EVENT_STA_WPS_ER_PIN, /*!< ESP32 station wps pin code in enrollee mode */
  38. SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP, /*!< ESP32 station wps overlap in enrollee mode */
  39. SYSTEM_EVENT_AP_START, /*!< ESP32 soft-AP start */
  40. SYSTEM_EVENT_AP_STOP, /*!< ESP32 soft-AP stop */
  41. SYSTEM_EVENT_AP_STACONNECTED, /*!< a station connected to ESP32 soft-AP */
  42. SYSTEM_EVENT_AP_STADISCONNECTED, /*!< a station disconnected from ESP32 soft-AP */
  43. SYSTEM_EVENT_AP_STAIPASSIGNED, /*!< ESP32 soft-AP assign an IP to a connected station */
  44. SYSTEM_EVENT_AP_PROBEREQRECVED, /*!< Receive probe request packet in soft-AP interface */
  45. SYSTEM_EVENT_STA_BEACON_TIMEOUT, /*!< ESP32 station beacon timeout */
  46. SYSTEM_EVENT_GOT_IP6, /*!< ESP32 station or ap or ethernet interface v6IP addr is preferred */
  47. SYSTEM_EVENT_ETH_START, /*!< ESP32 ethernet start */
  48. SYSTEM_EVENT_ETH_STOP, /*!< ESP32 ethernet stop */
  49. SYSTEM_EVENT_ETH_CONNECTED, /*!< ESP32 ethernet phy link up */
  50. SYSTEM_EVENT_ETH_DISCONNECTED, /*!< ESP32 ethernet phy link down */
  51. SYSTEM_EVENT_ETH_GOT_IP, /*!< ESP32 ethernet got IP from connected AP */
  52. SYSTEM_EVENT_MAX /*!< Number of members in this enum */
  53. } system_event_id_t;
  54. /* add this macro define for compatible with old IDF version */
  55. #ifndef SYSTEM_EVENT_AP_STA_GOT_IP6
  56. #define SYSTEM_EVENT_AP_STA_GOT_IP6 SYSTEM_EVENT_GOT_IP6
  57. #endif
  58. /** Argument structure of SYSTEM_EVENT_STA_WPS_ER_FAILED event */
  59. typedef wifi_event_sta_wps_fail_reason_t system_event_sta_wps_fail_reason_t;
  60. /** Argument structure of SYSTEM_EVENT_SCAN_DONE event */
  61. typedef wifi_event_sta_scan_done_t system_event_sta_scan_done_t;
  62. /** Argument structure of SYSTEM_EVENT_STA_CONNECTED event */
  63. typedef wifi_event_sta_connected_t system_event_sta_connected_t;
  64. /** Argument structure of SYSTEM_EVENT_STA_DISCONNECTED event */
  65. typedef wifi_event_sta_disconnected_t system_event_sta_disconnected_t;
  66. /** Argument structure of SYSTEM_EVENT_STA_AUTHMODE_CHANGE event */
  67. typedef wifi_event_sta_authmode_change_t system_event_sta_authmode_change_t;
  68. /** Argument structure of SYSTEM_EVENT_STA_WPS_ER_PIN event */
  69. typedef wifi_event_sta_wps_er_pin_t system_event_sta_wps_er_pin_t;
  70. /** Argument structure of SYSTEM_EVENT_STA_WPS_ER_PIN event */
  71. typedef wifi_event_sta_wps_er_success_t system_event_sta_wps_er_success_t;
  72. /** Argument structure of event */
  73. typedef wifi_event_ap_staconnected_t system_event_ap_staconnected_t;
  74. /** Argument structure of event */
  75. typedef wifi_event_ap_stadisconnected_t system_event_ap_stadisconnected_t;
  76. /** Argument structure of event */
  77. typedef wifi_event_ap_probe_req_rx_t system_event_ap_probe_req_rx_t;
  78. /** Argument structure of event */
  79. typedef ip_event_ap_staipassigned_t system_event_ap_staipassigned_t;
  80. /** Argument structure of event */
  81. typedef ip_event_got_ip_t system_event_sta_got_ip_t;
  82. /** Argument structure of event */
  83. typedef ip_event_got_ip6_t system_event_got_ip6_t;
  84. /** Union of all possible system_event argument structures */
  85. typedef union {
  86. system_event_sta_connected_t connected; /*!< ESP32 station connected to AP */
  87. system_event_sta_disconnected_t disconnected; /*!< ESP32 station disconnected to AP */
  88. system_event_sta_scan_done_t scan_done; /*!< ESP32 station scan (APs) done */
  89. system_event_sta_authmode_change_t auth_change; /*!< the auth mode of AP ESP32 station connected to changed */
  90. system_event_sta_got_ip_t got_ip; /*!< ESP32 station got IP, first time got IP or when IP is changed */
  91. system_event_sta_wps_er_pin_t sta_er_pin; /*!< ESP32 station WPS enrollee mode PIN code received */
  92. system_event_sta_wps_fail_reason_t sta_er_fail_reason; /*!< ESP32 station WPS enrollee mode failed reason code received */
  93. system_event_sta_wps_er_success_t sta_er_success; /*!< ESP32 station WPS enrollee success */
  94. system_event_ap_staconnected_t sta_connected; /*!< a station connected to ESP32 soft-AP */
  95. system_event_ap_stadisconnected_t sta_disconnected; /*!< a station disconnected to ESP32 soft-AP */
  96. system_event_ap_probe_req_rx_t ap_probereqrecved; /*!< ESP32 soft-AP receive probe request packet */
  97. system_event_ap_staipassigned_t ap_staipassigned; /**< ESP32 soft-AP assign an IP to the station*/
  98. system_event_got_ip6_t got_ip6; /*!< ESP32 station or ap or ethernet ipv6 addr state change to preferred */
  99. } system_event_info_t;
  100. /** Event, as a tagged enum */
  101. typedef struct {
  102. system_event_id_t event_id; /*!< event ID */
  103. system_event_info_t event_info; /*!< event information */
  104. } system_event_t;
  105. /** Event handler function type */
  106. typedef esp_err_t (*system_event_handler_t)(esp_event_base_t event_base,
  107. int32_t event_id,
  108. void* event_data,
  109. size_t event_data_size,
  110. TickType_t ticks_to_wait);
  111. /**
  112. * @brief Send a event to event task
  113. *
  114. * @note This API is part of the legacy event system. New code should use event library API in esp_event.h
  115. *
  116. * Other task/modules, such as the tcpip_adapter, can call this API to send an event to event task
  117. *
  118. * @param event Event to send
  119. *
  120. * @return ESP_OK : succeed
  121. * @return others : fail
  122. */
  123. esp_err_t esp_event_send(system_event_t *event) __attribute__ ((deprecated));
  124. /**
  125. * @brief Send a event to event task
  126. *
  127. * @note This API is used by WiFi Driver only.
  128. *
  129. * Other task/modules, such as the tcpip_adapter, can call this API to send an event to event task
  130. *
  131. * @param[in] event_base the event base that identifies the event
  132. * @param[in] event_id the event id that identifies the event
  133. * @param[in] event_data the data, specific to the event occurence, that gets passed to the handler
  134. * @param[in] event_data_size the size of the event data
  135. * @param[in] ticks_to_wait number of ticks to block on a full event queue
  136. *
  137. * @return ESP_OK : succeed
  138. * @return others : fail
  139. */
  140. esp_err_t esp_event_send_internal(esp_event_base_t event_base,
  141. int32_t event_id,
  142. void* event_data,
  143. size_t event_data_size,
  144. TickType_t ticks_to_wait);
  145. /**
  146. * @brief Default event handler for system events
  147. *
  148. * @note This API is part of the legacy event system. New code should use event library API in esp_event.h
  149. *
  150. * This function performs default handling of system events.
  151. * When using esp_event_loop APIs, it is called automatically before invoking the user-provided
  152. * callback function.
  153. *
  154. * Applications which implement a custom event loop must call this function
  155. * as part of event processing.
  156. *
  157. * @param event pointer to event to be handled
  158. * @return ESP_OK if an event was handled successfully
  159. */
  160. esp_err_t esp_event_process_default(system_event_t *event) __attribute__ ((deprecated));
  161. /**
  162. * @brief Install default event handlers for Ethernet interface
  163. *
  164. * @note This API is part of the legacy event system. New code should use event library API in esp_event.h
  165. *
  166. */
  167. void esp_event_set_default_eth_handlers(void);
  168. /**
  169. * @brief Install default event handlers for Wi-Fi interfaces (station and AP)
  170. *
  171. * @note This API is part of the legacy event system. New code should use event library API in esp_event.h
  172. */
  173. void esp_event_set_default_wifi_handlers(void) __attribute__ ((deprecated));
  174. /**
  175. * @brief Application specified event callback function
  176. *
  177. * @note This API is part of the legacy event system. New code should use event library API in esp_event.h
  178. *
  179. *
  180. * @param ctx reserved for user
  181. * @param event event type defined in this file
  182. *
  183. * @return
  184. * - ESP_OK: succeed
  185. * - others: fail
  186. */
  187. typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
  188. /**
  189. * @brief Initialize event loop
  190. *
  191. * @note This API is part of the legacy event system. New code should use event library API in esp_event.h
  192. *
  193. * Create the event handler and task
  194. *
  195. * @param cb application specified event callback, it can be modified by call esp_event_set_cb
  196. * @param ctx reserved for user
  197. *
  198. * @return
  199. * - ESP_OK: succeed
  200. * - others: fail
  201. */
  202. esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx) __attribute__ ((deprecated));
  203. /**
  204. * @brief Set application specified event callback function
  205. *
  206. * @note This API is part of the legacy event system. New code should use event library API in esp_event.h
  207. *
  208. * @attention 1. If cb is NULL, means application don't need to handle
  209. * If cb is not NULL, it will be call when an event is received, after the default event callback is completed
  210. *
  211. * @param cb application callback function
  212. * @param ctx argument to be passed to callback
  213. *
  214. *
  215. * @return old callback
  216. */
  217. system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx) __attribute__ ((deprecated));
  218. #ifdef __cplusplus
  219. }
  220. #endif