22
22
#include < string.h>
23
23
#include " ble/SafeEnum.h"
24
24
#include " ble/ArrayView.h"
25
+ #include " ble/gap/Types.h"
25
26
26
27
/* *
27
28
* @addtogroup ble
32
33
33
34
namespace ble {
34
35
36
+ /* * Special advertising set handle used for the legacy advertising set. */
37
+ static const advertising_handle_t LEGACY_ADVERTISING_HANDLE = 0x00 ;
38
+
39
+ /* * Special advertising set handle used as return or parameter to signify an invalid handle. */
40
+ static const advertising_handle_t INVALID_ADVERTISING_HANDLE = 0xFF ;
41
+
42
+ /* * Maximum advertising data length that can fit in a legacy PDU. */
43
+ static const uint8_t LEGACY_ADVERTISING_MAX_SIZE = 0x1F ;
44
+
45
+ /* * Features supported by the controller.
46
+ * @see BLUETOOTH SPECIFICATION Version 5.0 | Vol 6, Part B - 4.6 */
47
+ struct controller_supported_features_t : SafeEnum<controller_supported_features_t , uint8_t > {
48
+ enum type {
49
+ LE_ENCRYPTION = 0 ,
50
+ CONNECTION_PARAMETERS_REQUEST_PROCEDURE,
51
+ EXTENDED_REJECT_INDICATION,
52
+ SLAVE_INITIATED_FEATURES_EXCHANGE,
53
+ LE_PING,
54
+ LE_DATA_PACKET_LENGTH_EXTENSION,
55
+ LL_PRIVACY,
56
+ EXTENDED_SCANNER_FILTER_POLICIES,
57
+ LE_2M_PHY,
58
+ STABLE_MODULATION_INDEX_TRANSMITTER,
59
+ STABLE_MODULATION_INDEX_RECEIVER,
60
+ LE_CODED_PHY,
61
+ LE_EXTENDED_ADVERTISING,
62
+ LE_PERIODIC_ADVERTISING,
63
+ CHANNEL_SELECTION_ALGORITHM_2,
64
+ LE_POWER_CLASS
65
+ };
66
+
67
+ /* *
68
+ * Construct a new instance of ControllerSupportedFeatures_t.
69
+ */
70
+ controller_supported_features_t (type value) : SafeEnum(value) { }
71
+ };
72
+
35
73
/* *
36
74
* Opaque reference to a connection.
37
75
*
@@ -48,7 +86,6 @@ typedef uintptr_t connection_handle_t;
48
86
*/
49
87
typedef uint16_t attribute_handle_t ;
50
88
51
-
52
89
/* *
53
90
* Inclusive range of GATT attributes handles.
54
91
*
@@ -284,6 +321,10 @@ void set_all_zeros(byte_array_class &byte_array) {
284
321
memset (&byte_array[0 ], 0x00 , byte_array.size ());
285
322
}
286
323
324
+ /* *
325
+ * Model fixed size array values.
326
+ * @tparam array_size The size of the array.
327
+ */
287
328
template <size_t array_size>
288
329
struct byte_array_t {
289
330
/* *
@@ -556,7 +597,12 @@ struct peer_address_type_t :SafeEnum<peer_address_type_t, uint8_t> {
556
597
/* *
557
598
* A Random static address used as a device identity address.
558
599
*/
559
- RANDOM_STATIC_IDENTITY
600
+ RANDOM_STATIC_IDENTITY,
601
+
602
+ /* *
603
+ * No address provided (anonymous advertisement).
604
+ */
605
+ ANONYMOUS = 0xFF
560
606
};
561
607
562
608
/* *
@@ -578,6 +624,13 @@ struct peer_address_type_t :SafeEnum<peer_address_type_t, uint8_t> {
578
624
struct phy_t : SafeEnum<phy_t , uint8_t > {
579
625
/* * struct scoped enum wrapped by the class */
580
626
enum type {
627
+ /* *
628
+ * No phy selected.
629
+ *
630
+ * @note This value can be used to indicate the absence of phy
631
+ */
632
+ NONE = 0 ,
633
+
581
634
/* *
582
635
* 1Mbit/s LE.
583
636
*
@@ -625,6 +678,8 @@ struct phy_t : SafeEnum<phy_t, uint8_t> {
625
678
*/
626
679
phy_t (type value) :
627
680
SafeEnum<phy_t , uint8_t >(value) { }
681
+
682
+ explicit phy_t (uint8_t raw_value) : SafeEnum(raw_value) { }
628
683
};
629
684
630
685
/* *
@@ -658,16 +713,36 @@ class phy_set_t {
658
713
* @param phy_2m Prefer LE 2M if avaiable
659
714
* @param phy_coded Prefer coded modulation if avaiable
660
715
*/
661
- phy_set_t (
662
- bool phy_1m,
663
- bool phy_2m,
664
- bool phy_coded
665
- ) {
716
+ phy_set_t (bool phy_1m, bool phy_2m, bool phy_coded) :
717
+ _value ()
718
+ {
666
719
set_1m (phy_1m);
667
720
set_2m (phy_2m);
668
721
set_coded (phy_coded);
669
722
}
670
723
724
+ /* *
725
+ * Create a set from a single phy.
726
+ *
727
+ * @param phy The phy to add to the set.
728
+ */
729
+ phy_set_t (phy_t phy) : _value()
730
+ {
731
+ switch (phy.value ()) {
732
+ case phy_t ::LE_1M:
733
+ set_1m (true );
734
+ break ;
735
+ case phy_t ::LE_2M:
736
+ set_2m (true );
737
+ break ;
738
+ case phy_t ::LE_CODED:
739
+ set_coded (true );
740
+ break ;
741
+ default :
742
+ break ;
743
+ }
744
+ }
745
+
671
746
/* * Prefer 1M PHY. */
672
747
void set_1m (bool enabled = true ) {
673
748
if (enabled) {
@@ -715,6 +790,10 @@ class phy_set_t {
715
790
return _value;
716
791
}
717
792
793
+ uint8_t count () const {
794
+ return (get_1m () ? 1 : 0 ) + (get_2m () ? 1 : 0 ) + (get_coded () ? 1 : 0 );
795
+ }
796
+
718
797
private:
719
798
uint8_t _value;
720
799
};
0 commit comments