From: Luiz Augusto von Dentz Date: Mon, 4 Oct 2021 21:16:00 +0000 (-0700) Subject: shared/gatt-client: Make use of bt_att_resend X-Git-Tag: submit/tizen/20220313.220938~103 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=afddf2f2f162038a12e52ea02d4f8b1ec5a409ef;p=platform%2Fupstream%2Fbluez.git shared/gatt-client: Make use of bt_att_resend 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 Signed-off-by: Ayush Garg --- diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index 50e9537..f5f336a 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -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);