@@ -416,11 +416,34 @@ ble_error_t GattServer::insert_characteristic_value_attribute(
416
416
characteristic->isReadAuthorizationEnabled () ||
417
417
characteristic->isWriteAuthorizationEnabled ()
418
418
) {
419
- if (_auth_char_count >= MBED_CONF_BLE_API_IMPLEMENTATION_MAX_CHARACTERISTIC_AUTHORISATION_COUNT) {
419
+ if (_auth_callbacks_count >= MBED_CONF_BLE_API_IMPLEMENTATION_MAX_CHARACTERISTIC_AUTHORISATION_COUNT) {
420
420
return BLE_ERROR_NO_MEM;
421
421
}
422
- _auth_char[_auth_char_count] = characteristic;
423
- ++_auth_char_count;
422
+
423
+ char_auth_callback *new_cb = (char_auth_callback *) alloc_block (sizeof (char_auth_callback));
424
+
425
+ if (!new_cb) {
426
+ return BLE_ERROR_NO_MEM;
427
+ }
428
+
429
+ new_cb->read_cb = characteristic->readAuthorizationCallback ;
430
+ new_cb->write_cb = characteristic->writeAuthorizationCallback ;
431
+ new_cb->handle = characteristic->getValueHandle ();
432
+ new_cb->update_security = characteristic->getUpdateSecurityRequirement ();
433
+ new_cb->_next = nullptr ;
434
+
435
+ /* add it to the list */
436
+ if (_auth_callbacks) {
437
+ char_auth_callback *last_cb = _auth_callbacks;
438
+ while (last_cb->_next ) {
439
+ last_cb = last_cb->_next ;
440
+ }
441
+ last_cb->_next = new_cb;
442
+ } else {
443
+ _auth_callbacks = new_cb;
444
+ };
445
+
446
+ ++_auth_callbacks_count;
424
447
}
425
448
426
449
++attribute_it;
@@ -941,7 +964,8 @@ ble_error_t GattServer::reset(ble::GattServer* server)
941
964
currentHandle = 0 ;
942
965
cccd_cnt = 0 ;
943
966
944
- _auth_char_count = 0 ;
967
+ _auth_callbacks_count = 0 ;
968
+ _auth_callbacks = nullptr ;
945
969
946
970
AttsCccRegister (cccd_cnt, (attsCccSet_t *) cccds, cccd_cb);
947
971
@@ -978,8 +1002,8 @@ uint8_t GattServer::atts_read_cb(
978
1002
attsAttr_t *pAttr
979
1003
)
980
1004
{
981
- GattCharacteristic *auth_char = getInstance ().get_auth_char (handle);
982
- if (auth_char && auth_char-> isReadAuthorizationEnabled () ) {
1005
+ char_auth_callback *auth_cb = getInstance ().get_auth_callback (handle);
1006
+ if (auth_cb && auth_cb-> read_cb ) {
983
1007
GattReadAuthCallbackParams read_auth_params = {
984
1008
connId,
985
1009
handle,
@@ -989,9 +1013,10 @@ uint8_t GattServer::atts_read_cb(
989
1013
AUTH_CALLBACK_REPLY_SUCCESS
990
1014
};
991
1015
992
- GattAuthCallbackReply_t ret = auth_char->authorizeRead (&read_auth_params);
993
- if (ret != AUTH_CALLBACK_REPLY_SUCCESS) {
994
- return ret & 0xFF ;
1016
+ auth_cb->read_cb .call (&read_auth_params);
1017
+
1018
+ if (read_auth_params.authorizationReply != AUTH_CALLBACK_REPLY_SUCCESS) {
1019
+ return read_auth_params.authorizationReply & 0xFF ;
995
1020
}
996
1021
997
1022
pAttr->pValue = read_auth_params.data ;
@@ -1021,8 +1046,8 @@ uint8_t GattServer::atts_write_cb(
1021
1046
attsAttr_t *pAttr
1022
1047
)
1023
1048
{
1024
- GattCharacteristic* auth_char = getInstance ().get_auth_char (handle);
1025
- if (auth_char && auth_char-> isWriteAuthorizationEnabled () ) {
1049
+ char_auth_callback* auth_cb = getInstance ().get_auth_callback (handle);
1050
+ if (auth_cb && auth_cb-> write_cb ) {
1026
1051
GattWriteAuthCallbackParams write_auth_params = {
1027
1052
connId,
1028
1053
handle,
@@ -1032,9 +1057,10 @@ uint8_t GattServer::atts_write_cb(
1032
1057
AUTH_CALLBACK_REPLY_SUCCESS
1033
1058
};
1034
1059
1035
- GattAuthCallbackReply_t ret = auth_char->authorizeWrite (&write_auth_params);
1036
- if (ret!= AUTH_CALLBACK_REPLY_SUCCESS) {
1037
- return ret & 0xFF ;
1060
+ auth_cb->write_cb .call (&write_auth_params);
1061
+
1062
+ if (write_auth_params.authorizationReply != AUTH_CALLBACK_REPLY_SUCCESS) {
1063
+ return write_auth_params.authorizationReply & 0xFF ;
1038
1064
}
1039
1065
}
1040
1066
@@ -1329,14 +1355,16 @@ void *GattServer::alloc_block(size_t block_size)
1329
1355
return block->data ;
1330
1356
}
1331
1357
1332
- GattCharacteristic *GattServer::get_auth_char (uint16_t value_handle)
1358
+ GattServer::char_auth_callback *GattServer::get_auth_callback (uint16_t value_handle)
1333
1359
{
1334
- for (size_t i = 0 ; i < _auth_char_count; ++i) {
1335
- if (_auth_char[i]->getValueHandle () == value_handle) {
1336
- return _auth_char[i];
1360
+ GattServer::char_auth_callback* current = _auth_callbacks;
1361
+ while (current) {
1362
+ if (current->handle == value_handle) {
1363
+ break ;
1337
1364
}
1365
+ current = current->_next ;
1338
1366
}
1339
- return nullptr ;
1367
+ return current ;
1340
1368
}
1341
1369
1342
1370
bool GattServer::get_cccd_index_by_cccd_handle (GattAttribute::Handle_t cccd_handle, uint8_t &idx) const
@@ -1364,13 +1392,12 @@ bool GattServer::is_update_authorized(
1364
1392
GattAttribute::Handle_t value_handle
1365
1393
)
1366
1394
{
1367
- GattCharacteristic *auth_char = get_auth_char (value_handle);
1368
- if (!auth_char ) {
1395
+ char_auth_callback *auth_cb = get_auth_callback (value_handle);
1396
+ if (!auth_cb ) {
1369
1397
return true ;
1370
1398
}
1371
1399
1372
- att_security_requirement_t sec_req =
1373
- auth_char->getUpdateSecurityRequirement ();
1400
+ const att_security_requirement_t sec_req = auth_cb->update_security ;
1374
1401
1375
1402
if (sec_req == att_security_requirement_t ::NONE) {
1376
1403
return true ;
@@ -1426,8 +1453,8 @@ GattServer::GattServer() :
1426
1453
cccd_values (),
1427
1454
cccd_handles (),
1428
1455
cccd_cnt (0 ),
1429
- _auth_char ( ),
1430
- _auth_char_count (0 ),
1456
+ _auth_callbacks ( nullptr ),
1457
+ _auth_callbacks_count (0 ),
1431
1458
generic_access_service (),
1432
1459
generic_attribute_service (),
1433
1460
registered_service (nullptr ),
0 commit comments