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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 --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,
-- 
2.39.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux