write
Write Bluetooth LE LL protocol packet data to PCAP or PCAPNG file
Description
write(
writes Bluetooth® low energy (LE) link layer (LL) protocol packet data to the packet capture
(PCAP) or packet capture next generation (PCAPNG) file specified in the Bluetooth LE PCAP
file writer object, pcapObj
,packet
,timestamp
)pcapObj
. Input packet
specifies the Bluetooth LE LL protocol packet, and input timestamp
specifies the packet arrival time.
write(
specifies options using one or more name-value pair arguments. For example,
pcapObj
,packet
,timestamp
,Name,Value
)'PacketFormat','bits'
sets the format of the Bluetooth LE LL protocol
packets to bits.
Examples
Write Bluetooth LE LL Packet to PCAP File
Create a default Bluetooth LE PCAP file writer object.
pcapObj = blePCAPWriter;
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');
Use Bluetooth LE PCAP Writer to Write LL Packet to PCAPNG File
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');
Input Arguments
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.
pcapObj
— Bluetooth LE PCAP file writer object
blePCAPWriter
object
Bluetooth LE PCAP file writer object, specified as a blePCAPWriter
object.
packet
— Bluetooth LE LL protocol packet
binary-valued vector | character vector | string scalar | numeric vector | n-by-2 character array
Bluetooth LE LL protocol packet, specified as one of these values.
Binary-valued vector – This value represents bits.
Character vector – This value represents octets in hexadecimal format.
String scalar – This value represents octets in hexadecimal format.
Numeric vector with each element in the range [0, 255] – This value represents octets in decimal format.
n-by-2 character array – In this value, each row represents an octet in hexadecimal format.
Data Types: char
| string
| double
timestamp
— Packet arrival time
nonnegative integer
Packet arrival time in POSIX® microseconds elapsed since 1/1/1970, specified as a nonnegative integer.
Data Types: double
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'PacketFormat','bits'
sets the format of the Bluetooth LE LL
protocol packets to bits.
PhyHeader
— Bluetooth LE LL protocol packet metadata
binary-valued vector | character vector | string scalar | numeric vector | n-by-2 character array
Bluetooth LE LL protocol packet metadata, specified as the comma-separated pair
consisting of PhyHeader
and one of these values.
Binary-valued vector – This value represents bits.
Character vector – This value represents octets in hexadecimal format.
String scalar – This value represents octets in hexadecimal format.
Numeric vector with each element in the range [0, 255] – This value represents octets in decimal format.
n-by-2 character array – In this value, each row represents an octet in hexadecimal format.
Data Types: char
| string
| double
PacketComment
— Comment for the Bluetooth LE LL protocol packet
''
(default) | character vector | string scalar
Comment for the Bluetooth LE LL protocol packet, specified as the comma-separated
pair consisting of PacketComment
and a character vector or a
string scalar.
Data Types: char
| string
PacketFormat
— Format of the Bluetooth LE LL protocol packet
'octets'
(default) | 'bits'
Format of the Bluetooth LE LL protocol packet, specified as the comma-separated
pair consisting of PacketFormat
and 'octets'
or 'bits'
. If this value is specified as
'octets'
, packet
is specified as one of
these values.
Binary-valued vector – This value represents bits.
Character vector – This value represents octets in hexadecimal format.
String scalar – This value represents octets in hexadecimal format.
Numeric vector with each element in the range [0, 255] – This value represents octets in decimal format.
n-by-2 character array – In this value, each row represents an octet in hexadecimal format.
Data Types: char
| string
| double
PhyHeaderFormat
— Format of the PHY header
'octets'
(default) | 'bits'
Format of the physical layer (PHY) header, specified as the comma-separated pair
consisting of PhyHeaderFormat
and 'octets'
or
'bits'
. If you specify this value as 'octets'
,
the PhyHeader
argument can be specified as one of these values.
Binary-valued vector – This value represents bits.
Character vector – This value represents octets in hexadecimal format.
String scalar – This value represents octets in hexadecimal format.
Numeric vector with each element in the range [0, 255] – This value represents octets in decimal format.
n-by-2 character array – In this value, each row represents an octet in hexadecimal format
Data Types: char
| string
| double
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
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)