PcapPlusPlus  Next
pcpp::BluetoothHciLayer Class Reference

#include <BluetoothHciLayer.h>

Inheritance diagram for pcpp::BluetoothHciLayer:
pcpp::Layer pcpp::IDataContainer pcpp::BluetoothHciEventLayer

Public Types

enum class  BluetoothHciPacketType : uint8_t {
  Unknown = 0x00 , Command = 0x01 , AclData = 0x02 , ScoData = 0x03 ,
  Event = 0x04 , IsoData = 0x05
}
 
enum class  BluetoothHciDirection : uint32_t { HostToController = 0 , ControllerToHost = 1 , Unknown = 0xffffffff }
 

Public Member Functions

bool hasDirectionHeader () const
 
BluetoothHciDirection getDirection () const
 
BluetoothHciPacketType getPacketType () const
 
void parseNextLayer () override
 
void computeCalculateFields () override
 Does nothing for this layer.
 
OsiModelLayer getOsiModelLayer () const override
 
- Public Member Functions inherited from pcpp::Layer
 ~Layer () override
 
Layer * getNextLayer () const
 
Layer * getPrevLayer () const
 
ProtocolType getProtocol () const
 
bool isMemberOfProtocolFamily (ProtocolTypeFamily protocolTypeFamily) const
 
uint8_t * getData () const
 
size_t getDataLen () const
 
uint8_t * getLayerPayload () const
 
size_t getLayerPayloadSize () const
 
bool isAllocatedToPacket () const
 
void copyData (uint8_t *toArr) const
 Copy the raw data of this layer to another array. More...
 
size_t copyData (uint8_t *dest, size_t destSize) const
 Copy the raw data of this layer to another array, with a specified maximum size. More...
 
void serialize (ISerializer &serializer) const
 
uint8_t * getDataPtr (size_t offset=0) const override
 
virtual size_t getHeaderLen () const =0
 
virtual std::string toString () const =0
 

Static Public Member Functions

static BluetoothHciLayer * parseLayer (uint8_t *data, size_t dataLen, Packet *packet, bool hasDirectionHeader)
 
static bool isDataValid (const uint8_t *data, size_t dataLen, bool hasDirectionHeader)
 

Protected Member Functions

 BluetoothHciLayer (uint8_t *data, size_t dataLen, Packet *packet, bool hasDirectionHeader)
 
 BluetoothHciLayer (bool hasDirectionHeader)
 
size_t getDirectionHeaderLen () const
 
- Protected Member Functions inherited from pcpp::Layer
Packet * getAttachedPacket ()
 Get a pointer to the Packet this layer is attached to (if any). More...
 
Packet const * getAttachedPacket () const
 Get a pointer to the Packet this layer is attached to (if any). More...
 
void allocData (size_t dataLen, bool zeroInit=true)
 Requests the layer to allocate a new data buffer of the specified length. More...
 
template<typename T , typename... Args>
Layer * constructNextLayer (uint8_t *data, size_t dataLen, Args &&... extraArgs)
 Construct the next layer in the protocol stack. No validation is performed on the data. More...
 
template<typename T , typename... Args>
Layer * constructNextLayer (uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 
template<typename TFactory , typename... Args>
Layer * constructNextLayerFromFactory (TFactory factoryFn, uint8_t *data, size_t dataLen, Args &&... extraArgs)
 Construct the next layer in the protocol stack using a factory functor. More...
 
template<typename TFactory , typename... Args>
Layer * constructNextLayerFromFactory (TFactory factoryFn, uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 Construct the next layer in the protocol stack using a factory functor. More...
 
template<typename T , typename... Args>
Layer * tryConstructNextLayer (uint8_t *data, size_t dataLen, Args &&... extraArgs)
 
template<typename T , typename... Args>
Layer * tryConstructNextLayer (uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 
template<typename T , typename TFallback , typename... Args>
Layer * tryConstructNextLayerWithFallback (uint8_t *data, size_t dataLen, Args &&... extraArgs)
 Try to construct the next layer in the protocol stack with a fallback option. More...
 
template<typename T , typename TFallback , typename... Args>
Layer * tryConstructNextLayerWithFallback (uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 
template<typename TFallback , typename TFactory , typename... Args>
Layer * tryConstructNextLayerFromFactoryWithFallback (TFactory factoryFn, uint8_t *data, size_t dataLen, Args &&... extraArgs)
 Try to construct the next layer in the protocol stack using a factory functor with a fallback option. More...
 
template<typename TFallback , typename TFactory , typename... Args>
Layer * tryConstructNextLayerFromFactoryWithFallback (TFactory factoryFn, uint8_t *data, size_t dataLen, Packet *packet, Args &&... extraArgs)
 Try to construct the next layer in the protocol stack using a factory functor with a fallback option. More...
 
virtual void serializeLayer (ObjectScope &serializer) const
 

Static Protected Attributes

static constexpr size_t directionHeaderSize = 4
 

Additional Inherited Members

- Static Protected Member Functions inherited from pcpp::Layer
template<typename T >
static bool canReinterpretAs (const uint8_t *data, size_t dataLen)
 Check if the data is large enough to reinterpret as a type. More...
 

Detailed Description

An abstract base class for all Bluetooth HCI packet types. It handles the parts common to every HCI packet: the optional direction pseudo-header and the H4 packet indicator octet. Concrete subclasses parse a specific packet type and are created through BluetoothHciLayer::parseLayer()

Member Enumeration Documentation

◆ BluetoothHciDirection

The direction of an HCI packet, taken from the pseudo-header present in LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR captures

Enumerator
HostToController 

Sent from the host to the controller.

ControllerToHost 

Received by the host from the controller.

Unknown 

The capture has no direction pseudo-header (LINKTYPE_BLUETOOTH_HCI_H4)

◆ BluetoothHciPacketType

The HCI packet type, taken from the H4 packet indicator octet

Enumerator
Unknown 

Not a recognized HCI packet type. 0x00 is not a valid H4 packet indicator value.

Command 

A command sent from the host to the controller.

AclData 

ACL data.

ScoData 

Synchronous (SCO) data.

Event 

An event sent from the controller to the host.

IsoData 

Isochronous (ISO) data.

Constructor & Destructor Documentation

◆ BluetoothHciLayer() [1/2]

pcpp::BluetoothHciLayer::BluetoothHciLayer ( uint8_t *  data,
size_t  dataLen,
Packet *  packet,
bool  hasDirectionHeader 
)
inlineprotected

A constructor that creates the layer from an existing packet raw data

Parameters
[in]dataA pointer to the raw data
[in]dataLenSize of the data in bytes
[in]packetA pointer to the Packet instance where layer will be stored in
[in]hasDirectionHeaderTrue if the data starts with a 4-byte direction pseudo-header

◆ BluetoothHciLayer() [2/2]

pcpp::BluetoothHciLayer::BluetoothHciLayer ( bool  hasDirectionHeader)
inlineexplicitprotected

Constructor used by subclasses that will allocate their own buffer via allocData()

Parameters
[in]hasDirectionHeaderTrue if the buffer will include a 4-byte direction pseudo-header

Member Function Documentation

◆ getDirection()

BluetoothHciDirection pcpp::BluetoothHciLayer::getDirection ( ) const

Get the direction of this packet

Returns
The packet direction, or BluetoothHciDirection::Unknown if the capture has no direction pseudo-header

◆ getDirectionHeaderLen()

size_t pcpp::BluetoothHciLayer::getDirectionHeaderLen ( ) const
inlineprotected
Returns
Size of the direction pseudo-header, or 0 if this packet has none

◆ getOsiModelLayer()

OsiModelLayer pcpp::BluetoothHciLayer::getOsiModelLayer ( ) const
inlineoverridevirtual
Returns
The OSI Model layer this protocol belongs to

Implements pcpp::Layer.

◆ getPacketType()

BluetoothHciPacketType pcpp::BluetoothHciLayer::getPacketType ( ) const
inline
Returns
The HCI packet type this layer represents, or BluetoothHciPacketType::Unknown if the packet indicator octet doesn't match a known packet type

◆ hasDirectionHeader()

bool pcpp::BluetoothHciLayer::hasDirectionHeader ( ) const
inline
Returns
True if this packet is preceded by a direction pseudo-header, false otherwise

◆ isDataValid()

static bool pcpp::BluetoothHciLayer::isDataValid ( const uint8_t *  data,
size_t  dataLen,
bool  hasDirectionHeader 
)
static

A static method that validates the part of the input data common to all HCI packet types

Parameters
[in]dataThe pointer to the beginning of a byte stream of a Bluetooth HCI packet
[in]dataLenThe length of the byte stream
[in]hasDirectionHeaderTrue if the data is expected to start with a 4-byte direction pseudo-header
Returns
True if the data is long enough to hold the direction pseudo-header, if one is expected, followed by a packet indicator octet

◆ parseLayer()

static BluetoothHciLayer* pcpp::BluetoothHciLayer::parseLayer ( uint8_t *  data,
size_t  dataLen,
Packet *  packet,
bool  hasDirectionHeader 
)
static

A static factory that identifies the HCI packet type and creates the matching layer

Parameters
[in]dataA pointer to the raw data
[in]dataLenSize of the data in bytes
[in]packetA pointer to the Packet instance where layer will be stored in
[in]hasDirectionHeaderTrue if the data starts with a 4-byte direction pseudo-header (LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR), false if it starts directly with the H4 packet indicator (LINKTYPE_BLUETOOTH_HCI_H4)
Returns
An instance of a BluetoothHciLayer subclass, or nullptr if the data is invalid or the packet type is not supported yet

◆ parseNextLayer()

void pcpp::BluetoothHciLayer::parseNextLayer ( )
inlineoverridevirtual

HCI packets don't encapsulate another protocol, so no next layer is parsed. Subclasses that do encapsulate another protocol override this method

Implements pcpp::Layer.

Member Data Documentation

◆ directionHeaderSize

constexpr size_t pcpp::BluetoothHciLayer::directionHeaderSize = 4
staticconstexprprotected

Size of the direction pseudo-header on the wire. Exposed to derived classes so their static validators can size-check the raw buffer without needing the struct definition itself