%% Write WLAN MAC Packet to PCAPNG File Using PCAP File Writer
% Create a PCAPNG file writer object, specifying the name of the PCAPNG file.

pcapObj = pcapngWriter('FileName','wlanExample3', ...
    'FileComment','This is a sample file');

%   Create a WLAN PCAP file writer object, specifying the PCAP file writer and the presence of radiotap header.

wlanPCAP = wlanPCAPWriter('PCAPWriter',pcapObj,'RadiotapPresent', ...
    true);

% Generate a WLAN MAC packet of type QoS Data.

macConfig = wlanMACFrameConfig('FrameType','QoS Data');
payload = '00576000103afffe80';
mpdu = hex2dec(wlanMACFrame(payload,macConfig));

%  Write the WLAN MAC packet to the PCAPNG file.

radiotapBytes = [0 0 24 0 2 0 40 0 16 3 0 0 2 192 0 0 0 0 63 1 19 0 0 0];
timestamp = 18912345; % Number of microseconds
write(wlanPCAP,mpdu,timestamp,'Radiotap',radiotapBytes, ...
    'PacketComment','This is the first packet');

% Copyright 2020 The MathWorks, Inc.