Skip to content

Commit 8c5bbe0

Browse files
check authorisation before writing
1 parent 019a32c commit 8c5bbe0

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

connectivity/FEATURE_BLE/libraries/ble-api-implementation/source/GattServerImpl.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,23 @@ uint8_t GattServer::atts_write_cb(
991991
{
992992
uint8_t err;
993993

994+
GattCharacteristic* auth_char = getInstance().get_auth_char(handle);
995+
if (auth_char && auth_char->isWriteAuthorizationEnabled()) {
996+
GattWriteAuthCallbackParams write_auth_params = {
997+
connId,
998+
handle,
999+
offset,
1000+
len,
1001+
pValue,
1002+
AUTH_CALLBACK_REPLY_SUCCESS
1003+
};
1004+
1005+
GattAuthCallbackReply_t ret = auth_char->authorizeWrite(&write_auth_params);
1006+
if (ret!= AUTH_CALLBACK_REPLY_SUCCESS) {
1007+
return ret & 0xFF;
1008+
}
1009+
}
1010+
9941011
/* we don't write anything during the prepare phase */
9951012
bool write_happened = (operation != ATT_PDU_PREP_WRITE_REQ);
9961013

@@ -1039,23 +1056,6 @@ uint8_t GattServer::atts_write_cb(
10391056
break;
10401057
}
10411058

1042-
GattCharacteristic* auth_char = getInstance().get_auth_char(handle);
1043-
if (auth_char && auth_char->isWriteAuthorizationEnabled()) {
1044-
GattWriteAuthCallbackParams write_auth_params = {
1045-
connId,
1046-
handle,
1047-
offset,
1048-
len,
1049-
pValue,
1050-
AUTH_CALLBACK_REPLY_SUCCESS
1051-
};
1052-
1053-
GattAuthCallbackReply_t ret = auth_char->authorizeWrite(&write_auth_params);
1054-
if (ret!= AUTH_CALLBACK_REPLY_SUCCESS) {
1055-
return ret & 0xFF;
1056-
}
1057-
}
1058-
10591059
if (write_happened) {
10601060
GattWriteCallbackParams write_params = {
10611061
connId,

0 commit comments

Comments
 (0)