diff --git a/CMakeLists.txt b/CMakeLists.txt index 637bf4a6..740e1018 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,7 @@ if (HALST_STANDALONE) FetchContent_Declare( emil GIT_REPOSITORY https://github.com/philips-software/amp-embedded-infra-lib.git - GIT_TAG bcb58544b493ae12f1215b565acfb0bd73f2295c # unreleased + GIT_TAG 997c85e30b4e712764f3853059181b6e1e09f43a # unreleased ) FetchContent_MakeAvailable(emil) diff --git a/hal_st/middlewares/ble_middleware/GapCentralSt.cpp b/hal_st/middlewares/ble_middleware/GapCentralSt.cpp index 207ca77c..a39c6d4f 100644 --- a/hal_st/middlewares/ble_middleware/GapCentralSt.cpp +++ b/hal_st/middlewares/ble_middleware/GapCentralSt.cpp @@ -94,9 +94,9 @@ namespace hal aci_gap_terminate(connectionContext.connectionHandle, remoteUserTerminatedConnection); } - void GapCentralSt::SetAddress(hal::MacAddress macAddress, services::GapDeviceAddressType addressType) + void GapCentralSt::SetAddress(services::GapAddress address) { - GapSt::SetAddress(macAddress, addressType); + GapSt::SetAddress(address); } void GapCentralSt::StartDeviceDiscovery() diff --git a/hal_st/middlewares/ble_middleware/GapCentralSt.hpp b/hal_st/middlewares/ble_middleware/GapCentralSt.hpp index da3d0d72..59a8d0b9 100644 --- a/hal_st/middlewares/ble_middleware/GapCentralSt.hpp +++ b/hal_st/middlewares/ble_middleware/GapCentralSt.hpp @@ -5,6 +5,7 @@ #include "hal_st/middlewares/ble_middleware/GapSt.hpp" #include "infra/timer/Timer.hpp" #include "infra/util/AutoResetFunction.hpp" +#include "services/ble/Gap.hpp" namespace hal { @@ -19,7 +20,7 @@ namespace hal void Connect(hal::MacAddress macAddress, services::GapDeviceAddressType addressType, infra::Duration initiatingTimeout) override; void CancelConnect() override; void Disconnect() override; - void SetAddress(hal::MacAddress macAddress, services::GapDeviceAddressType addressType) override; + void SetAddress(services::GapAddress address) override; void StartDeviceDiscovery() override; void StopDeviceDiscovery() override; std::optional ResolvePrivateAddress(hal::MacAddress address) const override; diff --git a/hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp b/hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp index 5a810528..7c88379b 100644 --- a/hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp +++ b/hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp @@ -36,8 +36,16 @@ namespace hal services::GapAddress address; uint8_t length = 0; - aci_hal_read_config_data(CONFIG_DATA_PUBADDR_OFFSET, &length, address.address.data()); - address.type = services::GapDeviceAddressType::publicAddress; + if (identityAddressType == GAP_PUBLIC_ADDR) + { + aci_hal_read_config_data(CONFIG_DATA_PUBADDR_OFFSET, &length, address.address.data()); + address.type = services::GapDeviceAddressType::publicAddress; + } + else + { + aci_hal_read_config_data(CONFIG_DATA_RANDOM_ADDRESS_OFFSET, &length, address.address.data()); + address.type = services::GapDeviceAddressType::randomAddress; + } return address; } diff --git a/hal_st/middlewares/ble_middleware/GapSt.cpp b/hal_st/middlewares/ble_middleware/GapSt.cpp index 7ee29c71..6590ea42 100644 --- a/hal_st/middlewares/ble_middleware/GapSt.cpp +++ b/hal_st/middlewares/ble_middleware/GapSt.cpp @@ -36,7 +36,8 @@ namespace hal GapSt::GapSt(hal::HciEventSource& hciEventSource, services::BondStorageSynchronizer& bondStorageSynchronizer, const Configuration& configuration) : HciEventSink(hciEventSource) - , ownAddressType(configuration.privacy ? GAP_RESOLVABLE_PRIVATE_ADDR : GAP_PUBLIC_ADDR) + , identityAddressType(configuration.address.type == services::GapDeviceAddressType::publicAddress ? GAP_PUBLIC_ADDR : GAP_STATIC_RANDOM_ADDR) + , ownAddressType(configuration.privacy ? GAP_RESOLVABLE_PRIVATE_ADDR : identityAddressType) , securityLevel(configuration.security.securityLevel) , bondStorageSynchronizer(bondStorageSynchronizer) { @@ -54,7 +55,7 @@ namespace hal aci_hal_set_tx_power_level(1, configuration.txPowerLevel); aci_gatt_init(); - aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, CONFIG_DATA_PUBADDR_LEN, configuration.address.data()); + SetAddress(configuration.address); const std::array events = { { 0x9F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; hci_le_set_event_mask(events.data()); @@ -121,7 +122,7 @@ namespace hal SecureConnection secureConnectionSupport = SecurityLevelToSecureConnection(level); uint8_t mitmMode = SecurityLevelToMITM(level); - aci_gap_set_authentication_requirement(bondingMode, mitmMode, static_cast(secureConnectionSupport), keypressNotificationSupport, 16, 16, 1, 111111, GAP_PUBLIC_ADDR); + aci_gap_set_authentication_requirement(bondingMode, mitmMode, static_cast(secureConnectionSupport), keypressNotificationSupport, 16, 16, 1, 111111, identityAddressType); } void GapSt::SetIoCapabilities(services::GapPairing::IoCapabilities caps) @@ -286,12 +287,12 @@ namespace hal }); } - void GapSt::SetAddress(const hal::MacAddress& address, services::GapDeviceAddressType addressType) const + void GapSt::SetAddress(services::GapAddress address) const { - uint8_t offset = addressType == services::GapDeviceAddressType::publicAddress ? CONFIG_DATA_PUBADDR_OFFSET : CONFIG_DATA_RANDOM_ADDRESS_OFFSET; - uint8_t length = addressType == services::GapDeviceAddressType::publicAddress ? CONFIG_DATA_PUBADDR_LEN : CONFIG_DATA_RANDOM_ADDRESS_LEN; + uint8_t offset = address.type == services::GapDeviceAddressType::publicAddress ? CONFIG_DATA_PUBADDR_OFFSET : CONFIG_DATA_RANDOM_ADDRESS_OFFSET; + uint8_t length = address.type == services::GapDeviceAddressType::publicAddress ? CONFIG_DATA_PUBADDR_LEN : CONFIG_DATA_RANDOM_ADDRESS_LEN; - aci_hal_write_config_data(offset, length, address.data()); + aci_hal_write_config_data(offset, length, address.address.data()); } void GapSt::HciEvent(hci_event_pckt& event) diff --git a/hal_st/middlewares/ble_middleware/GapSt.hpp b/hal_st/middlewares/ble_middleware/GapSt.hpp index f65c61a1..88d004f1 100644 --- a/hal_st/middlewares/ble_middleware/GapSt.hpp +++ b/hal_st/middlewares/ble_middleware/GapSt.hpp @@ -43,7 +43,7 @@ namespace hal struct Configuration { - const MacAddress& address; + const services::GapAddress& address; const GapService& gapService; const RootKeys& rootKeys; const Security& security; @@ -98,7 +98,7 @@ namespace hal [[nodiscard]] virtual SecureConnection SecurityLevelToSecureConnection(services::GapPairing::SecurityLevel level) const; [[nodiscard]] virtual uint8_t SecurityLevelToMITM(services::GapPairing::SecurityLevel level) const; - void SetAddress(const MacAddress& address, services::GapDeviceAddressType addressType) const; + void SetAddress(services::GapAddress address) const; private: // Implementation of HciEventSink @@ -120,6 +120,7 @@ namespace hal }; ConnectionContext connectionContext; + uint8_t identityAddressType; uint8_t ownAddressType; services::GapPairing::SecurityLevel securityLevel; diff --git a/hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp b/hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp index 2f7e5cef..fe06b72f 100644 --- a/hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp +++ b/hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp @@ -24,13 +24,13 @@ namespace hal GapCentralSt::Disconnect(); } - void TracingGapCentralSt::SetAddress(hal::MacAddress macAddress, services::GapDeviceAddressType addressType) + void TracingGapCentralSt::SetAddress(services::GapAddress address) { tracer.Trace() << "TracingGapCentralSt::SetAddress, MAC address: " - << infra::AsMacAddress(macAddress) + << infra::AsMacAddress(address.address) << ", type: " - << addressType; - GapCentralSt::SetAddress(macAddress, addressType); + << address.type; + GapCentralSt::SetAddress(address); } void TracingGapCentralSt::StartDeviceDiscovery() diff --git a/hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp b/hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp index 79bf8639..c1c2327d 100644 --- a/hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp +++ b/hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp @@ -15,7 +15,7 @@ namespace hal // Implementation of services::GapCentral void Connect(hal::MacAddress macAddress, services::GapDeviceAddressType addressType, infra::Duration initiatingTimeout) override; void Disconnect() override; - void SetAddress(hal::MacAddress macAddress, services::GapDeviceAddressType addressType) override; + void SetAddress(services::GapAddress address) override; void StartDeviceDiscovery() override; void StopDeviceDiscovery() override; std::optional ResolvePrivateAddress(hal::MacAddress address) const override;