From 8c5bbe05fefff7caea85ec613e6bccbd3553c4b5 Mon Sep 17 00:00:00 2001 From: Paul Szczeanek Date: Wed, 19 Aug 2020 10:41:21 +0100 Subject: [PATCH] check authorisation before writing --- .../source/GattServerImpl.cpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/connectivity/FEATURE_BLE/libraries/ble-api-implementation/source/GattServerImpl.cpp b/connectivity/FEATURE_BLE/libraries/ble-api-implementation/source/GattServerImpl.cpp index a661c7e6f0..cc902aeafc 100644 --- a/connectivity/FEATURE_BLE/libraries/ble-api-implementation/source/GattServerImpl.cpp +++ b/connectivity/FEATURE_BLE/libraries/ble-api-implementation/source/GattServerImpl.cpp @@ -991,6 +991,23 @@ uint8_t GattServer::atts_write_cb( { uint8_t err; + GattCharacteristic* auth_char = getInstance().get_auth_char(handle); + if (auth_char && auth_char->isWriteAuthorizationEnabled()) { + GattWriteAuthCallbackParams write_auth_params = { + connId, + handle, + offset, + len, + pValue, + AUTH_CALLBACK_REPLY_SUCCESS + }; + + GattAuthCallbackReply_t ret = auth_char->authorizeWrite(&write_auth_params); + if (ret!= AUTH_CALLBACK_REPLY_SUCCESS) { + return ret & 0xFF; + } + } + /* we don't write anything during the prepare phase */ bool write_happened = (operation != ATT_PDU_PREP_WRITE_REQ); @@ -1039,23 +1056,6 @@ uint8_t GattServer::atts_write_cb( break; } - GattCharacteristic* auth_char = getInstance().get_auth_char(handle); - if (auth_char && auth_char->isWriteAuthorizationEnabled()) { - GattWriteAuthCallbackParams write_auth_params = { - connId, - handle, - offset, - len, - pValue, - AUTH_CALLBACK_REPLY_SUCCESS - }; - - GattAuthCallbackReply_t ret = auth_char->authorizeWrite(&write_auth_params); - if (ret!= AUTH_CALLBACK_REPLY_SUCCESS) { - return ret & 0xFF; - } - } - if (write_happened) { GattWriteCallbackParams write_params = { connId,