Skip to content

Commit 6c30f96

Browse files
szymon-czaprackisjanc
authored andcommitted
apps/bttester: Refactor reporting supported commands
Implement new way for reporting supported commands. Now only commands with registered handler will be present in the queried response.
1 parent 9d0217a commit 6c30f96

File tree

10 files changed

+38
-170
lines changed

10 files changed

+38
-170
lines changed

apps/bttester/src/btp/bttester.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ struct btp_handler {
9393
void tester_register_command_handlers(uint8_t service,
9494
const struct btp_handler *handlers,
9595
size_t num);
96+
97+
uint16_t tester_supported_commands(uint8_t service, uint8_t *cmds);
98+
9699
void
97100
tester_send_buf(uint8_t service, uint8_t opcode, uint8_t index,
98101
struct os_mbuf *buf);

apps/bttester/src/btp_bap.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,8 @@ supported_commands(const void *cmd, uint16_t cmd_len,
139139
{
140140
struct btp_bap_read_supported_commands_rp *rp = rsp;
141141

142-
/* octet 0 */
143-
tester_set_bit(rp->data, BTP_BAP_READ_SUPPORTED_COMMANDS);
144-
tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_SETUP);
145-
tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_RELEASE);
146-
tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_START);
147-
tester_set_bit(rp->data, BTP_BAP_BROADCAST_ADV_STOP);
148-
149-
/* octet 1 */
150-
tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_START);
151-
tester_set_bit(rp->data, BTP_BAP_BROADCAST_SOURCE_STOP);
152-
153-
*rsp_len = sizeof(*rp) + 2;
142+
*rsp_len = tester_supported_commands(BTP_SERVICE_ID_BAP, rp->data);
143+
*rsp_len += sizeof(*rp);
154144

155145
return BTP_STATUS_SUCCESS;
156146
}

apps/bttester/src/btp_core.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ supported_commands(const void *cmd, uint16_t cmd_len,
3535
{
3636
struct btp_core_read_supported_commands_rp *rp = rsp;
3737

38-
tester_set_bit(rp->data, BTP_CORE_READ_SUPPORTED_COMMANDS);
39-
tester_set_bit(rp->data, BTP_CORE_READ_SUPPORTED_SERVICES);
40-
tester_set_bit(rp->data, BTP_CORE_REGISTER_SERVICE);
41-
tester_set_bit(rp->data, BTP_CORE_UNREGISTER_SERVICE);
42-
43-
*rsp_len = sizeof(*rp) + 1;
38+
*rsp_len = tester_supported_commands(BTP_SERVICE_ID_CORE, rp->data);
39+
*rsp_len += sizeof(*rp);
4440

4541
return BTP_STATUS_SUCCESS;
4642
}

apps/bttester/src/btp_gap.c

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -128,55 +128,8 @@ supported_commands(const void *cmd, uint16_t cmd_len,
128128
{
129129
struct btp_gap_read_supported_commands_rp *rp = rsp;
130130

131-
/* octet 0 */
132-
tester_set_bit(rp->data, BTP_GAP_READ_SUPPORTED_COMMANDS);
133-
tester_set_bit(rp->data, BTP_GAP_READ_CONTROLLER_INDEX_LIST);
134-
tester_set_bit(rp->data, BTP_GAP_READ_CONTROLLER_INFO);
135-
tester_set_bit(rp->data, BTP_GAP_SET_CONNECTABLE);
136-
137-
/* octet 1 */
138-
tester_set_bit(rp->data, BTP_GAP_SET_DISCOVERABLE);
139-
tester_set_bit(rp->data, BTP_GAP_SET_BONDABLE);
140-
tester_set_bit(rp->data, BTP_GAP_START_ADVERTISING);
141-
tester_set_bit(rp->data, BTP_GAP_STOP_ADVERTISING);
142-
tester_set_bit(rp->data, BTP_GAP_START_DISCOVERY);
143-
tester_set_bit(rp->data, BTP_GAP_STOP_DISCOVERY);
144-
tester_set_bit(rp->data, BTP_GAP_CONNECT);
145-
tester_set_bit(rp->data, BTP_GAP_DISCONNECT);
146-
147-
/* octet 2 */
148-
tester_set_bit(rp->data, BTP_GAP_SET_IO_CAP);
149-
tester_set_bit(rp->data, BTP_GAP_PAIR);
150-
tester_set_bit(rp->data, BTP_GAP_UNPAIR);
151-
tester_set_bit(rp->data, BTP_GAP_PASSKEY_ENTRY);
152-
tester_set_bit(rp->data, BTP_GAP_PASSKEY_CONFIRM);
153-
tester_set_bit(rp->data, BTP_GAP_START_DIRECT_ADV);
154-
tester_set_bit(rp->data, BTP_GAP_CONN_PARAM_UPDATE);
155-
156-
/* octet 3 */
157-
tester_set_bit(rp->data, BTP_GAP_OOB_LEGACY_SET_DATA);
158-
tester_set_bit(rp->data, BTP_GAP_OOB_SC_GET_LOCAL_DATA);
159-
tester_set_bit(rp->data, BTP_GAP_OOB_SC_SET_REMOTE_DATA);
160-
tester_set_bit(rp->data, BTP_GAP_SET_MITM);
161-
tester_set_bit(rp->data, BTP_GAP_SET_FILTER_ACCEPT_LIST);
162-
163-
/* octet 4 */
164-
#if MYNEWT_VAL(BLE_PERIODIC_ADV)
165-
tester_set_bit(rp->data, GAP_SET_EXT_ADV);
166-
tester_set_bit(rp->data, GAP_PADV_CONFIGURE);
167-
tester_set_bit(rp->data, GAP_PADV_START);
168-
tester_set_bit(rp->data, GAP_PADV_SET_DATA);
169-
tester_set_bit(rp->data, GAP_PADV_CREATE_SYNC);
170-
#endif
171-
#if MYNEWT_VAL(BLE_PERIODIC_ADV_SYNC_TRANSFER)
172-
tester_set_bit(rp->data, GAP_PADV_SYNC_TRANSFER_SET_INFO);
173-
tester_set_bit(rp->data, GAP_PADV_SYNC_TRANSFER_START);
174-
tester_set_bit(rp->data, GAP_PADV_SYNC_TRANSFER_START);
175-
#endif
176-
177-
*rsp_len = sizeof(*rp) + 4 +
178-
(MYNEWT_VAL(BLE_PERIODIC_ADV) ||
179-
MYNEWT_VAL(BLE_PERIODIC_ADV_SYNC_TRANSFER) ? 1 : 0);
131+
*rsp_len = tester_supported_commands(BTP_SERVICE_ID_GAP, rp->data);
132+
*rsp_len += sizeof(*rp);
180133

181134
return BTP_STATUS_SUCCESS;
182135
}

apps/bttester/src/btp_gatt.c

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,38 +1960,8 @@ supported_commands(const void *cmd, uint16_t cmd_len,
19601960
{
19611961
struct btp_gatt_read_supported_commands_rp *rp = rsp;
19621962

1963-
/* octet 0 */
1964-
tester_set_bit(rp->data, BTP_GATT_READ_SUPPORTED_COMMANDS);
1965-
tester_set_bit(rp->data, BTP_GATT_START_SERVER);
1966-
1967-
/* octet 1 */
1968-
tester_set_bit(rp->data, BTP_GATT_EXCHANGE_MTU);
1969-
tester_set_bit(rp->data, BTP_GATT_DISC_ALL_PRIM_SVCS);
1970-
tester_set_bit(rp->data, BTP_GATT_DISC_PRIM_UUID);
1971-
tester_set_bit(rp->data, BTP_GATT_FIND_INCLUDED);
1972-
tester_set_bit(rp->data, BTP_GATT_DISC_ALL_CHRC);
1973-
tester_set_bit(rp->data, BTP_GATT_DISC_CHRC_UUID);
1974-
1975-
/* octet 2 */
1976-
tester_set_bit(rp->data, BTP_GATT_DISC_ALL_DESC);
1977-
tester_set_bit(rp->data, BTP_GATT_READ);
1978-
tester_set_bit(rp->data, BTP_GATT_READ_LONG);
1979-
tester_set_bit(rp->data, BTP_GATT_READ_MULTIPLE);
1980-
tester_set_bit(rp->data, BTP_GATT_WRITE_WITHOUT_RSP);
1981-
#if 0
1982-
tester_set_bit(rp->data, BTP_GATT_SIGNED_WRITE_WITHOUT_RSP);
1983-
#endif
1984-
tester_set_bit(rp->data, BTP_GATT_WRITE);
1985-
1986-
/* octet 3 */
1987-
tester_set_bit(rp->data, BTP_GATT_WRITE_LONG);
1988-
tester_set_bit(rp->data, BTP_GATT_CFG_NOTIFY);
1989-
tester_set_bit(rp->data, BTP_GATT_CFG_INDICATE);
1990-
tester_set_bit(rp->data, BTP_GATT_GET_ATTRIBUTES);
1991-
tester_set_bit(rp->data, BTP_GATT_GET_ATTRIBUTE_VALUE);
1992-
tester_set_bit(rp->data, BTP_GATT_CHANGE_DATABASE);
1993-
1994-
*rsp_len = sizeof(*rp) + 4;
1963+
*rsp_len = tester_supported_commands(BTP_SERVICE_ID_GATT, rp->data);
1964+
*rsp_len += sizeof(*rp);
19951965

19961966
return BTP_STATUS_SUCCESS;
19971967
}

apps/bttester/src/btp_gatt_cl.c

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,35 +1491,8 @@ supported_commands(const void *cmd, uint16_t cmd_len,
14911491
{
14921492
struct btp_gattc_read_supported_commands_rp *rp = rsp;
14931493

1494-
SYS_LOG_DBG("");
1495-
1496-
/* octet 0 */
1497-
tester_set_bit(rp->data, BTP_GATTC_READ_SUPPORTED_COMMANDS);
1498-
tester_set_bit(rp->data, BTP_GATTC_EXCHANGE_MTU);
1499-
tester_set_bit(rp->data, BTP_GATTC_DISC_ALL_PRIM_SVCS);
1500-
tester_set_bit(rp->data, BTP_GATTC_DISC_PRIM_UUID);
1501-
tester_set_bit(rp->data, BTP_GATTC_FIND_INCLUDED);
1502-
tester_set_bit(rp->data, BTP_GATTC_DISC_ALL_CHRC);
1503-
tester_set_bit(rp->data, BTP_GATTC_DISC_CHRC_UUID);
1504-
/* octet 1 */
1505-
tester_set_bit(rp->data, BTP_GATTC_DISC_ALL_DESC);
1506-
tester_set_bit(rp->data, BTP_GATTC_READ);
1507-
tester_set_bit(rp->data, BTP_GATTC_READ_UUID);
1508-
tester_set_bit(rp->data, BTP_GATTC_READ_LONG);
1509-
tester_set_bit(rp->data, BTP_GATTC_READ_MULTIPLE);
1510-
tester_set_bit(rp->data, BTP_GATTC_WRITE_WITHOUT_RSP);
1511-
#if 0
1512-
tester_set_bit(rp->data, BTP_GATTC_SIGNED_WRITE_WITHOUT_RSP);
1513-
#endif
1514-
tester_set_bit(rp->data, BTP_GATTC_WRITE);
1515-
/* octet 2 */
1516-
tester_set_bit(rp->data, BTP_GATTC_WRITE_LONG);
1517-
tester_set_bit(rp->data, BTP_GATTC_RELIABLE_WRITE);
1518-
tester_set_bit(rp->data, BTP_GATTC_CFG_NOTIFY);
1519-
tester_set_bit(rp->data, BTP_GATTC_CFG_INDICATE);
1520-
tester_set_bit(rp->data, BTP_GATTC_READ_MULTIPLE_VAR);
1521-
1522-
*rsp_len = sizeof(*rp) + 3;
1494+
*rsp_len = tester_supported_commands(BTP_SERVICE_ID_GATTC, rp->data);
1495+
*rsp_len += sizeof(*rp);
15231496

15241497
return BTP_STATUS_SUCCESS;
15251498
}

apps/bttester/src/btp_l2cap.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -678,15 +678,8 @@ supported_commands(const void *cmd, uint16_t cmd_len,
678678
{
679679
struct btp_l2cap_read_supported_commands_rp *rp = rsp;
680680

681-
/* octet 0 */
682-
tester_set_bit(rp->data, BTP_L2CAP_READ_SUPPORTED_COMMANDS);
683-
tester_set_bit(rp->data, BTP_L2CAP_CONNECT);
684-
tester_set_bit(rp->data, BTP_L2CAP_DISCONNECT);
685-
tester_set_bit(rp->data, BTP_L2CAP_SEND_DATA);
686-
tester_set_bit(rp->data, BTP_L2CAP_LISTEN);
687-
/* octet 1 */
688-
tester_set_bit(rp->data, BTP_L2CAP_CREDITS);
689-
*rsp_len = sizeof(*rp) + 2;
681+
*rsp_len = tester_supported_commands(BTP_SERVICE_ID_L2CAP, rp->data);
682+
*rsp_len += sizeof(*rp);
690683

691684
return BTP_STATUS_SUCCESS;
692685
}

apps/bttester/src/btp_mesh.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,8 @@ supported_commands(const void *cmd, uint16_t cmd_len,
9494
{
9595
struct btp_mesh_read_supported_commands_rp *rp = rsp;
9696

97-
/* octet 0 */
98-
tester_set_bit(rp->data, BTP_MESH_READ_SUPPORTED_COMMANDS);
99-
tester_set_bit(rp->data, BTP_MESH_CONFIG_PROVISIONING);
100-
tester_set_bit(rp->data, BTP_MESH_PROVISION_NODE);
101-
tester_set_bit(rp->data, BTP_MESH_INIT);
102-
tester_set_bit(rp->data, BTP_MESH_RESET);
103-
tester_set_bit(rp->data, BTP_MESH_INPUT_NUMBER);
104-
tester_set_bit(rp->data, BTP_MESH_INPUT_STRING);
105-
/* octet 1 */
106-
tester_set_bit(rp->data, BTP_MESH_IVU_TEST_MODE);
107-
tester_set_bit(rp->data, BTP_MESH_IVU_TOGGLE_STATE);
108-
tester_set_bit(rp->data, BTP_MESH_NET_SEND);
109-
tester_set_bit(rp->data, BTP_MESH_HEALTH_GENERATE_FAULTS);
110-
tester_set_bit(rp->data, BTP_MESH_HEALTH_CLEAR_FAULTS);
111-
tester_set_bit(rp->data, BTP_MESH_LPN);
112-
tester_set_bit(rp->data, BTP_MESH_LPN_POLL);
113-
tester_set_bit(rp->data, BTP_MESH_MODEL_SEND);
114-
/* octet 2 */
115-
#if MYNEWT_VAL(BLE_MESH_TESTING)
116-
tester_set_bit(rp->data, BTP_MESH_LPN_SUBSCRIBE);
117-
tester_set_bit(rp->data, BTP_MESH_LPN_UNSUBSCRIBE);
118-
tester_set_bit(rp->data, BTP_MESH_RPL_CLEAR);
119-
#endif /* CONFIG_BT_TESTING */
120-
tester_set_bit(rp->data, BTP_MESH_PROXY_IDENTITY);
121-
122-
*rsp_len = sizeof(*rp) + 3;
97+
*rsp_len = tester_supported_commands(BTP_SERVICE_ID_GAP, rp->data);
98+
*rsp_len += sizeof(*rp);
12399

124100
return BTP_STATUS_SUCCESS;
125101
}

apps/bttester/src/btp_pacs.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,8 @@ supported_commands(const void *cmd, uint16_t cmd_len,
266266
{
267267
struct btp_pacs_read_supported_commands_rp *rp = rsp;
268268

269-
/* octet 0 */
270-
tester_set_bit(rp->data, BTP_PACS_READ_SUPPORTED_COMMANDS);
271-
tester_set_bit(rp->data, BTP_PACS_UPDATE_CHARACTERISTIC);
272-
tester_set_bit(rp->data, BTP_PACS_SET_AVAILABLE_CONTEXTS);
273-
tester_set_bit(rp->data, BTP_PACS_SET_SUPPORTED_CONTEXTS);
274-
275-
*rsp_len = sizeof(*rp) + 1;
269+
*rsp_len = tester_supported_commands(BTP_SERVICE_ID_PACS, rp->data);
270+
*rsp_len += sizeof(*rp);
276271

277272
return BTP_STATUS_SUCCESS;
278273
}

apps/bttester/src/bttester.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,3 +377,22 @@ tester_rsp(uint8_t service, uint8_t opcode, uint8_t status)
377377
os_eventq_put(&avail_queue,
378378
CONTAINER_OF(cmd, struct btp_buf, data)->ev);
379379
}
380+
381+
uint16_t
382+
tester_supported_commands(uint8_t service, uint8_t *cmds)
383+
{
384+
uint8_t opcode_max = 0;
385+
386+
assert(service <= BTP_SERVICE_ID_MAX);
387+
388+
for (size_t i = 0; i < service_handler[service].num; i++) {
389+
const struct btp_handler *handler = &service_handler[service].handlers[i];
390+
tester_set_bit(cmds, handler->opcode);
391+
392+
if (handler->opcode > opcode_max) {
393+
opcode_max = handler->opcode;
394+
}
395+
}
396+
397+
return (opcode_max / 8) + 1;
398+
}

0 commit comments

Comments
 (0)