esp_event_legacy.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Copyright 2015-2016 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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_EVENT_H__
  14. #define __ESP_EVENT_H__
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include "esp_err.h"
  18. #include "esp_wifi_types.h"
  19. #include "tcpip_adapter.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. typedef enum {
  24. SYSTEM_EVENT_WIFI_READY = 0, /**< ESP32 WiFi ready */
  25. SYSTEM_EVENT_SCAN_DONE, /**< ESP32 finish scanning AP */
  26. SYSTEM_EVENT_STA_START, /**< ESP32 station start */
  27. SYSTEM_EVENT_STA_STOP, /**< ESP32 station stop */
  28. SYSTEM_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */
  29. SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected from AP */
  30. SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP32 station changed */
  31. SYSTEM_EVENT_STA_GOT_IP, /**< ESP32 station got IP from connected AP */
  32. SYSTEM_EVENT_STA_LOST_IP, /**< ESP32 station lost IP and the IP is reset to 0 */
  33. SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /**< ESP32 station wps succeeds in enrollee mode */
  34. SYSTEM_EVENT_STA_WPS_ER_FAILED, /**< ESP32 station wps fails in enrollee mode */
  35. SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP32 station wps timeout in enrollee mode */
  36. SYSTEM_EVENT_STA_WPS_ER_PIN, /**< ESP32 station wps pin code in enrollee mode */
  37. SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP, /*!< ESP32 station wps overlap in enrollee mode */
  38. SYSTEM_EVENT_AP_START, /**< ESP32 soft-AP start */
  39. SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
  40. SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
  41. SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
  42. SYSTEM_EVENT_AP_STAIPASSIGNED, /**< ESP32 soft-AP assign an IP to a connected station */
  43. SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
  44. SYSTEM_EVENT_GOT_IP6, /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
  45. SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */
  46. SYSTEM_EVENT_ETH_STOP, /**< ESP32 ethernet stop */
  47. SYSTEM_EVENT_ETH_CONNECTED, /**< ESP32 ethernet phy link up */
  48. SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP32 ethernet phy link down */
  49. SYSTEM_EVENT_ETH_GOT_IP, /**< ESP32 ethernet got IP from connected AP */
  50. SYSTEM_EVENT_MAX
  51. } system_event_id_t;
  52. /* add this macro define for compatible with old IDF version */
  53. #ifndef SYSTEM_EVENT_AP_STA_GOT_IP6
  54. #define SYSTEM_EVENT_AP_STA_GOT_IP6 SYSTEM_EVENT_GOT_IP6
  55. #endif
  56. typedef enum {
  57. WPS_FAIL_REASON_NORMAL = 0, /**< ESP32 WPS normal fail reason */
  58. WPS_FAIL_REASON_RECV_M2D, /**< ESP32 WPS receive M2D frame */
  59. WPS_FAIL_REASON_MAX
  60. }system_event_sta_wps_fail_reason_t;
  61. typedef struct {
  62. uint32_t status; /**< status of scanning APs */
  63. uint8_t number;
  64. uint8_t scan_id;
  65. } system_event_sta_scan_done_t;
  66. typedef struct {
  67. uint8_t ssid[32]; /**< SSID of connected AP */
  68. uint8_t ssid_len; /**< SSID length of connected AP */
  69. uint8_t bssid[6]; /**< BSSID of connected AP*/
  70. uint8_t channel; /**< channel of connected AP*/
  71. wifi_auth_mode_t authmode;
  72. } system_event_sta_connected_t;
  73. typedef struct {
  74. uint8_t ssid[32]; /**< SSID of disconnected AP */
  75. uint8_t ssid_len; /**< SSID length of disconnected AP */
  76. uint8_t bssid[6]; /**< BSSID of disconnected AP */
  77. uint8_t reason; /**< reason of disconnection */
  78. } system_event_sta_disconnected_t;
  79. typedef struct {
  80. wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
  81. wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
  82. } system_event_sta_authmode_change_t;
  83. typedef struct {
  84. tcpip_adapter_ip_info_t ip_info;
  85. bool ip_changed;
  86. } system_event_sta_got_ip_t;
  87. typedef struct {
  88. uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
  89. } system_event_sta_wps_er_pin_t;
  90. typedef struct {
  91. tcpip_adapter_if_t if_index;
  92. tcpip_adapter_ip6_info_t ip6_info;
  93. } system_event_got_ip6_t;
  94. typedef struct {
  95. uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */
  96. uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */
  97. } system_event_ap_staconnected_t;
  98. typedef struct {
  99. uint8_t mac[6]; /**< MAC address of the station disconnects to ESP32 soft-AP */
  100. uint8_t aid; /**< the aid that ESP32 soft-AP gave to the station disconnects to */
  101. } system_event_ap_stadisconnected_t;
  102. typedef struct {
  103. int rssi; /**< Received probe request signal strength */
  104. uint8_t mac[6]; /**< MAC address of the station which send probe request */
  105. } system_event_ap_probe_req_rx_t;
  106. typedef struct {
  107. ip4_addr_t ip;
  108. } system_event_ap_staipassigned_t;
  109. typedef union {
  110. system_event_sta_connected_t connected; /**< ESP32 station connected to AP */
  111. system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */
  112. system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */
  113. system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
  114. system_event_sta_got_ip_t got_ip; /**< ESP32 station got IP, first time got IP or when IP is changed */
  115. system_event_sta_wps_er_pin_t sta_er_pin; /**< ESP32 station WPS enrollee mode PIN code received */
  116. system_event_sta_wps_fail_reason_t sta_er_fail_reason;/**< ESP32 station WPS enrollee mode failed reason code received */
  117. system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
  118. system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
  119. system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 soft-AP receive probe request packet */
  120. system_event_ap_staipassigned_t ap_staipassigned; /**< ESP32 soft-AP assign an IP to the station*/
  121. system_event_got_ip6_t got_ip6; /**< ESP32 station or ap or ethernet ipv6 addr state change to preferred */
  122. } system_event_info_t;
  123. typedef struct {
  124. system_event_id_t event_id; /**< event ID */
  125. system_event_info_t event_info; /**< event information */
  126. } system_event_t;
  127. typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
  128. /**
  129. * @brief Send a event to event task
  130. *
  131. * @attention 1. Other task/modules, such as the TCPIP module, can call this API to send an event to event task
  132. *
  133. * @param system_event_t * event : event
  134. *
  135. * @return ESP_OK : succeed
  136. * @return others : fail
  137. */
  138. esp_err_t esp_event_send(system_event_t *event);
  139. /**
  140. * @brief Default event handler for system events
  141. *
  142. * This function performs default handling of system events.
  143. * When using esp_event_loop APIs, it is called automatically before invoking the user-provided
  144. * callback function.
  145. *
  146. * Applications which implement a custom event loop must call this function
  147. * as part of event processing.
  148. *
  149. * @param event pointer to event to be handled
  150. * @return ESP_OK if an event was handled successfully
  151. */
  152. esp_err_t esp_event_process_default(system_event_t *event);
  153. /**
  154. * @brief Install default event handlers for Ethernet interface
  155. *
  156. */
  157. void esp_event_set_default_eth_handlers();
  158. /**
  159. * @brief Install default event handlers for Wi-Fi interfaces (station and AP)
  160. *
  161. */
  162. void esp_event_set_default_wifi_handlers();
  163. #ifdef __cplusplus
  164. }
  165. #endif
  166. #endif /* __ESP_EVENT_H__ */