Merge branch 'bugfix/fix_set_country_code_before_wifi_start_issue' into 'master'

esp_wifi: fix set country code before wifi start issue.

Closes IDFGH-8011

See merge request espressif/esp-idf!19631
pull/9721/head
Mu Hai Dong 2022-09-05 12:17:11 +08:00
commit 681c538d77
5 zmienionych plików z 135 dodań i 41 usunięć

Wyświetl plik

@ -613,18 +613,19 @@ esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second);
* @attention 1. It is discouraged to call this API since this doesn't validate the per-country rules,
* it's up to the user to fill in all fields according to local regulations.
* Please use esp_wifi_set_country_code instead.
* @attention 2. The default country is CHINA {.cc="CN", .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO}
* @attention 3. When the country policy is WIFI_COUNTRY_POLICY_AUTO, the country info of the AP to which
* the station is connected is used. E.g. if the configured country info is {.cc="USA", .schan=1, .nchan=11}
* @attention 2. The default country is "01" (world safe mode) {.cc="01", .schan=1, .nchan=11, .policy=WIFI_COUNTRY_POLICY_AUTO}.
* @attention 3. The third octect of country code string is one of the following: ' ', 'O', 'I', 'X', otherwise it is considered as ' '.
* @attention 4. When the country policy is WIFI_COUNTRY_POLICY_AUTO, the country info of the AP to which
* the station is connected is used. E.g. if the configured country info is {.cc="US", .schan=1, .nchan=11}
* 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 to the country info of the station automatically,
* {.cc="US", .schan=1, .nchan=11} in the example.
* @attention 4. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, then the configured country info is used always.
* @attention 5. When the country info is changed because of configuration or because the station connects to a different
* @attention 5. When the country policy is WIFI_COUNTRY_POLICY_MANUAL, then the configured country info is used always.
* @attention 6. 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 also changed.
* @attention 6. The country configuration is stored into flash.
* @attention 7. When this API is called, the PHY init data will switch to the PHY init data type corresponding to the
* @attention 7. The country configuration is stored into flash.
* @attention 8. When this API is called, the PHY init data will switch to the PHY init data type corresponding to the
* country info.
*
* @param country the configured country info
@ -632,7 +633,6 @@ esp_err_t esp_wifi_get_channel(uint8_t *primary, wifi_second_chan_t *second);
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
* - ESP_ERR_INVALID_ARG: invalid argument
*/
esp_err_t esp_wifi_set_country(const wifi_country_t *country);
@ -1259,6 +1259,7 @@ esp_err_t esp_wifi_connectionless_module_set_wake_interval(uint16_t wake_interva
*
* @attention 7. When country code "01" (world safe mode) is set, SoftAP mode won't contain country IE.
* @attention 8. The default country is "01" (world safe mode) and ieee80211d_enabled is TRUE.
* @attention 9. The third octect of country code string is one of the following: ' ', 'O', 'I', 'X', otherwise it is considered as ' '.
*
* @param country the configured country ISO code
* @param ieee80211d_enabled 802.11d is enabled or not
@ -1266,7 +1267,6 @@ esp_err_t esp_wifi_connectionless_module_set_wake_interval(uint16_t wake_interva
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
* - ESP_ERR_INVALID_ARG: invalid argument
*/
esp_err_t esp_wifi_set_country_code(const char *country, bool ieee80211d_enabled);

@ -1 +1 @@
Subproject commit d72c8525a79d36214531ea3dc6df98ed849bbdf0
Subproject commit 4a6d15c134f162876951e068fd706a54563b6d9c

Wyświetl plik

@ -279,4 +279,109 @@ TEST_CASE("Calling esp_wifi_deinit() without stop", "[wifi_init]")
unity_utils_task_delete(th);
}
static void wifi_country_code_task(void* arg)
{
SemaphoreHandle_t *sema = (SemaphoreHandle_t *) arg;
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_erase"));
nvs_flash_erase();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
esp_err_t r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or NFS version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
//init tcpip stack
test_case_uses_tcpip();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
wifi_country_t country;
wifi_country_t country_01 = {.cc="01", .schan=1, .nchan=11, .policy=WIFI_COUNTRY_POLICY_MANUAL};
wifi_country_t country_CN = {.cc="CN", .schan=1, .nchan=13, .policy=WIFI_COUNTRY_POLICY_MANUAL};
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country"));
TEST_ESP_OK(esp_wifi_get_country(&country));
TEST_ASSERT(country.cc[0] == country_01.cc[0] && country.cc[1] == country_01.cc[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_country"));
TEST_ESP_OK(esp_wifi_set_country(&country_CN));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country"));
TEST_ESP_OK(esp_wifi_get_country(&country));
TEST_ASSERT(country.cc[0] == country_CN.cc[0] && country.cc[1] == country_CN.cc[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
nvs_flash_deinit();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_erase"));
nvs_flash_erase();
ESP_LOGI(TAG, EMPH_STR("nvs_flash_init"));
r = nvs_flash_init();
if (r == ESP_ERR_NVS_NO_FREE_PAGES || r == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_LOGI(TAG, EMPH_STR("no free pages or NFS version mismatch, erase.."));
TEST_ESP_OK(nvs_flash_erase());
r = nvs_flash_init();
}
TEST_ESP_OK(r);
//init tcpip stack
test_case_uses_tcpip();
ESP_LOGI(TAG, EMPH_STR("event_init"));
TEST_ESP_OK(event_init());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(&cfg));
char country_code_string[3];
char country_code_string_01[3] = "01";
char country_code_string_CN[3] = "CN";
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country_code"));
TEST_ESP_OK(esp_wifi_get_country_code(&country_code_string[0]));
TEST_ASSERT(country_code_string[0] == country_code_string_01[0] && country_code_string[1] == country_code_string_01[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_country_code"));
TEST_ESP_OK(esp_wifi_set_country_code(&country_code_string_CN[0], false));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_country_code"));
TEST_ESP_OK(esp_wifi_get_country_code(&country_code_string[0]));
TEST_ASSERT(country_code_string[0] == country_code_string_CN[0] && country_code_string[1] == country_code_string_CN[1]);
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_OK(esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("event_deinit"));
TEST_ESP_OK(event_deinit());
ESP_LOGI(TAG, EMPH_STR("nvs_flash_deinit..."));
nvs_flash_deinit();
ESP_LOGI(TAG, "test passed...");
xSemaphoreGive(*sema);
vTaskSuspend(NULL);
}
TEST_CASE("wifi set country code", "[wifi_init]")
{
TaskHandle_t th = NULL;
SemaphoreHandle_t sema = xSemaphoreCreateBinary();
TEST_ASSERT_NOT_NULL(sema);
printf("Creating tasks\n");
#ifndef CONFIG_FREERTOS_UNICORE
xTaskCreatePinnedToCore(wifi_country_code_task, "wifi_country_code_task", 2048*2, &sema, 3, &th, 0);
#else
xTaskCreate(wifi_country_code_task, "wifi_country_code_task", 2048*2, &sema, 3, &th);
#endif
TEST_ASSERT_NOT_NULL(th);
xSemaphoreTake(sema, portMAX_DELAY);
vSemaphoreDelete(sema);
sema = NULL;
unity_utils_task_delete(th);
}
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)

Wyświetl plik

@ -1365,13 +1365,7 @@ The following table depicts which country info is used in different Wi-Fi modes
For scan:
- If schan+nchan-1 >11 :
Use active scan from schan to 11 and use passive scan from 12 to 14.
- If schan+nchan-1 <= 11 :
Use active scan from schan to schan+nchan-1 and use passive scan from schan+nchan to 14.
Use active scan from 1 to 11 and use passive scan from 12 to 14.
Always keep in mind that if an AP with hidden SSID and station is set to a passive scan channel, the passive scan will not find it. In other words, if the application hopes to find the AP with hidden SSID in every channel, the policy of country info should be configured to WIFI_COUNTRY_POLICY_MANUAL.
@ -1381,24 +1375,25 @@ The following table depicts which country info is used in different Wi-Fi modes
For scan:
- If schan+nchan-1 >11 :
Use active scan from schan to 11 and use passive scan from 12 to schan+nchan-1.
- If schan+nchan-1 <= 11 :
Use active scan from schan to schan+nchan-1.
* - AP
- WIFI_COUNTRY_POLICY_AUTO
- Always use the configured country info.
* - AP
- WIFI_COUNTRY_POLICY_MANUAL
- Always use the configured country info.
* - Station/AP-coexistence
- WIFI_COUNTRY_POLICY_AUTO
- If the station does not connect to any external AP, the AP uses the configured country info. If the station connects to an external AP, the AP has the same country info as the station.
- Station: Same as station mode with policy WIFI_COUNTRY_POLICY_AUTO.
AP: If the station does not connect to any external AP, the AP uses the configured country info. If the station connects to an external AP, the AP has the same country info as the station.
Same as station mode with policy WIFI_COUNTRY_POLICY_AUTO.
* - Station/AP-coexistence
- WIFI_COUNTRY_POLICY_MANUAL
- Station: Same as station mode with policy WIFI_COUNTRY_POLICY_MANUAL.
AP: Same as AP mode with policy WIFI_COUNTRY_POLICY_MANUAL.
Home Channel

Wyświetl plik

@ -1365,13 +1365,7 @@ Wi-Fi 国家/地区代码
扫描时:
- 如果 schan+nchan-1>11
主动扫描起始信道至信道 11被动扫描信道 12 至 信道 14。
- 如果 schan+nchan-1<=11
主动扫描起始信道至信道 schan+nchan-1被动扫描信道 schan+nchan 至 信道 14。
主动扫描信道 1 至信道 11被动扫描信道 12 至 信道 14。
请记住,如果带有隐藏 SSID 的 AP 和 station 被设置在被动扫描信道上,被动扫描将无法找到该 AP。也就是说如果应用程序希望在每个信道中找到带有隐藏 SSID 的 AP国家/地区信息应该配置为 WIFI_COUNTRY_POLICY_MANUAL。
@ -1381,25 +1375,25 @@ Wi-Fi 国家/地区代码
扫描时:
- 如果 schan+nchan-1>11
主动扫描信道 schan 至信道 schan+nchan-1。
主动扫描起始信道至信道 11被动扫描信道 12 至 信道 schan+nchan-1。
- 如果 schan+nchan-1<=11
主动扫描起始信道至信道 schan+nchan-1。
* - AP 模式
- WIFI_COUNTRY_POLICY_AUTO
- 总是使用配置的国家/地区信息。
* - AP 模式
- WIFI_COUNTRY_POLICY_MANUAL
- 总是使用配置的国家/地区信息。
* - station/AP 共存模式
- WIFI_COUNTRY_POLICY_AUTO
- 如果 station 不连接任何外部 APAP 使用配置的国家/地区信息。如果 station 连接一个外部 AP该 AP 的国家/地区信息与该 station 相同。
与 station 模式、WIFI_COUNTRY_POLICY_AUTO 策略下使用的国家/地区信息相同。
- 该 station 与 station 模式、WIFI_COUNTRY_POLICY_AUTO 策略下使用的国家/地区信息相同。
如果 station 不连接任何外部 APAP 使用配置的国家/地区信息。如果 station 连接一个外部 AP该 AP 的国家/地区信息与该 station 相同。
* - station/AP 共存模式
- WIFI_COUNTRY_POLICY_MANUAL
- 该 station 与 station 模式、WIFI_COUNTRY_POLICY_MANUAL 策略下使用的国家/地区信息相同。
该 AP 与 AP 模式、WIFI_COUNTRY_POLICY_MANUAL 策略下使用的国家/地区信息相同。
主信道
*************************