Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nimble/audio/bass: Modify add source operation in BASS #1843

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
/** BLE AUDIO BASS Error: Invalid Source ID */
#define BLE_SVC_AUDIO_BASS_ERR_INVALID_SOURCE_ID 0x81

/** BLE AUDIO BASS ADVERTISING SID MAX VALUE */
#define BLE_SVC_AUDIO_BASS_ADV_SID_MAX_VAL 0x0F

/** BLE AUDIO BASS Encryption States */
enum ble_svc_audio_bass_big_enc {
/** BLE AUDIO BASS BIG Encryption: Not Encrypted */
Expand Down
66 changes: 43 additions & 23 deletions nimble/host/audio/services/bass/src/ble_audio_svc_bass.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,28 @@ ble_svc_audio_bass_remote_scan_started(uint8_t *data, uint16_t data_len, uint16_
return 0;
}

static int
check_bis_sync(uint16_t num_subgroups, const uint32_t *bis_sync_list)
{
uint32_t bis_sync_mask = 0;
int i;
int j;

for (i = 0; i < num_subgroups; i++) {
if (bis_sync_list[i] != 0xFFFFFFFF) {
for (j = 0; j < num_subgroups; j++) {
if (bis_sync_list[i] & bis_sync_mask) {
return BLE_HS_EINVAL;
}

bis_sync_mask |= bis_sync_list[i];
}
}
}

return 0;
}

static int
ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_handle)
{
Expand All @@ -307,9 +329,21 @@ ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_ha
operation.conn_handle = conn_handle;

operation.add_source.adv_addr.type = data[offset++];
if (operation.add_source.adv_addr.type != BLE_ADDR_PUBLIC ||
operation.add_source.adv_addr.type != BLE_ADDR_RANDOM) {
rc = BLE_HS_EINVAL;
ev.bass_operation_status.status = BLE_HS_EINVAL;
goto done;
}
memcpy(operation.add_source.adv_addr.val, &data[offset], 6);
offset += 6;
operation.add_source.adv_sid = data[offset++];
if (operation.add_source.adv_sid > BLE_SVC_AUDIO_BASS_ADV_SID_MAX_VAL) {
rc = BLE_HS_EINVAL;
ev.bass_operation_status.status = BLE_HS_EINVAL;
goto done;
}

operation.add_source.broadcast_id = get_le24(&data[offset]);
offset += 3;
operation.add_source.pa_sync = data[offset++];
Expand Down Expand Up @@ -346,6 +380,13 @@ ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_ha
operation.add_source.subgroups[i].metadata = &data[offset];
offset += operation.add_source.subgroups[i].metadata_length;
data_len -= operation.add_source.subgroups[i].metadata_length;

if (check_bis_sync(operation.add_source.num_subgroups,
operation.add_source.bis_sync)) {
rc = BLE_HS_EINVAL;
ev.bass_operation_status.status = BLE_HS_EREJECT;
goto done;
}
}

source_id_new = ble_svc_audio_bass_get_new_source_id();
Expand Down Expand Up @@ -393,9 +434,10 @@ ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_ha

ev.bass_operation_status.source_id = rcv_state->source_id;
rcv_state->state.source_addr.type = operation.add_source.adv_addr.type;
memcpy(&rcv_state->state.source_addr.type, operation.add_source.adv_addr.val, 6);
memcpy(&rcv_state->state.source_addr.val, operation.add_source.adv_addr.val, 6);
rcv_state->state.source_adv_sid = operation.add_source.adv_sid;
rcv_state->state.broadcast_id = operation.add_source.broadcast_id;
rcv_state->state.num_subgroups = operation.add_source.num_subgroups;

for (i = 0; i < operation.add_source.num_subgroups; i++) {
metadata_ptr = os_memblock_get(&ble_audio_svc_bass_metadata_pool);
Expand Down Expand Up @@ -423,28 +465,6 @@ ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_ha
return rc;
}

static int
check_bis_sync(uint16_t num_subgroups, const uint32_t *bis_sync_list)
{
uint32_t bis_sync_mask = 0;
int i;
int j;

for (i = 0; i < num_subgroups; i++) {
if (bis_sync_list[i] != 0xFFFFFFFF) {
for (j = 0; j < num_subgroups; j++) {
if (bis_sync_list[i] & bis_sync_mask) {
return BLE_HS_EINVAL;
}

bis_sync_mask |= bis_sync_list[i];
}
}
}

return 0;
}

static int
ble_svc_audio_bass_modify_source(uint8_t *data, uint16_t data_len, uint16_t conn_handle)
{
Expand Down
Loading