Skip to content
This repository was archived by the owner on Oct 27, 2022. It is now read-only.

Commit 4cd3a62

Browse files
committed
Merge branch 'feature/clean_up_sniffer_cb' into 'master'
feat: Clean the work flow of sniffer callback See merge request esp-components/esp-aliyun!108
2 parents 51b3741 + b69e663 commit 4cd3a62

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

platform/hal/os/espressif/HAL_AWSS_espressif.c

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ typedef void (*awss_wifi_mgmt_frame_cb_t)(_IN_ uint8_t * buffer,
234234

235235
static void IRAM_ATTR wifi_sniffer_cb(void *recv_buf, wifi_promiscuous_pkt_type_t type)
236236
{
237-
int with_fcs = 0;
237+
int with_fcs = 0;
238238
int link_type = AWSS_LINK_TYPE_NONE;
239239
uint16_t len = 0;
240240
wifi_promiscuous_pkt_t *pkt = (wifi_promiscuous_pkt_t *)recv_buf;
@@ -243,40 +243,36 @@ static void IRAM_ATTR wifi_sniffer_cb(void *recv_buf, wifi_promiscuous_pkt_type_
243243
if (type != WIFI_PKT_DATA && type != WIFI_PKT_MGMT) {
244244
return;
245245
}
246+
246247
info.rssi = pkt->rx_ctrl.rssi;
248+
247249
#ifdef CONFIG_TARGET_PLATFORM_ESP8266
248-
uint8_t total_num = 1, count=0;
249-
uint16_t seq_buf=0;
250+
uint8_t total_num = 1, count;
251+
uint16_t seq_buf;
252+
len = pkt->rx_ctrl.sig_mode ? pkt->rx_ctrl.HT_length : pkt->rx_ctrl.legacy_length;
250253

251254
if (pkt->rx_ctrl.aggregation) {
252255
total_num = pkt->rx_ctrl.ampdu_cnt;
253256
}
254-
for (count=0; count < total_num; count++) {
257+
258+
for (count = 0; count < total_num; count++) {
255259
if (total_num > 1) {
256-
if (pkt->rx_ctrl.sig_mode) {
257-
pkt->rx_ctrl.HT_length = *((uint16_t *)&pkt->payload[40+2*count]);
258-
} else {
259-
pkt->rx_ctrl.legacy_length = *((uint16_t *)&pkt->payload[40+2*count]);
260-
}
261-
if (seq_buf == 0) {
262-
seq_buf = ((uint16_t)pkt->payload[22] | ((uint16_t)pkt->payload[23] << 8)) >> 4;
263-
seq_buf = seq_buf - total_num + 1;
264-
}
265-
seq_buf++;
260+
len = *(uint16_t *)(pkt->payload + 40 + 2 * count);
266261
}
267-
len = (pkt->rx_ctrl.sig_mode ? pkt->rx_ctrl.HT_length : pkt->rx_ctrl.legacy_length);
268-
if (type == WIFI_PKT_MISC) {
269-
if (pkt->rx_ctrl.aggregation == 1) {
270-
len -= 4;
271-
}
262+
263+
if (type == WIFI_PKT_MISC && pkt->rx_ctrl.aggregation == 1) {
264+
len -= 4;
272265
}
266+
273267
if (s_sniffer_cb) {
274268
s_sniffer_cb((char *)pkt->payload, len - 4, link_type, with_fcs, info.rssi);
275269
}
270+
276271
if (total_num > 1) {
277-
pkt->payload[22] = (uint8_t)seq_buf;
278-
pkt->payload[23] = (pkt->payload[23] & 0xf0) || ((seq_buf >> 8) & 0x0f);
279-
}
272+
seq_buf = *(uint16_t *)(pkt->payload + 22) >> 4;
273+
seq_buf++;
274+
*(uint16_t *)(pkt->payload + 22) = (seq_buf << 4) | (*(uint16_t *)(pkt->payload + 22) & 0xF);
275+
}
280276
}
281277
#else
282278
if (s_sniffer_cb) {

0 commit comments

Comments
 (0)