Added optional data and length fields to the return struct for authorized reads so a new value can be provided for each individual authorization.
This commit is contained in:
parent
6151c498de
commit
e6d3736490
1 changed files with 23 additions and 7 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue