Showing posts with label nav. Show all posts
Showing posts with label nav. Show all posts

Monday, May 21, 2012

Are Apple iPhones Misbehaving on Wi-Fi

The latest generation of mobile devices, including the Apple iPhone 4S, may be causing performance degradation on your Wi-Fi network, which could be reported as a Denial of Service (DoS) attack by WIPS (wireless intrusion prevention systems).

One of my blog readers contacted me about a disturbing finding he had and asked for my opinion (thanks Thanh). The finding in question was that the Apple iPhone, iPad, and other mobile devices based on the latest Broadcom chipsets are setting really long Duration values in the range of 10-14ms within Wi-Fi control frames (e.g. RTS/CTS-to-self). This essentially reserves the medium for the device to transmit without a collision. The problem is that this is an excessively long period of time for an 802.11n capable device, and through my packet analysis I have found that no large frame transmission is subsequently occurring. This indicates that a performance problem may exist with the devices, and may be reported as an NAV DoS attack on the network by WIPS systems.

I've also heard anecdotal reports of this being observed on HTC Google Nexus One, Apple iPad 2, iPhone 4, some RIM Blackberrys, and even on a Broadcom evaluation board. So, there is a distinct possibility that this issue lies in the Broadcom chipset used in these devices and is not isolated to Apple devices. However, I have only tested this on my personal iPhone 4S and cannot directly verify those observations. So this post only details what I have actual been able to test and observe directly.

I had a hard time believing this could be true, so I investigated myself. Sure enough, I found the behavior when I tested.

Apple iPhone 4S Large Duration Value

What you see in the figure above is that the iPhone transmits CTS-to-Self frames at regular intervals, around once every second, with an excessively large Duration value. This causes all other Wi-Fi clients to set the NAV (virtual carrier sense) to the specified Duration value and defer transmission. Essentially, my iPhone was causing a blockage of all traffic on my wireless network for 11ms at regular intervals. Definitely not good for performance.

Possible valid explanations for this behavior could be:

1) Frame aggregation with 802.11n. I did see the iPhone using frame aggregation in other instances and using an appropriate Duration value around 4ms in those cases. But I did not see frame aggregation being used after the 11ms Duration control frames.

2) The use of a Transmit Opportunity (TXOP) on a QoS enabled WLAN in order to transmit a burst of packets within a specific QoS traffic class. I double-checked the TXOP values advertised by my access point and they are using the 802.11 default values of 0ms (single frame only) for best effort and background queues, 3.008ms for the video queue, and 1.504ms for the voice queue, which are much lower than the 11ms observed value.

3) A really large frame transmitted at a really low data rate. This is possible if the iPhone needed to transmit a 1,384 byte or larger frame at 1 Mbps to get such a Duration value. But I have all 802.11b rates disabled on my AP and verified in the packet trace that the iPhone was using 24 - 65 Mbps almost all the time, with only a few frames at my lowest available data rate of 6 Mbps.

After analyzing my packet trace I can find no evidence of my iPhone transmitting any data frames immediately after the control frame containing the high Duration value. This essentially rules out all three possible explanations.

Other possible explanations would be a poor client roaming algorithm that wants to halt traffic while it goes off-channel to scan for other APs to which it could roam, or a poorly designed battery saving technique for mobile devices. However, I captured on all three non-overlapping 2.4GHz channels and found no evidence of my iPhone probing on other channels during that 11ms time period. And using this as a battery saving technique doesn't even make a whole lot of sense because clients can already notify the AP of it's power save mode and the AP will buffer traffic until it wakes up, or at worst case send broadcast traffic at the configured DTIM interval, which is usually 102ms which allows for a much longer  sleep period anyways. Regardless, the iPhone indicated that it was staying awake (in active mode) in the control frames, so it appears to have not been putting the radio to sleep.

Frankly, I have no answer to explain this behavior. I don't exactly know what is going on.

The effect on a home network is likely to be small, since 11ms out of every 1 second is only about 1% of available airtime. However, in a corporate environment where mobile devices are being introduced into the environment at a staggering rate, the compound effect could be a serious reduction in Wi-Fi network performance and capacity! Think of having 30 students in a single classroom all connected with their mobile devices, 200 in a university lecture hall, or 500 at a trade show or conference. This is increasingly likely as smartphone and mobile device penetration is over 50% in the U.S. and other countries already, and consumers are typically carrying 2-3 Wi-Fi enabled devices with them at all time. The worst-case result in these environments would be so much reserved airtime that almost no network capacity would be left for actual user traffic. Just what we need trying to support tons of mobile devices on enterprise networks, huh.

If I uncover more details, I will update this post accordingly.

Thanks,
Andrew vonNagy

Monday, March 7, 2011

Understanding Wi-Fi Carrier Sense

The Importance of Carrier Sense
Carrier Sense (CS) is one of the most integral parts of modern Wi-Fi networks. Fundamentally, Wi-Fi is a multiple access link, which means that it is shared and requires vastly different protocol design and architecture than a point to point circuit (as any Masters graduate student studying computer science could tell you). In addition, random access to the medium is distributed across all stations on the network. Wi-Fi does not pass tokens, reserve the medium with bit-mappings, or use any other control mechanisms dictating which stations have access to transmit.

This distributed nature makes carrier sense (and subsequent medium contention) core components of network operation and efficiency. The practical implications are seen in Wi-Fi engineer's daily work. We perform site surveys, develop non-overlapping 1, 6, 11 channel plans, optimize channel re-use, and perform capacity planning all in the name of performance optimization for a network that runs over an unguided medium with random access distributed between stations. Understanding these principles of design and the protocol operation behind them are important for engineers to adequately and successfully build wireless networks.

The precursors to the IEEE 802.11 and Wi-Fi protocol design were developed in the pure ALOHAnet protocol, slotted ALOHA, and finally Carrier Sense Multiple Access (CSMA) developed for the 802.3 Ethernet specification.

As I've previously written, 802.11 Wi-Fi is based on CSMA/CA, whereas 802.3 Ethernet is based on CSMA/CD. What's the deal, one little letter difference? Well that one little letter represents a significant underlying difference between the two network protocols. What they both have in common is the need to perform Carrier Sense (CS) for medium idle/busy detection on a Multiple Access (MA) network segment (hence the CSMA portion). What differs are how stations determine if the medium is idle (Collision Detection versus Collision Avoidance), and how they are granted access to the medium once it is found to be idle (1-persistent for Ethernet versus p-persistent for Wi-Fi, where "p" indicates the probability of transmission when the medium is found to be idle). This is largely due to the inherent differences of electromagnetic signalling over guided versus unguided media (copper or fiber cabling versus the air). For an overview of collision avoidance and medium contention, see my previous series on Wireless QoS.

Let's review how carrier sense is performed.

Wi-Fi Carrier Sense Overview
Wi-Fi carrier sense is composed of two separate and distinct functions, Clear Channel Assessment (CCA) and the Network Allocation Vector (NAV). From a high level perspective, CCA is physical carrier sense which listens to received energy on the radio interface. NAV is virtual carrier sense which is used by stations to reserve the medium for mandatory frames which must follow the current frame.

It is important to note that CCA is not the same as the NAV. CCA indicates a busy medium for the current frame, whereas NAV reserves the medium as busy for future frames that are required to be transmitted immediately following the current frame.

Clear Channel Assessment
CCA is defined in the IEEE 802.11-2007 standards as part of the Physical Medium Dependant (PMD) and Physical Layer Convergence Protocol (PLCP) layer. For reference, the IEEE layer specifications include PMD, PLCP, MAC/LLC as shown below:

Clear Channel Assessment is composed of two related functions, carrier sense (CS) and energy detection (ED).

Carrier sense refers the ability of the receiver to detect and decode an incoming Wi-Fi signal preamble. In addition, CCA must be reported as BUSY when another Wi-Fi signal preamble is detected, and must be held as BUSY for the length of the received frame as indicated in the frame's PLCP Length field. Typically, any incoming Wi-Fi frame whose PLCP header can be decoded will cause CCA to report the medium as busy for the time required for the frame transmission to complete.

The PLCP header Length field indicates either the number of microseconds required for transmission of the full frame MPDU payload (DSSS), or the number of octects carried in the frame MPDU payload (OFDM) which is then used in combination with the Rate field (which identifies the modulation used for the payload) to determine the time required for MPDU transmission. Either way, the Length or Rate + Length fields give the receiver the information required to de-modulate the frame and determine how long the medium will be busy.

For reference, here is the PLCP frame header format for the DSSS PHY:

Note - for those curious, the PLCP header is always encoded at a fixed data rate so that the receiving stations can decode the information. DSSS PLCP is transmitted at 1 Mbps, DSSS Short Preamble at 2 Mbps, and OFDM at 6 Mbps. Only the frame MPDU payload is encoded at a variable data rate which is specified in the SIGNAL/RATE field.

Energy detection (ED) refers to the ability of the receiver to detect the non-Wi-Fi energy level present on the current channel (frequency range) based on the noise floor, ambient energy, interference sources, and unidentifiable Wi-Fi transmissions that may have been corrupted but can no longer be decoded. Unlike carrier sense which can determine the exact length of time the medium will be busy with the current frame, energy detection must sample the medium every slot time to determine if the energy still exists. In addition, energy detection requires a pre-defined threshold which determines if the reported energy level is adequate to report the medium as busy or idle. This is typically referred to as the ED threshold level or CCA sensitivity level. The ED threshold is usually much lower for valid Wi-Fi signals that can be decoded using carrier sense than it is for non-Wi-Fi signals. For example, the noise ED threshold must be 20 dB greater than the corresponding Wi-Fi signal ED threshold for most PHYs.

For more information on the CCA sensitivity level of each PHY, see the "Further Reading" notes at the end of this post.

As an interesting side note, when evaluating the RF environment with a spectrum analyzer, the ED threshold level value may be implemented differently than Wi-Fi stations. This may cause the spectrum analyzer's duty cycle metric to be out of alignment with how a Wi-Fi station would interpret the same environment. For example the Cisco Spectrum Expert SaGE v2 chipset reports duty cycle as any energy above the noise floor which is typically -92 to -95 dBm, whereas a client adhering to DSSS specifications transmitting at 50mW would only mark the medium as busy based on ED of -76 dBm or greater (per IEEE 802.11-2007 section 15.4.8.4). This difference is worth noting, but in my experience is not cause for significant concern when evaluating an environment for noise or interference.

Network Allocation Vector
In addition to CCA determining the medium idle/busy state for the current frame and noise, the NAV allows stations to indicate the amount of time required for transmission of required frames immediately following the current frame. This is important to reserve the medium as busy for these mandatory frames.

The importance of NAV virtual carrier sense is to ensure medium reservation for frames critical to operation of the 802.11 protocol. Typically these are control frames, but not always. They include 802.11 acknowledgements, subsequent data and acknowledgement frames as part of a fragment burst, and data and acknowledgement frames following an RTS/CTS exchange.

The NAV is carried in the 802.11 MAC header Duration field which is part of the MPDU payload, and is encoded at a variable data rate as discussed previously. Therefore, not all stations within the area may be able to decode the MPDU due to insufficient SNR. However, all stations within the area should still be able to decode the PLCP header used for CCA. Since the critical frames that the NAV protects use shorter inter-frame spacing values (SIFS for example), those frames should still gain access to the medium before any other station attempts to transmit and stations will detect a busy medium through CCA carrier sense. However, the added protection through NAV reservation is lost.

Stations that are able to decode the 802.11 header extract the Duration field value and use it mark the medium as busy for the amount of time specified (in microseconds). Therefore, the transmitter should follow the strict rules defined in the 802.11 specification for calculation of the NAV value to be sent within frames. Stations (including APs) not adhering to the specification could reserve too much time in order to hog the medium, as has been accused of at least one infrastructure vendor in the past. (I won't name names, but they know who they are :)

Note - The NAV timer also accounts for time required for appropriate inter-frame spacing, such as SIFS intervals between data and acknowledgement for example.

Summary and Recap
Every Wi-Fi station must first determine the state of the medium as idle or busy through the process of carrier sense, prior to being allowed to perform pro-active collision avoidance and ultimately transmit a frame. Carrier sense is composed of clear channel assessment and the network allocation vector, which together allow for adequate sensing of the physical environment as well as reserve the medium for frames critical to the operation of the protocol.

If you're like me, you find the physical layer properties of Wi-Fi networks fascinating. These fundamental concepts of carrier sense, CCA, NAV, modulation, encoding and the underlying physical properties of radio frequency propagation form the building blocks for most of the advanced mobile technologies that form our modern civilization. It's exciting to understand these concepts and see real-world examples in front of us everyday that are shaping our culture and our lives.

My intent is to convey my joy of these concepts to you, my readers, and inspire the same passion for Wi-Fi as I have. We are a new generation of RF engineers, not all that different from generations past who invented the telegraph, radio communications, and amateur ham radio operators.

Cheers,
Andrew


A Note on Nomenclature
PHY stands for Physical Layer Specifications.
DSSS stands for Direct Sequence Spread Spectrum, and is used in the original 802.11 PHY at 1 and 2 Mbps.
HR-DSSS stands for High Rate DSSS, and is used in the 802.11b PHY at 5.5 and 11 Mbps.
ERP stands for Extended Rate Physical, and is used with OFDM encoding with 802.11g PHY at 6 - 54 Mbps.
OFDM stands for Orthogonal Frequency Division Multiplexing, and is used in the 802.11a PHY at 6 - 54 Mbps.
HT stands for High Throughput, and is used with OFDM encoding with 802.11n PHY at 6.5 - 600 Mbps.

Further Reading
The following references are worthwhile reading for those looking for more information:

CSMA Persistence - "Computer Networks: Fifth Edition" by Andrew S. Tanenbaum and David J. Wetherall

The following sections in the IEEE 802.11-2007 standard:

PLCP Header Format in DSSS 15.2.2
PLCP Header Format in HR-DSSS 18.2.2
PLCP Header Format in ERP 19.3.2 (Can actually use any of the other 3 formats, depending on the situation)
PLCP Header Format in OFDM 17.3.2
PLCP Header Format in HT 20.3.2 (Found in the 802.11n amendment, not 802.11-2007)

CCA Sensitivity in DSSS 15.4.8.4
CCA Sensitivity in HR-DSSS 18.4.8.4
CCA Sensitivity in ERP 19.3.5
CCA Sensitivity in OFDM 17.3.10.5
CCA Sensitivity in HT 20.3.22.5 (Found in the 802.11n amendment, not 802.11-2007)

NAV 9.2.5.4 through 9.2.5.6, and 9.2.11