CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
cdc::hal::BleAdvParser Namespace Reference

Functions

bool findManufacturerData (const uint8_t *advData, uint8_t len, uint16_t *companyId, const uint8_t **data, uint8_t *dataLen)
 Extracts manufacturer-specific AD payload and company identifier.
bool findServiceUuid128 (const uint8_t *advData, uint8_t len, const uint8_t uuid128[16])
 Checks whether a specific 128-bit service UUID is present in AD structures.
bool findName (const uint8_t *advData, uint8_t len, char *name, uint8_t nameMaxLen)
 Extracts local device name from advertising data.
template<typename Callback>
static bool walkAdStructures (const uint8_t *advData, uint8_t len, Callback callback)
 Iterates over AD structures and invokes a callback for each structure.

Variables

static constexpr uint8_t AD_TYPE_SHORTENED_NAME = 0x08
 AD type constants from BLE Core Spec Supplement, Part A.
static constexpr uint8_t AD_TYPE_COMPLETE_NAME = 0x09
static constexpr uint8_t AD_TYPE_INCOMPLETE_UUID128 = 0x06
static constexpr uint8_t AD_TYPE_COMPLETE_UUID128 = 0x07
static constexpr uint8_t AD_TYPE_MANUFACTURER_SPECIFIC = 0xFF
static constexpr uint8_t UUID128_SIZE = 16
static constexpr uint8_t COMPANY_ID_SIZE = 2

Detailed Description

Stack-independent BLE advertising data parser. Parses raw AD structures per BLE Core Spec Vol 3, Part C, Section 11.

BLE Advertising Data Parser

Parses raw AD structures per BLE Core Spec Vol 3, Part C, Section 11. Each AD structure: [length][type][data...]

  • length = size of type + data (does NOT include the length byte itself)
  • type = AD type identifier
  • data = type-specific payload

Function Documentation

◆ findManufacturerData()

bool cdc::hal::BleAdvParser::findManufacturerData ( const uint8_t * advData,
uint8_t len,
uint16_t * companyId,
const uint8_t ** data,
uint8_t * dataLen )

Extracts manufacturer-specific AD payload and company identifier.

Find manufacturer-specific data in advertising data

Returns
true if found
Parameters
advDataRaw advertising data buffer.
lenBuffer length.
companyIdOutput company identifier.
dataOutput pointer to manufacturer payload bytes (after company ID).
dataLenOutput payload length.
Returns
true if manufacturer data was found and parsed.

Definition at line 81 of file BleAdvParser.cpp.

References AD_TYPE_MANUFACTURER_SPECIFIC, COMPANY_ID_SIZE, and walkAdStructures().

◆ findName()

bool cdc::hal::BleAdvParser::findName ( const uint8_t * advData,
uint8_t len,
char * name,
uint8_t nameMaxLen )

Extracts local device name from advertising data.

Extract device name from advertising data

Returns
true if found
Parameters
advDataRaw advertising data buffer.
lenBuffer length.
nameOutput buffer for the parsed name.
nameMaxLenSize of name.
Returns
true if a complete or shortened name field was found.

Definition at line 150 of file BleAdvParser.cpp.

References AD_TYPE_COMPLETE_NAME, AD_TYPE_SHORTENED_NAME, name, and walkAdStructures().

◆ findServiceUuid128()

bool cdc::hal::BleAdvParser::findServiceUuid128 ( const uint8_t * advData,
uint8_t len,
const uint8_t uuid128[16] )

Checks whether a specific 128-bit service UUID is present in AD structures.

Check if a 128-bit service UUID is advertised

Returns
true if found
Parameters
advDataRaw advertising data buffer.
lenBuffer length.
uuid128Target 128-bit UUID bytes.
Returns
true if the UUID appears in an incomplete or complete UUID128 AD field.

Definition at line 115 of file BleAdvParser.cpp.

References AD_TYPE_COMPLETE_UUID128, AD_TYPE_INCOMPLETE_UUID128, UUID128_SIZE, and walkAdStructures().

◆ walkAdStructures()

template<typename Callback>
bool cdc::hal::BleAdvParser::walkAdStructures ( const uint8_t * advData,
uint8_t len,
Callback callback )
static

Iterates over AD structures and invokes a callback for each structure.

Stops early when the callback reports a match.

Parameters
advDataRaw advertising data buffer.
lenTotal length of advData.
callbackCallback receiving (adType, adPayload, adPayloadLen).
Returns
true if the callback returned true for any structure, otherwise false.

Definition at line 38 of file BleAdvParser.cpp.

Referenced by findManufacturerData(), findName(), and findServiceUuid128().

Variable Documentation

◆ AD_TYPE_COMPLETE_NAME

uint8_t cdc::hal::BleAdvParser::AD_TYPE_COMPLETE_NAME = 0x09
staticconstexpr

Definition at line 20 of file BleAdvParser.cpp.

Referenced by findName().

◆ AD_TYPE_COMPLETE_UUID128

uint8_t cdc::hal::BleAdvParser::AD_TYPE_COMPLETE_UUID128 = 0x07
staticconstexpr

Definition at line 22 of file BleAdvParser.cpp.

Referenced by findServiceUuid128().

◆ AD_TYPE_INCOMPLETE_UUID128

uint8_t cdc::hal::BleAdvParser::AD_TYPE_INCOMPLETE_UUID128 = 0x06
staticconstexpr

Definition at line 21 of file BleAdvParser.cpp.

Referenced by findServiceUuid128().

◆ AD_TYPE_MANUFACTURER_SPECIFIC

uint8_t cdc::hal::BleAdvParser::AD_TYPE_MANUFACTURER_SPECIFIC = 0xFF
staticconstexpr

Definition at line 23 of file BleAdvParser.cpp.

Referenced by findManufacturerData().

◆ AD_TYPE_SHORTENED_NAME

uint8_t cdc::hal::BleAdvParser::AD_TYPE_SHORTENED_NAME = 0x08
staticconstexpr

AD type constants from BLE Core Spec Supplement, Part A.

Definition at line 19 of file BleAdvParser.cpp.

Referenced by findName().

◆ COMPANY_ID_SIZE

uint8_t cdc::hal::BleAdvParser::COMPANY_ID_SIZE = 2
staticconstexpr

Definition at line 26 of file BleAdvParser.cpp.

Referenced by findManufacturerData().

◆ UUID128_SIZE

uint8_t cdc::hal::BleAdvParser::UUID128_SIZE = 16
staticconstexpr

Definition at line 25 of file BleAdvParser.cpp.

Referenced by findServiceUuid128().