shared/gatt-client: Support cancel of prepare write
This patch add support to cancel prepare write done from gatt client
Note that Write Execute 0x00 is done on cancel
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index c4ec611..5ee753e 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -1795,6 +1795,26 @@
}
+static void cancel_prep_write_cb(uint8_t opcode, const void *pdu, uint16_t len,
+ void *user_data)
+{
+ struct request *req = user_data;
+ struct bt_gatt_client *client = req->client;
+
+ client->reliable_write_session_id = 0;
+}
+
+static bool cancel_prep_write_session(struct bt_gatt_client *client,
+ struct request *req)
+{
+ uint8_t pdu = 0x00;
+
+ return !!bt_att_send(client->att, BT_ATT_OP_EXEC_WRITE_REQ, &pdu,
+ sizeof(pdu),
+ cancel_prep_write_cb,
+ req, request_unref);
+}
+
bool bt_gatt_client_cancel(struct bt_gatt_client *client, unsigned int id)
{
struct request *req;
@@ -1809,13 +1829,17 @@
req->removed = true;
- if (!bt_att_cancel(client->att, req->att_id) && !req->long_write)
+ if (!bt_att_cancel(client->att, req->att_id) && !req->long_write &&
+ !req->prep_write)
return false;
/* If this was a long-write, we need to abort all prepared writes */
if (req->long_write)
return cancel_long_write_req(client, req);
+ if (req->prep_write)
+ return cancel_prep_write_session(client, req);
+
return true;
}
@@ -1829,6 +1853,9 @@
if (req->long_write)
cancel_long_write_req(req->client, req);
+
+ if (req->prep_write)
+ cancel_prep_write_session(req->client, req);
}
bool bt_gatt_client_cancel_all(struct bt_gatt_client *client)