Skip to content

Commit 33cbff4

Browse files
pan-adbridge
authored andcommitted
BLE: Address GattClient comments
* invalid namespace name documentation * vocabulary * typo * Add constants to improve readability * Fix abort usages
1 parent b6d4004 commit 33cbff4

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5XPalGattClient.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ static uint8_t convert_sd_att_error_code(uint16_t err)
161161
}
162162
}
163163

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+
164168
} // end of anonymous namespace
165169

166170
nRF5XGattClient::nRF5XGattClient() :
@@ -354,7 +358,7 @@ ble_error_t nRF5XGattClient::execute_write_queue(
354358
* The concept of procedures for Gatt operations formalize the process. A
355359
* procedure lifecycle is defined by three function:
356360
* - 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.
358362
* - handle: Event handler that process ble events comming from the softdevice.
359363
* This function drive the procedure flow and must be implemented by
360364
* Procedure childs.
@@ -415,7 +419,7 @@ struct nRF5XGattClient::GattProcedure {
415419
/**
416420
* A regular procedure is a procedure that follows Gatt specification.
417421
*
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
419423
* kind of procedure doesn't requires extra processing step.
420424
*
421425
* Given that such procedure expect a single event type from the soft device,
@@ -648,11 +652,13 @@ struct nRF5XGattClient::DiscoverPrimaryServiceProcedure : GattProcedure {
648652

649653
uint16_t expected_handle = bytes_to_u16(&response[idx][0]);
650654

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) {
652657
abort();
658+
return;
653659
}
654660

655-
memcpy(&response[idx][4], rsp.data, rsp.len);
661+
memcpy(&response[idx][read_by_group_type_long_uuid_index], rsp.data, rsp.len);
656662

657663
++idx;
658664

@@ -801,6 +807,7 @@ struct nRF5XGattClient::FindIncludedServicesProcedure : RegularGattProcedure {
801807
uint8_t* buffer = new(std::nothrow) uint8_t[buffer_size];
802808
if (!buffer) {
803809
abort();
810+
return;
804811
}
805812

806813
uint8_t *it = buffer;
@@ -898,6 +905,7 @@ struct nRF5XGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
898905
_response = flatten_response(evt.params.char_disc_rsp);
899906
if (!_response.buffer) {
900907
abort();
908+
return;
901909
}
902910

903911
// If element size is equal to 7 then the characteristic discovered
@@ -940,6 +948,7 @@ struct nRF5XGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
940948
// should never happen
941949
if (!_response.buffer) {
942950
abort();
951+
return;
943952
}
944953

945954
if (evt.gatt_status != BLE_GATT_STATUS_SUCCESS) {
@@ -954,8 +963,10 @@ struct nRF5XGattClient::DiscoverCharacteristicsProcedure : GattProcedure {
954963
uint8_t* current_element = &_response.buffer[_idx * _response.element_size];
955964
uint16_t expected_handle = bytes_to_u16(current_element);
956965

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) {
958968
abort();
969+
return;
959970
}
960971

961972
// note: elements are the pair characteristic declaration handle followed
@@ -1128,6 +1139,7 @@ struct nRF5XGattClient::ReadAttributeProcedure : RegularGattProcedure {
11281139
const ble_gattc_evt_read_rsp_t& rsp = evt.params.read_rsp;
11291140
if (rsp.offset != 0 ) {
11301141
abort();
1142+
return;
11311143
}
11321144

11331145
terminate(AttReadResponse(make_const_ArrayView(rsp.data, rsp.len)));
@@ -1606,7 +1618,7 @@ void nRF5XGattClient::handle_connection_termination(connection_handle_t connecti
16061618
}
16071619
}
16081620

1609-
} // cordio
1621+
} // nordic
16101622
} // vendor
16111623
} // pal
16121624
} // ble

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5XPalGattClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class nRF5XGattClient : public ble::pal::GattClient {
249249
GattProcedure* _procedures[max_procedures_count];
250250
};
251251

252-
} // cordio
252+
} // nordic
253253
} // vendor
254254
} // pal
255255
} // ble

0 commit comments

Comments
 (0)