From 2445e55cd4ddaa2b3863bdedb4dca520a93e1b93 Mon Sep 17 00:00:00 2001 From: Pavel Vasilyev Date: Wed, 4 Oct 2023 15:29:10 +0200 Subject: [PATCH] tests: bluetooth: tester: Move bt_mesh_init call to BTP_MESH_INIT cmd In some RPR tests we need to pass alternative composition data when testing CDP128. When bt_mesh_init is called from mesh service registration callback, we can't pass any arguments. Therefore we need to move bt_mesh_init call out from mesh service registration to BTP_MESH_INIT command. Signed-off-by: Pavel Vasilyev --- tests/bluetooth/tester/src/btp/btp_mesh.h | 4 +++ tests/bluetooth/tester/src/btp_mesh.c | 32 ++++++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_mesh.h b/tests/bluetooth/tester/src/btp/btp_mesh.h index 826f0fd0408..bb26524246e 100644 --- a/tests/bluetooth/tester/src/btp/btp_mesh.h +++ b/tests/bluetooth/tester/src/btp/btp_mesh.h @@ -77,6 +77,10 @@ struct btp_mesh_provision_node_cmd_v2 { } __packed; #define BTP_MESH_INIT 0x04 +struct btp_mesh_init_cmd { + bool comp_alt; +} __packed; + #define BTP_MESH_RESET 0x05 #define BTP_MESH_INPUT_NUMBER 0x06 struct btp_mesh_input_number_cmd { diff --git a/tests/bluetooth/tester/src/btp_mesh.c b/tests/bluetooth/tester/src/btp_mesh.c index 44ace086c69..6a180fcb6d1 100644 --- a/tests/bluetooth/tester/src/btp_mesh.c +++ b/tests/bluetooth/tester/src/btp_mesh.c @@ -1242,8 +1242,24 @@ static uint8_t provision_adv(const void *cmd, uint16_t cmd_len, static uint8_t init(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { + const struct btp_mesh_init_cmd *cp = cmd; int err; + if (!cp->comp_alt) { + LOG_WRN("Loading default comp data"); + err = bt_mesh_init(&prov, &comp); + } else { + LOG_WRN("Loading alternative comp data"); +#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV + health_srv.metadata = health_srv_meta_alt; +#endif + err = bt_mesh_init(&prov, &comp_alt); + } + + if (err) { + return BTP_STATUS_FAILED; + } + LOG_DBG(""); if (IS_ENABLED(CONFIG_BT_SETTINGS)) { @@ -4403,7 +4419,7 @@ static const struct btp_handler handlers[] = { }, { .opcode = BTP_MESH_INIT, - .expect_len = 0, + .expect_len = sizeof(struct btp_mesh_init_cmd), .func = init, }, { @@ -5208,26 +5224,12 @@ BT_MESH_LPN_CB_DEFINE(lpn_cb) = { uint8_t tester_init_mesh(void) { - int err; - if (IS_ENABLED(CONFIG_BT_TESTING)) { bt_test_cb_register(&bt_test_cb); } tester_register_command_handlers(BTP_SERVICE_ID_MESH, handlers, ARRAY_SIZE(handlers)); - if (default_comp) { - err = bt_mesh_init(&prov, &comp); - } else { -#ifdef CONFIG_BT_MESH_LARGE_COMP_DATA_SRV - health_srv.metadata = health_srv_meta_alt; -#endif - err = bt_mesh_init(&prov, &comp_alt); - } - - if (err) { - return BTP_STATUS_FAILED; - } return BTP_STATUS_SUCCESS; }