Main Content

wlanPCAPWriter

PCAP or PCAPNG file writer of WLAN MAC packets

Since R2021a

    Description

    The wlanPCAPWriter object writes generated and recovered WLAN medium access control (MAC) packets to a packet capture (PCAP) or packet capture next generation (PCAPNG) file (.pcap or .pcapng, respectively).

    Creation

    Description

    obj = wlanPCAPWriter creates a default WLAN PCAP or PCAPNG file writer object that writes WLAN MAC packets to a PCAP or PCAPNG file, respectively.

    example

    obj = wlanPCAPWriter(Name,Value) sets Properties using one or more name-value pairs. Enclose each property name in quotes. For example, ('FileExtension','pcapng') sets the extension of the file as .pcapng.

    Properties

    expand all

    Note

    The wlanPCAPWriter object does not overwrite the existing PCAP or PCAPNG file. During each call of this object, specify a unique PCAP or PCAPNG file name.

    Name of the PCAP or PCAPNG file, specified as a character row vector or a string scalar.

    Data Types: char | string

    Byte order, specified as 'little-endian' or 'big-endian'.

    Data Types: char | string

    Type of file, specified as 'pcap' or 'pcapng'.

    Data Types: char | string

    Comment for the PCAPNG file, specified as a character row vector or a string scalar.

    Dependencies

    To enable this property, set the FileExtension property to 'pcapng'.

    Data Types: char | string

    Name of device that captures WLAN packets, specified as a character row vector or a string scalar.

    Dependencies

    To enable this property, set the FileExtension property to 'pcapng'.

    Data Types: char | string

    Flag to indicate the presence of radiotap, specified as a logical 1 (true) or 0 (false).

    Data Types: logical

    PCAP or PCAPNG file writer object, specified as pcapWriter or pcapngWriter object.

    Object Functions

    expand all

    writeWrite protocol packet data to PCAP or PCAPNG file

    Examples

    collapse all

    Create a WLAN PCAP file writer object, specifying the name of the PCAP file.

    pcapObj = wlanPCAPWriter('FileName','wlanExample', ...
        'FileExtension','pcap');

    Generate a WLAN MAC packet of type QoS Data.

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

    Write the WLAN MAC packet to the PCAP file.

    timestamp = 0; % Number of microseconds
    write(pcapObj,mpdu,timestamp);

    Create a WLAN PCAP file writer object, specifying the name of the PCAPNG file.

    pcapObj = wlanPCAPWriter('FileName','wlanExample2', ...
        'FileExtension','pcapng');

    Generate a WLAN MAC packet of type QoS Data.

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

    Write the WLAN MAC packet to the PCAPNG format file.

    timestamp = 12800000; % Number of microseconds
    write(pcapObj,mpdu,timestamp,'PacketFormat','bits');

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

    References

    [1] Tuexen, M. “PCAP Next Generation (Pcapng) Capture File Format.” 2020. https://www.ietf.org/.

    [2] “Radiotap - Introduction.” Accessed May 20, 2020. https://www.radiotap.org/.

    [3] Group, The Tcpdump. “Tcpdump/Libpcap Public Repository.” Accessed May 20, 2020. https://www.tcpdump.org.

    [4] “Development/LibpcapFileFormat - The Wireshark Wiki.” Accessed May 20, 2020. https://www.wireshark.org.

    Extended Capabilities

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

    Version History

    Introduced in R2021a