Commit 7652ff6a authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann

Bluetooth: Move mgmt event sending out from hci_add_link_key()

There are two callers of hci_add_link_key(). The first one is the HCI
Link Key Notification event and the second one the mgmt code that
receives a list of link keys from user space. Previously we've had the
hci_add_link_key() function being responsible for also emitting a mgmt
signal but for the latter use case this should not happen. Because of
this a rather awkward new_key paramter has been passed to the function.

This patch moves the mgmt event sending out from the hci_add_link_key()
function, thereby making the code a bit more understandable.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent 567fa2aa
...@@ -860,8 +860,8 @@ void hci_uuids_clear(struct hci_dev *hdev); ...@@ -860,8 +860,8 @@ void hci_uuids_clear(struct hci_dev *hdev);
void hci_link_keys_clear(struct hci_dev *hdev); void hci_link_keys_clear(struct hci_dev *hdev);
struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
int new_key, bdaddr_t *bdaddr, u8 *val, bdaddr_t *bdaddr, u8 *val, u8 type,
u8 type, u8 pin_len); u8 pin_len, bool *persistent);
struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand, struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand,
bool master); bool master);
struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
......
...@@ -3002,12 +3002,11 @@ struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, ...@@ -3002,12 +3002,11 @@ struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
} }
struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
int new_key, bdaddr_t *bdaddr, u8 *val, bdaddr_t *bdaddr, u8 *val, u8 type,
u8 type, u8 pin_len) u8 pin_len, bool *persistent)
{ {
struct link_key *key, *old_key; struct link_key *key, *old_key;
u8 old_key_type; u8 old_key_type;
bool persistent;
old_key = hci_find_link_key(hdev, bdaddr); old_key = hci_find_link_key(hdev, bdaddr);
if (old_key) { if (old_key) {
...@@ -3042,15 +3041,9 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, ...@@ -3042,15 +3041,9 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
else else
key->type = type; key->type = type;
if (!new_key) if (persistent)
return key; *persistent = hci_persistent_key(hdev, conn, type,
old_key_type);
persistent = hci_persistent_key(hdev, conn, type, old_key_type);
mgmt_new_link_key(hdev, key, persistent);
if (conn)
conn->flush_key = !persistent;
return key; return key;
} }
......
...@@ -3111,6 +3111,8 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -3111,6 +3111,8 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
{ {
struct hci_ev_link_key_notify *ev = (void *) skb->data; struct hci_ev_link_key_notify *ev = (void *) skb->data;
struct hci_conn *conn; struct hci_conn *conn;
struct link_key *key;
bool persistent;
u8 pin_len = 0; u8 pin_len = 0;
BT_DBG("%s", hdev->name); BT_DBG("%s", hdev->name);
...@@ -3129,10 +3131,20 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -3129,10 +3131,20 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
hci_conn_drop(conn); hci_conn_drop(conn);
} }
if (test_bit(HCI_MGMT, &hdev->dev_flags)) if (!test_bit(HCI_MGMT, &hdev->dev_flags))
hci_add_link_key(hdev, conn, 1, &ev->bdaddr, ev->link_key, goto unlock;
ev->key_type, pin_len);
key = hci_add_link_key(hdev, conn, &ev->bdaddr, ev->link_key,
ev->key_type, pin_len, &persistent);
if (!key)
goto unlock;
mgmt_new_link_key(hdev, key, persistent);
if (conn)
conn->flush_key = !persistent;
unlock:
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
} }
......
...@@ -2424,8 +2424,8 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data, ...@@ -2424,8 +2424,8 @@ static int load_link_keys(struct sock *sk, struct hci_dev *hdev, void *data,
for (i = 0; i < key_count; i++) { for (i = 0; i < key_count; i++) {
struct mgmt_link_key_info *key = &cp->keys[i]; struct mgmt_link_key_info *key = &cp->keys[i];
hci_add_link_key(hdev, NULL, 0, &key->addr.bdaddr, key->val, hci_add_link_key(hdev, NULL, &key->addr.bdaddr, key->val,
key->type, key->pin_len); key->type, key->pin_len, NULL);
} }
cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0); cmd_complete(sk, hdev->id, MGMT_OP_LOAD_LINK_KEYS, 0, NULL, 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment