shared/gatt-client: Make use of bt_att_resend
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 4 Oct 2021 21:16:00 +0000 (14:16 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:37 +0000 (19:08 +0530)
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.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/shared/gatt-client.c

index 50e9537..f5f336a 100644 (file)
@@ -3153,17 +3153,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);
@@ -3498,6 +3499,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) {
@@ -3509,12 +3511,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;
        }
@@ -3584,6 +3587,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;
@@ -3594,12 +3598,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);