Direct-BT
2.3.1
Direct-BT - Direct Bluetooth Programming.
|
Go to the documentation of this file.
26 #ifndef BT_ADDRESS_HPP_
27 #define BT_ADDRESS_HPP_
68 return static_cast<uint8_t
>(rhs);
212 h = ( ( h << 5 ) - h ) +
b[i];
221 b[0] = 0;
b[1] = 0;
b[2] = 0;
222 b[3] = 0;
b[4] = 0;
b[5] = 0;
235 const uint8_t needle_b[],
const jau::nsize_t needle_length) noexcept;
261 std::string
toString() const noexcept;
269 if( lhs.length != rhs.length ) {
272 return !memcmp(&lhs.b, &rhs.b, lhs.length);
276 {
return !(lhs == rhs); }
283 __pack (
struct EUI48 {
296 constexpr EUI48() noexcept :
b{0} { }
297 EUI48(
const uint8_t * b_) noexcept;
311 static bool scanEUI48(
const std::string& str, EUI48& dest, std::string& errmsg);
323 EUI48(
const std::string& str);
325 constexpr EUI48(
const EUI48 &o) noexcept =
default;
326 EUI48(EUI48 &&o) noexcept =
default;
327 constexpr EUI48&
operator=(
const EUI48 &o) noexcept =
default;
328 EUI48&
operator=(EUI48 &&o) noexcept =
default;
330 constexpr std::size_t
hash_code() const noexcept {
332 std::size_t h =
b[0];
333 h = ( ( h << 5 ) - h ) +
b[1];
334 h = ( ( h << 5 ) - h ) +
b[2];
335 h = ( ( h << 5 ) - h ) +
b[3];
336 h = ( ( h << 5 ) - h ) +
b[4];
337 h = ( ( h << 5 ) - h ) +
b[5];
345 b[0] = 0;
b[1] = 0;
b[2] = 0;
346 b[3] = 0;
b[4] = 0;
b[5] = 0;
387 std::string
toString() const noexcept;
396 const uint8_t * a = lhs.b;
397 const uint8_t *
b = rhs.b;
398 return a[0] ==
b[0] &&
407 {
return !(lhs == rhs); }
436 : address(address_), type(type_) {}
441 address = std::move(o.address);
442 type = std::move(o.type);
450 address = std::move(o.address);
451 type = std::move(o.type);
491 return address == o.address &&
501 std::size_t h = hash;
505 h = ((h << 5) - h) +
number(type);
527 std::string
toString() const noexcept;
533 return lhs.address == rhs.address &&
534 lhs.type == rhs.type;
537 {
return !(lhs == rhs); }
548 return a.hash_code();
554 return a.hash_code();
560 return a.hash_code();
constexpr BDAddressAndType & operator=(const BDAddressAndType &o) noexcept
std::size_t operator()(direct_bt::EUI48 const &a) const noexcept
bool contains(const EUI48Sub &needle) const noexcept
Returns true, if given EUI48Sub needle is contained in this instance haystack.
void clear()
Method clears the underlying byte array b and sets length to zero.
constexpr BDAddressAndType() noexcept
BDAddressAndType(BDAddressAndType &&o) noexcept
static const BDAddressAndType ANY_DEVICE
Using EUI48::ANY_DEVICE and BDAddressType::BDADDR_UNDEFINED to match any device.
std::size_t hash_code() const noexcept
Implementation uses a lock-free volatile cache.
constexpr EUI48Sub(const EUI48Sub &o) noexcept=default
BLERandomAddressType getBLERandomAddressType(const BDAddressType addressType) const noexcept
constexpr std::size_t hash_code() const noexcept
BLERandomAddressType getBLERandomAddressType() const noexcept
Returns the BLERandomAddressType.
std::string toString() const noexcept
Returns the EUI48 sub-string representation, less or equal 17 characters representing less or equal 6...
BDAddressAndType(const BDAddressAndType &o) noexcept
BLERandomAddressType
BT Core Spec v5.2: Vol 6 LE, Part B Link Layer Specification: 1.3 Device Address.
bool operator==(const EUI48Sub &lhs, const EUI48Sub &rhs) noexcept
static const EUI48Sub ANY_DEVICE
EUI48 MAC address matching any device, i.e.
@ RANDOM_STATIC_IDENTITY
Resolved Random (Static) Identity Address.
static bool scanEUI48Sub(const std::string &str, EUI48Sub &dest, std::string &errmsg)
Fills given EUI48Sub instance via given string representation.
@ PUBLIC
Public Device Address.
uint8_t b[6]
The <= 6 byte EUI48 sub-address.
constexpr EUI48Sub() noexcept
constexpr bool isBREDRAddress() const noexcept
Returns true if the BDAddressType is a BREDR address type.
constexpr BDAddressType to_BDAddressType(const uint8_t v) noexcept
A 48 bit EUI-48 sub-identifier, see EUI48.
@ PUBLIC_IDENTITY
Public Resolved Identity Address.
static jau::snsize_t indexOf(const uint8_t haystack_b[], const jau::nsize_t haystack_length, const uint8_t needle_b[], const jau::nsize_t needle_length) noexcept
Find index of needle within haystack.
static const EUI48Sub ALL_DEVICE
EUI48 MAC address matching all device, i.e.
void clear()
Method clears the underlying byte array b and cached hash value.
static const BDAddressAndType ANY_BREDR_DEVICE
Using EUI48::ANY_DEVICE and BDAddressType::BDADDR_BREDR to match any BREDR device.
std::size_t operator()(direct_bt::BDAddressAndType const &a) const noexcept
@ RESOLVABLE_OR_PUBLIC
Controller Resolved Private Address or Public Address.
jau::nsize_t length
The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
void clearHash()
Method clears the cached hash value.
static const EUI48Sub LOCAL_DEVICE
EUI48 MAC address matching local device, i.e.
EUI48Sub & operator=(EUI48Sub &&o) noexcept=default
@ RANDOM
Random Device Address.
HCILEOwnAddressType to_HCILEOwnAddressType(const BDAddressType addrType) noexcept
constexpr std::size_t hash_code() const noexcept
BDAddressAndType & operator=(BDAddressAndType &&o) noexcept
constexpr uint8_t number(const BDAddressType rhs) noexcept
jau::snsize_t indexOf(const EUI48Sub &needle) const noexcept
Finds the index of given EUI48Sub needle within this instance haystack.
BDAddressAndType(const EUI48 &address_, BDAddressType type_)
std::size_t operator()(direct_bt::EUI48Sub const &a) const noexcept
@ STATIC_PUBLIC
Static public 'random' device address 0b11.
@ RESOLVABLE_PRIVAT
Resolvable private random device address 0b01.
@ RANDOM
Random Device Address.
std::string to_string(const BDAddressType type) noexcept
@ UNRESOLVABLE_PRIVAT
Non-resolvable private random device address 0b00.
BDAddressType
BT Core Spec v5.2: Vol 3, Part C Generic Access Profile (GAP): 15.1.1.1 Public Bluetooth address.
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
@ BDADDR_LE_RANDOM
Bluetooth LE random address, see BLERandomAddressType.
@ PUBLIC
Public Device Address.
@ UNDEFINED
HCIADDR_UNDEFINED.
@ UNDEFINED
Undefined, e.g.
@ RESOLVABLE_OR_RANDOM
Controller Resolved Private Address or Random Address.
constexpr bool isLEAddress() const noexcept
Returns true if the BDAddressType is a LE address type.
@ RESERVED
Reserved for future use 0b10.
EUI48Sub(EUI48Sub &&o) noexcept=default
bool operator!=(const EUI48Sub &lhs, const EUI48Sub &rhs) noexcept
bool matches(const BDAddressAndType &o) const noexcept
Returns true if both devices match, i.e.
HCILEPeerAddressType
HCI LE Address-Type is PUBLIC: 0x00, RANDOM: 0x01.
@ BDADDR_LE_PUBLIC
Bluetooth LE public address.
Unique Bluetooth EUI48 address and BDAddressType tuple.
@ BDADDR_BREDR
Bluetooth BREDR address.
constexpr EUI48Sub & operator=(const EUI48Sub &o) noexcept=default
@ BDADDR_UNDEFINED
Undefined.