public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 3/5] shared/bap: Read PAC Sink/Source if respective location is found
Date: Thu,  8 Dec 2022 17:03:12 -0800	[thread overview]
Message-ID: <20221209010314.707606-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20221209010314.707606-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If PAC Sink/Source has been found but not record has been recovered it
means an error must have occured so this attempt to read the records
once again.
---
 src/shared/bap.c | 146 +++++++++++++++++++++++++++--------------------
 1 file changed, 83 insertions(+), 63 deletions(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 04ef4f44c1dd..391838a96c55 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -2837,69 +2837,6 @@ static void read_sink_pac(struct bt_bap *bap, bool success, uint8_t att_ecode,
 	bap_parse_pacs(bap, BT_BAP_SINK, bap->rdb->sinks, value, length);
 }
 
-static void read_source_pac_loc(struct bt_bap *bap, bool success,
-				uint8_t att_ecode, const uint8_t *value,
-				uint16_t length, void *user_data)
-{
-	struct bt_pacs *pacs = bap_get_pacs(bap);
-
-	if (!success) {
-		DBG(bap, "Unable to read Source PAC Location: error 0x%02x",
-								att_ecode);
-		return;
-	}
-
-	gatt_db_attribute_write(pacs->source_loc, 0, value, length, 0, NULL,
-							NULL, NULL);
-}
-
-static void read_sink_pac_loc(struct bt_bap *bap, bool success,
-				uint8_t att_ecode, const uint8_t *value,
-				uint16_t length, void *user_data)
-{
-	struct bt_pacs *pacs = bap_get_pacs(bap);
-
-	if (!success) {
-		DBG(bap, "Unable to read Sink PAC Location: error 0x%02x",
-								att_ecode);
-		return;
-	}
-
-	gatt_db_attribute_write(pacs->sink_loc, 0, value, length, 0, NULL,
-							NULL, NULL);
-}
-
-static void read_pac_context(struct bt_bap *bap, bool success,
-				uint8_t att_ecode, const uint8_t *value,
-				uint16_t length, void *user_data)
-{
-	struct bt_pacs *pacs = bap_get_pacs(bap);
-
-	if (!success) {
-		DBG(bap, "Unable to read PAC Context: error 0x%02x", att_ecode);
-		return;
-	}
-
-	gatt_db_attribute_write(pacs->context, 0, value, length, 0, NULL,
-							NULL, NULL);
-}
-
-static void read_pac_supported_context(struct bt_bap *bap, bool success,
-					uint8_t att_ecode, const uint8_t *value,
-					uint16_t length, void *user_data)
-{
-	struct bt_pacs *pacs = bap_get_pacs(bap);
-
-	if (!success) {
-		DBG(bap, "Unable to read PAC Supproted Context: error 0x%02x",
-								att_ecode);
-		return;
-	}
-
-	gatt_db_attribute_write(pacs->supported_context, 0, value, length, 0,
-							NULL, NULL, NULL);
-}
-
 static void bap_pending_destroy(void *data)
 {
 	struct bt_bap_pending *pending = data;
@@ -2944,6 +2881,89 @@ static void bap_read_value(struct bt_bap *bap, uint16_t value_handle,
 	queue_push_tail(bap->pending, pending);
 }
 
+static void read_source_pac_loc(struct bt_bap *bap, bool success,
+				uint8_t att_ecode, const uint8_t *value,
+				uint16_t length, void *user_data)
+{
+	struct bt_pacs *pacs = bap_get_pacs(bap);
+
+	if (!success) {
+		DBG(bap, "Unable to read Source PAC Location: error 0x%02x",
+								att_ecode);
+		return;
+	}
+
+	gatt_db_attribute_write(pacs->source_loc, 0, value, length, 0, NULL,
+							NULL, NULL);
+
+	/* Resume reading sinks if supported but for some reason is empty */
+	if (pacs->source && queue_isempty(bap->rdb->sources)) {
+		uint16_t value_handle;
+
+		if (gatt_db_attribute_get_char_data(pacs->source,
+						NULL, &value_handle,
+						NULL, NULL, NULL))
+			bap_read_value(bap, value_handle, read_source_pac, bap);
+	}
+}
+
+static void read_sink_pac_loc(struct bt_bap *bap, bool success,
+				uint8_t att_ecode, const uint8_t *value,
+				uint16_t length, void *user_data)
+{
+	struct bt_pacs *pacs = bap_get_pacs(bap);
+
+	if (!success) {
+		DBG(bap, "Unable to read Sink PAC Location: error 0x%02x",
+								att_ecode);
+		return;
+	}
+
+	gatt_db_attribute_write(pacs->sink_loc, 0, value, length, 0, NULL,
+							NULL, NULL);
+
+	/* Resume reading sinks if supported but for some reason is empty */
+	if (pacs->sink && queue_isempty(bap->rdb->sinks)) {
+		uint16_t value_handle;
+
+		if (gatt_db_attribute_get_char_data(pacs->sink,
+						NULL, &value_handle,
+						NULL, NULL, NULL))
+			bap_read_value(bap, value_handle, read_sink_pac, bap);
+	}
+}
+
+static void read_pac_context(struct bt_bap *bap, bool success,
+				uint8_t att_ecode, const uint8_t *value,
+				uint16_t length, void *user_data)
+{
+	struct bt_pacs *pacs = bap_get_pacs(bap);
+
+	if (!success) {
+		DBG(bap, "Unable to read PAC Context: error 0x%02x", att_ecode);
+		return;
+	}
+
+	gatt_db_attribute_write(pacs->context, 0, value, length, 0, NULL,
+							NULL, NULL);
+}
+
+static void read_pac_supported_context(struct bt_bap *bap, bool success,
+					uint8_t att_ecode, const uint8_t *value,
+					uint16_t length, void *user_data)
+{
+	struct bt_pacs *pacs = bap_get_pacs(bap);
+
+	if (!success) {
+		DBG(bap, "Unable to read PAC Supproted Context: error 0x%02x",
+								att_ecode);
+		return;
+	}
+
+	gatt_db_attribute_write(pacs->supported_context, 0, value, length, 0,
+							NULL, NULL, NULL);
+}
+
 static void foreach_pacs_char(struct gatt_db_attribute *attr, void *user_data)
 {
 	struct bt_bap *bap = user_data;
-- 
2.37.3


  parent reply	other threads:[~2022-12-09  1:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09  1:03 [PATCH BlueZ 1/5] shared/att: Fix not requeueing in the same channel Luiz Augusto von Dentz
2022-12-09  1:03 ` [PATCH BlueZ 2/5] shared/bap: Log error message if request cannot be sent Luiz Augusto von Dentz
2022-12-09  1:03 ` Luiz Augusto von Dentz [this message]
2022-12-09  1:03 ` [PATCH BlueZ 4/5] shared/gatt-db: Allow passing NULL to gatt_db_attribute_write Luiz Augusto von Dentz
2022-12-09  1:03 ` [PATCH BlueZ 5/5] shared/bap: Make bt_bap_pac_register to be per session Luiz Augusto von Dentz
2022-12-09  4:33 ` [BlueZ,1/5] shared/att: Fix not requeueing in the same channel bluez.test.bot
2022-12-09 21:30 ` [PATCH BlueZ 1/5] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221209010314.707606-3-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox