esp_event.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_WPS_ER_SUCCESS, /**< ESP32 station wps succeeds in enrollee mode */
  33. SYSTEM_EVENT_STA_WPS_ER_FAILED, /**< ESP32 station wps fails in enrollee mode */
  34. SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP32 station wps timeout in enrollee mode */
  35. SYSTEM_EVENT_STA_WPS_ER_PIN, /**< ESP32 station wps pin code in enrollee mode */
  36. SYSTEM_EVENT_AP_START, /**< ESP32 soft-AP start */
  37. SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
  38. SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
  39. SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
  40. SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
  41. SYSTEM_EVENT_AP_STA_GOT_IP6, /**< ESP32 station or ap interface v6IP addr is preferred */
  42. SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */
  43. SYSTEM_EVENT_ETH_STOP, /**< ESP32 ethernet stop */
  44. SYSTEM_EVENT_ETH_CONNECTED, /**< ESP32 ethernet phy link up */
  45. SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP32 ethernet phy link down */
  46. SYSTEM_EVENT_ETH_GOT_IP, /**< ESP32 ethernet got IP from connected AP */
  47. SYSTEM_EVENT_MAX
  48. } system_event_id_t;
  49. typedef struct {
  50. uint32_t status; /**< status of scanning APs */
  51. uint8_t number;
  52. uint8_t scan_id;
  53. } system_event_sta_scan_done_t;
  54. typedef struct {
  55. uint8_t ssid[32]; /**< SSID of connected AP */
  56. uint8_t ssid_len; /**< SSID length of connected AP */
  57. uint8_t bssid[6]; /**< BSSID of connected AP*/
  58. uint8_t channel; /**< channel of connected AP*/
  59. wifi_auth_mode_t authmode;
  60. } system_event_sta_connected_t;
  61. typedef struct {
  62. uint8_t ssid[32]; /**< SSID of disconnected AP */
  63. uint8_t ssid_len; /**< SSID length of disconnected AP */
  64. uint8_t bssid[6]; /**< BSSID of disconnected AP */
  65. uint8_t reason; /**< reason of disconnection */
  66. } system_event_sta_disconnected_t;
  67. typedef struct {
  68. wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
  69. wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
  70. } system_event_sta_authmode_change_t;
  71. typedef struct {
  72. tcpip_adapter_ip_info_t ip_info;
  73. } system_event_sta_got_ip_t;
  74. typedef struct {
  75. uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
  76. } system_event_sta_wps_er_pin_t;
  77. typedef struct {
  78. tcpip_adapter_ip6_info_t ip6_info;
  79. } system_event_ap_sta_got_ip6_t;
  80. typedef struct {
  81. uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */
  82. uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */
  83. } system_event_ap_staconnected_t;
  84. typedef struct {
  85. uint8_t mac[6]; /**< MAC address of the station disconnects to ESP32 soft-AP */
  86. uint8_t aid; /**< the aid that ESP32 soft-AP gave to the station disconnects to */
  87. } system_event_ap_stadisconnected_t;
  88. typedef struct {
  89. int rssi; /**< Received probe request signal strength */
  90. uint8_t mac[6]; /**< MAC address of the station which send probe request */
  91. } system_event_ap_probe_req_rx_t;
  92. typedef union {
  93. system_event_sta_connected_t connected; /**< ESP32 station connected to AP */
  94. system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */
  95. system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */
  96. system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
  97. system_event_sta_got_ip_t got_ip; /**< ESP32 station got IP */
  98. system_event_sta_wps_er_pin_t sta_er_pin; /**< ESP32 station WPS enrollee mode PIN code received */
  99. system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
  100. system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
  101. system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 soft-AP receive probe request packet */
  102. system_event_ap_sta_got_ip6_t got_ip6; /**< ESP32 station or ap ipv6 addr state change to preferred */
  103. } system_event_info_t;
  104. typedef struct {
  105. system_event_id_t event_id; /**< event ID */
  106. system_event_info_t event_info; /**< event information */
  107. } system_event_t;
  108. typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
  109. /**
  110. * @brief Send a event to event task
  111. *
  112. * @attention 1. Other task/modules, such as the TCPIP module, can call this API to send an event to event task
  113. *
  114. * @param system_event_t * event : event
  115. *
  116. * @return ESP_OK : succeed
  117. * @return others : fail
  118. */
  119. esp_err_t esp_event_send(system_event_t *event);
  120. /**
  121. * @brief Default event handler for system events
  122. *
  123. * This function performs default handling of system events.
  124. * When using esp_event_loop APIs, it is called automatically before invoking the user-provided
  125. * callback function.
  126. *
  127. * Applications which implement a custom event loop must call this function
  128. * as part of event processing.
  129. *
  130. * @param event pointer to event to be handled
  131. * @return ESP_OK if an event was handled successfully
  132. */
  133. esp_err_t esp_event_process_default(system_event_t *event);
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif /* __ESP_EVENT_H__ */