802.11 Channel Access Methods: Explained
For most people, WiFi just happens. Networking professionals, however, usually become more interested in the "how." It may be from troubleshooting, or a simple sense of curiosity. With WiFi, a great place to start is with channel access and contention. Besides the simple on/off perception of WiFi, the most common complaint is undoubtedly "The WiFi is slow".
Let's take a look at how the devices interact with each other and spread a little bit of light on the subject. WiFi, and all multiple-access protocols have to have some way of allocating resources in terms of time. The eyes and ears of your devices can't be everywhere at once, which is exacerbated by WiFi being half-duplex, meaning that one device can only send or receive at one time instead of both similar to ethernet. A channel access method is simply an agreed upon method of figuring or assigning who can speak and listen at any one time. For WiFi, this is called CSMA/CA.
CSMA/CA – Carrier Sense Multiple Access / Collision Avoidance
CSMA/CA is best understood by first contrasting it with a popular and similar protocol most people are more familiar with, CSMA/CD. 802.3, more commonly known as ethernet, uses CSMA/CD, or Carrier Sense Multiple Access / Collision Detection. What this means is that it senses or listens on the Carrier first, to sense if the medium is busy. If anyone is speaking at the moment. The Carrier is the physical medium you're transmitting on, think "carrier wave".
Multiple access means that multiple devices can use the same carrier, as opposed to a single device. The reason for contending. Collision detection means that it listens to make sure while it's transmitting, that no one else is. Here's the break from ethernet, WiFi, as mentioned before, is Half-Duplex. That means we can't listen and transmit at the same time, therefore we can't use collision detection. So then, how do we make sure everyone gets a chance to talk, and listen? WiFi instead must avoid collisions instead. CSMA/CA uses this model.
Contention and Transmit Opportunities
A device trying to get a chance to transmit, or a TXOP, must go through the process, called contending for the medium. In nearly every contention method for random, as opposed to scheduled, access, the station (STA) is always listening as a base state. This means that at any time, the first step of the contention process is always engaged, aka listening.
The device is listening for any transmission. If it doesn't hear a transmission, it waits a pseudo-random amount of time, then it progresses to the next stage of transmitting the message. If it does hear another transmission it must back off as well. This is accomplished by the addition of two numbers — the back-off timer (depends on QoS settings) as well as the duration of the transmission that it heard. RThis number is submitted in every frame that a STA or AP sends, and includes the total time between the first bit and the last in the transmission or transmission sequence. After this time is complete it can then again try to transmit.
Carrier Sense: Physical Carrier Sense
The carrier sense or listening part of the equation comes in two flavors. 802.11 has two unique mechanisms to detect, and avoid, possible collisions. These are referred to as Physical Carrier Sense and Virtual Carrier sense. Together, they carry out a clear channel assessment (CCA). Physical Carrier sense is "what it says on the tin" and is the act of looking for a signal on the physical network. Every station is constantly performing this act, listening for the energy of any transmissions on the channel it is using. There are two ways that it does this, Energy Detect (ED) and Signal Detect (SD).
SD is used to look for any 802.11 specific transmissions. Because the radio is always listening, if it receives and decodes a transmission that is more than 4dB SNR, it looks for something in the PHY header of the transmission called the preamble. This number, 4dB over the noise floor, or a total of 4dB SNR is sometimes referred to as the preamble threshold as well. The preamble is used in 802.11 to notify stations that a transmission is incoming and helps synchronize the receiver with the following transmission so it knows what to expect. This is present in every 802.11 frame sent, from the shortest (ACK Frames) to the longest frames.
The second method for 802.11 is ED. ED picks up where the SD leaves off. It's important to remember that 802.11 is a protocol that operates in an unlicensed band, meaning that while there is regulation, the frequencies in the band are not restricted to the 802.11 protocol and must make accommodation for avoiding interfering and interference from other protocols. Energy detect differs from SD in that it's looking for any energy source and not only 802.11. The threshold is much higher for this than it is for SD as well, generally being applied at 20dB over the ED threshold. This means that if SD's threshold was a received sensitivity signal indicator (RSSI) of -86, the ED threshold is -66. Remember, both of these are related to SNR and therefore to the noise floor. Carrying out both of these tasks takes about four microseconds in total, and must happen before every transmission.
Carrier Sense: Virtual Carrier Sense
Virtual carrier sense is a way of making sure that the STA knows how long to have to wait before they try to contend for the next TXOP. It's somewhat an extension of the physical carrier sense's signal detect. The virtual carrier sense reads a field in the MAC Header called the Duration/ID field. The Duration/ID field contains information about the incoming transmission, and relies on the frame being successfully decoded. If it hasn't been decoded, the field can't be read and is for all intents and purposes, non-802.11.
This specifically is a problem if for some reason the signal is varied. Think of someone opening a door between you just after the preamble, or a power issue in the radio — as it doesn't matter if the signal is perfect after the preamble. The number in the preamble can vary widely (0-32767 values are allowed) but describes the time in microseconds that is required to transmit the entire frame exchange to follow. This tells all radios in range that for that amount of time, they need to stay quiet and listen. Contention will not begin for any STA that hears the transmission until the timer has elapsed.
Notably, the client sending calculates this number, and it shows the remaining time it will take to transmit, not including the frame that holds that value. An ACK frame that follows, for example will have a value of 0, as there are no more transmissions to be sent in that exchange. This number helps non-conversing stations set something called a NAV timer, which tells them how long to stay silent. The duration field is not an explicit instruction, as it is addressed to someone else. This, plus the previously-discussed back-off timer gives a sufficient amount of time to avoid most collisions.
Basic ACK Frames
The last piece of the puzzle is the ACK or acknowledgement frame. Because 802.11 cannot detect collisions, it must instead assume them. Every station after sending nearly any transmission must wait for an ACK frame. The ACK frame is an affirmative way of the recipient to say, "I got the message". If the sending station does not receive an ACK, it assumes something went wrong (collision, interference, etc) and sends the entire frame again, which is called a Retry.
Most slow WiFi you'll see day to day is a result of a large rate of retries, or duplicate transmissions. Notably, when a retry is made, the duration value is the same as the original along with every other aspect of the data except a subfield is incremented to allow the receiving station to know it's a retry. All NAV fields are then reset to this new value. This keeps the medium reserved for the transmitting station, but that conversely means no one else can use the medium. The usual reasons for a retry are poor signal, a collision, interference and an issue at the receiver.
Contention and medium access is a difficult topic in regard to 802.11. To understand it, you'll need far more details than a short blog post can contain. If you're curious to learn more, look into the CWNA and CWAP certification exams from Certified Wireless Network Professionals (CNWP). They cover wireless networking and related topics extensively.