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 2/5] shared/bap: Log error message if request cannot be sent
Date: Thu,  8 Dec 2022 17:03:11 -0800	[thread overview]
Message-ID: <20221209010314.707606-2-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>

This makes sure a error message is logged if a request cannot be sent
for some reason.
---
 src/shared/bap.c | 71 +++++++++++++++++++++++++++---------------------
 1 file changed, 40 insertions(+), 31 deletions(-)

diff --git a/src/shared/bap.c b/src/shared/bap.c
index 59ef81d11882..04ef4f44c1dd 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -3397,9 +3397,13 @@ static bool bap_send(struct bt_bap *bap, struct bt_bap_req *req)
 	};
 	size_t i;
 
+	DBG(bap, "req %p", req);
+
 	if (!gatt_db_attribute_get_char_data(ascs->ase_cp, NULL, &handle,
-						NULL, NULL, NULL))
+						NULL, NULL, NULL)) {
+		DBG(bap, "Unable to find Control Point");
 		return false;
+	}
 
 	hdr.op = req->op;
 	hdr.num = 1 + queue_length(req->group);
@@ -3416,12 +3420,41 @@ static bool bap_send(struct bt_bap *bap, struct bt_bap_req *req)
 	ret = bt_gatt_client_write_without_response(bap->client, handle,
 							false, iov.iov_base,
 							iov.iov_len);
-	if (!ret)
+	if (!ret) {
+		DBG(bap, "Unable to Write to Control Point");
 		return false;
+	}
 
 	bap->req = req;
 
-	return false;
+	return true;
+}
+
+static void bap_req_complete(struct bt_bap_req *req,
+				const struct bt_ascs_ase_rsp *rsp)
+{
+	struct queue *group;
+
+	if (!req->func)
+		goto done;
+
+	if (rsp)
+		req->func(req->stream, rsp->code, rsp->reason, req->user_data);
+	else
+		req->func(req->stream, BT_ASCS_RSP_UNSPECIFIED, 0x00,
+						req->user_data);
+
+done:
+	/* Detach from request so it can be freed separately */
+	group = req->group;
+	req->group = NULL;
+
+	queue_foreach(group, (queue_foreach_func_t)bap_req_complete,
+							(void *)rsp);
+
+	queue_destroy(group, NULL);
+
+	bap_req_free(req);
 }
 
 static bool bap_process_queue(void *data)
@@ -3429,14 +3462,17 @@ static bool bap_process_queue(void *data)
 	struct bt_bap *bap = data;
 	struct bt_bap_req *req;
 
+	DBG(bap, "");
+
 	if (bap->process_id) {
 		timeout_remove(bap->process_id);
 		bap->process_id = 0;
 	}
 
 	while ((req = queue_pop_head(bap->reqs))) {
-		if (!bap_send(bap, req))
+		if (bap_send(bap, req))
 			break;
+		bap_req_complete(req, NULL);
 	}
 
 	return false;
@@ -3482,33 +3518,6 @@ static bool bap_queue_req(struct bt_bap *bap, struct bt_bap_req *req)
 	return true;
 }
 
-static void bap_req_complete(struct bt_bap_req *req,
-				const struct bt_ascs_ase_rsp *rsp)
-{
-	struct queue *group;
-
-	if (!req->func)
-		goto done;
-
-	if (rsp)
-		req->func(req->stream, rsp->code, rsp->reason, req->user_data);
-	else
-		req->func(req->stream, BT_ASCS_RSP_UNSPECIFIED, 0x00,
-						req->user_data);
-
-done:
-	/* Detach from request so it can be freed separately */
-	group = req->group;
-	req->group = NULL;
-
-	queue_foreach(group, (queue_foreach_func_t)bap_req_complete,
-							(void *)rsp);
-
-	queue_destroy(group, NULL);
-
-	bap_req_free(req);
-}
-
 static void bap_cp_notify(struct bt_bap *bap, uint16_t value_handle,
 				const uint8_t *value, uint16_t length,
 				void *user_data)
-- 
2.37.3


  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 ` Luiz Augusto von Dentz [this message]
2022-12-09  1:03 ` [PATCH BlueZ 3/5] shared/bap: Read PAC Sink/Source if respective location is found Luiz Augusto von Dentz
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-2-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