YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | BlueZ - Bluetooth protocol stack for Linux |
Ron Shaffer | 2d0a034 | 2010-05-28 11:53:46 -0400 | [diff] [blame] | 3 | Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
| 5 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License version 2 as |
| 9 | published by the Free Software Foundation; |
| 10 | |
| 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 12 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 14 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 15 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 16 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 17 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 19 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 20 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 21 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | SOFTWARE IS DISCLAIMED. |
| 23 | */ |
| 24 | |
| 25 | /* Bluetooth HCI event handling. */ |
| 26 | |
Gustavo Padovan | 8c520a5 | 2012-05-23 04:04:22 -0300 | [diff] [blame] | 27 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/unaligned.h> |
| 29 | |
| 30 | #include <net/bluetooth/bluetooth.h> |
| 31 | #include <net/bluetooth/hci_core.h> |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 32 | #include <net/bluetooth/mgmt.h> |
Andrei Emeltchenko | 8e2a0d9 | 2012-09-27 17:26:08 +0300 | [diff] [blame^] | 33 | #include <net/bluetooth/a2mp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* Handle HCI Event packets */ |
| 36 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 37 | static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 39 | __u8 status = *((__u8 *) skb->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 41 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Andre Guedes | e6d465c | 2011-11-09 17:14:26 -0300 | [diff] [blame] | 43 | if (status) { |
| 44 | hci_dev_lock(hdev); |
| 45 | mgmt_stop_discovery_failed(hdev, status); |
| 46 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 47 | return; |
Andre Guedes | e6d465c | 2011-11-09 17:14:26 -0300 | [diff] [blame] | 48 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 50 | clear_bit(HCI_INQUIRY, &hdev->flags); |
| 51 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 52 | hci_dev_lock(hdev); |
Johan Hedberg | ff9ef57 | 2012-01-04 14:23:45 +0200 | [diff] [blame] | 53 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 54 | hci_dev_unlock(hdev); |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 55 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 56 | hci_req_complete(hdev, HCI_OP_INQUIRY_CANCEL, status); |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 57 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 58 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 61 | static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb) |
| 62 | { |
| 63 | __u8 status = *((__u8 *) skb->data); |
| 64 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 65 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 66 | |
| 67 | if (status) |
| 68 | return; |
| 69 | |
| 70 | set_bit(HCI_PERIODIC_INQ, &hdev->dev_flags); |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 71 | } |
| 72 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 73 | static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 75 | __u8 status = *((__u8 *) skb->data); |
| 76 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 77 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 78 | |
| 79 | if (status) |
| 80 | return; |
| 81 | |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 82 | clear_bit(HCI_PERIODIC_INQ, &hdev->dev_flags); |
| 83 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 84 | hci_conn_check_pending(hdev); |
| 85 | } |
| 86 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 87 | static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, |
| 88 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 89 | { |
| 90 | BT_DBG("%s", hdev->name); |
| 91 | } |
| 92 | |
| 93 | static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb) |
| 94 | { |
| 95 | struct hci_rp_role_discovery *rp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 98 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 100 | if (rp->status) |
| 101 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 103 | hci_dev_lock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 105 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 106 | if (conn) { |
| 107 | if (rp->role) |
| 108 | conn->link_mode &= ~HCI_LM_MASTER; |
| 109 | else |
| 110 | conn->link_mode |= HCI_LM_MASTER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 112 | |
| 113 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 116 | static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
| 117 | { |
| 118 | struct hci_rp_read_link_policy *rp = (void *) skb->data; |
| 119 | struct hci_conn *conn; |
| 120 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 121 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 122 | |
| 123 | if (rp->status) |
| 124 | return; |
| 125 | |
| 126 | hci_dev_lock(hdev); |
| 127 | |
| 128 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 129 | if (conn) |
| 130 | conn->link_policy = __le16_to_cpu(rp->policy); |
| 131 | |
| 132 | hci_dev_unlock(hdev); |
| 133 | } |
| 134 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 135 | static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 137 | struct hci_rp_write_link_policy *rp = (void *) skb->data; |
| 138 | struct hci_conn *conn; |
| 139 | void *sent; |
| 140 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 141 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 142 | |
| 143 | if (rp->status) |
| 144 | return; |
| 145 | |
| 146 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY); |
| 147 | if (!sent) |
| 148 | return; |
| 149 | |
| 150 | hci_dev_lock(hdev); |
| 151 | |
| 152 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 153 | if (conn) |
Harvey Harrison | 8398531 | 2008-05-02 16:25:46 -0700 | [diff] [blame] | 154 | conn->link_policy = get_unaligned_le16(sent + 2); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 155 | |
| 156 | hci_dev_unlock(hdev); |
| 157 | } |
| 158 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 159 | static void hci_cc_read_def_link_policy(struct hci_dev *hdev, |
| 160 | struct sk_buff *skb) |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 161 | { |
| 162 | struct hci_rp_read_def_link_policy *rp = (void *) skb->data; |
| 163 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 164 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 165 | |
| 166 | if (rp->status) |
| 167 | return; |
| 168 | |
| 169 | hdev->link_policy = __le16_to_cpu(rp->policy); |
| 170 | } |
| 171 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 172 | static void hci_cc_write_def_link_policy(struct hci_dev *hdev, |
| 173 | struct sk_buff *skb) |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 174 | { |
| 175 | __u8 status = *((__u8 *) skb->data); |
| 176 | void *sent; |
| 177 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 178 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 179 | |
| 180 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY); |
| 181 | if (!sent) |
| 182 | return; |
| 183 | |
| 184 | if (!status) |
| 185 | hdev->link_policy = get_unaligned_le16(sent); |
| 186 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 187 | hci_req_complete(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 190 | static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) |
| 191 | { |
| 192 | __u8 status = *((__u8 *) skb->data); |
| 193 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 194 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 195 | |
Gustavo F. Padovan | 1057213 | 2011-03-16 15:36:29 -0300 | [diff] [blame] | 196 | clear_bit(HCI_RESET, &hdev->flags); |
| 197 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 198 | hci_req_complete(hdev, HCI_OP_RESET, status); |
Andre Guedes | d23264a | 2011-11-25 20:53:38 -0300 | [diff] [blame] | 199 | |
Johan Hedberg | a297e97 | 2012-02-21 17:55:47 +0200 | [diff] [blame] | 200 | /* Reset all non-persistent flags */ |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 201 | hdev->dev_flags &= ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLASS) | |
| 202 | BIT(HCI_PERIODIC_INQ)); |
Andre Guedes | 69775ff | 2012-02-23 16:50:05 +0200 | [diff] [blame] | 203 | |
| 204 | hdev->discovery.state = DISCOVERY_STOPPED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 208 | { |
| 209 | __u8 status = *((__u8 *) skb->data); |
| 210 | void *sent; |
| 211 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 212 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 213 | |
| 214 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME); |
| 215 | if (!sent) |
| 216 | return; |
| 217 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 218 | hci_dev_lock(hdev); |
| 219 | |
Johan Hedberg | f51d5b2 | 2012-02-22 18:17:32 +0200 | [diff] [blame] | 220 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
| 221 | mgmt_set_local_name_complete(hdev, sent, status); |
Johan Hedberg | 28cc7bd | 2012-02-22 21:06:55 +0200 | [diff] [blame] | 222 | else if (!status) |
| 223 | memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH); |
Johan Hedberg | f51d5b2 | 2012-02-22 18:17:32 +0200 | [diff] [blame] | 224 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 225 | hci_dev_unlock(hdev); |
Johan Hedberg | 3159d38 | 2012-02-24 13:47:56 +0200 | [diff] [blame] | 226 | |
| 227 | hci_req_complete(hdev, HCI_OP_WRITE_LOCAL_NAME, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 231 | { |
| 232 | struct hci_rp_read_local_name *rp = (void *) skb->data; |
| 233 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 234 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 235 | |
| 236 | if (rp->status) |
| 237 | return; |
| 238 | |
Johan Hedberg | db99b5f | 2012-02-22 20:14:22 +0200 | [diff] [blame] | 239 | if (test_bit(HCI_SETUP, &hdev->dev_flags)) |
| 240 | memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 244 | { |
| 245 | __u8 status = *((__u8 *) skb->data); |
| 246 | void *sent; |
| 247 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 248 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 249 | |
| 250 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE); |
| 251 | if (!sent) |
| 252 | return; |
| 253 | |
| 254 | if (!status) { |
| 255 | __u8 param = *((__u8 *) sent); |
| 256 | |
| 257 | if (param == AUTH_ENABLED) |
| 258 | set_bit(HCI_AUTH, &hdev->flags); |
| 259 | else |
| 260 | clear_bit(HCI_AUTH, &hdev->flags); |
| 261 | } |
| 262 | |
Johan Hedberg | 33ef95e | 2012-02-16 23:56:27 +0200 | [diff] [blame] | 263 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
| 264 | mgmt_auth_enable_complete(hdev, status); |
| 265 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 266 | hci_req_complete(hdev, HCI_OP_WRITE_AUTH_ENABLE, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 270 | { |
| 271 | __u8 status = *((__u8 *) skb->data); |
| 272 | void *sent; |
| 273 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 274 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 275 | |
| 276 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE); |
| 277 | if (!sent) |
| 278 | return; |
| 279 | |
| 280 | if (!status) { |
| 281 | __u8 param = *((__u8 *) sent); |
| 282 | |
| 283 | if (param) |
| 284 | set_bit(HCI_ENCRYPT, &hdev->flags); |
| 285 | else |
| 286 | clear_bit(HCI_ENCRYPT, &hdev->flags); |
| 287 | } |
| 288 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 289 | hci_req_complete(hdev, HCI_OP_WRITE_ENCRYPT_MODE, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 293 | { |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 294 | __u8 param, status = *((__u8 *) skb->data); |
| 295 | int old_pscan, old_iscan; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 296 | void *sent; |
| 297 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 298 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 299 | |
| 300 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); |
| 301 | if (!sent) |
| 302 | return; |
| 303 | |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 304 | param = *((__u8 *) sent); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 305 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 306 | hci_dev_lock(hdev); |
| 307 | |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 308 | if (status) { |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 309 | mgmt_write_scan_failed(hdev, param, status); |
Johan Hedberg | 2d7cee5 | 2011-11-07 22:16:03 +0200 | [diff] [blame] | 310 | hdev->discov_timeout = 0; |
| 311 | goto done; |
| 312 | } |
| 313 | |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 314 | old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags); |
| 315 | old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 316 | |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 317 | if (param & SCAN_INQUIRY) { |
| 318 | set_bit(HCI_ISCAN, &hdev->flags); |
| 319 | if (!old_iscan) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 320 | mgmt_discoverable(hdev, 1); |
Johan Hedberg | 16ab91a | 2011-11-07 22:16:02 +0200 | [diff] [blame] | 321 | if (hdev->discov_timeout > 0) { |
| 322 | int to = msecs_to_jiffies(hdev->discov_timeout * 1000); |
| 323 | queue_delayed_work(hdev->workqueue, &hdev->discov_off, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 324 | to); |
Johan Hedberg | 16ab91a | 2011-11-07 22:16:02 +0200 | [diff] [blame] | 325 | } |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 326 | } else if (old_iscan) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 327 | mgmt_discoverable(hdev, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 328 | |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 329 | if (param & SCAN_PAGE) { |
| 330 | set_bit(HCI_PSCAN, &hdev->flags); |
| 331 | if (!old_pscan) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 332 | mgmt_connectable(hdev, 1); |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 333 | } else if (old_pscan) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 334 | mgmt_connectable(hdev, 0); |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 335 | |
| 336 | done: |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 337 | hci_dev_unlock(hdev); |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 338 | hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 342 | { |
| 343 | struct hci_rp_read_class_of_dev *rp = (void *) skb->data; |
| 344 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 345 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 346 | |
| 347 | if (rp->status) |
| 348 | return; |
| 349 | |
| 350 | memcpy(hdev->dev_class, rp->dev_class, 3); |
| 351 | |
| 352 | BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 353 | hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 357 | { |
| 358 | __u8 status = *((__u8 *) skb->data); |
| 359 | void *sent; |
| 360 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 361 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 362 | |
| 363 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV); |
| 364 | if (!sent) |
| 365 | return; |
| 366 | |
Marcel Holtmann | 7f9a903 | 2012-02-22 18:38:01 +0100 | [diff] [blame] | 367 | hci_dev_lock(hdev); |
| 368 | |
| 369 | if (status == 0) |
| 370 | memcpy(hdev->dev_class, sent, 3); |
| 371 | |
| 372 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
| 373 | mgmt_set_class_of_dev_complete(hdev, sent, status); |
| 374 | |
| 375 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) |
| 379 | { |
| 380 | struct hci_rp_read_voice_setting *rp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | __u16 setting; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 382 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 383 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 384 | |
| 385 | if (rp->status) |
| 386 | return; |
| 387 | |
| 388 | setting = __le16_to_cpu(rp->voice_setting); |
| 389 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 390 | if (hdev->voice_setting == setting) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 391 | return; |
| 392 | |
| 393 | hdev->voice_setting = setting; |
| 394 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 395 | BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 396 | |
Gustavo F. Padovan | 3c54711 | 2011-12-14 22:58:44 -0200 | [diff] [blame] | 397 | if (hdev->notify) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 398 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 399 | } |
| 400 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 401 | static void hci_cc_write_voice_setting(struct hci_dev *hdev, |
| 402 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 403 | { |
| 404 | __u8 status = *((__u8 *) skb->data); |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 405 | __u16 setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | void *sent; |
| 407 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 408 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 410 | if (status) |
| 411 | return; |
| 412 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 413 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING); |
| 414 | if (!sent) |
| 415 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 417 | setting = get_unaligned_le16(sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 419 | if (hdev->voice_setting == setting) |
| 420 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 422 | hdev->voice_setting = setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 424 | BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting); |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 425 | |
Gustavo F. Padovan | 3c54711 | 2011-12-14 22:58:44 -0200 | [diff] [blame] | 426 | if (hdev->notify) |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 427 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 430 | static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 432 | __u8 status = *((__u8 *) skb->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 434 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 436 | hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 439 | static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 440 | { |
| 441 | __u8 status = *((__u8 *) skb->data); |
| 442 | void *sent; |
| 443 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 444 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 445 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 446 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); |
| 447 | if (!sent) |
| 448 | return; |
| 449 | |
Johan Hedberg | ed2c4ee | 2012-02-17 00:56:28 +0200 | [diff] [blame] | 450 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 451 | mgmt_ssp_enable_complete(hdev, *((u8 *) sent), status); |
| 452 | else if (!status) { |
| 453 | if (*((u8 *) sent)) |
| 454 | set_bit(HCI_SSP_ENABLED, &hdev->dev_flags); |
| 455 | else |
| 456 | clear_bit(HCI_SSP_ENABLED, &hdev->dev_flags); |
| 457 | } |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 458 | } |
| 459 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 460 | static u8 hci_get_inquiry_mode(struct hci_dev *hdev) |
| 461 | { |
| 462 | if (hdev->features[6] & LMP_EXT_INQ) |
| 463 | return 2; |
| 464 | |
| 465 | if (hdev->features[3] & LMP_RSSI_INQ) |
| 466 | return 1; |
| 467 | |
| 468 | if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 469 | hdev->lmp_subver == 0x0757) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 470 | return 1; |
| 471 | |
| 472 | if (hdev->manufacturer == 15) { |
| 473 | if (hdev->hci_rev == 0x03 && hdev->lmp_subver == 0x6963) |
| 474 | return 1; |
| 475 | if (hdev->hci_rev == 0x09 && hdev->lmp_subver == 0x6963) |
| 476 | return 1; |
| 477 | if (hdev->hci_rev == 0x00 && hdev->lmp_subver == 0x6965) |
| 478 | return 1; |
| 479 | } |
| 480 | |
| 481 | if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 482 | hdev->lmp_subver == 0x1805) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 483 | return 1; |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | static void hci_setup_inquiry_mode(struct hci_dev *hdev) |
| 489 | { |
| 490 | u8 mode; |
| 491 | |
| 492 | mode = hci_get_inquiry_mode(hdev); |
| 493 | |
| 494 | hci_send_cmd(hdev, HCI_OP_WRITE_INQUIRY_MODE, 1, &mode); |
| 495 | } |
| 496 | |
| 497 | static void hci_setup_event_mask(struct hci_dev *hdev) |
| 498 | { |
| 499 | /* The second byte is 0xff instead of 0x9f (two reserved bits |
| 500 | * disabled) since a Broadcom 1.2 dongle doesn't respond to the |
| 501 | * command otherwise */ |
| 502 | u8 events[8] = { 0xff, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x00 }; |
| 503 | |
Ville Tervo | 6de6c18 | 2011-05-27 11:16:21 +0300 | [diff] [blame] | 504 | /* CSR 1.1 dongles does not accept any bitfield so don't try to set |
| 505 | * any event mask for pre 1.2 devices */ |
Andrei Emeltchenko | 5a13b09 | 2011-12-01 14:33:28 +0200 | [diff] [blame] | 506 | if (hdev->hci_ver < BLUETOOTH_VER_1_2) |
Ville Tervo | 6de6c18 | 2011-05-27 11:16:21 +0300 | [diff] [blame] | 507 | return; |
| 508 | |
| 509 | events[4] |= 0x01; /* Flow Specification Complete */ |
| 510 | events[4] |= 0x02; /* Inquiry Result with RSSI */ |
| 511 | events[4] |= 0x04; /* Read Remote Extended Features Complete */ |
| 512 | events[5] |= 0x08; /* Synchronous Connection Complete */ |
| 513 | events[5] |= 0x10; /* Synchronous Connection Changed */ |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 514 | |
| 515 | if (hdev->features[3] & LMP_RSSI_INQ) |
Johan Hedberg | a24299e | 2012-04-26 09:47:46 +0300 | [diff] [blame] | 516 | events[4] |= 0x02; /* Inquiry Result with RSSI */ |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 517 | |
Andre Guedes | 999dcd1 | 2012-07-24 15:03:52 -0300 | [diff] [blame] | 518 | if (lmp_sniffsubr_capable(hdev)) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 519 | events[5] |= 0x20; /* Sniff Subrating */ |
| 520 | |
| 521 | if (hdev->features[5] & LMP_PAUSE_ENC) |
| 522 | events[5] |= 0x80; /* Encryption Key Refresh Complete */ |
| 523 | |
| 524 | if (hdev->features[6] & LMP_EXT_INQ) |
| 525 | events[5] |= 0x40; /* Extended Inquiry Result */ |
| 526 | |
Andre Guedes | c58e810 | 2012-07-24 15:03:53 -0300 | [diff] [blame] | 527 | if (lmp_no_flush_capable(hdev)) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 528 | events[7] |= 0x01; /* Enhanced Flush Complete */ |
| 529 | |
| 530 | if (hdev->features[7] & LMP_LSTO) |
| 531 | events[6] |= 0x80; /* Link Supervision Timeout Changed */ |
| 532 | |
Andre Guedes | 9a1a199 | 2012-07-24 15:03:48 -0300 | [diff] [blame] | 533 | if (lmp_ssp_capable(hdev)) { |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 534 | events[6] |= 0x01; /* IO Capability Request */ |
| 535 | events[6] |= 0x02; /* IO Capability Response */ |
| 536 | events[6] |= 0x04; /* User Confirmation Request */ |
| 537 | events[6] |= 0x08; /* User Passkey Request */ |
| 538 | events[6] |= 0x10; /* Remote OOB Data Request */ |
| 539 | events[6] |= 0x20; /* Simple Pairing Complete */ |
| 540 | events[7] |= 0x04; /* User Passkey Notification */ |
| 541 | events[7] |= 0x08; /* Keypress Notification */ |
| 542 | events[7] |= 0x10; /* Remote Host Supported |
| 543 | * Features Notification */ |
| 544 | } |
| 545 | |
Andre Guedes | c383ddc | 2012-07-24 15:03:47 -0300 | [diff] [blame] | 546 | if (lmp_le_capable(hdev)) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 547 | events[7] |= 0x20; /* LE Meta-Event */ |
| 548 | |
| 549 | hci_send_cmd(hdev, HCI_OP_SET_EVENT_MASK, sizeof(events), events); |
| 550 | } |
| 551 | |
| 552 | static void hci_setup(struct hci_dev *hdev) |
| 553 | { |
Andrei Emeltchenko | e61ef49 | 2011-12-19 16:31:27 +0200 | [diff] [blame] | 554 | if (hdev->dev_type != HCI_BREDR) |
| 555 | return; |
| 556 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 557 | hci_setup_event_mask(hdev); |
| 558 | |
Andrei Emeltchenko | d095c1e | 2011-12-01 14:33:27 +0200 | [diff] [blame] | 559 | if (hdev->hci_ver > BLUETOOTH_VER_1_1) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 560 | hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL); |
| 561 | |
Gustavo Padovan | 6d3c730 | 2012-05-24 03:36:37 -0300 | [diff] [blame] | 562 | if (lmp_ssp_capable(hdev)) { |
Johan Hedberg | 54d04db | 2012-02-22 15:47:48 +0200 | [diff] [blame] | 563 | if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) { |
| 564 | u8 mode = 0x01; |
| 565 | hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 566 | sizeof(mode), &mode); |
Johan Hedberg | 54d04db | 2012-02-22 15:47:48 +0200 | [diff] [blame] | 567 | } else { |
| 568 | struct hci_cp_write_eir cp; |
| 569 | |
| 570 | memset(hdev->eir, 0, sizeof(hdev->eir)); |
| 571 | memset(&cp, 0, sizeof(cp)); |
| 572 | |
| 573 | hci_send_cmd(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp); |
| 574 | } |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | if (hdev->features[3] & LMP_RSSI_INQ) |
| 578 | hci_setup_inquiry_mode(hdev); |
| 579 | |
| 580 | if (hdev->features[7] & LMP_INQ_TX_PWR) |
| 581 | hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, 0, NULL); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 582 | |
| 583 | if (hdev->features[7] & LMP_EXTFEATURES) { |
| 584 | struct hci_cp_read_local_ext_features cp; |
| 585 | |
| 586 | cp.page = 0x01; |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 587 | hci_send_cmd(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, sizeof(cp), |
| 588 | &cp); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 589 | } |
Andre Guedes | e6100a2 | 2011-06-30 19:20:54 -0300 | [diff] [blame] | 590 | |
Johan Hedberg | 47990ea | 2012-02-22 11:58:37 +0200 | [diff] [blame] | 591 | if (test_bit(HCI_LINK_SECURITY, &hdev->dev_flags)) { |
| 592 | u8 enable = 1; |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 593 | hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(enable), |
| 594 | &enable); |
Johan Hedberg | 47990ea | 2012-02-22 11:58:37 +0200 | [diff] [blame] | 595 | } |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 598 | static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) |
| 599 | { |
| 600 | struct hci_rp_read_local_version *rp = (void *) skb->data; |
| 601 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 602 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 603 | |
| 604 | if (rp->status) |
Andrei Emeltchenko | 28b8df7 | 2012-02-24 12:45:44 +0200 | [diff] [blame] | 605 | goto done; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 606 | |
| 607 | hdev->hci_ver = rp->hci_ver; |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 608 | hdev->hci_rev = __le16_to_cpu(rp->hci_rev); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 609 | hdev->lmp_ver = rp->lmp_ver; |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 610 | hdev->manufacturer = __le16_to_cpu(rp->manufacturer); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 611 | hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 612 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 613 | BT_DBG("%s manufacturer 0x%4.4x hci ver %d:%d", hdev->name, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 614 | hdev->manufacturer, hdev->hci_ver, hdev->hci_rev); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 615 | |
| 616 | if (test_bit(HCI_INIT, &hdev->flags)) |
| 617 | hci_setup(hdev); |
Andrei Emeltchenko | 28b8df7 | 2012-02-24 12:45:44 +0200 | [diff] [blame] | 618 | |
| 619 | done: |
| 620 | hci_req_complete(hdev, HCI_OP_READ_LOCAL_VERSION, rp->status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | static void hci_setup_link_policy(struct hci_dev *hdev) |
| 624 | { |
Andrei Emeltchenko | 035100c | 2012-03-12 15:59:32 +0200 | [diff] [blame] | 625 | struct hci_cp_write_def_link_policy cp; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 626 | u16 link_policy = 0; |
| 627 | |
Andre Guedes | 9f92ebf | 2012-07-24 15:03:50 -0300 | [diff] [blame] | 628 | if (lmp_rswitch_capable(hdev)) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 629 | link_policy |= HCI_LP_RSWITCH; |
| 630 | if (hdev->features[0] & LMP_HOLD) |
| 631 | link_policy |= HCI_LP_HOLD; |
Andre Guedes | 6eded10 | 2012-07-24 15:03:51 -0300 | [diff] [blame] | 632 | if (lmp_sniff_capable(hdev)) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 633 | link_policy |= HCI_LP_SNIFF; |
| 634 | if (hdev->features[1] & LMP_PARK) |
| 635 | link_policy |= HCI_LP_PARK; |
| 636 | |
Andrei Emeltchenko | 035100c | 2012-03-12 15:59:32 +0200 | [diff] [blame] | 637 | cp.policy = cpu_to_le16(link_policy); |
| 638 | hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, sizeof(cp), &cp); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 639 | } |
| 640 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 641 | static void hci_cc_read_local_commands(struct hci_dev *hdev, |
| 642 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 643 | { |
| 644 | struct hci_rp_read_local_commands *rp = (void *) skb->data; |
| 645 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 646 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 647 | |
| 648 | if (rp->status) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 649 | goto done; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 650 | |
| 651 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 652 | |
| 653 | if (test_bit(HCI_INIT, &hdev->flags) && (hdev->commands[5] & 0x10)) |
| 654 | hci_setup_link_policy(hdev); |
| 655 | |
| 656 | done: |
| 657 | hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 658 | } |
| 659 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 660 | static void hci_cc_read_local_features(struct hci_dev *hdev, |
| 661 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 662 | { |
| 663 | struct hci_rp_read_local_features *rp = (void *) skb->data; |
| 664 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 665 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 666 | |
| 667 | if (rp->status) |
| 668 | return; |
| 669 | |
| 670 | memcpy(hdev->features, rp->features, 8); |
| 671 | |
| 672 | /* Adjust default settings according to features |
| 673 | * supported by device. */ |
| 674 | |
| 675 | if (hdev->features[0] & LMP_3SLOT) |
| 676 | hdev->pkt_type |= (HCI_DM3 | HCI_DH3); |
| 677 | |
| 678 | if (hdev->features[0] & LMP_5SLOT) |
| 679 | hdev->pkt_type |= (HCI_DM5 | HCI_DH5); |
| 680 | |
| 681 | if (hdev->features[1] & LMP_HV2) { |
| 682 | hdev->pkt_type |= (HCI_HV2); |
| 683 | hdev->esco_type |= (ESCO_HV2); |
| 684 | } |
| 685 | |
| 686 | if (hdev->features[1] & LMP_HV3) { |
| 687 | hdev->pkt_type |= (HCI_HV3); |
| 688 | hdev->esco_type |= (ESCO_HV3); |
| 689 | } |
| 690 | |
Andre Guedes | 45db810f | 2012-07-24 15:03:49 -0300 | [diff] [blame] | 691 | if (lmp_esco_capable(hdev)) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 692 | hdev->esco_type |= (ESCO_EV3); |
| 693 | |
| 694 | if (hdev->features[4] & LMP_EV4) |
| 695 | hdev->esco_type |= (ESCO_EV4); |
| 696 | |
| 697 | if (hdev->features[4] & LMP_EV5) |
| 698 | hdev->esco_type |= (ESCO_EV5); |
| 699 | |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 700 | if (hdev->features[5] & LMP_EDR_ESCO_2M) |
| 701 | hdev->esco_type |= (ESCO_2EV3); |
| 702 | |
| 703 | if (hdev->features[5] & LMP_EDR_ESCO_3M) |
| 704 | hdev->esco_type |= (ESCO_3EV3); |
| 705 | |
| 706 | if (hdev->features[5] & LMP_EDR_3S_ESCO) |
| 707 | hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); |
| 708 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 709 | BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 710 | hdev->features[0], hdev->features[1], |
| 711 | hdev->features[2], hdev->features[3], |
| 712 | hdev->features[4], hdev->features[5], |
| 713 | hdev->features[6], hdev->features[7]); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 714 | } |
| 715 | |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 716 | static void hci_set_le_support(struct hci_dev *hdev) |
| 717 | { |
| 718 | struct hci_cp_write_le_host_supported cp; |
| 719 | |
| 720 | memset(&cp, 0, sizeof(cp)); |
| 721 | |
Marcel Holtmann | 9d42820 | 2012-05-03 07:12:31 +0200 | [diff] [blame] | 722 | if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) { |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 723 | cp.le = 1; |
| 724 | cp.simul = !!(hdev->features[6] & LMP_SIMUL_LE_BR); |
| 725 | } |
| 726 | |
| 727 | if (cp.le != !!(hdev->host_features[0] & LMP_HOST_LE)) |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 728 | hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(cp), |
| 729 | &cp); |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 730 | } |
| 731 | |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 732 | static void hci_cc_read_local_ext_features(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 733 | struct sk_buff *skb) |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 734 | { |
| 735 | struct hci_rp_read_local_ext_features *rp = (void *) skb->data; |
| 736 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 737 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 738 | |
| 739 | if (rp->status) |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 740 | goto done; |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 741 | |
Andre Guedes | b5b32b6 | 2011-12-30 10:34:04 -0300 | [diff] [blame] | 742 | switch (rp->page) { |
| 743 | case 0: |
| 744 | memcpy(hdev->features, rp->features, 8); |
| 745 | break; |
| 746 | case 1: |
| 747 | memcpy(hdev->host_features, rp->features, 8); |
| 748 | break; |
| 749 | } |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 750 | |
Andre Guedes | c383ddc | 2012-07-24 15:03:47 -0300 | [diff] [blame] | 751 | if (test_bit(HCI_INIT, &hdev->flags) && lmp_le_capable(hdev)) |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 752 | hci_set_le_support(hdev); |
| 753 | |
| 754 | done: |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 755 | hci_req_complete(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, rp->status); |
| 756 | } |
| 757 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 758 | static void hci_cc_read_flow_control_mode(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 759 | struct sk_buff *skb) |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 760 | { |
| 761 | struct hci_rp_read_flow_control_mode *rp = (void *) skb->data; |
| 762 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 763 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 764 | |
| 765 | if (rp->status) |
| 766 | return; |
| 767 | |
| 768 | hdev->flow_ctl_mode = rp->mode; |
| 769 | |
| 770 | hci_req_complete(hdev, HCI_OP_READ_FLOW_CONTROL_MODE, rp->status); |
| 771 | } |
| 772 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 773 | static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) |
| 774 | { |
| 775 | struct hci_rp_read_buffer_size *rp = (void *) skb->data; |
| 776 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 777 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 778 | |
| 779 | if (rp->status) |
| 780 | return; |
| 781 | |
| 782 | hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu); |
| 783 | hdev->sco_mtu = rp->sco_mtu; |
| 784 | hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt); |
| 785 | hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt); |
| 786 | |
| 787 | if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) { |
| 788 | hdev->sco_mtu = 64; |
| 789 | hdev->sco_pkts = 8; |
| 790 | } |
| 791 | |
| 792 | hdev->acl_cnt = hdev->acl_pkts; |
| 793 | hdev->sco_cnt = hdev->sco_pkts; |
| 794 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 795 | BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu, |
| 796 | hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb) |
| 800 | { |
| 801 | struct hci_rp_read_bd_addr *rp = (void *) skb->data; |
| 802 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 803 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 804 | |
| 805 | if (!rp->status) |
| 806 | bacpy(&hdev->bdaddr, &rp->bdaddr); |
| 807 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 808 | hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status); |
| 809 | } |
| 810 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 811 | static void hci_cc_read_data_block_size(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 812 | struct sk_buff *skb) |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 813 | { |
| 814 | struct hci_rp_read_data_block_size *rp = (void *) skb->data; |
| 815 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 816 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 817 | |
| 818 | if (rp->status) |
| 819 | return; |
| 820 | |
| 821 | hdev->block_mtu = __le16_to_cpu(rp->max_acl_len); |
| 822 | hdev->block_len = __le16_to_cpu(rp->block_len); |
| 823 | hdev->num_blocks = __le16_to_cpu(rp->num_blocks); |
| 824 | |
| 825 | hdev->block_cnt = hdev->num_blocks; |
| 826 | |
| 827 | BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 828 | hdev->block_cnt, hdev->block_len); |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 829 | |
| 830 | hci_req_complete(hdev, HCI_OP_READ_DATA_BLOCK_SIZE, rp->status); |
| 831 | } |
| 832 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 833 | static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb) |
| 834 | { |
| 835 | __u8 status = *((__u8 *) skb->data); |
| 836 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 837 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 838 | |
| 839 | hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 840 | } |
| 841 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 842 | static void hci_cc_read_local_amp_info(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 843 | struct sk_buff *skb) |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 844 | { |
| 845 | struct hci_rp_read_local_amp_info *rp = (void *) skb->data; |
| 846 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 847 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 848 | |
| 849 | if (rp->status) |
Andrei Emeltchenko | 8e2a0d9 | 2012-09-27 17:26:08 +0300 | [diff] [blame^] | 850 | goto a2mp_rsp; |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 851 | |
| 852 | hdev->amp_status = rp->amp_status; |
| 853 | hdev->amp_total_bw = __le32_to_cpu(rp->total_bw); |
| 854 | hdev->amp_max_bw = __le32_to_cpu(rp->max_bw); |
| 855 | hdev->amp_min_latency = __le32_to_cpu(rp->min_latency); |
| 856 | hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu); |
| 857 | hdev->amp_type = rp->amp_type; |
| 858 | hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap); |
| 859 | hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size); |
| 860 | hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to); |
| 861 | hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to); |
| 862 | |
| 863 | hci_req_complete(hdev, HCI_OP_READ_LOCAL_AMP_INFO, rp->status); |
Andrei Emeltchenko | 8e2a0d9 | 2012-09-27 17:26:08 +0300 | [diff] [blame^] | 864 | |
| 865 | a2mp_rsp: |
| 866 | a2mp_send_getinfo_rsp(hdev); |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 867 | } |
| 868 | |
Johan Hedberg | b0916ea | 2011-01-10 13:44:55 +0200 | [diff] [blame] | 869 | static void hci_cc_delete_stored_link_key(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 870 | struct sk_buff *skb) |
Johan Hedberg | b0916ea | 2011-01-10 13:44:55 +0200 | [diff] [blame] | 871 | { |
| 872 | __u8 status = *((__u8 *) skb->data); |
| 873 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 874 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | b0916ea | 2011-01-10 13:44:55 +0200 | [diff] [blame] | 875 | |
| 876 | hci_req_complete(hdev, HCI_OP_DELETE_STORED_LINK_KEY, status); |
| 877 | } |
| 878 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 879 | static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb) |
| 880 | { |
| 881 | __u8 status = *((__u8 *) skb->data); |
| 882 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 883 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 884 | |
| 885 | hci_req_complete(hdev, HCI_OP_SET_EVENT_MASK, status); |
| 886 | } |
| 887 | |
| 888 | static void hci_cc_write_inquiry_mode(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 889 | struct sk_buff *skb) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 890 | { |
| 891 | __u8 status = *((__u8 *) skb->data); |
| 892 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 893 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 894 | |
| 895 | hci_req_complete(hdev, HCI_OP_WRITE_INQUIRY_MODE, status); |
| 896 | } |
| 897 | |
| 898 | static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 899 | struct sk_buff *skb) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 900 | { |
Marcel Holtmann | 91c4e9b | 2012-03-11 19:27:21 -0700 | [diff] [blame] | 901 | struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 902 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 903 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 904 | |
Marcel Holtmann | 91c4e9b | 2012-03-11 19:27:21 -0700 | [diff] [blame] | 905 | if (!rp->status) |
| 906 | hdev->inq_tx_power = rp->tx_power; |
| 907 | |
| 908 | hci_req_complete(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, rp->status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | static void hci_cc_set_event_flt(struct hci_dev *hdev, struct sk_buff *skb) |
| 912 | { |
| 913 | __u8 status = *((__u8 *) skb->data); |
| 914 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 915 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 916 | |
| 917 | hci_req_complete(hdev, HCI_OP_SET_EVENT_FLT, status); |
| 918 | } |
| 919 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 920 | static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 921 | { |
| 922 | struct hci_rp_pin_code_reply *rp = (void *) skb->data; |
| 923 | struct hci_cp_pin_code_reply *cp; |
| 924 | struct hci_conn *conn; |
| 925 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 926 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 927 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 928 | hci_dev_lock(hdev); |
| 929 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 930 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 931 | mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 932 | |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 933 | if (rp->status) |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 934 | goto unlock; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 935 | |
| 936 | cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY); |
| 937 | if (!cp) |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 938 | goto unlock; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 939 | |
| 940 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 941 | if (conn) |
| 942 | conn->pin_length = cp->pin_len; |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 943 | |
| 944 | unlock: |
| 945 | hci_dev_unlock(hdev); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 949 | { |
| 950 | struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data; |
| 951 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 952 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 953 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 954 | hci_dev_lock(hdev); |
| 955 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 956 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 957 | mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 958 | rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 959 | |
| 960 | hci_dev_unlock(hdev); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 961 | } |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 962 | |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 963 | static void hci_cc_le_read_buffer_size(struct hci_dev *hdev, |
| 964 | struct sk_buff *skb) |
| 965 | { |
| 966 | struct hci_rp_le_read_buffer_size *rp = (void *) skb->data; |
| 967 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 968 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 969 | |
| 970 | if (rp->status) |
| 971 | return; |
| 972 | |
| 973 | hdev->le_mtu = __le16_to_cpu(rp->le_mtu); |
| 974 | hdev->le_pkts = rp->le_max_pkt; |
| 975 | |
| 976 | hdev->le_cnt = hdev->le_pkts; |
| 977 | |
| 978 | BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts); |
| 979 | |
| 980 | hci_req_complete(hdev, HCI_OP_LE_READ_BUFFER_SIZE, rp->status); |
| 981 | } |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 982 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 983 | static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 984 | { |
| 985 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 986 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 987 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 988 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 989 | hci_dev_lock(hdev); |
| 990 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 991 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 992 | mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0, |
| 993 | rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 994 | |
| 995 | hci_dev_unlock(hdev); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 999 | struct sk_buff *skb) |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1000 | { |
| 1001 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1002 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1003 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1004 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1005 | hci_dev_lock(hdev); |
| 1006 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 1007 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1008 | mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1009 | ACL_LINK, 0, rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1010 | |
| 1011 | hci_dev_unlock(hdev); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1012 | } |
| 1013 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1014 | static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1015 | { |
| 1016 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1017 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1018 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1019 | |
| 1020 | hci_dev_lock(hdev); |
| 1021 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 1022 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1023 | mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1024 | 0, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1025 | |
| 1026 | hci_dev_unlock(hdev); |
| 1027 | } |
| 1028 | |
| 1029 | static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1030 | struct sk_buff *skb) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1031 | { |
| 1032 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1033 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1034 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1035 | |
| 1036 | hci_dev_lock(hdev); |
| 1037 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 1038 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1039 | mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1040 | ACL_LINK, 0, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1041 | |
| 1042 | hci_dev_unlock(hdev); |
| 1043 | } |
| 1044 | |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1045 | static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1046 | struct sk_buff *skb) |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1047 | { |
| 1048 | struct hci_rp_read_local_oob_data *rp = (void *) skb->data; |
| 1049 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1050 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1051 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1052 | hci_dev_lock(hdev); |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1053 | mgmt_read_local_oob_data_reply_complete(hdev, rp->hash, |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1054 | rp->randomizer, rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1055 | hci_dev_unlock(hdev); |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1056 | } |
| 1057 | |
Andre Guedes | 07f7fa5 | 2011-12-02 21:13:31 +0900 | [diff] [blame] | 1058 | static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 1059 | { |
| 1060 | __u8 status = *((__u8 *) skb->data); |
| 1061 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1062 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Andre Guedes | 7ba8b4b | 2012-02-03 17:47:59 -0300 | [diff] [blame] | 1063 | |
| 1064 | hci_req_complete(hdev, HCI_OP_LE_SET_SCAN_PARAM, status); |
Andre Guedes | 3fd2415 | 2012-02-03 17:48:01 -0300 | [diff] [blame] | 1065 | |
| 1066 | if (status) { |
| 1067 | hci_dev_lock(hdev); |
| 1068 | mgmt_start_discovery_failed(hdev, status); |
| 1069 | hci_dev_unlock(hdev); |
| 1070 | return; |
| 1071 | } |
Andre Guedes | 07f7fa5 | 2011-12-02 21:13:31 +0900 | [diff] [blame] | 1072 | } |
| 1073 | |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1074 | static void hci_cc_le_set_scan_enable(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1075 | struct sk_buff *skb) |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1076 | { |
| 1077 | struct hci_cp_le_set_scan_enable *cp; |
| 1078 | __u8 status = *((__u8 *) skb->data); |
| 1079 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1080 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1081 | |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1082 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE); |
| 1083 | if (!cp) |
| 1084 | return; |
| 1085 | |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1086 | switch (cp->enable) { |
| 1087 | case LE_SCANNING_ENABLED: |
Andre Guedes | 7ba8b4b | 2012-02-03 17:47:59 -0300 | [diff] [blame] | 1088 | hci_req_complete(hdev, HCI_OP_LE_SET_SCAN_ENABLE, status); |
| 1089 | |
Andre Guedes | 3fd2415 | 2012-02-03 17:48:01 -0300 | [diff] [blame] | 1090 | if (status) { |
| 1091 | hci_dev_lock(hdev); |
| 1092 | mgmt_start_discovery_failed(hdev, status); |
| 1093 | hci_dev_unlock(hdev); |
Andre Guedes | 7ba8b4b | 2012-02-03 17:47:59 -0300 | [diff] [blame] | 1094 | return; |
Andre Guedes | 3fd2415 | 2012-02-03 17:48:01 -0300 | [diff] [blame] | 1095 | } |
Andre Guedes | 7ba8b4b | 2012-02-03 17:47:59 -0300 | [diff] [blame] | 1096 | |
Andre Guedes | d23264a | 2011-11-25 20:53:38 -0300 | [diff] [blame] | 1097 | set_bit(HCI_LE_SCAN, &hdev->dev_flags); |
| 1098 | |
Andre Guedes | a8f13c8 | 2011-09-09 18:56:24 -0300 | [diff] [blame] | 1099 | hci_dev_lock(hdev); |
Andre Guedes | 343f935 | 2012-02-17 20:39:37 -0300 | [diff] [blame] | 1100 | hci_discovery_set_state(hdev, DISCOVERY_FINDING); |
Andre Guedes | a8f13c8 | 2011-09-09 18:56:24 -0300 | [diff] [blame] | 1101 | hci_dev_unlock(hdev); |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1102 | break; |
| 1103 | |
| 1104 | case LE_SCANNING_DISABLED: |
Andre Guedes | c9ecc48 | 2012-03-15 16:52:08 -0300 | [diff] [blame] | 1105 | if (status) { |
| 1106 | hci_dev_lock(hdev); |
| 1107 | mgmt_stop_discovery_failed(hdev, status); |
| 1108 | hci_dev_unlock(hdev); |
Andre Guedes | 7ba8b4b | 2012-02-03 17:47:59 -0300 | [diff] [blame] | 1109 | return; |
Andre Guedes | c9ecc48 | 2012-03-15 16:52:08 -0300 | [diff] [blame] | 1110 | } |
Andre Guedes | 7ba8b4b | 2012-02-03 17:47:59 -0300 | [diff] [blame] | 1111 | |
Andre Guedes | d23264a | 2011-11-25 20:53:38 -0300 | [diff] [blame] | 1112 | clear_bit(HCI_LE_SCAN, &hdev->dev_flags); |
| 1113 | |
Andre Guedes | bc3dd33 | 2012-03-06 19:37:06 -0300 | [diff] [blame] | 1114 | if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED && |
| 1115 | hdev->discovery.state == DISCOVERY_FINDING) { |
Andre Guedes | 5e0452c | 2012-02-17 20:39:38 -0300 | [diff] [blame] | 1116 | mgmt_interleaved_discovery(hdev); |
| 1117 | } else { |
| 1118 | hci_dev_lock(hdev); |
| 1119 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 1120 | hci_dev_unlock(hdev); |
| 1121 | } |
| 1122 | |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1123 | break; |
| 1124 | |
| 1125 | default: |
| 1126 | BT_ERR("Used reserved LE_Scan_Enable param %d", cp->enable); |
| 1127 | break; |
Andre Guedes | 3581508 | 2011-05-26 16:23:53 -0300 | [diff] [blame] | 1128 | } |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1129 | } |
| 1130 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 1131 | static void hci_cc_le_ltk_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1132 | { |
| 1133 | struct hci_rp_le_ltk_reply *rp = (void *) skb->data; |
| 1134 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1135 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 1136 | |
| 1137 | if (rp->status) |
| 1138 | return; |
| 1139 | |
| 1140 | hci_req_complete(hdev, HCI_OP_LE_LTK_REPLY, rp->status); |
| 1141 | } |
| 1142 | |
| 1143 | static void hci_cc_le_ltk_neg_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1144 | { |
| 1145 | struct hci_rp_le_ltk_neg_reply *rp = (void *) skb->data; |
| 1146 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1147 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 1148 | |
| 1149 | if (rp->status) |
| 1150 | return; |
| 1151 | |
| 1152 | hci_req_complete(hdev, HCI_OP_LE_LTK_NEG_REPLY, rp->status); |
| 1153 | } |
| 1154 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1155 | static void hci_cc_write_le_host_supported(struct hci_dev *hdev, |
| 1156 | struct sk_buff *skb) |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1157 | { |
Johan Hedberg | 06199cf | 2012-02-22 16:37:11 +0200 | [diff] [blame] | 1158 | struct hci_cp_write_le_host_supported *sent; |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1159 | __u8 status = *((__u8 *) skb->data); |
| 1160 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1161 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1162 | |
Johan Hedberg | 06199cf | 2012-02-22 16:37:11 +0200 | [diff] [blame] | 1163 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED); |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 1164 | if (!sent) |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1165 | return; |
| 1166 | |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 1167 | if (!status) { |
| 1168 | if (sent->le) |
| 1169 | hdev->host_features[0] |= LMP_HOST_LE; |
| 1170 | else |
| 1171 | hdev->host_features[0] &= ~LMP_HOST_LE; |
| 1172 | } |
| 1173 | |
| 1174 | if (test_bit(HCI_MGMT, &hdev->dev_flags) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1175 | !test_bit(HCI_INIT, &hdev->flags)) |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 1176 | mgmt_le_enable_complete(hdev, sent->le, status); |
| 1177 | |
| 1178 | hci_req_complete(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, status); |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1179 | } |
| 1180 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1181 | static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1182 | { |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1183 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1184 | |
| 1185 | if (status) { |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 1186 | hci_req_complete(hdev, HCI_OP_INQUIRY, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1187 | hci_conn_check_pending(hdev); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1188 | hci_dev_lock(hdev); |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 1189 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Andre Guedes | 7a13510 | 2011-11-09 17:14:25 -0300 | [diff] [blame] | 1190 | mgmt_start_discovery_failed(hdev, status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1191 | hci_dev_unlock(hdev); |
Johan Hedberg | 314b238 | 2011-04-27 10:29:57 -0400 | [diff] [blame] | 1192 | return; |
| 1193 | } |
| 1194 | |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 1195 | set_bit(HCI_INQUIRY, &hdev->flags); |
| 1196 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1197 | hci_dev_lock(hdev); |
Andre Guedes | 343f935 | 2012-02-17 20:39:37 -0300 | [diff] [blame] | 1198 | hci_discovery_set_state(hdev, DISCOVERY_FINDING); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1199 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1200 | } |
| 1201 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1202 | static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1204 | struct hci_cp_create_conn *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1205 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1207 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1208 | |
| 1209 | cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | if (!cp) |
| 1211 | return; |
| 1212 | |
| 1213 | hci_dev_lock(hdev); |
| 1214 | |
| 1215 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 1216 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1217 | BT_DBG("%s bdaddr %s hcon %p", hdev->name, batostr(&cp->bdaddr), conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
| 1219 | if (status) { |
| 1220 | if (conn && conn->state == BT_CONNECT) { |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 1221 | if (status != 0x0c || conn->attempt > 2) { |
| 1222 | conn->state = BT_CLOSED; |
| 1223 | hci_proto_connect_cfm(conn, status); |
| 1224 | hci_conn_del(conn); |
| 1225 | } else |
| 1226 | conn->state = BT_CONNECT2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | } |
| 1228 | } else { |
| 1229 | if (!conn) { |
| 1230 | conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr); |
| 1231 | if (conn) { |
Johan Hedberg | a0c808b | 2012-01-16 09:49:58 +0200 | [diff] [blame] | 1232 | conn->out = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | conn->link_mode |= HCI_LM_MASTER; |
| 1234 | } else |
Gustavo F. Padovan | 893ef97 | 2010-07-18 15:13:37 -0300 | [diff] [blame] | 1235 | BT_ERR("No memory for new connection"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | hci_dev_unlock(hdev); |
| 1240 | } |
| 1241 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1242 | static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1244 | struct hci_cp_add_sco *cp; |
| 1245 | struct hci_conn *acl, *sco; |
| 1246 | __u16 handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1248 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1249 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1250 | if (!status) |
| 1251 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1253 | cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO); |
| 1254 | if (!cp) |
| 1255 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1257 | handle = __le16_to_cpu(cp->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1259 | BT_DBG("%s handle 0x%4.4x", hdev->name, handle); |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 1260 | |
| 1261 | hci_dev_lock(hdev); |
| 1262 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1263 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1264 | if (acl) { |
| 1265 | sco = acl->link; |
| 1266 | if (sco) { |
| 1267 | sco->state = BT_CLOSED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1268 | |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1269 | hci_proto_connect_cfm(sco, status); |
| 1270 | hci_conn_del(sco); |
| 1271 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1272 | } |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 1273 | |
| 1274 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | } |
| 1276 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1277 | static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) |
| 1278 | { |
| 1279 | struct hci_cp_auth_requested *cp; |
| 1280 | struct hci_conn *conn; |
| 1281 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1282 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1283 | |
| 1284 | if (!status) |
| 1285 | return; |
| 1286 | |
| 1287 | cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED); |
| 1288 | if (!cp) |
| 1289 | return; |
| 1290 | |
| 1291 | hci_dev_lock(hdev); |
| 1292 | |
| 1293 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 1294 | if (conn) { |
| 1295 | if (conn->state == BT_CONFIG) { |
| 1296 | hci_proto_connect_cfm(conn, status); |
| 1297 | hci_conn_put(conn); |
| 1298 | } |
| 1299 | } |
| 1300 | |
| 1301 | hci_dev_unlock(hdev); |
| 1302 | } |
| 1303 | |
| 1304 | static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) |
| 1305 | { |
| 1306 | struct hci_cp_set_conn_encrypt *cp; |
| 1307 | struct hci_conn *conn; |
| 1308 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1309 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1310 | |
| 1311 | if (!status) |
| 1312 | return; |
| 1313 | |
| 1314 | cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT); |
| 1315 | if (!cp) |
| 1316 | return; |
| 1317 | |
| 1318 | hci_dev_lock(hdev); |
| 1319 | |
| 1320 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 1321 | if (conn) { |
| 1322 | if (conn->state == BT_CONFIG) { |
| 1323 | hci_proto_connect_cfm(conn, status); |
| 1324 | hci_conn_put(conn); |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | hci_dev_unlock(hdev); |
| 1329 | } |
| 1330 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1331 | static int hci_outgoing_auth_needed(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1332 | struct hci_conn *conn) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 1333 | { |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 1334 | if (conn->state != BT_CONFIG || !conn->out) |
| 1335 | return 0; |
| 1336 | |
Johan Hedberg | 765c2a9 | 2011-01-19 12:06:52 +0530 | [diff] [blame] | 1337 | if (conn->pending_sec_level == BT_SECURITY_SDP) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 1338 | return 0; |
| 1339 | |
| 1340 | /* Only request authentication for SSP connections or non-SSP |
Vinicius Costa Gomes | e9bf2bf | 2011-09-02 14:51:20 -0300 | [diff] [blame] | 1341 | * devices with sec_level HIGH or if MITM protection is requested */ |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1342 | if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) && |
| 1343 | conn->pending_sec_level != BT_SECURITY_HIGH) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 1344 | return 0; |
| 1345 | |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 1346 | return 1; |
| 1347 | } |
| 1348 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1349 | static int hci_resolve_name(struct hci_dev *hdev, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1350 | struct inquiry_entry *e) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1351 | { |
| 1352 | struct hci_cp_remote_name_req cp; |
| 1353 | |
| 1354 | memset(&cp, 0, sizeof(cp)); |
| 1355 | |
| 1356 | bacpy(&cp.bdaddr, &e->data.bdaddr); |
| 1357 | cp.pscan_rep_mode = e->data.pscan_rep_mode; |
| 1358 | cp.pscan_mode = e->data.pscan_mode; |
| 1359 | cp.clock_offset = e->data.clock_offset; |
| 1360 | |
| 1361 | return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
| 1362 | } |
| 1363 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 1364 | static bool hci_resolve_next_name(struct hci_dev *hdev) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1365 | { |
| 1366 | struct discovery_state *discov = &hdev->discovery; |
| 1367 | struct inquiry_entry *e; |
| 1368 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 1369 | if (list_empty(&discov->resolve)) |
| 1370 | return false; |
| 1371 | |
| 1372 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
Ram Malovany | c810089 | 2012-07-19 10:26:09 +0300 | [diff] [blame] | 1373 | if (!e) |
| 1374 | return false; |
| 1375 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 1376 | if (hci_resolve_name(hdev, e) == 0) { |
| 1377 | e->name_state = NAME_PENDING; |
| 1378 | return true; |
| 1379 | } |
| 1380 | |
| 1381 | return false; |
| 1382 | } |
| 1383 | |
| 1384 | static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1385 | bdaddr_t *bdaddr, u8 *name, u8 name_len) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 1386 | { |
| 1387 | struct discovery_state *discov = &hdev->discovery; |
| 1388 | struct inquiry_entry *e; |
| 1389 | |
| 1390 | if (conn && !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1391 | mgmt_device_connected(hdev, bdaddr, ACL_LINK, 0x00, 0, name, |
| 1392 | name_len, conn->dev_class); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 1393 | |
| 1394 | if (discov->state == DISCOVERY_STOPPED) |
| 1395 | return; |
| 1396 | |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1397 | if (discov->state == DISCOVERY_STOPPING) |
| 1398 | goto discov_complete; |
| 1399 | |
| 1400 | if (discov->state != DISCOVERY_RESOLVING) |
| 1401 | return; |
| 1402 | |
| 1403 | e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING); |
Ram Malovany | 7cc8380 | 2012-07-19 10:26:10 +0300 | [diff] [blame] | 1404 | /* If the device was not found in a list of found devices names of which |
| 1405 | * are pending. there is no need to continue resolving a next name as it |
| 1406 | * will be done upon receiving another Remote Name Request Complete |
| 1407 | * Event */ |
| 1408 | if (!e) |
| 1409 | return; |
| 1410 | |
| 1411 | list_del(&e->list); |
| 1412 | if (name) { |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1413 | e->name_state = NAME_KNOWN; |
Ram Malovany | 7cc8380 | 2012-07-19 10:26:10 +0300 | [diff] [blame] | 1414 | mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, |
| 1415 | e->data.rssi, name, name_len); |
Ram Malovany | c3e7c0d | 2012-07-19 10:26:11 +0300 | [diff] [blame] | 1416 | } else { |
| 1417 | e->name_state = NAME_NOT_KNOWN; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1418 | } |
| 1419 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 1420 | if (hci_resolve_next_name(hdev)) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1421 | return; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1422 | |
| 1423 | discov_complete: |
| 1424 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 1425 | } |
| 1426 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1427 | static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) |
| 1428 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1429 | struct hci_cp_remote_name_req *cp; |
| 1430 | struct hci_conn *conn; |
| 1431 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1432 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1433 | |
| 1434 | /* If successful wait for the name req complete event before |
| 1435 | * checking for the need to do authentication */ |
| 1436 | if (!status) |
| 1437 | return; |
| 1438 | |
| 1439 | cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ); |
| 1440 | if (!cp) |
| 1441 | return; |
| 1442 | |
| 1443 | hci_dev_lock(hdev); |
| 1444 | |
| 1445 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 1446 | |
| 1447 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
| 1448 | hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0); |
| 1449 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 1450 | if (!conn) |
| 1451 | goto unlock; |
| 1452 | |
| 1453 | if (!hci_outgoing_auth_needed(hdev, conn)) |
| 1454 | goto unlock; |
| 1455 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1456 | if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1457 | struct hci_cp_auth_requested cp; |
| 1458 | cp.handle = __cpu_to_le16(conn->handle); |
| 1459 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); |
| 1460 | } |
| 1461 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 1462 | unlock: |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1463 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1464 | } |
| 1465 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1466 | static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) |
| 1467 | { |
| 1468 | struct hci_cp_read_remote_features *cp; |
| 1469 | struct hci_conn *conn; |
| 1470 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1471 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1472 | |
| 1473 | if (!status) |
| 1474 | return; |
| 1475 | |
| 1476 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES); |
| 1477 | if (!cp) |
| 1478 | return; |
| 1479 | |
| 1480 | hci_dev_lock(hdev); |
| 1481 | |
| 1482 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 1483 | if (conn) { |
| 1484 | if (conn->state == BT_CONFIG) { |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1485 | hci_proto_connect_cfm(conn, status); |
| 1486 | hci_conn_put(conn); |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | hci_dev_unlock(hdev); |
| 1491 | } |
| 1492 | |
| 1493 | static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status) |
| 1494 | { |
| 1495 | struct hci_cp_read_remote_ext_features *cp; |
| 1496 | struct hci_conn *conn; |
| 1497 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1498 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1499 | |
| 1500 | if (!status) |
| 1501 | return; |
| 1502 | |
| 1503 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES); |
| 1504 | if (!cp) |
| 1505 | return; |
| 1506 | |
| 1507 | hci_dev_lock(hdev); |
| 1508 | |
| 1509 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 1510 | if (conn) { |
| 1511 | if (conn->state == BT_CONFIG) { |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1512 | hci_proto_connect_cfm(conn, status); |
| 1513 | hci_conn_put(conn); |
| 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | hci_dev_unlock(hdev); |
| 1518 | } |
| 1519 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1520 | static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| 1521 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1522 | struct hci_cp_setup_sync_conn *cp; |
| 1523 | struct hci_conn *acl, *sco; |
| 1524 | __u16 handle; |
| 1525 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1526 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1527 | |
| 1528 | if (!status) |
| 1529 | return; |
| 1530 | |
| 1531 | cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN); |
| 1532 | if (!cp) |
| 1533 | return; |
| 1534 | |
| 1535 | handle = __le16_to_cpu(cp->handle); |
| 1536 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1537 | BT_DBG("%s handle 0x%4.4x", hdev->name, handle); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1538 | |
| 1539 | hci_dev_lock(hdev); |
| 1540 | |
| 1541 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1542 | if (acl) { |
| 1543 | sco = acl->link; |
| 1544 | if (sco) { |
| 1545 | sco->state = BT_CLOSED; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1546 | |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1547 | hci_proto_connect_cfm(sco, status); |
| 1548 | hci_conn_del(sco); |
| 1549 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1553 | } |
| 1554 | |
| 1555 | static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 1556 | { |
| 1557 | struct hci_cp_sniff_mode *cp; |
| 1558 | struct hci_conn *conn; |
| 1559 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1560 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1561 | |
| 1562 | if (!status) |
| 1563 | return; |
| 1564 | |
| 1565 | cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE); |
| 1566 | if (!cp) |
| 1567 | return; |
| 1568 | |
| 1569 | hci_dev_lock(hdev); |
| 1570 | |
| 1571 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1572 | if (conn) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1573 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1574 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1575 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1576 | hci_sco_setup(conn, status); |
| 1577 | } |
| 1578 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1579 | hci_dev_unlock(hdev); |
| 1580 | } |
| 1581 | |
| 1582 | static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 1583 | { |
| 1584 | struct hci_cp_exit_sniff_mode *cp; |
| 1585 | struct hci_conn *conn; |
| 1586 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1587 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1588 | |
| 1589 | if (!status) |
| 1590 | return; |
| 1591 | |
| 1592 | cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE); |
| 1593 | if (!cp) |
| 1594 | return; |
| 1595 | |
| 1596 | hci_dev_lock(hdev); |
| 1597 | |
| 1598 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1599 | if (conn) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1600 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1601 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1602 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1603 | hci_sco_setup(conn, status); |
| 1604 | } |
| 1605 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1606 | hci_dev_unlock(hdev); |
| 1607 | } |
| 1608 | |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 1609 | static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) |
| 1610 | { |
| 1611 | struct hci_cp_disconnect *cp; |
| 1612 | struct hci_conn *conn; |
| 1613 | |
| 1614 | if (!status) |
| 1615 | return; |
| 1616 | |
| 1617 | cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT); |
| 1618 | if (!cp) |
| 1619 | return; |
| 1620 | |
| 1621 | hci_dev_lock(hdev); |
| 1622 | |
| 1623 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 1624 | if (conn) |
| 1625 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1626 | conn->dst_type, status); |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 1627 | |
| 1628 | hci_dev_unlock(hdev); |
| 1629 | } |
| 1630 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 1631 | static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status) |
| 1632 | { |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 1633 | struct hci_conn *conn; |
| 1634 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1635 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 1636 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 1637 | if (status) { |
Andre Guedes | f00a06a | 2012-07-27 15:10:13 -0300 | [diff] [blame] | 1638 | hci_dev_lock(hdev); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 1639 | |
Andre Guedes | 0c95ab7 | 2012-07-27 15:10:14 -0300 | [diff] [blame] | 1640 | conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT); |
Andre Guedes | f00a06a | 2012-07-27 15:10:13 -0300 | [diff] [blame] | 1641 | if (!conn) { |
| 1642 | hci_dev_unlock(hdev); |
| 1643 | return; |
| 1644 | } |
| 1645 | |
Andre Guedes | 0c95ab7 | 2012-07-27 15:10:14 -0300 | [diff] [blame] | 1646 | BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&conn->dst), |
Andre Guedes | f00a06a | 2012-07-27 15:10:13 -0300 | [diff] [blame] | 1647 | conn); |
| 1648 | |
| 1649 | conn->state = BT_CLOSED; |
Andre Guedes | 0c95ab7 | 2012-07-27 15:10:14 -0300 | [diff] [blame] | 1650 | mgmt_connect_failed(hdev, &conn->dst, conn->type, |
Andre Guedes | f00a06a | 2012-07-27 15:10:13 -0300 | [diff] [blame] | 1651 | conn->dst_type, status); |
| 1652 | hci_proto_connect_cfm(conn, status); |
| 1653 | hci_conn_del(conn); |
| 1654 | |
| 1655 | hci_dev_unlock(hdev); |
| 1656 | } |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 1657 | } |
| 1658 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 1659 | static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status) |
| 1660 | { |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1661 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 1662 | } |
| 1663 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1664 | static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1665 | { |
| 1666 | __u8 status = *((__u8 *) skb->data); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1667 | struct discovery_state *discov = &hdev->discovery; |
| 1668 | struct inquiry_entry *e; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1669 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1670 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1671 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 1672 | hci_req_complete(hdev, HCI_OP_INQUIRY, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1673 | |
| 1674 | hci_conn_check_pending(hdev); |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 1675 | |
| 1676 | if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) |
| 1677 | return; |
| 1678 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 1679 | if (!test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1680 | return; |
| 1681 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1682 | hci_dev_lock(hdev); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1683 | |
Andre Guedes | 343f935 | 2012-02-17 20:39:37 -0300 | [diff] [blame] | 1684 | if (discov->state != DISCOVERY_FINDING) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 1685 | goto unlock; |
| 1686 | |
| 1687 | if (list_empty(&discov->resolve)) { |
| 1688 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 1689 | goto unlock; |
| 1690 | } |
| 1691 | |
| 1692 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
| 1693 | if (e && hci_resolve_name(hdev, e) == 0) { |
| 1694 | e->name_state = NAME_PENDING; |
| 1695 | hci_discovery_set_state(hdev, DISCOVERY_RESOLVING); |
| 1696 | } else { |
| 1697 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 1698 | } |
| 1699 | |
| 1700 | unlock: |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1701 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1702 | } |
| 1703 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1704 | static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | { |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1706 | struct inquiry_data data; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1707 | struct inquiry_info *info = (void *) (skb->data + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | int num_rsp = *((__u8 *) skb->data); |
| 1709 | |
| 1710 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 1711 | |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1712 | if (!num_rsp) |
| 1713 | return; |
| 1714 | |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 1715 | if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags)) |
| 1716 | return; |
| 1717 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1718 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1719 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 1720 | for (; num_rsp; num_rsp--, info++) { |
Johan Hedberg | 388fc8f | 2012-02-23 00:38:59 +0200 | [diff] [blame] | 1721 | bool name_known, ssp; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 1722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | bacpy(&data.bdaddr, &info->bdaddr); |
| 1724 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 1725 | data.pscan_period_mode = info->pscan_period_mode; |
| 1726 | data.pscan_mode = info->pscan_mode; |
| 1727 | memcpy(data.dev_class, info->dev_class, 3); |
| 1728 | data.clock_offset = info->clock_offset; |
| 1729 | data.rssi = 0x00; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 1730 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 1731 | |
Johan Hedberg | 388fc8f | 2012-02-23 00:38:59 +0200 | [diff] [blame] | 1732 | name_known = hci_inquiry_cache_update(hdev, &data, false, &ssp); |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 1733 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1734 | info->dev_class, 0, !name_known, ssp, NULL, |
| 1735 | 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | hci_dev_unlock(hdev); |
| 1739 | } |
| 1740 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1741 | static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1743 | struct hci_ev_conn_complete *ev = (void *) skb->data; |
| 1744 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1746 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1747 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1749 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1750 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9499237 | 2009-04-19 19:30:03 +0200 | [diff] [blame] | 1751 | if (!conn) { |
| 1752 | if (ev->link_type != SCO_LINK) |
| 1753 | goto unlock; |
| 1754 | |
| 1755 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); |
| 1756 | if (!conn) |
| 1757 | goto unlock; |
| 1758 | |
| 1759 | conn->type = SCO_LINK; |
| 1760 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1761 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1762 | if (!ev->status) { |
| 1763 | conn->handle = __le16_to_cpu(ev->handle); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1764 | |
| 1765 | if (conn->type == ACL_LINK) { |
| 1766 | conn->state = BT_CONFIG; |
| 1767 | hci_conn_hold(conn); |
Szymon Janc | a9ea3ed | 2012-07-19 14:46:08 +0200 | [diff] [blame] | 1768 | |
| 1769 | if (!conn->out && !hci_conn_ssp_enabled(conn) && |
| 1770 | !hci_find_link_key(hdev, &ev->bdaddr)) |
| 1771 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
| 1772 | else |
| 1773 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1774 | } else |
| 1775 | conn->state = BT_CONNECTED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1776 | |
Marcel Holtmann | 9eba32b | 2009-08-22 14:19:26 -0700 | [diff] [blame] | 1777 | hci_conn_hold_device(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 1778 | hci_conn_add_sysfs(conn); |
| 1779 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1780 | if (test_bit(HCI_AUTH, &hdev->flags)) |
| 1781 | conn->link_mode |= HCI_LM_AUTH; |
| 1782 | |
| 1783 | if (test_bit(HCI_ENCRYPT, &hdev->flags)) |
| 1784 | conn->link_mode |= HCI_LM_ENCRYPT; |
| 1785 | |
| 1786 | /* Get remote features */ |
| 1787 | if (conn->type == ACL_LINK) { |
| 1788 | struct hci_cp_read_remote_features cp; |
| 1789 | cp.handle = ev->handle; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1790 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1791 | sizeof(cp), &cp); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1792 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1793 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1794 | /* Set packet type for incoming connection */ |
Andrei Emeltchenko | d095c1e | 2011-12-01 14:33:27 +0200 | [diff] [blame] | 1795 | if (!conn->out && hdev->hci_ver < BLUETOOTH_VER_2_0) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1796 | struct hci_cp_change_conn_ptype cp; |
| 1797 | cp.handle = ev->handle; |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 1798 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1799 | hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp), |
| 1800 | &cp); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1801 | } |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 1802 | } else { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1803 | conn->state = BT_CLOSED; |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 1804 | if (conn->type == ACL_LINK) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1805 | mgmt_connect_failed(hdev, &ev->bdaddr, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1806 | conn->dst_type, ev->status); |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 1807 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1808 | |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1809 | if (conn->type == ACL_LINK) |
| 1810 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1811 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1812 | if (ev->status) { |
| 1813 | hci_proto_connect_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1814 | hci_conn_del(conn); |
Marcel Holtmann | c89b6e6 | 2009-01-15 21:57:03 +0100 | [diff] [blame] | 1815 | } else if (ev->link_type != ACL_LINK) |
| 1816 | hci_proto_connect_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1817 | |
| 1818 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1820 | |
| 1821 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1824 | static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1826 | struct hci_ev_conn_request *ev = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | int mask = hdev->link_mode; |
| 1828 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1829 | BT_DBG("%s bdaddr %s type 0x%x", hdev->name, batostr(&ev->bdaddr), |
| 1830 | ev->link_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | |
| 1832 | mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type); |
| 1833 | |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 1834 | if ((mask & HCI_LM_ACCEPT) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1835 | !hci_blacklist_lookup(hdev, &ev->bdaddr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | /* Connection accepted */ |
Marcel Holtmann | c7bdd50 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 1837 | struct inquiry_entry *ie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | |
| 1840 | hci_dev_lock(hdev); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1841 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 1842 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 1843 | if (ie) |
Marcel Holtmann | c7bdd50 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 1844 | memcpy(ie->data.dev_class, ev->dev_class, 3); |
| 1845 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 1846 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, |
| 1847 | &ev->bdaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | if (!conn) { |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 1849 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr); |
| 1850 | if (!conn) { |
Gustavo F. Padovan | 893ef97 | 2010-07-18 15:13:37 -0300 | [diff] [blame] | 1851 | BT_ERR("No memory for new connection"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | hci_dev_unlock(hdev); |
| 1853 | return; |
| 1854 | } |
| 1855 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1856 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | memcpy(conn->dev_class, ev->dev_class, 3); |
| 1858 | conn->state = BT_CONNECT; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1859 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | hci_dev_unlock(hdev); |
| 1861 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1862 | if (ev->link_type == ACL_LINK || !lmp_esco_capable(hdev)) { |
| 1863 | struct hci_cp_accept_conn_req cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1865 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1867 | if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) |
| 1868 | cp.role = 0x00; /* Become master */ |
| 1869 | else |
| 1870 | cp.role = 0x01; /* Remain slave */ |
| 1871 | |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1872 | hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), |
| 1873 | &cp); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1874 | } else { |
| 1875 | struct hci_cp_accept_sync_conn_req cp; |
| 1876 | |
| 1877 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 1878 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1879 | |
Andrei Emeltchenko | 82781e6 | 2012-05-25 11:38:27 +0300 | [diff] [blame] | 1880 | cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40); |
| 1881 | cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40); |
| 1882 | cp.max_latency = __constant_cpu_to_le16(0xffff); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1883 | cp.content_format = cpu_to_le16(hdev->voice_setting); |
| 1884 | cp.retrans_effort = 0xff; |
| 1885 | |
| 1886 | hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1887 | sizeof(cp), &cp); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1888 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1889 | } else { |
| 1890 | /* Connection rejected */ |
| 1891 | struct hci_cp_reject_conn_req cp; |
| 1892 | |
| 1893 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9f5a0d7 | 2011-11-07 14:20:25 +0200 | [diff] [blame] | 1894 | cp.reason = HCI_ERROR_REJ_BAD_ADDR; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1895 | hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 | } |
| 1897 | } |
| 1898 | |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 1899 | static u8 hci_to_mgmt_reason(u8 err) |
| 1900 | { |
| 1901 | switch (err) { |
| 1902 | case HCI_ERROR_CONNECTION_TIMEOUT: |
| 1903 | return MGMT_DEV_DISCONN_TIMEOUT; |
| 1904 | case HCI_ERROR_REMOTE_USER_TERM: |
| 1905 | case HCI_ERROR_REMOTE_LOW_RESOURCES: |
| 1906 | case HCI_ERROR_REMOTE_POWER_OFF: |
| 1907 | return MGMT_DEV_DISCONN_REMOTE; |
| 1908 | case HCI_ERROR_LOCAL_HOST_TERM: |
| 1909 | return MGMT_DEV_DISCONN_LOCAL_HOST; |
| 1910 | default: |
| 1911 | return MGMT_DEV_DISCONN_UNKNOWN; |
| 1912 | } |
| 1913 | } |
| 1914 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1915 | static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1917 | struct hci_ev_disconn_complete *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1918 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1920 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | hci_dev_lock(hdev); |
| 1923 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1924 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 1925 | if (!conn) |
| 1926 | goto unlock; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 1927 | |
Johan Hedberg | 37d9ef7 | 2011-11-10 15:54:39 +0200 | [diff] [blame] | 1928 | if (ev->status == 0) |
| 1929 | conn->state = BT_CLOSED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 1931 | if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1932 | (conn->type == ACL_LINK || conn->type == LE_LINK)) { |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 1933 | if (ev->status) { |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 1934 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1935 | conn->dst_type, ev->status); |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 1936 | } else { |
| 1937 | u8 reason = hci_to_mgmt_reason(ev->reason); |
| 1938 | |
Johan Hedberg | afc747a | 2012-01-15 18:11:07 +0200 | [diff] [blame] | 1939 | mgmt_device_disconnected(hdev, &conn->dst, conn->type, |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 1940 | conn->dst_type, reason); |
| 1941 | } |
Johan Hedberg | 37d9ef7 | 2011-11-10 15:54:39 +0200 | [diff] [blame] | 1942 | } |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 1943 | |
Johan Hedberg | 37d9ef7 | 2011-11-10 15:54:39 +0200 | [diff] [blame] | 1944 | if (ev->status == 0) { |
Vishal Agarwal | 6ec5bca | 2012-04-16 14:44:44 +0530 | [diff] [blame] | 1945 | if (conn->type == ACL_LINK && conn->flush_key) |
| 1946 | hci_remove_link_key(hdev, &conn->dst); |
Johan Hedberg | 37d9ef7 | 2011-11-10 15:54:39 +0200 | [diff] [blame] | 1947 | hci_proto_disconn_cfm(conn, ev->reason); |
| 1948 | hci_conn_del(conn); |
| 1949 | } |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 1950 | |
| 1951 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | hci_dev_unlock(hdev); |
| 1953 | } |
| 1954 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1955 | static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1956 | { |
| 1957 | struct hci_ev_auth_complete *ev = (void *) skb->data; |
| 1958 | struct hci_conn *conn; |
| 1959 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1960 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1961 | |
| 1962 | hci_dev_lock(hdev); |
| 1963 | |
| 1964 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1965 | if (!conn) |
| 1966 | goto unlock; |
| 1967 | |
| 1968 | if (!ev->status) { |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 1969 | if (!hci_conn_ssp_enabled(conn) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1970 | test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1971 | BT_INFO("re-auth of legacy device is not possible."); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 1972 | } else { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1973 | conn->link_mode |= HCI_LM_AUTH; |
| 1974 | conn->sec_level = conn->pending_sec_level; |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 1975 | } |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1976 | } else { |
Johan Hedberg | bab73cb | 2012-02-09 16:07:29 +0200 | [diff] [blame] | 1977 | mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1978 | ev->status); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1979 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1980 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1981 | clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); |
| 1982 | clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1983 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1984 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 1985 | if (!ev->status && hci_conn_ssp_enabled(conn)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1986 | struct hci_cp_set_conn_encrypt cp; |
| 1987 | cp.handle = ev->handle; |
| 1988 | cp.encrypt = 0x01; |
| 1989 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1990 | &cp); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1991 | } else { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1992 | conn->state = BT_CONNECTED; |
| 1993 | hci_proto_connect_cfm(conn, ev->status); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1994 | hci_conn_put(conn); |
| 1995 | } |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1996 | } else { |
| 1997 | hci_auth_cfm(conn, ev->status); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1998 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 1999 | hci_conn_hold(conn); |
| 2000 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
| 2001 | hci_conn_put(conn); |
| 2002 | } |
| 2003 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2004 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2005 | if (!ev->status) { |
| 2006 | struct hci_cp_set_conn_encrypt cp; |
| 2007 | cp.handle = ev->handle; |
| 2008 | cp.encrypt = 0x01; |
| 2009 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2010 | &cp); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2011 | } else { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2012 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2013 | hci_encrypt_cfm(conn, ev->status, 0x00); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2014 | } |
| 2015 | } |
| 2016 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2017 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2018 | hci_dev_unlock(hdev); |
| 2019 | } |
| 2020 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2021 | static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2022 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2023 | struct hci_ev_remote_name *ev = (void *) skb->data; |
| 2024 | struct hci_conn *conn; |
| 2025 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2026 | BT_DBG("%s", hdev->name); |
| 2027 | |
| 2028 | hci_conn_check_pending(hdev); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2029 | |
| 2030 | hci_dev_lock(hdev); |
| 2031 | |
| 2032 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2033 | |
| 2034 | if (!test_bit(HCI_MGMT, &hdev->dev_flags)) |
| 2035 | goto check_auth; |
| 2036 | |
| 2037 | if (ev->status == 0) |
| 2038 | hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2039 | strnlen(ev->name, HCI_MAX_NAME_LENGTH)); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2040 | else |
| 2041 | hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0); |
| 2042 | |
| 2043 | check_auth: |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 2044 | if (!conn) |
| 2045 | goto unlock; |
| 2046 | |
| 2047 | if (!hci_outgoing_auth_needed(hdev, conn)) |
| 2048 | goto unlock; |
| 2049 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2050 | if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2051 | struct hci_cp_auth_requested cp; |
| 2052 | cp.handle = __cpu_to_le16(conn->handle); |
| 2053 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); |
| 2054 | } |
| 2055 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 2056 | unlock: |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2057 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2058 | } |
| 2059 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2060 | static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2061 | { |
| 2062 | struct hci_ev_encrypt_change *ev = (void *) skb->data; |
| 2063 | struct hci_conn *conn; |
| 2064 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2065 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2066 | |
| 2067 | hci_dev_lock(hdev); |
| 2068 | |
| 2069 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 2070 | if (conn) { |
| 2071 | if (!ev->status) { |
Marcel Holtmann | ae29319 | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 2072 | if (ev->encrypt) { |
| 2073 | /* Encryption implies authentication */ |
| 2074 | conn->link_mode |= HCI_LM_AUTH; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2075 | conn->link_mode |= HCI_LM_ENCRYPT; |
Vinicius Costa Gomes | da85e5e | 2011-06-09 18:50:53 -0300 | [diff] [blame] | 2076 | conn->sec_level = conn->pending_sec_level; |
Marcel Holtmann | ae29319 | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 2077 | } else |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2078 | conn->link_mode &= ~HCI_LM_ENCRYPT; |
| 2079 | } |
| 2080 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2081 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2082 | |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 2083 | if (ev->status && conn->state == BT_CONNECTED) { |
Gustavo Padovan | d839c81 | 2012-05-16 12:17:12 -0300 | [diff] [blame] | 2084 | hci_acl_disconn(conn, HCI_ERROR_AUTH_FAILURE); |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 2085 | hci_conn_put(conn); |
| 2086 | goto unlock; |
| 2087 | } |
| 2088 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2089 | if (conn->state == BT_CONFIG) { |
| 2090 | if (!ev->status) |
| 2091 | conn->state = BT_CONNECTED; |
| 2092 | |
| 2093 | hci_proto_connect_cfm(conn, ev->status); |
| 2094 | hci_conn_put(conn); |
| 2095 | } else |
| 2096 | hci_encrypt_cfm(conn, ev->status, ev->encrypt); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2097 | } |
| 2098 | |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 2099 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2100 | hci_dev_unlock(hdev); |
| 2101 | } |
| 2102 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2103 | static void hci_change_link_key_complete_evt(struct hci_dev *hdev, |
| 2104 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2105 | { |
| 2106 | struct hci_ev_change_link_key_complete *ev = (void *) skb->data; |
| 2107 | struct hci_conn *conn; |
| 2108 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2109 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2110 | |
| 2111 | hci_dev_lock(hdev); |
| 2112 | |
| 2113 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 2114 | if (conn) { |
| 2115 | if (!ev->status) |
| 2116 | conn->link_mode |= HCI_LM_SECURE; |
| 2117 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2118 | clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2119 | |
| 2120 | hci_key_change_cfm(conn, ev->status); |
| 2121 | } |
| 2122 | |
| 2123 | hci_dev_unlock(hdev); |
| 2124 | } |
| 2125 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2126 | static void hci_remote_features_evt(struct hci_dev *hdev, |
| 2127 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2128 | { |
| 2129 | struct hci_ev_remote_features *ev = (void *) skb->data; |
| 2130 | struct hci_conn *conn; |
| 2131 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2132 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2133 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2134 | hci_dev_lock(hdev); |
| 2135 | |
| 2136 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2137 | if (!conn) |
| 2138 | goto unlock; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2139 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2140 | if (!ev->status) |
| 2141 | memcpy(conn->features, ev->features, 8); |
| 2142 | |
| 2143 | if (conn->state != BT_CONFIG) |
| 2144 | goto unlock; |
| 2145 | |
| 2146 | if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) { |
| 2147 | struct hci_cp_read_remote_ext_features cp; |
| 2148 | cp.handle = ev->handle; |
| 2149 | cp.page = 0x01; |
| 2150 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2151 | sizeof(cp), &cp); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2152 | goto unlock; |
| 2153 | } |
| 2154 | |
Johan Hedberg | 671267b | 2012-05-12 16:11:50 -0300 | [diff] [blame] | 2155 | if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2156 | struct hci_cp_remote_name_req cp; |
| 2157 | memset(&cp, 0, sizeof(cp)); |
| 2158 | bacpy(&cp.bdaddr, &conn->dst); |
| 2159 | cp.pscan_rep_mode = 0x02; |
| 2160 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2161 | } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
| 2162 | mgmt_device_connected(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2163 | conn->dst_type, 0, NULL, 0, |
| 2164 | conn->dev_class); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2165 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2166 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2167 | conn->state = BT_CONNECTED; |
| 2168 | hci_proto_connect_cfm(conn, ev->status); |
| 2169 | hci_conn_put(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2170 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2171 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2172 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2173 | hci_dev_unlock(hdev); |
| 2174 | } |
| 2175 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2176 | static void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2177 | { |
| 2178 | BT_DBG("%s", hdev->name); |
| 2179 | } |
| 2180 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2181 | static void hci_qos_setup_complete_evt(struct hci_dev *hdev, |
| 2182 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2183 | { |
| 2184 | BT_DBG("%s", hdev->name); |
| 2185 | } |
| 2186 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2187 | static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2188 | { |
| 2189 | struct hci_ev_cmd_complete *ev = (void *) skb->data; |
| 2190 | __u16 opcode; |
| 2191 | |
| 2192 | skb_pull(skb, sizeof(*ev)); |
| 2193 | |
| 2194 | opcode = __le16_to_cpu(ev->opcode); |
| 2195 | |
| 2196 | switch (opcode) { |
| 2197 | case HCI_OP_INQUIRY_CANCEL: |
| 2198 | hci_cc_inquiry_cancel(hdev, skb); |
| 2199 | break; |
| 2200 | |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 2201 | case HCI_OP_PERIODIC_INQ: |
| 2202 | hci_cc_periodic_inq(hdev, skb); |
| 2203 | break; |
| 2204 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2205 | case HCI_OP_EXIT_PERIODIC_INQ: |
| 2206 | hci_cc_exit_periodic_inq(hdev, skb); |
| 2207 | break; |
| 2208 | |
| 2209 | case HCI_OP_REMOTE_NAME_REQ_CANCEL: |
| 2210 | hci_cc_remote_name_req_cancel(hdev, skb); |
| 2211 | break; |
| 2212 | |
| 2213 | case HCI_OP_ROLE_DISCOVERY: |
| 2214 | hci_cc_role_discovery(hdev, skb); |
| 2215 | break; |
| 2216 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 2217 | case HCI_OP_READ_LINK_POLICY: |
| 2218 | hci_cc_read_link_policy(hdev, skb); |
| 2219 | break; |
| 2220 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2221 | case HCI_OP_WRITE_LINK_POLICY: |
| 2222 | hci_cc_write_link_policy(hdev, skb); |
| 2223 | break; |
| 2224 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 2225 | case HCI_OP_READ_DEF_LINK_POLICY: |
| 2226 | hci_cc_read_def_link_policy(hdev, skb); |
| 2227 | break; |
| 2228 | |
| 2229 | case HCI_OP_WRITE_DEF_LINK_POLICY: |
| 2230 | hci_cc_write_def_link_policy(hdev, skb); |
| 2231 | break; |
| 2232 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2233 | case HCI_OP_RESET: |
| 2234 | hci_cc_reset(hdev, skb); |
| 2235 | break; |
| 2236 | |
| 2237 | case HCI_OP_WRITE_LOCAL_NAME: |
| 2238 | hci_cc_write_local_name(hdev, skb); |
| 2239 | break; |
| 2240 | |
| 2241 | case HCI_OP_READ_LOCAL_NAME: |
| 2242 | hci_cc_read_local_name(hdev, skb); |
| 2243 | break; |
| 2244 | |
| 2245 | case HCI_OP_WRITE_AUTH_ENABLE: |
| 2246 | hci_cc_write_auth_enable(hdev, skb); |
| 2247 | break; |
| 2248 | |
| 2249 | case HCI_OP_WRITE_ENCRYPT_MODE: |
| 2250 | hci_cc_write_encrypt_mode(hdev, skb); |
| 2251 | break; |
| 2252 | |
| 2253 | case HCI_OP_WRITE_SCAN_ENABLE: |
| 2254 | hci_cc_write_scan_enable(hdev, skb); |
| 2255 | break; |
| 2256 | |
| 2257 | case HCI_OP_READ_CLASS_OF_DEV: |
| 2258 | hci_cc_read_class_of_dev(hdev, skb); |
| 2259 | break; |
| 2260 | |
| 2261 | case HCI_OP_WRITE_CLASS_OF_DEV: |
| 2262 | hci_cc_write_class_of_dev(hdev, skb); |
| 2263 | break; |
| 2264 | |
| 2265 | case HCI_OP_READ_VOICE_SETTING: |
| 2266 | hci_cc_read_voice_setting(hdev, skb); |
| 2267 | break; |
| 2268 | |
| 2269 | case HCI_OP_WRITE_VOICE_SETTING: |
| 2270 | hci_cc_write_voice_setting(hdev, skb); |
| 2271 | break; |
| 2272 | |
| 2273 | case HCI_OP_HOST_BUFFER_SIZE: |
| 2274 | hci_cc_host_buffer_size(hdev, skb); |
| 2275 | break; |
| 2276 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2277 | case HCI_OP_WRITE_SSP_MODE: |
| 2278 | hci_cc_write_ssp_mode(hdev, skb); |
| 2279 | break; |
| 2280 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2281 | case HCI_OP_READ_LOCAL_VERSION: |
| 2282 | hci_cc_read_local_version(hdev, skb); |
| 2283 | break; |
| 2284 | |
| 2285 | case HCI_OP_READ_LOCAL_COMMANDS: |
| 2286 | hci_cc_read_local_commands(hdev, skb); |
| 2287 | break; |
| 2288 | |
| 2289 | case HCI_OP_READ_LOCAL_FEATURES: |
| 2290 | hci_cc_read_local_features(hdev, skb); |
| 2291 | break; |
| 2292 | |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 2293 | case HCI_OP_READ_LOCAL_EXT_FEATURES: |
| 2294 | hci_cc_read_local_ext_features(hdev, skb); |
| 2295 | break; |
| 2296 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2297 | case HCI_OP_READ_BUFFER_SIZE: |
| 2298 | hci_cc_read_buffer_size(hdev, skb); |
| 2299 | break; |
| 2300 | |
| 2301 | case HCI_OP_READ_BD_ADDR: |
| 2302 | hci_cc_read_bd_addr(hdev, skb); |
| 2303 | break; |
| 2304 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 2305 | case HCI_OP_READ_DATA_BLOCK_SIZE: |
| 2306 | hci_cc_read_data_block_size(hdev, skb); |
| 2307 | break; |
| 2308 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 2309 | case HCI_OP_WRITE_CA_TIMEOUT: |
| 2310 | hci_cc_write_ca_timeout(hdev, skb); |
| 2311 | break; |
| 2312 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 2313 | case HCI_OP_READ_FLOW_CONTROL_MODE: |
| 2314 | hci_cc_read_flow_control_mode(hdev, skb); |
| 2315 | break; |
| 2316 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 2317 | case HCI_OP_READ_LOCAL_AMP_INFO: |
| 2318 | hci_cc_read_local_amp_info(hdev, skb); |
| 2319 | break; |
| 2320 | |
Johan Hedberg | b0916ea | 2011-01-10 13:44:55 +0200 | [diff] [blame] | 2321 | case HCI_OP_DELETE_STORED_LINK_KEY: |
| 2322 | hci_cc_delete_stored_link_key(hdev, skb); |
| 2323 | break; |
| 2324 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 2325 | case HCI_OP_SET_EVENT_MASK: |
| 2326 | hci_cc_set_event_mask(hdev, skb); |
| 2327 | break; |
| 2328 | |
| 2329 | case HCI_OP_WRITE_INQUIRY_MODE: |
| 2330 | hci_cc_write_inquiry_mode(hdev, skb); |
| 2331 | break; |
| 2332 | |
| 2333 | case HCI_OP_READ_INQ_RSP_TX_POWER: |
| 2334 | hci_cc_read_inq_rsp_tx_power(hdev, skb); |
| 2335 | break; |
| 2336 | |
| 2337 | case HCI_OP_SET_EVENT_FLT: |
| 2338 | hci_cc_set_event_flt(hdev, skb); |
| 2339 | break; |
| 2340 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 2341 | case HCI_OP_PIN_CODE_REPLY: |
| 2342 | hci_cc_pin_code_reply(hdev, skb); |
| 2343 | break; |
| 2344 | |
| 2345 | case HCI_OP_PIN_CODE_NEG_REPLY: |
| 2346 | hci_cc_pin_code_neg_reply(hdev, skb); |
| 2347 | break; |
| 2348 | |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 2349 | case HCI_OP_READ_LOCAL_OOB_DATA: |
| 2350 | hci_cc_read_local_oob_data_reply(hdev, skb); |
| 2351 | break; |
| 2352 | |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 2353 | case HCI_OP_LE_READ_BUFFER_SIZE: |
| 2354 | hci_cc_le_read_buffer_size(hdev, skb); |
| 2355 | break; |
| 2356 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 2357 | case HCI_OP_USER_CONFIRM_REPLY: |
| 2358 | hci_cc_user_confirm_reply(hdev, skb); |
| 2359 | break; |
| 2360 | |
| 2361 | case HCI_OP_USER_CONFIRM_NEG_REPLY: |
| 2362 | hci_cc_user_confirm_neg_reply(hdev, skb); |
| 2363 | break; |
| 2364 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 2365 | case HCI_OP_USER_PASSKEY_REPLY: |
| 2366 | hci_cc_user_passkey_reply(hdev, skb); |
| 2367 | break; |
| 2368 | |
| 2369 | case HCI_OP_USER_PASSKEY_NEG_REPLY: |
| 2370 | hci_cc_user_passkey_neg_reply(hdev, skb); |
Szymon Janc | 16cde99 | 2012-04-13 12:32:42 +0200 | [diff] [blame] | 2371 | break; |
Andre Guedes | 07f7fa5 | 2011-12-02 21:13:31 +0900 | [diff] [blame] | 2372 | |
| 2373 | case HCI_OP_LE_SET_SCAN_PARAM: |
| 2374 | hci_cc_le_set_scan_param(hdev, skb); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 2375 | break; |
| 2376 | |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 2377 | case HCI_OP_LE_SET_SCAN_ENABLE: |
| 2378 | hci_cc_le_set_scan_enable(hdev, skb); |
| 2379 | break; |
| 2380 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 2381 | case HCI_OP_LE_LTK_REPLY: |
| 2382 | hci_cc_le_ltk_reply(hdev, skb); |
| 2383 | break; |
| 2384 | |
| 2385 | case HCI_OP_LE_LTK_NEG_REPLY: |
| 2386 | hci_cc_le_ltk_neg_reply(hdev, skb); |
| 2387 | break; |
| 2388 | |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 2389 | case HCI_OP_WRITE_LE_HOST_SUPPORTED: |
| 2390 | hci_cc_write_le_host_supported(hdev, skb); |
| 2391 | break; |
| 2392 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2393 | default: |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2394 | BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2395 | break; |
| 2396 | } |
| 2397 | |
Ville Tervo | 6bd3232 | 2011-02-16 16:32:41 +0200 | [diff] [blame] | 2398 | if (ev->opcode != HCI_OP_NOP) |
| 2399 | del_timer(&hdev->cmd_timer); |
| 2400 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2401 | if (ev->ncmd) { |
| 2402 | atomic_set(&hdev->cmd_cnt, 1); |
| 2403 | if (!skb_queue_empty(&hdev->cmd_q)) |
Gustavo F. Padovan | c347b76 | 2011-12-14 23:53:47 -0200 | [diff] [blame] | 2404 | queue_work(hdev->workqueue, &hdev->cmd_work); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2405 | } |
| 2406 | } |
| 2407 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2408 | static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2409 | { |
| 2410 | struct hci_ev_cmd_status *ev = (void *) skb->data; |
| 2411 | __u16 opcode; |
| 2412 | |
| 2413 | skb_pull(skb, sizeof(*ev)); |
| 2414 | |
| 2415 | opcode = __le16_to_cpu(ev->opcode); |
| 2416 | |
| 2417 | switch (opcode) { |
| 2418 | case HCI_OP_INQUIRY: |
| 2419 | hci_cs_inquiry(hdev, ev->status); |
| 2420 | break; |
| 2421 | |
| 2422 | case HCI_OP_CREATE_CONN: |
| 2423 | hci_cs_create_conn(hdev, ev->status); |
| 2424 | break; |
| 2425 | |
| 2426 | case HCI_OP_ADD_SCO: |
| 2427 | hci_cs_add_sco(hdev, ev->status); |
| 2428 | break; |
| 2429 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2430 | case HCI_OP_AUTH_REQUESTED: |
| 2431 | hci_cs_auth_requested(hdev, ev->status); |
| 2432 | break; |
| 2433 | |
| 2434 | case HCI_OP_SET_CONN_ENCRYPT: |
| 2435 | hci_cs_set_conn_encrypt(hdev, ev->status); |
| 2436 | break; |
| 2437 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2438 | case HCI_OP_REMOTE_NAME_REQ: |
| 2439 | hci_cs_remote_name_req(hdev, ev->status); |
| 2440 | break; |
| 2441 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2442 | case HCI_OP_READ_REMOTE_FEATURES: |
| 2443 | hci_cs_read_remote_features(hdev, ev->status); |
| 2444 | break; |
| 2445 | |
| 2446 | case HCI_OP_READ_REMOTE_EXT_FEATURES: |
| 2447 | hci_cs_read_remote_ext_features(hdev, ev->status); |
| 2448 | break; |
| 2449 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2450 | case HCI_OP_SETUP_SYNC_CONN: |
| 2451 | hci_cs_setup_sync_conn(hdev, ev->status); |
| 2452 | break; |
| 2453 | |
| 2454 | case HCI_OP_SNIFF_MODE: |
| 2455 | hci_cs_sniff_mode(hdev, ev->status); |
| 2456 | break; |
| 2457 | |
| 2458 | case HCI_OP_EXIT_SNIFF_MODE: |
| 2459 | hci_cs_exit_sniff_mode(hdev, ev->status); |
| 2460 | break; |
| 2461 | |
Johan Hedberg | 8962ee7 | 2011-01-20 12:40:27 +0200 | [diff] [blame] | 2462 | case HCI_OP_DISCONNECT: |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2463 | hci_cs_disconnect(hdev, ev->status); |
Johan Hedberg | 8962ee7 | 2011-01-20 12:40:27 +0200 | [diff] [blame] | 2464 | break; |
| 2465 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 2466 | case HCI_OP_LE_CREATE_CONN: |
| 2467 | hci_cs_le_create_conn(hdev, ev->status); |
| 2468 | break; |
| 2469 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 2470 | case HCI_OP_LE_START_ENC: |
| 2471 | hci_cs_le_start_enc(hdev, ev->status); |
| 2472 | break; |
| 2473 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2474 | default: |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2475 | BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2476 | break; |
| 2477 | } |
| 2478 | |
Ville Tervo | 6bd3232 | 2011-02-16 16:32:41 +0200 | [diff] [blame] | 2479 | if (ev->opcode != HCI_OP_NOP) |
| 2480 | del_timer(&hdev->cmd_timer); |
| 2481 | |
Gustavo F. Padovan | 1057213 | 2011-03-16 15:36:29 -0300 | [diff] [blame] | 2482 | if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2483 | atomic_set(&hdev->cmd_cnt, 1); |
| 2484 | if (!skb_queue_empty(&hdev->cmd_q)) |
Gustavo F. Padovan | c347b76 | 2011-12-14 23:53:47 -0200 | [diff] [blame] | 2485 | queue_work(hdev->workqueue, &hdev->cmd_work); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2486 | } |
| 2487 | } |
| 2488 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2489 | static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2490 | { |
| 2491 | struct hci_ev_role_change *ev = (void *) skb->data; |
| 2492 | struct hci_conn *conn; |
| 2493 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2494 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2495 | |
| 2496 | hci_dev_lock(hdev); |
| 2497 | |
| 2498 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 2499 | if (conn) { |
| 2500 | if (!ev->status) { |
| 2501 | if (ev->role) |
| 2502 | conn->link_mode &= ~HCI_LM_MASTER; |
| 2503 | else |
| 2504 | conn->link_mode |= HCI_LM_MASTER; |
| 2505 | } |
| 2506 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2507 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2508 | |
| 2509 | hci_role_switch_cfm(conn, ev->status, ev->role); |
| 2510 | } |
| 2511 | |
| 2512 | hci_dev_unlock(hdev); |
| 2513 | } |
| 2514 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2515 | static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2517 | struct hci_ev_num_comp_pkts *ev = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | int i; |
| 2519 | |
Andrei Emeltchenko | 32ac5b9 | 2011-12-19 16:31:29 +0200 | [diff] [blame] | 2520 | if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) { |
| 2521 | BT_ERR("Wrong event for mode %d", hdev->flow_ctl_mode); |
| 2522 | return; |
| 2523 | } |
| 2524 | |
Andrei Emeltchenko | c5993de | 2011-12-30 12:07:47 +0200 | [diff] [blame] | 2525 | if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) + |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2526 | ev->num_hndl * sizeof(struct hci_comp_pkts_info)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | BT_DBG("%s bad parameters", hdev->name); |
| 2528 | return; |
| 2529 | } |
| 2530 | |
Andrei Emeltchenko | c5993de | 2011-12-30 12:07:47 +0200 | [diff] [blame] | 2531 | BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl); |
| 2532 | |
Andrei Emeltchenko | 613a1c0 | 2011-12-19 16:31:30 +0200 | [diff] [blame] | 2533 | for (i = 0; i < ev->num_hndl; i++) { |
| 2534 | struct hci_comp_pkts_info *info = &ev->handles[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | struct hci_conn *conn; |
| 2536 | __u16 handle, count; |
| 2537 | |
Andrei Emeltchenko | 613a1c0 | 2011-12-19 16:31:30 +0200 | [diff] [blame] | 2538 | handle = __le16_to_cpu(info->handle); |
| 2539 | count = __le16_to_cpu(info->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | |
| 2541 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 2542 | if (!conn) |
| 2543 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2544 | |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 2545 | conn->sent -= count; |
| 2546 | |
| 2547 | switch (conn->type) { |
| 2548 | case ACL_LINK: |
| 2549 | hdev->acl_cnt += count; |
| 2550 | if (hdev->acl_cnt > hdev->acl_pkts) |
| 2551 | hdev->acl_cnt = hdev->acl_pkts; |
| 2552 | break; |
| 2553 | |
| 2554 | case LE_LINK: |
| 2555 | if (hdev->le_pkts) { |
| 2556 | hdev->le_cnt += count; |
| 2557 | if (hdev->le_cnt > hdev->le_pkts) |
| 2558 | hdev->le_cnt = hdev->le_pkts; |
| 2559 | } else { |
Andrei Emeltchenko | 70f23020 | 2010-12-01 16:58:25 +0200 | [diff] [blame] | 2560 | hdev->acl_cnt += count; |
| 2561 | if (hdev->acl_cnt > hdev->acl_pkts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | hdev->acl_cnt = hdev->acl_pkts; |
| 2563 | } |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 2564 | break; |
| 2565 | |
| 2566 | case SCO_LINK: |
| 2567 | hdev->sco_cnt += count; |
| 2568 | if (hdev->sco_cnt > hdev->sco_pkts) |
| 2569 | hdev->sco_cnt = hdev->sco_pkts; |
| 2570 | break; |
| 2571 | |
| 2572 | default: |
| 2573 | BT_ERR("Unknown type %d conn %p", conn->type, conn); |
| 2574 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | } |
| 2576 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2577 | |
Gustavo F. Padovan | 3eff45e | 2011-12-15 00:50:02 -0200 | [diff] [blame] | 2578 | queue_work(hdev->workqueue, &hdev->tx_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | } |
| 2580 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2581 | static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 2582 | { |
| 2583 | struct hci_ev_num_comp_blocks *ev = (void *) skb->data; |
| 2584 | int i; |
| 2585 | |
| 2586 | if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) { |
| 2587 | BT_ERR("Wrong event for mode %d", hdev->flow_ctl_mode); |
| 2588 | return; |
| 2589 | } |
| 2590 | |
| 2591 | if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) + |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2592 | ev->num_hndl * sizeof(struct hci_comp_blocks_info)) { |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 2593 | BT_DBG("%s bad parameters", hdev->name); |
| 2594 | return; |
| 2595 | } |
| 2596 | |
| 2597 | BT_DBG("%s num_blocks %d num_hndl %d", hdev->name, ev->num_blocks, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2598 | ev->num_hndl); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 2599 | |
| 2600 | for (i = 0; i < ev->num_hndl; i++) { |
| 2601 | struct hci_comp_blocks_info *info = &ev->handles[i]; |
| 2602 | struct hci_conn *conn; |
| 2603 | __u16 handle, block_count; |
| 2604 | |
| 2605 | handle = __le16_to_cpu(info->handle); |
| 2606 | block_count = __le16_to_cpu(info->blocks); |
| 2607 | |
| 2608 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
| 2609 | if (!conn) |
| 2610 | continue; |
| 2611 | |
| 2612 | conn->sent -= block_count; |
| 2613 | |
| 2614 | switch (conn->type) { |
| 2615 | case ACL_LINK: |
| 2616 | hdev->block_cnt += block_count; |
| 2617 | if (hdev->block_cnt > hdev->num_blocks) |
| 2618 | hdev->block_cnt = hdev->num_blocks; |
| 2619 | break; |
| 2620 | |
| 2621 | default: |
| 2622 | BT_ERR("Unknown type %d conn %p", conn->type, conn); |
| 2623 | break; |
| 2624 | } |
| 2625 | } |
| 2626 | |
| 2627 | queue_work(hdev->workqueue, &hdev->tx_work); |
| 2628 | } |
| 2629 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2630 | static void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2632 | struct hci_ev_mode_change *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2633 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2635 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2636 | |
| 2637 | hci_dev_lock(hdev); |
| 2638 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2639 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 2640 | if (conn) { |
| 2641 | conn->mode = ev->mode; |
| 2642 | conn->interval = __le16_to_cpu(ev->interval); |
| 2643 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 2644 | if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, |
| 2645 | &conn->flags)) { |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2646 | if (conn->mode == HCI_CM_ACTIVE) |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 2647 | set_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2648 | else |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 2649 | clear_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2650 | } |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2651 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2652 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2653 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | hci_dev_unlock(hdev); |
| 2657 | } |
| 2658 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2659 | static void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2661 | struct hci_ev_pin_code_req *ev = (void *) skb->data; |
| 2662 | struct hci_conn *conn; |
| 2663 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2664 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2665 | |
| 2666 | hci_dev_lock(hdev); |
| 2667 | |
| 2668 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Waldemar Rymarkiewicz | b6f9804 | 2011-09-23 10:01:30 +0200 | [diff] [blame] | 2669 | if (!conn) |
| 2670 | goto unlock; |
| 2671 | |
| 2672 | if (conn->state == BT_CONNECTED) { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2673 | hci_conn_hold(conn); |
| 2674 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
| 2675 | hci_conn_put(conn); |
| 2676 | } |
| 2677 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 2678 | if (!test_bit(HCI_PAIRABLE, &hdev->dev_flags)) |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 2679 | hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2680 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 2681 | else if (test_bit(HCI_MGMT, &hdev->dev_flags)) { |
Waldemar Rymarkiewicz | a770bb5 | 2011-04-28 12:07:59 +0200 | [diff] [blame] | 2682 | u8 secure; |
| 2683 | |
| 2684 | if (conn->pending_sec_level == BT_SECURITY_HIGH) |
| 2685 | secure = 1; |
| 2686 | else |
| 2687 | secure = 0; |
| 2688 | |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 2689 | mgmt_pin_code_request(hdev, &ev->bdaddr, secure); |
Waldemar Rymarkiewicz | a770bb5 | 2011-04-28 12:07:59 +0200 | [diff] [blame] | 2690 | } |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 2691 | |
Waldemar Rymarkiewicz | b6f9804 | 2011-09-23 10:01:30 +0200 | [diff] [blame] | 2692 | unlock: |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2693 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2696 | static void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2697 | { |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2698 | struct hci_ev_link_key_req *ev = (void *) skb->data; |
| 2699 | struct hci_cp_link_key_reply cp; |
| 2700 | struct hci_conn *conn; |
| 2701 | struct link_key *key; |
| 2702 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2703 | BT_DBG("%s", hdev->name); |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2704 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 2705 | if (!test_bit(HCI_LINK_KEYS, &hdev->dev_flags)) |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2706 | return; |
| 2707 | |
| 2708 | hci_dev_lock(hdev); |
| 2709 | |
| 2710 | key = hci_find_link_key(hdev, &ev->bdaddr); |
| 2711 | if (!key) { |
| 2712 | BT_DBG("%s link key not found for %s", hdev->name, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2713 | batostr(&ev->bdaddr)); |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2714 | goto not_found; |
| 2715 | } |
| 2716 | |
| 2717 | BT_DBG("%s found key type %u for %s", hdev->name, key->type, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2718 | batostr(&ev->bdaddr)); |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2719 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 2720 | if (!test_bit(HCI_DEBUG_KEYS, &hdev->dev_flags) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2721 | key->type == HCI_LK_DEBUG_COMBINATION) { |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2722 | BT_DBG("%s ignoring debug key", hdev->name); |
| 2723 | goto not_found; |
| 2724 | } |
| 2725 | |
| 2726 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 2727 | if (conn) { |
| 2728 | if (key->type == HCI_LK_UNAUTH_COMBINATION && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2729 | conn->auth_type != 0xff && (conn->auth_type & 0x01)) { |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 2730 | BT_DBG("%s ignoring unauthenticated key", hdev->name); |
| 2731 | goto not_found; |
| 2732 | } |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2733 | |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 2734 | if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2735 | conn->pending_sec_level == BT_SECURITY_HIGH) { |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 2736 | BT_DBG("%s ignoring key unauthenticated for high security", |
| 2737 | hdev->name); |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 2738 | goto not_found; |
| 2739 | } |
| 2740 | |
| 2741 | conn->key_type = key->type; |
| 2742 | conn->pin_length = key->pin_len; |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9b3b446 | 2012-05-23 11:31:20 +0300 | [diff] [blame] | 2746 | memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE); |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2747 | |
| 2748 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp); |
| 2749 | |
| 2750 | hci_dev_unlock(hdev); |
| 2751 | |
| 2752 | return; |
| 2753 | |
| 2754 | not_found: |
| 2755 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr); |
| 2756 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2759 | static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2760 | { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2761 | struct hci_ev_link_key_notify *ev = (void *) skb->data; |
| 2762 | struct hci_conn *conn; |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2763 | u8 pin_len = 0; |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2764 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2765 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2766 | |
| 2767 | hci_dev_lock(hdev); |
| 2768 | |
| 2769 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 2770 | if (conn) { |
| 2771 | hci_conn_hold(conn); |
| 2772 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 2773 | pin_len = conn->pin_length; |
Waldemar Rymarkiewicz | 13d3931 | 2011-04-28 12:07:55 +0200 | [diff] [blame] | 2774 | |
| 2775 | if (ev->key_type != HCI_LK_CHANGED_COMBINATION) |
| 2776 | conn->key_type = ev->key_type; |
| 2777 | |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2778 | hci_conn_put(conn); |
| 2779 | } |
| 2780 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 2781 | if (test_bit(HCI_LINK_KEYS, &hdev->dev_flags)) |
Johan Hedberg | d25e28a | 2011-04-28 11:28:59 -0700 | [diff] [blame] | 2782 | hci_add_link_key(hdev, conn, 1, &ev->bdaddr, ev->link_key, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2783 | ev->key_type, pin_len); |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 2784 | |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2785 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2788 | static void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2789 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2790 | struct hci_ev_clock_offset *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2791 | struct hci_conn *conn; |
| 2792 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2793 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2794 | |
| 2795 | hci_dev_lock(hdev); |
| 2796 | |
| 2797 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | if (conn && !ev->status) { |
| 2799 | struct inquiry_entry *ie; |
| 2800 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 2801 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 2802 | if (ie) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | ie->data.clock_offset = ev->clock_offset; |
| 2804 | ie->timestamp = jiffies; |
| 2805 | } |
| 2806 | } |
| 2807 | |
| 2808 | hci_dev_unlock(hdev); |
| 2809 | } |
| 2810 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2811 | static void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 2812 | { |
| 2813 | struct hci_ev_pkt_type_change *ev = (void *) skb->data; |
| 2814 | struct hci_conn *conn; |
| 2815 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2816 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 2817 | |
| 2818 | hci_dev_lock(hdev); |
| 2819 | |
| 2820 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 2821 | if (conn && !ev->status) |
| 2822 | conn->pkt_type = __le16_to_cpu(ev->pkt_type); |
| 2823 | |
| 2824 | hci_dev_unlock(hdev); |
| 2825 | } |
| 2826 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2827 | static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 2828 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2829 | struct hci_ev_pscan_rep_mode *ev = (void *) skb->data; |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 2830 | struct inquiry_entry *ie; |
| 2831 | |
| 2832 | BT_DBG("%s", hdev->name); |
| 2833 | |
| 2834 | hci_dev_lock(hdev); |
| 2835 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 2836 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 2837 | if (ie) { |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 2838 | ie->data.pscan_rep_mode = ev->pscan_rep_mode; |
| 2839 | ie->timestamp = jiffies; |
| 2840 | } |
| 2841 | |
| 2842 | hci_dev_unlock(hdev); |
| 2843 | } |
| 2844 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2845 | static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, |
| 2846 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2847 | { |
| 2848 | struct inquiry_data data; |
| 2849 | int num_rsp = *((__u8 *) skb->data); |
Johan Hedberg | 388fc8f | 2012-02-23 00:38:59 +0200 | [diff] [blame] | 2850 | bool name_known, ssp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2851 | |
| 2852 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 2853 | |
| 2854 | if (!num_rsp) |
| 2855 | return; |
| 2856 | |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 2857 | if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags)) |
| 2858 | return; |
| 2859 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2860 | hci_dev_lock(hdev); |
| 2861 | |
| 2862 | if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 2863 | struct inquiry_info_with_rssi_and_pscan_mode *info; |
| 2864 | info = (void *) (skb->data + 1); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2865 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 2866 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2867 | bacpy(&data.bdaddr, &info->bdaddr); |
| 2868 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 2869 | data.pscan_period_mode = info->pscan_period_mode; |
| 2870 | data.pscan_mode = info->pscan_mode; |
| 2871 | memcpy(data.dev_class, info->dev_class, 3); |
| 2872 | data.clock_offset = info->clock_offset; |
| 2873 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2874 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 2875 | |
| 2876 | name_known = hci_inquiry_cache_update(hdev, &data, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2877 | false, &ssp); |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 2878 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2879 | info->dev_class, info->rssi, |
| 2880 | !name_known, ssp, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2881 | } |
| 2882 | } else { |
| 2883 | struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); |
| 2884 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 2885 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2886 | bacpy(&data.bdaddr, &info->bdaddr); |
| 2887 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 2888 | data.pscan_period_mode = info->pscan_period_mode; |
| 2889 | data.pscan_mode = 0x00; |
| 2890 | memcpy(data.dev_class, info->dev_class, 3); |
| 2891 | data.clock_offset = info->clock_offset; |
| 2892 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2893 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 2894 | name_known = hci_inquiry_cache_update(hdev, &data, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2895 | false, &ssp); |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 2896 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2897 | info->dev_class, info->rssi, |
| 2898 | !name_known, ssp, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2899 | } |
| 2900 | } |
| 2901 | |
| 2902 | hci_dev_unlock(hdev); |
| 2903 | } |
| 2904 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2905 | static void hci_remote_ext_features_evt(struct hci_dev *hdev, |
| 2906 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2907 | { |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2908 | struct hci_ev_remote_ext_features *ev = (void *) skb->data; |
| 2909 | struct hci_conn *conn; |
| 2910 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2911 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2912 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2913 | hci_dev_lock(hdev); |
| 2914 | |
| 2915 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2916 | if (!conn) |
| 2917 | goto unlock; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2918 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2919 | if (!ev->status && ev->page == 0x01) { |
| 2920 | struct inquiry_entry *ie; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2921 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 2922 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 2923 | if (ie) |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 2924 | ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2925 | |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 2926 | if (ev->features[0] & LMP_HOST_SSP) |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 2927 | set_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2928 | } |
| 2929 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2930 | if (conn->state != BT_CONFIG) |
| 2931 | goto unlock; |
| 2932 | |
Johan Hedberg | 671267b | 2012-05-12 16:11:50 -0300 | [diff] [blame] | 2933 | if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2934 | struct hci_cp_remote_name_req cp; |
| 2935 | memset(&cp, 0, sizeof(cp)); |
| 2936 | bacpy(&cp.bdaddr, &conn->dst); |
| 2937 | cp.pscan_rep_mode = 0x02; |
| 2938 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2939 | } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
| 2940 | mgmt_device_connected(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2941 | conn->dst_type, 0, NULL, 0, |
| 2942 | conn->dev_class); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2943 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2944 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2945 | conn->state = BT_CONNECTED; |
| 2946 | hci_proto_connect_cfm(conn, ev->status); |
| 2947 | hci_conn_put(conn); |
| 2948 | } |
| 2949 | |
| 2950 | unlock: |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2951 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2952 | } |
| 2953 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2954 | static void hci_sync_conn_complete_evt(struct hci_dev *hdev, |
| 2955 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2956 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2957 | struct hci_ev_sync_conn_complete *ev = (void *) skb->data; |
| 2958 | struct hci_conn *conn; |
| 2959 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2960 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2961 | |
| 2962 | hci_dev_lock(hdev); |
| 2963 | |
| 2964 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 2965 | if (!conn) { |
| 2966 | if (ev->link_type == ESCO_LINK) |
| 2967 | goto unlock; |
| 2968 | |
| 2969 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); |
| 2970 | if (!conn) |
| 2971 | goto unlock; |
| 2972 | |
| 2973 | conn->type = SCO_LINK; |
| 2974 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2975 | |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2976 | switch (ev->status) { |
| 2977 | case 0x00: |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2978 | conn->handle = __le16_to_cpu(ev->handle); |
| 2979 | conn->state = BT_CONNECTED; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 2980 | |
Marcel Holtmann | 9eba32b | 2009-08-22 14:19:26 -0700 | [diff] [blame] | 2981 | hci_conn_hold_device(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 2982 | hci_conn_add_sysfs(conn); |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2983 | break; |
| 2984 | |
Stephen Coe | 705e571 | 2010-02-16 11:29:44 -0500 | [diff] [blame] | 2985 | case 0x11: /* Unsupported Feature or Parameter Value */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2986 | case 0x1c: /* SCO interval rejected */ |
Nick Pelly | 1038a00 | 2010-02-03 11:42:26 -0800 | [diff] [blame] | 2987 | case 0x1a: /* Unsupported Remote Feature */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2988 | case 0x1f: /* Unspecified error */ |
| 2989 | if (conn->out && conn->attempt < 2) { |
| 2990 | conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | |
| 2991 | (hdev->esco_type & EDR_ESCO_MASK); |
| 2992 | hci_setup_sync(conn, conn->link->handle); |
| 2993 | goto unlock; |
| 2994 | } |
| 2995 | /* fall through */ |
| 2996 | |
| 2997 | default: |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2998 | conn->state = BT_CLOSED; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2999 | break; |
| 3000 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 3001 | |
| 3002 | hci_proto_connect_cfm(conn, ev->status); |
| 3003 | if (ev->status) |
| 3004 | hci_conn_del(conn); |
| 3005 | |
| 3006 | unlock: |
| 3007 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3008 | } |
| 3009 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3010 | static void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3011 | { |
| 3012 | BT_DBG("%s", hdev->name); |
| 3013 | } |
| 3014 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3015 | static void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3016 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3017 | struct hci_ev_sniff_subrate *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3018 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3019 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3020 | } |
| 3021 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3022 | static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, |
| 3023 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3024 | { |
| 3025 | struct inquiry_data data; |
| 3026 | struct extended_inquiry_info *info = (void *) (skb->data + 1); |
| 3027 | int num_rsp = *((__u8 *) skb->data); |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 3028 | size_t eir_len; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3029 | |
| 3030 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 3031 | |
| 3032 | if (!num_rsp) |
| 3033 | return; |
| 3034 | |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 3035 | if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags)) |
| 3036 | return; |
| 3037 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3038 | hci_dev_lock(hdev); |
| 3039 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 3040 | for (; num_rsp; num_rsp--, info++) { |
Johan Hedberg | 388fc8f | 2012-02-23 00:38:59 +0200 | [diff] [blame] | 3041 | bool name_known, ssp; |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 3042 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3043 | bacpy(&data.bdaddr, &info->bdaddr); |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 3044 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 3045 | data.pscan_period_mode = info->pscan_period_mode; |
| 3046 | data.pscan_mode = 0x00; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3047 | memcpy(data.dev_class, info->dev_class, 3); |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 3048 | data.clock_offset = info->clock_offset; |
| 3049 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3050 | data.ssp_mode = 0x01; |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 3051 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 3052 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 4ddb193 | 2012-01-15 20:04:43 +0200 | [diff] [blame] | 3053 | name_known = eir_has_data_type(info->data, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3054 | sizeof(info->data), |
| 3055 | EIR_NAME_COMPLETE); |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 3056 | else |
| 3057 | name_known = true; |
| 3058 | |
Johan Hedberg | 388fc8f | 2012-02-23 00:38:59 +0200 | [diff] [blame] | 3059 | name_known = hci_inquiry_cache_update(hdev, &data, name_known, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3060 | &ssp); |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 3061 | eir_len = eir_get_length(info->data, sizeof(info->data)); |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 3062 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3063 | info->dev_class, info->rssi, !name_known, |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 3064 | ssp, info->data, eir_len); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3065 | } |
| 3066 | |
| 3067 | hci_dev_unlock(hdev); |
| 3068 | } |
| 3069 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 3070 | static void hci_key_refresh_complete_evt(struct hci_dev *hdev, |
| 3071 | struct sk_buff *skb) |
| 3072 | { |
| 3073 | struct hci_ev_key_refresh_complete *ev = (void *) skb->data; |
| 3074 | struct hci_conn *conn; |
| 3075 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3076 | BT_DBG("%s status 0x%2.2x handle 0x%4.4x", hdev->name, ev->status, |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 3077 | __le16_to_cpu(ev->handle)); |
| 3078 | |
| 3079 | hci_dev_lock(hdev); |
| 3080 | |
| 3081 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 3082 | if (!conn) |
| 3083 | goto unlock; |
| 3084 | |
| 3085 | if (!ev->status) |
| 3086 | conn->sec_level = conn->pending_sec_level; |
| 3087 | |
| 3088 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
| 3089 | |
| 3090 | if (ev->status && conn->state == BT_CONNECTED) { |
| 3091 | hci_acl_disconn(conn, HCI_ERROR_AUTH_FAILURE); |
| 3092 | hci_conn_put(conn); |
| 3093 | goto unlock; |
| 3094 | } |
| 3095 | |
| 3096 | if (conn->state == BT_CONFIG) { |
| 3097 | if (!ev->status) |
| 3098 | conn->state = BT_CONNECTED; |
| 3099 | |
| 3100 | hci_proto_connect_cfm(conn, ev->status); |
| 3101 | hci_conn_put(conn); |
| 3102 | } else { |
| 3103 | hci_auth_cfm(conn, ev->status); |
| 3104 | |
| 3105 | hci_conn_hold(conn); |
| 3106 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
| 3107 | hci_conn_put(conn); |
| 3108 | } |
| 3109 | |
| 3110 | unlock: |
| 3111 | hci_dev_unlock(hdev); |
| 3112 | } |
| 3113 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3114 | static u8 hci_get_auth_req(struct hci_conn *conn) |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 3115 | { |
| 3116 | /* If remote requests dedicated bonding follow that lead */ |
| 3117 | if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) { |
| 3118 | /* If both remote and local IO capabilities allow MITM |
| 3119 | * protection then require it, otherwise don't */ |
| 3120 | if (conn->remote_cap == 0x03 || conn->io_capability == 0x03) |
| 3121 | return 0x02; |
| 3122 | else |
| 3123 | return 0x03; |
| 3124 | } |
| 3125 | |
| 3126 | /* If remote requests no-bonding follow that lead */ |
| 3127 | if (conn->remote_auth == 0x00 || conn->remote_auth == 0x01) |
Waldemar Rymarkiewicz | 58797bf | 2011-04-28 12:07:58 +0200 | [diff] [blame] | 3128 | return conn->remote_auth | (conn->auth_type & 0x01); |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 3129 | |
| 3130 | return conn->auth_type; |
| 3131 | } |
| 3132 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3133 | static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3134 | { |
| 3135 | struct hci_ev_io_capa_request *ev = (void *) skb->data; |
| 3136 | struct hci_conn *conn; |
| 3137 | |
| 3138 | BT_DBG("%s", hdev->name); |
| 3139 | |
| 3140 | hci_dev_lock(hdev); |
| 3141 | |
| 3142 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3143 | if (!conn) |
| 3144 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3145 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3146 | hci_conn_hold(conn); |
| 3147 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 3148 | if (!test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3149 | goto unlock; |
| 3150 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 3151 | if (test_bit(HCI_PAIRABLE, &hdev->dev_flags) || |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3152 | (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 3153 | struct hci_cp_io_capability_reply cp; |
| 3154 | |
| 3155 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Hemant Gupta | 7a7f1e7 | 2012-01-16 13:34:29 +0530 | [diff] [blame] | 3156 | /* Change the IO capability from KeyboardDisplay |
| 3157 | * to DisplayYesNo as it is not supported by BT spec. */ |
| 3158 | cp.capability = (conn->io_capability == 0x04) ? |
| 3159 | 0x01 : conn->io_capability; |
Johan Hedberg | 7cbc9bd | 2011-04-28 11:29:04 -0700 | [diff] [blame] | 3160 | conn->auth_type = hci_get_auth_req(conn); |
| 3161 | cp.authentication = conn->auth_type; |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 3162 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 3163 | if (hci_find_remote_oob_data(hdev, &conn->dst) && |
| 3164 | (conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags))) |
Szymon Janc | ce85ee1 | 2011-03-22 13:12:23 +0100 | [diff] [blame] | 3165 | cp.oob_data = 0x01; |
| 3166 | else |
| 3167 | cp.oob_data = 0x00; |
| 3168 | |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 3169 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3170 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3171 | } else { |
| 3172 | struct hci_cp_io_capability_neg_reply cp; |
| 3173 | |
| 3174 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9f5a0d7 | 2011-11-07 14:20:25 +0200 | [diff] [blame] | 3175 | cp.reason = HCI_ERROR_PAIRING_NOT_ALLOWED; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3176 | |
| 3177 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3178 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3179 | } |
| 3180 | |
| 3181 | unlock: |
| 3182 | hci_dev_unlock(hdev); |
| 3183 | } |
| 3184 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3185 | static void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3186 | { |
| 3187 | struct hci_ev_io_capa_reply *ev = (void *) skb->data; |
| 3188 | struct hci_conn *conn; |
| 3189 | |
| 3190 | BT_DBG("%s", hdev->name); |
| 3191 | |
| 3192 | hci_dev_lock(hdev); |
| 3193 | |
| 3194 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 3195 | if (!conn) |
| 3196 | goto unlock; |
| 3197 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3198 | conn->remote_cap = ev->capability; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3199 | conn->remote_auth = ev->authentication; |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 3200 | if (ev->oob_data) |
| 3201 | set_bit(HCI_CONN_REMOTE_OOB, &conn->flags); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3202 | |
| 3203 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3204 | hci_dev_unlock(hdev); |
| 3205 | } |
| 3206 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3207 | static void hci_user_confirm_request_evt(struct hci_dev *hdev, |
| 3208 | struct sk_buff *skb) |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 3209 | { |
| 3210 | struct hci_ev_user_confirm_req *ev = (void *) skb->data; |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 3211 | int loc_mitm, rem_mitm, confirm_hint = 0; |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 3212 | struct hci_conn *conn; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 3213 | |
| 3214 | BT_DBG("%s", hdev->name); |
| 3215 | |
| 3216 | hci_dev_lock(hdev); |
| 3217 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 3218 | if (!test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 3219 | goto unlock; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 3220 | |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 3221 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 3222 | if (!conn) |
| 3223 | goto unlock; |
| 3224 | |
| 3225 | loc_mitm = (conn->auth_type & 0x01); |
| 3226 | rem_mitm = (conn->remote_auth & 0x01); |
| 3227 | |
| 3228 | /* If we require MITM but the remote device can't provide that |
| 3229 | * (it has NoInputNoOutput) then reject the confirmation |
| 3230 | * request. The only exception is when we're dedicated bonding |
| 3231 | * initiators (connect_cfm_cb set) since then we always have the MITM |
| 3232 | * bit set. */ |
| 3233 | if (!conn->connect_cfm_cb && loc_mitm && conn->remote_cap == 0x03) { |
| 3234 | BT_DBG("Rejecting request: remote device can't provide MITM"); |
| 3235 | hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3236 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 3237 | goto unlock; |
| 3238 | } |
| 3239 | |
| 3240 | /* If no side requires MITM protection; auto-accept */ |
| 3241 | if ((!loc_mitm || conn->remote_cap == 0x03) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3242 | (!rem_mitm || conn->io_capability == 0x03)) { |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 3243 | |
| 3244 | /* If we're not the initiators request authorization to |
| 3245 | * proceed from user space (mgmt_user_confirm with |
| 3246 | * confirm_hint set to 1). */ |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3247 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 3248 | BT_DBG("Confirming auto-accept as acceptor"); |
| 3249 | confirm_hint = 1; |
| 3250 | goto confirm; |
| 3251 | } |
| 3252 | |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 3253 | BT_DBG("Auto-accept of user confirmation with %ums delay", |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3254 | hdev->auto_accept_delay); |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 3255 | |
| 3256 | if (hdev->auto_accept_delay > 0) { |
| 3257 | int delay = msecs_to_jiffies(hdev->auto_accept_delay); |
| 3258 | mod_timer(&conn->auto_accept_timer, jiffies + delay); |
| 3259 | goto unlock; |
| 3260 | } |
| 3261 | |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 3262 | hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3263 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 3264 | goto unlock; |
| 3265 | } |
| 3266 | |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 3267 | confirm: |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 3268 | mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0, ev->passkey, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3269 | confirm_hint); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 3270 | |
| 3271 | unlock: |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 3272 | hci_dev_unlock(hdev); |
| 3273 | } |
| 3274 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3275 | static void hci_user_passkey_request_evt(struct hci_dev *hdev, |
| 3276 | struct sk_buff *skb) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 3277 | { |
| 3278 | struct hci_ev_user_passkey_req *ev = (void *) skb->data; |
| 3279 | |
| 3280 | BT_DBG("%s", hdev->name); |
| 3281 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 3282 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 3283 | mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 3284 | } |
| 3285 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 3286 | static void hci_user_passkey_notify_evt(struct hci_dev *hdev, |
| 3287 | struct sk_buff *skb) |
| 3288 | { |
| 3289 | struct hci_ev_user_passkey_notify *ev = (void *) skb->data; |
| 3290 | struct hci_conn *conn; |
| 3291 | |
| 3292 | BT_DBG("%s", hdev->name); |
| 3293 | |
| 3294 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 3295 | if (!conn) |
| 3296 | return; |
| 3297 | |
| 3298 | conn->passkey_notify = __le32_to_cpu(ev->passkey); |
| 3299 | conn->passkey_entered = 0; |
| 3300 | |
| 3301 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
| 3302 | mgmt_user_passkey_notify(hdev, &conn->dst, conn->type, |
| 3303 | conn->dst_type, conn->passkey_notify, |
| 3304 | conn->passkey_entered); |
| 3305 | } |
| 3306 | |
| 3307 | static void hci_keypress_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 3308 | { |
| 3309 | struct hci_ev_keypress_notify *ev = (void *) skb->data; |
| 3310 | struct hci_conn *conn; |
| 3311 | |
| 3312 | BT_DBG("%s", hdev->name); |
| 3313 | |
| 3314 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 3315 | if (!conn) |
| 3316 | return; |
| 3317 | |
| 3318 | switch (ev->type) { |
| 3319 | case HCI_KEYPRESS_STARTED: |
| 3320 | conn->passkey_entered = 0; |
| 3321 | return; |
| 3322 | |
| 3323 | case HCI_KEYPRESS_ENTERED: |
| 3324 | conn->passkey_entered++; |
| 3325 | break; |
| 3326 | |
| 3327 | case HCI_KEYPRESS_ERASED: |
| 3328 | conn->passkey_entered--; |
| 3329 | break; |
| 3330 | |
| 3331 | case HCI_KEYPRESS_CLEARED: |
| 3332 | conn->passkey_entered = 0; |
| 3333 | break; |
| 3334 | |
| 3335 | case HCI_KEYPRESS_COMPLETED: |
| 3336 | return; |
| 3337 | } |
| 3338 | |
| 3339 | if (test_bit(HCI_MGMT, &hdev->dev_flags)) |
| 3340 | mgmt_user_passkey_notify(hdev, &conn->dst, conn->type, |
| 3341 | conn->dst_type, conn->passkey_notify, |
| 3342 | conn->passkey_entered); |
| 3343 | } |
| 3344 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3345 | static void hci_simple_pair_complete_evt(struct hci_dev *hdev, |
| 3346 | struct sk_buff *skb) |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3347 | { |
| 3348 | struct hci_ev_simple_pair_complete *ev = (void *) skb->data; |
| 3349 | struct hci_conn *conn; |
| 3350 | |
| 3351 | BT_DBG("%s", hdev->name); |
| 3352 | |
| 3353 | hci_dev_lock(hdev); |
| 3354 | |
| 3355 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 3356 | if (!conn) |
| 3357 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3358 | |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 3359 | /* To avoid duplicate auth_failed events to user space we check |
| 3360 | * the HCI_CONN_AUTH_PEND flag which will be set if we |
| 3361 | * initiated the authentication. A traditional auth_complete |
| 3362 | * event gets always produced as initiator and is also mapped to |
| 3363 | * the mgmt_auth_failed event */ |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 3364 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status) |
Johan Hedberg | bab73cb | 2012-02-09 16:07:29 +0200 | [diff] [blame] | 3365 | mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3366 | ev->status); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 3367 | |
| 3368 | hci_conn_put(conn); |
| 3369 | |
| 3370 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3371 | hci_dev_unlock(hdev); |
| 3372 | } |
| 3373 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3374 | static void hci_remote_host_features_evt(struct hci_dev *hdev, |
| 3375 | struct sk_buff *skb) |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3376 | { |
| 3377 | struct hci_ev_remote_host_features *ev = (void *) skb->data; |
| 3378 | struct inquiry_entry *ie; |
| 3379 | |
| 3380 | BT_DBG("%s", hdev->name); |
| 3381 | |
| 3382 | hci_dev_lock(hdev); |
| 3383 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 3384 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 3385 | if (ie) |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 3386 | ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3387 | |
| 3388 | hci_dev_unlock(hdev); |
| 3389 | } |
| 3390 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3391 | static void hci_remote_oob_data_request_evt(struct hci_dev *hdev, |
| 3392 | struct sk_buff *skb) |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 3393 | { |
| 3394 | struct hci_ev_remote_oob_data_request *ev = (void *) skb->data; |
| 3395 | struct oob_data *data; |
| 3396 | |
| 3397 | BT_DBG("%s", hdev->name); |
| 3398 | |
| 3399 | hci_dev_lock(hdev); |
| 3400 | |
Johan Hedberg | a8b2d5c | 2012-01-08 23:11:15 +0200 | [diff] [blame] | 3401 | if (!test_bit(HCI_MGMT, &hdev->dev_flags)) |
Szymon Janc | e1ba1f1 | 2011-04-06 13:01:59 +0200 | [diff] [blame] | 3402 | goto unlock; |
| 3403 | |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 3404 | data = hci_find_remote_oob_data(hdev, &ev->bdaddr); |
| 3405 | if (data) { |
| 3406 | struct hci_cp_remote_oob_data_reply cp; |
| 3407 | |
| 3408 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 3409 | memcpy(cp.hash, data->hash, sizeof(cp.hash)); |
| 3410 | memcpy(cp.randomizer, data->randomizer, sizeof(cp.randomizer)); |
| 3411 | |
| 3412 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3413 | &cp); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 3414 | } else { |
| 3415 | struct hci_cp_remote_oob_data_neg_reply cp; |
| 3416 | |
| 3417 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 3418 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3419 | &cp); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 3420 | } |
| 3421 | |
Szymon Janc | e1ba1f1 | 2011-04-06 13:01:59 +0200 | [diff] [blame] | 3422 | unlock: |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 3423 | hci_dev_unlock(hdev); |
| 3424 | } |
| 3425 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3426 | static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 3427 | { |
| 3428 | struct hci_ev_le_conn_complete *ev = (void *) skb->data; |
| 3429 | struct hci_conn *conn; |
| 3430 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3431 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 3432 | |
| 3433 | hci_dev_lock(hdev); |
| 3434 | |
Andre Guedes | b47a09b | 2012-07-27 15:10:15 -0300 | [diff] [blame] | 3435 | conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 3436 | if (!conn) { |
| 3437 | conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr); |
| 3438 | if (!conn) { |
| 3439 | BT_ERR("No memory for new connection"); |
Andre Guedes | 230fd16 | 2012-07-27 15:10:10 -0300 | [diff] [blame] | 3440 | goto unlock; |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 3441 | } |
Andre Guedes | 29b7988 | 2011-05-31 14:20:54 -0300 | [diff] [blame] | 3442 | |
| 3443 | conn->dst_type = ev->bdaddr_type; |
Andre Guedes | b9b343d | 2012-07-27 15:10:11 -0300 | [diff] [blame] | 3444 | |
| 3445 | if (ev->role == LE_CONN_ROLE_MASTER) { |
| 3446 | conn->out = true; |
| 3447 | conn->link_mode |= HCI_LM_MASTER; |
| 3448 | } |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 3449 | } |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 3450 | |
Andre Guedes | cd17dec | 2012-07-27 15:10:16 -0300 | [diff] [blame] | 3451 | if (ev->status) { |
| 3452 | mgmt_connect_failed(hdev, &conn->dst, conn->type, |
| 3453 | conn->dst_type, ev->status); |
| 3454 | hci_proto_connect_cfm(conn, ev->status); |
| 3455 | conn->state = BT_CLOSED; |
| 3456 | hci_conn_del(conn); |
| 3457 | goto unlock; |
| 3458 | } |
| 3459 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3460 | if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
| 3461 | mgmt_device_connected(hdev, &ev->bdaddr, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3462 | conn->dst_type, 0, NULL, 0, NULL); |
Vinicius Costa Gomes | 83bc71b | 2011-05-06 18:41:43 -0300 | [diff] [blame] | 3463 | |
Vinicius Costa Gomes | 7b5c0d5 | 2011-06-09 18:50:50 -0300 | [diff] [blame] | 3464 | conn->sec_level = BT_SECURITY_LOW; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 3465 | conn->handle = __le16_to_cpu(ev->handle); |
| 3466 | conn->state = BT_CONNECTED; |
| 3467 | |
| 3468 | hci_conn_hold_device(conn); |
| 3469 | hci_conn_add_sysfs(conn); |
| 3470 | |
| 3471 | hci_proto_connect_cfm(conn, ev->status); |
| 3472 | |
| 3473 | unlock: |
| 3474 | hci_dev_unlock(hdev); |
| 3475 | } |
| 3476 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3477 | static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 3478 | { |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 3479 | u8 num_reports = skb->data[0]; |
| 3480 | void *ptr = &skb->data[1]; |
Andre Guedes | 3c9e919 | 2012-01-10 18:20:50 -0300 | [diff] [blame] | 3481 | s8 rssi; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 3482 | |
| 3483 | hci_dev_lock(hdev); |
| 3484 | |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 3485 | while (num_reports--) { |
| 3486 | struct hci_ev_le_advertising_info *ev = ptr; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 3487 | |
Andre Guedes | 3c9e919 | 2012-01-10 18:20:50 -0300 | [diff] [blame] | 3488 | rssi = ev->data[ev->length]; |
| 3489 | mgmt_device_found(hdev, &ev->bdaddr, LE_LINK, ev->bdaddr_type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3490 | NULL, rssi, 0, 1, ev->data, ev->length); |
Andre Guedes | 3c9e919 | 2012-01-10 18:20:50 -0300 | [diff] [blame] | 3491 | |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 3492 | ptr += sizeof(*ev) + ev->length + 1; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | hci_dev_unlock(hdev); |
| 3496 | } |
| 3497 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3498 | static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3499 | { |
| 3500 | struct hci_ev_le_ltk_req *ev = (void *) skb->data; |
| 3501 | struct hci_cp_le_ltk_reply cp; |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 3502 | struct hci_cp_le_ltk_neg_reply neg; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3503 | struct hci_conn *conn; |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 3504 | struct smp_ltk *ltk; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3505 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3506 | BT_DBG("%s handle 0x%4.4x", hdev->name, __le16_to_cpu(ev->handle)); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3507 | |
| 3508 | hci_dev_lock(hdev); |
| 3509 | |
| 3510 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 3511 | if (conn == NULL) |
| 3512 | goto not_found; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3513 | |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 3514 | ltk = hci_find_ltk(hdev, ev->ediv, ev->random); |
| 3515 | if (ltk == NULL) |
| 3516 | goto not_found; |
| 3517 | |
| 3518 | memcpy(cp.ltk, ltk->val, sizeof(ltk->val)); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3519 | cp.handle = cpu_to_le16(conn->handle); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 3520 | |
| 3521 | if (ltk->authenticated) |
| 3522 | conn->sec_level = BT_SECURITY_HIGH; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3523 | |
| 3524 | hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp); |
| 3525 | |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 3526 | if (ltk->type & HCI_SMP_STK) { |
| 3527 | list_del(<k->list); |
| 3528 | kfree(ltk); |
| 3529 | } |
| 3530 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3531 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 3532 | |
| 3533 | return; |
| 3534 | |
| 3535 | not_found: |
| 3536 | neg.handle = ev->handle; |
| 3537 | hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg); |
| 3538 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3539 | } |
| 3540 | |
Gustavo Padovan | 6039aa73 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3541 | static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 3542 | { |
| 3543 | struct hci_ev_le_meta *le_ev = (void *) skb->data; |
| 3544 | |
| 3545 | skb_pull(skb, sizeof(*le_ev)); |
| 3546 | |
| 3547 | switch (le_ev->subevent) { |
| 3548 | case HCI_EV_LE_CONN_COMPLETE: |
| 3549 | hci_le_conn_complete_evt(hdev, skb); |
| 3550 | break; |
| 3551 | |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 3552 | case HCI_EV_LE_ADVERTISING_REPORT: |
| 3553 | hci_le_adv_report_evt(hdev, skb); |
| 3554 | break; |
| 3555 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 3556 | case HCI_EV_LE_LTK_REQ: |
| 3557 | hci_le_ltk_request_evt(hdev, skb); |
| 3558 | break; |
| 3559 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 3560 | default: |
| 3561 | break; |
| 3562 | } |
| 3563 | } |
| 3564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3565 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) |
| 3566 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3567 | struct hci_event_hdr *hdr = (void *) skb->data; |
| 3568 | __u8 event = hdr->evt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | |
| 3570 | skb_pull(skb, HCI_EVENT_HDR_SIZE); |
| 3571 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3572 | switch (event) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | case HCI_EV_INQUIRY_COMPLETE: |
| 3574 | hci_inquiry_complete_evt(hdev, skb); |
| 3575 | break; |
| 3576 | |
| 3577 | case HCI_EV_INQUIRY_RESULT: |
| 3578 | hci_inquiry_result_evt(hdev, skb); |
| 3579 | break; |
| 3580 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3581 | case HCI_EV_CONN_COMPLETE: |
| 3582 | hci_conn_complete_evt(hdev, skb); |
Marcel Holtmann | 21d9e30 | 2005-09-13 01:32:25 +0200 | [diff] [blame] | 3583 | break; |
| 3584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | case HCI_EV_CONN_REQUEST: |
| 3586 | hci_conn_request_evt(hdev, skb); |
| 3587 | break; |
| 3588 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3589 | case HCI_EV_DISCONN_COMPLETE: |
| 3590 | hci_disconn_complete_evt(hdev, skb); |
| 3591 | break; |
| 3592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3593 | case HCI_EV_AUTH_COMPLETE: |
| 3594 | hci_auth_complete_evt(hdev, skb); |
| 3595 | break; |
| 3596 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3597 | case HCI_EV_REMOTE_NAME: |
| 3598 | hci_remote_name_evt(hdev, skb); |
| 3599 | break; |
| 3600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3601 | case HCI_EV_ENCRYPT_CHANGE: |
| 3602 | hci_encrypt_change_evt(hdev, skb); |
| 3603 | break; |
| 3604 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3605 | case HCI_EV_CHANGE_LINK_KEY_COMPLETE: |
| 3606 | hci_change_link_key_complete_evt(hdev, skb); |
| 3607 | break; |
| 3608 | |
| 3609 | case HCI_EV_REMOTE_FEATURES: |
| 3610 | hci_remote_features_evt(hdev, skb); |
| 3611 | break; |
| 3612 | |
| 3613 | case HCI_EV_REMOTE_VERSION: |
| 3614 | hci_remote_version_evt(hdev, skb); |
| 3615 | break; |
| 3616 | |
| 3617 | case HCI_EV_QOS_SETUP_COMPLETE: |
| 3618 | hci_qos_setup_complete_evt(hdev, skb); |
| 3619 | break; |
| 3620 | |
| 3621 | case HCI_EV_CMD_COMPLETE: |
| 3622 | hci_cmd_complete_evt(hdev, skb); |
| 3623 | break; |
| 3624 | |
| 3625 | case HCI_EV_CMD_STATUS: |
| 3626 | hci_cmd_status_evt(hdev, skb); |
| 3627 | break; |
| 3628 | |
| 3629 | case HCI_EV_ROLE_CHANGE: |
| 3630 | hci_role_change_evt(hdev, skb); |
| 3631 | break; |
| 3632 | |
| 3633 | case HCI_EV_NUM_COMP_PKTS: |
| 3634 | hci_num_comp_pkts_evt(hdev, skb); |
| 3635 | break; |
| 3636 | |
| 3637 | case HCI_EV_MODE_CHANGE: |
| 3638 | hci_mode_change_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3639 | break; |
| 3640 | |
| 3641 | case HCI_EV_PIN_CODE_REQ: |
| 3642 | hci_pin_code_request_evt(hdev, skb); |
| 3643 | break; |
| 3644 | |
| 3645 | case HCI_EV_LINK_KEY_REQ: |
| 3646 | hci_link_key_request_evt(hdev, skb); |
| 3647 | break; |
| 3648 | |
| 3649 | case HCI_EV_LINK_KEY_NOTIFY: |
| 3650 | hci_link_key_notify_evt(hdev, skb); |
| 3651 | break; |
| 3652 | |
| 3653 | case HCI_EV_CLOCK_OFFSET: |
| 3654 | hci_clock_offset_evt(hdev, skb); |
| 3655 | break; |
| 3656 | |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 3657 | case HCI_EV_PKT_TYPE_CHANGE: |
| 3658 | hci_pkt_type_change_evt(hdev, skb); |
| 3659 | break; |
| 3660 | |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 3661 | case HCI_EV_PSCAN_REP_MODE: |
| 3662 | hci_pscan_rep_mode_evt(hdev, skb); |
| 3663 | break; |
| 3664 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3665 | case HCI_EV_INQUIRY_RESULT_WITH_RSSI: |
| 3666 | hci_inquiry_result_with_rssi_evt(hdev, skb); |
| 3667 | break; |
| 3668 | |
| 3669 | case HCI_EV_REMOTE_EXT_FEATURES: |
| 3670 | hci_remote_ext_features_evt(hdev, skb); |
| 3671 | break; |
| 3672 | |
| 3673 | case HCI_EV_SYNC_CONN_COMPLETE: |
| 3674 | hci_sync_conn_complete_evt(hdev, skb); |
| 3675 | break; |
| 3676 | |
| 3677 | case HCI_EV_SYNC_CONN_CHANGED: |
| 3678 | hci_sync_conn_changed_evt(hdev, skb); |
| 3679 | break; |
| 3680 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3681 | case HCI_EV_SNIFF_SUBRATE: |
| 3682 | hci_sniff_subrate_evt(hdev, skb); |
| 3683 | break; |
| 3684 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3685 | case HCI_EV_EXTENDED_INQUIRY_RESULT: |
| 3686 | hci_extended_inquiry_result_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | break; |
| 3688 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 3689 | case HCI_EV_KEY_REFRESH_COMPLETE: |
| 3690 | hci_key_refresh_complete_evt(hdev, skb); |
| 3691 | break; |
| 3692 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3693 | case HCI_EV_IO_CAPA_REQUEST: |
| 3694 | hci_io_capa_request_evt(hdev, skb); |
| 3695 | break; |
| 3696 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3697 | case HCI_EV_IO_CAPA_REPLY: |
| 3698 | hci_io_capa_reply_evt(hdev, skb); |
| 3699 | break; |
| 3700 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 3701 | case HCI_EV_USER_CONFIRM_REQUEST: |
| 3702 | hci_user_confirm_request_evt(hdev, skb); |
| 3703 | break; |
| 3704 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 3705 | case HCI_EV_USER_PASSKEY_REQUEST: |
| 3706 | hci_user_passkey_request_evt(hdev, skb); |
| 3707 | break; |
| 3708 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 3709 | case HCI_EV_USER_PASSKEY_NOTIFY: |
| 3710 | hci_user_passkey_notify_evt(hdev, skb); |
| 3711 | break; |
| 3712 | |
| 3713 | case HCI_EV_KEYPRESS_NOTIFY: |
| 3714 | hci_keypress_notify_evt(hdev, skb); |
| 3715 | break; |
| 3716 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3717 | case HCI_EV_SIMPLE_PAIR_COMPLETE: |
| 3718 | hci_simple_pair_complete_evt(hdev, skb); |
| 3719 | break; |
| 3720 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3721 | case HCI_EV_REMOTE_HOST_FEATURES: |
| 3722 | hci_remote_host_features_evt(hdev, skb); |
| 3723 | break; |
| 3724 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 3725 | case HCI_EV_LE_META: |
| 3726 | hci_le_meta_evt(hdev, skb); |
| 3727 | break; |
| 3728 | |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 3729 | case HCI_EV_REMOTE_OOB_DATA_REQUEST: |
| 3730 | hci_remote_oob_data_request_evt(hdev, skb); |
| 3731 | break; |
| 3732 | |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3733 | case HCI_EV_NUM_COMP_BLOCKS: |
| 3734 | hci_num_comp_blocks_evt(hdev, skb); |
| 3735 | break; |
| 3736 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3737 | default: |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3738 | BT_DBG("%s event 0x%2.2x", hdev->name, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | break; |
| 3740 | } |
| 3741 | |
| 3742 | kfree_skb(skb); |
| 3743 | hdev->stat.evt_rx++; |
| 3744 | } |