Skip to content

Commit 301558a

Browse files
tedd-annashif
authored andcommitted
tests: bluetooth/tester: Add support Read Using Characteristic UUID
This patch adds an API to support Read Using Characteristic UUID. Signed-off-by: Tedd Ho-Jeong An <[email protected]>
1 parent 919aa17 commit 301558a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

tests/bluetooth/tester/src/bttester.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,16 @@ struct gatt_read_rp {
457457
u8_t data[0];
458458
} __packed;
459459

460+
#define GATT_READ_UUID 0x12
461+
struct gatt_read_uuid_cmd {
462+
u8_t address_type;
463+
u8_t address[6];
464+
u16_t start_handle;
465+
u16_t end_handle;
466+
u8_t uuid_length;
467+
u8_t uuid[0];
468+
} __packed;
469+
460470
#define GATT_READ_LONG 0x13
461471
struct gatt_read_long_cmd {
462472
u8_t address_type;

tests/bluetooth/tester/src/gatt.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,49 @@ static void read(u8_t *data, u16_t len)
13741374
BTP_STATUS_FAILED);
13751375
}
13761376

1377+
static void read_uuid(u8_t *data, u16_t len)
1378+
{
1379+
const struct gatt_read_uuid_cmd *cmd = (void *) data;
1380+
struct bt_conn *conn;
1381+
1382+
conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data);
1383+
if (!conn) {
1384+
goto fail_conn;
1385+
}
1386+
1387+
if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid.uuid)) {
1388+
goto fail;
1389+
}
1390+
1391+
if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
1392+
goto fail;
1393+
}
1394+
1395+
read_params.by_uuid.uuid = &uuid.uuid;
1396+
read_params.handle_count = 0;
1397+
read_params.by_uuid.start_handle = sys_le16_to_cpu(cmd->start_handle);
1398+
read_params.by_uuid.end_handle = sys_le16_to_cpu(cmd->end_handle);
1399+
read_params.func = read_cb;
1400+
1401+
btp_opcode = GATT_READ_UUID;
1402+
1403+
if (bt_gatt_read(conn, &read_params) < 0) {
1404+
read_destroy(&read_params);
1405+
1406+
goto fail;
1407+
}
1408+
1409+
bt_conn_unref(conn);
1410+
1411+
return;
1412+
fail:
1413+
bt_conn_unref(conn);
1414+
1415+
fail_conn:
1416+
tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_UUID, CONTROLLER_INDEX,
1417+
BTP_STATUS_FAILED);
1418+
}
1419+
13771420
static void read_long(u8_t *data, u16_t len)
13781421
{
13791422
const struct gatt_read_long_cmd *cmd = (void *) data;
@@ -1908,6 +1951,9 @@ void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
19081951
case GATT_READ:
19091952
read(data, len);
19101953
return;
1954+
case GATT_READ_UUID:
1955+
read_uuid(data, len);
1956+
return;
19111957
case GATT_READ_LONG:
19121958
read_long(data, len);
19131959
return;

0 commit comments

Comments
 (0)