From f0a4318b06aa4d9434d18bce40d387454e756a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kopy=C5=9Bci=C5=84ski?= Date: Thu, 13 Jul 2023 10:09:14 +0200 Subject: [PATCH] bluetooth: tester: Use define for variable length BTP commands This makes code a bit easier to follow. --- apps/bttester/src/btp/bttester.h | 5 +++++ apps/bttester/src/btp_gap.c | 4 ++-- apps/bttester/src/btp_gatt.c | 20 ++++++++++---------- apps/bttester/src/btp_gatt_cl.c | 18 +++++++++--------- apps/bttester/src/btp_l2cap.c | 4 ++-- apps/bttester/src/btp_mesh.c | 10 +++++----- 6 files changed, 33 insertions(+), 28 deletions(-) diff --git a/apps/bttester/src/btp/bttester.h b/apps/bttester/src/btp/bttester.h index 120e623db3..8e8b98b5ad 100644 --- a/apps/bttester/src/btp/bttester.h +++ b/apps/bttester/src/btp/bttester.h @@ -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; diff --git a/apps/bttester/src/btp_gap.c b/apps/bttester/src/btp_gap.c index 0d3d5e9a60..9201d0f891 100644 --- a/apps/bttester/src/btp_gap.c +++ b/apps/bttester/src/btp_gap.c @@ -1799,7 +1799,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_GAP_START_ADVERTISING, - .expect_len = -1, + .expect_len = BTP_HANDLER_LENGTH_VARIABLE, .func = start_advertising, }, { @@ -1884,7 +1884,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, }, }; diff --git a/apps/bttester/src/btp_gatt.c b/apps/bttester/src/btp_gatt.c index b239b33d06..c80955556d 100644 --- a/apps/bttester/src/btp_gatt.c +++ b/apps/bttester/src/btp_gatt.c @@ -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, }, { @@ -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, }, { @@ -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, }, { @@ -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, }, { @@ -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, }, { diff --git a/apps/bttester/src/btp_gatt_cl.c b/apps/bttester/src/btp_gatt_cl.c index e878bf7a03..6d711b6c68 100644 --- a/apps/bttester/src/btp_gatt_cl.c +++ b/apps/bttester/src/btp_gatt_cl.c @@ -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, }, { @@ -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, }, { @@ -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, }, { @@ -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, }, { diff --git a/apps/bttester/src/btp_l2cap.c b/apps/bttester/src/btp_l2cap.c index 825f123ffc..facd2a9f8a 100644 --- a/apps/bttester/src/btp_l2cap.c +++ b/apps/bttester/src/btp_l2cap.c @@ -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, }, { @@ -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, }, { diff --git a/apps/bttester/src/btp_mesh.c b/apps/bttester/src/btp_mesh.c index d0dc0d4955..66a0551fd5 100644 --- a/apps/bttester/src/btp_mesh.c +++ b/apps/bttester/src/btp_mesh.c @@ -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, }, { @@ -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, }, { @@ -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, }, { @@ -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, }, {