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