@@ -161,6 +161,10 @@ static uint8_t convert_sd_att_error_code(uint16_t err)
161
161
}
162
162
}
163
163
164
+ static const size_t long_uuid_length = 16 ;
165
+ static const size_t read_by_group_type_long_uuid_index = 4 ;
166
+ static const size_t characteristic_declaration_length = 1 + 2 + 16 ;
167
+
164
168
} // end of anonymous namespace
165
169
166
170
nRF5XGattClient::nRF5XGattClient () :
@@ -354,7 +358,7 @@ ble_error_t nRF5XGattClient::execute_write_queue(
354
358
* The concept of procedures for Gatt operations formalize the process. A
355
359
* procedure lifecycle is defined by three function:
356
360
* - start: Launch of the procedure. It initiate the first request to send to
357
- * the peer. It must be implemented by Procedure childs .
361
+ * the peer. It must be implemented by Procedure derived classes .
358
362
* - handle: Event handler that process ble events comming from the softdevice.
359
363
* This function drive the procedure flow and must be implemented by
360
364
* Procedure childs.
@@ -415,7 +419,7 @@ struct nRF5XGattClient::GattProcedure {
415
419
/* *
416
420
* A regular procedure is a procedure that follows Gatt specification.
417
421
*
418
- * It initiate a single request to the peer and except a single response. This
422
+ * It initiate a single request to the peer and excepts a single response. This
419
423
* kind of procedure doesn't requires extra processing step.
420
424
*
421
425
* Given that such procedure expect a single event type from the soft device,
@@ -648,11 +652,13 @@ struct nRF5XGattClient::DiscoverPrimaryServiceProcedure : GattProcedure {
648
652
649
653
uint16_t expected_handle = bytes_to_u16 (&response[idx][0 ]);
650
654
651
- if (rsp.handle != expected_handle || rsp.offset != 0 || rsp.len != 16 ) {
655
+ if (rsp.handle != expected_handle || rsp.offset != 0 ||
656
+ rsp.len != long_uuid_length) {
652
657
abort ();
658
+ return ;
653
659
}
654
660
655
- memcpy (&response[idx][4 ], rsp.data , rsp.len );
661
+ memcpy (&response[idx][read_by_group_type_long_uuid_index ], rsp.data , rsp.len );
656
662
657
663
++idx;
658
664
@@ -801,6 +807,7 @@ struct nRF5XGattClient::FindIncludedServicesProcedure : RegularGattProcedure {
801
807
uint8_t * buffer = new (std::nothrow) uint8_t [buffer_size];
802
808
if (!buffer) {
803
809
abort ();
810
+ return ;
804
811
}
805
812
806
813
uint8_t *it = buffer;
@@ -898,6 +905,7 @@ struct nRF5XGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
898
905
_response = flatten_response (evt.params .char_disc_rsp );
899
906
if (!_response.buffer ) {
900
907
abort ();
908
+ return ;
901
909
}
902
910
903
911
// If element size is equal to 7 then the characteristic discovered
@@ -940,6 +948,7 @@ struct nRF5XGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
940
948
// should never happen
941
949
if (!_response.buffer ) {
942
950
abort ();
951
+ return ;
943
952
}
944
953
945
954
if (evt.gatt_status != BLE_GATT_STATUS_SUCCESS) {
@@ -954,8 +963,10 @@ struct nRF5XGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
954
963
uint8_t * current_element = &_response.buffer [_idx * _response.element_size ];
955
964
uint16_t expected_handle = bytes_to_u16 (current_element);
956
965
957
- if (rsp.handle != expected_handle || rsp.offset != 0 || rsp.len != (1 + 2 + 16 )) {
966
+ if (rsp.handle != expected_handle || rsp.offset != 0 ||
967
+ rsp.len != characteristic_declaration_length) {
958
968
abort ();
969
+ return ;
959
970
}
960
971
961
972
// note: elements are the pair characteristic declaration handle followed
@@ -1128,6 +1139,7 @@ struct nRF5XGattClient::ReadAttributeProcedure : RegularGattProcedure {
1128
1139
const ble_gattc_evt_read_rsp_t & rsp = evt.params .read_rsp ;
1129
1140
if (rsp.offset != 0 ) {
1130
1141
abort ();
1142
+ return ;
1131
1143
}
1132
1144
1133
1145
terminate (AttReadResponse (make_const_ArrayView (rsp.data , rsp.len )));
@@ -1606,7 +1618,7 @@ void nRF5XGattClient::handle_connection_termination(connection_handle_t connecti
1606
1618
}
1607
1619
}
1608
1620
1609
- } // cordio
1621
+ } // nordic
1610
1622
} // vendor
1611
1623
} // pal
1612
1624
} // ble
0 commit comments