mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 18:57:19 +02:00
Merge branch 'bugfix/fix_set_country_code_before_wifi_start_issue_v4.4' into 'release/v4.4'
Bugfix/fix set country code before wifi start issue v4.4(Backport v4.4) See merge request espressif/esp-idf!20095
This commit is contained in:
@ -600,18 +600,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 CHINA {.cc="CN", .schan=1, .nchan=13, .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
|
||||
@ -909,7 +910,7 @@ esp_err_t esp_wifi_set_vendor_ie_cb(esp_vendor_ie_cb_t cb, void *ctx);
|
||||
* @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_STARTED: WiFi is not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument, e.g. parameter is out of range
|
||||
*/
|
||||
esp_err_t esp_wifi_set_max_tx_power(int8_t power);
|
||||
@ -922,7 +923,7 @@ esp_err_t esp_wifi_set_max_tx_power(int8_t power);
|
||||
* @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_STARTED: WiFi is not started by esp_wifi_start
|
||||
* - ESP_ERR_WIFI_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_get_max_tx_power(int8_t *power);
|
||||
@ -1018,7 +1019,7 @@ esp_err_t esp_wifi_set_csi_rx_cb(wifi_csi_cb_t cb, void *ctx);
|
||||
* 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 or promiscuous mode is not enabled
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_set_csi_config(const wifi_csi_config_t *config);
|
||||
@ -1031,7 +1032,7 @@ esp_err_t esp_wifi_set_csi_config(const wifi_csi_config_t *config);
|
||||
* 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 or promiscuous mode is not enabled
|
||||
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
|
||||
* - ESP_ERR_INVALID_ARG: invalid argument
|
||||
*/
|
||||
esp_err_t esp_wifi_set_csi(bool en);
|
||||
@ -1244,6 +1245,7 @@ esp_err_t esp_wifi_set_connectionless_wake_interval(uint16_t interval);
|
||||
*
|
||||
* @attention 7. When country code "01" (world safe mode) is set, SoftAP mode won't contain country IE.
|
||||
* @attention 8. The default country is "CN" 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
|
||||
|
Submodule components/esp_wifi/lib updated: a7d80f7e4e...e00ab6536d
@ -273,3 +273,109 @@ TEST_CASE("Calling esp_wifi_deinit() without stop", "[wifi_init]")
|
||||
sema = NULL;
|
||||
test_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_CN.cc[0] && country.cc[1] == country_CN.cc[1]);
|
||||
|
||||
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_country"));
|
||||
TEST_ESP_OK(esp_wifi_set_country(&country_01));
|
||||
|
||||
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_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_CN[0] && country_code_string[1] == country_code_string_CN[1]);
|
||||
|
||||
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_country_code"));
|
||||
TEST_ESP_OK(esp_wifi_set_country_code(&country_code_string_01[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_01[0] && country_code_string[1] == country_code_string_01[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;
|
||||
test_utils_task_delete(th);
|
||||
}
|
||||
|
@ -1301,98 +1301,111 @@ When to Use LR
|
||||
|
||||
The general conditions for using LR are:
|
||||
|
||||
- Both the AP and station are devices.
|
||||
- Both the AP and station are Espressif devices.
|
||||
- Long distance Wi-Fi connection and data transmission is required.
|
||||
- Data throughput requirements are very small, such as remote device control, etc.
|
||||
|
||||
Wi-Fi Country Code
|
||||
+++++++++++++++++++++++++
|
||||
|
||||
Call :cpp:func:`esp_wifi_set_country()` to set the country info.
|
||||
The table below describes the fields in detail, please consult local 2.4 GHz RF operating regulations before configuring these fields.
|
||||
Call :cpp:func:`esp_wifi_set_country()` to set the country info. The table below describes the fields in detail. Please consult local 2.4 GHz RF operating regulations before configuring these fields.
|
||||
|
||||
+------------------+-----------------------------------------------------------------------------------+
|
||||
| Field | Description |
|
||||
+==================+===================================================================================+
|
||||
| cc[3] | Country code string, this attributes identify the country or noncountry entity |
|
||||
| | in which the station/AP is operating. If it's a country, the first two |
|
||||
| | octets of this string is the two character country info as described in document |
|
||||
| | ISO/IEC3166-1. The third octect is one of the following: |
|
||||
| | |
|
||||
| | - an ASCII space character, if the regulations under which the station/AP is |
|
||||
| | operating encompass all environments for the current frequency band in the |
|
||||
| | country. |
|
||||
| | - an ASCII 'O' character if the regulations under which the station/AP is |
|
||||
| | operating are for an outdoor environment only. |
|
||||
| | - an ASCII 'I' character if the regulations under which the station/AP is |
|
||||
| | operating are for an indoor environment only. |
|
||||
| | - an ASCII 'X' character if the station/AP is operating under a noncountry |
|
||||
| | entity. The first two octets of the noncountry entity is two ASCII 'XX' |
|
||||
| | characters. |
|
||||
| | - the binary representation of the Operating Class table number currently in use.|
|
||||
| | Refer to Annex E, IEEE Std 802.11-2012. |
|
||||
| | |
|
||||
+------------------+-----------------------------------------------------------------------------------+
|
||||
| schan | Start channel, it's the minimum channel number of the regulations under which the |
|
||||
| | station/AP can operate. |
|
||||
| | |
|
||||
+------------------+-----------------------------------------------------------------------------------+
|
||||
| nchan | Total number of channels as per the regulations, e.g. if the schan=1, nchan=13, |
|
||||
| | it means the station/AP can send data from channel 1 to 13. |
|
||||
| | |
|
||||
+------------------+-----------------------------------------------------------------------------------+
|
||||
| policy | Country policy, this field control which country info will be used if the |
|
||||
| | configured country info is conflict with the connected AP's. More description |
|
||||
| | about policy is provided in following section. |
|
||||
| | |
|
||||
+------------------+-----------------------------------------------------------------------------------+
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 15 55
|
||||
|
||||
The default country info is {.cc="CN", .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO}, if the Wi-Fi Mode is station/AP coexist mode, they share the same configured country info. Sometimes, the country info of AP, to which the station is connected, is different from the country info of configured. For example, the configured station has country info {.cc="JP", .schan=1, .nchan=14, policy=WIFI_COUNTRY_POLICY_AUTO}, but the connected AP has country info {.cc="CN", .schan=1, .nchan=13}, then country info of connected AP's is used.
|
||||
Following table depicts which country info is used in different Wi-Fi Mode and different country policy, also describe the impact to active scan.
|
||||
* - Field
|
||||
- Description
|
||||
* - cc[3]
|
||||
- Country code string. This attribute identifies the country or noncountry entity in which the station/AP is operating. If it is a country, the first two octets of this string is the two-character country info as described in the document ISO/IEC3166-1. The third octect is one of the following:
|
||||
|
||||
- an ASCII space character, which means the regulations under which the station/AP is operating encompass all environments for the current frequency band in the country.
|
||||
- an ASCII ‘O’ character, which means the regulations under which the station/AP is operating are for an outdoor environment only.
|
||||
- an ASCII ‘I’ character, which means the regulations under which the station/AP is operating are for an indoor environment only.
|
||||
- an ASCII ‘X’ character, which means the station/AP is operating under a noncountry entity. The first two octets of the noncountry entity is two ASCII ‘XX’ characters.
|
||||
- the binary representation of the Operating Class table number currently in use. Refer to Annex E of IEEE Std 802.11-2020.
|
||||
|
||||
* - schan
|
||||
- Start channel. It is the minimum channel number of the regulations under which the station/AP can operate.
|
||||
* - nchan
|
||||
- Total number of channels as per the regulations. For example, if the schan=1, nchan=13, then the station/AP can send data from channel 1 to 13.
|
||||
* - policy
|
||||
- Country policy. This field controls which country info will be used if the configured country info is in conflict with the connected AP’s. For more details on related policies, see the following section.
|
||||
|
||||
|
||||
The default country info is::
|
||||
|
||||
wifi_country_t config = {
|
||||
.cc = "CN",
|
||||
.schan = 1,
|
||||
.nchan = 13,
|
||||
.policy = WIFI_COUNTRY_POLICY_AUTO,
|
||||
};
|
||||
|
||||
If the Wi-Fi Mode is station/AP coexist mode, they share the same configured country info. Sometimes, the country info of AP, to which the station is connected, is different from the country info of configured. For example, the configured station has country info::
|
||||
|
||||
wifi_country_t config = {
|
||||
.cc = "JP",
|
||||
.schan = 1,
|
||||
.nchan = 14,
|
||||
.policy = WIFI_COUNTRY_POLICY_AUTO,
|
||||
};
|
||||
|
||||
but the connected AP has country info::
|
||||
|
||||
wifi_country_t config = {
|
||||
.cc = "CN",
|
||||
.schan = 1,
|
||||
.nchan = 13,
|
||||
};
|
||||
|
||||
then country info of connected AP's is used.
|
||||
|
||||
The following table depicts which country info is used in different Wi-Fi modes and different country policies, and it also describes the impact on active scan.
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 15 15 35
|
||||
|
||||
* - Wi-Fi Mode
|
||||
- Policy
|
||||
- Description
|
||||
* - Station
|
||||
- WIFI_COUNTRY_POLICY_AUTO
|
||||
- If the connected AP has country IE in its beacon, the country info equals to the country info in beacon. Otherwise, use the default country info.
|
||||
|
||||
For scan:
|
||||
|
||||
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.
|
||||
|
||||
* - Station
|
||||
- WIFI_COUNTRY_POLICY_MANUAL
|
||||
- Always use the configured country info.
|
||||
|
||||
For scan:
|
||||
|
||||
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
|
||||
- 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.
|
||||
|
||||
* - 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.
|
||||
|
||||
+-----------+----------------------------+----------------------------------------------------------------+
|
||||
| WiFi Mode | Policy | Description |
|
||||
+===========+============================+================================================================+
|
||||
| Station | WIFI_COUNTRY_POLICY_AUTO | If the connected AP has country IE in its beacon, the country |
|
||||
| | | info equals to the country info in beacon, otherwise, use |
|
||||
| | | default country info. |
|
||||
| | | |
|
||||
| | | 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. |
|
||||
| | | |
|
||||
| | | Always keep in mind that if an AP with hidden SSID |
|
||||
| | | 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. |
|
||||
| | | |
|
||||
+-----------+----------------------------+----------------------------------------------------------------+
|
||||
| Station | WIFI_COUNTRY_POLICY_MANUAL | Always use the configured country info. |
|
||||
| | | |
|
||||
| | | For scan, scans channel "schan" to "schan+nchan-1" with active |
|
||||
| | | scan. |
|
||||
| | | |
|
||||
+-----------+----------------------------+----------------------------------------------------------------+
|
||||
| AP | WIFI_COUNTRY_POLICY_AUTO | Always use the configured country info. |
|
||||
| | | |
|
||||
+-----------+----------------------------+----------------------------------------------------------------+
|
||||
| AP | WIFI_COUNTRY_POLICY_MANUAL | Always use the configured country info. |
|
||||
| | | |
|
||||
+-----------+----------------------------+----------------------------------------------------------------+
|
||||
|Station/AP-| WIFI_COUNTRY_POLICY_AUTO | If the station doesn't connects to any AP, the AP use the |
|
||||
| | | configured country info. |
|
||||
|coexistence| | If the station connects to an AP, the AP has the same |
|
||||
| | | country info as the station. |
|
||||
| | | |
|
||||
| | | Same as station mode with policy WIFI_COUNTRY_POLICY_AUTO. |
|
||||
+-----------+----------------------------+----------------------------------------------------------------+
|
||||
|
||||
Home Channel
|
||||
*************************
|
||||
|
@ -1189,7 +1189,7 @@ LR 吞吐量
|
||||
|
||||
通常使用 LR 的场景包括:
|
||||
|
||||
- AP 和 station 都是设备。
|
||||
- AP 和 station 都是乐鑫设备。
|
||||
- 需要长距离 Wi-Fi 连接和数据传输。
|
||||
- 数据吞吐量要求非常小,例如远程设备控制等。
|
||||
|
||||
@ -1198,65 +1198,102 @@ Wi-Fi 国家/地区代码
|
||||
|
||||
调用 :cpp:func:`esp_wifi_set_country()`,设置国家/地区信息。下表详细介绍了各个字段,请在配置这些字段之前参考当地的 2.4 GHz RF 操作规定。
|
||||
|
||||
+--------+----------------------------------------------------------------------------------------------------------------+
|
||||
| 字段 | 描述 |
|
||||
+--------+----------------------------------------------------------------------------------------------------------------+
|
||||
| cc[3] | 国家/地区代码字符串,此属性标识 station/AP |
|
||||
| | 位于的国家/地区或非国家/地区实体。如果是一个国家/地区,该字符串的前两个八位字节是 |
|
||||
| | ISO/IEC3166-1 中规定的国家/地区两位字母代码。第三个八位字节应是下述之一: |
|
||||
| | |
|
||||
| | -ASCII 码空格字符,代表 station/AP 所处国家/地区的规定允许当前频段所需的所有环境。 |
|
||||
| | |
|
||||
| | -ASCII 码 'O' 字符,代表 station/AP 所处国家/地区的规定仅允许室外环境。 |
|
||||
| | |
|
||||
| | -ASCII 码 'I' 字符,代表 station/AP 所处国家/地区的规定仅允许室内环境。 |
|
||||
| | |
|
||||
| | -ASCII 码 'X' 字符,代表 station/AP 位于非国家/地区实体。非国家实体的前两个八位字节是两个ASCII 码 'XX' 字符。 |
|
||||
| | |
|
||||
| | -当前使用的操作类表编号的二进制形式。见 IEEE Std 802.11-2012 附件 E。 |
|
||||
+--------+----------------------------------------------------------------------------------------------------------------+
|
||||
| schan | 起始信道,station/AP 所处国家/地区规定的最小信道数。 |
|
||||
+--------+----------------------------------------------------------------------------------------------------------------+
|
||||
| nchan | 规定的总信道数,比如,如果 schan=1,nchan=13,那么 station/AP 可以从信道 1 至 13 发送数据。 |
|
||||
+--------+----------------------------------------------------------------------------------------------------------------+
|
||||
| policy | 国家/地区政策,当配置的国家/地区信息与所连 AP |
|
||||
| | 的国家/地区信息冲突时,该字段决定使用哪一信息。更多政策相关信息,可参见下文。 |
|
||||
+--------+----------------------------------------------------------------------------------------------------------------+
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 15 55
|
||||
|
||||
默认国家/地区信息为 {.cc="CN", .schan=1, .nchan=13, policy=WIFI_COUNTRY_POLICY_AUTO},如果 Wi-Fi 模式为 AP-STA 共存模式,则它们配置的国家/地区信息相同。有时,station 所连 AP 的国家/地区信息与配置的不同。例如,配置的 station 国家/地区信息为 {.cc="JP", .schan=1, .nchan=14, policy=WIFI_COUNTRY_POLICY_AUTO},但所连 AP 的国家/地区信息为 {.cc="CN", .schan=1, .nchan=13},此时,使用 AP 的国家/地区信息。
|
||||
下表描述了在不同 Wi-Fi 模式和不同国家/地区政策下使用的国家/地区信息,并描述了对主动扫描的影响。
|
||||
* - 字段
|
||||
- 描述
|
||||
* - cc[3]
|
||||
- 国家/地区代码字符串,此属性标识 station/AP 位于的国家/地区或非国家/地区实体。如果是一个国家/地区,该字符串的前两个八位字节是 ISO/IEC3166-1 中规定的国家/地区两位字母代码。第三个八位字节应是下述之一:
|
||||
|
||||
- ASCII 码空格字符,代表 station/AP 所处国家/地区的规定允许当前频段所需的所有环境。
|
||||
- ASCII 码 ‘O’ 字符,代表 station/AP 所处国家/地区的规定仅允许室外环境。
|
||||
- ASCII 码 ‘I’ 字符,代表 station/AP 所处国家/地区的规定仅允许室内环境。
|
||||
- ASCII 码 ‘X’ 字符,代表 station/AP 位于非国家/地区实体。非国家实体的前两个八位字节是两个 ASCII 码 ‘XX’ 字符。
|
||||
- 当前使用的操作类表编号的二进制形式。见 IEEE Std 802.11-2020 附件 E。
|
||||
|
||||
* - schan
|
||||
- 起始信道,station/AP 所处国家/地区规定的最小信道值。
|
||||
* - nchan
|
||||
- 规定的总信道数,比如,如果 schan=1,nchan=13,那么 station/AP 可以从信道 1 至 13 发送数据。
|
||||
* - policy
|
||||
- 国家/地区策略,当配置的国家/地区信息与所连 AP 的国家/地区信息冲突时,该字段决定使用哪一信息。更多策略相关信息,可参见下文。
|
||||
|
||||
|
||||
默认国家/地区信息为::
|
||||
|
||||
wifi_country_t config = {
|
||||
.cc = "CN",
|
||||
.schan = 1,
|
||||
.nchan = 13,
|
||||
.policy = WIFI_COUNTRY_POLICY_AUTO,
|
||||
};
|
||||
|
||||
如果 Wi-Fi 模式为 station/AP 共存模式,则它们配置的国家/地区信息相同。有时,station 所连 AP 的国家/地区信息与配置的不同。例如,配置的 station 国家/地区信息为::
|
||||
|
||||
wifi_country_t config = {
|
||||
.cc = "JP",
|
||||
.schan = 1,
|
||||
.nchan = 14,
|
||||
.policy = WIFI_COUNTRY_POLICY_AUTO,
|
||||
};
|
||||
|
||||
但所连 AP 的国家/地区信息为::
|
||||
|
||||
wifi_country_t config = {
|
||||
.cc = "CN",
|
||||
.schan = 1,
|
||||
.nchan = 13,
|
||||
};
|
||||
|
||||
此时,使用所连 AP 的国家/地区信息。
|
||||
|
||||
下表描述了在不同 Wi-Fi 模式和不同国家/地区策略下使用的国家/地区信息,并描述了对主动扫描的影响。
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
:widths: 15 15 35
|
||||
|
||||
* - Wi-Fi 模式
|
||||
- 策略
|
||||
- 描述
|
||||
* - station 模式
|
||||
- WIFI_COUNTRY_POLICY_AUTO
|
||||
- 如果所连 AP 的 beacon 中有国家/地区的 IE,使用的国家/地区信息为 beacon 中的信息,否则,使用默认信息。
|
||||
|
||||
扫描时:
|
||||
|
||||
主动扫描信道 1 至信道 11,被动扫描信道 12 至 信道 14。
|
||||
|
||||
请记住,如果带有隐藏 SSID 的 AP 和 station 被设置在被动扫描信道上,被动扫描将无法找到该 AP。也就是说,如果应用程序希望在每个信道中找到带有隐藏 SSID 的 AP,国家/地区信息应该配置为 WIFI_COUNTRY_POLICY_MANUAL。
|
||||
|
||||
* - station 模式
|
||||
- WIFI_COUNTRY_POLICY_MANUAL
|
||||
- 总是使用配置的国家/地区信息。
|
||||
|
||||
扫描时:
|
||||
|
||||
主动扫描信道 schan 至信道 schan+nchan-1。
|
||||
|
||||
* - AP 模式
|
||||
- WIFI_COUNTRY_POLICY_AUTO
|
||||
- 总是使用配置的国家/地区信息。
|
||||
|
||||
* - AP 模式
|
||||
- WIFI_COUNTRY_POLICY_MANUAL
|
||||
- 总是使用配置的国家/地区信息。
|
||||
|
||||
* - station/AP 共存模式
|
||||
- WIFI_COUNTRY_POLICY_AUTO
|
||||
- 该 station 与 station 模式、WIFI_COUNTRY_POLICY_AUTO 策略下使用的国家/地区信息相同。
|
||||
如果 station 不连接任何外部 AP,AP 使用配置的国家/地区信息。如果 station 连接一个外部 AP,该 AP 的国家/地区信息与该 station 相同。
|
||||
|
||||
* - station/AP 共存模式
|
||||
- WIFI_COUNTRY_POLICY_MANUAL
|
||||
- 该 station 与 station 模式、WIFI_COUNTRY_POLICY_MANUAL 策略下使用的国家/地区信息相同。
|
||||
该 AP 与 AP 模式、WIFI_COUNTRY_POLICY_MANUAL 策略下使用的国家/地区信息相同。
|
||||
|
||||
+---------------------+----------------------------+------------------------------------------------------------------------------+
|
||||
| Wi-Fi 模式 | 政策 | 描述 |
|
||||
+---------------------+----------------------------+------------------------------------------------------------------------------+
|
||||
| Station 模式 | WIFI_COUNTRY_POLICY_AUTO | 如果所连 AP 的 beacon 中有国家/地区的 IE,使用的国家/地区信息为 beacon |
|
||||
| | | 中的信息,否则,使用默认信息。 |
|
||||
| | | |
|
||||
| | | 扫描时: |
|
||||
| | | |
|
||||
| | | -如果 schan+nchan-1>11, |
|
||||
| | | 主动扫描起始信道至信道 11,被动扫描信道 12 至 信道 |
|
||||
| | | schan+nchan-1。 |
|
||||
| | | |
|
||||
| | | -如果 schan+nchan-1<=11, |
|
||||
| | | 主动扫描起始信道至信道 schan+nchan-1。 |
|
||||
| | | |
|
||||
| | | 请记住,如果 AP 带有隐藏 SSID |
|
||||
| | | 且被设置为被动扫描信道,被动扫描将无法找到该 |
|
||||
| | | AP。也就是说,如果应用程序希望在每个信道中找到带有隐藏 |
|
||||
| | | SSID 的 AP,国家/地区信息应该配置为 |
|
||||
| | | WIFI_COUNTRY_POLICY_MANUAL。 |
|
||||
+---------------------+----------------------------+------------------------------------------------------------------------------+
|
||||
| Station 模式 | WIFI_COUNTRY_POLICY_MANUAL | 总是使用配置的国家/地区信息。 扫描时,主动扫描起始信道至信道 schan+nchan-1。 |
|
||||
+---------------------+----------------------------+------------------------------------------------------------------------------+
|
||||
| AP 模式 | WIFI_COUNTRY_POLICY_AUTO | 总是使用配置的国家/地区信息。 |
|
||||
+---------------------+----------------------------+------------------------------------------------------------------------------+
|
||||
| AP 模式 | WIFI_COUNTRY_POLICY_MANUAL | 总是使用配置的国家/地区信息。 |
|
||||
+---------------------+----------------------------+------------------------------------------------------------------------------+
|
||||
| Station/AP 共存模式 | WIFI_COUNTRY_POLICY_AUTO | 如果 station 不连接任何 AP,AP 使用配置的国家/地区信息。如果 station |
|
||||
| | | 连接一个 AP,该 AP 的国家/地区信息与该 station 相同。与 |
|
||||
| | | Station 模式、WIFI_COUNTRY_POLICY_AUTO 政策下使用的国家/地区信息相同。 |
|
||||
+---------------------+----------------------------+------------------------------------------------------------------------------+
|
||||
|
||||
|
||||
主信道
|
||||
|
Reference in New Issue
Block a user