esp_event_legacy.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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_AP_START, /**< ESP32 soft-AP start */
  38. SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
  39. SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
  40. SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
  41. SYSTEM_EVENT_AP_STAIPASSIGNED, /**< ESP32 soft-AP assign an IP to a connected station */
  42. SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
  43. SYSTEM_EVENT_GOT_IP6, /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
  44. SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */
  45. SYSTEM_EVENT_ETH_STOP, /**< ESP32 ethernet stop */
  46. SYSTEM_EVENT_ETH_CONNECTED, /**< ESP32 ethernet phy link up */
  47. SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP32 ethernet phy link down */
  48. SYSTEM_EVENT_ETH_GOT_IP, /**< ESP32 ethernet got IP from connected AP */
  49. SYSTEM_EVENT_MAX
  50. } system_event_id_t;
  51. /* add this macro define for compatible with old IDF version */
  52. #ifndef SYSTEM_EVENT_AP_STA_GOT_IP6
  53. #define SYSTEM_EVENT_AP_STA_GOT_IP6 SYSTEM_EVENT_GOT_IP6
  54. #endif
  55. typedef enum {
  56. WPS_FAIL_REASON_NORMAL = 0, /**< ESP32 WPS normal fail reason */
  57. WPS_FAIL_REASON_RECV_M2D, /**< ESP32 WPS receive M2D frame */
  58. WPS_FAIL_REASON_MAX
  59. }system_event_sta_wps_fail_reason_t;
  60. typedef struct {
  61. uint32_t status; /**< status of scanning APs */
  62. uint8_t number;
  63. uint8_t scan_id;
  64. } system_event_sta_scan_done_t;
  65. typedef struct {
  66. uint8_t ssid[32]; /**< SSID of connected AP */
  67. uint8_t ssid_len; /**< SSID length of connected AP */
  68. uint8_t bssid[6]; /**< BSSID of connected AP*/
  69. uint8_t channel; /**< channel of connected AP*/
  70. wifi_auth_mode_t authmode;
  71. } system_event_sta_connected_t;
  72. typedef struct {
  73. uint8_t ssid[32]; /**< SSID of disconnected AP */
  74. uint8_t ssid_len; /**< SSID length of disconnected AP */
  75. uint8_t bssid[6]; /**< BSSID of disconnected AP */
  76. uint8_t reason; /**< reason of disconnection */
  77. } system_event_sta_disconnected_t;
  78. typedef struct {
  79. wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
  80. wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
  81. } system_event_sta_authmode_change_t;
  82. typedef struct {
  83. tcpip_adapter_ip_info_t ip_info;
  84. bool ip_changed;
  85. } system_event_sta_got_ip_t;
  86. typedef struct {
  87. uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
  88. } system_event_sta_wps_er_pin_t;
  89. typedef struct {
  90. tcpip_adapter_if_t if_index;
  91. tcpip_adapter_ip6_info_t ip6_info;
  92. } system_event_got_ip6_t;
  93. typedef struct {
  94. uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */
  95. uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */
  96. } system_event_ap_staconnected_t;
  97. typedef struct {
  98. uint8_t mac[6]; /**< MAC address of the station disconnects to ESP32 soft-AP */
  99. uint8_t aid; /**< the aid that ESP32 soft-AP gave to the station disconnects to */
  100. } system_event_ap_stadisconnected_t;
  101. typedef struct {
  102. int rssi; /**< Received probe request signal strength */
  103. uint8_t mac[6]; /**< MAC address of the station which send probe request */
  104. } system_event_ap_probe_req_rx_t;
  105. typedef union {
  106. system_event_sta_connected_t connected; /**< ESP32 station connected to AP */
  107. system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */
  108. system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */
  109. system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
  110. system_event_sta_got_ip_t got_ip; /**< ESP32 station got IP, first time got IP or when IP is changed */
  111. system_event_sta_wps_er_pin_t sta_er_pin; /**< ESP32 station WPS enrollee mode PIN code received */
  112. system_event_sta_wps_fail_reason_t sta_er_fail_reason;/**< ESP32 station WPS enrollee mode failed reason code received */
  113. system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
  114. system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
  115. system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 soft-AP receive probe request packet */
  116. system_event_got_ip6_t got_ip6; /**< ESP32 station or ap or ethernet ipv6 addr state change to preferred */
  117. } system_event_info_t;
  118. typedef struct {
  119. system_event_id_t event_id; /**< event ID */
  120. system_event_info_t event_info; /**< event information */
  121. } system_event_t;
  122. typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
  123. /**
  124. * @brief Send a event to event task
  125. *
  126. * @attention 1. Other task/modules, such as the TCPIP module, can call this API to send an event to event task
  127. *
  128. * @param system_event_t * event : event
  129. *
  130. * @return ESP_OK : succeed
  131. * @return others : fail
  132. */
  133. esp_err_t esp_event_send(system_event_t *event);
  134. /**
  135. * @brief Default event handler for system events
  136. *
  137. * This function performs default handling of system events.
  138. * When using esp_event_loop APIs, it is called automatically before invoking the user-provided
  139. * callback function.
  140. *
  141. * Applications which implement a custom event loop must call this function
  142. * as part of event processing.
  143. *
  144. * @param event pointer to event to be handled
  145. * @return ESP_OK if an event was handled successfully
  146. */
  147. esp_err_t esp_event_process_default(system_event_t *event);
  148. /**
  149. * @brief Install default event handlers for Ethernet interface
  150. *
  151. */
  152. void esp_event_set_default_eth_handlers();
  153. /**
  154. * @brief Install default event handlers for Wi-Fi interfaces (station and AP)
  155. *
  156. */
  157. void esp_event_set_default_wifi_handlers();
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. #endif /* __ESP_EVENT_H__ */