public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile
@ 2025-04-23 15:07 Arun Raghavan
  2025-04-23 15:07 ` [PATCH BlueZ v2 1/3] profiles/audio: asha: Reset state on disconnect Arun Raghavan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Arun Raghavan @ 2025-04-23 15:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Arun Raghavan, sanchayan

This set of two patches fixes re-connection issues for the ASHA profile.

v2:
  * Incorporate feedback from review -- reset state in
    `bt_asha_reset()`, and use "attach" instead of "probe"
  * Add a minor renaming patch for readability

Arun Raghavan (2):
  profiles/audio: asha: Only expose device after we have attributes
  shared: asha: Use a more descriptive name for the state callback

Sanchayan Maity (1):
  profiles/audio: asha: Reset state on disconnect

 profiles/audio/asha.c |  6 ++---
 src/shared/asha.c     | 57 ++++++++++++++++++++++++++++++++-----------
 src/shared/asha.h     | 13 +++++++---
 3 files changed, 55 insertions(+), 21 deletions(-)

-- 
2.49.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH BlueZ v2 1/3] profiles/audio: asha: Reset state on disconnect
  2025-04-23 15:07 [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile Arun Raghavan
@ 2025-04-23 15:07 ` Arun Raghavan
  2025-04-23 15:07 ` [PATCH BlueZ v2 2/3] profiles/audio: asha: Only expose device after we have attributes Arun Raghavan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Arun Raghavan @ 2025-04-23 15:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Sanchayan Maity

From: Sanchayan Maity <sanchayan@asymptotic.io>

---
 src/shared/asha.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/shared/asha.c b/src/shared/asha.c
index e7bba4cc4..fa6b489d6 100644
--- a/src/shared/asha.c
+++ b/src/shared/asha.c
@@ -174,6 +174,8 @@ void bt_asha_reset(struct bt_asha *asha)
 	bt_gatt_client_unref(asha->client);
 	asha->client = NULL;
 
+	bt_asha_state_reset(asha);
+
 	asha->psm = 0;
 
 	update_asha_set(asha, false);
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH BlueZ v2 2/3] profiles/audio: asha: Only expose device after we have attributes
  2025-04-23 15:07 [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile Arun Raghavan
  2025-04-23 15:07 ` [PATCH BlueZ v2 1/3] profiles/audio: asha: Reset state on disconnect Arun Raghavan
@ 2025-04-23 15:07 ` Arun Raghavan
  2025-04-23 15:07 ` [PATCH BlueZ v2 3/3] shared: asha: Use a more descriptive name for the state callback Arun Raghavan
  2025-04-23 21:00 ` [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile patchwork-bot+bluetooth
  3 siblings, 0 replies; 5+ messages in thread
From: Arun Raghavan @ 2025-04-23 15:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Arun Raghavan, sanchayan

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 --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);
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH BlueZ v2 3/3] shared: asha: Use a more descriptive name for the state callback
  2025-04-23 15:07 [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile Arun Raghavan
  2025-04-23 15:07 ` [PATCH BlueZ v2 1/3] profiles/audio: asha: Reset state on disconnect Arun Raghavan
  2025-04-23 15:07 ` [PATCH BlueZ v2 2/3] profiles/audio: asha: Only expose device after we have attributes Arun Raghavan
@ 2025-04-23 15:07 ` Arun Raghavan
  2025-04-23 21:00 ` [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile patchwork-bot+bluetooth
  3 siblings, 0 replies; 5+ messages in thread
From: Arun Raghavan @ 2025-04-23 15:07 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Arun Raghavan, sanchayan

---
 src/shared/asha.c | 24 ++++++++++++------------
 src/shared/asha.h |  4 ++--
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/src/shared/asha.c b/src/shared/asha.c
index d99ae4d8b..bcaf6b843 100644
--- a/src/shared/asha.c
+++ b/src/shared/asha.c
@@ -189,8 +189,8 @@ void bt_asha_state_reset(struct bt_asha *asha)
 {
 	asha->state = ASHA_STOPPED;
 
-	asha->cb = NULL;
-	asha->cb_user_data = NULL;
+	asha->state_cb = NULL;
+	asha->state_cb_data = NULL;
 }
 
 void bt_asha_free(struct bt_asha *asha)
@@ -210,8 +210,8 @@ static void asha_acp_sent(bool success, uint8_t err, void *user_data)
 	} else {
 		error("Failed to send AudioControlPoint command: %d", err);
 
-		if (asha->cb)
-			asha->cb(-1, asha->cb_user_data);
+		if (asha->state_cb)
+			asha->state_cb(-1, asha->state_cb_data);
 
 		bt_asha_state_reset(asha);
 	}
@@ -226,8 +226,8 @@ static int asha_send_acp(struct bt_asha *asha, uint8_t *cmd,
 		return -1;
 	}
 
-	asha->cb = cb;
-	asha->cb_user_data = user_data;
+	asha->state_cb = cb;
+	asha->state_cb_data = user_data;
 
 	return 0;
 }
@@ -439,8 +439,8 @@ static void audio_status_notify(uint16_t value_handle, const uint8_t *value,
 	struct bt_asha *asha = user_data;
 	uint8_t status = *value;
 	/* Back these up to survive the reset paths */
-	bt_asha_cb_t cb = asha->cb;
-	bt_asha_cb_t cb_user_data = asha->cb_user_data;
+	bt_asha_cb_t state_cb = asha->state_cb;
+	bt_asha_cb_t state_cb_data = asha->state_cb_data;
 
 	if (asha->state == ASHA_STARTING) {
 		if (status == 0) {
@@ -457,10 +457,10 @@ static void audio_status_notify(uint16_t value_handle, const uint8_t *value,
 		DBG("ASHA stop %s", status == 0 ? "complete" : "failed");
 	}
 
-	if (cb) {
-		cb(status, cb_user_data);
-		asha->cb = NULL;
-		asha->cb_user_data = NULL;
+	if (state_cb) {
+		state_cb(status, state_cb_data);
+		asha->state_cb = NULL;
+		asha->state_cb_data = NULL;
 	}
 }
 
diff --git a/src/shared/asha.h b/src/shared/asha.h
index 39e55f22e..680a27010 100644
--- a/src/shared/asha.h
+++ b/src/shared/asha.h
@@ -44,8 +44,8 @@ struct bt_asha {
 	int8_t volume;
 
 	enum bt_asha_state_t state;
-	bt_asha_cb_t cb;
-	void *cb_user_data;
+	bt_asha_cb_t state_cb;
+	void *state_cb_data;
 
 	bt_asha_attach_cb_t attach_cb;
 	void *attach_cb_data;
-- 
2.49.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile
  2025-04-23 15:07 [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile Arun Raghavan
                   ` (2 preceding siblings ...)
  2025-04-23 15:07 ` [PATCH BlueZ v2 3/3] shared: asha: Use a more descriptive name for the state callback Arun Raghavan
@ 2025-04-23 21:00 ` patchwork-bot+bluetooth
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+bluetooth @ 2025-04-23 21:00 UTC (permalink / raw)
  To: Arun Raghavan; +Cc: linux-bluetooth, sanchayan

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Wed, 23 Apr 2025 11:07:39 -0400 you wrote:
> This set of two patches fixes re-connection issues for the ASHA profile.
> 
> v2:
>   * Incorporate feedback from review -- reset state in
>     `bt_asha_reset()`, and use "attach" instead of "probe"
>   * Add a minor renaming patch for readability
> 
> [...]

Here is the summary with links:
  - [BlueZ,v2,1/3] profiles/audio: asha: Reset state on disconnect
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=918432b2c68d
  - [BlueZ,v2,2/3] profiles/audio: asha: Only expose device after we have attributes
    (no matching commit)
  - [BlueZ,v2,3/3] shared: asha: Use a more descriptive name for the state callback
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=629672307f6c

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-23 20:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-23 15:07 [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile Arun Raghavan
2025-04-23 15:07 ` [PATCH BlueZ v2 1/3] profiles/audio: asha: Reset state on disconnect Arun Raghavan
2025-04-23 15:07 ` [PATCH BlueZ v2 2/3] profiles/audio: asha: Only expose device after we have attributes Arun Raghavan
2025-04-23 15:07 ` [PATCH BlueZ v2 3/3] shared: asha: Use a more descriptive name for the state callback Arun Raghavan
2025-04-23 21:00 ` [PATCH BlueZ v2 0/3] Fixes for re-connection issues with ASHA profile patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox