This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

802.11 MAC Frame Generation

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


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

The general MAC frame format consists of a header, frame body, and frame check sequence (FCS). Header holds the information about the frame. Frame body carries the data that needs to be transmitted. The transmitter calculates the FCS over the header and frame body. The receiver uses 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 negotiated between the devices to match capabilities of both the devices.

Data Frames:

  • Frames that are used to transmit the higher layers data (MAC payload).

  • The payload given to the MAC layer is termed as a 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 aggregation of MSDUs (A-MSDU) and MPDUs (A-MPDU) as specified in Section and Section 9.7 of [ 1 ].

  • 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 instance, control frames like RTS and CTS help in reserving the channel to avoid collisions while Ack frame helps 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 wlanMACFrame function to generate MAC frames. This function consumes a MAC frame configuration object wlanMACFrameConfig. 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 WLAN MAC frame generator supports the generation of following frames.

  • Management Frames: Beacon

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

  • Control Frames: RTS, CTS, Ack

Control Frame Generation

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

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

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

Configure the frame header fields.

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

Generate RTS frame using the configuration.

rtsFrame = wlanMACFrame(rtsCfg);

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');
  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

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 (MAC payload). A 20 byte payload containing a repeating sequence of hexadecimal value '11' is used in this example.

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

Generate QoS Data frame using payload and configuration.

qosDataFrame = wlanMACFrame(payload, qosDataCfg);

The output MAC frame is an MPDU with single MSDU. Refer 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');
  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]

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

% Create a management frame body configuration object
frameBodyCfg = wlanMACManagementConfig;
  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: {255x2 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;
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 beacon frame
beaconFrame = wlanMACFrame(beaconCfg);

Exporting to a PCAP File

The generated frames are exported to a PCAP file, which can be analyzed and visualized with a third party packet analyzer such as Wireshark. The helper function helperWLANExportToPCAP generates a PCAP file containing WLAN MAC frames.

% Export the generated MAC frames to a PCAP file
helperWLANExportToPCAP({rtsFrame, qosDataFrame, beaconFrame}, 'macFrames.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 WLAN Toolbox. The captured analysis of the frames in Wireshark is shown below.

  • 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. Alternatively, the generated MAC frames can be used to transmit over air as demonstrated in the examples 802.11 OFDM Beacon Frame Generation and 802.11ac Waveform Generation with MAC Frames.


This example uses the following helper function:

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. Wireshark software: