From a36b04fde56948bb42873ba4f9d198ff63f6acc7 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Fri, 7 Dec 2018 12:33:31 +0000 Subject: [PATCH] BLE: Add an option to inject the random static address during the reset sequence. --- .../TARGET_CORDIO/driver/CordioHCIDriver.cpp | 24 ++++++++++++++++++- .../TARGET_CORDIO/driver/CordioHCIDriver.h | 8 +++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp index 9ca29a336e..e9ae414f72 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp @@ -17,6 +17,7 @@ #include #include +#include "CordioBLE.h" #include "CordioHCIDriver.h" #include "hci_api.h" #include "hci_cmd.h" @@ -139,10 +140,26 @@ void CordioHCIDriver::handle_reset_sequence(uint8_t *pMsg) HciReadBdAddrCmd(); break; - case HCI_OPCODE_READ_BD_ADDR: + case HCI_OPCODE_READ_BD_ADDR: { /* parse and store event parameters */ BdaCpy(hciCoreCb.bdAddr, pMsg); + ble::address_t static_address; + + 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() + ); + } else { + /* send next command in sequence */ + HciLeReadBufSizeCmd(); + } + break; + } + + case HCI_OPCODE_LE_SET_RAND_ADDR: /* send next command in sequence */ HciLeReadBufSizeCmd(); break; @@ -246,6 +263,11 @@ void CordioHCIDriver::handle_reset_sequence(uint8_t *pMsg) } } +bool CordioHCIDriver::get_random_static_address(ble::address_t& address) +{ + return false; +} + void CordioHCIDriver::signal_reset_sequence_done() { hci_mbed_os_signal_reset_sequence_done(); diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h index a3b923e270..2db8ce02a3 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.h @@ -19,6 +19,7 @@ #include #include +#include #include "wsf_buf.h" #include "CordioHCITransportDriver.h" @@ -108,6 +109,13 @@ public: */ virtual void handle_reset_sequence(uint8_t *msg); + /** + * Get the random static address of the controller + * + * @return false if the address has not been set and true otherwise. + */ + virtual bool get_random_static_address(ble::address_t& address); + /** * Signal to the stack that the reset sequence has been done. */