gap: cache own address on start advertising and connecting, provide getters

This commit is contained in:
Matthias Ringwald 2021-06-11 11:24:08 +02:00
parent d5314cbe14
commit 6bcfa63272
4 changed files with 49 additions and 12 deletions

View File

@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed ### Fixed
- GAP: store link key in hci connection struct to allow authenticate after pairing without bonding - GAP: store link key in hci connection struct to allow authenticate after pairing without bonding
- GAP: avoid requesting authentication twice - GAP: avoid requesting authentication twice
- GAP: gap: cache own address on start advertising and connecting, provide getters
- ATT DB: fix spelling `gatt_server_get_handle_range_for_service_with_uuid128`, `gatt_server_get_handle_range_for_service_with_uuid16` - ATT DB: fix spelling `gatt_server_get_handle_range_for_service_with_uuid128`, `gatt_server_get_handle_range_for_service_with_uuid16`
### Changed ### Changed

View File

@ -884,10 +884,19 @@ uint8_t gap_qos_set(hci_con_handle_t con_handle, hci_service_type_t service_type
// LE // LE
/** /**
* @brief Get own addr type and address used for LE * @brief Get own addr type and address used for LE for next scan/advertisement/connect operation
*/ */
void gap_le_get_own_address(uint8_t * addr_type, bd_addr_t addr); void gap_le_get_own_address(uint8_t * addr_type, bd_addr_t addr);
/**
* @brief Get own addr type and address used for LE advertisements (Peripheral)
*/
void gap_le_get_own_advertisements_address(uint8_t * addr_type, bd_addr_t addr);
/**
* @brief Get own addr type and address used for LE connections (Central)
*/
void gap_le_get_own_connection_address(uint8_t * addr_type, bd_addr_t addr);
/** /**
* @brief Get state of connection re-encryption for bonded devices when in central role * @brief Get state of connection re-encryption for bonded devices when in central role

View File

@ -1100,19 +1100,36 @@ static int hci_le_supported(void){
#ifdef ENABLE_BLE #ifdef ENABLE_BLE
/** static void hci_get_own_address_for_addr_type(bd_addr_type_t own_addr_type, bd_addr_t own_addr){
* @brief Get addr type and address used for LE in Advertisements, Scan Responses, if (own_addr_type == BD_ADDR_TYPE_LE_PUBLIC){
*/ (void)memcpy(own_addr, hci_stack->local_bd_addr, 6);
void gap_le_get_own_address(uint8_t * addr_type, bd_addr_t addr){
*addr_type = hci_stack->le_own_addr_type;
if (hci_stack->le_own_addr_type){
(void)memcpy(addr, hci_stack->le_random_address, 6);
} else { } else {
(void)memcpy(addr, hci_stack->local_bd_addr, 6); (void)memcpy(own_addr, hci_stack->le_random_address, 6);
} }
} }
void gap_le_get_own_address(uint8_t * addr_type, bd_addr_t addr){
*addr_type = hci_stack->le_own_addr_type;
hci_get_own_address_for_addr_type(hci_stack->le_own_addr_type, addr);
}
#ifdef ENABLE_LE_PERIPHERAL
void gap_le_get_own_advertisements_address(uint8_t * addr_type, bd_addr_t addr){
*addr_type = hci_stack->le_advertisements_own_addr_type;
hci_get_own_address_for_addr_type(hci_stack->le_advertisements_own_addr_type, addr);
};
#endif
#ifdef ENABLE_LE_CENTRAL #ifdef ENABLE_LE_CENTRAL
/**
* @brief Get own addr type and address used for LE connections (Central)
*/
void gap_le_get_own_connection_address(uint8_t * addr_type, bd_addr_t addr){
*addr_type = hci_stack->le_connection_own_addr_type;
hci_get_own_address_for_addr_type(hci_stack->le_connection_own_addr_type, addr);
}
void le_handle_advertisement_report(uint8_t *packet, uint16_t size){ void le_handle_advertisement_report(uint8_t *packet, uint16_t size){
int offset = 3; int offset = 3;
@ -4102,11 +4119,12 @@ static bool hci_run_general_gap_le(void){
#ifdef ENABLE_LE_PERIPHERAL #ifdef ENABLE_LE_PERIPHERAL
if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_PARAMS){ if (hci_stack->le_advertisements_todo & LE_ADVERTISEMENT_TASKS_SET_PARAMS){
hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_PARAMS; hci_stack->le_advertisements_todo &= ~LE_ADVERTISEMENT_TASKS_SET_PARAMS;
hci_stack->le_advertisements_own_addr_type = hci_stack->le_own_addr_type;
hci_send_cmd(&hci_le_set_advertising_parameters, hci_send_cmd(&hci_le_set_advertising_parameters,
hci_stack->le_advertisements_interval_min, hci_stack->le_advertisements_interval_min,
hci_stack->le_advertisements_interval_max, hci_stack->le_advertisements_interval_max,
hci_stack->le_advertisements_type, hci_stack->le_advertisements_type,
hci_stack->le_own_addr_type, hci_stack->le_advertisements_own_addr_type,
hci_stack->le_advertisements_direct_address_type, hci_stack->le_advertisements_direct_address_type,
hci_stack->le_advertisements_direct_address, hci_stack->le_advertisements_direct_address,
hci_stack->le_advertisements_channel_map, hci_stack->le_advertisements_channel_map,
@ -4266,13 +4284,15 @@ static bool hci_run_general_gap_le(void){
if ( (hci_stack->le_connecting_state == LE_CONNECTING_IDLE) && (hci_stack->le_connecting_request == LE_CONNECTING_WHITELIST)){ if ( (hci_stack->le_connecting_state == LE_CONNECTING_IDLE) && (hci_stack->le_connecting_request == LE_CONNECTING_WHITELIST)){
bd_addr_t null_addr; bd_addr_t null_addr;
memset(null_addr, 0, 6); memset(null_addr, 0, 6);
hci_stack->le_connection_own_addr_type = hci_stack->le_own_addr_type;
hci_get_own_address_for_addr_type(hci_stack->le_connection_own_addr_type, hci_stack->le_connection_own_address);
hci_send_cmd(&hci_le_create_connection, hci_send_cmd(&hci_le_create_connection,
hci_stack->le_connection_scan_interval, // scan interval: 60 ms hci_stack->le_connection_scan_interval, // scan interval: 60 ms
hci_stack->le_connection_scan_window, // scan interval: 30 ms hci_stack->le_connection_scan_window, // scan interval: 30 ms
1, // use whitelist 1, // use whitelist
0, // peer address type 0, // peer address type
null_addr, // peer bd addr null_addr, // peer bd addr
hci_stack->le_own_addr_type, // our addr type: hci_stack->le_connection_own_addr_type, // our addr type:
hci_stack->le_connection_interval_min, // conn interval min hci_stack->le_connection_interval_min, // conn interval min
hci_stack->le_connection_interval_max, // conn interval max hci_stack->le_connection_interval_max, // conn interval max
hci_stack->le_connection_latency, // conn latency hci_stack->le_connection_latency, // conn latency
@ -4289,6 +4309,7 @@ static bool hci_run_general_gap_le(void){
if (hci_stack->le_advertisements_enabled_for_current_roles && !hci_stack->le_advertisements_active){ if (hci_stack->le_advertisements_enabled_for_current_roles && !hci_stack->le_advertisements_active){
// check if advertisements should be enabled given // check if advertisements should be enabled given
hci_stack->le_advertisements_active = true; hci_stack->le_advertisements_active = true;
hci_get_own_address_for_addr_type(hci_stack->le_connection_own_addr_type, hci_stack->le_advertisements_own_address);
hci_send_cmd(&hci_le_set_advertise_enable, 1); hci_send_cmd(&hci_le_set_advertise_enable, 1);
return true; return true;
} }
@ -4316,13 +4337,15 @@ static bool hci_run_general_pending_commands(void){
#ifdef ENABLE_BLE #ifdef ENABLE_BLE
#ifdef ENABLE_LE_CENTRAL #ifdef ENABLE_LE_CENTRAL
log_info("sending hci_le_create_connection"); log_info("sending hci_le_create_connection");
hci_stack->le_connection_own_addr_type = hci_stack->le_own_addr_type;
hci_get_own_address_for_addr_type(hci_stack->le_connection_own_addr_type, hci_stack->le_connection_own_address);
hci_send_cmd(&hci_le_create_connection, hci_send_cmd(&hci_le_create_connection,
hci_stack->le_connection_scan_interval, // conn scan interval hci_stack->le_connection_scan_interval, // conn scan interval
hci_stack->le_connection_scan_window, // conn scan windows hci_stack->le_connection_scan_window, // conn scan windows
0, // don't use whitelist 0, // don't use whitelist
connection->address_type, // peer address type connection->address_type, // peer address type
connection->address, // peer bd addr connection->address, // peer bd addr
hci_stack->le_own_addr_type, // our addr type: hci_stack->le_connection_own_addr_type, // our addr type:
hci_stack->le_connection_interval_min, // conn interval min hci_stack->le_connection_interval_min, // conn interval min
hci_stack->le_connection_interval_max, // conn interval max hci_stack->le_connection_interval_max, // conn interval max
hci_stack->le_connection_latency, // conn latency hci_stack->le_connection_latency, // conn latency

View File

@ -993,6 +993,8 @@ typedef struct {
uint16_t le_maximum_ce_length; uint16_t le_maximum_ce_length;
uint16_t le_connection_scan_interval; uint16_t le_connection_scan_interval;
uint16_t le_connection_scan_window; uint16_t le_connection_scan_window;
bd_addr_type_t le_connection_own_addr_type;
bd_addr_t le_connection_own_address;
#endif #endif
le_connection_parameter_range_t le_connection_parameter_range; le_connection_parameter_range_t le_connection_parameter_range;
@ -1016,6 +1018,8 @@ typedef struct {
uint8_t le_advertisements_channel_map; uint8_t le_advertisements_channel_map;
uint8_t le_advertisements_filter_policy; uint8_t le_advertisements_filter_policy;
bd_addr_t le_advertisements_direct_address; bd_addr_t le_advertisements_direct_address;
bd_addr_type_t le_advertisements_own_addr_type;
bd_addr_t le_advertisements_own_address;
uint8_t le_max_number_peripheral_connections; uint8_t le_max_number_peripheral_connections;
#endif #endif