diff --git a/hal_st/middlewares/ble_middleware/GapCentralSt.cpp b/hal_st/middlewares/ble_middleware/GapCentralSt.cpp index d23243f0..f530a490 100644 --- a/hal_st/middlewares/ble_middleware/GapCentralSt.cpp +++ b/hal_st/middlewares/ble_middleware/GapCentralSt.cpp @@ -29,23 +29,6 @@ namespace hal return static_cast(eventType); } - services::GapAdvertisingEventAddressType ToAdvertisingAddressType(uint8_t addressType, const uint8_t address[6]) - { - if (addressType == static_cast(services::GapDeviceAddressType::publicAddress)) - return services::GapAdvertisingEventAddressType::publicDeviceAddress; - else if (addressType == static_cast(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) { return dataLengthChangeEvent.MaxTxOctets == services::GapConnectionParameters::connectionInitialMaxTxOctets && @@ -313,7 +296,7 @@ namespace hal auto advertisementData = const_cast(&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, advertisingReport.Address); + discoveredDevice.addressType = static_cast(advertisingReport.Address_Type); discoveredDevice.data = infra::MemoryRange(advertisementData, advertisementData + advertisingReport.Length_Data); discoveredDevice.rssi = static_cast(*const_cast(advertisementData + advertisingReport.Length_Data)); diff --git a/hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp b/hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp index 56a66623..511bf7a3 100644 --- a/hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp +++ b/hal_st/middlewares/ble_middleware/GapPeripheralSt.cpp @@ -21,9 +21,9 @@ namespace hal { services::GapAddress address; /* Use last peer addres to get current RPA */ - [[maybe_unused]] auto status = hci_le_read_local_resolvable_address(connectionContext.peerAddressType, connectionContext.peerAddress.data(), address.address.data()); + [[maybe_unused]] auto status = hci_le_read_local_resolvable_address(static_cast(connectionContext.peerAddressType), connectionContext.peerAddress.data(), address.address.data()); - address.type = services::GapDeviceAddressType::publicAddress; + address.type = services::GapDeviceAddressType::randomAddress; assert(status == BLE_STATUS_SUCCESS); @@ -133,14 +133,14 @@ namespace hal aci_gap_add_devices_to_resolving_list(1, &dummyPeer, 1); std::copy(std::begin(dummyPeer.Peer_Identity_Address), std::end(dummyPeer.Peer_Identity_Address), connectionContext.peerAddress.begin()); - connectionContext.peerAddressType = dummyPeer.Peer_Identity_Address_Type; + connectionContext.peerAddressType = static_cast(dummyPeer.Peer_Identity_Address_Type); } else { aci_gap_add_devices_to_resolving_list(numberOfBondedAddress, reinterpret_cast(bondedDevices.begin()), 1); std::copy(std::begin(bondedDevices[numberOfBondedAddress - 1].Address), std::end(bondedDevices[numberOfBondedAddress - 1].Address), connectionContext.peerAddress.begin()); - connectionContext.peerAddressType = bondedDevices[numberOfBondedAddress - 1].Address_Type; + connectionContext.peerAddressType = static_cast(bondedDevices[numberOfBondedAddress - 1].Address_Type); for (uint8_t i = 0; i < numberOfBondedAddress; i++) hci_le_set_privacy_mode(bondedDevices[i].Address_Type, bondedDevices[i].Address, HCI_PRIV_MODE_DEVICE); diff --git a/hal_st/middlewares/ble_middleware/GapSt.cpp b/hal_st/middlewares/ble_middleware/GapSt.cpp index ead75d9d..ce0c7105 100644 --- a/hal_st/middlewares/ble_middleware/GapSt.cpp +++ b/hal_st/middlewares/ble_middleware/GapSt.cpp @@ -91,9 +91,9 @@ namespace hal return numberOfBondedAddress; } - bool GapSt::IsDeviceBonded(MacAddress identityAddress) const + bool GapSt::IsDeviceBonded(MacAddress address, services::GapDeviceAddressType addressType) const { - return aci_gap_is_device_bonded(static_cast(PeerAddressType::publicStatic), identityAddress.data()) == BLE_STATUS_SUCCESS; + return aci_gap_is_device_bonded(static_cast(addressType), address.data()) == BLE_STATUS_SUCCESS; } void GapSt::Pair() @@ -171,7 +171,7 @@ namespace hal auto connectionCompleteEvent = *reinterpret_cast(metaEvent->data); if (connectionCompleteEvent.Status == BLE_STATUS_SUCCESS) - SetConnectionContext(connectionCompleteEvent.Connection_Handle, connectionCompleteEvent.Peer_Address_Type, &connectionCompleteEvent.Peer_Address[0]); + SetConnectionContext(connectionCompleteEvent.Connection_Handle, static_cast(connectionCompleteEvent.Peer_Address_Type), &connectionCompleteEvent.Peer_Address[0]); } void GapSt::HandleHciLeEnhancedConnectionCompleteEvent(evt_le_meta_event* metaEvent) @@ -179,7 +179,7 @@ namespace hal auto connectionCompleteEvt = *reinterpret_cast(metaEvent->data); if (connectionCompleteEvt.Status == BLE_STATUS_SUCCESS) - SetConnectionContext(connectionCompleteEvt.Connection_Handle, connectionCompleteEvt.Peer_Address_Type, &connectionCompleteEvt.Peer_Address[0]); + SetConnectionContext(connectionCompleteEvt.Connection_Handle, static_cast(connectionCompleteEvt.Peer_Address_Type), &connectionCompleteEvt.Peer_Address[0]); } void GapSt::HandleBondLostEvent(evt_blecore_aci* vendorEvent) @@ -206,7 +206,7 @@ namespace hal really_assert(pairingComplete->Connection_Handle == connectionContext.connectionHandle); - if (aci_gap_is_device_bonded(connectionContext.peerAddressType, connectionContext.peerAddress.data()) == BLE_STATUS_SUCCESS) + if (aci_gap_is_device_bonded(static_cast(connectionContext.peerAddressType), connectionContext.peerAddress.data()) == BLE_STATUS_SUCCESS) { hal::MacAddress address = connectionContext.peerAddress; aci_gap_resolve_private_addr(connectionContext.peerAddress.data(), address.data()); @@ -310,29 +310,11 @@ namespace hal } } - void GapSt::SetConnectionContext(uint16_t connectionHandle, uint8_t peerAddressType, uint8_t* peerAddress) + void GapSt::SetConnectionContext(uint16_t connectionHandle, services::GapDeviceAddressType peerAddressType, uint8_t* peerAddress) { - static constexpr auto deducePeerAddressType = [](auto peerAddressType) - { - - switch (static_cast(peerAddressType)) - { - case PeerAddressType::publicStatic: - case PeerAddressType::randomStatic: - return peerAddressType; - - case PeerAddressType::resolvablePrivate: - return infra::enum_cast(PeerAddressType::publicStatic); - - case PeerAddressType::nonResolvablePrivate: - default: - return infra::enum_cast(PeerAddressType::randomStatic); - } - }; - maxAttMtu = defaultMaxAttMtuSize; connectionContext.connectionHandle = connectionHandle; - connectionContext.peerAddressType = deducePeerAddressType(peerAddressType); + connectionContext.peerAddressType = peerAddressType; std::copy_n(peerAddress, connectionContext.peerAddress.size(), std::begin(connectionContext.peerAddress)); } diff --git a/hal_st/middlewares/ble_middleware/GapSt.hpp b/hal_st/middlewares/ble_middleware/GapSt.hpp index e2f4ac3e..701195c0 100644 --- a/hal_st/middlewares/ble_middleware/GapSt.hpp +++ b/hal_st/middlewares/ble_middleware/GapSt.hpp @@ -45,7 +45,7 @@ namespace hal void RemoveOldestBond() override; std::size_t GetMaxNumberOfBonds() const override; std::size_t GetNumberOfBonds() const override; - bool IsDeviceBonded(MacAddress identityAddress) const override; + bool IsDeviceBonded(MacAddress address, services::GapDeviceAddressType addressType) const override; // Implementation of GapPairing void Pair() override; @@ -82,22 +82,14 @@ namespace hal void HandleHciLeMetaEvent(hci_event_pckt& eventPacket); void HandleHciVendorSpecificDebugEvent(hci_event_pckt& eventPacket); - void SetConnectionContext(uint16_t connectionHandle, uint8_t peerAddressType, uint8_t* peerAddress); + void SetConnectionContext(uint16_t connectionHandle, services::GapDeviceAddressType peerAddressType, uint8_t* peerAddress); void UpdateNrBonds(); protected: - enum class PeerAddressType : uint8_t - { - publicStatic, - randomStatic, - resolvablePrivate, - nonResolvablePrivate - }; - struct ConnectionContext { uint16_t connectionHandle; - uint8_t peerAddressType; + services::GapDeviceAddressType peerAddressType; MacAddress peerAddress; }; diff --git a/hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp b/hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp index 8a907630..0f4b30ea 100644 --- a/hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp +++ b/hal_st/middlewares/ble_middleware/TracingGapCentralSt.cpp @@ -80,10 +80,10 @@ namespace hal return GapCentralSt::GetNumberOfBonds(); } - bool TracingGapCentralSt::IsDeviceBonded(hal::MacAddress identityAddress) const + bool TracingGapCentralSt::IsDeviceBonded(hal::MacAddress address, services::GapDeviceAddressType addressType) const { - auto ret = GapCentralSt::IsDeviceBonded(identityAddress); - tracer.Trace() << "TracingGapCentralSt::IsDeviceBonded " << infra::AsMacAddress(identityAddress) << " -> " << (ret ? "true" : "false"); + auto ret = GapCentralSt::IsDeviceBonded(address, addressType); + tracer.Trace() << "TracingGapCentralSt::IsDeviceBonded " << infra::AsMacAddress(address) << " -> " << (ret ? "true" : "false"); return ret; } diff --git a/hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp b/hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp index 35ff5ee8..3ee4afc2 100644 --- a/hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp +++ b/hal_st/middlewares/ble_middleware/TracingGapCentralSt.hpp @@ -25,7 +25,7 @@ namespace hal void RemoveOldestBond() override; std::size_t GetMaxNumberOfBonds() const override; std::size_t GetNumberOfBonds() const override; - bool IsDeviceBonded(hal::MacAddress identityAddress) const override; + bool IsDeviceBonded(hal::MacAddress address, services::GapDeviceAddressType addressType) const override; // Implementation of GapPairing void Pair() override;