23 #include "ble/SafeEnum.h" 24 #include "platform/Span.h" 25 #include "ble/gap/Types.h" 54 CONNECTION_PARAMETERS_REQUEST_PROCEDURE,
55 EXTENDED_REJECT_INDICATION,
56 SLAVE_INITIATED_FEATURES_EXCHANGE,
58 LE_DATA_PACKET_LENGTH_EXTENSION,
60 EXTENDED_SCANNER_FILTER_POLICIES,
62 STABLE_MODULATION_INDEX_TRANSMITTER,
63 STABLE_MODULATION_INDEX_RECEIVER,
65 LE_EXTENDED_ADVERTISING,
66 LE_PERIODIC_ADVERTISING,
67 CHANNEL_SELECTION_ALGORITHM_2,
135 return !(lhs == rhs);
154 attribute_handle_t begin,
155 attribute_handle_t end
174 ENCRYPTED_WITH_SC_AND_MITM
189 PASSKEY_ENTRY_FAILED = 0x01,
190 OOB_NOT_AVAILABLE = 0x02,
191 AUTHENTICATION_REQUIREMENTS = 0x03,
192 CONFIRM_VALUE_FAILED = 0x04,
193 PAIRING_NOT_SUPPORTED = 0x05,
194 ENCRYPTION_KEY_SIZE = 0x06,
195 COMMAND_NOT_SUPPORTED = 0x07,
196 UNSPECIFIED_REASON = 0x08,
197 REPEATED_ATTEMPTS = 0x09,
198 INVALID_PARAMETERS = 0x0A,
199 DHKEY_CHECK_FAILED = 0x0B,
200 NUMERIC_COMPARISON_FAILED = 0x0c,
201 BR_EDR_PAIRING_IN_PROGRESS = 0x0D,
202 CROSS_TRANSPORT_KEY_DERIVATION_OR_GENERATION_NOT_ALLOWED = 0x0E
219 DISPLAY_YES_NO = 0x01,
220 KEYBOARD_ONLY = 0x02,
221 NO_INPUT_NO_OUTPUT = 0x03,
222 KEYBOARD_DISPLAY = 0x04
241 static const uint8_t PASSKEY_LEN = 6;
242 static const uint8_t NUMBER_OFFSET =
'0';
248 memset(ascii, NUMBER_OFFSET, PASSKEY_LEN);
258 memcpy(ascii, passkey, PASSKEY_LEN);
260 memset(ascii, NUMBER_OFFSET, PASSKEY_LEN);
270 for (
int i = 5, m = 100000; i >= 0; --i, m /= 10) {
271 uint32_t result = passkey / m;
272 ascii[i] = NUMBER_OFFSET + result;
273 passkey -= result * m;
281 return to_num(ascii);
289 static uint32_t
to_num(
const uint8_t *ascii) {
290 uint32_t passkey = 0;
291 for (
size_t i = 0, m = 1; i < PASSKEY_LEN; ++i, m *= 10) {
292 passkey += (ascii[i] - NUMBER_OFFSET) * m;
304 uint8_t ascii[PASSKEY_LEN];
310 template <
class byte_array_
class>
312 for (
size_t i = 0; i < byte_array.size(); i++) {
313 if (byte_array[i] != 0) {
323 template <
class byte_array_
class>
325 memset(&byte_array[0], 0x00, byte_array.size());
332 template <
size_t array_size>
337 static const size_t size_ = array_size;
343 memset(_value, 0x00,
sizeof(_value));
352 memcpy(_value, input_value,
sizeof(_value));
362 memcpy(_value, input_value, size);
369 return memcmp(lhs._value, rhs._value,
sizeof(lhs._value)) == 0;
376 return !(lhs == rhs);
415 uint8_t _value[array_size];
425 template<
size_t Size>
438 template<
size_t Size>
478 memset(_value, 0x00,
sizeof(_value));
487 memcpy(_value, input_value,
sizeof(_value));
519 static const uint8_t size = 2;
725 set_coded(phy_coded);
735 switch (phy.
value()) {
753 _value |= PHY_SET_1M;
755 _value &= ~PHY_SET_1M;
762 _value |= PHY_SET_2M;
764 _value &= ~PHY_SET_2M;
771 _value |= PHY_SET_CODED;
773 _value &= ~PHY_SET_CODED;
777 bool get_1m()
const {
778 return (_value & PHY_SET_1M);
781 bool get_2m()
const {
782 return (_value & PHY_SET_2M);
785 bool get_coded()
const {
786 return (_value & PHY_SET_CODED);
789 operator uint8_t()
const {
793 uint8_t
value()
const {
797 uint8_t count()
const {
798 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.
Span< uint8_t, Size > make_Span(byte_array_t< Size > &src)
Construct a fixed size Span from a byte_array_t.
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.
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.
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'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.
Nonowning view to a sequence of contiguous elements.
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.
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.