Skip to content

Commit e7c9126

Browse files
committed
Add support to resolve MAC address
Return the resolved MAC address instead of the random public one
1 parent 50860b1 commit e7c9126

File tree

7 files changed

+31
-0
lines changed

7 files changed

+31
-0
lines changed

services/ble/Gap.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ namespace services
8484
return GapBondingObserver::Subject().GetNumberOfBonds();
8585
}
8686

87+
bool GapBondingDecorator::IsDeviceBounded(hal::MacAddress deviceAddress) const
88+
{
89+
return GapBondingObserver::Subject().IsDeviceBounded(deviceAddress);
90+
}
91+
8792
void GapPeripheralDecorator::StateChanged(GapState state)
8893
{
8994
GapPeripheral::NotifyObservers([&state](auto& obs)
@@ -178,6 +183,11 @@ namespace services
178183
GapCentralObserver::Subject().StopDeviceDiscovery();
179184
}
180185

186+
hal::MacAddress GapCentralDecorator::ResolveDeviceAddress(hal::MacAddress deviceAddress) const
187+
{
188+
return GapCentralObserver::Subject().ResolveDeviceAddress(deviceAddress);
189+
}
190+
181191
GapAdvertisingDataParser::GapAdvertisingDataParser(infra::ConstByteRange data)
182192
: data(data)
183193
{}

services/ble/Gap.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ namespace services
207207

208208
virtual std::size_t GetMaxNumberOfBonds() const = 0;
209209
virtual std::size_t GetNumberOfBonds() const = 0;
210+
virtual bool IsDeviceBounded(hal::MacAddress deviceAddress) const = 0;
210211
};
211212

212213
class GapBondingDecorator
@@ -224,6 +225,7 @@ namespace services
224225
void RemoveOldestBond() override;
225226
std::size_t GetMaxNumberOfBonds() const override;
226227
std::size_t GetNumberOfBonds() const override;
228+
bool IsDeviceBounded(hal::MacAddress deviceAddress) const override;
227229
};
228230

229231
class GapPeripheral;
@@ -317,6 +319,7 @@ namespace services
317319
virtual void SetAddress(hal::MacAddress macAddress, GapDeviceAddressType addressType) = 0;
318320
virtual void StartDeviceDiscovery() = 0;
319321
virtual void StopDeviceDiscovery() = 0;
322+
virtual hal::MacAddress ResolveDeviceAddress(hal::MacAddress deviceAddress) const = 0;
320323
};
321324

322325
class GapCentralDecorator
@@ -337,6 +340,7 @@ namespace services
337340
void SetAddress(hal::MacAddress macAddress, GapDeviceAddressType addressType) override;
338341
void StartDeviceDiscovery() override;
339342
void StopDeviceDiscovery() override;
343+
hal::MacAddress ResolveDeviceAddress(hal::MacAddress deviceAddress) const override;
340344
};
341345
}
342346

services/ble/Gap.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ service GapCentral
194194
rpc NumericComparisonConfirm(BoolValue) returns (Nothing) { option (method_id) = 10; }
195195
rpc RemoveAllBonds(Nothing) returns (Nothing) { option (method_id) = 11; }
196196
rpc SetDeviceDiscoveryFilter(DeviceDiscoveryFilter) returns (Nothing) { option (method_id) = 12; }
197+
rpc ResolveDeviceAddress(Address) returns (Nothing) { option (method_id) = 13; }
198+
rpc IsDeviceBounded(Address) returns (Nothing) { option (method_id) = 14; }
197199
}
198200

199201
service GapPeripheralResponse
@@ -218,4 +220,6 @@ service GapCentralResponse
218220
rpc PairingFailed(PairingStatus) returns (Nothing) { option (method_id) = 5; }
219221
rpc NumberOfBondsChanged(UInt32Value) returns (Nothing) { option (method_id) = 6; }
220222
rpc DeviceStarted(Nothing) returns (Nothing) { option (method_id) = 7; }
223+
rpc ResolveDeviceAddress(Address) returns (Nothing) { option (method_id) = 8; }
224+
rpc IsDeviceBounded(Address) returns (Nothing) { option (method_id) = 9; }
221225
}

services/ble/test/TestGapBonding.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,12 @@ namespace services
4141

4242
EXPECT_CALL(gapBonding, GetNumberOfBonds()).WillOnce(testing::Return(5));
4343
EXPECT_EQ(decorator.GetNumberOfBonds(), 5);
44+
45+
hal::MacAddress mac = { 0x00, 0x1A, 0x7D, 0xDA, 0x71, 0x13 };
46+
EXPECT_CALL(gapBonding, IsDeviceBounded(mac)).WillOnce(testing::Return(true));
47+
EXPECT_THAT(decorator.IsDeviceBounded(mac), testing::IsTrue());
48+
49+
EXPECT_CALL(gapBonding, IsDeviceBounded(mac)).WillOnce(testing::Return(false));
50+
EXPECT_THAT(decorator.IsDeviceBounded(mac), testing::IsFalse());
4451
}
4552
}

services/ble/test/TestGapCentral.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ namespace services
7979

8080
EXPECT_CALL(gap, StopDeviceDiscovery());
8181
decorator.StopDeviceDiscovery();
82+
83+
hal::MacAddress mac = { 0x00, 0x1A, 0x7D, 0xDA, 0x71, 0x13 };
84+
EXPECT_CALL(gap, ResolveDeviceAddress(mac));
85+
decorator.ResolveDeviceAddress(mac);
8286
}
8387

8488
TEST(GapAdvertisingDataParserTest, payload_too_small)

services/ble/test_doubles/GapBondingMock.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace services
1414
MOCK_METHOD(void, RemoveOldestBond, ());
1515
MOCK_METHOD(std::size_t, GetMaxNumberOfBonds, (), (const));
1616
MOCK_METHOD(std::size_t, GetNumberOfBonds, (), (const));
17+
MOCK_METHOD(bool, IsDeviceBounded, (hal::MacAddress deviceAddress), (const));
1718
};
1819
}
1920

services/ble/test_doubles/GapCentralMock.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace services
1616
MOCK_METHOD(void, SetAddress, (hal::MacAddress macAddress, GapDeviceAddressType addressType));
1717
MOCK_METHOD(void, StartDeviceDiscovery, ());
1818
MOCK_METHOD(void, StopDeviceDiscovery, ());
19+
MOCK_METHOD(hal::MacAddress, ResolveDeviceAddress, (hal::MacAddress deviceAddress), (const));
1920
};
2021
}
2122

0 commit comments

Comments
 (0)