Skip to content

Commit ca51138

Browse files
szymon-czaprackisjanc
authored andcommitted
apps: bttester: Add notify multiple command
Add functionality to utilize BTP notify multiple command. Existing notify handling parses non-existent data.
1 parent cc14187 commit ca51138

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

apps/bttester/src/btp/btp_gatt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,13 @@ struct btp_gatt_set_mult_val_cmd {
320320
uint8_t data[0];
321321
} __packed;
322322

323+
#define BTP_GATT_NOTIFY_MULTIPLE 0x21
324+
struct btp_gatt_notify_mult_val_cmd {
325+
ble_addr_t addr;
326+
uint16_t count;
327+
uint16_t handles[0];
328+
} __packed;
329+
323330
/* GATT events */
324331
#define BTP_GATT_EV_NOTIFICATION 0x80
325332
struct btp_gatt_notification_ev {

apps/bttester/src/btp_gatt.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct find_attr_data {
9595

9696
struct notify_mult_cb_data {
9797
size_t tuple_cnt;
98-
uint16_t handles[0];
98+
uint16_t handles[8];
9999
};
100100

101101
static int
@@ -1950,6 +1950,38 @@ set_mult(const void *cmd, uint16_t cmd_len,
19501950
return BTP_STATUS_SUCCESS;
19511951
}
19521952

1953+
static uint8_t
1954+
notify_mult(const void *cmd, uint16_t cmd_len,
1955+
void *rsp, uint16_t *rsp_len)
1956+
{
1957+
const struct btp_gatt_notify_mult_val_cmd *cp = cmd;
1958+
struct notify_mult_cb_data cb_data;
1959+
int i;
1960+
1961+
1962+
if (cmd_len < sizeof(*cp) ||
1963+
(cmd_len != (sizeof(*cp) +
1964+
(le16toh(cp->count) * sizeof(cp->handles[0]))))) {
1965+
1966+
return BTP_STATUS_FAILED;
1967+
}
1968+
1969+
if (le16toh(cp->count) > sizeof(cb_data.handles)) {
1970+
SYS_LOG_ERR("Too many handles to notify");
1971+
return BTP_STATUS_FAILED;
1972+
}
1973+
1974+
for (i = 0; i < cp->count; i++) {
1975+
cb_data.handles[i] = le16toh(cp->handles[i]);
1976+
}
1977+
1978+
cb_data.tuple_cnt = cp->count;
1979+
1980+
ble_gap_conn_foreach_handle(notify_multiple, (void *)&cb_data);
1981+
1982+
return BTP_STATUS_SUCCESS;
1983+
}
1984+
19531985
static uint8_t
19541986
change_database(const void *cmd, uint16_t cmd_len,
19551987
void *rsp, uint16_t *rsp_len)
@@ -2137,6 +2169,11 @@ static const struct btp_handler handlers[] = {
21372169
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
21382170
.func = set_mult,
21392171
},
2172+
{
2173+
.opcode = BTP_GATT_NOTIFY_MULTIPLE,
2174+
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
2175+
.func = notify_mult,
2176+
},
21402177
};
21412178

21422179
int

0 commit comments

Comments
 (0)