From ba9fc86712b5e7645ab9cf646b1020091eeff43f Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 11 Jun 2021 11:26:12 +0200 Subject: [PATCH] sm: fix race condition between local address changes and pairing procedure Cahce address active for connection/advertisements on connection complete --- CHANGELOG.md | 1 + src/ble/sm.c | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fe5d430f..9a0311ed0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - GAP: store link key in hci connection struct to allow authenticate after pairing without bonding - GAP: avoid requesting authentication twice - GAP: gap: cache own address on start advertising and connecting, provide getters +- SM: fix race condition between local address changes and pairing procedure - ATT DB: fix spelling `gatt_server_get_handle_range_for_service_with_uuid128`, `gatt_server_get_handle_range_for_service_with_uuid16` ### Changed diff --git a/src/ble/sm.c b/src/ble/sm.c index ea3a90b14..dad9582ee 100644 --- a/src/ble/sm.c +++ b/src/ble/sm.c @@ -3510,9 +3510,13 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint sm_conn->sm_role = packet[6]; sm_conn->sm_peer_addr_type = packet[7]; reverse_bd_addr(&packet[8], sm_conn->sm_peer_address); - gap_le_get_own_address(&sm_conn->sm_own_addr_type, sm_conn->sm_own_address); - - log_info("New sm_conn, role %s", sm_conn->sm_role ? "slave" : "master"); + if (sm_conn->sm_role){ + // responder - use own address from advertisements + gap_le_get_own_advertisements_address(&sm_conn->sm_own_addr_type, sm_conn->sm_own_address); + } else { + // initiator - use own address from create connection + gap_le_get_own_connection_address(&sm_conn->sm_own_addr_type, sm_conn->sm_own_address); + } // reset security properties sm_conn->sm_connection_encrypted = 0;