Skip to content

Commit fd45b04

Browse files
committed
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 d4ba8ff commit fd45b04

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
@@ -1278,6 +1278,20 @@ enum {
12781278
*/
12791279
BT_GATT_SUBSCRIBE_FLAG_VOLATILE,
12801280

1281+
/** No resubscribe flag
1282+
*
1283+
* By default when BT_GATT_SUBSCRIBE_FLAG_VOLATILE is unset, the
1284+
* subscription will be automatically renewed when the client
1285+
* reconnects, as a workaround for GATT servers that do not persist
1286+
* subscriptions.
1287+
*
1288+
* This flag will disable the automatic resubscription. It is useful
1289+
* if the application layer knows that the GATT server remembers
1290+
* subscriptions from previous connections and wants to avoid renewing
1291+
* the subscriptions.
1292+
*/
1293+
BT_GATT_SUBSCRIBE_FLAG_NO_RESUB,
1294+
12811295
/** Write pending flag
12821296
*
12831297
* 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
@@ -3579,11 +3579,15 @@ static void add_subscriptions(struct bt_conn *conn)
35793579
continue;
35803580
}
35813581

3582-
/* Force write to CCC to workaround devices that don't track
3583-
* it properly.
3584-
*/
3585-
gatt_write_ccc(conn, params->ccc_handle, params->value,
3586-
gatt_write_ccc_rsp, params);
3582+
if (bt_addr_le_is_bonded(conn->id, &conn->le.dst) &&
3583+
!atomic_test_bit(params->flags,
3584+
BT_GATT_SUBSCRIBE_FLAG_NO_RESUB)) {
3585+
/* Force write to CCC to workaround devices that don't
3586+
* track it properly.
3587+
*/
3588+
gatt_write_ccc(conn, params->ccc_handle, params->value,
3589+
gatt_write_ccc_rsp, params);
3590+
}
35873591
}
35883592
}
35893593

0 commit comments

Comments
 (0)