diff --git a/subsys/bluetooth/host/conn.c b/subsys/bluetooth/host/conn.c index 3eaebfe8caf..1c4e46658dd 100644 --- a/subsys/bluetooth/host/conn.c +++ b/subsys/bluetooth/host/conn.c @@ -1626,7 +1626,7 @@ struct bt_conn *bt_conn_lookup_state_le(const bt_addr_le_t *peer, return NULL; } -void bt_conn_disconnect_all(void) +void bt_conn_disconnect_all(u8_t id) { int i; @@ -1637,6 +1637,10 @@ void bt_conn_disconnect_all(void) continue; } + if (conn->id != id) { + continue; + } + if (conn->state == BT_CONN_CONNECTED) { bt_conn_disconnect(conn, BT_HCI_ERR_REMOTE_USER_TERM_CONN); diff --git a/subsys/bluetooth/host/conn_internal.h b/subsys/bluetooth/host/conn_internal.h index 66a74086d67..cb3463c5692 100644 --- a/subsys/bluetooth/host/conn_internal.h +++ b/subsys/bluetooth/host/conn_internal.h @@ -162,7 +162,7 @@ u8_t bt_conn_get_io_capa(void); u8_t bt_conn_ssp_get_auth(const struct bt_conn *conn); void bt_conn_ssp_auth(struct bt_conn *conn, u32_t passkey); -void bt_conn_disconnect_all(void); +void bt_conn_disconnect_all(u8_t id); /* Look up an existing connection */ struct bt_conn *bt_conn_lookup_handle(u16_t handle); diff --git a/subsys/bluetooth/host/hci_core.c b/subsys/bluetooth/host/hci_core.c index cf2802c2b28..71698a09a3c 100644 --- a/subsys/bluetooth/host/hci_core.c +++ b/subsys/bluetooth/host/hci_core.c @@ -749,7 +749,7 @@ static void update_conn_param(struct bt_conn *conn) } #if defined(CONFIG_BT_SMP) -static void update_pending_id(struct bt_keys *keys) +static void update_pending_id(struct bt_keys *keys, void *data) { if (keys->flags & BT_KEYS_ID_PENDING_ADD) { keys->flags &= ~BT_KEYS_ID_PENDING_ADD; @@ -777,7 +777,7 @@ static void le_enh_conn_complete(struct bt_hci_evt_le_enh_conn_complete *evt) #if defined(CONFIG_BT_SMP) if (atomic_test_and_clear_bit(bt_dev.flags, BT_DEV_ID_PENDING)) { - bt_keys_foreach(BT_KEYS_IRK, update_pending_id); + bt_keys_foreach(BT_KEYS_IRK, update_pending_id, NULL); } #endif @@ -1303,12 +1303,12 @@ static int set_flow_control(void) } #endif /* CONFIG_BT_HCI_ACL_FLOW_CONTROL */ -static int bt_clear_all_pairings(void) +static int bt_clear_all_pairings(u8_t id) { - bt_conn_disconnect_all(); + bt_conn_disconnect_all(id); if (IS_ENABLED(CONFIG_BT_SMP)) { - bt_keys_clear_all(); + bt_keys_clear_all(id); } if (IS_ENABLED(CONFIG_BT_BREDR)) { @@ -1327,7 +1327,7 @@ int bt_unpair(u8_t id, const bt_addr_le_t *addr) } if (!addr || !bt_addr_le_cmp(addr, BT_ADDR_LE_ANY)) { - return bt_clear_all_pairings(); + return bt_clear_all_pairings(id); } conn = bt_conn_lookup_addr_le(id, addr); @@ -2552,7 +2552,7 @@ done: return err; } -static void keys_add_id(struct bt_keys *keys) +static void keys_add_id(struct bt_keys *keys, void *data) { hci_id_add(&keys->addr, keys->irk.val); } @@ -2606,7 +2606,7 @@ int bt_id_del(struct bt_keys *keys) if (bt_dev.le.rl_entries > bt_dev.le.rl_size) { bt_dev.le.rl_entries--; keys->keys &= ~BT_KEYS_IRK; - bt_keys_foreach(BT_KEYS_IRK, keys_add_id); + bt_keys_foreach(BT_KEYS_IRK, keys_add_id, NULL); goto done; } diff --git a/subsys/bluetooth/host/keys.c b/subsys/bluetooth/host/keys.c index fe1df5243e7..3ae85eac6ed 100644 --- a/subsys/bluetooth/host/keys.c +++ b/subsys/bluetooth/host/keys.c @@ -56,13 +56,14 @@ struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr) return NULL; } -void bt_keys_foreach(int type, void (*func)(struct bt_keys *keys)) +void bt_keys_foreach(int type, void (*func)(struct bt_keys *keys, void *data), + void *data) { int i; for (i = 0; i < ARRAY_SIZE(key_pool); i++) { if ((key_pool[i].keys & type)) { - func(&key_pool[i]); + func(&key_pool[i], data); } } } @@ -204,9 +205,18 @@ void bt_keys_clear(struct bt_keys *keys) memset(keys, 0, sizeof(*keys)); } -void bt_keys_clear_all(void) +static void keys_clear_id(struct bt_keys *keys, void *data) { - bt_keys_foreach(BT_KEYS_ALL, bt_keys_clear); + u8_t *id = data; + + if (*id == keys->id) { + bt_keys_clear(keys); + } +} + +void bt_keys_clear_all(u8_t id) +{ + bt_keys_foreach(BT_KEYS_ALL, keys_clear_id, &id); } #if defined(CONFIG_BT_SETTINGS) @@ -317,7 +327,7 @@ static int keys_commit(void) * called multiple times for the same address, especially if * the keys were already removed. */ - bt_keys_foreach(BT_KEYS_IRK, (bt_keys_func_t)bt_id_add); + bt_keys_foreach(BT_KEYS_IRK, (bt_keys_func_t)bt_id_add, NULL); return 0; } diff --git a/subsys/bluetooth/host/keys.h b/subsys/bluetooth/host/keys.h index 4267e9f2c32..7579066170c 100644 --- a/subsys/bluetooth/host/keys.h +++ b/subsys/bluetooth/host/keys.h @@ -64,7 +64,8 @@ struct bt_keys { offsetof(struct bt_keys, storage_start)) typedef void (*bt_keys_func_t)(struct bt_keys *keys); -void bt_keys_foreach(int type, bt_keys_func_t func); +void bt_keys_foreach(int type, void (*func)(struct bt_keys *keys, void *data), + void *data); struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr); struct bt_keys *bt_keys_get_type(int type, u8_t id, const bt_addr_le_t *addr); @@ -74,7 +75,7 @@ struct bt_keys *bt_keys_find_addr(u8_t id, const bt_addr_le_t *addr); void bt_keys_add_type(struct bt_keys *keys, int type); void bt_keys_clear(struct bt_keys *keys); -void bt_keys_clear_all(void); +void bt_keys_clear_all(u8_t id); #if defined(CONFIG_BT_SETTINGS) int bt_keys_store(struct bt_keys *keys);