BlueToe
an alternative GATT/BLE implementation
Loading...
Searching...
No Matches
scheduled_radio.hpp
1#ifndef BLUETOE_LINK_LAYER_SCHEDULED_RADIO_HPP
2#define BLUETOE_LINK_LAYER_SCHEDULED_RADIO_HPP
3
4#include <cstdint>
5#include <buffer.hpp>
6#include <address.hpp>
7#include <ll_data_pdu_buffer.hpp>
8
9namespace bluetoe {
10namespace link_layer {
11
12 class delta_time;
13 class write_buffer;
14 class read_buffer;
15
26 template < std::size_t TransmitSize, std::size_t ReceiveSize, typename CallBack >
27 class scheduled_radio : public ll_data_pdu_buffer< TransmitSize, ReceiveSize, scheduled_radio< TransmitSize, ReceiveSize, CallBack > >
28 {
29 public:
34
55 unsigned channel,
56 const bluetoe::link_layer::write_buffer& advertising_data,
57 const bluetoe::link_layer::write_buffer& response_data,
59 const bluetoe::link_layer::read_buffer& receive );
60
83 unsigned channel,
86 bluetoe::link_layer::delta_time connection_interval );
87
102 std::pair< bool, bluetoe::link_layer::delta_time > disarm_connection_event();
103
117 bluetoe::link_layer::delta_time max_cb_runtime );
118
123
130 void set_access_address_and_crc_init( std::uint32_t access_address, std::uint32_t crc_init );
131
135 std::uint32_t static_random_address_seed() const;
136
145 void run();
146
152 void wake_up();
153
162
166 class lock_guard;
167
173 static constexpr std::size_t radio_maximum_white_list_entries = 4;
174
184
192
196 bool radio_is_in_white_list( const device_address& addr ) const;
197
202 std::size_t radio_white_list_free_size() const;
203
208
222
227
239
244
249
254
258 void radio_set_phy( details::phy_ll_encoding receiving_encoding, details::phy_ll_encoding transmiting_c_encoding );
259
266 static constexpr std::size_t radio_package_overhead = 0;
267
271 static constexpr bool hardware_supports_encryption = false;
272
276 static constexpr bool hardware_supports_2mbit = true;
277
281 static constexpr bool hardware_supports_synchronized_user_timer = true;
282 };
283
290 template < std::size_t TransmitSize, std::size_t ReceiveSize, typename CallBack >
291 class scheduled_radio_with_encryption : public scheduled_radio< TransmitSize, ReceiveSize, CallBack >
292 {
293 public:
297 static constexpr bool hardware_supports_lesc_pairing = false;
298
302 static constexpr bool hardware_supports_legacy_pairing = true;
303
308
312 bluetoe::details::uint128_t create_srand();
313
317 bluetoe::details::longterm_key_t create_long_term_key();
318
330 bluetoe::details::uint128_t c1(
331 const bluetoe::details::uint128_t& temp_key,
332 const bluetoe::details::uint128_t& rand,
333 const bluetoe::details::uint128_t& p1,
334 const bluetoe::details::uint128_t& p2 ) const;
335
346 bluetoe::details::uint128_t s1(
347 const bluetoe::details::uint128_t& temp_key,
348 const bluetoe::details::uint128_t& prand,
349 const bluetoe::details::uint128_t& crand );
350
362 std::pair< std::uint64_t, std::uint32_t > setup_encryption( bluetoe::details::uint128_t key, std::uint64_t skdm, std::uint32_t ivm );
363
367 bool is_valid_public_key( const std::uint8_t* public_key ) const;
368
372 std::pair< bluetoe::details::ecdh_public_key_t, bluetoe::details::ecdh_private_key_t > generate_keys();
373
377 bluetoe::details::uint128_t select_random_nonce();
378
382 bluetoe::details::ecdh_shared_secret_t p256( const std::uint8_t* private_key, const std::uint8_t* public_key );
383
387 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 );
388
392 std::pair< bluetoe::details::uint128_t, bluetoe::details::uint128_t > f5(
393 const bluetoe::details::ecdh_shared_secret_t dh_key,
394 const bluetoe::details::uint128_t& nonce_central,
395 const bluetoe::details::uint128_t& nonce_periperal,
396 const bluetoe::link_layer::device_address& addr_controller,
397 const bluetoe::link_layer::device_address& addr_peripheral );
398
402 bluetoe::details::uint128_t f6(
403 const bluetoe::details::uint128_t& key,
404 const bluetoe::details::uint128_t& n1,
405 const bluetoe::details::uint128_t& n2,
406 const bluetoe::details::uint128_t& r,
407 const bluetoe::details::io_capabilities_t& io_caps,
408 const bluetoe::link_layer::device_address& addr_controller,
409 const bluetoe::link_layer::device_address& addr_peripheral );
410
414 std::uint32_t g2(
415 const std::uint8_t* u,
416 const std::uint8_t* v,
417 const bluetoe::details::uint128_t& x,
418 const bluetoe::details::uint128_t& y );
419
423 bluetoe::details::uint128_t create_passkey();
424
429
434
439
444 };
445
463 struct pdu_layout {
467 static std::uint16_t header( const read_buffer& pdu );
468
472 static std::uint16_t header( const write_buffer& pdu );
473
477 static std::uint16_t header( const std::uint8_t* pdu );
478
482 static void header( const read_buffer& pdu, std::uint16_t header_value );
483
487 static void header( std::uint8_t* pdu, std::uint16_t header_value );
488
492 static std::pair< std::uint8_t*, std::uint8_t* > body( const read_buffer& pdu );
493
497 static std::pair< const std::uint8_t*, const std::uint8_t* > body( const write_buffer& pdu );
498
506 static constexpr std::size_t data_channel_pdu_memory_size( std::size_t payload_size );
507 };
508}
509
510}
511
512#endif // include guard