From a8781dae81a8e71eb407ab80d197f989297b58cc Mon Sep 17 00:00:00 2001 From: Petri Pitkanen Date: Wed, 3 Sep 2025 09:42:45 +0300 Subject: [PATCH] tests: Bluetooth: Tester: Add support for scan parameters Add new command to set scanning parameters, including scan window, scan interval, and physical interface (1M and coded PHYs). Signed-off-by: Petri Pitkanen --- tests/bluetooth/tester/src/btp/btp_gap.h | 11 ++++++ tests/bluetooth/tester/src/btp_gap.c | 50 +++++++++++++++++++----- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/tests/bluetooth/tester/src/btp/btp_gap.h b/tests/bluetooth/tester/src/btp/btp_gap.h index 924859c461c2d..5226cbb649d57 100644 --- a/tests/bluetooth/tester/src/btp/btp_gap.h +++ b/tests/bluetooth/tester/src/btp/btp_gap.h @@ -138,6 +138,17 @@ struct btp_gap_stop_advertising_rp { #define BTP_GAP_DISCOVERY_FLAG_OWN_ID_ADDR 0x20 #define BTP_GAP_DISCOVERY_FLAG_USE_FILTER_LIST 0x40 +#define BTP_GAP_SET_DISCOVERY_PARAMS 0x2f + +#define BTP_GAP_PHY_LE_1M 0x01 +#define BTP_GAP_PHY_LE_CODED 0x02 +struct btp_gap_set_discovery_params_cmd { + uint16_t interval; + uint16_t window; + uint8_t phy; /* 1M and Coded */ + uint8_t flags; /* For future use */ +} __packed; + #define BTP_GAP_START_DISCOVERY 0x0c struct btp_gap_start_discovery_cmd { uint8_t flags; diff --git a/tests/bluetooth/tester/src/btp_gap.c b/tests/bluetooth/tester/src/btp_gap.c index 1344933eec529..b99ae342b1623 100644 --- a/tests/bluetooth/tester/src/btp_gap.c +++ b/tests/bluetooth/tester/src/btp_gap.c @@ -1196,6 +1196,41 @@ static uint8_t br_start_discovery(const struct btp_gap_start_discovery_cmd *cp) } #endif /* CONFIG_BT_CLASSIC */ +static struct bt_le_scan_param scan_param = { + .type = BT_LE_SCAN_TYPE_PASSIVE, + .options = BT_LE_SCAN_OPT_FILTER_DUPLICATE, + .interval = BT_GAP_SCAN_FAST_INTERVAL, + .window = BT_GAP_SCAN_FAST_WINDOW, + .timeout = 0, + .interval_coded = 0, + .window_coded = 0, +}; + +static uint8_t set_discovery_params(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) +{ + const struct btp_gap_set_discovery_params_cmd *cp = cmd; + + if (cp->interval < 4 || cp->window < 4 || cp->window > cp->interval) { + LOG_ERR("Invalid discovery parameters"); + return BTP_STATUS_FAILED; + } + + /* 1M default we do not need to test for it */ + if (cp->phy & ~(BTP_GAP_PHY_LE_1M | BTP_GAP_PHY_LE_CODED)) { + LOG_ERR("Invalid PHY"); + return BTP_STATUS_FAILED; + } + + scan_param.interval = cp->interval; + scan_param.window = cp->window; + + if (cp->phy & BTP_GAP_PHY_LE_CODED) { + scan_param.options |= BT_LE_SCAN_OPT_CODED; + } + + return BTP_STATUS_SUCCESS; +} + static uint8_t start_discovery(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len) { @@ -1206,16 +1241,6 @@ static uint8_t start_discovery(const void *cmd, uint16_t cmd_len, return br_start_discovery(cp); } - struct bt_le_scan_param scan_param = { - .type = BT_LE_SCAN_TYPE_PASSIVE, - .options = BT_LE_SCAN_OPT_FILTER_DUPLICATE, - .interval = BT_GAP_SCAN_FAST_INTERVAL, - .window = BT_GAP_SCAN_FAST_WINDOW, - .timeout = 0, - .interval_coded = 0, - .window_coded = 0, - }; - if (cp->flags & BTP_GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN) { scan_param.type = BT_LE_SCAN_TYPE_ACTIVE; } @@ -2884,6 +2909,11 @@ static const struct btp_handler handlers[] = { .expect_len = 0, .func = stop_advertising, }, + { + .opcode = BTP_GAP_SET_DISCOVERY_PARAMS, + .expect_len = sizeof(struct btp_gap_set_discovery_params_cmd), + .func = set_discovery_params, + }, { .opcode = BTP_GAP_START_DISCOVERY, .expect_len = sizeof(struct btp_gap_start_discovery_cmd),