Merge branch 'bugfix/nan_sd_dp_fixes_v5.1' into 'release/v5.1'

NAN Service discovery and datapath bugfixes (Backport v5.1)

See merge request espressif/esp-idf!24383
This commit is contained in:
Jiang Jiang Jian 2023-07-10 21:44:49 +08:00
commit a09a503073
20 changed files with 92 additions and 70 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2018-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -90,12 +90,6 @@ esp_err_t coex_preference_set(coex_prefer_t prefer);
*/
uint32_t coex_status_get(void);
/**
* @brief Set software coexist condition.
* @return : software coexist condition
*/
void coex_condition_set(uint32_t type, bool dissatisfy);
/**
* @brief WiFi requests coexistence.
*

@ -1 +1 @@
Subproject commit 28e2858208c0f8720c43618e90dbbfaf6035ebf5
Subproject commit 08e1c246c74050565806289000f9d506bfb6ac01

View File

@ -1769,7 +1769,7 @@ pm_on_probe_resp_rx = 0x40001ecc;
hal_set_sta_tsf = 0x40001ed0;
ic_update_sta_tsf = 0x40001ed4;
ic_tx_pkt = 0x40001ed8;
pm_send_probe_stop = 0x40001edc;
//pm_send_probe_stop = 0x40001edc;
pm_send_probe_start = 0x40001ee0;
pm_on_coex_schm_process_restart = 0x40001ee4;
hal_mac_set_rxq_policy = 0x40001ee8;
@ -1940,7 +1940,7 @@ ieee80211_setup_phy_mode = 0x4000207c;
ieee80211_sta_is_connected = 0x40002080;
current_task_is_wifi_task = 0x40002084;
wifi_get_init_state = 0x40002088;
ieee80211_timer_process = 0x4000208c;
/* ieee80211_timer_process = 0x4000208c; */
/* cnx_coexist_timeout = 0x40002090; */
/* sta_recv_mgmt = 0x40002094;*/
ieee80211_send_setup = 0x40002098;

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -424,13 +424,6 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void)
#endif
}
static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy)
{
#if CONFIG_SW_COEXIST_ENABLE
coex_condition_set(type, dissatisfy);
#endif
}
static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
{
#if CONFIG_SW_COEXIST_ENABLE
@ -657,7 +650,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
._coex_enable = coex_enable_wrapper,
._coex_disable = coex_disable_wrapper,
._coex_status_get = coex_status_get_wrapper,
._coex_condition_set = coex_condition_set_wrapper,
._coex_wifi_request = coex_wifi_request_wrapper,
._coex_wifi_release = coex_wifi_release_wrapper,
._coex_wifi_channel_set = coex_wifi_channel_set_wrapper,

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -390,13 +390,6 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void)
#endif
}
static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy)
{
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_condition_set(type, dissatisfy);
#endif
}
static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
{
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
@ -626,7 +619,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
._coex_enable = coex_enable_wrapper,
._coex_disable = coex_disable_wrapper,
._coex_status_get = coex_status_get_wrapper,
._coex_condition_set = coex_condition_set_wrapper,
._coex_wifi_request = coex_wifi_request_wrapper,
._coex_wifi_release = coex_wifi_release_wrapper,
._coex_wifi_channel_set = coex_wifi_channel_set_wrapper,

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -407,13 +407,6 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void)
#endif
}
static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy)
{
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_condition_set(type, dissatisfy);
#endif
}
static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
{
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
@ -643,7 +636,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
._coex_enable = coex_enable_wrapper,
._coex_disable = coex_disable_wrapper,
._coex_status_get = coex_status_get_wrapper,
._coex_condition_set = coex_condition_set_wrapper,
._coex_wifi_request = coex_wifi_request_wrapper,
._coex_wifi_release = coex_wifi_release_wrapper,
._coex_wifi_channel_set = coex_wifi_channel_set_wrapper,

View File

@ -396,13 +396,6 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void)
#endif
}
static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy)
{
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_condition_set(type, dissatisfy);
#endif
}
static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
{
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
@ -632,7 +625,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
._coex_enable = coex_enable_wrapper,
._coex_disable = coex_disable_wrapper,
._coex_status_get = coex_status_get_wrapper,
._coex_condition_set = coex_condition_set_wrapper,
._coex_wifi_request = coex_wifi_request_wrapper,
._coex_wifi_release = coex_wifi_release_wrapper,
._coex_wifi_channel_set = coex_wifi_channel_set_wrapper,

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -415,13 +415,6 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void)
#endif
}
static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy)
{
#if CONFIG_EXTERNAL_COEX_ENABLE
coex_condition_set(type, dissatisfy);
#endif
}
static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
{
#if CONFIG_EXTERNAL_COEX_ENABLE
@ -653,7 +646,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
._coex_enable = coex_enable_wrapper,
._coex_disable = coex_disable_wrapper,
._coex_status_get = coex_status_get_wrapper,
._coex_condition_set = coex_condition_set_wrapper,
._coex_wifi_request = coex_wifi_request_wrapper,
._coex_wifi_release = coex_wifi_release_wrapper,
._coex_wifi_channel_set = coex_wifi_channel_set_wrapper,

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -432,13 +432,6 @@ static IRAM_ATTR uint32_t coex_status_get_wrapper(void)
#endif
}
static void coex_condition_set_wrapper(uint32_t type, bool dissatisfy)
{
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
coex_condition_set(type, dissatisfy);
#endif
}
static int coex_wifi_request_wrapper(uint32_t event, uint32_t latency, uint32_t duration)
{
#if CONFIG_SW_COEXIST_ENABLE || CONFIG_EXTERNAL_COEX_ENABLE
@ -668,7 +661,6 @@ wifi_osi_funcs_t g_wifi_osi_funcs = {
._coex_enable = coex_enable_wrapper,
._coex_disable = coex_disable_wrapper,
._coex_status_get = coex_status_get_wrapper,
._coex_condition_set = coex_condition_set_wrapper,
._coex_wifi_request = coex_wifi_request_wrapper,
._coex_wifi_release = coex_wifi_release_wrapper,
._coex_wifi_channel_set = coex_wifi_channel_set_wrapper,

View File

@ -584,7 +584,7 @@ esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw);
/**
* @brief Set primary/secondary channel of device
*
* @attention 1. This API should be called after esp_wifi_start()
* @attention 1. This API should be called after esp_wifi_start() and before esp_wifi_stop()
* @attention 2. When device is in STA mode, this API should not be called when STA is scanning or connecting to an external AP
* @attention 3. When device is in softAP mode, this API should not be called when softAP has connected to external STAs
* @attention 4. When device is in STA+softAP mode, this API should not be called when in the scenarios described above
@ -599,6 +599,7 @@ esp_err_t esp_wifi_get_bandwidth(wifi_interface_t ifx, wifi_bandwidth_t *bw);
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
* - ESP_ERR_WIFI_IF: invalid interface
* - ESP_ERR_INVALID_ARG: invalid argument
* - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start
*/
esp_err_t esp_wifi_set_channel(uint8_t primary, wifi_second_chan_t second);

View File

@ -165,6 +165,7 @@ typedef struct {
bool show_hidden; /**< enable to scan AP whose SSID is hidden */
wifi_scan_type_t scan_type; /**< scan type, active or passive */
wifi_scan_time_t scan_time; /**< scan time per channel */
uint8_t home_chan_dwell_time;/**< time spent at home channel between scanning consecutive channels.*/
} wifi_scan_config_t;
typedef enum {
@ -1063,6 +1064,7 @@ typedef struct {
uint8_t subscribe_id; /**< Subscribe Service Identifier */
uint8_t publish_id; /**< Publish Service Identifier */
uint8_t pub_if_mac[6]; /**< NAN Interface MAC of the Publisher */
bool update_pub_id; /**< Indicates whether publisher's service ID needs to be updated */
} wifi_event_nan_svc_match_t;
/** Argument structure for WIFI_EVENT_NAN_REPLIED event */

@ -1 +1 @@
Subproject commit c1a8747dab1ef3a138195b0a7e5de8dd9dfe539e
Subproject commit fd77ffcf8e56ad5c9ea85d635f40ce63134101b0

View File

@ -161,6 +161,8 @@ void esp_wifi_nan_get_ipv6_linklocal_from_mac(ip6_addr_t *ip6, uint8_t *mac_addr
/**
* brief Get own Service information from Service ID OR Name.
*
* @attention If service information is to be fetched from service name, set own_svc_id as zero.
*
* @param[inout] own_svc_id As input, it indicates Service ID to search for.
* As output, it indicates Service ID of the service found using Service Name.
* @param[inout] svc_name As input, it indicates Service Name to search for.

View File

@ -32,6 +32,8 @@
#define MACADDR_EQUAL(a1, a2) (memcmp(a1, a2, MACADDR_LEN))
#define MACADDR_COPY(dst, src) (memcpy(dst, src, MACADDR_LEN))
#define NAN_DW_INTVL_MS 524 /* NAN DW interval (512 TU's ~= 524 mSec) */
#define NAN_NDP_RESP_TIMEOUT_DW 4
#define NAN_NDP_RESP_TIMEOUT NAN_NDP_RESP_TIMEOUT_DW*NAN_DW_INTVL_MS
/* Global Variables */
static const char *TAG = "nan_app";
@ -180,6 +182,16 @@ static struct peer_svc_info *nan_find_peer_svc(uint8_t own_svc_id, uint8_t peer_
return p_peer_svc;
}
static bool nan_update_peer_svc(uint8_t own_svc_id, uint8_t peer_svc_id, uint8_t peer_nmi[])
{
struct peer_svc_info *peer_info = nan_find_peer_svc(own_svc_id, 0, peer_nmi);
if (peer_info) {
peer_info->svc_id = peer_svc_id;
return true;
}
return false;
}
static bool nan_record_peer_svc(uint8_t own_svc_id, uint8_t peer_svc_id, uint8_t peer_nmi[])
{
struct own_svc_info *p_own_svc;
@ -388,6 +400,11 @@ static void nan_fill_params_from_event(void *evt_data, uint8_t event)
case WIFI_EVENT_NAN_SVC_MATCH: {
wifi_event_nan_svc_match_t *evt = (wifi_event_nan_svc_match_t *)evt_data;
if (evt->update_pub_id) {
if (nan_update_peer_svc(evt->subscribe_id, evt->publish_id, evt->pub_if_mac)) {
break;
}
}
if (!nan_find_peer_svc(evt->subscribe_id, evt->publish_id, evt->pub_if_mac)) {
nan_record_peer_svc(evt->subscribe_id, evt->publish_id, evt->pub_if_mac);
}
@ -867,7 +884,7 @@ uint8_t esp_wifi_nan_datapath_req(wifi_nan_datapath_req_t *req)
nan_record_new_ndl(ndp_id, req->pub_id, req->peer_mac, ESP_WIFI_NDP_ROLE_INITIATOR);
ESP_LOGD(TAG, "Requested NDP with "MACSTR" [NDP ID - %d]", MAC2STR(req->peer_mac), ndp_id);
EventBits_t bits = os_event_group_wait_bits(nan_event_group, NDP_ACCEPTED | NDP_REJECTED, pdFALSE, pdFALSE, pdMS_TO_TICKS(2*NAN_DW_INTVL_MS));
EventBits_t bits = os_event_group_wait_bits(nan_event_group, NDP_ACCEPTED | NDP_REJECTED, pdFALSE, pdFALSE, pdMS_TO_TICKS(NAN_NDP_RESP_TIMEOUT));
if (bits & NDP_ACCEPTED) {
os_event_group_clear_bits(nan_event_group, NDP_ACCEPTED);
return ndp_id;

View File

@ -111,6 +111,8 @@ The RF resource allocation mechanism is based on priority. As shown below, both
}
.. _coexist_policy:
Coexistence Policy
^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -22,6 +22,10 @@ The following features are supported:
- Multiple antennas
- Channel state information
.. only:: SOC_WIFI_NAN_SUPPORT
- Wi-Fi Aware (NAN)
.. only:: esp32c6
- 4 virtual Wi-Fi interfaces, which are STA, AP, Sniffer and reserved.
@ -1674,6 +1678,19 @@ For establishing a secure connection, AP and station negotiate and agree on the
Detailed information on creating certificates and how to run wpa2_enterprise example on {IDF_TARGET_NAME} can be found in :example:`wifi/wifi_enterprise`.
.. only:: SOC_WIFI_NAN_SUPPORT
Wi-Fi Aware\ :sup:`TM` (NAN)
----------------------------
Wi-Fi Aware\ :sup:`TM` or NAN (Neighbor Awareness Networking) is a protocol that allows Wi-Fi devices to discover services in their proximity. NAN uses direct device-to-device communication and does not require any Internet or AP connection.
Multiple NAN devices in the vicinity will form a NAN cluster which allows them to communicate with each other. NAN devices in a cluster synchronise their clocks and listen to each other periodically on Channel 6. Devices can advertise (Publish) or seek for (Subscribe) services within their NAN Cluster using Service Discovery protocols. Matching of services is done by service name and optionally matching filters. Once a Subscriber gets a match with a Publisher, it can either send a message (Follow-up) or establish a datapath (NDP) with the Publisher. After NDP is setup both devices will obtain an IPv6 address and can use it for communication.
Please note that NAN Datapath security is not supported i.e. the data packets will go out unencrypted. NAN uses a separate interface for Discovery and Datapath, which is other than that used for STA and AP. NAN operates in standalone mode, which means co-existence with STA or AP interface is not supported.
Refer to ESP-IDF examples :idf_file:`examples/wifi/wifi_aware/nan_publisher/README.md` and :idf_file:`examples/wifi/wifi_aware/nan_subscriber/README.md` to setup a NAN Publisher and Subscriber.
Wireless Network Management
----------------------------
@ -1728,7 +1745,11 @@ In maximum power-saving mode, station wakes up in every listen interval to recei
Call ``esp_wifi_set_ps(WIFI_PS_MIN_MODEM)`` to enable Modem-sleep minimum power-saving mode or ``esp_wifi_set_ps(WIFI_PS_MAX_MODEM)`` to enable Modem-sleep maximum power-saving mode after calling :cpp:func:`esp_wifi_init()`. When station connects to AP, Modem-sleep will start. When station disconnects from AP, Modem-sleep will stop.
Call ``esp_wifi_set_ps(WIFI_PS_NONE)`` to disable Modem-sleep entirely. This has much higher power consumption, but provides minimum latency for receiving Wi-Fi data in real time. When Modem-sleep is enabled, received Wi-Fi data can be delayed for as long as the DTIM period (minimum power-saving mode) or the listen interval (maximum power-saving mode). Disabling Modem-sleep entirely is not possible for Wi-Fi and Bluetooth coexist mode.
Call ``esp_wifi_set_ps(WIFI_PS_NONE)`` to disable Modem-sleep mode entirely. Disabling it increases power consumption, but minimizes the delay in receiving Wi-Fi data in real time. When Modem-sleep mode is enabled, the delay in receiving Wi-Fi data may be the same as the DTIM cycle (minimum power-saving mode) or the listening interval (maximum power-saving mode).
.. only:: SOC_SUPPORT_COEXISTENCE
Note that in coexist mode, Wi-Fi will remain active only during Wi-Fi time slice, and sleep during non Wi-Fi time slice even if ``esp_wifi_set_ps(WIFI_PS_NONE)`` is called. Please refer to :ref:`coexist policy <coexist_policy>`.
The default Modem-sleep mode is WIFI_PS_MIN_MODEM.

View File

@ -110,6 +110,7 @@ RF 共存
Coexistence -> RF;
}
.. _coexist_policy-cn:
共存策略
^^^^^^^^^^^^^^

View File

@ -1728,7 +1728,11 @@ Modem-sleep 模式包括最小和最大节能模式。在最小节能模式下
调用 :cpp:func:`esp_wifi_init()` 后,调用 ``esp_wifi_set_ps(WIFI_PS_MIN_MODEM)`` 可使能 Modem-sleep 最小节能模式。调用 ``esp_wifi_set_ps(WIFI_PS_MAX_MODEM)`` 可使能 Modem-sleep 最大节能模式。station 连接到 AP 时Modem-sleep 模式将启动。station 与 AP 断开连接时Modem-sleep 模式将停止。
调用 ``esp_wifi_set_ps(WIFI_PS_NONE)`` 可以完全禁用 Modem-sleep 模式。禁用会增大功耗,但可以最大限度减少实时接收 Wi-Fi 数据的延迟。使能 Modem-sleep 时,接收 Wi-Fi 数据的延迟时间可能与 DTIM 周期(最小节能模式)或监听间隔(最大节能模式)相同。在 Wi-Fi 与 Bluetooth LE 共存模式下,无法完全禁用 modem-sleep 模式。
调用 ``esp_wifi_set_ps(WIFI_PS_NONE)`` 可以完全禁用 Modem-sleep 模式。禁用会增大功耗,但可以最大限度减少实时接收 Wi-Fi 数据的延迟。使能 Modem-sleep 模式时,接收 Wi-Fi 数据的延迟时间可能与 DTIM 周期(最小节能模式)或监听间隔(最大节能模式)相同。
.. only:: SOC_SUPPORT_COEXISTENCE
注意在共存模式下, 即使调用 ``esp_wifi_set_ps(WIFI_PS_NONE)``, Wi-Fi 也仅会在 Wi-Fi 时间片内保持活动状态, 非 Wi-Fi 时间片内仍然睡眠。请参照 :ref:`共存策略 <coexist_policy-cn>`
默认的 Modem-sleep 模式是 WIFI_PS_MIN_MODEM。

View File

@ -58,4 +58,29 @@ menu "Example Configuration"
help
When enable long range, the PHY rate of ESP32 will be 512Kbps or 256Kbps
config ESPNOW_ENABLE_POWER_SAVE
bool "Enable ESPNOW Power Save"
default "n"
select ESP_WIFI_STA_DISCONNECTED_PM_ENABLE
depends on ESPNOW_WIFI_MODE_STATION
help
With ESPNOW power save enabled, chip would be able to wakeup and sleep periodically
Notice ESP_WIFI_STA_DISCONNECTED_PM_ENABLE is essential at Wi-Fi disconnected
config ESPNOW_WAKE_WINDOW
int "ESPNOW wake window, unit in millisecond"
range 0 65535
default 50
depends on ESPNOW_ENABLE_POWER_SAVE
help
ESPNOW wake window
config ESPNOW_WAKE_INTERVAL
int "ESPNOW wake interval, unit in millisecond"
range 1 65535
default 100
depends on ESPNOW_ENABLE_POWER_SAVE
help
ESPNOW wake interval
endmenu

View File

@ -299,8 +299,9 @@ static esp_err_t example_espnow_init(void)
ESP_ERROR_CHECK( esp_now_init() );
ESP_ERROR_CHECK( esp_now_register_send_cb(example_espnow_send_cb) );
ESP_ERROR_CHECK( esp_now_register_recv_cb(example_espnow_recv_cb) );
#if CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE
ESP_ERROR_CHECK( esp_now_set_wake_window(65535) );
#if CONFIG_ESPNOW_ENABLE_POWER_SAVE
ESP_ERROR_CHECK( esp_now_set_wake_window(CONFIG_ESPNOW_WAKE_WINDOW) );
ESP_ERROR_CHECK( esp_wifi_connectionless_module_set_wake_interval(CONFIG_ESPNOW_WAKE_INTERVAL) );
#endif
/* Set primary master key. */
ESP_ERROR_CHECK( esp_now_set_pmk((uint8_t *)CONFIG_ESPNOW_PMK) );