Skip to content

Commit

Permalink
Changes after sync up with Oguzcan
Browse files Browse the repository at this point in the history
  • Loading branch information
cassio-lazaro committed Dec 19, 2024
1 parent 1f26321 commit be9b76a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 27 deletions.
8 changes: 8 additions & 0 deletions hal_st/middlewares/ble_middleware/GapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ namespace hal
aci_gap_terminate_gap_proc(GAP_GENERAL_DISCOVERY_PROC);
}

infra::Optional<hal::MacAddress> GapCentralSt::ResolveDeviceAddress(hal::MacAddress deviceAddress) const
{
hal::MacAddress address;
if (aci_gap_resolve_private_addr(deviceAddress.data(), address.data()) != BLE_STATUS_SUCCESS)
return infra::none;
return infra::MakeOptional(address);
}

void GapCentralSt::AllowPairing(bool)
{}

Expand Down
1 change: 1 addition & 0 deletions hal_st/middlewares/ble_middleware/GapCentralSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace hal
void SetAddress(hal::MacAddress macAddress, services::GapDeviceAddressType addressType) override;
void StartDeviceDiscovery() override;
void StopDeviceDiscovery() override;
infra::Optional<hal::MacAddress> ResolveDeviceAddress(hal::MacAddress deviceAddress) const override;

// Implementation of GapPairing
void AllowPairing(bool allow) override;
Expand Down
21 changes: 7 additions & 14 deletions hal_st/middlewares/ble_middleware/GapSt.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#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 @@ -91,6 +93,11 @@ namespace hal
return numberOfBondedAddress;
}

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

void GapSt::Pair()
{
really_assert(connectionContext.connectionHandle != GapSt::invalidConnection);
Expand Down Expand Up @@ -151,13 +158,6 @@ namespace hal
std::abort();
}

hal::MacAddress GapSt::ResolveDeviceAddress(hal::MacAddress deviceAddress) const
{
hal::MacAddress address = connectionContext.peerAddress;
aci_gap_resolve_private_addr(deviceAddress.data(), address.data());
return address;
}

void GapSt::HandleHciDisconnectEvent(hci_event_pckt& eventPacket)
{
auto disconnectionCompleteEvent = *reinterpret_cast<hci_disconnection_complete_event_rp0*>(eventPacket.data);
Expand Down Expand Up @@ -316,13 +316,6 @@ namespace hal
{
static constexpr auto deducePeerAddressType = [](auto peerAddressType)
{
enum class PeerAddressType : uint8_t
{
PUBLIC,
RANDOM,
RESOLVED_PUBLIC_IDENTITY,
RESOLVED_RANDOM_STATIC_IDENTITY
};

switch (static_cast<PeerAddressType>(peerAddressType))
{
Expand Down
20 changes: 14 additions & 6 deletions hal_st/middlewares/ble_middleware/GapSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace hal
: public services::AttMtuExchange
, public services::GapBonding
, public services::GapPairing
, private hal::HciEventSink
, private HciEventSink
{
public:
struct GapService
Expand All @@ -31,7 +31,7 @@ namespace hal

struct Configuration
{
const hal::MacAddress& address;
const MacAddress& address;
const GapService& gapService;
const RootKeys& rootKeys;
uint8_t txPowerLevel;
Expand All @@ -45,17 +45,17 @@ namespace hal
void RemoveOldestBond() override;
std::size_t GetMaxNumberOfBonds() const override;
std::size_t GetNumberOfBonds() const override;
bool IsDeviceBounded(MacAddress deviceAddress) const override;

// Implementation of GapPairing
void Pair() override;
void SetSecurityMode(services::GapPairing::SecurityMode mode, services::GapPairing::SecurityLevel level) override;
void SetIoCapabilities(services::GapPairing::IoCapabilities caps) override;
void AuthenticateWithPasskey(uint32_t passkey) override;
void NumericComparisonConfirm(bool accept) override;
hal::MacAddress ResolveDeviceAddress(hal::MacAddress deviceAddress) const override;

protected:
GapSt(hal::HciEventSource& hciEventSource, services::BondStorageSynchronizer& bondStorageSynchronizer, const Configuration& configuration);
GapSt(HciEventSource& hciEventSource, services::BondStorageSynchronizer& bondStorageSynchronizer, const Configuration& configuration);

virtual void HandleHciDisconnectEvent(hci_event_pckt& eventPacket);

Expand All @@ -73,7 +73,7 @@ namespace hal
virtual void HandleL2capConnectionUpdateRequestEvent(evt_blecore_aci* vendorEvent){};
virtual void HandleMtuExchangeResponseEvent(evt_blecore_aci* vendorEvent);

void SetAddress(const hal::MacAddress& address, services::GapDeviceAddressType addressType);
void SetAddress(const MacAddress& address, services::GapDeviceAddressType addressType);

private:
// Implementation of HciEventSink
Expand All @@ -86,11 +86,19 @@ namespace hal
void UpdateNrBonds();

protected:
enum class PeerAddressType : uint8_t
{
PUBLIC,
RANDOM,
RESOLVED_PUBLIC_IDENTITY,
RESOLVED_RANDOM_STATIC_IDENTITY
};

struct ConnectionContext
{
uint16_t connectionHandle;
uint8_t peerAddressType;
hal::MacAddress peerAddress;
MacAddress peerAddress;
};

ConnectionContext connectionContext;
Expand Down
20 changes: 14 additions & 6 deletions hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ namespace hal
GapCentralSt::StopDeviceDiscovery();
}

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);
return resolvedMac;
}

void TracingGapCentralSt::RemoveAllBonds()
{
tracer.Trace() << "TracingGapCentralSt::RemoveAllBonds";
Expand All @@ -69,6 +76,13 @@ namespace hal
return GapCentralSt::GetNumberOfBonds();
}

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

void TracingGapCentralSt::Pair()
{
tracer.Trace() << "TracingGapCentralSt::Pair";
Expand Down Expand Up @@ -99,12 +113,6 @@ namespace hal
GapCentralSt::NumericComparisonConfirm(accept);
}

hal::MacAddress TracingGapCentralSt::ResolveDeviceAddress(hal::MacAddress deviceAddress) const
{
tracer.Trace() << "TracingGapCentralSt::ResolveDeviceAddress";
return GapCentralSt::ResolveDeviceAddress(deviceAddress);
}

void TracingGapCentralSt::HandleHciDisconnectEvent(hci_event_pckt& eventPacket)
{
const auto disconnectEvt = reinterpret_cast<hci_disconnection_complete_event_rp0*>(eventPacket.data);
Expand Down
3 changes: 2 additions & 1 deletion hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ namespace hal
void SetAddress(hal::MacAddress macAddress, services::GapDeviceAddressType addressType) override;
void StartDeviceDiscovery() override;
void StopDeviceDiscovery() override;
infra::Optional<hal::MacAddress> ResolveDeviceAddress(hal::MacAddress deviceAddress) const override;

// Implementation of GapBonding
void RemoveAllBonds() override;
void RemoveOldestBond() override;
std::size_t GetMaxNumberOfBonds() const override;
std::size_t GetNumberOfBonds() const override;
bool IsDeviceBounded(hal::MacAddress deviceAddress) const override;

// Implementation of GapPairing
void Pair() override;
void SetSecurityMode(services::GapPairing::SecurityMode mode, services::GapPairing::SecurityLevel level) override;
void SetIoCapabilities(services::GapPairing::IoCapabilities caps) override;
void AuthenticateWithPasskey(uint32_t passkey) override;
void NumericComparisonConfirm(bool accept) override;
hal::MacAddress ResolveDeviceAddress(hal::MacAddress deviceAddress) const override;

protected:
// Implementation of GapCentralSt
Expand Down

0 comments on commit be9b76a

Please sign in to comment.