check authorisation before writing

pull/13449/head
Paul Szczeanek 2020-08-19 10:41:21 +01:00
parent 019a32c75b
commit 8c5bbe05fe
1 changed files with 17 additions and 17 deletions

View File

@ -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,