diff mbox series

[BlueZ,8/8] bap: handle adapters that are not CIS Central / Peripheral capable

Message ID 89c50cadaefa56c85346ad7f2cd86eab756f3987.1675103676.git.pav@iki.fi
State New
Headers show
Series None | expand

Commit Message

Pauli Virtanen Jan. 30, 2023, 6:37 p.m. UTC
When BT adapter is not CIS Peripheral capable, use the shared/bap code
in its central-only mode, and don't register anything in the local GATT
database.

When BT adapter is not CIS Central capable, ignore the remote device
GATT database, so that we work purely in peripheral mode.

If BT adapter supports neither feature, don't do anything with BAP.
---
 profiles/audio/bap.c   | 18 ++++++++++++++++--
 profiles/audio/media.c | 11 ++++++-----
 2 files changed, 22 insertions(+), 7 deletions(-)

Comments

Luiz Augusto von Dentz Feb. 7, 2023, 1:27 a.m. UTC | #1
Hi Pauli,

On Mon, Jan 30, 2023 at 11:06 AM Pauli Virtanen <pav@iki.fi> wrote:
>
> When BT adapter is not CIS Peripheral capable, use the shared/bap code
> in its central-only mode, and don't register anything in the local GATT
> database.
>
> When BT adapter is not CIS Central capable, ignore the remote device
> GATT database, so that we work purely in peripheral mode.
>
> If BT adapter supports neither feature, don't do anything with BAP.
> ---
>  profiles/audio/bap.c   | 18 ++++++++++++++++--
>  profiles/audio/media.c | 11 ++++++-----
>  2 files changed, 22 insertions(+), 7 deletions(-)
>
> diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
> index e5ffb7230..28c0d139a 100644
> --- a/profiles/audio/bap.c
> +++ b/profiles/audio/bap.c
> @@ -1254,6 +1254,8 @@ static int bap_probe(struct btd_service *service)
>         struct btd_adapter *adapter = device_get_adapter(device);
>         struct btd_gatt_database *database = btd_adapter_get_database(adapter);
>         struct bap_data *data = btd_service_get_user_data(service);
> +       struct bt_bap_db *ldb;
> +       struct gatt_db *device_db;
>         char addr[18];
>
>         ba2str(device_get_address(device), addr);
> @@ -1264,17 +1266,29 @@ static int bap_probe(struct btd_service *service)
>                 return -ENOTSUP;
>         }
>
> +       if (!btd_adapter_cis_central_capable(adapter) &&
> +           !btd_adapter_cis_peripheral_capable(adapter)) {
> +               DBG("BAP requires CIS features, unsupported by adapter");
> +               return -ENOTSUP;
> +       }
> +
>         /* Ignore, if we were probed for this device already */
>         if (data) {
>                 error("Profile probed twice for the same device!");
>                 return -EINVAL;
>         }
>
> +       if (btd_adapter_cis_central_capable(adapter))
> +               device_db = btd_device_get_gatt_db(device);
> +       else
> +               device_db = NULL;
> +
>         data = bap_data_new(device);
>         data->service = service;
>
> -       data->bap = bt_bap_new(btd_gatt_database_get_db(database),
> -                                       btd_device_get_gatt_db(device));
> +       ldb = bt_bap_get_local_db(btd_gatt_database_get_db(database),
> +                               btd_adapter_cis_peripheral_capable(adapter));

Don't really like the idea of having an API to access the bt_bap_db,
can we just pass NULL to ldb as before? We can work out internally in
bap.c to handle this properly.

> +       data->bap = bt_bap_new(ldb, device_db);
>         if (!data->bap) {
>                 error("Unable to create BAP instance");
>                 free(data);
> diff --git a/profiles/audio/media.c b/profiles/audio/media.c
> index d68085514..6f83b03b5 100644
> --- a/profiles/audio/media.c
> +++ b/profiles/audio/media.c
> @@ -1105,8 +1105,9 @@ static void bap_debug(const char *str, void *user_data)
>  static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type,
>                                                                 int *err)
>  {
> +       struct btd_adapter *adapter = endpoint->adapter->btd_adapter;
>         struct btd_gatt_database *database;
> -       struct gatt_db *db;
> +       struct bt_bap_db *ldb;
>         struct iovec data;
>         char *name;
>
> @@ -1116,7 +1117,7 @@ static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type,
>                 return false;
>         }
>
> -       database = btd_adapter_get_database(endpoint->adapter->btd_adapter);
> +       database = btd_adapter_get_database(adapter);
>         if (!database) {
>                 error("Adapter database not found");
>                 return false;
> @@ -1128,8 +1129,6 @@ static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type,
>                 return false;
>         }
>
> -       db = btd_gatt_database_get_db(database);
> -
>         data.iov_base = endpoint->capabilities;
>         data.iov_len = endpoint->size;
>
> @@ -1141,7 +1140,9 @@ static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type,
>                 return false;
>         }
>
> -       endpoint->pac = bt_bap_add_pac(db, name, type, endpoint->codec,
> +       ldb = bt_bap_get_local_db(btd_gatt_database_get_db(database),
> +                               btd_adapter_cis_peripheral_capable(adapter));
> +       endpoint->pac = bt_bap_add_pac(ldb, name, type, endpoint->codec,
>                                         &endpoint->qos, &data, NULL);
>         if (!endpoint->pac) {
>                 error("Unable to create PAC");
> --
> 2.39.1
>
diff mbox series

Patch

diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index e5ffb7230..28c0d139a 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -1254,6 +1254,8 @@  static int bap_probe(struct btd_service *service)
 	struct btd_adapter *adapter = device_get_adapter(device);
 	struct btd_gatt_database *database = btd_adapter_get_database(adapter);
 	struct bap_data *data = btd_service_get_user_data(service);
+	struct bt_bap_db *ldb;
+	struct gatt_db *device_db;
 	char addr[18];
 
 	ba2str(device_get_address(device), addr);
@@ -1264,17 +1266,29 @@  static int bap_probe(struct btd_service *service)
 		return -ENOTSUP;
 	}
 
+	if (!btd_adapter_cis_central_capable(adapter) &&
+	    !btd_adapter_cis_peripheral_capable(adapter)) {
+		DBG("BAP requires CIS features, unsupported by adapter");
+		return -ENOTSUP;
+	}
+
 	/* Ignore, if we were probed for this device already */
 	if (data) {
 		error("Profile probed twice for the same device!");
 		return -EINVAL;
 	}
 
+	if (btd_adapter_cis_central_capable(adapter))
+		device_db = btd_device_get_gatt_db(device);
+	else
+		device_db = NULL;
+
 	data = bap_data_new(device);
 	data->service = service;
 
-	data->bap = bt_bap_new(btd_gatt_database_get_db(database),
-					btd_device_get_gatt_db(device));
+	ldb = bt_bap_get_local_db(btd_gatt_database_get_db(database),
+				btd_adapter_cis_peripheral_capable(adapter));
+	data->bap = bt_bap_new(ldb, device_db);
 	if (!data->bap) {
 		error("Unable to create BAP instance");
 		free(data);
diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index d68085514..6f83b03b5 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -1105,8 +1105,9 @@  static void bap_debug(const char *str, void *user_data)
 static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type,
 								int *err)
 {
+	struct btd_adapter *adapter = endpoint->adapter->btd_adapter;
 	struct btd_gatt_database *database;
-	struct gatt_db *db;
+	struct bt_bap_db *ldb;
 	struct iovec data;
 	char *name;
 
@@ -1116,7 +1117,7 @@  static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type,
 		return false;
 	}
 
-	database = btd_adapter_get_database(endpoint->adapter->btd_adapter);
+	database = btd_adapter_get_database(adapter);
 	if (!database) {
 		error("Adapter database not found");
 		return false;
@@ -1128,8 +1129,6 @@  static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type,
 		return false;
 	}
 
-	db = btd_gatt_database_get_db(database);
-
 	data.iov_base = endpoint->capabilities;
 	data.iov_len = endpoint->size;
 
@@ -1141,7 +1140,9 @@  static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type,
 		return false;
 	}
 
-	endpoint->pac = bt_bap_add_pac(db, name, type, endpoint->codec,
+	ldb = bt_bap_get_local_db(btd_gatt_database_get_db(database),
+				btd_adapter_cis_peripheral_capable(adapter));
+	endpoint->pac = bt_bap_add_pac(ldb, name, type, endpoint->codec,
 					&endpoint->qos, &data, NULL);
 	if (!endpoint->pac) {
 		error("Unable to create PAC");