mac80211-injection.txt 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. How to use packet injection with mac80211
  2. =========================================
  3. mac80211 now allows arbitrary packets to be injected down any Monitor Mode
  4. interface from userland. The packet you inject needs to be composed in the
  5. following format:
  6. [ radiotap header ]
  7. [ ieee80211 header ]
  8. [ payload ]
  9. The radiotap format is discussed in
  10. ./Documentation/networking/radiotap-headers.txt.
  11. Despite many radiotap parameters being currently defined, most only make sense
  12. to appear on received packets. The following information is parsed from the
  13. radiotap headers and used to control injection:
  14. * IEEE80211_RADIOTAP_FLAGS
  15. IEEE80211_RADIOTAP_F_FCS: FCS will be removed and recalculated
  16. IEEE80211_RADIOTAP_F_WEP: frame will be encrypted if key available
  17. IEEE80211_RADIOTAP_F_FRAG: frame will be fragmented if longer than the
  18. current fragmentation threshold.
  19. * IEEE80211_RADIOTAP_TX_FLAGS
  20. IEEE80211_RADIOTAP_F_TX_NOACK: frame should be sent without waiting for
  21. an ACK even if it is a unicast frame
  22. * IEEE80211_RADIOTAP_RATE
  23. legacy rate for the transmission (only for devices without own rate control)
  24. * IEEE80211_RADIOTAP_MCS
  25. HT rate for the transmission (only for devices without own rate control).
  26. Also some flags are parsed
  27. IEEE80211_RADIOTAP_MCS_SGI: use short guard interval
  28. IEEE80211_RADIOTAP_MCS_BW_40: send in HT40 mode
  29. * IEEE80211_RADIOTAP_DATA_RETRIES
  30. number of retries when either IEEE80211_RADIOTAP_RATE or
  31. IEEE80211_RADIOTAP_MCS was used
  32. * IEEE80211_RADIOTAP_VHT
  33. VHT mcs and number of streams used in the transmission (only for devices
  34. without own rate control). Also other fields are parsed
  35. flags field
  36. IEEE80211_RADIOTAP_VHT_FLAG_SGI: use short guard interval
  37. bandwidth field
  38. 1: send using 40MHz channel width
  39. 4: send using 80MHz channel width
  40. 11: send using 160MHz channel width
  41. The injection code can also skip all other currently defined radiotap fields
  42. facilitating replay of captured radiotap headers directly.
  43. Here is an example valid radiotap header defining some parameters
  44. 0x00, 0x00, // <-- radiotap version
  45. 0x0b, 0x00, // <- radiotap header length
  46. 0x04, 0x0c, 0x00, 0x00, // <-- bitmap
  47. 0x6c, // <-- rate
  48. 0x0c, //<-- tx power
  49. 0x01 //<-- antenna
  50. The ieee80211 header follows immediately afterwards, looking for example like
  51. this:
  52. 0x08, 0x01, 0x00, 0x00,
  53. 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  54. 0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
  55. 0x13, 0x22, 0x33, 0x44, 0x55, 0x66,
  56. 0x10, 0x86
  57. Then lastly there is the payload.
  58. After composing the packet contents, it is sent by send()-ing it to a logical
  59. mac80211 interface that is in Monitor mode. Libpcap can also be used,
  60. (which is easier than doing the work to bind the socket to the right
  61. interface), along the following lines:
  62. ppcap = pcap_open_live(szInterfaceName, 800, 1, 20, szErrbuf);
  63. ...
  64. r = pcap_inject(ppcap, u8aSendBuffer, nLength);
  65. You can also find a link to a complete inject application here:
  66. http://wireless.kernel.org/en/users/Documentation/packetspammer
  67. Andy Green <andy@warmcat.com>