BLE: Add an HCI driver API to set the random static address.

pull/12321/head
Vincent Coubard 2020-01-28 13:20:17 +00:00
parent f469f710bc
commit c66dd7fd1f
6 changed files with 60 additions and 4 deletions

View File

@ -1257,6 +1257,13 @@ public:
#endif // BLE_FEATURE_PRIVACY
#if !defined(DOXYGEN_ONLY)
/*
* API reserverved for the controller driver to set the random static address.
* Setting a new random static address while the controller is operating is
* forbidden by the Bluetooth specification.
*/
ble_error_t setRandomStaticAddress(const ble::address_t& address);
protected:
/** Can only be called if use_non_deprecated_scan_api() hasn't been called.
* This guards against mixed use of deprecated and nondeprecated API.
@ -1407,6 +1414,7 @@ protected:
ble_error_t getCentralPrivacyConfiguration_(
central_privay_configuration_t *configuration
);
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
void useVersionOneAPI_() const;
void useVersionTwoAPI_() const;

View File

@ -306,6 +306,11 @@ public:
const BLEProtocol::AddressBytes_t address
);
/**
* @see Gap::setRandomStaticAddress
*/
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
/**
* @see Gap::getAddress
*/

View File

@ -494,6 +494,12 @@ ble_error_t Gap<Impl>::getCentralPrivacyConfiguration(
#endif // BLE_ROLE_OBSERVER
#endif // BLE_FEATURE_PRIVACY
template<class Impl>
ble_error_t Gap<Impl>::setRandomStaticAddress(const ble::address_t& address)
{
return impl()->setRandomStaticAddress_(address);
}
// -----------------------------------------------------------------------------
/* ------------------------- Default implementations ------------------------ */
// -----------------------------------------------------------------------------
@ -861,6 +867,12 @@ ble_error_t Gap<Impl>::getCentralPrivacyConfiguration_(
return BLE_ERROR_NOT_IMPLEMENTED;
}
template<class Impl>
ble_error_t Gap<Impl>::setRandomStaticAddress_(const ble::address_t& address)
{
return BLE_ERROR_NOT_IMPLEMENTED;
}
} // namespace interface
} // namespace ble

View File

@ -510,6 +510,26 @@ ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEve
}
}
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::setRandomStaticAddress_(
const ble::address_t& address
)
{
if (is_random_static_address(address.data()) == false) {
return BLE_ERROR_INVALID_PARAM;
}
ble_error_t err = _pal_gap.set_random_address(address);
if (err) {
return err;
}
_address_type = LegacyAddressType::RANDOM_STATIC;
_address = address;
_random_static_identity_address = address;
return BLE_ERROR_NONE;
}
template <template<class> class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler>
ble_error_t GenericGap<PalGapImpl, PalSecurityManager, ConnectionEventMonitorEventHandler>::getAddress_(
LegacyAddressType_t *type,

View File

@ -96,6 +96,13 @@ buf_pool_desc_t CordioHCIDriver::get_default_buffer_pool_description()
return buf_pool_desc_t(buffer, pool_desc);
}
void CordioHCIDriver::set_random_static_address(const ble::address_t& address)
{
ble_error_t err = cordio::BLE::deviceInstance().getGap().setRandomStaticAddress(address);
MBED_ASSERT(err == BLE_ERROR_NONE);
}
void CordioHCIDriver::start_reset_sequence()
{
/* send an HCI Reset command to start the sequence */
@ -148,10 +155,7 @@ void CordioHCIDriver::handle_reset_sequence(uint8_t *pMsg)
if (get_random_static_address(static_address)) {
// note: will send the HCI command to send the random address
cordio::BLE::deviceInstance().getGap().setAddress(
BLEProtocol::AddressType::RANDOM_STATIC,
static_address.data()
);
set_random_static_address(static_address.data());
} else {
/* send next command in sequence */
HciLeReadBufSizeCmd();

View File

@ -151,6 +151,13 @@ protected:
*/
buf_pool_desc_t get_default_buffer_pool_description();
/**
* Allows the driver to set a random static address. Unlike the HCI command
* this function reports the random static address to the whole BLE system.
* @param random_static_address The random static address to set.
*/
void set_random_static_address(const ble::address_t& random_static_address);
private:
/**
* Initialize the chip.