1<!-- 2Author: Xianjun jiao 3SPDX-FileCopyrightText: 2019 UGent 4SPDX-License-Identifier: AGPL-3.0-or-later 5--> 6 7 8We extend the **CSI** (Channel State Information) to **CSI** (Chip State Information)! 9 10## Quick start 11- Power on the SDR board. 12- 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: 13 ``` 14 ssh [email protected] 15 (password: openwifi) 16 cd openwifi 17 ./wgd.sh 18 (Wait for the script completed) 19 ./monitor_ch.sh sdr0 11 20 (Monitor on channel 11. You can change 11 to other channel that is busy) 21 insmod side_ch.ko 22 ./side_ch_ctl g 23 ``` 24 You should see on board outputs like: 25 ``` 26 loop 64 side info count 61 27 loop 128 side info count 99 28 ... 29 ``` 30 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. 31 32- On your computer (NOT in ssh!), run: 33 ``` 34 cd openwifi/user_space/side_ch_ctl_src 35 python3 side_info_display.py 36 ``` 37 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**. 38  39 40 While running, all information is 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. 41 42## Understand the CSI feature 43 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. 44  45 46 The CSI information format is shown in this figure. 47  48 49 For each element, the actual size is 64bit. 50 - timestamp: 64bit TSF timer value, which is the same timestamp value shown by other sniffer software, like tcpdump, wireshark or openwifi printing in dmesg. 51 - freq_offset: Only the 1st 16bit is used. 52 - 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. 53 54 The python and Matlab scripts are recommended for you to understand the CSI packet format precisely. 55 56## Config the capture condition and interval 57 The quick start guide will monitor all CSI information 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**". 58 59 A quick example: Capture only CSI of those packets from the device with MAC address 56:5b:01:ec:e2:8f 60 ``` 61 ./side_ch_ctl wh1h4001 62 ./side_ch_ctl wh7h01ece28f 63 (01ece28f are the last 32 bits of MAC address 56:5b:01:ec:e2:8f) 64 ./side_ch_ctl g 65 ``` 66 The parameter string format is explained in detail: 67 ``` 68 whXhY 69 ``` 70 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. 71 - 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: 72 ``` 73 Turn on FC only match: 74 ./side_ch_ctl wh1h1001 75 (1001 is the value in hex format) 76 Turn on addr2 (source address) only match: 77 ./side_ch_ctl wh1h4001 78 79 Turn on both FC and addr1 (target address) match: 80 ./side_ch_ctl wh1h3001 81 82 Turn off conditional capture (all packets will be captured): 83 ./side_ch_ctl wh1h0001 84 ``` 85 - To specify the condition matching target (when that type of match is turned on by above command): 86 ``` 87 Specify the FC matching target: 88 ./side_ch_ctl wh5hY 89 (Y is the FC value in hex format) 90 Specify the addr1 (target address) matching target: 91 ./side_ch_ctl wh6hY 92 93 Specify the addr2 (source address) matching target: 94 ./side_ch_ctl wh7hY 95 (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.) 96 ``` 97 The command "**side_ch_ctl g**" will perform CSI capture every 100ms until you press ctrl+C. To use a different capture interval: 98 ``` 99 side_ch_ctl gN 100 ``` 101 The interval will become N*1ms 102 103## Config the num_eq 104 The num_eq (number of equalizer output) is configurable in case you don't need so many equalizer information. 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. 105 - When insert the kernel module, use: 106 ``` 107 insmod side_ch.ko num_eq_init=3 108 ``` 109 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) 110 - When launch the python script, use: 111 ``` 112 side_info_display.py 3 113 ``` 114 - When use the Matlab script, please change the num_eq variable in the script to 3 (3 is just an example). 115 116## Compile the side channel driver and user space program 117 - side_ch.ko 118 ``` 119 $OPENWIFI_DIR/driver/side_ch/make_driver.sh $OPENWIFI_DIR $XILINX_DIR ARCH_BIT 120(For Zynq 7000, ARCH_BIT should be 32, for Zynq MPSoC, ARCH_BIT should be 64) 121 ``` 122 - side_ch_ctl (take user_space/side_ch_ctl_src/side_ch_ctl.c and compile it on board!) 123 ``` 124 gcc -o side_ch_ctl side_ch_ctl.c 125 ``` 126 127## Run the CSI together with modes other than monitor 128 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. 129 130## Map the CSI information to the WiFi packet 131 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. 132 133 Please learn the python and Matlab script to extract CSI information per packet according to your requirement. 134