Skip to content
Permalink
Browse files

Bluetooth: GATT: Fix not canceling on unsubscribe

This introduces a new flag (BT_GATT_SUBSCRIBE_WRITE_PENDING) which is
set when a write operation requires canceling before the parameters can
be reused.

Fixes #17534

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
  • Loading branch information...
Vudentz authored and carlescufi committed Jul 16, 2019
1 parent 662a519 commit 219bb6fe1fd45b6054ee0bfa2398d9ec52221c41
Showing with 15 additions and 0 deletions.
  1. +7 −0 include/bluetooth/gatt.h
  2. +8 −0 subsys/bluetooth/host/gatt.c
@@ -1228,6 +1228,13 @@ enum {
* issue a new subscription.
*/
BT_GATT_SUBSCRIBE_FLAG_VOLATILE = BIT(0),

/** Write pending flag
*
* If set, indicates write operation is pending waiting remote end to
* respond.
*/
BT_GATT_SUBSCRIBE_WRITE_PENDING = BIT(1),
};

/** @brief GATT Subscribe parameters */
@@ -3013,6 +3013,8 @@ static void gatt_write_ccc_rsp(struct bt_conn *conn, u8_t err,

BT_DBG("err 0x%02x", err);

params->flags &= ~BT_GATT_SUBSCRIBE_WRITE_PENDING;

/* if write to CCC failed we remove subscription and notify app */
if (err) {
sys_snode_t *node, *tmp, *prev = NULL;
@@ -3050,6 +3052,8 @@ static int gatt_write_ccc(struct bt_conn *conn, u16_t handle, u16_t value,

BT_DBG("handle 0x%04x value 0x%04x", handle, value);

params->flags |= BT_GATT_SUBSCRIBE_WRITE_PENDING;

return gatt_send(conn, buf, func, params, NULL);
}

@@ -3123,6 +3127,10 @@ int bt_gatt_unsubscribe(struct bt_conn *conn,
if (params == tmp) {
found = true;
sys_slist_remove(&subscriptions, prev, &tmp->node);
/* Attempt to cancel if write is pending */
if (params->flags & BT_GATT_SUBSCRIBE_WRITE_PENDING) {
bt_gatt_cancel(conn, params);
}
continue;
} else {
prev = &tmp->node;

0 comments on commit 219bb6f

Please sign in to comment.
You can’t perform that action at this time.