Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
9ba128b
trying to split the mtu interface
XavierBernhardt-Philips Dec 4, 2025
c304937
Update MTU exchange interface
XavierBernhardt-Philips Dec 4, 2025
6cdcbaa
Merge branch 'main' into feature/split_AttMtuInterface
XavierBernhardt-Philips Dec 4, 2025
2f58760
refactor: simplify MTU exchange handling and update default max ATT M…
XavierBernhardt-Philips Dec 4, 2025
8de2e05
refactor: move MtuExchange implementation to GattClientSt interface
XavierBernhardt-Philips Dec 8, 2025
63032dd
refactor: replace AttMtuExchangeReceiver with AttMtuExchange in GattC…
XavierBernhardt-Philips Dec 8, 2025
b86d735
test
XavierBernhardt-Philips Dec 8, 2025
22359a4
test
XavierBernhardt-Philips Dec 8, 2025
264c8f6
reorganise
XavierBernhardt-Philips Dec 8, 2025
19df356
Merge remote-tracking branch 'origin/HEAD' into feature/split_AttMtuI…
XavierBernhardt-Philips Dec 8, 2025
d774217
chore: update EMIL to version with maxAttMtu in GattClient base class
XavierBernhardt-Philips Dec 8, 2025
e647760
refactor: remove maxAttMtu member from GattClientSt and GattServerSt …
XavierBernhardt-Philips Dec 11, 2025
7e3d415
Merge remote-tracking branch 'origin/main' into feature/split_AttMtuI…
XavierBernhardt-Philips Dec 12, 2025
61fafd1
update emil
XavierBernhardt-Philips Dec 16, 2025
5411d44
Merge branch 'main' into feature/split_AttMtuInterface
XavierBernhardt-Philips Dec 16, 2025
bcc17cf
emil
XavierBernhardt-Philips Dec 16, 2025
09f826a
removed duplicate header
XavierBernhardt-Philips Dec 16, 2025
6073031
changes
XavierBernhardt-Philips Dec 16, 2025
652064e
asd
XavierBernhardt-Philips Dec 16, 2025
22493c5
fix
XavierBernhardt-Philips Dec 17, 2025
72e7ef4
emil
XavierBernhardt-Philips Dec 17, 2025
9622c18
emil
XavierBernhardt-Philips Dec 17, 2025
1c49b77
Merge branch 'main' into feature/split_AttMtuInterface
XavierBernhardt-Philips Dec 17, 2025
185cfda
emil
XavierBernhardt-Philips Dec 17, 2025
b716da5
Merge branch 'main' into feature/split_AttMtuInterface
XavierBernhardt-Philips Dec 17, 2025
98c03d2
emil
XavierBernhardt-Philips Dec 17, 2025
43c8d0c
Adapt MtuExchange signature changes and refactor GattClientSt
oguzcanoguz Dec 18, 2025
3503d96
update infralib hash
oguzcanoguz Dec 18, 2025
103a045
Merge branch 'main' into feature/split_AttMtuInterface
oguzcanoguz Dec 18, 2025
8ddc07a
adapt to interface changes
oguzcanoguz Dec 23, 2025
2ecf9ab
adapt to interface changes
oguzcanoguz Dec 23, 2025
8a63005
Merge branch 'temp' into feature/split_AttMtuInterface
oguzcanoguz Dec 23, 2025
511d5cf
Update infralib hash
oguzcanoguz Dec 23, 2025
22d1f1b
emil
XavierBernhardt-Philips Jan 5, 2026
038a1fa
Merge branch 'main' into feature/split_AttMtuInterface
XavierBernhardt-Philips Jan 19, 2026
9fb2898
Merge branch 'main' into feature/split_AttMtuInterface
XavierBernhardt-Philips Jan 19, 2026
4762886
emil
XavierBernhardt-Philips Jan 21, 2026
2b6eed9
Merge remote-tracking branch 'origin/main' into feature/split_AttMtuI…
XavierBernhardt-Philips Jan 21, 2026
d1919dc
Update CMakeLists.txt
XavierBernhardt-Philips Jan 21, 2026
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 f38e0ac947cf81a1d48ffd79b079ac3f8c20ccac # unreleased
GIT_TAG 0d8f096330aca30e935f84caf6b3c76c176cec34 # unreleased
)
FetchContent_MakeAvailable(emil)

Expand Down
19 changes: 4 additions & 15 deletions hal_st/middlewares/ble_middleware/GapSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ namespace hal
SVCCTL_Init();
}

uint16_t GapSt::EffectiveMaxAttMtuSize() const
{
return maxAttMtu;
}

void GapSt::MtuExchange()
{
auto status = aci_gatt_exchange_config(this->connectionContext.connectionHandle);
assert(status == BLE_STATUS_SUCCESS);
}

void GapSt::RemoveAllBonds()
{
bondStorageSynchronizer.RemoveAllBonds();
Expand Down Expand Up @@ -229,11 +218,11 @@ namespace hal
void GapSt::HandleMtuExchangeResponseEvent(const aci_att_exchange_mtu_resp_event_rp0& event)
{
really_assert(event.Connection_Handle == connectionContext.connectionHandle);
maxAttMtu = event.Server_RX_MTU;
SetAttMtu(event.Server_RX_MTU);

AttMtuExchange::NotifyObservers([](auto& observer)
services::AttMtuExchange::NotifyObservers([](auto& observer)
{
observer.ExchangedMaxAttMtuSize();
observer.ExchangedAttMtuSize();
});
}

Expand Down Expand Up @@ -385,7 +374,7 @@ namespace hal

void GapSt::SetConnectionContext(uint16_t connectionHandle, services::GapDeviceAddressType peerAddressType, const uint8_t* peerAddress)
{
maxAttMtu = defaultMaxAttMtuSize;
SetAttMtu(defaultAttMtuSize);
connectionContext.connectionHandle = connectionHandle;
connectionContext.peerAddressType = peerAddressType;
std::copy_n(peerAddress, connectionContext.peerAddress.size(), std::begin(connectionContext.peerAddress));
Expand Down
7 changes: 1 addition & 6 deletions hal_st/middlewares/ble_middleware/GapSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace hal
{
class GapSt
: public services::AttMtuExchange
: public services::AttMtuExchangeImpl
, public services::GapBonding
, public services::GapPairing
, private HciEventSink
Expand Down Expand Up @@ -51,10 +51,6 @@ namespace hal
bool privacy;
};

// Implementation of AttMtuExchange
uint16_t EffectiveMaxAttMtuSize() const override;
void MtuExchange() override;

// Implementation of GapBonding
void RemoveAllBonds() override;
void RemoveOldestBond() override;
Expand Down Expand Up @@ -142,7 +138,6 @@ namespace hal

private:
services::BondStorageSynchronizer& bondStorageSynchronizer;
uint16_t maxAttMtu = defaultMaxAttMtuSize;
};
}

Expand Down
76 changes: 44 additions & 32 deletions hal_st/middlewares/ble_middleware/GattClientSt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace hal

void GattClientSt::StartServiceDiscovery()
{
onDiscoveryCompletion = [this](services::OperationStatus status)
onOperationDone = [this](services::OperationStatus status)
{
infra::Subject<services::GattClientObserver>::NotifyObservers([status](auto& observer)
{
Expand All @@ -27,13 +27,12 @@ namespace hal
};

auto ret = aci_gatt_disc_all_primary_services(connectionHandle);
if (ret != BLE_STATUS_SUCCESS)
onDiscoveryCompletion(services::OperationStatus::error);
HandleBleStatusError(ret);
}

void GattClientSt::StartCharacteristicDiscovery(services::AttAttribute::Handle handle, services::AttAttribute::Handle endHandle)
{
onDiscoveryCompletion = [this](services::OperationStatus status)
onOperationDone = [this](services::OperationStatus status)
{
infra::Subject<services::GattClientObserver>::NotifyObservers([status](auto& observer)
{
Expand All @@ -42,13 +41,12 @@ namespace hal
};

auto ret = aci_gatt_disc_all_char_of_service(connectionHandle, handle, endHandle);
if (ret != BLE_STATUS_SUCCESS)
onDiscoveryCompletion(services::OperationStatus::error);
HandleBleStatusError(ret);
}

void GattClientSt::StartDescriptorDiscovery(services::AttAttribute::Handle handle, services::AttAttribute::Handle endHandle)
{
onDiscoveryCompletion = [this](services::OperationStatus status)
onOperationDone = [this](services::OperationStatus status)
{
infra::Subject<services::GattClientObserver>::NotifyObservers([status](auto& observer)
{
Expand All @@ -57,41 +55,32 @@ namespace hal
};

auto ret = aci_gatt_disc_all_char_desc(connectionHandle, handle, endHandle);
if (ret != BLE_STATUS_SUCCESS)
onDiscoveryCompletion(services::OperationStatus::error);
HandleBleStatusError(ret);
}

void GattClientSt::Read(services::AttAttribute::Handle handle, const infra::Function<void(const infra::ConstByteRange&)>& onResponse, const infra::Function<void(services::OperationStatus)>& onDone)
{
this->onReadResponse = onResponse;
this->onCharacteristicOperationsDone = [this, onDone](services::OperationStatus result)
{
onDone(result);
};
onReadResponse = onResponse;
onOperationDone = onDone;

auto ret = aci_gatt_read_char_value(connectionHandle, handle);
if (ret != BLE_STATUS_SUCCESS)
this->onCharacteristicOperationsDone(services::OperationStatus::error);
HandleBleStatusError(ret);
}

void GattClientSt::Write(services::AttAttribute::Handle handle, infra::ConstByteRange data, const infra::Function<void(services::OperationStatus)>& onDone)
{
this->onCharacteristicOperationsDone = [this, onDone](services::OperationStatus result)
{
onDone(result);
};
onOperationDone = onDone;

auto ret = aci_gatt_write_char_value(connectionHandle, handle, data.size(), data.cbegin());
if (ret != BLE_STATUS_SUCCESS)
this->onCharacteristicOperationsDone(services::OperationStatus::error);
HandleBleStatusError(ret);
}

void GattClientSt::WriteWithoutResponse(services::AttAttribute::Handle handle, infra::ConstByteRange data, const infra::Function<void(services::OperationStatus)>& onDone)
{
auto var = aci_gatt_write_without_resp(connectionHandle, handle, data.size(), data.cbegin());
if (var == BLE_STATUS_SUCCESS)
auto ret = aci_gatt_write_without_resp(connectionHandle, handle, data.size(), data.cbegin());
if (ret == BLE_STATUS_SUCCESS)
onDone(services::OperationStatus::success);
else if (var == BLE_STATUS_INSUFFICIENT_RESOURCES)
else if (ret == BLE_STATUS_INSUFFICIENT_RESOURCES)
onDone(services::OperationStatus::retry);
else
onDone(services::OperationStatus::error);
Expand Down Expand Up @@ -216,10 +205,9 @@ namespace hal

void GattClientSt::HandleGattCompleteResponse(const aci_gatt_proc_complete_event_rp0& event)
{
if (this->onDiscoveryCompletion)
this->onDiscoveryCompletion(event.Error_Code == BLE_STATUS_SUCCESS ? services::OperationStatus::success : services::OperationStatus::error); // Does this conflict with other operations? If not, why do we even get a GattComplete for discovery?
else if (this->onCharacteristicOperationsDone)
this->onCharacteristicOperationsDone(event.Error_Code == BLE_STATUS_SUCCESS ? services::OperationStatus::success : services::OperationStatus::error);
really_assert(onOperationDone);

onOperationDone(event.Error_Code == BLE_STATUS_SUCCESS ? services::OperationStatus::success : services::OperationStatus::error);
}

void GattClientSt::HandleHciLeConnectionCompleteEvent(const hci_le_connection_complete_event_rp0& event)
Expand Down Expand Up @@ -262,7 +250,7 @@ namespace hal
{
observer.IndicationReceived(event.Attribute_Handle, data, [this]()
{
this->HandleGattConfirmIndication();
HandleGattConfirmIndication();
});
});
}
Expand Down Expand Up @@ -358,7 +346,31 @@ namespace hal
const uint16_t offsetCccd = 1;

auto ret = aci_gatt_write_char_desc(connectionHandle, handle + offsetCccd, sizeof(characteristicValue), reinterpret_cast<uint8_t*>(&characteristicValue));
if (ret != BLE_STATUS_SUCCESS)
onCharacteristicOperationsDone(services::OperationStatus::error);
HandleBleStatusError(ret);
}

void GattClientSt::MtuExchange(const infra::Function<void(services::OperationStatus)>& onDone)
{
onOperationDone = onDone;

auto status = aci_gatt_exchange_config(connectionHandle);
HandleBleStatusError(status);
}

void GattClientSt::HandleAttExchangeMtuResponse(const aci_att_exchange_mtu_resp_event_rp0& event)
{
really_assert(event.Connection_Handle == connectionHandle);
SetAttMtu(event.Server_RX_MTU);

AttMtuExchange::NotifyObservers([](auto& observer)
{
observer.ExchangedAttMtuSize();
});
}

void GattClientSt::HandleBleStatusError(tBleStatus status)
{
if (status != BLE_STATUS_SUCCESS)
onOperationDone(services::OperationStatus::error);
}
}
10 changes: 7 additions & 3 deletions hal_st/middlewares/ble_middleware/GattClientSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#include "infra/util/AutoResetFunction.hpp"
#include "infra/util/BoundedVector.hpp"
#include "infra/util/Function.hpp"
#include "services/ble/Gatt.hpp"
#include "services/ble/GattClient.hpp"

namespace hal
{
class GattClientSt
: public services::GattClient
, public hal::HciEventSink
, public services::AttMtuExchangeImpl
{
public:
explicit GattClientSt(hal::HciEventSource& hciEventSource);
Expand All @@ -29,6 +31,7 @@ namespace hal
void DisableNotification(services::AttAttribute::Handle handle, const infra::Function<void(services::OperationStatus)>& onDone) override;
void EnableIndication(services::AttAttribute::Handle handle, const infra::Function<void(services::OperationStatus)>& onDone) override;
void DisableIndication(services::AttAttribute::Handle handle, const infra::Function<void(services::OperationStatus)>& onDone) override;
void MtuExchange(const infra::Function<void(services::OperationStatus)>& onDone) override;

// Implementation of hal::HciEventSink
void HciEvent(hci_event_pckt& event) override;
Expand All @@ -50,6 +53,7 @@ namespace hal
virtual void HandleAttReadByGroupTypeResponse(const aci_att_read_by_group_type_resp_event_rp0& event);
virtual void HandleAttReadByTypeResponse(const aci_att_read_by_type_resp_event_rp0& event);
virtual void HandleAttFindInfoResponse(const aci_att_find_info_resp_event_rp0& event);
virtual void HandleAttExchangeMtuResponse(const aci_att_exchange_mtu_resp_event_rp0& event);

virtual void HandleServiceDiscovered(infra::DataInputStream& stream, bool isUuid16);
void HandleUuidFromDiscovery(infra::DataInputStream& stream, bool isUuid16, services::AttAttribute::Uuid& type);
Expand All @@ -59,11 +63,12 @@ namespace hal
void HandleDescriptorDiscovered(infra::DataInputStream& stream, bool isUuid16);

void WriteCharacteristicDescriptor(services::AttAttribute::Handle handle, services::GattCharacteristic::PropertyFlags property, services::GattDescriptor::ClientCharacteristicConfiguration::CharacteristicValue characteristicValue);
void HandleBleStatusError(tBleStatus status);

template<services::GattCharacteristic::PropertyFlags p, services::GattDescriptor::ClientCharacteristicConfiguration::CharacteristicValue v>
void WriteCharacteristicDescriptor(services::AttAttribute::Handle handle, const infra::Function<void(services::OperationStatus)>& onDone)
{
this->onCharacteristicOperationsDone = [this, onDone](services::OperationStatus result)
this->onOperationDone = [this, onDone](services::OperationStatus result)
{
onDone(result);
};
Expand All @@ -85,9 +90,8 @@ namespace hal

static constexpr uint16_t invalidConnection = 0xffff;

infra::AutoResetFunction<void(services::OperationStatus status)> onDiscoveryCompletion;
infra::AutoResetFunction<void(const infra::ConstByteRange&)> onReadResponse;
infra::AutoResetFunction<void(services::OperationStatus), sizeof(void*) + sizeof(infra::Function<void(services::OperationStatus)>)> onCharacteristicOperationsDone;
infra::AutoResetFunction<void(services::OperationStatus), sizeof(void*) + sizeof(infra::Function<void(services::OperationStatus)>)> onOperationDone;
};
}

Expand Down
3 changes: 3 additions & 0 deletions hal_st/middlewares/ble_middleware/GattServerSt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "ble/ble.h"
#include "hal_st/middlewares/ble_middleware/HciEventObserver.hpp"
#include "services/ble/Gatt.hpp"
#include "services/ble/GattServer.hpp"

namespace hal
Expand All @@ -11,6 +12,8 @@ namespace hal
: public services::GattServer
, public services::GattServerCharacteristicOperations
, public hal::HciEventSink
, public services::AttMtuExchangeImpl

{
public:
explicit GattServerSt(hal::HciEventSource& hciEventSource);
Expand Down
10 changes: 5 additions & 5 deletions hal_st/middlewares/ble_middleware/SystemTransportLayerWb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ namespace
void ShciCore2Init(const hal::SystemTransportLayerWb::Configuration& configuration)
{
const uint8_t maxNumberOfBleLinks = 0x01;
const uint8_t prepareWriteListSize = BLE_PREP_WRITE_X_ATT(configuration.maxAttMtuSize);
const uint8_t numberOfBleMemoryBlocks = BLE_MBLOCKS_CALC(prepareWriteListSize, configuration.maxAttMtuSize, maxNumberOfBleLinks);
const uint8_t prepareWriteListSize = BLE_PREP_WRITE_X_ATT(configuration.attMtuSize);
const uint8_t numberOfBleMemoryBlocks = BLE_MBLOCKS_CALC(prepareWriteListSize, configuration.attMtuSize, maxNumberOfBleLinks);
const uint8_t bleStackOptions = (SHCI_C2_BLE_INIT_OPTIONS_LL_HOST | SHCI_C2_BLE_INIT_OPTIONS_WITH_SVC_CHANGE_DESC | SHCI_C2_BLE_INIT_OPTIONS_DEVICE_NAME_RO | SHCI_C2_BLE_INIT_OPTIONS_NO_EXT_ADV | SHCI_C2_BLE_INIT_OPTIONS_NO_CS_ALGO2 |
SHCI_C2_BLE_INIT_OPTIONS_FULL_GATTDB_NVM | SHCI_C2_BLE_INIT_OPTIONS_GATT_CACHING_NOTUSED | SHCI_C2_BLE_INIT_OPTIONS_POWER_CLASS_2_3 | SHCI_C2_BLE_INIT_OPTIONS_APPEARANCE_READONLY | SHCI_C2_BLE_INIT_OPTIONS_ENHANCED_ATT_NOTSUPPORTED);

Expand Down Expand Up @@ -130,7 +130,7 @@ namespace
0x01, // Enable or disable the Extended Packet length feature
prepareWriteListSize,
numberOfBleMemoryBlocks,
configuration.maxAttMtuSize,
configuration.attMtuSize,
0x1FA, // Sleep clock accuracy in Slave mode
0x00, // Sleep clock accuracy in Master mode
ToLowSpeedClock(configuration.rfWakeupClock), // Source for the low speed clock for RF wake-up
Expand Down Expand Up @@ -163,8 +163,8 @@ namespace hal
, configuration(configuration)
, onInitialized(onInitialized)
{
really_assert(configuration.maxAttMtuSize >= BLE_DEFAULT_ATT_MTU && configuration.maxAttMtuSize <= 251);
// BLE middleware supported maxAttMtuSize = 512. Current usage of library limits maxAttMtuSize to 251 (max HCI buffer size)
really_assert(configuration.attMtuSize >= BLE_DEFAULT_ATT_MTU && configuration.attMtuSize <= 251);
// BLE middleware supported attMtuSize = 512. Current usage of library limits attMtuSize to 251 (max HCI buffer size)

TL_Init();
ShciInit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace hal

struct Configuration
{
uint16_t maxAttMtuSize;
uint16_t attMtuSize;
RfWakeupClock rfWakeupClock;
};

Expand Down
18 changes: 9 additions & 9 deletions hal_st/middlewares/ble_middleware/SystemTransportLayerWba.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <array>
extern "C"
{
#include "ble_common.h"
#include "ble_bufsize.h"
#include "ble_common.h"
#include "blestack.h"
}

Expand All @@ -21,7 +21,7 @@ extern "C"

tBleStatus ProcessEventPacket(const uint8_t* data)
{
SVCCTL_UserEvtRx(const_cast<uint8_t *>(data));
SVCCTL_UserEvtRx(const_cast<uint8_t*>(data));
return BLE_STATUS_SUCCESS;
}

Expand Down Expand Up @@ -50,18 +50,18 @@ namespace
std::array<uint32_t, DIVC(gattBufferSize, 4)> bleGattBuffer;
const uint8_t bleStackOptions = 0;

constexpr uint8_t PrepareWriteListSize(uint16_t maxAttMtuSize)
constexpr uint8_t PrepareWriteListSize(uint16_t attMtuSize)
{
return static_cast<uint8_t>(BLE_PREP_WRITE_X_ATT(maxAttMtuSize));
return static_cast<uint8_t>(BLE_PREP_WRITE_X_ATT(attMtuSize));
}
}

namespace hal
{
SystemTransportLayerWba::SystemTransportLayerWba(uint16_t maxAttMtuSize)
SystemTransportLayerWba::SystemTransportLayerWba(uint16_t attMtuSize)
{
really_assert(maxAttMtuSize >= BLE_DEFAULT_ATT_MTU && maxAttMtuSize <= 251);
// BLE middleware supported maxAttMtuSize = 512. Current usage of library limits maxAttMtuSize to 251 (max HCI buffer size)
really_assert(attMtuSize >= BLE_DEFAULT_ATT_MTU && attMtuSize <= 251);
// BLE middleware supported attMtuSize = 512. Current usage of library limits attMtuSize to 251 (max HCI buffer size)

BleStack_init_t bleStackInitParameters = {
reinterpret_cast<uint8_t*>(bleBuffer.begin()),
Expand All @@ -72,9 +72,9 @@ namespace hal
numAttrServ,
attrValueArrSize,
maxNumberOfBleLinks,
PrepareWriteListSize(maxAttMtuSize),
PrepareWriteListSize(attMtuSize),
mblockCount,
maxAttMtuSize,
attMtuSize,
248,
64,
maxNumberOfConnectionOrientedChannels,
Expand Down
Loading
Loading