Skip to content

Commit 21ad886

Browse files
handle mtu and data len events for softdevice
1 parent 06a2a40 commit 21ad886

File tree

1 file changed

+47
-6
lines changed
  • features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle

1 file changed

+47
-6
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "ble/GapEvents.h"
2828
#include "nRF5xn.h"
29+
#include <algorithm>
2930

3031
#ifdef S110
3132
#define IS_LEGACY_DEVICE_MANAGER_ENABLED 1
@@ -368,15 +369,55 @@ void btle_handler(const ble_evt_t *p_ble_evt)
368369

369370
ASSERT_STATUS_RET_VOID(sd_ble_gap_data_length_update(p_gap_evt->conn_handle, &dlp, NULL));
370371
break;
372+
// Handle Data length negotiation result
373+
case BLE_GAP_EVT_DATA_LENGTH_UPDATE: {
374+
/* inform user application */
375+
if (gap._eventHandler) {
376+
Gap::Handle_t connection = p_ble_evt->evt.gap_evt.conn_handle;
377+
const ble_gap_evt_data_length_update_t &update =
378+
p_ble_evt->evt.gap_evt.params.data_length_update;
379+
380+
gap._eventHandler->onPacketPayloadSizeChanged(
381+
connection,
382+
update.effective_params.max_tx_octets,
383+
update.effective_params.max_rx_octets
384+
);
385+
}
386+
break;
371387
}
372388

373-
// Handle MTU exchange request
374-
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST:
375-
{
376-
// Respond with the server MTU
377-
uint16_t conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
389+
case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: {
390+
/* Respond with the server MTU */
391+
uint16_t conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
378392
ASSERT_STATUS_RET_VOID(sd_ble_gatts_exchange_mtu_reply(conn_handle, NRF_SDH_BLE_GATT_MAX_MTU_SIZE));
379-
break;
393+
394+
/* inform user application */
395+
if (gap._eventHandler) {
396+
Gap::Handle_t connection = p_ble_evt->evt.gap_evt.conn_handle;
397+
const ble_gatts_evt_exchange_mtu_request_t &update =
398+
p_ble_evt->evt.gatts_evt.params.exchange_mtu_request;
399+
400+
gap._eventHandler->onAttMtuChanged(
401+
connection,
402+
std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.client_rx_mtu))
403+
);
404+
}
405+
break;
406+
}
407+
408+
case BLE_GATTC_EVT_EXCHANGE_MTU_RSP: {
409+
/* inform user application */
410+
if (gap._eventHandler) {
411+
Gap::Handle_t connection = p_ble_evt->evt.gap_evt.conn_handle;
412+
const ble_gattc_evt_exchange_mtu_rsp_t &update =
413+
p_ble_evt->evt.gattc_evt.params.exchange_mtu_rsp;
414+
415+
gap._eventHandler->onAttMtuChanged(
416+
connection,
417+
std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.server_rx_mtu))
418+
);
419+
}
420+
break;
380421
}
381422
#endif
382423
case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: {

0 commit comments

Comments
 (0)