Skip to content

Commit 3052891

Browse files
lylezhu2012kartben
authored andcommitted
tests: bluetooth: classic: Add test cases for ATTR ID list feature
Add two optional arguments to shell commands `sdp_client sa_discovery` and `sdp_client ssa_discovery`. The first argument is the beginning of the attribute ID. The second argument is the ending of the attribute ID. If the second argument is omitted, the ending of the attribute ID is 0xffff. Add test case `test_sdp_ssa_discover_multiple_records_with_range` to test the ssa request with attribute ID list. Add test case `test_sdp_sa_discover_multiple_records_with_range` to test the sa request with attribute ID list. Signed-off-by: Lyle Zhu <[email protected]>
1 parent 22346b4 commit 3052891

File tree

2 files changed

+205
-4
lines changed

2 files changed

+205
-4
lines changed

tests/bluetooth/classic/sdp_c/pytest/test_sdp.py

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,73 @@ async def sdp_ssa_discover_multiple_records(hci_port, shell, dut, address) -> No
542542
assert found is True
543543

544544

545+
async def sdp_ssa_discover_multiple_records_with_range(hci_port, shell, dut, address) -> None:
546+
logger.info('<<< SDP Discovery ...')
547+
async with await open_transport_or_link(hci_port) as hci_transport:
548+
device = Device.with_hci(
549+
'Bumble',
550+
Address('F0:F1:F2:F3:F4:F5'),
551+
hci_transport.source,
552+
hci_transport.sink,
553+
)
554+
device.classic_enabled = True
555+
device.le_enabled = False
556+
device.sdp_service_records = SDP_SERVICE_MULTIPLE_RECORDS
557+
with open(f"bumble_hci_{sys._getframe().f_code.co_name}.log", "wb") as snoop_file:
558+
device.host.snooper = BtSnooper(snoop_file)
559+
await device_power_on(device)
560+
await device.send_command(HCI_Write_Page_Timeout_Command(page_timeout=0xFFFF))
561+
562+
target_address = address.split(" ")[0]
563+
logger.info(f'=== Connecting to {target_address}...')
564+
try:
565+
connection = await device.connect(target_address, transport=BT_BR_EDR_TRANSPORT)
566+
logger.info(f'=== Connected to {connection.peer_address}!')
567+
except Exception as e:
568+
logger.error(f'Fail to connect to {target_address}!')
569+
raise e
570+
571+
# Discover SDP Record with range SDP_SERVICE_RECORD_HANDLE_ATTRIBUTE_ID ~
572+
# SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID
573+
shell.exec_command(
574+
f"sdp_client ssa_discovery {BT_L2CAP_PROTOCOL_ID.to_hex_str()} "
575+
f"{SDP_SERVICE_RECORD_HANDLE_ATTRIBUTE_ID} "
576+
f"{SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID}"
577+
)
578+
found, lines = await wait_for_shell_response(dut, "SDP Discovery Done")
579+
logger.info(f'{lines}')
580+
assert found is True
581+
582+
# Discover SDP Record with range SDP_SUPPORTED_FEATURES_ATTRIBUTE_ID ~
583+
# SDP_SUPPORTED_FEATURES_ATTRIBUTE_ID
584+
shell.exec_command(
585+
f"sdp_client ssa_discovery {BT_L2CAP_PROTOCOL_ID.to_hex_str()} "
586+
f"{SDP_SUPPORTED_FEATURES_ATTRIBUTE_ID} "
587+
f"{SDP_SUPPORTED_FEATURES_ATTRIBUTE_ID}"
588+
)
589+
found, lines = await wait_for_shell_response(dut, "SDP Discovery Done")
590+
logger.info(f'{lines}')
591+
assert found is True
592+
593+
# Discover SDP Record with range SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID ~
594+
# 0xffff
595+
shell.exec_command(
596+
f"sdp_client ssa_discovery {BT_L2CAP_PROTOCOL_ID.to_hex_str()} "
597+
f"{SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID} 0xffff"
598+
)
599+
found, lines = await wait_for_shell_response(dut, "SDP Discovery Done")
600+
logger.info(f'{lines}')
601+
assert found is True
602+
603+
# Discover SDP Record with range 0xff00 ~ 0xffff
604+
shell.exec_command(
605+
f"sdp_client ssa_discovery {BT_L2CAP_PROTOCOL_ID.to_hex_str()} 0xff00 0xffff"
606+
)
607+
found, lines = await wait_for_shell_response(dut, "No SDP Record")
608+
logger.info(f'{lines}')
609+
assert found is True
610+
611+
545612
async def sdp_ss_discover_no_record(hci_port, shell, dut, address) -> None:
546613
logger.info('<<< SDP Discovery ...')
547614
async with await open_transport_or_link(hci_port) as hci_transport:
@@ -889,6 +956,69 @@ async def sdp_sa_discover_multiple_records(hci_port, shell, dut, address) -> Non
889956
assert found is True
890957

891958

959+
async def sdp_sa_discover_multiple_records_with_range(hci_port, shell, dut, address) -> None:
960+
logger.info('<<< SDP Discovery ...')
961+
async with await open_transport_or_link(hci_port) as hci_transport:
962+
device = Device.with_hci(
963+
'Bumble',
964+
Address('F0:F1:F2:F3:F4:F5'),
965+
hci_transport.source,
966+
hci_transport.sink,
967+
)
968+
device.classic_enabled = True
969+
device.le_enabled = False
970+
device.sdp_service_records = SDP_SERVICE_MULTIPLE_RECORDS
971+
with open(f"bumble_hci_{sys._getframe().f_code.co_name}.log", "wb") as snoop_file:
972+
device.host.snooper = BtSnooper(snoop_file)
973+
await device_power_on(device)
974+
await device.send_command(HCI_Write_Page_Timeout_Command(page_timeout=0xFFFF))
975+
976+
target_address = address.split(" ")[0]
977+
logger.info(f'=== Connecting to {target_address}...')
978+
try:
979+
connection = await device.connect(target_address, transport=BT_BR_EDR_TRANSPORT)
980+
logger.info(f'=== Connected to {connection.peer_address}!')
981+
except Exception as e:
982+
logger.error(f'Fail to connect to {target_address}!')
983+
raise e
984+
985+
# Discover SDP Record with range SDP_SERVICE_RECORD_HANDLE_ATTRIBUTE_ID ~
986+
# SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID
987+
shell.exec_command(
988+
f"sdp_client sa_discovery 00010003 {SDP_SERVICE_RECORD_HANDLE_ATTRIBUTE_ID} "
989+
f"{SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID}"
990+
)
991+
found, lines = await wait_for_shell_response(dut, "SDP Discovery Done")
992+
logger.info(f'{lines}')
993+
assert found is True
994+
995+
# Discover SDP Record with range SDP_SUPPORTED_FEATURES_ATTRIBUTE_ID ~
996+
# SDP_SUPPORTED_FEATURES_ATTRIBUTE_ID
997+
shell.exec_command(
998+
f"sdp_client sa_discovery 00010003 {SDP_SUPPORTED_FEATURES_ATTRIBUTE_ID} "
999+
f"{SDP_SUPPORTED_FEATURES_ATTRIBUTE_ID}"
1000+
)
1001+
found, lines = await wait_for_shell_response(dut, "SDP Discovery Done")
1002+
logger.info(f'{lines}')
1003+
assert found is True
1004+
1005+
# Discover SDP Record with range SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID ~
1006+
# 0xffff
1007+
shell.exec_command(
1008+
"sdp_client sa_discovery 00010003 "
1009+
f"{SDP_PROTOCOL_DESCRIPTOR_LIST_ATTRIBUTE_ID} 0xffff"
1010+
)
1011+
found, lines = await wait_for_shell_response(dut, "SDP Discovery Done")
1012+
logger.info(f'{lines}')
1013+
assert found is True
1014+
1015+
# Discover SDP Record with range 0xff00 ~ 0xffff
1016+
shell.exec_command("sdp_client sa_discovery 00010003 0xff00 0xffff")
1017+
found, lines = await wait_for_shell_response(dut, "No SDP Record")
1018+
logger.info(f'{lines}')
1019+
assert found is True
1020+
1021+
8921022
async def sdp_ssa_discover_fail(hci_port, shell, dut, address) -> None:
8931023
def on_app_connection_request(self, request) -> None:
8941024
logger.info('Force L2CAP connection failure')
@@ -969,6 +1099,14 @@ def test_sdp_ssa_discover_multiple_records(
9691099
hci, iut_address = sdp_client_dut
9701100
asyncio.run(sdp_ssa_discover_multiple_records(hci, shell, dut, iut_address))
9711101

1102+
def test_sdp_ssa_discover_multiple_records_with_range(
1103+
self, shell: Shell, dut: DeviceAdapter, sdp_client_dut
1104+
):
1105+
"""Test case to request SDP records with range. Multiple SDP record registered."""
1106+
logger.info(f'test_sdp_ssa_discover_multiple_records_with_range {sdp_client_dut}')
1107+
hci, iut_address = sdp_client_dut
1108+
asyncio.run(sdp_ssa_discover_multiple_records_with_range(hci, shell, dut, iut_address))
1109+
9721110
def test_sdp_ss_discover_no_record(self, shell: Shell, dut: DeviceAdapter, sdp_client_dut):
9731111
"""Test case to request SDP records. No SDP record registered."""
9741112
logger.info(f'test_sdp_ss_discover_no_record {sdp_client_dut}')
@@ -1021,6 +1159,14 @@ def test_sdp_sa_discover_multiple_records(
10211159
hci, iut_address = sdp_client_dut
10221160
asyncio.run(sdp_sa_discover_multiple_records(hci, shell, dut, iut_address))
10231161

1162+
def test_sdp_sa_discover_multiple_records_with_range(
1163+
self, shell: Shell, dut: DeviceAdapter, sdp_client_dut
1164+
):
1165+
"""Test case to request SDP records with range. Multiple SDP record registered."""
1166+
logger.info(f'test_sdp_sa_discover_multiple_records_with_range {sdp_client_dut}')
1167+
hci, iut_address = sdp_client_dut
1168+
asyncio.run(sdp_sa_discover_multiple_records_with_range(hci, shell, dut, iut_address))
1169+
10241170
def test_sdp_ssa_discover_fail(self, shell: Shell, dut: DeviceAdapter, sdp_client_dut):
10251171
"""Test case to request SDP records. but the L2CAP connecting fail."""
10261172
logger.info(f'test_sdp_ssa_discover_fail {sdp_client_dut}')

tests/bluetooth/classic/sdp_c/src/sdp_client.c

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,12 @@ static uint8_t sdp_discover_func(struct bt_conn *conn, struct bt_sdp_client_resu
166166
return BT_SDP_DISCOVER_UUID_CONTINUE;
167167
}
168168

169+
static struct bt_sdp_attribute_id_list attr_ids;
170+
static struct bt_sdp_attribute_id_range attr_id_ranges[1];
171+
169172
static int cmd_ssa_discovery(const struct shell *sh, size_t argc, char *argv[])
170173
{
171-
int err;
174+
int err = 0;
172175
size_t len;
173176
uint8_t uuid128[BT_UUID_SIZE_128];
174177

@@ -198,9 +201,33 @@ static int cmd_ssa_discovery(const struct shell *sh, size_t argc, char *argv[])
198201
return -ENOEXEC;
199202
}
200203

204+
attr_ids.count = 0;
205+
206+
if (argc > 2) {
207+
attr_ids.count = ARRAY_SIZE(attr_id_ranges);
208+
attr_ids.ranges = attr_id_ranges;
209+
attr_id_ranges[0].beginning = (uint16_t)shell_strtol(argv[2], 0, &err);
210+
if (err < 0) {
211+
shell_error(sh, "Invalid beginning ATTR ID");
212+
return -ENOEXEC;
213+
}
214+
attr_id_ranges[0].ending = 0xffff;
215+
}
216+
217+
if (argc > 3) {
218+
attr_id_ranges[0].ending = (uint16_t)shell_strtol(argv[3], 0, &err);
219+
if (err < 0) {
220+
shell_error(sh, "Invalid ending ATTR ID");
221+
return -ENOEXEC;
222+
}
223+
}
224+
201225
sdp_discover.func = sdp_discover_func;
202226
sdp_discover.pool = &sdp_client_pool;
203227
sdp_discover.type = BT_SDP_DISCOVER_SERVICE_SEARCH_ATTR;
228+
if (attr_ids.count != 0) {
229+
sdp_discover.ids = &attr_ids;
230+
}
204231

205232
err = bt_sdp_discover(default_conn, &sdp_discover);
206233
if (err) {
@@ -256,7 +283,7 @@ static int cmd_ss_discovery(const struct shell *sh, size_t argc, char *argv[])
256283

257284
static int cmd_sa_discovery(const struct shell *sh, size_t argc, char *argv[])
258285
{
259-
int err;
286+
int err = 0;
260287
size_t len;
261288
uint32_t handle;
262289

@@ -270,9 +297,33 @@ static int cmd_sa_discovery(const struct shell *sh, size_t argc, char *argv[])
270297
return -ENOEXEC;
271298
}
272299

300+
attr_ids.count = 0;
301+
302+
if (argc > 2) {
303+
attr_ids.count = ARRAY_SIZE(attr_id_ranges);
304+
attr_ids.ranges = attr_id_ranges;
305+
attr_id_ranges[0].beginning = (uint16_t)shell_strtol(argv[2], 0, &err);
306+
if (err < 0) {
307+
shell_error(sh, "Invalid beginning ATTR ID");
308+
return -ENOEXEC;
309+
}
310+
attr_id_ranges[0].ending = 0xffff;
311+
}
312+
313+
if (argc > 3) {
314+
attr_id_ranges[0].ending = (uint16_t)shell_strtol(argv[3], 0, &err);
315+
if (err < 0) {
316+
shell_error(sh, "Invalid ending ATTR ID");
317+
return -ENOEXEC;
318+
}
319+
}
320+
273321
sdp_discover.func = sdp_discover_func;
274322
sdp_discover.pool = &sdp_client_pool;
275323
sdp_discover.type = BT_SDP_DISCOVER_SERVICE_ATTR;
324+
if (attr_ids.count != 0) {
325+
sdp_discover.ids = &attr_ids;
326+
}
276327

277328
err = bt_sdp_discover(default_conn, &sdp_discover);
278329
if (err) {
@@ -311,10 +362,14 @@ static int cmd_ssa_discovery_fail(const struct shell *sh, size_t argc, char *arg
311362
return 0;
312363
}
313364

365+
#define HELP_ATTR_ID_LIST " [start] [end]"
366+
314367
SHELL_STATIC_SUBCMD_SET_CREATE(sdp_client_cmds,
315368
SHELL_CMD_ARG(ss_discovery, NULL, "<Big endian UUID>", cmd_ss_discovery, 2, 0),
316-
SHELL_CMD_ARG(sa_discovery, NULL, "<Service Record Handle>", cmd_sa_discovery, 2, 0),
317-
SHELL_CMD_ARG(ssa_discovery, NULL, "<Big endian UUID>", cmd_ssa_discovery, 2, 0),
369+
SHELL_CMD_ARG(sa_discovery, NULL, "<Service Record Handle>" HELP_ATTR_ID_LIST,
370+
cmd_sa_discovery, 2, 2),
371+
SHELL_CMD_ARG(ssa_discovery, NULL, "<Big endian UUID>" HELP_ATTR_ID_LIST,
372+
cmd_ssa_discovery, 2, 2),
318373
SHELL_CMD_ARG(ssa_discovery_fail, NULL, "", cmd_ssa_discovery_fail, 1, 0),
319374
SHELL_SUBCMD_SET_END
320375
);

0 commit comments

Comments
 (0)