Main Content


Generate WLAN MAC frame (MPDU or A-MPDU)



[frame,frameLength] = wlanMACFrame(cfgMAC) generates frame, a WLAN medium access control (MAC) frame for the specified MAC frame configuration object. The function generates a MAC protocol data unit (MPDU) or an aggregate MPDU (A-MPDU), depending on the property values of the cfgMAC input. The function also returns frameLength, the total length of the generated MAC frame.


[frame,frameLength] = wlanMACFrame(payload,cfgMAC) generates a WLAN MAC frame containing MAC service data units (MSDUs) payload. For the MAC frame to contain the MSDUs, you must set the FrameType property of the cfgMAC input to 'Data' or 'QoS Data'. Otherwise, the function ignores payload.


[frame,frameLength] = wlanMACFrame(payload,cfgMAC,cfgPHY) generates a WLAN MAC frame for the physical layer (PHY) format and transmission parameters specified in cfgPHY. To generate A-MPDUs in high-efficiency (HE), very high throughput (VHT), or high-throughput (HT) format, use this syntax.

[frame,frameLength] = wlanMACFrame(cfgMAC,cfgPHY) generates a WLAN MAC trigger frame for the specified MAC and PHY configurations. To create a MAC trigger frame, the cfgPHY input must be a wlanNonHTConfig object, and you must set the FrameType property of the cfgMAC input to 'Trigger'.


[frame,frameLength] = wlanMACFrame(___,OutputFormat=format) specifies the data format of the generated frame in addition to any input argument combination from previous syntaxes.


collapse all

Create a wlanMACFrameConfig object for a request-to-send (RTS) MAC frame.

cfgMAC = wlanMACFrameConfig(FrameType="RTS");

Generate the frame by calling the wlanMACFrame function and display the result.

[frame,frameLength] = wlanMACFrame(cfgMAC);

Generate a quality of service (QoS) Data MAC frame with a specified payload.

macConfig = wlanMACFrameConfig(FrameType="QoS Data");
payload = "00576000103afffe80";
[frame,frameLength] = wlanMACFrame(payload,macConfig);

Create a MAC frame configuration object.

 cfgMAC = wlanMACFrameConfig(FrameType="QoS Data", ...
     FrameFormat="HT-Mixed", ...

Create an HT PHY configuration object.

cfgPHY = wlanHTConfig(MCS=4);  

Calculate the MSDU lengths required to generate a 5000-octet A-MPDU frame, displaying the result.

msduLengths = wlanMSDULengths(5000,cfgMAC,cfgPHY);
        2302        2302         294

Create MSDUs with random data using the MSDU length vector.

 numMSDUs = numel(msduLengths);
 payload = cell(1,numMSDUs);
  for i = 1:numMSDUs
      payload{i} = randi([0 255],1,msduLengths(i));

Generate the 5000-octet A-MPDU.

[frame,frameLength] = wlanMACFrame(payload,cfgMAC,cfgPHY);

Create a wlanMACManagementConfig configuration object, specifying the service set identifier (SSID).

cfgMgmt = wlanMACManagementConfig(SSID="demo SSID");

Create a wlanMACFrameConfig configuration object, specifying the management frame-body configuration object as mgmtConfig and a beacon MAC frame.

cfgMAC = wlanMACFrameConfig(FrameType="Beacon", ...

Generate the beacon MAC frame with the specified SSID.

[macFrame,frameLength] = wlanMACFrame(cfgMAC);

Display the frame length.

frameLength = 56

Create a basic MAC trigger frame to carry information for two users.

Create a MAC trigger frame-body configuration object, specifying a channel bandwidth of 40 MHz.

cfgTrigger = wlanMACTriggerConfig(ChannelBandwidth="CBW40");

Create configuration objects for the User Info fields of the trigger frame.

cfgUser1 = wlanMACTriggerUserConfig(AID12=1, ...
cfgUser2 = wlanMACTriggerUserConfig(AID12=2, ...

Add the User Info fields to the trigger frame.

cfgTrigger = addUserInfo(cfgTrigger,cfgUser1);
cfgTrigger = addUserInfo(cfgTrigger,cfgUser2);

Configure the trigger frame by creating a MAC frame-body configuration object, specifying the frame type and the trigger frame-body configuration.

cfgMAC = wlanMACFrameConfig(FrameType="Trigger", ...

Specify a non-HT PHY configuration by creating a default non-HT configuration object.

cfgPHY = wlanNonHTConfig;

Create the MAC trigger frame and display its length.

[frame,frameLength] = wlanMACFrame(cfgMAC,cfgPHY);

Create a wlanMACFrameConfig object for an RTS MAC frame.

cfgMAC = wlanMACFrameConfig(FrameType="RTS");

Generate the RTS MAC frame in bit format.

[frame,frameLength] = wlanMACFrame(cfgMAC,OutputFormat="bits");

Input Arguments

collapse all

MAC frame configuration, specified as a wlanMACFrameConfig object. This object defines the type of MAC frame and its applicable properties.

One or more MSDUs, specified as a numeric vector, character vector, string, or cell array. The value you specify depends on whether the frame is aggregated.

  • To generate an MPDU, specify this argument as one of these values:

    • A numeric vector of octets in decimal format, where each element is an integer in the interval [0, 255]

    • A character vector of octets in hexadecimal format

    • A string scalar of octets in hexadecimal format

    The value you specify represents one MSDU.

  • To generate an A-MPDU, specify this argument as one of these values:

    • A cell array of numeric vectors

    • A cell array of character vectors

    • A string array

    Each element of the specified array represents one MSDU.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | char | string | cell

PHY format configuration, specified as a configuration object of type wlanHESUConfig, wlanVHTConfig, or wlanHTConfig. The value you specify must be compatible with the frame format specified in the cfgMAC input.

  • If the FrameFormat property of cfgMAC is "HE-SU" or "HE-EXT-SU", specify this argument as a wlanHESUConfig object.

  • If the FrameFormat property of cfgMAC is "VHT", specify this argument as a wlanVHTConfig object.

  • If the FrameFormat property of cfgMAC is "HT-Mixed", specify this argument as a wlanHTConfig object.

Specify this argument to:

  • Ensure that the frame does not exceed the transmission time limit.

  • Add end-of-frame (EOF) padding to frames in very-high-throughput (VHT) or high-efficiency (HE) format.

  • Maintain minimum start spacing between MPDUs in an A-MPDU.

MAC frame format, specified as "octets" or "bits".

Data Types: char | string

Output Arguments

collapse all

MAC frame (MPDU or A-MPDU), returned as one of these values.

  • A character array, where each row is an octet in hexadecimal format, when you specify the format input as "octets"

  • A binary-valued column vector when you specify the format input as "bits"

Data Types: int8 | char

Length of generated MAC frame, in octets, returned as a nonnegative integer. For VHT- and HE-format A-MPDUs, this output is the A-MPDU pre-EOF padding (APEP) length, which is less than or equal to the length of the frame output. For all other formats, this output is the physical layer convergence procedure (PLCP) service data unit (PSDU) length.

Data Types: double


[1] IEEE Std 802.11™-2020 (Revision of IEEE Std 802.11-2016). “Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications.” IEEE Standard for Information Technology — Telecommunications and Information Exchange between Systems— Local and Metropolitan Area Networks — Specific Requirements.

[2] IEEE Std 802.11ax™-2021 (Amendment to IEEE Std 802.11-2020). “Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications. Amendment 1: Enhancements for High Efficiency WLAN.” IEEE Standard for Information technology — Telecommunications and information exchange between systems. Local and metropolitan area networks — Specific requirements.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2018b