Main Content

blePCAPWriter

PCAP or PCAPNG file writer of Bluetooth LE LL packets

    Description

    The blePCAPWriter object writes generated and recovered Bluetooth® low energy (LE) link layer (LL) packets to a packet capture (PCAP) or packet capture next generation (PCAPNG) file (.pcap or .pcapng, respectively).

    Creation

    Description

    obj = blePCAPWriter creates a default Bluetooth LE PCAP or PCAPNG file writer object that writes Bluetooth LE LL packets to a PCAP or PCAPNG file, respectively.

    example

    obj = blePCAPWriter(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 blePCAPWriter object does not overwrite the existing PCAP or PCAPNG file. Each time when you create 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 vector or a string scalar.

    Data Types: char | string

    Name of the interface on which Bluetooth LE packets are captured, specified as a character vector or a string scalar.

    Data Types: char | string

    Flag to indicate the presence of physical layer (PHY) header, 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 Bluetooth LE LL protocol packet data to PCAP or PCAPNG file

    Examples

    collapse all

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

    pcapObj = blePCAPWriter('FileName','writeblepacket');

    Generate a Bluetooth LE LL packet.

    cfgLLData = bleLLDataChannelPDUConfig('LLID', ...
        'Data (start fragment/complete)');
    payload = '0E00050014010A001F004000170017000000';
    llDataPDU = bleLLDataChannelPDU(cfgLLData,payload);
    connAccessAddress = de2bi(hex2dec('E213BC42'),32)';
    llpacket = [connAccessAddress; llDataPDU];

    Write the Bluetooth LE LL packet to the PCAP file.

    timestamp = 0;                                         % Packet arrival time in POSIX® microseconds elapsed since 1/1/1970
    write(pcapObj,llpacket,timestamp,'PacketFormat','bits');

    Create a Bluetooth LE PCAPNG file writer object, specifying the name and extension of the PCAPNG file.

    pcapObj = blePCAPWriter('FileName','sampleBLELL', ...
        'FileExtension','pcapng');

    Generate a Bluetooth LE LL packet.

    cfgLLData = bleLLDataChannelPDUConfig('LLID', ...
        'Data (start fragment/complete)');
    payload = '0E00050014010A001F004000170017000000';
    llDataPDU = bleLLDataChannelPDU(cfgLLData,payload);
    connAccessAddress = de2bi(hex2dec('E213BC42'),32)';
    llpacket = [connAccessAddress; llDataPDU];

    Write the Bluetooth LE LL packet to the PCAPNG file.

    timestamp = 12800000;                               % Packet arrival time in POSIX® microseconds elapsed since 1/1/1970
    write(pcapObj,llpacket,timestamp,'PacketFormat','bits');

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

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

    Create a Bluetooth LE PCAP file writer object, specifying the PCAPNG file writer and the presence of PHY header.

    blePCAP = blePCAPWriter('PCAPWriter',pcapObj,'PhyHeaderPresent',true);

    Generate a Bluetooth LE LL packet.

    cfgLLAdv = bleLLAdvertisingChannelPDUConfig;
    cfgLLAdv.PDUType = 'Advertising indication';
    cfgLLAdv.AdvertisingData = '020106';
    llDataPDU = bleLLAdvertisingChannelPDU(cfgLLAdv);
    connAccessAddress = de2bi(hex2dec('E213BC42'),32)';
    llpacket = [connAccessAddress;llDataPDU];

    Write the Bluetooth LE LL packet to the PCAPNG file.

    PhyHeaderBytes = [39 10 8 1 10 10 10 10 15 00];
    timestamp = 18912345;                           % Packet arrival time in POSIX® microseconds elapsed since 1/1/1970
    write(blePCAP,llpacket,timestamp,'PacketFormat','bits', ...
        'PhyHeader',PhyHeaderBytes, ...
        'PacketComment','This is the first packet');

    References

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

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

    [3] “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 R2020b