Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions services/ble/Gap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ namespace services
GapCentralObserver::Subject().Disconnect();
}

void GapCentralDecorator::SetAddress(hal::MacAddress macAddress, GapDeviceAddressType addressType)
void GapCentralDecorator::SetAddress(services::GapAddress address)
{
GapCentralObserver::Subject().SetAddress(macAddress, addressType);
GapCentralObserver::Subject().SetAddress(address);
}

void GapCentralDecorator::StartDeviceDiscovery()
Expand Down Expand Up @@ -393,6 +393,14 @@ namespace services
AddData(payload, infra::ReinterpretCastMemoryRange<const uint8_t>(infra::MakeRangeFromSingleObject(address)));
}

void GapAdvertisementFormatter::AppendRandomTargetAddress(hal::MacAddress address)
{
really_assert(sizeof(address) + headerSize <= RemainingSpaceAvailable());

AddHeader(payload, sizeof(address), GapAdvertisementDataType::randomTargetAddress);
AddData(payload, infra::ReinterpretCastMemoryRange<const uint8_t>(infra::MakeRangeFromSingleObject(address)));
}

void GapAdvertisementFormatter::AppendAppearance(uint16_t appearance)
{
really_assert(sizeof(appearance) + headerSize <= RemainingSpaceAvailable());
Expand Down
6 changes: 4 additions & 2 deletions services/ble/Gap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace services
shortenedLocalName = 0x08u,
completeLocalName = 0x09u,
publicTargetAddress = 0x17u,
randomTargetAddress = 0x18u,
appearance = 0x19u,
manufacturerSpecificData = 0xffu
};
Expand Down Expand Up @@ -333,6 +334,7 @@ namespace services
void AppendListOfServicesUuid(infra::MemoryRange<AttAttribute::Uuid16> services);
void AppendListOfServicesUuid(infra::MemoryRange<AttAttribute::Uuid128> services);
void AppendPublicTargetAddress(hal::MacAddress address);
void AppendRandomTargetAddress(hal::MacAddress address);
void AppendAppearance(uint16_t appearance);

infra::ConstByteRange FormattedAdvertisementData() const;
Expand Down Expand Up @@ -372,7 +374,7 @@ namespace services
virtual void Connect(hal::MacAddress macAddress, GapDeviceAddressType addressType, infra::Duration initiatingTimeout) = 0;
virtual void CancelConnect() = 0;
virtual void Disconnect() = 0;
virtual void SetAddress(hal::MacAddress macAddress, GapDeviceAddressType addressType) = 0;
virtual void SetAddress(services::GapAddress address) = 0;
virtual void StartDeviceDiscovery() = 0;
virtual void StopDeviceDiscovery() = 0;
virtual std::optional<hal::MacAddress> ResolvePrivateAddress(hal::MacAddress address) const = 0;
Expand All @@ -393,7 +395,7 @@ namespace services
void Connect(hal::MacAddress macAddress, GapDeviceAddressType addressType, infra::Duration initiatingTimeout) override;
void CancelConnect() override;
void Disconnect() override;
void SetAddress(hal::MacAddress macAddress, GapDeviceAddressType addressType) override;
void SetAddress(services::GapAddress address) override;
void StartDeviceDiscovery() override;
void StopDeviceDiscovery() override;
std::optional<hal::MacAddress> ResolvePrivateAddress(hal::MacAddress address) const override;
Expand Down
18 changes: 18 additions & 0 deletions services/ble/test/TestGapAdvertisementFormatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ namespace services
EXPECT_EQ(data[7], 0x06);
}

TEST_F(GapAdvertisementFormatterTest, append_random_target_address)
{
hal::MacAddress address({ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 });

formatter.AppendRandomTargetAddress(address);

auto data = formatter.FormattedAdvertisementData();
EXPECT_EQ(data.size(), 8);
EXPECT_EQ(data[0], 7);
EXPECT_EQ(data[1], 0x18);
EXPECT_EQ(data[2], 0x01);
EXPECT_EQ(data[3], 0x02);
EXPECT_EQ(data[4], 0x03);
EXPECT_EQ(data[5], 0x04);
EXPECT_EQ(data[6], 0x05);
EXPECT_EQ(data[7], 0x06);
}

TEST_F(GapAdvertisementFormatterTest, multiple_append_operations)
{
formatter.AppendFlags(GapPeripheral::AdvertisementFlags::leGeneralDiscoverableMode);
Expand Down
4 changes: 2 additions & 2 deletions services/ble/test/TestGapCentral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ namespace services
EXPECT_CALL(gap, Disconnect());
decorator.Disconnect();

EXPECT_CALL(gap, SetAddress(MacAddressContentsEqual(macAddress), GapDeviceAddressType::publicAddress));
decorator.SetAddress(macAddress, GapDeviceAddressType::publicAddress);
EXPECT_CALL(gap, SetAddress(testing::Eq(GapAddress{ macAddress, GapDeviceAddressType::publicAddress })));
decorator.SetAddress({ macAddress, GapDeviceAddressType::publicAddress });

EXPECT_CALL(gap, StartDeviceDiscovery());
decorator.StartDeviceDiscovery();
Expand Down
2 changes: 1 addition & 1 deletion services/ble/test_doubles/GapCentralMock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace services
MOCK_METHOD(void, Connect, (hal::MacAddress macAddress, GapDeviceAddressType addressType, infra::Duration initiatingTimeout));
MOCK_METHOD(void, CancelConnect, ());
MOCK_METHOD(void, Disconnect, ());
MOCK_METHOD(void, SetAddress, (hal::MacAddress macAddress, GapDeviceAddressType addressType));
MOCK_METHOD(void, SetAddress, (services::GapAddress address));
MOCK_METHOD(void, StartDeviceDiscovery, ());
MOCK_METHOD(void, StopDeviceDiscovery, ());
MOCK_METHOD(std::optional<hal::MacAddress>, ResolvePrivateAddress, (hal::MacAddress address), (const));
Expand Down
Loading