From f3b72ef6aac16814a09e129a486afec8f19773ae Mon Sep 17 00:00:00 2001
From: XiaXiaotian <xiaxiaotian@espressif.com>
Date: Thu, 27 Dec 2018 21:06:58 +0800
Subject: [PATCH] esp32: fix invalid channel state information(CSI) data index

    Due to a hardware limitation in ESP32, the first four bytes of some
    CSI data is invalid, not the last four bytes.

    Correct a mistake of CSI sub-carrier index in documentation.
---
 components/esp32/include/esp_wifi_types.h |  2 +-
 components/esp32/lib                      |  2 +-
 docs/en/api-guides/wifi.rst               | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/components/esp32/include/esp_wifi_types.h b/components/esp32/include/esp_wifi_types.h
index 2a4d2beb72..e16ca19bdf 100644
--- a/components/esp32/include/esp_wifi_types.h
+++ b/components/esp32/include/esp_wifi_types.h
@@ -405,7 +405,7 @@ typedef struct {
 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 */
+    bool first_word_invalid;   /**< first four bytes of the CSI data is invalid or not */
     int8_t *buf;               /**< buffer of CSI data */
     uint16_t len;              /**< length of CSI data */
 } wifi_csi_info_t;
diff --git a/components/esp32/lib b/components/esp32/lib
index 0eef73e06f..15e5970465 160000
--- a/components/esp32/lib
+++ b/components/esp32/lib
@@ -1 +1 @@
-Subproject commit 0eef73e06f960afc6403a60bcc2a18cf55e9bbf8
+Subproject commit 15e597046578a458950345ccb19d09b24085c0fd
diff --git a/docs/en/api-guides/wifi.rst b/docs/en/api-guides/wifi.rst
index a85518a7c1..d25ba605b0 100644
--- a/docs/en/api-guides/wifi.rst
+++ b/docs/en/api-guides/wifi.rst
@@ -1662,11 +1662,11 @@ Channel state information (CSI) refers to the channel information of a Wi-Fi con
 +             +--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
 |             | STBC               |  non STBC   |  non STBC   |     STBC    | non STBC | non STBC | STBC |  non STBC   |     STBC    | non STBC | non STBC |  STBC  |  non STBC   |     STBC    |
 +-------------+--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
-| sub-carrier | LLTF               | 0~31,-31~-1 | 0~31,-31~-1 | 0~31,-31~-1 |   0~63   |   0~63   | 0~63 |     0~63    |     0~63    |  -64~-1  |  -64~-1  | -64~-1 |    -64~-1   |    -64~-1   |
+| sub-carrier | LLTF               | 0~31,-32~-1 | 0~31,-32~-1 | 0~31,-32~-1 |   0~63   |   0~63   | 0~63 |     0~63    |     0~63    |  -64~-1  |  -64~-1  | -64~-1 |    -64~-1   |    -64~-1   |
 +             +--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
-| index       | HT-LTF             |      -      | 0~31,-31~-1 | 0~31,-31~-1 |     -    |   0~63   | 0~62 | 0~63,-64~-1 | 0~60,-60~-1 |     -    |  -64~-1  | -62~-1 | 0~63,-64~-1 | 0~60,-60~-1 |
+| index       | HT-LTF             |      -      | 0~31,-32~-1 | 0~31,-32~-1 |     -    |   0~63   | 0~62 | 0~63,-64~-1 | 0~60,-60~-1 |     -    |  -64~-1  | -62~-1 | 0~63,-64~-1 | 0~60,-60~-1 |
 +             +--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
-|             | STBC-HT-LTF        |      -      |      -      | 0~31,-31~-1 |     -    |     -    | 0~62 |       -     | 0~60,-60~-1 |     -    |     -    | -62~-1 |       -     | 0~60,-60~-1 |
+|             | STBC-HT-LTF        |      -      |      -      | 0~31,-32~-1 |     -    |     -    | 0~62 |       -     | 0~60,-60~-1 |     -    |     -    | -62~-1 |       -     | 0~60,-60~-1 |
 +-------------+--------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
 | total bytes                      |     128     |     256     |     384     |    128   |    256   | 380  |      384    |      612    |    128   |    256   |   376  |      384    |      612    |
 +----------------------------------+-------------+-------------+-------------+----------+----------+------+-------------+-------------+----------+----------+--------+-------------+-------------+
@@ -1678,8 +1678,8 @@ All of the information in the table can be found in the structure wifi_csi_info_
     - Channel bandwidth refers to cwb field of rx_ctrl field. 
     - STBC refers to stbc field of rx_ctrl field. 
     - Total bytes refers to len field. 
-    - The CSI data corresponding to each Long Training Field type is stored in a buffer starting from the buf field. Each item is stored as two bytes: imaginary part followed by real part. The order is: LLTF, HT-LTF, STBC-HT-LTF. However all 3 items may not be present, depending on the packet type (see above).
-    - If last_word_invalid field of wifi_csi_info_t is true, it means that the last four bytes of CSI data is invalid due to a hardware limitation in ESP32. 
+    - The CSI data corresponding to each Long Training Field(LTF) type is stored in a buffer starting from the buf field. Each item is stored as two bytes: imaginary part followed by real part. The order of each item is the same as the sub-carrier in the table. The order of LTF is: LLTF, HT-LTF, STBC-HT-LTF. However all 3 LTFs may not be present, depending on the channel and packet information (see above). 
+    - If first_word_invalid field of wifi_csi_info_t is true, it means that the first four bytes of CSI data is invalid due to a hardware limitation in ESP32. 
     - More information like RSSI, noise floor of RF, receiving time and antenna is in the rx_ctrl field.
 
 .. note::
-- 
2.40.0