blePCAPWriter

PCAP or PCAPNG file writer of BLE LL packets

    Download Required: To use blePCAPWriter, first download Communications Toolbox™ Library for the Bluetooth® Protocol. For more information, see Get and Manage Add-Ons. Alternatively, see Communications Toolbox Library for the Bluetooth Protocol File Exchange.

    Description

    The blePCAPWriter object writes generated and recovered Bluetooth low energy (BLE) 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 BLE PCAP or PCAPNG file writer object that writes BLE 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. 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 vector or a string scalar.

    Data Types: char | string

    Name of the interface on which BLE 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 BLE LL protocol packet data to PCAP or PCAPNG file

    Examples

    collapse all

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

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

    Generate a BLE 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 BLE LL packet to the PCAP file.

    timestamp = 0; % Number of microseconds
    write(pcapObj,llpacket,timestamp,'PacketFormat','bits');

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

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

    Generate a BLE 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 BLE LL packet to the PCAPNG file.

    timestamp = 12800000; % Number of microseconds
    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 BLE PCAP file writer object, specifying the PCAPNG file writer and the presence of PHY header.

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

    Generate a BLE LL packet.

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

    Write the BLE LL packet to the PCAPNG file.

    PhyHeaderBytes = [39 10 8 1 10 10 10 10 15 00];
    timestamp = 18912345; % Number of microseconds
    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™.

    See Also

    Objects

    Introduced in R2020b