Skip to content

Commit 9d81960

Browse files
paul-szczepanek-armadbridge
authored andcommitted
fix using an invalid cccd index
1 parent b858482 commit 9d81960

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ class GattServer : public ::GattServer,
222222
void add_generic_attribute_service();
223223
void* alloc_block(size_t block_size);
224224
GattCharacteristic* get_auth_char(uint16_t value_handle);
225-
bool get_cccd_id(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const;
226-
bool has_cccd(GattAttribute::Handle_t char_handle) const;
225+
bool get_cccd_index_by_cccd_handle(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const;
226+
bool get_cccd_index_by_value_handle(GattAttribute::Handle_t char_handle, uint8_t& idx) const;
227227
bool is_update_authorized(Gap::Handle_t connection, GattAttribute::Handle_t value_handle);
228228

229229
struct alloc_block_t {

features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ ble_error_t GattServer::read(
560560
) {
561561
// Check to see if this is a CCCD
562562
uint8_t cccd_index;
563-
if (get_cccd_id(att_handle, cccd_index)) {
563+
if (get_cccd_index_by_cccd_handle(att_handle, cccd_index)) {
564564
if (connection == DM_CONN_ID_NONE) {
565565
return BLE_ERROR_PARAM_OUT_OF_RANGE;
566566
}
@@ -588,7 +588,7 @@ ble_error_t GattServer::write(
588588
// Check to see if this is a CCCD, if it is the case update the value for all
589589
// connections
590590
uint8_t cccd_index;
591-
if (get_cccd_id(att_handle, cccd_index)) {
591+
if (get_cccd_index_by_cccd_handle(att_handle, cccd_index)) {
592592
if (len != sizeof(uint16_t)) {
593593
return BLE_ERROR_INVALID_PARAM;
594594
}
@@ -615,7 +615,7 @@ ble_error_t GattServer::write(
615615
}
616616

617617
// return if the update does not have to be propagated to peers
618-
if (local_only || !has_cccd(att_handle)) {
618+
if (local_only || !get_cccd_index_by_value_handle(att_handle, cccd_index)) {
619619
return BLE_ERROR_NONE;
620620
}
621621

@@ -660,7 +660,7 @@ ble_error_t GattServer::write(
660660
) {
661661
// Check to see if this is a CCCD
662662
uint8_t cccd_index;
663-
if (get_cccd_id(att_handle, cccd_index)) {
663+
if (get_cccd_index_by_cccd_handle(att_handle, cccd_index)) {
664664
if ((connection == DM_CONN_ID_NONE) || (len != 2)) { // CCCDs are always 16 bits
665665
return BLE_ERROR_PARAM_OUT_OF_RANGE;
666666
}
@@ -677,7 +677,7 @@ ble_error_t GattServer::write(
677677
}
678678

679679
// return if the update does not have to be propagated to peers
680-
if (local_only || !has_cccd(att_handle)) {
680+
if (local_only || !get_cccd_index_by_value_handle(att_handle, cccd_index)) {
681681
return BLE_ERROR_NONE;
682682
}
683683

@@ -1211,7 +1211,7 @@ GattCharacteristic* GattServer::get_auth_char(uint16_t value_handle)
12111211
return NULL;
12121212
}
12131213

1214-
bool GattServer::get_cccd_id(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const
1214+
bool GattServer::get_cccd_index_by_cccd_handle(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const
12151215
{
12161216
for (idx = 0; idx < cccd_cnt; idx++) {
12171217
if (cccd_handle == cccds[idx].handle) {
@@ -1221,10 +1221,10 @@ bool GattServer::get_cccd_id(GattAttribute::Handle_t cccd_handle, uint8_t& idx)
12211221
return false;
12221222
}
12231223

1224-
bool GattServer::has_cccd(GattAttribute::Handle_t char_handle) const
1224+
bool GattServer::get_cccd_index_by_value_handle(GattAttribute::Handle_t char_handle, uint8_t& idx) const
12251225
{
1226-
for (uint8_t cccd_index = 0; cccd_index < cccd_cnt; ++cccd_index) {
1227-
if (char_handle == cccd_handles[cccd_index]) {
1226+
for (idx = 0; idx < cccd_cnt; ++idx) {
1227+
if (char_handle == cccd_handles[idx]) {
12281228
return true;
12291229
}
12301230
}

0 commit comments

Comments
 (0)