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>
This commit is contained in:
parent
662a519a17
commit
219bb6fe1f
2 changed files with 15 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue