Skip to content

Commit ce11081

Browse files
authored
Merge pull request #8884 from pan-/fix-cordio-connection-iteration
BLE: Fix iteration on connections in CordioGattServer.
2 parents 3e90bb8 + 0c21112 commit ce11081

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -596,14 +596,10 @@ ble_error_t GattServer::write(
596596
uint16_t cccd_value;
597597
memcpy(&cccd_value, buffer, sizeof(cccd_value));
598598

599-
uint16_t conn_id = 0;
600-
uint16_t conn_found = 0;
601-
while ((conn_found < DM_CONN_MAX) && (conn_id < CONNECTION_ID_LIMIT)) {
599+
for (dmConnId_t conn_id = DM_CONN_MAX; conn_id > DM_CONN_ID_NONE; --conn_id) {
602600
if (DmConnInUse(conn_id) == true) {
603-
++conn_found;
604601
AttsCccSet(conn_id, cccd_index, cccd_value);
605602
}
606-
++conn_id;
607603
}
608604

609605
return BLE_ERROR_NONE;
@@ -622,13 +618,10 @@ ble_error_t GattServer::write(
622618
// This characteristic has a CCCD attribute. Handle notifications and
623619
// indications for all active connections if the authentication is
624620
// successful
625-
uint16_t conn_id = 0;
626-
uint16_t conn_found = 0;
627621
size_t updates_sent = 0;
628622

629-
while((conn_found < DM_CONN_MAX) && (conn_id < CONNECTION_ID_LIMIT)) {
623+
for (dmConnId_t conn_id = DM_CONN_MAX; conn_id > DM_CONN_ID_NONE; --conn_id) {
630624
if (DmConnInUse(conn_id) == true) {
631-
++conn_found;
632625
if (is_update_authorized(conn_id, att_handle)) {
633626
uint16_t cccd_config = AttsCccEnabled(conn_id, cccd_index);
634627
if (cccd_config & ATT_CLIENT_CFG_NOTIFY) {
@@ -641,7 +634,6 @@ ble_error_t GattServer::write(
641634
}
642635
}
643636
}
644-
++conn_id;
645637
}
646638

647639
if (updates_sent) {
@@ -709,20 +701,15 @@ ble_error_t GattServer::areUpdatesEnabled(
709701
) {
710702
for (size_t idx = 0; idx < cccd_cnt; idx++) {
711703
if (characteristic.getValueHandle() == cccd_handles[idx]) {
712-
uint16_t conn_id = 0;
713-
uint16_t conn_found = 0;
714-
715-
while ((conn_found < DM_CONN_MAX) && (conn_id < CONNECTION_ID_LIMIT)) {
704+
for (dmConnId_t conn_id = DM_CONN_MAX; conn_id > DM_CONN_ID_NONE; --conn_id) {
716705
if (DmConnInUse(conn_id) == true) {
717-
++conn_found;
718706
uint16_t cccd_value = AttsCccGet(conn_id, idx);
719707
if (cccd_value & (ATT_CLIENT_CFG_NOTIFY | ATT_CLIENT_CFG_INDICATE)) {
720708
*enabled = true;
721709
return BLE_ERROR_NONE;
722710
}
723711

724712
}
725-
++conn_id;
726713
}
727714
*enabled = false;
728715
return BLE_ERROR_NONE;

0 commit comments

Comments
 (0)