From cb5f7690a4ab654a5a5e0a60a59e3acc99cc31ab Mon Sep 17 00:00:00 2001 From: Liu Zhi Fu Date: Tue, 8 Nov 2016 17:34:46 +0800 Subject: [PATCH 1/2] esp32/make: add detailed return error code for wifi APIs 1. Add detailed return error code for wifi APIs 2. Add description about error code in esp_wifi.h 3. Modify esp_wifi_reg_rxcb to esp_wifi_internal_reg_rxcb 4. Modify esp_wifi_set_sta_ip to esp_wifi_internal_set_sta_ip 5. Mark system_init as deprecated API --- components/esp32/event_default_handlers.c | 12 +- components/esp32/include/esp_err.h | 2 + components/esp32/include/esp_system.h | 10 +- components/esp32/include/esp_wifi.h | 291 ++++++++++++------- components/esp32/include/esp_wifi_internal.h | 33 ++- components/esp32/lib | 2 +- make/project.mk | 3 +- 7 files changed, 241 insertions(+), 112 deletions(-) diff --git a/components/esp32/event_default_handlers.c b/components/esp32/event_default_handlers.c index 37ba63404..a2bb3ccea 100644 --- a/components/esp32/event_default_handlers.c +++ b/components/esp32/event_default_handlers.c @@ -18,6 +18,7 @@ #include "esp_err.h" #include "esp_wifi.h" +#include "esp_wifi_internal.h" #include "esp_event.h" #include "esp_event_loop.h" #include "esp_task.h" @@ -76,8 +77,7 @@ static system_event_handle_t g_system_event_handle_table[] = { static esp_err_t system_event_sta_got_ip_default(system_event_t *event) { - extern esp_err_t esp_wifi_set_sta_ip(void); - WIFI_API_CALL_CHECK("esp_wifi_set_sta_ip", esp_wifi_set_sta_ip(), ESP_OK); + WIFI_API_CALL_CHECK("esp_wifi_internal_set_sta_ip", esp_wifi_internal_set_sta_ip(), ESP_OK); ESP_LOGI(TAG, "ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR, IP2STR(&event->event_info.got_ip.ip_info.ip), @@ -92,7 +92,7 @@ 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_reg_rxcb", esp_wifi_reg_rxcb(WIFI_IF_AP, (wifi_rxcb_t)tcpip_adapter_ap_input), ESP_OK); + WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(WIFI_IF_AP, (wifi_rxcb_t)tcpip_adapter_ap_input), ESP_OK); WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(WIFI_IF_AP, ap_mac), ESP_OK); tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip); @@ -103,7 +103,7 @@ esp_err_t system_event_ap_start_handle_default(system_event_t *event) esp_err_t system_event_ap_stop_handle_default(system_event_t *event) { - WIFI_API_CALL_CHECK("esp_wifi_reg_rxcb", esp_wifi_reg_rxcb(WIFI_IF_AP, NULL), ESP_OK); + WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(WIFI_IF_AP, NULL), ESP_OK); tcpip_adapter_stop(TCPIP_ADAPTER_IF_AP); @@ -133,7 +133,7 @@ esp_err_t system_event_sta_connected_handle_default(system_event_t *event) { tcpip_adapter_dhcp_status_t status; - WIFI_API_CALL_CHECK("esp_wifi_reg_rxcb", esp_wifi_reg_rxcb(WIFI_IF_STA, (wifi_rxcb_t)tcpip_adapter_sta_input), ESP_OK); + WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(WIFI_IF_STA, (wifi_rxcb_t)tcpip_adapter_sta_input), ESP_OK); tcpip_adapter_up(TCPIP_ADAPTER_IF_STA); @@ -165,7 +165,7 @@ esp_err_t system_event_sta_connected_handle_default(system_event_t *event) esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event) { tcpip_adapter_down(TCPIP_ADAPTER_IF_STA); - WIFI_API_CALL_CHECK("esp_wifi_reg_rxcb", esp_wifi_reg_rxcb(WIFI_IF_STA, NULL), ESP_OK); + WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(WIFI_IF_STA, NULL), ESP_OK); return ESP_OK; } diff --git a/components/esp32/include/esp_err.h b/components/esp32/include/esp_err.h index af9d2ec33..dc2c6c2d7 100644 --- a/components/esp32/include/esp_err.h +++ b/components/esp32/include/esp_err.h @@ -34,6 +34,8 @@ typedef int32_t esp_err_t; #define ESP_ERR_INVALID_SIZE 0x104 #define ESP_ERR_NOT_FOUND 0x105 +#define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */ + /** * Macro which can be used to check the error code, * and terminate the program in case the code is not ESP_OK. diff --git a/components/esp32/include/esp_system.h b/components/esp32/include/esp_system.h index 8c6564c55..d416e23d0 100644 --- a/components/esp32/include/esp_system.h +++ b/components/esp32/include/esp_system.h @@ -16,7 +16,6 @@ #define __ESP_SYSTEM_H__ #include -#include #include "esp_err.h" #include "esp_deepsleep.h" @@ -33,6 +32,13 @@ extern "C" { * @{ */ +/** + * @attention application don't need to call this function anymore. It do nothing and will + * be removed in future version. + */ +void system_init(void) __attribute__ ((deprecated)); + + /** * @brief Get information of the SDK version. * @@ -170,8 +176,6 @@ bool system_rtc_mem_write(uint16_t dst, const void *src, uint16_t n); esp_err_t system_efuse_read_mac(uint8_t mac[6]); -void system_init(void); - /** * @} */ diff --git a/components/esp32/include/esp_wifi.h b/components/esp32/include/esp_wifi.h index 80ced5dc6..8e2c1df55 100644 --- a/components/esp32/include/esp_wifi.h +++ b/components/esp32/include/esp_wifi.h @@ -70,6 +70,23 @@ extern "C" { #endif +#define ESP_ERR_WIFI_OK ESP_OK /*!< No error */ +#define ESP_ERR_WIFI_FAIL ESP_FAIL /*!< General fail code */ +#define ESP_ERR_WIFI_NO_MEM ESP_ERR_NO_MEM /*!< Out of memory */ +#define ESP_ERR_WIFI_ARG ESP_ERR_INVALID_ARG /*!< Invalid argument */ +#define ESP_ERR_WIFI_NOT_INIT (ESP_ERR_WIFI_BASE + 1) /*!< WiFi driver is not installed by esp_wifi_init */ +#define ESP_ERR_WIFI_NOT_START (ESP_ERR_WIFI_BASE + 2) /*!< WiFi driver is not started by esp_wifi_start */ +#define ESP_ERR_WIFI_NOT_SUPPORT (ESP_ERR_WIFI_BASE + 3) /*!< WiFi API doesn't support */ +#define ESP_ERR_WIFI_IF (ESP_ERR_WIFI_BASE + 4) /*!< WiFi interface error */ +#define ESP_ERR_WIFI_MODE (ESP_ERR_WIFI_BASE + 5) /*!< WiFi mode error */ +#define ESP_ERR_WIFI_STATE (ESP_ERR_WIFI_BASE + 6) /*!< WiFi internal state error */ +#define ESP_ERR_WIFI_CONN (ESP_ERR_WIFI_BASE + 7) /*!< WiFi internal control block of station or soft-AP error */ +#define ESP_ERR_WIFI_NVS (ESP_ERR_WIFI_BASE + 8) /*!< WiFi internal NVS module error */ +#define ESP_ERR_WIFI_MAC (ESP_ERR_WIFI_BASE + 9) /*!< MAC address is invalid */ +#define ESP_ERR_WIFI_SSID (ESP_ERR_WIFI_BASE + 10) /*!< SSID is invalid */ +#define ESP_ERR_WIFI_PASSWORD (ESP_ERR_WIFI_BASE + 11) /*!< Passord is invalid */ +#define ESP_ERR_WIFI_TIMEOUT (ESP_ERR_WIFI_BASE + 12) /*!< Timeout error */ + typedef struct { system_event_handler_t event_handler; /**< WiFi event handler */ } wifi_init_config_t; @@ -92,8 +109,10 @@ typedef struct { * * @param wifi_init_config_t *config : provide WiFi init configuration * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NO_MEM : out of memory + * - others : refer to error code esp_err.h */ esp_err_t esp_wifi_init(wifi_init_config_t *config); @@ -104,7 +123,6 @@ esp_err_t esp_wifi_init(wifi_init_config_t *config); * @attention 1. This API should be called if you want to remove WiFi driver from the system * * @return ESP_OK : succeed - * @return others : fail */ esp_err_t esp_wifi_deinit(void); @@ -116,8 +134,11 @@ esp_err_t esp_wifi_deinit(void); * * @param wifi_mode_t mode : WiFi operating modes: * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - others : refer to error code in esp_err.h */ esp_err_t esp_wifi_set_mode(wifi_mode_t mode); @@ -126,8 +147,10 @@ esp_err_t esp_wifi_set_mode(wifi_mode_t mode); * * @param wifi_mode_t *mode : store current WiFi mode * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_get_mode(wifi_mode_t *mode); @@ -139,8 +162,13 @@ esp_err_t esp_wifi_get_mode(wifi_mode_t *mode); * * @param null * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_NO_MEM : out of memory + * - ESP_ERR_WIFI_CONN : WiFi internal error, station or soft-AP control block wrong + * - ESP_ERR_WIFI_FAIL : other WiFi internal errors */ esp_err_t esp_wifi_start(void); @@ -152,8 +180,9 @@ esp_err_t esp_wifi_start(void); * * @param null * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init */ esp_err_t esp_wifi_stop(void); @@ -165,8 +194,12 @@ esp_err_t esp_wifi_stop(void); * * @param null * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start + * - ESP_ERR_WIFI_CONN : WiFi internal error, station or soft-AP control block wrong + * - ESP_ERR_WIFI_SSID : SSID of AP which station connects is invalid */ esp_err_t esp_wifi_connect(void); @@ -175,8 +208,11 @@ esp_err_t esp_wifi_connect(void); * * @param null * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start + * - ESP_ERR_WIFI_FAIL : other WiFi internal errors */ esp_err_t esp_wifi_disconnect(void); @@ -185,8 +221,9 @@ esp_err_t esp_wifi_disconnect(void); * * @param null * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - others : fail */ esp_err_t esp_wifi_clear_fast_connect(void); @@ -195,8 +232,12 @@ esp_err_t esp_wifi_clear_fast_connect(void); * * @param uint16_t aid : when aid is 0, deauthenticate all stations, otherwise deauthenticate station whose associated id is aid * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_MODE : WiFi mode is wrong */ esp_err_t esp_wifi_deauth_sta(uint16_t aid); @@ -211,8 +252,12 @@ esp_err_t esp_wifi_deauth_sta(uint16_t aid); * @param bool block : if block is true, this API will block the caller until the scan is done, otherwise * it will return immediately * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start + * - ESP_ERR_WIFI_TIMEOUT : blocking scan is timeout + * - others : refer to error code in esp_err.h */ esp_err_t esp_wifi_scan_start(wifi_scan_config_t *conf, bool block); @@ -220,8 +265,10 @@ esp_err_t esp_wifi_scan_start(wifi_scan_config_t *conf, bool block); * @brief Stop the scan in process * * @param null - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start */ esp_err_t esp_wifi_scan_stop(void); @@ -232,8 +279,11 @@ esp_err_t esp_wifi_scan_stop(void); * * @attention This API can only be called when the scan is completed, otherwise it may get wrong value * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number); @@ -244,8 +294,12 @@ esp_err_t esp_wifi_scan_get_ap_num(uint16_t *number); the actual AP number this API returns * @param wifi_ap_record_t *ap_records: wifi_ap_record_t array to hold the found APs * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_NOT_START : WiFi is not started by esp_wifi_start + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_NO_MEM : out of memory */ esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_records); @@ -255,8 +309,9 @@ esp_err_t esp_wifi_scan_get_ap_records(uint16_t *number, wifi_ap_record_t *ap_re * * @param wifi_ap_record_t *ap_info: the wifi_ap_record_t to hold station assocated AP * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - others : fail */ esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info); @@ -265,8 +320,7 @@ esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info); * * @param wifi_ps_type_t type : power save type * - * @return ESP_OK : succeed - * @return others : fail + * @return ESP_ERR_WIFI_NOT_SUPPORT : not support yet */ esp_err_t esp_wifi_set_ps(wifi_ps_type_t type); @@ -275,8 +329,7 @@ esp_err_t esp_wifi_set_ps(wifi_ps_type_t type); * * @param wifi_ps_type_t *type : store current power save type * - * @return ESP_OK : succeed - * @return others : fail + * @return ESP_ERR_WIFI_NOT_SUPPORT : not support yet */ esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type); @@ -289,8 +342,11 @@ esp_err_t esp_wifi_get_ps(wifi_ps_type_t *type); * @param wifi_interface_t ifx : interfaces * @param uint8_t protocol : WiFi protocol bitmap * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_IF : invalid interface + * - others : refer to erro code in esp_err.h */ esp_err_t esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap); @@ -300,8 +356,12 @@ esp_err_t esp_wifi_set_protocol(wifi_interface_t ifx, uint8_t protocol_bitmap); * @param wifi_interface_t ifx : interfaces * @param uint8_t protocol : store current WiFi protocol bitmap of interface ifx * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_IF : invalid interface + * - ESP_ERR_WIFI_ARG : invalid argument + * - others : refer to error code in esp_err.h */ esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap); @@ -314,8 +374,12 @@ esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bitmap); * @param wifi_interface_t ifx : interface to be configured * @param wifi_bandwidth_t bw : bandwidth * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_IF : invalid interface + * - ESP_ERR_WIFI_ARG : invalid argument + * - others : refer to error code in esp_err.h */ esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw); @@ -327,8 +391,11 @@ esp_err_t esp_wifi_set_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t bw); * @param wifi_interface_t ifx : interface to be configured * @param wifi_bandwidth_t *bw : store bandwidth of interface ifx * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_IF : invalid interface + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw); @@ -340,8 +407,11 @@ esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw); * @param uint8_t primary : for HT20, primary is the channel number, for HT40, primary is the primary channel * @param wifi_second_chan_t second : for HT20, second is ignored, for HT40, second is the second channel * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_IF : invalid interface + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second); @@ -353,8 +423,10 @@ esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second); * @param uint8_t *primary : store current primary channel * @param wifi_second_chan_t *second : store current second channel * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second); @@ -364,8 +436,11 @@ esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second); * * @param wifi_country_t country : country type * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - others : refer to error code in esp_err.h */ esp_err_t esp_wifi_set_country(wifi_country_t country); @@ -374,8 +449,10 @@ esp_err_t esp_wifi_set_country(wifi_country_t country); * * @param wifi_country_t country : store current country * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_get_country(wifi_country_t *country); @@ -390,8 +467,14 @@ esp_err_t esp_wifi_get_country(wifi_country_t *country); * @param wifi_interface_t ifx : interface * @param uint8 mac[6]: the MAC address. * - * @return true : succeed - * @return false : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_IF : invalid interface + * - ESP_ERR_WIFI_MAC : invalid mac address + * - ESP_ERR_WIFI_MODE : WiFi mode is wrong + * - others : refer to error code in esp_err.h */ esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, uint8_t mac[6]); @@ -400,8 +483,11 @@ esp_err_t esp_wifi_set_mac(wifi_interface_t ifx, uint8_t mac[6]); * * @param uint8_t mac[6] : store mac of this interface ifx * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_IF : invalid interface */ esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]); @@ -413,8 +499,7 @@ esp_err_t esp_wifi_get_mac(wifi_interface_t ifx, uint8_t mac[6]); * @param void *buf : the data received * @param uint16_t len : data length * - * @return ESP_OK : succeed - * @return others : fail + * @return none */ typedef void (* wifi_promiscuous_cb_t)(void *buf, uint16_t len); @@ -425,8 +510,9 @@ typedef void (* wifi_promiscuous_cb_t)(void *buf, uint16_t len); * * @param wifi_promiscuous_cb_t cb : callback * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init */ esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb); @@ -435,8 +521,9 @@ esp_err_t esp_wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb); * * @param bool promiscuous : false - disable / true - enable * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init */ esp_err_t esp_wifi_set_promiscuous(bool en); @@ -445,8 +532,10 @@ esp_err_t esp_wifi_set_promiscuous(bool en); * * @param bool *enable : store the current status of promiscuous mode * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_get_promiscuous(bool *en); @@ -461,8 +550,15 @@ esp_err_t esp_wifi_get_promiscuous(bool *en); * @param wifi_interface_t ifx : interface * @param wifi_config_t *conf : station or soft-AP configuration * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_IF : invalid interface + * - ESP_ERR_WIFI_MODE : invalid mode + * - ESP_ERR_WIFI_PASSWORD : invalid password + * - ESP_ERR_WIFI_NVS : WiFi internal NVS error + * - others : refer to the erro code in esp_err.h */ esp_err_t esp_wifi_set_config(wifi_interface_t ifx, wifi_config_t *conf); @@ -472,8 +568,11 @@ esp_err_t esp_wifi_set_config(wifi_interface_t ifx, wifi_config_t *conf); * @param wifi_interface_t ifx : interface * @param wifi_config_t *conf : station or soft-AP configuration * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_IF : invalid interface */ esp_err_t esp_wifi_get_config(wifi_interface_t ifx, wifi_config_t *conf); @@ -484,8 +583,12 @@ esp_err_t esp_wifi_get_config(wifi_interface_t ifx, wifi_config_t *conf); * * @param wifi_sta_list_t *sta: station list * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_MODE : WiFi mode is wrong + * - ESP_ERR_WIFI_CONN : WiFi internal error, the station/soft-AP control block is invalid */ esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta); @@ -497,42 +600,24 @@ esp_err_t esp_wifi_ap_get_sta_list(wifi_sta_list_t *sta); * * @param wifi_storage_t storage : storage type * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_set_storage(wifi_storage_t storage); -/** - * @brief The WiFi RX callback function - * - * Each time the WiFi need to forward the packets to high layer, the callback function will be called - * - */ -typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb); - -/** - * @brief Set the WiFi RX callback - * - * @attention 1. Currently we support only one RX callback for each interface - * - * @param wifi_interface_t ifx : interface - * @param wifi_rxcb_t fn : WiFi RX callback - * - * @return ESP_OK : succeed - * @return others : fail - */ -esp_err_t esp_wifi_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn); - /** * @brief Set auto connect * The default value is true * - * @attention 1. - * * @param bool en : true - enable auto connect / false - disable auto connect * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_MODE : WiFi internal error, the station/soft-AP control block is invalid + * - others : refer to error code in esp_err.h */ esp_err_t esp_wifi_set_auto_connect(bool en); @@ -541,8 +626,10 @@ esp_err_t esp_wifi_set_auto_connect(bool en); * * @param bool *en : store current auto connect configuration * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument */ esp_err_t esp_wifi_get_auto_connect(bool *en); @@ -559,8 +646,11 @@ esp_err_t esp_wifi_get_auto_connect(bool *en); 1 - WIFI_VND_IE_ID_1 * @param uint8_t *vnd_ie : pointer to a vendor specific element * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG : invalid argument + * - ESP_ERR_WIFI_NO_MEM : out of memory */ esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, uint8_t *vnd_ie); @@ -584,8 +674,9 @@ typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const * @param esp_vendor_ie_cb_t cb : callback function * @param void *ctx : reserved * - * @return ESP_OK : succeed - * @return others : fail + * @return + * - ESP_OK : succeed + * - ESP_ERR_WIFI_NOT_INIT : WiFi is not initialized by eps_wifi_init */ esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx); diff --git a/components/esp32/include/esp_wifi_internal.h b/components/esp32/include/esp_wifi_internal.h index 217d5f6d1..9aa05dc71 100644 --- a/components/esp32/include/esp_wifi_internal.h +++ b/components/esp32/include/esp_wifi_internal.h @@ -71,7 +71,38 @@ void esp_wifi_internal_free_rx_buffer(void* buffer); * @return True : success transmit the buffer to wifi driver * False : failed to transmit the buffer to wifi driver */ -bool esp_wifi_internal_tx(wifi_interface_t wifi_if, void *buffer, u16_t len); +int esp_wifi_internal_tx(wifi_interface_t wifi_if, void *buffer, u16_t len); + +/** + * @brief The WiFi RX callback function + * + * Each time the WiFi need to forward the packets to high layer, the callback function will be called + * + */ +typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb); + +/** + * @brief Set the WiFi RX callback + * + * @attention 1. Currently we support only one RX callback for each interface + * + * @param wifi_interface_t ifx : interface + * @param wifi_rxcb_t fn : WiFi RX callback + * + * @return ESP_OK : succeed + * @return others : fail + */ +esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn); + +/** + * @brief Notify WIFI driver that the station got ip successfully + * + * @param none + * + * @return ESP_OK : succeed + * @return others : fail + */ +esp_err_t esp_wifi_internal_set_sta_ip(void); #ifdef __cplusplus } diff --git a/components/esp32/lib b/components/esp32/lib index 596a82d4e..66236c85b 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit 596a82d4e0122432a51d3ec5a62975db9fd38179 +Subproject commit 66236c85b3ef1a6d756d4e7d58cc6a1180e31365 diff --git a/make/project.mk b/make/project.mk index 67e2e92bd..a60a3958f 100644 --- a/make/project.mk +++ b/make/project.mk @@ -166,7 +166,8 @@ CPPFLAGS := -DESP_PLATFORM $(CPPFLAGS) COMMON_WARNING_FLAGS = -Wall -Werror \ -Wno-error=unused-function \ -Wno-error=unused-but-set-variable \ - -Wno-error=unused-variable + -Wno-error=unused-variable \ + -Wno-error=deprecated-declarations # Flags which control code generation and dependency generation, both for C and C++ COMMON_FLAGS = \ From 8dee0a3f6d5a0bed87ed1da032cd394703e66a83 Mon Sep 17 00:00:00 2001 From: Liu Zhi Fu Date: Tue, 8 Nov 2016 19:19:28 +0800 Subject: [PATCH 2/2] esp32: modify the code according to review comments 1. Adjust error code definition 2. Refractor the comments for esp_wifi_internal_tx --- components/esp32/include/esp_err.h | 1 + components/esp32/include/esp_wifi.h | 21 ++++++++++---------- components/esp32/include/esp_wifi_internal.h | 9 +++++---- components/esp32/lib | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/components/esp32/include/esp_err.h b/components/esp32/include/esp_err.h index dc2c6c2d7..f8271ba25 100644 --- a/components/esp32/include/esp_err.h +++ b/components/esp32/include/esp_err.h @@ -33,6 +33,7 @@ typedef int32_t esp_err_t; #define ESP_ERR_INVALID_STATE 0x103 #define ESP_ERR_INVALID_SIZE 0x104 #define ESP_ERR_NOT_FOUND 0x105 +#define ESP_ERR_NOT_SUPPORTED 0x106 #define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */ diff --git a/components/esp32/include/esp_wifi.h b/components/esp32/include/esp_wifi.h index 8e2c1df55..88ea0d9a6 100644 --- a/components/esp32/include/esp_wifi.h +++ b/components/esp32/include/esp_wifi.h @@ -74,18 +74,19 @@ extern "C" { #define ESP_ERR_WIFI_FAIL ESP_FAIL /*!< General fail code */ #define ESP_ERR_WIFI_NO_MEM ESP_ERR_NO_MEM /*!< Out of memory */ #define ESP_ERR_WIFI_ARG ESP_ERR_INVALID_ARG /*!< Invalid argument */ +#define ESP_ERR_WIFI_NOT_SUPPORT ESP_ERR_NOT_SUPPORTED /*!< Indicates that API is not supported yet */ + #define ESP_ERR_WIFI_NOT_INIT (ESP_ERR_WIFI_BASE + 1) /*!< WiFi driver is not installed by esp_wifi_init */ #define ESP_ERR_WIFI_NOT_START (ESP_ERR_WIFI_BASE + 2) /*!< WiFi driver is not started by esp_wifi_start */ -#define ESP_ERR_WIFI_NOT_SUPPORT (ESP_ERR_WIFI_BASE + 3) /*!< WiFi API doesn't support */ -#define ESP_ERR_WIFI_IF (ESP_ERR_WIFI_BASE + 4) /*!< WiFi interface error */ -#define ESP_ERR_WIFI_MODE (ESP_ERR_WIFI_BASE + 5) /*!< WiFi mode error */ -#define ESP_ERR_WIFI_STATE (ESP_ERR_WIFI_BASE + 6) /*!< WiFi internal state error */ -#define ESP_ERR_WIFI_CONN (ESP_ERR_WIFI_BASE + 7) /*!< WiFi internal control block of station or soft-AP error */ -#define ESP_ERR_WIFI_NVS (ESP_ERR_WIFI_BASE + 8) /*!< WiFi internal NVS module error */ -#define ESP_ERR_WIFI_MAC (ESP_ERR_WIFI_BASE + 9) /*!< MAC address is invalid */ -#define ESP_ERR_WIFI_SSID (ESP_ERR_WIFI_BASE + 10) /*!< SSID is invalid */ -#define ESP_ERR_WIFI_PASSWORD (ESP_ERR_WIFI_BASE + 11) /*!< Passord is invalid */ -#define ESP_ERR_WIFI_TIMEOUT (ESP_ERR_WIFI_BASE + 12) /*!< Timeout error */ +#define ESP_ERR_WIFI_IF (ESP_ERR_WIFI_BASE + 3) /*!< WiFi interface error */ +#define ESP_ERR_WIFI_MODE (ESP_ERR_WIFI_BASE + 4) /*!< WiFi mode error */ +#define ESP_ERR_WIFI_STATE (ESP_ERR_WIFI_BASE + 5) /*!< WiFi internal state error */ +#define ESP_ERR_WIFI_CONN (ESP_ERR_WIFI_BASE + 6) /*!< WiFi internal control block of station or soft-AP error */ +#define ESP_ERR_WIFI_NVS (ESP_ERR_WIFI_BASE + 7) /*!< WiFi internal NVS module error */ +#define ESP_ERR_WIFI_MAC (ESP_ERR_WIFI_BASE + 8) /*!< MAC address is invalid */ +#define ESP_ERR_WIFI_SSID (ESP_ERR_WIFI_BASE + 9) /*!< SSID is invalid */ +#define ESP_ERR_WIFI_PASSWORD (ESP_ERR_WIFI_BASE + 10) /*!< Passord is invalid */ +#define ESP_ERR_WIFI_TIMEOUT (ESP_ERR_WIFI_BASE + 11) /*!< Timeout error */ typedef struct { system_event_handler_t event_handler; /**< WiFi event handler */ diff --git a/components/esp32/include/esp_wifi_internal.h b/components/esp32/include/esp_wifi_internal.h index 9aa05dc71..2015b5063 100644 --- a/components/esp32/include/esp_wifi_internal.h +++ b/components/esp32/include/esp_wifi_internal.h @@ -62,14 +62,15 @@ void esp_wifi_internal_free_rx_buffer(void* buffer); /** * @brief transmit the buffer via wifi driver * - * @attention1 TODO should modify the return type from bool to int - * * @param wifi_interface_t wifi_if : wifi interface id * @param void *buffer : the buffer to be tansmit * @param u16_t len : the length of buffer * - * @return True : success transmit the buffer to wifi driver - * False : failed to transmit the buffer to wifi driver + * @return + * - ERR_OK : Successfully transmit the buffer to wifi driver + * - ERR_MEM : Out of memory + * - ERR_IF : WiFi driver error + * - ERR_ARG : Invalid argument */ int esp_wifi_internal_tx(wifi_interface_t wifi_if, void *buffer, u16_t len); diff --git a/components/esp32/lib b/components/esp32/lib index 66236c85b..76f910980 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit 66236c85b3ef1a6d756d4e7d58cc6a1180e31365 +Subproject commit 76f91098061b0052fe1bb67e85001014f39b84a0