xref: /openwifi/doc/app_notes/csi.md (revision a6085186d94dfe08b0e09c18c8d4b1b4fe38ea35)
1*a6085186SLina Ceballos<!--
2*a6085186SLina CeballosSPDX-FileCopyrightText: 2019 Jiao Xianjun <[email protected]>
3*a6085186SLina CeballosSPDX-License-Identifier: AGPL-3.0-or-later
4*a6085186SLina Ceballos-->
5*a6085186SLina Ceballos
6*a6085186SLina Ceballos
76dfa79bdSJiao XianjunWe extend the **CSI** (Channel State Information) to **CSI** (Chip State Information)!
86dfa79bdSJiao Xianjun
922dd0cc4SXianjun Jiao## Quick start
1022dd0cc4SXianjun Jiao- Power on the SDR board.
1122dd0cc4SXianjun Jiao- Connect a computer to the SDR board via Ethernet cable. The computer should have static IP 192.168.10.1. Open a terminal on the computer, and then in the terminal:
1222dd0cc4SXianjun Jiao  ```
1322dd0cc4SXianjun Jiao  ssh [email protected]
1422dd0cc4SXianjun Jiao  (password: openwifi)
1522dd0cc4SXianjun Jiao  cd openwifi
1622dd0cc4SXianjun Jiao  ./wgd.sh
1722dd0cc4SXianjun Jiao  (Wait for the script completed)
1822dd0cc4SXianjun Jiao  ./monitor_ch.sh sdr0 11
1922dd0cc4SXianjun Jiao  (Monitor on channel 11. You can change 11 to other channel that is busy)
2022dd0cc4SXianjun Jiao  insmod side_ch.ko
2122dd0cc4SXianjun Jiao  ./side_ch_ctl g
2222dd0cc4SXianjun Jiao  ```
2322dd0cc4SXianjun Jiao  You should see on board outputs like:
2422dd0cc4SXianjun Jiao  ```
2522dd0cc4SXianjun Jiao  loop 64 side info count 61
2622dd0cc4SXianjun Jiao  loop 128 side info count 99
2722dd0cc4SXianjun Jiao  ...
2822dd0cc4SXianjun Jiao  ```
2922dd0cc4SXianjun Jiao  If the second number (61, 99, ...) is not zero and keeps increasing, that means the CSI (Chip State Information) is going to the computer smoothly.
3022dd0cc4SXianjun Jiao
3122dd0cc4SXianjun Jiao- Open another terminal on the computer, and run:
3222dd0cc4SXianjun Jiao  ```
3322dd0cc4SXianjun Jiao  cd openwifi/user_space/side_ch_ctl_src
3422dd0cc4SXianjun Jiao  python3 side_info_display.py
3522dd0cc4SXianjun Jiao  ```
3622dd0cc4SXianjun Jiao  The python script needs "matplotlib.pyplot" and "numpy" packages installed. Now you should see 3 figures showing run-time **frequency offset**, **channel state/response** and **constellation form equalizer**. Meanwhile the python script prints the **timestamp**.
37f128da31SJiao Xianjun  ![](./csi-screen-shot.jpg)
3822dd0cc4SXianjun Jiao
39d37eefc6SJiao Xianjun  While running, all informations are also stored into a file **side_info.txt**. A matlab script **test_side_info_file_display.m** is offered to help you do analysis on the Chip State Information offline.
4022dd0cc4SXianjun Jiao
41db036a32SJiao Xianjun## Understand the CSI feature
421f919d9fSJiao Xianjun  The CSI information is extracted via the openwifi **side channel** infrastructure. This figure explains the related modules (also related source code file name) and how the information goes from the SDR board to the computer.
431f919d9fSJiao Xianjun  ![](./csi-architecture.jpg)
441f919d9fSJiao Xianjun
451f919d9fSJiao Xianjun  The CSI information format is shown in this figure.
461f919d9fSJiao Xianjun  ![](./csi-information-format.jpg)
471f919d9fSJiao Xianjun
481f919d9fSJiao Xianjun  For each element, the actual size is 64bit.
491f919d9fSJiao Xianjun  - timestamp: 64bit TSF timer value, which is the same timestamp value shown by other sniffer software, like tcpdump, wireshark or openwifi printing in dmesg.
501f919d9fSJiao Xianjun  - freq_offset: Only the 1st 16bit is used.
511f919d9fSJiao Xianjun  - csi (channel state/response) and equalizer: Only the first two 16bit are used for I/Q of channel response and equalizer output. The remaining two 16bit are reserved for future multi-antenna cases.
521f919d9fSJiao Xianjun
531f919d9fSJiao Xianjun  The python and Matlab scripts are recommended for you to understand the CSI packet format precisely.
541f919d9fSJiao Xianjun
5522dd0cc4SXianjun Jiao## Config the capture condition and interval
56d37eefc6SJiao Xianjun  The quick start guide will monitor all CSI informations of all packets decoded by the WiFi ofdm receiver. To monitor only specific packets that match the specific conditions: FC (Frame Control), addr1 (target MAC address), addr2 (source MAC address), configuration command should be issued before executing "**side_ch_ctl g**". The configuration command is realized by feeding a different parameter to "**side_ch_ctl**".
5722dd0cc4SXianjun Jiao
5822dd0cc4SXianjun Jiao  A quick example: Capture only CSI of those packets from the device with MAC address 56:5b:01:ec:e2:8f
5922dd0cc4SXianjun Jiao  ```
6022dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h4001
6122dd0cc4SXianjun Jiao  ./side_ch_ctl wh7h01ece28f
625bec388bSJiao Xianjun  (01ece28f are the last 32 bits of MAC address 56:5b:01:ec:e2:8f)
6322dd0cc4SXianjun Jiao  ./side_ch_ctl g
6422dd0cc4SXianjun Jiao  ```
6522dd0cc4SXianjun Jiao  The parameter string format is explained in detail:
6622dd0cc4SXianjun Jiao  ```
6722dd0cc4SXianjun Jiao  whXhY
6822dd0cc4SXianjun Jiao  ```
6922dd0cc4SXianjun Jiao  The X is the register index, and the Y is the value in hex format. The remaining "w", "h" and "h" should be kept untouched.
7022dd0cc4SXianjun Jiao  - To turn on conditional capture, X should be 1. For Y: bit11~bit0 should be 001(hex), bit12: on/off of FC match, bit13: on/off of addr1 match, bit14 : on/off of addr2 match. Examples:
7122dd0cc4SXianjun Jiao  ```
72d37eefc6SJiao Xianjun  Turn on FC only match:
7322dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h1001
7402b2164dSJiao Xianjun  (1001 is the value in hex format)
75d37eefc6SJiao Xianjun  Turn on addr2 (source address) only match:
7622dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h4001
7722dd0cc4SXianjun Jiao
78d37eefc6SJiao Xianjun  Turn on both FC and addr1 (target address) match:
7922dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h3001
8022dd0cc4SXianjun Jiao
8122dd0cc4SXianjun Jiao  Turn off conditional capture (all packets will be captured):
8222dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h0001
8322dd0cc4SXianjun Jiao  ```
84d37eefc6SJiao Xianjun  - To specify the condition matching target (when that type of match is turned on by above command):
8522dd0cc4SXianjun Jiao  ```
8622dd0cc4SXianjun Jiao  Specify the FC matching target:
8722dd0cc4SXianjun Jiao  ./side_ch_ctl wh5hY
8802b2164dSJiao Xianjun  (Y is the FC value in hex format)
8922dd0cc4SXianjun Jiao  Specify the addr1 (target address) matching target:
9022dd0cc4SXianjun Jiao  ./side_ch_ctl wh6hY
9122dd0cc4SXianjun Jiao
9222dd0cc4SXianjun Jiao  Specify the addr2 (source address) matching target:
9322dd0cc4SXianjun Jiao  ./side_ch_ctl wh7hY
9402b2164dSJiao Xianjun  (Y is the MAC address in hex format. Only the last 32 bits are needed. Example: for 56:5b:01:ec:e2:8f, 01ece28f should be input.)
9522dd0cc4SXianjun Jiao  ```
9622dd0cc4SXianjun Jiao  The command "**side_ch_ctl g**" will perform CSI capture every 100ms until you press ctrl+C. To use a different capture interval:
9722dd0cc4SXianjun Jiao  ```
9822dd0cc4SXianjun Jiao  side_ch_ctl gN
9922dd0cc4SXianjun Jiao  ```
100f71252c5SXianjun Jiao  The interval will become N*1ms
10122dd0cc4SXianjun Jiao
10222dd0cc4SXianjun Jiao## Config the num_eq
10322dd0cc4SXianjun Jiao  The num_eq (number of equalizer output) is configurable in case you don't need so many equalizer informations. The valid value is 0~8. You should align the num_eq value at the side_ch.ko, side_info_display.py and test_side_info_file_display.m.
10422dd0cc4SXianjun Jiao  - When insert the kernel module, use:
10522dd0cc4SXianjun Jiao  ```
10622dd0cc4SXianjun Jiao  insmod side_ch.ko num_eq_init=3
10722dd0cc4SXianjun Jiao  ```
10822dd0cc4SXianjun Jiao  You can replace 3 by number 0~8. (8 is the default value. You don't need to specify it like in the Quick start section)
10922dd0cc4SXianjun Jiao  - When launch the python script, use:
11022dd0cc4SXianjun Jiao  ```
11122dd0cc4SXianjun Jiao  side_info_display.py 3
11222dd0cc4SXianjun Jiao  ```
11322dd0cc4SXianjun Jiao  - When use the Matlab script, please change the num_eq variable in the script to 3 (3 is just an example).
11422dd0cc4SXianjun Jiao
115f71252c5SXianjun Jiao## Compile the side channel driver and user space program
116f71252c5SXianjun Jiao  - side_ch.ko
117f71252c5SXianjun Jiao  ```
118f71252c5SXianjun Jiao  $OPENWIFI_DIR/driver/side_ch/make_driver.sh $OPENWIFI_DIR $XILINX_DIR ARCH_BIT
119f71252c5SXianjun Jiao(For Zynq 7000, ARCH_BIT should be 32, for Zynq MPSoC, ARCH_BIT should be 64)
120f71252c5SXianjun Jiao  ```
121f71252c5SXianjun Jiao  - side_ch_ctl (take user_space/side_ch_ctl_src/side_ch_ctl.c and compile it on board!)
122f71252c5SXianjun Jiao  ```
123f71252c5SXianjun Jiao  gcc -o side_ch_ctl side_ch_ctl.c
124f71252c5SXianjun Jiao  ```
125f71252c5SXianjun Jiao
126db036a32SJiao Xianjun## Run the CSI together with modes other than monitor
127d37eefc6SJiao Xianjun  The openwifi CSI feature could run with not only monitor mode but also other modes, such as AP-Client or ad-hoc mode. After the communication functionality is fully up in those modes, you can start CSI feature from "**insmod side_ch.ko**" and "**./side_ch_ctl g**" on board as described in the previous sections to extract CSI to your computer.
12822dd0cc4SXianjun Jiao
12922dd0cc4SXianjun Jiao## Map the CSI information to the WiFi packet
130d37eefc6SJiao Xianjun  If you want to relate the CSI information to the WiFi packet, you need to capture WiFi packets (tcpdump/wireshark/etc) while capturing CSI. Then you can match the timestamp (TSF timer value) between WiFi packet and CSI information, because this is the unique same identity of a Wifi packet and related CSI information.
13122dd0cc4SXianjun Jiao
132d37eefc6SJiao Xianjun  Please learn the python and Matlab script to extract CSI information per packet according to your requirement.
133