Skip to content

apps: bttester: Implement notify / Remove set_mult #1964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions apps/bttester/src/btp/btp_gatt.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,11 @@ struct btp_gatt_change_database_cmd {
uint8_t visibility;
} __packed;

#define BTP_GATT_SET_MULT_VALUE 0x20
struct btp_gatt_set_mult_val_cmd {
#define BTP_GATT_NOTIFY_MULTIPLE 0x21
struct btp_gatt_notify_mult_val_cmd {
ble_addr_t addr;
uint16_t count;
uint8_t data[0];
uint16_t handles[0];
} __packed;

/* GATT events */
Expand Down
47 changes: 18 additions & 29 deletions apps/bttester/src/btp_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct find_attr_data {

struct notify_mult_cb_data {
size_t tuple_cnt;
uint16_t handles[0];
uint16_t handles[8];
};

static int
Expand Down Expand Up @@ -1871,44 +1871,33 @@ notify_multiple(uint16_t conn_handle, void *arg)
}

static uint8_t
set_mult(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
notify_mult(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
{
const struct btp_gatt_set_mult_val_cmd *cp = cmd;
struct ble_gatt_notif tuples[16];
int i;
int rc = 0;
int data_idx = 0;
uint16_t data_len;
const struct btp_gatt_notify_mult_val_cmd *cp = cmd;
struct notify_mult_cb_data cb_data;
int i;

for (i = 0; i < cp->count; i++) {
tuples[i].handle = get_le16(cp->data + data_idx);
data_idx += 2;
tuples[i].value = ble_hs_mbuf_att_pkt();
if (tuples[i].value == NULL) {
rc = ENOMEM;
goto done;
}

data_len = get_le16(cp->data + data_idx);
data_idx += 2;
if (cmd_len < sizeof(*cp) ||
(cmd_len != (sizeof(*cp) +
(le16toh(cp->count) * sizeof(cp->handles[0]))))) {

return BTP_STATUS_FAILED;
}

os_mbuf_append(tuples[i].value, cp->data + data_idx, data_len);
data_idx += data_len;
if (le16toh(cp->count) > sizeof(cb_data.handles)) {
SYS_LOG_ERR("Too many handles to notify");
return BTP_STATUS_FAILED;
}

for (i = 0; i < cp->count; i++) {
ble_att_svr_write_local(tuples[i].handle, tuples[i].value);
cb_data.handles[i] = tuples[i].handle;
cb_data.handles[i] = le16toh(cp->handles[i]);
}

cb_data.tuple_cnt = cp->count;

ble_gap_conn_foreach_handle(notify_multiple, (void *)&cb_data);
done:
if (rc != 0) {
return BTP_STATUS_FAILED;
}

return BTP_STATUS_SUCCESS;
}
Expand Down Expand Up @@ -2096,9 +2085,9 @@ static const struct btp_handler handlers[] = {
.func = get_attr_val,
},
{
.opcode = BTP_GATT_SET_MULT_VALUE,
.opcode = BTP_GATT_NOTIFY_MULTIPLE,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = set_mult,
.func = notify_mult,
},
};

Expand Down
Loading