diff mbox series

[BlueZ,v2,8/9] shared/bap: support client-only case

Message ID e06482dca2dc887b224c94d8ab5e82d6561be06a.1676112710.git.pav@iki.fi (mailing list archive)
State New, archived
Headers show
Series [BlueZ,v2,1/9] doc: remove unimplemented Quality Report from MGMT settings | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint fail WARNING: I3 - ignore-body-lines: gitlint will be switching from using Python regex 'match' (match beginning) to 'search' (match anywhere) semantics. Please review your ignore-body-lines.regex option accordingly. To remove this warning, set general.regex-style-search=True. More details: https://jorisroovers.github.io/gitlint/configuration/#regex-style-search 19: B2 Line has trailing whitespace: " " 23: B2 Line has trailing whitespace: " "
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Pauli Virtanen Feb. 11, 2023, 10:53 a.m. UTC
When client-only, skip registering ASCS and PACS in the local GATT DB.

The data structures used to track the local ASE & PAC registrations and
ASE state are then also not needed, and are set to NULL in this case.

In this case, local "endpoints" exist only in the form of locally added
bt_bap_pac PAC data. These usually are in 1-to-1 correspondence with the
Media1 API endpoints registered by media applications.
---

Notes:
    v2:
    * Use named boolean flag for client-only in bt_bap_db instead of just
      NULL field values, maybe makes the intent a bit clearer.
    * Add bt_bap_set_client_only for setting the client-only flag on
      databases, instead of exposing bt_bap_db.
    
    The client-only state cannot be indicated to bt_bap_new by passing in
    ldb==NULL, because the local PACs are in the ldb and we need to know
    which adapter the bt_bap is for.
    
    So instead use a separate function that sets the flag. It cannot make
    already peripheral-enabled DB client-only (currently), but this is not
    needed now, and maybe not in the future either.

 src/shared/bap.c | 42 +++++++++++++++++++++++++++++++++---------
 src/shared/bap.h |  2 ++
 2 files changed, 35 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 22f2e6714..e85815d8d 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -109,6 +109,7 @@  struct bt_ascs {
 };
 
 struct bt_bap_db {
+	bool client_only;
 	struct gatt_db *db;
 	struct bt_pacs *pacs;
 	struct bt_ascs *ascs;
@@ -620,7 +621,7 @@  static struct bt_bap_endpoint *bap_get_endpoint(struct bt_bap_db *db,
 {
 	struct bt_bap_endpoint *ep;
 
-	if (!db || !attr)
+	if (!db || !attr || db->client_only)
 		return NULL;
 
 	ep = queue_find(db->endpoints, bap_endpoint_match, attr);
@@ -652,7 +653,7 @@  static struct bt_bap_endpoint *bap_get_endpoint_id(struct bt_bap *bap,
 	struct gatt_db_attribute *attr = NULL;
 	size_t i;
 
-	if (!bap || !db)
+	if (!bap || !db || db->client_only)
 		return NULL;
 
 	ep = queue_find(db->endpoints, bap_endpoint_match_id, UINT_TO_PTR(id));
@@ -2170,7 +2171,7 @@  static struct bt_ascs *ascs_new(struct gatt_db *db)
 	return ascs;
 }
 
-static struct bt_bap_db *bap_db_new(struct gatt_db *db)
+static struct bt_bap_db *bap_db_new(struct gatt_db *db, bool client_only)
 {
 	struct bt_bap_db *bdb;
 
@@ -2178,19 +2179,23 @@  static struct bt_bap_db *bap_db_new(struct gatt_db *db)
 		return NULL;
 
 	bdb = new0(struct bt_bap_db, 1);
+	bdb->client_only = client_only;
 	bdb->db = gatt_db_ref(db);
 	bdb->sinks = queue_new();
 	bdb->sources = queue_new();
-	bdb->endpoints = queue_new();
 
 	if (!bap_db)
 		bap_db = queue_new();
 
-	bdb->pacs = pacs_new(db);
-	bdb->pacs->bdb = bdb;
+	if (!client_only) {
+		bdb->endpoints = queue_new();
+
+		bdb->pacs = pacs_new(db);
+		bdb->pacs->bdb = bdb;
 
-	bdb->ascs = ascs_new(db);
-	bdb->ascs->bdb = bdb;
+		bdb->ascs = ascs_new(db);
+		bdb->ascs->bdb = bdb;
+	}
 
 	queue_push_tail(bap_db, bdb);
 
@@ -2205,7 +2210,20 @@  static struct bt_bap_db *bap_get_db(struct gatt_db *db)
 	if (bdb)
 		return bdb;
 
-	return bap_db_new(db);
+	return bap_db_new(db, false);
+}
+
+int bt_bap_set_client_only(struct gatt_db *db)
+{
+	struct bt_bap_db *bdb;
+
+	bdb = queue_find(bap_db, bap_db_match, db);
+	if (bdb)
+		return bdb->client_only ? 0 : -EINVAL;
+
+	bap_db_new(db, true);
+
+	return 0;
 }
 
 static struct bt_pacs *bap_get_pacs(struct bt_bap *bap)
@@ -2328,6 +2346,9 @@  static void bap_add_sink(struct bt_bap_pac *pac)
 
 	queue_push_tail(pac->bdb->sinks, pac);
 
+	if (pac->bdb->client_only)
+		return;
+
 	memset(value, 0, sizeof(value));
 
 	iov.iov_base = value;
@@ -2346,6 +2367,9 @@  static void bap_add_source(struct bt_bap_pac *pac)
 
 	queue_push_tail(pac->bdb->sources, pac);
 
+	if (pac->bdb->client_only)
+		return;
+
 	memset(value, 0, sizeof(value));
 
 	iov.iov_base = value;
diff --git a/src/shared/bap.h b/src/shared/bap.h
index 47a15636c..90d373e35 100644
--- a/src/shared/bap.h
+++ b/src/shared/bap.h
@@ -111,6 +111,8 @@  struct bt_bap_pac *bt_bap_add_pac(struct gatt_db *db, const char *name,
 					struct iovec *data,
 					struct iovec *metadata);
 
+int bt_bap_set_client_only(struct gatt_db *db);
+
 struct bt_bap_pac_ops {
 	int (*select)(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac,
 			struct bt_bap_pac_qos *qos,