Skip to content

Commit f2a34a6

Browse files
Vudentzjhedberg
authored andcommitted
Bluetooth: GATT: Fix not clearing Client Features
When a device is considered unpaired any configuration set in Client Features shall also be removed. Fixes #15329 Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 510a6dc commit f2a34a6

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

subsys/bluetooth/host/gatt.c

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3103,7 +3103,7 @@ static u8_t remove_peer_from_attr(const struct bt_gatt_attr *attr,
31033103
return BT_GATT_ITER_CONTINUE;
31043104
}
31053105

3106-
int bt_gatt_clear_ccc(u8_t id, const bt_addr_le_t *addr)
3106+
static int bt_gatt_clear_ccc(u8_t id, const bt_addr_le_t *addr)
31073107
{
31083108
char key[BT_SETTINGS_KEY_MAX];
31093109

@@ -3124,6 +3124,60 @@ int bt_gatt_clear_ccc(u8_t id, const bt_addr_le_t *addr)
31243124
return settings_delete(key);
31253125
}
31263126

3127+
#if defined(CONFIG_BT_GATT_CACHING)
3128+
static struct gatt_cf_cfg *find_cf_cfg_by_addr(const bt_addr_le_t *addr)
3129+
{
3130+
int i;
3131+
3132+
for (i = 0; i < ARRAY_SIZE(cf_cfg); i++) {
3133+
if (!bt_addr_le_cmp(addr, &cf_cfg[i].peer)) {
3134+
return &cf_cfg[i];
3135+
}
3136+
}
3137+
3138+
return NULL;
3139+
}
3140+
#endif /* CONFIG_BT_GATT_CACHING */
3141+
3142+
static int bt_gatt_clear_cf(u8_t id, const bt_addr_le_t *addr)
3143+
{
3144+
#if defined(CONFIG_BT_GATT_CACHING)
3145+
char key[BT_SETTINGS_KEY_MAX];
3146+
struct gatt_cf_cfg *cfg;
3147+
3148+
if (id) {
3149+
char id_str[4];
3150+
3151+
snprintk(id_str, sizeof(id_str), "%u", id);
3152+
bt_settings_encode_key(key, sizeof(key), "cf",
3153+
(bt_addr_le_t *)addr, id_str);
3154+
} else {
3155+
bt_settings_encode_key(key, sizeof(key), "cf",
3156+
(bt_addr_le_t *)addr, NULL);
3157+
}
3158+
3159+
cfg = find_cf_cfg_by_addr(addr);
3160+
if (cfg) {
3161+
clear_cf_cfg(cfg);
3162+
}
3163+
3164+
return settings_delete(key);
3165+
#endif /* CONFIG_BT_GATT_CACHING */
3166+
return 0;
3167+
}
3168+
3169+
int bt_gatt_clear(u8_t id, const bt_addr_le_t *addr)
3170+
{
3171+
int err;
3172+
3173+
err = bt_gatt_clear_ccc(id, addr);
3174+
if (err < 0) {
3175+
return err;
3176+
}
3177+
3178+
return bt_gatt_clear_cf(id, addr);
3179+
}
3180+
31273181
static void ccc_clear(struct _bt_gatt_ccc *ccc, bt_addr_le_t *addr)
31283182
{
31293183
struct bt_gatt_ccc_cfg *cfg;
@@ -3254,19 +3308,6 @@ static int ccc_set(int argc, char **argv, void *val_ctx)
32543308
BT_SETTINGS_DEFINE(ccc, ccc_set, NULL, NULL);
32553309

32563310
#if defined(CONFIG_BT_GATT_CACHING)
3257-
static struct gatt_cf_cfg *find_cf_cfg_by_addr(const bt_addr_le_t *addr)
3258-
{
3259-
int i;
3260-
3261-
for (i = 0; i < ARRAY_SIZE(cf_cfg); i++) {
3262-
if (!bt_addr_le_cmp(addr, &cf_cfg[i].peer)) {
3263-
return &cf_cfg[i];
3264-
}
3265-
}
3266-
3267-
return NULL;
3268-
}
3269-
32703311
static int cf_set(int argc, char **argv, void *val_ctx)
32713312
{
32723313
struct gatt_cf_cfg *cfg;

subsys/bluetooth/host/gatt_internal.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ void bt_gatt_disconnected(struct bt_conn *conn);
1818
bool bt_gatt_change_aware(struct bt_conn *conn, bool req);
1919

2020
int bt_gatt_store_ccc(u8_t id, const bt_addr_le_t *addr);
21-
int bt_gatt_clear_ccc(u8_t id, const bt_addr_le_t *addr);
21+
22+
int bt_gatt_clear(u8_t id, const bt_addr_le_t *addr);
2223

2324
#if defined(CONFIG_BT_GATT_CLIENT)
2425
void bt_gatt_notification(struct bt_conn *conn, u16_t handle,

subsys/bluetooth/host/hci_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1492,7 +1492,7 @@ int bt_unpair(u8_t id, const bt_addr_le_t *addr)
14921492
}
14931493

14941494
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
1495-
bt_gatt_clear_ccc(id, addr);
1495+
bt_gatt_clear(id, addr);
14961496
}
14971497

14981498
return 0;

subsys/bluetooth/host/keys.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static void keys_clear_id(struct bt_keys *keys, void *data)
231231

232232
if (*id == keys->id) {
233233
if (IS_ENABLED(CONFIG_BT_SETTINGS)) {
234-
bt_gatt_clear_ccc(*id, &keys->addr);
234+
bt_gatt_clear(*id, &keys->addr);
235235
}
236236

237237
bt_keys_clear(keys);

0 commit comments

Comments
 (0)