From c452d8ff0e4c8a5f037da1fbb66e0eab8e25e9b3 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Wed, 9 Jan 2019 09:51:39 +0000 Subject: [PATCH 01/18] add mtu events --- features/FEATURE_BLE/ble/gap/Gap.h | 31 +++++++++++++++++++ features/FEATURE_BLE/ble/generic/GenericGap.h | 11 +++++++ features/FEATURE_BLE/ble/pal/PalGap.h | 17 ++++++++++ .../FEATURE_BLE/source/generic/GenericGap.cpp | 17 ++++++++++ 4 files changed, 76 insertions(+) diff --git a/features/FEATURE_BLE/ble/gap/Gap.h b/features/FEATURE_BLE/ble/gap/Gap.h index 98f60f4596..f859e49782 100644 --- a/features/FEATURE_BLE/ble/gap/Gap.h +++ b/features/FEATURE_BLE/ble/gap/Gap.h @@ -492,6 +492,37 @@ public: { } + /** + * Function invoked when the connections changes the ATT_MTU which controls + * the maximum size of an attribute that can be read in a single L2CAP packet + * which might be fragmented across multiple packets. + * + * @param connectionHandle The handle of the connection that changed the size. + * @param attMtuSize + */ + virtual void onAttMtuChanged( + connection_handle_t connectionHandle, + uint16_t attMtuSize + ) + { + } + + /** + * Function invoked when the connections changes the maximum number of octets + * that can be sent or received by the controller in a single packet. + * + * @param connectionHandle The handle of the connection that changed the size. + * @param txSize Number of octets we can send on this connection in a single packet. + * @param rxSize Number of octets we can receive on this connection in a single packet. + */ + virtual void onPacketPaylodSizeChanged( + connection_handle_t connectionHandle, + uint16_t txSize, + uint16_t rxSize + ) + { + } + protected: /** * Prevent polymorphic deletion and avoid unnecessary virtual destructor diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index b46bcb6716..2c8b686a0a 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -627,6 +627,17 @@ private: phy_t rx_phy ); + virtual void on_att_mtu_changed( + Handle_t connection_handle, + uint16_t att_mtu_size + ); + + virtual void on_packet_paylod_size_changed( + Handle_t connection_handle, + uint16_t tx_size, + uint16_t rx_size + ); + virtual void on_phy_update_complete( pal::hci_error_code_t hci_status, Handle_t connection_handle, diff --git a/features/FEATURE_BLE/ble/pal/PalGap.h b/features/FEATURE_BLE/ble/pal/PalGap.h index 39e06f2622..1e3c95b1d3 100644 --- a/features/FEATURE_BLE/ble/pal/PalGap.h +++ b/features/FEATURE_BLE/ble/pal/PalGap.h @@ -44,6 +44,23 @@ struct Gap { ble::phy_t rx_phy ) = 0; + /** + * @copydoc Gap::EventHandler::onAttMtuChanged + */ + virtual void on_att_mtu_changed( + Handle_t connection_handle, + uint16_t att_mtu_size + ) = 0; + + /** + * @copydoc Gap::EventHandler::onPacketPaylodSizeChanged + */ + virtual void on_packet_paylod_size_changed( + Handle_t connection_handle, + uint16_t tx_size, + uint16_t rx_size + ) = 0; + /** * @copydoc Gap::EventHandler::onPhyUpdateComplete */ diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 4ca9b9df09..8e622906ab 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -860,6 +860,23 @@ void GenericGap::on_read_phy( } } +void GenericGap::on_att_mtu_changed( + Handle_t connection_handle, + uint16_t att_mtu_size +) +{ + onAttMtuChanged(connectionHandle, attMtuSize); +} + +void GenericGap::on_packet_paylod_size_changed( + Handle_t connection_handle, + uint16_t tx_size, + uint16_t rx_size +) +{ + onPacketPaylodSizeChanged(connectionHandle, txSize, rxSize); +} + void GenericGap::on_phy_update_complete( pal::hci_error_code_t hci_status, Handle_t connection_handle, From 108d6908be4c197e86f7ed478f4bd7e9c319e304 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Wed, 9 Jan 2019 15:27:46 +0000 Subject: [PATCH 02/18] route ble events to gap --- features/FEATURE_BLE/ble/pal/PalGap.h | 4 ++-- features/FEATURE_BLE/source/generic/GenericGap.cpp | 8 ++++++-- .../targets/TARGET_CORDIO/CordioPalAttClient.h | 13 ++++++++++++- .../targets/TARGET_CORDIO/source/CordioBLE.cpp | 14 ++++++++++++++ 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/features/FEATURE_BLE/ble/pal/PalGap.h b/features/FEATURE_BLE/ble/pal/PalGap.h index 1e3c95b1d3..5d0a16432d 100644 --- a/features/FEATURE_BLE/ble/pal/PalGap.h +++ b/features/FEATURE_BLE/ble/pal/PalGap.h @@ -48,7 +48,7 @@ struct Gap { * @copydoc Gap::EventHandler::onAttMtuChanged */ virtual void on_att_mtu_changed( - Handle_t connection_handle, + connection_handle_t connection_handle, uint16_t att_mtu_size ) = 0; @@ -56,7 +56,7 @@ struct Gap { * @copydoc Gap::EventHandler::onPacketPaylodSizeChanged */ virtual void on_packet_paylod_size_changed( - Handle_t connection_handle, + connection_handle_t connection_handle, uint16_t tx_size, uint16_t rx_size ) = 0; diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 8e622906ab..72959127d7 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -865,7 +865,9 @@ void GenericGap::on_att_mtu_changed( uint16_t att_mtu_size ) { - onAttMtuChanged(connectionHandle, attMtuSize); + if (_eventHandler) { + _eventHandler->onAttMtuChanged(connection_handle, att_mtu_size); + } } void GenericGap::on_packet_paylod_size_changed( @@ -874,7 +876,9 @@ void GenericGap::on_packet_paylod_size_changed( uint16_t rx_size ) { - onPacketPaylodSizeChanged(connectionHandle, txSize, rxSize); + if (_eventHandler) { + _eventHandler->onPacketPaylodSizeChanged(connection_handle, tx_size, rx_size); + } } void GenericGap::on_phy_update_complete( diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h index cff00fceea..83d79454d0 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h @@ -22,6 +22,8 @@ #include "ble/pal/SimpleAttServerMessage.h" #include "att_api.h" #include "att_defs.h" +#include "ble/pal/PalGap.h" +#include "CordioPalGap.h" namespace ble { namespace pal { @@ -318,11 +320,20 @@ public: */ static void att_client_handler(const attEvt_t* event) { + if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) { + ble::pal::Gap::EventHandler *handler; + handler = ble::pal::vendor::cordio::Gap::get_gap().get_event_handler(); + if (handler) { + handler->on_att_mtu_changed(event->hdr.param, event->mtu); + } + return; + } + // all handlers are stored in a static array static const event_handler_t handlers[] = { &timeout_event_handler, &event_handler, - &event_handler, + //&event_handler, &event_handler, &event_handler, &event_handler, diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index ba57e6bb96..8be2da8092 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -286,6 +286,20 @@ void BLE::processEvents() void BLE::device_manager_cb(dmEvt_t* dm_event) { + if (dm_event->hdr.status == HCI_SUCCESS && dm_event->hdr.event == DM_CONN_DATA_LEN_CHANGE_IND) { + // this event can only happen after a connection has been established therefore gap is present + ble::pal::Gap::EventHandler *handler; + handler = ble::pal::vendor::cordio::Gap::get_gap().get_event_handler(); + if (handler) { + handler->on_packet_paylod_size_changed( + dm_event->hdr.param, + dm_event->dataLenChange.maxTxOctets, + dm_event->dataLenChange.maxRxOctets + ); + } + return; + } + BLE::deviceInstance().stack_handler(0, &dm_event->hdr); } From 06a2a403e959d58a749341496cc7810972f062d0 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Wed, 9 Jan 2019 17:26:26 +0000 Subject: [PATCH 03/18] fix typos --- features/FEATURE_BLE/ble/gap/Gap.h | 2 +- features/FEATURE_BLE/ble/generic/GenericGap.h | 6 +++--- features/FEATURE_BLE/ble/pal/PalGap.h | 4 ++-- features/FEATURE_BLE/source/generic/GenericGap.cpp | 4 ++-- .../FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/features/FEATURE_BLE/ble/gap/Gap.h b/features/FEATURE_BLE/ble/gap/Gap.h index f859e49782..483293d39d 100644 --- a/features/FEATURE_BLE/ble/gap/Gap.h +++ b/features/FEATURE_BLE/ble/gap/Gap.h @@ -515,7 +515,7 @@ public: * @param txSize Number of octets we can send on this connection in a single packet. * @param rxSize Number of octets we can receive on this connection in a single packet. */ - virtual void onPacketPaylodSizeChanged( + virtual void onPacketPayloadSizeChanged( connection_handle_t connectionHandle, uint16_t txSize, uint16_t rxSize diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index 2c8b686a0a..c620c1772b 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -628,12 +628,12 @@ private: ); virtual void on_att_mtu_changed( - Handle_t connection_handle, + connection_handle_t connection_handle, uint16_t att_mtu_size ); - virtual void on_packet_paylod_size_changed( - Handle_t connection_handle, + virtual void on_packet_payload_size_changed( + connection_handle_t connection_handle, uint16_t tx_size, uint16_t rx_size ); diff --git a/features/FEATURE_BLE/ble/pal/PalGap.h b/features/FEATURE_BLE/ble/pal/PalGap.h index 5d0a16432d..6570ad6ebc 100644 --- a/features/FEATURE_BLE/ble/pal/PalGap.h +++ b/features/FEATURE_BLE/ble/pal/PalGap.h @@ -53,9 +53,9 @@ struct Gap { ) = 0; /** - * @copydoc Gap::EventHandler::onPacketPaylodSizeChanged + * @copydoc Gap::EventHandler::onPacketPayloadSizeChanged */ - virtual void on_packet_paylod_size_changed( + virtual void on_packet_payload_size_changed( connection_handle_t connection_handle, uint16_t tx_size, uint16_t rx_size diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 72959127d7..90212423c9 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -870,14 +870,14 @@ void GenericGap::on_att_mtu_changed( } } -void GenericGap::on_packet_paylod_size_changed( +void GenericGap::on_packet_payload_size_changed( Handle_t connection_handle, uint16_t tx_size, uint16_t rx_size ) { if (_eventHandler) { - _eventHandler->onPacketPaylodSizeChanged(connection_handle, tx_size, rx_size); + _eventHandler->onPacketPayloadSizeChanged(connection_handle, tx_size, rx_size); } } diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index 8be2da8092..051c0b1a13 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -291,7 +291,7 @@ void BLE::device_manager_cb(dmEvt_t* dm_event) ble::pal::Gap::EventHandler *handler; handler = ble::pal::vendor::cordio::Gap::get_gap().get_event_handler(); if (handler) { - handler->on_packet_paylod_size_changed( + handler->on_packet_payload_size_changed( dm_event->hdr.param, dm_event->dataLenChange.maxTxOctets, dm_event->dataLenChange.maxRxOctets From 21ad886e9eb6a2f3d270d94ed2c8e3166a9b2ffe Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 15 Jan 2019 13:25:19 +0000 Subject: [PATCH 04/18] handle mtu and data len events for softdevice --- .../TARGET_NRF52/source/btle/btle.cpp | 53 ++++++++++++++++--- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp index 962ddef9b7..1f74a7115f 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp @@ -26,6 +26,7 @@ #include "ble/GapEvents.h" #include "nRF5xn.h" +#include #ifdef S110 #define IS_LEGACY_DEVICE_MANAGER_ENABLED 1 @@ -368,15 +369,55 @@ void btle_handler(const ble_evt_t *p_ble_evt) ASSERT_STATUS_RET_VOID(sd_ble_gap_data_length_update(p_gap_evt->conn_handle, &dlp, NULL)); break; + // Handle Data length negotiation result + case BLE_GAP_EVT_DATA_LENGTH_UPDATE: { + /* inform user application */ + if (gap._eventHandler) { + Gap::Handle_t connection = p_ble_evt->evt.gap_evt.conn_handle; + const ble_gap_evt_data_length_update_t &update = + p_ble_evt->evt.gap_evt.params.data_length_update; + + gap._eventHandler->onPacketPayloadSizeChanged( + connection, + update.effective_params.max_tx_octets, + update.effective_params.max_rx_octets + ); + } + break; } - // Handle MTU exchange request - case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: - { - // Respond with the server MTU - uint16_t conn_handle = p_ble_evt->evt.gatts_evt.conn_handle; + case BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST: { + /* Respond with the server MTU */ + uint16_t conn_handle = p_ble_evt->evt.gatts_evt.conn_handle; ASSERT_STATUS_RET_VOID(sd_ble_gatts_exchange_mtu_reply(conn_handle, NRF_SDH_BLE_GATT_MAX_MTU_SIZE)); - break; + + /* inform user application */ + if (gap._eventHandler) { + Gap::Handle_t connection = p_ble_evt->evt.gap_evt.conn_handle; + const ble_gatts_evt_exchange_mtu_request_t &update = + p_ble_evt->evt.gatts_evt.params.exchange_mtu_request; + + gap._eventHandler->onAttMtuChanged( + connection, + std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.client_rx_mtu)) + ); + } + break; + } + + case BLE_GATTC_EVT_EXCHANGE_MTU_RSP: { + /* inform user application */ + if (gap._eventHandler) { + Gap::Handle_t connection = p_ble_evt->evt.gap_evt.conn_handle; + const ble_gattc_evt_exchange_mtu_rsp_t &update = + p_ble_evt->evt.gattc_evt.params.exchange_mtu_rsp; + + gap._eventHandler->onAttMtuChanged( + connection, + std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.server_rx_mtu)) + ); + } + break; } #endif case BLE_GAP_EVT_CONN_PARAM_UPDATE_REQUEST: { From 356ec39d02967af4fcb6331fb53e2e3f2ae49191 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 15 Jan 2019 13:25:31 +0000 Subject: [PATCH 05/18] fix style --- .../TARGET_NRF52/source/btle/btle.cpp | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp index 1f74a7115f..c3fa48b81c 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp @@ -335,26 +335,27 @@ void btle_handler(const ble_evt_t *p_ble_evt) #if (NRF_SD_BLE_API_VERSION >= 5) #ifndef S140 // Handle PHY upgrade request - case BLE_GAP_EVT_PHY_UPDATE_REQUEST: + case BLE_GAP_EVT_PHY_UPDATE_REQUEST: { gap.on_phy_update_request( p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.phy_update_request ); break; + } #endif - case BLE_GAP_EVT_PHY_UPDATE: + case BLE_GAP_EVT_PHY_UPDATE: { gap.on_phy_update( p_ble_evt->evt.gap_evt.conn_handle, p_ble_evt->evt.gap_evt.params.phy_update ); break; + } - // Handle Data length negotiation request - case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: - { - ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt; + // Handle Data length negotiation request + case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: { + ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt; uint8_t const data_length_peer = - p_gap_evt->params.data_length_update_request.peer_params.max_tx_octets; + p_gap_evt->params.data_length_update_request.peer_params.max_tx_octets; uint8_t const data_length = MIN( NRF_SDH_BLE_GATT_MAX_MTU_SIZE + 4 /* L2CAP header size */, @@ -363,12 +364,14 @@ void btle_handler(const ble_evt_t *p_ble_evt) ble_gap_data_length_params_t const dlp = { - /* max_rx_octets */ data_length, - /* max_tx_octets */ data_length + /* max_rx_octets */data_length, + /* max_tx_octets */data_length }; ASSERT_STATUS_RET_VOID(sd_ble_gap_data_length_update(p_gap_evt->conn_handle, &dlp, NULL)); - break; + break; + } + // Handle Data length negotiation result case BLE_GAP_EVT_DATA_LENGTH_UPDATE: { /* inform user application */ From b6df6d54a1266af41ceba4d6bab1a502d9d56465 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 15 Jan 2019 14:26:30 +0000 Subject: [PATCH 06/18] change event names --- features/FEATURE_BLE/ble/gap/Gap.h | 10 +++++++--- features/FEATURE_BLE/ble/generic/GenericGap.h | 2 +- features/FEATURE_BLE/ble/pal/PalGap.h | 6 +++--- features/FEATURE_BLE/source/generic/GenericGap.cpp | 6 +++--- .../targets/TARGET_CORDIO/source/CordioBLE.cpp | 2 +- .../TARGET_NRF52/source/btle/btle.cpp | 6 +++--- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/features/FEATURE_BLE/ble/gap/Gap.h b/features/FEATURE_BLE/ble/gap/Gap.h index 483293d39d..54d71e0bc0 100644 --- a/features/FEATURE_BLE/ble/gap/Gap.h +++ b/features/FEATURE_BLE/ble/gap/Gap.h @@ -500,7 +500,7 @@ public: * @param connectionHandle The handle of the connection that changed the size. * @param attMtuSize */ - virtual void onAttMtuChanged( + virtual void onAttMtuChange( connection_handle_t connectionHandle, uint16_t attMtuSize ) @@ -509,13 +509,17 @@ public: /** * Function invoked when the connections changes the maximum number of octets - * that can be sent or received by the controller in a single packet. + * that can be sent or received by the controller in a single packet. A single + * L2CAP packet can be fragmented across many such packets. + * + * @note This only triggers if controller supports data length extension and + * negotiated data length is longer than the default 23. * * @param connectionHandle The handle of the connection that changed the size. * @param txSize Number of octets we can send on this connection in a single packet. * @param rxSize Number of octets we can receive on this connection in a single packet. */ - virtual void onPacketPayloadSizeChanged( + virtual void onDataLengthChange( connection_handle_t connectionHandle, uint16_t txSize, uint16_t rxSize diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index c620c1772b..f00489a5c0 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -632,7 +632,7 @@ private: uint16_t att_mtu_size ); - virtual void on_packet_payload_size_changed( + virtual void on_data_length_change( connection_handle_t connection_handle, uint16_t tx_size, uint16_t rx_size diff --git a/features/FEATURE_BLE/ble/pal/PalGap.h b/features/FEATURE_BLE/ble/pal/PalGap.h index 6570ad6ebc..d4cea30243 100644 --- a/features/FEATURE_BLE/ble/pal/PalGap.h +++ b/features/FEATURE_BLE/ble/pal/PalGap.h @@ -45,7 +45,7 @@ struct Gap { ) = 0; /** - * @copydoc Gap::EventHandler::onAttMtuChanged + * @copydoc Gap::EventHandler::onAttMtuChange */ virtual void on_att_mtu_changed( connection_handle_t connection_handle, @@ -53,9 +53,9 @@ struct Gap { ) = 0; /** - * @copydoc Gap::EventHandler::onPacketPayloadSizeChanged + * @copydoc Gap::EventHandler::onDataLengthChange */ - virtual void on_packet_payload_size_changed( + virtual void on_data_length_change( connection_handle_t connection_handle, uint16_t tx_size, uint16_t rx_size diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 90212423c9..321ee6e4a6 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -866,18 +866,18 @@ void GenericGap::on_att_mtu_changed( ) { if (_eventHandler) { - _eventHandler->onAttMtuChanged(connection_handle, att_mtu_size); + _eventHandler->onAttMtuChange(connection_handle, att_mtu_size); } } -void GenericGap::on_packet_payload_size_changed( +void GenericGap::on_data_length_change( Handle_t connection_handle, uint16_t tx_size, uint16_t rx_size ) { if (_eventHandler) { - _eventHandler->onPacketPayloadSizeChanged(connection_handle, tx_size, rx_size); + _eventHandler->onDataLengthChange(connection_handle, tx_size, rx_size); } } diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index 051c0b1a13..5cffdac74b 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -291,7 +291,7 @@ void BLE::device_manager_cb(dmEvt_t* dm_event) ble::pal::Gap::EventHandler *handler; handler = ble::pal::vendor::cordio::Gap::get_gap().get_event_handler(); if (handler) { - handler->on_packet_payload_size_changed( + handler->on_data_length_change( dm_event->hdr.param, dm_event->dataLenChange.maxTxOctets, dm_event->dataLenChange.maxRxOctets diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp index c3fa48b81c..7e7e4258f5 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp @@ -380,7 +380,7 @@ void btle_handler(const ble_evt_t *p_ble_evt) const ble_gap_evt_data_length_update_t &update = p_ble_evt->evt.gap_evt.params.data_length_update; - gap._eventHandler->onPacketPayloadSizeChanged( + gap._eventHandler->onDataLengthChange( connection, update.effective_params.max_tx_octets, update.effective_params.max_rx_octets @@ -400,7 +400,7 @@ void btle_handler(const ble_evt_t *p_ble_evt) const ble_gatts_evt_exchange_mtu_request_t &update = p_ble_evt->evt.gatts_evt.params.exchange_mtu_request; - gap._eventHandler->onAttMtuChanged( + gap._eventHandler->onAttMtuChange( connection, std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.client_rx_mtu)) ); @@ -415,7 +415,7 @@ void btle_handler(const ble_evt_t *p_ble_evt) const ble_gattc_evt_exchange_mtu_rsp_t &update = p_ble_evt->evt.gattc_evt.params.exchange_mtu_rsp; - gap._eventHandler->onAttMtuChanged( + gap._eventHandler->onAttMtuChange( connection, std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.server_rx_mtu)) ); From 02d5391cd01755e4da2c4381484beb9325020ebd Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Wed, 16 Jan 2019 14:23:28 +0000 Subject: [PATCH 07/18] fix possible truncation --- .../TARGET_NRF52/source/btle/btle.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp index 7e7e4258f5..57cb8ef3f8 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp @@ -355,15 +355,14 @@ void btle_handler(const ble_evt_t *p_ble_evt) case BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST: { ble_gap_evt_t const * p_gap_evt = &p_ble_evt->evt.gap_evt; uint8_t const data_length_peer = - p_gap_evt->params.data_length_update_request.peer_params.max_tx_octets; + p_gap_evt->params.data_length_update_request.peer_params.max_tx_octets; uint8_t const data_length = MIN( NRF_SDH_BLE_GATT_MAX_MTU_SIZE + 4 /* L2CAP header size */, data_length_peer ); - ble_gap_data_length_params_t const dlp = - { + ble_gap_data_length_params_t const dlp = { /* max_rx_octets */data_length, /* max_tx_octets */data_length }; From c10fc2eb8ed2b303cfa5775934dd517ba87c3e79 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Wed, 16 Jan 2019 16:55:50 +0000 Subject: [PATCH 08/18] add API to trigger MTU negotiation --- features/FEATURE_BLE/ble/GattClient.h | 21 +++++++++++++++++++ .../ble/generic/GenericGattClient.h | 7 +++++++ .../source/generic/GenericGattClient.cpp | 6 ++++++ 3 files changed, 34 insertions(+) diff --git a/features/FEATURE_BLE/ble/GattClient.h b/features/FEATURE_BLE/ble/GattClient.h index fc60e5c840..71ac437170 100644 --- a/features/FEATURE_BLE/ble/GattClient.h +++ b/features/FEATURE_BLE/ble/GattClient.h @@ -635,6 +635,27 @@ public: (void) characteristic; } + /** + * Trigger MTU negotiation. This might result in a Gap event onAttMtuChange + * being called if MTU changes. + * + * @note This does not guarantee a change in MTU size. If size remains + * unchanged no event will be generated. + * + * @param connection Connection on which the MTU is to be negotiated. + * + * @return BLE_ERROR_NONE if the procedure has been launched successfully + * otherwise an appropriate error. + */ + virtual ble_error_t negotiateAttMtu( + Gap::Handle_t connection + ) { + /* Requesting action from porter(s): override this API if this + capability is supported. */ + (void) connection; + return BLE_ERROR_NOT_IMPLEMENTED; + } + /** * Register an handler for Handle Value Notification/Indication events. * diff --git a/features/FEATURE_BLE/ble/generic/GenericGattClient.h b/features/FEATURE_BLE/ble/generic/GenericGattClient.h index b135535d93..c4e0049adc 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGattClient.h +++ b/features/FEATURE_BLE/ble/generic/GenericGattClient.h @@ -111,6 +111,13 @@ public: const DiscoveredCharacteristic& characteristic ); + /** + * @see GattClient::negotiateAttMtu + */ + virtual ble_error_t negotiateAttMtu( + connection_handle_t connection + ); + /** * @see GattClient::reset */ diff --git a/features/FEATURE_BLE/source/generic/GenericGattClient.cpp b/features/FEATURE_BLE/source/generic/GenericGattClient.cpp index c89577d988..2036ec6f77 100644 --- a/features/FEATURE_BLE/source/generic/GenericGattClient.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGattClient.cpp @@ -1259,6 +1259,12 @@ void GenericGattClient::terminateCharacteristicDescriptorDiscovery( } +ble_error_t GenericGattClient::negotiateAttMtu( + connection_handle_t connection +) { + return _pal_client->exchange_mtu(connection); +} + ble_error_t GenericGattClient::reset(void) { // _is_reseting prevent executions of new procedure while the instance resets. From a3f635eb8826426d93a34f69f0fa0397d14e5199 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Wed, 30 Jan 2019 10:50:25 +0000 Subject: [PATCH 09/18] fix type name --- features/FEATURE_BLE/ble/GattClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/FEATURE_BLE/ble/GattClient.h b/features/FEATURE_BLE/ble/GattClient.h index 71ac437170..a429b6c94e 100644 --- a/features/FEATURE_BLE/ble/GattClient.h +++ b/features/FEATURE_BLE/ble/GattClient.h @@ -648,7 +648,7 @@ public: * otherwise an appropriate error. */ virtual ble_error_t negotiateAttMtu( - Gap::Handle_t connection + ble::connection_handle_t connection ) { /* Requesting action from porter(s): override this API if this capability is supported. */ From b6282852543090fc2af724c3d626bf160e01de33 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Fri, 1 Feb 2019 19:29:48 +0000 Subject: [PATCH 10/18] route mtu changed events to server and client instead of gap --- features/FEATURE_BLE/ble/GattClient.h | 37 ++++++++++ features/FEATURE_BLE/ble/GattServer.h | 37 ++++++++++ features/FEATURE_BLE/ble/gap/Gap.h | 15 ---- features/FEATURE_BLE/ble/generic/GenericGap.h | 5 -- .../ble/generic/GenericGattClient.h | 18 ++++- features/FEATURE_BLE/ble/pal/PalGap.h | 8 -- features/FEATURE_BLE/ble/pal/PalGattClient.h | 21 +++++- .../FEATURE_BLE/source/generic/GenericGap.cpp | 10 --- .../source/generic/GenericGattClient.cpp | 2 +- .../targets/TARGET_CORDIO/CordioGattServer.h | 4 + .../TARGET_CORDIO/CordioPalAttClient.cpp | 73 +++++++++++++++++++ .../TARGET_CORDIO/CordioPalAttClient.h | 50 +------------ .../TARGET_CORDIO/source/CordioGattServer.cpp | 7 +- .../source/nRF5xGattServer.h | 3 + .../TARGET_NRF51/source/nRF5xGattServer.h | 3 + .../TARGET_NRF52/source/btle/btle.cpp | 6 +- .../TARGET_NRF52/source/nRF5xGattServer.h | 3 + 17 files changed, 211 insertions(+), 91 deletions(-) create mode 100644 features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp diff --git a/features/FEATURE_BLE/ble/GattClient.h b/features/FEATURE_BLE/ble/GattClient.h index a429b6c94e..5eff0df04e 100644 --- a/features/FEATURE_BLE/ble/GattClient.h +++ b/features/FEATURE_BLE/ble/GattClient.h @@ -83,6 +83,38 @@ */ class GattClient { public: + + /** + * Definition of the general handler of GattClient related events. + */ + struct EventHandler { + /** + * Function invoked when the connections changes the ATT_MTU which controls + * the maximum size of an attribute that can be read in a single L2CAP packet + * which might be fragmented across multiple packets. + * + * @param connectionHandle The handle of the connection that changed the size. + * @param attMtuSize + */ + virtual void onAttMtuChange( + ble::connection_handle_t connectionHandle, + uint16_t attMtuSize + ) + { + } + }; + + /** + * Assign the event handler implementation that will be used by the + * module to signal events back to the application. + * + * @param handler Application implementation of an EventHandler. + */ + void setEventHandler(EventHandler *handler) + { + _eventHandler = handler; + } + /** * Attribute read event handler. * @@ -815,6 +847,11 @@ public: } protected: + /** + * Event handler provided by the application. + */ + EventHandler *_eventHandler; + /** * Callchain containing all registered event handlers for data read * events. diff --git a/features/FEATURE_BLE/ble/GattServer.h b/features/FEATURE_BLE/ble/GattServer.h index 3b0d140392..8335e7f798 100644 --- a/features/FEATURE_BLE/ble/GattServer.h +++ b/features/FEATURE_BLE/ble/GattServer.h @@ -87,6 +87,38 @@ */ class GattServer { public: + + /** + * Definition of the general handler of GattServer related events. + */ + struct EventHandler { + /** + * Function invoked when the connections changes the ATT_MTU which controls + * the maximum size of an attribute that can be read in a single L2CAP packet + * which might be fragmented across multiple packets. + * + * @param connectionHandle The handle of the connection that changed the size. + * @param attMtuSize + */ + virtual void onAttMtuChange( + ble::connection_handle_t connectionHandle, + uint16_t attMtuSize + ) + { + } + }; + + /** + * Assign the event handler implementation that will be used by the + * module to signal events back to the application. + * + * @param handler Application implementation of an EventHandler. + */ + void setEventHandler(EventHandler *handler) + { + _eventHandler = handler; + } + /** * Event handler invoked when the server has sent data to a client. * @@ -778,6 +810,11 @@ public: } protected: + /** + * Event handler provided by the application. + */ + EventHandler *_eventHandler; + /** * The total number of services added to the ATT table. */ diff --git a/features/FEATURE_BLE/ble/gap/Gap.h b/features/FEATURE_BLE/ble/gap/Gap.h index 54d71e0bc0..93d1957709 100644 --- a/features/FEATURE_BLE/ble/gap/Gap.h +++ b/features/FEATURE_BLE/ble/gap/Gap.h @@ -492,21 +492,6 @@ public: { } - /** - * Function invoked when the connections changes the ATT_MTU which controls - * the maximum size of an attribute that can be read in a single L2CAP packet - * which might be fragmented across multiple packets. - * - * @param connectionHandle The handle of the connection that changed the size. - * @param attMtuSize - */ - virtual void onAttMtuChange( - connection_handle_t connectionHandle, - uint16_t attMtuSize - ) - { - } - /** * Function invoked when the connections changes the maximum number of octets * that can be sent or received by the controller in a single packet. A single diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index f00489a5c0..be0903edc1 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -627,11 +627,6 @@ private: phy_t rx_phy ); - virtual void on_att_mtu_changed( - connection_handle_t connection_handle, - uint16_t att_mtu_size - ); - virtual void on_data_length_change( connection_handle_t connection_handle, uint16_t tx_size, diff --git a/features/FEATURE_BLE/ble/generic/GenericGattClient.h b/features/FEATURE_BLE/ble/generic/GenericGattClient.h index c4e0049adc..eece4dfed4 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGattClient.h +++ b/features/FEATURE_BLE/ble/generic/GenericGattClient.h @@ -33,8 +33,20 @@ namespace generic { * @attention: Not part of the public interface of BLE API. */ class GenericGattClient : public GattClient, - public pal::SigningEventMonitor { + public pal::SigningEventMonitor, + public pal::GattClient::EventHandler { public: + + virtual void on_att_mtu_change( + ble::connection_handle_t connection_handle, + uint16_t att_mtu_size + ) + { + if (_eventHandler) { + _eventHandler->onAttMtuChange(connection_handle, att_mtu_size); + } + } + /** * Create a GenericGattClient from a pal::GattClient */ @@ -128,6 +140,10 @@ public: */ virtual void set_signing_event_handler(pal::SigningEventMonitor::EventHandler *signing_event_handler); + ::GattClient::EventHandler* getEventHandler() { + return _eventHandler; + } + private: struct ProcedureControlBlock; struct DiscoveryControlBlock; diff --git a/features/FEATURE_BLE/ble/pal/PalGap.h b/features/FEATURE_BLE/ble/pal/PalGap.h index d4cea30243..3598fdace2 100644 --- a/features/FEATURE_BLE/ble/pal/PalGap.h +++ b/features/FEATURE_BLE/ble/pal/PalGap.h @@ -44,14 +44,6 @@ struct Gap { ble::phy_t rx_phy ) = 0; - /** - * @copydoc Gap::EventHandler::onAttMtuChange - */ - virtual void on_att_mtu_changed( - connection_handle_t connection_handle, - uint16_t att_mtu_size - ) = 0; - /** * @copydoc Gap::EventHandler::onDataLengthChange */ diff --git a/features/FEATURE_BLE/ble/pal/PalGattClient.h b/features/FEATURE_BLE/ble/pal/PalGattClient.h index 2152c428f4..d0362240e5 100644 --- a/features/FEATURE_BLE/ble/pal/PalGattClient.h +++ b/features/FEATURE_BLE/ble/pal/PalGattClient.h @@ -55,8 +55,27 @@ namespace pal { * the class AttClientToGattClientAdapter */ class GattClient { - public: + /** + * Definition of the general handler of GattClient related events. + */ + struct EventHandler { + /** + * Function invoked when the connections changes the ATT_MTU which controls + * the maximum size of an attribute that can be read in a single L2CAP packet + * which might be fragmented across multiple packets. + * + * @param connectionHandle The handle of the connection that changed the size. + * @param attMtuSize + */ + virtual void on_att_mtu_change( + ble::connection_handle_t connection_handle, + uint16_t att_mtu_size + ) + { + } + }; + /** * Initialisation of the instance. An implementation can use this function * to initialise the subsystems needed to realize the operations of this diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 321ee6e4a6..26a1cbcb01 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -860,16 +860,6 @@ void GenericGap::on_read_phy( } } -void GenericGap::on_att_mtu_changed( - Handle_t connection_handle, - uint16_t att_mtu_size -) -{ - if (_eventHandler) { - _eventHandler->onAttMtuChange(connection_handle, att_mtu_size); - } -} - void GenericGap::on_data_length_change( Handle_t connection_handle, uint16_t tx_size, diff --git a/features/FEATURE_BLE/source/generic/GenericGattClient.cpp b/features/FEATURE_BLE/source/generic/GenericGattClient.cpp index 2036ec6f77..4ca3616fff 100644 --- a/features/FEATURE_BLE/source/generic/GenericGattClient.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGattClient.cpp @@ -1280,7 +1280,7 @@ ble_error_t GenericGattClient::reset(void) { } void GenericGattClient::set_signing_event_handler( - EventHandler *signing_event_handler + pal::SigningEventMonitor::EventHandler *signing_event_handler ) { _signing_event_handler = signing_event_handler; } diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h index bb9da0dbe5..84dc2dbdf0 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h @@ -62,6 +62,10 @@ public: */ static GattServer &getInstance(); + ::GattServer::EventHandler* getEventHandler() { + return _eventHandler; + } + /** * Initialize the GattServer and add mandatory services (generic access and * generic attribute service). diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp new file mode 100644 index 0000000000..37b6373d43 --- /dev/null +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp @@ -0,0 +1,73 @@ +/* mbed Microcontroller Library + * Copyright (c) 2019 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "CordioPalAttClient.h" +#include "CordioBLE.h" + +namespace ble { +namespace pal { +namespace vendor { +namespace cordio { + +void CordioAttClient::att_client_handler(const attEvt_t* event) +{ + if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) { + ble::vendor::cordio::BLE& ble = ble::vendor::cordio::BLE::deviceInstance(); + ble::pal::GattClient::EventHandler &handler = ble.getGattClient(); + handler.on_att_mtu_change(event->hdr.param, event->mtu); + } else { + // all handlers are stored in a static array + static const event_handler_t handlers[] = { + &timeout_event_handler, + &event_handler, + //&event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler, + &event_handler + }; + + // event->hdr.param: connection handle + // event->header.event: opcode from the request + // event->header.status: success or error code ... + // event->pValue: starting after opcode for response; starting after opcode + handle for server initiated responses. + // event->handle: handle for server initiated responses + + // traverse all handlers and execute them with the event in input. + // exit if an handler has handled the event. + for(size_t i = 0; i < (sizeof(handlers)/sizeof(handlers[0])); ++i) { + if (handlers[i](event)) { + return; + } + } + } + + // pass events not handled to the server side + ble::vendor::cordio::GattServer::getInstance().att_cb(event); +} + +} // cordio +} // vendor +} // pal +} // ble diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h index 83d79454d0..dcda0d1be2 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h @@ -24,6 +24,8 @@ #include "att_defs.h" #include "ble/pal/PalGap.h" #include "CordioPalGap.h" +#include "PalGattClient.h" +#include "CordioBLE.h" namespace ble { namespace pal { @@ -318,53 +320,7 @@ public: /** * Callback which handle attEvt_t and forward them to on_server_event. */ - static void att_client_handler(const attEvt_t* event) - { - if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) { - ble::pal::Gap::EventHandler *handler; - handler = ble::pal::vendor::cordio::Gap::get_gap().get_event_handler(); - if (handler) { - handler->on_att_mtu_changed(event->hdr.param, event->mtu); - } - return; - } - - // all handlers are stored in a static array - static const event_handler_t handlers[] = { - &timeout_event_handler, - &event_handler, - //&event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler, - &event_handler - }; - - // event->hdr.param: connection handle - // event->header.event: opcode from the request - // event->header.status: success or error code ... - // event->pValue: starting after opcode for response; starting after opcode + handle for server initiated responses. - // event->handle: handle for server initiated responses - - // traverse all handlers and execute them with the event in input. - // exit if an handler has handled the event. - for(size_t i = 0; i < (sizeof(handlers)/sizeof(handlers[0])); ++i) { - if (handlers[i](event)) { - return; - } - } - - // pass events not handled to the server side - ble::vendor::cordio::GattServer::getInstance().att_cb(event); - } + static void att_client_handler(const attEvt_t* event); private: /** diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp index 8a096aab26..f3747b0cd6 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp @@ -849,7 +849,12 @@ void GattServer::cccd_cb(attsCccEvt_t *evt) void GattServer::att_cb(const attEvt_t *evt) { - if (evt->hdr.status == ATT_SUCCESS && evt->hdr.event == ATTS_HANDLE_VALUE_CNF) { + if (evt->hdr.status == ATT_SUCCESS && evt->hdr.event == ATT_MTU_UPDATE_IND) { + ::GattServer::EventHandler *handler = getInstance().getEventHandler(); + if (handler) { + handler->onAttMtuChange(evt->hdr.param, evt->mtu); + } + } else if (evt->hdr.status == ATT_SUCCESS && evt->hdr.event == ATTS_HANDLE_VALUE_CNF) { getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_SENT, evt->handle); } } diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_MCU_NRF51822/source/nRF5xGattServer.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_MCU_NRF51822/source/nRF5xGattServer.h index b2e5f87dea..a115d24775 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_MCU_NRF51822/source/nRF5xGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_MCU_NRF51822/source/nRF5xGattServer.h @@ -41,6 +41,9 @@ public: void eventCallback(void); void hwCallback(ble_evt_t *p_ble_evt); + EventHandler* getEventHandler() { + return _eventHandler; + } private: const static unsigned BLE_TOTAL_CHARACTERISTICS = 20; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGattServer.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGattServer.h index 6be90ff733..baedd6473d 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGattServer.h @@ -41,6 +41,9 @@ public: void eventCallback(void); void hwCallback(const ble_evt_t *p_ble_evt); + EventHandler* getEventHandler() { + return _eventHandler; + } private: const static unsigned BLE_TOTAL_CHARACTERISTICS = 20; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp index 57cb8ef3f8..7616973a44 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp @@ -399,7 +399,8 @@ void btle_handler(const ble_evt_t *p_ble_evt) const ble_gatts_evt_exchange_mtu_request_t &update = p_ble_evt->evt.gatts_evt.params.exchange_mtu_request; - gap._eventHandler->onAttMtuChange( + nRF5xGattServer &gatt_server = (nRF5xGattServer&) ble.getGattServer(); + gatt_server.getEventHandler()->onAttMtuChange( connection, std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.client_rx_mtu)) ); @@ -414,7 +415,8 @@ void btle_handler(const ble_evt_t *p_ble_evt) const ble_gattc_evt_exchange_mtu_rsp_t &update = p_ble_evt->evt.gattc_evt.params.exchange_mtu_rsp; - gap._eventHandler->onAttMtuChange( + nRF5xGattServer &gatt_client = (nRF5xGattClient&) ble.getGattClient(); + gatt_client.getEventHandler()->onAttMtuChange( connection, std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.server_rx_mtu)) ); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h index 253c2d1446..77d6f91fa5 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h @@ -41,6 +41,9 @@ public: void eventCallback(void); void hwCallback(const ble_evt_t *p_ble_evt); + EventHandler* getEventHandler() { + return _eventHandler; + } private: const static unsigned BLE_TOTAL_CHARACTERISTICS = NRF_SDH_BLE_TOTAL_CHARACTERISTICS; From 03b747a6f62963893b3b2d470bcd926f759f4740 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 5 Feb 2019 12:14:47 +0000 Subject: [PATCH 11/18] Get the pal event handler from pal gattclient --- features/FEATURE_BLE/ble/pal/PalGattClient.h | 23 ++++++++++++++++++- .../targets/TARGET_CORDIO/CordioBLE.h | 7 ++++++ .../TARGET_CORDIO/CordioPalAttClient.cpp | 6 +++-- .../TARGET_CORDIO/source/CordioBLE.cpp | 10 ++++++-- 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/features/FEATURE_BLE/ble/pal/PalGattClient.h b/features/FEATURE_BLE/ble/pal/PalGattClient.h index d0362240e5..da798e4f5f 100644 --- a/features/FEATURE_BLE/ble/pal/PalGattClient.h +++ b/features/FEATURE_BLE/ble/pal/PalGattClient.h @@ -601,8 +601,27 @@ public: _transaction_timeout_cb = cb; } + /** + * Sets the event handler that us called by the PAL porters to notify the stack of events + * which will in turn be passed onto the user application when appropriate. + * + * @param event_handler The new event handler interface implementation. + */ + void set_event_handler(EventHandler* event_handler) { + _event_handler = event_handler; + } + + /** + * Get the currently registered event handler. + * + * @return Currently registered event handler. NULL if no event handler is present. + */ + EventHandler* get_event_handler() { + return _event_handler; + } + protected: - GattClient() { } + GattClient() : _event_handler(NULL) { } virtual ~GattClient() { } @@ -640,6 +659,8 @@ protected: } private: + EventHandler* _event_handler; + /** * Callback called when the client receive a message from the server. */ diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h index a8083c3bbe..695114911d 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h @@ -107,6 +107,13 @@ public: */ virtual generic::GenericGattClient &getGattClient(); + /** + * Get the PAL Gatt Client. + * + * @return PAL Gatt Client. + */ + pal::AttClientToGattClientAdapter &BLE::getPalGattClient(); + /** * @see BLEInstanceBase::getSecurityManager */ diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp index 37b6373d43..35eb9122db 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp @@ -26,8 +26,10 @@ void CordioAttClient::att_client_handler(const attEvt_t* event) { if (event->hdr.status == ATT_SUCCESS && event->hdr.event == ATT_MTU_UPDATE_IND) { ble::vendor::cordio::BLE& ble = ble::vendor::cordio::BLE::deviceInstance(); - ble::pal::GattClient::EventHandler &handler = ble.getGattClient(); - handler.on_att_mtu_change(event->hdr.param, event->mtu); + ble::pal::GattClient::EventHandler *handler = ble.getPalGattClient().get_event_handler(); + if (handler) { + handler->on_att_mtu_change(event->hdr.param, event->mtu); + } } else { // all handlers are stored in a static array static const event_handler_t handlers[] = { diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp index 5cffdac74b..de6dd0bd82 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioBLE.cpp @@ -199,13 +199,19 @@ const GattServer& BLE::getGattServer() const } generic::GenericGattClient& BLE::getGattClient() +{ + static generic::GenericGattClient gatt_client(&getPalGattClient()); + + return gatt_client; +} + +pal::AttClientToGattClientAdapter& BLE::getPalGattClient() { static pal::AttClientToGattClientAdapter pal_client( pal::vendor::cordio::CordioAttClient::get_client() ); - static generic::GenericGattClient client(&pal_client); - return client; + return pal_client; } SecurityManager& BLE::getSecurityManager() From de60b2a56a3389febaa27dbebe6fdbb7705d4617 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 5 Feb 2019 12:15:45 +0000 Subject: [PATCH 12/18] remove unused converter --- .../TARGET_CORDIO/CordioPalAttClient.cpp | 1 - .../TARGET_CORDIO/CordioPalAttClient.h | 19 ------------------- 2 files changed, 20 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp index 35eb9122db..c642ce9989 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp @@ -35,7 +35,6 @@ void CordioAttClient::att_client_handler(const attEvt_t* event) static const event_handler_t handlers[] = { &timeout_event_handler, &event_handler, - //&event_handler, &event_handler, &event_handler, &event_handler, diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h index dcda0d1be2..f646302283 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h @@ -400,25 +400,6 @@ private: } }; - /** - * Converter for an AttExchangeMTUResponse. - */ - struct ExchangeMtuResponseConverter { - static bool can_convert(const attEvt_t* event) - { - if(event->hdr.status == ATT_SUCCESS && - event->hdr.event == ATT_MTU_UPDATE_IND) { - return true; - } - return false; - } - - static AttExchangeMTUResponse convert(const attEvt_t* event) - { - return AttExchangeMTUResponse(event->mtu); - } - }; - /** * Converter for a SimpleAttFindInformationResponse. */ From 3808db90b25b174eeb4a234da79288e6f10e9443 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 5 Feb 2019 14:26:16 +0000 Subject: [PATCH 13/18] require pal event handler to be complete --- features/FEATURE_BLE/ble/pal/PalGattClient.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/features/FEATURE_BLE/ble/pal/PalGattClient.h b/features/FEATURE_BLE/ble/pal/PalGattClient.h index da798e4f5f..56d72f2b9f 100644 --- a/features/FEATURE_BLE/ble/pal/PalGattClient.h +++ b/features/FEATURE_BLE/ble/pal/PalGattClient.h @@ -71,9 +71,7 @@ public: virtual void on_att_mtu_change( ble::connection_handle_t connection_handle, uint16_t att_mtu_size - ) - { - } + ) = 0; }; /** From 1cea53b6a7c3874cfe070838a63153f1b29c6903 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 5 Feb 2019 14:35:05 +0000 Subject: [PATCH 14/18] use grandfathered convention for class members names and initialise them --- features/FEATURE_BLE/ble/GattClient.h | 6 +++--- features/FEATURE_BLE/ble/GattServer.h | 5 +++-- .../FEATURE_BLE/ble/generic/GenericGattClient.h | 13 ++++++++++--- .../targets/TARGET_CORDIO/CordioGattServer.h | 2 +- .../TARGET_MCU_NRF51822/source/nRF5xGattServer.h | 2 +- .../TARGET_NRF51/source/nRF5xGattServer.h | 2 +- .../TARGET_NRF52/source/nRF5xGattServer.h | 2 +- 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/features/FEATURE_BLE/ble/GattClient.h b/features/FEATURE_BLE/ble/GattClient.h index 5eff0df04e..828536ffbd 100644 --- a/features/FEATURE_BLE/ble/GattClient.h +++ b/features/FEATURE_BLE/ble/GattClient.h @@ -112,7 +112,7 @@ public: */ void setEventHandler(EventHandler *handler) { - _eventHandler = handler; + eventHandler = handler; } /** @@ -795,7 +795,7 @@ public: } protected: - GattClient() + GattClient() : eventHandler(NULL) { /* Empty */ } @@ -850,7 +850,7 @@ protected: /** * Event handler provided by the application. */ - EventHandler *_eventHandler; + EventHandler *eventHandler; /** * Callchain containing all registered event handlers for data read diff --git a/features/FEATURE_BLE/ble/GattServer.h b/features/FEATURE_BLE/ble/GattServer.h index 8335e7f798..2a1bf417ce 100644 --- a/features/FEATURE_BLE/ble/GattServer.h +++ b/features/FEATURE_BLE/ble/GattServer.h @@ -116,7 +116,7 @@ public: */ void setEventHandler(EventHandler *handler) { - _eventHandler = handler; + eventHandler = handler; } /** @@ -198,6 +198,7 @@ protected: GattServer() : serviceCount(0), characteristicCount(0), + eventHandler(NULL), dataSentCallChain(), dataWrittenCallChain(), dataReadCallChain(), @@ -813,7 +814,7 @@ protected: /** * Event handler provided by the application. */ - EventHandler *_eventHandler; + EventHandler *eventHandler; /** * The total number of services added to the ATT table. diff --git a/features/FEATURE_BLE/ble/generic/GenericGattClient.h b/features/FEATURE_BLE/ble/generic/GenericGattClient.h index eece4dfed4..3759e8f1bd 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGattClient.h +++ b/features/FEATURE_BLE/ble/generic/GenericGattClient.h @@ -37,13 +37,16 @@ class GenericGattClient : public GattClient, public pal::GattClient::EventHandler { public: + /** + * @see pal::GattClient::EventHandler::on_att_mtu_change + */ virtual void on_att_mtu_change( ble::connection_handle_t connection_handle, uint16_t att_mtu_size ) { - if (_eventHandler) { - _eventHandler->onAttMtuChange(connection_handle, att_mtu_size); + if (eventHandler) { + eventHandler->onAttMtuChange(connection_handle, att_mtu_size); } } @@ -140,8 +143,12 @@ public: */ virtual void set_signing_event_handler(pal::SigningEventMonitor::EventHandler *signing_event_handler); + /** + * Return the user registered event handler. + * @return User registered event handler or NULL if none is present. + */ ::GattClient::EventHandler* getEventHandler() { - return _eventHandler; + return eventHandler; } private: diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h index 84dc2dbdf0..4979ce6249 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h @@ -63,7 +63,7 @@ public: static GattServer &getInstance(); ::GattServer::EventHandler* getEventHandler() { - return _eventHandler; + return eventHandler; } /** diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_MCU_NRF51822/source/nRF5xGattServer.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_MCU_NRF51822/source/nRF5xGattServer.h index a115d24775..7cd58b1cf4 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_MCU_NRF51822/source/nRF5xGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_MCU_NRF51822/source/nRF5xGattServer.h @@ -42,7 +42,7 @@ public: void hwCallback(ble_evt_t *p_ble_evt); EventHandler* getEventHandler() { - return _eventHandler; + return eventHandler; } private: diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGattServer.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGattServer.h index baedd6473d..8069c8c5e9 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGattServer.h @@ -42,7 +42,7 @@ public: void hwCallback(const ble_evt_t *p_ble_evt); EventHandler* getEventHandler() { - return _eventHandler; + return eventHandler; } private: diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h index 77d6f91fa5..270a211ac2 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGattServer.h @@ -42,7 +42,7 @@ public: void hwCallback(const ble_evt_t *p_ble_evt); EventHandler* getEventHandler() { - return _eventHandler; + return eventHandler; } private: From f52b20c1699b40a98f6acc69ddb775b4140b9a09 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 5 Feb 2019 17:02:43 +0000 Subject: [PATCH 15/18] move cpp to sources --- .../targets/TARGET_CORDIO/{ => source}/CordioPalAttClient.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename features/FEATURE_BLE/targets/TARGET_CORDIO/{ => source}/CordioPalAttClient.cpp (100%) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalAttClient.cpp similarity index 100% rename from features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.cpp rename to features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalAttClient.cpp From 193092f6d9500b086e9f17eaafdb3e1751fef6e0 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Mon, 11 Feb 2019 09:58:56 +0000 Subject: [PATCH 16/18] added spdx licence ident --- .../targets/TARGET_CORDIO/source/CordioPalAttClient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalAttClient.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalAttClient.cpp index c642ce9989..aa0786dec1 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalAttClient.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioPalAttClient.cpp @@ -1,5 +1,6 @@ /* mbed Microcontroller Library * Copyright (c) 2019 ARM Limited + * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From cdd5c9f3b09ad9a65804b33bef435fc9ee884d5d Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Tue, 12 Feb 2019 10:08:59 +0000 Subject: [PATCH 17/18] fix nrf52 mtu --- .../TARGET_NRF52/source/btle/btle.cpp | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp index 7616973a44..7fc6bba930 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/btle/btle.cpp @@ -400,10 +400,12 @@ void btle_handler(const ble_evt_t *p_ble_evt) p_ble_evt->evt.gatts_evt.params.exchange_mtu_request; nRF5xGattServer &gatt_server = (nRF5xGattServer&) ble.getGattServer(); - gatt_server.getEventHandler()->onAttMtuChange( - connection, - std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.client_rx_mtu)) - ); + if (gatt_server.getEventHandler()) { + gatt_server.getEventHandler()->onAttMtuChange( + connection, + std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.client_rx_mtu)) + ); + } } break; } @@ -415,11 +417,13 @@ void btle_handler(const ble_evt_t *p_ble_evt) const ble_gattc_evt_exchange_mtu_rsp_t &update = p_ble_evt->evt.gattc_evt.params.exchange_mtu_rsp; - nRF5xGattServer &gatt_client = (nRF5xGattClient&) ble.getGattClient(); - gatt_client.getEventHandler()->onAttMtuChange( - connection, - std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.server_rx_mtu)) - ); + nRF5xGattClient &gatt_client = (nRF5xGattClient&) ble.getGattClient(); + if (gatt_client.get_event_handler()) { + gatt_client.get_event_handler()->on_att_mtu_change( + connection, + std::min(NRF_SDH_BLE_GATT_MAX_MTU_SIZE, (int)(update.server_rx_mtu)) + ); + } } break; } From d801ed340e5d275ae4fd502c1ed15de229c8bb26 Mon Sep 17 00:00:00 2001 From: paul-szczepanek-arm <33840200+paul-szczepanek-arm@users.noreply.github.com> Date: Thu, 14 Feb 2019 10:00:42 +0000 Subject: [PATCH 18/18] removed redundant qualifier tripping up GCC --- features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h index 695114911d..57596f121a 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioBLE.h @@ -112,7 +112,7 @@ public: * * @return PAL Gatt Client. */ - pal::AttClientToGattClientAdapter &BLE::getPalGattClient(); + pal::AttClientToGattClientAdapter &getPalGattClient(); /** * @see BLEInstanceBase::getSecurityManager