Skip to content

Commit 34151b6

Browse files
committed
tests: Bluetooth: Tester: Audio: Adds BRS
This commit adds API to tester to allow exposing of Broadcast Receive State. Signed-off-by: Omkar Kulkarni <[email protected]>
1 parent 0e7ad53 commit 34151b6

File tree

5 files changed

+94
-0
lines changed

5 files changed

+94
-0
lines changed

subsys/bluetooth/audio/bap_scan_delegator.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,6 +1620,7 @@ int bt_bap_scan_delegator_add_src(const struct bt_bap_scan_delegator_add_src_par
16201620
state->pa_sync_state = param->pa_state;
16211621
state->encrypt_state = param->encrypt_state;
16221622
state->num_subgroups = param->num_subgroups;
1623+
state->encrypt_state = param->encrypt_state;
16231624
if (state->num_subgroups > 0U) {
16241625
(void)memcpy(state->subgroups, param->subgroups,
16251626
sizeof(state->subgroups));

tests/bluetooth/tester/src/audio/btp/btp_bap.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,19 @@ struct btp_bap_broadcast_source_setup_v2_rp {
202202
uint32_t gap_settings;
203203
} __packed;
204204

205+
#define BTP_BAP_SCAN_DELEGATOR_ADD_SRC 0x1a
206+
struct btp_bap_scan_delegator_add_src_cmd {
207+
bt_addr_le_t broadcaster_address;
208+
uint8_t advertiser_sid;
209+
uint8_t broadcast_id[BT_AUDIO_BROADCAST_ID_SIZE];
210+
uint8_t big_encryption;
211+
uint8_t num_subgroups;
212+
uint8_t subgroups[];
213+
} __packed;
214+
struct btp_bap_scan_delegator_add_src_rp {
215+
uint8_t src_id;
216+
} __packed;
217+
205218
/* BAP events */
206219
#define BTP_BAP_EV_DISCOVERY_COMPLETED 0x80
207220
struct btp_bap_discovery_completed_ev {

tests/bluetooth/tester/src/audio/btp_bap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,11 @@ static const struct btp_handler bap_handlers[] = {
474474
.expect_len = sizeof(struct btp_bap_send_past_cmd),
475475
.func = btp_bap_broadcast_assistant_send_past,
476476
},
477+
{
478+
.opcode = BTP_BAP_SCAN_DELEGATOR_ADD_SRC,
479+
.expect_len = BTP_HANDLER_LENGTH_VARIABLE,
480+
.func = btp_bap_scan_delegator_add_src,
481+
},
477482
#endif /* CONFIG_BT_BAP_BROADCAST_SOURCE || CONFIG_BT_BAP_BROADCAST_SINK */
478483
};
479484

tests/bluetooth/tester/src/audio/btp_bap_broadcast.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,79 @@ uint8_t btp_bap_broadcast_assistant_send_past(const void *cmd, uint16_t cmd_len,
18331833
return BTP_STATUS_SUCCESS;
18341834
}
18351835

1836+
uint8_t btp_bap_scan_delegator_add_src(const void *cmd, uint16_t cmd_len, void *rsp,
1837+
uint16_t *rsp_len)
1838+
{
1839+
const struct btp_bap_scan_delegator_add_src_cmd *cp = cmd;
1840+
struct btp_bap_scan_delegator_add_src_rp *rp = rsp;
1841+
struct bt_bap_scan_delegator_add_src_param param = {0};
1842+
const uint8_t *ptr;
1843+
size_t remaining;
1844+
int err;
1845+
1846+
if (cmd_len < sizeof(*cp)) {
1847+
return BTP_STATUS_FAILED;
1848+
}
1849+
1850+
if (cp->num_subgroups > CONFIG_BT_BAP_BASS_MAX_SUBGROUPS) {
1851+
return BTP_STATUS_FAILED;
1852+
}
1853+
1854+
bt_addr_le_copy(&param.addr, &cp->broadcaster_address);
1855+
param.sid = cp->advertiser_sid;
1856+
param.encrypt_state = (enum bt_bap_big_enc_state)cp->big_encryption;
1857+
param.broadcast_id = sys_get_le24(cp->broadcast_id);
1858+
param.num_subgroups = cp->num_subgroups;
1859+
1860+
ptr = cp->subgroups;
1861+
remaining = cmd_len - sizeof(*cp);
1862+
for (uint8_t i = 0; i < param.num_subgroups; i++) {
1863+
struct bt_bap_bass_subgroup *subgroup = &param.subgroups[i];
1864+
uint32_t bis_sync;
1865+
1866+
if (remaining < sizeof(uint32_t) + sizeof(uint8_t)) {
1867+
return BTP_STATUS_FAILED;
1868+
}
1869+
1870+
bis_sync = sys_get_le32(ptr);
1871+
ptr += sizeof(uint32_t);
1872+
remaining -= sizeof(uint32_t);
1873+
1874+
if (bis_sync == BT_BAP_BIS_SYNC_NO_PREF) {
1875+
subgroup->bis_sync = bis_sync;
1876+
} else {
1877+
subgroup->bis_sync = bis_sync << 1;
1878+
}
1879+
1880+
subgroup->metadata_len = *ptr;
1881+
ptr += sizeof(uint8_t);
1882+
remaining -= sizeof(uint8_t);
1883+
1884+
if (subgroup->metadata_len > sizeof(subgroup->metadata) ||
1885+
subgroup->metadata_len > remaining) {
1886+
return BTP_STATUS_FAILED;
1887+
}
1888+
1889+
memcpy(subgroup->metadata, ptr, subgroup->metadata_len);
1890+
ptr += subgroup->metadata_len;
1891+
remaining -= subgroup->metadata_len;
1892+
}
1893+
1894+
if (remaining != 0U) {
1895+
return BTP_STATUS_FAILED;
1896+
}
1897+
1898+
err = bt_bap_scan_delegator_add_src(&param);
1899+
if (err < 0) {
1900+
return BTP_STATUS_VAL(err);
1901+
}
1902+
1903+
rp->src_id = (uint8_t)err;
1904+
*rsp_len = sizeof(*rp);
1905+
1906+
return BTP_STATUS_SUCCESS;
1907+
}
1908+
18361909
static bool broadcast_inited;
18371910

18381911
int btp_bap_broadcast_init(void)

tests/bluetooth/tester/src/audio/btp_bap_broadcast.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,5 @@ uint8_t btp_bap_broadcast_assistant_set_broadcast_code(const void *cmd, uint16_t
120120
void *rsp, uint16_t *rsp_len);
121121
uint8_t btp_bap_broadcast_assistant_send_past(const void *cmd, uint16_t cmd_len,
122122
void *rsp, uint16_t *rsp_len);
123+
uint8_t btp_bap_scan_delegator_add_src(const void *cmd, uint16_t cmd_len,
124+
void *rsp, uint16_t *rsp_len);

0 commit comments

Comments
 (0)