diff mbox series

[BlueZ,04/10] shared/bap: Allow checking bis caps against peer caps

Message ID 20240716142207.4298-5-iulia.tanasescu@nxp.com
State New
Headers show
Series Initial implementation of BAP Broadcast Assistant | expand

Commit Message

Iulia Tanasescu July 16, 2024, 2:22 p.m. UTC
A BAP Broadcast Assistant needs to match stream capabilities with
capabilities discovered in the Sink PAC characteristic on the peer.

This updates bt_bap_verify_bis to check the provided stream capabilities
against local or remote capabilities, depending on the bap structure
provided:

If the device is acting as a BAP Broadcast Sink and the bap session was
created after scanning a Broadcast Source, the stream caps will be matched
with the local broadcast sink PAC.

If the device is acting as a Broadcast Assistant and the bap session is a
client session with a BAP Scan Delegator, the stream caps will be matched
with the PAC records populated in the rdb at service discovery.
---
 src/shared/bap.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/src/shared/bap.c b/src/shared/bap.c
index d2a500e48..44fb06169 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -6577,7 +6577,7 @@  static void bap_sink_match_allocation(size_t i, uint8_t l, uint8_t t,
 		data->found = false;
 }
 
-static struct bt_ltv_match bap_check_bis(struct bt_bap_db *ldb,
+static struct bt_ltv_match bap_check_bis(uint32_t sink_loc, struct queue *pacs,
 	struct iovec *bis_data)
 {
 	struct bt_ltv_match compare_data = {};
@@ -6588,10 +6588,10 @@  static struct bt_ltv_match bap_check_bis(struct bt_bap_db *ldb,
 	 */
 	compare_data.found = true;
 
-	if (ldb->pacs->sink_loc_value) {
+	if (sink_loc) {
 		uint8_t type = BAP_CHANNEL_ALLOCATION_LTV_TYPE;
 
-		compare_data.data32 = ldb->pacs->sink_loc_value;
+		compare_data.data32 = sink_loc;
 		util_ltv_foreach(bis_data->iov_base, bis_data->iov_len, &type,
 				bap_sink_match_allocation, &compare_data);
 	}
@@ -6600,8 +6600,7 @@  static struct bt_ltv_match bap_check_bis(struct bt_bap_db *ldb,
 	if (compare_data.found) {
 		compare_data.data = bis_data;
 		compare_data.found = false;
-		queue_foreach(ldb->broadcast_sinks, check_local_pac,
-				&compare_data);
+		queue_foreach(pacs, check_local_pac, &compare_data);
 	}
 
 	return compare_data;
@@ -6642,14 +6641,29 @@  void bt_bap_verify_bis(struct bt_bap *bap, uint8_t bis_index,
 		struct bt_bap_pac **lpac)
 {
 	struct bt_ltv_match match_data;
+	uint32_t sink_loc;
+	struct queue *pacs;
 
 	if (!caps)
 		return;
 
+	/* If the bap session corresponds to a client connection with
+	 * a BAP Server, bis caps should be checked against peer caps.
+	 * If the bap session corresponds to a scanned broadcast source,
+	 * bis caps should be checked against local broadcast sink caps.
+	 */
+	if (bap->client) {
+		sink_loc = bap->rdb->pacs->sink_loc_value;
+		pacs = bap->rdb->sinks;
+	} else {
+		sink_loc = bap->ldb->pacs->sink_loc_value;
+		pacs = bap->ldb->broadcast_sinks;
+	}
+
 	/* Check each BIS Codec Specific Configuration LTVs against our Codec
 	 * Specific Capabilities and if the BIS matches create a PAC with it
 	 */
-	match_data = bap_check_bis(bap->ldb, caps);
+	match_data = bap_check_bis(sink_loc, pacs, caps);
 	if (match_data.found == true) {
 		*lpac = match_data.data;
 		DBG(bap, "Matching BIS %i", bis_index);