From 222abd4a5cf030ed1dcd127b572273eab5668e78 Mon Sep 17 00:00:00 2001 From: Szymon Czapracki Date: Mon, 23 Sep 2024 14:29:45 +0200 Subject: [PATCH] nimble/audio: Add subgroups information for modify operation This commit adds subgroups info for modify source operation. Now metadata field can be handled in scan delegator during modify procedure. --- .../services/bass/ble_audio_svc_bass.h | 2 - .../services/bass/src/ble_audio_svc_bass.c | 49 +++++++++---------- .../host/audio/src/ble_audio_scan_delegator.c | 5 +- 3 files changed, 27 insertions(+), 29 deletions(-) diff --git a/nimble/host/audio/services/bass/include/services/bass/ble_audio_svc_bass.h b/nimble/host/audio/services/bass/include/services/bass/ble_audio_svc_bass.h index 48f1a53232..873ac7ae62 100644 --- a/nimble/host/audio/services/bass/include/services/bass/ble_audio_svc_bass.h +++ b/nimble/host/audio/services/bass/include/services/bass/ble_audio_svc_bass.h @@ -327,8 +327,6 @@ struct ble_svc_audio_bass_operation { /** Number of subgroups */ uint16_t num_subgroups; - /** BIS Synchronisation of subgroups */ - uint32_t bis_sync[BLE_SVC_AUDIO_BASS_SUB_NUM_MAX]; /** Subgroup entries */ struct ble_svc_audio_bass_subgroup subgroups[BLE_SVC_AUDIO_BASS_SUB_NUM_MAX]; diff --git a/nimble/host/audio/services/bass/src/ble_audio_svc_bass.c b/nimble/host/audio/services/bass/src/ble_audio_svc_bass.c index cc4805f951..e3cecb060e 100644 --- a/nimble/host/audio/services/bass/src/ble_audio_svc_bass.c +++ b/nimble/host/audio/services/bass/src/ble_audio_svc_bass.c @@ -282,28 +282,6 @@ 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) { @@ -382,7 +360,7 @@ ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_ha data_len -= operation.add_source.subgroups[i].metadata_length; if (check_bis_sync(operation.add_source.num_subgroups, - operation.add_source.bis_sync)) { + operation.add_source.subgroups)) { rc = BLE_HS_EINVAL; ev.bass_operation_status.status = BLE_HS_EREJECT; goto done; @@ -466,6 +444,27 @@ ble_svc_audio_bass_add_source(uint8_t *data, uint16_t data_len, uint16_t conn_ha } static int +check_bis_sync(uint16_t num_subgroups, struct ble_svc_audio_bass_subgroup *subgroups) +{ + uint32_t bis_sync_mask = 0; + int i; + int j; + + for (i = 0; i < num_subgroups; i++) { + if (subgroups[i].bis_sync != 0xFFFFFFFF) { + for (j = 0; j < num_subgroups; j++) { + if (subgroups[i].bis_sync & bis_sync_mask) { + return BLE_HS_EINVAL; + } + + bis_sync_mask |= subgroups[i].bis_sync; + } + } + } + + return 0; +} + ble_svc_audio_bass_modify_source(uint8_t *data, uint16_t data_len, uint16_t conn_handle) { struct ble_svc_audio_bass_operation operation; @@ -517,7 +516,7 @@ ble_svc_audio_bass_modify_source(uint8_t *data, uint16_t data_len, uint16_t conn } for (i = 0; i < operation.modify_source.num_subgroups; i++) { - operation.modify_source.bis_sync[i] = get_le32(&data[offset]); + operation.modify_source.subgroups.bis_sync[i] = get_le32(&data[offset]); offset += 4; operation.modify_source.subgroups[i].metadata_length = data[offset++]; data_len -= 5; @@ -532,7 +531,7 @@ ble_svc_audio_bass_modify_source(uint8_t *data, uint16_t data_len, uint16_t conn } if (check_bis_sync(operation.modify_source.num_subgroups, - operation.modify_source.bis_sync)) { + operation.modify_source.subgroups)) { rc = BLE_HS_EINVAL; ev.bass_operation_status.status = BLE_HS_EREJECT; goto done; diff --git a/nimble/host/audio/src/ble_audio_scan_delegator.c b/nimble/host/audio/src/ble_audio_scan_delegator.c index 60e04adc36..08a5ac645d 100644 --- a/nimble/host/audio/src/ble_audio_scan_delegator.c +++ b/nimble/host/audio/src/ble_audio_scan_delegator.c @@ -197,8 +197,9 @@ bass_modify_source_op_handler(struct ble_svc_audio_bass_operation *op, void *arg BLE_AUDIO_DBG_ASSERT(sync_opt->num_subgroups < ARRAY_SIZE(sync_opt->subgroups)); for (uint8_t i = 0; i < sync_opt->num_subgroups; i++) { - sync_opt->subgroups[i].bis_sync = op->modify_source.bis_sync[i]; - /* FIXME: Missing metadata in Modify Source */ + sync_opt->subgroups[i].bis_sync = op->modify_source.subgroups[i].bis_sync_state; + sync_opt->subgroups[i].metadata_length = op->modify_source.subgroups[i].metadata_length; + sync_opt->subgroups[i].metadata = op->modify_source.subgroups[i].metadata; } action.type = BLE_AUDIO_SCAN_DELEGATOR_ACTION_SOURCE_MODIFY;