Bluetooth: GATT: Use atomic_t for subscribe flags
This makes use of atomic_t helpers to set, test and clear flags. Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
219bb6fe1f
commit
29782a006b
3 changed files with 13 additions and 7 deletions
|
@ -1227,14 +1227,16 @@ enum {
|
|||
* when the client reconnects, it will have to
|
||||
* issue a new subscription.
|
||||
*/
|
||||
BT_GATT_SUBSCRIBE_FLAG_VOLATILE = BIT(0),
|
||||
BT_GATT_SUBSCRIBE_FLAG_VOLATILE,
|
||||
|
||||
/** Write pending flag
|
||||
*
|
||||
* If set, indicates write operation is pending waiting remote end to
|
||||
* respond.
|
||||
*/
|
||||
BT_GATT_SUBSCRIBE_WRITE_PENDING = BIT(1),
|
||||
BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING,
|
||||
|
||||
BT_GATT_SUBSCRIBE_NUM_FLAGS
|
||||
};
|
||||
|
||||
/** @brief GATT Subscribe parameters */
|
||||
|
@ -1250,7 +1252,8 @@ struct bt_gatt_subscribe_params {
|
|||
/** Subscribe value */
|
||||
u16_t value;
|
||||
/** Subscription flags */
|
||||
u8_t flags;
|
||||
ATOMIC_DEFINE(flags, BT_GATT_SUBSCRIBE_NUM_FLAGS);
|
||||
|
||||
sys_snode_t node;
|
||||
};
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ typedef enum bt_l2cap_chan_state {
|
|||
BT_L2CAP_CONNECTED,
|
||||
/** Channel in disconnecting state */
|
||||
BT_L2CAP_DISCONNECT,
|
||||
|
||||
} __packed bt_l2cap_chan_state_t;
|
||||
|
||||
/** @brief Status of L2CAP channel. */
|
||||
|
|
|
@ -1829,7 +1829,8 @@ static void remove_subscriptions(struct bt_conn *conn)
|
|||
}
|
||||
|
||||
if (!bt_addr_le_is_bonded(conn->id, &conn->le.dst) ||
|
||||
(params->flags & BT_GATT_SUBSCRIBE_FLAG_VOLATILE)) {
|
||||
(atomic_test_bit(params->flags,
|
||||
BT_GATT_SUBSCRIBE_FLAG_VOLATILE))) {
|
||||
/* Remove subscription */
|
||||
params->value = 0U;
|
||||
gatt_subscription_remove(conn, prev, params);
|
||||
|
@ -3013,7 +3014,7 @@ 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;
|
||||
atomic_clear_bit(params->flags, BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING);
|
||||
|
||||
/* if write to CCC failed we remove subscription and notify app */
|
||||
if (err) {
|
||||
|
@ -3052,7 +3053,7 @@ 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;
|
||||
atomic_set_bit(params->flags, BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING);
|
||||
|
||||
return gatt_send(conn, buf, func, params, NULL);
|
||||
}
|
||||
|
@ -3128,7 +3129,8 @@ int bt_gatt_unsubscribe(struct bt_conn *conn,
|
|||
found = true;
|
||||
sys_slist_remove(&subscriptions, prev, &tmp->node);
|
||||
/* Attempt to cancel if write is pending */
|
||||
if (params->flags & BT_GATT_SUBSCRIBE_WRITE_PENDING) {
|
||||
if (atomic_test_bit(params->flags,
|
||||
BT_GATT_SUBSCRIBE_FLAG_WRITE_PENDING)) {
|
||||
bt_gatt_cancel(conn, params);
|
||||
}
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue