Skip to content

Commit

Permalink
apps/bttester: Add option to set scannable adv
Browse files Browse the repository at this point in the history
This commit adds handling for
scannable btp command/response.
  • Loading branch information
szymon-czapracki committed Nov 7, 2024
1 parent 12b877e commit 2961fb1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions apps/bttester/src/btp/btp_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct btp_gap_read_controller_index_list_rp {
#define BTP_GAP_SETTINGS_STATIC_ADDRESS 15
#define BTP_GAP_SETTINGS_EXTENDED_ADVERTISING 17
#define BTP_GAP_SETTINGS_PERIODIC_ADVERTISING 18
#define BTP_GAP_SETTINGS_SCANNABLE 19

#define BTP_GAP_READ_CONTROLLER_INFO 0x03
struct btp_gap_read_controller_info_rp {
Expand Down Expand Up @@ -328,6 +329,15 @@ struct gap_periodic_adv_sync_transfer_recv_cmd {
uint16_t sync_timeout;
uint8_t flags;
} __packed;

#define BTP_GAP_SET_SCANNABLE 0x30
struct btp_gap_set_scannable_cmd {
uint8_t scannable;
} __packed;
struct btp_gap_set_scannable_rp {
uint32_t current_settings;
} __packed;

/* events */
#define BTP_GAP_EV_NEW_SETTINGS 0x80
struct btp_gap_new_settings_ev {
Expand Down
33 changes: 33 additions & 0 deletions apps/bttester/src/btp_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,34 @@ set_connectable(const void *cmd, uint16_t cmd_len,
return BTP_STATUS_SUCCESS;
}

static uint8_t
set_scannable(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
{
const struct btp_gap_set_scannable_cmd *cp = cmd;
struct btp_gap_set_scannable_rp *rp = rsp;

SYS_LOG_DBG("")

if (cp->scannable) {
current_settings |= BIT(BTP_GAP_SETTINGS_SCANNABLE);
#if MYNEWT_VAL(BLE_EXT_ADV)
adv_params.scannable = 0;
#endif
} else {
current_settings &= ~BIT(BTP_GAP_SETTINGS_SCANNABLE);
#if MYNEWT_VAL(BLE_EXT_ADV)
adv_params.scannable = 0;
#endif
}

rp->current_settings = htole32(current_settings);

*rsp_len = sizeof(*rp);

return BTP_STATUS_SUCCESS;
}

static uint8_t
set_discoverable(const void *cmd, uint16_t cmd_len,
void *rsp, uint16_t *rsp_len)
Expand Down Expand Up @@ -2261,6 +2289,11 @@ static const struct btp_handler handlers[] = {
.expect_len = sizeof(struct btp_gap_set_connectable_cmd),
.func = set_connectable,
},
{
.opcode = BTP_GAP_SET_SCANNABLE,
.expect_len = sizeof(struct btp_gap_set_scannable_cmd),
.func = set_scannable,
},
{
.opcode = BTP_GAP_SET_DISCOVERABLE,
.expect_len = sizeof(struct btp_gap_set_discoverable_cmd),
Expand Down

0 comments on commit 2961fb1

Please sign in to comment.