diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2011-04-28 14:29:03 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-04-28 15:14:43 -0400 |
commit | 4df378a10e31698df1679f3329301d773a654b61 (patch) | |
tree | 033d9f8267801fd657339fd0299c96979556930f | |
parent | 4748fed2d1a2a7a816277754498b8aa70850e051 (diff) |
Bluetooth: Add store_hint parameter to mgmt_new_key
Even for keys that shouldn't be stored some use cases require the
knowledge of a new key having been created so that the conclusion of a
successful pairing can be made. Therefore, always send the mgmt_new_key
event but add a store_hint parameter to it to indicate to user space
whether the key should be stored or not.
Signed-off-by: Johan Hedberg <johan.hedberg@nokia.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
-rw-r--r-- | include/net/bluetooth/hci_core.h | 2 | ||||
-rw-r--r-- | include/net/bluetooth/mgmt.h | 1 | ||||
-rw-r--r-- | net/bluetooth/hci_core.c | 21 | ||||
-rw-r--r-- | net/bluetooth/mgmt.c | 3 |
4 files changed, 16 insertions, 11 deletions
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 88c2cd92eaea..14cc3249c1eb 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h | |||
@@ -775,7 +775,7 @@ int mgmt_index_removed(u16 index); | |||
775 | int mgmt_powered(u16 index, u8 powered); | 775 | int mgmt_powered(u16 index, u8 powered); |
776 | int mgmt_discoverable(u16 index, u8 discoverable); | 776 | int mgmt_discoverable(u16 index, u8 discoverable); |
777 | int mgmt_connectable(u16 index, u8 connectable); | 777 | int mgmt_connectable(u16 index, u8 connectable); |
778 | int mgmt_new_key(u16 index, struct link_key *key); | 778 | int mgmt_new_key(u16 index, struct link_key *key, u8 persistent); |
779 | int mgmt_connected(u16 index, bdaddr_t *bdaddr); | 779 | int mgmt_connected(u16 index, bdaddr_t *bdaddr); |
780 | int mgmt_disconnected(u16 index, bdaddr_t *bdaddr); | 780 | int mgmt_disconnected(u16 index, bdaddr_t *bdaddr); |
781 | int mgmt_disconnect_failed(u16 index); | 781 | int mgmt_disconnect_failed(u16 index); |
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h index 353a85dc2de0..4899286ed4e4 100644 --- a/include/net/bluetooth/mgmt.h +++ b/include/net/bluetooth/mgmt.h | |||
@@ -230,6 +230,7 @@ struct mgmt_ev_controller_error { | |||
230 | 230 | ||
231 | #define MGMT_EV_NEW_KEY 0x000A | 231 | #define MGMT_EV_NEW_KEY 0x000A |
232 | struct mgmt_ev_new_key { | 232 | struct mgmt_ev_new_key { |
233 | __u8 store_hint; | ||
233 | struct mgmt_key_info key; | 234 | struct mgmt_key_info key; |
234 | } __packed; | 235 | } __packed; |
235 | 236 | ||
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 60260cae3a04..b6bda3fac10e 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c | |||
@@ -1062,7 +1062,7 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, | |||
1062 | bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len) | 1062 | bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len) |
1063 | { | 1063 | { |
1064 | struct link_key *key, *old_key; | 1064 | struct link_key *key, *old_key; |
1065 | u8 old_key_type; | 1065 | u8 old_key_type, persistent; |
1066 | 1066 | ||
1067 | old_key = hci_find_link_key(hdev, bdaddr); | 1067 | old_key = hci_find_link_key(hdev, bdaddr); |
1068 | if (old_key) { | 1068 | if (old_key) { |
@@ -1089,12 +1089,6 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, | |||
1089 | conn->key_type = type; | 1089 | conn->key_type = type; |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | if (new_key && !hci_persistent_key(hdev, conn, type, old_key_type)) { | ||
1093 | list_del(&key->list); | ||
1094 | kfree(key); | ||
1095 | return 0; | ||
1096 | } | ||
1097 | |||
1098 | bacpy(&key->bdaddr, bdaddr); | 1092 | bacpy(&key->bdaddr, bdaddr); |
1099 | memcpy(key->val, val, 16); | 1093 | memcpy(key->val, val, 16); |
1100 | key->pin_len = pin_len; | 1094 | key->pin_len = pin_len; |
@@ -1104,8 +1098,17 @@ int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, | |||
1104 | else | 1098 | else |
1105 | key->type = type; | 1099 | key->type = type; |
1106 | 1100 | ||
1107 | if (new_key) | 1101 | if (!new_key) |
1108 | mgmt_new_key(hdev->id, key); | 1102 | return 0; |
1103 | |||
1104 | persistent = hci_persistent_key(hdev, conn, type, old_key_type); | ||
1105 | |||
1106 | mgmt_new_key(hdev->id, key, persistent); | ||
1107 | |||
1108 | if (!persistent) { | ||
1109 | list_del(&key->list); | ||
1110 | kfree(key); | ||
1111 | } | ||
1109 | 1112 | ||
1110 | return 0; | 1113 | return 0; |
1111 | } | 1114 | } |
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c index 232ea8bfff19..2481d257ed98 100644 --- a/net/bluetooth/mgmt.c +++ b/net/bluetooth/mgmt.c | |||
@@ -1858,12 +1858,13 @@ int mgmt_connectable(u16 index, u8 connectable) | |||
1858 | return ret; | 1858 | return ret; |
1859 | } | 1859 | } |
1860 | 1860 | ||
1861 | int mgmt_new_key(u16 index, struct link_key *key) | 1861 | int mgmt_new_key(u16 index, struct link_key *key, u8 persistent) |
1862 | { | 1862 | { |
1863 | struct mgmt_ev_new_key ev; | 1863 | struct mgmt_ev_new_key ev; |
1864 | 1864 | ||
1865 | memset(&ev, 0, sizeof(ev)); | 1865 | memset(&ev, 0, sizeof(ev)); |
1866 | 1866 | ||
1867 | ev.store_hint = persistent; | ||
1867 | bacpy(&ev.key.bdaddr, &key->bdaddr); | 1868 | bacpy(&ev.key.bdaddr, &key->bdaddr); |
1868 | ev.key.type = key->type; | 1869 | ev.key.type = key->type; |
1869 | memcpy(ev.key.val, key->val, 16); | 1870 | memcpy(ev.key.val, key->val, 16); |