1Some usual/frequent control trick over the openwifi FPGA. You need to do these controls on board in the openwifi directory. 2 3[[CCA LBT threshold and disable](#CCA-LBT-threshold-and-disable)] 4[[Retransmission and ACK tx control](#Retransmission-and-ACK-tx-control)] 5[[NAV DIFS EIFS CW disable and enable](#NAV-DIFS-EIFS-CW-disable-and-enable)] 6[[CW max and min config](#CW-max-and-min-config)] 7 8[[Rx gain config](#Rx-gain-config)] 9[[Tx power config](#Tx-power-config)] 10[[Tx Lo and port config](#Tx-Lo-and-port-config)] 11[[Antenna selection](#Antenna-selection)] 12[[Restrict the frequency](#Restrict-the-frequency)] 13[[Receiver sensitivity control](#Receiver-sensitivity-control)] 14 15[[Tx rate config](#Tx-rate-config)] 16[[Arbitrary Tx IQ sample](#Arbitrary-Tx-IQ-sample)] 17 18## CCA LBT threshold and disable 19 20In normal operation, different threshold is set to FPGA according to the different calibration of different frequency/channel by driver automatically. Show the current LBT threshold in FPGA: 21``` 22./set_lbt_th.sh 23``` 24"reg val: 00000086" means the current threshold is 134 (86 in Hex). Its unit is rssi_half_db. Check rssi_half_db_to_rssi_dbm()/rssi_dbm_to_rssi_half_db() in sdr.c to see the relation to rssi dBm. 25 26Override a new threshold -NNdBm to FPGA, for example -70dBm: 27``` 28./set_lbt_th.sh 70 29``` 30Above will disable the automatic CCA threshold setting from the openwifi driver. 31 32Recover the driver automatic control on the threshold: 33``` 34./set_lbt_th.sh 0 35``` 36Disable the CCA by setting a very strong level as threshold, for example -1dBm: 37``` 38./set_lbt_th.sh 1 39``` 40After above command, the CCA engine will always believe the channel is idle, because the rx signal strength not likely could exceed -1dBm. 41 42## Retransmission and ACK tx control 43 44The best way of override the maximum number of re-transmission for a Tx packet is doing it in the driver openwifi_tx() function. 45``` 46retry_limit_hw_value = ( retry_limit_raw==0?0:((retry_limit_raw - 1)&0xF) ); 47``` 48Override retry_limit_hw_value to 0 to disable re-transmission. Override it to 1 means that let FPGA do maximum 1 time re-transmission. 49 50The FPGA also has a register to override the re-transmission and ACK behavior. Check the current register value. 51``` 52./sdrctl dev sdr0 get reg xpu 11 53``` 54When operate this register, make sure you only change the relevant bits and leave other bits untouched, because other bits have other purposes. Also check the xpu register 11 in the [project document](../README.md) 55 56To override the maximum number of re-transmission, set bit3 to 1, and set the value (0 ~ 7) to bit2 ~ 0. Example, override the maximum number of re-transmission to 1 57``` 58./sdrctl dev sdr0 set reg xpu 11 9 59``` 60 619 in binary form is 01001. 62 63To disable the ACK TX after receive a packet, set bit4 to 1. (Assume we want to preserve the above re-transmission overriding setting) 64``` 65./sdrctl dev sdr0 set reg xpu 11 25 66``` 67 6825 in binary form is 11001. the 1001 of bit3 to 1 is untouched. 69 70Disabling ACK TX might be useful for monitor mode and packet injection. 71 72## NAV DIFS EIFS CW disable and enable 73 74To check the current NAV/DIFS/EIFS/CW disable status, just run 75``` 76./nav_disable.sh 77./difs_disable.sh 78./eifs_disable.sh 79./cw_disable.sh 80``` 81If NAV is disabled, the openwifi will always assume the NAV (Network Allocation Vector) is already counting down to 0. If DIFS/EIFS is disabled, when the CSMA engine needs to wait for DIFS/EIFS, it won't wait anymore. If CW is disabled, the contention window is fixed to 0, and there won't be any number of slots for random backoff procedure. To disable them, just input 1 as the script argument. 82``` 83./nav_disable.sh 1 84./difs_disable.sh 1 85./eifs_disable.sh 1 86./cw_disable.sh 1 87``` 88To enable them, just input 0 as the script argument. 89``` 90./nav_disable.sh 0 91./difs_disable.sh 0 92./eifs_disable.sh 0 93./cw_disable.sh 0 94``` 95 96## CW max and min config 97 98When the openwifi NIC bring up (as AP/Client/ad-hoc/etc), Linux will configure the CW (Contention Window) max and min value for FPGA queue 3 ~ 0 via openwifi_conf_tx() in the openwifi driver. You can check the current CW configuration in FPGA (set by Linux). 99``` 100./cw_max_min_cfg.sh 101``` 102It will show sth like 103``` 104FPGA cw max min for q3 to q0: 1023 15; 63 15; 15 7; 7 3 105FPGA cw max min for q3 to q0: a4644332 106``` 107The CW max and min for q3 ~ 0 are a4, 64, 43, 32 (in hex). Example explanation for q3: in hex the configuration is a4, which means 10 and 4 in the logarithmic domain, (2^10)-1=1023 and (2^4)-1=15 in the linear domain. 108 109To override the CW max and min for queue 3 ~ 0, for example 2047 31; 63 31; 15 7; 7 3, just map it to a hex string b5654332 for queue 3 ~ 0 and give it as the script argument: 110``` 111./cw_max_min_cfg.sh b5654332 112``` 113It will show sth like 114``` 115FPGA cw max min for q3 to q0: 2047 31; 63 31; 15 7; 7 3 116FPGA cw max min for q3 to q0: b5654332 117SYSFS cw max min for q3 to q0: 2047 31; 63 31; 15 7; 7 3 118SYSFS cw max min for q3 to q0: b5654332 119``` 120To give the control back to Linux 121``` 122./cw_max_min_cfg.sh 0 123``` 124Be careful that above command won't bring the Linux CW max min setting back to FPGA automatically, because Linux normally only call the setting function openwifi_conf_tx() for 1 time when the NIC is started. So either you write down the Linux setting by checking it at the beginning, and set it back via cw_max_min_cfg.sh before giving it argument 0, or re-load the NIC/driver to trigger the Linux setting action for the NIC. 125 126## Rx gain config 127 128In normal operation, you don't need to do Rx gain control manually, because it is controled by the AD9361 AGC function. For optimization/experiment purpose, you might want to use the manual rx gain control, you can run 129``` 130./set_rx_gain_manual.sh 30 131``` 132Above command will turn the automatic gain control mode to manual gain control mode, and set 30dB to the Rx gain module. 133 134Bring it back to the automatic gain control mode 135``` 136./set_rx_gain_auto.sh 137``` 138To find out a good reference about a manual Rx gain setting for the current link/peer, you can set it to automatic mode and then run 139``` 140rx_gain_show.sh 141``` 142for multiple times to check the actual AGC gain vlaue for received packet as explained in this [Access counter/statistics in driver](driver_stat.md). Then you can set the AGC gain value as argument to the **set_rx_gain_manual.sh** with the corret **offset**! For example, if **rx_gain_show.sh** reports a AGC gain value 34 for many successfully received data packets, and you want to use it as a manual gain setting, you need to set 143``` 144./set_rx_gain_manual.sh 20 145``` 146if the current working channel is 5220MHz (34 - 14dB offset = 20). You need to set 147``` 148./set_rx_gain_manual.sh 29 149``` 150if the current working channel is in 2.4GHz (34 - 5dB offset = 29). 151 152## Tx power config 153``` 154./sdrctl dev sdr0 set reg rf 0 20000 155``` 156Above command will set Tx power attenuation to 20dB (20*1000). By default it is 0dB. 157 158If you want an initial attenuation 20dB while loading and bringing up the openwifi NIC, please use the **init_tx_att** argument for the sdr.ko. 159``` 160insmod sdr.ko init_tx_att=20000 161``` 162You can change above driver loading action at the end of **wgd.sh**. 163 164The initial Tx attenuation might be useful when you connect two SDR boards directly by cable. Even though, you shouldn't not connect them during the setup phase (bring up the AP or client), because the initialization/tuning of AD9361 might generate big Tx power and kill the other AD9361's Rx. Only connect two SDR boards by cable after both sides have been setup and the attenuation setting takes effect. 165 166To increase the Tx power, you can consider add external PA like [this](https://github.com/open-sdr/openwifi/issues/53#issuecomment-767621478). Or increase the value of register 13 of tx_intf (check [README](../README.md)). 167 168Read the register value: 169``` 170./sdrctl dev sdr0 get reg tx_intf 13 171``` 172 173Set the register value to N (a number larger than the value read back above): 174``` 175./sdrctl dev sdr0 set reg tx_intf 13 N 176``` 177Bigger value in that register could hurt the Tx EVM and long packet signal. You need to fine tune it for your case. 178 179## Tx Lo and port config 180 181In normal operation, the Tx Lo and RF port are controled by FPGA automatically during signal Tx. To check the current Tx Lo and RF port switch status 182``` 183./set_tx_port.sh 184./set_tx_lo.sh 185``` 186Give argument **1** to above scripts to turn them **ON**, **0** for **OFF**. 187 188## Antenna selection 189 190By default, the 1st Tx and Rx antennas are used (tx0 and rx0). You can change the tx antenna to tx1 by 191``` 192./sdrctl dev sdr0 set reg drv_tx 4 1 193``` 194Change the tx antenna back to tx0 by 195``` 196./sdrctl dev sdr0 set reg drv_tx 4 0 197``` 198Change the rx antenna to rx1 and rx0 by 199``` 200./sdrctl dev sdr0 set reg drv_rx 4 1 201./sdrctl dev sdr0 set reg drv_rx 4 0 202``` 203 204## Restrict the frequency 205 206Since the AD9361 frequency tuning could generate big unwanted Tx noise, and it could damage the other AD9361 Rx during the test via cable, a restricted frequency can be set to avoid the possible frequency tuning (such as the background scan of Wifi). For example, you want the AD9361 works only in 5220Mhz: 207``` 208./set_restrict_freq.sh 5220 209``` 210Above command will fix the AD9361 in 5220MHz and let driver ignore frequency tuning request other than 5220MHz. The restriction can be removed by: 211``` 212./set_restrict_freq.sh 0 213``` 214To let openwifi work at arbitrary frequency, please check [Let openwifi work at arbitrary frequency](../README.md#let-openwifi-work-at-arbitrary-frequency) 215 216## Receiver sensitivity control 217 218Sometimes too good sensitivity could be a bad thing. WiFi receiver could be "attracted" by many weak signal/packet in the background, and has less "attention" to its real communication target (client/AP). Openwifi has offered a way to make the receiver less sensitive by setting a threshold. When the received signal is lower than this threshold, the receiver will not try to search the WiFi short preamble, i.e. ignore it. For example, if you want to set -70dBm as the threshold, use: 219``` 220./sdrctl dev sdr0 set reg drv_rx 0 70 221``` 222 223## Tx rate config 224 225By default, the Linux rate adaptation algorithm **minstrel_ht** set the packet rate/MCS automatically via openwifi_tx() function. 226``` 227rate_hw_value = ieee80211_get_tx_rate(dev, info)->hw_value; 228``` 229To override the Linux automatic control for non-ht packet 230``` 231./sdrctl dev sdr0 set reg drv_tx 0 N 232``` 233Value N: 0 for Linux auto control; 4 ~ 11 for 6M, 9M, 12M, 18M, 24M, 36M, 48M, 54M. 234 235To override the Linux automatic control for ht packet 236``` 237./sdrctl dev sdr0 set reg drv_tx 1 N 238``` 239Value N: 0 for Linux auto control; 4 ~ 11 for 6.5M, 13M, 19.5M, 26M, 39M, 52M, 58.5M, 65M. By default, the normal GI is used. To use the short GI, you need to add 16 to the target value N. 240 241## Arbitrary Tx IQ sample 242 243Arbitrary IQ sample (maximum 512 samples) can be written to tx_intf and sent for test purpose. 244