Merge branch 'refactor/wifi_remove_legacy_evts' into 'master'

Remove legacy system event framework.

Closes IDF-3608

See merge request espressif/esp-idf!16240
This commit is contained in:
Jiang Jiang Jian
2022-03-10 10:30:10 +08:00
24 changed files with 55 additions and 990 deletions

View File

@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
@@ -6,6 +11,7 @@
#include "unity.h" #include "unity.h"
#include "test_utils.h" #include "test_utils.h"
#include "esp_event.h" #include "esp_event.h"
#include "esp_netif.h"
#include "esp_eth.h" #include "esp_eth.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_http_client.h" #include "esp_http_client.h"

View File

@@ -12,7 +12,6 @@ if(${target} STREQUAL "linux")
list(APPEND priv_include_dirs "$ENV{IDF_PATH}/tools/mocks/esp_system/include") list(APPEND priv_include_dirs "$ENV{IDF_PATH}/tools/mocks/esp_system/include")
else() else()
list(APPEND requires "esp_netif") list(APPEND requires "esp_netif")
list(APPEND srcs "event_loop_legacy.c" "event_send.c")
if(${target} STREQUAL "esp32") if(${target} STREQUAL "esp32")
list(APPEND priv_requires esp_eth esp_timer) list(APPEND priv_requires esp_eth esp_timer)
else() else()

View File

@@ -133,10 +133,3 @@ esp_err_t esp_event_loop_delete_default(void)
return ESP_OK; return ESP_OK;
} }
#if !CONFIG_IDF_TARGET_LINUX
/* Include the code to forward legacy system_event_t events to the this default
* event loop.
*/
#include "event_send_compat.inc"
#endif

View File

@@ -1,100 +0,0 @@
// Copyright 2015-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 "esp_err.h"
#include "esp_log.h"
#include "esp_event.h"
#include "esp_event_legacy.h"
#include "sdkconfig.h"
static const char* TAG = "event";
static system_event_cb_t s_event_handler_cb;
static void *s_event_ctx;
static bool s_initialized;
ESP_EVENT_DEFINE_BASE(SYSTEM_EVENT);
static void esp_event_post_to_user(void* arg, esp_event_base_t base, int32_t id, void* data)
{
if (s_event_handler_cb) {
system_event_t* event = (system_event_t*) data;
(*s_event_handler_cb)(s_event_ctx, event);
}
}
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_legacy(system_event_t *event)
{
if (!s_initialized) {
ESP_LOGE(TAG, "system event loop not initialized via esp_event_loop_init");
return ESP_ERR_INVALID_STATE;
}
return esp_event_post(SYSTEM_EVENT, event->event_id, event, sizeof(*event), portMAX_DELAY);
}
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx)
{
if (s_initialized) {
ESP_LOGE(TAG, "system event loop already initialized");
return ESP_ERR_INVALID_STATE;
}
esp_err_t err = esp_event_loop_create_default();
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
return err;
}
err = esp_event_handler_register(SYSTEM_EVENT, ESP_EVENT_ANY_ID, esp_event_post_to_user, NULL);
if (err != ESP_OK) {
return err;
}
s_initialized = true;
s_event_handler_cb = cb;
s_event_ctx = ctx;
return ESP_OK;
}
esp_err_t esp_event_loop_deinit(void)
{
if (!s_initialized) {
ESP_LOGE(TAG, "system event loop not initialized");
return ESP_ERR_INVALID_STATE;
}
esp_err_t err = esp_event_handler_unregister(SYSTEM_EVENT, ESP_EVENT_ANY_ID, esp_event_post_to_user);
if (err != ESP_OK) {
return err;
}
err = esp_event_loop_delete_default();
if (err != ESP_OK && err != ESP_ERR_INVALID_STATE) {
return err;
}
s_initialized = false;
s_event_handler_cb = NULL;
s_event_ctx = NULL;
return ESP_OK;
}

View File

@@ -1,190 +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 <string.h>
#include "esp_log.h"
#include "esp_event.h"
#include "esp_event_legacy.h"
#define TAG "event_send"
esp_err_t esp_event_send_noop(system_event_t *event);
extern esp_err_t esp_event_send_legacy(system_event_t *event) __attribute__((weak, alias("esp_event_send_noop")));
extern esp_err_t esp_event_send_to_default_loop(system_event_t *event) __attribute((weak, alias("esp_event_send_noop")));
esp_err_t esp_event_send_noop(system_event_t *event)
{
return ESP_OK;
}
#if CONFIG_ESP32_WIFI_ENABLED
static system_event_id_t esp_event_legacy_wifi_event_id(int32_t event_id)
{
switch (event_id) {
case WIFI_EVENT_WIFI_READY:
return SYSTEM_EVENT_WIFI_READY;
case WIFI_EVENT_SCAN_DONE:
return SYSTEM_EVENT_SCAN_DONE;
case WIFI_EVENT_STA_START:
return SYSTEM_EVENT_STA_START;
case WIFI_EVENT_STA_STOP:
return SYSTEM_EVENT_STA_STOP;
case WIFI_EVENT_STA_CONNECTED:
return SYSTEM_EVENT_STA_CONNECTED;
case WIFI_EVENT_STA_DISCONNECTED:
return SYSTEM_EVENT_STA_DISCONNECTED;
case WIFI_EVENT_STA_AUTHMODE_CHANGE:
return SYSTEM_EVENT_STA_AUTHMODE_CHANGE;
case WIFI_EVENT_STA_BSS_RSSI_LOW:
return SYSTEM_EVENT_STA_BSS_RSSI_LOW;
case WIFI_EVENT_STA_WPS_ER_SUCCESS:
return SYSTEM_EVENT_STA_WPS_ER_SUCCESS;
case WIFI_EVENT_STA_WPS_ER_FAILED:
return SYSTEM_EVENT_STA_WPS_ER_FAILED;
case WIFI_EVENT_STA_WPS_ER_TIMEOUT:
return SYSTEM_EVENT_STA_WPS_ER_TIMEOUT;
case WIFI_EVENT_STA_WPS_ER_PIN:
return SYSTEM_EVENT_STA_WPS_ER_PIN;
case WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP:
return SYSTEM_EVENT_STA_WPS_ER_PBC_OVERLAP;
case WIFI_EVENT_AP_START:
return SYSTEM_EVENT_AP_START;
case WIFI_EVENT_AP_STOP:
return SYSTEM_EVENT_AP_STOP;
case WIFI_EVENT_AP_STACONNECTED:
return SYSTEM_EVENT_AP_STACONNECTED;
case WIFI_EVENT_AP_STADISCONNECTED:
return SYSTEM_EVENT_AP_STADISCONNECTED;
case WIFI_EVENT_AP_PROBEREQRECVED:
return SYSTEM_EVENT_AP_PROBEREQRECVED;
case WIFI_EVENT_ACTION_TX_STATUS:
return SYSTEM_EVENT_ACTION_TX_STATUS;
case WIFI_EVENT_ROC_DONE:
return SYSTEM_EVENT_ROC_DONE;
case WIFI_EVENT_FTM_REPORT:
return SYSTEM_EVENT_FTM_REPORT;
case WIFI_EVENT_STA_BEACON_TIMEOUT:
return SYSTEM_EVENT_STA_BEACON_TIMEOUT;
default:
ESP_LOGE(TAG, "invalid wifi event id %d", event_id);
return SYSTEM_EVENT_MAX;
}
}
#endif // CONFIG_ESP32_WIFI_ENABLED
static system_event_id_t esp_event_legacy_ip_event_id(int32_t event_id)
{
switch (event_id) {
case IP_EVENT_STA_GOT_IP:
return SYSTEM_EVENT_STA_GOT_IP;
case IP_EVENT_STA_LOST_IP:
return SYSTEM_EVENT_STA_LOST_IP;
case IP_EVENT_AP_STAIPASSIGNED:
return SYSTEM_EVENT_AP_STAIPASSIGNED;
case IP_EVENT_GOT_IP6:
return SYSTEM_EVENT_GOT_IP6;
case IP_EVENT_ETH_GOT_IP:
return SYSTEM_EVENT_ETH_GOT_IP;
case IP_EVENT_ETH_LOST_IP:
return SYSTEM_EVENT_ETH_LOST_IP;
default:
ESP_LOGE(TAG, "invalid ip event id %d", event_id);
return SYSTEM_EVENT_MAX;
}
}
static system_event_id_t esp_event_legacy_event_id(esp_event_base_t event_base, int32_t event_id)
{
#if CONFIG_ESP32_WIFI_ENABLED
if (event_base == WIFI_EVENT) {
return esp_event_legacy_wifi_event_id(event_id);
}
#endif
if (event_base == IP_EVENT) {
return esp_event_legacy_ip_event_id(event_id);
} else {
ESP_LOGE(TAG, "invalid event base %s", event_base);
return SYSTEM_EVENT_MAX;
}
}
esp_err_t esp_event_send(system_event_t *event)
{
// send the event to the new style event loop
esp_err_t err = esp_event_send_to_default_loop(event);
if (err != ESP_OK) {
return err;
}
// send the event to the legacy event loop
err = esp_event_send_legacy(event);
if (err != ESP_OK) {
return err;
}
return ESP_OK;
}
esp_err_t esp_event_send_internal(esp_event_base_t event_base,
int32_t event_id,
void* event_data,
size_t event_data_size,
TickType_t ticks_to_wait)
{
system_event_t event;
// send the event to the new style event loop
esp_err_t err = esp_event_post(event_base, event_id, event_data, event_data_size, ticks_to_wait);
if (err != ESP_OK) {
return err;
}
event.event_id = esp_event_legacy_event_id(event_base, event_id);
if (event_data) {
memcpy(&event.event_info, event_data, event_data_size);
}
return esp_event_send_legacy(&event);
}

View File

@@ -1,317 +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 "esp_event.h"
#include "esp_log.h"
#include "esp_event_legacy.h"
#include "esp_wifi_types.h"
#include "esp_netif.h"
#include "esp_mac.h"
#if CONFIG_ETH_ENABLED
#include "esp_eth.h"
#endif
/**
* The purpose of this file is to provide an "esp_event_send_to_default_loop"
* function, which is used to forward legacy events (system_event_t) sent using
* esp_event_send, to the new default event loop (esp_event_post).
*
* For each of the events in system_event_id_t, we extract the event data from
* the corresponding system_event_info_t member, and forward that to
* esp_event_post function.
*
* Some macros are used to reduce the amount of boilerplate.
*
* Note that this function only needs to be included into the output file if
* the new default event loop is used. This function is in a separate file for
* readability reasons. In order to be linked if the contents of
* default_event_loop.c is linked, this file is #include-ed into default_event_loop.c.
*/
#if LOG_LOCAL_LEVEL >= 4 /* ESP_LOG_DEBUG */
#define WITH_EVENT_DEBUG
#endif
#ifdef WITH_EVENT_DEBUG
static void esp_system_event_debug(const system_event_t* event);
#endif
#define HANDLE_SYS_EVENT(base_, name_) \
case SYSTEM_EVENT_ ## name_: \
return esp_event_post(base_ ## _EVENT, base_ ## _EVENT_ ## name_, \
NULL, 0, send_timeout)
#define HANDLE_SYS_EVENT_ARG(base_, name_, member_) \
case SYSTEM_EVENT_ ## name_: \
return esp_event_post(base_ ## _EVENT, base_ ## _EVENT_ ## name_, \
&event->event_info.member_, sizeof(event->event_info.member_), \
send_timeout)
esp_err_t esp_event_send_to_default_loop(system_event_t *event)
{
#ifdef WITH_EVENT_DEBUG
esp_system_event_debug(event);
#endif // WITH_EVENT_DEBUG
const TickType_t send_timeout = 0;
switch (event->event_id) {
/* Wi-Fi common events */
HANDLE_SYS_EVENT(WIFI, WIFI_READY);
HANDLE_SYS_EVENT_ARG(WIFI, SCAN_DONE, scan_done);
HANDLE_SYS_EVENT(WIFI, STA_START);
HANDLE_SYS_EVENT(WIFI, STA_STOP);
HANDLE_SYS_EVENT_ARG(WIFI, FTM_REPORT, ftm_report);
/* STA events */
HANDLE_SYS_EVENT_ARG(WIFI, STA_CONNECTED, connected);
HANDLE_SYS_EVENT_ARG(WIFI, STA_DISCONNECTED, disconnected);
HANDLE_SYS_EVENT_ARG(WIFI, STA_AUTHMODE_CHANGE, auth_change);
/* WPS events */
HANDLE_SYS_EVENT(WIFI, STA_WPS_ER_SUCCESS);
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);
HANDLE_SYS_EVENT(WIFI, AP_STOP);
HANDLE_SYS_EVENT_ARG(WIFI, AP_STACONNECTED, sta_connected);
HANDLE_SYS_EVENT_ARG(WIFI, AP_STADISCONNECTED, sta_disconnected);
HANDLE_SYS_EVENT_ARG(WIFI, AP_PROBEREQRECVED, ap_probereqrecved);
#if CONFIG_ETH_ENABLED
/* 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);
#endif
/* 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_ARG(IP, AP_STAIPASSIGNED,ap_staipassigned);
default:
return ESP_ERR_NOT_SUPPORTED;
}
}
#ifdef WITH_EVENT_DEBUG
static const char* TAG = "system_event";
typedef struct {
int err;
const char *reason;
} wifi_reason_t;
static const wifi_reason_t wifi_reason[] =
{
{0, "other reason"},
{WIFI_REASON_UNSPECIFIED, "unspecified"},
{WIFI_REASON_AUTH_EXPIRE, "auth expire"},
{WIFI_REASON_AUTH_LEAVE, "auth leave"},
{WIFI_REASON_ASSOC_EXPIRE, "assoc expire"},
{WIFI_REASON_ASSOC_TOOMANY, "assoc too many"},
{WIFI_REASON_NOT_AUTHED, "not authed"},
{WIFI_REASON_NOT_ASSOCED, "not assoced"},
{WIFI_REASON_ASSOC_LEAVE, "assoc leave"},
{WIFI_REASON_ASSOC_NOT_AUTHED, "assoc not authed"},
{WIFI_REASON_BEACON_TIMEOUT, "beacon timeout"},
{WIFI_REASON_NO_AP_FOUND, "no ap found"},
{WIFI_REASON_AUTH_FAIL, "auth fail"},
{WIFI_REASON_ASSOC_FAIL, "assoc fail"},
{WIFI_REASON_HANDSHAKE_TIMEOUT, "hanshake timeout"},
{WIFI_REASON_DISASSOC_PWRCAP_BAD, "bad Power Capability, disassoc"},
{WIFI_REASON_DISASSOC_SUPCHAN_BAD, "bad Supported Channels, disassoc"},
{WIFI_REASON_IE_INVALID, "invalid IE"},
{WIFI_REASON_MIC_FAILURE, "MIC failure"},
{WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT, "4-way keying handshake timeout"},
{WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT, "Group key handshake"},
{WIFI_REASON_IE_IN_4WAY_DIFFERS, "IE in 4-way differs"},
{WIFI_REASON_GROUP_CIPHER_INVALID, "invalid group cipher"},
{WIFI_REASON_PAIRWISE_CIPHER_INVALID, "invalid pairwise cipher"},
{WIFI_REASON_AKMP_INVALID, "invalid AKMP"},
{WIFI_REASON_UNSUPP_RSN_IE_VERSION, "unsupported RSN IE version"},
{WIFI_REASON_INVALID_RSN_IE_CAP, "invalid RSN IE capability"},
{WIFI_REASON_802_1X_AUTH_FAILED, "802.1x auth failed"},
{WIFI_REASON_CIPHER_SUITE_REJECTED, "cipher suite rejected"}
};
static const char* wifi_disconnect_reason_to_str(int err)
{
for (int i=0; i< sizeof(wifi_reason)/sizeof(wifi_reason[0]); i++){
if (err == wifi_reason[i].err){
return wifi_reason[i].reason;
}
}
return wifi_reason[0].reason;
}
static void esp_system_event_debug(const system_event_t* event)
{
if (event == NULL) {
return;
}
switch (event->event_id) {
case SYSTEM_EVENT_WIFI_READY: {
ESP_LOGD(TAG, "SYSTEM_EVENT_WIFI_READY");
break;
}
case SYSTEM_EVENT_SCAN_DONE: {
const 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: {
const 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: {
const 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 (%s)", \
disconnected->ssid, disconnected->ssid_len, MAC2STR(disconnected->bssid), disconnected->reason,
wifi_disconnect_reason_to_str(disconnected->reason));
break;
}
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: {
const 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_FTM_REPORT: {
ESP_LOGD(TAG, "SYSTEM_EVENT_FTM_REPORT");
break;
}
case SYSTEM_EVENT_STA_GOT_IP: {
const 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_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;
}
case SYSTEM_EVENT_AP_STOP: {
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STOP");
break;
}
case SYSTEM_EVENT_AP_STACONNECTED: {
const 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: {
const 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: {
const 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;
}
case SYSTEM_EVENT_GOT_IP6: {
const esp_ip6_addr_t *addr = &event->event_info.got_ip6.ip6_info.ip;
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STA_GOT_IP6 address " IPV6STR, IPV62STR(*addr));
break;
}
#if CONFIG_IDF_TARGET_ESP32
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;
}
}
}
#endif // WITH_EVENT_DEBUG

View File

@@ -15,10 +15,6 @@
#include "freertos/semphr.h" #include "freertos/semphr.h"
#include "esp_event_base.h" #include "esp_event_base.h"
// Legacy event loop not implemented on Linux target
#if !CONFIG_IDF_TARGET_LINUX
#include "esp_event_legacy.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {

View File

@@ -1,253 +0,0 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "esp_wifi_types.h"
#include "esp_netif.h"
#ifdef __cplusplus
extern "C" {
#endif
/** System event types enumeration */
typedef enum {
SYSTEM_EVENT_WIFI_READY = 0, /*!< ESP32 Wi-Fi 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_BSS_RSSI_LOW, /*!< ESP32 station connected BSS rssi goes below threshold */
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_AP_PROBEREQRECVED, /*!< Receive probe request packet in soft-AP interface */
SYSTEM_EVENT_ACTION_TX_STATUS, /*!< Receive status of Action frame transmitted */
SYSTEM_EVENT_ROC_DONE, /*!< Indicates the completion of Remain-on-Channel operation status */
SYSTEM_EVENT_STA_BEACON_TIMEOUT, /*!< ESP32 station beacon timeout */
SYSTEM_EVENT_FTM_REPORT, /*!< Receive report of FTM procedure */
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_LOST_IP, /*!< ESP32 ethernet lost IP and the IP is reset to 0 */
SYSTEM_EVENT_MAX /*!< Number of members in this enum */
} 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
/** 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;
/** Argument structure of SYSTEM_EVENT_SCAN_DONE event */
typedef wifi_event_sta_scan_done_t system_event_sta_scan_done_t;
/** Argument structure of SYSTEM_EVENT_STA_CONNECTED event */
typedef wifi_event_sta_connected_t system_event_sta_connected_t;
/** Argument structure of SYSTEM_EVENT_STA_DISCONNECTED event */
typedef wifi_event_sta_disconnected_t system_event_sta_disconnected_t;
/** Argument structure of SYSTEM_EVENT_STA_AUTHMODE_CHANGE event */
typedef wifi_event_sta_authmode_change_t system_event_sta_authmode_change_t;
/** 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;
/** Argument structure of SYSTEM_EVENT_STA_WPS_ER_PIN event */
typedef wifi_event_sta_wps_er_success_t system_event_sta_wps_er_success_t;
/** Argument structure of event */
typedef wifi_event_ap_staconnected_t system_event_ap_staconnected_t;
/** Argument structure of event */
typedef wifi_event_ap_stadisconnected_t system_event_ap_stadisconnected_t;
/** Argument structure of event */
typedef wifi_event_ap_probe_req_rx_t system_event_ap_probe_req_rx_t;
/** Argument structure of SYSTEM_EVENT_FTM_REPORT event */
typedef wifi_event_ftm_report_t system_event_ftm_report_t;
/** 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;
/** Argument structure of event */
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_sta_wps_er_success_t sta_er_success; /*!< ESP32 station WPS enrollee success */
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_ftm_report_t ftm_report; /*!< Report of FTM procedure */
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_info_t;
/** Event, as a tagged enum */
typedef struct {
system_event_id_t event_id; /*!< event ID */
system_event_info_t event_info; /*!< event information */
} system_event_t;
/** Event handler function type */
typedef esp_err_t (*system_event_handler_t)(esp_event_base_t event_base,
int32_t event_id,
void* event_data,
size_t event_data_size,
TickType_t ticks_to_wait);
/**
* @brief Send an event to event task
*
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
*
* Other task/modules, such as the tcpip_adapter, can call this API to send an event to event task
*
* @param event Event to send
*
* @return ESP_OK : succeed
* @return others : fail
*/
esp_err_t esp_event_send(system_event_t *event) __attribute__ ((deprecated));
/**
* @brief Send an event to event task
*
* @note This API is used by Wi-Fi Driver only.
*
* Other task/modules, such as the tcpip_adapter, can call this API to send an event to event task
*
* @param[in] event_base the event base that identifies the event
* @param[in] event_id the event ID that identifies the event
* @param[in] event_data the data, specific to the event occurrence, that gets passed to the handler
* @param[in] event_data_size the size of the event data
* @param[in] ticks_to_wait number of ticks to block on a full event queue
*
* @return ESP_OK : succeed
* @return others : fail
*/
esp_err_t esp_event_send_internal(esp_event_base_t event_base,
int32_t event_id,
void* event_data,
size_t event_data_size,
TickType_t ticks_to_wait);
/**
* @brief Default event handler for system events
*
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
*
* 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) __attribute__ ((deprecated));
/**
* @brief Install default event handlers for Ethernet interface
*
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
*
*/
void esp_event_set_default_eth_handlers(void);
/**
* @brief Install default event handlers for Wi-Fi interfaces (station and AP)
*
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
*/
void esp_event_set_default_wifi_handlers(void) __attribute__ ((deprecated));
/**
* @brief Application specified event callback function
*
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
*
*
* @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
*
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
*
* 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) __attribute__ ((deprecated));
/**
* @brief Set application specified event callback function
*
* @note This API is part of the legacy event system. New code should use event library API in esp_event.h
*
* @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
*
*
* @return old callback
*/
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx) __attribute__ ((deprecated));
#ifdef __cplusplus
}
#endif

View File

@@ -1,16 +1,8 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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 <string.h> #include <string.h>
#include "esp_netif.h" #include "esp_netif.h"
@@ -77,8 +69,8 @@ void esp_netif_action_connected(void *esp_netif, esp_event_base_t base, int32_t
memcpy(&evt.ip_info, &ip, sizeof(esp_netif_ip_info_t)); memcpy(&evt.ip_info, &ip, sizeof(esp_netif_ip_info_t));
esp_netif_set_old_ip_info(esp_netif, &ip); esp_netif_set_old_ip_info(esp_netif, &ip);
ESP_NETIF_CALL_CHECK("esp_event_send_internal in esp_netif_action_connected", ESP_NETIF_CALL_CHECK("esp_event_post in esp_netif_action_connected",
esp_event_send_internal(IP_EVENT, esp_netif_get_event_id(esp_netif, ESP_NETIF_IP_EVENT_GOT_IP) , esp_event_post(IP_EVENT, esp_netif_get_event_id(esp_netif, ESP_NETIF_IP_EVENT_GOT_IP) ,
&evt, sizeof(evt), 0), ESP_OK); &evt, sizeof(evt), 0), ESP_OK);
ESP_LOGD(TAG, "static ip: ip changed=%d", evt.ip_changed); ESP_LOGD(TAG, "static ip: ip changed=%d", evt.ip_changed);
} else { } else {

View File

@@ -773,7 +773,7 @@ static void esp_netif_dhcps_cb(uint8_t ip[4], uint8_t mac[6])
ESP_LOGI(TAG, "DHCP server assigned IP to a station, IP is: " IPSTR, IP2STR(&evt.ip)); ESP_LOGI(TAG, "DHCP server assigned IP to a station, IP is: " IPSTR, IP2STR(&evt.ip));
ESP_LOGD(TAG, "Client's MAC: %x:%x:%x:%x:%x:%x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); ESP_LOGD(TAG, "Client's MAC: %x:%x:%x:%x:%x:%x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
int ret = esp_event_send_internal(IP_EVENT, IP_EVENT_AP_STAIPASSIGNED, &evt, sizeof(evt), 0); int ret = esp_event_post(IP_EVENT, IP_EVENT_AP_STAIPASSIGNED, &evt, sizeof(evt), 0);
if (ESP_OK != ret) { if (ESP_OK != ret) {
ESP_LOGE(TAG, "dhcps cb: failed to post IP_EVENT_AP_STAIPASSIGNED (%x)", ret); ESP_LOGE(TAG, "dhcps cb: failed to post IP_EVENT_AP_STAIPASSIGNED (%x)", ret);
} }
@@ -1073,7 +1073,7 @@ static void esp_netif_dhcpc_cb(struct netif *netif)
memcpy(&evt.ip_info, ip_info, sizeof(esp_netif_ip_info_t)); memcpy(&evt.ip_info, ip_info, sizeof(esp_netif_ip_info_t));
memcpy(ip_info_old, ip_info, sizeof(esp_netif_ip_info_t)); memcpy(ip_info_old, ip_info, sizeof(esp_netif_ip_info_t));
ESP_LOGD(TAG, "if%p ip changed=%d", esp_netif, evt.ip_changed); ESP_LOGD(TAG, "if%p ip changed=%d", esp_netif, evt.ip_changed);
ret = esp_event_send_internal(IP_EVENT, evt_id, &evt, sizeof(evt), 0); ret = esp_event_post(IP_EVENT, evt_id, &evt, sizeof(evt), 0);
if (ESP_OK != ret) { if (ESP_OK != ret) {
ESP_LOGE(TAG, "dhcpc cb: failed to post got ip event (%x)", ret); ESP_LOGE(TAG, "dhcpc cb: failed to post got ip event (%x)", ret);
} }
@@ -1112,7 +1112,7 @@ static void esp_netif_ip_lost_timer(void *arg)
ESP_LOGD(TAG, "if%p ip lost tmr: raise ip lost event", esp_netif); ESP_LOGD(TAG, "if%p ip lost tmr: raise ip lost event", esp_netif);
memset(esp_netif->ip_info_old, 0, sizeof(esp_netif_ip_info_t)); memset(esp_netif->ip_info_old, 0, sizeof(esp_netif_ip_info_t));
if (esp_netif->lost_ip_event) { if (esp_netif->lost_ip_event) {
ret = esp_event_send_internal(IP_EVENT, esp_netif->lost_ip_event, ret = esp_event_post(IP_EVENT, esp_netif->lost_ip_event,
&evt, sizeof(evt), 0); &evt, sizeof(evt), 0);
if (ESP_OK != ret) { if (ESP_OK != ret) {
ESP_LOGE(TAG, "ip lost timer: failed to post lost ip event (%x)", ret); ESP_LOGE(TAG, "ip lost timer: failed to post lost ip event (%x)", ret);
@@ -1578,7 +1578,7 @@ static esp_err_t esp_netif_set_ip_info_api(esp_netif_api_msg_t *msg)
memcpy(&evt.ip_info, ip_info, sizeof(esp_netif_ip_info_t)); memcpy(&evt.ip_info, ip_info, sizeof(esp_netif_ip_info_t));
memcpy(esp_netif->ip_info_old, ip_info, sizeof(esp_netif_ip_info_t)); memcpy(esp_netif->ip_info_old, ip_info, sizeof(esp_netif_ip_info_t));
ret = esp_event_send_internal(IP_EVENT, evt_id, &evt, sizeof(evt), 0); ret = esp_event_post(IP_EVENT, evt_id, &evt, sizeof(evt), 0);
if (ESP_OK != ret) { if (ESP_OK != ret) {
ESP_LOGE(TAG, "set ip info: failed to post got ip event (%x)", ret); ESP_LOGE(TAG, "set ip info: failed to post got ip event (%x)", ret);
} }
@@ -1750,7 +1750,7 @@ static void esp_netif_nd6_cb(struct netif *p_netif, uint8_t ip_index)
#endif /* LWIP_IPV6_SCOPES */ #endif /* LWIP_IPV6_SCOPES */
memcpy(&evt.ip6_info, &ip6_info, sizeof(esp_netif_ip6_info_t)); memcpy(&evt.ip6_info, &ip6_info, sizeof(esp_netif_ip6_info_t));
int ret = esp_event_send_internal(IP_EVENT, IP_EVENT_GOT_IP6, &evt, sizeof(evt), 0); int ret = esp_event_post(IP_EVENT, IP_EVENT_GOT_IP6, &evt, sizeof(evt), 0);
if (ESP_OK != ret) { if (ESP_OK != ret) {
ESP_LOGE(TAG, "nd6 cb: failed to post IP_EVENT_GOT_IP6 (%x)", ret); ESP_LOGE(TAG, "nd6 cb: failed to post IP_EVENT_GOT_IP6 (%x)", ret);
} }
@@ -2132,7 +2132,7 @@ static esp_err_t esp_netif_add_ip6_address_api(esp_netif_api_msg_t *msg)
addr->preferred ? IP6_ADDR_PREFERRED : IP6_ADDR_DEPRECATED); addr->preferred ? IP6_ADDR_PREFERRED : IP6_ADDR_DEPRECATED);
ip_event_got_ip6_t evt = {.esp_netif = msg->esp_netif, .if_index = -1, .ip_index = index}; ip_event_got_ip6_t evt = {.esp_netif = msg->esp_netif, .if_index = -1, .ip_index = index};
evt.ip6_info.ip = addr->addr; evt.ip6_info.ip = addr->addr;
ESP_RETURN_ON_ERROR(esp_event_send_internal(IP_EVENT, IP_EVENT_GOT_IP6, &evt, sizeof(evt), 0), TAG, ESP_RETURN_ON_ERROR(esp_event_post(IP_EVENT, IP_EVENT_GOT_IP6, &evt, sizeof(evt), 0), TAG,
"Failed to post IP_EVENT_GOT_IP6"); "Failed to post IP_EVENT_GOT_IP6");
return error; return error;
} }

View File

@@ -1,16 +1,8 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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 "esp_netif.h" #include "esp_netif.h"
@@ -139,7 +131,7 @@ static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx)
err = esp_event_post(IP_EVENT, netif->lost_ip_event, &evt, sizeof(evt), 0); err = esp_event_post(IP_EVENT, netif->lost_ip_event, &evt, sizeof(evt), 0);
if (ESP_OK != err) { if (ESP_OK != err) {
ESP_LOGE(TAG, "esp_event_send_internal failed with code %d", err); ESP_LOGE(TAG, "esp_event_post failed with code %d", err);
} }
return; return;

View File

@@ -34,7 +34,7 @@
* *
* The event task is a daemon task, which receives events from WiFi driver or from other subsystem, such * The event task is a daemon task, which receives events from WiFi driver or from other subsystem, such
* as TCPIP stack, event task will call the default callback function on receiving the event. For example, * as TCPIP stack, event task will call the default callback function on receiving the event. For example,
* on receiving event SYSTEM_EVENT_STA_CONNECTED, it will call tcpip_adapter_start() to start the DHCP * on receiving event WIFI_EVENT_STA_CONNECTED, it will call esp_netif API to start the DHCP
* client in it's default handler. * client in it's default handler.
* *
* Application can register it's own event callback function by API esp_event_init, then the application callback * Application can register it's own event callback function by API esp_event_init, then the application callback
@@ -87,7 +87,6 @@ extern "C" {
* @brief WiFi stack configuration parameters passed to esp_wifi_init call. * @brief WiFi stack configuration parameters passed to esp_wifi_init call.
*/ */
typedef struct { typedef struct {
system_event_handler_t event_handler; /**< WiFi event handler */
wifi_osi_funcs_t* osi_funcs; /**< WiFi OS functions */ wifi_osi_funcs_t* osi_funcs; /**< WiFi OS functions */
wpa_crypto_funcs_t wpa_crypto_funcs; /**< WiFi station crypto functions when connect */ wpa_crypto_funcs_t wpa_crypto_funcs; /**< WiFi station crypto functions when connect */
int static_rx_buf_num; /**< WiFi static RX buffer number */ int static_rx_buf_num; /**< WiFi static RX buffer number */
@@ -206,7 +205,6 @@ extern uint64_t g_wifi_feature_caps;
#define CONFIG_FEATURE_FTM_RESPONDER_BIT (1<<3) #define CONFIG_FEATURE_FTM_RESPONDER_BIT (1<<3)
#define WIFI_INIT_CONFIG_DEFAULT() { \ #define WIFI_INIT_CONFIG_DEFAULT() { \
.event_handler = &esp_event_send_internal, \
.osi_funcs = &g_wifi_osi_funcs, \ .osi_funcs = &g_wifi_osi_funcs, \
.wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \ .wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
.static_rx_buf_num = CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM,\ .static_rx_buf_num = CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM,\

View File

@@ -1,20 +1,14 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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_WIFI_DEFAULT_H #ifndef _ESP_WIFI_DEFAULT_H
#define _ESP_WIFI_DEFAULT_H #define _ESP_WIFI_DEFAULT_H
#include "esp_netif.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif

View File

@@ -7,6 +7,7 @@
#include "freertos/event_groups.h" #include "freertos/event_groups.h"
#include "unity.h" #include "unity.h"
#include "esp_event.h" #include "esp_event.h"
#include "esp_netif.h"
#include "esp_eth.h" #include "esp_eth.h"
#include "esp_log.h" #include "esp_log.h"

View File

@@ -1,22 +1,15 @@
// Copyright 2019 Espressif Systems (Shanghai) PTE LTD /*
// * SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
// Licensed under the Apache License, Version 2.0 (the "License"); *
// you may not use this file except in compliance with the License. * SPDX-License-Identifier: Apache-2.0
// 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.
#pragma once #pragma once
#include <protocomm.h> #include <protocomm.h>
#include "esp_event.h" #include "esp_event.h"
#include "esp_wifi_types.h"
#include "wifi_provisioning/wifi_config.h" #include "wifi_provisioning/wifi_config.h"
#ifdef __cplusplus #ifdef __cplusplus
@@ -484,25 +477,6 @@ esp_err_t wifi_prov_mgr_endpoint_register(const char *ep_name,
*/ */
void wifi_prov_mgr_endpoint_unregister(const char *ep_name); void wifi_prov_mgr_endpoint_unregister(const char *ep_name);
/**
* @brief Event handler for provisioning manager
*
* This is called from the main event handler and controls the
* provisioning manager's internal state machine depending on
* incoming Wi-Fi events
*
* @note : This function is DEPRECATED, because events are now
* handled internally using the event loop library, esp_event.
* Calling this will do nothing and simply return ESP_OK.
*
* @param[in] ctx Event context data
* @param[in] event Event info
*
* @return
* - ESP_OK : Event handled successfully
*/
esp_err_t wifi_prov_mgr_event_handler(void *ctx, system_event_t *event) __attribute__ ((deprecated));
/** /**
* @brief Get state of Wi-Fi Station during provisioning * @brief Get state of Wi-Fi Station during provisioning
* *

View File

@@ -788,14 +788,6 @@ static esp_err_t update_wifi_scan_results(void)
return ret; return ret;
} }
/* DEPRECATED : Event handler for starting/stopping provisioning.
* To be called from within the context of the main
* event handler */
esp_err_t wifi_prov_mgr_event_handler(void *ctx, system_event_t *event)
{
return ESP_OK;
}
static void wifi_prov_mgr_event_handler_internal( static void wifi_prov_mgr_event_handler_internal(
void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data) void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{ {

View File

@@ -412,7 +412,7 @@ struct wps_data *wps_init(void)
wpa_printf(MSG_DEBUG, "WPS PIN [%s]", tmpp); wpa_printf(MSG_DEBUG, "WPS PIN [%s]", tmpp);
wifi_event_sta_wps_er_pin_t evt; wifi_event_sta_wps_er_pin_t evt;
os_memcpy(evt.pin_code, data->dev_password, 8); os_memcpy(evt.pin_code, data->dev_password, 8);
esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PIN, &evt, sizeof(evt), portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PIN, &evt, sizeof(evt), portMAX_DELAY);
} while (0); } while (0);
} else if (wps_get_type() == WPS_TYPE_PBC) { } else if (wps_get_type() == WPS_TYPE_PBC) {
data->pbc = 1; data->pbc = 1;
@@ -980,7 +980,7 @@ int wps_stop_process(wifi_event_sta_wps_fail_reason_t reason_code)
wpa_printf(MSG_DEBUG, "Write wps_fail_information"); wpa_printf(MSG_DEBUG, "Write wps_fail_information");
esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY);
return ESP_OK; return ESP_OK;
} }
@@ -1007,7 +1007,7 @@ int wps_finish(void)
if (config == NULL) { if (config == NULL) {
wifi_event_sta_wps_fail_reason_t reason_code = WPS_FAIL_REASON_NORMAL; wifi_event_sta_wps_fail_reason_t reason_code = WPS_FAIL_REASON_NORMAL;
esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY);
return ESP_FAIL; return ESP_FAIL;
} }
@@ -1287,7 +1287,7 @@ out:
esp_wifi_disarm_sta_connection_timer_internal(); esp_wifi_disarm_sta_connection_timer_internal();
ets_timer_disarm(&sm->wps_timeout_timer); ets_timer_disarm(&sm->wps_timeout_timer);
esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_FAILED, &reason_code, sizeof(reason_code), portMAX_DELAY);
return ret; return ret;
} }
@@ -1493,7 +1493,7 @@ wifi_station_wps_timeout_internal(void)
wps_set_status(WPS_STATUS_DISABLE); wps_set_status(WPS_STATUS_DISABLE);
esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_TIMEOUT, 0, 0, portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_TIMEOUT, 0, 0, portMAX_DELAY);
} }
void wifi_station_wps_timeout(void) void wifi_station_wps_timeout(void)
@@ -1562,10 +1562,10 @@ void wifi_station_wps_success_internal(void)
os_memcpy(evt.ap_cred[i].ssid, sm->ssid[i], sm->ssid_len[i]); os_memcpy(evt.ap_cred[i].ssid, sm->ssid[i], sm->ssid_len[i]);
os_memcpy(evt.ap_cred[i].passphrase, sm->key[i], sm->key_len[i]); os_memcpy(evt.ap_cred[i].passphrase, sm->key[i], sm->key_len[i]);
} }
esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS, &evt, esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS, &evt,
sizeof(evt), portMAX_DELAY); sizeof(evt), portMAX_DELAY);
} else { } else {
esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS, esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_SUCCESS,
0, 0, portMAX_DELAY); 0, 0, portMAX_DELAY);
} }
} }
@@ -1841,7 +1841,7 @@ wifi_wps_scan_done(void *arg, STATUS status)
} else { } else {
wpa_printf(MSG_INFO, "PBC session overlap!"); wpa_printf(MSG_INFO, "PBC session overlap!");
wps_set_status(WPS_STATUS_DISABLE); wps_set_status(WPS_STATUS_DISABLE);
esp_event_send_internal(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP, 0, 0, portMAX_DELAY); esp_event_post(WIFI_EVENT, WIFI_EVENT_STA_WPS_ER_PBC_OVERLAP, 0, 0, portMAX_DELAY);
} }
wpa_printf(MSG_DEBUG, "wps scan_done discover_ssid_cnt = %d", sm->discover_ssid_cnt); wpa_printf(MSG_DEBUG, "wps scan_done discover_ssid_cnt = %d", sm->discover_ssid_cnt);

View File

@@ -37,7 +37,6 @@ INPUT = \
$(PROJECT_PATH)/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h \ $(PROJECT_PATH)/components/wpa_supplicant/esp_supplicant/include/esp_dpp.h \
$(PROJECT_PATH)/components/esp_event/include/esp_event.h \ $(PROJECT_PATH)/components/esp_event/include/esp_event.h \
$(PROJECT_PATH)/components/esp_event/include/esp_event_base.h \ $(PROJECT_PATH)/components/esp_event/include/esp_event_base.h \
$(PROJECT_PATH)/components/esp_event/include/esp_event_legacy.h \
$(PROJECT_PATH)/components/bt/include/esp32/include/esp_bt.h \ $(PROJECT_PATH)/components/bt/include/esp32/include/esp_bt.h \
$(PROJECT_PATH)/components/bt/common/api/include/api/esp_blufi_api.h \ $(PROJECT_PATH)/components/bt/common/api/include/api/esp_blufi_api.h \
$(PROJECT_PATH)/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h \ $(PROJECT_PATH)/components/bt/host/bluedroid/api/include/api/esp_bt_defs.h \

View File

@@ -224,5 +224,3 @@ Related Documents
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
Legacy event loop API reference <esp_event_legacy>

View File

@@ -1,7 +0,0 @@
Legacy event loop
=================
API Reference
-------------
.. include-build-file:: inc/esp_event_legacy.inc

View File

@@ -1 +0,0 @@
.. include:: ../../../en/api-reference/system/esp_event_legacy.rst

View File

@@ -1,3 +1,8 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
/* Net-suite test code /* Net-suite test code
This example code is in the Public Domain (or CC0 licensed, at your option.) This example code is in the Public Domain (or CC0 licensed, at your option.)
@@ -8,6 +13,7 @@
*/ */
#include <string.h> #include <string.h>
#include "esp_event.h" #include "esp_event.h"
#include "esp_netif.h"
#include "esp_log.h" #include "esp_log.h"
#include "stdinout.h" #include "stdinout.h"
#include "lwip/err.h" #include "lwip/err.h"

View File

@@ -429,7 +429,6 @@ components/esp_eth/src/esp_eth_phy.c
components/esp_eth/src/ksz8851.h components/esp_eth/src/ksz8851.h
components/esp_eth/src/openeth.h components/esp_eth/src/openeth.h
components/esp_eth/src/w5500.h components/esp_eth/src/w5500.h
components/esp_eth/test/test_emac.c
components/esp_eth/test_apps/component_ut_test.py components/esp_eth/test_apps/component_ut_test.py
components/esp_eth/test_apps/main/esp_eth_test.c components/esp_eth/test_apps/main/esp_eth_test.c
components/esp_event/esp_event_private.c components/esp_event/esp_event_private.c
@@ -441,7 +440,6 @@ components/esp_event/include/esp_event_base.h
components/esp_event/include/esp_event_loop.h components/esp_event/include/esp_event_loop.h
components/esp_event/private_include/esp_event_internal.h components/esp_event/private_include/esp_event_internal.h
components/esp_event/private_include/esp_event_private.h components/esp_event/private_include/esp_event_private.h
components/esp_event/test/test_default_loop.c
components/esp_event/test/test_event.c components/esp_event/test/test_event.c
components/esp_gdbstub/esp32/gdbstub_target_config.h components/esp_gdbstub/esp32/gdbstub_target_config.h
components/esp_gdbstub/esp32c3/gdbstub_target_config.h components/esp_gdbstub/esp32c3/gdbstub_target_config.h
@@ -485,14 +483,12 @@ components/esp_local_ctrl/src/esp_local_ctrl_handler.c
components/esp_local_ctrl/src/esp_local_ctrl_priv.h components/esp_local_ctrl/src/esp_local_ctrl_priv.h
components/esp_local_ctrl/src/esp_local_ctrl_transport_ble.c components/esp_local_ctrl/src/esp_local_ctrl_transport_ble.c
components/esp_local_ctrl/src/esp_local_ctrl_transport_httpd.c components/esp_local_ctrl/src/esp_local_ctrl_transport_httpd.c
components/esp_netif/esp_netif_handlers.c
components/esp_netif/include/esp_netif_net_stack.h components/esp_netif/include/esp_netif_net_stack.h
components/esp_netif/include/esp_netif_ppp.h components/esp_netif/include/esp_netif_ppp.h
components/esp_netif/include/esp_netif_slip.h components/esp_netif/include/esp_netif_slip.h
components/esp_netif/include/esp_netif_sta_list.h components/esp_netif/include/esp_netif_sta_list.h
components/esp_netif/loopback/esp_netif_loopback.c components/esp_netif/loopback/esp_netif_loopback.c
components/esp_netif/lwip/esp_netif_lwip_defaults.c components/esp_netif/lwip/esp_netif_lwip_defaults.c
components/esp_netif/lwip/esp_netif_lwip_ppp.c
components/esp_netif/lwip/esp_netif_lwip_ppp.h components/esp_netif/lwip/esp_netif_lwip_ppp.h
components/esp_netif/lwip/esp_netif_lwip_slip.c components/esp_netif/lwip/esp_netif_lwip_slip.c
components/esp_netif/lwip/esp_netif_lwip_slip.h components/esp_netif/lwip/esp_netif_lwip_slip.h
@@ -739,7 +735,6 @@ components/esp_wifi/include/esp_private/esp_wifi_private.h
components/esp_wifi/include/esp_private/esp_wifi_types_private.h components/esp_wifi/include/esp_private/esp_wifi_types_private.h
components/esp_wifi/include/esp_private/wifi_types.h components/esp_wifi/include/esp_private/wifi_types.h
components/esp_wifi/include/esp_smartconfig.h components/esp_wifi/include/esp_smartconfig.h
components/esp_wifi/include/esp_wifi_default.h
components/esp_wifi/include/esp_wifi_netif.h components/esp_wifi/include/esp_wifi_netif.h
components/esp_wifi/include/smartconfig_ack.h components/esp_wifi/include/smartconfig_ack.h
components/esp_wifi/src/lib_printf.c components/esp_wifi/src/lib_printf.c
@@ -1758,7 +1753,6 @@ components/vfs/test/test_vfs_append.c
components/vfs/test/test_vfs_lwip.c components/vfs/test/test_vfs_lwip.c
components/vfs/test/test_vfs_paths.c components/vfs/test/test_vfs_paths.c
components/vfs/test/test_vfs_uart.c components/vfs/test/test_vfs_uart.c
components/wifi_provisioning/include/wifi_provisioning/manager.h
components/wifi_provisioning/include/wifi_provisioning/scheme_ble.h components/wifi_provisioning/include/wifi_provisioning/scheme_ble.h
components/wifi_provisioning/include/wifi_provisioning/scheme_console.h components/wifi_provisioning/include/wifi_provisioning/scheme_console.h
components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h components/wifi_provisioning/include/wifi_provisioning/scheme_softap.h
@@ -2165,7 +2159,6 @@ examples/mesh/ip_internal_network/main/mqtt_app.c
examples/mesh/manual_networking/main/include/mesh_light.h examples/mesh/manual_networking/main/include/mesh_light.h
examples/mesh/manual_networking/main/mesh_light.c examples/mesh/manual_networking/main/mesh_light.c
examples/mesh/manual_networking/main/mesh_main.c examples/mesh/manual_networking/main/mesh_main.c
examples/network/network_tests/main/net_suite.c
examples/network/network_tests/main/stdinout.c examples/network/network_tests/main/stdinout.c
examples/network/network_tests/main/stdinout.h examples/network/network_tests/main/stdinout.h
examples/network/simple_sniffer/components/pcap/pcap.c examples/network/simple_sniffer/components/pcap/pcap.c