Main Content

Generate and Parse WLAN MAC Frames

This example shows how to configure and generate WLAN MAC frames, then recover the payload of MSDUs by parsing the MAC frame.

Introduction

The IEEE® 802.11™ family of standards supports four types of MAC frame: control, data, management, and extension. Within each of these types, the standard defines a range of subtypes, each of which serves a specific purpose in an 802.11™ network.

This example demonstrates how to configure, generate, and parse MPDUs and A-MPDUs by using WLAN Toolbox™ configuration objects and functions.

Generate and Decode MPDU

Create a MAC frame configuration object for a Data frame, specifying a high-efficiency single-user (HE SU) physical layer (PHY) configuration.

cfgMPDU = wlanMACFrameConfig('FrameType','Data','FrameFormat','HE-SU');

Specify an MSDU as a numeric vector of octets in bit format. You can also specify MSDUs as a character vector or string of octets in hexadecimal format.

msdu = randi([0 255],32,1);

Generate the MPDU by calling the wlanMACFrame function, specifying bits as the output format.

[mpdu,mpduLength] = wlanMACFrame(msdu,cfgMPDU,'OutputFormat','bits');

Recover the MSDU by calling the wlanMPDUDecode function. The function also returns the MAC frame configuration object and the status of the decoding. Check that the decoding operation returns the correct frame format and display the status.

[rxCfgMPDU,payload,status] = wlanMPDUDecode(mpdu,wlanHESUConfig);
disp(isequal(cfgMPDU.FrameFormat,rxCfgMPDU.FrameFormat))
   1
disp(status)
    Success

Generate and Parse A-MPDU

Create a configuration object for a QoS Data MAC frame, specifying an HE SU PHY configuration. Enable MPDU aggregation and disable MSDU aggregation.

cfgAMPDU = wlanMACFrameConfig('FrameType','QoS Data','FrameFormat','HE-SU',... 
    'MPDUAggregation',true,'MSDUAggregation',false);

Specify a cell array of MSDUs, specifying each MSDU as a numeric vector of octets in bit format. You can also specify MSDUs as a character vector or string of octets in hexadecimal format.

msduList = repmat({randi([0 255],32,1)},1,4);

Generate the MPDU for a HE SU PHY configuration by calling the wlanMACFrame function.

cfgPHY = wlanHESUConfig('MCS',5);
[ampdu,ampduLength] = wlanMACFrame(msduList,cfgAMPDU,cfgPHY,'OutputFormat','bits');

Deaggregate the A-MPDU to return the MPDU list by calling the wlanAMPDUDeaggregate function. The function also returns the result of the delimiter cyclic redundancy check (CRC) and the status of A-MPDU deaggregation.

[mpduList,delimiterCRCFailure,status] = wlanAMPDUDeaggregate(ampdu,cfgPHY);

Display the number of delimiter CRC failures and the status of deaggregation.

disp(nnz(delimiterCRCFailure))
     0
disp(status)
    Success

Obtain the MSDUs by decoding the deaggregated MPDUs with the wlanMPDUDecode function and display the status of the decoding process.

if strcmp(status,'Success')
    for i = 1:numel(mpduList)
        if ~delimiterCRCFailure(i)
            [cfg,msdu,decodeStatus] = wlanMPDUDecode(mpduList{i},cfgPHY,'DataFormat','octets');
            disp(['MPDU ' num2str(i) ' decoding status: ' char(decodeStatus)])
        end
    end
end
MPDU 1 decoding status: Success
MPDU 2 decoding status: Success
MPDU 3 decoding status: Success
MPDU 4 decoding status: Success

Related Topics