From f40be8eb77aa258672a49ee522ee226d83c21be7 Mon Sep 17 00:00:00 2001 From: Liu Zhi Fu Date: Fri, 26 May 2017 14:11:16 +0800 Subject: [PATCH] esp32: add sniffer filter api Add sniffer filter to filter specified packets --- components/esp32/include/esp_wifi.h | 25 +++++++++++++++++++++++ components/esp32/include/esp_wifi_types.h | 15 ++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/components/esp32/include/esp_wifi.h b/components/esp32/include/esp_wifi.h index ae78f629c..6e51bf2ef 100755 --- a/components/esp32/include/esp_wifi.h +++ b/components/esp32/include/esp_wifi.h @@ -610,6 +610,31 @@ esp_err_t esp_wifi_set_promiscuous(bool en); */ esp_err_t esp_wifi_get_promiscuous(bool *en); +/** + * @brief Enable the promiscuous filter. + * + * @attention 1. The default filter is to filter all packets except WIFI_PKT_MISC + * + * @param filter the packet type filtered by promisucous + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init + */ +esp_err_t esp_wifi_set_promiscuous_filter(const wifi_promiscuous_filter_t *filter); + +/** + * @brief Get the promiscuous filter. + * + * @param[out] filter store the current status of promiscuous filter + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init + * - ESP_ERR_WIFI_ARG: invalid argument + */ +esp_err_t esp_wifi_get_promiscuous_filter(wifi_promiscuous_filter_t *filter); + /** * @brief Set the configuration of the ESP32 STA or AP * diff --git a/components/esp32/include/esp_wifi_types.h b/components/esp32/include/esp_wifi_types.h index 02b8563a6..f9a046739 100755 --- a/components/esp32/include/esp_wifi_types.h +++ b/components/esp32/include/esp_wifi_types.h @@ -246,12 +246,23 @@ typedef struct { * */ typedef enum { - WIFI_PKT_CTRL, /**< control type, receive packet buf is wifi_promiscuous_pkt_t */ WIFI_PKT_MGMT, /**< management type, receive packet buf is wifi_promiscuous_pkt_t */ WIFI_PKT_DATA, /**< data type, receive packet buf is wifi_promiscuous_pkt_t */ - WIFI_PKT_MISC, /**< other type, receive packet buf is wifi_promiscuous_pkt_t */ + WIFI_PKT_MISC, /**< other type, such as MIMO etc, receive packet buf is wifi_promiscuous_pkt_t but the payload is NULL!!! */ } wifi_promiscuous_pkt_type_t; + +#define WIFI_PROMIS_FILTER_MASK_ALL (0xFFFFFFFF) /**< filter all packets */ +#define WIFI_PROMIS_FILTER_MASK_MGMT (1) /**< filter the packets with type of WIFI_PKT_MGMT */ +#define WIFI_PROMIS_FILTER_MASK_DATA (1<<1) /**< filter the packets with type of WIFI_PKT_DATA */ +#define WIFI_PROMIS_FILTER_MASK_MISC (1<<2) /**< filter the packets with type of WIFI_PKT_MISC */ +#define WIFI_PROMIS_FILTER_MASK_DATA_MPDU (1<<3) /**< filter the MPDU which is a kind of WIFI_PKT_DATA */ +#define WIFI_PROMIS_FILTER_MASK_DATA_AMPDU (1<<4) /**< filter the AMPDU which is a kind of WIFI_PKT_DATA */ + +typedef struct { + uint32_t filter_mask; +} wifi_promiscuous_filter_t; + #ifdef __cplusplus } #endif