From a719fbf25d056feb08633ebd4638590b42777944 Mon Sep 17 00:00:00 2001 From: Tasos Papalyras Date: Mon, 7 Oct 2024 00:43:53 +0300 Subject: [PATCH] Cleanup, update s113v7 --- adapter_nrf528xx-full.go | 2 -- adapter_nrf528xx-peripheral.go | 20 +++++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/adapter_nrf528xx-full.go b/adapter_nrf528xx-full.go index 4b6fde7..0375ab3 100644 --- a/adapter_nrf528xx-full.go +++ b/adapter_nrf528xx-full.go @@ -158,8 +158,6 @@ func handleEvent() { // way to handle it, ignore it. C.sd_ble_gatts_sys_attr_set(gattsEvent.conn_handle, nil, 0, 0) case C.BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: - // This event is generated by some devices. While we could support - // larger MTUs, this default MTU is supported everywhere. rsp := gattsEvent.params.unionfield_exchange_mtu_request() effectiveMtu := min(DefaultAdapter.cfg.Gatt.AttMtu, uint16(rsp.client_rx_mtu)) if debug { diff --git a/adapter_nrf528xx-peripheral.go b/adapter_nrf528xx-peripheral.go index cd094a2..f70749b 100644 --- a/adapter_nrf528xx-peripheral.go +++ b/adapter_nrf528xx-peripheral.go @@ -91,9 +91,16 @@ func handleEvent() { // way to handle it, ignore it. C.sd_ble_gatts_sys_attr_set(gattsEvent.conn_handle, nil, 0, 0) case C.BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: - // This event is generated by some devices. While we could support - // larger MTUs, this default MTU is supported everywhere. - C.sd_ble_gatts_exchange_mtu_reply(gattsEvent.conn_handle, C.BLE_GATT_ATT_MTU_DEFAULT) + rsp := gattsEvent.params.unionfield_exchange_mtu_request() + effectiveMtu := min(DefaultAdapter.cfg.Gatt.AttMtu, uint16(rsp.client_rx_mtu)) + if debug { + println("mtu exchange requested. self:", DefaultAdapter.cfg.Gatt.AttMtu, ", peer:", rsp.client_rx_mtu, ", effective:", effectiveMtu) + } + + var errCode = C.sd_ble_gatts_exchange_mtu_reply(gattsEvent.conn_handle, C.uint16_t(effectiveMtu)) + if debug { + println("mtu exchange replied, err:", Error(errCode).Error()) + } case C.BLE_GATTS_EVT_HVN_TX_COMPLETE: // ignore confirmation of a notification successfully sent default: @@ -107,3 +114,10 @@ func handleEvent() { } } } + +func min(a, b uint16) uint16 { + if a < b { + return a + } + return b +}