]> granicus.if.org Git - esp-idf/commitdiff
add Channel State Information(CSI) support
authorXia Xiaotian <xiaxiaotian@espressif.com>
Wed, 9 May 2018 08:44:06 +0000 (16:44 +0800)
committerXia Xiaotian <xiaxiaotian@espressif.com>
Sun, 20 May 2018 11:25:25 +0000 (19:25 +0800)
components/esp32/Kconfig [changed mode: 0644->0755]
components/esp32/include/esp_wifi.h
components/esp32/include/esp_wifi_types.h
components/esp32/lib

old mode 100644 (file)
new mode 100755 (executable)
index 7ef096a..8fe485e
@@ -956,6 +956,14 @@ config ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM
         can deliver frames faster than WiFi layer can transmit. In these cases, we may run out of TX
         buffers.
 
+config ESP32_WIFI_CSI_ENABLED
+    bool "WiFi CSI(Channel State Information)"
+    default n
+    help
+        Select this option to enable CSI(Channel State Information) feature. CSI takes about 
+        CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM KB of RAM. If CSI is not used, it is better to disable 
+        this feature in order to save memory.
+
 config ESP32_WIFI_AMPDU_TX_ENABLED
     bool "WiFi AMPDU TX"
     default y
index f3333eebd901e7c8cab274e3376829787d7cd8ab..bacfb13c673439750c702149a962d4150b440aaf 100755 (executable)
@@ -99,6 +99,7 @@ typedef struct {
     int                    tx_buf_type;            /**< WiFi TX buffer type */
     int                    static_tx_buf_num;      /**< WiFi static TX buffer number */
     int                    dynamic_tx_buf_num;     /**< WiFi dynamic TX buffer number */
+    int                    csi_enable;             /**< WiFi channel state information enable flag */
     int                    ampdu_rx_enable;        /**< WiFi AMPDU RX feature enable flag */
     int                    ampdu_tx_enable;        /**< WiFi AMPDU TX feature enable flag */
     int                    nvs_enable;             /**< WiFi NVS flash enable flag */
@@ -121,6 +122,12 @@ typedef struct {
 #define WIFI_DYNAMIC_TX_BUFFER_NUM 0
 #endif
 
+#if CONFIG_ESP32_WIFI_CSI_ENABLED
+#define WIFI_CSI_ENABLED         1
+#else
+#define WIFI_CSI_ENABLED         0
+#endif
+
 #if CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED
 #define WIFI_AMPDU_RX_ENABLED        1
 #else
@@ -175,6 +182,7 @@ extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
     .tx_buf_type = CONFIG_ESP32_WIFI_TX_BUFFER_TYPE,\
     .static_tx_buf_num = WIFI_STATIC_TX_BUFFER_NUM,\
     .dynamic_tx_buf_num = WIFI_DYNAMIC_TX_BUFFER_NUM,\
+    .csi_enable = WIFI_CSI_ENABLED,\
     .ampdu_rx_enable = WIFI_AMPDU_RX_ENABLED,\
     .ampdu_tx_enable = WIFI_AMPDU_TX_ENABLED,\
     .nvs_enable = WIFI_NVS_ENABLED,\
@@ -964,6 +972,59 @@ esp_err_t esp_wifi_get_event_mask(uint32_t *mask);
 
 esp_err_t esp_wifi_80211_tx(wifi_interface_t ifx, const void *buffer, int len, bool en_sys_seq);
 
+/**
+  * @brief The RX callback function of Channel State Information(CSI)  data. 
+  *
+  *        Each time a CSI data is received, the callback function will be called.
+  *
+  * @param ctx context argument, passed to esp_wifi_set_csi_rx_cb() when registering callback function. 
+  * @param data CSI data received. 
+  *
+  */
+typedef void (* wifi_csi_cb_t)(void *ctx, wifi_csi_info_t *data);
+
+
+/**
+  * @brief Register the RX callback function of CSI data.
+  *
+  *        Each time a CSI data is received, the callback function will be called.
+  *
+  * @param cb  callback
+  * @param ctx context argument, passed to callback function
+  *
+  * @return
+  *    - ESP_OK: succeed
+  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
+  */
+
+esp_err_t esp_wifi_set_csi_rx_cb(wifi_csi_cb_t cb, void *ctx);
+
+/**
+  * @brief Set CSI data configuration
+  *
+  * @param config configuration
+  * 
+  * return
+  *    - ESP_OK: succeed
+  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
+  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
+  *    - ESP_ERR_INVALID_ARG: invalid argument
+  */
+esp_err_t esp_wifi_set_csi_config(const wifi_csi_config_t *config);
+
+/**
+  * @brief Enable or disable CSI
+  *
+  * @param en true - enable, false - disable
+  *
+  * return
+  *    - ESP_OK: succeed
+  *    - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
+  *    - ESP_ERR_WIFI_NOT_START: WiFi is not started by esp_wifi_start or promiscuous mode is not enabled
+  *    - ESP_ERR_INVALID_ARG: invalid argument
+  */
+esp_err_t esp_wifi_set_csi(bool en);
+
 #ifdef __cplusplus
 }
 #endif
index 47972099690221636a20cd64350ee0b543b9eb61..be4a68c2897b9f118a37988c4584080cc996c381 100755 (executable)
@@ -308,13 +308,15 @@ typedef struct {
     unsigned stbc:2;          /**< STBC */
     unsigned fec_coding:1;    /**< Flag is set for 11n packets which are LDPC */
     unsigned sgi:1;           /**< SGI */
-    unsigned noise_floor:8;   /**< noise floor */
+    signed noise_floor:8;     /**< noise floor */
     unsigned ampdu_cnt:8;     /**< ampdu cnt */
-    unsigned channel:4;       /**< which channel this packet in */
-    unsigned :12;             /**< reserve */
-    unsigned timestamp:32;    /**< timestamp */
-    unsigned :32;             /**< reserve */
+    unsigned channel:4;       /**< which primary channel this packet in */
+    unsigned second_channel:4;/**< which second channel this packet in */
+    unsigned :8;              /**< reserve */
+    unsigned timestamp:32;    /**< timestamp, unit: microsecond */
     unsigned :32;             /**< reserve */
+    unsigned :31;             /**< reserve */
+    unsigned ant:1;           /**< antenna number from which this packet is received */
     unsigned sig_len:12;      /**< length of packet */
     unsigned :12;             /**< reserve */
     unsigned rx_state:8;      /**< rx state */
@@ -369,6 +371,30 @@ typedef struct {
 #define WIFI_EVENT_MASK_NONE                (0)           /**< mask none of the WiFi events */
 #define WIFI_EVENT_MASK_AP_PROBEREQRECVED   (BIT(0))      /**< mask SYSTEM_EVENT_AP_PROBEREQRECVED event */
 
+/**
+  * @brief Channel state information(CSI) configuration type
+  *
+  */
+typedef struct {
+    bool lltf_en;           /**< enable to receive legacy long training field(lltf) data */
+    bool htltf_en;          /**< enable to receive HT long training field(htltf) data */
+    bool stbcltf2_en;       /**< enable to receive space time block code long training field(stbcltf2) data */
+    bool manu_scale;        /**< manually scale the CSI data by left shifting or automatically scale the CSI data. If set true, please set the shift bits. false: automatically. true: manually */ 
+    uint8_t shift;          /**< manually left shift bits of the scale of the CSI data. The range of the left shift bits is 0~15 */
+} wifi_csi_config_t;
+
+/**
+  * @brief CSI data type
+  *
+  */
+typedef struct {
+    wifi_pkt_rx_ctrl_t rx_ctrl;/**< received packet radio metadata header of the CSI data */
+    uint8_t mac[6];            /**< source MAC address of the CSI data */
+    bool last_word_invalid;    /**< last four bytes of the CSI data is invalid or not */
+    uint8_t *buf;              /**< buffer of CSI data */
+    uint16_t len;              /**< length of CSI data */
+} wifi_csi_info_t;
+
 #ifdef __cplusplus
 }
 #endif
index 0503727b12bf40e5578959c6d9478f25312cdc81..8b2f4de9d779f72829a6ce54be2b7b5f1d9add09 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 0503727b12bf40e5578959c6d9478f25312cdc81
+Subproject commit 8b2f4de9d779f72829a6ce54be2b7b5f1d9add09