2018-11-05 22:09:32 -05:00
|
|
|
|
// Copyright 2015-2018 Espressif Systems (Shanghai) PTE LTD
|
2016-08-17 11:08:22 -04:00
|
|
|
|
//
|
|
|
|
|
// 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
|
2018-11-05 22:09:32 -05:00
|
|
|
|
//
|
2016-08-17 11:08:22 -04:00
|
|
|
|
// 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.
|
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
#pragma once
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
2016-09-26 23:47:47 -04:00
|
|
|
|
#include "esp_wifi_types.h"
|
2016-09-06 01:02:02 -04:00
|
|
|
|
#include "tcpip_adapter.h"
|
|
|
|
|
|
2016-08-17 11:08:22 -04:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** System event types enumeration */
|
2016-08-17 11:08:22 -04:00
|
|
|
|
typedef enum {
|
2018-11-05 22:09:32 -05:00
|
|
|
|
SYSTEM_EVENT_WIFI_READY = 0, /*!< ESP32 WiFi ready */
|
|
|
|
|
SYSTEM_EVENT_SCAN_DONE, /*!< ESP32 finish scanning AP */
|
|
|
|
|
SYSTEM_EVENT_STA_START, /*!< ESP32 station start */
|
|
|
|
|
SYSTEM_EVENT_STA_STOP, /*!< ESP32 station stop */
|
|
|
|
|
SYSTEM_EVENT_STA_CONNECTED, /*!< ESP32 station connected to AP */
|
|
|
|
|
SYSTEM_EVENT_STA_DISCONNECTED, /*!< ESP32 station disconnected from AP */
|
|
|
|
|
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /*!< the auth mode of AP connected by ESP32 station changed */
|
|
|
|
|
SYSTEM_EVENT_STA_GOT_IP, /*!< ESP32 station got IP from connected AP */
|
|
|
|
|
SYSTEM_EVENT_STA_LOST_IP, /*!< ESP32 station lost IP and the IP is reset to 0 */
|
|
|
|
|
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 */
|
2019-05-28 23:52:51 -04:00
|
|
|
|
SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP, /*!< ESP32 station wps overlap in enrollee mode */
|
2018-11-05 22:09:32 -05:00
|
|
|
|
SYSTEM_EVENT_AP_START, /*!< ESP32 soft-AP start */
|
|
|
|
|
SYSTEM_EVENT_AP_STOP, /*!< ESP32 soft-AP stop */
|
|
|
|
|
SYSTEM_EVENT_AP_STACONNECTED, /*!< a station connected to ESP32 soft-AP */
|
|
|
|
|
SYSTEM_EVENT_AP_STADISCONNECTED, /*!< a station disconnected from ESP32 soft-AP */
|
|
|
|
|
SYSTEM_EVENT_AP_STAIPASSIGNED, /*!< ESP32 soft-AP assign an IP to a connected station */
|
|
|
|
|
SYSTEM_EVENT_AP_PROBEREQRECVED, /*!< Receive probe request packet in soft-AP interface */
|
|
|
|
|
SYSTEM_EVENT_GOT_IP6, /*!< ESP32 station or ap or ethernet interface v6IP addr is preferred */
|
|
|
|
|
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 */
|
|
|
|
|
SYSTEM_EVENT_MAX /*!< Number of members in this enum */
|
2016-08-17 11:08:22 -04:00
|
|
|
|
} system_event_id_t;
|
|
|
|
|
|
2017-07-05 04:29:02 -04: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
|
|
|
|
|
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of SYSTEM_EVENT_STA_WPS_ER_FAILED event */
|
|
|
|
|
typedef wifi_event_sta_wps_fail_reason_t system_event_sta_wps_fail_reason_t;
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of SYSTEM_EVENT_SCAN_DONE event */
|
|
|
|
|
typedef wifi_event_sta_scan_done_t system_event_sta_scan_done_t;
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of SYSTEM_EVENT_STA_CONNECTED event */
|
|
|
|
|
typedef wifi_event_sta_connected_t system_event_sta_connected_t;
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of SYSTEM_EVENT_STA_DISCONNECTED event */
|
|
|
|
|
typedef wifi_event_sta_disconnected_t system_event_sta_disconnected_t;
|
2016-08-19 00:08:45 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of SYSTEM_EVENT_STA_AUTHMODE_CHANGE event */
|
|
|
|
|
typedef wifi_event_sta_authmode_change_t system_event_sta_authmode_change_t;
|
2016-11-09 22:24:31 -05:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of SYSTEM_EVENT_STA_WPS_ER_PIN event */
|
|
|
|
|
typedef wifi_event_sta_wps_er_pin_t system_event_sta_wps_er_pin_t;
|
2016-11-09 04:27:12 -05:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of event */
|
|
|
|
|
typedef wifi_event_ap_staconnected_t system_event_ap_staconnected_t;
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of event */
|
|
|
|
|
typedef wifi_event_ap_stadisconnected_t system_event_ap_stadisconnected_t;
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of event */
|
|
|
|
|
typedef wifi_event_ap_probe_req_rx_t system_event_ap_probe_req_rx_t;
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of event */
|
|
|
|
|
typedef ip_event_ap_staipassigned_t system_event_ap_staipassigned_t;
|
|
|
|
|
|
|
|
|
|
/** Argument structure of event */
|
|
|
|
|
typedef ip_event_got_ip_t system_event_sta_got_ip_t;
|
2019-03-10 23:03:48 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Argument structure of event */
|
|
|
|
|
typedef ip_event_got_ip6_t system_event_got_ip6_t;
|
|
|
|
|
|
|
|
|
|
/** Union of all possible system_event argument structures */
|
2016-08-17 11:08:22 -04:00
|
|
|
|
typedef union {
|
2018-11-05 22:09:32 -05:00
|
|
|
|
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 */
|
|
|
|
|
system_event_sta_got_ip_t got_ip; /*!< ESP32 station got IP, first time got IP or when IP is changed */
|
|
|
|
|
system_event_sta_wps_er_pin_t sta_er_pin; /*!< ESP32 station WPS enrollee mode PIN code received */
|
|
|
|
|
system_event_sta_wps_fail_reason_t sta_er_fail_reason; /*!< ESP32 station WPS enrollee mode failed reason code received */
|
|
|
|
|
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 */
|
|
|
|
|
system_event_ap_probe_req_rx_t ap_probereqrecved; /*!< ESP32 soft-AP receive probe request packet */
|
2019-03-10 23:03:48 -04:00
|
|
|
|
system_event_ap_staipassigned_t ap_staipassigned; /**< ESP32 soft-AP assign an IP to the station*/
|
2018-11-05 22:09:32 -05:00
|
|
|
|
system_event_got_ip6_t got_ip6; /*!< ESP32 station or ap or ethernet ipv6 addr state change to preferred */
|
2016-08-17 11:08:22 -04:00
|
|
|
|
} system_event_info_t;
|
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Event, as a tagged enum */
|
2016-08-17 11:08:22 -04:00
|
|
|
|
typedef struct {
|
2018-11-05 22:09:32 -05:00
|
|
|
|
system_event_id_t event_id; /*!< event ID */
|
|
|
|
|
system_event_info_t event_info; /*!< event information */
|
2016-08-17 11:08:22 -04:00
|
|
|
|
} system_event_t;
|
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/** Event handler function type */
|
2016-09-26 23:47:47 -04:00
|
|
|
|
typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
|
|
|
|
|
|
2016-09-07 08:33:13 -04:00
|
|
|
|
/**
|
|
|
|
|
* @brief Send a event to event task
|
|
|
|
|
*
|
2018-11-21 02:56:06 -05:00
|
|
|
|
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
|
|
|
|
|
*
|
2018-11-05 22:09:32 -05:00
|
|
|
|
* Other task/modules, such as the tcpip_adapter, can call this API to send an event to event task
|
2016-09-12 04:43:32 -04:00
|
|
|
|
*
|
2018-11-05 22:09:32 -05:00
|
|
|
|
* @param event Event to send
|
2016-09-07 08:33:13 -04:00
|
|
|
|
*
|
|
|
|
|
* @return ESP_OK : succeed
|
|
|
|
|
* @return others : fail
|
|
|
|
|
*/
|
2016-09-12 04:43:32 -04:00
|
|
|
|
esp_err_t esp_event_send(system_event_t *event);
|
2016-09-07 08:33:13 -04:00
|
|
|
|
|
|
|
|
|
/**
|
2018-11-05 22:09:32 -05:00
|
|
|
|
* @brief Default event handler for system events
|
|
|
|
|
*
|
2018-11-21 02:56:06 -05:00
|
|
|
|
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
|
|
|
|
|
*
|
2018-11-05 22:09:32 -05: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.
|
|
|
|
|
*
|
|
|
|
|
* Applications which implement a custom event loop must call this function
|
|
|
|
|
* as part of event processing.
|
|
|
|
|
*
|
|
|
|
|
* @param event pointer to event to be handled
|
|
|
|
|
* @return ESP_OK if an event was handled successfully
|
|
|
|
|
*/
|
2016-09-25 13:17:32 -04:00
|
|
|
|
esp_err_t esp_event_process_default(system_event_t *event);
|
2016-09-07 08:33:13 -04:00
|
|
|
|
|
2017-08-16 02:33:37 -04:00
|
|
|
|
/**
|
|
|
|
|
* @brief Install default event handlers for Ethernet interface
|
|
|
|
|
*
|
2018-11-21 02:56:06 -05:00
|
|
|
|
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
|
|
|
|
|
*
|
2017-08-16 02:33:37 -04:00
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
|
void esp_event_set_default_eth_handlers(void);
|
2016-08-17 11:08:22 -04:00
|
|
|
|
|
2017-08-17 00:11:34 -04:00
|
|
|
|
/**
|
|
|
|
|
* @brief Install default event handlers for Wi-Fi interfaces (station and AP)
|
|
|
|
|
*
|
2018-11-21 02:56:06 -05:00
|
|
|
|
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
|
2017-08-17 00:11:34 -04:00
|
|
|
|
*/
|
2019-07-16 05:33:30 -04:00
|
|
|
|
void esp_event_set_default_wifi_handlers(void);
|
2017-08-17 00:11:34 -04:00
|
|
|
|
|
2018-11-05 22:09:32 -05:00
|
|
|
|
/**
|
|
|
|
|
* @brief Application specified event callback function
|
|
|
|
|
*
|
2018-11-21 02:56:06 -05:00
|
|
|
|
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
|
|
|
|
|
*
|
|
|
|
|
*
|
2018-11-05 22:09:32 -05:00
|
|
|
|
* @param ctx reserved for user
|
|
|
|
|
* @param event event type defined in this file
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* - ESP_OK: succeed
|
|
|
|
|
* - others: fail
|
|
|
|
|
*/
|
|
|
|
|
typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Initialize event loop
|
2018-11-21 02:56:06 -05:00
|
|
|
|
*
|
|
|
|
|
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
|
|
|
|
|
*
|
2018-11-05 22:09:32 -05:00
|
|
|
|
* Create the event handler and task
|
|
|
|
|
*
|
|
|
|
|
* @param cb application specified event callback, it can be modified by call esp_event_set_cb
|
|
|
|
|
* @param ctx reserved for user
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
* - ESP_OK: succeed
|
|
|
|
|
* - others: fail
|
|
|
|
|
*/
|
|
|
|
|
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Set application specified event callback function
|
|
|
|
|
*
|
2018-11-21 02:56:06 -05:00
|
|
|
|
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
|
|
|
|
|
*
|
2018-11-05 22:09:32 -05:00
|
|
|
|
* @attention 1. If cb is NULL, means application don't need to handle
|
|
|
|
|
* If cb is not NULL, it will be call when an event is received, after the default event callback is completed
|
|
|
|
|
*
|
|
|
|
|
* @param cb application callback function
|
|
|
|
|
* @param ctx argument to be passed to callback
|
|
|
|
|
*
|
2018-11-21 02:56:06 -05:00
|
|
|
|
*
|
2018-11-05 22:09:32 -05:00
|
|
|
|
* @return old callback
|
|
|
|
|
*/
|
|
|
|
|
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx);
|
|
|
|
|
|
2016-08-17 11:08:22 -04:00
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|