Skip to content

Commit b2f434b

Browse files
apps: bttester: add set_val GATT command
Opcode 0x06 and btp_cmd struct were previously defined in btp_gatt.h but command implementation was missing. Can be used to send notifications or indications.
1 parent 4829e7a commit b2f434b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

apps/bttester/src/btp_gatt.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,39 @@ notify_mult(const void *cmd, uint16_t cmd_len,
19371937
return BTP_STATUS_SUCCESS;
19381938
}
19391939

1940+
static uint8_t
1941+
set_val(const void *cmd, uint16_t cmd_len,
1942+
void *rsp, uint16_t *rsp_len)
1943+
{
1944+
const struct btp_gatt_set_value_cmd *cp = cmd;
1945+
struct os_mbuf *value;
1946+
uint16_t handle;
1947+
int rc = 0;
1948+
1949+
handle = cp->attr_id;
1950+
value = ble_hs_mbuf_att_pkt();
1951+
if (value == NULL) {
1952+
return BTP_STATUS_FAILED;
1953+
}
1954+
os_mbuf_append(value, cp->value, cp->len);
1955+
1956+
ble_att_svr_write_local(handle, value);
1957+
1958+
if (notify_state) {
1959+
rc = ble_gatts_notify_custom(myconn_handle, handle, value);
1960+
}
1961+
1962+
if (indicate_state) {
1963+
rc = ble_gatts_indicate_custom(myconn_handle, notify_handle, value);
1964+
}
1965+
1966+
if (rc != 0) {
1967+
return BTP_STATUS_FAILED;
1968+
}
1969+
1970+
return BTP_STATUS_SUCCESS;
1971+
}
1972+
19401973
static uint8_t
19411974
change_database(const void *cmd, uint16_t cmd_len,
19421975
void *rsp, uint16_t *rsp_len)
@@ -1961,6 +1994,7 @@ supported_commands(const void *cmd, uint16_t cmd_len,
19611994
/* octet 0 */
19621995
tester_set_bit(rp->data, BTP_GATT_READ_SUPPORTED_COMMANDS);
19631996
tester_set_bit(rp->data, BTP_GATT_START_SERVER);
1997+
tester_set_bit(rp->data, BTP_GATT_SET_VALUE);
19641998

19651999
/* octet 1 */
19662000
tester_set_bit(rp->data, BTP_GATT_EXCHANGE_MTU);
@@ -2017,6 +2051,11 @@ static const struct btp_handler handlers[] = {
20172051
.expect_len = sizeof(struct btp_gatt_exchange_mtu_cmd),
20182052
.func = exchange_mtu,
20192053
},
2054+
{
2055+
.opcode = BTP_GATT_SET_VALUE,
2056+
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
2057+
.func = set_val,
2058+
},
20202059
{
20212060
.opcode = BTP_GATT_DISC_ALL_PRIM_SVCS,
20222061
.expect_len = sizeof(struct btp_gatt_disc_all_prim_svcs_cmd),

0 commit comments

Comments
 (0)