Skip to content

Commit 2b390b2

Browse files
author
Jiang Jiang Jian
committed
Merge branch 'feature/add_tx_callback_api_for_80211_tx' into 'master'
feat(wifi): Added tx callback function for 80211 tx Closes WIFI-6820 See merge request espressif/esp-idf!37673
2 parents f56cc82 + cad0ad9 commit 2b390b2

File tree

9 files changed

+82
-10
lines changed

9 files changed

+82
-10
lines changed

components/esp_wifi/include/esp_now.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ extern "C" {
5757
* @brief Status of sending ESPNOW data .
5858
*/
5959
typedef enum {
60-
ESP_NOW_SEND_SUCCESS = 0, /**< Send ESPNOW data successfully */
61-
ESP_NOW_SEND_FAIL, /**< Send ESPNOW data fail */
60+
ESP_NOW_SEND_SUCCESS = WIFI_SEND_SUCCESS, /**< Send ESPNOW data successfully */
61+
ESP_NOW_SEND_FAIL = WIFI_SEND_FAIL, /**< Send ESPNOW data fail */
6262
} esp_now_send_status_t;
6363

6464
/**
@@ -84,14 +84,19 @@ typedef struct esp_now_peer_num {
8484
} esp_now_peer_num_t;
8585

8686
/**
87-
* @brief ESPNOW packet information
87+
* @brief ESPNOW receive packet information
8888
*/
8989
typedef struct esp_now_recv_info {
9090
uint8_t * src_addr; /**< Source address of ESPNOW packet */
9191
uint8_t * des_addr; /**< Destination address of ESPNOW packet */
9292
wifi_pkt_rx_ctrl_t * rx_ctrl; /**< Rx control info of ESPNOW packet */
9393
} esp_now_recv_info_t;
9494

95+
/**
96+
* @brief ESPNOW sending packet information
97+
*/
98+
typedef wifi_tx_info_t esp_now_send_info_t;
99+
95100
/**
96101
* @brief ESPNOW rate config
97102
*/
@@ -108,10 +113,10 @@ typedef void (*esp_now_recv_cb_t)(const esp_now_recv_info_t * esp_now_info, cons
108113

109114
/**
110115
* @brief Callback function of sending ESPNOW data
111-
* @param mac_addr peer MAC address
112-
* @param status status of sending ESPNOW data (succeed or fail)
116+
* @param esp_now_send_info_t Sending information for ESPNOW data
117+
* @param status status of sending ESPNOW data (succeed or fail). This is will be removed later, since the tx_info->tx_status also works.
113118
*/
114-
typedef void (*esp_now_send_cb_t)(const uint8_t *mac_addr, esp_now_send_status_t status);
119+
typedef void (*esp_now_send_cb_t)(const esp_now_send_info_t *tx_info, esp_now_send_status_t status);
115120

116121
/**
117122
* @brief Initialize ESPNOW function

components/esp_wifi/include/esp_wifi.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,27 @@ esp_err_t esp_wifi_get_event_mask(uint32_t *mask);
11981198

11991199
esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
12001200

1201+
/**
1202+
* @brief Callback function of 80211 tx data
1203+
*
1204+
* @param tx_info TX information of 80211 tx. The information can only be used in the callback context.
1205+
*/
1206+
typedef void (*esp_wifi_80211_tx_done_cb_t)(const esp_80211_tx_info_t *tx_info);
1207+
1208+
/**
1209+
* @brief Register the TX callback function of 80211 tx data.
1210+
*
1211+
* @attention This callback will be executed in WiFi task, so avoid doing any time consuming activity in the callback.
1212+
* Doing heavy work here can affect the WiFi performance.
1213+
*
1214+
* @param cb callback function. If the cb is NULL, then unregister the tx cb.
1215+
*
1216+
* @return
1217+
* - ESP_OK: succeed
1218+
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
1219+
*/
1220+
esp_err_t esp_wifi_register_80211_tx_cb(esp_wifi_80211_tx_done_cb_t cb);
1221+
12011222
/**
12021223
* @brief The RX callback function of Channel State Information(CSI) data.
12031224
*

components/esp_wifi/include/esp_wifi_types_generic.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,6 +1486,29 @@ typedef struct {
14861486
uint8_t regulatory_type; /**< regulatory type of country */
14871487
} wifi_regdomain_t;
14881488

1489+
/**
1490+
* @brief Status of wifi sending data
1491+
*/
1492+
typedef enum {
1493+
WIFI_SEND_SUCCESS = 0, /**< Sending Wi-Fi data successfully */
1494+
WIFI_SEND_FAIL, /**< Sending Wi-Fi data fail */
1495+
} wifi_tx_status_t;
1496+
1497+
/**
1498+
* @brief Information of wifi sending data
1499+
*/
1500+
typedef struct {
1501+
uint8_t *des_addr; /**< The address of the receive device */
1502+
uint8_t *src_addr; /**< The address of the sending device */
1503+
wifi_interface_t ifidx; /**< Interface of sending 80211 tx data */
1504+
uint8_t *data; /**< The data for 80211 tx, start from the MAC header */
1505+
uint8_t data_len; /**< The frame body length for 80211 tx, excluding the MAC header */
1506+
wifi_phy_rate_t rate; /**< Data rate */
1507+
wifi_tx_status_t tx_status; /**< Status of sending 80211 tx data */
1508+
} wifi_tx_info_t;
1509+
1510+
typedef wifi_tx_info_t esp_80211_tx_info_t;
1511+
14891512
#ifdef __cplusplus
14901513
}
14911514
#endif

docs/en/migration-guides/release-5.x/5.5/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Migration from 5.4 to 5.5
99
system
1010
peripherals
1111
protocols
12+
wifi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Wi-Fi
2+
======
3+
4+
:link_to_translation:`zh_CN:[中文]`
5+
6+
7+
Breaking Changes
8+
~~~~~~~~~~~~~~~~
9+
10+
The parameters for the ESP-NOW sending data callback function has changed from ``uint8_t *mac_addr`` to ``esp_now_send_info_t *tx_info``.

docs/zh_CN/migration-guides/release-5.x/5.5/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
system
1010
peripherals
1111
protocols
12+
wifi
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Wi-Fi
2+
=====
3+
4+
:link_to_translation:`en:[English]`
5+
6+
7+
重大更新
8+
~~~~~~~~
9+
10+
ESP-NOW 的发包回调函数的参数从 ``uint8_t *mac_addr`` 变为 ``esp_now_send_info_t *tx_info``。
11+

examples/wifi/espnow/main/espnow_example_main.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ static void example_wifi_init(void)
6161
/* ESPNOW sending or receiving callback function is called in WiFi task.
6262
* Users should not do lengthy operations from this task. Instead, post
6363
* necessary data to a queue and handle it from a lower priority task. */
64-
static void example_espnow_send_cb(const uint8_t *mac_addr, esp_now_send_status_t status)
64+
static void example_espnow_send_cb(const esp_now_send_info_t *tx_info, esp_now_send_status_t status)
6565
{
6666
example_espnow_event_t evt;
6767
example_espnow_event_send_cb_t *send_cb = &evt.info.send_cb;
6868

69-
if (mac_addr == NULL) {
69+
if (tx_info == NULL) {
7070
ESP_LOGE(TAG, "Send cb arg error");
7171
return;
7272
}
7373

7474
evt.id = EXAMPLE_ESPNOW_SEND_CB;
75-
memcpy(send_cb->mac_addr, mac_addr, ESP_NOW_ETH_ALEN);
75+
memcpy(send_cb->mac_addr, tx_info->des_addr, ESP_NOW_ETH_ALEN);
7676
send_cb->status = status;
7777
if (xQueueSend(s_example_espnow_queue, &evt, ESPNOW_MAXDELAY) != pdTRUE) {
7878
ESP_LOGW(TAG, "Send send queue fail");

0 commit comments

Comments
 (0)