2016-08-17 15:08:22 +00:00
|
|
|
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2016-09-13 07:57:11 +00:00
|
|
|
|
2016-08-17 15:08:22 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
2016-09-05 03:05:07 +00:00
|
|
|
#include <string.h>
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
#include "esp_err.h"
|
|
|
|
#include "esp_wifi.h"
|
2016-11-08 09:34:46 +00:00
|
|
|
#include "esp_wifi_internal.h"
|
2016-08-17 15:08:22 +00:00
|
|
|
#include "esp_event.h"
|
2016-09-25 17:17:32 +00:00
|
|
|
#include "esp_event_loop.h"
|
2016-09-01 06:09:21 +00:00
|
|
|
#include "esp_task.h"
|
2016-11-08 09:45:17 +00:00
|
|
|
#include "esp_eth.h"
|
2017-08-07 10:30:46 +00:00
|
|
|
#include "esp_system.h"
|
2016-11-08 09:45:17 +00:00
|
|
|
|
2016-11-08 03:24:44 +00:00
|
|
|
#include "rom/ets_sys.h"
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
#include "freertos/FreeRTOS.h"
|
|
|
|
#include "freertos/task.h"
|
|
|
|
#include "freertos/queue.h"
|
|
|
|
#include "freertos/semphr.h"
|
|
|
|
|
|
|
|
#include "tcpip_adapter.h"
|
2016-09-23 06:46:39 +00:00
|
|
|
#include "esp_log.h"
|
2016-08-17 15:08:22 +00:00
|
|
|
|
2016-09-25 17:17:32 +00:00
|
|
|
const char* TAG = "event";
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
#define WIFI_API_CALL_CHECK(info, api_call, ret) \
|
|
|
|
do{\
|
|
|
|
esp_err_t __err = (api_call);\
|
|
|
|
if ((ret) != __err) {\
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGE(TAG, "%s %d %s ret=%d", __FUNCTION__, __LINE__, (info), __err);\
|
2016-08-17 15:08:22 +00:00
|
|
|
return __err;\
|
|
|
|
}\
|
|
|
|
} while(0)
|
|
|
|
|
2017-02-24 03:46:23 +00:00
|
|
|
typedef esp_err_t (*system_event_handler_t)(system_event_t *e);
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
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);
|
2016-09-13 07:57:11 +00:00
|
|
|
static esp_err_t system_event_sta_got_ip_default(system_event_t *event);
|
2016-08-17 15:08:22 +00:00
|
|
|
|
2016-11-08 09:45:17 +00:00
|
|
|
static esp_err_t system_event_eth_start_handle_default(system_event_t *event);
|
|
|
|
static esp_err_t system_event_eth_stop_handle_default(system_event_t *event);
|
|
|
|
static esp_err_t system_event_eth_connected_handle_default(system_event_t *event);
|
|
|
|
static esp_err_t system_event_eth_disconnected_handle_default(system_event_t *event);
|
2017-02-24 03:46:23 +00:00
|
|
|
|
|
|
|
/* Default event handler functions
|
|
|
|
|
|
|
|
Any entry in this table which is disabled by config will have a NULL handler.
|
|
|
|
*/
|
2017-08-16 06:33:37 +00:00
|
|
|
static system_event_handler_t default_event_handlers[SYSTEM_EVENT_MAX] = { 0 };
|
|
|
|
|
2016-11-08 09:45:17 +00:00
|
|
|
esp_err_t system_event_eth_start_handle_default(system_event_t *event)
|
|
|
|
{
|
|
|
|
tcpip_adapter_ip_info_t eth_ip;
|
|
|
|
uint8_t eth_mac[6];
|
|
|
|
|
|
|
|
esp_eth_get_mac(eth_mac);
|
|
|
|
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, ð_ip);
|
2017-08-08 04:48:14 +00:00
|
|
|
tcpip_adapter_eth_start(eth_mac, ð_ip);
|
2016-11-08 09:45:17 +00:00
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t system_event_eth_stop_handle_default(system_event_t *event)
|
|
|
|
{
|
|
|
|
tcpip_adapter_stop(TCPIP_ADAPTER_IF_ETH);
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t system_event_eth_connected_handle_default(system_event_t *event)
|
|
|
|
{
|
|
|
|
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) || ip4_addr_isany_val(eth_ip.gw))) {
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t system_event_eth_disconnected_handle_default(system_event_t *event)
|
|
|
|
{
|
|
|
|
tcpip_adapter_down(TCPIP_ADAPTER_IF_ETH);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-13 07:57:11 +00:00
|
|
|
static esp_err_t system_event_sta_got_ip_default(system_event_t *event)
|
2016-08-30 06:04:12 +00:00
|
|
|
{
|
2016-11-08 09:34:46 +00:00
|
|
|
WIFI_API_CALL_CHECK("esp_wifi_internal_set_sta_ip", esp_wifi_internal_set_sta_ip(), ESP_OK);
|
2016-09-05 03:05:07 +00:00
|
|
|
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGI(TAG, "ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR,
|
2016-09-13 07:57:11 +00:00
|
|
|
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));
|
2016-09-05 03:05:07 +00:00
|
|
|
|
2016-08-30 06:04:12 +00:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:08:22 +00:00
|
|
|
esp_err_t system_event_ap_start_handle_default(system_event_t *event)
|
|
|
|
{
|
2016-09-06 05:02:02 +00:00
|
|
|
tcpip_adapter_ip_info_t ap_ip;
|
2016-08-17 15:08:22 +00:00
|
|
|
uint8_t ap_mac[6];
|
|
|
|
|
2016-11-08 09:45:17 +00:00
|
|
|
WIFI_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);
|
|
|
|
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_AP, ap_mac), ESP_OK);
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip);
|
2017-08-08 04:48:14 +00:00
|
|
|
tcpip_adapter_ap_start(ap_mac, &ap_ip);
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t system_event_ap_stop_handle_default(system_event_t *event)
|
|
|
|
{
|
2016-11-08 09:45:17 +00:00
|
|
|
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL), ESP_OK);
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
tcpip_adapter_stop(TCPIP_ADAPTER_IF_AP);
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t system_event_sta_start_handle_default(system_event_t *event)
|
|
|
|
{
|
2016-09-06 05:02:02 +00:00
|
|
|
tcpip_adapter_ip_info_t sta_ip;
|
2016-08-17 15:08:22 +00:00
|
|
|
uint8_t sta_mac[6];
|
|
|
|
|
2016-11-08 09:45:17 +00:00
|
|
|
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_STA, sta_mac), ESP_OK);
|
2016-08-17 15:08:22 +00:00
|
|
|
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
2017-08-08 04:48:14 +00:00
|
|
|
tcpip_adapter_sta_start(sta_mac, &sta_ip);
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2016-08-26 03:52:46 +00:00
|
|
|
tcpip_adapter_dhcp_status_t status;
|
2016-09-13 07:57:11 +00:00
|
|
|
|
2016-11-08 09:45:17 +00:00
|
|
|
WIFI_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);
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
|
2016-08-26 03:52:46 +00:00
|
|
|
|
|
|
|
tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_STA, &status);
|
|
|
|
|
|
|
|
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
|
|
|
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_STA);
|
2016-09-05 03:05:07 +00:00
|
|
|
} else if (status == TCPIP_ADAPTER_DHCP_STOPPED) {
|
2016-09-06 05:02:02 +00:00
|
|
|
tcpip_adapter_ip_info_t sta_ip;
|
2016-09-05 03:05:07 +00:00
|
|
|
|
2016-09-06 05:02:02 +00:00
|
|
|
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
2016-09-05 03:05:07 +00:00
|
|
|
|
2016-09-05 12:14:58 +00:00
|
|
|
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;
|
2016-09-05 03:05:07 +00:00
|
|
|
|
2016-09-05 12:14:58 +00:00
|
|
|
//notify event
|
2016-09-12 08:43:32 +00:00
|
|
|
evt.event_id = SYSTEM_EVENT_STA_GOT_IP;
|
2016-09-05 12:14:58 +00:00
|
|
|
memcpy(&evt.event_info.got_ip.ip_info, &sta_ip, sizeof(tcpip_adapter_ip_info_t));
|
|
|
|
|
|
|
|
esp_event_send(&evt);
|
|
|
|
} else {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGE(TAG, "invalid static ip");
|
2016-09-05 12:14:58 +00:00
|
|
|
}
|
2016-08-26 03:52:46 +00:00
|
|
|
}
|
2016-08-17 15:08:22 +00:00
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event)
|
|
|
|
{
|
|
|
|
tcpip_adapter_down(TCPIP_ADAPTER_IF_STA);
|
2016-11-08 09:45:17 +00:00
|
|
|
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, NULL), ESP_OK);
|
2016-08-17 15:08:22 +00:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static esp_err_t esp_system_event_debug(system_event_t *event)
|
|
|
|
{
|
|
|
|
if (event == NULL) {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGE(TAG, "event is null!");
|
2016-08-17 15:08:22 +00:00
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event->event_id) {
|
2016-09-13 07:57:11 +00:00
|
|
|
case SYSTEM_EVENT_WIFI_READY: {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_WIFI_READY");
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_SCAN_DONE: {
|
2016-09-23 06:46:39 +00:00
|
|
|
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);
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_STA_START: {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_START");
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_STA_STOP: {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_STOP");
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_STA_CONNECTED: {
|
2016-09-23 06:46:39 +00:00
|
|
|
system_event_sta_connected_t *connected = &event->event_info.connected;
|
2016-11-08 03:24:44 +00:00
|
|
|
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);
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_STA_DISCONNECTED: {
|
2016-09-23 06:46:39 +00:00
|
|
|
system_event_sta_disconnected_t *disconnected = &event->event_info.disconnected;
|
2016-11-08 03:24:44 +00:00
|
|
|
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);
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: {
|
2016-09-23 06:46:39 +00:00
|
|
|
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);
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_STA_GOT_IP: {
|
2016-09-23 06:46:39 +00:00
|
|
|
system_event_sta_got_ip_t *got_ip = &event->event_info.got_ip;
|
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_STA_GOTIP, ip:" IPSTR ", mask:" IPSTR ", gw:" IPSTR,
|
|
|
|
IP2STR(&got_ip->ip_info.ip),
|
|
|
|
IP2STR(&got_ip->ip_info.netmask),
|
|
|
|
IP2STR(&got_ip->ip_info.gw));
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-11-09 09:27:12 +00:00
|
|
|
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;
|
|
|
|
}
|
2016-09-13 07:57:11 +00:00
|
|
|
case SYSTEM_EVENT_AP_START: {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_START");
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_AP_STOP: {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STOP");
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_AP_STACONNECTED: {
|
2016-09-23 06:46:39 +00:00
|
|
|
system_event_ap_staconnected_t *staconnected = &event->event_info.sta_connected;
|
2016-11-08 03:24:44 +00:00
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STACONNECTED, mac:" MACSTR ", aid:%d", \
|
|
|
|
MAC2STR(staconnected->mac), staconnected->aid);
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_AP_STADISCONNECTED: {
|
2016-09-23 06:46:39 +00:00
|
|
|
system_event_ap_stadisconnected_t *stadisconnected = &event->event_info.sta_disconnected;
|
2016-11-08 03:24:44 +00:00
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_STADISCONNECTED, mac:" MACSTR ", aid:%d", \
|
|
|
|
MAC2STR(stadisconnected->mac), stadisconnected->aid);
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SYSTEM_EVENT_AP_PROBEREQRECVED: {
|
2016-09-23 06:46:39 +00:00
|
|
|
system_event_ap_probe_req_rx_t *ap_probereqrecved = &event->event_info.ap_probereqrecved;
|
2016-11-08 03:24:44 +00:00
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_AP_PROBEREQRECVED, rssi:%d, mac:" MACSTR, \
|
|
|
|
ap_probereqrecved->rssi, \
|
|
|
|
MAC2STR(ap_probereqrecved->mac));
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-06-07 07:26:44 +00:00
|
|
|
case SYSTEM_EVENT_AP_STA_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;
|
|
|
|
}
|
2016-11-08 09:45:17 +00:00
|
|
|
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: {
|
|
|
|
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_GOT_IP");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-13 07:57:11 +00:00
|
|
|
default: {
|
2017-06-07 07:26:44 +00:00
|
|
|
ESP_LOGW(TAG, "unexpected system event %d!", event->event_id);
|
2016-09-13 07:57:11 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-08-17 15:08:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
2016-09-25 17:17:32 +00:00
|
|
|
esp_err_t esp_event_process_default(system_event_t *event)
|
2016-08-17 15:08:22 +00:00
|
|
|
{
|
|
|
|
if (event == NULL) {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGE(TAG, "Error: event is null!");
|
2016-08-17 15:08:22 +00:00
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_system_event_debug(event);
|
2017-02-24 03:46:23 +00:00
|
|
|
if ((event->event_id < SYSTEM_EVENT_MAX)) {
|
|
|
|
if (default_event_handlers[event->event_id] != NULL) {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGV(TAG, "enter default callback");
|
2017-02-24 03:46:23 +00:00
|
|
|
default_event_handlers[event->event_id](event);
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGV(TAG, "exit default callback");
|
2016-08-17 15:08:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-09-23 06:46:39 +00:00
|
|
|
ESP_LOGE(TAG, "mismatch or invalid event, id=%d", event->event_id);
|
2016-09-13 07:57:11 +00:00
|
|
|
return ESP_FAIL;
|
|
|
|
}
|
2016-08-17 15:08:22 +00:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
2017-08-07 05:05:36 +00:00
|
|
|
|
2017-08-17 04:11:34 +00:00
|
|
|
void esp_event_set_default_wifi_handlers()
|
2017-08-07 05:05:36 +00:00
|
|
|
{
|
2017-08-07 10:27:58 +00:00
|
|
|
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_AP_START] = system_event_ap_start_handle_default;
|
|
|
|
default_event_handlers[SYSTEM_EVENT_AP_STOP] = system_event_ap_stop_handle_default;
|
|
|
|
|
2017-08-07 10:30:46 +00:00
|
|
|
esp_register_shutdown_handler((shutdown_handler_t)esp_wifi_stop);
|
2017-08-07 05:05:36 +00:00
|
|
|
}
|
2017-08-16 06:33:37 +00:00
|
|
|
|
|
|
|
void esp_event_set_default_eth_handlers()
|
|
|
|
{
|
|
|
|
default_event_handlers[SYSTEM_EVENT_ETH_START] = system_event_eth_start_handle_default;
|
|
|
|
default_event_handlers[SYSTEM_EVENT_ETH_STOP] = system_event_eth_stop_handle_default;
|
|
|
|
default_event_handlers[SYSTEM_EVENT_ETH_CONNECTED] = system_event_eth_connected_handle_default;
|
|
|
|
default_event_handlers[SYSTEM_EVENT_ETH_DISCONNECTED] = system_event_eth_disconnected_handle_default;
|
|
|
|
}
|