Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
BTAddress.hpp
Go to the documentation of this file.
1 /*
2  * Author: Sven Gothel <sgothel@jausoft.com>
3  * Copyright (c) 2021 Gothel Software e.K.
4  * Copyright (c) 2020 ZAFENA AB
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining
7  * a copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sublicense, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 #ifndef BT_ADDRESS_HPP_
27 #define BT_ADDRESS_HPP_
28 
29 #include <cstring>
30 #include <string>
31 #include <cstdint>
32 #include <functional>
33 
34 #include <jau/packed_attribute.hpp>
35 #include <jau/ordered_atomic.hpp>
36 
37 namespace direct_bt {
38 
39  /**
40  * BT Core Spec v5.2: Vol 3, Part C Generic Access Profile (GAP): 15.1.1.1 Public Bluetooth address
41  * <pre>
42  * 1) BT public address used as BD_ADDR for BR/EDR physical channel is defined in Vol 2, Part B 1.2
43  * - EUI-48 or MAC (6 octets)
44  *
45  * 2) BT public address used as BD_ADDR for the LE physical channel is defined in Vol 6, Part B 1.3
46  * BT Core Spec v5.2: Vol 3, Part C Generic Access Profile (GAP): 15.1.1.2 Random Bluetooth address
47  *
48  * 3) BT random address used as BD_ADDR on the LE physical channel is defined in Vol 3, Part C 10.8
49  * </pre>
50  */
51  enum class BDAddressType : uint8_t {
52  /** Bluetooth BREDR address */
53  BDADDR_BREDR = 0x00,
54  /** Bluetooth LE public address */
55  BDADDR_LE_PUBLIC = 0x01,
56  /** Bluetooth LE random address, see {@link BLERandomAddressType} */
57  BDADDR_LE_RANDOM = 0x02,
58  /** Undefined */
59  BDADDR_UNDEFINED = 0xff
60  };
61  constexpr BDAddressType to_BDAddressType(const uint8_t v) noexcept {
62  if( v <= 2 ) {
63  return static_cast<BDAddressType>(v);
64  }
66  }
67  constexpr uint8_t number(const BDAddressType rhs) noexcept {
68  return static_cast<uint8_t>(rhs);
69  }
70  std::string to_string(const BDAddressType type) noexcept;
71 
72  /**
73  * BT Core Spec v5.2: Vol 6 LE, Part B Link Layer Specification: 1.3 Device Address
74  * <p>
75  * BT Core Spec v5.2: Vol 6 LE, Part B Link Layer Specification: 1.3.2 Random device Address
76  * </p>
77  * <p>
78  * Table 1.2, address bits [47:46]
79  * </p>
80  * <p>
81  * If {@link BDAddressType} is {@link BDAddressType::BDADDR_LE_RANDOM},
82  * its value shall be different than {@link BLERandomAddressType::UNDEFINED}.
83  * </p>
84  * <p>
85  * If {@link BDAddressType} is not {@link BDAddressType::BDADDR_LE_RANDOM},
86  * its value shall be {@link BLERandomAddressType::UNDEFINED}.
87  * </p>
88  */
89  enum class BLERandomAddressType : uint8_t {
90  /** Non-resolvable private random device address 0b00 */
91  UNRESOLVABLE_PRIVAT = 0x00,
92  /** Resolvable private random device address 0b01 */
93  RESOLVABLE_PRIVAT = 0x01,
94  /** Reserved for future use 0b10 */
95  RESERVED = 0x02,
96  /** Static public 'random' device address 0b11 */
97  STATIC_PUBLIC = 0x03,
98  /** Undefined, e.g. address not of type {@link BDAddressType::BDADDR_LE_RANDOM} */
99  UNDEFINED = 0xff
100  };
101  constexpr uint8_t number(const BLERandomAddressType rhs) noexcept { return static_cast<uint8_t>(rhs); }
102  std::string to_string(const BLERandomAddressType type) noexcept;
103 
104  /**
105  * HCI LE Address-Type is PUBLIC: 0x00, RANDOM: 0x01
106  * <p>
107  * BT Core Spec v5.2: Vol 4, Part E Host Controller Interface (HCI) Functionality:
108  * <pre>
109  * > 7.8.5: LE Set Advertising Parameters command
110  * -- Own_Address_Type: public: 0x00 (default), random: 0x01, resolvable-1: 0x02, resolvable-2: 0x03
111  * > 7.8.10: LE Set Scan Parameters command
112  * -- Own_Address_Type: public: 0x00 (default), random: 0x01, resolvable-1: 0x02, resolvable-2: 0x03
113  * > 7.8.12: LE Create Connection command
114  * -- Own_Address_Type: public: 0x00 (default), random: 0x01,
115  * Public Identity Address (resolvable-1, any not supporting LE_Set_Privacy_Mode command): 0x02,
116  * Random (static) Identity Address (resolvable-2, any not supporting LE_Set_Privacy_Mode command): 0x03
117  * </pre>
118  * </p>
119  */
120  enum class HCILEPeerAddressType : uint8_t {
121  /** Public Device Address */
122  PUBLIC = 0x00,
123  /** Random Device Address */
124  RANDOM = 0x01,
125  /** Public Resolved Identity Address */
126  PUBLIC_IDENTITY = 0x02,
127  /** Resolved Random (Static) Identity Address */
128  RANDOM_STATIC_IDENTITY = 0x03,
129  UNDEFINED = 0xff /**< HCIADDR_UNDEFINED */
130  };
131  constexpr uint8_t number(const HCILEPeerAddressType rhs) noexcept { return static_cast<uint8_t>(rhs); }
132  BDAddressType to_BDAddressType(const HCILEPeerAddressType hciPeerAddrType) noexcept;
133  std::string to_string(const HCILEPeerAddressType type) noexcept;
134 
135  enum class HCILEOwnAddressType : uint8_t {
136  /** Public Device Address */
137  PUBLIC = 0x00,
138  /** Random Device Address */
139  RANDOM = 0x01,
140  /** Controller Resolved Private Address or Public Address */
141  RESOLVABLE_OR_PUBLIC = 0x02,
142  /** Controller Resolved Private Address or Random Address */
143  RESOLVABLE_OR_RANDOM = 0x03,
144  UNDEFINED = 0xff
145  };
146  constexpr uint8_t number(const HCILEOwnAddressType rhs) noexcept { return static_cast<uint8_t>(rhs); }
147  BDAddressType to_BDAddressType(const HCILEOwnAddressType hciOwnAddrType) noexcept;
149  std::string to_string(const HCILEOwnAddressType type) noexcept;
150 
151  /**
152  * A 48 bit EUI-48 sub-identifier, see EUI48.
153  */
154  struct EUI48Sub {
155  /** EUI48 MAC address matching any device, i.e. `0:0:0:0:0:0`. */
156  static const EUI48Sub ANY_DEVICE;
157  /** EUI48 MAC address matching all device, i.e. `ff:ff:ff:ff:ff:ff`. */
158  static const EUI48Sub ALL_DEVICE;
159  /** EUI48 MAC address matching local device, i.e. `0:0:0:ff:ff:ff`. */
160  static const EUI48Sub LOCAL_DEVICE;
161 
162  /**
163  * The <= 6 byte EUI48 sub-address.
164  */
165  uint8_t b[6]; // == sizeof(EUI48)
166 
167  /**
168  * The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
169  */
171 
172  constexpr EUI48Sub() noexcept : b{0}, length{0} { }
173  EUI48Sub(const uint8_t * b_, const jau::nsize_t len_) noexcept;
174 
175  /**
176  * Fills given EUI48Sub instance via given string representation.
177  * <p>
178  * Implementation is consistent with EUI48Sub::toString().
179  * </p>
180  * @param str a string of less or equal of 17 characters representing less or equal of 6 bytes as hexadecimal numbers separated via colon,
181  * e.g. `01:02:03:0A:0B:0C`, `01:02:03:0A`, `:`, (empty).
182  * @param dest EUI48Sub to set its value
183  * @param errmsg error parsing message if returning false
184  * @return true if successful, otherwise false
185  * @see EUI48Sub::EUI48Sub
186  * @see EUI48Sub::toString()
187  */
188  static bool scanEUI48Sub(const std::string& str, EUI48Sub& dest, std::string& errmsg);
189 
190  /**
191  * Construct a sub EUI48 via given string representation.
192  * <p>
193  * Implementation is consistent with EUI48Sub::toString().
194  * </p>
195  * @param str a string of less or equal of 17 characters representing less or equal of 6 bytes as hexadecimal numbers separated via colon,
196  * e.g. `01:02:03:0A:0B:0C`, `01:02:03:0A`, `:`, (empty).
197  * @see EUI48Sub::scanEUI48Sub()
198  * @see EUI48Sub::toString()
199  * @throws jau::IllegalArgumentException if given string doesn't comply with EUI48
200  */
201  EUI48Sub(const std::string& str);
202 
203  constexpr EUI48Sub(const EUI48Sub &o) noexcept = default;
204  EUI48Sub(EUI48Sub &&o) noexcept = default;
205  constexpr EUI48Sub& operator=(const EUI48Sub &o) noexcept = default;
206  EUI48Sub& operator=(EUI48Sub &&o) noexcept = default;
207 
208  constexpr std::size_t hash_code() const noexcept {
209  // 31 * x == (x << 5) - x
210  std::size_t h = length;
211  for(jau::nsize_t i=0; i<length; i++) {
212  h = ( ( h << 5 ) - h ) + b[i];
213  }
214  return h;
215  }
216 
217  /**
218  * Method clears the underlying byte array {@link #b} and sets length to zero.
219  */
220  void clear() {
221  b[0] = 0; b[1] = 0; b[2] = 0;
222  b[3] = 0; b[4] = 0; b[5] = 0;
223  length = 0;
224  }
225 
226  /**
227  * Find index of needle within haystack.
228  * @param haystack_b haystack data
229  * @param haystack_length haystack length
230  * @param needle_b needle data
231  * @param needle_length needle length
232  * @return index of first element of needle within haystack or -1 if not found. If the needle length is zero, 0 (found) is returned.
233  */
234  static jau::snsize_t indexOf(const uint8_t haystack_b[], const jau::nsize_t haystack_length,
235  const uint8_t needle_b[], const jau::nsize_t needle_length) noexcept;
236 
237  /**
238  * Finds the index of given EUI48Sub needle within this instance haystack.
239  * @param needle
240  * @return index of first element of needle within this instance haystack or -1 if not found. If the needle length is zero, 0 (found) is returned.
241  */
242  jau::snsize_t indexOf(const EUI48Sub& needle) const noexcept {
243  return indexOf(b, length, needle.b, needle.length);
244  }
245 
246  /**
247  * Returns true, if given EUI48Sub needle is contained in this instance haystack.
248  * <p>
249  * If the sub is zero, true is returned.
250  * </p>
251  */
252  bool contains(const EUI48Sub& needle) const noexcept {
253  return 0 <= indexOf(needle);
254  }
255 
256  /**
257  * Returns the EUI48 sub-string representation,
258  * less or equal 17 characters representing less or equal 6 bytes as upper case hexadecimal numbers separated via colon,
259  * e.g. `01:02:03:0A:0B:0C`, `01:02:03:0A`, `:`, (empty).
260  */
261  std::string toString() const noexcept;
262  };
263  inline std::string to_string(const EUI48Sub& a) noexcept { return a.toString(); }
264 
265  inline bool operator==(const EUI48Sub& lhs, const EUI48Sub& rhs) noexcept {
266  if( &lhs == &rhs ) {
267  return true;
268  }
269  if( lhs.length != rhs.length ) {
270  return false;
271  }
272  return !memcmp(&lhs.b, &rhs.b, lhs.length);
273  }
274 
275  inline bool operator!=(const EUI48Sub& lhs, const EUI48Sub& rhs) noexcept
276  { return !(lhs == rhs); }
277 
278 
279  /**
280  * A packed 48 bit EUI-48 identifier, formerly known as MAC-48
281  * or simply network device MAC address (Media Access Control address).
282  */
283  __pack ( struct EUI48 {
284  /** EUI48 MAC address matching any device, i.e. `0:0:0:0:0:0`. */
285  static const EUI48 ANY_DEVICE;
286  /** EUI48 MAC address matching all device, i.e. `ff:ff:ff:ff:ff:ff`. */
287  static const EUI48 ALL_DEVICE;
288  /** EUI48 MAC address matching local device, i.e. `0:0:0:ff:ff:ff`. */
289  static const EUI48 LOCAL_DEVICE;
290 
291  /**
292  * The 6 byte EUI48 address.
293  */
294  uint8_t b[6]; // == sizeof(EUI48)
295 
296  constexpr EUI48() noexcept : b{0} { }
297  EUI48(const uint8_t * b_) noexcept;
298 
299  /**
300  * Fills given EUI48 instance via given string representation.
301  * <p>
302  * Implementation is consistent with EUI48::toString().
303  * </p>
304  * @param str a string of exactly 17 characters representing 6 bytes as hexadecimal numbers separated via colon `01:02:03:0A:0B:0C`.
305  * @param dest EUI48 to set its value
306  * @param errmsg error parsing message if returning false
307  * @return true if successful, otherwise false
308  * @see EUI48::EUI48
309  * @see EUI48::toString()
310  */
311  static bool scanEUI48(const std::string& str, EUI48& dest, std::string& errmsg);
312 
313  /**
314  * Construct instance via given string representation.
315  * <p>
316  * Implementation is consistent with EUI48::toString().
317  * </p>
318  * @param str a string of exactly 17 characters representing 6 bytes as hexadecimal numbers separated via colon `01:02:03:0A:0B:0C`.
319  * @see EUI48::scanEUI48()
320  * @see EUI48::toString()
321  * @throws jau::IllegalArgumentException if given string doesn't comply with EUI48
322  */
323  EUI48(const std::string& str);
324 
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;
329 
330  constexpr std::size_t hash_code() const noexcept {
331  // 31 * x == (x << 5) - x
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];
338  return h;
339  }
340 
341  /**
342  * Method clears the underlying byte array {@link #b}.
343  */
344  void clear() {
345  b[0] = 0; b[1] = 0; b[2] = 0;
346  b[3] = 0; b[4] = 0; b[5] = 0;
347  }
348 
349  /**
350  * Returns the BLERandomAddressType.
351  * <p>
352  * If ::BDAddressType is ::BDAddressType::BDADDR_LE_RANDOM,
353  * method shall return a valid value other than ::BLERandomAddressType::UNDEFINED.
354  * </p>
355  * <p>
356  * If BDAddressType is not ::BDAddressType::BDADDR_LE_RANDOM,
357  * method shall return ::BLERandomAddressType::UNDEFINED.
358  * </p>
359  * @since 2.2.0
360  */
361  BLERandomAddressType getBLERandomAddressType(const BDAddressType addressType) const noexcept;
362 
363  /**
364  * Finds the index of given EUI48Sub needle within this instance haystack.
365  * @param needle
366  * @return index of first element of needle within this instance haystack or -1 if not found. If the needle length is zero, 0 (found) is returned.
367  */
368  jau::snsize_t indexOf(const EUI48Sub& needle) const noexcept {
369  return EUI48Sub::indexOf(b, sizeof(b), needle.b, needle.length);
370  }
371 
372  /**
373  * Returns true, if given EUI48Sub needle is contained in this instance haystack.
374  * <p>
375  * If the sub is zero, true is returned.
376  * </p>
377  */
378  bool contains(const EUI48Sub& needle) const noexcept {
379  return 0 <= indexOf(needle);
380  }
381 
382  /**
383  * Returns the EUI48 string representation,
384  * exactly 17 characters representing 6 bytes as upper case hexadecimal numbers separated via colon `01:02:03:0A:0B:0C`.
385  * @see EUI48::EUI48()
386  */
387  std::string toString() const noexcept;
388  } );
389  inline std::string to_string(const EUI48& a) noexcept { return a.toString(); }
390 
391  inline bool operator==(const EUI48& lhs, const EUI48& rhs) noexcept {
392  if( &lhs == &rhs ) {
393  return true;
394  }
395  //return !memcmp(&lhs, &rhs, sizeof(EUI48));
396  const uint8_t * a = lhs.b;
397  const uint8_t * b = rhs.b;
398  return a[0] == b[0] &&
399  a[1] == b[1] &&
400  a[2] == b[2] &&
401  a[3] == b[3] &&
402  a[4] == b[4] &&
403  a[5] == b[5];
404  }
405 
406  inline bool operator!=(const EUI48& lhs, const EUI48& rhs) noexcept
407  { return !(lhs == rhs); }
408 
409  /**
410  * Unique Bluetooth EUI48 address and ::BDAddressType tuple.
411  * <p>
412  * Bluetooth EUI48 address itself is not unique as it requires the ::BDAddressType bits.<br>
413  * E.g. there could be two devices with the same EUI48 address, one using ::BDAddressType::BDADDR_LE_PUBLIC
414  * and one using ::BDAddressType::BDADDR_LE_RANDOM being a ::BLERandomAddressType::RESOLVABLE_PRIVAT.
415  * </p>
416  */
418  public:
419  /** Using EUI48::ANY_DEVICE and ::BDAddressType::BDADDR_BREDR to match any BREDR device. */
421 
422  /**
423  * Using EUI48::ANY_DEVICE and ::BDAddressType::BDADDR_UNDEFINED to match any device.<br>
424  * This constant is suitable to {@link #matches(BDAddressAndType) any device.
425  */
427 
430 
431  private:
432  jau::relaxed_atomic_size_t hash = 0; // default 0, cache
433 
434  public:
435  BDAddressAndType(const EUI48 & address_, BDAddressType type_)
436  : address(address_), type(type_) {}
437 
438  constexpr BDAddressAndType() noexcept : address(), type{BDAddressType::BDADDR_UNDEFINED} { }
439  BDAddressAndType(const BDAddressAndType &o) noexcept : address(o.address), type(o.type) { }
441  address = std::move(o.address);
442  type = std::move(o.type);
443  }
444  constexpr BDAddressAndType& operator=(const BDAddressAndType &o) noexcept {
445  address = o.address;
446  type = o.type;
447  return *this;
448  }
450  address = std::move(o.address);
451  type = std::move(o.type);
452  return *this;
453  }
454 
455  /**
456  * Returns true if the BDAddressType is a LE address type.
457  */
458  constexpr bool isLEAddress() const noexcept {
460  }
461 
462  /**
463  * Returns true if the BDAddressType is a BREDR address type.
464  */
465  constexpr bool isBREDRAddress() const noexcept { return BDAddressType::BDADDR_BREDR == type; }
466 
467  /**
468  * Returns the BLERandomAddressType.
469  * <p>
470  * If type is ::BDAddressType::BDADDR_LE_RANDOM},
471  * method shall return a valid value other than ::BLERandomAddressType::UNDEFINED.
472  * </p>
473  * <p>
474  * If type is not ::BDAddressType::BDADDR_LE_RANDOM,
475  * method shall return ::BLERandomAddressType::UNDEFINED.
476  * </p>
477  * @since 2.0.0
478  */
480  return address.getBLERandomAddressType(type);
481  }
482 
483  /**
484  * Returns true if both devices match, i.e. equal address
485  * and equal type or at least one type is {@link BDAddressType#BDADDR_UNDEFINED}.
486  */
487  bool matches(const BDAddressAndType & o) const noexcept {
488  if(this == &o) {
489  return true;
490  }
491  return address == o.address &&
492  ( type == o.type ||
495  }
496 
497  /**
498  * Implementation uses a lock-free volatile cache.
499  */
500  std::size_t hash_code() const noexcept {
501  std::size_t h = hash;
502  if( 0 == h ) {
503  // 31 * x == (x << 5) - x
504  h = 31 + address.hash_code();
505  h = ((h << 5) - h) + number(type);
506  const_cast<BDAddressAndType *>(this)->hash = h;
507  }
508  return h;
509  }
510 
511  /**
512  * Method clears the cached hash value.
513  * @see #clear()
514  */
515  void clearHash() { hash = 0; }
516 
517  /**
518  * Method clears the underlying byte array {@link #b} and cached hash value.
519  * @see #clearHash()
520  */
521  void clear() {
522  hash = 0;
523  address.clear();
525  }
526 
527  std::string toString() const noexcept;
528  };
529  inline bool operator==(const BDAddressAndType& lhs, const BDAddressAndType& rhs) noexcept {
530  if( &lhs == &rhs ) {
531  return true;
532  }
533  return lhs.address == rhs.address &&
534  lhs.type == rhs.type;
535  }
536  inline bool operator!=(const BDAddressAndType& lhs, const BDAddressAndType& rhs) noexcept
537  { return !(lhs == rhs); }
538 
539  inline std::string to_string(const BDAddressAndType& a) noexcept { return a.toString(); }
540 
541 } // namespace direct_bt
542 
543 // injecting specialization of std::hash to namespace std of our types above
544 namespace std
545 {
546  template<> struct hash<direct_bt::EUI48Sub> {
547  std::size_t operator()(direct_bt::EUI48Sub const& a) const noexcept {
548  return a.hash_code();
549  }
550  };
551 
552  template<> struct hash<direct_bt::EUI48> {
553  std::size_t operator()(direct_bt::EUI48 const& a) const noexcept {
554  return a.hash_code();
555  }
556  };
557 
558  template<> struct hash<direct_bt::BDAddressAndType> {
559  std::size_t operator()(direct_bt::BDAddressAndType const& a) const noexcept {
560  return a.hash_code();
561  }
562  };
563 }
564 
565 #endif /* BT_ADDRESS_HPP_ */
direct_bt::BDAddressAndType::operator=
constexpr BDAddressAndType & operator=(const BDAddressAndType &o) noexcept
Definition: BTAddress.hpp:444
std::hash< direct_bt::EUI48 >::operator()
std::size_t operator()(direct_bt::EUI48 const &a) const noexcept
Definition: BTAddress.hpp:553
direct_bt::EUI48Sub::contains
bool contains(const EUI48Sub &needle) const noexcept
Returns true, if given EUI48Sub needle is contained in this instance haystack.
Definition: BTAddress.hpp:252
direct_bt::EUI48Sub::clear
void clear()
Method clears the underlying byte array b and sets length to zero.
Definition: BTAddress.hpp:220
direct_bt::BDAddressAndType::BDAddressAndType
constexpr BDAddressAndType() noexcept
Definition: BTAddress.hpp:438
direct_bt::BDAddressAndType::BDAddressAndType
BDAddressAndType(BDAddressAndType &&o) noexcept
Definition: BTAddress.hpp:440
direct_bt::BDAddressAndType::ANY_DEVICE
static const BDAddressAndType ANY_DEVICE
Using EUI48::ANY_DEVICE and BDAddressType::BDADDR_UNDEFINED to match any device.
Definition: BTAddress.hpp:426
direct_bt::HCILEOwnAddressType::UNDEFINED
@ UNDEFINED
direct_bt::BDAddressAndType::hash_code
std::size_t hash_code() const noexcept
Implementation uses a lock-free volatile cache.
Definition: BTAddress.hpp:500
direct_bt::EUI48Sub::EUI48Sub
constexpr EUI48Sub(const EUI48Sub &o) noexcept=default
direct_bt::EUI48::getBLERandomAddressType
BLERandomAddressType getBLERandomAddressType(const BDAddressType addressType) const noexcept
Definition: BTTypes0.cpp:152
direct_bt::EUI48Sub::hash_code
constexpr std::size_t hash_code() const noexcept
Definition: BTAddress.hpp:208
packed_attribute.hpp
direct_bt::BDAddressAndType::getBLERandomAddressType
BLERandomAddressType getBLERandomAddressType() const noexcept
Returns the BLERandomAddressType.
Definition: BTAddress.hpp:479
direct_bt::EUI48Sub::toString
std::string toString() const noexcept
Returns the EUI48 sub-string representation, less or equal 17 characters representing less or equal 6...
Definition: BTTypes0.cpp:166
direct_bt::BDAddressAndType::BDAddressAndType
BDAddressAndType(const BDAddressAndType &o) noexcept
Definition: BTAddress.hpp:439
direct_bt::BLERandomAddressType
BLERandomAddressType
BT Core Spec v5.2: Vol 6 LE, Part B Link Layer Specification: 1.3 Device Address.
Definition: BTAddress.hpp:89
direct_bt
Definition: ATTPDUTypes.hpp:171
direct_bt::operator==
bool operator==(const EUI48Sub &lhs, const EUI48Sub &rhs) noexcept
Definition: BTAddress.hpp:265
direct_bt::EUI48Sub::ANY_DEVICE
static const EUI48Sub ANY_DEVICE
EUI48 MAC address matching any device, i.e.
Definition: BTAddress.hpp:156
direct_bt::HCILEPeerAddressType::RANDOM_STATIC_IDENTITY
@ RANDOM_STATIC_IDENTITY
Resolved Random (Static) Identity Address.
direct_bt::EUI48Sub::scanEUI48Sub
static bool scanEUI48Sub(const std::string &str, EUI48Sub &dest, std::string &errmsg)
Fills given EUI48Sub instance via given string representation.
Definition: BTTypes0.cpp:186
direct_bt::HCILEPeerAddressType::PUBLIC
@ PUBLIC
Public Device Address.
direct_bt::EUI48Sub::b
uint8_t b[6]
The <= 6 byte EUI48 sub-address.
Definition: BTAddress.hpp:165
direct_bt::EUI48Sub::EUI48Sub
constexpr EUI48Sub() noexcept
Definition: BTAddress.hpp:172
direct_bt::BDAddressAndType::isBREDRAddress
constexpr bool isBREDRAddress() const noexcept
Returns true if the BDAddressType is a BREDR address type.
Definition: BTAddress.hpp:465
direct_bt::to_BDAddressType
constexpr BDAddressType to_BDAddressType(const uint8_t v) noexcept
Definition: BTAddress.hpp:61
direct_bt::EUI48Sub
A 48 bit EUI-48 sub-identifier, see EUI48.
Definition: BTAddress.hpp:154
direct_bt::HCILEPeerAddressType::PUBLIC_IDENTITY
@ PUBLIC_IDENTITY
Public Resolved Identity Address.
direct_bt::EUI48Sub::indexOf
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.
Definition: BTTypes0.cpp:242
ordered_atomic.hpp
direct_bt::EUI48Sub::ALL_DEVICE
static const EUI48Sub ALL_DEVICE
EUI48 MAC address matching all device, i.e.
Definition: BTAddress.hpp:158
direct_bt::BDAddressAndType::clear
void clear()
Method clears the underlying byte array b and cached hash value.
Definition: BTAddress.hpp:521
jau::ordered_atomic< std::size_t, std::memory_order::memory_order_relaxed >
direct_bt::BDAddressAndType::ANY_BREDR_DEVICE
static const BDAddressAndType ANY_BREDR_DEVICE
Using EUI48::ANY_DEVICE and BDAddressType::BDADDR_BREDR to match any BREDR device.
Definition: BTAddress.hpp:420
std::hash< direct_bt::BDAddressAndType >::operator()
std::size_t operator()(direct_bt::BDAddressAndType const &a) const noexcept
Definition: BTAddress.hpp:559
direct_bt::HCILEOwnAddressType::RESOLVABLE_OR_PUBLIC
@ RESOLVABLE_OR_PUBLIC
Controller Resolved Private Address or Public Address.
direct_bt::BDAddressAndType::type
BDAddressType type
Definition: BTAddress.hpp:429
direct_bt::EUI48Sub::length
jau::nsize_t length
The actual length in bytes of the EUI48 sub-address, less or equal 6 bytes.
Definition: BTAddress.hpp:170
direct_bt::BDAddressAndType::clearHash
void clearHash()
Method clears the cached hash value.
Definition: BTAddress.hpp:515
direct_bt::EUI48Sub::LOCAL_DEVICE
static const EUI48Sub LOCAL_DEVICE
EUI48 MAC address matching local device, i.e.
Definition: BTAddress.hpp:160
direct_bt::EUI48Sub::operator=
EUI48Sub & operator=(EUI48Sub &&o) noexcept=default
direct_bt::HCILEOwnAddressType::RANDOM
@ RANDOM
Random Device Address.
direct_bt::to_HCILEOwnAddressType
HCILEOwnAddressType to_HCILEOwnAddressType(const BDAddressType addrType) noexcept
Definition: BTTypes0.cpp:89
direct_bt::EUI48::hash_code
constexpr std::size_t hash_code() const noexcept
Definition: BTAddress.hpp:388
direct_bt::BDAddressAndType::operator=
BDAddressAndType & operator=(BDAddressAndType &&o) noexcept
Definition: BTAddress.hpp:449
direct_bt::number
constexpr uint8_t number(const BDAddressType rhs) noexcept
Definition: BTAddress.hpp:67
direct_bt::EUI48Sub::indexOf
jau::snsize_t indexOf(const EUI48Sub &needle) const noexcept
Finds the index of given EUI48Sub needle within this instance haystack.
Definition: BTAddress.hpp:242
direct_bt::BDAddressAndType::BDAddressAndType
BDAddressAndType(const EUI48 &address_, BDAddressType type_)
Definition: BTAddress.hpp:435
std::hash< direct_bt::EUI48Sub >::operator()
std::size_t operator()(direct_bt::EUI48Sub const &a) const noexcept
Definition: BTAddress.hpp:547
direct_bt::BLERandomAddressType::STATIC_PUBLIC
@ STATIC_PUBLIC
Static public 'random' device address 0b11.
direct_bt::BLERandomAddressType::RESOLVABLE_PRIVAT
@ RESOLVABLE_PRIVAT
Resolvable private random device address 0b01.
direct_bt::HCILEPeerAddressType::RANDOM
@ RANDOM
Random Device Address.
direct_bt::to_string
std::string to_string(const BDAddressType type) noexcept
Definition: BTTypes0.cpp:129
direct_bt::BLERandomAddressType::UNRESOLVABLE_PRIVAT
@ UNRESOLVABLE_PRIVAT
Non-resolvable private random device address 0b00.
direct_bt::BDAddressType
BDAddressType
BT Core Spec v5.2: Vol 3, Part C Generic Access Profile (GAP): 15.1.1.1 Public Bluetooth address.
Definition: BTAddress.hpp:51
direct_bt::EUI48
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
Definition: BTAddress.hpp:388
direct_bt::BDAddressAndType::address
EUI48 address
Definition: BTAddress.hpp:428
jau::snsize_t
int_fast32_t snsize_t
Natural 'ssize_t' alternative using int_fast32_t as its natural sized type.
Definition: int_types.hpp:56
jau::nsize_t
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
Definition: int_types.hpp:44
direct_bt::BDAddressType::BDADDR_LE_RANDOM
@ BDADDR_LE_RANDOM
Bluetooth LE random address, see BLERandomAddressType.
direct_bt::HCILEOwnAddressType::PUBLIC
@ PUBLIC
Public Device Address.
direct_bt::HCILEPeerAddressType::UNDEFINED
@ UNDEFINED
HCIADDR_UNDEFINED.
direct_bt::BLERandomAddressType::UNDEFINED
@ UNDEFINED
Undefined, e.g.
direct_bt::HCILEOwnAddressType::RESOLVABLE_OR_RANDOM
@ RESOLVABLE_OR_RANDOM
Controller Resolved Private Address or Random Address.
direct_bt::BDAddressAndType::isLEAddress
constexpr bool isLEAddress() const noexcept
Returns true if the BDAddressType is a LE address type.
Definition: BTAddress.hpp:458
direct_bt::BLERandomAddressType::RESERVED
@ RESERVED
Reserved for future use 0b10.
direct_bt::EUI48Sub::EUI48Sub
EUI48Sub(EUI48Sub &&o) noexcept=default
direct_bt::operator!=
bool operator!=(const EUI48Sub &lhs, const EUI48Sub &rhs) noexcept
Definition: BTAddress.hpp:275
direct_bt::BDAddressAndType::matches
bool matches(const BDAddressAndType &o) const noexcept
Returns true if both devices match, i.e.
Definition: BTAddress.hpp:487
direct_bt::HCILEPeerAddressType
HCILEPeerAddressType
HCI LE Address-Type is PUBLIC: 0x00, RANDOM: 0x01.
Definition: BTAddress.hpp:120
direct_bt::BDAddressType::BDADDR_LE_PUBLIC
@ BDADDR_LE_PUBLIC
Bluetooth LE public address.
direct_bt::EUI48::clear
void clear()
Definition: BTAddress.hpp:388
direct_bt::BDAddressAndType
Unique Bluetooth EUI48 address and BDAddressType tuple.
Definition: BTAddress.hpp:417
direct_bt::BDAddressType::BDADDR_BREDR
@ BDADDR_BREDR
Bluetooth BREDR address.
direct_bt::HCILEOwnAddressType
HCILEOwnAddressType
Definition: BTAddress.hpp:135
direct_bt::EUI48Sub::operator=
constexpr EUI48Sub & operator=(const EUI48Sub &o) noexcept=default
direct_bt::BDAddressType::BDADDR_UNDEFINED
@ BDADDR_UNDEFINED
Undefined.