Skip to content

Commit d6c5b2f

Browse files
authored
Merge pull request #13622 from pan-/cordio-configure-identity-address
Cordio configure identity address
2 parents de531fd + fd3bda3 commit d6c5b2f

File tree

13 files changed

+161
-40
lines changed

13 files changed

+161
-40
lines changed

connectivity/FEATURE_BLE/include/ble/Gap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,8 @@ class Gap {
14481448
* forbidden by the Bluetooth specification.
14491449
*/
14501450
ble_error_t setRandomStaticAddress(const ble::address_t& address);
1451+
1452+
ble::address_t getRandomStaticAddress();
14511453
#endif // !defined(DOXYGEN_ONLY)
14521454

14531455
private:

connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/include/dm_api.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3035,6 +3035,18 @@ void DmSecSetLocalCsrk(uint8_t *pCsrk);
30353035
/*************************************************************************************************/
30363036
void DmSecSetLocalIrk(uint8_t *pIrk);
30373037

3038+
/*************************************************************************************************/
3039+
/*!
3040+
* \brief This function sets the local identity address used by the device.
3041+
*
3042+
* \param pAddr Pointer to the address.
3043+
* \param type Type of the address.
3044+
*
3045+
* \return None.
3046+
*/
3047+
/*************************************************************************************************/
3048+
void DmSecSetLocalIdentityAddr(const uint8_t *pAddr, uint8_t type);
3049+
30383050
/*************************************************************************************************/
30393051
/*!
30403052
* \brief This function generates an ECC key for use with LESC security.
@@ -3345,6 +3357,25 @@ uint8_t *DmSecGetLocalCsrk(void);
33453357
/*************************************************************************************************/
33463358
uint8_t *DmSecGetLocalIrk(void);
33473359

3360+
/*************************************************************************************************/
3361+
/*!
3362+
* \brief For internal use only. This function gets the local identity address used by the device.
3363+
*
3364+
* \return Pointer to the identity address.
3365+
*/
3366+
/*************************************************************************************************/
3367+
uint8_t *DmSecGetLocalIdentityAddr(void);
3368+
3369+
/*************************************************************************************************/
3370+
/*!
3371+
* \brief For internal use only. This function gets the local identity address type used by the
3372+
* device.
3373+
*
3374+
* \return The identity address type.
3375+
*/
3376+
/*************************************************************************************************/
3377+
uint8_t DmSecGetLocalIdentityAddrType(void);
3378+
33483379
/*************************************************************************************************/
33493380
/*!
33503381
* \brief For internal use only. Read the features of the remote device.

connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ void DmSecInit(void)
329329
dmFcnIfTbl[DM_ID_SEC] = (dmFcnIf_t *) &dmSecFcnIf;
330330

331331
dmSecCb.pCsrk = dmSecCb.pIrk = (uint8_t *) calc128Zeros;
332+
dmSecCb.addrType = DM_ADDR_NONE;
332333
}
333334

334335
/*************************************************************************************************/
@@ -363,6 +364,24 @@ void DmSecSetLocalIrk(uint8_t *pIrk)
363364
WsfTaskUnlock();
364365
}
365366

367+
/*************************************************************************************************/
368+
/*!
369+
* \brief This function sets the local identity address used by the device.
370+
*
371+
* \param pAddr Pointer to the address.
372+
* \param type Type of the address.
373+
*
374+
* \return None.
375+
*/
376+
/*************************************************************************************************/
377+
void DmSecSetLocalIdentityAddr(const uint8_t *pAddr, uint8_t type)
378+
{
379+
WsfTaskLock();
380+
dmSecCb.addrType = type;
381+
BdaCpy(dmSecCb.bdAddr, pAddr);
382+
WsfTaskUnlock();
383+
}
384+
366385
/*************************************************************************************************/
367386
/*!
368387
* \brief This function gets the local CSRK used by the device.
@@ -387,6 +406,39 @@ uint8_t *DmSecGetLocalIrk(void)
387406
return dmSecCb.pIrk;
388407
}
389408

409+
/*************************************************************************************************/
410+
/*!
411+
* \brief For internal use only. This function gets the local identity address used by the device.
412+
*
413+
* \return Pointer to the identity address.
414+
*/
415+
/*************************************************************************************************/
416+
uint8_t *DmSecGetLocalIdentityAddr(void)
417+
{
418+
if (dmSecCb.addrType != DM_ADDR_NONE) {
419+
return dmSecCb.bdAddr;
420+
} else {
421+
return HciGetBdAddr();
422+
}
423+
}
424+
425+
/*************************************************************************************************/
426+
/*!
427+
* \brief For internal use only. This function gets the local identity address type used by the
428+
* device.
429+
*
430+
* \return The identity address type.
431+
*/
432+
/*************************************************************************************************/
433+
uint8_t DmSecGetLocalIdentityAddrType(void)
434+
{
435+
if (dmSecCb.addrType != DM_ADDR_NONE) {
436+
return dmSecCb.addrType;
437+
} else {
438+
return DM_ADDR_PUBLIC;
439+
}
440+
}
441+
390442
/*************************************************************************************************/
391443
/*!
392444
* \brief Reset the sec module.

connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/dm/dm_sec.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ typedef struct
8383
{
8484
uint8_t *pIrk;
8585
uint8_t *pCsrk;
86+
bdAddr_t bdAddr;
87+
uint8_t addrType;
8688
} dmSecCb_t;
8789

8890
/**************************************************************************************************

connectivity/FEATURE_BLE/libraries/cordio_stack/ble-host/sources/stack/smp/smp_act.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ bool_t smpSendKey(smpCcb_t *pCcb, uint8_t keyDist)
567567
{
568568
/* send second part of IRK */
569569
UINT8_TO_BSTREAM(p, SMP_CMD_ID_ADDR_INFO);
570-
UINT8_TO_BSTREAM(p, DM_ADDR_PUBLIC);
571-
BDA_TO_BSTREAM(p, HciGetBdAddr());
570+
UINT8_TO_BSTREAM(p, DmSecGetLocalIdentityAddrType());
571+
BDA_TO_BSTREAM(p, DmSecGetLocalIdentityAddr());
572572

573573
}
574574
else if ((keyDist & SMP_KEY_DIST_SIGN) &&

connectivity/FEATURE_BLE/source/Gap.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,4 +501,9 @@ ble_error_t Gap::setRandomStaticAddress(const ble::address_t &address)
501501
return impl->setRandomStaticAddress(address);
502502
}
503503

504+
ble::address_t Gap::getRandomStaticAddress()
505+
{
506+
return impl->getRandomStaticAddress();
507+
}
508+
504509
} // namespace ble

connectivity/FEATURE_BLE/source/cordio/source/PalSecurityManagerImpl.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,21 +220,6 @@ ble_error_t PalSecurityManager::set_private_address_timeout(
220220
return BLE_ERROR_NONE;
221221
}
222222

223-
/**
224-
* @see ::ble::PalSecurityManager::get_identity_address
225-
*/
226-
227-
ble_error_t PalSecurityManager::get_identity_address(
228-
address_t &address,
229-
bool &public_address
230-
)
231-
{
232-
// On cordio, the public address is hardcoded as the identity address.
233-
address = address_t(HciGetBdAddr());
234-
public_address = true;
235-
return BLE_ERROR_NONE;
236-
}
237-
238223
////////////////////////////////////////////////////////////////////////////
239224
// Keys
240225
//
@@ -288,6 +273,17 @@ ble_error_t PalSecurityManager::set_irk(const irk_t &irk)
288273
return BLE_ERROR_NONE;
289274
}
290275

276+
ble_error_t PalSecurityManager::set_identity_address(
277+
const address_t &address,
278+
bool public_address
279+
)
280+
{
281+
DmSecSetLocalIdentityAddr(
282+
address.data(),
283+
public_address ? DM_ADDR_PUBLIC : DM_ADDR_RANDOM
284+
);
285+
return BLE_ERROR_NONE;
286+
}
291287

292288
ble_error_t PalSecurityManager::set_csrk(
293289
const csrk_t &csrk,

connectivity/FEATURE_BLE/source/cordio/source/PalSecurityManagerImpl.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,6 @@ class PalSecurityManager final : public ble::PalSecurityManager {
183183
*/
184184
ble_error_t set_private_address_timeout(uint16_t timeout_in_seconds) final;
185185

186-
/**
187-
* @see ::ble::PalSecurityManager::get_identity_address
188-
*/
189-
ble_error_t get_identity_address(address_t &address, bool &public_address) final;
190-
191186
////////////////////////////////////////////////////////////////////////////
192187
// Keys
193188
//
@@ -214,6 +209,13 @@ class PalSecurityManager final : public ble::PalSecurityManager {
214209
*/
215210
ble_error_t set_irk(const irk_t &irk) final;
216211

212+
/**
213+
* @see ::ble::PalSecurityManager::set_identity_address
214+
*/
215+
ble_error_t set_identity_address(
216+
const address_t &address, bool public_address
217+
) final;
218+
217219
/**
218220
* @see ::ble::PalSecurityManager::set_csrk
219221
*/

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ ble_error_t Gap::setRandomStaticAddress(
415415
return BLE_ERROR_NONE;
416416
}
417417

418+
ble::address_t Gap::getRandomStaticAddress()
419+
{
420+
return _random_static_identity_address;
421+
}
418422

419423
ble_error_t Gap::getAddress(
420424
own_address_type_t &type,

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ class Gap :
346346
*/
347347
ble_error_t setRandomStaticAddress(const ble::address_t &address);
348348

349+
ble::address_t getRandomStaticAddress();
350+
349351
#endif // !defined(DOXYGEN_ONLY)
350352

351353
/* ===================================================================== */

0 commit comments

Comments
 (0)