xref: /openwifi/doc/app_notes/csi.md (revision 22dd0cc4861dbe973efee122229ab82ac3dd2c9a)
1*22dd0cc4SXianjun Jiao## Quick start
2*22dd0cc4SXianjun Jiao- Power on the SDR board.
3*22dd0cc4SXianjun 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:
4*22dd0cc4SXianjun Jiao  ```
5*22dd0cc4SXianjun Jiao  ssh [email protected]
6*22dd0cc4SXianjun Jiao  (password: openwifi)
7*22dd0cc4SXianjun Jiao  cd openwifi
8*22dd0cc4SXianjun Jiao  ./wgd.sh
9*22dd0cc4SXianjun Jiao  (Wait for the script completed)
10*22dd0cc4SXianjun Jiao  ./monitor_ch.sh sdr0 11
11*22dd0cc4SXianjun Jiao  (Monitor on channel 11. You can change 11 to other channel that is busy)
12*22dd0cc4SXianjun Jiao  insmod side_ch.ko
13*22dd0cc4SXianjun Jiao  ./side_ch_ctl g
14*22dd0cc4SXianjun Jiao  ```
15*22dd0cc4SXianjun Jiao  You should see on board outputs like:
16*22dd0cc4SXianjun Jiao  ```
17*22dd0cc4SXianjun Jiao  loop 64 side info count 61
18*22dd0cc4SXianjun Jiao  loop 128 side info count 99
19*22dd0cc4SXianjun Jiao  ...
20*22dd0cc4SXianjun Jiao  ```
21*22dd0cc4SXianjun 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.
22*22dd0cc4SXianjun Jiao
23*22dd0cc4SXianjun Jiao- Open another terminal on the computer, and run:
24*22dd0cc4SXianjun Jiao  ```
25*22dd0cc4SXianjun Jiao  cd openwifi/user_space/side_ch_ctl_src
26*22dd0cc4SXianjun Jiao  python3 side_info_display.py
27*22dd0cc4SXianjun Jiao  ```
28*22dd0cc4SXianjun 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**.
29*22dd0cc4SXianjun Jiao
30*22dd0cc4SXianjun Jiao  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.
31*22dd0cc4SXianjun Jiao
32*22dd0cc4SXianjun Jiao## Config the capture condition and interval
33*22dd0cc4SXianjun Jiao  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 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**".
34*22dd0cc4SXianjun Jiao
35*22dd0cc4SXianjun Jiao  A quick example: Capture only CSI of those packets from the device with MAC address 56:5b:01:ec:e2:8f
36*22dd0cc4SXianjun Jiao  ```
37*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h4001
38*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh7h01ece28f
39*22dd0cc4SXianjun Jiao  ./side_ch_ctl g
40*22dd0cc4SXianjun Jiao  ```
41*22dd0cc4SXianjun Jiao  The parameter string format is explained in detail:
42*22dd0cc4SXianjun Jiao  ```
43*22dd0cc4SXianjun Jiao  whXhY
44*22dd0cc4SXianjun Jiao  ```
45*22dd0cc4SXianjun 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.
46*22dd0cc4SXianjun 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:
47*22dd0cc4SXianjun Jiao  ```
48*22dd0cc4SXianjun Jiao  Turn on FC match:
49*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h1001
50*22dd0cc4SXianjun Jiao
51*22dd0cc4SXianjun Jiao  Turn on addr2 (source address) match:
52*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h4001
53*22dd0cc4SXianjun Jiao
54*22dd0cc4SXianjun Jiao  Turn on FC and addr1 (target address) match:
55*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h3001
56*22dd0cc4SXianjun Jiao
57*22dd0cc4SXianjun Jiao  Turn off conditional capture (all packets will be captured):
58*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh1h0001
59*22dd0cc4SXianjun Jiao  ```
60*22dd0cc4SXianjun Jiao  - To specify the condition matching target:
61*22dd0cc4SXianjun Jiao  ```
62*22dd0cc4SXianjun Jiao  Specify the FC matching target:
63*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh5hY
64*22dd0cc4SXianjun Jiao
65*22dd0cc4SXianjun Jiao  Specify the addr1 (target address) matching target:
66*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh6hY
67*22dd0cc4SXianjun Jiao
68*22dd0cc4SXianjun Jiao  Specify the addr2 (source address) matching target:
69*22dd0cc4SXianjun Jiao  ./side_ch_ctl wh7hY
70*22dd0cc4SXianjun Jiao  ```
71*22dd0cc4SXianjun Jiao  The command "**side_ch_ctl g**" will perform CSI capture every 100ms until you press ctrl+C. To use a different capture interval:
72*22dd0cc4SXianjun Jiao  ```
73*22dd0cc4SXianjun Jiao  side_ch_ctl gN
74*22dd0cc4SXianjun Jiao  ```
75*22dd0cc4SXianjun Jiao  The interval will become N*100ms
76*22dd0cc4SXianjun Jiao
77*22dd0cc4SXianjun Jiao## Understand CSI feature
78*22dd0cc4SXianjun Jiao  The CSI information is extracted via the openwifi **side channel** infrastructure. This figure explains the related module (and related source code file name) and how the information goes from the board to the computer.
79*22dd0cc4SXianjun Jiao  ![](./csi-architecture.jpg)
80*22dd0cc4SXianjun Jiao
81*22dd0cc4SXianjun Jiao  The CSI information format is shown in this figure.
82*22dd0cc4SXianjun Jiao  ![](./csi-information-format.jpg)
83*22dd0cc4SXianjun Jiao
84*22dd0cc4SXianjun Jiao  For each element, the actual size is 64bit.
85*22dd0cc4SXianjun Jiao  - timestamp: 64bit TSF timer value, which is the same timestamp value shown by other sniffer software, like tcpdump, wireshark or openwifi printing in dmesg.
86*22dd0cc4SXianjun Jiao  - freq_offset: Only the 1st 16bit is used.
87*22dd0cc4SXianjun Jiao  - 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.
88*22dd0cc4SXianjun Jiao
89*22dd0cc4SXianjun Jiao  The python and Matlab scripts are recommended for you to understand the CSI packet format precisely.
90*22dd0cc4SXianjun Jiao
91*22dd0cc4SXianjun Jiao## Config the num_eq
92*22dd0cc4SXianjun 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.
93*22dd0cc4SXianjun Jiao  - When insert the kernel module, use:
94*22dd0cc4SXianjun Jiao  ```
95*22dd0cc4SXianjun Jiao  insmod side_ch.ko num_eq_init=3
96*22dd0cc4SXianjun Jiao  ```
97*22dd0cc4SXianjun 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)
98*22dd0cc4SXianjun Jiao  - When launch the python script, use:
99*22dd0cc4SXianjun Jiao  ```
100*22dd0cc4SXianjun Jiao  side_info_display.py 3
101*22dd0cc4SXianjun Jiao  ```
102*22dd0cc4SXianjun Jiao  - When use the Matlab script, please change the num_eq variable in the script to 3 (3 is just an example).
103*22dd0cc4SXianjun Jiao
104*22dd0cc4SXianjun Jiao## Run CSI together with mode other than monitor
105*22dd0cc4SXianjun Jiao  The CSI could run with not only monitor mode. When you run openwifi in AP-Client or ad-hoc mode, after your communication functionality is fully up, you can start from "**insmod side_ch.ko**" and "**./side_ch_ctl g**" on board as described in the quick start section to extract CSI to your computer.
106*22dd0cc4SXianjun Jiao
107*22dd0cc4SXianjun Jiao## Map the CSI information to the WiFi packet
108*22dd0cc4SXianjun Jiao  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.
109*22dd0cc4SXianjun Jiao
110*22dd0cc4SXianjun Jiao  Please read the python and Matlab script to extract CSI information per packet according to your requirement.
111