26 #include "platform/Span.h" 28 #include "ble/common/SafeEnum.h" 29 #include "ble/gap/Types.h" 58 CONNECTION_PARAMETERS_REQUEST_PROCEDURE,
59 EXTENDED_REJECT_INDICATION,
60 SLAVE_INITIATED_FEATURES_EXCHANGE,
62 LE_DATA_PACKET_LENGTH_EXTENSION,
64 EXTENDED_SCANNER_FILTER_POLICIES,
66 STABLE_MODULATION_INDEX_TRANSMITTER,
67 STABLE_MODULATION_INDEX_RECEIVER,
69 LE_EXTENDED_ADVERTISING,
70 LE_PERIODIC_ADVERTISING,
71 CHANNEL_SELECTION_ALGORITHM_2,
139 return !(lhs == rhs);
158 attribute_handle_t begin,
159 attribute_handle_t end
179 ENCRYPTED_WITH_SC_AND_MITM
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
224 DISPLAY_YES_NO = 0x01,
225 KEYBOARD_ONLY = 0x02,
226 NO_INPUT_NO_OUTPUT = 0x03,
227 KEYBOARD_DISPLAY = 0x04
246 static const uint8_t PASSKEY_LEN = 6;
247 static const uint8_t NUMBER_OFFSET =
'0';
253 memset(ascii, NUMBER_OFFSET, PASSKEY_LEN);
263 memcpy(ascii, passkey, PASSKEY_LEN);
265 memset(ascii, NUMBER_OFFSET, PASSKEY_LEN);
275 #if BLE_PASSKEY_DISPLAY_REVERSED_DIGITS_DEPRECATION 276 for (
int i = 5, m = 100000; i >= 0; --i, m /= 10) {
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;
290 return to_num(ascii);
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;
313 uint8_t ascii[PASSKEY_LEN];
319 template <
class byte_array_
class>
322 for (
size_t i = 0; i < byte_array.size(); i++) {
323 if (byte_array[i] != 0) {
333 template <
class byte_array_
class>
336 memset(&byte_array[0], 0x00, byte_array.size());
343 template <
size_t array_size>
348 static const size_t size_ = array_size;
354 memset(_value, 0x00,
sizeof(_value));
363 memcpy(_value, input_value,
sizeof(_value));
373 memcpy(_value, input_value, size);
380 return memcmp(lhs._value, rhs._value,
sizeof(lhs._value)) == 0;
387 return !(lhs == rhs);
426 uint8_t _value[array_size];
436 template<
size_t Size>
449 template<
size_t Size>
489 memset(_value, 0x00,
sizeof(_value));
498 memcpy(_value, input_value,
sizeof(_value));
530 static const uint8_t size = 2;
736 set_coded(phy_coded);
746 switch (phy.
value()) {
764 _value |= PHY_SET_1M;
766 _value &= ~PHY_SET_1M;
773 _value |= PHY_SET_2M;
775 _value &= ~PHY_SET_2M;
782 _value |= PHY_SET_CODED;
784 _value &= ~PHY_SET_CODED;
788 bool get_1m()
const {
789 return (_value & PHY_SET_1M);
792 bool get_2m()
const {
793 return (_value & PHY_SET_2M);
796 bool get_coded()
const {
797 return (_value & PHY_SET_CODED);
800 operator uint8_t()
const {
804 uint8_t
value()
const {
808 uint8_t count()
const {
809 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.
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.
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.
entry_t()
Empty constructor.
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.
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.
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.
BLE address representation.
Nonowning view to a sequence of contiguous elements.
Type that describes link's encryption state.
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.
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.
Random static device address.
PasskeyAscii()
Default to all zeroes.
uint8_t size
Number addresses in this whitelist.