Merge branch 'bugfix/add_sniffer_fcs_filter' into 'master'

example: Add sniffer FCSFAIL filter

Closes IDFGH-4661

See merge request espressif/esp-idf!12249
This commit is contained in:
Jiang Jiang Jian
2021-05-08 07:31:51 +00:00
4 changed files with 21 additions and 17 deletions

View File

@@ -73,7 +73,7 @@ void esp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint32_t len,
return; return;
} }
req->ifx = ESP_IF_WIFI_STA; req->ifx = WIFI_IF_STA;
memcpy(req->dest_mac, dest_mac, ETH_ALEN); memcpy(req->dest_mac, dest_mac, ETH_ALEN);
req->no_ack = false; req->no_ack = false;
req->data_len = len; req->data_len = len;
@@ -373,7 +373,7 @@ static void esp_dpp_task(void *pvParameters )
int channel; int channel;
channel = p->chan_list[counter++ % p->num_chan]; channel = p->chan_list[counter++ % p->num_chan];
esp_wifi_remain_on_channel(ESP_IF_WIFI_STA, WIFI_ROC_REQ, channel, esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, channel,
BOOTSTRAP_ROC_WAIT_TIME, s_action_rx_cb); BOOTSTRAP_ROC_WAIT_TIME, s_action_rx_cb);
} }
break; break;
@@ -533,7 +533,7 @@ esp_supp_dpp_bootstrap_gen(const char *chan_list, enum dpp_bootstrap_type type,
goto fail; goto fail;
} }
params->type = type; params->type = type;
esp_wifi_get_mac(ESP_IF_WIFI_STA, params->mac); esp_wifi_get_mac(WIFI_IF_STA, params->mac);
if (uri_info) { if (uri_info) {
params->info_len = strlen(uri_info); params->info_len = strlen(uri_info);
@@ -608,7 +608,7 @@ esp_err_t esp_supp_dpp_start_listen(void)
void esp_supp_dpp_stop_listen(void) void esp_supp_dpp_stop_listen(void)
{ {
s_dpp_stop_listening = true; s_dpp_stop_listening = true;
esp_wifi_remain_on_channel(ESP_IF_WIFI_STA, WIFI_ROC_CANCEL, 0, 0, NULL); esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_CANCEL, 0, 0, NULL);
} }
esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb) esp_err_t esp_supp_dpp_init(esp_supp_dpp_event_cb_t cb)

View File

@@ -128,7 +128,7 @@ void esp_send_action_frame(uint8_t *dest_mac, const uint8_t *buf, uint32_t len,
wifi_action_tx_req_t *req = os_zalloc(sizeof(*req) + len);; wifi_action_tx_req_t *req = os_zalloc(sizeof(*req) + len);;
TEST_ASSERT( req != NULL); TEST_ASSERT( req != NULL);
req->ifx = ESP_IF_WIFI_STA; req->ifx = WIFI_IF_STA;
memcpy(req->dest_mac, dest_mac, ETH_ALEN); memcpy(req->dest_mac, dest_mac, ETH_ALEN);
req->no_ack = false; req->no_ack = false;
req->data_len = len; req->data_len = len;
@@ -155,7 +155,7 @@ TEST_CASE("Test scan and ROC simultaneously", "[Offchan]")
xEventGroupWaitBits(wifi_event, WIFI_START_EVENT, 1, 0, 5000 / portTICK_RATE_MS); xEventGroupWaitBits(wifi_event, WIFI_START_EVENT, 1, 0, 5000 / portTICK_RATE_MS);
TEST_ESP_OK(esp_wifi_remain_on_channel(ESP_IF_WIFI_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL, TEST_ESP_OK(esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL,
100, rx_cb)); 100, rx_cb));
ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, false)); ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, false));
bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_SCAN_DONE_EVENT, bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_SCAN_DONE_EVENT,
@@ -164,7 +164,7 @@ TEST_CASE("Test scan and ROC simultaneously", "[Offchan]")
vTaskDelay(1000 / portTICK_PERIOD_MS); vTaskDelay(1000 / portTICK_PERIOD_MS);
ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, false)); ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, false));
TEST_ESP_OK(esp_wifi_remain_on_channel(ESP_IF_WIFI_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL, TEST_ESP_OK(esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL,
100, rx_cb)); 100, rx_cb));
bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_SCAN_DONE_EVENT, bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_SCAN_DONE_EVENT,
pdTRUE, pdFALSE, 5000 / portTICK_RATE_MS); pdTRUE, pdFALSE, 5000 / portTICK_RATE_MS);
@@ -221,17 +221,17 @@ static void test_wifi_roc(void)
start_wifi_as_sta(); start_wifi_as_sta();
xEventGroupWaitBits(wifi_event, WIFI_START_EVENT, 1, 0, 5000 / portTICK_RATE_MS); xEventGroupWaitBits(wifi_event, WIFI_START_EVENT, 1, 0, 5000 / portTICK_RATE_MS);
TEST_ESP_OK(esp_wifi_get_mac(ESP_IF_WIFI_STA, mac)); TEST_ESP_OK(esp_wifi_get_mac(WIFI_IF_STA, mac));
sprintf(mac_str, MACSTR, MAC2STR(mac)); sprintf(mac_str, MACSTR, MAC2STR(mac));
unity_send_signal_param("Listener mac", mac_str); unity_send_signal_param("Listener mac", mac_str);
TEST_ESP_OK(esp_wifi_remain_on_channel(ESP_IF_WIFI_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL, TEST_ESP_OK(esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_REQ, TEST_LISTEN_CHANNEL,
10000, rx_cb)); 10000, rx_cb));
bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_ACTION_RX_EVENT, bits = xEventGroupWaitBits(wifi_event, WIFI_ROC_DONE_EVENT | WIFI_ACTION_RX_EVENT,
pdTRUE, pdFALSE, portMAX_DELAY); pdTRUE, pdFALSE, portMAX_DELAY);
/* Confirm that Frame has been received successfully */ /* Confirm that Frame has been received successfully */
if (bits == WIFI_ACTION_RX_EVENT) { if (bits == WIFI_ACTION_RX_EVENT) {
TEST_ESP_OK(esp_wifi_remain_on_channel(ESP_IF_WIFI_STA, WIFI_ROC_CANCEL, 0, 0, NULL)); TEST_ESP_OK(esp_wifi_remain_on_channel(WIFI_IF_STA, WIFI_ROC_CANCEL, 0, 0, NULL));
vTaskDelay(1000 / portTICK_PERIOD_MS); vTaskDelay(1000 / portTICK_PERIOD_MS);
stop_wifi(); stop_wifi();
} else { } else {

View File

@@ -28,6 +28,7 @@
#define SNIFFER_PROCESS_PACKET_TIMEOUT_MS (100) #define SNIFFER_PROCESS_PACKET_TIMEOUT_MS (100)
#define SNIFFER_PROCESS_APPTRACE_TIMEOUT_US (100) #define SNIFFER_PROCESS_APPTRACE_TIMEOUT_US (100)
#define SNIFFER_APPTRACE_RETRY (10) #define SNIFFER_APPTRACE_RETRY (10)
#define SNIFFER_RX_FCS_ERR (0X41)
static const char *SNIFFER_TAG = "cmd_sniffer"; static const char *SNIFFER_TAG = "cmd_sniffer";
#define SNIFFER_CHECK(a, str, goto_tag, ...) \ #define SNIFFER_CHECK(a, str, goto_tag, ...) \
@@ -82,10 +83,11 @@ static uint32_t hash_func(const char *str, uint32_t max_num)
static void create_wifi_filter_hashtable(void) static void create_wifi_filter_hashtable(void)
{ {
char *wifi_filter_keys[SNIFFER_WLAN_FILTER_MAX] = {"mgmt", "data", "ctrl", "misc", "mpdu", "ampdu"}; char *wifi_filter_keys[SNIFFER_WLAN_FILTER_MAX] = {"mgmt", "data", "ctrl", "misc", "mpdu", "ampdu", "fcsfail"};
uint32_t wifi_filter_values[SNIFFER_WLAN_FILTER_MAX] = {WIFI_PROMIS_FILTER_MASK_MGMT, WIFI_PROMIS_FILTER_MASK_DATA, uint32_t wifi_filter_values[SNIFFER_WLAN_FILTER_MAX] = {WIFI_PROMIS_FILTER_MASK_MGMT, WIFI_PROMIS_FILTER_MASK_DATA,
WIFI_PROMIS_FILTER_MASK_CTRL, WIFI_PROMIS_FILTER_MASK_MISC, WIFI_PROMIS_FILTER_MASK_CTRL, WIFI_PROMIS_FILTER_MASK_MISC,
WIFI_PROMIS_FILTER_MASK_DATA_MPDU, WIFI_PROMIS_FILTER_MASK_DATA_AMPDU WIFI_PROMIS_FILTER_MASK_DATA_MPDU, WIFI_PROMIS_FILTER_MASK_DATA_AMPDU,
WIFI_PROMIS_FILTER_MASK_FCSFAIL
}; };
for (int i = 0; i < SNIFFER_WLAN_FILTER_MAX; i++) { for (int i = 0; i < SNIFFER_WLAN_FILTER_MAX; i++) {
uint32_t idx = hash_func(wifi_filter_keys[i], SNIFFER_WLAN_FILTER_MAX); uint32_t idx = hash_func(wifi_filter_keys[i], SNIFFER_WLAN_FILTER_MAX);
@@ -126,6 +128,7 @@ static void wifi_sniffer_cb(void *recv_buf, wifi_promiscuous_pkt_type_t type)
packet_info.seconds = sniffer->rx_ctrl.timestamp / 1000000U; packet_info.seconds = sniffer->rx_ctrl.timestamp / 1000000U;
packet_info.microseconds = sniffer->rx_ctrl.timestamp % 1000000U; packet_info.microseconds = sniffer->rx_ctrl.timestamp % 1000000U;
packet_info.length = sniffer->rx_ctrl.sig_len; packet_info.length = sniffer->rx_ctrl.sig_len;
/* For now, the sniffer only dumps the length of the MISC type frame */ /* For now, the sniffer only dumps the length of the MISC type frame */
if (type != WIFI_PKT_MISC && !sniffer->rx_ctrl.rx_state) { if (type != WIFI_PKT_MISC && !sniffer->rx_ctrl.rx_state) {
packet_info.length -= SNIFFER_PAYLOAD_FCS_LEN; packet_info.length -= SNIFFER_PAYLOAD_FCS_LEN;
@@ -378,7 +381,7 @@ void register_sniffer(void)
"name of the file storing the packets in pcap format"); "name of the file storing the packets in pcap format");
sniffer_args.interface = arg_str0("i", "interface", "<wlan>", sniffer_args.interface = arg_str0("i", "interface", "<wlan>",
"which interface to capture packet"); "which interface to capture packet");
sniffer_args.filter = arg_strn("F", "filter", "<mgmt|data|ctrl|misc|mpdu|ampdu>", 0, 6, "filter parameters"); sniffer_args.filter = arg_strn("F", "filter", "<mgmt|data|ctrl|misc|mpdu|ampdu|fcsfail>", 0, 7, "filter parameters");
sniffer_args.channel = arg_int0("c", "channel", "<channel>", "communication channel to use"); sniffer_args.channel = arg_int0("c", "channel", "<channel>", "communication channel to use");
sniffer_args.stop = arg_lit0(NULL, "stop", "stop running sniffer"); sniffer_args.stop = arg_lit0(NULL, "stop", "stop running sniffer");
sniffer_args.end = arg_end(1); sniffer_args.end = arg_end(1);

View File

@@ -31,6 +31,7 @@ typedef enum {
SNIFFER_WLAN_FILTER_MISC, /*!< MISC */ SNIFFER_WLAN_FILTER_MISC, /*!< MISC */
SNIFFER_WLAN_FILTER_MPDU, /*!< MPDU */ SNIFFER_WLAN_FILTER_MPDU, /*!< MPDU */
SNIFFER_WLAN_FILTER_AMPDU, /*!< AMPDU */ SNIFFER_WLAN_FILTER_AMPDU, /*!< AMPDU */
SNIFFER_WLAN_FILTER_FCSFAIL, /*!< When this bit is set, the hardware will receive packets for which frame check sequence failed */
SNIFFER_WLAN_FILTER_MAX SNIFFER_WLAN_FILTER_MAX
} sniffer_wlan_filter_t; } sniffer_wlan_filter_t;