From 54cd46ac6848778c407d80b7b2b8c29efd4edb88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Narajowski?= Date: Tue, 5 Apr 2022 11:35:36 +0200 Subject: [PATCH] tests/bluetooth/tester: Refactor Read UUID callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ATT_READ_BY_TYPE_RSP returns Attribute Data List so handle it in the application. This affects GATT/CL/GAR/BV-03-C. Signed-off-by: MichaƂ Narajowski --- tests/bluetooth/tester/src/bttester.h | 10 ++++-- tests/bluetooth/tester/src/gatt.c | 49 +++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/tests/bluetooth/tester/src/bttester.h b/tests/bluetooth/tester/src/bttester.h index 626eb3a28ba..d49b664f762 100644 --- a/tests/bluetooth/tester/src/bttester.h +++ b/tests/bluetooth/tester/src/bttester.h @@ -575,6 +575,12 @@ struct gatt_read_rp { uint8_t data[]; } __packed; +struct gatt_char_value { + uint16_t handle; + uint8_t data_len; + uint8_t data[0]; +} __packed; + #define GATT_READ_UUID 0x12 struct gatt_read_uuid_cmd { uint8_t address_type; @@ -586,8 +592,8 @@ struct gatt_read_uuid_cmd { } __packed; struct gatt_read_uuid_rp { uint8_t att_response; - uint16_t data_length; - uint8_t data[]; + uint8_t values_count; + struct gatt_char_value values[0]; } __packed; #define GATT_READ_LONG 0x13 diff --git a/tests/bluetooth/tester/src/gatt.c b/tests/bluetooth/tester/src/gatt.c index deacd02d0e5..237250de9a3 100644 --- a/tests/bluetooth/tester/src/gatt.c +++ b/tests/bluetooth/tester/src/gatt.c @@ -1396,6 +1396,51 @@ static uint8_t read_cb(struct bt_conn *conn, uint8_t err, return BT_GATT_ITER_CONTINUE; } +static uint8_t read_uuid_cb(struct bt_conn *conn, uint8_t err, + struct bt_gatt_read_params *params, const void *data, + uint16_t length) +{ + struct gatt_read_uuid_rp *rp = (void *)gatt_buf.buf; + struct gatt_char_value value; + + /* Respond to the Lower Tester with ATT Error received */ + if (err) { + rp->att_response = err; + } + + /* read complete */ + if (!data) { + tester_send(BTP_SERVICE_ID_GATT, btp_opcode, CONTROLLER_INDEX, + gatt_buf.buf, gatt_buf.len); + read_destroy(params); + + return BT_GATT_ITER_STOP; + } + + value.handle = params->by_uuid.start_handle; + value.data_len = length; + + if (!gatt_buf_add(&value, sizeof(struct gatt_char_value))) { + tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, + CONTROLLER_INDEX, BTP_STATUS_FAILED); + read_destroy(params); + + return BT_GATT_ITER_STOP; + } + + if (!gatt_buf_add(data, length)) { + tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode, + CONTROLLER_INDEX, BTP_STATUS_FAILED); + read_destroy(params); + + return BT_GATT_ITER_STOP; + } + + rp->values_count++; + + return BT_GATT_ITER_CONTINUE; +} + static void read_data(uint8_t *data, uint16_t len) { const struct gatt_read_cmd *cmd = (void *) data; @@ -1449,7 +1494,7 @@ static void read_uuid(uint8_t *data, uint16_t len) goto fail; } - if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) { + if (!gatt_buf_reserve(sizeof(struct gatt_read_uuid_rp))) { goto fail; } @@ -1457,7 +1502,7 @@ static void read_uuid(uint8_t *data, uint16_t len) read_params.handle_count = 0; read_params.by_uuid.start_handle = sys_le16_to_cpu(cmd->start_handle); read_params.by_uuid.end_handle = sys_le16_to_cpu(cmd->end_handle); - read_params.func = read_cb; + read_params.func = read_uuid_cb; btp_opcode = GATT_READ_UUID;