Skip to content

Commit

Permalink
tests: bluetooth: tester: Enable and fill BTP_GAP_SET_POWERED command…
Browse files Browse the repository at this point in the history
… Issue-number#67346

[Description] Fill in the empty BTP GAP cmd: Opcode 0x05 - Set Powered command/response, which is used to power on/off a controller per BTP protocol. It will call bt_disable() then HCI close() to shutdown BLE controller, Zephyr bt-tester originally uses Register GAP Service cmd to call bt_enable() then HCI open() to enable BT, so everytime user want to reset BLE/reload BLE FW during use, enter GAP Set Powered OFF cmd(01 05 00 01 00 00) first then Register GAP Service cmd(00 03 ff 01 00 01) is ok.

Signed-off-by: Ying Zhang <[email protected]>
  • Loading branch information
zhaynxp committed Jan 9, 2024
1 parent 4824e40 commit f520dad
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
5 changes: 3 additions & 2 deletions tests/bluetooth/tester/src/btp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/bluetooth/tester/src/btp_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
37 changes: 37 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,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 {

Check warning on line 462 in tests/bluetooth/tester/src/btp_gap.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

UNNECESSARY_ELSE

tests/bluetooth/tester/src/btp_gap.c:462 else is not generally useful after a break or return
atomic_clear_bit(&current_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)
{
Expand Down Expand Up @@ -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),
Expand Down
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 @@ -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;
Expand Down

0 comments on commit f520dad

Please sign in to comment.