esp_event.h 5.7 KB

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