From e6d3736490946a5c5570dddbfb50763af5c55cb8 Mon Sep 17 00:00:00 2001 From: Marcus Chang Date: Tue, 16 Dec 2014 11:35:29 +0000 Subject: [PATCH] Added optional data and length fields to the return struct for authorized reads so a new value can be provided for each individual authorization. --- nRF51GattServer.cpp | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/nRF51GattServer.cpp b/nRF51GattServer.cpp index e0e696f..5905b08 100644 --- a/nRF51GattServer.cpp +++ b/nRF51GattServer.cpp @@ -333,16 +333,32 @@ void nRF51GattServer::hwCallback(ble_evt_t *p_ble_evt) GattCharacteristicReadAuthCBParams cbParams = { .charHandle = i, .offset = gattsEventP->params.authorize_request.request.read.offset, + .len = 0, + .data = NULL }; + + /* Ask for authorization and, potentially, new data. + Use updated parameters to construct reply. + */ + p_characteristics[i]->authorizeRead(&cbParams); + ble_gatts_rw_authorize_reply_params_t reply = { - .type = BLE_GATTS_AUTHORIZE_TYPE_READ, - .params = { - .read = { - .gatt_status = (p_characteristics[i]->authorizeRead(&cbParams) ? - BLE_GATT_STATUS_SUCCESS : BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED) - } - } + .type = BLE_GATTS_AUTHORIZE_TYPE_READ }; + + if (cbParams.authorizationReply == true) { + reply.params.read.gatt_status = BLE_GATT_STATUS_SUCCESS; + + if (cbParams.data != NULL) { + reply.params.read.update = 1; + reply.params.read.offset = cbParams.offset; + reply.params.read.len = cbParams.len; + reply.params.read.p_data = cbParams.data; + } + } else { + reply.params.read.gatt_status = BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED; + } + sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply); break; }