Skip to content

Ble driver set random static address #12321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions features/FEATURE_BLE/ble/gap/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,13 @@ class Gap : public StaticInterface<Impl, Gap> {
#endif // BLE_FEATURE_PRIVACY

#if !defined(DOXYGEN_ONLY)
/*
* API reserved 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.
Expand Down Expand Up @@ -1407,6 +1414,7 @@ class Gap : public StaticInterface<Impl, Gap> {
ble_error_t getCentralPrivacyConfiguration_(
central_privay_configuration_t *configuration
);
ble_error_t setRandomStaticAddress_(const ble::address_t& address);
void useVersionOneAPI_() const;
void useVersionTwoAPI_() const;

Expand Down
5 changes: 5 additions & 0 deletions features/FEATURE_BLE/ble/generic/GenericGap.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ class GenericGap :
const BLEProtocol::AddressBytes_t address
);

/**
* @see Gap::setRandomStaticAddress
*/
ble_error_t setRandomStaticAddress_(const ble::address_t& address);

/**
* @see Gap::getAddress
*/
Expand Down
12 changes: 12 additions & 0 deletions features/FEATURE_BLE/source/gap/Gap.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------ */
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -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

20 changes: 20 additions & 0 deletions features/FEATURE_BLE/source/generic/GenericGap.tpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ class CordioHCIDriver {
*/
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,7 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg)
memcpy(addr, pMsg, sizeof(addr));
DM_RAND_ADDR_SET(addr, DM_RAND_ADDR_STATIC);
// note: will invoke set rand address
cordio::BLE::deviceInstance().getGap().setAddress(
BLEProtocol::AddressType::RANDOM_STATIC,
addr
);
set_random_static_address(addr);
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
memcpy(addr, pMsg, sizeof(addr));
DM_RAND_ADDR_SET(addr, DM_RAND_ADDR_STATIC);
// note: will invoke set rand address
cordio::BLE::deviceInstance().getGap().setAddress(
BLEProtocol::AddressType::RANDOM_STATIC,
addr
);
set_random_static_address(addr);
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
memcpy(addr, pMsg, sizeof(addr));
DM_RAND_ADDR_SET(addr, DM_RAND_ADDR_STATIC);
// note: will invoke set rand address
cordio::BLE::deviceInstance().getGap().setAddress(
BLEProtocol::AddressType::RANDOM_STATIC,
addr
);
set_random_static_address(addr);
}
break;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,7 @@ class HCIDriver : public cordio::CordioHCIDriver {
memcpy(addr, pMsg, sizeof(addr));
DM_RAND_ADDR_SET(addr, DM_RAND_ADDR_STATIC);
// note: will invoke set rand address
cordio::BLE::deviceInstance().getGap().setAddress(
BLEProtocol::AddressType::RANDOM_STATIC,
addr
);
set_random_static_address(addr);
}
break;

Expand Down