Skip to content

Commit 7096fa5

Browse files
jsiverskogcarlescufi
authored andcommitted
Bluetooth: GATT: Remove all subscriptions for connection when unpairing
Make sure all subscriptions are removed when a connection is unpaired. Fixes #21131 Signed-off-by: Jacob Siverskog <[email protected]>
1 parent afe0882 commit 7096fa5

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

include/bluetooth/gatt.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,8 @@ struct bt_gatt_subscribe_params;
12561256
/** @typedef bt_gatt_notify_func_t
12571257
* @brief Notification callback function
12581258
*
1259-
* @param conn Connection object.
1259+
* @param conn Connection object. May be NULL, indicating that the peer is
1260+
* being unpaired
12601261
* @param params Subscription parameters.
12611262
* @param data Attribute value data. If NULL then subscription was removed.
12621263
* @param length Attribute value length.

subsys/bluetooth/host/gatt.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4137,6 +4137,23 @@ static int sc_clear_by_addr(u8_t id, const bt_addr_le_t *addr)
41374137
return 0;
41384138
}
41394139

4140+
static void bt_gatt_clear_subscriptions(const bt_addr_le_t *addr)
4141+
{
4142+
#if defined(CONFIG_BT_GATT_CLIENT)
4143+
struct bt_gatt_subscribe_params *params, *tmp;
4144+
sys_snode_t *prev = NULL;
4145+
4146+
SYS_SLIST_FOR_EACH_CONTAINER_SAFE(&subscriptions, params, tmp, node) {
4147+
if (bt_addr_le_cmp(addr, &params->_peer)) {
4148+
prev = &params->node;
4149+
continue;
4150+
}
4151+
params->value = 0U;
4152+
gatt_subscription_remove(NULL, prev, params);
4153+
}
4154+
#endif /* CONFIG_BT_GATT_CLIENT */
4155+
}
4156+
41404157
int bt_gatt_clear(u8_t id, const bt_addr_le_t *addr)
41414158
{
41424159
int err;
@@ -4156,6 +4173,8 @@ int bt_gatt_clear(u8_t id, const bt_addr_le_t *addr)
41564173
return err;
41574174
}
41584175

4176+
bt_gatt_clear_subscriptions(addr);
4177+
41594178
return 0;
41604179
}
41614180

tests/bluetooth/tester/src/gatt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,14 +1650,14 @@ static u8_t notify_func(struct bt_conn *conn,
16501650
const void *data, u16_t length)
16511651
{
16521652
struct gatt_notification_ev *ev = (void *) ev_buf;
1653-
const bt_addr_le_t *addr = bt_conn_get_dst(conn);
1653+
const bt_addr_le_t *addr;
16541654

1655-
if (!data) {
1655+
if (!conn || !data) {
16561656
LOG_DBG("Unsubscribed");
16571657
(void)memset(params, 0, sizeof(*params));
16581658
return BT_GATT_ITER_STOP;
16591659
}
1660-
1660+
addr = bt_conn_get_dst(conn);
16611661
ev->type = (u8_t) subscribe_params.value;
16621662
ev->handle = sys_cpu_to_le16(subscribe_params.value_handle);
16631663
ev->data_length = sys_cpu_to_le16(length);

0 commit comments

Comments
 (0)