Skip to content

Commit bea0196

Browse files
apps/bttester: Fix BTP event data truncation in GATT Read Long response
Fixes an issue where large GATT Read Long response (e.g. 512 bytes) was truncated in tester_event causing the GATT/CL/GAR/BV-04-C qualification test case to fail. This was caused by passing buf->om_data and buf->om_len to tester_event. The data exceeding single memory chain buffer was left ignored in next mbuf in the list (buf->om_next).
1 parent 793cb16 commit bea0196

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

apps/bttester/src/btp_gatt_cl.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -871,11 +871,11 @@ read_long_cb(uint16_t conn_handle,
871871
struct ble_gatt_attr *attr,
872872
void *arg)
873873
{
874-
struct btp_gattc_read_rp *rp;
874+
struct btp_gattc_read_rp *rp = NULL;
875875
uint8_t opcode = (uint8_t) (int) arg;
876-
uint8_t err = (uint8_t) error->status;
877-
struct os_mbuf *buf = os_msys_get(0, 0);
876+
uint8_t err = (uint8_t)error->status;
878877
struct ble_gap_conn_desc conn;
878+
uint16_t len;
879879
int rc = 0;
880880

881881
SYS_LOG_DBG("status=%d", error->status);
@@ -885,7 +885,8 @@ read_long_cb(uint16_t conn_handle,
885885
goto free;
886886
}
887887

888-
rp = os_mbuf_extend(buf, sizeof(*rp));
888+
len = sizeof(*rp) + (error->status == BLE_HS_EDONE ? gatt_buf.len : 0);
889+
rp = malloc(len);
889890
if (!rp) {
890891
rc = BLE_HS_ENOMEM;
891892
goto free;
@@ -897,18 +898,18 @@ read_long_cb(uint16_t conn_handle,
897898

898899
if (error->status != 0 && error->status != BLE_HS_EDONE) {
899900
rp->data_length = 0;
900-
tester_event(BTP_SERVICE_ID_GATTC, opcode,
901-
buf->om_data, buf->om_len);
901+
tester_event(BTP_SERVICE_ID_GATTC, opcode, rp, sizeof(*rp));
902902
read_destroy();
903903
goto free;
904904
}
905905

906906
if (error->status == BLE_HS_EDONE) {
907907
rp->status = 0;
908908
rp->data_length = gatt_buf.len;
909-
os_mbuf_append(buf, gatt_buf.buf, gatt_buf.len);
910-
tester_event(BTP_SERVICE_ID_GATTC, opcode,
911-
buf->om_data, buf->om_len);
909+
if (gatt_buf.len > 0) {
910+
memcpy(rp->data, gatt_buf.buf, gatt_buf.len);
911+
}
912+
tester_event(BTP_SERVICE_ID_GATTC, opcode, rp, len);
912913
read_destroy();
913914
goto free;
914915
}
@@ -922,7 +923,7 @@ read_long_cb(uint16_t conn_handle,
922923
rp->data_length += attr->om->om_len;
923924

924925
free:
925-
os_mbuf_free_chain(buf);
926+
free(rp);
926927
return rc;
927928
}
928929

0 commit comments

Comments
 (0)