Mistake on this page?
Report an issue in GitHub or email us
common/BLETypes.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2020 ARM Limited
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef BLE_TYPES_H_
20 #define BLE_TYPES_H_
21 
22 #include <cstddef>
23 #include <cstdint>
24 #include <cstring>
25 
26 #include "platform/Span.h"
27 
28 #include "ble/common/SafeEnum.h"
29 #include "ble/gap/Types.h"
30 
31 /**
32  * @addtogroup ble
33  * @{
34  * @addtogroup common
35  * @{
36  */
37 
38 namespace ble {
39 
40 using mbed::Span;
41 using mbed::make_Span;
43 
44 /** Special advertising set handle used for the legacy advertising set. */
45 static const advertising_handle_t LEGACY_ADVERTISING_HANDLE = 0x00;
46 
47 /** Special advertising set handle used as return or parameter to signify an invalid handle. */
48 static const advertising_handle_t INVALID_ADVERTISING_HANDLE = 0xFF;
49 
50 /** Maximum advertising data length that can fit in a legacy PDU. */
51 static const uint8_t LEGACY_ADVERTISING_MAX_SIZE = 0x1F;
52 
53 /** Features supported by the controller.
54  * @see BLUETOOTH SPECIFICATION Version 5.0 | Vol 6, Part B - 4.6 */
55 struct controller_supported_features_t : SafeEnum<controller_supported_features_t, uint8_t> {
56  enum type {
57  LE_ENCRYPTION = 0,
58  CONNECTION_PARAMETERS_REQUEST_PROCEDURE,
59  EXTENDED_REJECT_INDICATION,
60  SLAVE_INITIATED_FEATURES_EXCHANGE,
61  LE_PING,
62  LE_DATA_PACKET_LENGTH_EXTENSION,
63  LL_PRIVACY,
64  EXTENDED_SCANNER_FILTER_POLICIES,
65  LE_2M_PHY,
66  STABLE_MODULATION_INDEX_TRANSMITTER,
67  STABLE_MODULATION_INDEX_RECEIVER,
68  LE_CODED_PHY,
69  LE_EXTENDED_ADVERTISING,
70  LE_PERIODIC_ADVERTISING,
71  CHANNEL_SELECTION_ALGORITHM_2,
72  LE_POWER_CLASS
73  };
74 
75  /**
76  * Construct a new instance of ControllerSupportedFeatures_t.
77  */
79 };
80 
81 /**
82  * Opaque reference to a connection.
83  *
84  * Internally a connection handle is an unsigned integer capable of holding a
85  * pointer.
86  *
87  * The real type (either a pointer to an object or an integer) is opaque for
88  * users and platform dependent.
89  */
90 typedef uintptr_t connection_handle_t;
91 
92 /**
93  * Reference to an attribute in a GATT database.
94  */
95 typedef uint16_t attribute_handle_t;
96 
97  /**
98  * Inclusive range of GATT attributes handles.
99  *
100  * @note Instances can be constructed with the help of the factory function
101  * attribute_handle_range().
102  */
104  /**
105  * Beginning of the range.
106  */
107  attribute_handle_t begin;
108 
109  /**
110  * End of the range.
111  */
112  attribute_handle_t end;
113 
114  /**
115  * Equal operator for attribute_handle_range_t.
116  *
117  * @param[in] lhs Left hand side of the expression.
118  * @param[in] rhs Right hand side of the expression.
119  *
120  * @return true if lhs is equal to rhs and false otherwise.
121  */
122  friend bool operator==(
124  ) {
125  return (lhs.begin == rhs.begin) && (lhs.end == rhs.end);
126  }
127 
128  /**
129  * Not equal operator for attribute_handle_range_t.
130  *
131  * @param[in] lhs Left hand side of the expression.
132  * @param[in] rhs Right hand side of the expression.
133  *
134  * @return true if lhs is not equal to rhs and false otherwise.
135  */
136  friend bool operator!=(
138  ) {
139  return !(lhs == rhs);
140  }
141 };
142 
143 
144 /**
145  * Construct an attribute_handle_range_t from its first and last attribute handle.
146  *
147  * @param[in] begin Handle at the beginning of the range.
148  * @param[in] end Handle at the end of the range.
149  *
150  * @return An instance of attribute_handle_range_t where
151  * attribute_handle_range_t::begin is equal to begin and
152  * attribute_handle_range_t::end is equal to end.
153  *
154  * @note This function is defined instead of a constructor to keep "POD-ness"
155  * of attribute_handle_range_t.
156  */
158  attribute_handle_t begin,
159  attribute_handle_t end
160 )
161 {
162  attribute_handle_range_t result = {
163  begin,
164  end
165  };
166  return result;
167 }
168 
169 /**
170  * Type that describes link's encryption state.
171  */
172 struct link_encryption_t : SafeEnum<link_encryption_t, uint8_t> {
173  /** struct scoped enum wrapped by the class */
174  enum type {
175  NOT_ENCRYPTED, /**< The link is not secured. */
176  ENCRYPTION_IN_PROGRESS, /**< Link security is being established. */
177  ENCRYPTED, /**< The link is secure. */
178  ENCRYPTED_WITH_MITM, /**< The link is secure and authenticated. */
179  ENCRYPTED_WITH_SC_AND_MITM /**< The link is secure and authenticated with a secure connection key. */
180  };
181 
182  /**
183  * Construct a new instance of link_encryption_t.
184  */
186 };
187 
188 /**
189  * Type that describe a pairing failure.
190  */
191 struct pairing_failure_t : SafeEnum<pairing_failure_t, uint8_t> {
192  /** struct scoped enum wrapped by the class */
193  enum type {
194  PASSKEY_ENTRY_FAILED = 0x01,
195  OOB_NOT_AVAILABLE = 0x02,
196  AUTHENTICATION_REQUIREMENTS = 0x03,
197  CONFIRM_VALUE_FAILED = 0x04,
198  PAIRING_NOT_SUPPORTED = 0x05,
199  ENCRYPTION_KEY_SIZE = 0x06,
200  COMMAND_NOT_SUPPORTED = 0x07,
201  UNSPECIFIED_REASON = 0x08,
202  REPEATED_ATTEMPTS = 0x09,
203  INVALID_PARAMETERS = 0x0A,
204  DHKEY_CHECK_FAILED = 0x0B,
205  NUMERIC_COMPARISON_FAILED = 0x0c,
206  BR_EDR_PAIRING_IN_PROGRESS = 0x0D,
207  CROSS_TRANSPORT_KEY_DERIVATION_OR_GENERATION_NOT_ALLOWED = 0x0E
208  };
209 
210  /**
211  * Construct a new instance of pairing_failure_t.
212  */
214 };
215 
216 
217 /**
218  * Type that describe the IO capability of a device; it is used during Pairing
219  * Feature exchange.
220  */
221 struct io_capability_t : SafeEnum<io_capability_t, uint8_t> {
222  enum type {
223  DISPLAY_ONLY = 0x00,
224  DISPLAY_YES_NO = 0x01,
225  KEYBOARD_ONLY = 0x02,
226  NO_INPUT_NO_OUTPUT = 0x03,
227  KEYBOARD_DISPLAY = 0x04
228  };
229 
230  /**
231  * Construct a new instance of io_capability_t.
232  */
233  io_capability_t(type value) : SafeEnum<io_capability_t, uint8_t>(value) { }
234 };
235 
236 /**
237  * Passkey stored as a number.
238  */
239 typedef uint32_t passkey_num_t;
240 
241 /**
242  * Passkey stored as a string of digits.
243  */
245 public:
246  static const uint8_t PASSKEY_LEN = 6;
247  static const uint8_t NUMBER_OFFSET = '0';
248 
249  /**
250  * Default to all zeroes
251  */
253  memset(ascii, NUMBER_OFFSET, PASSKEY_LEN);
254  }
255 
256  /**
257  * Initialize a data from a string.
258  *
259  * @param[in] passkey value of the data.
260  */
261  PasskeyAscii(const uint8_t* passkey) {
262  if (passkey) {
263  memcpy(ascii, passkey, PASSKEY_LEN);
264  } else {
265  memset(ascii, NUMBER_OFFSET, PASSKEY_LEN);
266  }
267  }
268 
269  /**
270  * Initialize a data from a number.
271  *
272  * @param[in] passkey value of the data.
273  */
274  PasskeyAscii(passkey_num_t passkey) {
275 #if BLE_PASSKEY_DISPLAY_REVERSED_DIGITS_DEPRECATION
276  for (int i = 5, m = 100000; i >= 0; --i, m /= 10) {
277 #else
278  for (int i = 0, m = 100000; i < PASSKEY_LEN; ++i, m /= 10) {
279 #endif //BLE_PASSKEY_DISPLAY_REVERSED_DIGITS_DEPRECATION
280  uint32_t result = passkey / m;
281  ascii[i] = NUMBER_OFFSET + result;
282  passkey -= result * m;
283  }
284  }
285 
286  /**
287  * Cast to number.
288  */
289  operator passkey_num_t() {
290  return to_num(ascii);
291  }
292 
293  /**
294  * Convert ASCII string of digits into a number.
295  * @param[in] ascii ASCII string of 6 digits stored as ASCII characters
296  * @return Passkey as a number.
297  */
298  static uint32_t to_num(const uint8_t *ascii) {
299  uint32_t passkey = 0;
300  for (size_t i = 0, m = 1; i < PASSKEY_LEN; ++i, m *= 10) {
301  passkey += (ascii[i] - NUMBER_OFFSET) * m;
302  }
303  return passkey;
304  }
305 
306  /**
307  * Return the pointer to the buffer holding the string.
308  */
309  uint8_t* value() {
310  return ascii;
311  }
312 private:
313  uint8_t ascii[PASSKEY_LEN];
314 };
315 
316 /**
317  * Returns true if every byte is equal to zero
318  */
319 template <class byte_array_class>
320 bool is_all_zeros(byte_array_class &byte_array)
321 {
322  for (size_t i = 0; i < byte_array.size(); i++) {
323  if (byte_array[i] != 0) {
324  return false;
325  }
326  }
327  return true;
328 }
329 
330 /**
331  * Zero out all bytes
332  */
333 template <class byte_array_class>
334 void set_all_zeros(byte_array_class &byte_array)
335 {
336  memset(&byte_array[0], 0x00, byte_array.size());
337 }
338 
339 /**
340  * Model fixed size array values.
341  * @tparam array_size The size of the array.
342  */
343 template <size_t array_size>
344 struct byte_array_t {
345  /**
346  * Size of the array; accessible at compile time.
347  */
348  static const size_t size_ = array_size;
349 
350  /**
351  * Default to all zeroes
352  */
354  memset(_value, 0x00, sizeof(_value));
355  }
356 
357  /**
358  * Initialize a data from an array of bytes.
359  *
360  * @param[in] input_value value of the data.
361  */
362  byte_array_t(const uint8_t *input_value) {
363  memcpy(_value, input_value, sizeof(_value));
364  }
365 
366  /**
367  * Initialize a data from an buffer of bytes.
368  *
369  * @param[in] input_value pointer to buffer.
370  * @param[in] size buffer size
371  */
372  byte_array_t(const uint8_t* input_value, size_t size) {
373  memcpy(_value, input_value, size);
374  }
375 
376  /**
377  * Equal operator between two octet types.
378  */
379  friend bool operator==(const byte_array_t& lhs, const byte_array_t& rhs) {
380  return memcmp(lhs._value, rhs._value, sizeof(lhs._value)) == 0;
381  }
382 
383  /**
384  * Non equal operator between two octet types.
385  */
386  friend bool operator!=(const byte_array_t& lhs, const byte_array_t& rhs) {
387  return !(lhs == rhs);
388  }
389 
390  /**
391  * Subscript operator to access data content
392  */
393  uint8_t& operator[](size_t i) {
394  return _value[i];
395  }
396 
397  /**
398  * Subscript operator to access data content
399  */
400  uint8_t operator[](size_t i) const {
401  return _value[i];
402  }
403 
404  /**
405  * Return the pointer to the buffer holding data.
406  */
407  const uint8_t* data() const {
408  return _value;
409  }
410 
411  /**
412  * Return the pointer to the buffer holding data.
413  */
414  uint8_t* data() {
415  return _value;
416  }
417 
418  /**
419  * Size in byte of a data.
420  */
421  static size_t size() {
422  return array_size;
423  }
424 
425 protected:
426  uint8_t _value[array_size];
427 };
428 
429 /**
430  * Construct a fixed size Span from a byte_array_t.
431  *
432  * @param src byte_array_t to create a Span from.
433  *
434  * @return A Span to @p src.
435  */
436 template<size_t Size>
438 {
439  return Span<uint8_t, Size>(src.data(), src.size());
440 }
441 
442 /**
443  * Construct a fixed size Span from a const byte_array_t.
444  *
445  * @param src byte_array_t to create a Span from.
446  *
447  * @return A Span to @p src.
448  */
449 template<size_t Size>
451 {
452  return Span<const uint8_t, Size>(src.data(), src.size());
453 }
454 
455 /** 128 bit keys used by paired devices */
457 typedef byte_array_t<16> csrk_t;
458 typedef byte_array_t<16> ltk_t;
459 
460 /** Used to identify LTK for legacy pairing connections */
462 typedef byte_array_t<8> rand_t;
463 
464 /** Out of band data exchanged during pairing */
465 typedef byte_array_t<16> oob_tk_t; /**< legacy pairing TK */
466 typedef byte_array_t<16> oob_lesc_value_t; /**< secure connections oob random 128 value */
467 typedef byte_array_t<16> oob_confirm_t; /**< secure connections oob confirmation value */
468 
469 /** data to be encrypted */
471 
472 /** public key coordinate, two of which define the public key */
474 
475 /** Diffie-Hellman key */
477 
478 /** counter for signed data writes done by GattClient */
479 typedef uint32_t sign_count_t;
480 
481 /**
482  * MAC address data type.
483  */
484 struct address_t : public byte_array_t<6> {
485  /**
486  * Create an invalid mac address, equal to 00:00:00:00:00:00
487  */
489  memset(_value, 0x00, sizeof(_value));
490  }
491 
492  /**
493  * Initialize a data from an array of bytes.
494  *
495  * @param[in] input_value value of the data.
496  */
497  address_t(const uint8_t *input_value) {
498  memcpy(_value, input_value, sizeof(_value));
499  }
500 };
501 
502 /**
503  * Type that describes a random device address type.
504  */
505 struct random_address_type_t : SafeEnum<random_address_type_t, uint8_t> {
506  /** struct scoped enum wrapped by the class */
507  enum type {
508  STATIC, /**< Random static device address. */
509  NON_RESOLVABLE_PRIVATE, /**< Random non resolvable private address. */
510  RESOLVABLE_PRIVATE /**< Random resolvable private address. */
511  };
512 
513  /**
514  * Construct a new instance of random_address_type_t.
515  */
517  SafeEnum<random_address_type_t, uint8_t>(value) { }
518 };
519 
520 /**
521  * Security requirement that can be attached to an attribute operation.
522  */
523 struct att_security_requirement_t : SafeEnum<att_security_requirement_t, uint8_t> {
524  /**
525  * Number of bits required to store the value.
526  *
527  * This value can be used to define a bitfield that host a value of this
528  * enum.
529  */
530  static const uint8_t size = 2;
531 
532  /** struct scoped enum wrapped by the class */
533  enum type {
534  /**
535  * The operation does not have security requirements.
536  *
537  * It is equivalent to: SecurityMode 1 level 1: No authentication, no
538  * encryption and no signing required.
539  *
540  * @note This security mode is not applicable for signed operation.
541  *
542  * @note Equivalent to SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK.
543  */
545 
546  /**
547  * The operation requires security and there's no requirement towards
548  * peer authentication.
549  *
550  * @note Security can be achieved either by signing messages or
551  * encrypting the link.
552  *
553  * @note Signing is only applicable for signed write operations.
554  *
555  * @note Equivalent to SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM
556  * or SecurityManager::SECURITY_MODE_SIGNED_NO_MITM.
557  */
559 
560  /**
561  * The operation requires security and the peer must be authenticated.
562  *
563  * @note Security can be achieved either by signing messages or
564  * encrypting the link.
565  *
566  * @note Equivalent to SecurityManager::SECURITY_MODE_ENCRYPTION_WITH_MITM
567  * or SecurityManager::SECURITY_MODE_SIGNED_WITH_MITM.
568  */
570 
571  /**
572  * The operation require encryption with an authenticated peer that
573  * paired using secure connection pairing.
574  *
575  * @note This security mode is not applicable for signed operation;
576  * security is achieved with link encryption.
577  */
578  SC_AUTHENTICATED
579  };
580 
581  /**
582  * Construct a new instance of att_security_requirement_t.
583  */
585  SafeEnum<att_security_requirement_t, uint8_t>(value) { }
586 };
587 
588 /**
589  * Type that describes a peer device address type.
590  */
591 struct peer_address_type_t :SafeEnum<peer_address_type_t, uint8_t> {
592  /** struct scoped enum wrapped by the class */
593  enum type {
594  /**
595  * Public device address.
596  */
597  PUBLIC = 0,
598 
599  /**
600  * Random address.
601  *
602  * Use Gap::getRandomAddressType to retrieve the type of the random
603  * address.
604  */
606 
607  /**
608  * A Public address used as a device identity address.
609  */
611 
612  /**
613  * A Random static address used as a device identity address.
614  */
616 
617  /**
618  * No address provided (anonymous advertisement).
619  */
620  ANONYMOUS = 0xFF
621  };
622 
623  /**
624  * Construct a new instance of peer_address_type_t.
625  */
627  SafeEnum<peer_address_type_t, uint8_t>(value) { }
628 
629  /**
630  * Default initialization of peer_address_type_t.
631  */
633  SafeEnum<peer_address_type_t, uint8_t>(PUBLIC) { }
634 };
635 
636 /**
637  * Type that describes a bluetooth PHY(sical) transport.
638  */
639 struct phy_t : SafeEnum<phy_t, uint8_t> {
640  /** struct scoped enum wrapped by the class */
641  enum type {
642  /**
643  * No phy selected.
644  *
645  * @note This value can be used to indicate the absence of phy
646  */
647  NONE = 0,
648 
649  /**
650  * 1Mbit/s LE.
651  *
652  * @note This physical transport was available since Bluetooth 4.0
653  */
654  LE_1M = 1,
655 
656  /**
657  * 2Mbit/s LE.
658  *
659  * Modulation is similar to LE_1M but differs in rate. Therefore range
660  * performances are in the same ballpark as LE_1M while the increased rate
661  * minimize time spent to transfer or receive a packet which leads to a
662  * better power consumption and/or faster transfer.
663  *
664  * @note This transport has been introduced with the Bluetooth 5.
665  * @note When operating at 2Mbit/s range is not exactly identical to the
666  * range at 1Mbit/s due to a loss in sensitivity.
667  */
668  LE_2M = 2,
669 
670  /**
671  * LE Coded PHY.
672  *
673  * This transport reuse the 1Mbit/s channel with different coding schemes.
674  * Either two (S=2) or eight (S=8) symbols can be used to represent a
675  * bit while the 1Mbit/s transport use 1 symbol to code 1 bit of data.
676  *
677  * Here is the data rate of the two coding schemes:
678  * - S=2: 500kbit/s
679  * - S=8: 125kbit/s
680  *
681  * The goal of the coded PHY is to increase the range of BLE devices.
682  * Of course given it takes more time to transfer data, transmission
683  * and reception last longer which leads to an increase in power
684  * consumption.
685  *
686  * @note This transport has been introduced with the Bluetooth 5.
687  */
688  LE_CODED
689  };
690 
691  /**
692  * Construct a new instance of phy_t.
693  */
695  SafeEnum<phy_t, uint8_t>(value) { }
696 
697  explicit phy_t(uint8_t raw_value) : SafeEnum(raw_value) { }
698 };
699 
700 /**
701  * Type that describe a set of PHY(sical) transports. This is used to
702  * indicate preference for the PHY transports set within it.
703  */
704 class phy_set_t {
705 public:
706  enum PhysFlags_t {
707  PHY_SET_1M = 0x01,
708  PHY_SET_2M = 0x02,
709  PHY_SET_CODED = 0x04
710  };
711 
712  /**
713  * Create set that indicates no preference.
714  */
715  phy_set_t() : _value(0) { }
716 
717  /**
718  * Create a set based on the mask specified in the Bluetooth spec.
719  *
720  * @param value Octet containing the set of preferred PHYs
721  */
722  phy_set_t(uint8_t value) : _value(value) { }
723 
724  /**
725  * Create a set based on individual settings.
726  *
727  * @param phy_1m Prefer LE 1M
728  * @param phy_2m Prefer LE 2M if avaiable
729  * @param phy_coded Prefer coded modulation if avaiable
730  */
731  phy_set_t(bool phy_1m, bool phy_2m, bool phy_coded) :
732  _value()
733  {
734  set_1m(phy_1m);
735  set_2m(phy_2m);
736  set_coded(phy_coded);
737  }
738 
739  /**
740  * Create a set from a single phy.
741  *
742  * @param phy The phy to add to the set.
743  */
744  phy_set_t(phy_t phy) : _value()
745  {
746  switch (phy.value()) {
747  case phy_t::LE_1M:
748  set_1m(true);
749  break;
750  case phy_t::LE_2M:
751  set_2m(true);
752  break;
753  case phy_t::LE_CODED:
754  set_coded(true);
755  break;
756  default:
757  break;
758  }
759  }
760 
761  /** Prefer 1M PHY. */
762  void set_1m(bool enabled = true) {
763  if (enabled) {
764  _value |= PHY_SET_1M;
765  } else {
766  _value &= ~PHY_SET_1M;
767  }
768  }
769 
770  /** Prefer 2M PHY. */
771  void set_2m(bool enabled = true) {
772  if (enabled) {
773  _value |= PHY_SET_2M;
774  } else {
775  _value &= ~PHY_SET_2M;
776  }
777  }
778 
779  /** Prefer coded PHY. */
780  void set_coded(bool enabled = true) {
781  if (enabled) {
782  _value |= PHY_SET_CODED;
783  } else {
784  _value &= ~PHY_SET_CODED;
785  }
786  }
787 
788  bool get_1m() const {
789  return (_value & PHY_SET_1M);
790  }
791 
792  bool get_2m() const {
793  return (_value & PHY_SET_2M);
794  }
795 
796  bool get_coded() const {
797  return (_value & PHY_SET_CODED);
798  }
799 
800  operator uint8_t() const {
801  return _value;
802  }
803 
804  uint8_t value() const {
805  return _value;
806  }
807 
808  uint8_t count() const {
809  return (get_1m() ? 1 : 0) + (get_2m() ? 1 : 0) + (get_coded() ? 1 : 0);
810  }
811 
812 private:
813  uint8_t _value;
814 };
815 
816 /**
817  * Type describing the number of symbols per bit in le coded PHY.
818  */
819 struct coded_symbol_per_bit_t :SafeEnum<coded_symbol_per_bit_t, uint8_t> {
820  /** struct scoped enum wrapped by the class */
821  enum type {
822  /**
823  * The Number of symbol used to code a bit is undefined.
824  */
826 
827  /**
828  * Two symbols to code a bit.
829  */
830  S2,
831 
832  /**
833  * Eight symbols to code a bit.
834  */
835  S8
836  };
837 
838  /**
839  * Construct a new instance of coded_symbol_per_bit_t.
840  */
842  SafeEnum<coded_symbol_per_bit_t, uint8_t>(value) { }
843 };
844 
845 
846 /**
847  * Representation of a whitelist of addresses.
848  */
849 struct whitelist_t {
850  /**
851  * BLE address representation.
852  *
853  * It contains an address-type (peer_address_type_t) and the address value
854  * (address_t).
855  */
856  struct entry_t {
857  /**
858  * Construct an entry_t object with the supplied type and address.
859  *
860  * @param[in] typeIn The peer address type.
861  * @param[in] addressIn The peer address.
862  *
863  * @post type is equal to typeIn and address is equal to the content
864  * present in addressIn.
865  */
866  entry_t(peer_address_type_t typeIn, const address_t &addressIn) :
867  type(typeIn),
868  address(addressIn)
869  { }
870 
871  /**
872  * Empty constructor.
873  *
874  * @note The address constructed with the empty constructor is not
875  * valid.
876  *
877  * @post type is equal to PUBLIC and the address value is equal to
878  * 00:00:00:00:00:00
879  */
880  entry_t() : type(), address() { }
881 
882  /**
883  * Type of the peer address.
884  */
886 
887  /**
888  * Value of the peer address.
889  */
891  };
892 
893  /**
894  * Pointer to the array of the addresses composing the whitelist.
895  */
897 
898  /**
899  * Number addresses in this whitelist.
900  */
901  uint8_t size;
902 
903  /**
904  * Capacity of the array holding the addresses.
905  */
906  uint8_t capacity;
907 };
908 
909 /** events sent and received when passkey is being entered */
911  KEYPRESS_STARTED, /**< Passkey entry started */
912  KEYPRESS_ENTERED, /**< Passkey digit entered */
913  KEYPRESS_ERASED, /**< Passkey digit erased */
914  KEYPRESS_CLEARED, /**< Passkey cleared */
915  KEYPRESS_COMPLETED, /**< Passkey entry completed */
916 };
917 
918 } // namespace ble
919 
920 /**
921  * @}
922  * @}
923  */
924 
925 #endif /* BLE_TYPES_H_ */
static const advertising_handle_t INVALID_ADVERTISING_HANDLE
Special advertising set handle used as return or parameter to signify an invalid handle.
Span< uint8_t, Size > make_Span(byte_array_t< Size > &src)
Construct a fixed size Span from a byte_array_t.
Passkey entry completed.
type
struct scoped enum wrapped by the class
byte_array_t(const uint8_t *input_value)
Initialize a data from an array of bytes.
byte_array_t< 32 > dhkey_t
Diffie-Hellman key.
byte_array_t()
Default to all zeroes.
phy_set_t(uint8_t value)
Create a set based on the mask specified in the Bluetooth spec.
address_t(const uint8_t *input_value)
Initialize a data from an array of bytes.
pairing_failure_t(type value)
Construct a new instance of pairing_failure_t.
uintptr_t connection_handle_t
Opaque reference to a connection.
random_address_type_t(type value)
Construct a new instance of random_address_type_t.
entry_t * addresses
Pointer to the array of the addresses composing the whitelist.
friend bool operator==(const attribute_handle_range_t &lhs, const attribute_handle_range_t &rhs)
Equal operator for attribute_handle_range_t.
address_t address
Value of the peer address.
Span< T, Extent > make_Span(T *elements)
Generate a Span from a pointer to a C/C++ array.
Definition: Span.h:1034
address_t()
Create an invalid mac address, equal to 00:00:00:00:00:00.
friend bool operator==(const byte_array_t &lhs, const byte_array_t &rhs)
Equal operator between two octet types.
coded_symbol_per_bit_t(type value)
Construct a new instance of coded_symbol_per_bit_t.
Type that describes a random device address type.
Model fixed size array values.
const uint8_t * data() const
Return the pointer to the buffer holding data.
Passkey cleared.
uint8_t * data()
Return the pointer to the buffer holding data.
Type describing the number of symbols per bit in le coded PHY.
Security requirement that can be attached to an attribute operation.
Span< const uint8_t, Size > make_const_Span(const byte_array_t< Size > &src)
Construct a fixed size Span from a const byte_array_t.
The Number of symbol used to code a bit is undefined.
The operation requires security and there&#39;s no requirement towards peer authentication.
Inclusive range of GATT attributes handles.
byte_array_t< 16 > encryption_block_t
data to be encrypted
phy_set_t()
Create set that indicates no preference.
entry_t()
Empty constructor.
peer_address_type_t(type value)
Construct a new instance of peer_address_type_t.
uint8_t value() const
Explicit access to the inner value of the SafeEnum instance.
uint8_t & operator[](size_t i)
Subscript operator to access data content.
Keypress_t
events sent and received when passkey is being entered
The operation does not have security requirements.
Representation of a whitelist of addresses.
entry_t(peer_address_type_t typeIn, const address_t &addressIn)
Construct an entry_t object with the supplied type and address.
peer_address_type_t()
Default initialization of peer_address_type_t.
type
struct scoped enum wrapped by the class
A Random static address used as a device identity address.
Helper class used to define safe enumerations.
byte_array_t(const uint8_t *input_value, size_t size)
Initialize a data from an buffer of bytes.
SafeEnum(uint8_t value)
Construction of an enumeration value.
controller_supported_features_t(type value)
Construct a new instance of ControllerSupportedFeatures_t.
void set_2m(bool enabled=true)
Prefer 2M PHY.
Passkey stored as a string of digits.
type
struct scoped enum wrapped by the class
byte_array_t< 16 > oob_tk_t
Out of band data exchanged during pairing.
static const advertising_handle_t LEGACY_ADVERTISING_HANDLE
Special advertising set handle used for the legacy advertising set.
Span< const T, Extent > make_const_Span(const T(&elements)[Extent])
Generate a Span to a const content from a reference to a C/C++ array.
Definition: Span.h:1073
MAC address data type.
Passkey entry started.
void set_all_zeros(byte_array_class &byte_array)
Zero out all bytes.
attribute_handle_t end
End of the range.
type
struct scoped enum wrapped by the class
PasskeyAscii(passkey_num_t passkey)
Initialize a data from a number.
Type that describes a bluetooth PHY(sical) transport.
io_capability_t(type value)
Construct a new instance of io_capability_t.
type
struct scoped enum wrapped by the class
Random non resolvable private address.
static const uint8_t LEGACY_ADVERTISING_MAX_SIZE
Maximum advertising data length that can fit in a legacy PDU.
byte_array_t< 32 > public_key_coord_t
public key coordinate, two of which define the public key
attribute_handle_t begin
Beginning of the range.
BLE address representation.
Nonowning view to a sequence of contiguous elements.
Definition: Span.h:215
PasskeyAscii(const uint8_t *passkey)
Initialize a data from a string.
Two symbols to code a bit.
uint8_t operator[](size_t i) const
Subscript operator to access data content.
byte_array_t< 16 > oob_lesc_value_t
secure connections oob random 128 value
static size_t size()
Size in byte of a data.
friend bool operator!=(const attribute_handle_range_t &lhs, const attribute_handle_range_t &rhs)
Not equal operator for attribute_handle_range_t.
phy_t(type value)
Construct a new instance of phy_t.
uint32_t sign_count_t
counter for signed data writes done by GattClient
Type that describes a peer device address type.
friend bool operator!=(const byte_array_t &lhs, const byte_array_t &rhs)
Non equal operator between two octet types.
Type that describe a set of PHY(sical) transports.
A Public address used as a device identity address.
byte_array_t< 2 > ediv_t
Used to identify LTK for legacy pairing connections.
phy_set_t(bool phy_1m, bool phy_2m, bool phy_coded)
Create a set based on individual settings.
Passkey digit entered.
att_security_requirement_t(type value)
Construct a new instance of att_security_requirement_t.
bool is_all_zeros(byte_array_class &byte_array)
Returns true if every byte is equal to zero.
uint8_t capacity
Capacity of the array holding the addresses.
static attribute_handle_range_t attribute_handle_range(attribute_handle_t begin, attribute_handle_t end)
Construct an attribute_handle_range_t from its first and last attribute handle.
type
struct scoped enum wrapped by the class
The operation requires security and the peer must be authenticated.
void set_1m(bool enabled=true)
Prefer 1M PHY.
uint8_t * value()
Return the pointer to the buffer holding the string.
phy_set_t(phy_t phy)
Create a set from a single phy.
peer_address_type_t type
Type of the peer address.
Type that describe a pairing failure.
byte_array_t< 16 > oob_confirm_t
secure connections oob confirmation value
void set_coded(bool enabled=true)
Prefer coded PHY.
Entry namespace for all BLE API definitions.
byte_array_t< 16 > irk_t
128 bit keys used by paired devices
static uint32_t to_num(const uint8_t *ascii)
Convert ASCII string of digits into a number.
uint16_t attribute_handle_t
Reference to an attribute in a GATT database.
Features supported by the controller.
Type that describe the IO capability of a device; it is used during Pairing Feature exchange...
uint32_t passkey_num_t
Passkey stored as a number.
Passkey digit erased.
Random static device address.
PasskeyAscii()
Default to all zeroes.
uint8_t size
Number addresses in this whitelist.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.