fix(wifi): Add refactoring and migration guide for USD, Offchan_tx, ROC

1. fix(wifi): Rename old NAN configuration to NAN-Sync
  - Rename CONFIG_ESP_WIFI_NAN_ENABLE to CONFIG_ESP_WIFI_NAN_SYNC_ENABLE to indicate
    the support for Synchronized NAN (Wi-Fi Aware).
  - Because the original flag really controls the synchronized feature set, rename it
    to CONFIG_ESP_WIFI_NAN_SYNC_ENABLE so the NAN-Sync and NAN-USD paths can be
    selected independently without confusion.
2. Document esp_wifi_start requirement and fix USD examples
3. Rename nan_callbacks to nan_sync_callbacks
4. Remove the discovery_flag, clarify docs for sync vs USD flows, and add USD start/stop APIs
5. Require esp_wifi_start() before USD start
6. docs(nan): add NAN-USD application examples
7. add migration guide and hints for NAN-USD proto field
8. Improve allow_broadcast documentation
9. Add attention to the API esp_wifi_remain_on_channel
10. fix(wifi): align NAN API renames and docs for v6.0
  - keep shared APIs under esp_wifi_nan_* while reserving
    sync/usd names for mode-specific entry points
  - clarify synchronized-cluster scope in headers, docs, and migration notes (EN/zh-CN)
  - update examples for renamed helpers and WIFI_NAN_SYNC_CONFIG_DEFAULT()
  - rename `wifi_nan_config_t` to `wifi_nan_sync_config_t`
11. Mark NAN-USD as esp-idf experimental feature
This commit is contained in:
Sarvesh Bodakhe
2025-09-30 14:46:56 +05:30
parent a5f6bc639b
commit 4c3d6c1292
30 changed files with 342 additions and 251 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ const esp_netif_ip_info_t _g_esp_netif_soft_ap_ip = {
const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_AP();
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
const esp_netif_inherent_config_t _g_esp_netif_inherent_nan_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_NAN();
#endif
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -158,7 +158,7 @@ extern "C" {
}
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
/**
* @brief Default configuration reference of WIFI NAN
*/
@@ -204,7 +204,7 @@ extern "C" {
#define ESP_NETIF_BASE_DEFAULT_WIFI_AP &_g_esp_netif_inherent_ap_config
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
/**
* @brief Default base config (esp-netif inherent) of WIFI NAN
*/
@@ -230,7 +230,7 @@ extern "C" {
#ifdef CONFIG_ESP_WIFI_SOFTAP_SUPPORT
#define ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP _g_esp_netif_netstack_default_wifi_ap
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
#define ESP_NETIF_NETSTACK_DEFAULT_WIFI_NAN _g_esp_netif_netstack_default_wifi_nan
#endif
#ifdef CONFIG_PPP_SUPPORT
@@ -249,7 +249,7 @@ extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_sta
#ifdef CONFIG_ESP_WIFI_SOFTAP_SUPPORT
extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_ap;
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_nan;
#endif
#ifdef CONFIG_PPP_SUPPORT
@@ -264,7 +264,7 @@ extern const esp_netif_inherent_config_t _g_esp_netif_inherent_sta_config;
#ifdef CONFIG_ESP_WIFI_SOFTAP_SUPPORT
extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config;
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
extern const esp_netif_inherent_config_t _g_esp_netif_inherent_nan_config;
#endif
extern const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config;
+1 -1
View File
@@ -48,7 +48,7 @@ if(CONFIG_ESP_WIFI_ENABLED OR CONFIG_ESP_HOST_WIFI_ENABLED)
"src/smartconfig_ack.c")
endif()
if(CONFIG_ESP_WIFI_NAN_ENABLE OR CONFIG_ESP_WIFI_NAN_USD_ENABLE)
if(CONFIG_ESP_WIFI_NAN_SYNC_ENABLE OR CONFIG_ESP_WIFI_NAN_USD_ENABLE)
list(APPEND srcs "wifi_apps/nan_app/src/nan_app.c")
endif()
if(CONFIG_ESP_WIFI_ENABLE_ROAMING_APP)
+6 -5
View File
@@ -576,19 +576,20 @@ menu "Wi-Fi"
Maximum espnow encrypted peers number + maximum number of connections of SoftAP = Max hardware
keys number. When using ESP mesh, this value should be set to a maximum of 6.
config ESP_WIFI_NAN_ENABLE
bool "WiFi Aware"
config ESP_WIFI_NAN_SYNC_ENABLE
bool "Enable Wi-Fi Aware: Synchronization (NAN-Sync)"
default n
depends on SOC_WIFI_NAN_SUPPORT
select LWIP_IPV6
help
Enable WiFi Aware (NAN) feature.
Enable Wi-Fi Aware: Synchronization feature (NAN-Sync).
config ESP_WIFI_NAN_USD_ENABLE
bool "Enable NAN USD"
bool "Enable Wi-Fi Aware: Unsynchronized service discovery (NAN-USD)"
depends on IDF_EXPERIMENTAL_FEATURES
default n
help
Enable NAN(WiFi Aware) Unsynchronized service discovery
Enable Wi-Fi Aware: Unsynchronized service discovery (NAN-USD)
config ESP_WIFI_MBEDTLS_CRYPTO
bool "Use MbedTLS crypto APIs"
@@ -39,7 +39,7 @@ typedef struct {
void *storage; /**< storage for FreeRTOS queue */
} wifi_static_queue_t;
struct nan_callbacks {
struct nan_sync_callbacks {
void (* service_match)(uint8_t sub_id, uint8_t pub_id, uint8_t pub_mac[6], uint16_t capab,
uint8_t ssi_ver, uint8_t *ssi, uint16_t ssi_len);
void (* replied)(uint8_t pub_id, uint8_t sub_id, uint8_t pub_mac[6], uint8_t *ssi, uint16_t ssi_len);
@@ -780,7 +780,7 @@ esp_err_t esp_nan_internal_datapath_end(wifi_nan_datapath_end_req_t *req);
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_nan_internal_register_callbacks(struct nan_callbacks *cb);
esp_err_t esp_nan_internal_register_callbacks(struct nan_sync_callbacks *cb);
/**
* @brief Connect WiFi station to the AP.
+2
View File
@@ -1788,6 +1788,8 @@ esp_err_t esp_wifi_action_tx_req(wifi_action_tx_req_t *req);
/**
* @brief Remain on the target channel for required duration
*
* @attention 1. The API returns ESP_ERR_INVALID_ARG when `req->allow_broadcast` is true and the device operates in AP+STA mode.
*
* @param req roc request structure containing relevant fields
*
* @return
@@ -592,8 +592,7 @@ typedef struct {
uint8_t master_pref; /**< Device's preference value to serve as NAN Master */
uint8_t scan_time; /**< Scan time in seconds while searching for a NAN cluster */
uint16_t warm_up_sec; /**< Warm up time before assuming NAN Anchor Master role */
bool discovery_flag; /**< False in case of NAN Synchronization, True in case of Unsynchronized service discovery (USD)*/
} wifi_nan_config_t;
} wifi_nan_sync_config_t;
/**
* @brief Configuration data for device's AP or STA or NAN.
@@ -605,7 +604,7 @@ typedef struct {
typedef union {
wifi_ap_config_t ap; /**< Configuration of AP */
wifi_sta_config_t sta; /**< Configuration of STA */
wifi_nan_config_t nan; /**< Configuration of NAN */
wifi_nan_sync_config_t nan; /**< Configuration of NAN */
} wifi_config_t;
/**
@@ -799,8 +798,8 @@ typedef struct {
bool no_ack; /**< Indicates no ack required */
wifi_action_rx_cb_t rx_cb; /**< Rx Callback to receive action frames */
uint8_t op_id; /**< Unique Identifier for operation provided by wifi driver */
uint32_t data_len; /**< Length of the appended Data */
uint8_t bssid[6]; /**< BSSID (A3) address. If all zeroes, broadcast address will be used */
uint32_t data_len; /**< Length of the appended Data */
uint8_t data[0]; /**< Appended Data payload */
} wifi_action_tx_req_t;
@@ -835,10 +834,11 @@ typedef struct {
wifi_action_rx_cb_t rx_cb; /**< Rx Callback to receive action mgmt frames */
uint8_t op_id; /**< ID of this specific ROC operation provided by wifi driver */
wifi_action_roc_done_cb_t done_cb; /**< Callback to function that will be called upon ROC done. If assigned, WIFI_EVENT_ROC_DONE event will not be posted */
bool allow_broadcast; /**< If set to true, broadcast/multicast action frames will be received
in the ROC Rx callback, enabling peer discovery.
If false (default), broadcast/multicast action frames will be filtered out
and not passed to the Rx callback, reducing CPU usage. */
bool allow_broadcast; /**< If set to true, broadcast/multicast action frames from any network (Address3/BSSID=ANY)
will be received in the ROC Rx callback, enabling peer discovery.
If false (default), broadcast/multicast action frames from other networks
will be filtered out in hardware and not passed to the Rx callback, reducing CPU usage.
Frames whose Address3/BSSID is already broadcast are always delivered. */
} wifi_roc_req_t;
/**
@@ -1125,8 +1125,8 @@ typedef enum {
WIFI_EVENT_BTWT_SETUP, /**< bTWT setup */
WIFI_EVENT_BTWT_TEARDOWN, /**< bTWT teardown*/
WIFI_EVENT_NAN_STARTED, /**< NAN Discovery has started */
WIFI_EVENT_NAN_STOPPED, /**< NAN Discovery has stopped */
WIFI_EVENT_NAN_SYNC_STARTED, /**< NAN Synchronization Discovery has started */
WIFI_EVENT_NAN_SYNC_STOPPED, /**< NAN Synchronization Discovery has stopped */
WIFI_EVENT_NAN_SVC_MATCH, /**< NAN Service Discovery match found */
WIFI_EVENT_NAN_REPLIED, /**< Replied to a NAN peer with Service Discovery match */
WIFI_EVENT_NAN_RECEIVE, /**< Received a Follow-up message */
+1
View File
@@ -28,6 +28,7 @@ CONFIG_ESP32_WIFI_IRAM_OPT CONFIG_ESP_WIFI_IRAM_OPT
CONFIG_ESP32_WIFI_RX_IRAM_OPT CONFIG_ESP_WIFI_RX_IRAM_OPT
CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE CONFIG_ESP_WIFI_ENABLE_WPA3_SAE
CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA CONFIG_ESP_WIFI_ENABLE_WPA3_OWE_STA
CONFIG_ESP_WIFI_NAN_ENABLE CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
# renaming supplicant kconfig to esp_wifi kconfig
CONFIG_WPA_MBEDTLS_CRYPTO CONFIG_ESP_WIFI_MBEDTLS_CRYPTO
+13 -13
View File
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -12,7 +12,7 @@
#include "esp_wifi_netif.h"
#include <string.h>
#include <inttypes.h>
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
#include "apps_private/wifi_apps_private.h"
#endif
#if CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
@@ -170,7 +170,7 @@ static void wifi_default_action_sta_got_ip(void *arg, esp_event_base_t base, int
}
}
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
static void wifi_default_action_nan_started(void *arg, esp_event_base_t base, int32_t event_id, void *data)
{
if (s_wifi_netifs[WIFI_IF_NAN] != NULL) {
@@ -202,9 +202,9 @@ static esp_err_t clear_default_wifi_handlers(void)
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_AP_STOP, wifi_default_action_ap_stop);
#endif
esp_event_handler_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, wifi_default_action_sta_got_ip);
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_NAN_STARTED, wifi_default_action_nan_started);
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_NAN_STOPPED, wifi_default_action_nan_stopped);
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_NAN_SYNC_STARTED, wifi_default_action_nan_started);
esp_event_handler_unregister(WIFI_EVENT, WIFI_EVENT_NAN_SYNC_STOPPED, wifi_default_action_nan_stopped);
#endif
esp_unregister_shutdown_handler((shutdown_handler_t)esp_wifi_stop);
wifi_default_handlers_set = false;
@@ -258,13 +258,13 @@ static esp_err_t set_default_wifi_handlers(void)
goto fail;
}
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
err = esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_NAN_STARTED, wifi_default_action_nan_started, NULL);
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
err = esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_NAN_SYNC_STARTED, wifi_default_action_nan_started, NULL);
if (err != ESP_OK) {
goto fail;
}
err = esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_NAN_STOPPED, wifi_default_action_nan_stopped, NULL);
err = esp_event_handler_register(WIFI_EVENT, WIFI_EVENT_NAN_SYNC_STOPPED, wifi_default_action_nan_stopped, NULL);
if (err != ESP_OK) {
goto fail;
}
@@ -364,7 +364,7 @@ static inline esp_err_t esp_netif_attach_wifi(esp_netif_t *esp_netif, wifi_inter
#ifdef CONFIG_ESP_WIFI_SOFTAP_SUPPORT
&& wifi_if != WIFI_IF_AP
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
&& wifi_if != WIFI_IF_NAN
#endif
)) {
@@ -386,7 +386,7 @@ esp_err_t esp_netif_attach_wifi_ap(esp_netif_t *esp_netif)
}
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
esp_err_t esp_netif_attach_wifi_nan(esp_netif_t *esp_netif)
{
return esp_netif_attach_wifi(esp_netif, WIFI_IF_NAN);
@@ -425,7 +425,7 @@ esp_netif_t* esp_netif_create_default_wifi_sta(void)
return netif;
}
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
/**
* @brief User init default NAN (official API)
*/
@@ -465,7 +465,7 @@ esp_netif_t* esp_netif_create_wifi(wifi_interface_t wifi_if, const esp_netif_inh
} else if (wifi_if == WIFI_IF_AP) {
cfg.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP;
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
} else if (wifi_if == WIFI_IF_NAN) {
cfg.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_NAN;
#endif
+6 -6
View File
@@ -27,7 +27,7 @@
#if __has_include("esp_psram.h")
#include "esp_psram.h"
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
#include "apps_private/wifi_apps_private.h"
#endif
#ifdef CONFIG_ESP_WIFI_FTM_ENABLE
@@ -187,7 +187,7 @@ static esp_err_t wifi_deinit_internal(void)
ESP_LOGW(TAG, "Failed to unregister Rx callbacks");
}
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
esp_nan_app_deinit();
#endif
@@ -484,7 +484,7 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config)
esp_wifi_config_info();
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
esp_nan_app_init();
#endif
@@ -649,7 +649,7 @@ void create_new_bss_for_sa_query_failed_sta(uint8_t arg)
}
#endif /* CONFIG_ESP_WIFI_SOFTAP_SUPPORT */
#ifndef CONFIG_ESP_WIFI_NAN_ENABLE
#ifndef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
esp_err_t nan_start(void)
{
@@ -680,7 +680,7 @@ int wifi_create_nan(void)
return 0;
}
int wifi_nan_set_config_local(wifi_nan_config_t *p)
int wifi_nan_set_config_local(wifi_nan_sync_config_t *p)
{
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
return 0;
@@ -707,7 +707,7 @@ void nan_ndp_resp_timeout_process(void *p)
{
/* Do not remove, stub to overwrite weak link in Wi-Fi Lib */
}
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
#if CONFIG_IDF_TARGET_ESP32C2
#if CONFIG_ESP32C2_REV_MIN_FULL < 200
+2 -2
View File
@@ -46,7 +46,7 @@ static esp_err_t wifi_ap_receive(void *buffer, uint16_t len, void *eb)
}
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
static esp_err_t wifi_nan_receive(void *buffer, uint16_t len, void *eb)
{
return s_wifi_rxcbs[WIFI_IF_NAN](s_wifi_netifs[WIFI_IF_NAN], buffer, len, eb);
@@ -158,7 +158,7 @@ esp_err_t esp_wifi_register_if_rxcb(wifi_netif_driver_t ifx, esp_netif_receive_t
break;
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
case WIFI_IF_NAN:
rxcb = wifi_nan_receive;
break;
@@ -1 +1 @@
CONFIG_ESP_WIFI_NAN_ENABLE=y
CONFIG_ESP_WIFI_NAN_SYNC_ENABLE=y
@@ -15,7 +15,7 @@
extern "C" {
#endif
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
/**
* @brief Initialize the NAN App and required Data Structures
@@ -35,7 +35,7 @@ void esp_nan_app_deinit(void);
* @brief NAN App action handler for NAN Started event. Sets up other event handlers and
* initializes NAN App context
*
* @attention This API should be called in WIFI_EVENT_NAN_STARTED event handler
* @attention This API should be called in WIFI_EVENT_NAN_SYNC_STARTED event handler
*
* @param nan_netif Netif handle corresponding to NAN interface.
*/
@@ -45,11 +45,11 @@ void esp_nan_action_start(esp_netif_t *nan_netif);
* @brief NAN App action handler for NAN Stopped event. Clears other event handlers and
* resets NAN App context
*
* @attention This API should be called in WIFI_EVENT_NAN_STOPPED event handler
* @attention This API should be called in WIFI_EVENT_NAN_SYNC_STOPPED event handler
*/
void esp_nan_action_stop(void);
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
#ifdef __cplusplus
}
@@ -15,17 +15,12 @@
extern "C" {
#endif
#define WIFI_NAN_CONFIG_DEFAULT() { \
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
#define WIFI_NAN_SYNC_CONFIG_DEFAULT() { \
.op_channel = 6, \
.master_pref = 2, \
.scan_time = 3, \
.warm_up_sec = 5, \
.discovery_flag = 0, \
};
/* For USD, all parameters other than discovery_flag are ignored */
#define WIFI_USD_NAN_CONFIG_DEFAULT() { \
.discovery_flag = 1, \
};
#define NDP_STATUS_ACCEPTED 1
@@ -46,7 +41,8 @@ struct nan_peer_record {
};
/**
* @brief Start NAN Discovery or Unsynchronized service discovery (USD) with provided configuration
* @brief Start NAN Synchronization using the provided parameters.
* @note Discovery traffic begins only after publish/subscribe services are started.
*
* @attention This API should be called after esp_wifi_init().
*
@@ -56,30 +52,132 @@ struct nan_peer_record {
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_wifi_nan_start(const wifi_nan_config_t *nan_cfg);
esp_err_t esp_wifi_nan_sync_start(const wifi_nan_sync_config_t *nan_cfg);
/**
* @brief Stop NAN Discovery or USD and end publish/subscribe services
* @brief Stop NAN Synchronization discovery and end publish/subscribe services
*
* @attention This API will end datapaths if any in NAN synchronization
* @attention This API will stop USD if discovery_flag is set to true, else it will stop NAN Discovery
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_wifi_nan_stop(void);
esp_err_t esp_wifi_nan_sync_stop(void);
/**
* @brief Start Publishing a service to the NAN/USD Peers in vicinity
* @brief Send a NAN datapath request to a matched publisher within the synchronized NAN cluster
*
* @attention This API should be called after esp_wifi_nan_start().
* @attention This API will start a publisher in USD if discovery_flag is true
* @attention This API should be called by the Subscriber after a match occurs with a Publisher.
*
* @param req NAN Datapath Request parameters.
*
* @return
* - non-zero NAN Datapath identifier: If NAN datapath req was accepted by publisher
* - zero: If NAN datapath req was rejected by publisher or a timeout occurs
*/
uint8_t esp_wifi_nan_datapath_req(wifi_nan_datapath_req_t *req);
/**
* @brief Respond to a NAN datapath request within the synchronized NAN cluster
*
* @attention This API should be called if ndp_resp_needed is set 1 in wifi_nan_publish_cfg_t and
* a WIFI_EVENT_NDP_INDICATION event is received due to an incoming NDP request.
*
* @param resp NAN Datapath Response parameters.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_wifi_nan_datapath_resp(wifi_nan_datapath_resp_t *resp);
/**
* @brief Terminate an active NAN datapath within the synchronized NAN cluster
*
* @param req NAN Datapath end request parameters.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_wifi_nan_datapath_end(wifi_nan_datapath_end_req_t *req);
/**
* @brief Get IPv6 Link Local address using MAC address
*
* @param[out] ip6 Derived IPv6 Link Local address.
* @param[in] mac_addr Input MAC Address.
*/
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.
* @note Returns records discovered while participating in a synchronized NAN cluster.
*
* @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.
* As output, it indicates Service Name of the service found using Service ID.
* @param[out] num_peer_records Number of peers discovered by corresponding service.
* @return
* - ESP_OK: succeed
* - ESP_FAIL: failed
*/
esp_err_t esp_wifi_nan_get_own_svc_info(uint8_t *own_svc_id, char *svc_name, int *num_peer_records);
/**
* brief Get a list of Peers discovered by the given Service.
*
* @note Reports peers discovered via synchronized NAN operations.
*
* @param[inout] num_peer_records As input param, it stores max peers peer_record can hold.
* As output param, it specifies the actual number of peers this API returns.
* @param own_svc_id Service ID of own service.
* @param[out] peer_record Pointer to first peer record.
* @return
* - ESP_OK: succeed
* - ESP_FAIL: failed
*/
esp_err_t esp_wifi_nan_get_peer_records(int *num_peer_records, uint8_t own_svc_id, struct nan_peer_record *peer_record);
/**
* brief Find Peer's Service information using Peer MAC and optionally Service Name.
*
* @note Provides peer information available from synchronized NAN discovery.
*
* @param svc_name Service Name of the published/subscribed service.
* @param peer_mac Peer's NAN Management Interface MAC address.
* @param[out] peer_info Peer's service information structure.
* @return
* - ESP_OK: succeed
* - ESP_FAIL: failed
*/
esp_err_t esp_wifi_nan_get_peer_info(char *svc_name, uint8_t *peer_mac, struct nan_peer_record *peer_info);
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
#if defined(CONFIG_ESP_WIFI_NAN_SYNC_ENABLE) || defined(CONFIG_ESP_WIFI_NAN_USD_ENABLE)
/**
* @brief Start publishing a service to NAN peers within a synchronized cluster or to NAN-USD peers
*
* @attention Call after `esp_wifi_nan_sync_start()` when operating in NAN-Sync, or after
* `esp_wifi_nan_usd_start()` when operating in NAN-USD.
* @attention When NAN-USD discovery is active the publish request is routed through the
* USD engine, otherwise it uses NAN synchronization.
* @attention A maximum of two services is allowed simultaneously
* (e.g., one publish and one subscribe, or two publish/subscribe).
* This limit is defined by the ESP_WIFI_NAN_MAX_SVC_SUPPORTED.
*
* @param publish_cfg Configuration parameters for publishing a service.
* When operating in NAN-USD, populate `publish_cfg->usd_publish_config`
* (for example using `esp_wifi_usd_get_default_publish_cfg()`) to tune
* the USD dwell and channel parameters.
*
* @return
* - non-zero: Publish service identifier
@@ -88,15 +186,20 @@ esp_err_t esp_wifi_nan_stop(void);
uint8_t esp_wifi_nan_publish_service(const wifi_nan_publish_cfg_t *publish_cfg);
/**
* @brief Subscribe to a service published by a NAN peer within a cluster or a USD peer
* @brief Subscribe to a service published by a NAN peer within a synchronized cluster or by a NAN-USD peer
*
* @attention This API should be called after esp_wifi_nan_start().
* @attention This API will start a subscriber in USD if discovery_flag is true
* @attention Call after `esp_wifi_nan_sync_start()` when operating in NAN-Sync, or after
* `esp_wifi_nan_usd_start()` when operating in NAN-USD.
* @attention With NAN-USD discovery enabled the subscribe request is handled by the USD
* engine, otherwise it uses NAN synchronization.
* @attention A maximum of two services is allowed simultaneously
* (e.g., one publish and one subscribe, or two publish/subscribe).
* This limit is defined by the ESP_WIFI_NAN_MAX_SVC_SUPPORTED.
*
* @param subscribe_cfg Configuration parameters for subscribing for a service.
* When operating in NAN-USD, populate `subscribe_cfg->usd_subscribe_config`
* (for example using `esp_wifi_usd_get_default_subscribe_cfg()`) to tune
* the USD dwell and channel parameters.
*
* @return
* - non-zero: Subscribe service identifier
@@ -128,92 +231,29 @@ esp_err_t esp_wifi_nan_send_message(wifi_nan_followup_params_t *fup_params);
*/
esp_err_t esp_wifi_nan_cancel_service(uint8_t service_id);
/**
* @brief Send NAN Datapath Request to a NAN Publisher with matched service
*
* @attention This API should be called by the Subscriber after a match occurs with a Publisher.
*
* @param req NAN Datapath Request parameters.
*
* @return
* - non-zero NAN Datapath identifier: If NAN datapath req was accepted by publisher
* - zero: If NAN datapath req was rejected by publisher or a timeout occurs
*/
uint8_t esp_wifi_nan_datapath_req(wifi_nan_datapath_req_t *req);
#endif /* NAN-Sync || NAN-USD */
#ifdef CONFIG_ESP_WIFI_NAN_USD_ENABLE
/**
* @brief Respond to a NAN Datapath request with Accept or Reject
* @brief Start NAN Unsynchronized service discovery (USD)
*
* @attention This API should be called if ndp_resp_needed is set 1 in wifi_nan_publish_cfg_t and
* a WIFI_EVENT_NDP_INDICATION event is received due to an incoming NDP request.
*
* @param resp NAN Datapath Response parameters.
* @attention This API should be called after esp_wifi_start().
* @note USD currently operates over the Station interface; this may change in future releases.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_wifi_nan_datapath_resp(wifi_nan_datapath_resp_t *resp);
esp_err_t esp_wifi_nan_usd_start(void);
/**
* @brief Terminate a NAN Datapath
*
* @param req NAN Datapath end request parameters.
* @brief Stop NAN Unsynchronized service discovery (USD) and end publish/subscribe services
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_wifi_nan_datapath_end(wifi_nan_datapath_end_req_t *req);
/**
* @brief Get IPv6 Link Local address using MAC address
*
* @param[out] ip6 Derived IPv6 Link Local address.
* @param[in] mac_addr Input MAC Address.
*/
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.
* As output, it indicates Service Name of the service found using Service ID.
* @param[out] num_peer_records Number of peers discovered by corresponding service.
* @return
* - ESP_OK: succeed
* - ESP_FAIL: failed
*/
esp_err_t esp_wifi_nan_get_own_svc_info(uint8_t *own_svc_id, char *svc_name, int *num_peer_records);
/**
* brief Get a list of Peers discovered by the given Service.
*
* @param[inout] num_peer_records As input param, it stores max peers peer_record can hold.
* As output param, it specifies the actual number of peers this API returns.
* @param own_svc_id Service ID of own service.
* @param[out] peer_record Pointer to first peer record.
* @return
* - ESP_OK: succeed
* - ESP_FAIL: failed
*/
esp_err_t esp_wifi_nan_get_peer_records(int *num_peer_records, uint8_t own_svc_id, struct nan_peer_record *peer_record);
/**
* brief Find Peer's Service information using Peer MAC and optionally Service Name.
*
* @param svc_name Service Name of the published/subscribed service.
* @param peer_mac Peer's NAN Management Interface MAC address.
* @param[out] peer_info Peer's service information structure.
* @return
* - ESP_OK: succeed
* - ESP_FAIL: failed
*/
esp_err_t esp_wifi_nan_get_peer_info(char *svc_name, uint8_t *peer_mac, struct nan_peer_record *peer_info);
esp_err_t esp_wifi_nan_usd_stop(void);
/**
* @brief Get default configuration for USD publish operation.
@@ -250,6 +290,8 @@ wifi_nan_usd_config_t esp_wifi_usd_get_default_publish_cfg(void);
*/
wifi_nan_usd_config_t esp_wifi_usd_get_default_subscribe_cfg(void);
#endif /* CONFIG_ESP_WIFI_NAN_USD_ENABLE */
#ifdef __cplusplus
}
#endif
@@ -45,13 +45,13 @@
/* Global Variables */
static const char *TAG = "nan_app";
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
static EventGroupHandle_t nan_event_group;
static bool s_app_default_handlers_set = false;
static uint8_t null_mac[MACADDR_LEN] = {0};
static void *s_nan_data_lock = NULL;
static uint32_t s_fup_context;
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
#ifdef CONFIG_ESP_WIFI_NAN_USD_ENABLE
#endif /* CONFIG_ESP_WIFI_NAN_USD_ENABLE */
static bool s_usd_in_progress = false;
@@ -62,7 +62,7 @@ static const uint8_t s_wfa_oui[3] = {0x50, 0x6f, 0x9a};
#define NAN_SDEA_CTRL_FSD_GAS BIT(1)
#define NAN_SDEA_CTRL_DATAPATH_REQD BIT(2)
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
#define NAN_DATA_LOCK() os_mutex_lock(s_nan_data_lock)
#define NAN_DATA_UNLOCK() os_mutex_unlock(s_nan_data_lock)
@@ -760,7 +760,7 @@ void esp_nan_action_start(esp_netif_t *nan_netif)
s_nan_ctx.state = NAN_STARTED_BIT;
NAN_DATA_UNLOCK();
struct nan_callbacks nan_cb = {
struct nan_sync_callbacks nan_cb = {
.service_match = nan_app_service_match_cb,
.replied = nan_app_replied_cb,
.receive = nan_app_receive_cb,
@@ -794,13 +794,10 @@ void esp_nan_action_stop(void)
os_event_group_set_bits(nan_event_group, NAN_STOPPED_BIT);
}
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
esp_err_t esp_wifi_nan_start(const wifi_nan_config_t *nan_cfg)
esp_err_t esp_wifi_nan_sync_start(const wifi_nan_sync_config_t *nan_cfg)
{
wifi_mode_t mode;
esp_err_t ret;
s_usd_in_progress = false;
ret = esp_wifi_get_mode(&mode);
if (ret == ESP_ERR_WIFI_NOT_INIT) {
@@ -811,89 +808,48 @@ esp_err_t esp_wifi_nan_start(const wifi_nan_config_t *nan_cfg)
return ret;
}
#if (!CONFIG_ESP_WIFI_NAN_ENABLE)
if (!nan_cfg->discovery_flag) {
ESP_LOGE(TAG, "discovery_flag must be set when"
"ESP_WIFI_NAN_USD_ENABLE is enabled");
return ESP_FAIL;
}
#endif
/* XXX: For now, NAN-USD and NAN-Sync can not coexist. */
#ifdef CONFIG_ESP_WIFI_NAN_USD_ENABLE
if (nan_cfg->discovery_flag) {
/* NAN-USD Only */
ESP_RETURN_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_STA), "NAN-USD", "Setting STA mode failed");
ESP_RETURN_ON_ERROR(esp_wifi_start(), "NAN-USD", "Starting WiFi failed");
ESP_RETURN_ON_ERROR(esp_nan_usd_init(), "NAN-USD", "Failed to initialise NAN USD engine");
s_usd_in_progress = true;
ESP_LOGI(TAG, "NaN-USD Started");
return ESP_OK;
/* NAN-Synchronization Only */
wifi_config_t config = {0};
if (!s_nan_data_lock) {
ESP_LOGE(TAG, "NAN Data lock doesn't exist");
return ESP_FAIL;
}
#endif /* CONFIG_ESP_WIFI_NAN_USD_ENABLE */
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
else {
if (nan_cfg->discovery_flag) {
/* Should reach here only if ESP_WIFI_NAN_USD_ENABLE is disabled */
ESP_LOGE(TAG, "Can not set discovery_flag without "
"ESP_WIFI_NAN_USD_ENABLE enabled");
return ESP_FAIL;
}
/* NAN-Synchronization Only */
wifi_config_t config = {0};
if (!s_nan_data_lock) {
ESP_LOGE(TAG, "NAN Data lock doesn't exist");
return ESP_FAIL;
}
NAN_DATA_LOCK();
if (s_nan_ctx.state & NAN_STARTED_BIT) {
ESP_LOGI(TAG, "NAN already started");
NAN_DATA_UNLOCK();
return ESP_OK;
}
NAN_DATA_LOCK();
if (s_nan_ctx.state & NAN_STARTED_BIT) {
ESP_LOGI(TAG, "NAN already started");
NAN_DATA_UNLOCK();
ESP_RETURN_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_NAN), TAG, "Set mode NAN failed");
memcpy(&config.nan, nan_cfg, sizeof(wifi_nan_config_t));
ESP_RETURN_ON_ERROR(esp_wifi_set_config(WIFI_IF_NAN, &config), TAG, "Setting NAN config failed");
if (esp_wifi_start() != ESP_OK) {
ESP_LOGE(TAG, "Starting wifi failed");
NAN_DATA_LOCK();
s_nan_ctx.nan_netif = NULL;
NAN_DATA_UNLOCK();
return ESP_FAIL;
}
EventBits_t bits = os_event_group_wait_bits(nan_event_group, NAN_STARTED_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
if (!(bits & NAN_STARTED_BIT)) {
NAN_DATA_LOCK();
s_nan_ctx.nan_netif = NULL;
NAN_DATA_UNLOCK();
return ESP_FAIL;
}
return ESP_OK;
}
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
return ESP_FAIL;
NAN_DATA_UNLOCK();
ESP_RETURN_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_NAN), TAG, "Set mode NAN failed");
memcpy(&config.nan, nan_cfg, sizeof(wifi_nan_sync_config_t));
ESP_RETURN_ON_ERROR(esp_wifi_set_config(WIFI_IF_NAN, &config), TAG, "Setting NAN config failed");
if (esp_wifi_start() != ESP_OK) {
ESP_LOGE(TAG, "Starting wifi failed");
NAN_DATA_LOCK();
s_nan_ctx.nan_netif = NULL;
NAN_DATA_UNLOCK();
return ESP_FAIL;
}
EventBits_t bits = os_event_group_wait_bits(nan_event_group, NAN_STARTED_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
if (!(bits & NAN_STARTED_BIT)) {
NAN_DATA_LOCK();
s_nan_ctx.nan_netif = NULL;
NAN_DATA_UNLOCK();
return ESP_FAIL;
}
return ESP_OK;
}
esp_err_t esp_wifi_nan_stop(void)
esp_err_t esp_wifi_nan_sync_stop(void)
{
#ifdef CONFIG_ESP_WIFI_NAN_USD_ENABLE
if (s_usd_in_progress) {
s_usd_in_progress = false;
esp_nan_usd_deinit();
ESP_RETURN_ON_ERROR(esp_wifi_stop(), TAG, "Stopping NAN-USD failed");
ESP_LOGI(TAG, "NaN-USD Stopped");
return ESP_OK;
}
#endif /* CONFIG_ESP_WIFI_NAN_USD_ENABLE */
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
NAN_DATA_LOCK();
if (!(s_nan_ctx.state & NAN_STARTED_BIT)) {
ESP_LOGE(TAG, "NAN isn't started");
@@ -930,9 +886,9 @@ esp_err_t esp_wifi_nan_stop(void)
NAN_DATA_LOCK();
memset(&s_nan_ctx, 0, sizeof(nan_ctx_t));
NAN_DATA_UNLOCK();
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
return ESP_OK;
}
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
uint8_t esp_wifi_nan_publish_service(const wifi_nan_publish_cfg_t *publish_cfg)
{
@@ -983,7 +939,7 @@ uint8_t esp_wifi_nan_publish_service(const wifi_nan_publish_cfg_t *publish_cfg)
}
#endif /* CONFIG_ESP_WIFI_NAN_USD_ENABLE */
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
NAN_DATA_LOCK();
if (!(s_nan_ctx.state & NAN_STARTED_BIT)) {
ESP_LOGE(TAG, "NAN not started!");
@@ -1015,7 +971,7 @@ uint8_t esp_wifi_nan_publish_service(const wifi_nan_publish_cfg_t *publish_cfg)
fail:
NAN_DATA_UNLOCK();
return 0;
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
return 0;
}
@@ -1063,7 +1019,7 @@ uint8_t esp_wifi_nan_subscribe_service(const wifi_nan_subscribe_cfg_t *subscribe
}
#endif /* CONFIG_ESP_WIFI_NAN_USD_ENABLE */
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
NAN_DATA_LOCK();
if (!(s_nan_ctx.state & NAN_STARTED_BIT)) {
ESP_LOGE(TAG, "NAN not started!");
@@ -1093,7 +1049,7 @@ uint8_t esp_wifi_nan_subscribe_service(const wifi_nan_subscribe_cfg_t *subscribe
fail:
NAN_DATA_UNLOCK();
return 0;
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
return 0;
}
@@ -1132,7 +1088,7 @@ esp_err_t esp_wifi_nan_send_message(wifi_nan_followup_params_t *fup_params)
}
#endif /* CONFIG_ESP_WIFI_NAN_USD_ENABLE */
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
struct peer_svc_info *p_peer_svc;
NAN_DATA_LOCK();
p_peer_svc = nan_find_peer_svc(fup_params->inst_id,
@@ -1178,7 +1134,7 @@ esp_err_t esp_wifi_nan_send_message(wifi_nan_followup_params_t *fup_params)
ESP_LOGE(TAG, "Timeout, failed to send Follow-up message!");
ret = ESP_FAIL;
}
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
return ret;
}
@@ -1189,9 +1145,8 @@ esp_err_t esp_wifi_nan_cancel_service(uint8_t service_id)
if (s_usd_in_progress) {
return esp_nan_usd_cancel_service(service_id);
}
else
#endif /* CONFIG_ESP_WIFI_NAN_USD_ENABLE */
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
NAN_DATA_LOCK();
struct own_svc_info *p_own_svc = nan_find_own_svc(service_id);
@@ -1223,12 +1178,12 @@ fail:
done:
NAN_DATA_UNLOCK();
return ESP_OK;
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
return ESP_FAIL;
}
#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
#ifdef CONFIG_ESP_WIFI_NAN_SYNC_ENABLE
uint8_t esp_wifi_nan_datapath_req(wifi_nan_datapath_req_t *req)
{
uint8_t ndp_id = 0;
@@ -1497,9 +1452,32 @@ esp_err_t esp_wifi_nan_get_peer_info(char *svc_name, uint8_t *peer_mac, struct n
return ESP_FAIL;
}
}
#endif /* CONFIG_ESP_WIFI_NAN_ENABLE */
#endif /* CONFIG_ESP_WIFI_NAN_SYNC_ENABLE */
#ifdef CONFIG_ESP_WIFI_NAN_USD_ENABLE
esp_err_t esp_wifi_nan_usd_start(void)
{
if (!s_usd_in_progress) {
ESP_RETURN_ON_ERROR(esp_wifi_set_mode(WIFI_MODE_STA), "NAN-USD", "Setting STA mode failed");
ESP_RETURN_ON_ERROR(esp_nan_usd_init(), "NAN-USD", "Failed to initialise NAN USD engine");
s_usd_in_progress = true;
ESP_LOGI(TAG, "NaN-USD Started");
return ESP_OK;
}
return ESP_OK;
}
esp_err_t esp_wifi_nan_usd_stop(void)
{
if (s_usd_in_progress) {
s_usd_in_progress = false;
esp_nan_usd_deinit();
ESP_LOGI(TAG, "NaN-USD Stopped");
return ESP_OK;
}
return ESP_OK;
}
wifi_nan_usd_config_t esp_wifi_usd_get_default_publish_cfg(void)
{
wifi_country_t country;
@@ -38,7 +38,7 @@ static void nan_sta_stop_handler(void *arg, esp_event_base_t event_base,
int32_t event_id, void *event_data)
{
if (event_id == WIFI_EVENT_STA_STOP) {
esp_wifi_nan_stop();
esp_wifi_nan_usd_stop();
}
}
@@ -18,6 +18,10 @@ Application Examples
- :example:`wifi/wifi_aware/nan_subscriber` demonstrates how to use the NAN protocol to discover other devices that publishes the required service in the proximity, and communicate with them either by sending a message or initiating a datapath.
- :example:`wifi/wifi_aware/usd_publisher` demonstrates how to use lightweight NAN Unsynchronized Service Discovery (NAN-USD) to advertise a service to nearby devices without forming NAN clusters. It walks through bringing up USD, publishing a service, responding to subscribers with follow-up messages, and returning to the idle state once discovery completes.
- :example:`wifi/wifi_aware/usd_subscriber` demonstrates how to use the lightweight NAN Unsynchronized Service Discovery (NAN-USD) protocol to discover services advertised by nearby devices and interact with them. It covers enabling USD discovery, subscribing to services, handling follow-up exchanges, and terminating discovery after the session ends.
API Reference
-------------
@@ -46,4 +46,18 @@ The following Wi-Fi functions have been modified.
- **WPS:** The function ``esp_wifi_wps_start`` no longer accepts a ``timeout_ms`` argument. It should now be called as ``esp_wifi_wps_start(void)``.
- **NAN:** The function argument ``ndp_resp_needed`` of ``esp_wifi_nan_publish_service`` has been moved to structure ``wifi_nan_publish_cfg_t``.
- **NAN:**
- NAN API's are modified so that they can be shared between two separate NAN modes of operation called NAN Synchronization (NAN-Sync) and NAN Unsynchronized Discovery (NAN-USD) roles:
- ``esp_wifi_nan_sync_start`` and ``esp_wifi_nan_sync_stop`` replace the previous ``esp_wifi_nan_start`` / ``esp_wifi_nan_stop`` pair.
- Functions starting with prefix ``esp_wifi_nan_*`` are shared by both NAN-Sync and NAN-USD modes (for example ``esp_wifi_nan_publish_service`` and ``esp_wifi_nan_subscribe_service``).
- Use ``WIFI_NAN_SYNC_CONFIG_DEFAULT()`` instead of the former ``WIFI_NAN_CONFIG_DEFAULT()`` macro when initialising synchronized NAN configuration.
- The structure ``wifi_nan_config_t`` has been renamed to ``wifi_nan_sync_config_t``; update declarations such as ``wifi_config_t.nan`` to use the new type.
- NAN datapath APIs and associated structures are valid for NAN Synchronization (NAN-Sync) clusters only.
- Wi-Fi events ``WIFI_EVENT_NAN_STARTED`` / ``WIFI_EVENT_NAN_STOPPED`` have been renamed to ``WIFI_EVENT_NAN_SYNC_STARTED`` / ``WIFI_EVENT_NAN_SYNC_STOPPED``.
- The function argument ``ndp_resp_needed`` of ``esp_wifi_nan_publish_service`` has been moved to structure ``wifi_nan_publish_cfg_t``.
- The structure ``wifi_nan_wfa_ssi_t`` now declares its ``proto`` field as ``uint8_t`` (previously ``wifi_nan_svc_proto_t``). Update code that stores pointers to this field or relies on its size to treat it as a single octet.
- The structures ``wifi_nan_publish_cfg_t`` and ``wifi_nan_subscribe_cfg_t`` now include a ``usd_discovery_flag`` bitfield together with corresponding ``wifi_nan_usd_config_t`` members. Add designated initialisers for these fields when constructing the structures to avoid accidental field shifts.
- **Off-Channel Operations:**
- The structure :cpp:struct:`wifi_action_tx_req_t` now includes a ``bssid`` field that is placed in Address3 of the transmitted action frame. Initialise this field explicitly; leaving it all zeros retains the previous behaviour where the Wi-Fi driver inserts the broadcast address, so frames do not carry unintended BSSID values.
- The structure :cpp:struct:`wifi_roc_req_t` now includes an ``allow_broadcast`` flag that controls whether broadcast and multicast action frames are passed to the ``rx_cb`` callback during remain-on-channel operations. Existing applications should review the default ``false`` value and enable it when discovery of broadcast peers is required. Frames whose Address3/BSSID is already broadcast continue to reach the callback even when ``allow_broadcast`` remains ``false``.
@@ -46,5 +46,18 @@ Wi-Fi
- **WPS** 函数 ``esp_wifi_wps_start`` 不再接受 ``timeout_ms`` 参数。现在应调用为 ``esp_wifi_wps_start(void)``
- **NAN** 函数 ``esp_wifi_nan_publish_service`` 的参数 ``ndp_resp_needed`` 已移至结构体 ``wifi_nan_publish_cfg_t``
- **NAN**
- 已调整 NAN API,使其可在两个独立的 NAN 工作模式间共享:NAN 同步(NAN-Sync)与 NAN 非同步发现(NAN-USD):
- ``esp_wifi_nan_sync_start````esp_wifi_nan_sync_stop`` 取代原有的 ``esp_wifi_nan_start`` / ``esp_wifi_nan_stop``
- 以 ``esp_wifi_nan_*`` 为前缀的函数在 NAN-Sync 与 NAN 非同步发现(NAN-USD) 模式间通用(例如 ``esp_wifi_nan_publish_service````esp_wifi_nan_subscribe_service``)。
- 初始化 NAN 同步配置时,请使用 ``WIFI_NAN_SYNC_CONFIG_DEFAULT()``,原 ``WIFI_NAN_CONFIG_DEFAULT()`` 已停用。
- 结构体 ``wifi_nan_config_t`` 已重命名为 ``wifi_nan_sync_config_t``,例如需将 ``wifi_config_t.nan`` 等声明更新为新类型。
- NAN 数据通道相关的 API 与结构体目前仅适用于 NAN 同步(NAN-Sync)集群。
- Wi-Fi 事件 ``WIFI_EVENT_NAN_STARTED`` / ``WIFI_EVENT_NAN_STOPPED`` 已重命名为 ``WIFI_EVENT_NAN_SYNC_STARTED`` / ``WIFI_EVENT_NAN_SYNC_STOPPED``
- 函数 ``esp_wifi_nan_publish_service`` 的参数 ``ndp_resp_needed`` 已移至结构体 ``wifi_nan_publish_cfg_t``
- 结构体 ``wifi_nan_wfa_ssi_t`` 中的 ``proto`` 字段类型现为 ``uint8_t`` (之前为 ``wifi_nan_svc_proto_t``)。如果代码存储该字段的指针或依赖其大小,请按单个八位字节处理。
- 结构体 ``wifi_nan_publish_cfg_t````wifi_nan_subscribe_cfg_t`` 新增 ``usd_discovery_flag`` 位域及对应的 ``wifi_nan_usd_config_t`` 成员。构造这些结构体时,请为新增字段提供指定初始化器,以避免字段偏移。
- **离信道操作:**
- 结构体 :cpp:struct:`wifi_action_tx_req_t` 新增 ``bssid`` 字段,该字段会写入发送动作帧的 Address3。请显式初始化该字段;保持全零时将沿用之前的行为,由 Wi-Fi 驱动填入广播地址,从而避免帧携带意外的 BSSID。
- 结构体 :cpp:struct:`wifi_roc_req_t` 新增 ``allow_broadcast`` 标志,用于控制在驻留信道期间是否将广播/组播动作帧传递给 ``rx_cb`` 回调。现有应用应结合默认值 ``false`` 评估是否需要启用该选项,以便在需要时进行广播节点发现。若动作帧的 Address3/BSSID 本身为广播地址,即便 ``allow_broadcast`` 保持 ``false``,回调仍会收到该帧。
@@ -234,7 +234,7 @@ static int wifi_cmd_nan_disc(int argc, char **argv)
}
if (nan_args.init->count) {
wifi_nan_config_t nan_cfg = WIFI_NAN_CONFIG_DEFAULT();
wifi_nan_sync_config_t nan_cfg = WIFI_NAN_SYNC_CONFIG_DEFAULT();
if (nan_args.master_pref->count) {
nan_cfg.master_pref = nan_args.master_pref->ival[0];
@@ -250,7 +250,7 @@ static int wifi_cmd_nan_disc(int argc, char **argv)
g_nan_netif = esp_netif_create_default_wifi_nan();
}
if ((esp_wifi_nan_start(&nan_cfg)) != ESP_OK) {
if ((esp_wifi_nan_sync_start(&nan_cfg)) != ESP_OK) {
ESP_LOGI(TAG, "Failed to start NAN");
esp_netif_destroy_default_wifi(g_nan_netif);
g_nan_netif = NULL;
@@ -266,7 +266,7 @@ static int wifi_cmd_nan_disc(int argc, char **argv)
}
if (nan_args.deinit->count) {
ret = esp_wifi_nan_stop();
ret = esp_wifi_nan_sync_stop();
if (ret != ESP_OK) {
ESP_LOGI(TAG, "Failed to stop NAN");
@@ -1 +1 @@
CONFIG_ESP_WIFI_NAN_ENABLE=y
CONFIG_ESP_WIFI_NAN_SYNC_ENABLE=y
@@ -81,10 +81,10 @@ void wifi_nan_publish(void)
&instance_any_id));
/* Start NAN Discovery */
wifi_nan_config_t nan_cfg = WIFI_NAN_CONFIG_DEFAULT();
wifi_nan_sync_config_t nan_cfg = WIFI_NAN_SYNC_CONFIG_DEFAULT();
esp_netif_create_default_wifi_nan();
esp_wifi_nan_start(&nan_cfg);
esp_wifi_nan_sync_start(&nan_cfg);
ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
WIFI_EVENT_NDP_INDICATION,
@@ -1 +1 @@
CONFIG_ESP_WIFI_NAN_ENABLE=y
CONFIG_ESP_WIFI_NAN_SYNC_ENABLE=y
@@ -177,10 +177,10 @@ void wifi_nan_subscribe(void)
#endif
/* Start NAN Discovery */
wifi_nan_config_t nan_cfg = WIFI_NAN_CONFIG_DEFAULT();
wifi_nan_sync_config_t nan_cfg = WIFI_NAN_SYNC_CONFIG_DEFAULT();
esp_netif_t *nan_netif = esp_netif_create_default_wifi_nan();
(void) nan_netif;
esp_wifi_nan_start(&nan_cfg);
esp_wifi_nan_sync_start(&nan_cfg);
/* Subscribe a service */
uint8_t sub_id;
@@ -1 +1 @@
CONFIG_ESP_WIFI_NAN_ENABLE=y
CONFIG_ESP_WIFI_NAN_SYNC_ENABLE=y
@@ -59,9 +59,10 @@ void wifi_usd_publish(void)
NULL,
&instance_any_id));
ESP_RETURN_VOID_ON_ERROR(esp_wifi_start(), TAG, "NAN-USD failed to start Wi-Fi");
/* Start USD-NAN Discovery */
wifi_nan_config_t usd_nan_cfg = WIFI_USD_NAN_CONFIG_DEFAULT();
ESP_RETURN_VOID_ON_ERROR(esp_wifi_nan_start(&usd_nan_cfg), TAG, "NAN-USD initialization failed");
ESP_RETURN_VOID_ON_ERROR(esp_wifi_nan_usd_start(), TAG, "NAN-USD initialization failed");
wifi_nan_publish_cfg_t publish_cfg = {
.service_name = EXAMPLE_USD_SVC_NAME,
@@ -101,7 +102,7 @@ void wifi_usd_publish(void)
}
esp_wifi_nan_cancel_service(g_publish_id);
esp_wifi_nan_stop();
esp_wifi_nan_usd_stop();
}
void initialise_wifi(void)
@@ -110,6 +111,7 @@ void initialise_wifi(void)
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
}
void app_main(void)
@@ -1 +1,2 @@
CONFIG_ESP_WIFI_NAN_USD_ENABLE=y
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
@@ -87,9 +87,10 @@ void wifi_usd_subscribe(void)
NULL,
&instance_any_id));
ESP_RETURN_VOID_ON_ERROR(esp_wifi_start(), TAG, "NAN-USD failed to start Wi-Fi");
/* Start NAN-USD Discovery */
wifi_nan_config_t nan_usd_cfg = WIFI_USD_NAN_CONFIG_DEFAULT();
esp_wifi_nan_start(&nan_usd_cfg);
ESP_RETURN_VOID_ON_ERROR(esp_wifi_nan_usd_start(), TAG, "NAN-USD initialization failed");
wifi_nan_subscribe_cfg_t subscribe_cfg = {
.service_name = EXAMPLE_USD_SVC_NAME,
@@ -134,6 +135,7 @@ void initialise_wifi(void)
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_NULL));
}
void app_main(void)
@@ -1 +1,2 @@
CONFIG_ESP_WIFI_NAN_USD_ENABLE=y
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
+30
View File
@@ -624,6 +624,10 @@
re: "error: implicit declaration of function 'esp_wifi_config_espnow_rate'"
hint: "The function 'esp_wifi_config_espnow_rate' has been removed. Use 'esp_now_set_peer_rate_config' instead."
-
re: "(initialization|assignment) of 'wifi_nan_svc_proto_t \\*' from incompatible pointer type 'uint8_t \\*'"
hint: "The field 'proto' in structure 'wifi_nan_wfa_ssi_t' is now declared as 'uint8_t'. Update pointer usage accordingly, for example by using a 'uint8_t *' or copying the enum value into a separate variable."
-
re: "error: too many arguments to function 'esp_wifi_wps_start'"
hint: "The function 'esp_wifi_wps_start' no longer accepts a 'timeout_ms' argument."
@@ -656,10 +660,36 @@
re: "error: 'peer_svc_info' undeclared"
hint: "The field 'peer_svc_info' from structure 'wifi_event_nan_receive_t' has been removed. Please use the equivalent fields 'ssi' and 'ssi_len' instead."
-
re: "error: 'WIFI_EVENT_NAN_STARTED' undeclared"
hint: "The Wi-Fi NAN event 'WIFI_EVENT_NAN_STARTED' has been renamed to 'WIFI_EVENT_NAN_SYNC_STARTED'."
-
re: "error: 'WIFI_EVENT_NAN_STOPPED' undeclared"
hint: "The Wi-Fi NAN event 'WIFI_EVENT_NAN_STOPPED' has been renamed to 'WIFI_EVENT_NAN_SYNC_STOPPED'."
-
re: "error: too few arguments to function 'esp_wifi_nan_publish_service'"
hint: "The function argument 'ndp_resp_needed' of 'esp_wifi_nan_publish_service' has been moved to structure 'wifi_nan_publish_cfg_t'."
-
re: "error: implicit declaration of function '{}'"
hint: "The NAN synchronization API '{}' has been renamed to '{}'."
variables:
-
re_variables: ['esp_wifi_nan_start']
hint_variables: ['esp_wifi_nan_start', 'esp_wifi_nan_sync_start']
-
re_variables: ['esp_wifi_nan_stop']
hint_variables: ['esp_wifi_nan_stop', 'esp_wifi_nan_sync_stop']
-
re_variables: ['WIFI_NAN_CONFIG_DEFAULT']
hint_variables: ['WIFI_NAN_CONFIG_DEFAULT', 'WIFI_NAN_SYNC_CONFIG_DEFAULT']
-
re: "error: unknown type name 'wifi_nan_config_t'"
hint: "The structure 'wifi_nan_config_t' has been renamed to 'wifi_nan_sync_config_t'."
-
re: "error: '(WIFI_REASON_ASSOC_EXPIRE|WIFI_REASON_NOT_AUTHED|WIFI_REASON_NOT_ASSOCED)' undeclared"
hint: "The Wi-Fi disconnection reason codes '{0}' have been removed. Please use '{1}', '{2}', and '{3}' respectively."