[PATCH BlueZ 2/4] shared/gatt-client: Make use of bt_att_resend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

This makes use of bt_att_resend when sending continuation of PDUs such
as BT_ATT_OP_READ_BLOB_REQ and BT_ATT_OP_PREP_WRITE_REQ to avoid having
it interleave with other procedures, which is both simpler for the
peripheral to handle as well as it should reduce the lifetime of the
objects used for tracking the state of these procedures.
---
 src/shared/gatt-client.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 094922486..be0d3b091 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -2865,17 +2865,18 @@ static void read_long_cb(uint8_t opcode, const void *pdu,
 
 	if (length >= bt_att_get_mtu(op->client->att) - 1) {
 		uint8_t pdu[4];
+		int err;
 
 		put_le16(op->value_handle, pdu);
 		put_le16(op->offset, pdu + 2);
 
-		req->att_id = bt_att_send(op->client->att,
+		err = bt_att_resend(op->client->att, req->att_id,
 							BT_ATT_OP_READ_BLOB_REQ,
 							pdu, sizeof(pdu),
 							read_long_cb,
 							request_ref(req),
 							request_unref);
-		if (req->att_id)
+		if (!err)
 			return;
 
 		request_unref(req);
@@ -3121,6 +3122,7 @@ static void handle_next_prep_write(struct request *req)
 	struct long_write_op *op = req->data;
 	bool success = true;
 	uint8_t *pdu;
+	int err;
 
 	pdu = malloc(op->cur_length + 4);
 	if (!pdu) {
@@ -3132,12 +3134,13 @@ static void handle_next_prep_write(struct request *req)
 	put_le16(op->offset + op->index, pdu + 2);
 	memcpy(pdu + 4, op->value + op->index, op->cur_length);
 
-	req->att_id = bt_att_send(op->client->att, BT_ATT_OP_PREP_WRITE_REQ,
-							pdu, op->cur_length + 4,
-							prepare_write_cb,
-							request_ref(req),
-							request_unref);
-	if (!req->att_id) {
+	err = bt_att_resend(op->client->att, req->att_id,
+						BT_ATT_OP_PREP_WRITE_REQ,
+						pdu, op->cur_length + 4,
+						prepare_write_cb,
+						request_ref(req),
+						request_unref);
+	if (err) {
 		request_unref(req);
 		success = false;
 	}
@@ -3207,6 +3210,7 @@ static void complete_write_long_op(struct request *req, bool success,
 {
 	struct long_write_op *op = req->data;
 	uint8_t pdu;
+	int err;
 
 	op->success = success;
 	op->att_ecode = att_ecode;
@@ -3217,12 +3221,13 @@ static void complete_write_long_op(struct request *req, bool success,
 	else
 		pdu = 0x00;  /* Cancel */
 
-	req->att_id = bt_att_send(op->client->att, BT_ATT_OP_EXEC_WRITE_REQ,
-							&pdu, sizeof(pdu),
-							execute_write_cb,
-							request_ref(req),
-							request_unref);
-	if (req->att_id)
+	err = bt_att_resend(op->client->att, req->att_id,
+					BT_ATT_OP_EXEC_WRITE_REQ,
+					&pdu, sizeof(pdu),
+					execute_write_cb,
+					request_ref(req),
+					request_unref);
+	if (!err)
 		return;
 
 	request_unref(req);
-- 
2.31.1




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux