Diff between 4b4c9383d58ad63faf18908e5d3864d52dc686c1 and f49953d96fab77fccf80ab5af56538ac749c3489

Changed Files

File Additions Deletions Status
profiles/audio/bass.c +42 -0 modified

Full Patch

diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index 67ee847..96e7677 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -137,6 +137,10 @@ static struct queue *delegators;
 
 static const char *state2str(enum assistant_state state);
 
+static struct bass_data *bass_data_new(struct btd_device *device);
+static void bass_data_add(struct bass_data *data);
+static void bass_data_remove(struct bass_data *data);
+
 static void bass_debug(const char *str, void *user_data)
 {
 	DBG_IDX(0xffff, "%s", str);
@@ -560,9 +564,11 @@ static void confirm_cb(GIOChannel *io, void *user_data)
 static void bap_attached(struct bt_bap *bap, void *user_data)
 {
 	struct btd_service *service;
+	struct btd_profile *p;
 	struct btd_device *device;
 	struct btd_adapter *adapter;
 	struct bass_delegator *dg;
+	struct bass_data *data;
 	GError *err = NULL;
 
 	DBG("%p", bap);
@@ -571,9 +577,22 @@ static void bap_attached(struct bt_bap *bap, void *user_data)
 	if (!service)
 		return;
 
+	p = btd_service_get_profile(service);
+	if (!p)
+		return;
+
+	/* Only handle sessions with Broadcast Sources */
+	if (!g_str_equal(p->remote_uuid, BCAAS_UUID_STR))
+		return;
+
 	device = btd_service_get_device(service);
 	adapter = device_get_adapter(device);
 
+	/* Create BASS session with the Broadcast Source */
+	data = bass_data_new(device);
+
+	bass_data_add(data);
+
 	dg = queue_find(delegators, delegator_match_device, device);
 	if (!dg)
 		/* Only probe devices added via Broadcast Assistants */
@@ -625,11 +644,21 @@ static void setup_free(void *data)
 	bt_bass_clear_bis_sync(setup->dg->src, setup->bis);
 }
 
+static bool match_device(const void *data, const void *match_data)
+{
+	const struct bass_data *bdata = data;
+	const struct btd_device *device = match_data;
+
+	return bdata->device == device;
+}
+
 static void bap_detached(struct bt_bap *bap, void *user_data)
 {
 	struct btd_service *service;
+	struct btd_profile *p;
 	struct btd_device *device;
 	struct bass_delegator *dg;
+	struct bass_data *data;
 
 	DBG("%p", bap);
 
@@ -637,8 +666,21 @@ static void bap_detached(struct bt_bap *bap, void *user_data)
 	if (!service)
 		return;
 
+	p = btd_service_get_profile(service);
+	if (!p)
+		return;
+
+	/* Only handle sessions with Broadcast Sources */
+	if (!g_str_equal(p->remote_uuid, BCAAS_UUID_STR))
+		return;
+
 	device = btd_service_get_device(service);
 
+	/* Remove BASS session with the Broadcast Source device */
+	data = queue_find(sessions, match_device, device);
+	if (data)
+		bass_data_remove(data);
+
 	dg = queue_remove_if(delegators, delegator_match_device, device);
 	if (!dg)
 		return;