From 60da98ee0b3e5ac6e598e039a41dd1de9ba51d28 Mon Sep 17 00:00:00 2001 From: Tim Cook Date: Sun, 26 Nov 2017 16:24:21 -0500 Subject: [PATCH 1/2] set ble_rsp_key member of structure bte_appl_cfg in function bta_dm_co_ble_set_rsp_key_req (function incorrectly uses ble_init_key member). Merges https://github.com/espressif/esp-idf/pull/1320 --- components/bt/bluedroid/btif/bta_dm_co.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/bluedroid/btif/bta_dm_co.c b/components/bt/bluedroid/btif/bta_dm_co.c index 2c4ec22ae..83e6db1fe 100644 --- a/components/bt/bluedroid/btif/bta_dm_co.c +++ b/components/bt/bluedroid/btif/bta_dm_co.c @@ -492,7 +492,7 @@ void bta_dm_co_ble_set_rsp_key_req(UINT8 rsp_key) { #if (SMP_INCLUDED == TRUE) rsp_key &= 0x0f; // 4~7bit reservd, only used the 0~3bit - bte_appl_cfg.ble_init_key &= rsp_key; + bte_appl_cfg.ble_resp_key &= rsp_key; #endif ///SMP_INCLUDED == TRUE } From eb408e50c4ebb6a776a74d7b62c9a5d5a00ff76a Mon Sep 17 00:00:00 2001 From: Tim Cook Date: Sun, 26 Nov 2017 16:25:46 -0500 Subject: [PATCH 2/2] n btm_sec_save_le_key() set BTM_SEC_LE_LINK_KEY_KNOWN (and BTM_SEC_LE_LINK_KEY_AUTHED if MITM was used) when process a local Long Term Key (key type BTM_LE_KEY_LENC). This is because these flags share bits with the BTM_SEC_FLAG_LKEY_KNOWN (and BTM_SEC_FLAG_LKEY_AUTHED) flag in btm_api.h. Without this code a link that is encrypted via SM pairing where only the local device exchanges the LTK (peer does not send its LTK) will not allow GATT operations that require encryption (request will be incorrectly rejected with insufficient authentication reason, regardless of if MITM is required). Merges https://github.com/espressif/esp-idf/pull/1320 --- components/bt/bluedroid/stack/btm/btm_ble.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/bt/bluedroid/stack/btm/btm_ble.c b/components/bt/bluedroid/stack/btm/btm_ble.c index baa69d53f..e04fa2f50 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble.c +++ b/components/bt/bluedroid/stack/btm/btm_ble.c @@ -1221,6 +1221,14 @@ void btm_sec_save_le_key(BD_ADDR bd_addr, tBTM_LE_KEY_TYPE key_type, tBTM_LE_KEY p_rec->ble.keys.key_size = p_keys->lenc_key.key_size; p_rec->ble.key_type |= BTM_LE_KEY_LENC; + /* Set that link key is known since this shares field with BTM_SEC_FLAG_LKEY_KNOWN flag in btm_api.h*/ + p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_KNOWN; + if ( p_keys->pcsrk_key.sec_level == SMP_SEC_AUTHENTICATED) { + p_rec->sec_flags |= BTM_SEC_LE_LINK_KEY_AUTHED; + } else { + p_rec->sec_flags &= ~BTM_SEC_LE_LINK_KEY_AUTHED; + } + BTM_TRACE_DEBUG("BTM_LE_KEY_LENC key_type=0x%x DIV=0x%x key_size=0x%x sec_level=0x%x", p_rec->ble.key_type, p_rec->ble.keys.div,