diff --git a/tests/bluetooth/tester/src/btp.c b/tests/bluetooth/tester/src/btp.c index 60f3bc1cbbdf268..063c1a6ed0a2362 100644 --- a/tests/bluetooth/tester/src/btp.c +++ b/tests/bluetooth/tester/src/btp.c @@ -63,8 +63,9 @@ void tester_register_command_handlers(uint8_t service, size_t num) { __ASSERT_NO_MSG(service <= BTP_SERVICE_ID_MAX); - __ASSERT_NO_MSG(service_handler[service].handlers == NULL); - + if (service_handler[service].handlers != NULL) { + (void)memset(&service_handler[service], 0, ARRAY_SIZE(service_handler)); + } service_handler[service].handlers = handlers; service_handler[service].num = num; } diff --git a/tests/bluetooth/tester/src/btp_core.c b/tests/bluetooth/tester/src/btp_core.c index b76bd8841057b68..37a2284a905db45 100644 --- a/tests/bluetooth/tester/src/btp_core.c +++ b/tests/bluetooth/tester/src/btp_core.c @@ -28,7 +28,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_BTTESTER_LOG_LEVEL); #include "btp/btp.h" -static ATOMIC_DEFINE(registered_services, BTP_SERVICE_ID_MAX); +ATOMIC_DEFINE(registered_services, BTP_SERVICE_ID_MAX); static uint8_t supported_commands(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index 93958720d300b4b..f4c931e8dc4569e 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -449,6 +449,38 @@ static uint8_t set_oob_sc_remote_data(const void *cmd, uint16_t cmd_len, } #endif /* !defined(CONFIG_BT_SMP_OOB_LEGACY_PAIR_ONLY) */ +static uint8_t set_powered(const void *cmd, uint16_t cmd_len, + void *rsp, uint16_t *rsp_len) +{ + const struct btp_gap_set_powered_cmd *cp = cmd; + struct btp_gap_set_powered_rp *rp = rsp; + int err; + + if (cp->powered) { + LOG_ERR("Please Register GAP Service to enable Bluetooth!"); + return BTP_STATUS_FAILED; + } else { + atomic_clear_bit(¤t_settings, BTP_GAP_SETTINGS_POWERED); + extern ATOMIC_DEFINE(registered_services, BTP_SERVICE_ID_MAX); + for (uint8_t i = 1; i <= BTP_SERVICE_ID_MAX; i++) { + atomic_test_and_clear_bit(registered_services, i); + } + bt_conn_cb_unregister(&conn_callbacks); + + err = bt_disable(); + if (err < 0) { + LOG_ERR("Unable to disable Bluetooth: %d", err); + return BTP_STATUS_FAILED; + } + } + + rp->current_settings = sys_cpu_to_le32(current_settings); + + *rsp_len = sizeof(*rp); + + return BTP_STATUS_SUCCESS; +} + static uint8_t set_connectable(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -1684,6 +1716,11 @@ static const struct btp_handler handlers[] = { .expect_len = 0, .func = controller_info, }, + { + .opcode = BTP_GAP_SET_POWERED, + .expect_len = sizeof(struct btp_gap_set_powered_cmd), + .func = set_powered, + }, { .opcode = BTP_GAP_SET_CONNECTABLE, .expect_len = sizeof(struct btp_gap_set_connectable_cmd), diff --git a/tests/bluetooth/tester/src/btp_gatt.c b/tests/bluetooth/tester/src/btp_gatt.c index f1a656c435f0451..da8e639c5b52f3f 100644 --- a/tests/bluetooth/tester/src/btp_gatt.c +++ b/tests/bluetooth/tester/src/btp_gatt.c @@ -2593,6 +2593,9 @@ static const struct btp_handler handlers[] = { uint8_t tester_init_gatt(void) { + if (server_buf) { + net_buf_destroy(server_buf); + } server_buf = net_buf_alloc(&server_pool, K_NO_WAIT); if (!server_buf) { return BTP_STATUS_FAILED;