26#include "platform/Span.h"
28#include "ble/common/SafeEnum.h"
29#include "ble/gap/Types.h"
45static const advertising_handle_t LEGACY_ADVERTISING_HANDLE = 0x00;
48static const advertising_handle_t INVALID_ADVERTISING_HANDLE = 0xFF;
51static const uint8_t LEGACY_ADVERTISING_MAX_SIZE = 0x1F;
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);
157static inline attribute_handle_range_t attribute_handle_range(
162 attribute_handle_range_t result = {
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) {
280 uint32_t result = passkey / m;
281 ascii[i] = NUMBER_OFFSET + result;
282 passkey -= result * m;
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];
319template <
class byte_array_
class>
322 for (
size_t i = 0; i < byte_array.size(); i++) {
323 if (byte_array[i] != 0) {
333template <
class byte_array_
class>
336 memset(&byte_array[0], 0x00, byte_array.size());
343template <
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];
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()) {
753 case phy_t::LE_CODED:
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);
Passkey stored as a string of digits.
static uint32_t to_num(const uint8_t *ascii)
Convert ASCII string of digits into a number.
uint8_t * value()
Return the pointer to the buffer holding the string.
PasskeyAscii(passkey_num_t passkey)
Initialize a data from a number.
PasskeyAscii(const uint8_t *passkey)
Initialize a data from a string.
PasskeyAscii()
Default to all zeroes.
Type that describe a set of PHY(sical) transports.
phy_set_t(phy_t phy)
Create a set from a single phy.
void set_coded(bool enabled=true)
Prefer coded PHY.
phy_set_t(bool phy_1m, bool phy_2m, bool phy_coded)
Create a set based on individual settings.
phy_set_t(uint8_t value)
Create a set based on the mask specified in the Bluetooth spec.
void set_2m(bool enabled=true)
Prefer 2M PHY.
void set_1m(bool enabled=true)
Prefer 1M PHY.
phy_set_t()
Create set that indicates no preference.
Entry namespace for all BLE API definitions.
uint32_t sign_count_t
counter for signed data writes done by GattClient
uint32_t passkey_num_t
Passkey stored as a number.
byte_array_t< 16 > oob_tk_t
Out of band data exchanged during pairing.
byte_array_t< 2 > ediv_t
Used to identify LTK for legacy pairing connections.
byte_array_t< 32 > public_key_coord_t
public key coordinate, two of which define the public key
byte_array_t< 32 > dhkey_t
Diffie-Hellman key.
void set_all_zeros(byte_array_class &byte_array)
Zero out all bytes.
byte_array_t< 16 > encryption_block_t
data to be encrypted
bool is_all_zeros(byte_array_class &byte_array)
Returns true if every byte is equal to zero.
byte_array_t< 16 > oob_lesc_value_t
secure connections oob random 128 value
byte_array_t< 16 > oob_confirm_t
secure connections oob confirmation value
uint16_t attribute_handle_t
Reference to an attribute in a GATT database.
byte_array_t< 16 > irk_t
128 bit keys used by paired devices
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.
Keypress_t
events sent and received when passkey is being entered
@ KEYPRESS_ENTERED
Passkey digit entered.
@ KEYPRESS_COMPLETED
Passkey entry completed.
@ KEYPRESS_CLEARED
Passkey cleared.
@ KEYPRESS_STARTED
Passkey entry started.
@ KEYPRESS_ERASED
Passkey digit erased.
Span< uint8_t, Size > make_Span(byte_array_t< Size > &src)
Construct a fixed size Span from a byte_array_t.
uintptr_t connection_handle_t
Opaque reference to a connection.
Helper class used to define safe enumerations.
uint8_t value() const
Explicit access to the inner value of the SafeEnum instance.
address_t()
Create an invalid mac address, equal to 00:00:00:00:00:00.
address_t(const uint8_t *input_value)
Initialize a data from an array of bytes.
Security requirement that can be attached to an attribute operation.
type
struct scoped enum wrapped by the class
@ UNAUTHENTICATED
The operation requires security and there's no requirement towards peer authentication.
@ NONE
The operation does not have security requirements.
@ AUTHENTICATED
The operation requires security and the peer must be authenticated.
att_security_requirement_t(type value)
Construct a new instance of att_security_requirement_t.
Inclusive range of GATT attributes handles.
friend bool operator!=(const attribute_handle_range_t &lhs, const attribute_handle_range_t &rhs)
Not equal operator for attribute_handle_range_t.
friend bool operator==(const attribute_handle_range_t &lhs, const attribute_handle_range_t &rhs)
Equal operator for attribute_handle_range_t.
attribute_handle_t begin
Beginning of the range.
attribute_handle_t end
End of the range.
Model fixed size array values.
static size_t size()
Size in byte of a data.
uint8_t & operator[](size_t i)
Subscript operator to access data content.
const uint8_t * data() const
Return the pointer to the buffer holding data.
uint8_t * data()
Return the pointer to the buffer holding data.
friend bool operator!=(const byte_array_t &lhs, const byte_array_t &rhs)
Non equal operator between two octet types.
byte_array_t(const uint8_t *input_value)
Initialize a data from an array of bytes.
friend bool operator==(const byte_array_t &lhs, const byte_array_t &rhs)
Equal operator between two octet types.
byte_array_t()
Default to all zeroes.
uint8_t operator[](size_t i) const
Subscript operator to access data content.
byte_array_t(const uint8_t *input_value, size_t size)
Initialize a data from an buffer of bytes.
Type describing the number of symbols per bit in le coded PHY.
type
struct scoped enum wrapped by the class
@ S2
Two symbols to code a bit.
@ UNDEFINED
The Number of symbol used to code a bit is undefined.
coded_symbol_per_bit_t(type value)
Construct a new instance of coded_symbol_per_bit_t.
Features supported by the controller.
controller_supported_features_t(type value)
Construct a new instance of ControllerSupportedFeatures_t.
Type that describe the IO capability of a device; it is used during Pairing Feature exchange.
io_capability_t(type value)
Construct a new instance of io_capability_t.
Type that describes link's encryption state.
type
struct scoped enum wrapped by the class
@ NOT_ENCRYPTED
The link is not secured.
@ ENCRYPTED_WITH_MITM
The link is secure and authenticated.
@ ENCRYPTED_WITH_SC_AND_MITM
The link is secure and authenticated with a secure connection key.
@ ENCRYPTED
The link is secure.
@ ENCRYPTION_IN_PROGRESS
Link security is being established.
link_encryption_t(type value)
Construct a new instance of link_encryption_t.
Type that describe a pairing failure.
pairing_failure_t(type value)
Construct a new instance of pairing_failure_t.
type
struct scoped enum wrapped by the class
Type that describes a peer device address type.
peer_address_type_t(type value)
Construct a new instance of peer_address_type_t.
type
struct scoped enum wrapped by the class
@ RANDOM_STATIC_IDENTITY
A Random static address used as a device identity address.
@ PUBLIC_IDENTITY
A Public address used as a device identity address.
peer_address_type_t()
Default initialization of peer_address_type_t.
Type that describes a bluetooth PHY(sical) transport.
phy_t(type value)
Construct a new instance of phy_t.
type
struct scoped enum wrapped by the class
Type that describes a random device address type.
random_address_type_t(type value)
Construct a new instance of random_address_type_t.
type
struct scoped enum wrapped by the class
@ STATIC
Random static device address.
@ NON_RESOLVABLE_PRIVATE
Random non resolvable private address.
BLE address representation.
address_t address
Value of the peer address.
entry_t()
Empty constructor.
peer_address_type_t type
Type of the peer address.
entry_t(peer_address_type_t typeIn, const address_t &addressIn)
Construct an entry_t object with the supplied type and address.
Representation of a whitelist of addresses.
entry_t * addresses
Pointer to the array of the addresses composing the whitelist.
uint8_t size
Number addresses in this whitelist.
uint8_t capacity
Capacity of the array holding the addresses.
Nonowning view to a sequence of contiguous elements.