@@ -48,11 +48,13 @@ static int low_level_send_cb(esp_aio_t* aio);
48
48
49
49
static inline bool check_pbuf_to_insert (struct pbuf * p )
50
50
{
51
- uint8_t * buf = (uint8_t * )p -> payload ;
51
+ uint8_t * buf = (uint8_t * )p -> payload ;
52
+
52
53
/*Check if pbuf is tcp ip*/
53
54
if (buf [12 ] == 0x08 && buf [13 ] == 0x00 && buf [23 ] == 0x06 ) {
54
- return true;
55
+ return true;
55
56
}
57
+
56
58
return false;
57
59
}
58
60
@@ -69,20 +71,23 @@ static void insert_to_list(int fd, struct pbuf* p)
69
71
return ;
70
72
}
71
73
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
+
73
76
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 ));
76
78
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" ));
79
81
return ;
80
82
}
83
+
81
84
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 ++ ;
86
91
return ;
87
92
}
88
93
@@ -94,16 +99,15 @@ static void insert_to_list(int fd, struct pbuf* p)
94
99
tmp_pbuf_list1 -> err_cnt ++ ;
95
100
return ;
96
101
}
102
+
97
103
tmp_pbuf_list2 = tmp_pbuf_list1 ;
98
104
tmp_pbuf_list1 = tmp_pbuf_list2 -> next ;
99
105
}
100
106
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 ));
104
108
105
109
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" ));
107
111
return ;
108
112
}
109
113
@@ -112,6 +116,8 @@ static void insert_to_list(int fd, struct pbuf* p)
112
116
tmp_pbuf_list1 -> p = p ;
113
117
tmp_pbuf_list1 -> next = NULL ;
114
118
tmp_pbuf_list1 -> err_cnt = 0 ;
119
+ tmp_pbuf_list2 -> next = tmp_pbuf_list1 ;
120
+ pbuf_send_list_num ++ ;
115
121
}
116
122
117
123
void send_from_list ()
@@ -121,7 +127,7 @@ void send_from_list()
121
127
while (pbuf_list_head != NULL ) {
122
128
if (pbuf_list_head -> p -> ref == 1 ) {
123
129
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 ));
125
131
pbuf_free (pbuf_list_head -> p );
126
132
free (pbuf_list_head );
127
133
pbuf_send_list_num -- ;
@@ -141,21 +147,23 @@ void send_from_list()
141
147
142
148
if (err == ERR_MEM ) {
143
149
pbuf_list_head -> err_cnt ++ ;
150
+
144
151
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 ));
146
153
pbuf_free (pbuf_list_head -> p );
147
154
free (pbuf_list_head );
148
155
pbuf_send_list_num -- ;
149
156
pbuf_list_head = tmp_pbuf_list1 ;
150
157
}
158
+
151
159
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 ));
154
162
free (pbuf_list_head );
155
163
pbuf_send_list_num -- ;
156
164
pbuf_list_head = tmp_pbuf_list1 ;
157
165
} 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 ));
159
167
pbuf_free (pbuf_list_head -> p );
160
168
free (pbuf_list_head );
161
169
pbuf_send_list_num -- ;
@@ -202,9 +210,31 @@ static void low_level_init(struct netif* netif)
202
210
*
203
211
* @return 0 meaning successs
204
212
*/
205
- static int low_level_send_cb (esp_aio_t * aio )
213
+ static int low_level_send_cb (esp_aio_t * aio )
206
214
{
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
+ }
208
238
209
239
pbuf_free (pbuf );
210
240
@@ -219,9 +249,9 @@ static int low_level_send_cb(esp_aio_t *aio)
219
249
*
220
250
* @return LWIP pbuf pointer which it not "PBUF_FLAG_IS_CUSTOM" attribute
221
251
*/
222
- static inline struct pbuf * ethernetif_transform_pbuf (struct pbuf * pbuf )
252
+ static inline struct pbuf * ethernetif_transform_pbuf (struct pbuf * pbuf )
223
253
{
224
- struct pbuf * p ;
254
+ struct pbuf * p ;
225
255
226
256
if (!(pbuf -> flags & PBUF_FLAG_IS_CUSTOM ) && IS_DRAM (pbuf -> payload )) {
227
257
/*
@@ -232,8 +262,10 @@ static inline struct pbuf *ethernetif_transform_pbuf(struct pbuf *pbuf)
232
262
}
233
263
234
264
p = pbuf_alloc (PBUF_RAW , pbuf -> len , PBUF_RAM );
235
- if (!p )
265
+
266
+ if (!p ) {
236
267
return NULL ;
268
+ }
237
269
238
270
if (IS_IRAM (p -> payload )) {
239
271
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)
246
278
/*
247
279
* The input pbuf(named "pbuf") should not be freed, becasue it will be
248
280
* freed by upper layer.
249
- *
281
+ *
250
282
* The output pbuf(named "p") should not be freed either, becasue it will
251
283
* be freed at callback function "low_level_send_cb".
252
284
*/
@@ -285,6 +317,7 @@ static int8_t low_level_output(struct netif* netif, struct pbuf* p)
285
317
#endif
286
318
287
319
p = ethernetif_transform_pbuf (p );
320
+
288
321
if (!p ) {
289
322
LWIP_DEBUGF (NETIF_DEBUG , ("low_level_output: lack memory\n" ));
290
323
return ERR_OK ;
@@ -305,8 +338,9 @@ static int8_t low_level_output(struct netif* netif, struct pbuf* p)
305
338
#if ESP_UDP
306
339
udp_sync_set_ret (netif , err );
307
340
#endif
341
+
308
342
if (err != ERR_OK ) {
309
- if (err == ERR_MEM ){
343
+ if (err == ERR_MEM ) {
310
344
insert_to_list (aio .fd , p );
311
345
err = ERR_OK ;
312
346
}
0 commit comments