Skip to content

Commit 6aa89ae

Browse files
calculate chunk size when needed and use reported packet length
1 parent 8c5bbe0 commit 6aa89ae

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

connectivity/FEATURE_BLE/libraries/ble-api-implementation/source/GattClientImpl.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,9 @@ struct GattClient::WriteControlBlock : public ProcedureControlBlock {
640640
connection_handle_t connection_handle,
641641
uint16_t attribute_handle,
642642
uint8_t* data,
643-
uint16_t write_length,
644-
uint16_t chunk_size
643+
uint16_t write_length
645644
) : ProcedureControlBlock(WRITE_PROCEDURE, connection_handle),
646-
attribute_handle(attribute_handle), write_length(write_length), chunk_size(chunk_size), offset(0), data(data),
645+
attribute_handle(attribute_handle), write_length(write_length), offset(0), data(data),
647646
prepare_success(false), status(BLE_ERROR_INITIALIZATION_INCOMPLETE), error_code(0xFF) {
648647
}
649648

@@ -725,10 +724,10 @@ struct GattClient::WriteControlBlock : public ProcedureControlBlock {
725724

726725
void handle_prepare_write_response(GattClient* client, const AttPrepareWriteResponse& write_response) {
727726
ble_error_t err = BLE_ERROR_UNSPECIFIED;
728-
uint16_t mtu_size = client->get_mtu(connection_handle);
729-
offset += chunk_size;
727+
offset += write_response.partial_value.size();
730728
uint16_t data_left = write_length - offset; /* offset is guaranteed to be less of equal to write_length */
731729
if (data_left) {
730+
uint16_t chunk_size = client->get_mtu(connection_handle) - PREPARE_WRITE_HEADER_LENGTH;
732731
if (chunk_size > data_left) {
733732
chunk_size = data_left;
734733
}
@@ -836,7 +835,6 @@ struct GattClient::WriteControlBlock : public ProcedureControlBlock {
836835
uint16_t attribute_handle;
837836
uint16_t write_length;
838837
uint16_t offset;
839-
uint16_t chunk_size;
840838
uint8_t* data;
841839
bool prepare_success;
842840
ble_error_t status;
@@ -1190,8 +1188,7 @@ ble_error_t GattClient::write(
11901188
connection_handle,
11911189
attribute_handle,
11921190
data,
1193-
length,
1194-
mtu - PREPARE_WRITE_HEADER_LENGTH
1191+
length
11951192
);
11961193

11971194
if (write_pcb == nullptr) {

0 commit comments

Comments
 (0)