diff mbox series

[BlueZ,v3,6/6] adapter: Trigger adapter driver when a broadcast source is discovered

Message ID 20230802084140.51105-7-claudia.rosu@nxp.com (mailing list archive)
State Superseded
Headers show
Series Add support for BAP broadcast sink | 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 1: T1 Title exceeds max length (84>80): "[BlueZ,v3,6/6] adapter: Trigger adapter driver when a broadcast source is discovered"

Commit Message

Claudia Draghicescu Aug. 2, 2023, 8:41 a.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).