mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-06-27 20:27:43 +08:00
feat(esp_event): modify for ESP8266 to support esp_event
This commit is contained in:
@ -29,8 +29,6 @@ else()
|
||||
"source/esp_wifi_os_adapter.c"
|
||||
"source/esp_wifi.c"
|
||||
"source/ets_printf.c"
|
||||
"source/event_default_handlers.c"
|
||||
"source/event_loop.c"
|
||||
"source/phy_init.c"
|
||||
"source/reset_reason.c"
|
||||
"source/startup.c"
|
||||
@ -53,7 +51,7 @@ else()
|
||||
|
||||
set(include_dirs "include" "include/driver")
|
||||
|
||||
set(requires "esp_common")
|
||||
set(requires "esp_common" "esp_event")
|
||||
set(priv_requires "wpa_supplicant" "log" "spi_flash" "tcpip_adapter" "esp_ringbuf" "bootloader_support" "nvs_flash" "util")
|
||||
set(fragments linker.lf ld/esp8266_fragments.lf ld/esp8266_bss_fragments.lf)
|
||||
|
||||
|
@ -1,201 +0,0 @@
|
||||
// Copyright 2018 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"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
#include "tcpip_adapter.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define ESP_EVENT_IPV6 LWIP_IPV6
|
||||
|
||||
typedef enum {
|
||||
SYSTEM_EVENT_WIFI_READY = 0, /**< ESP8266 WiFi ready */
|
||||
SYSTEM_EVENT_SCAN_DONE, /**< ESP8266 finish scanning AP */
|
||||
SYSTEM_EVENT_STA_START, /**< ESP8266 station start */
|
||||
SYSTEM_EVENT_STA_STOP, /**< ESP8266 station stop */
|
||||
SYSTEM_EVENT_STA_CONNECTED, /**< ESP8266 station connected to AP */
|
||||
SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP8266 station disconnected from AP */
|
||||
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP8266 station changed */
|
||||
SYSTEM_EVENT_STA_GOT_IP, /**< ESP8266 station got IP from connected AP */
|
||||
SYSTEM_EVENT_STA_LOST_IP, /**< ESP8266 station lost IP and the IP is reset to 0 */
|
||||
SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /**< ESP8266 station wps succeeds in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_FAILED, /**< ESP8266 station wps fails in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP8266 station wps timeout in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_PIN, /**< ESP8266 station wps pin code in enrollee mode */
|
||||
SYSTEM_EVENT_AP_START, /**< ESP8266 soft-AP start */
|
||||
SYSTEM_EVENT_AP_STOP, /**< ESP8266 soft-AP stop */
|
||||
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP8266 soft-AP */
|
||||
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP8266 soft-AP */
|
||||
SYSTEM_EVENT_AP_STAIPASSIGNED, /**< ESP8266 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, /**< ESP8266 station or ap or ethernet interface v6IP addr is preferred */
|
||||
SYSTEM_EVENT_ETH_START, /**< ESP8266 ethernet start */
|
||||
SYSTEM_EVENT_ETH_STOP, /**< ESP8266 ethernet stop */
|
||||
SYSTEM_EVENT_ETH_CONNECTED, /**< ESP8266 ethernet phy link up */
|
||||
SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP8266 ethernet phy link down */
|
||||
SYSTEM_EVENT_ETH_GOT_IP, /**< ESP8266 ethernet got IP from connected AP */
|
||||
SYSTEM_EVENT_MAX
|
||||
} system_event_id_t;
|
||||
|
||||
/* 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
|
||||
|
||||
typedef enum {
|
||||
WPS_FAIL_REASON_NORMAL = 0, /**< ESP8266 WPS normal fail reason */
|
||||
WPS_FAIL_REASON_RECV_M2D, /**< ESP8266 WPS receive M2D frame */
|
||||
WPS_FAIL_REASON_MAX
|
||||
}system_event_sta_wps_fail_reason_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t status; /**< status of scanning APs */
|
||||
uint8_t number;
|
||||
uint8_t scan_id;
|
||||
} 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*/
|
||||
wifi_auth_mode_t authmode;
|
||||
} 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 {
|
||||
wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
|
||||
wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
|
||||
} system_event_sta_authmode_change_t;
|
||||
|
||||
typedef struct {
|
||||
tcpip_adapter_ip_info_t ip_info;
|
||||
bool ip_changed;
|
||||
} system_event_sta_got_ip_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
|
||||
} system_event_sta_wps_er_pin_t;
|
||||
|
||||
typedef struct {
|
||||
tcpip_adapter_if_t if_index;
|
||||
tcpip_adapter_ip6_info_t ip6_info;
|
||||
} system_event_got_ip6_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t mac[6]; /**< MAC address of the station connected to ESP8266 soft-AP */
|
||||
uint8_t aid; /**< the aid that ESP8266 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 ESP8266 soft-AP */
|
||||
uint8_t aid; /**< the aid that ESP8266 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; /**< ESP8266 station connected to AP */
|
||||
system_event_sta_disconnected_t disconnected; /**< ESP8266 station disconnected to AP */
|
||||
system_event_sta_scan_done_t scan_done; /**< ESP8266 station scan (APs) done */
|
||||
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP8266 station connected to changed */
|
||||
system_event_sta_got_ip_t got_ip; /**< ESP8266 station got IP, first time got IP or when IP is changed */
|
||||
system_event_sta_wps_er_pin_t sta_er_pin; /**< ESP8266 station WPS enrollee mode PIN code received */
|
||||
system_event_sta_wps_fail_reason_t sta_er_fail_reason;/**< ESP8266 station WPS enrollee mode failed reason code received */
|
||||
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP8266 soft-AP */
|
||||
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP8266 soft-AP */
|
||||
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP8266 soft-AP receive probe request packet */
|
||||
system_event_got_ip6_t got_ip6; /**< ESP8266 station or ap or ethernet ipv6 addr state change to preferred */
|
||||
} system_event_info_t;
|
||||
|
||||
typedef struct {
|
||||
system_event_id_t event_id; /**< event ID */
|
||||
system_event_info_t event_info; /**< event information */
|
||||
} system_event_t;
|
||||
|
||||
typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Send a event to event task
|
||||
*
|
||||
* @attention 1. Other task/modules, such as the TCPIP module, can call this API to send an event to event task
|
||||
*
|
||||
* @param system_event_t * event : event
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
esp_err_t esp_event_send(system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Default event handler for system events
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
esp_err_t esp_event_process_default(system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Install default event handlers for Wi-Fi interfaces (station and AP)
|
||||
*
|
||||
*/
|
||||
void esp_event_set_default_wifi_handlers();
|
||||
|
||||
/**
|
||||
* @brief Create default event loop
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: Success
|
||||
* - ESP_ERR_NO_MEM: Cannot allocate memory for event loops list
|
||||
* - ESP_FAIL: Failed to create task loop
|
||||
* - Others: Fail
|
||||
*/
|
||||
esp_err_t esp_event_loop_create_default(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP_EVENT_H__ */
|
@ -1,83 +0,0 @@
|
||||
// Copyright 2018 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_LOOP_H__
|
||||
#define __ESP_EVENT_LOOP_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_event.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/queue.h"
|
||||
|
||||
#define EVENT_LOOP_STACKSIZE CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Application specified event callback function
|
||||
*
|
||||
* @param void *ctx : reserved for user
|
||||
* @param system_event_t *event : event type defined in this file
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
|
||||
|
||||
/**
|
||||
* @brief Initialize event loop
|
||||
* Create the event handler and task
|
||||
*
|
||||
* @param system_event_cb_t cb : application specified event callback, it can be modified by call esp_event_set_cb
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
*/
|
||||
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Set application specified event callback function
|
||||
*
|
||||
* @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 system_event_cb_t cb : callback
|
||||
* @param void *ctx : reserved for user
|
||||
*
|
||||
* @return system_event_cb_t : old callback
|
||||
*/
|
||||
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx);
|
||||
|
||||
/**
|
||||
* @brief Get the queue used by event loop
|
||||
*
|
||||
* @attention : currently this API is used to initialize "q" parameter
|
||||
* of wifi_init structure.
|
||||
*
|
||||
* @return QueueHandle_t : event queue handle
|
||||
*/
|
||||
QueueHandle_t esp_event_loop_get_queue(void);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ESP_EVENT_LOOP_H__ */
|
@ -18,8 +18,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sys/queue.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_interface.h"
|
||||
#include "esp_event_base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -418,6 +420,91 @@ typedef struct {
|
||||
unsigned unused: 4; /*!< Resolved */
|
||||
} wifi_tx_status_t;
|
||||
|
||||
/** @cond **/
|
||||
/** @brief WiFi event base declaration */
|
||||
ESP_EVENT_DECLARE_BASE(WIFI_EVENT);
|
||||
/** @endcond **/
|
||||
|
||||
/** WiFi event declarations */
|
||||
typedef enum {
|
||||
WIFI_EVENT_WIFI_READY = 0, /**< WiFi ready */
|
||||
WIFI_EVENT_SCAN_DONE, /**< finish scanning AP */
|
||||
WIFI_EVENT_STA_START, /**< station start */
|
||||
WIFI_EVENT_STA_STOP, /**< station stop */
|
||||
WIFI_EVENT_STA_CONNECTED, /**< station connected to AP */
|
||||
WIFI_EVENT_STA_DISCONNECTED, /**< station disconnected from AP */
|
||||
WIFI_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by station changed */
|
||||
WIFI_EVENT_STA_WPS_ER_SUCCESS, /**< station wps succeeds in enrollee mode */
|
||||
WIFI_EVENT_STA_WPS_ER_FAILED, /**< station wps fails in enrollee mode */
|
||||
WIFI_EVENT_STA_WPS_ER_TIMEOUT, /**< station wps timeout in enrollee mode */
|
||||
WIFI_EVENT_STA_WPS_ER_PIN, /**< station wps pin code in enrollee mode */
|
||||
WIFI_EVENT_AP_START, /**< soft-AP start */
|
||||
WIFI_EVENT_AP_STOP, /**< soft-AP stop */
|
||||
WIFI_EVENT_AP_STACONNECTED, /**< a station connected to soft-AP */
|
||||
WIFI_EVENT_AP_STADISCONNECTED, /**< a station disconnected from soft-AP */
|
||||
WIFI_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
|
||||
} wifi_event_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_STA_WPS_ER_FAILED event */
|
||||
typedef enum {
|
||||
WPS_FAIL_REASON_NORMAL = 0, /**< WPS normal fail reason */
|
||||
WPS_FAIL_REASON_RECV_M2D, /**< WPS receive M2D frame */
|
||||
WPS_FAIL_REASON_MAX
|
||||
} wifi_event_sta_wps_fail_reason_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_SCAN_DONE event */
|
||||
typedef struct {
|
||||
uint32_t status; /**< status of scanning APs: 0 — success, 1 - failure */
|
||||
uint8_t number; /**< number of scan results */
|
||||
uint8_t scan_id; /**< scan sequence number, used for block scan */
|
||||
} wifi_event_sta_scan_done_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_STA_CONNECTED event */
|
||||
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*/
|
||||
wifi_auth_mode_t authmode;/**< authentication mode used by AP*/
|
||||
} wifi_event_sta_connected_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_STA_AUTHMODE_CHANGE event */
|
||||
typedef struct {
|
||||
wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
|
||||
wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
|
||||
} wifi_event_sta_authmode_change_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_STA_WPS_ER_PIN event */
|
||||
typedef struct {
|
||||
uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
|
||||
} wifi_event_sta_wps_er_pin_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_AP_STACONNECTED event */
|
||||
typedef struct {
|
||||
uint8_t mac[6]; /**< MAC address of the station connected to soft-AP */
|
||||
uint8_t aid; /**< the aid that soft-AP gives to the station connected to */
|
||||
} wifi_event_ap_staconnected_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_AP_STADISCONNECTED event */
|
||||
typedef struct {
|
||||
uint8_t mac[6]; /**< MAC address of the station disconnects to soft-AP */
|
||||
uint8_t aid; /**< the aid that soft-AP gave to the station disconnects to */
|
||||
} wifi_event_ap_stadisconnected_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_AP_PROBEREQRECVED event */
|
||||
typedef struct {
|
||||
int rssi; /**< Received probe request signal strength */
|
||||
uint8_t mac[6]; /**< MAC address of the station which send probe request */
|
||||
} wifi_event_ap_probe_req_rx_t;
|
||||
|
||||
/** Argument structure for WIFI_EVENT_STA_DISCONNECTED event */
|
||||
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 */
|
||||
} wifi_event_sta_disconnected_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -16,9 +16,12 @@
|
||||
#include "esp_libc.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_log.h"
|
||||
#include "internal/esp_wifi_internal.h"
|
||||
#include "phy.h"
|
||||
|
||||
#define TAG "wifi_init"
|
||||
|
||||
const size_t _g_esp_wifi_ppt_task_stk_size = CONFIG_WIFI_PPT_TASKSTACK_SIZE;
|
||||
|
||||
#if CONFIG_ESP8266_WIFI_CONNECT_OPEN_ROUTER_WHEN_PWD_IS_SET
|
||||
@ -29,6 +32,8 @@ const bool _g_esp_wifi_connect_open_router_when_pwd_is_set = false;
|
||||
|
||||
esp_err_t esp_wifi_init_internal(const wifi_init_config_t *config);
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(WIFI_EVENT);
|
||||
|
||||
static void esp_wifi_set_debug_log()
|
||||
{
|
||||
/* set WiFi log level and module */
|
||||
@ -124,11 +129,16 @@ static void esp_wifi_set_debug_log()
|
||||
*/
|
||||
esp_err_t esp_wifi_init(const wifi_init_config_t *config)
|
||||
{
|
||||
esp_event_set_default_wifi_handlers();
|
||||
esp_err_t result = esp_wifi_init_internal(config);
|
||||
if (result == ESP_OK) {
|
||||
esp_wifi_set_debug_log();
|
||||
}
|
||||
|
||||
result = tcpip_adapter_set_default_wifi_handlers();
|
||||
if (result != ESP_OK) {
|
||||
ESP_LOGW(TAG, "Failed to set default Wi-Fi event handlers (0x%x)", result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1,323 +0,0 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_system.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
|
||||
#include "tcpip_adapter.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char* TAG = "event";
|
||||
|
||||
#define WIFI_API_CALL_CHECK(info, api_call, ret) \
|
||||
do{\
|
||||
esp_err_t __err = (api_call);\
|
||||
if ((ret) != __err) {\
|
||||
ESP_LOGE(TAG, "%s %d %s ret=0x%X", __FUNCTION__, __LINE__, (info), __err);\
|
||||
return __err;\
|
||||
}\
|
||||
} while(0)
|
||||
|
||||
typedef esp_err_t (*system_event_handler_t)(system_event_t *e);
|
||||
|
||||
static esp_err_t system_event_ap_start_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_ap_stop_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_start_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_stop_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_connected_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_got_ip_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_lost_ip_default(system_event_t *event);
|
||||
|
||||
/* Default event handler functions
|
||||
|
||||
Any entry in this table which is disabled by config will have a NULL handler.
|
||||
*/
|
||||
static system_event_handler_t default_event_handlers[SYSTEM_EVENT_MAX] = { 0 };
|
||||
|
||||
static esp_err_t system_event_sta_got_ip_default(system_event_t *event)
|
||||
{
|
||||
ESP_LOGI(TAG, "sta ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR,
|
||||
IP2STR(&event->event_info.got_ip.ip_info.ip),
|
||||
IP2STR(&event->event_info.got_ip.ip_info.netmask),
|
||||
IP2STR(&event->event_info.got_ip.ip_info.gw));
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t system_event_sta_lost_ip_default(system_event_t *event)
|
||||
{
|
||||
ESP_LOGI(TAG, "station ip lost");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_ap_start_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_ip_info_t ap_ip;
|
||||
uint8_t ap_mac[6];
|
||||
|
||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_AP, ap_mac), ESP_OK);
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_AP, ap_mac, &ap_ip);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_ap_stop_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_stop(TCPIP_ADAPTER_IF_AP);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_sta_start_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_ip_info_t sta_ip;
|
||||
uint8_t sta_mac[6];
|
||||
|
||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_STA, sta_mac), ESP_OK);
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_STA, sta_mac, &sta_ip);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_sta_stop_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_stop(TCPIP_ADAPTER_IF_STA);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_dhcp_status_t status;
|
||||
|
||||
tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
|
||||
tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &status);
|
||||
|
||||
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
|
||||
} else if (status == TCPIP_ADAPTER_DHCP_STOPPED) {
|
||||
tcpip_adapter_ip_info_t sta_ip;
|
||||
tcpip_adapter_ip_info_t sta_old_ip;
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||
tcpip_adapter_get_old_ip_info(TCPIP_ADAPTER_IF_STA, &sta_old_ip);
|
||||
|
||||
if (!(ip4_addr_isany_val(sta_ip.ip) || ip4_addr_isany_val(sta_ip.netmask) || ip4_addr_isany_val(sta_ip.gw))) {
|
||||
system_event_t evt;
|
||||
|
||||
evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
|
||||
evt.event_info.got_ip.ip_changed = false;
|
||||
|
||||
if (memcmp(&sta_ip, &sta_old_ip, sizeof(sta_ip))) {
|
||||
evt.event_info.got_ip.ip_changed = true;
|
||||
}
|
||||
|
||||
memcpy(&evt.event_info.got_ip.ip_info, &sta_ip, sizeof(tcpip_adapter_ip_info_t));
|
||||
tcpip_adapter_set_old_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||
|
||||
esp_event_send(&evt);
|
||||
ESP_LOGD(TAG, "static ip: ip changed=%d", evt.event_info.got_ip.ip_changed);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "invalid static ip");
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_down(TCPIP_ADAPTER_IF_STA);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static esp_err_t esp_system_event_debug(system_event_t *event)
|
||||
{
|
||||
if (event == NULL) {
|
||||
ESP_LOGE(TAG, "event is null!");
|
||||
printf("event is null!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
switch (event->event_id) {
|
||||
case SYSTEM_EVENT_WIFI_READY: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_WIFI_READY");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_SCAN_DONE: {
|
||||
system_event_sta_scan_done_t *scan_done = &event->event_info.scan_done;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_SCAN_DONE, status:%d, number:%d", scan_done->status, scan_done->number);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_START: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_START");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_STOP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_STOP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_CONNECTED: {
|
||||
system_event_sta_connected_t *connected = &event->event_info.connected;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_CONNECTED, ssid:%s, ssid_len:%d, bssid:" MACSTR ", channel:%d, authmode:%d", \
|
||||
connected->ssid, connected->ssid_len, MAC2STR(connected->bssid), connected->channel, connected->authmode);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_DISCONNECTED: {
|
||||
system_event_sta_disconnected_t *disconnected = &event->event_info.disconnected;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_DISCONNECTED, ssid:%s, ssid_len:%d, bssid:" MACSTR ", reason:%d", \
|
||||
disconnected->ssid, disconnected->ssid_len, MAC2STR(disconnected->bssid), disconnected->reason);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: {
|
||||
system_event_sta_authmode_change_t *auth_change = &event->event_info.auth_change;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_AUTHMODE_CHNAGE, old_mode:%d, new_mode:%d", auth_change->old_mode, auth_change->new_mode);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_GOT_IP: {
|
||||
system_event_sta_got_ip_t *got_ip = &event->event_info.got_ip;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_GOT_IP, ip:" IPSTR ", mask:" IPSTR ", gw:" IPSTR,
|
||||
IP2STR(&got_ip->ip_info.ip),
|
||||
IP2STR(&got_ip->ip_info.netmask),
|
||||
IP2STR(&got_ip->ip_info.gw));
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_LOST_IP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_LOST_IP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_SUCCESS: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_SUCCESS");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_FAILED: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_FAILED");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_TIMEOUT");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_PIN: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_PIN");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_START: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_START");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STOP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STOP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STACONNECTED: {
|
||||
system_event_ap_staconnected_t *staconnected = &event->event_info.sta_connected;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STACONNECTED, mac:" MACSTR ", aid:%d", \
|
||||
MAC2STR(staconnected->mac), staconnected->aid);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STADISCONNECTED: {
|
||||
system_event_ap_stadisconnected_t *stadisconnected = &event->event_info.sta_disconnected;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STADISCONNECTED, mac:" MACSTR ", aid:%d", \
|
||||
MAC2STR(stadisconnected->mac), stadisconnected->aid);
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_STAIPASSIGNED: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STAIPASSIGNED");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_PROBEREQRECVED: {
|
||||
system_event_ap_probe_req_rx_t *ap_probereqrecved = &event->event_info.ap_probereqrecved;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:" MACSTR, \
|
||||
ap_probereqrecved->rssi, \
|
||||
MAC2STR(ap_probereqrecved->mac));
|
||||
break;
|
||||
}
|
||||
#if ESP_EVENT_IPV6
|
||||
case SYSTEM_EVENT_GOT_IP6: {
|
||||
ip6_addr_t *addr = &event->event_info.got_ip6.ip6_info.ip;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STA_GOT_IP6 address %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
|
||||
IP6_ADDR_BLOCK1(addr),
|
||||
IP6_ADDR_BLOCK2(addr),
|
||||
IP6_ADDR_BLOCK3(addr),
|
||||
IP6_ADDR_BLOCK4(addr),
|
||||
IP6_ADDR_BLOCK5(addr),
|
||||
IP6_ADDR_BLOCK6(addr),
|
||||
IP6_ADDR_BLOCK7(addr),
|
||||
IP6_ADDR_BLOCK8(addr));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
default: {
|
||||
ESP_LOGW(TAG, "unexpected system event %d!", event->event_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_process_default(system_event_t *event)
|
||||
{
|
||||
if (event == NULL) {
|
||||
ESP_LOGE(TAG, "Error: event is null!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_system_event_debug(event);
|
||||
if ((event->event_id < SYSTEM_EVENT_MAX)) {
|
||||
if (default_event_handlers[event->event_id] != NULL) {
|
||||
ESP_LOGV(TAG, "enter default callback");
|
||||
default_event_handlers[event->event_id](event);
|
||||
ESP_LOGV(TAG, "exit default callback");
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "mismatch or invalid event, id=%d", event->event_id);
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
void esp_event_set_default_wifi_handlers()
|
||||
{
|
||||
default_event_handlers[SYSTEM_EVENT_STA_START] = system_event_sta_start_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_STOP] = system_event_sta_stop_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_CONNECTED] = system_event_sta_connected_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_DISCONNECTED] = system_event_sta_disconnected_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_GOT_IP] = system_event_sta_got_ip_default;
|
||||
default_event_handlers[SYSTEM_EVENT_STA_LOST_IP] = system_event_sta_lost_ip_default;
|
||||
default_event_handlers[SYSTEM_EVENT_AP_START] = system_event_ap_start_handle_default;
|
||||
default_event_handlers[SYSTEM_EVENT_AP_STOP] = system_event_ap_stop_handle_default;
|
||||
|
||||
//esp_register_shutdown_handler((shutdown_handler_t)esp_wifi_stop);
|
||||
}
|
@ -1,116 +0,0 @@
|
||||
// Copyright 2018 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.
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "queue.h"
|
||||
|
||||
static const char* TAG = "event";
|
||||
static bool s_event_init_flag = false;
|
||||
static void *s_event_queue = NULL;
|
||||
static system_event_cb_t s_event_handler_cb = NULL;
|
||||
static void *s_event_ctx = NULL;
|
||||
|
||||
static esp_err_t esp_event_post_to_user(system_event_t *event)
|
||||
{
|
||||
if (s_event_handler_cb) {
|
||||
return (*s_event_handler_cb)(s_event_ctx, event);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void esp_event_loop_task(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
system_event_t evt;
|
||||
if (xQueueReceive(s_event_queue, &evt, portMAX_DELAY) == pdPASS) {
|
||||
esp_err_t ret = esp_event_process_default(&evt);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "default event handler failed!");
|
||||
}
|
||||
ret = esp_event_post_to_user(&evt);
|
||||
if (ret != ESP_OK) {
|
||||
ESP_LOGE(TAG, "post event to user fail!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx)
|
||||
{
|
||||
system_event_cb_t old_cb = s_event_handler_cb;
|
||||
s_event_handler_cb = cb;
|
||||
s_event_ctx = ctx;
|
||||
return old_cb;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_send(system_event_t *event)
|
||||
{
|
||||
if (s_event_queue == NULL) {
|
||||
ESP_LOGE(TAG, "Event loop not initialized via esp_event_loop_init, but esp_event_send called");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
int ret = xQueueGenericSend(s_event_queue, event, 0, queueSEND_TO_BACK);
|
||||
if (ret != pdPASS) {
|
||||
if (event) {
|
||||
ESP_LOGE(TAG, "e=%d f", event->event_id);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "e null");
|
||||
}
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
QueueHandle_t esp_event_loop_get_queue(void)
|
||||
{
|
||||
return s_event_queue;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx)
|
||||
{
|
||||
if (s_event_init_flag) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
s_event_handler_cb = cb;
|
||||
s_event_ctx = ctx;
|
||||
s_event_queue = xQueueCreate(32, sizeof(system_event_t));
|
||||
if(s_event_queue == NULL)
|
||||
return ESP_ERR_NO_MEM;
|
||||
if(xTaskCreate(esp_event_loop_task, "esp_event_loop_task", EVENT_LOOP_STACKSIZE, NULL, configMAX_PRIORITIES - 5, NULL) != pdPASS) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
s_event_handler_cb = cb;
|
||||
s_event_ctx = ctx;
|
||||
s_event_init_flag = true;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_event_loop_create_default(void)
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
@ -5,9 +5,7 @@ idf_component_register(SRCS "default_event_loop.c"
|
||||
"event_send.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_INCLUDE_DIRS "private_include"
|
||||
REQUIRES log tcpip_adapter
|
||||
PRIV_REQUIRES esp_eth
|
||||
LDFRAGMENTS linker.lf)
|
||||
REQUIRES log tcpip_adapter)
|
||||
|
||||
if(GCC_NOT_5_2_0 AND CONFIG_ESP_EVENT_LOOP_PROFILING)
|
||||
# uses C11 atomic feature
|
||||
|
@ -14,12 +14,4 @@ menu "Event Loop Library"
|
||||
help
|
||||
Enable posting events from interrupt handlers.
|
||||
|
||||
config ESP_EVENT_POST_FROM_IRAM_ISR
|
||||
bool "Support posting events from ISRs placed in IRAM"
|
||||
default y
|
||||
depends on ESP_EVENT_POST_FROM_ISR
|
||||
help
|
||||
Enable posting events from interrupt handlers placed in IRAM. Enabling this option places API functions
|
||||
esp_event_post and esp_event_post_to in IRAM.
|
||||
|
||||
endmenu
|
||||
|
@ -4,7 +4,6 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS := include
|
||||
COMPONENT_PRIV_INCLUDEDIRS := private_include
|
||||
COMPONENT_SRCDIRS := .
|
||||
COMPONENT_ADD_LDFRAGMENTS := linker.lf
|
||||
|
||||
ifdef CONFIG_ESP_EVENT_LOOP_PROFILING
|
||||
PROFILING_ENABLED := 1
|
||||
|
@ -17,7 +17,6 @@
|
||||
#include "esp_event_legacy.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "tcpip_adapter.h"
|
||||
#include "esp_eth.h"
|
||||
|
||||
/**
|
||||
* The purpose of this file is to provide an "esp_event_send_to_default_loop"
|
||||
@ -80,7 +79,6 @@ esp_err_t esp_event_send_to_default_loop(system_event_t *event)
|
||||
HANDLE_SYS_EVENT(WIFI, STA_WPS_ER_TIMEOUT);
|
||||
HANDLE_SYS_EVENT_ARG(WIFI, STA_WPS_ER_FAILED, sta_er_fail_reason);
|
||||
HANDLE_SYS_EVENT_ARG(WIFI, STA_WPS_ER_PIN, sta_er_pin);
|
||||
HANDLE_SYS_EVENT(WIFI, STA_WPS_ER_PBC_OVERLAP);
|
||||
|
||||
/* AP events */
|
||||
HANDLE_SYS_EVENT(WIFI, AP_START);
|
||||
@ -89,21 +87,8 @@ esp_err_t esp_event_send_to_default_loop(system_event_t *event)
|
||||
HANDLE_SYS_EVENT_ARG(WIFI, AP_STADISCONNECTED, sta_disconnected);
|
||||
HANDLE_SYS_EVENT_ARG(WIFI, AP_PROBEREQRECVED, ap_probereqrecved);
|
||||
|
||||
/* Ethernet events */
|
||||
/* Some extra defines to fit the old naming scheme... */
|
||||
#define ETH_EVENT_ETH_START ETHERNET_EVENT_START
|
||||
#define ETH_EVENT_ETH_STOP ETHERNET_EVENT_STOP
|
||||
#define ETH_EVENT_ETH_CONNECTED ETHERNET_EVENT_CONNECTED
|
||||
#define ETH_EVENT_ETH_DISCONNECTED ETHERNET_EVENT_DISCONNECTED
|
||||
|
||||
HANDLE_SYS_EVENT(ETH, ETH_START);
|
||||
HANDLE_SYS_EVENT(ETH, ETH_STOP);
|
||||
HANDLE_SYS_EVENT(ETH, ETH_CONNECTED);
|
||||
HANDLE_SYS_EVENT(ETH, ETH_DISCONNECTED);
|
||||
|
||||
/* IP events */
|
||||
HANDLE_SYS_EVENT_ARG(IP, STA_GOT_IP, got_ip);
|
||||
HANDLE_SYS_EVENT_ARG(IP, ETH_GOT_IP, got_ip);
|
||||
HANDLE_SYS_EVENT(IP, STA_LOST_IP);
|
||||
HANDLE_SYS_EVENT_ARG(IP, GOT_IP6, got_ip6);
|
||||
HANDLE_SYS_EVENT(IP, AP_STAIPASSIGNED);
|
||||
@ -234,10 +219,6 @@ static void esp_system_event_debug(const system_event_t* event)
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_PIN");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_AP_START: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_START");
|
||||
break;
|
||||
@ -269,6 +250,7 @@ static void esp_system_event_debug(const system_event_t* event)
|
||||
MAC2STR(ap_probereqrecved->mac));
|
||||
break;
|
||||
}
|
||||
#if LWIP_IPV6
|
||||
case SYSTEM_EVENT_GOT_IP6: {
|
||||
const ip6_addr_t *addr = &event->event_info.got_ip6.ip6_info.ip;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STA_GOT_IP6 address %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x",
|
||||
@ -282,30 +264,7 @@ static void esp_system_event_debug(const system_event_t* event)
|
||||
IP6_ADDR_BLOCK8(addr));
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_START: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_START");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_STOP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_STOP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_CONNECTED: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_CONNECETED");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_DISCONNECETED");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_GOT_IP: {
|
||||
const system_event_sta_got_ip_t *got_ip = &event->event_info.got_ip;
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_GOT_IP, ip:" IPSTR ", mask:" IPSTR ", gw:" IPSTR,
|
||||
IP2STR(&got_ip->ip_info.ip),
|
||||
IP2STR(&got_ip->ip_info.netmask),
|
||||
IP2STR(&got_ip->ip_info.gw));
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default: {
|
||||
ESP_LOGW(TAG, "unexpected system event %d!", event->event_id);
|
||||
break;
|
||||
|
@ -27,32 +27,31 @@ extern "C" {
|
||||
|
||||
/** System event types enumeration */
|
||||
typedef enum {
|
||||
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 */
|
||||
SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP, /*!< ESP32 station wps overlap in enrollee mode */
|
||||
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_WIFI_READY = 0, /*!< WiFi ready */
|
||||
SYSTEM_EVENT_SCAN_DONE, /*!< finish scanning AP */
|
||||
SYSTEM_EVENT_STA_START, /*!< station start */
|
||||
SYSTEM_EVENT_STA_STOP, /*!< station stop */
|
||||
SYSTEM_EVENT_STA_CONNECTED, /*!< station connected to AP */
|
||||
SYSTEM_EVENT_STA_DISCONNECTED, /*!< station disconnected from AP */
|
||||
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /*!< the auth mode of AP connected by station changed */
|
||||
SYSTEM_EVENT_STA_GOT_IP, /*!< station got IP from connected AP */
|
||||
SYSTEM_EVENT_STA_LOST_IP, /*!< station lost IP and the IP is reset to 0 */
|
||||
SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /*!< station wps succeeds in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_FAILED, /*!< station wps fails in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /*!< station wps timeout in enrollee mode */
|
||||
SYSTEM_EVENT_STA_WPS_ER_PIN, /*!< station wps pin code in enrollee mode */
|
||||
SYSTEM_EVENT_AP_START, /*!< soft-AP start */
|
||||
SYSTEM_EVENT_AP_STOP, /*!< soft-AP stop */
|
||||
SYSTEM_EVENT_AP_STACONNECTED, /*!< a station connected to soft-AP */
|
||||
SYSTEM_EVENT_AP_STADISCONNECTED, /*!< a station disconnected from soft-AP */
|
||||
SYSTEM_EVENT_AP_STAIPASSIGNED, /*!< 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_ETH_START, /*!< ethernet start */
|
||||
SYSTEM_EVENT_ETH_STOP, /*!< ethernet stop */
|
||||
SYSTEM_EVENT_ETH_CONNECTED, /*!< ethernet phy link up */
|
||||
SYSTEM_EVENT_ETH_DISCONNECTED, /*!< ethernet phy link down */
|
||||
SYSTEM_EVENT_ETH_GOT_IP, /*!< ethernet got IP from connected AP */
|
||||
SYSTEM_EVENT_GOT_IP6, /*!< station or ap or ethernet interface v6IP addr is preferred */
|
||||
SYSTEM_EVENT_MAX /*!< Number of members in this enum */
|
||||
} system_event_id_t;
|
||||
|
||||
@ -100,18 +99,18 @@ typedef ip_event_got_ip6_t system_event_got_ip6_t;
|
||||
|
||||
/** Union of all possible system_event argument structures */
|
||||
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 */
|
||||
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 */
|
||||
system_event_ap_staipassigned_t ap_staipassigned; /**< ESP32 soft-AP assign an IP to the station*/
|
||||
system_event_got_ip6_t got_ip6; /*!< ESP32 station or ap or ethernet ipv6 addr state change to preferred */
|
||||
system_event_sta_connected_t connected; /*!< station connected to AP */
|
||||
system_event_sta_disconnected_t disconnected; /*!< station disconnected to AP */
|
||||
system_event_sta_scan_done_t scan_done; /*!< station scan (APs) done */
|
||||
system_event_sta_authmode_change_t auth_change; /*!< the auth mode of AP station connected to changed */
|
||||
system_event_sta_got_ip_t got_ip; /*!< station got IP, first time got IP or when IP is changed */
|
||||
system_event_sta_wps_er_pin_t sta_er_pin; /*!< station WPS enrollee mode PIN code received */
|
||||
system_event_sta_wps_fail_reason_t sta_er_fail_reason; /*!< station WPS enrollee mode failed reason code received */
|
||||
system_event_ap_staconnected_t sta_connected; /*!< a station connected to soft-AP */
|
||||
system_event_ap_stadisconnected_t sta_disconnected; /*!< a station disconnected to soft-AP */
|
||||
system_event_ap_probe_req_rx_t ap_probereqrecved; /*!< soft-AP receive probe request packet */
|
||||
system_event_ap_staipassigned_t ap_staipassigned; /**< soft-AP assign an IP to the station*/
|
||||
system_event_got_ip6_t got_ip6; /*!< station or ap or ethernet ipv6 addr state change to preferred */
|
||||
} system_event_info_t;
|
||||
|
||||
/** Event, as a tagged enum */
|
||||
|
@ -1,6 +0,0 @@
|
||||
if ESP_EVENT_POST_FROM_IRAM_ISR = y:
|
||||
[mapping:esp_event]
|
||||
archive: libesp_event.a
|
||||
entries:
|
||||
esp_event:esp_event_isr_post_to (noflash)
|
||||
default_event_loop:esp_event_isr_post (noflash)
|
@ -1,6 +0,0 @@
|
||||
# sdkconfig replacement configurations for deprecated options formatted as
|
||||
# CONFIG_DEPRECATED_OPTION CONFIG_NEW_OPTION
|
||||
|
||||
CONFIG_EVENT_LOOP_PROFILING CONFIG_ESP_EVENT_LOOP_PROFILING
|
||||
CONFIG_POST_EVENTS_FROM_ISR CONFIG_ESP_EVENT_POST_FROM_ISR
|
||||
CONFIG_POST_EVENTS_FROM_IRAM_ISR CONFIG_ESP_EVENT_POST_FROM_IRAM_ISR
|
@ -16,8 +16,6 @@
|
||||
#include "tcpip_adapter.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_private/wifi.h"
|
||||
#include "esp_eth.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
@ -42,97 +40,29 @@ static void handle_sta_connected(void *arg, esp_event_base_t base, int32_t event
|
||||
static void handle_sta_disconnected(void *arg, esp_event_base_t base, int32_t event_id, void *data);
|
||||
static void handle_sta_got_ip(void *arg, esp_event_base_t base, int32_t event_id, void *data);
|
||||
|
||||
static void handle_eth_start(void *arg, esp_event_base_t base, int32_t event_id, void *data);
|
||||
static void handle_eth_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data);
|
||||
static void handle_eth_connected(void *arg, esp_event_base_t base, int32_t event_id, void *data);
|
||||
static void handle_eth_disconnected(void *arg, esp_event_base_t base, int32_t event_id, void *data);
|
||||
static void handle_eth_got_ip(void *arg, esp_event_base_t base, int32_t event_id, void *data);
|
||||
|
||||
static void handle_eth_start(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
tcpip_adapter_ip_info_t eth_ip;
|
||||
uint8_t eth_mac[6];
|
||||
esp_eth_handle_t eth_handle = *(esp_eth_handle_t*)data;
|
||||
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, eth_mac);
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, ð_ip);
|
||||
tcpip_adapter_eth_start(eth_mac, ð_ip, eth_handle);
|
||||
}
|
||||
|
||||
static void handle_eth_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
tcpip_adapter_stop(TCPIP_ADAPTER_IF_ETH);
|
||||
}
|
||||
|
||||
static void handle_eth_connected(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
tcpip_adapter_dhcp_status_t status;
|
||||
|
||||
tcpip_adapter_up(TCPIP_ADAPTER_IF_ETH);
|
||||
|
||||
tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_ETH, &status);
|
||||
|
||||
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_ETH);
|
||||
} else if (status == TCPIP_ADAPTER_DHCP_STOPPED) {
|
||||
tcpip_adapter_ip_info_t eth_ip;
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, ð_ip);
|
||||
|
||||
if (!(ip4_addr_isany_val(eth_ip.ip) || ip4_addr_isany_val(eth_ip.netmask))) {
|
||||
system_event_t evt;
|
||||
|
||||
//notify event
|
||||
evt.event_id = SYSTEM_EVENT_ETH_GOT_IP;
|
||||
memcpy(&evt.event_info.got_ip.ip_info, ð_ip, sizeof(tcpip_adapter_ip_info_t));
|
||||
|
||||
esp_event_send(&evt);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "invalid static ip");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_eth_disconnected(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
tcpip_adapter_down(TCPIP_ADAPTER_IF_ETH);
|
||||
}
|
||||
|
||||
static void handle_sta_got_ip(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
API_CALL_CHECK("esp_wifi_internal_set_sta_ip", esp_wifi_internal_set_sta_ip(), ESP_OK);
|
||||
|
||||
const ip_event_got_ip_t *event = (const ip_event_got_ip_t *) data;
|
||||
|
||||
ESP_LOGI(TAG, "sta ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR,
|
||||
IP2STR(&event->ip_info.ip),
|
||||
IP2STR(&event->ip_info.netmask),
|
||||
IP2STR(&event->ip_info.gw));
|
||||
}
|
||||
|
||||
static void handle_eth_got_ip(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
const ip_event_got_ip_t *event = (const ip_event_got_ip_t *) data;
|
||||
ESP_LOGI(TAG, "eth ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR,
|
||||
IP2STR(&event->ip_info.ip),
|
||||
IP2STR(&event->ip_info.netmask),
|
||||
IP2STR(&event->ip_info.gw));
|
||||
}
|
||||
|
||||
static void handle_ap_start(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
tcpip_adapter_ip_info_t ap_ip;
|
||||
uint8_t ap_mac[6];
|
||||
|
||||
API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, (wifi_rxcb_t)tcpip_adapter_ap_input), ESP_OK);
|
||||
API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_AP, ap_mac), ESP_OK);
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip);
|
||||
tcpip_adapter_ap_start(ap_mac, &ap_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_AP, ap_mac, &ap_ip);
|
||||
}
|
||||
|
||||
static void handle_ap_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL), ESP_OK);
|
||||
|
||||
tcpip_adapter_stop(TCPIP_ADAPTER_IF_AP);
|
||||
}
|
||||
|
||||
@ -142,8 +72,9 @@ static void handle_sta_start(void *arg, esp_event_base_t base, int32_t event_id,
|
||||
uint8_t sta_mac[6];
|
||||
|
||||
API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_STA, sta_mac), ESP_OK);
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||
tcpip_adapter_sta_start(sta_mac, &sta_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_STA, sta_mac, &sta_ip);
|
||||
}
|
||||
|
||||
static void handle_sta_stop(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
@ -155,10 +86,7 @@ static void handle_sta_connected(void *arg, esp_event_base_t base, int32_t event
|
||||
{
|
||||
tcpip_adapter_dhcp_status_t status;
|
||||
|
||||
API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, (wifi_rxcb_t)tcpip_adapter_sta_input), ESP_OK);
|
||||
|
||||
tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
|
||||
|
||||
tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &status);
|
||||
|
||||
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||
@ -194,7 +122,6 @@ static void handle_sta_connected(void *arg, esp_event_base_t base, int32_t event
|
||||
static void handle_sta_disconnected(void *arg, esp_event_base_t base, int32_t event_id, void *data)
|
||||
{
|
||||
tcpip_adapter_down(TCPIP_ADAPTER_IF_STA);
|
||||
API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, NULL), ESP_OK);
|
||||
}
|
||||
|
||||
|
||||
@ -236,11 +163,6 @@ esp_err_t tcpip_adapter_set_default_wifi_handlers()
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = esp_register_shutdown_handler((shutdown_handler_t)esp_wifi_stop);
|
||||
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
fail:
|
||||
@ -257,52 +179,6 @@ esp_err_t tcpip_adapter_clear_default_wifi_handlers()
|
||||
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_AP_START, handle_ap_start);
|
||||
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_AP_STOP, handle_ap_stop);
|
||||
esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, handle_sta_got_ip);
|
||||
esp_unregister_shutdown_handler((shutdown_handler_t)esp_wifi_stop);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t tcpip_adapter_set_default_eth_handlers()
|
||||
{
|
||||
esp_err_t err;
|
||||
err = esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_START, handle_eth_start, NULL);
|
||||
if (err != ESP_OK) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_STOP, handle_eth_stop, NULL);
|
||||
if (err != ESP_OK) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_CONNECTED, handle_eth_connected, NULL);
|
||||
if (err != ESP_OK) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = esp_event_handler_register(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, handle_eth_disconnected, NULL);
|
||||
if (err != ESP_OK) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
err = esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, handle_eth_got_ip, NULL);
|
||||
if (err != ESP_OK) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
|
||||
fail:
|
||||
tcpip_adapter_clear_default_eth_handlers();
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t tcpip_adapter_clear_default_eth_handlers()
|
||||
{
|
||||
esp_event_handler_unregister(ETH_EVENT, ETHERNET_EVENT_START, handle_eth_start);
|
||||
esp_event_handler_unregister(ETH_EVENT, ETHERNET_EVENT_STOP, handle_eth_stop);
|
||||
esp_event_handler_unregister(ETH_EVENT, ETHERNET_EVENT_CONNECTED, handle_eth_connected);
|
||||
esp_event_handler_unregister(ETH_EVENT, ETHERNET_EVENT_DISCONNECTED, handle_eth_disconnected);
|
||||
esp_event_handler_unregister(IP_EVENT, IP_EVENT_ETH_GOT_IP, handle_eth_got_ip);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -174,6 +174,35 @@ typedef enum{
|
||||
TCPIP_ADAPTER_IP_REQUEST_RETRY_TIME = 52, /**< request IP address retry counter */
|
||||
} tcpip_adapter_option_id_t;
|
||||
|
||||
/** @brief IP event base declaration */
|
||||
ESP_EVENT_DECLARE_BASE(IP_EVENT);
|
||||
|
||||
/** IP event declarations */
|
||||
typedef enum {
|
||||
IP_EVENT_STA_GOT_IP, /*!< station got IP from connected AP */
|
||||
IP_EVENT_STA_LOST_IP, /*!< station lost IP and the IP is reset to 0 */
|
||||
IP_EVENT_AP_STAIPASSIGNED, /*!< soft-AP assign an IP to a connected station */
|
||||
IP_EVENT_GOT_IP6, /*!< station or ap or ethernet interface v6IP addr is preferred */
|
||||
} ip_event_t;
|
||||
|
||||
/** Event structure for IP_EVENT_AP_STAIPASSIGNED event */
|
||||
typedef struct {
|
||||
ip4_addr_t ip; /*!< IP address which was assigned to the station */
|
||||
} ip_event_ap_staipassigned_t;
|
||||
|
||||
/** Event structure for IP_EVENT_STA_GOT_IP, IP_EVENT_ETH_GOT_IP events */
|
||||
typedef struct {
|
||||
tcpip_adapter_if_t if_index; /*!< Interface for which the event is received */
|
||||
tcpip_adapter_ip_info_t ip_info; /*!< IP address, netmask, gatway IP address */
|
||||
bool ip_changed; /*!< Whether the assigned IP has changed or not */
|
||||
} ip_event_got_ip_t;
|
||||
|
||||
/** Event structure for IP_EVENT_GOT_IP6 event */
|
||||
typedef struct {
|
||||
tcpip_adapter_if_t if_index; /*!< Interface for which the event is received */
|
||||
tcpip_adapter_ip6_info_t ip6_info; /*!< IPv6 address of the interface */
|
||||
} ip_event_got_ip6_t;
|
||||
|
||||
struct tcpip_adapter_api_msg_s;
|
||||
typedef int (*tcpip_adapter_api_fn)(struct tcpip_adapter_api_msg_s *msg);
|
||||
|
||||
@ -615,6 +644,22 @@ esp_err_t tcpip_adapter_get_netif(tcpip_adapter_if_t tcpip_if, void ** netif);
|
||||
*/
|
||||
bool tcpip_adapter_is_netif_up(tcpip_adapter_if_t tcpip_if);
|
||||
|
||||
/**
|
||||
* @brief Install default event handlers for Wi-Fi interfaces (station and AP)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - one of the errors from esp_event on failure
|
||||
*/
|
||||
esp_err_t tcpip_adapter_set_default_wifi_handlers();
|
||||
|
||||
/**
|
||||
* @brief Uninstall default event handlers for Wi-Fi interfaces (station and AP)
|
||||
* @return
|
||||
* - ESP_OK on success
|
||||
* - one of the errors from esp_event on failure
|
||||
*/
|
||||
esp_err_t tcpip_adapter_clear_default_wifi_handlers();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -79,6 +79,8 @@ static bool tcpip_inited = false;
|
||||
|
||||
static const char* TAG = "tcpip_adapter";
|
||||
|
||||
ESP_EVENT_DEFINE_BASE(IP_EVENT);
|
||||
|
||||
/* Avoid warning. No header file has include these function */
|
||||
err_t ethernetif_init(struct netif* netif);
|
||||
void system_station_got_ip_set();
|
||||
@ -93,6 +95,7 @@ static void tcpip_adapter_dhcps_cb(u8_t client_ip[4])
|
||||
client_ip[0],client_ip[1],client_ip[2],client_ip[3]);
|
||||
system_event_t evt;
|
||||
evt.event_id = SYSTEM_EVENT_AP_STAIPASSIGNED;
|
||||
memcpy(&evt.event_info.ap_staipassigned.ip, client_ip, 4);
|
||||
esp_event_send(&evt);
|
||||
}
|
||||
|
||||
@ -584,6 +587,7 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i
|
||||
evt.event_info.got_ip.ip_changed = true;
|
||||
}
|
||||
|
||||
evt.event_info.got_ip.if_index = TCPIP_ADAPTER_IF_STA;
|
||||
memcpy(&evt.event_info.got_ip.ip_info, ip_info, sizeof(tcpip_adapter_ip_info_t));
|
||||
memcpy(&esp_ip_old[tcpip_if], ip_info, sizeof(tcpip_adapter_ip_info_t));
|
||||
esp_event_send(&evt);
|
||||
|
Reference in New Issue
Block a user