From 761fc3f28840aae5c72dab571b2ece639f0a9408 Mon Sep 17 00:00:00 2001 From: Cassio Romanin de Lazaro Date: Mon, 16 Dec 2024 16:25:41 +0000 Subject: [PATCH] Add support to resolve MAC address Return the resolved MAC address instead of the random public one --- services/ble/Gap.cpp | 5 +++++ services/ble/Gap.hpp | 2 ++ services/ble/Gap.proto | 2 ++ services/ble/test/TestGapPairing.cpp | 4 ++++ services/ble/test_doubles/GapPairingMock.hpp | 1 + 5 files changed, 14 insertions(+) diff --git a/services/ble/Gap.cpp b/services/ble/Gap.cpp index 0082d0d1d..c18251872 100644 --- a/services/ble/Gap.cpp +++ b/services/ble/Gap.cpp @@ -56,6 +56,11 @@ namespace services GapPairingObserver::Subject().NumericComparisonConfirm(accept); } + hal::MacAddress GapPairingDecorator::ResolveDeviceAddress(hal::MacAddress deviceAddress) const + { + return GapPairingObserver::Subject().ResolveDeviceAddress(deviceAddress); + } + void GapBondingDecorator::NumberOfBondsChanged(std::size_t nrBonds) { GapBonding::NotifyObservers([&nrBonds](auto& obs) diff --git a/services/ble/Gap.hpp b/services/ble/Gap.hpp index 8a99a3691..f8128c401 100644 --- a/services/ble/Gap.hpp +++ b/services/ble/Gap.hpp @@ -164,6 +164,7 @@ namespace services virtual void AuthenticateWithPasskey(uint32_t passkey) = 0; virtual void NumericComparisonConfirm(bool accept) = 0; + virtual hal::MacAddress ResolveDeviceAddress(hal::MacAddress deviceAddress) const = 0; }; class GapPairingDecorator @@ -185,6 +186,7 @@ namespace services void SetIoCapabilities(IoCapabilities caps) override; void AuthenticateWithPasskey(uint32_t passkey) override; void NumericComparisonConfirm(bool accept) override; + hal::MacAddress ResolveDeviceAddress(hal::MacAddress deviceAddress) const override; }; class GapBonding; diff --git a/services/ble/Gap.proto b/services/ble/Gap.proto index a96a4ef2d..3fa7ca75a 100644 --- a/services/ble/Gap.proto +++ b/services/ble/Gap.proto @@ -194,6 +194,7 @@ service GapCentral rpc NumericComparisonConfirm(BoolValue) returns (Nothing) { option (method_id) = 10; } rpc RemoveAllBonds(Nothing) returns (Nothing) { option (method_id) = 11; } rpc SetDeviceDiscoveryFilter(DeviceDiscoveryFilter) returns (Nothing) { option (method_id) = 12; } + rpc ResolveDeviceAddress(Address) returns (Nothing) { option (method_id) = 13; } } service GapPeripheralResponse @@ -218,4 +219,5 @@ service GapCentralResponse rpc PairingFailed(PairingStatus) returns (Nothing) { option (method_id) = 5; } rpc NumberOfBondsChanged(UInt32Value) returns (Nothing) { option (method_id) = 6; } rpc DeviceStarted(Nothing) returns (Nothing) { option (method_id) = 7; } + rpc ResolveDeviceAddress(Address) returns (Nothing) { option (method_id) = 8; } } diff --git a/services/ble/test/TestGapPairing.cpp b/services/ble/test/TestGapPairing.cpp index 436b17390..334e85483 100644 --- a/services/ble/test/TestGapPairing.cpp +++ b/services/ble/test/TestGapPairing.cpp @@ -51,5 +51,9 @@ namespace services EXPECT_CALL(gapPairing, NumericComparisonConfirm(::testing::IsFalse())); decorator.NumericComparisonConfirm(false); + + hal::MacAddress mac = { 0x00, 0x1A, 0x7D, 0xDA, 0x71, 0x13 }; + EXPECT_CALL(gapPairing, ResolveDeviceAddress(mac)); + decorator.ResolveDeviceAddress(mac); } } diff --git a/services/ble/test_doubles/GapPairingMock.hpp b/services/ble/test_doubles/GapPairingMock.hpp index efd0f9a9b..1353d5564 100644 --- a/services/ble/test_doubles/GapPairingMock.hpp +++ b/services/ble/test_doubles/GapPairingMock.hpp @@ -16,6 +16,7 @@ namespace services MOCK_METHOD(void, SetIoCapabilities, (IoCapabilities caps)); MOCK_METHOD(void, AuthenticateWithPasskey, (uint32_t passkey)); MOCK_METHOD(void, NumericComparisonConfirm, (bool accept)); + MOCK_METHOD(hal::MacAddress, ResolveDeviceAddress, (hal::MacAddress deviceAddress), (const)); }; }