From 2a715e4203f1c4860aa89a20f2f8c821f8b27a57 Mon Sep 17 00:00:00 2001 From: yinqingzhao Date: Fri, 25 Oct 2024 19:33:55 +0800 Subject: [PATCH] feat(twt): twt add parameter to enable keep alive --- components/esp_wifi/include/esp_wifi_he.h | 9 +++++++++ components/esp_wifi/include/esp_wifi_he_types.h | 1 + components/esp_wifi/lib | 2 +- examples/wifi/itwt/main/Kconfig.projbuild | 6 ++++++ examples/wifi/itwt/main/itwt.c | 12 ++++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/components/esp_wifi/include/esp_wifi_he.h b/components/esp_wifi/include/esp_wifi_he.h index 67880654ab..28da491264 100644 --- a/components/esp_wifi/include/esp_wifi_he.h +++ b/components/esp_wifi/include/esp_wifi_he.h @@ -143,6 +143,15 @@ esp_err_t esp_wifi_enable_rx_statistics(bool rx_stats, bool rx_mu_stats); */ esp_err_t esp_wifi_enable_tx_statistics(esp_wifi_aci_t aci, bool tx_stats); +/** + * @brief Set WiFi TWT config + * + * @param[in] config pointer to the WiFi TWT configure structure. + * + * @return + * - ESP_OK: succeed + */ +esp_err_t esp_wifi_sta_twt_config(wifi_twt_config_t *config); #ifdef __cplusplus } diff --git a/components/esp_wifi/include/esp_wifi_he_types.h b/components/esp_wifi/include/esp_wifi_he_types.h index 397cd088f5..4e49c90a78 100644 --- a/components/esp_wifi/include/esp_wifi_he_types.h +++ b/components/esp_wifi/include/esp_wifi_he_types.h @@ -252,6 +252,7 @@ typedef enum { /** Argument structure for twt configuration */ typedef struct { bool post_wakeup_event; /**< post twt wakeup event */ + bool twt_enable_keep_alive; /**< twt enable send qos null to keep alive */ } wifi_twt_config_t; /** Argument structure for WIFI_EVENT_TWT_WAKEUP event */ diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index eaa36d56a5..e94341d8f6 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit eaa36d56a58ba6ab8d16ebce7683a3b93b690d41 +Subproject commit e94341d8f69625a0c01ce19acc47b05039f849bb diff --git a/examples/wifi/itwt/main/Kconfig.projbuild b/examples/wifi/itwt/main/Kconfig.projbuild index 9eb0e46e7b..8d8dd52b2e 100644 --- a/examples/wifi/itwt/main/Kconfig.projbuild +++ b/examples/wifi/itwt/main/Kconfig.projbuild @@ -38,6 +38,12 @@ menu "Example Configuration" help Set static gateway address. + config EXAMPLE_TWT_ENABLE_KEEP_ALIVE_QOS_NULL + bool "enable keep alive qos null" + default n + help + Enable send QOS NULL to keep alive during TWT. + menu "iTWT Configuration" config EXAMPLE_ITWT_TRIGGER_ENABLE bool "trigger-enabled" diff --git a/examples/wifi/itwt/main/itwt.c b/examples/wifi/itwt/main/itwt.c index 7706afdb8b..6722beb56c 100644 --- a/examples/wifi/itwt/main/itwt.c +++ b/examples/wifi/itwt/main/itwt.c @@ -48,6 +48,12 @@ static const char *TAG = "itwt"; #define DEFAULT_PWD CONFIG_EXAMPLE_WIFI_PASSWORD #define ITWT_SETUP_SUCCESS 1 +#if CONFIG_EXAMPLE_TWT_ENABLE_KEEP_ALIVE_QOS_NULL +bool keep_alive_enabled = true; +#else +bool keep_alive_enabled = false; +#endif + #if CONFIG_EXAMPLE_ITWT_TRIGGER_ENABLE uint8_t trigger_enabled = 1; #else @@ -259,6 +265,12 @@ static void wifi_itwt(void) ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA)); ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config)); + wifi_twt_config_t wifi_twt_config = { + .post_wakeup_event = false, + .twt_enable_keep_alive = keep_alive_enabled, + }; + ESP_ERROR_CHECK(esp_wifi_sta_twt_config(&wifi_twt_config)); + esp_wifi_set_bandwidth(WIFI_IF_STA, WIFI_BW_HT20); esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AX); esp_wifi_set_ps(WIFI_PS_MIN_MODEM);