Skip to content

Commit 9168db8

Browse files
m-alperen-senerPavelVPV
authored andcommitted
tests: bluetooth: tester: add support for wid 145 and 167
wid 145 requests handle of a UUID of a long characteristic. wid 167 requests to remove the characteristic by handle requested in wid 145. 2 new commands are added to support these wids: - BTP_GATT_GET_HANDLE_FROM_UUID to request handle of a certain UUID - BTP_GATT_REMOVE_HANDLE_FROM_DB to remove attribute by handle. Signed-off-by: alperen sener <alperen.sener@nordicsemi.no> Signed-off-by: Pavel Vasilyev <pavel.vasilyev@nordicsemi.no>
1 parent d21f6b5 commit 9168db8

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

tests/bluetooth/tester/src/btp/btp_gatt.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,21 @@ struct btp_gatt_cfg_notify_mult_cmd {
347347
uint16_t cnt;
348348
uint16_t attr_id[];
349349
} __packed;
350+
351+
#define BTP_GATT_GET_HANDLE_FROM_UUID 0x22
352+
struct btp_gatt_get_handle_from_uuid_cmd {
353+
uint8_t uuid_length;
354+
uint8_t uuid[];
355+
} __packed;
356+
struct btp_gatt_get_handle_from_uuid_rp {
357+
uint16_t handle;
358+
} __packed;
359+
360+
#define BTP_GATT_REMOVE_HANDLE_FROM_DB 0x23
361+
struct btp_gatt_remove_handle_from_db_cmd {
362+
uint16_t handle;
363+
} __packed;
364+
350365
/* GATT events */
351366
#define BTP_GATT_EV_NOTIFICATION 0x80
352367
struct btp_gatt_notification_ev {

tests/bluetooth/tester/src/btp_gatt.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ static int alloc_characteristic(struct add_characteristic *ch)
452452
chrc_data->uuid = attr_value->uuid;
453453

454454
ch->char_id = attr_chrc->handle;
455+
455456
return 0;
456457
}
457458

@@ -2139,6 +2140,57 @@ static uint8_t notify_mult(const void *cmd, uint16_t cmd_len,
21392140
}
21402141
#endif /* CONFIG_BT_GATT_NOTIFY_MULTIPLE */
21412142

2143+
static uint8_t get_handle_from_uuid(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len)
2144+
{
2145+
const struct btp_gatt_get_handle_from_uuid_cmd *cp = cmd;
2146+
struct btp_gatt_get_handle_from_uuid_rp *rp = rsp;
2147+
struct bt_uuid search_uuid;
2148+
2149+
if (btp2bt_uuid(cp->uuid, cp->uuid_length, &search_uuid)) {
2150+
return BTP_STATUS_FAILED;
2151+
}
2152+
2153+
char uuid_str[BT_UUID_STR_LEN];
2154+
2155+
bt_uuid_to_str(&search_uuid, uuid_str, sizeof(uuid_str));
2156+
2157+
for (int i = 0; i < SERVER_MAX_ATTRIBUTES; i++) {
2158+
if (bt_uuid_cmp(server_db[i].uuid, &search_uuid) == 0) {
2159+
rp->handle = server_db[i].handle;
2160+
*rsp_len = sizeof(*rp);
2161+
2162+
return BTP_STATUS_SUCCESS;
2163+
}
2164+
}
2165+
2166+
return BTP_STATUS_FAILED;
2167+
}
2168+
2169+
static uint8_t remove_handle_from_db(const void *cmd, uint16_t cmd_len, void *rsp,
2170+
uint16_t *rsp_len)
2171+
{
2172+
const struct btp_gatt_remove_handle_from_db_cmd *cp = cmd;
2173+
uint16_t handle = sys_le16_to_cpu(cp->handle);
2174+
2175+
for (int i = 0; i < svc_count; i++) {
2176+
for (int j = 0; j < server_svcs[i].attr_count; j++) {
2177+
if (server_svcs[i].attrs[j].handle == handle) {
2178+
int err;
2179+
2180+
err = bt_gatt_service_unregister(&server_svcs[i]);
2181+
if (err < 0) {
2182+
LOG_ERR("Failed to unregister service [%d]: %d", i, err);
2183+
return BTP_STATUS_FAILED;
2184+
}
2185+
2186+
return BTP_STATUS_SUCCESS;
2187+
}
2188+
}
2189+
}
2190+
2191+
return BTP_STATUS_FAILED;
2192+
}
2193+
21422194
struct get_attrs_foreach_data {
21432195
struct net_buf_simple *buf;
21442196
const struct bt_uuid *uuid;
@@ -2565,6 +2617,16 @@ static const struct btp_handler handlers[] = {
25652617
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
25662618
.func = notify_mult,
25672619
},
2620+
{
2621+
.opcode = BTP_GATT_GET_HANDLE_FROM_UUID,
2622+
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
2623+
.func = get_handle_from_uuid,
2624+
},
2625+
{
2626+
.opcode = BTP_GATT_REMOVE_HANDLE_FROM_DB,
2627+
.expect_len = sizeof(struct btp_gatt_remove_handle_from_db_cmd),
2628+
.func = remove_handle_from_db,
2629+
}
25682630
};
25692631

25702632
uint8_t tester_init_gatt(void)

0 commit comments

Comments
 (0)