This is an automated email from the ASF dual-hosted git repository. sjanc pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 1d3c98ff4675b6f2608ff046b6462609ee706169 Author: Piotr Narajowski <[email protected]> AuthorDate: Thu Jan 30 16:13:01 2025 +0100 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. --- apps/bttester/src/btp_gatt.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/apps/bttester/src/btp_gatt.c b/apps/bttester/src/btp_gatt.c index a15d584c8..b0f21e07c 100644 --- a/apps/bttester/src/btp_gatt.c +++ b/apps/bttester/src/btp_gatt.c @@ -1927,6 +1927,51 @@ notify_mult(const void *cmd, uint16_t cmd_len, return BTP_STATUS_SUCCESS; } +static uint8_t +set_val(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) +{ + const struct btp_gatt_set_value_cmd *cp = cmd; + struct os_mbuf *om; + uint8_t cccd_value; + uint16_t handle; + int rc = 0; + + SYS_LOG_DBG(""); + + if ((cmd_len < sizeof(*cp)) || (cmd_len != sizeof(*cp) + htole16(cp->len))) { + return BTP_STATUS_FAILED; + } + + handle = cp->attr_id; + om = ble_hs_mbuf_from_flat(cp->value, cp->len); + if (!om) { + return BTP_STATUS_FAILED; + } + + ble_att_svr_write_local(handle, om); + + rc = ble_gatts_read_cccd(myconn_handle, handle, &cccd_value); + + if (rc != 0) { + return BTP_STATUS_FAILED; + } + + /* Indications take precedence over notifications if both are enabled */ + if (cccd_value & BLE_GATT_CCCD_INDICATE) { + /* Handles 0x02 (Indicate) and 0x03 (Notify & Indicate) */ + rc = ble_gatts_indicate(myconn_handle, handle); + } else if (cccd_value & BLE_GATT_CCCD_NOTIFY) { + /* Handles 0x01 (Notify only) */ + rc = ble_gatts_notify(myconn_handle, handle); + } + + if (rc != 0) { + return BTP_STATUS_FAILED; + } + + return BTP_STATUS_SUCCESS; +} + static uint8_t change_database(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) @@ -1977,6 +2022,11 @@ static const struct btp_handler handlers[] = { .expect_len = sizeof(struct btp_gatt_exchange_mtu_cmd), .func = exchange_mtu, }, + { + .opcode = BTP_GATT_SET_VALUE, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, + .func = set_val, + }, { .opcode = BTP_GATT_DISC_ALL_PRIM_SVCS, .expect_len = sizeof(struct btp_gatt_disc_all_prim_svcs_cmd),
