Main Content

802.11 MAC Frame Generation

This example shows how to generate IEEE® 802.11™ MAC frames.

Introduction

This example shows how WLAN MAC frames specified in Section 9 of [ 1 ] and [ 2 ] can be generated and exported to a packet capture (PCAP) file for analysis with third party packet analysis tools. In this example Wireshark [ 3 ] is used to verify the content of MAC frames is as expected.

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.

The standard specifies four types of frames: Management, Data, Control, and Extension. There are multiple subtypes of each frame type. These are identified by the Type and Subtype fields of the frame control field in the MAC header.

Management Frames:

  • Frames that are used for connection establishment and maintenance.

  • These frames carry the information fields and elements that indicate the capabilities and configuration of the device operating in the 802.11 network. While establishing the connection, these information fields and elements are communicated between the devices to match capabilities of both devices.

  • The MAC layer adds header and FCS to the frame-body carrying the information to form a MAC protocol data unit (MPDU).

Data Frames:

  • Frames that are used to transmit the higher-layer data.

  • The payload given to the MAC layer is termed MAC service data unit (MSDU). The MAC layer adds header and FCS to the MSDU to form a MAC protocol data unit (MPDU).

  • To improve the throughput, WLAN supports aggregated MSDUs (A-MSDUs) and aggregated MPDUs (A-MPDUs) as specified in Sections 9.3.2.2, 9.7 of [ 1 ] and [ 2 ].

  • If MSDU aggregation is enabled, multiple MSDUs are aggregated to form an A-MSDU and then the MAC header and FCS are added to an A-MSDU to form an MPDU.

  • If MPDU aggregation is enabled, multiple MPDUs are aggregated to form an A-MPDU.

Control Frames:

  • Frames that are used to support the delivery of data, management, and extension frames.

  • Each control frame has a specific functionality. For example, control frames like request-to-send (RTS) and clear-to-send (CTS) help in reserving the channel to avoid collisions, while Ack frames help in recognizing successful transmission.

Extension Frames:

  • This frame type is an extension to the three frame types defined above.

  • DMG Beacon is the only frame currently specified under this frame type in [ 1 ].

You can use the wlanMACFrame function to generate MAC frames. This function accepts a MAC frame configuration object wlanMACFrameConfig as an input. This object configures the fields in the MAC header. Set the FrameType property to the desired Subtype description in Table 9-1 of [ 1 ] to set the appropriate Type and Subtype fields in the MAC header. The wlanMACFrame function supports the generation of following MPDUs.

  • Management Frames: Beacon

  • Data Frames: Data, Null, QoS Data, QoS Null

  • Control Frames: RTS, CTS, Ack, Block Ack

In addition to the above MPDUs, wlanMACFrame also supports generation of A-MPDUs containing MPDUs of type QoS Data.

Control Frame Generation

To generate an RTS frame, create a MAC frame configuration object with the FrameType set to 'RTS'.

rtsCfg = wlanMACFrameConfig('FrameType', 'RTS');
disp(rtsCfg);
  wlanMACFrameConfig with properties:

          FrameType: 'RTS'
    PowerManagement: 0
           MoreData: 0
           Duration: 0
           Address1: 'FFFFFFFFFFFF'
           Address2: '00123456789B'

   Read-only properties:
            Decoded: 0

Configure the frame header fields.

% Duration
rtsCfg.Duration = 500;
% Receiver address
rtsCfg.Address1 = 'FCF8B0102001';
% Transmitter address
rtsCfg.Address2 = 'FCF8B0102002';

Generate an RTS frame using the configuration.

% Generate octets for an RTS frame
rtsFrame = wlanMACFrame(rtsCfg);

By default, the output of wlanMACFrame is a sequence of hexadecimal octets. If you want to generate the MAC frame as a sequence of bits, set the OutputFormat parameter to bits.

% Generate bits for an RTS frame
rtsFrameBits = wlanMACFrame(rtsCfg, 'OutputFormat', 'bits');

Data Frame Generation

To generate a QoS Data frame, create a MAC frame configuration object with the FrameType set to 'QoS Data'.

qosDataCfg = wlanMACFrameConfig('FrameType', 'QoS Data');
disp(qosDataCfg);
  wlanMACFrameConfig with properties:

          FrameType: 'QoS Data'
        FrameFormat: 'Non-HT'
               ToDS: 0
             FromDS: 1
     Retransmission: 0
    PowerManagement: 0
           MoreData: 0
           Duration: 0
           Address1: 'FFFFFFFFFFFF'
           Address2: '00123456789B'
           Address3: '00123456789B'
     SequenceNumber: 0
                TID: 0
          AckPolicy: 'No Ack'
    MSDUAggregation: 0

   Read-only properties:
            Decoded: 0

Configure the frame header fields.

% From DS flag
qosDataCfg.FromDS = 1;
% To DS flag
qosDataCfg.ToDS = 0;
% Acknowledgment Policy
qosDataCfg.AckPolicy = 'Normal Ack';
% Receiver address
qosDataCfg.Address1 = 'FCF8B0102001';
% Transmitter address
qosDataCfg.Address2 = 'FCF8B0102002';

The QoS Data frame is used to transmit a payload from higher-layer. A 20-byte payload containing a repeating sequence of hexadecimal value '11' is used in this example.

payload = repmat('11', 1, 20);

Generate a QoS Data frame using payload and configuration.

% Generate octets for a QoS Data frame
qosDataFrame = wlanMACFrame(payload, qosDataCfg);

By default, the output of wlanMACFrame is a sequence of hexadecimal octets. If you want to generate the MAC frame as a sequence of bits, set the OutputFormat parameter to bits.

% Generate bits for a QoS Data frame
qosDataFrameBits = wlanMACFrame(payload, qosDataCfg, 'OutputFormat', 'bits');

The output MAC frame is an MPDU with a single MSDU. Refer to the example 802.11ac Waveform Generation with MAC Frames for A-MSDU and A-MPDU generation.

Management Frame Generation

To generate a Beacon frame, create a MAC frame configuration object with the FrameType set to 'Beacon'.

beaconCfg = wlanMACFrameConfig('FrameType', 'Beacon');
disp(beaconCfg);
  wlanMACFrameConfig with properties:

           FrameType: 'Beacon'
                ToDS: 0
              FromDS: 1
      Retransmission: 0
     PowerManagement: 0
            MoreData: 0
            Duration: 0
            Address1: 'FFFFFFFFFFFF'
            Address2: '00123456789B'
            Address3: '00123456789B'
      SequenceNumber: 0
    ManagementConfig: [1x1 wlanMACManagementConfig]

   Read-only properties:
             Decoded: 0

Beacon frame-body consists of information fields and information elements as explained in Section 9.3.3.3 of [ 1 ]. You can configure these information fields and elements using wlanMACManagementConfig.

% Create a management frame-body configuration object
frameBodyCfg = wlanMACManagementConfig;
disp(frameBodyCfg);
  wlanMACManagementConfig with properties:

                   FrameType: 'Beacon'
                   Timestamp: 0
              BeaconInterval: 100
               ESSCapability: 1
              IBSSCapability: 0
                     Privacy: 0
               ShortPreamble: 0
          SpectrumManagement: 0
                  QoSSupport: 1
           ShortSlotTimeUsed: 0
                 APSDSupport: 0
            RadioMeasurement: 0
      DelayedBlockAckSupport: 0
    ImmediateBlockAckSupport: 0
                        SSID: 'default SSID'
                  BasicRates: {'6 Mbps'  '12 Mbps'  '24 Mbps'}
             AdditionalRates: {}

   Read-only properties:
         InformationElements: {511x2 cell}

Configure the information fields and elements in the frame-body configuration. You can add information elements using addIE(elementID, information) method as shown below. Refer Section 9.4 in [ 1 ] for the list of information fields and information elements.

% Beacon Interval
frameBodyCfg.BeaconInterval = 100;
% Timestamp
frameBodyCfg.Timestamp = 123456;
% SSID
frameBodyCfg.SSID = 'TEST_BEACON';
% Add DS Parameter IE (element ID - 3) with channel number 11 (0x0b)
frameBodyCfg = frameBodyCfg.addIE(3, '0b');

Assign the updated frame-body configuration object to the ManagementConfig property in the MAC frame configuration.

% Update management frame-body configuration
beaconCfg.ManagementConfig = frameBodyCfg;

Generate the Beacon frame with the updated frame configuration.

% Generate octets for a Beacon frame
beaconFrame = wlanMACFrame(beaconCfg);

By default, the output of wlanMACFrame is a sequence of hexadecimal octets. If you want to generate the MAC frame as a sequence of bits, set the OutputFormat parameter to bits.

% Generate bits for a Beacon frame
beaconFrameBits = wlanMACFrame(beaconCfg, 'OutputFormat', 'bits');

Exporting to a PCAP File

This example uses pcapWriter object to export the generated MAC frames to a file with .pcap extension. To analyze and visualize this file, use a third part packet analyzer such as Wireshark. To export the generated MAC frames to a file with .pcapng extension, use pcapngWriter object.

Create an object of type pcapWriter and specify the packet capture file name. The constants wlanLinkType and timestamp specifies the link layer header type [ 4 ] and the capture time of a WLAN frame, respectively. In this example, the capture time is same for all the frames. Before writing packets to the file with .pcap or .pcapng extension, use writeGlobalHeader function to write a global header to the file.

timestamp = 124800; % timestamp (in microseconds)
wlanLinkType = 105; % link-layer header type
pcap = pcapWriter('FileName', 'macFrames');
writeGlobalHeader(pcap, wlanLinkType); % global header in pcap file

Use the write function to write all the MAC frames to a PCAP file

% MAC frames to be exported to a PCAP file
frames = {rtsFrame, qosDataFrame, beaconFrame};

% Write all the packets to the PCAP file
for idx = 1:numel(frames)
    write(pcap, frames{idx}, timestamp);
end

% Clear the object
clear pcap;

Visualization of the Generated MAC Frames

You can open the PCAP files containing the generated MAC frames in a packet analyzer. The frames decoded by the Wireshark match the standard compliant MAC frames generated using the WLAN Toolbox. This figure shows the analysis of the captured MAC frames in Wireshark.

  • RTS frame

  • QoS Data frame

  • Beacon frame

Conclusion and Further Exploration

This example demonstrated generation of MAC frames for the IEEE 802.11 standard. You can use a packet analyzer to view the generated MAC frames. To transmit the generated MAC frames over air, refer 802.11 OFDM Beacon Frame Generation and 802.11ac Waveform Generation with MAC Frames examples.

Selected Bibliography

  1. IEEE Std 802.11™-2016 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

  2. IEEE P802.11ax™/D4.1 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 6: Enhancements for High Efficiency WLAN

  3. Wireshark · Go Deep. https://www.wireshark.org/. Accessed 30 June 2020

  4. Group, The Tcpdump. Tcpdump/Libpcap Public Repository. https://www.tcpdump.org. Accessed 30 June 2020