%% Decode MPDUs Extracted from A-MPDU
% Deaggregate a VHT A-MPDU and decode the extracted MPDUs.
% Create a WLAN MAC frame configuration object for a VHT A-MPDU.

txCfgMAC = wlanMACFrameConfig('FrameType','QoS Data', ...
    'FrameFormat','VHT');

% Create a VHT-format configuration object with default settings.

cfgPHY = wlanVHTConfig;

% Generate a random payload of eight MSDUs.

txPayload =  repmat({randi([0 255],1,40)},1,8);

% Generate the A-MPDU containing eight MPDUs for the specified MAC and PHY configurations.

ampdu = wlanMACFrame(txPayload,txCfgMAC,cfgPHY);

% Extract the list of MPDUs by deaggregating the A-MPDU. Display the status of the deaggregation and the delimiter CRC.

[mpduList,failCRC,status] = wlanAMPDUDeaggregate(ampdu,cfgPHY, ...
    'DataFormat','octets');
disp(status)
disp(failCRC)

% Decode all of the MPDUs in the extracted. Confirm successful decoding by displaying the status.

if strcmp(status,'Success')
    for i = 1:numel(mpduList)
        if ~failCRC(i)
            [cfgMAC,payload,status(i)] = ...
                wlanMPDUDecode(mpduList{i},cfgPHY, ...
                'DataFormat','octets');
        end
    end
end
disp(status)

% Copyright 2018 The MathWorks, Inc.