From 38f09fb776ca329976ac80b3df2caa5d7b902fbb Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 4 Oct 2022 10:39:31 +0900 Subject: [PATCH] bluetooth: nrf52: Fix bug that pairing is required for each connections There are the following issues which cause reconnection without bonding information: - Pass no own data by sd_ble_sec_params_reply(). - Pass no data by sd_ble_sec_info_reply() --- sdk/modules/bluetooth/hal/nrf52/ble_comm.c | 6 +++--- sdk/modules/bluetooth/hal/nrf52/ble_comm_internal.h | 4 ++-- sdk/modules/bluetooth/hal/nrf52/ble_gap.c | 12 ++++++------ .../bluetooth/hal/nrf52/ble_storage_operations.c | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/sdk/modules/bluetooth/hal/nrf52/ble_comm.c b/sdk/modules/bluetooth/hal/nrf52/ble_comm.c index 3f0a8caa1..5f38e1067 100644 --- a/sdk/modules/bluetooth/hal/nrf52/ble_comm.c +++ b/sdk/modules/bluetooth/hal/nrf52/ble_comm.c @@ -1594,11 +1594,11 @@ void onSecInfoRequest(BLE_Evt *pBleEvent, ble_evt_t *pBleNrfEvt) { continue; } - if(!memcmp(BondInfoInFlash[index].peerEncKey.master_id.rand, secinfo->master_id.rand, BLE_GAP_SEC_RAND_LEN)) + if(!memcmp(BondInfoInFlash[index].ownEncKey.master_id.rand, secinfo->master_id.rand, BLE_GAP_SEC_RAND_LEN)) { BLE_PRT("onSecInfoRequest: master_id exitsting index %d\n", index); - enc_info = &BondInfoInFlash[index].peerEncKey.enc_info; - id_info = &BondInfoInFlash[index].peerIdKey.id_info; + enc_info = &BondInfoInFlash[index].ownEncKey.enc_info; + id_info = &BondInfoInFlash[index].ownIdKey.id_info; break; } } diff --git a/sdk/modules/bluetooth/hal/nrf52/ble_comm_internal.h b/sdk/modules/bluetooth/hal/nrf52/ble_comm_internal.h index d69b4133c..f4630491f 100644 --- a/sdk/modules/bluetooth/hal/nrf52/ble_comm_internal.h +++ b/sdk/modules/bluetooth/hal/nrf52/ble_comm_internal.h @@ -91,8 +91,8 @@ typedef struct { BLE_GapConnHandle connHandle; BLE_GapBondInfo bondInfo; - //ble_gap_id_key_t ownIdKey; - //ble_gap_enc_key_t ownEncKey; + ble_gap_id_key_t ownIdKey; + ble_gap_enc_key_t ownEncKey; ble_gap_id_key_t peerIdKey; ble_gap_enc_key_t peerEncKey; } bleGapWrapperBondInfo; diff --git a/sdk/modules/bluetooth/hal/nrf52/ble_gap.c b/sdk/modules/bluetooth/hal/nrf52/ble_gap.c index af4b78abd..16c68627c 100644 --- a/sdk/modules/bluetooth/hal/nrf52/ble_gap.c +++ b/sdk/modules/bluetooth/hal/nrf52/ble_gap.c @@ -438,8 +438,8 @@ int BLE_GapExchangePairingFeature(BLE_GapConnHandle connHandle, BLE_GapPairingFe memset(&secParams,0,sizeof(secParams)); memset(&keysExchanged,0,sizeof(keysExchanged)); - //memset(&gapMem.wrapperBondInfo.ownEncKey,0,sizeof(gapMem.wrapperBondInfo.ownEncKey)); - //memset(&gapMem.wrapperBondInfo.ownIdKey,0,sizeof(gapMem.wrapperBondInfo.ownIdKey)); + memset(&gapMem.wrapperBondInfo.ownEncKey,0,sizeof(gapMem.wrapperBondInfo.ownEncKey)); + memset(&gapMem.wrapperBondInfo.ownIdKey,0,sizeof(gapMem.wrapperBondInfo.ownIdKey)); memset(&gapMem.wrapperBondInfo.peerEncKey,0,sizeof(gapMem.wrapperBondInfo.peerEncKey)); memset(&gapMem.wrapperBondInfo.peerIdKey,0,sizeof(gapMem.wrapperBondInfo.peerIdKey)); @@ -450,13 +450,13 @@ int BLE_GapExchangePairingFeature(BLE_GapConnHandle connHandle, BLE_GapPairingFe secParams.mitm = (pairingFeature->authReq & BLE_GAP_AUTH_MITM) >> 1; secParams.bond = (pairingFeature->authReq & BLE_GAP_AUTH_BOND) >> 0; - //secParams.kdist_own.enc = 1; - //secParams.kdist_own.id = 1; + secParams.kdist_own.enc = 1; + secParams.kdist_own.id = 1; secParams.kdist_peer.enc = 1; secParams.kdist_peer.id = 1; - //keysExchanged.keys_own.p_enc_key = &gapMem.wrapperBondInfo.ownEncKey; - //keysExchanged.keys_own.p_id_key = &gapMem.wrapperBondInfo.ownIdKey; + keysExchanged.keys_own.p_enc_key = &gapMem.wrapperBondInfo.ownEncKey; + keysExchanged.keys_own.p_id_key = &gapMem.wrapperBondInfo.ownIdKey; keysExchanged.keys_peer.p_enc_key = &gapMem.wrapperBondInfo.peerEncKey; keysExchanged.keys_peer.p_id_key = &gapMem.wrapperBondInfo.peerIdKey; diff --git a/sdk/modules/bluetooth/hal/nrf52/ble_storage_operations.c b/sdk/modules/bluetooth/hal/nrf52/ble_storage_operations.c index c63f47a45..3762634cf 100644 --- a/sdk/modules/bluetooth/hal/nrf52/ble_storage_operations.c +++ b/sdk/modules/bluetooth/hal/nrf52/ble_storage_operations.c @@ -58,7 +58,7 @@ #define BSO_FILE_PATH_NAME BSO_FILE_PATH"/%s" #define BSO_REGISTRY_DB "bso_registry_db" */ -#define REGDB_VALUE_MAX 60 +#define REGDB_VALUE_MAX 112 #define REGDB_KEY_NAME_MAX 4 /* #define BSO_FILE_NAME_MAX 64