23 #include "ble/SafeEnum.h" 25 #include "ble/gap/Types.h" 50 CONNECTION_PARAMETERS_REQUEST_PROCEDURE,
51 EXTENDED_REJECT_INDICATION,
52 SLAVE_INITIATED_FEATURES_EXCHANGE,
54 LE_DATA_PACKET_LENGTH_EXTENSION,
56 EXTENDED_SCANNER_FILTER_POLICIES,
58 STABLE_MODULATION_INDEX_TRANSMITTER,
59 STABLE_MODULATION_INDEX_RECEIVER,
61 LE_EXTENDED_ADVERTISING,
62 LE_PERIODIC_ADVERTISING,
63 CHANNEL_SELECTION_ALGORITHM_2,
131 return !(lhs == rhs);
150 attribute_handle_t begin,
151 attribute_handle_t end
170 ENCRYPTED_WITH_SC_AND_MITM
185 PASSKEY_ENTRY_FAILED = 0x01,
186 OOB_NOT_AVAILABLE = 0x02,
187 AUTHENTICATION_REQUIREMENTS = 0x03,
188 CONFIRM_VALUE_FAILED = 0x04,
189 PAIRING_NOT_SUPPORTED = 0x05,
190 ENCRYPTION_KEY_SIZE = 0x06,
191 COMMAND_NOT_SUPPORTED = 0x07,
192 UNSPECIFIED_REASON = 0x08,
193 REPEATED_ATTEMPTS = 0x09,
194 INVALID_PARAMETERS = 0x0A,
195 DHKEY_CHECK_FAILED = 0x0B,
196 NUMERIC_COMPARISON_FAILED = 0x0c,
197 BR_EDR_PAIRING_IN_PROGRESS = 0x0D,
198 CROSS_TRANSPORT_KEY_DERIVATION_OR_GENERATION_NOT_ALLOWED = 0x0E
215 DISPLAY_YES_NO = 0x01,
216 KEYBOARD_ONLY = 0x02,
217 NO_INPUT_NO_OUTPUT = 0x03,
218 KEYBOARD_DISPLAY = 0x04
237 static const uint8_t PASSKEY_LEN = 6;
238 static const uint8_t NUMBER_OFFSET =
'0';
244 memset(ascii, NUMBER_OFFSET, PASSKEY_LEN);
254 memcpy(ascii, passkey, PASSKEY_LEN);
256 memset(ascii, NUMBER_OFFSET, PASSKEY_LEN);
266 for (
int i = 5, m = 100000; i >= 0; --i, m /= 10) {
267 uint32_t result = passkey / m;
268 ascii[i] = NUMBER_OFFSET + result;
269 passkey -= result * m;
277 return to_num(ascii);
285 static uint32_t
to_num(
const uint8_t *ascii) {
286 uint32_t passkey = 0;
287 for (
size_t i = 0, m = 1; i < PASSKEY_LEN; ++i, m *= 10) {
288 passkey += (ascii[i] - NUMBER_OFFSET) * m;
300 uint8_t ascii[PASSKEY_LEN];
306 template <
class byte_array_
class>
308 for (
size_t i = 0; i < byte_array.size(); i++) {
309 if (byte_array[i] != 0) {
319 template <
class byte_array_
class>
321 memset(&byte_array[0], 0x00, byte_array.size());
328 template <
size_t array_size>
333 static const size_t size_ = array_size;
339 memset(_value, 0x00,
sizeof(_value));
348 memcpy(_value, input_value,
sizeof(_value));
358 memcpy(_value, input_value, size);
365 return memcmp(lhs._value, rhs._value,
sizeof(lhs._value)) == 0;
372 return !(lhs == rhs);
411 uint8_t _value[array_size];
421 template<
size_t Size>
434 template<
size_t Size>
474 memset(_value, 0x00,
sizeof(_value));
483 memcpy(_value, input_value,
sizeof(_value));
515 static const uint8_t size = 2;
721 set_coded(phy_coded);
731 switch (phy.
value()) {
749 _value |= PHY_SET_1M;
751 _value &= ~PHY_SET_1M;
758 _value |= PHY_SET_2M;
760 _value &= ~PHY_SET_2M;
767 _value |= PHY_SET_CODED;
769 _value &= ~PHY_SET_CODED;
773 bool get_1m()
const {
774 return (_value & PHY_SET_1M);
777 bool get_2m()
const {
778 return (_value & PHY_SET_2M);
781 bool get_coded()
const {
782 return (_value & PHY_SET_CODED);
785 operator uint8_t()
const {
789 uint8_t
value()
const {
793 uint8_t count()
const {
794 return (get_1m() ? 1 : 0) + (get_2m() ? 1 : 0) + (get_coded() ? 1 : 0);
static const advertising_handle_t INVALID_ADVERTISING_HANDLE
Special advertising set handle used as return or parameter to signify an invalid handle.
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.
ArrayView< T, Size > make_ArrayView(T(&elements)[Size])
Generate an array view from a reference to a C/C++ array.
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.
The link is secure and authenticated.
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.
friend bool operator==(const attribute_handle_range_t &lhs, const attribute_handle_range_t &rhs)
Equal operator for attribute_handle_range_t.
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.
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.
Immutable view to an array.
The Number of symbol used to code a bit is undefined.
The operation requires security and there'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.
peer_address_type_t(type value)
Construct a new instance of peer_address_type_t.
link_encryption_t(type value)
Construct a new instance of link_encryption_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.
The operation does not have security requirements.
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.
Link security is being established.
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.
void set_all_zeros(byte_array_class &byte_array)
Zero out all bytes.
type
struct scoped enum wrapped by the class
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.
Type that describes link's encryption state.
uint8_t advertising_handle_t
Handle of an advertising set.
PasskeyAscii(const uint8_t *passkey)
Initialize a data from a string.
ArrayView< const T, Size > make_const_ArrayView(T(&elements)[Size])
Generate a const array view from a reference to a C/C++ array.
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.
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.
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.
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.
Random static device address.
PasskeyAscii()
Default to all zeroes.