Skip to content

Commit

Permalink
tests: bluetooth/tester: Add support Read Using Characteristic UUID
Browse files Browse the repository at this point in the history
This patch adds an API to support Read Using Characteristic UUID.

Signed-off-by: Tedd Ho-Jeong An <tedd.an@intel.com>
  • Loading branch information
tedd-an authored and jhedberg committed Apr 24, 2019
1 parent 6576efe commit 543b9c9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/bluetooth/tester/src/bttester.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -457,6 +457,16 @@ struct gatt_read_rp {
u8_t data[0]; u8_t data[0];
} __packed; } __packed;


#define GATT_READ_UUID 0x12
struct gatt_read_uuid_cmd {
u8_t address_type;
u8_t address[6];
u16_t start_handle;
u16_t end_handle;
u8_t uuid_length;
u8_t uuid[0];
} __packed;

#define GATT_READ_LONG 0x13 #define GATT_READ_LONG 0x13
struct gatt_read_long_cmd { struct gatt_read_long_cmd {
u8_t address_type; u8_t address_type;
Expand Down
46 changes: 46 additions & 0 deletions tests/bluetooth/tester/src/gatt.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1374,6 +1374,49 @@ static void read(u8_t *data, u16_t len)
BTP_STATUS_FAILED); BTP_STATUS_FAILED);
} }


static void read_uuid(u8_t *data, u16_t len)
{
const struct gatt_read_uuid_cmd *cmd = (void *) data;
struct bt_conn *conn;

conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, (bt_addr_le_t *)data);
if (!conn) {
goto fail_conn;
}

if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid.uuid)) {
goto fail;
}

if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
goto fail;
}

read_params.by_uuid.uuid = &uuid.uuid;
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;

btp_opcode = GATT_READ_UUID;

if (bt_gatt_read(conn, &read_params) < 0) {
read_destroy(&read_params);

goto fail;
}

bt_conn_unref(conn);

return;
fail:
bt_conn_unref(conn);

fail_conn:
tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_UUID, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}

static void read_long(u8_t *data, u16_t len) static void read_long(u8_t *data, u16_t len)
{ {
const struct gatt_read_long_cmd *cmd = (void *) data; const struct gatt_read_long_cmd *cmd = (void *) data;
Expand Down Expand Up @@ -1908,6 +1951,9 @@ void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
case GATT_READ: case GATT_READ:
read(data, len); read(data, len);
return; return;
case GATT_READ_UUID:
read_uuid(data, len);
return;
case GATT_READ_LONG: case GATT_READ_LONG:
read_long(data, len); read_long(data, len);
return; return;
Expand Down

0 comments on commit 543b9c9

Please sign in to comment.