diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c index aec3bd39562571..75de8fdd38bfed 100644 --- a/subsys/bluetooth/host/gatt.c +++ b/subsys/bluetooth/host/gatt.c @@ -3103,7 +3103,7 @@ static u8_t remove_peer_from_attr(const struct bt_gatt_attr *attr, return BT_GATT_ITER_CONTINUE; } -int bt_gatt_clear_ccc(u8_t id, const bt_addr_le_t *addr) +static int bt_gatt_clear_ccc(u8_t id, const bt_addr_le_t *addr) { char key[BT_SETTINGS_KEY_MAX]; @@ -3124,6 +3124,60 @@ int bt_gatt_clear_ccc(u8_t id, const bt_addr_le_t *addr) return settings_delete(key); } +#if defined(CONFIG_BT_GATT_CACHING) +static struct gatt_cf_cfg *find_cf_cfg_by_addr(const bt_addr_le_t *addr) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(cf_cfg); i++) { + if (!bt_addr_le_cmp(addr, &cf_cfg[i].peer)) { + return &cf_cfg[i]; + } + } + + return NULL; +} +#endif /* CONFIG_BT_GATT_CACHING */ + +static int bt_gatt_clear_cf(u8_t id, const bt_addr_le_t *addr) +{ +#if defined(CONFIG_BT_GATT_CACHING) + char key[BT_SETTINGS_KEY_MAX]; + struct gatt_cf_cfg *cfg; + + if (id) { + char id_str[4]; + + snprintk(id_str, sizeof(id_str), "%u", id); + bt_settings_encode_key(key, sizeof(key), "cf", + (bt_addr_le_t *)addr, id_str); + } else { + bt_settings_encode_key(key, sizeof(key), "cf", + (bt_addr_le_t *)addr, NULL); + } + + cfg = find_cf_cfg_by_addr(addr); + if (cfg) { + clear_cf_cfg(cfg); + } + + return settings_delete(key); +#endif /* CONFIG_BT_GATT_CACHING */ + return 0; +} + +int bt_gatt_clear(u8_t id, const bt_addr_le_t *addr) +{ + int err; + + err = bt_gatt_clear_ccc(id, addr); + if (err < 0) { + return err; + } + + return bt_gatt_clear_cf(id, addr); +} + static void ccc_clear(struct _bt_gatt_ccc *ccc, bt_addr_le_t *addr) { struct bt_gatt_ccc_cfg *cfg; @@ -3254,19 +3308,6 @@ static int ccc_set(int argc, char **argv, void *val_ctx) BT_SETTINGS_DEFINE(ccc, ccc_set, NULL, NULL); #if defined(CONFIG_BT_GATT_CACHING) -static struct gatt_cf_cfg *find_cf_cfg_by_addr(const bt_addr_le_t *addr) -{ - int i; - - for (i = 0; i < ARRAY_SIZE(cf_cfg); i++) { - if (!bt_addr_le_cmp(addr, &cf_cfg[i].peer)) { - return &cf_cfg[i]; - } - } - - return NULL; -} - static int cf_set(int argc, char **argv, void *val_ctx) { struct gatt_cf_cfg *cfg; diff --git a/subsys/bluetooth/host/gatt_internal.h b/subsys/bluetooth/host/gatt_internal.h index 67c46844e0d83e..d716c1b13f6735 100644 --- a/subsys/bluetooth/host/gatt_internal.h +++ b/subsys/bluetooth/host/gatt_internal.h @@ -18,7 +18,8 @@ void bt_gatt_disconnected(struct bt_conn *conn); bool bt_gatt_change_aware(struct bt_conn *conn, bool req); int bt_gatt_store_ccc(u8_t id, const bt_addr_le_t *addr); -int bt_gatt_clear_ccc(u8_t id, const bt_addr_le_t *addr); + +int bt_gatt_clear(u8_t id, const bt_addr_le_t *addr); #if defined(CONFIG_BT_GATT_CLIENT) void bt_gatt_notification(struct bt_conn *conn, u16_t handle, diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index f8d83dc491635b..2bbb6d1e3d02c2 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -1479,7 +1479,7 @@ int bt_unpair(u8_t id, const bt_addr_le_t *addr) } if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - bt_gatt_clear_ccc(id, addr); + bt_gatt_clear(id, addr); } return 0; diff --git a/subsys/bluetooth/host/keys.c b/subsys/bluetooth/host/keys.c index 1e98fb9ac7e2d3..df6c92e0660403 100644 --- a/subsys/bluetooth/host/keys.c +++ b/subsys/bluetooth/host/keys.c @@ -231,7 +231,7 @@ static void keys_clear_id(struct bt_keys *keys, void *data) if (*id == keys->id) { if (IS_ENABLED(CONFIG_BT_SETTINGS)) { - bt_gatt_clear_ccc(*id, &keys->addr); + bt_gatt_clear(*id, &keys->addr); } bt_keys_clear(keys);