xref: /openwifi/doc/app_notes/inject_80211.md (revision bb0a2c5897be8851861bd9d7b2cdc7a9aa83bb1a)
1<!--
2Author: Michael Mehari
3SPDX-FileCopyrightText: 2019 UGent
4SPDX-License-Identifier: AGPL-3.0-or-later
5-->
6
7## 802.11 packet injection
8
9The 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.
10
11Ping 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.
12
13Luckily, 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.
14
15To 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]>.
16
17### Build inject_80211 on board
18Userspace program to inject 802.11 packets through mac80211 supported (softmac) wireless devices.
19
20Login/ssh to the board and setup internet connection according to the Quick Start. Then
21```
22apt install libpcap-dev
23cd openwifi/inject_80211
24make
25```
26
27### Options of program inject_80211
28  ```
29-m/--hw_mode <hardware operation mode> (a,g,n)
30-r/--rate_index <rate/MCS index> (0,1,2,3,4,5,6,7)
31-i/--sgi_flag (0,1)
32-n/--num_packets <number of packets>
33-s/--payload_size <payload size in bytes>
34-d/--delay <delay between packets in usec>
35-h   this menu
36  ```
37
38### Example:
39Login/ssh to the board, Then
40```
41cd openwifi
42./wgd.sh
43./monitor_ch.sh sdr0 11
44(Above will turn sdr0 into the monitor mode and monitor on channel 11)
45./inject_80211/inject_80211 -m n -r 0  -n 64 -s 10 sdr0
46(Above will inject 10 802.11n packets at 6.5Mbps bitrate and 64bytes size via NIC sdr0)
47```
48When 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
50Or add extra virtual monitor interface on top of sdr0, and inject packets:
51```
52iw dev sdr0 interface add mon0 type monitor && ifconfig mon0 up
53./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
54```
55
56### Link performance test
57
58To make a profound experimental analysis on the physical layer performance, we can rely on automation scripts.
59
60The following script will inject 100 802.11n packets at different bitrates and payload sizes.
61
62```
63#!/bin/bash
64
65HW_MODE='n'
66COUNT=100
67DELAY=1000
68RATE=( 0 1 2 3 4 5 6 7 )
69SIZE=( $(seq -s' ' 50 100 1450) ) # paload size in bytes
70IF="mon0"
71
72for (( i = 0 ; i < ${#PAYLOAD[@]} ; i++ )) do
73	for (( j = 0 ; j < ${#RATE[@]} ; j++ )) do
74		inject_80211 -m $HW_MODE -n $COUNT -d $DELAY -r ${RATE[$j]} -s ${SIZE[$i]} $IF
75		sleep 1
76	done
77done
78
79```
80
81On the receiver side, we can use tcpdump to collect the pcap traces.
82
83```
84iw dev wlan0 interface add mon0 type monitor && ifconfig mon0 up
85tcpdump -i mon0 -w trace.pcap 'wlan addr1 ff:ff:ff:ff:ff:ff and wlan addr2 66:55:44:33:22:11'
86```
87
88Wlan addresses *ff:ff:ff:ff:ff:ff* and *66:55:44:33:22:11* are specific to our injector application.
89
90Next, we analyze the collected pcap traces using the analysis tool provided.
91
92```
93analyze_80211 trace.pcap
94```
95
96An excerpt from a sample analysis looks the following
97
98```
99HW MODE	RATE(Mbps)	SGI	SIZE(bytes)	COUNT	Duration(sec)
100=======	==========	===	===========	=====	=============
101802.11n	6.5           	OFF	54		100	0.11159
102802.11n	13.0		OFF	54		100	0.11264
103802.11n	19.5		OFF	54		100	0.11156
104802.11n	26.0		OFF	54	    	100	0.11268
105802.11n	39.0		OFF	54	    	100	0.11333
106802.11n	52.0		OFF	54	    	100	0.11149
107802.11n	58.5		OFF	54	    	100	0.11469
108802.11n	65.0		OFF	54	    	100	0.11408
109```
110
111