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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions hal_st/middlewares/ble_middleware/GapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion hal_st/middlewares/ble_middleware/GapCentralSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<hal::MacAddress> ResolvePrivateAddress(hal::MacAddress address) const override;
Expand Down
12 changes: 10 additions & 2 deletions hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment on lines +39 to +48
Copy link
Member

@danielschenk Daniël Schenk (danielschenk) Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there are two more types. I think this is safer

Suggested change
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;
}
switch (identityAddressType)
{
case GAP_PUBLIC_ADDR:
aci_hal_read_config_data(CONFIG_DATA_PUBADDR_OFFSET, &length, address.address.data());
address.type = services::GapDeviceAddressType::publicAddress;
break;
case GAP_STATIC_RANDOM_ADDR:
aci_hal_read_config_data(CONFIG_DATA_RANDOM_ADDRESS_OFFSET, &length, address.address.data());
address.type = services::GapDeviceAddressType::randomAddress;
break;
default:
LOG_AND_ABORT("unknown address type: %u", identityAddressType);
}

Copy link
Contributor

@heinwessels-philips heinwessels (heinwessels-philips) Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intended way to log the unexpected enum is: LOG_AND_ABORT_ENUM(identityAddressType);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not an enum, but I edited it to print the value regardless


return address;
}
Expand Down
15 changes: 8 additions & 7 deletions hal_st/middlewares/ble_middleware/GapSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<uint8_t, 8> events = { { 0x9F, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } };
hci_le_set_event_mask(events.data());
Expand Down Expand Up @@ -121,7 +122,7 @@ namespace hal
SecureConnection secureConnectionSupport = SecurityLevelToSecureConnection(level);
uint8_t mitmMode = SecurityLevelToMITM(level);

aci_gap_set_authentication_requirement(bondingMode, mitmMode, static_cast<uint8_t>(secureConnectionSupport), keypressNotificationSupport, 16, 16, 1, 111111, GAP_PUBLIC_ADDR);
aci_gap_set_authentication_requirement(bondingMode, mitmMode, static_cast<uint8_t>(secureConnectionSupport), keypressNotificationSupport, 16, 16, 1, 111111, identityAddressType);
}

void GapSt::SetIoCapabilities(services::GapPairing::IoCapabilities caps)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions hal_st/middlewares/ble_middleware/GapSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace hal

struct Configuration
{
const MacAddress& address;
const services::GapAddress& address;
const GapService& gapService;
const RootKeys& rootKeys;
const Security& security;
Expand Down Expand Up @@ -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
Expand All @@ -120,6 +120,7 @@ namespace hal
};

ConnectionContext connectionContext;
uint8_t identityAddressType;
uint8_t ownAddressType;
services::GapPairing::SecurityLevel securityLevel;

Expand Down
8 changes: 4 additions & 4 deletions hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<hal::MacAddress> ResolvePrivateAddress(hal::MacAddress address) const override;
Expand Down
Loading