diff --git a/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/include/dm_api.h b/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/include/dm_api.h index daadd5d91f..04271c308f 100644 --- a/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/include/dm_api.h +++ b/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/include/dm_api.h @@ -3035,6 +3035,18 @@ void DmSecSetLocalCsrk(uint8_t *pCsrk); /*************************************************************************************************/ void DmSecSetLocalIrk(uint8_t *pIrk); +/*************************************************************************************************/ +/*! + * \brief This function sets the local identity address used by the device. + * + * \param pAddr Pointer to the address. + * \param type Type of the address. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecSetLocalIdentityAddr(const uint8_t *pAddr, uint8_t type); + /*************************************************************************************************/ /*! * \brief This function generates an ECC key for use with LESC security. @@ -3345,6 +3357,25 @@ uint8_t *DmSecGetLocalCsrk(void); /*************************************************************************************************/ uint8_t *DmSecGetLocalIrk(void); +/*************************************************************************************************/ +/*! + * \brief For internal use only. This function gets the local identity address used by the device. + * + * \return Pointer to the identity address. + */ +/*************************************************************************************************/ +uint8_t *DmSecGetLocalIdentityAddr(void); + +/*************************************************************************************************/ +/*! + * \brief For internal use only. This function gets the local identity address type used by the + * device. + * + * \return The identity address type. + */ +/*************************************************************************************************/ +uint8_t DmSecGetLocalIdentityAddrType(void); + /*************************************************************************************************/ /*! * \brief For internal use only. Read the features of the remote device. diff --git a/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.c b/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.c index 7d66f73b32..c3869e3ec6 100644 --- a/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.c +++ b/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.c @@ -329,6 +329,7 @@ void DmSecInit(void) dmFcnIfTbl[DM_ID_SEC] = (dmFcnIf_t *) &dmSecFcnIf; dmSecCb.pCsrk = dmSecCb.pIrk = (uint8_t *) calc128Zeros; + dmSecCb.addrType = DM_ADDR_NONE; } /*************************************************************************************************/ @@ -363,6 +364,24 @@ void DmSecSetLocalIrk(uint8_t *pIrk) WsfTaskUnlock(); } +/*************************************************************************************************/ +/*! + * \brief This function sets the local identity address used by the device. + * + * \param pAddr Pointer to the address. + * \param type Type of the address. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecSetLocalIdentityAddr(const uint8_t *pAddr, uint8_t type) +{ + WsfTaskLock(); + dmSecCb.addrType = type; + BdaCpy(dmSecCb.bdAddr, pAddr); + WsfTaskUnlock(); +} + /*************************************************************************************************/ /*! * \brief This function gets the local CSRK used by the device. @@ -387,6 +406,39 @@ uint8_t *DmSecGetLocalIrk(void) return dmSecCb.pIrk; } +/*************************************************************************************************/ +/*! + * \brief For internal use only. This function gets the local identity address used by the device. + * + * \return Pointer to the identity address. + */ +/*************************************************************************************************/ +uint8_t *DmSecGetLocalIdentityAddr(void) +{ + if (dmSecCb.addrType != DM_ADDR_NONE) { + return dmSecCb.bdAddr; + } else { + return HciGetBdAddr(); + } +} + +/*************************************************************************************************/ +/*! + * \brief For internal use only. This function gets the local identity address type used by the + * device. + * + * \return The identity address type. + */ +/*************************************************************************************************/ +uint8_t DmSecGetLocalIdentityAddrType(void) +{ + if (dmSecCb.addrType != DM_ADDR_NONE) { + return dmSecCb.addrType; + } else { + return DM_ADDR_PUBLIC; + } +} + /*************************************************************************************************/ /*! * \brief Reset the sec module. diff --git a/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.h b/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.h index 6aa292a70b..7f3dd58113 100644 --- a/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.h +++ b/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.h @@ -83,6 +83,8 @@ typedef struct { uint8_t *pIrk; uint8_t *pCsrk; + bdAddr_t bdAddr; + uint8_t addrType; } dmSecCb_t; /************************************************************************************************** diff --git a/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/smp/smp_act.c b/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/smp/smp_act.c index 3c1ac36652..486c55cebd 100644 --- a/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/smp/smp_act.c +++ b/connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/smp/smp_act.c @@ -567,8 +567,8 @@ bool_t smpSendKey(smpCcb_t *pCcb, uint8_t keyDist) { /* send second part of IRK */ UINT8_TO_BSTREAM(p, SMP_CMD_ID_ADDR_INFO); - UINT8_TO_BSTREAM(p, DM_ADDR_PUBLIC); - BDA_TO_BSTREAM(p, HciGetBdAddr()); + UINT8_TO_BSTREAM(p, DmSecGetLocalIdentityAddrType()); + BDA_TO_BSTREAM(p, DmSecGetLocalIdentityAddr()); } else if ((keyDist & SMP_KEY_DIST_SIGN) &&