802.11 MAC Frame Decoding
This example shows how to decode IEEE® 802.11™ MAC frames.
Background
The general MAC frame format consists of a header, frame-body, and frame check sequence (FCS). The header holds information about the frame. The frame-body carries data that needs to be transmitted. The transmitter calculates the FCS over the header and frame-body. The receiver uses the FCS to confirm that the header and frame-body are properly received. The following diagram shows the structure of a general MAC frame.
For more information, see the WLAN MAC Frame Structure topic.
Introduction
This example shows how WLAN MAC frames specified in Section 9.3 of [ 1 ], [ 2 ], and [ 3 ] can be decoded. It also shows how aggregated MAC frames specified in Section 9.7 of [ 1 ], [ 2 ], or [ 3 ] can be deaggregated.
WLAN Toolbox™ supports MPDU decoding for the following MAC frames:
Management Frames: Beacon
Data Frames: Data, Null, QoS Data, QoS Null
Control Frames: RTS, CTS, Ack, Block Ack, CF-End, Trigger
In addition to MPDU decoding, WLAN Toolbox also supports deaggregation of an A-MPDU.
MPDU Decoding
An MPDU can be a data, control or management frame type. wlanMPDUDecode
can be used to decode an MPDU. This function processes the given MPDU and a physical layer configuration object to output the decoded MAC parameters.
To illustrate MPDU decoding, a valid MPDU is created using wlanMACFrame
. The created MPDU is passed to the wlanMPDUDecode
function and the outputs are observed.
Create an MPDU
A QoS Data frame is created for this example using wlanMACFrame
. The following inputs are required to form a Non-HT format QoS Data frame containing a 40-octet payload:
txFrameCfg
: A MAC frame configuration object of typewlanMACFrameConfig
.txMSDU
: A 40-octet payload (MSDU) to be included in the QoS Data frame.
% Create a MAC frame configuration object txFrameCfg = wlanMACFrameConfig(FrameType='QoS Data', ... FrameFormat='Non-HT'); % 40-octet payload for each 'QoS Data' frame txMSDU = randi([0, 255], 40, 1); % Physical layer configuration phyCfg = wlanNonHTConfig; % Create the MPDU mpdu = wlanMACFrame(txMSDU, txFrameCfg);
Decode the MPDU
wlanMPDUDecode
consumes an MPDU, a PHY configuration object of type wlanNonHTConfig
, wlanHTConfig
, wlanVHTConfig
, or wlanHESUConfig
and optionally a (Name, Value) pair for DataFormat
specifying the input format of the MPDU. Since the MPDU generated using wlanMACFrame
is in terms of octets, DataFormat
is set to octets
. wlanMPDUDecode
decodes the MPDU and outputs the following information:
rxFrameCfg
: A MAC frame configuration object of typewlanMACFrameConfig
, containing the decoded MAC parameters.rxMSDU
: A cell array, where each element is an n-by-2 character array representing the decoded MSDU. Multiple MSDUs are returned when the MPDU contains an aggregated MSDU (A-MSDU) as the payload.status
: An enumeration of type status, which indicates whether the MPDU decoding was successful.
% Decode the MPDU. [rxFrameCfg, rxMSDU, status] = wlanMPDUDecode(mpdu, phyCfg, ... DataFormat='octets'); % Check if the MPDU is decoded successfully disp(['Status of the MPDU decoding: ' char(status)]) % Observe the outputs, if the MPDU is decoded successfully if strcmp(status, 'Success') disp(['Type of the decoded MPDU: ' rxFrameCfg.FrameType]) disp(['Number of MSDUs in the MPDU: ' num2str(numel(rxMSDU))]) for i = 1:numel(rxMSDU) disp(['Size of MSDU-' num2str(i) ': ' num2str(size(rxMSDU{i}, 1)) ' octets']) end end
Status of the MPDU decoding: Success Type of the decoded MPDU: QoS Data Number of MSDUs in the MPDU: 1 Size of MSDU-1: 40 octets
A-MPDU Deaggregation
An A-MPDU is an aggregation of multiple MPDUs. The type of MPDUs in an A-MPDU are restricted as specified in Section 9.7.3 of [ 1 ].
wlanAMPDUDeaggregate
can be used to deaggregate an A-MPDU. This function processes the given A-MPDU and the corresponding physical layer configuration object to output the deaggregated list of MPDUs. wlanAMPDUDeaggregate
is capable of decoding HT (High Throughput), VHT (Very High Throughput), HE-SU (High Efficiency Single User) and HE-EXT-SU (High Efficiency Extended Range Single User) format A-MPDUs as specified in [ 1 ] and [ 2 ].
To illustrate the A-MPDU deaggregation, a valid A-MPDU containing five MPDUs is created using wlanMACFrame
. The created A-MPDU is passed to the wlanAMPDUDeaggregate
function and the outputs are observed.
Create an A-MPDU
The following inputs are required to form an HE-SU format A-MPDU containing five MPDUs (QoS Data frames), each MPDU containing a 40-octet payload:
txFrameCfg
: A MAC frame configuration object of typewlanMACFrameConfig
.txMSDUList
: A five element cell array containing payload (MSDU) for five MPDUs. SinceMSDUAggregation
is set to false in thetxFrameCfg
, a separate MPDU is created for each MSDU.phyCfg
: A physical layer configuration object of typewlanHESUConfig
.
% Create a MAC frame configuration object txFrameCfg = wlanMACFrameConfig(FrameType='QoS Data', ... FrameFormat='HE-SU', ... MPDUAggregation=true, ... MSDUAggregation=false); % 40-octet payload for each 'QoS Data' frame txMSDUList = repmat({randi([0, 255], 40, 1)}, 1, 5); % Physical layer configuration phyCfg = wlanHESUConfig(MCS=3); % Create the A-MPDU containing 5 MPDUs ampdu = wlanMACFrame(txMSDUList, txFrameCfg, phyCfg);
Deaggregate the A-MPDU
wlanAMPDUDeaggregate
consumes an A-MPDU, a PHY configuration object of type wlanHTConfig
, wlanVHTConfig
, or wlanHESUConfig
and optionally a (Name, Value) pair for DataFormat
specifying the input format of the A-MPDU. It finds and validates the MPDU delimiters, extracts the MPDUs and outputs the following information that can be used for further processing the MPDUs:
mpduList
: A cell array containing the list of MPDUs extracted from the A-MPDU.delimCRCFails
: A logical row vector representing delimiter CRC validity for the corresponding index inmpduList
. A value of true represents that the MPDU present inmpduList
at the corresponding index may not be properly extracted.ampduStatus
: An enumeration of type status, which indicates whether the A-MPDU deaggregation was successful.
% Deaggregate the A-MPDU [mpduList, delimCRCFails, ampduStatus] = wlanAMPDUDeaggregate(ampdu, phyCfg, ... DataFormat='octets'); % Observe the outputs disp(['Status of A-MPDU deaggregation: ' char(ampduStatus)]) disp(['Number of MPDUs extracted from the A-MPDU: ' num2str(numel(mpduList))]) disp(['Number of MPDUs with delimiter CRC fails: ' num2str(nnz(delimCRCFails))])
Status of A-MPDU deaggregation: Success Number of MPDUs extracted from the A-MPDU: 5 Number of MPDUs with delimiter CRC fails: 0
Decode the list of MPDUs
The mpduList
contains the list of MPDUs extracted from the A-MPDU. Each of the MPDUs present in the list can be decoded separately. However, if the delimCRCFails
contains any true
values, the MPDU present in mpduList
at the corresponding index can be considered invalid as it may not be properly extracted because of the delimiter CRC failure.
% Decode the list of MPDUs if strcmp(ampduStatus, 'Success') % Number of MPDUs in the list numMPDUs = numel(mpduList); for i = 1:numMPDUs % Decode the MPDU only if the corresponding delimiter CRC is valid if ~delimCRCFails(i) [rxFrameCfg, rxMSDU, mpduStatus] = wlanMPDUDecode(mpduList{i}, phyCfg, ... DataFormat='octets'); disp(['MPDU-' num2str(i) ' decoding status: ' char(mpduStatus)]) disp(['MPDU-' num2str(i) ' type: ' rxFrameCfg.FrameType]) disp(['MPDU-' num2str(i) ' payload size: ' num2str(size(rxMSDU{1}, 1)) ' octets']) disp(' ') end end end
MPDU-1 decoding status: Success MPDU-1 type: QoS Data MPDU-1 payload size: 40 octets MPDU-2 decoding status: Success MPDU-2 type: QoS Data MPDU-2 payload size: 40 octets MPDU-3 decoding status: Success MPDU-3 type: QoS Data MPDU-3 payload size: 40 octets MPDU-4 decoding status: Success MPDU-4 type: QoS Data MPDU-4 payload size: 40 octets MPDU-5 decoding status: Success MPDU-5 type: QoS Data MPDU-5 payload size: 40 octets
Conclusion and Further Exploration
This example demonstrated how to deaggregate and decode IEEE 802.11 MAC frames. You can also explore WLAN Beacon Receiver Using Software-Defined Radio and Recovery Procedure for an 802.11ac Packet examples for decoding the MAC frames retrieved from the captured waveforms.
Selected Bibliography
"IEEE Standard for Information Technology--Telecommunications and Information Exchange between Systems - Local and Metropolitan Area Networks--Specific Requirements Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications." IEEE. https://doi.org/10.1109/IEEESTD.2021.9363693.
"IEEE Standard for Information Technology--Telecommunications and Information Exchange between Systems Local and Metropolitan Area Networks--Specific Requirements Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications Amendment 1: Enhancements for High-Efficiency WLAN." IEEE. https://doi.org/10.1109/IEEESTD.2021.9442429.
"IEEE Draft Standard for Information Technology - Telecommunications and Information Exchange between Systems Local and Metropolitan Area Networks - Specific Requirements - Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications Amendment: Enhancements for Extremely High Throughput (EHT)." IEEE P802.11be/D3.0, January 2023, March 2023, 1-999. https://ieeexplore.ieee.org/servlet/opac?punumber=10058124.