Skip to content

Commit

Permalink
Merge branch 'feature/nan_datapath' into 'master'
Browse files Browse the repository at this point in the history
NAN Datapath support and console example

Closes WIFI-1223

See merge request espressif/esp-idf!13593
  • Loading branch information
jack0c committed Mar 10, 2023
2 parents a8948eb + 4c76af3 commit d5f53fb
Show file tree
Hide file tree
Showing 53 changed files with 3,302 additions and 43 deletions.
7 changes: 4 additions & 3 deletions components/esp_hw_support/include/esp_interface.h
Expand Up @@ -15,9 +15,10 @@ extern "C" {
#endif

typedef enum {
ESP_IF_WIFI_STA = 0, /**< ESP32 station interface */
ESP_IF_WIFI_AP, /**< ESP32 soft-AP interface */
ESP_IF_ETH, /**< ESP32 ethernet interface */
ESP_IF_WIFI_STA = 0, /**< Station interface */
ESP_IF_WIFI_AP, /**< Soft-AP interface */
ESP_IF_WIFI_NAN, /**< NAN interface */
ESP_IF_ETH, /**< Ethernet interface */
ESP_IF_MAX
} esp_interface_t;

Expand Down
6 changes: 5 additions & 1 deletion components/esp_netif/esp_netif_defaults.c
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -28,6 +28,10 @@ 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
const esp_netif_inherent_config_t _g_esp_netif_inherent_nan_config = ESP_NETIF_INHERENT_DEFAULT_WIFI_NAN();
#endif

const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config = ESP_NETIF_INHERENT_DEFAULT_ETH();

#ifdef CONFIG_PPP_SUPPORT
Expand Down
40 changes: 40 additions & 0 deletions components/esp_netif/include/esp_netif_defaults.h
Expand Up @@ -64,6 +64,18 @@ extern "C" {
}
#endif

#define ESP_NETIF_INHERENT_DEFAULT_WIFI_NAN() \
{ \
.flags = 0, \
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
.get_ip_event = 0, \
.lost_ip_event = 0, \
.if_key = "WIFI_NAN_DEF", \
.if_desc = "nan", \
.route_prio = 10 \
};

#define ESP_NETIF_INHERENT_DEFAULT_ETH() \
{ \
.flags = (esp_netif_flags_t)(ESP_NETIF_IPV4_ONLY_FLAGS(ESP_NETIF_DHCP_CLIENT) | ESP_NETIF_DEFAULT_ARP_FLAGS | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \
Expand Down Expand Up @@ -130,6 +142,18 @@ extern "C" {
}
#endif

#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
/**
* @brief Default configuration reference of WIFI NAN
*/
#define ESP_NETIF_DEFAULT_WIFI_NAN() \
{ \
.base = ESP_NETIF_BASE_DEFAULT_WIFI_NAN, \
.driver = NULL, \
.stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_NAN, \
}
#endif

/**
* @brief Default configuration reference of WIFI STA
*/
Expand Down Expand Up @@ -164,6 +188,13 @@ extern "C" {
#define ESP_NETIF_BASE_DEFAULT_WIFI_AP &_g_esp_netif_inherent_ap_config
#endif

#ifdef CONFIG_ESP_WIFI_NAN_ENABLE
/**
* @brief Default base config (esp-netif inherent) of WIFI NAN
*/
#define ESP_NETIF_BASE_DEFAULT_WIFI_NAN &_g_esp_netif_inherent_nan_config
#endif

/**
* @brief Default base config (esp-netif inherent) of ethernet interface
*/
Expand All @@ -183,6 +214,9 @@ 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
#define ESP_NETIF_NETSTACK_DEFAULT_WIFI_NAN _g_esp_netif_netstack_default_wifi_nan
#endif
#ifdef CONFIG_PPP_SUPPORT
#define ESP_NETIF_NETSTACK_DEFAULT_PPP _g_esp_netif_netstack_default_ppp
#endif
Expand All @@ -199,6 +233,9 @@ 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
extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_nan;
#endif
#ifdef CONFIG_PPP_SUPPORT
extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp;
#endif
Expand All @@ -211,6 +248,9 @@ 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
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;
#ifdef CONFIG_PPP_SUPPORT
extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ppp_config;
Expand Down
9 changes: 8 additions & 1 deletion components/esp_netif/include/lwip/esp_netif_net_stack.h
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -65,6 +65,13 @@ err_t wlanif_init_ap(struct netif *netif);
*/
err_t wlanif_init_sta(struct netif *netif);

/**
* @brief LWIP's network stack init function for WiFi Aware interface (NAN)
* @param netif LWIP's network interface handle
* @return ERR_OK on success
*/
err_t wlanif_init_nan(struct netif *netif);

/**
* @brief LWIP's network stack input packet function for WiFi (both STA/AP)
* @param h LWIP's network interface handle
Expand Down
7 changes: 7 additions & 0 deletions components/esp_netif/lwip/esp_netif_lwip_defaults.c
Expand Up @@ -48,6 +48,12 @@ static const struct esp_netif_netstack_config s_wifi_netif_config_sta = {
.input_fn = wlanif_input
}
};
static const struct esp_netif_netstack_config s_wifi_netif_config_nan = {
.lwip = {
.init_fn = wlanif_init_nan,
.input_fn = wlanif_input
}
};

#if defined(CONFIG_PPP_SUPPORT)
static const struct esp_netif_netstack_config s_netif_config_ppp = {
Expand All @@ -64,6 +70,7 @@ const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp = &s_n

const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_eth = &s_eth_netif_config;
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_sta = &s_wifi_netif_config_sta;
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_nan = &s_wifi_netif_config_nan;
const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_ap = &s_wifi_netif_config_ap;

#endif /*CONFIG_ESP_NETIF_TCPIP_LWIP*/
6 changes: 6 additions & 0 deletions components/esp_netif/lwip/netif/wlanif.c
Expand Up @@ -230,3 +230,9 @@ err_t wlanif_init_ap(struct netif *netif) {
netif->name[1] = 'p';
return wlanif_init(netif);
}

err_t wlanif_init_nan(struct netif *netif) {
netif->name[0] = 'n';
netif->name[1] = 'a';
return wlanif_init(netif);
}
7 changes: 6 additions & 1 deletion components/esp_wifi/CMakeLists.txt
Expand Up @@ -29,10 +29,15 @@ if(CONFIG_ESP_WIFI_ENABLED)
list(APPEND srcs
"src/smartconfig_ack.c")
endif()

if(CONFIG_ESP_WIFI_NAN_ENABLE)
list(APPEND srcs "wifi_apps/src/nan_app.c")
endif()

endif()

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "include"
INCLUDE_DIRS "include" "wifi_apps/include"
REQUIRES esp_event esp_phy esp_netif
PRIV_REQUIRES driver esptool_py esp_pm esp_timer nvs_flash
wpa_supplicant hal lwip esp_coex ${extra_priv_requires}
Expand Down
8 changes: 7 additions & 1 deletion components/esp_wifi/Kconfig
Expand Up @@ -397,9 +397,15 @@ menu "Wi-Fi"
The number of hardware keys for encryption is fixed. And the espnow and SoftAP share the same
hardware keys. So this configuration will affect the maximum connection number of SoftAP.
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"
default n
depends on SOC_WIFI_NAN_SUPPORT
help
Enable WiFi Aware (NAN) feature.

config ESP_WIFI_ENABLE_WIFI_TX_STATS
bool "Enable Wi-Fi transmission statistics"
depends on SOC_WIFI_HE_SUPPORT
Expand Down
84 changes: 84 additions & 0 deletions components/esp_wifi/include/esp_private/wifi.h
Expand Up @@ -639,6 +639,90 @@ void esp_wifi_beacon_monitor_configure(wifi_beacon_monitor_config_t *config);
*/
void esp_wifi_internal_mac_sleep_configure(bool light_sleep_enable, bool modem_state_enable);

/**
* @brief Start Publishing a service in the NAN cluster
*
* @attention This API should be called after esp_wifi_start() in NAN Mode.
*
* @param publish_cfg Configuration parameters for publishing a service.
* @param id Identifier for the Publish service.
* @param cancel Cancel the service identified by the id.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_nan_internal_publish_service(const wifi_nan_publish_cfg_t *publish_cfg,
uint8_t *id, bool cancel);

/**
* @brief Subscribe for a service within the NAN cluster
*
* @attention This API should be called after esp_wifi_start() in NAN Mode.
*
* @param subscribe_cfg Configuration parameters for subscribing for a service.
* @param id Identifier for the Subscribe service.
* @param cancel Cancel the service identified by the id.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_nan_internal_subscribe_service(const wifi_nan_subscribe_cfg_t *subscribe_cfg,
uint8_t *id, bool cancel);

/**
* @brief Send Follow-up to the Publisher with matching service
*
* @attention This API should be called after WIFI_EVENT_NAN_SVC_MATCH event is received.
*
* @param fup_params Configuration parameters for sending a Follow-up to the Peer.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_nan_internal_send_followup(const wifi_nan_followup_params_t *fup_params);

/**
* @brief Send Datapath Request to the Publisher with matching service
*
* @attention This API should be called after WIFI_EVENT_NAN_SVC_MATCH event is received.
*
* @param req NAN Datapath Request parameters.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_nan_internal_datapath_req(wifi_nan_datapath_req_t *req, uint8_t *ndp_id);

/**
* @brief Send Datapath Response to accept or reject the received request
*
* @attention This API should be called on the Publisher after receiving WIFI_EVENT_NDP_INDICATION event.
*
* @param resp NAN Datapath Response parameters.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_nan_internal_datapath_resp(wifi_nan_datapath_resp_t *resp);

/**
* @brief End NAN Datapath that is active
*
* @attention This API should be called after receiving WIFI_EVENT_NDP_CONFIRM event.
*
* @param req NAN Datapath end request parameters.
*
* @return
* - ESP_OK: succeed
* - others: failed
*/
esp_err_t esp_nan_internal_datapath_end(wifi_nan_datapath_end_req_t *req);

#ifdef __cplusplus
}
#endif
Expand Down
23 changes: 13 additions & 10 deletions components/esp_wifi/include/esp_wifi.h
Expand Up @@ -268,7 +268,7 @@ esp_err_t esp_wifi_deinit(void);
/**
* @brief Set the WiFi operating mode
*
* Set the WiFi operating mode as station, soft-AP or station+soft-AP,
* Set the WiFi operating mode as station, soft-AP, station+soft-AP or NAN.
* The default mode is station mode.
*
* @param mode WiFi operating mode
Expand All @@ -295,9 +295,10 @@ esp_err_t esp_wifi_get_mode(wifi_mode_t *mode);

/**
* @brief Start WiFi according to current configuration
* If mode is WIFI_MODE_STA, it create station control block and start station
* If mode is WIFI_MODE_AP, it create soft-AP control block and start soft-AP
* If mode is WIFI_MODE_APSTA, it create soft-AP and station control block and start soft-AP and station
* If mode is WIFI_MODE_STA, it creates station control block and starts station
* If mode is WIFI_MODE_AP, it creates soft-AP control block and starts soft-AP
* If mode is WIFI_MODE_APSTA, it creates soft-AP and station control block and starts soft-AP and station
* If mode is WIFI_MODE_NAN, it creates NAN control block and starts NAN
*
* @return
* - ESP_OK: succeed
Expand All @@ -311,9 +312,10 @@ esp_err_t esp_wifi_start(void);

/**
* @brief Stop WiFi
* If mode is WIFI_MODE_STA, it stop station and free station control block
* If mode is WIFI_MODE_AP, it stop soft-AP and free soft-AP control block
* If mode is WIFI_MODE_APSTA, it stop station/soft-AP and free station/soft-AP control block
* If mode is WIFI_MODE_STA, it stops station and frees station control block
* If mode is WIFI_MODE_AP, it stops soft-AP and frees soft-AP control block
* If mode is WIFI_MODE_APSTA, it stops station/soft-AP and frees station/soft-AP control block
* If mode is WIFI_MODE_NAN, it stops NAN and frees NAN control block
*
* @return
* - ESP_OK: succeed
Expand Down Expand Up @@ -790,16 +792,16 @@ esp_err_t esp_wifi_set_promiscuous_ctrl_filter(const wifi_promiscuous_filter_t *
esp_err_t esp_wifi_get_promiscuous_ctrl_filter(wifi_promiscuous_filter_t *filter);

/**
* @brief Set the configuration of the STA or AP
* @brief Set the configuration of the STA, AP or NAN
*
* @attention 1. This API can be called only when specified interface is enabled, otherwise, API fail
* @attention 2. For station configuration, bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.
* @attention 3. ESP devices are limited to only one channel, so when in the soft-AP+station mode, the soft-AP will adjust its channel automatically to be the same as
* the channel of the station.
* @attention 4. The configuration will be stored in NVS
* @attention 4. The configuration will be stored in NVS for station and soft-AP
*
* @param interface interface
* @param conf station or soft-AP configuration
* @param conf station, soft-AP or NAN configuration
*
* @return
* - ESP_OK: succeed
Expand Down Expand Up @@ -1345,6 +1347,7 @@ esp_err_t esp_wifi_sta_get_aid(uint16_t *aid);
* - ESP_OK: succeed
*/
esp_err_t esp_wifi_sta_get_negotiated_phymode(wifi_phy_mode_t *phymode);

#ifdef __cplusplus
}
#endif
Expand Down
22 changes: 22 additions & 0 deletions components/esp_wifi/include/esp_wifi_crypto_types.h
Expand Up @@ -365,6 +365,26 @@ typedef uint8_t * (*esp_ccmp_encrypt_t)(const uint8_t *tk, uint8_t *frame, size_
typedef int (*esp_aes_gmac_t)(const uint8_t *key, size_t keylen, const uint8_t *iv, size_t iv_len,
const uint8_t *aad, size_t aad_len, uint8_t *mic);

/**
* @brief SHA256 hash for data vector
* @num_elem: Number of elements in the data vector
* @addr: Pointers to the data areas
* @len: Lengths of the data blocks
* @mac: Buffer for the hash
* Returns: 0 on success, -1 on failure
*/
typedef int (*esp_sha256_vector_t)(size_t num_elem, const uint8_t *addr[], const size_t *len, uint8_t *buf);

/**
* @brief CRC32 value in little endian.
*
* @param crc: Initial CRC value (result of last calculation or 0 for the first time)
* @param buf: Data buffer that used to calculate the CRC value
* @param len: Length of the data buffer
* @return CRC32 value
*/
typedef uint32_t (*esp_crc32_le_t)(uint32_t crc, uint8_t const *buf, uint32_t len);

/**
* @brief The crypto callback function structure used when do station security connect.
* The structure can be set as software crypto or the crypto optimized by device's
Expand Down Expand Up @@ -398,6 +418,8 @@ typedef struct {
esp_ccmp_decrypt_t ccmp_decrypt;
esp_ccmp_encrypt_t ccmp_encrypt;
esp_aes_gmac_t aes_gmac;
esp_sha256_vector_t sha256_vector;
esp_crc32_le_t crc32;
}wpa_crypto_funcs_t;

/**
Expand Down

0 comments on commit d5f53fb

Please sign in to comment.