Skip to content

Commit

Permalink
Bluetooth: tester: Use Unregister GAP Service command to shutdown Blu…
Browse files Browse the repository at this point in the history
…etooth subsystem

Use Unregister GAP Service command to support power off Bluetooth controller as well as cleanup app layer resource.

Fixes #67346

Signed-off-by: Ying Zhang <[email protected]>
  • Loading branch information
zhaynxp committed Jan 11, 2024
1 parent 4824e40 commit 3a94633
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/bluetooth/tester/src/btp.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ void tester_register_command_handlers(uint8_t service,
service_handler[service].num = num;
}

void tester_unregister_command_handlers(uint8_t service)
{
if (service_handler[service].handlers != NULL) {
(void)memset(&service_handler[service], 0, ARRAY_SIZE(service_handler));
}
}

static const struct btp_handler *find_btp_handler(uint8_t service, uint8_t opcode)
{
if ((service > BTP_SERVICE_ID_MAX) ||
Expand Down
1 change: 1 addition & 0 deletions tests/bluetooth/tester/src/btp/bttester.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct btp_handler {
void tester_register_command_handlers(uint8_t service,
const struct btp_handler *handlers,
size_t num);
void tester_unregister_command_handlers(uint8_t service);

uint8_t tester_init_gatt(void);
uint8_t tester_unregister_gatt(void);
Expand Down
74 changes: 73 additions & 1 deletion tests/bluetooth/tester/src/btp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,79 @@ static uint8_t unregister_service(const void *cmd, uint16_t cmd_len,
atomic_clear_bit(registered_services, cp->id);
}

return BTP_STATUS_FAILED;
return status;
}

void unregister_all_services_except_gap(void)
{
for (uint8_t i = BTP_SERVICE_ID_GATT; i <= BTP_SERVICE_ID_MAX; i++) {
atomic_test_and_clear_bit(registered_services, i);
tester_unregister_command_handlers(i);

switch (i) {
case BTP_SERVICE_ID_GATT:
tester_unregister_gatt();
break;
#if defined(CONFIG_BT_L2CAP_DYNAMIC_CHANNEL)
case BTP_SERVICE_ID_L2CAP:
tester_unregister_l2cap();
break;
#endif /* CONFIG_BT_L2CAP_DYNAMIC_CHANNEL */
#if defined(CONFIG_BT_MESH)
case BTP_SERVICE_ID_MESH:
tester_unregister_mesh();
break;
case BTP_SERVICE_ID_MESH_MDL:
tester_unregister_mmdl();
break;
#endif /* CONFIG_BT_MESH */
#if defined(CONFIG_BT_VCP_VOL_REND)
case BTP_SERVICE_ID_VCS:
tester_unregister_vcs();
break;
case BTP_SERVICE_ID_AICS:
tester_unregister_aics();
break;
case BTP_SERVICE_ID_VOCS:
tester_unregister_vocs();
break;
#endif /* CONFIG_BT_VCP_VOL_REND */
#if defined(CONFIG_BT_IAS)
case BTP_SERVICE_ID_IAS:
tester_unregister_ias();
break;
#endif /* CONFIG_BT_IAS */
#if defined(CONFIG_BT_BAP_UNICAST_CLIENT) || defined(CONFIG_BT_BAP_UNICAST_SERVER)
case BTP_SERVICE_ID_PACS:
tester_unregister_pacs();
break;
case BTP_SERVICE_ID_ASCS:
tester_unregister_ascs();
break;
case BTP_SERVICE_ID_BAP:
tester_unregister_bap();
break;
case BTP_SERVICE_ID_MICP:
tester_unregister_micp();
break;
#endif /* CONFIG_BT_BAP_UNICAST_CLIENT or CONFIG_BT_BAP_UNICAST_SERVER */
#if defined(CONFIG_BT_HAS)
case BTP_SERVICE_ID_HAS:
tester_unregister_has();
break;
#endif /* CONFIG_BT_HAS */
#if defined(CONFIG_BT_CSIP_SET_MEMBER)
case BTP_SERVICE_ID_CSIS:
tester_unregister_csis();
break;
#endif /* CONFIG_BT_CSIP_SET_MEMBER */
#if defined(CONFIG_BT_TBS_CLIENT)
case BTP_SERVICE_ID_CCP:
tester_unregister_ccp();
break;
#endif /* CONFIG_BT_TBS_CLIENT */
}
}
}

static const struct btp_handler handlers[] = {
Expand Down
15 changes: 15 additions & 0 deletions tests/bluetooth/tester/src/btp_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,22 @@ uint8_t tester_init_gap(void)
return BTP_STATUS_SUCCESS;
}

/*Unregister GAP service represents shutdown the Bluetooth subsystem*/
uint8_t tester_unregister_gap(void)
{
int err;

bt_conn_cb_unregister(&conn_callbacks);
tester_unregister_command_handlers(BTP_SERVICE_ID_GAP);

extern void unregister_all_services_except_gap(void);
unregister_all_services_except_gap();

err = bt_disable();
if (err < 0) {
LOG_ERR("Unable to disable Bluetooth: %d", err);
return BTP_STATUS_FAILED;
}

return BTP_STATUS_SUCCESS;
}
3 changes: 3 additions & 0 deletions tests/bluetooth/tester/src/btp_gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2608,5 +2608,8 @@ uint8_t tester_init_gatt(void)

uint8_t tester_unregister_gatt(void)
{
if (server_buf) {
net_buf_destroy(server_buf);
}
return BTP_STATUS_SUCCESS;
}

0 comments on commit 3a94633

Please sign in to comment.