Skip to content

Bluetooth: GATT: Fix not clearing Client Features #15328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 55 additions & 14 deletions subsys/bluetooth/host/gatt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion subsys/bluetooth/host/gatt_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion subsys/bluetooth/host/keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down