Merge branch 'feature/add_channel_switch_api_for_espnow' into 'master'

feat(wifi): Added switch channel api for espnow

Closes WIFI-6379 and WIFI-5499

See merge request espressif/esp-idf!38767
This commit is contained in:
Jiang Jiang Jian
2025-09-20 13:33:33 +08:00
6 changed files with 57 additions and 1 deletions

View File

@@ -102,6 +102,31 @@ typedef wifi_tx_info_t esp_now_send_info_t;
*/ */
typedef wifi_tx_rate_config_t esp_now_rate_config_t; typedef wifi_tx_rate_config_t esp_now_rate_config_t;
/**
* @brief ESPNOW switch channel information
*/
typedef struct {
wifi_action_tx_t type; /**< ACTION TX operation type */
uint8_t channel; /**< Channel on which to perform ESPNOW TX Operation */
wifi_second_chan_t sec_channel; /**< Secondary channel */
uint32_t wait_time_ms; /**< Duration to wait for on target channel */
uint8_t op_id; /**< Unique Identifier for operation provided by wifi driver */
uint8_t dest_mac[6]; /**< Destination MAC address */
uint16_t data_len; /**< Length of the appended Data */
uint8_t data[0]; /**< Appended Data payload */
} esp_now_switch_channel_t;
/**
* @brief ESPNOW remain on channel information
*/
typedef struct {
wifi_roc_t type; /**< ROC operation type */
uint8_t channel; /**< Channel on which to perform ESPNOW ROC Operation */
wifi_second_chan_t sec_channel; /**< Secondary channel */
uint32_t wait_time_ms; /**< Duration to wait for on target channel */
uint8_t op_id; /**< ID of this specific ROC operation provided by wifi driver */
} esp_now_remain_on_channel_t;
/** /**
* @brief Callback function of receiving ESPNOW data * @brief Callback function of receiving ESPNOW data
* @param esp_now_info received ESPNOW packet information * @param esp_now_info received ESPNOW packet information
@@ -394,6 +419,32 @@ esp_err_t esp_now_set_user_oui(uint8_t *oui);
*/ */
esp_err_t esp_now_get_user_oui(uint8_t *oui); esp_err_t esp_now_get_user_oui(uint8_t *oui);
/**
* @brief ESPNOW switch to a specific channel for a required duration, and send one ESPNOW data.
*
* @param config ESPNOW switch channel relevant information
*
* @return
* - ESP_OK : succeed
* - ESP_ERR_NO_MEM: failed to allocate memory
* - ESP_ERR_INVALID_ARG: the <channel, sec_channel> pair is invalid
* - ESP_FAIL: failed to send frame
*/
esp_err_t esp_now_switch_channel_tx(esp_now_switch_channel_t *config);
/**
* @brief ESPNOW remain on the target channel for required duration.
*
* @param config ESPNOW remain on channel relevant information
*
* @return
* - ESP_OK : succeed
* - ESP_ERR_NO_MEM: failed to allocate memory
* - ESP_ERR_INVALID_ARG: the <channel, sec_channel> pair is invalid
* - ESP_FAIL: failed to perform roc operation
*/
esp_err_t esp_now_remain_on_channel(esp_now_remain_on_channel_t *config);
/** /**
* @} * @}
*/ */

View File

@@ -1829,6 +1829,7 @@ esp_err_t esp_wifi_get_bandwidths(wifi_interface_t ifx, wifi_bandwidths_t *bw);
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_NO_MEM: failed to allocate memory * - ESP_ERR_NO_MEM: failed to allocate memory
* - ESP_ERR_INVALID_ARG: the <channel, sec_channel> pair is invalid
* - ESP_FAIL: failed to send frame * - ESP_FAIL: failed to send frame
*/ */
esp_err_t esp_wifi_action_tx_req(wifi_action_tx_req_t *req); esp_err_t esp_wifi_action_tx_req(wifi_action_tx_req_t *req);
@@ -1841,6 +1842,7 @@ esp_err_t esp_wifi_action_tx_req(wifi_action_tx_req_t *req);
* @return * @return
* - ESP_OK: succeed * - ESP_OK: succeed
* - ESP_ERR_NO_MEM: failed to allocate memory * - ESP_ERR_NO_MEM: failed to allocate memory
* - ESP_ERR_INVALID_ARG: the <channel, sec_channel> pair is invalid
* - ESP_FAIL: failed to perform roc operation * - ESP_FAIL: failed to perform roc operation
*/ */
esp_err_t esp_wifi_remain_on_channel(wifi_roc_req_t * req); esp_err_t esp_wifi_remain_on_channel(wifi_roc_req_t * req);

View File

@@ -794,6 +794,7 @@ typedef struct {
uint8_t dest_mac[6]; /**< Destination MAC address */ uint8_t dest_mac[6]; /**< Destination MAC address */
wifi_action_tx_t type; /**< ACTION TX operation type */ wifi_action_tx_t type; /**< ACTION TX operation type */
uint8_t channel; /**< Channel on which to perform ACTION TX Operation */ uint8_t channel; /**< Channel on which to perform ACTION TX Operation */
wifi_second_chan_t sec_channel; /**< Secondary channel */
uint32_t wait_time_ms; /**< Duration to wait for on target channel */ uint32_t wait_time_ms; /**< Duration to wait for on target channel */
bool no_ack; /**< Indicates no ack required */ bool no_ack; /**< Indicates no ack required */
wifi_action_rx_cb_t rx_cb; /**< Rx Callback to receive action frames */ wifi_action_rx_cb_t rx_cb; /**< Rx Callback to receive action frames */

View File

@@ -162,6 +162,7 @@ esp_err_t esp_dpp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint3
req->data_len = len; req->data_len = len;
req->rx_cb = s_action_rx_cb; req->rx_cb = s_action_rx_cb;
req->channel = channel; req->channel = channel;
req->sec_channel = WIFI_SECOND_CHAN_NONE;
req->wait_time_ms = wait_time_ms; req->wait_time_ms = wait_time_ms;
req->type = WIFI_OFFCHAN_TX_REQ; req->type = WIFI_OFFCHAN_TX_REQ;
os_memcpy(req->data, buf, req->data_len); os_memcpy(req->data, buf, req->data_len);

View File

@@ -135,6 +135,7 @@ void esp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint32_t len,
req->data_len = len; req->data_len = len;
req->rx_cb = dummy_rx_action; req->rx_cb = dummy_rx_action;
req->channel = channel; req->channel = channel;
req->sec_channel = WIFI_SECOND_CHAN_NONE;
req->wait_time_ms = wait_time_ms; req->wait_time_ms = wait_time_ms;
req->type = WIFI_OFFCHAN_TX_REQ; req->type = WIFI_OFFCHAN_TX_REQ;