2016-08-17 15:08:22 +00:00
|
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#ifndef __ESP_EVENT_H__
|
|
|
|
|
#define __ESP_EVENT_H__
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
2016-09-27 03:47:47 +00:00
|
|
|
|
#include "esp_wifi_types.h"
|
2016-09-06 05:02:02 +00:00
|
|
|
|
#include "tcpip_adapter.h"
|
|
|
|
|
|
2016-08-17 15:08:22 +00:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
2016-09-12 08:43:32 +00:00
|
|
|
|
SYSTEM_EVENT_WIFI_READY = 0, /**< ESP32 WiFi ready */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
SYSTEM_EVENT_SCAN_DONE, /**< ESP32 finish scanning AP */
|
|
|
|
|
SYSTEM_EVENT_STA_START, /**< ESP32 station start */
|
2016-09-12 08:43:32 +00:00
|
|
|
|
SYSTEM_EVENT_STA_STOP, /**< ESP32 station stop */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
SYSTEM_EVENT_STA_CONNECTED, /**< ESP32 station connected to AP */
|
2016-09-12 08:43:32 +00:00
|
|
|
|
SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP32 station disconnected from AP */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP32 station changed */
|
2016-09-12 08:43:32 +00:00
|
|
|
|
SYSTEM_EVENT_STA_GOT_IP, /**< ESP32 station got IP from connected AP */
|
2017-07-19 01:15:11 +00:00
|
|
|
|
SYSTEM_EVENT_STA_LOST_IP, /**< ESP32 station lost IP and the IP is reset to 0 */
|
2016-11-09 09:27:12 +00:00
|
|
|
|
SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /**< ESP32 station wps succeeds in enrollee mode */
|
|
|
|
|
SYSTEM_EVENT_STA_WPS_ER_FAILED, /**< ESP32 station wps fails in enrollee mode */
|
|
|
|
|
SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP32 station wps timeout in enrollee mode */
|
|
|
|
|
SYSTEM_EVENT_STA_WPS_ER_PIN, /**< ESP32 station wps pin code in enrollee mode */
|
2016-09-12 08:43:32 +00:00
|
|
|
|
SYSTEM_EVENT_AP_START, /**< ESP32 soft-AP start */
|
|
|
|
|
SYSTEM_EVENT_AP_STOP, /**< ESP32 soft-AP stop */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP32 soft-AP */
|
2016-09-12 08:43:32 +00:00
|
|
|
|
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
|
2018-04-09 03:01:44 +00:00
|
|
|
|
SYSTEM_EVENT_AP_STAIPASSIGNED, /**< ESP32 soft-AP assign an IP to a connected station */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
|
2017-07-05 08:29:02 +00:00
|
|
|
|
SYSTEM_EVENT_GOT_IP6, /**< ESP32 station or ap or ethernet interface v6IP addr is preferred */
|
2016-11-08 09:45:17 +00:00
|
|
|
|
SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */
|
|
|
|
|
SYSTEM_EVENT_ETH_STOP, /**< ESP32 ethernet stop */
|
|
|
|
|
SYSTEM_EVENT_ETH_CONNECTED, /**< ESP32 ethernet phy link up */
|
|
|
|
|
SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP32 ethernet phy link down */
|
|
|
|
|
SYSTEM_EVENT_ETH_GOT_IP, /**< ESP32 ethernet got IP from connected AP */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
SYSTEM_EVENT_MAX
|
|
|
|
|
} system_event_id_t;
|
|
|
|
|
|
2017-07-05 08:29:02 +00:00
|
|
|
|
/* add this macro define for compatible with old IDF version */
|
|
|
|
|
#ifndef SYSTEM_EVENT_AP_STA_GOT_IP6
|
|
|
|
|
#define SYSTEM_EVENT_AP_STA_GOT_IP6 SYSTEM_EVENT_GOT_IP6
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-06-13 11:37:22 +00:00
|
|
|
|
typedef enum {
|
|
|
|
|
WPS_FAIL_REASON_NORMAL = 0, /**< ESP32 WPS normal fail reason */
|
|
|
|
|
WPS_FAIL_REASON_RECV_M2D, /**< ESP32 WPS receive M2D frame */
|
|
|
|
|
WPS_FAIL_REASON_MAX
|
|
|
|
|
}system_event_sta_wps_fail_reason_t;
|
2016-08-17 15:08:22 +00:00
|
|
|
|
typedef struct {
|
2016-09-12 08:43:32 +00:00
|
|
|
|
uint32_t status; /**< status of scanning APs */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
uint8_t number;
|
2016-08-30 10:09:48 +00:00
|
|
|
|
uint8_t scan_id;
|
2016-08-17 15:08:22 +00:00
|
|
|
|
} system_event_sta_scan_done_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint8_t ssid[32]; /**< SSID of connected AP */
|
|
|
|
|
uint8_t ssid_len; /**< SSID length of connected AP */
|
|
|
|
|
uint8_t bssid[6]; /**< BSSID of connected AP*/
|
|
|
|
|
uint8_t channel; /**< channel of connected AP*/
|
2016-09-06 08:14:40 +00:00
|
|
|
|
wifi_auth_mode_t authmode;
|
2016-08-17 15:08:22 +00:00
|
|
|
|
} system_event_sta_connected_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint8_t ssid[32]; /**< SSID of disconnected AP */
|
|
|
|
|
uint8_t ssid_len; /**< SSID length of disconnected AP */
|
|
|
|
|
uint8_t bssid[6]; /**< BSSID of disconnected AP */
|
|
|
|
|
uint8_t reason; /**< reason of disconnection */
|
|
|
|
|
} system_event_sta_disconnected_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2016-09-06 08:14:40 +00:00
|
|
|
|
wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
|
|
|
|
|
wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
} system_event_sta_authmode_change_t;
|
|
|
|
|
|
2016-08-19 04:08:45 +00:00
|
|
|
|
typedef struct {
|
2016-09-06 05:02:02 +00:00
|
|
|
|
tcpip_adapter_ip_info_t ip_info;
|
2017-07-19 01:15:11 +00:00
|
|
|
|
bool ip_changed;
|
2016-09-06 05:02:02 +00:00
|
|
|
|
} system_event_sta_got_ip_t;
|
2016-08-19 04:08:45 +00:00
|
|
|
|
|
2016-11-09 09:27:12 +00:00
|
|
|
|
typedef struct {
|
2016-11-09 10:15:10 +00:00
|
|
|
|
uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
|
2016-11-10 03:24:31 +00:00
|
|
|
|
} system_event_sta_wps_er_pin_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2017-07-05 08:29:02 +00:00
|
|
|
|
tcpip_adapter_if_t if_index;
|
2016-11-10 03:24:31 +00:00
|
|
|
|
tcpip_adapter_ip6_info_t ip6_info;
|
2017-07-05 08:29:02 +00:00
|
|
|
|
} system_event_got_ip6_t;
|
2016-11-09 09:27:12 +00:00
|
|
|
|
|
2016-08-17 15:08:22 +00:00
|
|
|
|
typedef struct {
|
|
|
|
|
uint8_t mac[6]; /**< MAC address of the station connected to ESP32 soft-AP */
|
|
|
|
|
uint8_t aid; /**< the aid that ESP32 soft-AP gives to the station connected to */
|
|
|
|
|
} system_event_ap_staconnected_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
uint8_t mac[6]; /**< MAC address of the station disconnects to ESP32 soft-AP */
|
|
|
|
|
uint8_t aid; /**< the aid that ESP32 soft-AP gave to the station disconnects to */
|
|
|
|
|
} system_event_ap_stadisconnected_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
int rssi; /**< Received probe request signal strength */
|
|
|
|
|
uint8_t mac[6]; /**< MAC address of the station which send probe request */
|
|
|
|
|
} system_event_ap_probe_req_rx_t;
|
|
|
|
|
|
|
|
|
|
typedef union {
|
|
|
|
|
system_event_sta_connected_t connected; /**< ESP32 station connected to AP */
|
|
|
|
|
system_event_sta_disconnected_t disconnected; /**< ESP32 station disconnected to AP */
|
|
|
|
|
system_event_sta_scan_done_t scan_done; /**< ESP32 station scan (APs) done */
|
|
|
|
|
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP32 station connected to changed */
|
2017-07-19 01:15:11 +00:00
|
|
|
|
system_event_sta_got_ip_t got_ip; /**< ESP32 station got IP, first time got IP or when IP is changed */
|
2016-11-14 06:34:09 +00:00
|
|
|
|
system_event_sta_wps_er_pin_t sta_er_pin; /**< ESP32 station WPS enrollee mode PIN code received */
|
2017-06-13 11:37:22 +00:00
|
|
|
|
system_event_sta_wps_fail_reason_t sta_er_fail_reason;/**< ESP32 station WPS enrollee mode failed reason code received */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP32 soft-AP */
|
|
|
|
|
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP32 soft-AP */
|
2016-09-12 08:43:32 +00:00
|
|
|
|
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP32 soft-AP receive probe request packet */
|
2017-07-05 08:29:02 +00:00
|
|
|
|
system_event_got_ip6_t got_ip6; /**< ESP32 station or ap or ethernet ipv6 addr state change to preferred */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
} system_event_info_t;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2016-09-25 16:51:56 +00:00
|
|
|
|
system_event_id_t event_id; /**< event ID */
|
2016-08-17 15:08:22 +00:00
|
|
|
|
system_event_info_t event_info; /**< event information */
|
|
|
|
|
} system_event_t;
|
|
|
|
|
|
2016-09-27 03:47:47 +00:00
|
|
|
|
typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
|
|
|
|
|
|
2016-09-07 12:33:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief Send a event to event task
|
|
|
|
|
*
|
2016-09-12 08:43:32 +00:00
|
|
|
|
* @attention 1. Other task/modules, such as the TCPIP module, can call this API to send an event to event task
|
|
|
|
|
*
|
2016-09-07 12:33:13 +00:00
|
|
|
|
* @param system_event_t * event : event
|
|
|
|
|
*
|
|
|
|
|
* @return ESP_OK : succeed
|
|
|
|
|
* @return others : fail
|
|
|
|
|
*/
|
2016-09-12 08:43:32 +00:00
|
|
|
|
esp_err_t esp_event_send(system_event_t *event);
|
2016-09-07 12:33:13 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2016-09-25 17:17:32 +00:00
|
|
|
|
* @brief Default event handler for system events
|
2016-09-07 12:33:13 +00:00
|
|
|
|
*
|
2016-09-25 17:17:32 +00:00
|
|
|
|
* This function performs default handling of system events.
|
|
|
|
|
* When using esp_event_loop APIs, it is called automatically before invoking the user-provided
|
|
|
|
|
* callback function.
|
2016-09-12 08:43:32 +00:00
|
|
|
|
*
|
2016-09-25 17:17:32 +00:00
|
|
|
|
* Applications which implement a custom event loop must call this function
|
|
|
|
|
* as part of event processing.
|
2016-09-07 12:33:13 +00:00
|
|
|
|
*
|
2016-09-25 17:17:32 +00:00
|
|
|
|
* @param event pointer to event to be handled
|
|
|
|
|
* @return ESP_OK if an event was handled successfully
|
2016-09-07 12:33:13 +00:00
|
|
|
|
*/
|
2016-09-25 17:17:32 +00:00
|
|
|
|
esp_err_t esp_event_process_default(system_event_t *event);
|
2016-09-07 12:33:13 +00:00
|
|
|
|
|
2017-08-16 06:33:37 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief Install default event handlers for Ethernet interface
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void esp_event_set_default_eth_handlers();
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
2017-08-17 04:11:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* @brief Install default event handlers for Wi-Fi interfaces (station and AP)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void esp_event_set_default_wifi_handlers();
|
|
|
|
|
|
2016-08-17 15:08:22 +00:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif /* __ESP_EVENT_H__ */
|