Skip to content

Commit 7051733

Browse files
committed
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 <[email protected]>
1 parent 4b39be6 commit 7051733

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

tests/bluetooth/tester/src/btp/btp_gap.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,17 @@ struct btp_gap_stop_advertising_rp {
138138
#define BTP_GAP_DISCOVERY_FLAG_OWN_ID_ADDR 0x20
139139
#define BTP_GAP_DISCOVERY_FLAG_USE_FILTER_LIST 0x40
140140

141+
#define BTP_GAP_SET_DISCOVERY_PARAMS 0x2f
142+
143+
#define BTP_GAP_PHY_LE_1M 0x01
144+
#define BTP_GAP_PHY_LE_CODED 0x02
145+
struct btp_gap_set_discovery_params_cmd {
146+
uint16_t interval;
147+
uint16_t window;
148+
uint8_t phy; /* 1M and Coded */
149+
uint8_t flags; /* For future use */
150+
} __packed;
151+
141152
#define BTP_GAP_START_DISCOVERY 0x0c
142153
struct btp_gap_start_discovery_cmd {
143154
uint8_t flags;

tests/bluetooth/tester/src/btp_gap.c

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,41 @@ static uint8_t br_start_discovery(const struct btp_gap_start_discovery_cmd *cp)
11961196
}
11971197
#endif /* CONFIG_BT_CLASSIC */
11981198

1199+
static struct bt_le_scan_param scan_param = {
1200+
.type = BT_LE_SCAN_TYPE_PASSIVE,
1201+
.options = BT_LE_SCAN_OPT_FILTER_DUPLICATE,
1202+
.interval = BT_GAP_SCAN_FAST_INTERVAL,
1203+
.window = BT_GAP_SCAN_FAST_WINDOW,
1204+
.timeout = 0,
1205+
.interval_coded = 0,
1206+
.window_coded = 0,
1207+
};
1208+
1209+
static uint8_t set_discovery_params(const void *cmd, uint16_t cmd_len, void *rsp, uint16_t *rsp_len)
1210+
{
1211+
const struct btp_gap_set_discovery_params_cmd *cp = cmd;
1212+
1213+
if (cp->interval < 4 || cp->window < 4 || cp->window > cp->interval) {
1214+
LOG_ERR("Invalid discovery parameters");
1215+
return BTP_STATUS_FAILED;
1216+
}
1217+
1218+
/* 1M default we do not need to test for it */
1219+
if (cp->phy & ~(BTP_GAP_PHY_LE_1M | BTP_GAP_PHY_LE_CODED)) {
1220+
LOG_ERR("Invalid PHY");
1221+
return BTP_STATUS_FAILED;
1222+
}
1223+
1224+
scan_param.interval = cp->interval;
1225+
scan_param.window = cp->window;
1226+
1227+
if (cp->phy & BTP_GAP_PHY_LE_CODED) {
1228+
scan_param.options |= BT_LE_SCAN_OPT_CODED;
1229+
}
1230+
1231+
return BTP_STATUS_SUCCESS;
1232+
}
1233+
11991234
static uint8_t start_discovery(const void *cmd, uint16_t cmd_len,
12001235
void *rsp, uint16_t *rsp_len)
12011236
{
@@ -1206,16 +1241,6 @@ static uint8_t start_discovery(const void *cmd, uint16_t cmd_len,
12061241
return br_start_discovery(cp);
12071242
}
12081243

1209-
struct bt_le_scan_param scan_param = {
1210-
.type = BT_LE_SCAN_TYPE_PASSIVE,
1211-
.options = BT_LE_SCAN_OPT_FILTER_DUPLICATE,
1212-
.interval = BT_GAP_SCAN_FAST_INTERVAL,
1213-
.window = BT_GAP_SCAN_FAST_WINDOW,
1214-
.timeout = 0,
1215-
.interval_coded = 0,
1216-
.window_coded = 0,
1217-
};
1218-
12191244
if (cp->flags & BTP_GAP_DISCOVERY_FLAG_LE_ACTIVE_SCAN) {
12201245
scan_param.type = BT_LE_SCAN_TYPE_ACTIVE;
12211246
}
@@ -2884,6 +2909,11 @@ static const struct btp_handler handlers[] = {
28842909
.expect_len = 0,
28852910
.func = stop_advertising,
28862911
},
2912+
{
2913+
.opcode = BTP_GAP_SET_DISCOVERY_PARAMS,
2914+
.expect_len = sizeof(struct btp_gap_set_discovery_params_cmd),
2915+
.func = set_discovery_params,
2916+
},
28872917
{
28882918
.opcode = BTP_GAP_START_DISCOVERY,
28892919
.expect_len = sizeof(struct btp_gap_start_discovery_cmd),

0 commit comments

Comments
 (0)