Skip to content

Commit

Permalink
bluetooth: tester: Use define for variable length BTP commands
Browse files Browse the repository at this point in the history
This makes code a bit easier to follow.
  • Loading branch information
KKopyscinski committed Jul 26, 2023
1 parent 7b4b78b commit 2a0290c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 28 deletions.
5 changes: 5 additions & 0 deletions apps/bttester/src/btp/bttester.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ tester_rsp_full(uint8_t service, uint8_t opcode, const void *rsp, size_t len);
void
tester_event(uint8_t service, uint8_t opcode, const void *data, size_t len);

/* Used to indicate that command length is variable and that validation will
* be done in handler.
*/
#define BTP_HANDLER_LENGTH_VARIABLE (-1)

struct btp_handler {
uint8_t opcode;
uint8_t index;
Expand Down
4 changes: 2 additions & 2 deletions apps/bttester/src/btp_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GAP_START_ADVERTISING,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = start_advertising,
},
{
Expand Down Expand Up @@ -1886,7 +1886,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GAP_SET_FILTER_ACCEPT_LIST,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = set_filter_accept_list,
},
};
Expand Down
20 changes: 10 additions & 10 deletions apps/bttester/src/btp_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATT_DISC_PRIM_UUID,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = disc_prim_uuid,
},
{
Expand All @@ -1933,7 +1933,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATT_DISC_CHRC_UUID,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = disc_chrc_uuid,
},
{
Expand All @@ -1953,7 +1953,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATT_READ_UUID,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = read_uuid,
},
{
Expand All @@ -1963,34 +1963,34 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATT_READ_MULTIPLE,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = read_multiple,
},
{
.opcode = BTP_GATT_WRITE_WITHOUT_RSP,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = write_without_rsp,
},
#if 0
{
.opcode = BTP_GATT_SIGNED_WRITE_WITHOUT_RSP,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = write_signed_without_rsp,
},
#endif
{
.opcode = BTP_GATT_WRITE,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = write_data,
},
{
.opcode = BTP_GATT_WRITE_LONG,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = write_long,
},
{
.opcode = BTP_GATT_RELIABLE_WRITE,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = reliable_write,
},
{
Expand All @@ -2005,7 +2005,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATT_GET_ATTRIBUTES,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = get_attrs,
},
{
Expand Down
18 changes: 9 additions & 9 deletions apps/bttester/src/btp_gatt_cl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1459,7 +1459,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATTC_DISC_PRIM_UUID,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = disc_prim_uuid,
},
{
Expand All @@ -1474,7 +1474,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATTC_DISC_CHRC_UUID,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = disc_chrc_uuid,
},
{
Expand All @@ -1489,7 +1489,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATTC_READ_UUID,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = read_uuid,
},
{
Expand All @@ -1499,34 +1499,34 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_GATTC_READ_MULTIPLE,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = read_multiple,
},
{
.opcode = BTP_GATTC_WRITE_WITHOUT_RSP,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = write_without_rsp,
},
#if 0
{
.opcode = BTP_GATTC_SIGNED_WRITE_WITHOUT_RSP,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = write_signed_without_rsp,
},
#endif
{
.opcode = BTP_GATTC_WRITE,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = write,
},
{
.opcode = BTP_GATTC_WRITE_LONG,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = write_long,
},
{
.opcode = BTP_GATTC_RELIABLE_WRITE,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = reliable_write,
},
{
Expand Down
4 changes: 2 additions & 2 deletions apps/bttester/src/btp_l2cap.c
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_L2CAP_SEND_DATA,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = send_data,
},
{
Expand All @@ -735,7 +735,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_L2CAP_RECONFIGURE,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = reconfigure,
},
{
Expand Down
10 changes: 5 additions & 5 deletions apps/bttester/src/btp_mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,12 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_MESH_CONFIG_PROVISIONING,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = config_prov,
},
{
.opcode = BTP_MESH_PROVISION_NODE,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = provision_node,
},
{
Expand All @@ -862,7 +862,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_MESH_INPUT_STRING,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = input_string,
},
{
Expand All @@ -887,7 +887,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_MESH_NET_SEND,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = net_send,
},
{
Expand All @@ -902,7 +902,7 @@ static const struct btp_handler handlers[] = {
},
{
.opcode = BTP_MESH_MODEL_SEND,
.expect_len = -1,
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
.func = model_send,
},
{
Expand Down

0 comments on commit 2a0290c

Please sign in to comment.