From dbf4cdb698d626bc070e6b8a1fae45a289bb01a6 Mon Sep 17 00:00:00 2001 From: Hugues Kamba Date: Tue, 7 Jan 2020 13:06:13 +0000 Subject: [PATCH] Replace deprecated BLE API calls As the `LegacyGap` class has been deprecated, in favor of the `Gap` class, all references of its references in the code base has been replaced. --- .../TARGET_CORDIO/driver/CordioHCIDriver.cpp | 17 ++++++++++------- .../TARGET_CORDIO_ODIN_W2/HCIDriver.cpp | 19 +++++++++++-------- .../COMPONENT_CYW43XXX/HCIDriver.cpp | 19 +++++++++++-------- .../TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp | 19 +++++++++++-------- .../stm32wb_HCIDriver.cpp | 19 +++++++++++-------- 5 files changed, 54 insertions(+), 39 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp index d166424efa8..f88bb0283b8 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/driver/CordioHCIDriver.cpp @@ -144,14 +144,17 @@ void CordioHCIDriver::handle_reset_sequence(uint8_t *pMsg) /* parse and store event parameters */ BdaCpy(hciCoreCb.bdAddr, pMsg); - ble::address_t static_address; - - if (get_random_static_address(static_address)) { + const ble::peripheral_privacy_configuration_t configuration = { + .use_non_resolvable_random_address = false, + .resolution_strategy = ble::peripheral_privacy_configuration_t::DO_NOT_RESOLVE + }; + + if ( + cordio::BLE::deviceInstance().getGap( + ).setPeripheralPrivacyConfiguration(&configuration) + ) { // note: will send the HCI command to send the random address - cordio::BLE::deviceInstance().getGap().setAddress( - BLEProtocol::AddressType::RANDOM_STATIC, - static_address.data() - ); + cordio::BLE::deviceInstance().getGap().enablePrivacy(false); } else { /* send next command in sequence */ HciLeReadBufSizeCmd(); diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp index d49198a304e..fd4e7a0d457 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO_ODIN_W2/HCIDriver.cpp @@ -337,14 +337,17 @@ void ble::vendor::odin_w2::HCIDriver::handle_reset_sequence(uint8_t *pMsg) randCnt++; HciLeRandCmd(); } else { - uint8_t addr[6] = { 0 }; - 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 - ); + const ble::peripheral_privacy_configuration_t configuration = { + .use_non_resolvable_random_address = false, + .resolution_strategy = ble::peripheral_privacy_configuration_t::DO_NOT_RESOLVE + }; + if ( + cordio::BLE::deviceInstance().getGap( + ).setPeripheralPrivacyConfiguration(&configuration) + ) { + // note: will invoke set rand address + cordio::BLE::deviceInstance().getGap().enablePrivacy(false); + } } break; diff --git a/features/FEATURE_BLE/targets/TARGET_Cypress/COMPONENT_CYW43XXX/HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_Cypress/COMPONENT_CYW43XXX/HCIDriver.cpp index e51294df66c..9c0fe89752f 100644 --- a/features/FEATURE_BLE/targets/TARGET_Cypress/COMPONENT_CYW43XXX/HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_Cypress/COMPONENT_CYW43XXX/HCIDriver.cpp @@ -297,14 +297,17 @@ class HCIDriver : public cordio::CordioHCIDriver { randCnt++; HciLeRandCmd(); } else { - uint8_t addr[6] = { 0 }; - 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 - ); + const ble::peripheral_privacy_configuration_t configuration = { + .use_non_resolvable_random_address = false, + .resolution_strategy = ble::peripheral_privacy_configuration_t::DO_NOT_RESOLVE + }; + if ( + cordio::BLE::deviceInstance().getGap( + ).setPeripheralPrivacyConfiguration(&configuration) + ) { + // note: will invoke set rand address + cordio::BLE::deviceInstance().getGap().enablePrivacy(false); + } } break; diff --git a/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp index 545889c914f..0819133b9f7 100644 --- a/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_STM/TARGET_CYW4343X/HCIDriver.cpp @@ -261,14 +261,17 @@ class HCIDriver : public cordio::CordioHCIDriver { randCnt++; HciLeRandCmd(); } else { - uint8_t addr[6] = { 0 }; - 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 - ); + const ble::peripheral_privacy_configuration_t configuration = { + .use_non_resolvable_random_address = false, + .resolution_strategy = ble::peripheral_privacy_configuration_t::DO_NOT_RESOLVE + }; + if ( + cordio::BLE::deviceInstance().getGap( + ).setPeripheralPrivacyConfiguration(&configuration) + ) { + // note: will invoke set rand address + cordio::BLE::deviceInstance().getGap().enablePrivacy(false); + } } break; diff --git a/features/FEATURE_BLE/targets/TARGET_STM/TARGET_NUCLEO_WB55RG/stm32wb_HCIDriver.cpp b/features/FEATURE_BLE/targets/TARGET_STM/TARGET_NUCLEO_WB55RG/stm32wb_HCIDriver.cpp index 9fa45582ab3..fd7dc65430e 100644 --- a/features/FEATURE_BLE/targets/TARGET_STM/TARGET_NUCLEO_WB55RG/stm32wb_HCIDriver.cpp +++ b/features/FEATURE_BLE/targets/TARGET_STM/TARGET_NUCLEO_WB55RG/stm32wb_HCIDriver.cpp @@ -307,14 +307,17 @@ class HCIDriver : public cordio::CordioHCIDriver randCnt++; HciLeRandCmd(); } else { - uint8_t addr[6] = { 0 }; - 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 - ); + const ble::peripheral_privacy_configuration_t configuration = { + .use_non_resolvable_random_address = false, + .resolution_strategy = ble::peripheral_privacy_configuration_t::DO_NOT_RESOLVE + }; + if ( + cordio::BLE::deviceInstance().getGap( + ).setPeripheralPrivacyConfiguration(&configuration) + ) { + // note: will invoke set rand address + cordio::BLE::deviceInstance().getGap().enablePrivacy(false); + } } break;