BlueToe
an alternative GATT/BLE implementation
|
extension of a scheduled_radio with functions to support encryption More...
#include <bluetoe/link_layer/scheduled_radio.hpp>
Public Member Functions | |
bluetoe::details::uint128_t | create_srand () |
Function to create the Srand according to 2.3.5.5 Part H, Vol 3, Core Spec. | |
bluetoe::details::longterm_key_t | create_long_term_key () |
Function to create a random long term key and random Rand and EDIV values to identify this newly created key. | |
bluetoe::details::uint128_t | c1 (const bluetoe::details::uint128_t &temp_key, const bluetoe::details::uint128_t &rand, const bluetoe::details::uint128_t &p1, const bluetoe::details::uint128_t &p2) const |
Confirm value generation function c1 for LE Legacy Pairing. | |
bluetoe::details::uint128_t | s1 (const bluetoe::details::uint128_t &temp_key, const bluetoe::details::uint128_t &prand, const bluetoe::details::uint128_t &crand) |
Key generation function s1 for LE Legacy Pairing. | |
std::pair< std::uint64_t, std::uint32_t > | setup_encryption (bluetoe::details::uint128_t key, std::uint64_t skdm, std::uint32_t ivm) |
setup the hardware with all data required for encryption | |
bool | is_valid_public_key (const std::uint8_t *public_key) const |
std::pair< bluetoe::details::ecdh_public_key_t, bluetoe::details::ecdh_private_key_t > | generate_keys () |
generate public private key pair for DH | |
bluetoe::details::uint128_t | select_random_nonce () |
random nonce required for LESC pairing | |
bluetoe::details::ecdh_shared_secret_t | p256 (const std::uint8_t *private_key, const std::uint8_t *public_key) |
p256() security toolbox function, as specified in the core spec | |
bluetoe::details::uint128_t | f4 (const std::uint8_t *u, const std::uint8_t *v, const std::array< std::uint8_t, 16 > &k, std::uint8_t z) |
f4() security toolbox function, as specified in the core spec | |
std::pair< bluetoe::details::uint128_t, bluetoe::details::uint128_t > | f5 (const bluetoe::details::ecdh_shared_secret_t dh_key, const bluetoe::details::uint128_t &nonce_central, const bluetoe::details::uint128_t &nonce_periperal, const bluetoe::link_layer::device_address &addr_controller, const bluetoe::link_layer::device_address &addr_peripheral) |
f5() security toolbox function, as specified in the core spec | |
bluetoe::details::uint128_t | f6 (const bluetoe::details::uint128_t &key, const bluetoe::details::uint128_t &n1, const bluetoe::details::uint128_t &n2, const bluetoe::details::uint128_t &r, const bluetoe::details::io_capabilities_t &io_caps, const bluetoe::link_layer::device_address &addr_controller, const bluetoe::link_layer::device_address &addr_peripheral) |
f6() security toolbox function, as specified in the core spec | |
std::uint32_t | g2 (const std::uint8_t *u, const std::uint8_t *v, const bluetoe::details::uint128_t &x, const bluetoe::details::uint128_t &y) |
g2() security toolbox function, as specified in the core spec | |
bluetoe::details::uint128_t | create_passkey () |
void | start_receive_encrypted () |
start the encryption of received PDUs with the next connection event. | |
void | start_transmit_encrypted () |
start to encrypt transmitted PDUs with the next connection event. | |
void | stop_receive_encrypted () |
stop receiving encrypted with the next connection event. | |
void | stop_transmit_encrypted () |
stop transmitting encrypted with the next connection event. | |
Public Member Functions inherited from bluetoe::link_layer::scheduled_radio< TransmitSize, ReceiveSize, CallBack > | |
scheduled_radio () | |
void | schedule_advertisment (unsigned channel, const bluetoe::link_layer::write_buffer &advertising_data, const bluetoe::link_layer::write_buffer &response_data, bluetoe::link_layer::delta_time when, const bluetoe::link_layer::read_buffer &receive) |
schedules for transmission of advertising data and starts to receive 150µs later | |
bluetoe::link_layer::delta_time | schedule_connection_event (unsigned channel, bluetoe::link_layer::delta_time start_receive, bluetoe::link_layer::delta_time end_receive, bluetoe::link_layer::delta_time connection_interval) |
schedules a connection event | |
std::pair< bool, bluetoe::link_layer::delta_time > | disarm_connection_event () |
tries to stop a scheduled connection event | |
bool | schedule_synchronized_user_timer (bluetoe::link_layer::delta_time timeout, bluetoe::link_layer::delta_time max_cb_runtime) |
sets up a timer | |
bool | cancel_synchronized_user_timer () |
cancel the user timer | |
void | set_access_address_and_crc_init (std::uint32_t access_address, std::uint32_t crc_init) |
set the access address initial CRC value for transmitted and received PDU | |
std::uint32_t | static_random_address_seed () const |
function to return a device specific value that is persistent and unique for the device (CPU id or such) | |
void | run () |
allocates the CPU to the scheduled_radio | |
void | wake_up () |
forces the run() function to return at least once | |
void | request_event_cancelation () |
forces the call of CallBack::try_event_cancelation() from the context of the run() function | |
bool | radio_add_to_white_list (const device_address &addr) |
add the given address to the white list. | |
bool | radio_remove_from_white_list (const device_address &addr) |
remove the given address from the white list | |
bool | radio_is_in_white_list (const device_address &addr) const |
returns true, if the given address in within the white list | |
std::size_t | radio_white_list_free_size () const |
returns the number of addresses that could be added to the white list before add_to_white_list() would return false. | |
void | radio_clear_white_list () |
remove all entries from the white list | |
void | connection_request_filter (bool b) |
Accept connection requests only from devices within the white list. | |
bool | connection_request_filter () const |
current value of the property. | |
void | radio_scan_request_filter (bool b) |
Accept scan requests only from devices within the white list. | |
bool | radio_scan_request_filter () const |
current value of the property. | |
bool | radio_is_connection_request_in_filter (const device_address &addr) const |
returns true, if a connection request from the given address should be answered. | |
bool | radio_is_scan_request_in_filter (const device_address &addr) const |
returns true, if a scan request from the given address should be answered. | |
void | radio_set_phy (details::phy_ll_encoding receiving_encoding, details::phy_ll_encoding transmiting_c_encoding) |
change the used PHY encoding for the transmitting and receiving side | |
Public Member Functions inherited from bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, scheduled_radio< TransmitSize, ReceiveSize, CallBack > > | |
ll_data_pdu_buffer () | |
constexpr std::size_t | max_max_rx_size () const |
returns the maximum value that can be used as maximum receive size. | |
std::size_t | max_rx_size () const |
the current maximum receive size | |
void | max_rx_size (std::size_t max_size) |
set the maximum receive size | |
constexpr std::size_t | max_max_tx_size () const |
returns the maximum value that can be used as maximum receive size. | |
std::size_t | max_tx_size () const |
the current maximum transmit size | |
void | max_tx_size (std::size_t max_size) |
set the maximum transmit size | |
std::uint8_t * | raw_pdu_buffer () |
returns the underlying raw buffer with a size of at least ll_data_pdu_buffer::size | |
void | stop_pdu_buffer () |
places the buffer in stopped mode. | |
void | reset_pdu_buffer () |
places the buffer in running mode. | |
read_buffer | allocate_transmit_buffer (std::size_t size) |
allocates a certain amount of memory to place a PDU to be transmitted . | |
read_buffer | allocate_transmit_buffer () |
calls allocate_transmit_buffer( max_tx_size() + layout_overhead ); | |
void | commit_transmit_buffer (read_buffer) |
indicates that prior allocated memory is now ready for transmission | |
bool | pending_outgoing_data_available () const |
returns true, if there is pending, outgoing data | |
write_buffer | next_received () const |
returns the oldest PDU out of the receive buffer. | |
void | free_received () |
removes the oldest PDU from the receive buffer. | |
Static Public Attributes | |
static constexpr bool | hardware_supports_lesc_pairing = false |
indicates the support for LESC pairing | |
static constexpr bool | hardware_supports_legacy_pairing = true |
indicates the support for legacy pairing | |
static constexpr bool | hardware_supports_encryption = hardware_supports_lesc_pairing || hardware_supports_legacy_pairing |
indication no support for encryption | |
Static Public Attributes inherited from bluetoe::link_layer::scheduled_radio< TransmitSize, ReceiveSize, CallBack > | |
static constexpr std::size_t | radio_maximum_white_list_entries = 4 |
giving the maximum number of white list entries, the scheduled radio supports by hardware | |
static constexpr std::size_t | radio_package_overhead = 0 |
a number of bytes that are additional required by the hardware to handle an over the air package/PDU. | |
static constexpr bool | hardware_supports_encryption = false |
indication no support for encryption | |
static constexpr bool | hardware_supports_2mbit = true |
indicates support for 2Mbit | |
static constexpr bool | hardware_supports_synchronized_user_timer = true |
indicates support for schedule_synchronized_user_timer() | |
Static Public Attributes inherited from bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, scheduled_radio< TransmitSize, ReceiveSize, CallBack > > | |
static constexpr std::size_t | size |
the size of memory in bytes that are return by raw() | |
static constexpr std::size_t | min_buffer_size |
the minimum size an element in the buffer can have (header size + payload size). | |
static constexpr std::size_t | max_buffer_size |
the maximum size an element in the buffer can have (header size + payload size). | |
static constexpr std::size_t | header_size |
16 bit header size of a link layer PDU | |
static constexpr std::size_t | layout_overhead |
addition layout overhead introduced by the applied layout | |
Additional Inherited Members | |
Public Types inherited from bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, scheduled_radio< TransmitSize, ReceiveSize, CallBack > > | |
using | layout = typename pdu_layout_by_radio< scheduled_radio< TransmitSize, ReceiveSize, CallBack > >::pdu_layout |
layout to be applied to each PDU. | |
Protected Member Functions inherited from bluetoe::link_layer::ll_data_pdu_buffer< TransmitSize, ReceiveSize, scheduled_radio< TransmitSize, ReceiveSize, CallBack > > | |
read_buffer | allocate_receive_buffer () const |
allocates a buffer for the next PDU to be received. | |
write_buffer | received (read_buffer) |
This function will be called by the scheduled radio when a PDU was received without error. | |
write_buffer | acknowledge (read_buffer) |
This function will be called, instead of received(), when the CRC of a received PDU is ok, but the MIC is not ok. | |
write_buffer | next_transmit () |
returns the next PDU to be transmitted | |
extension of a scheduled_radio with functions to support encryption
To allow the utilization of hardware support for certain cryptographical functions, this interface abstracts at a quite high level.
bluetoe::details::uint128_t bluetoe::link_layer::scheduled_radio_with_encryption< TransmitSize, ReceiveSize, CallBack >::c1 | ( | const bluetoe::details::uint128_t & | temp_key, |
const bluetoe::details::uint128_t & | rand, | ||
const bluetoe::details::uint128_t & | p1, | ||
const bluetoe::details::uint128_t & | p2 | ||
) | const |
Confirm value generation function c1 for LE Legacy Pairing.
temp_key | the temporary key from the LE legacy pairing algorithm |
rand | the value created by create_srand() or the |
p1 | p1 = pres || preq || rat’ || iat’ (see 2.3.3 Confirm value generation function c1 for LE Legacy Pairing) |
p2 | p2 = padding || ia || ra (see 2.3.3 Confirm value generation function c1 for LE Legacy Pairing) |
The function calculates the confirm value based on the peripherals or centrals random value (Srand or Mrand), the temporary key and the data in the pairing request and response.
bluetoe::details::uint128_t bluetoe::link_layer::scheduled_radio_with_encryption< TransmitSize, ReceiveSize, CallBack >::create_passkey | ( | ) |
Functions required by IO capabilties
bool bluetoe::link_layer::scheduled_radio_with_encryption< TransmitSize, ReceiveSize, CallBack >::is_valid_public_key | ( | const std::uint8_t * | public_key | ) | const |
features required for LESC
bluetoe::details::uint128_t bluetoe::link_layer::scheduled_radio_with_encryption< TransmitSize, ReceiveSize, CallBack >::s1 | ( | const bluetoe::details::uint128_t & | temp_key, |
const bluetoe::details::uint128_t & | prand, | ||
const bluetoe::details::uint128_t & | crand | ||
) |
Key generation function s1 for LE Legacy Pairing.
The key generation function s1 is used to generate the STK during the LE legacy pairing process.
temp_key | the temporary key from the LE legacy pairing algorithm |
prand | The peripheral random value (Prand). |
crand | The central random value (Crand). |
std::pair< std::uint64_t, std::uint32_t > bluetoe::link_layer::scheduled_radio_with_encryption< TransmitSize, ReceiveSize, CallBack >::setup_encryption | ( | bluetoe::details::uint128_t | key, |
std::uint64_t | skdm, | ||
std::uint32_t | ivm | ||
) |
setup the hardware with all data required for encryption
The encryption is prepaired but not started jet.
key | long term or short term key to be used for encryption |
skdm | The central's portion of the session key diversifier. |
ivm | The IVm field contains the central portion of the initialization vector. |
The function returns SKDs and IVs (the peripherals portion of the session key diversifier and initialization vector), to be send to the central.