Writing an 802.11 frame parser in Rust.

100 points frostie314

Hi,

in the last few months, I've been working on a frame parser for the 802.11 (aka. WLAN/Wi-Fi) frame format. In doing so, I've had to push the language to it's limit, which allowed me to keep the library no_std and free of allocations. Since so far I haven't received any issues or PRs and thought, that some people here might be able to give a second opinion on design choices I made.

The GitHub Repo can be found at: https://github.com/Frostie314159/ieee80211-rs

WLAN frames have 3 types:

  • management
  • control
  • data

Each of these has sixteen possible subtypes, some of which are unused. These main frame types are represented in the IEEE80211Frame enum. Management frames are frames like beacons, which are broadcast by APs and tell devices, which networks are present. Every management header contains certain addresses, and the specific subtypes add their own fixed header. Most management frames then contain tagged data called Information Elements (IE), which consist of one byte indicating the type of the IE and one byte indicating the length. The SSID is also an IE.

When reading a frame, the fixed headers are parsed immediately, while the tagged part is stored as an Elements struct, which internally contains a slice. Each element has its own type representation. When extracting these from the body, the Element::get_elements function can be used, which takes the type of the IE as a generic parameter and returns the parsed IE.

I used to have an enum, which contained every possible type of IE, but due to some IEs growing over 100 bytes, large amounts of space were wasted. This was replaced by a stack allocated list, which can contain different types, while causing minimal overhead. This can be found in the ieee80211::element_chain module.

Let me know what you think.