From b99468273675615ef83e8f95a245bc5723c28b2a Mon Sep 17 00:00:00 2001 From: xiehang Date: Mon, 8 Jul 2019 11:26:18 +0800 Subject: [PATCH] WiFi: Modify the wifi_country struct in VNC to keep it consistent with IDF 1. Modfy wifi_country struct 2. Add md5 check esp_wifi_types.h 3. Add md5 check esp_wifi.h --- components/esp32/esp_err_to_name.c | 9 ++ .../include/esp_private/esp_wifi_private.h | 24 +++++ .../esp_private/esp_wifi_types_private.h | 21 +++++ components/esp32/include/esp_wifi.h | 92 ++++--------------- components/esp32/include/esp_wifi_internal.h | 22 +++++ components/esp32/include/esp_wifi_types.h | 5 +- components/esp32/lib | 2 +- components/esp32/test/component.mk | 10 ++ components/esp32/test/test_header_files_md5.c | 24 ++++- 9 files changed, 131 insertions(+), 78 deletions(-) create mode 100644 components/esp32/include/esp_private/esp_wifi_private.h create mode 100644 components/esp32/include/esp_private/esp_wifi_types_private.h diff --git a/components/esp32/esp_err_to_name.c b/components/esp32/esp_err_to_name.c index a6ab5cbc65..2222eb2aa3 100644 --- a/components/esp32/esp_err_to_name.c +++ b/components/esp32/esp_err_to_name.c @@ -282,6 +282,15 @@ static const esp_err_msg_t esp_err_msg_table[] = { # endif # ifdef ESP_ERR_WIFI_NOT_CONNECT ERR_TBL_IT(ESP_ERR_WIFI_NOT_CONNECT), /* 12303 0x300f Station still in disconnect status */ +# endif +# ifdef ESP_ERR_WIFI_POST + ERR_TBL_IT(ESP_ERR_WIFI_POST), /* 12306 0x3012 Failed to post the event to WiFi task */ +# endif +# ifdef ESP_ERR_WIFI_INIT_STATE + ERR_TBL_IT(ESP_ERR_WIFI_INIT_STATE), /* 12307 0x3013 Invalod WiFi state when init/deinit is called */ +# endif +# ifdef ESP_ERR_WIFI_STOP_STATE + ERR_TBL_IT(ESP_ERR_WIFI_STOP_STATE), /* 12308 0x3014 Returned when WiFi is stopping */ # endif // components/esp32/include/esp_wps.h # ifdef ESP_ERR_WIFI_REGISTRAR diff --git a/components/esp32/include/esp_private/esp_wifi_private.h b/components/esp32/include/esp_private/esp_wifi_private.h new file mode 100644 index 0000000000..fcdebb6ba5 --- /dev/null +++ b/components/esp32/include/esp_private/esp_wifi_private.h @@ -0,0 +1,24 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _ESP_WIFI_PRIVATE_H +#define _ESP_WIFI_PRIVATE_H + +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" +#include "rom/queue.h" +#include "sdkconfig.h" +#include "esp_wifi_crypto_types.h" +#include "esp_wifi_os_adapter.h" + +#endif /* _ESP_WIFI_PRIVATE_H */ diff --git a/components/esp32/include/esp_private/esp_wifi_types_private.h b/components/esp32/include/esp_private/esp_wifi_types_private.h new file mode 100644 index 0000000000..dd56e0fdec --- /dev/null +++ b/components/esp32/include/esp_private/esp_wifi_types_private.h @@ -0,0 +1,21 @@ +// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _ESP_WIFI_TYPES_PRIVATE_H +#define _ESP_WIFI_TYPES_PRIVATE_H + +#include "rom/queue.h" +#include "esp_interface.h" + +#endif diff --git a/components/esp32/include/esp_wifi.h b/components/esp32/include/esp_wifi.h index e67f4606bd..57014b8d9a 100644 --- a/components/esp32/include/esp_wifi.h +++ b/components/esp32/include/esp_wifi.h @@ -59,15 +59,10 @@ #include #include -#include "freertos/FreeRTOS.h" -#include "freertos/queue.h" -#include "rom/queue.h" -#include "sdkconfig.h" #include "esp_err.h" #include "esp_wifi_types.h" -#include "esp_wifi_crypto_types.h" #include "esp_event.h" -#include "esp_wifi_os_adapter.h" +#include "esp_private/esp_wifi_private.h" #ifdef __cplusplus extern "C" { @@ -89,6 +84,10 @@ extern "C" { #define ESP_ERR_WIFI_WOULD_BLOCK (ESP_ERR_WIFI_BASE + 14) /*!< The caller would block */ #define ESP_ERR_WIFI_NOT_CONNECT (ESP_ERR_WIFI_BASE + 15) /*!< Station still in disconnect status */ +#define ESP_ERR_WIFI_POST (ESP_ERR_WIFI_BASE + 18) /*!< Failed to post the event to WiFi task */ +#define ESP_ERR_WIFI_INIT_STATE (ESP_ERR_WIFI_BASE + 19) /*!< Invalod WiFi state when init/deinit is called */ +#define ESP_ERR_WIFI_STOP_STATE (ESP_ERR_WIFI_BASE + 20) /*!< Returned when WiFi is stopping */ + /** * @brief WiFi stack configuration parameters passed to esp_wifi_init call. */ @@ -581,7 +580,7 @@ esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second); * and the country info of the AP to which the station is connected is {.cc="JP", .schan=1, .nchan=14} * then the country info that will be used is {.cc="JP", .schan=1, .nchan=14}. If the station disconnected * from the AP the country info is set back back to the country info of the station automatically, - * {.cc="USA", .schan=1, .nchan=11} in the example. + * {.cc="US", .schan=1, .nchan=11} in the example. * @attention 3. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, always use the configured country info. * @attention 4. When the country info is changed because of configuration or because the station connects to a different * external AP, the country IE in probe response/beacon of the soft-AP is changed also. @@ -840,6 +839,16 @@ esp_err_t esp_wifi_set_auto_connect(bool en) __attribute__ ((deprecated)); */ esp_err_t esp_wifi_get_auto_connect(bool *en) __attribute__ ((deprecated)); +/** + * @brief Function signature for received Vendor-Specific Information Element callback. + * @param ctx Context argument, as passed to esp_wifi_set_vendor_ie_cb() when registering callback. + * @param type Information element type, based on frame type received. + * @param sa Source 802.11 address. + * @param vnd_ie Pointer to the vendor specific element data received. + * @param rssi Received signal strength indication. + */ +typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const vendor_ie_data_t *vnd_ie, int rssi); + /** * @brief Set 802.11 Vendor-Specific Information Element * @@ -858,16 +867,6 @@ esp_err_t esp_wifi_get_auto_connect(bool *en) __attribute__ ((deprecated)); */ esp_err_t esp_wifi_set_vendor_ie(bool enable, wifi_vendor_ie_type_t type, wifi_vendor_ie_id_t idx, const void *vnd_ie); -/** - * @brief Function signature for received Vendor-Specific Information Element callback. - * @param ctx Context argument, as passed to esp_wifi_set_vendor_ie_cb() when registering callback. - * @param type Information element type, based on frame type received. - * @param sa Source 802.11 address. - * @param vnd_ie Pointer to the vendor specific element data received. - * @param rssi Received signal strength indication. - */ -typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const uint8_t sa[6], const vendor_ie_data_t *vnd_ie, int rssi); - /** * @brief Register Vendor-Specific Information Element monitoring callback. * @@ -881,60 +880,22 @@ typedef void (*esp_vendor_ie_cb_t) (void *ctx, wifi_vendor_ie_type_t type, const esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx); /** - * @brief Set maximum WiFi transmiting power + * @brief Set maximum WiFi transmitting power * - * @attention WiFi transmiting power is divided to six levels in phy init data. - * Level0 represents highest transmiting power and level5 represents lowest - * transmiting power. Packets of different rates are transmitted in - * different powers according to the configuration in phy init data. - * This API only sets maximum WiFi transmiting power. If this API is called, - * the transmiting power of every packet will be less than or equal to the - * value set by this API. If this API is not called, the value of maximum - * transmitting power set in phy_init_data.bin or menuconfig (depend on - * whether to use phy init data in partition or not) will be used. Default - * value is level0. Values passed in power are mapped to transmit power - * levels as follows: - * - [78, 127]: level0 - * - [76, 77]: level1 - * - [74, 75]: level2 - * - [68, 73]: level3 - * - [60, 67]: level4 - * - [52, 59]: level5 - * - [44, 51]: level5 - 2dBm - * - [34, 43]: level5 - 4.5dBm - * - [28, 33]: level5 - 6dBm - * - [20, 27]: level5 - 8dBm - * - [8, 19]: level5 - 11dBm - * - [-128, 7]: level5 - 14dBm - * - * @param power Maximum WiFi transmiting power. + * @param power Maximum WiFi transmitting power, unit is 0.25dBm, range is [40, 82] corresponding to 10dBm - 20.5dBm here. * * @return * - ESP_OK: succeed * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init * - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start + * - ESP_ERR_WIFI_NOT_ARG: invalid argument */ esp_err_t esp_wifi_set_max_tx_power(int8_t power); /** * @brief Get maximum WiFi transmiting power * - * @attention This API gets maximum WiFi transmiting power. Values got - * from power are mapped to transmit power levels as follows: - * - 78: 19.5dBm - * - 76: 19dBm - * - 74: 18.5dBm - * - 68: 17dBm - * - 60: 15dBm - * - 52: 13dBm - * - 44: 11dBm - * - 34: 8.5dBm - * - 28: 7dBm - * - 20: 5dBm - * - 8: 2dBm - * - -4: -1dBm - * - * @param power Maximum WiFi transmiting power. + * @param power Maximum WiFi transmitting power, unit is 0.25dBm. * * @return * - ESP_OK: succeed @@ -1102,19 +1063,6 @@ esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config); */ esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config); -/** - * @brief A general API to set/get WiFi internal configuration, it's for debug only - * - * @param cmd : ioctl command type - * @param cfg : configuration for the command - * - * @return - * - ESP_OK: succeed - * - others: failed - */ -esp_err_t esp_wifi_internal_ioctl(int cmd, wifi_ioctl_config_t *cfg); - - #ifdef __cplusplus } #endif diff --git a/components/esp32/include/esp_wifi_internal.h b/components/esp32/include/esp_wifi_internal.h index 53f69350de..9309ea0e9f 100644 --- a/components/esp32/include/esp_wifi_internal.h +++ b/components/esp32/include/esp_wifi_internal.h @@ -149,6 +149,28 @@ esp_err_t esp_wifi_internal_osi_funcs_md5_check(const char *md5); */ esp_err_t esp_wifi_internal_crypto_funcs_md5_check(const char *md5); +/** + * @brief Check the MD5 values of the esp_wifi_types.h in IDF and WiFi library + * + * @attention 1. It is used for internal CI version check + * + * @return + * - ESP_OK : succeed + * - ESP_WIFI_INVALID_ARG : MD5 check fail + */ +esp_err_t esp_wifi_internal_wifi_type_md5_check(const char *md5); + +/** + * @brief Check the MD5 values of the esp_wifi.h in IDF and WiFi library + * + * @attention 1. It is used for internal CI version check + * + * @return + * - ESP_OK : succeed + * - ESP_WIFI_INVALID_ARG : MD5 check fail + */ +esp_err_t esp_wifi_internal_esp_wifi_md5_check(const char *md5); + /** * @brief Check the git commit id of WiFi library * diff --git a/components/esp32/include/esp_wifi_types.h b/components/esp32/include/esp_wifi_types.h index f536370497..a27aa51ce2 100644 --- a/components/esp32/include/esp_wifi_types.h +++ b/components/esp32/include/esp_wifi_types.h @@ -18,9 +18,8 @@ #include #include -#include "rom/queue.h" #include "esp_err.h" -#include "esp_interface.h" +#include "esp_private/esp_wifi_types_private.h" #ifdef __cplusplus extern "C" { @@ -49,7 +48,7 @@ typedef struct { char cc[3]; /**< country code string */ uint8_t schan; /**< start channel */ uint8_t nchan; /**< total channel number */ - int8_t max_tx_power; /**< maximum tx power */ + int8_t max_tx_power; /**< This field is used for getting WiFi maximum transmitting power, call esp_wifi_set_max_tx_power to set the maximum transmitting power. */ wifi_country_policy_t policy; /**< country policy */ } wifi_country_t; diff --git a/components/esp32/lib b/components/esp32/lib index 0a9c853930..4590b95ba6 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit 0a9c853930e5371ce703b8fcff22094992c598c8 +Subproject commit 4590b95ba646daa52882de1b27ee923d0da52ef7 diff --git a/components/esp32/test/component.mk b/components/esp32/test/component.mk index 592b9b9048..9c2a973d98 100644 --- a/components/esp32/test/component.mk +++ b/components/esp32/test/component.mk @@ -17,6 +17,16 @@ WIFI_CRYPTO_MD5_VAL=\"$(shell md5sum $(IDF_PATH)/components/esp32/include/esp_wi CFLAGS+=-DWIFI_CRYPTO_MD5=$(WIFI_CRYPTO_MD5_VAL) +# Calculate MD5 value of header file esp_wifi_types.h +WIFI_TYPE_MD5_VAL=\"$(shell md5sum $(IDF_PATH)/components/esp32/include/esp_wifi_types.h | cut -c 1-7)\" +CFLAGS+=-DWIFI_TYPE_MD5=$(WIFI_TYPE_MD5_VAL) + + +# Calculate MD5 value of header file esp_wifi.h +WIFI_ESP_WIFI_MD5_VAL=\"$(shell md5sum $(IDF_PATH)/components/esp32/include/esp_wifi.h | cut -c 1-7)\" +CFLAGS+=-DWIFI_ESP_WIFI_MD5=$(WIFI_ESP_WIFI_MD5_VAL) + + test_tjpgd.o: test_tjpgd_logo.h test_tjpgd_logo.h: $(COMPONENT_PATH)/logo.jpg diff --git a/components/esp32/test/test_header_files_md5.c b/components/esp32/test/test_header_files_md5.c index 009de0ea59..c93c682d2b 100644 --- a/components/esp32/test/test_header_files_md5.c +++ b/components/esp32/test/test_header_files_md5.c @@ -11,7 +11,7 @@ TEST_CASE("wifi os adapter MD5","[wifi]") { const char *test_wifi_os_funcs_md5 = WIFI_OS_ADAPTER_MD5; - ESP_LOGI(TAG, "test wifi os adapter MD5..."); + ESP_LOGI(TAG, "test eps_wifi_os_adapter.h MD5..."); TEST_ESP_OK(esp_wifi_internal_osi_funcs_md5_check(test_wifi_os_funcs_md5)); ESP_LOGI(TAG, "test passed..."); @@ -21,8 +21,28 @@ TEST_CASE("wifi crypto types MD5","[wifi]") { const char *test_wifi_crypto_funcs_md5 = WIFI_CRYPTO_MD5; - ESP_LOGI(TAG, "test wifi crypto adapter MD5..."); + ESP_LOGI(TAG, "test esp_wifi_crypto_adapter.h MD5..."); TEST_ESP_OK(esp_wifi_internal_crypto_funcs_md5_check(test_wifi_crypto_funcs_md5)); ESP_LOGI(TAG, "test passed..."); } + +TEST_CASE("wifi type MD5","[wifi]") +{ + const char *test_wifi_type_md5 = WIFI_TYPE_MD5; + + ESP_LOGI(TAG, "test esp_wifi_types.h MD5..."); + TEST_ESP_OK(esp_wifi_internal_wifi_type_md5_check(test_wifi_type_md5)); + + ESP_LOGI(TAG, "test passed..."); +} + +TEST_CASE("esp wifi MD5","[wifi]") +{ + const char *test_esp_wifi_md5 = WIFI_ESP_WIFI_MD5; + + ESP_LOGI(TAG, "test esp_wifi.h MD5..."); + TEST_ESP_OK(esp_wifi_internal_esp_wifi_md5_check(test_esp_wifi_md5)); + + ESP_LOGI(TAG, "test passed..."); +}