xref: /openwifi/doc/app_notes/inject_80211.md (revision a6085186d94dfe08b0e09c18c8d4b1b4fe38ea35)
1<!--
2SPDX-FileCopyrightText: 2019 Jiao Xianjun <[email protected]>
3SPDX-License-Identifier: AGPL-3.0-or-later
4-->
5
6## 802.11 packet injection
7
8The 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.
9
10Ping 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.
11
12Luckily, the mac80211 Linux subsystem provides packet injection functionality and it allows us to have finer control over physical layer testing.
13
14To 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]>.
15
16### inject_80211
17Userspace program to inject 802.11 packets through mac80211 supported (softmac) wireless devices.
18
19### Options
20  ```
21-m/--hw_mode <hardware operation mode> (a,g,n)
22-r/--rate_index <rate/MCS index> (0,1,2,3,4,5,6,7)
23-i/--sgi_flag (0,1)
24-n/--num_packets <number of packets>
25-s/--payload_size <payload size in bytes>
26-d/--delay <delay between packets in usec>
27-h   this menu
28  ```
29
30### Example:
31```
32iw dev wlan0 interface add mon0 type monitor && ifconfig mon0 up
33inject_80211 -m n -r 0  -n 64 -s 100 mon0     # Inject 10 802.11n packets at 6.5Mbps bitrate and 64bytes size
34```
35
36### Link performance test
37
38To make a profound experimental analysis on the physical layer performance, we can rely on automation scripts.
39
40The following script will inject 100 802.11n packets at different bitrates and payload sizes.
41
42```
43#!/bin/bash
44
45HW_MODE='n'
46COUNT=100
47DELAY=1000
48RATE=( 0 1 2 3 4 5 6 7 )
49SIZE=( $(seq -s' ' 50 100 1450) ) # paload size in bytes
50IF="mon0"
51
52for (( i = 0 ; i < ${#PAYLOAD[@]} ; i++ )) do
53	for (( j = 0 ; j < ${#RATE[@]} ; j++ )) do
54		inject_80211 -m $HW_MODE -n $COUNT -d $DELAY -r ${RATE[$j]} -s ${SIZE[$i]} $IF
55		sleep 1
56	done
57done
58
59```
60
61On the receiver side, we can use tcpdump to collect the pcap traces.
62
63```
64iw dev wlan0 interface add mon0 type monitor && ifconfig mon0 up
65tcpdump -i mon0 -w trace.pcap 'wlan addr1 ff:ff:ff:ff:ff:ff and wlan addr2 66:55:44:33:22:11'
66```
67
68Wlan addresses *ff:ff:ff:ff:ff:ff* and *66:55:44:33:22:11* are specific to our injector application.
69
70Next, we analyze the collected pcap traces using the analysis tool provided.
71
72```
73analyze_80211 trace.pcap
74```
75
76An excerpt from a sample analysis looks the following
77
78```
79HW MODE	RATE(Mbps)	SGI	SIZE(bytes)	COUNT	Duration(sec)
80=======	==========	===	===========	=====	=============
81802.11n	6.5           	OFF	54		100	0.11159
82802.11n	13.0		OFF	54		100	0.11264
83802.11n	19.5		OFF	54		100	0.11156
84802.11n	26.0		OFF	54	    	100	0.11268
85802.11n	39.0		OFF	54	    	100	0.11333
86802.11n	52.0		OFF	54	    	100	0.11149
87802.11n	58.5		OFF	54	    	100	0.11469
88802.11n	65.0		OFF	54	    	100	0.11408
89```
90
91