wifi: add code for setting wifi log level and module
This commit is contained in:
parent
7458c1c1e2
commit
e621e0af8b
5 changed files with 255 additions and 4 deletions
|
@ -1154,6 +1154,82 @@ config ESP32_WIFI_SOFTAP_BEACON_MAX_LEN
|
|||
|
||||
Setting a longer beacon length also assists with debugging as the conflicting root nodes can be identified more quickly.
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_ENABLE
|
||||
bool "Enable WiFi debug log"
|
||||
default n
|
||||
help
|
||||
Select this option to enable WiFi debug log
|
||||
|
||||
choice ESP32_WIFI_DEBUG_LOG_LEVEL
|
||||
depends on ESP32_WIFI_DEBUG_LOG_ENABLE
|
||||
prompt "WiFi debug log level"
|
||||
default ESP32_WIFI_LOG_DEBUG
|
||||
help
|
||||
The WiFi log is divided into the following levels: ERROR,WARNING,INFO,DEBUG,VERBOSE.
|
||||
The ERROR,WARNING,INFO levels are enabled by default, and the DEBUG,VERBOSE levels can be enabled here.
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_DEBUG
|
||||
bool "WiFi Debug Log Debug"
|
||||
config ESP32_WIFI_DEBUG_LOG_VERBOSE
|
||||
bool "WiFi Debug Log Verbose"
|
||||
endchoice
|
||||
|
||||
choice ESP32_WIFI_DEBUG_LOG_MODULE
|
||||
depends on ESP32_WIFI_DEBUG_LOG_ENABLE
|
||||
prompt "WiFi debug log module"
|
||||
default ESP32_WIFI_DEBUG_LOG_MODULE_WIFI
|
||||
help
|
||||
The WiFi log module contains three parts: WIFI,COEX,MESH.
|
||||
The WIFI module indicates the logs related to WiFi, the COEX module indicates the logs related to WiFi and BT(or BLE) coexist,
|
||||
the MESH module indicates the logs related to Mesh. When ESP32_WIFI_LOG_MODULE_ALL is enabled, all modules are selected.
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_MODULE_ALL
|
||||
bool "WiFi Debug Log Module All"
|
||||
config ESP32_WIFI_DEBUG_LOG_MODULE_WIFI
|
||||
bool "WiFi Debug Log Module WiFi"
|
||||
config ESP32_WIFI_DEBUG_LOG_MODULE_COEX
|
||||
bool "WiFi Debug Log Module Coex"
|
||||
config ESP32_WIFI_DEBUG_LOG_MODULE_MESH
|
||||
bool "WiFi Debug Log Module Mesh"
|
||||
endchoice
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_SUBMODULE
|
||||
depends on ESP32_WIFI_DEBUG_LOG_ENABLE
|
||||
bool "WiFi debug log submodule"
|
||||
default n
|
||||
help
|
||||
Enable this option to set the WiFi debug log submodule.
|
||||
Currently the log submodule contains the following parts: INIT,IOCTL,CONN,SCAN.
|
||||
The INIT submodule indicates the initialization process.The IOCTL submodule indicates the API calling process.
|
||||
The CONN submodule indicates the connecting process.The SCAN submodule indicates the scaning process.
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL
|
||||
depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE
|
||||
bool "WiFi Debug Log Submodule All"
|
||||
default n
|
||||
help
|
||||
When this option is enabled, all debug submodules are selected.
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_SUBMODULE_INIT
|
||||
depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE && (!ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL)
|
||||
bool "WiFi Debug Log Submodule Init"
|
||||
default n
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_SUBMODULE_IOCTL
|
||||
depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE && (!ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL)
|
||||
bool "WiFi Debug Log Submodule Ioctl"
|
||||
default n
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_SUBMODULE_CONN
|
||||
depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE && (!ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL)
|
||||
bool "WiFi Debug Log Submodule Conn"
|
||||
default n
|
||||
|
||||
config ESP32_WIFI_DEBUG_LOG_SUBMODULE_SCAN
|
||||
depends on ESP32_WIFI_DEBUG_LOG_SUBMODULE && (!ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL)
|
||||
bool "WiFi Debug Log Submodule Scan"
|
||||
default n
|
||||
|
||||
endmenu # Wi-Fi
|
||||
|
||||
menu PHY
|
||||
|
|
|
@ -46,6 +46,57 @@ do{\
|
|||
}\
|
||||
} while(0)
|
||||
|
||||
typedef struct {
|
||||
int err;
|
||||
const char *reason;
|
||||
} wifi_reason_t;
|
||||
|
||||
static const wifi_reason_t wifi_reason[] =
|
||||
{
|
||||
{0, "wifi reason: other reason"},
|
||||
{WIFI_REASON_UNSPECIFIED, "wifi reason: unspecified"},
|
||||
{WIFI_REASON_AUTH_EXPIRE, "wifi reason: auth expire"},
|
||||
{WIFI_REASON_AUTH_LEAVE, "wifi reason: auth leave"},
|
||||
{WIFI_REASON_ASSOC_EXPIRE, "wifi reason: assoc expire"},
|
||||
{WIFI_REASON_ASSOC_TOOMANY, "wifi reason: assoc too many"},
|
||||
{WIFI_REASON_NOT_AUTHED, "wifi reason: not authed"},
|
||||
{WIFI_REASON_NOT_ASSOCED, "wifi reason: not assoced"},
|
||||
{WIFI_REASON_ASSOC_LEAVE, "wifi reason: assoc leave"},
|
||||
{WIFI_REASON_ASSOC_NOT_AUTHED, "wifi reason: assoc not authed"},
|
||||
{WIFI_REASON_BEACON_TIMEOUT, "wifi reason: beacon timeout"},
|
||||
{WIFI_REASON_NO_AP_FOUND, "wifi reason: no ap found"},
|
||||
{WIFI_REASON_AUTH_FAIL, "wifi reason: auth fail"},
|
||||
{WIFI_REASON_ASSOC_FAIL, "wifi reason: assoc fail"},
|
||||
{WIFI_REASON_HANDSHAKE_TIMEOUT, "wifi reason: hanshake timeout"},
|
||||
{WIFI_REASON_DISASSOC_PWRCAP_BAD, "wifi reason: bad Power Capability, disassoc"},
|
||||
{WIFI_REASON_DISASSOC_SUPCHAN_BAD, "wifi reason: bad Supported Channels, disassoc"},
|
||||
{WIFI_REASON_IE_INVALID, "wifi reason: invalid IE"},
|
||||
{WIFI_REASON_MIC_FAILURE, "wifi reason: MIC failure"},
|
||||
{WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT, "wifi reason: 4-way keying handshake timeout"},
|
||||
{WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT, "wifi reason: Group key handshake"},
|
||||
{WIFI_REASON_IE_IN_4WAY_DIFFERS, "wifi reason: IE in 4-way differs"},
|
||||
{WIFI_REASON_GROUP_CIPHER_INVALID, "wifi reason: invalid group cipher"},
|
||||
{WIFI_REASON_PAIRWISE_CIPHER_INVALID, "wifi reason: invalid pairwise cipher"},
|
||||
{WIFI_REASON_AKMP_INVALID, "wifi reason: invalid AKMP"},
|
||||
{WIFI_REASON_UNSUPP_RSN_IE_VERSION, "wifi reason: unsupported RSN IE version"},
|
||||
{WIFI_REASON_INVALID_RSN_IE_CAP, "wifi reason: invalid RSN IE capability"},
|
||||
{WIFI_REASON_802_1X_AUTH_FAILED, "wifi reason: 802.1x auth failed"},
|
||||
{WIFI_REASON_CIPHER_SUITE_REJECTED, "wifi reason: cipher suite rejected"}
|
||||
};
|
||||
|
||||
const char* wifi_get_reason(int err)
|
||||
{
|
||||
int i=0;
|
||||
|
||||
for (i=0; i< sizeof(wifi_reason)/sizeof(wifi_reason_t); i++){
|
||||
if (err == wifi_reason[i].err){
|
||||
return wifi_reason[i].reason;
|
||||
}
|
||||
}
|
||||
|
||||
return wifi_reason[0].reason;
|
||||
}
|
||||
|
||||
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);
|
||||
|
@ -277,8 +328,8 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
|
|||
}
|
||||
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);
|
||||
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_get_reason(disconnected->reason));
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_STA_AUTHMODE_CHANGE: {
|
||||
|
|
|
@ -46,6 +46,40 @@ typedef struct {
|
|||
void *storage; /**< storage for FreeRTOS queue */
|
||||
} wifi_static_queue_t;
|
||||
|
||||
/**
|
||||
* @brief WiFi log level
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
WIFI_LOG_ERROR = 0, /*enabled by default*/
|
||||
WIFI_LOG_WARNING, /*enabled by default*/
|
||||
WIFI_LOG_INFO, /*enabled by default*/
|
||||
WIFI_LOG_DEBUG, /*can be set in menuconfig*/
|
||||
WIFI_LOG_VERBOSE, /*can be set in menuconfig*/
|
||||
} wifi_log_level_t;
|
||||
|
||||
/**
|
||||
* @brief WiFi log module definition
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
WIFI_LOG_MODULE_ALL = 0, /*all log modules */
|
||||
WIFI_LOG_MODULE_WIFI, /*logs related to WiFi*/
|
||||
WIFI_LOG_MODULE_COEX, /*logs related to WiFi and BT(or BLE) coexist*/
|
||||
WIFI_LOG_MODULE_MESH, /*logs related to Mesh*/
|
||||
} wifi_log_module_t;
|
||||
|
||||
/**
|
||||
* @brief WiFi log submodule definition
|
||||
*
|
||||
*/
|
||||
#define WIFI_LOG_SUBMODULE_ALL (0) /*all log submodules*/
|
||||
#define WIFI_LOG_SUBMODULE_INIT (1) /*logs related to initialization*/
|
||||
#define WIFI_LOG_SUBMODULE_IOCTL (1<<1) /*logs related to API calling*/
|
||||
#define WIFI_LOG_SUBMODULE_CONN (1<<2) /*logs related to connecting*/
|
||||
#define WIFI_LOG_SUBMODULE_SCAN (1<<3) /*logs related to scaning*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize Wi-Fi Driver
|
||||
* Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
|
||||
|
@ -224,6 +258,46 @@ void *wifi_calloc( size_t n, size_t size );
|
|||
*/
|
||||
esp_err_t esp_wifi_internal_update_mac_time( uint32_t time_delta );
|
||||
|
||||
/**
|
||||
* @brief Set current WiFi log level
|
||||
*
|
||||
* @param level Log level.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_FAIL: level is invalid
|
||||
*/
|
||||
esp_err_t esp_wifi_internal_set_log_level(wifi_log_level_t level);
|
||||
|
||||
/**
|
||||
* @brief Set current log module and submodule
|
||||
*
|
||||
* @param module Log module
|
||||
* @param submodule Log submodule
|
||||
* @param enable enable or disable
|
||||
* If module == 0 && enable == 0, all log modules are disabled.
|
||||
* If module == 0 && enable == 1, all log modules are enabled.
|
||||
* If submodule == 0 && enable == 0, all log submodules are disabled.
|
||||
* If submodule == 0 && enable == 1, all log submodules are enabled.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_internal_set_log_mod(wifi_log_module_t module, uint32_t submodule, bool enable);
|
||||
|
||||
/**
|
||||
* @brief Get current WiFi log info
|
||||
*
|
||||
* @param log_level the return log level.
|
||||
* @param log_mod the return log module and submodule
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
*/
|
||||
esp_err_t esp_wifi_internal_get_log(wifi_log_level_t *log_level, uint32_t *log_mod);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b16383705d7844e125f5063cb642f5964f2d8ff4
|
||||
Subproject commit e33ab451f5a95537be2c486172ddaffa64f3dcac
|
|
@ -36,6 +36,53 @@ static void __attribute__((constructor)) s_set_default_wifi_log_level()
|
|||
esp_log_level_set("wifi", CONFIG_LOG_DEFAULT_LEVEL);
|
||||
}
|
||||
|
||||
static void esp_wifi_set_debug_log()
|
||||
{
|
||||
/* set WiFi log level and module */
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE
|
||||
uint32_t g_wifi_log_level = WIFI_LOG_INFO;
|
||||
uint32_t g_wifi_log_module = 0;
|
||||
uint32_t g_wifi_log_submodule = 0;
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_DEBUG
|
||||
g_wifi_log_level = WIFI_LOG_DEBUG;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_VERBOSE
|
||||
g_wifi_log_level = WIFI_LOG_VERBOSE;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_MODULE_ALL
|
||||
g_wifi_log_module = WIFI_LOG_MODULE_ALL;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_MODULE_WIFI
|
||||
g_wifi_log_module = WIFI_LOG_MODULE_WIFI;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_MODULE_COEX
|
||||
g_wifi_log_module = WIFI_LOG_MODULE_COEX;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_MODULE_MESH
|
||||
g_wifi_log_module = WIFI_LOG_MODULE_MESH;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_ALL
|
||||
g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_ALL;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_INIT
|
||||
g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_INIT;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_IOCTL
|
||||
g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_IOCTL;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_CONN
|
||||
g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_CONN;
|
||||
#endif
|
||||
#if CONFIG_ESP32_WIFI_DEBUG_LOG_SUBMODULE_SCAN
|
||||
g_wifi_log_submodule |= WIFI_LOG_SUBMODULE_SCAN;
|
||||
#endif
|
||||
esp_wifi_internal_set_log_level(g_wifi_log_level);
|
||||
esp_wifi_internal_set_log_mod(g_wifi_log_module, g_wifi_log_submodule, true);
|
||||
|
||||
#endif /* CONFIG_ESP32_WIFI_DEBUG_LOG_ENABLE*/
|
||||
|
||||
}
|
||||
|
||||
esp_err_t esp_wifi_init(const wifi_init_config_t *config)
|
||||
{
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
|
@ -48,7 +95,10 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
|
|||
}
|
||||
#endif
|
||||
esp_event_set_default_wifi_handlers();
|
||||
return esp_wifi_init_internal(config);
|
||||
esp_err_t result = esp_wifi_init_internal(config);
|
||||
esp_wifi_set_debug_log();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
|
|
Loading…
Reference in a new issue