diff mbox series

[BlueZ,2/5] shared/bap: Log error message if request cannot be sent

Message ID 20221209010314.707606-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,1/5] shared/att: Fix not requeueing in the same channel | expand

Commit Message

Luiz Augusto von Dentz Dec. 9, 2022, 1:03 a.m. UTC
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 mbox series

Patch

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)