Skip to content

Commit 1635d54

Browse files
committed
Merge branch 'feature/add_wifi_send_buffer_result_to_aio_ret' into 'master'
feat(lib): add wifi buffer send result to aio ret See merge request sdk/ESP8266_RTOS_SDK!441
2 parents 57e11f6 + fe0c690 commit 1635d54

File tree

5 files changed

+138
-70
lines changed

5 files changed

+138
-70
lines changed

components/esp8266/include/esp_wifi_types.h

+75-41
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ typedef union {
121121

122122
/** @brief Parameters for an SSID scan. */
123123
typedef struct {
124-
uint8_t *ssid; /**< SSID of AP */
125-
uint8_t *bssid; /**< MAC address of AP */
124+
uint8_t* ssid; /**< SSID of AP */
125+
uint8_t* bssid; /**< MAC address of AP */
126126
uint8_t channel; /**< channel, scan the specific channel */
127127
bool show_hidden; /**< enable to scan AP whose SSID is hidden */
128128
wifi_scan_type_t scan_type; /**< scan type, active or passive */
@@ -156,30 +156,30 @@ typedef struct {
156156
wifi_cipher_type_t pairwise_cipher; /**< pairwise cipher of AP */
157157
wifi_cipher_type_t group_cipher; /**< group cipher of AP */
158158
wifi_ant_t ant; /**< antenna used to receive beacon from AP */
159-
uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
160-
uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
161-
uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
162-
uint32_t phy_lr:1; /**< bit: 3 flag to identify if low rate is enabled or not */
163-
uint32_t wps:1; /**< bit: 4 flag to identify if WPS is supported or not */
164-
uint32_t reserved:27; /**< bit: 5..31 reserved */
159+
uint32_t phy_11b: 1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
160+
uint32_t phy_11g: 1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
161+
uint32_t phy_11n: 1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
162+
uint32_t phy_lr: 1; /**< bit: 3 flag to identify if low rate is enabled or not */
163+
uint32_t wps: 1; /**< bit: 4 flag to identify if WPS is supported or not */
164+
uint32_t reserved: 27; /**< bit: 5..31 reserved */
165165
wifi_country_t country; /**< country information of AP */
166166
} wifi_ap_record_t;
167167

168168
typedef enum {
169169
WIFI_FAST_SCAN = 0, /**< Do fast scan, scan will end after find SSID match AP */
170170
WIFI_ALL_CHANNEL_SCAN, /**< All channel scan, scan will end after scan all the channel */
171-
}wifi_scan_method_t;
171+
} wifi_scan_method_t;
172172

173173
typedef enum {
174174
WIFI_CONNECT_AP_BY_SIGNAL = 0, /**< Sort match AP in scan list by RSSI */
175175
WIFI_CONNECT_AP_BY_SECURITY, /**< Sort match AP in scan list by security mode */
176-
}wifi_sort_method_t;
176+
} wifi_sort_method_t;
177177

178178
/** @brief Structure describing parameters for a WiFi fast scan */
179179
typedef struct {
180180
int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */
181181
wifi_auth_mode_t authmode; /**< The weakest authmode to accept in the fast scan mode */
182-
}wifi_fast_scan_threshold_t;
182+
} wifi_fast_scan_threshold_t;
183183

184184
typedef enum {
185185
WIFI_PS_NONE, /**< No power save */
@@ -238,11 +238,11 @@ typedef union {
238238
/** @brief Description of STA associated with AP */
239239
typedef struct {
240240
uint8_t mac[6]; /**< mac address */
241-
uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
242-
uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
243-
uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
244-
uint32_t phy_lr:1; /**< bit: 3 flag to identify if low rate is enabled or not */
245-
uint32_t reserved:28; /**< bit: 4..31 reserved */
241+
uint32_t phy_11b: 1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
242+
uint32_t phy_11g: 1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
243+
uint32_t phy_11n: 1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
244+
uint32_t phy_lr: 1; /**< bit: 3 flag to identify if low rate is enabled or not */
245+
uint32_t reserved: 28; /**< bit: 4..31 reserved */
246246
} wifi_sta_info_t;
247247

248248
#define ESP_WIFI_MAX_CONN_NUM (10) /**< max number of stations which can connect to ESP8266 soft-AP */
@@ -298,31 +298,31 @@ typedef struct {
298298

299299
/** @brief Received packet radio metadata header, this is the common header at the beginning of all promiscuous mode RX callback buffers */
300300
typedef struct {
301-
signed rssi:8; /**< signal intensity of packet */
302-
unsigned rate:4; /**< data rate */
303-
unsigned is_group:1;
304-
unsigned :1; /**< reserve */
305-
unsigned sig_mode:2; /**< 0:is not 11n packet; 1:is 11n packet */
306-
unsigned legacy_length:12;
307-
unsigned damatch0:1;
308-
unsigned damatch1:1;
309-
unsigned bssidmatch0:1;
310-
unsigned bssidmatch1:1;
311-
unsigned mcs:7; /**< if is 11n packet, shows the modulation(range from 0 to 76) */
312-
unsigned cwb:1; /**< if is 11n packet, shows if is HT40 packet or not */
313-
unsigned HT_length:16; /**< reserve */
314-
unsigned smoothing:1; /**< reserve */
315-
unsigned not_sounding:1; /**< reserve */
316-
unsigned :1; /**< reserve */
317-
unsigned aggregation:1; /**< Aggregation */
318-
unsigned stbc:2; /**< STBC */
319-
unsigned fec_coding:1; /**< Flag is set for 11n packets which are LDPC */
320-
unsigned sgi:1; /**< SGI */
321-
unsigned rxend_state:8;
322-
unsigned ampdu_cnt:8; /**< ampdu cnt */
323-
unsigned channel:4; /**< which channel this packet in */
324-
unsigned :4; /**< reserve */
325-
signed noise_floor:8;
301+
signed rssi: 8; /**< signal intensity of packet */
302+
unsigned rate: 4; /**< data rate */
303+
unsigned is_group: 1;
304+
unsigned : 1; /**< reserve */
305+
unsigned sig_mode: 2; /**< 0:is not 11n packet; 1:is 11n packet */
306+
unsigned legacy_length: 12;
307+
unsigned damatch0: 1;
308+
unsigned damatch1: 1;
309+
unsigned bssidmatch0: 1;
310+
unsigned bssidmatch1: 1;
311+
unsigned mcs: 7; /**< if is 11n packet, shows the modulation(range from 0 to 76) */
312+
unsigned cwb: 1; /**< if is 11n packet, shows if is HT40 packet or not */
313+
unsigned HT_length: 16; /**< reserve */
314+
unsigned smoothing: 1; /**< reserve */
315+
unsigned not_sounding: 1; /**< reserve */
316+
unsigned : 1; /**< reserve */
317+
unsigned aggregation: 1; /**< Aggregation */
318+
unsigned stbc: 2; /**< STBC */
319+
unsigned fec_coding: 1; /**< Flag is set for 11n packets which are LDPC */
320+
unsigned sgi: 1; /**< SGI */
321+
unsigned rxend_state: 8;
322+
unsigned ampdu_cnt: 8; /**< ampdu cnt */
323+
unsigned channel: 4; /**< which channel this packet in */
324+
unsigned : 4; /**< reserve */
325+
signed noise_floor: 8;
326326
} wifi_pkt_rx_ctrl_t;
327327

328328
/** @brief Payload passed to 'buf' parameter of promiscuous mode RX callback.
@@ -372,6 +372,40 @@ typedef struct {
372372
#define WIFI_EVENT_MASK_NONE (0) /**< mask none of the WiFi events */
373373
#define WIFI_EVENT_MASK_AP_PROBEREQRECVED (BIT(0)) /**< mask SYSTEM_EVENT_AP_PROBEREQRECVED event */
374374

375+
typedef enum {
376+
TX_STATUS_SUCCESS = 1,
377+
TX_STATUS_SRC_EXCEED,
378+
TX_STATUS_LRC_EXCEED,
379+
TX_STATUS_DISCARD,
380+
} wifi_tx_result_t;
381+
382+
typedef enum {
383+
PHY_RATE_1_LONG,
384+
PHY_RATE_2_LONG,
385+
PHY_RATE_5_LONG,
386+
PHY_RATE_11_LONG,
387+
PHY_RATE_RESERVED,
388+
PHY_RATE_2_SHORT,
389+
PHY_RATE_5_SHORT,
390+
PHY_RATE_11_SHORT,
391+
PHY_RATE_48,
392+
PHY_RATE_24,
393+
PHY_RATE_12,
394+
PHY_RATE_6,
395+
PHY_RATE_54,
396+
PHY_RATE_36,
397+
PHY_RATE_18,
398+
PHY_RATE_9,
399+
} wifi_tx_rate_t;
400+
401+
typedef struct {
402+
unsigned wifi_tx_result: 8;
403+
unsigned wifi_tx_src: 6;
404+
unsigned wifi_tx_lrc: 6;
405+
unsigned wifi_tx_rate: 8;
406+
unsigned unused: 4;
407+
} wifi_tx_status_t;
408+
375409
#ifdef __cplusplus
376410
}
377411
#endif

components/esp8266/lib/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
gwen:
22
core: b9f2d3e
33
net80211: eca7811
4-
pp: eca7811
4+
pp: 82269d9
55
smartconfig:eca7811
66
wpa: eca7811
77
phy: 1055_8

components/esp8266/lib/libpp.a

36 Bytes
Binary file not shown.

components/lwip/port/esp8266/netif/ethernetif.c

+61-27
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ static int low_level_send_cb(esp_aio_t* aio);
4848

4949
static inline bool check_pbuf_to_insert(struct pbuf* p)
5050
{
51-
uint8_t* buf = (uint8_t *)p->payload;
51+
uint8_t* buf = (uint8_t*)p->payload;
52+
5253
/*Check if pbuf is tcp ip*/
5354
if (buf[12] == 0x08 && buf[13] == 0x00 && buf[23] == 0x06) {
54-
return true;
55+
return true;
5556
}
57+
5658
return false;
5759
}
5860

@@ -69,20 +71,23 @@ static void insert_to_list(int fd, struct pbuf* p)
6971
return;
7072
}
7173

72-
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Insert %p,%d\n",p,pbuf_send_list_num));
74+
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Insert %p,%d\n", p, pbuf_send_list_num));
75+
7376
if (pbuf_list_head == NULL) {
74-
pbuf_list_head = (pbuf_send_list_t* )malloc(sizeof(pbuf_send_list_t));
75-
pbuf_send_list_num++;
77+
tmp_pbuf_list1 = (pbuf_send_list_t*)malloc(sizeof(pbuf_send_list_t));
7678

77-
if (!pbuf_list_head) {
78-
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("no menory malloc pbuf list error\n"));
79+
if (!tmp_pbuf_list1) {
80+
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("no memory malloc pbuf list error\n"));
7981
return;
8082
}
83+
8184
pbuf_ref(p);
82-
pbuf_list_head->aiofd = fd;
83-
pbuf_list_head->p = p;
84-
pbuf_list_head->next = NULL;
85-
pbuf_list_head->err_cnt = 0;
85+
tmp_pbuf_list1->aiofd = fd;
86+
tmp_pbuf_list1->p = p;
87+
tmp_pbuf_list1->next = NULL;
88+
tmp_pbuf_list1->err_cnt = 0;
89+
pbuf_list_head = tmp_pbuf_list1;
90+
pbuf_send_list_num++;
8691
return;
8792
}
8893

@@ -94,16 +99,15 @@ static void insert_to_list(int fd, struct pbuf* p)
9499
tmp_pbuf_list1->err_cnt ++;
95100
return;
96101
}
102+
97103
tmp_pbuf_list2 = tmp_pbuf_list1;
98104
tmp_pbuf_list1 = tmp_pbuf_list2->next;
99105
}
100106

101-
tmp_pbuf_list2->next = (pbuf_send_list_t*)malloc(sizeof(pbuf_send_list_t));
102-
pbuf_send_list_num++;
103-
tmp_pbuf_list1 = tmp_pbuf_list2->next;
107+
tmp_pbuf_list1 = (pbuf_send_list_t*)malloc(sizeof(pbuf_send_list_t));
104108

105109
if (!tmp_pbuf_list1) {
106-
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("no menory malloc pbuf list error\n"));
110+
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("no memory malloc pbuf list error\n"));
107111
return;
108112
}
109113

@@ -112,6 +116,8 @@ static void insert_to_list(int fd, struct pbuf* p)
112116
tmp_pbuf_list1->p = p;
113117
tmp_pbuf_list1->next = NULL;
114118
tmp_pbuf_list1->err_cnt = 0;
119+
tmp_pbuf_list2->next = tmp_pbuf_list1;
120+
pbuf_send_list_num++;
115121
}
116122

117123
void send_from_list()
@@ -121,7 +127,7 @@ void send_from_list()
121127
while (pbuf_list_head != NULL) {
122128
if (pbuf_list_head->p->ref == 1) {
123129
tmp_pbuf_list1 = pbuf_list_head->next;
124-
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Delete %p,%d\n",pbuf_list_head->p,pbuf_send_list_num));
130+
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Delete %p,%d\n", pbuf_list_head->p, pbuf_send_list_num));
125131
pbuf_free(pbuf_list_head->p);
126132
free(pbuf_list_head);
127133
pbuf_send_list_num--;
@@ -141,21 +147,23 @@ void send_from_list()
141147

142148
if (err == ERR_MEM) {
143149
pbuf_list_head->err_cnt++;
150+
144151
if (pbuf_list_head->err_cnt >= 3) {
145-
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Delete %p,%d\n",pbuf_list_head->p,pbuf_send_list_num));
152+
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Delete %p,%d\n", pbuf_list_head->p, pbuf_send_list_num));
146153
pbuf_free(pbuf_list_head->p);
147154
free(pbuf_list_head);
148155
pbuf_send_list_num--;
149156
pbuf_list_head = tmp_pbuf_list1;
150157
}
158+
151159
return;
152-
} else if (err == ERR_OK){
153-
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Delete %p,%d\n",pbuf_list_head->p,pbuf_send_list_num));
160+
} else if (err == ERR_OK) {
161+
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Delete %p,%d\n", pbuf_list_head->p, pbuf_send_list_num));
154162
free(pbuf_list_head);
155163
pbuf_send_list_num--;
156164
pbuf_list_head = tmp_pbuf_list1;
157165
} else {
158-
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Delete %p,%d\n",pbuf_list_head->p,pbuf_send_list_num));
166+
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Delete %p,%d\n", pbuf_list_head->p, pbuf_send_list_num));
159167
pbuf_free(pbuf_list_head->p);
160168
free(pbuf_list_head);
161169
pbuf_send_list_num--;
@@ -202,9 +210,31 @@ static void low_level_init(struct netif* netif)
202210
*
203211
* @return 0 meaning successs
204212
*/
205-
static int low_level_send_cb(esp_aio_t *aio)
213+
static int low_level_send_cb(esp_aio_t* aio)
206214
{
207-
struct pbuf *pbuf = aio->arg;
215+
struct pbuf* pbuf = aio->arg;
216+
wifi_tx_status_t* status = (wifi_tx_status_t*) & (aio->ret);
217+
218+
if ((TX_STATUS_SUCCESS != status->wifi_tx_result) && check_pbuf_to_insert(pbuf)) {
219+
uint8_t* buf = (uint8_t*)pbuf->payload;
220+
struct eth_hdr ethhdr;
221+
222+
if (*(buf - 17) & 0x01) { //From DS
223+
memcpy(&ethhdr.dest, buf - 2, ETH_HWADDR_LEN);
224+
memcpy(&ethhdr.src, buf - 2 - ETH_HWADDR_LEN, ETH_HWADDR_LEN);
225+
} else if (*(buf - 17) & 0x02) { //To DS
226+
memcpy(&ethhdr.dest, buf - 2 - ETH_HWADDR_LEN - ETH_HWADDR_LEN, ETH_HWADDR_LEN);
227+
memcpy(&ethhdr.src, buf - 2, 6);
228+
} else {
229+
pbuf_free(pbuf);
230+
return 0;
231+
}
232+
233+
memcpy(buf, &ethhdr, (ETH_HWADDR_LEN + ETH_HWADDR_LEN));
234+
LWIP_DEBUGF(PBUF_CACHE_DEBUG, ("Send packet fail: result:%d, LRC:%d, SRC:%d, RATE:%d",
235+
status->wifi_tx_result, status->wifi_tx_lrc, status->wifi_tx_src, status->wifi_tx_rate));
236+
insert_to_list(aio->fd, aio->arg);
237+
}
208238

209239
pbuf_free(pbuf);
210240

@@ -219,9 +249,9 @@ static int low_level_send_cb(esp_aio_t *aio)
219249
*
220250
* @return LWIP pbuf pointer which it not "PBUF_FLAG_IS_CUSTOM" attribute
221251
*/
222-
static inline struct pbuf *ethernetif_transform_pbuf(struct pbuf *pbuf)
252+
static inline struct pbuf* ethernetif_transform_pbuf(struct pbuf* pbuf)
223253
{
224-
struct pbuf *p;
254+
struct pbuf* p;
225255

226256
if (!(pbuf->flags & PBUF_FLAG_IS_CUSTOM) && IS_DRAM(pbuf->payload)) {
227257
/*
@@ -232,8 +262,10 @@ static inline struct pbuf *ethernetif_transform_pbuf(struct pbuf *pbuf)
232262
}
233263

234264
p = pbuf_alloc(PBUF_RAW, pbuf->len, PBUF_RAM);
235-
if (!p)
265+
266+
if (!p) {
236267
return NULL;
268+
}
237269

238270
if (IS_IRAM(p->payload)) {
239271
LWIP_DEBUGF(NETIF_DEBUG, ("low_level_output: data in IRAM\n"));
@@ -246,7 +278,7 @@ static inline struct pbuf *ethernetif_transform_pbuf(struct pbuf *pbuf)
246278
/*
247279
* The input pbuf(named "pbuf") should not be freed, becasue it will be
248280
* freed by upper layer.
249-
*
281+
*
250282
* The output pbuf(named "p") should not be freed either, becasue it will
251283
* be freed at callback function "low_level_send_cb".
252284
*/
@@ -285,6 +317,7 @@ static int8_t low_level_output(struct netif* netif, struct pbuf* p)
285317
#endif
286318

287319
p = ethernetif_transform_pbuf(p);
320+
288321
if (!p) {
289322
LWIP_DEBUGF(NETIF_DEBUG, ("low_level_output: lack memory\n"));
290323
return ERR_OK;
@@ -305,8 +338,9 @@ static int8_t low_level_output(struct netif* netif, struct pbuf* p)
305338
#if ESP_UDP
306339
udp_sync_set_ret(netif, err);
307340
#endif
341+
308342
if (err != ERR_OK) {
309-
if (err == ERR_MEM){
343+
if (err == ERR_MEM) {
310344
insert_to_list(aio.fd, p);
311345
err = ERR_OK;
312346
}

components/tcpip_adapter/tcpip_adapter_lwip.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ esp_err_t tcpip_adapter_start(tcpip_adapter_if_t tcpip_if, uint8_t *mac, tcpip_a
241241
}
242242

243243
if (esp_netif[tcpip_if] == NULL) {
244-
ESP_LOGE(TAG, "TCPIP adapter has no menory\n");
244+
ESP_LOGE(TAG, "TCPIP adapter has no memory\n");
245245
return ESP_ERR_NO_MEM;
246246
}
247247
memcpy(esp_netif[tcpip_if]->hwaddr, mac, NETIF_MAX_HWADDR_LEN);

0 commit comments

Comments
 (0)