Skip to content

Commit

Permalink
Add new logic for advertising data and fix code review
Browse files Browse the repository at this point in the history
  • Loading branch information
cassio-lazaro committed Jan 13, 2025
1 parent be9b76a commit 7e513fb
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
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 c77731ba79bfbe8af22450cf33fcdf4fd30a3587 # unreleased
GIT_TAG 863b57558fa785625d96758a3cbdcbbdd73ac8bd # unreleased
)
FetchContent_MakeAvailable(emil)

Expand Down
18 changes: 15 additions & 3 deletions hal_st/middlewares/ble_middleware/GapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,21 @@ namespace hal
return static_cast<services::GapAdvertisingEventType>(eventType);
}

services::GapAdvertisingEventAddressType ToAdvertisingAddressType(uint8_t addressType)
services::GapAdvertisingEventAddressType ToAdvertisingAddressType(uint8_t addressType, const uint8_t address[6])
{
return static_cast<services::GapAdvertisingEventAddressType>(addressType);
if (addressType == static_cast<uint8_t>(services::GapDeviceAddressType::publicAddress))
return services::GapAdvertisingEventAddressType::publicDeviceAddress;
else if (addressType == static_cast<uint8_t>(services::GapDeviceAddressType::randomAddress))
{
auto mode = address[5] >> 6; // Address in EUI-48 format
if (mode == 0x3)
return services::GapAdvertisingEventAddressType::randomDeviceAddress;
else if (mode == 0x01)
return services::GapAdvertisingEventAddressType::publicIdentityAddress;
else if (mode == 0x00)
return services::GapAdvertisingEventAddressType::randomIdentityAddress;
}
return services::GapAdvertisingEventAddressType::randomDeviceAddress;
}

bool IsTxDataLengthConfigured(const hci_le_data_length_change_event_rp0& dataLengthChangeEvent)
Expand Down Expand Up @@ -298,7 +310,7 @@ namespace hal
auto advertisementData = const_cast<uint8_t*>(&advertisingReport.Length_Data) + 1;
std::copy_n(std::begin(advertisingReport.Address), discoveredDevice.address.size(), std::begin(discoveredDevice.address));
discoveredDevice.eventType = ToAdvertisingEventType(advertisingReport.Event_Type);
discoveredDevice.addressType = ToAdvertisingAddressType(advertisingReport.Address_Type);
discoveredDevice.addressType = ToAdvertisingAddressType(advertisingReport.Address_Type, advertisingReport.Address);
discoveredDevice.data = infra::MemoryRange(advertisementData, advertisementData + advertisingReport.Length_Data);
discoveredDevice.rssi = static_cast<int8_t>(*const_cast<uint8_t*>(advertisementData + advertisingReport.Length_Data));

Expand Down
18 changes: 8 additions & 10 deletions hal_st/middlewares/ble_middleware/GapSt.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "hal_st/middlewares/ble_middleware/GapSt.hpp"
#include "ble_gap_aci.h"
#include "services/ble/Gap.hpp"
#include <algorithm>
#include <cstdint>

namespace hal
{
Expand Down Expand Up @@ -93,9 +91,9 @@ namespace hal
return numberOfBondedAddress;
}

bool GapSt::IsDeviceBounded(MacAddress deviceAddress) const
bool GapSt::IsDeviceBonded(MacAddress deviceAddress) const
{
return (aci_gap_is_device_bonded(static_cast<uint8_t>(PeerAddressType::PUBLIC), deviceAddress.data()) == BLE_STATUS_SUCCESS);
return aci_gap_is_device_bonded(static_cast<uint8_t>(PeerAddressType::publicStatic), deviceAddress.data()) == BLE_STATUS_SUCCESS;
}

void GapSt::Pair()
Expand Down Expand Up @@ -319,16 +317,16 @@ namespace hal

switch (static_cast<PeerAddressType>(peerAddressType))
{
case PeerAddressType::PUBLIC:
case PeerAddressType::RANDOM:
case PeerAddressType::publicStatic:
case PeerAddressType::randomStatic:
return peerAddressType;

case PeerAddressType::RESOLVED_PUBLIC_IDENTITY:
return infra::enum_cast(PeerAddressType::PUBLIC);
case PeerAddressType::resolvablePrivate:
return infra::enum_cast(PeerAddressType::publicStatic);

case PeerAddressType::RESOLVED_RANDOM_STATIC_IDENTITY:
case PeerAddressType::nonResolvablePrivate:
default:
return infra::enum_cast(PeerAddressType::RANDOM);
return infra::enum_cast(PeerAddressType::randomStatic);
}
};

Expand Down
10 changes: 5 additions & 5 deletions hal_st/middlewares/ble_middleware/GapSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace hal
void RemoveOldestBond() override;
std::size_t GetMaxNumberOfBonds() const override;
std::size_t GetNumberOfBonds() const override;
bool IsDeviceBounded(MacAddress deviceAddress) const override;
bool IsDeviceBonded(MacAddress deviceAddress) const override;

// Implementation of GapPairing
void Pair() override;
Expand Down Expand Up @@ -88,10 +88,10 @@ namespace hal
protected:
enum class PeerAddressType : uint8_t
{
PUBLIC,
RANDOM,
RESOLVED_PUBLIC_IDENTITY,
RESOLVED_RANDOM_STATIC_IDENTITY
publicStatic,
randomStatic,
resolvablePrivate,
nonResolvablePrivate
};

struct ConnectionContext
Expand Down
12 changes: 8 additions & 4 deletions hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ namespace hal
infra::Optional<hal::MacAddress> TracingGapCentralSt::ResolveDeviceAddress(hal::MacAddress deviceAddress) const
{
auto resolvedMac = GapCentralSt::ResolveDeviceAddress(deviceAddress);
tracer.Trace() << "TracingGapCentralSt::ResolveDeviceAddress, MAC address: " << infra::AsMacAddress(deviceAddress) << " resolved MAC address " << infra::AsMacAddress(*resolvedMac);
tracer.Trace() << "TracingGapCentralSt::ResolveDeviceAddress, MAC address: " << infra::AsMacAddress(deviceAddress);
if (resolvedMac)
tracer.Continue() << ", resolved MAC address " << infra::AsMacAddress(*resolvedMac);
else
tracer.Continue() << ", could not resolve MAC address";
return resolvedMac;
}

Expand Down Expand Up @@ -76,10 +80,10 @@ namespace hal
return GapCentralSt::GetNumberOfBonds();
}

bool TracingGapCentralSt::IsDeviceBounded(hal::MacAddress deviceAddress) const
bool TracingGapCentralSt::IsDeviceBonded(hal::MacAddress deviceAddress) const
{
auto ret = GapCentralSt::IsDeviceBounded(deviceAddress);
tracer.Trace() << "TracingGapCentralSt::IsDeviceBounded " << infra::AsMacAddress(deviceAddress) << " -> " << (ret ? "true" : "false");
auto ret = GapCentralSt::IsDeviceBonded(deviceAddress);
tracer.Trace() << "TracingGapCentralSt::IsDeviceBonded " << infra::AsMacAddress(deviceAddress) << " -> " << (ret ? "true" : "false");
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace hal
void RemoveOldestBond() override;
std::size_t GetMaxNumberOfBonds() const override;
std::size_t GetNumberOfBonds() const override;
bool IsDeviceBounded(hal::MacAddress deviceAddress) const override;
bool IsDeviceBonded(hal::MacAddress deviceAddress) const override;

// Implementation of GapPairing
void Pair() override;
Expand Down

0 comments on commit 7e513fb

Please sign in to comment.