diff mbox series

[BlueZ,v4,3/6] adapter: Broadcast source discovery

Message ID 20230802132355.4953-4-claudia.rosu@nxp.com
State New
Headers show
Series Add support for BAP broadcast sink | expand

Commit Message

Claudia Draghicescu Aug. 2, 2023, 1:23 p.m. UTC
This adds a new method in the adapter driver, device_resolved() called
when a broadcast source that advertises the BCAA_UUID is discovered.

---
 src/adapter.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/adapter.h |  2 ++
 2 files changed, 50 insertions(+)
diff mbox series

Patch

diff --git a/src/adapter.c b/src/adapter.c
index 491bd7031..29c6a576a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -7029,6 +7029,45 @@  static bool is_filter_match(GSList *discovery_filter, struct eir_data *eir_data,
 	return got_match;
 }
 
+static int find_baas(gconstpointer a, gconstpointer b)
+{
+	const struct eir_sd *sd = a;
+	const char *baas_uuid = b;
+
+	return strcmp(sd->uuid, baas_uuid);
+}
+
+static bool accept_bcast_adv(struct btd_adapter *adapter)
+{
+	if ((btd_adapter_has_settings(adapter, MGMT_SETTING_ISO_SYNC_RECEIVER)))
+		return true;
+
+	return false;
+}
+
+static bool is_bcast_source(struct eir_data *eir_data)
+{
+	if (!(eir_data->flags & (EIR_LIM_DISC | EIR_GEN_DISC))
+		&& (g_slist_find_custom(eir_data->sd_list,
+				BCAA_SERVICE_UUID, find_baas))) {
+		return true;
+	}
+
+	return false;
+}
+static void bcast_new_source(struct btd_adapter *adapter,
+				 struct btd_device *device)
+{
+	GSList *l;
+
+	for (l = adapter->drivers; l; l = g_slist_next(l)) {
+		struct btd_adapter_driver *driver = l->data;
+
+		if (!strcmp(driver->name, "bcast"))
+			driver->device_discovered(adapter, device);
+	}
+}
+
 static void filter_duplicate_data(void *data, void *user_data)
 {
 	struct discovery_client *client = data;
@@ -7152,12 +7191,21 @@  void btd_adapter_device_found(struct btd_adapter *adapter,
 			return;
 		}
 
+		if (accept_bcast_adv(adapter) && is_bcast_source(&eir_data))
+			monitoring = true;
+
 		if (!discoverable && !monitoring && !eir_data.rsi) {
 			eir_data_free(&eir_data);
 			return;
 		}
 
 		dev = adapter_create_device(adapter, bdaddr, bdaddr_type);
+
+		if (dev && is_bcast_source(&eir_data)) {
+			bcast_new_source(adapter, dev);
+			btd_device_set_temporary(dev, false);
+		}
+
 	}
 
 	if (!dev) {
diff --git a/src/adapter.h b/src/adapter.h
index ca96c1f65..ee32f7110 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -125,6 +125,8 @@  struct btd_adapter_driver {
 						struct btd_device *device);
 	void (*device_resolved)(struct btd_adapter *adapter,
 						struct btd_device *device);
+	void (*device_discovered)(struct btd_adapter *adapter,
+						struct btd_device *device);
 
 	/* Indicates the driver is experimental and shall only be registered
 	 * when experimental has been enabled (see: main.conf:Experimental).