Skip to content

Commit db106a2

Browse files
fnde-otjhedberg
authored andcommitted
bluetooth: host: Add flag to prevent client resubscription on reconnect
When set, the BT_GATT_SUBSCRIBE_FLAG_NO_RESUB flag indicates that the subscription should not be renewed when reconnecting with the server. This is useful if the application layer knows that the GATT server persists subscription information. Signed-off-by: François Delawarde <[email protected]>
1 parent bf361aa commit db106a2

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

include/bluetooth/gatt.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,20 @@ enum {
12791279
*/
12801280
BT_GATT_SUBSCRIBE_FLAG_VOLATILE,
12811281

1282+
/** No resubscribe flag
1283+
*
1284+
* By default when BT_GATT_SUBSCRIBE_FLAG_VOLATILE is unset, the
1285+
* subscription will be automatically renewed when the client
1286+
* reconnects, as a workaround for GATT servers that do not persist
1287+
* subscriptions.
1288+
*
1289+
* This flag will disable the automatic resubscription. It is useful
1290+
* if the application layer knows that the GATT server remembers
1291+
* subscriptions from previous connections and wants to avoid renewing
1292+
* the subscriptions.
1293+
*/
1294+
BT_GATT_SUBSCRIBE_FLAG_NO_RESUB,
1295+
12821296
/** Write pending flag
12831297
*
12841298
* If set, indicates write operation is pending waiting remote end to

subsys/bluetooth/host/gatt.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3570,11 +3570,15 @@ static void add_subscriptions(struct bt_conn *conn)
35703570
continue;
35713571
}
35723572

3573-
/* Force write to CCC to workaround devices that don't track
3574-
* it properly.
3575-
*/
3576-
gatt_write_ccc(conn, params->ccc_handle, params->value,
3577-
gatt_write_ccc_rsp, params);
3573+
if (bt_addr_le_is_bonded(conn->id, &conn->le.dst) &&
3574+
!atomic_test_bit(params->flags,
3575+
BT_GATT_SUBSCRIBE_FLAG_NO_RESUB)) {
3576+
/* Force write to CCC to workaround devices that don't
3577+
* track it properly.
3578+
*/
3579+
gatt_write_ccc(conn, params->ccc_handle, params->value,
3580+
gatt_write_ccc_rsp, params);
3581+
}
35783582
}
35793583
}
35803584

0 commit comments

Comments
 (0)