diff mbox series

[BlueZ,v2,2/3] profiles/audio: asha: Only expose device after we have attributes

Message ID 20250423150742.319463-3-arun@asymptotic.io
State New
Headers show
Series Fixes for re-connection issues with ASHA profile | expand

Commit Message

Arun Raghavan April 23, 2025, 3:07 p.m. UTC
Let's get the PSM and read-only properties before we expose the device
and transport. While we're at it, rename "probe" as "attach" for
consistency.
---
 profiles/audio/asha.c |  6 +++---
 src/shared/asha.c     | 31 +++++++++++++++++++++++++++++--
 src/shared/asha.h     |  9 +++++++--
 3 files changed, 39 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/profiles/audio/asha.c b/profiles/audio/asha.c
index 10115b92d..9e32822c9 100644
--- a/profiles/audio/asha.c
+++ b/profiles/audio/asha.c
@@ -458,10 +458,10 @@  static int asha_source_accept(struct btd_service *service)
 		return -1;
 	}
 
-	if (!bt_asha_probe(asha_dev->asha, db, client))
+	if (!bt_asha_attach(asha_dev->asha, db, client,
+		(bt_asha_attach_cb_t) asha_source_endpoint_register, asha_dev)) {
 		return -1;
-
-	asha_source_endpoint_register(asha_dev);
+	}
 
 	btd_service_connecting_complete(service, 0);
 
diff --git a/src/shared/asha.c b/src/shared/asha.c
index fa6b489d6..d99ae4d8b 100644
--- a/src/shared/asha.c
+++ b/src/shared/asha.c
@@ -177,6 +177,10 @@  void bt_asha_reset(struct bt_asha *asha)
 	bt_asha_state_reset(asha);
 
 	asha->psm = 0;
+	memset(asha->hisyncid, 0, sizeof(asha->hisyncid));
+
+	asha->attach_cb = NULL;
+	asha->attach_cb_data = NULL;
 
 	update_asha_set(asha, false);
 }
@@ -335,6 +339,21 @@  static bool uuid_cmp(const char *uuid1, const bt_uuid_t *uuid2)
 	return bt_uuid_cmp(&lhs, uuid2) == 0;
 }
 
+static void check_probe_done(struct bt_asha *asha)
+{
+	uint8_t zeroes[8] = { 0, };
+
+	/* Once we have ROPs & PSM, we should be good to go */
+	if (asha->psm == 0 || memcmp(asha->hisyncid, zeroes, sizeof(zeroes) == 0))
+		return;
+
+	if (asha->attach_cb) {
+		asha->attach_cb(asha->attach_cb_data);
+		asha->attach_cb = NULL;
+		asha->attach_cb_data = NULL;
+	}
+}
+
 static void read_psm(bool success,
 			uint8_t att_ecode,
 			const uint8_t *value,
@@ -356,6 +375,8 @@  static void read_psm(bool success,
 	asha->psm = get_le16(value);
 
 	DBG("Got PSM: %u", asha->psm);
+
+	check_probe_done(asha);
 }
 
 static void read_rops(bool success,
@@ -400,6 +421,8 @@  static void read_rops(bool success,
 			asha->render_delay, asha->codec_ids);
 
 	update_asha_set(asha, true);
+
+	check_probe_done(asha);
 }
 
 static void audio_status_register(uint16_t att_ecode, void *user_data)
@@ -501,14 +524,18 @@  static void foreach_asha_service(struct gatt_db_attribute *attr,
 	gatt_db_service_foreach_char(asha->attr, handle_characteristic, asha);
 }
 
-bool bt_asha_probe(struct bt_asha *asha, struct gatt_db *db,
-						struct bt_gatt_client *client)
+bool bt_asha_attach(struct bt_asha *asha, struct gatt_db *db,
+		struct bt_gatt_client *client, bt_asha_attach_cb_t attach_cb,
+							void *cb_user_data)
 {
 	bt_uuid_t asha_uuid;
 
 	asha->db = gatt_db_ref(db);
 	asha->client = bt_gatt_client_clone(client);
 
+	asha->attach_cb = attach_cb;
+	asha->attach_cb_data = cb_user_data;
+
 	bt_uuid16_create(&asha_uuid, ASHA_SERVICE);
 	gatt_db_foreach_service(db, &asha_uuid, foreach_asha_service, asha);
 
diff --git a/src/shared/asha.h b/src/shared/asha.h
index e87a9fc3f..39e55f22e 100644
--- a/src/shared/asha.h
+++ b/src/shared/asha.h
@@ -23,6 +23,7 @@  enum bt_asha_state_t {
 };
 
 typedef void (*bt_asha_cb_t)(int status, void *data);
+typedef void (*bt_asha_attach_cb_t)(void *data);
 
 struct bt_asha {
 	struct bt_gatt_client *client;
@@ -45,6 +46,9 @@  struct bt_asha {
 	enum bt_asha_state_t state;
 	bt_asha_cb_t cb;
 	void *cb_user_data;
+
+	bt_asha_attach_cb_t attach_cb;
+	void *attach_cb_data;
 };
 
 struct bt_asha_set {
@@ -65,5 +69,6 @@  unsigned int bt_asha_stop(struct bt_asha *asha, bt_asha_cb_t cb,
 
 bool bt_asha_set_volume(struct bt_asha *asha, int8_t volume);
 
-bool bt_asha_probe(struct bt_asha *asha, struct gatt_db *db,
-						struct bt_gatt_client *client);
+bool bt_asha_attach(struct bt_asha *asha, struct gatt_db *db,
+		struct bt_gatt_client *client, bt_asha_attach_cb_t probe_cb,
+							void *cb_user_data);