xref: /freebsd/sys/net80211/PROTOCOL.md (revision 490c53e9353feb129fe0acb8d9ba8fa52db24e2c)
1*490c53e9SAdrian Chadd# 802.11 protocol overview
2*490c53e9SAdrian Chadd
3*490c53e9SAdrian ChaddThis is a quick overview of the 802.11 protocol and where it intersects with
4*490c53e9SAdrian Chaddnet80211.  It is not intended as a comprehensive deep dive into all of 802.11.
5*490c53e9SAdrian Chadd
6*490c53e9SAdrian ChaddTODO: link to appropriate sections in 802.11-2016 / 802.11-2020 depending upon
7*490c53e9SAdrian Chaddwhich PDF is freely available.
8*490c53e9SAdrian Chadd
9*490c53e9SAdrian Chadd## 802.11 overview
10*490c53e9SAdrian Chadd
11*490c53e9SAdrian ChaddThe 802.11 protocol / specification is a very large document which covers
12*490c53e9SAdrian Chaddeverything from the raw signals going out over the air up to how devices
13*490c53e9SAdrian Chaddneed to behave in different operating modes.
14*490c53e9SAdrian Chadd
15*490c53e9SAdrian ChaddThe IEEE specification documents and amendments describe what devices should
16*490c53e9SAdrian Chaddand must do in order to interoperate.  It's important to note that the
17*490c53e9SAdrian Chaddintersection of "what the standard says" and "what devices do" is not always
18*490c53e9SAdrian Chaddfully aligned.  The 802.11 specification has evolved over twenty-five years
19*490c53e9SAdrian Chaddand for the most part this allows interoperability between the original 802.11b
20*490c53e9SAdrian Chaddhardware and modern multi-band 802.11ax devices.
21*490c53e9SAdrian Chadd
22*490c53e9SAdrian ChaddIt's also important to note that 802.11 is not just limited to the IEEE
23*490c53e9SAdrian Chaddspecifications.  802.11 devices are almost exclusively RF devices (if you
24*490c53e9SAdrian Chaddread the specification you may find the old infrared / IR protocol definition!)
25*490c53e9SAdrian Chaddand so need to operate inside of the radio regulatory rules defined by each
26*490c53e9SAdrian Chaddcountry.  These define a wide variety of RF environmental behaviours
27*490c53e9SAdrian Chaddincluding frequencies can be used, when devices can transmit, what transmit
28*490c53e9SAdrian Chaddpower is allowed, interoperability with other devices (802.11 and non-802.11)
29*490c53e9SAdrian Chaddand radar interoperability.  For the purposes of this document these will
30*490c53e9SAdrian Chaddbe called "regulatory concerns" and will be covered elsewhere.
31*490c53e9SAdrian Chadd
32*490c53e9SAdrian ChaddThe 802.11 specification breaks things up into a handful of top level areas:
33*490c53e9SAdrian Chadd
34*490c53e9SAdrian Chadd * the PHY layer - how the device interfaces with the RF environment and
35*490c53e9SAdrian Chadd   encodes/decodes RF transmissions into data streams.
36*490c53e9SAdrian Chadd * the MAC layer - defines how data is packetized into individual data frames,
37*490c53e9SAdrian Chadd   exchanged with the upper layer (ethernet/bridge), deciding when and what
38*490c53e9SAdrian Chadd   to transmit via the PHY layer.
39*490c53e9SAdrian Chadd * MLME - (MAC layer management entities) - defines all of the state methods
40*490c53e9SAdrian Chadd   and transitions that underpin the 802.11 MAC state machine.
41*490c53e9SAdrian Chadd * Security - the cipher and key management components.
42*490c53e9SAdrian Chadd * PHY specifications - the specific implementations of PHYs - 2GHz DSSS
43*490c53e9SAdrian Chadd   (spread spectrum), 2GHZ CCK, OFDM, ERP, 802.11n / HT, 802.11ac / VHT, etc.
44*490c53e9SAdrian Chadd
45*490c53e9SAdrian ChaddMost 802.11 implementations do not implement a 1:1 definition of each of these
46*490c53e9SAdrian Chaddlayers - notably implementing every single MLME state would be a huge amount
47*490c53e9SAdrian Chaddof work.
48*490c53e9SAdrian Chadd
49*490c53e9SAdrian Chadd## 802.11 revisions
50*490c53e9SAdrian Chadd
51*490c53e9SAdrian ChaddThere have been many revisions of the 802.11 specification. The specifications
52*490c53e9SAdrian Chaddcan be found online at https://www.ieee802.org/11/.
53*490c53e9SAdrian Chadd
54*490c53e9SAdrian ChaddThe latest specification being implemented in net80211 is 802.11-2020, however
55*490c53e9SAdrian Chaddnet80211 is far from completely compliant.  Generally new code which implements
56*490c53e9SAdrian Chadd802.11 features / protocol handling should identify the specification and
57*490c53e9SAdrian Chaddsection which it is referencing.
58*490c53e9SAdrian Chadd
59*490c53e9SAdrian Chadd## 802.11 protocol and frame definitions
60*490c53e9SAdrian Chadd
61*490c53e9SAdrian Chaddnet80211 keeps most 802.11 frame and protocol definitions in a single location
62*490c53e9SAdrian Chadd(ieee80211.h).
63*490c53e9SAdrian ChaddThis contains descriptions of the 802.11 frame and field definitions, ranging
64*490c53e9SAdrian Chaddfrom the lowest definition of the frame itself up through frame types/subtypes,
65*490c53e9SAdrian Chaddindividual field definitions, information elements, action frames, and
66*490c53e9SAdrian Chaddanything else that can be found in the 802.11 specifications.
67*490c53e9SAdrian Chadd
68*490c53e9SAdrian ChaddThe PHY definitions can be found in (ieee80211_phy.c) and (ieee80211_phy.h).
69*490c53e9SAdrian ChaddNotably those include the frame timing information useful for rate control
70*490c53e9SAdrian Chaddand frame duration calculations.
71*490c53e9SAdrian Chadd
72*490c53e9SAdrian Chadd## 802.11 Revisions
73*490c53e9SAdrian Chadd
74*490c53e9SAdrian Chadd(TBD)
75*490c53e9SAdrian Chadd
76*490c53e9SAdrian Chadd### Legacy 802.11
77*490c53e9SAdrian Chadd
78*490c53e9SAdrian ChaddThe earliest 802.11 devices implement 1Mbit/s and 2Mbit/s direct spread spectrum
79*490c53e9SAdrian Chaddframes.  These include the earliest Wavelan devices.  These are grandfathered
80*490c53e9SAdrian Chaddinto 802.11b.  The PHY specification can be found in 802.11-2020 Section 15.)
81*490c53e9SAdrian Chadd
82*490c53e9SAdrian Chadd### 802.11b
83*490c53e9SAdrian Chadd
84*490c53e9SAdrian Chadd802.11b devices implement Section 15 (1Mbit/2Mbit) PHYs as well as the high
85*490c53e9SAdrian Chaddrate DSSS specification (802.11-2020 Section 16) to provide 5.5Mbit and 11Mbit
86*490c53e9SAdrian ChaddCCK rates.  They interoperate with legacy 802.11 devices by using compatible
87*490c53e9SAdrian ChaddPHY encodings and will limit their performance if said legacy devices are
88*490c53e9SAdrian Chadddetected.
89*490c53e9SAdrian Chadd
90*490c53e9SAdrian Chadd### 802.11a
91*490c53e9SAdrian Chadd
92*490c53e9SAdrian Chadd802.11a devices implement OFDM rates from 6Mbit/s to 54Mbit/s on the 5GHz
93*490c53e9SAdrian Chaddband.  Among other features, it also defines 5MHz and 10MHz wide channel
94*490c53e9SAdrian Chaddbehaviour.  This is covered in the OFDM PHY specification (802.11-2020
95*490c53e9SAdrian ChaddSection 17.)
96*490c53e9SAdrian Chadd
97*490c53e9SAdrian Chadd### 802.11g
98*490c53e9SAdrian Chadd
99*490c53e9SAdrian Chadd802.11g devices implement OFDM rates from 802.11a, the CCK rates from 802.11b
100*490c53e9SAdrian Chaddand the DSSS rates from legacy 802.11.  These are covered in the ERP
101*490c53e9SAdrian Chaddspecification (802.11-2020 Section 18.) There are some MAC extensions for
102*490c53e9SAdrian Chaddnegotiating 802.11b / 802.11g interoperability and these are documented
103*490c53e9SAdrian Chaddthroughout the MAC specification.  This also specifies support for 5MHz and
104*490c53e9SAdrian Chadd10MHz wide channels.
105*490c53e9SAdrian Chadd
106*490c53e9SAdrian Chadd### 802.11n (HT)
107*490c53e9SAdrian Chadd
108*490c53e9SAdrian Chadd802.11n introduced a variety of high throughput rates and feature support
109*490c53e9SAdrian Chadd(hence why it's called HT - high throughput).  It introduces higher density
110*490c53e9SAdrian ChaddOFDM rate encodings, 20 and 40MHz wide channels with interoperability for
111*490c53e9SAdrian Chaddearlier devices, packet aggregation via A-MPDU and A-MSDU, MIMO (multiple input,
112*490c53e9SAdrian Chaddmultiple output spatial streams), some initial beamforming support, power
113*490c53e9SAdrian Chaddsaving extensions and more.
114*490c53e9SAdrian Chadd
115*490c53e9SAdrian ChaddThe physical layer support is covered in the HT PHY specification (802.11-2020
116*490c53e9SAdrian ChaddSection 19.)  The rest of the MAC extensions are documented throughout the
117*490c53e9SAdrian Chaddrest of the specification.
118*490c53e9SAdrian Chadd
119*490c53e9SAdrian Chadd### 802.11ac (VHT)
120*490c53e9SAdrian Chadd
121*490c53e9SAdrian Chadd802.11ac extends the 802.11n specification (hence why it's VHT - Very
122*490c53e9SAdrian ChaddHigh Throughput) and boosts performance by adding higher density OFDM QAM
123*490c53e9SAdrian Chaddencoding (256-QAM), wider channels (80MHz, 160MHz), split 80+80MHz channel
124*490c53e9SAdrian Chaddsupport, much larger A-MSDU / A-MPDU frame sizes, support for MU-MIMO
125*490c53e9SAdrian Chadd(multi-user MIMO) allowing APs to transmit to multiple STAs at the same time
126*490c53e9SAdrian Chaddand various other extensions.
127*490c53e9SAdrian Chadd
128*490c53e9SAdrian ChaddIt builds on top of the 802.11n MAC and PHY specification, so a lot of
129*490c53e9SAdrian Chadd802.11n feature and MAC negotiation happens as part of 802.11ac negotiation.
130*490c53e9SAdrian Chadd
131*490c53e9SAdrian ChaddThe PHY layer is covered in the VHT PHY Specification (802.11-2020 Section
132*490c53e9SAdrian Chadd21.)  Again, the rest of the MAC extensions are documented throughout the
133*490c53e9SAdrian Chaddrest of the specification.
134*490c53e9SAdrian Chadd
135*490c53e9SAdrian Chadd### Greenfield versus backwards compatibility
136*490c53e9SAdrian Chadd
137*490c53e9SAdrian ChaddThe various protocols supported by 802.11 build on top of earlier protocols.
138*490c53e9SAdrian ChaddSo typically you're not building a single implementation for each protocol -
139*490c53e9SAdrian Chaddfor example, you can't handle 802.11ac support without implementing a large
140*490c53e9SAdrian Chaddamount of 802.11n support.
141*490c53e9SAdrian Chadd
142*490c53e9SAdrian Chadd(As a side note, the 802.11 frame has a protocol version field, and
143*490c53e9SAdrian Chaddthat actually changed in 802.11ah (900MHz and longer distance bands) -
144*490c53e9SAdrian Chaddwhich changes a lot of what the fields do.  No, net80211 currently does not
145*490c53e9SAdrian Chaddsupport 802.11ah and will drop frames whose 802.11 protocol ID is not
146*490c53e9SAdrian Chaddsupported.)
147*490c53e9SAdrian Chadd
148*490c53e9SAdrian ChaddAt the PHY layer, later model hardware can transmit data encodings which
149*490c53e9SAdrian Chaddearlier model hardware just won't recognise.  All they'll see is an increase
150*490c53e9SAdrian Chaddin RF power on the channel at best and signals that will confuse the
151*490c53e9SAdrian ChaddRX decoder / cause hardware issues at worst.)
152*490c53e9SAdrian Chadd
153*490c53e9SAdrian ChaddSo each of the PHY specifications will lay out a few things:
154*490c53e9SAdrian Chadd
155*490c53e9SAdrian Chadd * How frames should be encoded in the air in a way that earlier
156*490c53e9SAdrian Chadd   hardware can decode them enough to know it's not for them;
157*490c53e9SAdrian Chadd * How devices can identify that earlier protocol devices are around and
158*490c53e9SAdrian Chadd   change the configuration (eg STA changing its own configuration,
159*490c53e9SAdrian Chadd   AP changing the configuration of the network it controls, etc)
160*490c53e9SAdrian Chadd   to provide backwards compatibility.
161*490c53e9SAdrian Chadd
162*490c53e9SAdrian ChaddThese come at a performance cost.  For example, an 802.11g AP which
163*490c53e9SAdrian Chaddsupports 802.11b and 802.11 devices needs to notice that an 802.11b
164*490c53e9SAdrian Chadddevice wishes to associate, and when it sees this, change some of
165*490c53e9SAdrian Chaddits configuration (notably "long preamble" so 802.11b devices can
166*490c53e9SAdrian Chadddecode frames that are being transmitted, whether destined to it or not.)
167*490c53e9SAdrian Chadd
168*490c53e9SAdrian ChaddVarious devices allow backwards compatbility to be configured.
169*490c53e9SAdrian ChaddFor example, an 802.11n AP may be configured to deny non-802.11n clients.
170*490c53e9SAdrian ChaddThis may improve performance but then earlier clients can't connect.
171*490c53e9SAdrian Chadd
172*490c53e9SAdrian ChaddIn 802.11n deployments this was known as a "greenfield deployment".
173*490c53e9SAdrian ChaddThis typically disables any and all pre-11n interoperability at both
174*490c53e9SAdrian Chadda MAC and PHY layer.  net80211 has some flags for this to specifically
175*490c53e9SAdrian Chaddinform devices that they can configure the hardware for such a setup.
176*490c53e9SAdrian ChaddNot all drivers implement it however, and in a lot of cases they will
177*490c53e9SAdrian Chaddstill handle pre-11n framing, even if the net80211 code will deny
178*490c53e9SAdrian Chaddassociation.
179*490c53e9SAdrian Chadd
180*490c53e9SAdrian ChaddThere are other components to backwards compatibility which are worth
181*490c53e9SAdrian Chaddkeeping in mind when reading through the 802.11 specification and
182*490c53e9SAdrian Chaddnet80211 stack / driver code.  These include:
183*490c53e9SAdrian Chadd
184*490c53e9SAdrian Chadd * short/long preamble - (vap_update_preamble)
185*490c53e9SAdrian Chadd * short/long slot time configuration - (vap_update_slot)
186*490c53e9SAdrian Chadd * 802.11g protection mode (vap_update_erp_protmode) -
187*490c53e9SAdrian Chadd   whether to use CTS-to-self around each transmission
188*490c53e9SAdrian Chadd * 802.11n protection mode (vap_update_ht_protmode) -
189*490c53e9SAdrian Chadd   whether to use RTS/CTS around each transmission
190*490c53e9SAdrian Chadd * 802.11n 20/40MHz BSS operation (whether an 802.11n AP sees other APs that
191*490c53e9SAdrian Chadd   overlap its frequency range and need to reconfigure how to protect
192*490c53e9SAdrian Chadd   transmissions)
193*490c53e9SAdrian Chadd
194*490c53e9SAdrian Chadd## How 802.11 (very briefly) works over the air
195*490c53e9SAdrian Chadd
196*490c53e9SAdrian ChaddThis is a very brief and not at all comprehensive overview of how 802.11
197*490c53e9SAdrian Chaddworks over the air.  The goal of this section is to provide enough background
198*490c53e9SAdrian Chaddinformation to help de-mystify reading the net80211 stack and wireless
199*490c53e9SAdrian Chadddriver source.
200*490c53e9SAdrian Chadd
201*490c53e9SAdrian Chadd### Why there's timing requirements in the first place
202*490c53e9SAdrian Chadd
203*490c53e9SAdrian ChaddEach of the PHY sections in the 802.11 specification describe what
204*490c53e9SAdrian Chaddthe PHY needs to do in order to transmit and receive data. It's not
205*490c53e9SAdrian Chaddanywhere as easy as "toggle some bits on a wire".
206*490c53e9SAdrian Chadd
207*490c53e9SAdrian ChaddAn important thing to understand is that hardware isn't immediate.
208*490c53e9SAdrian ChaddAll the state machines in your 802.11 devices take non-zero time
209*490c53e9SAdrian Chaddto make decisions about when to transmit, when to receive, locking
210*490c53e9SAdrian Chaddonto a signal, deciding it can be decoded, getting reset for the next
211*490c53e9SAdrian Chaddframe, etc.
212*490c53e9SAdrian Chadd
213*490c53e9SAdrian ChaddSo a lot of what you'll see in 802.11 negotiation and feature support
214*490c53e9SAdrian Chaddis linked to the underlying hardware implementations and limitations
215*490c53e9SAdrian Chaddof the time.  For example the 802.11b specification defines the slot time
216*490c53e9SAdrian Chaddas 20uS, but the 802.11g specification lowers it to 9uS.  The "slot time"
217*490c53e9SAdrian Chaddvalue defines the unit of time used for contention management / backoff, and
218*490c53e9SAdrian Chaddit's defined partly by what the speed of light dictates (ie how big
219*490c53e9SAdrian Chaddof a physical area you want to be able to "hear" in determining if the
220*490c53e9SAdrian Chaddarea is busy) and how quickly the hardware can guarantee to respond.
221*490c53e9SAdrian ChaddIt dropped to 9uS because hardware got better, but to interoperate
222*490c53e9SAdrian Chaddwith older devices without starting to transmit before they're
223*490c53e9SAdrian Chaddready to react, 802.11g devices will fall back to 20uS slot time when
224*490c53e9SAdrian Chaddthey detect an 802.11b device.
225*490c53e9SAdrian Chadd
226*490c53e9SAdrian ChaddThis carries through everywhere in odd places that you're not necessarily
227*490c53e9SAdrian Chaddaware of.  For example, the 802.11n A-MPDU definition includes negotiated
228*490c53e9SAdrian Chaddpadding between frames and limits encryption ciphers (typically CCMP or
229*490c53e9SAdrian ChaddGCMP.)  This is due to hardware support - the MAC may be able to support
230*490c53e9SAdrian Chaddmuch less padding when no encryption is used, but setting up / resetting
231*490c53e9SAdrian Chaddthe encryption / decryption blocks may take more time and thus larger
232*490c53e9SAdrian ChaddA-MPDU padding values are negotiated.
233*490c53e9SAdrian Chadd
234*490c53e9SAdrian Chadd### Wait, the speed of light?
235*490c53e9SAdrian Chadd
236*490c53e9SAdrian ChaddYes.  The speed of light is roughly 300 metres for each microsecond of
237*490c53e9SAdrian Chaddtravel time.
238*490c53e9SAdrian Chadd
239*490c53e9SAdrian Chadd### Preambles, SIGs, PLCP, sending actual data and waiting / slot times
240*490c53e9SAdrian Chadd
241*490c53e9SAdrian ChaddThere are a few things that are worth understanding at a high level.
242*490c53e9SAdrian Chadd
243*490c53e9SAdrian Chadd * The first thing that a device needs to do is determine
244*490c53e9SAdrian Chadd   whether the air is busy or free.  There'll be some hardware
245*490c53e9SAdrian Chadd   to determine the signal level versus noise floor and provide
246*490c53e9SAdrian Chadd   a signal to the transmit hardware that the air is free,
247*490c53e9SAdrian Chadd   and to the receiver that it may want to try start decoding
248*490c53e9SAdrian Chadd   something.
249*490c53e9SAdrian Chadd
250*490c53e9SAdrian Chadd * The receiver needs to get in synchronisation with the transmitter.
251*490c53e9SAdrian Chadd   This is a one way operation - the transmitter needs to transmit
252*490c53e9SAdrian Chadd   enough of a signal that the receiver can "lock onto" and get itself
253*490c53e9SAdrian Chadd   ready for further data.  This is called the "preamble" - it's
254*490c53e9SAdrian Chadd   typically a low bitrate repeating pattern of data that gives
255*490c53e9SAdrian Chadd   the receiver hardware time to lock onto, figure out the signal
256*490c53e9SAdrian Chadd   level and be ready for the next phase.
257*490c53e9SAdrian Chadd
258*490c53e9SAdrian Chadd * Note that the receiver may pick up the preamble at any point in its
259*490c53e9SAdrian Chadd   transmission so it can't guarantee it will see exactly "x" bits of some
260*490c53e9SAdrian Chadd   repeating pattern.
261*490c53e9SAdrian Chadd
262*490c53e9SAdrian Chadd * Then there's other bits and pieces - eg look for L-SIG, HT-SIG
263*490c53e9SAdrian Chadd   in the PHY documentation - which is used to further synchronise
264*490c53e9SAdrian Chadd   what's about to happen.
265*490c53e9SAdrian Chadd
266*490c53e9SAdrian Chadd * Finally it will start transmitting the PHY framing bits needed to
267*490c53e9SAdrian Chadd   identify what the upcoming transmit rate and configuration is
268*490c53e9SAdrian Chadd   (all the stuff leading up to the PLCP header, then the PLCP header.)
269*490c53e9SAdrian Chadd
270*490c53e9SAdrian ChaddThings get more complicated with MIMO, MU-MIMO, 802.11ax OFDM-A, etc but
271*490c53e9SAdrian Chadddon't worry about those for now - they build on top of all of these
272*490c53e9SAdrian Chaddideas.
273*490c53e9SAdrian Chadd
274*490c53e9SAdrian ChaddOnce the data is transmitted, there's some quiet time between frames
275*490c53e9SAdrian Chaddbefore the receiver can ACK (and then a period of time where an ACK
276*490c53e9SAdrian Chaddis expected.)  The transmitter needs to finish transmitting, then
277*490c53e9SAdrian Chaddreset its internal state back to idle to be ready to receive - and
278*490c53e9SAdrian Chaddthere's the pesky speed of light speed of 300m per microsecond -
279*490c53e9SAdrian Chaddso there's some MAC (interframe spacing) and PHY (slot time) enforcing
280*490c53e9SAdrian Chaddquiet so everyone has a chance to receive the frame and the reciver
281*490c53e9SAdrian Chaddgets ready to receive.  Then if there's an ACK, the ACK happens.
282*490c53e9SAdrian Chadd
283*490c53e9SAdrian Chadd### PLCP header
284*490c53e9SAdrian Chadd
285*490c53e9SAdrian ChaddOnce all of the preamble, SIG/training stuff is done, the transmitter
286*490c53e9SAdrian Chaddwill send a PLCP header with information about the transmitter
287*490c53e9SAdrian Chaddtype and rate (and that's very handwaving it.)  net80211 has definitions
288*490c53e9SAdrian Chaddfor the plcp header (ieee80211_plcp_hdr) but it's highly unlikely it will
289*490c53e9SAdrian Chaddbe relevant or available in modern devices.
290*490c53e9SAdrian Chadd
291*490c53e9SAdrian Chadd### How data is encoded - encoding rates, symbols, guard intervals
292*490c53e9SAdrian Chadd
293*490c53e9SAdrian ChaddNow, once the transmitter has sent all of that, it will start to send
294*490c53e9SAdrian Chaddactual data encoded at the desired transmit rate.  The data bits
295*490c53e9SAdrian Chaddthat you're transmitting go through a variety of encoding schemes
296*490c53e9SAdrian Chaddbefore they're turned into bits that are clocked out at the 802.11
297*490c53e9SAdrian Chaddphysical layer (think "forward error correction" as an example),
298*490c53e9SAdrian Chaddbut they're turned into what are known as "symbols".
299*490c53e9SAdrian Chadd
300*490c53e9SAdrian ChaddA symbol can be thought of as a group of bits encoded in one specific
301*490c53e9SAdrian ChaddRF representation.  Explaining all the details isn't in scope of this
302*490c53e9SAdrian Chadddocument (and I encourage interested parties to do a quick dive
303*490c53e9SAdrian Chaddinto information theory!) but there are a couple of important higher
304*490c53e9SAdrian Chaddlevel concepts to understand here that influence what happens
305*490c53e9SAdrian Chaddlater on in packet delivery.
306*490c53e9SAdrian Chadd
307*490c53e9SAdrian ChaddFor OFDM encoding:
308*490c53e9SAdrian Chadd
309*490c53e9SAdrian Chadd  * Each symbol is preceded by a quiet time called a guard interval, to make
310*490c53e9SAdrian Chadd    sure any reflections don't interfere with the upcoming symbol;
311*490c53e9SAdrian Chadd  * Each symbol is then transmitted for a specific length of time to make sure
312*490c53e9SAdrian Chadd    it's received by everyone inside the desired area (again light = 300m/sec
313*490c53e9SAdrian Chadd    per microsecond);
314*490c53e9SAdrian Chadd  * All symbols for a given 802.11 MPDU are sent at the exact same rate;
315*490c53e9SAdrian Chadd  * This is repeated until all the symbols are transmitted.
316*490c53e9SAdrian Chadd
317*490c53e9SAdrian ChaddThe higher the data rate used, the higher the signal level needs to be
318*490c53e9SAdrian Chaddand lower the tolerance it has to interference.  Forward error correction
319*490c53e9SAdrian Chaddcan only do so much, and the higher throughput rate encodings sacrifice
320*490c53e9SAdrian ChaddFEC for throughput.
321*490c53e9SAdrian Chadd
322*490c53e9SAdrian ChaddOnce an uncorrectable error occurs and the frame fails CRC, the whole MPDU is
323*490c53e9SAdrian Chadddropped by the receiver.
324*490c53e9SAdrian Chadd
325*490c53e9SAdrian ChaddPart of why A-MPDU is so important for high throughput is that the
326*490c53e9SAdrian Chadderrors are limited to a single MPDU in the burst of MPDUs. Ie, if
327*490c53e9SAdrian Chaddthe transmitter sends ten MPDUs in a single A-MPDU, and five of them
328*490c53e9SAdrian Chaddhave uncorrectable errors, then five .. well, didn't.  This means
329*490c53e9SAdrian Chaddthe receiver can ACK some but not all of the MPDUs, and the transmitter
330*490c53e9SAdrian Chaddcan re-send those with new MPDUs.
331*490c53e9SAdrian Chadd
332*490c53e9SAdrian ChaddThe default guard interval is 800ns.  802.11n allows for negotiating
333*490c53e9SAdrian Chaddshorter guard interval (400ns) which can be done per device in a BSS.
334*490c53e9SAdrian ChaddAn 800ns guard interval is a little short of 300 metres, and 400ns is
335*490c53e9SAdrian Chadda little short of 150 metres - so using short guard interval means
336*490c53e9SAdrian Chaddyou trade increased performance for potential decreased performance
337*490c53e9SAdrian Chaddif you have reflections or stations more than 150 metres away.
338*490c53e9SAdrian Chadd
339*490c53e9SAdrian Chadd802.11ax adds support for 1.6us and 3.2us guard intervals for physically
340*490c53e9SAdrian Chaddlarger deployments.
341*490c53e9SAdrian Chadd
342*490c53e9SAdrian Chadd### MAC layer framing
343*490c53e9SAdrian Chadd
344*490c53e9SAdrian ChaddThe MAC layer handles data that is encapsulated in the given transmit
345*490c53e9SAdrian Chaddrate that was established in the PHY (PLCP) header.  This includes
346*490c53e9SAdrian Chaddthe 802.11 MAC header, CRC trailer, any of the cipher processing that
347*490c53e9SAdrian Chaddhappens in between.  In the case of 802.11n, it can encapsulate
348*490c53e9SAdrian Chaddmultiple frames being sent back to back in a single transmission.
349*490c53e9SAdrian Chadd
350*490c53e9SAdrian ChaddDevices which do partial / no offload will typically produce and
351*490c53e9SAdrian Chaddconsume 802.11 MAC layer frames to the driver and net80211.
352*490c53e9SAdrian ChaddIt's thus important to understand MAC framing and frame types.
353*490c53e9SAdrian Chadd
354*490c53e9SAdrian Chadd### MPDU versus MSDU
355*490c53e9SAdrian Chadd
356*490c53e9SAdrian ChaddAn MSDU (MAC service data unit) is an individual frame (think "802.2/802.3
357*490c53e9SAdrian Chaddethernet") passed from the network stack into net80211.
358*490c53e9SAdrian Chadd
359*490c53e9SAdrian ChaddAn MPDU (MAC protocol data unit) is one or more MSDU frames wrapped by an
360*490c53e9SAdrian Chadd(ieee80211_frame) header and CRC trailer.  It is what is eventually
361*490c53e9SAdrian Chaddencapsulated inside the PHY framing (preambles, training symbols, PLCP
362*490c53e9SAdrian Chaddheader, etc) and sent over the air.
363*490c53e9SAdrian Chadd
364*490c53e9SAdrian ChaddNotably an 802.11 MPDU isn't just an IPv4/IPv6 frame with an 802.11
365*490c53e9SAdrian Chaddheader/trailer - it is a full ethernet frame that is being wrapped
366*490c53e9SAdrian Chaddby 802.11 framing.
367*490c53e9SAdrian Chadd
368*490c53e9SAdrian Chadd### Tracking airtime with NAV
369*490c53e9SAdrian Chadd
370*490c53e9SAdrian Chadd802.11 devices have to interoperate in a shared medium.  Earlier protocol
371*490c53e9SAdrian Chadddefinitions require one transmitter at a time.  Later specification
372*490c53e9SAdrian Chadddevices (MU-MIMO with 802.11ac, OFDM-A with 802.11ax, etc) introduce the
373*490c53e9SAdrian Chaddability for devices to transmit and receive simultaneously.
374*490c53e9SAdrian Chadd
375*490c53e9SAdrian ChaddThe simplest way to track this is with NAV (network access vector.)
376*490c53e9SAdrian ChaddThe NAV implementation in pre-11ax devices is a single counter which
377*490c53e9SAdrian Chaddcounts down to zero.  Once it is zero, the air is considered "available"
378*490c53e9SAdrian Chaddto attempt to check to transmit on.  The transmitter will also check
379*490c53e9SAdrian Chaddwhether the air is busy (ie can it detect any signals present) before
380*490c53e9SAdrian Chaddit transmits - this is called CCA (clear channel access) and is
381*490c53e9SAdrian Chaddtypically implemented in hardware.
382*490c53e9SAdrian Chadd
383*490c53e9SAdrian ChaddThe duration field in (ieee80211_frame) is a microsecond field which
384*490c53e9SAdrian Chaddcovers the whole duration of the frame being transmitted.  Receivers
385*490c53e9SAdrian Chaddthat decode the frame - even if it's not destined to them! - will listen
386*490c53e9SAdrian Chaddto the NAV and add it to their own NAV.
387*490c53e9SAdrian Chadd
388*490c53e9SAdrian ChaddAll 802.11 frames have a duration field.
389*490c53e9SAdrian Chadd
390*490c53e9SAdrian Chadd### Fragmented frames
391*490c53e9SAdrian Chadd
392*490c53e9SAdrian Chadd(TBD)
393*490c53e9SAdrian Chadd
394*490c53e9SAdrian Chadd### Sequence counters and duplication detection
395*490c53e9SAdrian Chadd
396*490c53e9SAdrian Chadd(TBD)
397*490c53e9SAdrian Chadd
398*490c53e9SAdrian Chadd### EDCA and QoS
399*490c53e9SAdrian Chadd
400*490c53e9SAdrian Chadd(TBD)
401*490c53e9SAdrian Chadd
402*490c53e9SAdrian Chadd### Inter-frame spacing (IFS)
403*490c53e9SAdrian Chadd
404*490c53e9SAdrian Chadd(TBD)
405*490c53e9SAdrian Chadd
406*490c53e9SAdrian Chadd## 802.11 frame layout
407*490c53e9SAdrian Chadd
408*490c53e9SAdrian ChaddAn individual 802.11 frame contains frame control (version, type, subtype),
409*490c53e9SAdrian Chaddduration, addressing, sequence number and optional QoS information.
410*490c53e9SAdrian ChaddThe basic definition is available at (ieee80211_frame) but other definitions
411*490c53e9SAdrian Chaddare also possible - (ieee80211_qosframe), (ieee80211_frame_addr4),
412*490c53e9SAdrian Chadd(ieee80211_qosframe_addr4).
413*490c53e9SAdrian Chadd
414*490c53e9SAdrian ChaddIt then has a 4 byte CRC32 trailer appended at the end.
415*490c53e9SAdrian Chadd
416*490c53e9SAdrian Chadd### Addressing types and traffic direction
417*490c53e9SAdrian Chadd
418*490c53e9SAdrian Chadd(TBD - 3addr, 4addr, each of the fields, etc)
419*490c53e9SAdrian Chadd
420*490c53e9SAdrian Chadd### QoS versus non-QoS frames
421*490c53e9SAdrian Chadd
422*490c53e9SAdrian Chadd(TBD)
423*490c53e9SAdrian Chadd
424*490c53e9SAdrian Chadd### RTS/CTS exchange and airtime
425*490c53e9SAdrian Chadd
426*490c53e9SAdrian Chadd(TBD)
427*490c53e9SAdrian Chadd
428*490c53e9SAdrian Chadd### CTS-to-self / OFDM protection
429*490c53e9SAdrian Chadd
430*490c53e9SAdrian ChaddCTS to self is a concept introduced in 802.11g.  The general idea is that a
431*490c53e9SAdrian Chaddtransmitter can send a CTS to its own MAC address for the duration that it
432*490c53e9SAdrian Chaddwishes to transmit for.  Since the CTS frame is transmitted at a slower
433*490c53e9SAdrian Chaddlegacy rate, it both reserves airtime in any receiver in earshot, and
434*490c53e9SAdrian Chaddit is understood by older 11b only devices which do not understand 11g.
435*490c53e9SAdrian Chadd
436*490c53e9SAdrian ChaddThis ends up also being useful for 11n, 11ac etc to interoperate with
437*490c53e9SAdrian Chaddearlier devices, but they typically rely on a normal RTS exchange.
438*490c53e9SAdrian Chadd
439*490c53e9SAdrian Chadd### Data frames
440*490c53e9SAdrian Chadd
441*490c53e9SAdrian Chadd(TBD)
442*490c53e9SAdrian Chadd
443*490c53e9SAdrian Chadd### Management frames
444*490c53e9SAdrian Chadd
445*490c53e9SAdrian Chadd(TBD)
446*490c53e9SAdrian Chadd
447*490c53e9SAdrian Chadd### Control frames
448*490c53e9SAdrian Chadd
449*490c53e9SAdrian Chadd(TBD)
450*490c53e9SAdrian Chadd
451*490c53e9SAdrian ChaddNotably, control frames do not have a sequence number and so can't be
452*490c53e9SAdrian Chaddde-duplicated.
453*490c53e9SAdrian Chadd
454*490c53e9SAdrian Chadd### Action frames
455*490c53e9SAdrian Chadd
456*490c53e9SAdrian Chadd(TBD)
457*490c53e9SAdrian Chadd
458*490c53e9SAdrian Chadd## Frame combinations
459*490c53e9SAdrian Chadd
460*490c53e9SAdrian ChaddThere are various ways that 802.11 frames are combined together to improve
461*490c53e9SAdrian Chaddperformance.
462*490c53e9SAdrian Chadd
463*490c53e9SAdrian Chadd### ACK, Delayed Block-ACK, Immediate Block-ACK
464*490c53e9SAdrian Chadd
465*490c53e9SAdrian Chadd(TBD)
466*490c53e9SAdrian Chadd
467*490c53e9SAdrian Chadd### Atheros Fast Frames
468*490c53e9SAdrian Chadd
469*490c53e9SAdrian Chadd(TBD)
470*490c53e9SAdrian Chadd
471*490c53e9SAdrian Chadd### A-MSDU
472*490c53e9SAdrian Chadd
473*490c53e9SAdrian Chadd(TBD)
474*490c53e9SAdrian Chadd
475*490c53e9SAdrian Chadd### A-MPDU
476*490c53e9SAdrian Chadd
477*490c53e9SAdrian Chadd(TBD)
478*490c53e9SAdrian Chadd
479*490c53e9SAdrian Chadd## Security / Encryption
480*490c53e9SAdrian Chadd
481*490c53e9SAdrian ChaddThis is a much larger topic, however it's worth touching on the basics here to
482*490c53e9SAdrian Chaddunderstand how frames are redirected into the security/encryption paths in
483*490c53e9SAdrian Chaddnet80211 and what devices may do with said frames.
484*490c53e9SAdrian Chadd
485*490c53e9SAdrian Chadd### WEP, IV header and keys
486*490c53e9SAdrian Chadd
487*490c53e9SAdrian ChaddWEP is an obsolete encryption method dating back to the earliest 802.11b
488*490c53e9SAdrian Chaddspecifications.  It involves a 4 byte header which includes
489*490c53e9SAdrian Chadd
490*490c53e9SAdrian Chadd * a 24 bit IV (initialisation vector);
491*490c53e9SAdrian Chadd * a 2 bit field indication which of four keys to use;
492*490c53e9SAdrian Chadd * A CRC at the end.
493*490c53e9SAdrian Chadd
494*490c53e9SAdrian ChaddIt's relevant today because later cipher frame formats still use the IV
495*490c53e9SAdrian Chaddheader - they're just extended to include more information.  Notably, the
496*490c53e9SAdrian Chaddfour key indexes are typically implemented and used in hardware, and have
497*490c53e9SAdrian Chadddifferent meanings depending upon the kind of traffic being handled.
498*490c53e9SAdrian Chadd
499*490c53e9SAdrian Chadd### WPA/WPA2 management
500*490c53e9SAdrian Chadd
501*490c53e9SAdrian ChaddThis is handled in userland.  The 802.11 specification covers everything
502*490c53e9SAdrian Chaddinvolved in key exchange and management but it's out of scope for this 802.11
503*490c53e9SAdrian Chaddoverview documentation.
504*490c53e9SAdrian Chadd
505*490c53e9SAdrian Chadd### CCMP, GCMP, TKIP frames
506*490c53e9SAdrian Chadd
507*490c53e9SAdrian ChaddThese later ciphers still use the WEP header, but they then add extra bytes
508*490c53e9SAdrian Chaddto it to include the larger sequence number space, other options needed
509*490c53e9SAdrian Chaddfor said ciphers, and a larger trailer for CRC and TKIP MIC.
510*490c53e9SAdrian Chadd
511*490c53e9SAdrian Chadd### IV duplication / tracking
512*490c53e9SAdrian Chadd
513*490c53e9SAdrian Chaddnet80211 tracks the received IV / sequence number for each station indexed
514*490c53e9SAdrian Chaddby QoS TID.  Anything with an earlier IV is discarded as a stale packet or
515*490c53e9SAdrian Chaddpotential replay attack.  See the ni_txseqs[] and ni_rxseqs[] field in
516*490c53e9SAdrian Chadd(ieee80211_node).
517*490c53e9SAdrian Chadd
518*490c53e9SAdrian ChaddNote that the 802.11 layer sequence number field will apply /first/.  Traffic
519*490c53e9SAdrian Chaddwhich the 802.11 input layer thinks is old or retransmits will be discarded
520*490c53e9SAdrian Chaddbefore handed to the net80211 crypto routines.
521*490c53e9SAdrian Chadd
522*490c53e9SAdrian Chadd### Unicast vs Group Keys
523*490c53e9SAdrian Chadd
524*490c53e9SAdrian ChaddWEP has four global keys which are shared between all devices wishing to
525*490c53e9SAdrian Chaddcommunicate.  The keys are provided in the WEP header.
526*490c53e9SAdrian Chadd
527*490c53e9SAdrian ChaddHowever for later ciphers the four key indexes start taking on new meanings.
528*490c53e9SAdrian ChaddNotably key index 0 is the "unicast key" which handles traffic for a given
529*490c53e9SAdrian Chaddstation and is unique for that station, and keys 2 and 3 are used for
530*490c53e9SAdrian Chaddgroup keys - shared keys for broadcast traffic that all stations need to be
531*490c53e9SAdrian Chaddable to decrypt.
532*490c53e9SAdrian Chadd
533*490c53e9SAdrian Chadd(key 1 is also used for unicast station traffic for seamless station key
534*490c53e9SAdrian Chaddupdating, but net80211 currently doesn't support this extension/feature.)
535*490c53e9SAdrian Chadd
536*490c53e9SAdrian ChaddThere's also upcoming work for encrypted management traffic and encrypted
537*490c53e9SAdrian Chaddbeacons which reuse the key indexes for their traffic, but then don't treat
538*490c53e9SAdrian Chaddthem as "global keys" - they start being treated as "global keys but only
539*490c53e9SAdrian Chaddfor this traffic type."
540*490c53e9SAdrian Chadd
541*490c53e9SAdrian ChaddIt's important to understand the difference between global keys (WEP) versus
542*490c53e9SAdrian Chaddgroup and unicast keys (everything else) when looking through the net80211
543*490c53e9SAdrian Chadddata and encryption handling paths.
544*490c53e9SAdrian Chadd
545*490c53e9SAdrian Chadd## 802.11 Operating Modes
546*490c53e9SAdrian Chadd
547*490c53e9SAdrian Chadd(TBD)
548*490c53e9SAdrian Chadd
549*490c53e9SAdrian Chadd### Station
550*490c53e9SAdrian Chadd
551*490c53e9SAdrian Chadd(TBD)
552*490c53e9SAdrian Chadd
553*490c53e9SAdrian Chadd### Access Point
554*490c53e9SAdrian Chadd
555*490c53e9SAdrian Chadd(TBD)
556*490c53e9SAdrian Chadd
557*490c53e9SAdrian Chadd### IBSS / Ad-Hoc
558*490c53e9SAdrian Chadd
559*490c53e9SAdrian Chadd(TBD)
560*490c53e9SAdrian Chadd
561*490c53e9SAdrian Chadd### Mesh / 802.11s
562*490c53e9SAdrian Chadd
563*490c53e9SAdrian Chadd(TBD)
564