162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci========================================= 462306a36Sopenharmony_ciHow to use packet injection with mac80211 562306a36Sopenharmony_ci========================================= 662306a36Sopenharmony_ci 762306a36Sopenharmony_cimac80211 now allows arbitrary packets to be injected down any Monitor Mode 862306a36Sopenharmony_ciinterface from userland. The packet you inject needs to be composed in the 962306a36Sopenharmony_cifollowing format:: 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci [ radiotap header ] 1262306a36Sopenharmony_ci [ ieee80211 header ] 1362306a36Sopenharmony_ci [ payload ] 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ciThe radiotap format is discussed in 1662306a36Sopenharmony_ci./Documentation/networking/radiotap-headers.rst. 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ciDespite many radiotap parameters being currently defined, most only make sense 1962306a36Sopenharmony_cito appear on received packets. The following information is parsed from the 2062306a36Sopenharmony_ciradiotap headers and used to control injection: 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci * IEEE80211_RADIOTAP_FLAGS 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci ========================= =========================================== 2562306a36Sopenharmony_ci IEEE80211_RADIOTAP_F_FCS FCS will be removed and recalculated 2662306a36Sopenharmony_ci IEEE80211_RADIOTAP_F_WEP frame will be encrypted if key available 2762306a36Sopenharmony_ci IEEE80211_RADIOTAP_F_FRAG frame will be fragmented if longer than the 2862306a36Sopenharmony_ci current fragmentation threshold. 2962306a36Sopenharmony_ci ========================= =========================================== 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci * IEEE80211_RADIOTAP_TX_FLAGS 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci ============================= ======================================== 3462306a36Sopenharmony_ci IEEE80211_RADIOTAP_F_TX_NOACK frame should be sent without waiting for 3562306a36Sopenharmony_ci an ACK even if it is a unicast frame 3662306a36Sopenharmony_ci ============================= ======================================== 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci * IEEE80211_RADIOTAP_RATE 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci legacy rate for the transmission (only for devices without own rate control) 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci * IEEE80211_RADIOTAP_MCS 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci HT rate for the transmission (only for devices without own rate control). 4562306a36Sopenharmony_ci Also some flags are parsed 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci ============================ ======================== 4862306a36Sopenharmony_ci IEEE80211_RADIOTAP_MCS_SGI use short guard interval 4962306a36Sopenharmony_ci IEEE80211_RADIOTAP_MCS_BW_40 send in HT40 mode 5062306a36Sopenharmony_ci ============================ ======================== 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci * IEEE80211_RADIOTAP_DATA_RETRIES 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci number of retries when either IEEE80211_RADIOTAP_RATE or 5562306a36Sopenharmony_ci IEEE80211_RADIOTAP_MCS was used 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci * IEEE80211_RADIOTAP_VHT 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci VHT mcs and number of streams used in the transmission (only for devices 6062306a36Sopenharmony_ci without own rate control). Also other fields are parsed 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci flags field 6362306a36Sopenharmony_ci IEEE80211_RADIOTAP_VHT_FLAG_SGI: use short guard interval 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci bandwidth field 6662306a36Sopenharmony_ci * 1: send using 40MHz channel width 6762306a36Sopenharmony_ci * 4: send using 80MHz channel width 6862306a36Sopenharmony_ci * 11: send using 160MHz channel width 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ciThe injection code can also skip all other currently defined radiotap fields 7162306a36Sopenharmony_cifacilitating replay of captured radiotap headers directly. 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ciHere is an example valid radiotap header defining some parameters:: 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci 0x00, 0x00, // <-- radiotap version 7662306a36Sopenharmony_ci 0x0b, 0x00, // <- radiotap header length 7762306a36Sopenharmony_ci 0x04, 0x0c, 0x00, 0x00, // <-- bitmap 7862306a36Sopenharmony_ci 0x6c, // <-- rate 7962306a36Sopenharmony_ci 0x0c, //<-- tx power 8062306a36Sopenharmony_ci 0x01 //<-- antenna 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ciThe ieee80211 header follows immediately afterwards, looking for example like 8362306a36Sopenharmony_cithis:: 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci 0x08, 0x01, 0x00, 0x00, 8662306a36Sopenharmony_ci 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 8762306a36Sopenharmony_ci 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 8862306a36Sopenharmony_ci 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, 8962306a36Sopenharmony_ci 0x10, 0x86 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ciThen lastly there is the payload. 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ciAfter composing the packet contents, it is sent by send()-ing it to a logical 9462306a36Sopenharmony_cimac80211 interface that is in Monitor mode. Libpcap can also be used, 9562306a36Sopenharmony_ci(which is easier than doing the work to bind the socket to the right 9662306a36Sopenharmony_ciinterface), along the following lines::: 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci ppcap = pcap_open_live(szInterfaceName, 800, 1, 20, szErrbuf); 9962306a36Sopenharmony_ci ... 10062306a36Sopenharmony_ci r = pcap_inject(ppcap, u8aSendBuffer, nLength); 10162306a36Sopenharmony_ci 10262306a36Sopenharmony_ciYou can also find a link to a complete inject application here: 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_cihttps://wireless.wiki.kernel.org/en/users/Documentation/packetspammer 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ciAndy Green <andy@warmcat.com> 107