Skip to content

Commit 13d30ee

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 0ba168d commit 13d30ee

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
@@ -1911,6 +1911,39 @@ set_mult(const void *cmd, uint16_t cmd_len,
19111911
return BTP_STATUS_SUCCESS;
19121912
}
19131913

1914+
static uint8_t
1915+
set_val(const void *cmd, uint16_t cmd_len,
1916+
void *rsp, uint16_t *rsp_len)
1917+
{
1918+
const struct btp_gatt_set_value_cmd *cp = cmd;
1919+
struct os_mbuf *value;
1920+
uint16_t handle;
1921+
int rc = 0;
1922+
1923+
handle = cp->attr_id;
1924+
value = ble_hs_mbuf_att_pkt();
1925+
if (value == NULL) {
1926+
return BTP_STATUS_FAILED;
1927+
}
1928+
os_mbuf_append(value, cp->value, cp->len);
1929+
1930+
ble_att_svr_write_local(handle, value);
1931+
1932+
if (notify_state) {
1933+
rc = ble_gatts_notify_custom(myconn_handle, handle, value);
1934+
}
1935+
1936+
if (indicate_state) {
1937+
rc = ble_gatts_indicate_custom(myconn_handle, notify_handle, value);
1938+
}
1939+
1940+
if (rc != 0) {
1941+
return BTP_STATUS_FAILED;
1942+
}
1943+
1944+
return BTP_STATUS_SUCCESS;
1945+
}
1946+
19141947
static uint8_t
19151948
change_database(const void *cmd, uint16_t cmd_len,
19161949
void *rsp, uint16_t *rsp_len)
@@ -1935,6 +1968,7 @@ supported_commands(const void *cmd, uint16_t cmd_len,
19351968
/* octet 0 */
19361969
tester_set_bit(rp->data, BTP_GATT_READ_SUPPORTED_COMMANDS);
19371970
tester_set_bit(rp->data, BTP_GATT_START_SERVER);
1971+
tester_set_bit(rp->data, BTP_GATT_SET_VALUE);
19381972

19391973
/* octet 1 */
19401974
tester_set_bit(rp->data, BTP_GATT_EXCHANGE_MTU);
@@ -1991,6 +2025,11 @@ static const struct btp_handler handlers[] = {
19912025
.expect_len = sizeof(struct btp_gatt_exchange_mtu_cmd),
19922026
.func = exchange_mtu,
19932027
},
2028+
{
2029+
.opcode = BTP_GATT_SET_VALUE,
2030+
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
2031+
.func = set_val,
2032+
},
19942033
{
19952034
.opcode = BTP_GATT_DISC_ALL_PRIM_SVCS,
19962035
.expect_len = sizeof(struct btp_gatt_disc_all_prim_svcs_cmd),

0 commit comments

Comments
 (0)