Bluetooth: Pass identity to connection and pairing clearing functions
When doing bt_unpair() we need to pass the given identity when disconnecting and clearing keys, in case all associated pairings were requested to be cleared. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
parent
e70c556dcc
commit
cbb1b84f91
5 changed files with 32 additions and 17 deletions
|
@ -1626,7 +1626,7 @@ struct bt_conn *bt_conn_lookup_state_le(const bt_addr_le_t *peer,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_conn_disconnect_all(void)
|
void bt_conn_disconnect_all(u8_t id)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -1637,6 +1637,10 @@ void bt_conn_disconnect_all(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (conn->id != id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (conn->state == BT_CONN_CONNECTED) {
|
if (conn->state == BT_CONN_CONNECTED) {
|
||||||
bt_conn_disconnect(conn,
|
bt_conn_disconnect(conn,
|
||||||
BT_HCI_ERR_REMOTE_USER_TERM_CONN);
|
BT_HCI_ERR_REMOTE_USER_TERM_CONN);
|
||||||
|
|
|
@ -162,7 +162,7 @@ u8_t bt_conn_get_io_capa(void);
|
||||||
u8_t bt_conn_ssp_get_auth(const struct bt_conn *conn);
|
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_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 */
|
/* Look up an existing connection */
|
||||||
struct bt_conn *bt_conn_lookup_handle(u16_t handle);
|
struct bt_conn *bt_conn_lookup_handle(u16_t handle);
|
||||||
|
|
|
@ -749,7 +749,7 @@ static void update_conn_param(struct bt_conn *conn)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_BT_SMP)
|
#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) {
|
if (keys->flags & BT_KEYS_ID_PENDING_ADD) {
|
||||||
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 defined(CONFIG_BT_SMP)
|
||||||
if (atomic_test_and_clear_bit(bt_dev.flags, BT_DEV_ID_PENDING)) {
|
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
|
#endif
|
||||||
|
|
||||||
|
@ -1303,12 +1303,12 @@ static int set_flow_control(void)
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_HCI_ACL_FLOW_CONTROL */
|
#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)) {
|
if (IS_ENABLED(CONFIG_BT_SMP)) {
|
||||||
bt_keys_clear_all();
|
bt_keys_clear_all(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_BT_BREDR)) {
|
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)) {
|
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);
|
conn = bt_conn_lookup_addr_le(id, addr);
|
||||||
|
@ -2552,7 +2552,7 @@ done:
|
||||||
return err;
|
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);
|
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) {
|
if (bt_dev.le.rl_entries > bt_dev.le.rl_size) {
|
||||||
bt_dev.le.rl_entries--;
|
bt_dev.le.rl_entries--;
|
||||||
keys->keys &= ~BT_KEYS_IRK;
|
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;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,13 +56,14 @@ struct bt_keys *bt_keys_get_addr(u8_t id, const bt_addr_le_t *addr)
|
||||||
return NULL;
|
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;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(key_pool); i++) {
|
for (i = 0; i < ARRAY_SIZE(key_pool); i++) {
|
||||||
if ((key_pool[i].keys & type)) {
|
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));
|
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)
|
#if defined(CONFIG_BT_SETTINGS)
|
||||||
|
@ -317,7 +327,7 @@ static int keys_commit(void)
|
||||||
* called multiple times for the same address, especially if
|
* called multiple times for the same address, especially if
|
||||||
* the keys were already removed.
|
* 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,8 @@ struct bt_keys {
|
||||||
offsetof(struct bt_keys, storage_start))
|
offsetof(struct bt_keys, storage_start))
|
||||||
|
|
||||||
typedef void (*bt_keys_func_t)(struct bt_keys *keys);
|
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_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);
|
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_add_type(struct bt_keys *keys, int type);
|
||||||
void bt_keys_clear(struct bt_keys *keys);
|
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)
|
#if defined(CONFIG_BT_SETTINGS)
|
||||||
int bt_keys_store(struct bt_keys *keys);
|
int bt_keys_store(struct bt_keys *keys);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue