1a6085186SLina Ceballos<!-- 2*a2a0d4bdSXianjun JiaoAuthor: Michael Mehari, Xianjun Jiao 3ea75aaf6SJiao XianjunSPDX-FileCopyrightText: 2019 UGent 4a6085186SLina CeballosSPDX-License-Identifier: AGPL-3.0-or-later 5a6085186SLina Ceballos--> 67273ec43Smmehari 7*a2a0d4bdSXianjun Jiao## 802.11 packet injection and fuzzing 87273ec43Smmehari 9*a2a0d4bdSXianjun JiaoThe Linux wireless networking stack (i.e. driver, mac80211, cfg80211, net_dev, user app) is a robust implementation supporting a plethora of wireless devices. As robust as it is, it also has a drawback when it comes to single-layer testing and manual/total control mode (fuzzing). 107273ec43Smmehari 117273ec43SmmehariPing and Iperf are well established performance measurement tools. However, using such tools to measure 802.11 PHY performance can be misleading, simply because they touch multiple layers in the network stack. 127273ec43Smmehari 13*a2a0d4bdSXianjun JiaoLuckily, the mac80211 Linux subsystem provides packet injection functionality when the NIC is in the monitor mode and it allows us to have finer control for physical layer testing and/or fuzzing. 147273ec43Smmehari 15*a2a0d4bdSXianjun JiaoBesides the traditional fuzzing tool (like scapy), we have adapted a [packetspammer](https://github.com/gnychis/packetspammer) application, which is originally written by Andy Green <[email protected]> and maintained by George Nychis <[email protected]>, to show how to inject packets and control the FPGA behavior. 167273ec43Smmehari 17fdbf6a5aSJiao Xianjun### Build inject_80211 on board 187273ec43SmmehariUserspace program to inject 802.11 packets through mac80211 supported (softmac) wireless devices. 197273ec43Smmehari 204ec04889SJiao XianjunLogin/ssh to the board and setup internet connection according to the Quick Start. Then 21fdbf6a5aSJiao Xianjun``` 22fdbf6a5aSJiao Xianjuncd openwifi/inject_80211 23fdbf6a5aSJiao Xianjunmake 24fdbf6a5aSJiao Xianjun``` 25*a2a0d4bdSXianjun Jiao### Customize the packet content 26*a2a0d4bdSXianjun JiaoTo customize the packet, following piece of the inject_80211.c needs to be changed: 27*a2a0d4bdSXianjun Jiao``` 28*a2a0d4bdSXianjun Jiao/* IEEE80211 header */ 29*a2a0d4bdSXianjun Jiaostatic const u8 ieee_hdr[] = 30*a2a0d4bdSXianjun Jiao{ 31*a2a0d4bdSXianjun Jiao 0x08, 0x01, 0x00, 0x00, // Frame Control, Duration/ID 32*a2a0d4bdSXianjun Jiao 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Address 1 33*a2a0d4bdSXianjun Jiao 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, // Address 2 34*a2a0d4bdSXianjun Jiao 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, // Address 3 35*a2a0d4bdSXianjun Jiao 0x10, 0x86, // Sequence Control 36*a2a0d4bdSXianjun Jiao}; 37*a2a0d4bdSXianjun Jiao``` 38*a2a0d4bdSXianjun JiaoNote: The byte/bit order might not be intuitive when comparing with the standard. 39*a2a0d4bdSXianjun Jiao 40*a2a0d4bdSXianjun Jiao### FPGA behavior control 41*a2a0d4bdSXianjun Jiao- ACK and retransmission after FPGA sends packet 42*a2a0d4bdSXianjun Jiao 43*a2a0d4bdSXianjun JiaoIn openwifi_tx of sdr.c, many FPGA behaviors can be controled. Generally they are controled by the information from upper layer (Linux mac80211), but you can override them in driver (sdr.c) 44*a2a0d4bdSXianjun Jiao 45*a2a0d4bdSXianjun JiaoIf 802.11 ACK is expected from the peer after the packet is sent by FPGA, variable **pkt_need_ack** should be overridden to 1. In this case, the FPGA will try to receive ACK, and report the sending status (ACK is received or not) to upper layer (Linux mac80211) 46*a2a0d4bdSXianjun Jiao 47*a2a0d4bdSXianjun JiaoThe maximum times of transmission for the packet can be controled by variable **retry_limit_raw**. If no ACK is received after the packet is sent, FPGA will try retransmissions automatically if retry_limit_raw>1. 48*a2a0d4bdSXianjun Jiao 49*a2a0d4bdSXianjun Jiao- ACK after FPGA receives packet in monitor mode 50*a2a0d4bdSXianjun Jiao 51*a2a0d4bdSXianjun JiaoEven in monitor mode, openwifi FPGA still sends ACK after the packet is received, if the conditions are met: MAC address is matched, it is a data frame, etc. To disable this automatic ACK generation, the register 11 of xpu should be set to 16: 52*a2a0d4bdSXianjun Jiao``` 53*a2a0d4bdSXianjun Jiaosdrctl dev sdr0 set reg xpu 11 16 54*a2a0d4bdSXianjun Jiao``` 55fdbf6a5aSJiao Xianjun 5610ae6518SJiao Xianjun### Options of program inject_80211 577273ec43Smmehari``` 587273ec43Smmehari-m/--hw_mode <hardware operation mode> (a,g,n) 597273ec43Smmehari-r/--rate_index <rate/MCS index> (0,1,2,3,4,5,6,7) 607273ec43Smmehari-i/--sgi_flag (0,1) 617273ec43Smmehari-n/--num_packets <number of packets> 627273ec43Smmehari-s/--payload_size <payload size in bytes> 637273ec43Smmehari-d/--delay <delay between packets in usec> 647273ec43Smmehari-h this menu 657273ec43Smmehari``` 667273ec43Smmehari 677273ec43Smmehari### Example: 6864ce2ec9SJiao XianjunLogin/ssh to the board, Then 697273ec43Smmehari``` 7064ce2ec9SJiao Xianjuncd openwifi 7164ce2ec9SJiao Xianjun./wgd.sh 7264ce2ec9SJiao Xianjun./monitor_ch.sh sdr0 11 73e42aed84SJiao Xianjun(Above will turn sdr0 into the monitor mode and monitor on channel 11) 74e42aed84SJiao Xianjun./inject_80211/inject_80211 -m n -r 0 -n 64 -s 10 sdr0 75e42aed84SJiao Xianjun(Above will inject 10 802.11n packets at 6.5Mbps bitrate and 64bytes size via NIC sdr0) 7664ce2ec9SJiao Xianjun``` 77e42aed84SJiao XianjunWhen above injection command is running, you could see the injected packets with wireshark (or other packet sniffer) on another WiFi device monitoring channel 11. 78e42aed84SJiao Xianjun 7964ce2ec9SJiao XianjunOr add extra virtual monitor interface on top of sdr0, and inject packets: 8064ce2ec9SJiao Xianjun``` 8164ce2ec9SJiao Xianjuniw dev sdr0 interface add mon0 type monitor && ifconfig mon0 up 82e42aed84SJiao Xianjun./inject_80211/inject_80211 -m n -r 0 -n 64 -s 10 mon0 # Inject 10 802.11n packets at 6.5Mbps bitrate and 64bytes size 837273ec43Smmehari``` 847273ec43Smmehari 857273ec43Smmehari### Link performance test 867273ec43Smmehari 877273ec43SmmehariTo make a profound experimental analysis on the physical layer performance, we can rely on automation scripts. 887273ec43Smmehari 897273ec43SmmehariThe following script will inject 100 802.11n packets at different bitrates and payload sizes. 907273ec43Smmehari 917273ec43Smmehari``` 927273ec43Smmehari#!/bin/bash 937273ec43Smmehari 947273ec43SmmehariHW_MODE='n' 957273ec43SmmehariCOUNT=100 967273ec43SmmehariDELAY=1000 977273ec43SmmehariRATE=( 0 1 2 3 4 5 6 7 ) 987273ec43SmmehariSIZE=( $(seq -s' ' 50 100 1450) ) # paload size in bytes 997273ec43SmmehariIF="mon0" 1007273ec43Smmehari 1017273ec43Smmeharifor (( i = 0 ; i < ${#PAYLOAD[@]} ; i++ )) do 1027273ec43Smmehari for (( j = 0 ; j < ${#RATE[@]} ; j++ )) do 1037273ec43Smmehari inject_80211 -m $HW_MODE -n $COUNT -d $DELAY -r ${RATE[$j]} -s ${SIZE[$i]} $IF 1047273ec43Smmehari sleep 1 1057273ec43Smmehari done 1067273ec43Smmeharidone 1077273ec43Smmehari 1087273ec43Smmehari``` 1097273ec43Smmehari 1107273ec43SmmehariOn the receiver side, we can use tcpdump to collect the pcap traces. 1117273ec43Smmehari 1127273ec43Smmehari``` 113*a2a0d4bdSXianjun Jiaoiw dev sdr0 interface add mon0 type monitor && ifconfig mon0 up 1147273ec43Smmeharitcpdump -i mon0 -w trace.pcap 'wlan addr1 ff:ff:ff:ff:ff:ff and wlan addr2 66:55:44:33:22:11' 1157273ec43Smmehari``` 1167273ec43Smmehari 1177273ec43SmmehariWlan addresses *ff:ff:ff:ff:ff:ff* and *66:55:44:33:22:11* are specific to our injector application. 1187273ec43Smmehari 1197273ec43SmmehariNext, we analyze the collected pcap traces using the analysis tool provided. 1207273ec43Smmehari 1217273ec43Smmehari``` 1227273ec43Smmeharianalyze_80211 trace.pcap 1237273ec43Smmehari``` 1247273ec43Smmehari 1257273ec43SmmehariAn excerpt from a sample analysis looks the following 1267273ec43Smmehari 1277273ec43Smmehari``` 1287273ec43SmmehariHW MODE RATE(Mbps) SGI SIZE(bytes) COUNT Duration(sec) 1297273ec43Smmehari======= ========== === =========== ===== ============= 1307273ec43Smmehari802.11n 6.5 OFF 54 100 0.11159 1317273ec43Smmehari802.11n 13.0 OFF 54 100 0.11264 1327273ec43Smmehari802.11n 19.5 OFF 54 100 0.11156 1337273ec43Smmehari802.11n 26.0 OFF 54 100 0.11268 1347273ec43Smmehari802.11n 39.0 OFF 54 100 0.11333 1357273ec43Smmehari802.11n 52.0 OFF 54 100 0.11149 1367273ec43Smmehari802.11n 58.5 OFF 54 100 0.11469 1377273ec43Smmehari802.11n 65.0 OFF 54 100 0.11408 1387273ec43Smmehari``` 1397273ec43Smmehari 140