PcapPlusPlus  Next
pcpp::BluetoothHciEventLayer Class Reference

#include <BluetoothHciLayer.h>

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

Classes

struct  SerializedFields
 

Public Member Functions

 BluetoothHciEventLayer (uint8_t eventCode, const std::vector< uint8_t > &parameters={})
 
 BluetoothHciEventLayer (BluetoothHciDirection direction, uint8_t eventCode, const std::vector< uint8_t > &parameters={})
 
uint8_t getEventCode () const
 
void setEventCode (uint8_t eventCode)
 
uint8_t getParameterTotalLength () const
 
uint8_t * getParameters () const
 
void setParameters (const std::vector< uint8_t > &parameters)
 
size_t getHeaderLen () const override
 
std::string toString () const override
 
- Public Member Functions inherited from pcpp::BluetoothHciLayer
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
 

Static Public Member Functions

static bool isDataValid (const uint8_t *data, size_t dataLen, bool hasDirectionHeader)
 
- Static Public Member Functions inherited from pcpp::BluetoothHciLayer
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

void serializeLayer (ObjectScope &serializer) const override
 
- Protected Member Functions inherited from pcpp::BluetoothHciLayer
 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...
 

Additional Inherited Members

- Public Types inherited from pcpp::BluetoothHciLayer
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 }
 
- 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...
 
- Static Protected Attributes inherited from pcpp::BluetoothHciLayer
static constexpr size_t directionHeaderSize = 4
 

Detailed Description

Represents a Bluetooth HCI Event packet, identified by the H4 packet indicator octet 0x04

Constructor & Destructor Documentation

◆ BluetoothHciEventLayer() [1/2]

pcpp::BluetoothHciEventLayer::BluetoothHciEventLayer ( uint8_t  eventCode,
const std::vector< uint8_t > &  parameters = {} 
)
explicit

Construct a new Event layer with no direction pseudo-header, suitable for serialization to LINKTYPE_BLUETOOTH_HCI_H4 captures

Parameters
[in]eventCodeThe HCI event code
[in]parametersThe raw parameter bytes. Must contain at most 255 bytes
Exceptions
std::invalid_argumentif parameters contains more than 255 bytes

◆ BluetoothHciEventLayer() [2/2]

pcpp::BluetoothHciEventLayer::BluetoothHciEventLayer ( BluetoothHciDirection  direction,
uint8_t  eventCode,
const std::vector< uint8_t > &  parameters = {} 
)

Construct a new Event layer prefixed with the 4-byte direction pseudo-header, suitable for serialization to LINKTYPE_BLUETOOTH_HCI_H4_WITH_PHDR captures

Parameters
[in]directionThe packet direction
[in]eventCodeThe HCI event code
[in]parametersThe raw parameter bytes. Must contain at most 255 bytes
Exceptions
std::invalid_argumentif direction is not HostToController or ControllerToHost, or if parameters contains more than 255 bytes

Member Function Documentation

◆ getEventCode()

uint8_t pcpp::BluetoothHciEventLayer::getEventCode ( ) const
inline

Get the event code of this packet

Returns
The event code

◆ getHeaderLen()

size_t pcpp::BluetoothHciEventLayer::getHeaderLen ( ) const
inlineoverridevirtual
Returns
The entire data length. HCI Event packets don't encapsulate another protocol, so the whole buffer is treated as the header

Implements pcpp::Layer.

◆ getParameters()

uint8_t* pcpp::BluetoothHciEventLayer::getParameters ( ) const
inline

Get a pointer to the raw event parameters

Returns
A pointer to the raw parameter bytes

◆ getParameterTotalLength()

uint8_t pcpp::BluetoothHciEventLayer::getParameterTotalLength ( ) const

Get the parameter total length. If the packet is truncated, i.e. the parameterTotalLength field is larger than the number of parameter bytes actually present, the number of bytes present is returned

Returns
The parameter total length, in bytes

◆ isDataValid()

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

A static method that validates the input data

Parameters
[in]dataThe pointer to the beginning of a byte stream of a Bluetooth HCI Event 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 valid and can represent a Bluetooth HCI Event packet

◆ serializeLayer()

void pcpp::BluetoothHciEventLayer::serializeLayer ( ObjectScope &  serializer) const
overrideprotectedvirtual

Serializes the layer's data into a provided serializer object. This is used for generating serialized representations (like JSON) of the packet layers. This method should be overridden by derived layers to provide specific serialization logic.

Parameters
[in]serializerThe object scope serializer to which the layer details should be written.

Reimplemented from pcpp::Layer.

◆ setEventCode()

void pcpp::BluetoothHciEventLayer::setEventCode ( uint8_t  eventCode)
inline

Set the event code of this packet

Parameters
[in]eventCodeThe new event code

◆ setParameters()

void pcpp::BluetoothHciEventLayer::setParameters ( const std::vector< uint8_t > &  parameters)

Replace the parameter bytes of this packet. The parameterTotalLength field is updated to match

Parameters
[in]parametersThe new parameter bytes. Must contain at most 255 bytes
Exceptions
std::invalid_argumentif parameters contains more than 255 bytes
std::runtime_errorif the layer could not be extended or shortened to fit the new parameters

◆ toString()

std::string pcpp::BluetoothHciEventLayer::toString ( ) const
overridevirtual
Returns
A string representation of the layer most important data (should look like the layer description in Wireshark)

Implements pcpp::Layer.