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