Skip to content

Commit

Permalink
Bluetooth: tester: Add support for BTP_GAP_SET_POWERED command
Browse files Browse the repository at this point in the history
Fill BTP_GAP_SET_POWERED command to support power on/off BT controller

Fixes: #67346

Signed-off-by: Ying Zhang <[email protected]>
  • Loading branch information
zhaynxp committed Mar 6, 2024
1 parent 4824e40 commit 9bba095
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/bluetooth/tester/src/btp_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,37 @@ 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) {
err = bt_enable(NULL);
if (err < 0) {
LOG_ERR("Unable to enable Bluetooth: %d", err);
return BTP_STATUS_FAILED;
}
bt_conn_cb_register(&conn_callbacks);
atomic_set_bit(&current_settings, BTP_GAP_SETTINGS_POWERED);
} else {
err = bt_disable();
if (err < 0) {
LOG_ERR("Unable to disable Bluetooth: %d", err);
return BTP_STATUS_FAILED;
}
bt_conn_cb_unregister(&conn_callbacks);
atomic_clear_bit(&current_settings, BTP_GAP_SETTINGS_POWERED);
}
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)
{
Expand Down Expand Up @@ -1684,6 +1715,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),
Expand Down

0 comments on commit 9bba095

Please sign in to comment.