xref: /openwifi/doc/app_notes/inject_80211.md (revision e42aed846ec83a8639baea7139ab1be51455c2bb)
1a6085186SLina Ceballos<!--
2ea75aaf6SJiao XianjunAuthor: Michael Mehari
3ea75aaf6SJiao XianjunSPDX-FileCopyrightText: 2019 UGent
4a6085186SLina CeballosSPDX-License-Identifier: AGPL-3.0-or-later
5a6085186SLina Ceballos-->
67273ec43Smmehari
77273ec43Smmehari## 802.11 packet injection
87273ec43Smmehari
97273ec43SmmehariThe 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.
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*e42aed84SJiao XianjunLuckily, the mac80211 Linux subsystem provides packet injection functionality when the NIC is in the monitor mode and it allows us to have finer control over physical layer testing.
147273ec43Smmehari
157273ec43SmmehariTo this end, we have adapted a [packetspammer](https://github.com/gnychis/packetspammer) application originally written by Andy Green <[email protected]> and maintained by George Nychis <[email protected]>.
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```
224ec04889SJiao Xianjunapt install libpcap-dev
23fdbf6a5aSJiao Xianjuncd openwifi/inject_80211
24fdbf6a5aSJiao Xianjunmake
25fdbf6a5aSJiao Xianjun```
26fdbf6a5aSJiao Xianjun
2710ae6518SJiao Xianjun### Options of program inject_80211
287273ec43Smmehari  ```
297273ec43Smmehari-m/--hw_mode <hardware operation mode> (a,g,n)
307273ec43Smmehari-r/--rate_index <rate/MCS index> (0,1,2,3,4,5,6,7)
317273ec43Smmehari-i/--sgi_flag (0,1)
327273ec43Smmehari-n/--num_packets <number of packets>
337273ec43Smmehari-s/--payload_size <payload size in bytes>
347273ec43Smmehari-d/--delay <delay between packets in usec>
357273ec43Smmehari-h   this menu
367273ec43Smmehari  ```
377273ec43Smmehari
387273ec43Smmehari### Example:
3964ce2ec9SJiao XianjunLogin/ssh to the board, Then
407273ec43Smmehari```
4164ce2ec9SJiao Xianjuncd openwifi
4264ce2ec9SJiao Xianjun./wgd.sh
4364ce2ec9SJiao Xianjun./monitor_ch.sh sdr0 11
44*e42aed84SJiao Xianjun(Above will turn sdr0 into the monitor mode and monitor on channel 11)
45*e42aed84SJiao Xianjun./inject_80211/inject_80211 -m n -r 0  -n 64 -s 10 sdr0
46*e42aed84SJiao Xianjun(Above will inject 10 802.11n packets at 6.5Mbps bitrate and 64bytes size via NIC sdr0)
4764ce2ec9SJiao Xianjun```
48*e42aed84SJiao 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.
49*e42aed84SJiao Xianjun
5064ce2ec9SJiao XianjunOr add extra virtual monitor interface on top of sdr0, and inject packets:
5164ce2ec9SJiao Xianjun```
5264ce2ec9SJiao Xianjuniw dev sdr0 interface add mon0 type monitor && ifconfig mon0 up
53*e42aed84SJiao 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
547273ec43Smmehari```
557273ec43Smmehari
567273ec43Smmehari### Link performance test
577273ec43Smmehari
587273ec43SmmehariTo make a profound experimental analysis on the physical layer performance, we can rely on automation scripts.
597273ec43Smmehari
607273ec43SmmehariThe following script will inject 100 802.11n packets at different bitrates and payload sizes.
617273ec43Smmehari
627273ec43Smmehari```
637273ec43Smmehari#!/bin/bash
647273ec43Smmehari
657273ec43SmmehariHW_MODE='n'
667273ec43SmmehariCOUNT=100
677273ec43SmmehariDELAY=1000
687273ec43SmmehariRATE=( 0 1 2 3 4 5 6 7 )
697273ec43SmmehariSIZE=( $(seq -s' ' 50 100 1450) ) # paload size in bytes
707273ec43SmmehariIF="mon0"
717273ec43Smmehari
727273ec43Smmeharifor (( i = 0 ; i < ${#PAYLOAD[@]} ; i++ )) do
737273ec43Smmehari	for (( j = 0 ; j < ${#RATE[@]} ; j++ )) do
747273ec43Smmehari		inject_80211 -m $HW_MODE -n $COUNT -d $DELAY -r ${RATE[$j]} -s ${SIZE[$i]} $IF
757273ec43Smmehari		sleep 1
767273ec43Smmehari	done
777273ec43Smmeharidone
787273ec43Smmehari
797273ec43Smmehari```
807273ec43Smmehari
817273ec43SmmehariOn the receiver side, we can use tcpdump to collect the pcap traces.
827273ec43Smmehari
837273ec43Smmehari```
847273ec43Smmehariiw dev wlan0 interface add mon0 type monitor && ifconfig mon0 up
857273ec43Smmeharitcpdump -i mon0 -w trace.pcap 'wlan addr1 ff:ff:ff:ff:ff:ff and wlan addr2 66:55:44:33:22:11'
867273ec43Smmehari```
877273ec43Smmehari
887273ec43SmmehariWlan addresses *ff:ff:ff:ff:ff:ff* and *66:55:44:33:22:11* are specific to our injector application.
897273ec43Smmehari
907273ec43SmmehariNext, we analyze the collected pcap traces using the analysis tool provided.
917273ec43Smmehari
927273ec43Smmehari```
937273ec43Smmeharianalyze_80211 trace.pcap
947273ec43Smmehari```
957273ec43Smmehari
967273ec43SmmehariAn excerpt from a sample analysis looks the following
977273ec43Smmehari
987273ec43Smmehari```
997273ec43SmmehariHW MODE	RATE(Mbps)	SGI	SIZE(bytes)	COUNT	Duration(sec)
1007273ec43Smmehari=======	==========	===	===========	=====	=============
1017273ec43Smmehari802.11n	6.5           	OFF	54		100	0.11159
1027273ec43Smmehari802.11n	13.0		OFF	54		100	0.11264
1037273ec43Smmehari802.11n	19.5		OFF	54		100	0.11156
1047273ec43Smmehari802.11n	26.0		OFF	54	    	100	0.11268
1057273ec43Smmehari802.11n	39.0		OFF	54	    	100	0.11333
1067273ec43Smmehari802.11n	52.0		OFF	54	    	100	0.11149
1077273ec43Smmehari802.11n	58.5		OFF	54	    	100	0.11469
1087273ec43Smmehari802.11n	65.0		OFF	54	    	100	0.11408
1097273ec43Smmehari```
1107273ec43Smmehari
111