1*529690b6SJiao Xianjun<!-- 2*529690b6SJiao XianjunAuthor: Xianjun Jiao 3*529690b6SJiao XianjunSPDX-FileCopyrightText: 2022 UGent 4*529690b6SJiao XianjunSPDX-License-Identifier: AGPL-3.0-or-later 5*529690b6SJiao Xianjun--> 6*529690b6SJiao Xianjun 7*529690b6SJiao XianjunOne super power of the openwifi platform is "**Full Duplex**" which means that openwifi baseband can receive its own TX signal. 8*529690b6SJiao XianjunThis makes the IQ sample and WiFi packet self loopback test possible. Reading the normal IQ sample capture [app note](iq.md) will help if you have issue or 9*529690b6SJiao Xianjunwant to understand openwifi side channel (for IQ and CSI) deeper. 10*529690b6SJiao Xianjun 11*529690b6SJiao Xianjun 12*529690b6SJiao Xianjun[[IQ self loopback quick start](#IQ-self-loopback-quick-start)] 13*529690b6SJiao Xianjun[[Check the packet loopback on board](#Check-the-packet-loopback-on-board)] 14*529690b6SJiao Xianjun[[Self loopback config](#Self-loopback-config)] 15*529690b6SJiao Xianjun 16*529690b6SJiao Xianjun## IQ self loopback quick start 17*529690b6SJiao Xianjun(Please replace the IQ length **8187** by **4095** if you use low end FPGA board: zedboard/adrv9464z7020/antsdr/zc702) 18*529690b6SJiao Xianjun- Power on the SDR board. 19*529690b6SJiao Xianjun- Put the Tx and Rx antenna as close as possible. 20*529690b6SJiao Xianjun- 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: 21*529690b6SJiao Xianjun ``` 22*529690b6SJiao Xianjun ssh [email protected] 23*529690b6SJiao Xianjun (password: openwifi) 24*529690b6SJiao Xianjun cd openwifi 25*529690b6SJiao Xianjun ./wgd.sh 26*529690b6SJiao Xianjun (Bring up the openwifi NIC sdr0) 27*529690b6SJiao Xianjun ./monitor_ch.sh sdr0 44 28*529690b6SJiao Xianjun (Setup monitor mode in WiFi channel 44. You should find a channel as clean as possible in your location) 29*529690b6SJiao Xianjun insmod side_ch.ko iq_len_init=8187 30*529690b6SJiao Xianjun ./side_ch_ctl wh11d0 31*529690b6SJiao Xianjun (Set 0 to register 11. It means the pre trigger length is 0, so we only capture IQ after trigger condition is met) 32*529690b6SJiao Xianjun ./side_ch_ctl wh8d16 33*529690b6SJiao Xianjun (Set 16 to register 8 -- set trigger condition to phy_tx_started signal from openofdm tx core) 34*529690b6SJiao Xianjun ./sdrctl dev sdr0 set reg xpu 1 1 35*529690b6SJiao Xianjun (Unmute the baseband self-receiving to receive openwifi own TX signal/packet -- important for self loopback!) 36*529690b6SJiao Xianjun ./side_ch_ctl g0 37*529690b6SJiao Xianjun ``` 38*529690b6SJiao Xianjun You should see on outputs like: 39*529690b6SJiao Xianjun ``` 40*529690b6SJiao Xianjun loop 22848 side info count 0 41*529690b6SJiao Xianjun loop 22912 side info count 0 42*529690b6SJiao Xianjun ... 43*529690b6SJiao Xianjun ``` 44*529690b6SJiao Xianjun Now the count is always 0, because we haven't instructed openwifi to send packet for loopback test. 45*529690b6SJiao Xianjun 46*529690b6SJiao Xianjun- Leave above ssh session untouched. Open a new ssh session to the board from your computer. Then run on board: 47*529690b6SJiao Xianjun ``` 48*529690b6SJiao Xianjun cd openwifi/inject_80211/ 49*529690b6SJiao Xianjun make 50*529690b6SJiao Xianjun (Build our example packet injection program) 51*529690b6SJiao Xianjun ./inject_80211 -m n -r 5 -n 1 sdr0 52*529690b6SJiao Xianjun (Inject one packet to openwifi sdr0 NIC) 53*529690b6SJiao Xianjun ``` 54*529690b6SJiao Xianjun Normally in the previous ssh session, the count becomes 1. It means one packet (of IQ sample) is sent and captured via loopback over the air. 55*529690b6SJiao Xianjun 56*529690b6SJiao Xianjun- On your computer (NOT ssh onboard!), run: 57*529690b6SJiao Xianjun ``` 58*529690b6SJiao Xianjun cd openwifi/user_space/side_ch_ctl_src 59*529690b6SJiao Xianjun python3 iq_capture.py 8187 60*529690b6SJiao Xianjun ``` 61*529690b6SJiao Xianjun You might need to install beforehand: "sudo apt install python3-numpy", and "sudo apt install python3-matplotlib". 62*529690b6SJiao Xianjun 63*529690b6SJiao Xianjun- Leave the above host session untouched. Let's go to the second ssh session (packet injection), and do single packet Tx again: 64*529690b6SJiao Xianjun ``` 65*529690b6SJiao Xianjun ./inject_80211 -m n -r 5 -n 1 sdr0 66*529690b6SJiao Xianjun ``` 67*529690b6SJiao Xianjun Normally in the 1st ssh session, the count becomes 2. You should also see IQ sample capture figures like this: 68*529690b6SJiao Xianjun  69*529690b6SJiao Xianjun 70*529690b6SJiao Xianjun- Stop the python3 script, which plots above, in the host session. A file **iq.txt** is generated. You can use the Matlab script test_iq_file_display.m 71*529690b6SJiao Xianjunto do further offline analysis, or feed the IQ sample to the openwifi receiver simulation, etc. 72*529690b6SJiao Xianjun 73*529690b6SJiao Xianjun## Check the packet loopback on board 74*529690b6SJiao Xianjun 75*529690b6SJiao Xianjun- While signal/packet is looped back, you can capture it on board via normal sniffer program for further check/analysis on the packet (bit/byte level instead of IQ level), such as tcpdump or tshark. 76*529690b6SJiao Xianjun A new ssh session to the board should be opened to do this before running the packet injection: 77*529690b6SJiao Xianjun ``` 78*529690b6SJiao Xianjun tcpdump -i sdr0 79*529690b6SJiao Xianjun ``` 80*529690b6SJiao Xianjun After the packet injection, you should see the packet information printed by tcpdump from self over-the-air loopback. 81*529690b6SJiao Xianjun 82*529690b6SJiao Xianjun- You can also see the openwifi printk message of Rx packet (self Tx looped back) while the packet comes to the openwifi Rx interrupt. 83*529690b6SJiao Xianjun A new ssh session to the board should be opened to do this before running the packet injection: 84*529690b6SJiao Xianjun ``` 85*529690b6SJiao Xianjun cd openwifi 86*529690b6SJiao Xianjun ./sdrctl dev sdr0 set reg drv_rx 7 7 87*529690b6SJiao Xianjun (Turn on the openwifi Rx printk logging) 88*529690b6SJiao Xianjun ``` 89*529690b6SJiao Xianjun After the packet injection, in the same ssh session run: 90*529690b6SJiao Xianjun ``` 91*529690b6SJiao Xianjun dmesg 92*529690b6SJiao Xianjun ``` 93*529690b6SJiao Xianjun You should see the printk message from openwifi_rx_interrupt() function in the openwifi driver (sdr.c). 94*529690b6SJiao Xianjun 95*529690b6SJiao Xianjun## Self loopback config 96*529690b6SJiao Xianjun 97*529690b6SJiao Xianjun- By default, the loopback is via the air (from Tx antenna to Rx antenna). FPGA inernal loopback option is offered to have IQ sample and packet without 98*529690b6SJiao Xianjun any interference. To have FPGA internal loopback, run before the packet injection: 99*529690b6SJiao Xianjun ``` 100*529690b6SJiao Xianjun ./side_ch_ctl wh5h4 101*529690b6SJiao Xianjun ``` 102*529690b6SJiao Xianjun To change back to loopback over the air, run: 103*529690b6SJiao Xianjun ``` 104*529690b6SJiao Xianjun ./side_ch_ctl wh5h0 105*529690b6SJiao Xianjun ``` 106*529690b6SJiao Xianjun- Lots of packet injection parameters can be set: number of packet, type (data/control/management), MCS/rate, size, interval, etc. Please run the packet injection 107*529690b6SJiao Xianjun program without any arguments to see the help. 108*529690b6SJiao Xianjun 109*529690b6SJiao Xianjun- Besides the packet Tx via injection over monitor mode for loopback test, normal WiFi mode (AP/Client/ad-hoc) can also run together with self loopback. 110*529690b6SJiao Xianjun For instance, run **fosdem.sh** instead of **wgd.sh** to setup an openwifi AP that will transmit beacons. The wgd.sh can also be replaced with other scenario 111*529690b6SJiao Xianjun setup scripts. Please check [Application notes](README.md) 112*529690b6SJiao Xianjun 113*529690b6SJiao Xianjun- To understand deeper of all above commands/settings, please refer to [Capture IQ sample, AGC gain, RSSI with many types of trigger condition](iq.md) and 114*529690b6SJiao Xianjun [Capture dual antenna TX/RX IQ for multi-purpose (capture collision)](iq_2ant.md) 115