xref: /OK3568_Linux_fs/kernel/Documentation/networking/mac80211-injection.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun=========================================
4*4882a593SmuzhiyunHow to use packet injection with mac80211
5*4882a593Smuzhiyun=========================================
6*4882a593Smuzhiyun
7*4882a593Smuzhiyunmac80211 now allows arbitrary packets to be injected down any Monitor Mode
8*4882a593Smuzhiyuninterface from userland.  The packet you inject needs to be composed in the
9*4882a593Smuzhiyunfollowing format::
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun [ radiotap header  ]
12*4882a593Smuzhiyun [ ieee80211 header ]
13*4882a593Smuzhiyun [ payload ]
14*4882a593Smuzhiyun
15*4882a593SmuzhiyunThe radiotap format is discussed in
16*4882a593Smuzhiyun./Documentation/networking/radiotap-headers.rst.
17*4882a593Smuzhiyun
18*4882a593SmuzhiyunDespite many radiotap parameters being currently defined, most only make sense
19*4882a593Smuzhiyunto appear on received packets.  The following information is parsed from the
20*4882a593Smuzhiyunradiotap headers and used to control injection:
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun * IEEE80211_RADIOTAP_FLAGS
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun   =========================  ===========================================
25*4882a593Smuzhiyun   IEEE80211_RADIOTAP_F_FCS   FCS will be removed and recalculated
26*4882a593Smuzhiyun   IEEE80211_RADIOTAP_F_WEP   frame will be encrypted if key available
27*4882a593Smuzhiyun   IEEE80211_RADIOTAP_F_FRAG  frame will be fragmented if longer than the
28*4882a593Smuzhiyun			      current fragmentation threshold.
29*4882a593Smuzhiyun   =========================  ===========================================
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun * IEEE80211_RADIOTAP_TX_FLAGS
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun   =============================  ========================================
34*4882a593Smuzhiyun   IEEE80211_RADIOTAP_F_TX_NOACK  frame should be sent without waiting for
35*4882a593Smuzhiyun				  an ACK even if it is a unicast frame
36*4882a593Smuzhiyun   =============================  ========================================
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun * IEEE80211_RADIOTAP_RATE
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun   legacy rate for the transmission (only for devices without own rate control)
41*4882a593Smuzhiyun
42*4882a593Smuzhiyun * IEEE80211_RADIOTAP_MCS
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun   HT rate for the transmission (only for devices without own rate control).
45*4882a593Smuzhiyun   Also some flags are parsed
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun   ============================  ========================
48*4882a593Smuzhiyun   IEEE80211_RADIOTAP_MCS_SGI    use short guard interval
49*4882a593Smuzhiyun   IEEE80211_RADIOTAP_MCS_BW_40  send in HT40 mode
50*4882a593Smuzhiyun   ============================  ========================
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun * IEEE80211_RADIOTAP_DATA_RETRIES
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun   number of retries when either IEEE80211_RADIOTAP_RATE or
55*4882a593Smuzhiyun   IEEE80211_RADIOTAP_MCS was used
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun * IEEE80211_RADIOTAP_VHT
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun   VHT mcs and number of streams used in the transmission (only for devices
60*4882a593Smuzhiyun   without own rate control). Also other fields are parsed
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun   flags field
63*4882a593Smuzhiyun	IEEE80211_RADIOTAP_VHT_FLAG_SGI: use short guard interval
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun   bandwidth field
66*4882a593Smuzhiyun	* 1: send using 40MHz channel width
67*4882a593Smuzhiyun	* 4: send using 80MHz channel width
68*4882a593Smuzhiyun	* 11: send using 160MHz channel width
69*4882a593Smuzhiyun
70*4882a593SmuzhiyunThe injection code can also skip all other currently defined radiotap fields
71*4882a593Smuzhiyunfacilitating replay of captured radiotap headers directly.
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunHere is an example valid radiotap header defining some parameters::
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun	0x00, 0x00, // <-- radiotap version
76*4882a593Smuzhiyun	0x0b, 0x00, // <- radiotap header length
77*4882a593Smuzhiyun	0x04, 0x0c, 0x00, 0x00, // <-- bitmap
78*4882a593Smuzhiyun	0x6c, // <-- rate
79*4882a593Smuzhiyun	0x0c, //<-- tx power
80*4882a593Smuzhiyun	0x01 //<-- antenna
81*4882a593Smuzhiyun
82*4882a593SmuzhiyunThe ieee80211 header follows immediately afterwards, looking for example like
83*4882a593Smuzhiyunthis::
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun	0x08, 0x01, 0x00, 0x00,
86*4882a593Smuzhiyun	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
87*4882a593Smuzhiyun	0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
88*4882a593Smuzhiyun	0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
89*4882a593Smuzhiyun	0x10, 0x86
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunThen lastly there is the payload.
92*4882a593Smuzhiyun
93*4882a593SmuzhiyunAfter composing the packet contents, it is sent by send()-ing it to a logical
94*4882a593Smuzhiyunmac80211 interface that is in Monitor mode.  Libpcap can also be used,
95*4882a593Smuzhiyun(which is easier than doing the work to bind the socket to the right
96*4882a593Smuzhiyuninterface), along the following lines:::
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun	ppcap = pcap_open_live(szInterfaceName, 800, 1, 20, szErrbuf);
99*4882a593Smuzhiyun	...
100*4882a593Smuzhiyun	r = pcap_inject(ppcap, u8aSendBuffer, nLength);
101*4882a593Smuzhiyun
102*4882a593SmuzhiyunYou can also find a link to a complete inject application here:
103*4882a593Smuzhiyun
104*4882a593Smuzhiyunhttps://wireless.wiki.kernel.org/en/users/Documentation/packetspammer
105*4882a593Smuzhiyun
106*4882a593SmuzhiyunAndy Green <andy@warmcat.com>
107