YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | BlueZ - Bluetooth protocol stack for Linux |
Ron Shaffer | 2d0a034 | 2010-05-28 11:53:46 -0400 | [diff] [blame] | 3 | Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
| 5 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License version 2 as |
| 9 | published by the Free Software Foundation; |
| 10 | |
| 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 12 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 14 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 15 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 16 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 17 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 19 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 20 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 21 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | SOFTWARE IS DISCLAIMED. |
| 23 | */ |
| 24 | |
| 25 | /* Bluetooth HCI event handling. */ |
| 26 | |
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 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [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 | |
| 75 | clear_bit(HCI_INQUIRY, &hdev->flags); |
| 76 | |
| 77 | hci_conn_check_pending(hdev); |
| 78 | } |
| 79 | |
| 80 | static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, struct sk_buff *skb) |
| 81 | { |
| 82 | BT_DBG("%s", hdev->name); |
| 83 | } |
| 84 | |
| 85 | static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb) |
| 86 | { |
| 87 | struct hci_rp_role_discovery *rp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 90 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 92 | if (rp->status) |
| 93 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 95 | hci_dev_lock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 97 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 98 | if (conn) { |
| 99 | if (rp->role) |
| 100 | conn->link_mode &= ~HCI_LM_MASTER; |
| 101 | else |
| 102 | conn->link_mode |= HCI_LM_MASTER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 104 | |
| 105 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 108 | static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
| 109 | { |
| 110 | struct hci_rp_read_link_policy *rp = (void *) skb->data; |
| 111 | struct hci_conn *conn; |
| 112 | |
| 113 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 114 | |
| 115 | if (rp->status) |
| 116 | return; |
| 117 | |
| 118 | hci_dev_lock(hdev); |
| 119 | |
| 120 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 121 | if (conn) |
| 122 | conn->link_policy = __le16_to_cpu(rp->policy); |
| 123 | |
| 124 | hci_dev_unlock(hdev); |
| 125 | } |
| 126 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 127 | 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] | 128 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 129 | struct hci_rp_write_link_policy *rp = (void *) skb->data; |
| 130 | struct hci_conn *conn; |
| 131 | void *sent; |
| 132 | |
| 133 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 134 | |
| 135 | if (rp->status) |
| 136 | return; |
| 137 | |
| 138 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY); |
| 139 | if (!sent) |
| 140 | return; |
| 141 | |
| 142 | hci_dev_lock(hdev); |
| 143 | |
| 144 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 145 | if (conn) |
Harvey Harrison | 8398531 | 2008-05-02 16:25:46 -0700 | [diff] [blame] | 146 | conn->link_policy = get_unaligned_le16(sent + 2); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 147 | |
| 148 | hci_dev_unlock(hdev); |
| 149 | } |
| 150 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 151 | static void hci_cc_read_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
| 152 | { |
| 153 | struct hci_rp_read_def_link_policy *rp = (void *) skb->data; |
| 154 | |
| 155 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 156 | |
| 157 | if (rp->status) |
| 158 | return; |
| 159 | |
| 160 | hdev->link_policy = __le16_to_cpu(rp->policy); |
| 161 | } |
| 162 | |
| 163 | static void hci_cc_write_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
| 164 | { |
| 165 | __u8 status = *((__u8 *) skb->data); |
| 166 | void *sent; |
| 167 | |
| 168 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 169 | |
| 170 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY); |
| 171 | if (!sent) |
| 172 | return; |
| 173 | |
| 174 | if (!status) |
| 175 | hdev->link_policy = get_unaligned_le16(sent); |
| 176 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 177 | hci_req_complete(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 180 | static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) |
| 181 | { |
| 182 | __u8 status = *((__u8 *) skb->data); |
| 183 | |
| 184 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 185 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 186 | hci_req_complete(hdev, HCI_OP_RESET, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 190 | { |
| 191 | __u8 status = *((__u8 *) skb->data); |
| 192 | void *sent; |
| 193 | |
| 194 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 195 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 196 | if (status) |
| 197 | return; |
| 198 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 199 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME); |
| 200 | if (!sent) |
| 201 | return; |
| 202 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 203 | memcpy(hdev->dev_name, sent, 248); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 207 | { |
| 208 | struct hci_rp_read_local_name *rp = (void *) skb->data; |
| 209 | |
| 210 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 211 | |
| 212 | if (rp->status) |
| 213 | return; |
| 214 | |
| 215 | memcpy(hdev->dev_name, rp->name, 248); |
| 216 | } |
| 217 | |
| 218 | static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 219 | { |
| 220 | __u8 status = *((__u8 *) skb->data); |
| 221 | void *sent; |
| 222 | |
| 223 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 224 | |
| 225 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE); |
| 226 | if (!sent) |
| 227 | return; |
| 228 | |
| 229 | if (!status) { |
| 230 | __u8 param = *((__u8 *) sent); |
| 231 | |
| 232 | if (param == AUTH_ENABLED) |
| 233 | set_bit(HCI_AUTH, &hdev->flags); |
| 234 | else |
| 235 | clear_bit(HCI_AUTH, &hdev->flags); |
| 236 | } |
| 237 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 238 | hci_req_complete(hdev, HCI_OP_WRITE_AUTH_ENABLE, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 242 | { |
| 243 | __u8 status = *((__u8 *) skb->data); |
| 244 | void *sent; |
| 245 | |
| 246 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 247 | |
| 248 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE); |
| 249 | if (!sent) |
| 250 | return; |
| 251 | |
| 252 | if (!status) { |
| 253 | __u8 param = *((__u8 *) sent); |
| 254 | |
| 255 | if (param) |
| 256 | set_bit(HCI_ENCRYPT, &hdev->flags); |
| 257 | else |
| 258 | clear_bit(HCI_ENCRYPT, &hdev->flags); |
| 259 | } |
| 260 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 261 | hci_req_complete(hdev, HCI_OP_WRITE_ENCRYPT_MODE, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 265 | { |
| 266 | __u8 status = *((__u8 *) skb->data); |
| 267 | void *sent; |
| 268 | |
| 269 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 270 | |
| 271 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); |
| 272 | if (!sent) |
| 273 | return; |
| 274 | |
| 275 | if (!status) { |
| 276 | __u8 param = *((__u8 *) sent); |
Johan Hedberg | 9fbcbb4 | 2010-12-30 00:18:33 +0200 | [diff] [blame] | 277 | int old_pscan, old_iscan; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 278 | |
Johan Hedberg | 9fbcbb4 | 2010-12-30 00:18:33 +0200 | [diff] [blame] | 279 | old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags); |
| 280 | old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 281 | |
Johan Hedberg | 73f22f6 | 2010-12-29 16:00:25 +0200 | [diff] [blame] | 282 | if (param & SCAN_INQUIRY) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 283 | set_bit(HCI_ISCAN, &hdev->flags); |
Johan Hedberg | 9fbcbb4 | 2010-12-30 00:18:33 +0200 | [diff] [blame] | 284 | if (!old_iscan) |
| 285 | mgmt_discoverable(hdev->id, 1); |
| 286 | } else if (old_iscan) |
Johan Hedberg | 73f22f6 | 2010-12-29 16:00:25 +0200 | [diff] [blame] | 287 | mgmt_discoverable(hdev->id, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 288 | |
Johan Hedberg | 9fbcbb4 | 2010-12-30 00:18:33 +0200 | [diff] [blame] | 289 | if (param & SCAN_PAGE) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 290 | set_bit(HCI_PSCAN, &hdev->flags); |
Johan Hedberg | 9fbcbb4 | 2010-12-30 00:18:33 +0200 | [diff] [blame] | 291 | if (!old_pscan) |
| 292 | mgmt_connectable(hdev->id, 1); |
| 293 | } else if (old_pscan) |
| 294 | mgmt_connectable(hdev->id, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 295 | } |
| 296 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 297 | hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 301 | { |
| 302 | struct hci_rp_read_class_of_dev *rp = (void *) skb->data; |
| 303 | |
| 304 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 305 | |
| 306 | if (rp->status) |
| 307 | return; |
| 308 | |
| 309 | memcpy(hdev->dev_class, rp->dev_class, 3); |
| 310 | |
| 311 | BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name, |
| 312 | hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); |
| 313 | } |
| 314 | |
| 315 | static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 316 | { |
| 317 | __u8 status = *((__u8 *) skb->data); |
| 318 | void *sent; |
| 319 | |
| 320 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 321 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 322 | if (status) |
| 323 | return; |
| 324 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 325 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV); |
| 326 | if (!sent) |
| 327 | return; |
| 328 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 329 | memcpy(hdev->dev_class, sent, 3); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) |
| 333 | { |
| 334 | struct hci_rp_read_voice_setting *rp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | __u16 setting; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 336 | |
| 337 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 338 | |
| 339 | if (rp->status) |
| 340 | return; |
| 341 | |
| 342 | setting = __le16_to_cpu(rp->voice_setting); |
| 343 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 344 | if (hdev->voice_setting == setting) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 345 | return; |
| 346 | |
| 347 | hdev->voice_setting = setting; |
| 348 | |
| 349 | BT_DBG("%s voice setting 0x%04x", hdev->name, setting); |
| 350 | |
| 351 | if (hdev->notify) { |
| 352 | tasklet_disable(&hdev->tx_task); |
| 353 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
| 354 | tasklet_enable(&hdev->tx_task); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) |
| 359 | { |
| 360 | __u8 status = *((__u8 *) skb->data); |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 361 | __u16 setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | void *sent; |
| 363 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 364 | BT_DBG("%s status 0x%x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 366 | if (status) |
| 367 | return; |
| 368 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 369 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING); |
| 370 | if (!sent) |
| 371 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 373 | setting = get_unaligned_le16(sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 375 | if (hdev->voice_setting == setting) |
| 376 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 378 | hdev->voice_setting = setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 389 | 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] | 390 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 391 | __u8 status = *((__u8 *) skb->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 393 | BT_DBG("%s status 0x%x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 395 | hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 398 | static void hci_cc_read_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 399 | { |
| 400 | struct hci_rp_read_ssp_mode *rp = (void *) skb->data; |
| 401 | |
| 402 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 403 | |
| 404 | if (rp->status) |
| 405 | return; |
| 406 | |
| 407 | hdev->ssp_mode = rp->mode; |
| 408 | } |
| 409 | |
| 410 | static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 411 | { |
| 412 | __u8 status = *((__u8 *) skb->data); |
| 413 | void *sent; |
| 414 | |
| 415 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 416 | |
| 417 | if (status) |
| 418 | return; |
| 419 | |
| 420 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); |
| 421 | if (!sent) |
| 422 | return; |
| 423 | |
| 424 | hdev->ssp_mode = *((__u8 *) sent); |
| 425 | } |
| 426 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 427 | static u8 hci_get_inquiry_mode(struct hci_dev *hdev) |
| 428 | { |
| 429 | if (hdev->features[6] & LMP_EXT_INQ) |
| 430 | return 2; |
| 431 | |
| 432 | if (hdev->features[3] & LMP_RSSI_INQ) |
| 433 | return 1; |
| 434 | |
| 435 | if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 && |
| 436 | hdev->lmp_subver == 0x0757) |
| 437 | return 1; |
| 438 | |
| 439 | if (hdev->manufacturer == 15) { |
| 440 | if (hdev->hci_rev == 0x03 && hdev->lmp_subver == 0x6963) |
| 441 | return 1; |
| 442 | if (hdev->hci_rev == 0x09 && hdev->lmp_subver == 0x6963) |
| 443 | return 1; |
| 444 | if (hdev->hci_rev == 0x00 && hdev->lmp_subver == 0x6965) |
| 445 | return 1; |
| 446 | } |
| 447 | |
| 448 | if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 && |
| 449 | hdev->lmp_subver == 0x1805) |
| 450 | return 1; |
| 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | static void hci_setup_inquiry_mode(struct hci_dev *hdev) |
| 456 | { |
| 457 | u8 mode; |
| 458 | |
| 459 | mode = hci_get_inquiry_mode(hdev); |
| 460 | |
| 461 | hci_send_cmd(hdev, HCI_OP_WRITE_INQUIRY_MODE, 1, &mode); |
| 462 | } |
| 463 | |
| 464 | static void hci_setup_event_mask(struct hci_dev *hdev) |
| 465 | { |
| 466 | /* The second byte is 0xff instead of 0x9f (two reserved bits |
| 467 | * disabled) since a Broadcom 1.2 dongle doesn't respond to the |
| 468 | * command otherwise */ |
| 469 | u8 events[8] = { 0xff, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x00 }; |
| 470 | |
| 471 | /* Events for 1.2 and newer controllers */ |
| 472 | if (hdev->lmp_ver > 1) { |
| 473 | events[4] |= 0x01; /* Flow Specification Complete */ |
| 474 | events[4] |= 0x02; /* Inquiry Result with RSSI */ |
| 475 | events[4] |= 0x04; /* Read Remote Extended Features Complete */ |
| 476 | events[5] |= 0x08; /* Synchronous Connection Complete */ |
| 477 | events[5] |= 0x10; /* Synchronous Connection Changed */ |
| 478 | } |
| 479 | |
| 480 | if (hdev->features[3] & LMP_RSSI_INQ) |
| 481 | events[4] |= 0x04; /* Inquiry Result with RSSI */ |
| 482 | |
| 483 | if (hdev->features[5] & LMP_SNIFF_SUBR) |
| 484 | events[5] |= 0x20; /* Sniff Subrating */ |
| 485 | |
| 486 | if (hdev->features[5] & LMP_PAUSE_ENC) |
| 487 | events[5] |= 0x80; /* Encryption Key Refresh Complete */ |
| 488 | |
| 489 | if (hdev->features[6] & LMP_EXT_INQ) |
| 490 | events[5] |= 0x40; /* Extended Inquiry Result */ |
| 491 | |
| 492 | if (hdev->features[6] & LMP_NO_FLUSH) |
| 493 | events[7] |= 0x01; /* Enhanced Flush Complete */ |
| 494 | |
| 495 | if (hdev->features[7] & LMP_LSTO) |
| 496 | events[6] |= 0x80; /* Link Supervision Timeout Changed */ |
| 497 | |
| 498 | if (hdev->features[6] & LMP_SIMPLE_PAIR) { |
| 499 | events[6] |= 0x01; /* IO Capability Request */ |
| 500 | events[6] |= 0x02; /* IO Capability Response */ |
| 501 | events[6] |= 0x04; /* User Confirmation Request */ |
| 502 | events[6] |= 0x08; /* User Passkey Request */ |
| 503 | events[6] |= 0x10; /* Remote OOB Data Request */ |
| 504 | events[6] |= 0x20; /* Simple Pairing Complete */ |
| 505 | events[7] |= 0x04; /* User Passkey Notification */ |
| 506 | events[7] |= 0x08; /* Keypress Notification */ |
| 507 | events[7] |= 0x10; /* Remote Host Supported |
| 508 | * Features Notification */ |
| 509 | } |
| 510 | |
| 511 | if (hdev->features[4] & LMP_LE) |
| 512 | events[7] |= 0x20; /* LE Meta-Event */ |
| 513 | |
| 514 | hci_send_cmd(hdev, HCI_OP_SET_EVENT_MASK, sizeof(events), events); |
| 515 | } |
| 516 | |
| 517 | static void hci_setup(struct hci_dev *hdev) |
| 518 | { |
| 519 | hci_setup_event_mask(hdev); |
| 520 | |
| 521 | if (hdev->lmp_ver > 1) |
| 522 | hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL); |
| 523 | |
| 524 | if (hdev->features[6] & LMP_SIMPLE_PAIR) { |
| 525 | u8 mode = 0x01; |
| 526 | hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, sizeof(mode), &mode); |
| 527 | } |
| 528 | |
| 529 | if (hdev->features[3] & LMP_RSSI_INQ) |
| 530 | hci_setup_inquiry_mode(hdev); |
| 531 | |
| 532 | if (hdev->features[7] & LMP_INQ_TX_PWR) |
| 533 | hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, 0, NULL); |
| 534 | } |
| 535 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 536 | static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) |
| 537 | { |
| 538 | struct hci_rp_read_local_version *rp = (void *) skb->data; |
| 539 | |
| 540 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 541 | |
| 542 | if (rp->status) |
| 543 | return; |
| 544 | |
| 545 | hdev->hci_ver = rp->hci_ver; |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 546 | hdev->hci_rev = __le16_to_cpu(rp->hci_rev); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 547 | hdev->lmp_ver = rp->lmp_ver; |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 548 | hdev->manufacturer = __le16_to_cpu(rp->manufacturer); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 549 | hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 550 | |
| 551 | BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name, |
| 552 | hdev->manufacturer, |
| 553 | hdev->hci_ver, hdev->hci_rev); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 554 | |
| 555 | if (test_bit(HCI_INIT, &hdev->flags)) |
| 556 | hci_setup(hdev); |
| 557 | } |
| 558 | |
| 559 | static void hci_setup_link_policy(struct hci_dev *hdev) |
| 560 | { |
| 561 | u16 link_policy = 0; |
| 562 | |
| 563 | if (hdev->features[0] & LMP_RSWITCH) |
| 564 | link_policy |= HCI_LP_RSWITCH; |
| 565 | if (hdev->features[0] & LMP_HOLD) |
| 566 | link_policy |= HCI_LP_HOLD; |
| 567 | if (hdev->features[0] & LMP_SNIFF) |
| 568 | link_policy |= HCI_LP_SNIFF; |
| 569 | if (hdev->features[1] & LMP_PARK) |
| 570 | link_policy |= HCI_LP_PARK; |
| 571 | |
| 572 | link_policy = cpu_to_le16(link_policy); |
| 573 | hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, |
| 574 | sizeof(link_policy), &link_policy); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb) |
| 578 | { |
| 579 | struct hci_rp_read_local_commands *rp = (void *) skb->data; |
| 580 | |
| 581 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 582 | |
| 583 | if (rp->status) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 584 | goto done; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 585 | |
| 586 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 587 | |
| 588 | if (test_bit(HCI_INIT, &hdev->flags) && (hdev->commands[5] & 0x10)) |
| 589 | hci_setup_link_policy(hdev); |
| 590 | |
| 591 | done: |
| 592 | hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb) |
| 596 | { |
| 597 | struct hci_rp_read_local_features *rp = (void *) skb->data; |
| 598 | |
| 599 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 600 | |
| 601 | if (rp->status) |
| 602 | return; |
| 603 | |
| 604 | memcpy(hdev->features, rp->features, 8); |
| 605 | |
| 606 | /* Adjust default settings according to features |
| 607 | * supported by device. */ |
| 608 | |
| 609 | if (hdev->features[0] & LMP_3SLOT) |
| 610 | hdev->pkt_type |= (HCI_DM3 | HCI_DH3); |
| 611 | |
| 612 | if (hdev->features[0] & LMP_5SLOT) |
| 613 | hdev->pkt_type |= (HCI_DM5 | HCI_DH5); |
| 614 | |
| 615 | if (hdev->features[1] & LMP_HV2) { |
| 616 | hdev->pkt_type |= (HCI_HV2); |
| 617 | hdev->esco_type |= (ESCO_HV2); |
| 618 | } |
| 619 | |
| 620 | if (hdev->features[1] & LMP_HV3) { |
| 621 | hdev->pkt_type |= (HCI_HV3); |
| 622 | hdev->esco_type |= (ESCO_HV3); |
| 623 | } |
| 624 | |
| 625 | if (hdev->features[3] & LMP_ESCO) |
| 626 | hdev->esco_type |= (ESCO_EV3); |
| 627 | |
| 628 | if (hdev->features[4] & LMP_EV4) |
| 629 | hdev->esco_type |= (ESCO_EV4); |
| 630 | |
| 631 | if (hdev->features[4] & LMP_EV5) |
| 632 | hdev->esco_type |= (ESCO_EV5); |
| 633 | |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 634 | if (hdev->features[5] & LMP_EDR_ESCO_2M) |
| 635 | hdev->esco_type |= (ESCO_2EV3); |
| 636 | |
| 637 | if (hdev->features[5] & LMP_EDR_ESCO_3M) |
| 638 | hdev->esco_type |= (ESCO_3EV3); |
| 639 | |
| 640 | if (hdev->features[5] & LMP_EDR_3S_ESCO) |
| 641 | hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); |
| 642 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 643 | BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name, |
| 644 | hdev->features[0], hdev->features[1], |
| 645 | hdev->features[2], hdev->features[3], |
| 646 | hdev->features[4], hdev->features[5], |
| 647 | hdev->features[6], hdev->features[7]); |
| 648 | } |
| 649 | |
| 650 | static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) |
| 651 | { |
| 652 | struct hci_rp_read_buffer_size *rp = (void *) skb->data; |
| 653 | |
| 654 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 655 | |
| 656 | if (rp->status) |
| 657 | return; |
| 658 | |
| 659 | hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu); |
| 660 | hdev->sco_mtu = rp->sco_mtu; |
| 661 | hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt); |
| 662 | hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt); |
| 663 | |
| 664 | if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) { |
| 665 | hdev->sco_mtu = 64; |
| 666 | hdev->sco_pkts = 8; |
| 667 | } |
| 668 | |
| 669 | hdev->acl_cnt = hdev->acl_pkts; |
| 670 | hdev->sco_cnt = hdev->sco_pkts; |
| 671 | |
| 672 | BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, |
| 673 | hdev->acl_mtu, hdev->acl_pkts, |
| 674 | hdev->sco_mtu, hdev->sco_pkts); |
| 675 | } |
| 676 | |
| 677 | static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb) |
| 678 | { |
| 679 | struct hci_rp_read_bd_addr *rp = (void *) skb->data; |
| 680 | |
| 681 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 682 | |
| 683 | if (!rp->status) |
| 684 | bacpy(&hdev->bdaddr, &rp->bdaddr); |
| 685 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 686 | hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status); |
| 687 | } |
| 688 | |
| 689 | static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb) |
| 690 | { |
| 691 | __u8 status = *((__u8 *) skb->data); |
| 692 | |
| 693 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 694 | |
| 695 | hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 696 | } |
| 697 | |
Johan Hedberg | b0916ea | 2011-01-10 13:44:55 +0200 | [diff] [blame] | 698 | static void hci_cc_delete_stored_link_key(struct hci_dev *hdev, |
| 699 | struct sk_buff *skb) |
| 700 | { |
| 701 | __u8 status = *((__u8 *) skb->data); |
| 702 | |
| 703 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 704 | |
| 705 | hci_req_complete(hdev, HCI_OP_DELETE_STORED_LINK_KEY, status); |
| 706 | } |
| 707 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 708 | static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb) |
| 709 | { |
| 710 | __u8 status = *((__u8 *) skb->data); |
| 711 | |
| 712 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 713 | |
| 714 | hci_req_complete(hdev, HCI_OP_SET_EVENT_MASK, status); |
| 715 | } |
| 716 | |
| 717 | static void hci_cc_write_inquiry_mode(struct hci_dev *hdev, |
| 718 | struct sk_buff *skb) |
| 719 | { |
| 720 | __u8 status = *((__u8 *) skb->data); |
| 721 | |
| 722 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 723 | |
| 724 | hci_req_complete(hdev, HCI_OP_WRITE_INQUIRY_MODE, status); |
| 725 | } |
| 726 | |
| 727 | static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, |
| 728 | struct sk_buff *skb) |
| 729 | { |
| 730 | __u8 status = *((__u8 *) skb->data); |
| 731 | |
| 732 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 733 | |
| 734 | hci_req_complete(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, status); |
| 735 | } |
| 736 | |
| 737 | static void hci_cc_set_event_flt(struct hci_dev *hdev, struct sk_buff *skb) |
| 738 | { |
| 739 | __u8 status = *((__u8 *) skb->data); |
| 740 | |
| 741 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 742 | |
| 743 | hci_req_complete(hdev, HCI_OP_SET_EVENT_FLT, status); |
| 744 | } |
| 745 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 746 | static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 747 | { |
| 748 | struct hci_rp_pin_code_reply *rp = (void *) skb->data; |
| 749 | struct hci_cp_pin_code_reply *cp; |
| 750 | struct hci_conn *conn; |
| 751 | |
| 752 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 753 | |
| 754 | if (test_bit(HCI_MGMT, &hdev->flags)) |
| 755 | mgmt_pin_code_reply_complete(hdev->id, &rp->bdaddr, rp->status); |
| 756 | |
| 757 | if (rp->status != 0) |
| 758 | return; |
| 759 | |
| 760 | cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY); |
| 761 | if (!cp) |
| 762 | return; |
| 763 | |
| 764 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 765 | if (conn) |
| 766 | conn->pin_length = cp->pin_len; |
| 767 | } |
| 768 | |
| 769 | static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 770 | { |
| 771 | struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data; |
| 772 | |
| 773 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
| 774 | |
| 775 | if (test_bit(HCI_MGMT, &hdev->flags)) |
| 776 | mgmt_pin_code_neg_reply_complete(hdev->id, &rp->bdaddr, |
| 777 | rp->status); |
| 778 | } |
| 779 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 780 | static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) |
| 781 | { |
| 782 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 783 | |
| 784 | if (status) { |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 785 | hci_req_complete(hdev, HCI_OP_INQUIRY, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 786 | |
| 787 | hci_conn_check_pending(hdev); |
| 788 | } else |
| 789 | set_bit(HCI_INQUIRY, &hdev->flags); |
| 790 | } |
| 791 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) |
| 793 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 794 | struct hci_cp_create_conn *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 797 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 798 | |
| 799 | cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | if (!cp) |
| 801 | return; |
| 802 | |
| 803 | hci_dev_lock(hdev); |
| 804 | |
| 805 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 806 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 807 | 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] | 808 | |
| 809 | if (status) { |
| 810 | if (conn && conn->state == BT_CONNECT) { |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 811 | if (status != 0x0c || conn->attempt > 2) { |
| 812 | conn->state = BT_CLOSED; |
| 813 | hci_proto_connect_cfm(conn, status); |
| 814 | hci_conn_del(conn); |
| 815 | } else |
| 816 | conn->state = BT_CONNECT2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | } |
| 818 | } else { |
| 819 | if (!conn) { |
| 820 | conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr); |
| 821 | if (conn) { |
| 822 | conn->out = 1; |
| 823 | conn->link_mode |= HCI_LM_MASTER; |
| 824 | } else |
Gustavo F. Padovan | 893ef97 | 2010-07-18 15:13:37 -0300 | [diff] [blame] | 825 | BT_ERR("No memory for new connection"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 827 | } |
| 828 | |
| 829 | hci_dev_unlock(hdev); |
| 830 | } |
| 831 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 832 | static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 834 | struct hci_cp_add_sco *cp; |
| 835 | struct hci_conn *acl, *sco; |
| 836 | __u16 handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 838 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 839 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 840 | if (!status) |
| 841 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 843 | cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO); |
| 844 | if (!cp) |
| 845 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 847 | handle = __le16_to_cpu(cp->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 849 | BT_DBG("%s handle %d", hdev->name, handle); |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 850 | |
| 851 | hci_dev_lock(hdev); |
| 852 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 853 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 854 | if (acl) { |
| 855 | sco = acl->link; |
| 856 | if (sco) { |
| 857 | sco->state = BT_CLOSED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 858 | |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 859 | hci_proto_connect_cfm(sco, status); |
| 860 | hci_conn_del(sco); |
| 861 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 862 | } |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 863 | |
| 864 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 867 | static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) |
| 868 | { |
| 869 | struct hci_cp_auth_requested *cp; |
| 870 | struct hci_conn *conn; |
| 871 | |
| 872 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 873 | |
| 874 | if (!status) |
| 875 | return; |
| 876 | |
| 877 | cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED); |
| 878 | if (!cp) |
| 879 | return; |
| 880 | |
| 881 | hci_dev_lock(hdev); |
| 882 | |
| 883 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 884 | if (conn) { |
| 885 | if (conn->state == BT_CONFIG) { |
| 886 | hci_proto_connect_cfm(conn, status); |
| 887 | hci_conn_put(conn); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | hci_dev_unlock(hdev); |
| 892 | } |
| 893 | |
| 894 | static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) |
| 895 | { |
| 896 | struct hci_cp_set_conn_encrypt *cp; |
| 897 | struct hci_conn *conn; |
| 898 | |
| 899 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 900 | |
| 901 | if (!status) |
| 902 | return; |
| 903 | |
| 904 | cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT); |
| 905 | if (!cp) |
| 906 | return; |
| 907 | |
| 908 | hci_dev_lock(hdev); |
| 909 | |
| 910 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 911 | if (conn) { |
| 912 | if (conn->state == BT_CONFIG) { |
| 913 | hci_proto_connect_cfm(conn, status); |
| 914 | hci_conn_put(conn); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | hci_dev_unlock(hdev); |
| 919 | } |
| 920 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 921 | static int hci_outgoing_auth_needed(struct hci_dev *hdev, |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 922 | struct hci_conn *conn) |
| 923 | { |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 924 | if (conn->state != BT_CONFIG || !conn->out) |
| 925 | return 0; |
| 926 | |
Johan Hedberg | 765c2a9 | 2011-01-19 12:06:52 +0530 | [diff] [blame] | 927 | if (conn->pending_sec_level == BT_SECURITY_SDP) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 928 | return 0; |
| 929 | |
| 930 | /* Only request authentication for SSP connections or non-SSP |
| 931 | * devices with sec_level HIGH */ |
| 932 | if (!(hdev->ssp_mode > 0 && conn->ssp_mode > 0) && |
Johan Hedberg | 765c2a9 | 2011-01-19 12:06:52 +0530 | [diff] [blame] | 933 | conn->pending_sec_level != BT_SECURITY_HIGH) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 934 | return 0; |
| 935 | |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 936 | return 1; |
| 937 | } |
| 938 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 939 | static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) |
| 940 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 941 | struct hci_cp_remote_name_req *cp; |
| 942 | struct hci_conn *conn; |
| 943 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 944 | BT_DBG("%s status 0x%x", hdev->name, status); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 945 | |
| 946 | /* If successful wait for the name req complete event before |
| 947 | * checking for the need to do authentication */ |
| 948 | if (!status) |
| 949 | return; |
| 950 | |
| 951 | cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ); |
| 952 | if (!cp) |
| 953 | return; |
| 954 | |
| 955 | hci_dev_lock(hdev); |
| 956 | |
| 957 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 958 | if (conn && hci_outgoing_auth_needed(hdev, conn)) { |
| 959 | struct hci_cp_auth_requested cp; |
| 960 | cp.handle = __cpu_to_le16(conn->handle); |
| 961 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); |
| 962 | } |
| 963 | |
| 964 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 965 | } |
| 966 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 967 | static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) |
| 968 | { |
| 969 | struct hci_cp_read_remote_features *cp; |
| 970 | struct hci_conn *conn; |
| 971 | |
| 972 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 973 | |
| 974 | if (!status) |
| 975 | return; |
| 976 | |
| 977 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES); |
| 978 | if (!cp) |
| 979 | return; |
| 980 | |
| 981 | hci_dev_lock(hdev); |
| 982 | |
| 983 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 984 | if (conn) { |
| 985 | if (conn->state == BT_CONFIG) { |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 986 | hci_proto_connect_cfm(conn, status); |
| 987 | hci_conn_put(conn); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | hci_dev_unlock(hdev); |
| 992 | } |
| 993 | |
| 994 | static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status) |
| 995 | { |
| 996 | struct hci_cp_read_remote_ext_features *cp; |
| 997 | struct hci_conn *conn; |
| 998 | |
| 999 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 1000 | |
| 1001 | if (!status) |
| 1002 | return; |
| 1003 | |
| 1004 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES); |
| 1005 | if (!cp) |
| 1006 | return; |
| 1007 | |
| 1008 | hci_dev_lock(hdev); |
| 1009 | |
| 1010 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 1011 | if (conn) { |
| 1012 | if (conn->state == BT_CONFIG) { |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1013 | hci_proto_connect_cfm(conn, status); |
| 1014 | hci_conn_put(conn); |
| 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | hci_dev_unlock(hdev); |
| 1019 | } |
| 1020 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1021 | static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| 1022 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1023 | struct hci_cp_setup_sync_conn *cp; |
| 1024 | struct hci_conn *acl, *sco; |
| 1025 | __u16 handle; |
| 1026 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1027 | BT_DBG("%s status 0x%x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1028 | |
| 1029 | if (!status) |
| 1030 | return; |
| 1031 | |
| 1032 | cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN); |
| 1033 | if (!cp) |
| 1034 | return; |
| 1035 | |
| 1036 | handle = __le16_to_cpu(cp->handle); |
| 1037 | |
| 1038 | BT_DBG("%s handle %d", hdev->name, handle); |
| 1039 | |
| 1040 | hci_dev_lock(hdev); |
| 1041 | |
| 1042 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1043 | if (acl) { |
| 1044 | sco = acl->link; |
| 1045 | if (sco) { |
| 1046 | sco->state = BT_CLOSED; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1047 | |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1048 | hci_proto_connect_cfm(sco, status); |
| 1049 | hci_conn_del(sco); |
| 1050 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 1057 | { |
| 1058 | struct hci_cp_sniff_mode *cp; |
| 1059 | struct hci_conn *conn; |
| 1060 | |
| 1061 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 1062 | |
| 1063 | if (!status) |
| 1064 | return; |
| 1065 | |
| 1066 | cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE); |
| 1067 | if (!cp) |
| 1068 | return; |
| 1069 | |
| 1070 | hci_dev_lock(hdev); |
| 1071 | |
| 1072 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1073 | if (conn) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1074 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend); |
| 1075 | |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1076 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend)) |
| 1077 | hci_sco_setup(conn, status); |
| 1078 | } |
| 1079 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1080 | hci_dev_unlock(hdev); |
| 1081 | } |
| 1082 | |
| 1083 | static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 1084 | { |
| 1085 | struct hci_cp_exit_sniff_mode *cp; |
| 1086 | struct hci_conn *conn; |
| 1087 | |
| 1088 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 1089 | |
| 1090 | if (!status) |
| 1091 | return; |
| 1092 | |
| 1093 | cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE); |
| 1094 | if (!cp) |
| 1095 | return; |
| 1096 | |
| 1097 | hci_dev_lock(hdev); |
| 1098 | |
| 1099 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1100 | if (conn) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1101 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend); |
| 1102 | |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1103 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend)) |
| 1104 | hci_sco_setup(conn, status); |
| 1105 | } |
| 1106 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1107 | hci_dev_unlock(hdev); |
| 1108 | } |
| 1109 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame^] | 1110 | static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status) |
| 1111 | { |
| 1112 | struct hci_cp_le_create_conn *cp; |
| 1113 | struct hci_conn *conn; |
| 1114 | |
| 1115 | BT_DBG("%s status 0x%x", hdev->name, status); |
| 1116 | |
| 1117 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN); |
| 1118 | if (!cp) |
| 1119 | return; |
| 1120 | |
| 1121 | hci_dev_lock(hdev); |
| 1122 | |
| 1123 | conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr); |
| 1124 | |
| 1125 | BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr), |
| 1126 | conn); |
| 1127 | |
| 1128 | if (status) { |
| 1129 | if (conn && conn->state == BT_CONNECT) { |
| 1130 | conn->state = BT_CLOSED; |
| 1131 | hci_proto_connect_cfm(conn, status); |
| 1132 | hci_conn_del(conn); |
| 1133 | } |
| 1134 | } else { |
| 1135 | if (!conn) { |
| 1136 | conn = hci_conn_add(hdev, LE_LINK, &cp->peer_addr); |
| 1137 | if (conn) |
| 1138 | conn->out = 1; |
| 1139 | else |
| 1140 | BT_ERR("No memory for new connection"); |
| 1141 | } |
| 1142 | } |
| 1143 | |
| 1144 | hci_dev_unlock(hdev); |
| 1145 | } |
| 1146 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1147 | static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1148 | { |
| 1149 | __u8 status = *((__u8 *) skb->data); |
| 1150 | |
| 1151 | BT_DBG("%s status %d", hdev->name, status); |
| 1152 | |
| 1153 | clear_bit(HCI_INQUIRY, &hdev->flags); |
| 1154 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 1155 | hci_req_complete(hdev, HCI_OP_INQUIRY, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1156 | |
| 1157 | hci_conn_check_pending(hdev); |
| 1158 | } |
| 1159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1161 | { |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1162 | struct inquiry_data data; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1163 | struct inquiry_info *info = (void *) (skb->data + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | int num_rsp = *((__u8 *) skb->data); |
| 1165 | |
| 1166 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 1167 | |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1168 | if (!num_rsp) |
| 1169 | return; |
| 1170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | for (; num_rsp; num_rsp--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | bacpy(&data.bdaddr, &info->bdaddr); |
| 1175 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 1176 | data.pscan_period_mode = info->pscan_period_mode; |
| 1177 | data.pscan_mode = info->pscan_mode; |
| 1178 | memcpy(data.dev_class, info->dev_class, 3); |
| 1179 | data.clock_offset = info->clock_offset; |
| 1180 | data.rssi = 0x00; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 1181 | data.ssp_mode = 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | info++; |
| 1183 | hci_inquiry_cache_update(hdev, &data); |
| 1184 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | hci_dev_unlock(hdev); |
| 1187 | } |
| 1188 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1189 | 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] | 1190 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1191 | struct hci_ev_conn_complete *ev = (void *) skb->data; |
| 1192 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1194 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1197 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1198 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9499237 | 2009-04-19 19:30:03 +0200 | [diff] [blame] | 1199 | if (!conn) { |
| 1200 | if (ev->link_type != SCO_LINK) |
| 1201 | goto unlock; |
| 1202 | |
| 1203 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); |
| 1204 | if (!conn) |
| 1205 | goto unlock; |
| 1206 | |
| 1207 | conn->type = SCO_LINK; |
| 1208 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1209 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1210 | if (!ev->status) { |
| 1211 | conn->handle = __le16_to_cpu(ev->handle); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1212 | |
| 1213 | if (conn->type == ACL_LINK) { |
| 1214 | conn->state = BT_CONFIG; |
| 1215 | hci_conn_hold(conn); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1216 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 1217 | mgmt_connected(hdev->id, &ev->bdaddr); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1218 | } else |
| 1219 | conn->state = BT_CONNECTED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1220 | |
Marcel Holtmann | 9eba32b | 2009-08-22 14:19:26 -0700 | [diff] [blame] | 1221 | hci_conn_hold_device(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 1222 | hci_conn_add_sysfs(conn); |
| 1223 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1224 | if (test_bit(HCI_AUTH, &hdev->flags)) |
| 1225 | conn->link_mode |= HCI_LM_AUTH; |
| 1226 | |
| 1227 | if (test_bit(HCI_ENCRYPT, &hdev->flags)) |
| 1228 | conn->link_mode |= HCI_LM_ENCRYPT; |
| 1229 | |
| 1230 | /* Get remote features */ |
| 1231 | if (conn->type == ACL_LINK) { |
| 1232 | struct hci_cp_read_remote_features cp; |
| 1233 | cp.handle = ev->handle; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1234 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, |
| 1235 | sizeof(cp), &cp); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1236 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1237 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1238 | /* Set packet type for incoming connection */ |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 1239 | if (!conn->out && hdev->hci_ver < 3) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1240 | struct hci_cp_change_conn_ptype cp; |
| 1241 | cp.handle = ev->handle; |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 1242 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
| 1243 | hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, |
| 1244 | sizeof(cp), &cp); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1245 | } |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 1246 | } else { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1247 | conn->state = BT_CLOSED; |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 1248 | if (conn->type == ACL_LINK) |
| 1249 | mgmt_connect_failed(hdev->id, &ev->bdaddr, ev->status); |
| 1250 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1251 | |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1252 | if (conn->type == ACL_LINK) |
| 1253 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 1254 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1255 | if (ev->status) { |
| 1256 | hci_proto_connect_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1257 | hci_conn_del(conn); |
Marcel Holtmann | c89b6e6 | 2009-01-15 21:57:03 +0100 | [diff] [blame] | 1258 | } else if (ev->link_type != ACL_LINK) |
| 1259 | hci_proto_connect_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1260 | |
| 1261 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1263 | |
| 1264 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | } |
| 1266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1268 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1269 | struct hci_ev_conn_request *ev = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | int mask = hdev->link_mode; |
| 1271 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1272 | BT_DBG("%s bdaddr %s type 0x%x", hdev->name, |
| 1273 | batostr(&ev->bdaddr), ev->link_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
| 1275 | mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type); |
| 1276 | |
Johan Hedberg | f035856 | 2010-05-18 13:20:32 +0200 | [diff] [blame] | 1277 | if ((mask & HCI_LM_ACCEPT) && !hci_blacklist_lookup(hdev, &ev->bdaddr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | /* Connection accepted */ |
Marcel Holtmann | c7bdd50 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 1279 | struct inquiry_entry *ie; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | |
| 1282 | hci_dev_lock(hdev); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1283 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 1284 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 1285 | if (ie) |
Marcel Holtmann | c7bdd50 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 1286 | memcpy(ie->data.dev_class, ev->dev_class, 3); |
| 1287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
| 1289 | if (!conn) { |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 1290 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr); |
| 1291 | if (!conn) { |
Gustavo F. Padovan | 893ef97 | 2010-07-18 15:13:37 -0300 | [diff] [blame] | 1292 | BT_ERR("No memory for new connection"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | hci_dev_unlock(hdev); |
| 1294 | return; |
| 1295 | } |
| 1296 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1298 | memcpy(conn->dev_class, ev->dev_class, 3); |
| 1299 | conn->state = BT_CONNECT; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1300 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | hci_dev_unlock(hdev); |
| 1302 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1303 | if (ev->link_type == ACL_LINK || !lmp_esco_capable(hdev)) { |
| 1304 | struct hci_cp_accept_conn_req cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1306 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1308 | if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) |
| 1309 | cp.role = 0x00; /* Become master */ |
| 1310 | else |
| 1311 | cp.role = 0x01; /* Remain slave */ |
| 1312 | |
| 1313 | hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, |
| 1314 | sizeof(cp), &cp); |
| 1315 | } else { |
| 1316 | struct hci_cp_accept_sync_conn_req cp; |
| 1317 | |
| 1318 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 1319 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1320 | |
| 1321 | cp.tx_bandwidth = cpu_to_le32(0x00001f40); |
| 1322 | cp.rx_bandwidth = cpu_to_le32(0x00001f40); |
| 1323 | cp.max_latency = cpu_to_le16(0xffff); |
| 1324 | cp.content_format = cpu_to_le16(hdev->voice_setting); |
| 1325 | cp.retrans_effort = 0xff; |
| 1326 | |
| 1327 | hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, |
| 1328 | sizeof(cp), &cp); |
| 1329 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | } else { |
| 1331 | /* Connection rejected */ |
| 1332 | struct hci_cp_reject_conn_req cp; |
| 1333 | |
| 1334 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 1335 | cp.reason = 0x0f; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1336 | hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1341 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1342 | struct hci_ev_disconn_complete *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1343 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | |
| 1345 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 1346 | |
Johan Hedberg | 8962ee7 | 2011-01-20 12:40:27 +0200 | [diff] [blame] | 1347 | if (ev->status) { |
| 1348 | mgmt_disconnect_failed(hdev->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | return; |
Johan Hedberg | 8962ee7 | 2011-01-20 12:40:27 +0200 | [diff] [blame] | 1350 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | |
| 1352 | hci_dev_lock(hdev); |
| 1353 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1354 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 1355 | if (!conn) |
| 1356 | goto unlock; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 1357 | |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 1358 | conn->state = BT_CLOSED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 1360 | if (conn->type == ACL_LINK) |
| 1361 | mgmt_disconnected(hdev->id, &conn->dst); |
| 1362 | |
| 1363 | hci_proto_disconn_cfm(conn, ev->reason); |
| 1364 | hci_conn_del(conn); |
| 1365 | |
| 1366 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | hci_dev_unlock(hdev); |
| 1368 | } |
| 1369 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1370 | static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1371 | { |
| 1372 | struct hci_ev_auth_complete *ev = (void *) skb->data; |
| 1373 | struct hci_conn *conn; |
| 1374 | |
| 1375 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 1376 | |
| 1377 | hci_dev_lock(hdev); |
| 1378 | |
| 1379 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 1380 | if (conn) { |
Johan Hedberg | 765c2a9 | 2011-01-19 12:06:52 +0530 | [diff] [blame] | 1381 | if (!ev->status) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1382 | conn->link_mode |= HCI_LM_AUTH; |
Johan Hedberg | 765c2a9 | 2011-01-19 12:06:52 +0530 | [diff] [blame] | 1383 | conn->sec_level = conn->pending_sec_level; |
| 1384 | } else |
Johan Hedberg | da213f4 | 2010-06-18 11:08:56 +0300 | [diff] [blame] | 1385 | conn->sec_level = BT_SECURITY_LOW; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1386 | |
| 1387 | clear_bit(HCI_CONN_AUTH_PEND, &conn->pend); |
| 1388 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1389 | if (conn->state == BT_CONFIG) { |
| 1390 | if (!ev->status && hdev->ssp_mode > 0 && |
| 1391 | conn->ssp_mode > 0) { |
| 1392 | struct hci_cp_set_conn_encrypt cp; |
| 1393 | cp.handle = ev->handle; |
| 1394 | cp.encrypt = 0x01; |
| 1395 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, |
| 1396 | sizeof(cp), &cp); |
| 1397 | } else { |
| 1398 | conn->state = BT_CONNECTED; |
| 1399 | hci_proto_connect_cfm(conn, ev->status); |
| 1400 | hci_conn_put(conn); |
| 1401 | } |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1402 | } else { |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1403 | hci_auth_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1404 | |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1405 | hci_conn_hold(conn); |
| 1406 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
| 1407 | hci_conn_put(conn); |
| 1408 | } |
| 1409 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1410 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) { |
| 1411 | if (!ev->status) { |
| 1412 | struct hci_cp_set_conn_encrypt cp; |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1413 | cp.handle = ev->handle; |
| 1414 | cp.encrypt = 0x01; |
| 1415 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, |
| 1416 | sizeof(cp), &cp); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1417 | } else { |
| 1418 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); |
| 1419 | hci_encrypt_cfm(conn, ev->status, 0x00); |
| 1420 | } |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | hci_dev_unlock(hdev); |
| 1425 | } |
| 1426 | |
| 1427 | static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1428 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1429 | struct hci_ev_remote_name *ev = (void *) skb->data; |
| 1430 | struct hci_conn *conn; |
| 1431 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1432 | BT_DBG("%s", hdev->name); |
| 1433 | |
| 1434 | hci_conn_check_pending(hdev); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1435 | |
| 1436 | hci_dev_lock(hdev); |
| 1437 | |
| 1438 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 1439 | if (conn && hci_outgoing_auth_needed(hdev, conn)) { |
| 1440 | struct hci_cp_auth_requested cp; |
| 1441 | cp.handle = __cpu_to_le16(conn->handle); |
| 1442 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); |
| 1443 | } |
| 1444 | |
| 1445 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1449 | { |
| 1450 | struct hci_ev_encrypt_change *ev = (void *) skb->data; |
| 1451 | struct hci_conn *conn; |
| 1452 | |
| 1453 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 1454 | |
| 1455 | hci_dev_lock(hdev); |
| 1456 | |
| 1457 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 1458 | if (conn) { |
| 1459 | if (!ev->status) { |
Marcel Holtmann | ae29319 | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 1460 | if (ev->encrypt) { |
| 1461 | /* Encryption implies authentication */ |
| 1462 | conn->link_mode |= HCI_LM_AUTH; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1463 | conn->link_mode |= HCI_LM_ENCRYPT; |
Marcel Holtmann | ae29319 | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 1464 | } else |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1465 | conn->link_mode &= ~HCI_LM_ENCRYPT; |
| 1466 | } |
| 1467 | |
| 1468 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); |
| 1469 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1470 | if (conn->state == BT_CONFIG) { |
| 1471 | if (!ev->status) |
| 1472 | conn->state = BT_CONNECTED; |
| 1473 | |
| 1474 | hci_proto_connect_cfm(conn, ev->status); |
| 1475 | hci_conn_put(conn); |
| 1476 | } else |
| 1477 | hci_encrypt_cfm(conn, ev->status, ev->encrypt); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | hci_dev_unlock(hdev); |
| 1481 | } |
| 1482 | |
| 1483 | static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1484 | { |
| 1485 | struct hci_ev_change_link_key_complete *ev = (void *) skb->data; |
| 1486 | struct hci_conn *conn; |
| 1487 | |
| 1488 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 1489 | |
| 1490 | hci_dev_lock(hdev); |
| 1491 | |
| 1492 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 1493 | if (conn) { |
| 1494 | if (!ev->status) |
| 1495 | conn->link_mode |= HCI_LM_SECURE; |
| 1496 | |
| 1497 | clear_bit(HCI_CONN_AUTH_PEND, &conn->pend); |
| 1498 | |
| 1499 | hci_key_change_cfm(conn, ev->status); |
| 1500 | } |
| 1501 | |
| 1502 | hci_dev_unlock(hdev); |
| 1503 | } |
| 1504 | |
| 1505 | static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1506 | { |
| 1507 | struct hci_ev_remote_features *ev = (void *) skb->data; |
| 1508 | struct hci_conn *conn; |
| 1509 | |
| 1510 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 1511 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1512 | hci_dev_lock(hdev); |
| 1513 | |
| 1514 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 1515 | if (!conn) |
| 1516 | goto unlock; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1517 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 1518 | if (!ev->status) |
| 1519 | memcpy(conn->features, ev->features, 8); |
| 1520 | |
| 1521 | if (conn->state != BT_CONFIG) |
| 1522 | goto unlock; |
| 1523 | |
| 1524 | if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) { |
| 1525 | struct hci_cp_read_remote_ext_features cp; |
| 1526 | cp.handle = ev->handle; |
| 1527 | cp.page = 0x01; |
| 1528 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES, |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1529 | sizeof(cp), &cp); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 1530 | goto unlock; |
| 1531 | } |
| 1532 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1533 | if (!ev->status) { |
| 1534 | struct hci_cp_remote_name_req cp; |
| 1535 | memset(&cp, 0, sizeof(cp)); |
| 1536 | bacpy(&cp.bdaddr, &conn->dst); |
| 1537 | cp.pscan_rep_mode = 0x02; |
| 1538 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
| 1539 | } |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 1540 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 1541 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 1542 | conn->state = BT_CONNECTED; |
| 1543 | hci_proto_connect_cfm(conn, ev->status); |
| 1544 | hci_conn_put(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1545 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1546 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 1547 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1548 | hci_dev_unlock(hdev); |
| 1549 | } |
| 1550 | |
| 1551 | static inline void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1552 | { |
| 1553 | BT_DBG("%s", hdev->name); |
| 1554 | } |
| 1555 | |
| 1556 | static inline void hci_qos_setup_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1557 | { |
| 1558 | BT_DBG("%s", hdev->name); |
| 1559 | } |
| 1560 | |
| 1561 | static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1562 | { |
| 1563 | struct hci_ev_cmd_complete *ev = (void *) skb->data; |
| 1564 | __u16 opcode; |
| 1565 | |
| 1566 | skb_pull(skb, sizeof(*ev)); |
| 1567 | |
| 1568 | opcode = __le16_to_cpu(ev->opcode); |
| 1569 | |
| 1570 | switch (opcode) { |
| 1571 | case HCI_OP_INQUIRY_CANCEL: |
| 1572 | hci_cc_inquiry_cancel(hdev, skb); |
| 1573 | break; |
| 1574 | |
| 1575 | case HCI_OP_EXIT_PERIODIC_INQ: |
| 1576 | hci_cc_exit_periodic_inq(hdev, skb); |
| 1577 | break; |
| 1578 | |
| 1579 | case HCI_OP_REMOTE_NAME_REQ_CANCEL: |
| 1580 | hci_cc_remote_name_req_cancel(hdev, skb); |
| 1581 | break; |
| 1582 | |
| 1583 | case HCI_OP_ROLE_DISCOVERY: |
| 1584 | hci_cc_role_discovery(hdev, skb); |
| 1585 | break; |
| 1586 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 1587 | case HCI_OP_READ_LINK_POLICY: |
| 1588 | hci_cc_read_link_policy(hdev, skb); |
| 1589 | break; |
| 1590 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1591 | case HCI_OP_WRITE_LINK_POLICY: |
| 1592 | hci_cc_write_link_policy(hdev, skb); |
| 1593 | break; |
| 1594 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 1595 | case HCI_OP_READ_DEF_LINK_POLICY: |
| 1596 | hci_cc_read_def_link_policy(hdev, skb); |
| 1597 | break; |
| 1598 | |
| 1599 | case HCI_OP_WRITE_DEF_LINK_POLICY: |
| 1600 | hci_cc_write_def_link_policy(hdev, skb); |
| 1601 | break; |
| 1602 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1603 | case HCI_OP_RESET: |
| 1604 | hci_cc_reset(hdev, skb); |
| 1605 | break; |
| 1606 | |
| 1607 | case HCI_OP_WRITE_LOCAL_NAME: |
| 1608 | hci_cc_write_local_name(hdev, skb); |
| 1609 | break; |
| 1610 | |
| 1611 | case HCI_OP_READ_LOCAL_NAME: |
| 1612 | hci_cc_read_local_name(hdev, skb); |
| 1613 | break; |
| 1614 | |
| 1615 | case HCI_OP_WRITE_AUTH_ENABLE: |
| 1616 | hci_cc_write_auth_enable(hdev, skb); |
| 1617 | break; |
| 1618 | |
| 1619 | case HCI_OP_WRITE_ENCRYPT_MODE: |
| 1620 | hci_cc_write_encrypt_mode(hdev, skb); |
| 1621 | break; |
| 1622 | |
| 1623 | case HCI_OP_WRITE_SCAN_ENABLE: |
| 1624 | hci_cc_write_scan_enable(hdev, skb); |
| 1625 | break; |
| 1626 | |
| 1627 | case HCI_OP_READ_CLASS_OF_DEV: |
| 1628 | hci_cc_read_class_of_dev(hdev, skb); |
| 1629 | break; |
| 1630 | |
| 1631 | case HCI_OP_WRITE_CLASS_OF_DEV: |
| 1632 | hci_cc_write_class_of_dev(hdev, skb); |
| 1633 | break; |
| 1634 | |
| 1635 | case HCI_OP_READ_VOICE_SETTING: |
| 1636 | hci_cc_read_voice_setting(hdev, skb); |
| 1637 | break; |
| 1638 | |
| 1639 | case HCI_OP_WRITE_VOICE_SETTING: |
| 1640 | hci_cc_write_voice_setting(hdev, skb); |
| 1641 | break; |
| 1642 | |
| 1643 | case HCI_OP_HOST_BUFFER_SIZE: |
| 1644 | hci_cc_host_buffer_size(hdev, skb); |
| 1645 | break; |
| 1646 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 1647 | case HCI_OP_READ_SSP_MODE: |
| 1648 | hci_cc_read_ssp_mode(hdev, skb); |
| 1649 | break; |
| 1650 | |
| 1651 | case HCI_OP_WRITE_SSP_MODE: |
| 1652 | hci_cc_write_ssp_mode(hdev, skb); |
| 1653 | break; |
| 1654 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1655 | case HCI_OP_READ_LOCAL_VERSION: |
| 1656 | hci_cc_read_local_version(hdev, skb); |
| 1657 | break; |
| 1658 | |
| 1659 | case HCI_OP_READ_LOCAL_COMMANDS: |
| 1660 | hci_cc_read_local_commands(hdev, skb); |
| 1661 | break; |
| 1662 | |
| 1663 | case HCI_OP_READ_LOCAL_FEATURES: |
| 1664 | hci_cc_read_local_features(hdev, skb); |
| 1665 | break; |
| 1666 | |
| 1667 | case HCI_OP_READ_BUFFER_SIZE: |
| 1668 | hci_cc_read_buffer_size(hdev, skb); |
| 1669 | break; |
| 1670 | |
| 1671 | case HCI_OP_READ_BD_ADDR: |
| 1672 | hci_cc_read_bd_addr(hdev, skb); |
| 1673 | break; |
| 1674 | |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 1675 | case HCI_OP_WRITE_CA_TIMEOUT: |
| 1676 | hci_cc_write_ca_timeout(hdev, skb); |
| 1677 | break; |
| 1678 | |
Johan Hedberg | b0916ea | 2011-01-10 13:44:55 +0200 | [diff] [blame] | 1679 | case HCI_OP_DELETE_STORED_LINK_KEY: |
| 1680 | hci_cc_delete_stored_link_key(hdev, skb); |
| 1681 | break; |
| 1682 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 1683 | case HCI_OP_SET_EVENT_MASK: |
| 1684 | hci_cc_set_event_mask(hdev, skb); |
| 1685 | break; |
| 1686 | |
| 1687 | case HCI_OP_WRITE_INQUIRY_MODE: |
| 1688 | hci_cc_write_inquiry_mode(hdev, skb); |
| 1689 | break; |
| 1690 | |
| 1691 | case HCI_OP_READ_INQ_RSP_TX_POWER: |
| 1692 | hci_cc_read_inq_rsp_tx_power(hdev, skb); |
| 1693 | break; |
| 1694 | |
| 1695 | case HCI_OP_SET_EVENT_FLT: |
| 1696 | hci_cc_set_event_flt(hdev, skb); |
| 1697 | break; |
| 1698 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1699 | case HCI_OP_PIN_CODE_REPLY: |
| 1700 | hci_cc_pin_code_reply(hdev, skb); |
| 1701 | break; |
| 1702 | |
| 1703 | case HCI_OP_PIN_CODE_NEG_REPLY: |
| 1704 | hci_cc_pin_code_neg_reply(hdev, skb); |
| 1705 | break; |
| 1706 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1707 | default: |
| 1708 | BT_DBG("%s opcode 0x%x", hdev->name, opcode); |
| 1709 | break; |
| 1710 | } |
| 1711 | |
| 1712 | if (ev->ncmd) { |
| 1713 | atomic_set(&hdev->cmd_cnt, 1); |
| 1714 | if (!skb_queue_empty(&hdev->cmd_q)) |
Marcel Holtmann | c78ae28 | 2009-11-18 01:02:54 +0100 | [diff] [blame] | 1715 | tasklet_schedule(&hdev->cmd_task); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1716 | } |
| 1717 | } |
| 1718 | |
| 1719 | static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1720 | { |
| 1721 | struct hci_ev_cmd_status *ev = (void *) skb->data; |
| 1722 | __u16 opcode; |
| 1723 | |
| 1724 | skb_pull(skb, sizeof(*ev)); |
| 1725 | |
| 1726 | opcode = __le16_to_cpu(ev->opcode); |
| 1727 | |
| 1728 | switch (opcode) { |
| 1729 | case HCI_OP_INQUIRY: |
| 1730 | hci_cs_inquiry(hdev, ev->status); |
| 1731 | break; |
| 1732 | |
| 1733 | case HCI_OP_CREATE_CONN: |
| 1734 | hci_cs_create_conn(hdev, ev->status); |
| 1735 | break; |
| 1736 | |
| 1737 | case HCI_OP_ADD_SCO: |
| 1738 | hci_cs_add_sco(hdev, ev->status); |
| 1739 | break; |
| 1740 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1741 | case HCI_OP_AUTH_REQUESTED: |
| 1742 | hci_cs_auth_requested(hdev, ev->status); |
| 1743 | break; |
| 1744 | |
| 1745 | case HCI_OP_SET_CONN_ENCRYPT: |
| 1746 | hci_cs_set_conn_encrypt(hdev, ev->status); |
| 1747 | break; |
| 1748 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1749 | case HCI_OP_REMOTE_NAME_REQ: |
| 1750 | hci_cs_remote_name_req(hdev, ev->status); |
| 1751 | break; |
| 1752 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1753 | case HCI_OP_READ_REMOTE_FEATURES: |
| 1754 | hci_cs_read_remote_features(hdev, ev->status); |
| 1755 | break; |
| 1756 | |
| 1757 | case HCI_OP_READ_REMOTE_EXT_FEATURES: |
| 1758 | hci_cs_read_remote_ext_features(hdev, ev->status); |
| 1759 | break; |
| 1760 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1761 | case HCI_OP_SETUP_SYNC_CONN: |
| 1762 | hci_cs_setup_sync_conn(hdev, ev->status); |
| 1763 | break; |
| 1764 | |
| 1765 | case HCI_OP_SNIFF_MODE: |
| 1766 | hci_cs_sniff_mode(hdev, ev->status); |
| 1767 | break; |
| 1768 | |
| 1769 | case HCI_OP_EXIT_SNIFF_MODE: |
| 1770 | hci_cs_exit_sniff_mode(hdev, ev->status); |
| 1771 | break; |
| 1772 | |
Johan Hedberg | 8962ee7 | 2011-01-20 12:40:27 +0200 | [diff] [blame] | 1773 | case HCI_OP_DISCONNECT: |
| 1774 | if (ev->status != 0) |
| 1775 | mgmt_disconnect_failed(hdev->id); |
| 1776 | break; |
| 1777 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame^] | 1778 | case HCI_OP_LE_CREATE_CONN: |
| 1779 | hci_cs_le_create_conn(hdev, ev->status); |
| 1780 | break; |
| 1781 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1782 | default: |
| 1783 | BT_DBG("%s opcode 0x%x", hdev->name, opcode); |
| 1784 | break; |
| 1785 | } |
| 1786 | |
| 1787 | if (ev->ncmd) { |
| 1788 | atomic_set(&hdev->cmd_cnt, 1); |
| 1789 | if (!skb_queue_empty(&hdev->cmd_q)) |
Marcel Holtmann | c78ae28 | 2009-11-18 01:02:54 +0100 | [diff] [blame] | 1790 | tasklet_schedule(&hdev->cmd_task); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | |
| 1794 | static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1795 | { |
| 1796 | struct hci_ev_role_change *ev = (void *) skb->data; |
| 1797 | struct hci_conn *conn; |
| 1798 | |
| 1799 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 1800 | |
| 1801 | hci_dev_lock(hdev); |
| 1802 | |
| 1803 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 1804 | if (conn) { |
| 1805 | if (!ev->status) { |
| 1806 | if (ev->role) |
| 1807 | conn->link_mode &= ~HCI_LM_MASTER; |
| 1808 | else |
| 1809 | conn->link_mode |= HCI_LM_MASTER; |
| 1810 | } |
| 1811 | |
| 1812 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->pend); |
| 1813 | |
| 1814 | hci_role_switch_cfm(conn, ev->status, ev->role); |
| 1815 | } |
| 1816 | |
| 1817 | hci_dev_unlock(hdev); |
| 1818 | } |
| 1819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1821 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1822 | struct hci_ev_num_comp_pkts *ev = (void *) skb->data; |
Marcel Holtmann | 1ebb925 | 2005-11-08 09:57:21 -0800 | [diff] [blame] | 1823 | __le16 *ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | int i; |
| 1825 | |
| 1826 | skb_pull(skb, sizeof(*ev)); |
| 1827 | |
| 1828 | BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl); |
| 1829 | |
| 1830 | if (skb->len < ev->num_hndl * 4) { |
| 1831 | BT_DBG("%s bad parameters", hdev->name); |
| 1832 | return; |
| 1833 | } |
| 1834 | |
| 1835 | tasklet_disable(&hdev->tx_task); |
| 1836 | |
Marcel Holtmann | 1ebb925 | 2005-11-08 09:57:21 -0800 | [diff] [blame] | 1837 | for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | struct hci_conn *conn; |
| 1839 | __u16 handle, count; |
| 1840 | |
Harvey Harrison | 8398531 | 2008-05-02 16:25:46 -0700 | [diff] [blame] | 1841 | handle = get_unaligned_le16(ptr++); |
| 1842 | count = get_unaligned_le16(ptr++); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | |
| 1844 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
| 1845 | if (conn) { |
| 1846 | conn->sent -= count; |
| 1847 | |
Marcel Holtmann | 5b7f9909 | 2007-07-11 09:51:55 +0200 | [diff] [blame] | 1848 | if (conn->type == ACL_LINK) { |
Andrei Emeltchenko | 70f23020 | 2010-12-01 16:58:25 +0200 | [diff] [blame] | 1849 | hdev->acl_cnt += count; |
| 1850 | if (hdev->acl_cnt > hdev->acl_pkts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | hdev->acl_cnt = hdev->acl_pkts; |
Marcel Holtmann | 5b7f9909 | 2007-07-11 09:51:55 +0200 | [diff] [blame] | 1852 | } else { |
Andrei Emeltchenko | 70f23020 | 2010-12-01 16:58:25 +0200 | [diff] [blame] | 1853 | hdev->sco_cnt += count; |
| 1854 | if (hdev->sco_cnt > hdev->sco_pkts) |
Marcel Holtmann | 5b7f9909 | 2007-07-11 09:51:55 +0200 | [diff] [blame] | 1855 | hdev->sco_cnt = hdev->sco_pkts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1856 | } |
| 1857 | } |
| 1858 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1859 | |
Marcel Holtmann | c78ae28 | 2009-11-18 01:02:54 +0100 | [diff] [blame] | 1860 | tasklet_schedule(&hdev->tx_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
| 1862 | tasklet_enable(&hdev->tx_task); |
| 1863 | } |
| 1864 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1865 | 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] | 1866 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1867 | struct hci_ev_mode_change *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1868 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | |
| 1870 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 1871 | |
| 1872 | hci_dev_lock(hdev); |
| 1873 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1874 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 1875 | if (conn) { |
| 1876 | conn->mode = ev->mode; |
| 1877 | conn->interval = __le16_to_cpu(ev->interval); |
| 1878 | |
| 1879 | if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) { |
| 1880 | if (conn->mode == HCI_CM_ACTIVE) |
| 1881 | conn->power_save = 1; |
| 1882 | else |
| 1883 | conn->power_save = 0; |
| 1884 | } |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 1885 | |
| 1886 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend)) |
| 1887 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | hci_dev_unlock(hdev); |
| 1891 | } |
| 1892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1894 | { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1895 | struct hci_ev_pin_code_req *ev = (void *) skb->data; |
| 1896 | struct hci_conn *conn; |
| 1897 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1898 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1899 | |
| 1900 | hci_dev_lock(hdev); |
| 1901 | |
| 1902 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Marcel Holtmann | 3d7a9d1 | 2009-05-09 12:09:21 -0700 | [diff] [blame] | 1903 | if (conn && conn->state == BT_CONNECTED) { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1904 | hci_conn_hold(conn); |
| 1905 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
| 1906 | hci_conn_put(conn); |
| 1907 | } |
| 1908 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 1909 | if (!test_bit(HCI_PAIRABLE, &hdev->flags)) |
| 1910 | hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, |
| 1911 | sizeof(ev->bdaddr), &ev->bdaddr); |
| 1912 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1913 | if (test_bit(HCI_MGMT, &hdev->flags)) |
| 1914 | mgmt_pin_code_request(hdev->id, &ev->bdaddr); |
| 1915 | |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1916 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } |
| 1918 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1920 | { |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 1921 | struct hci_ev_link_key_req *ev = (void *) skb->data; |
| 1922 | struct hci_cp_link_key_reply cp; |
| 1923 | struct hci_conn *conn; |
| 1924 | struct link_key *key; |
| 1925 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1926 | BT_DBG("%s", hdev->name); |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 1927 | |
| 1928 | if (!test_bit(HCI_LINK_KEYS, &hdev->flags)) |
| 1929 | return; |
| 1930 | |
| 1931 | hci_dev_lock(hdev); |
| 1932 | |
| 1933 | key = hci_find_link_key(hdev, &ev->bdaddr); |
| 1934 | if (!key) { |
| 1935 | BT_DBG("%s link key not found for %s", hdev->name, |
| 1936 | batostr(&ev->bdaddr)); |
| 1937 | goto not_found; |
| 1938 | } |
| 1939 | |
| 1940 | BT_DBG("%s found key type %u for %s", hdev->name, key->type, |
| 1941 | batostr(&ev->bdaddr)); |
| 1942 | |
| 1943 | if (!test_bit(HCI_DEBUG_KEYS, &hdev->flags) && key->type == 0x03) { |
| 1944 | BT_DBG("%s ignoring debug key", hdev->name); |
| 1945 | goto not_found; |
| 1946 | } |
| 1947 | |
| 1948 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 1949 | |
| 1950 | if (key->type == 0x04 && conn && conn->auth_type != 0xff && |
| 1951 | (conn->auth_type & 0x01)) { |
| 1952 | BT_DBG("%s ignoring unauthenticated key", hdev->name); |
| 1953 | goto not_found; |
| 1954 | } |
| 1955 | |
| 1956 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 1957 | memcpy(cp.link_key, key->val, 16); |
| 1958 | |
| 1959 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp); |
| 1960 | |
| 1961 | hci_dev_unlock(hdev); |
| 1962 | |
| 1963 | return; |
| 1964 | |
| 1965 | not_found: |
| 1966 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr); |
| 1967 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1971 | { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1972 | struct hci_ev_link_key_notify *ev = (void *) skb->data; |
| 1973 | struct hci_conn *conn; |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 1974 | u8 pin_len = 0; |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1975 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1976 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1977 | |
| 1978 | hci_dev_lock(hdev); |
| 1979 | |
| 1980 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 1981 | if (conn) { |
| 1982 | hci_conn_hold(conn); |
| 1983 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1984 | pin_len = conn->pin_length; |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1985 | hci_conn_put(conn); |
| 1986 | } |
| 1987 | |
Johan Hedberg | 55ed8ca | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 1988 | if (test_bit(HCI_LINK_KEYS, &hdev->flags)) |
| 1989 | hci_add_link_key(hdev, 1, &ev->bdaddr, ev->link_key, |
| 1990 | ev->key_type, pin_len); |
| 1991 | |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 1992 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1995 | static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 1996 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1997 | struct hci_ev_clock_offset *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 1998 | struct hci_conn *conn; |
| 1999 | |
| 2000 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 2001 | |
| 2002 | hci_dev_lock(hdev); |
| 2003 | |
| 2004 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | if (conn && !ev->status) { |
| 2006 | struct inquiry_entry *ie; |
| 2007 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 2008 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 2009 | if (ie) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | ie->data.clock_offset = ev->clock_offset; |
| 2011 | ie->timestamp = jiffies; |
| 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | hci_dev_unlock(hdev); |
| 2016 | } |
| 2017 | |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 2018 | static inline void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2019 | { |
| 2020 | struct hci_ev_pkt_type_change *ev = (void *) skb->data; |
| 2021 | struct hci_conn *conn; |
| 2022 | |
| 2023 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 2024 | |
| 2025 | hci_dev_lock(hdev); |
| 2026 | |
| 2027 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 2028 | if (conn && !ev->status) |
| 2029 | conn->pkt_type = __le16_to_cpu(ev->pkt_type); |
| 2030 | |
| 2031 | hci_dev_unlock(hdev); |
| 2032 | } |
| 2033 | |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 2034 | static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2035 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2036 | struct hci_ev_pscan_rep_mode *ev = (void *) skb->data; |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 2037 | struct inquiry_entry *ie; |
| 2038 | |
| 2039 | BT_DBG("%s", hdev->name); |
| 2040 | |
| 2041 | hci_dev_lock(hdev); |
| 2042 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 2043 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 2044 | if (ie) { |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 2045 | ie->data.pscan_rep_mode = ev->pscan_rep_mode; |
| 2046 | ie->timestamp = jiffies; |
| 2047 | } |
| 2048 | |
| 2049 | hci_dev_unlock(hdev); |
| 2050 | } |
| 2051 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2052 | static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2053 | { |
| 2054 | struct inquiry_data data; |
| 2055 | int num_rsp = *((__u8 *) skb->data); |
| 2056 | |
| 2057 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 2058 | |
| 2059 | if (!num_rsp) |
| 2060 | return; |
| 2061 | |
| 2062 | hci_dev_lock(hdev); |
| 2063 | |
| 2064 | if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { |
| 2065 | struct inquiry_info_with_rssi_and_pscan_mode *info = (void *) (skb->data + 1); |
| 2066 | |
| 2067 | for (; num_rsp; num_rsp--) { |
| 2068 | bacpy(&data.bdaddr, &info->bdaddr); |
| 2069 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 2070 | data.pscan_period_mode = info->pscan_period_mode; |
| 2071 | data.pscan_mode = info->pscan_mode; |
| 2072 | memcpy(data.dev_class, info->dev_class, 3); |
| 2073 | data.clock_offset = info->clock_offset; |
| 2074 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2075 | data.ssp_mode = 0x00; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2076 | info++; |
| 2077 | hci_inquiry_cache_update(hdev, &data); |
| 2078 | } |
| 2079 | } else { |
| 2080 | struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); |
| 2081 | |
| 2082 | for (; num_rsp; num_rsp--) { |
| 2083 | bacpy(&data.bdaddr, &info->bdaddr); |
| 2084 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 2085 | data.pscan_period_mode = info->pscan_period_mode; |
| 2086 | data.pscan_mode = 0x00; |
| 2087 | memcpy(data.dev_class, info->dev_class, 3); |
| 2088 | data.clock_offset = info->clock_offset; |
| 2089 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2090 | data.ssp_mode = 0x00; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2091 | info++; |
| 2092 | hci_inquiry_cache_update(hdev, &data); |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | hci_dev_unlock(hdev); |
| 2097 | } |
| 2098 | |
| 2099 | static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2100 | { |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2101 | struct hci_ev_remote_ext_features *ev = (void *) skb->data; |
| 2102 | struct hci_conn *conn; |
| 2103 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2104 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2105 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2106 | hci_dev_lock(hdev); |
| 2107 | |
| 2108 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2109 | if (!conn) |
| 2110 | goto unlock; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2111 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2112 | if (!ev->status && ev->page == 0x01) { |
| 2113 | struct inquiry_entry *ie; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2114 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 2115 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 2116 | if (ie) |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2117 | ie->data.ssp_mode = (ev->features[0] & 0x01); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2118 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2119 | conn->ssp_mode = (ev->features[0] & 0x01); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2120 | } |
| 2121 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2122 | if (conn->state != BT_CONFIG) |
| 2123 | goto unlock; |
| 2124 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2125 | if (!ev->status) { |
| 2126 | struct hci_cp_remote_name_req cp; |
| 2127 | memset(&cp, 0, sizeof(cp)); |
| 2128 | bacpy(&cp.bdaddr, &conn->dst); |
| 2129 | cp.pscan_rep_mode = 0x02; |
| 2130 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
| 2131 | } |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2132 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2133 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 2134 | conn->state = BT_CONNECTED; |
| 2135 | hci_proto_connect_cfm(conn, ev->status); |
| 2136 | hci_conn_put(conn); |
| 2137 | } |
| 2138 | |
| 2139 | unlock: |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2140 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2141 | } |
| 2142 | |
| 2143 | static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2144 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2145 | struct hci_ev_sync_conn_complete *ev = (void *) skb->data; |
| 2146 | struct hci_conn *conn; |
| 2147 | |
| 2148 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 2149 | |
| 2150 | hci_dev_lock(hdev); |
| 2151 | |
| 2152 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 2153 | if (!conn) { |
| 2154 | if (ev->link_type == ESCO_LINK) |
| 2155 | goto unlock; |
| 2156 | |
| 2157 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); |
| 2158 | if (!conn) |
| 2159 | goto unlock; |
| 2160 | |
| 2161 | conn->type = SCO_LINK; |
| 2162 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2163 | |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2164 | switch (ev->status) { |
| 2165 | case 0x00: |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2166 | conn->handle = __le16_to_cpu(ev->handle); |
| 2167 | conn->state = BT_CONNECTED; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 2168 | |
Marcel Holtmann | 9eba32b | 2009-08-22 14:19:26 -0700 | [diff] [blame] | 2169 | hci_conn_hold_device(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 2170 | hci_conn_add_sysfs(conn); |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2171 | break; |
| 2172 | |
Stephen Coe | 705e571 | 2010-02-16 11:29:44 -0500 | [diff] [blame] | 2173 | case 0x11: /* Unsupported Feature or Parameter Value */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2174 | case 0x1c: /* SCO interval rejected */ |
Nick Pelly | 1038a00 | 2010-02-03 11:42:26 -0800 | [diff] [blame] | 2175 | case 0x1a: /* Unsupported Remote Feature */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2176 | case 0x1f: /* Unspecified error */ |
| 2177 | if (conn->out && conn->attempt < 2) { |
| 2178 | conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | |
| 2179 | (hdev->esco_type & EDR_ESCO_MASK); |
| 2180 | hci_setup_sync(conn, conn->link->handle); |
| 2181 | goto unlock; |
| 2182 | } |
| 2183 | /* fall through */ |
| 2184 | |
| 2185 | default: |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2186 | conn->state = BT_CLOSED; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 2187 | break; |
| 2188 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2189 | |
| 2190 | hci_proto_connect_cfm(conn, ev->status); |
| 2191 | if (ev->status) |
| 2192 | hci_conn_del(conn); |
| 2193 | |
| 2194 | unlock: |
| 2195 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2199 | { |
| 2200 | BT_DBG("%s", hdev->name); |
| 2201 | } |
| 2202 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2203 | static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2204 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2205 | struct hci_ev_sniff_subrate *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2206 | struct hci_conn *conn; |
| 2207 | |
| 2208 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 2209 | |
| 2210 | hci_dev_lock(hdev); |
| 2211 | |
| 2212 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 2213 | if (conn) { |
| 2214 | } |
| 2215 | |
| 2216 | hci_dev_unlock(hdev); |
| 2217 | } |
| 2218 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2219 | static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2220 | { |
| 2221 | struct inquiry_data data; |
| 2222 | struct extended_inquiry_info *info = (void *) (skb->data + 1); |
| 2223 | int num_rsp = *((__u8 *) skb->data); |
| 2224 | |
| 2225 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 2226 | |
| 2227 | if (!num_rsp) |
| 2228 | return; |
| 2229 | |
| 2230 | hci_dev_lock(hdev); |
| 2231 | |
| 2232 | for (; num_rsp; num_rsp--) { |
| 2233 | bacpy(&data.bdaddr, &info->bdaddr); |
| 2234 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 2235 | data.pscan_period_mode = info->pscan_period_mode; |
| 2236 | data.pscan_mode = 0x00; |
| 2237 | memcpy(data.dev_class, info->dev_class, 3); |
| 2238 | data.clock_offset = info->clock_offset; |
| 2239 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2240 | data.ssp_mode = 0x01; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2241 | info++; |
| 2242 | hci_inquiry_cache_update(hdev, &data); |
| 2243 | } |
| 2244 | |
| 2245 | hci_dev_unlock(hdev); |
| 2246 | } |
| 2247 | |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 2248 | static inline u8 hci_get_auth_req(struct hci_conn *conn) |
| 2249 | { |
| 2250 | /* If remote requests dedicated bonding follow that lead */ |
| 2251 | if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) { |
| 2252 | /* If both remote and local IO capabilities allow MITM |
| 2253 | * protection then require it, otherwise don't */ |
| 2254 | if (conn->remote_cap == 0x03 || conn->io_capability == 0x03) |
| 2255 | return 0x02; |
| 2256 | else |
| 2257 | return 0x03; |
| 2258 | } |
| 2259 | |
| 2260 | /* If remote requests no-bonding follow that lead */ |
| 2261 | if (conn->remote_auth == 0x00 || conn->remote_auth == 0x01) |
| 2262 | return 0x00; |
| 2263 | |
| 2264 | return conn->auth_type; |
| 2265 | } |
| 2266 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2267 | static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2268 | { |
| 2269 | struct hci_ev_io_capa_request *ev = (void *) skb->data; |
| 2270 | struct hci_conn *conn; |
| 2271 | |
| 2272 | BT_DBG("%s", hdev->name); |
| 2273 | |
| 2274 | hci_dev_lock(hdev); |
| 2275 | |
| 2276 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 2277 | if (!conn) |
| 2278 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2279 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 2280 | hci_conn_hold(conn); |
| 2281 | |
| 2282 | if (!test_bit(HCI_MGMT, &hdev->flags)) |
| 2283 | goto unlock; |
| 2284 | |
| 2285 | if (test_bit(HCI_PAIRABLE, &hdev->flags) || |
| 2286 | (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 2287 | struct hci_cp_io_capability_reply cp; |
| 2288 | |
| 2289 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 2290 | cp.capability = conn->io_capability; |
| 2291 | cp.oob_data = 0; |
| 2292 | cp.authentication = hci_get_auth_req(conn); |
| 2293 | |
| 2294 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY, |
| 2295 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 2296 | } else { |
| 2297 | struct hci_cp_io_capability_neg_reply cp; |
| 2298 | |
| 2299 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 2300 | cp.reason = 0x16; /* Pairing not allowed */ |
| 2301 | |
| 2302 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY, |
| 2303 | sizeof(cp), &cp); |
| 2304 | } |
| 2305 | |
| 2306 | unlock: |
| 2307 | hci_dev_unlock(hdev); |
| 2308 | } |
| 2309 | |
| 2310 | static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2311 | { |
| 2312 | struct hci_ev_io_capa_reply *ev = (void *) skb->data; |
| 2313 | struct hci_conn *conn; |
| 2314 | |
| 2315 | BT_DBG("%s", hdev->name); |
| 2316 | |
| 2317 | hci_dev_lock(hdev); |
| 2318 | |
| 2319 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 2320 | if (!conn) |
| 2321 | goto unlock; |
| 2322 | |
| 2323 | hci_conn_hold(conn); |
| 2324 | |
| 2325 | conn->remote_cap = ev->capability; |
| 2326 | conn->remote_oob = ev->oob_data; |
| 2327 | conn->remote_auth = ev->authentication; |
| 2328 | |
| 2329 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2330 | hci_dev_unlock(hdev); |
| 2331 | } |
| 2332 | |
| 2333 | static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2334 | { |
| 2335 | struct hci_ev_simple_pair_complete *ev = (void *) skb->data; |
| 2336 | struct hci_conn *conn; |
| 2337 | |
| 2338 | BT_DBG("%s", hdev->name); |
| 2339 | |
| 2340 | hci_dev_lock(hdev); |
| 2341 | |
| 2342 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 2343 | if (conn) |
| 2344 | hci_conn_put(conn); |
| 2345 | |
| 2346 | hci_dev_unlock(hdev); |
| 2347 | } |
| 2348 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2349 | static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2350 | { |
| 2351 | struct hci_ev_remote_host_features *ev = (void *) skb->data; |
| 2352 | struct inquiry_entry *ie; |
| 2353 | |
| 2354 | BT_DBG("%s", hdev->name); |
| 2355 | |
| 2356 | hci_dev_lock(hdev); |
| 2357 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 2358 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 2359 | if (ie) |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2360 | ie->data.ssp_mode = (ev->features[0] & 0x01); |
| 2361 | |
| 2362 | hci_dev_unlock(hdev); |
| 2363 | } |
| 2364 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame^] | 2365 | static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2366 | { |
| 2367 | struct hci_ev_le_conn_complete *ev = (void *) skb->data; |
| 2368 | struct hci_conn *conn; |
| 2369 | |
| 2370 | BT_DBG("%s status %d", hdev->name, ev->status); |
| 2371 | |
| 2372 | hci_dev_lock(hdev); |
| 2373 | |
| 2374 | conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr); |
| 2375 | if (!conn) |
| 2376 | goto unlock; |
| 2377 | |
| 2378 | if (ev->status) { |
| 2379 | hci_proto_connect_cfm(conn, ev->status); |
| 2380 | conn->state = BT_CLOSED; |
| 2381 | hci_conn_del(conn); |
| 2382 | goto unlock; |
| 2383 | } |
| 2384 | |
| 2385 | conn->handle = __le16_to_cpu(ev->handle); |
| 2386 | conn->state = BT_CONNECTED; |
| 2387 | |
| 2388 | hci_conn_hold_device(conn); |
| 2389 | hci_conn_add_sysfs(conn); |
| 2390 | |
| 2391 | hci_proto_connect_cfm(conn, ev->status); |
| 2392 | |
| 2393 | unlock: |
| 2394 | hci_dev_unlock(hdev); |
| 2395 | } |
| 2396 | |
| 2397 | static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 2398 | { |
| 2399 | struct hci_ev_le_meta *le_ev = (void *) skb->data; |
| 2400 | |
| 2401 | skb_pull(skb, sizeof(*le_ev)); |
| 2402 | |
| 2403 | switch (le_ev->subevent) { |
| 2404 | case HCI_EV_LE_CONN_COMPLETE: |
| 2405 | hci_le_conn_complete_evt(hdev, skb); |
| 2406 | break; |
| 2407 | |
| 2408 | default: |
| 2409 | break; |
| 2410 | } |
| 2411 | } |
| 2412 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) |
| 2414 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2415 | struct hci_event_hdr *hdr = (void *) skb->data; |
| 2416 | __u8 event = hdr->evt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | |
| 2418 | skb_pull(skb, HCI_EVENT_HDR_SIZE); |
| 2419 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2420 | switch (event) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | case HCI_EV_INQUIRY_COMPLETE: |
| 2422 | hci_inquiry_complete_evt(hdev, skb); |
| 2423 | break; |
| 2424 | |
| 2425 | case HCI_EV_INQUIRY_RESULT: |
| 2426 | hci_inquiry_result_evt(hdev, skb); |
| 2427 | break; |
| 2428 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2429 | case HCI_EV_CONN_COMPLETE: |
| 2430 | hci_conn_complete_evt(hdev, skb); |
Marcel Holtmann | 21d9e30 | 2005-09-13 01:32:25 +0200 | [diff] [blame] | 2431 | break; |
| 2432 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | case HCI_EV_CONN_REQUEST: |
| 2434 | hci_conn_request_evt(hdev, skb); |
| 2435 | break; |
| 2436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | case HCI_EV_DISCONN_COMPLETE: |
| 2438 | hci_disconn_complete_evt(hdev, skb); |
| 2439 | break; |
| 2440 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | case HCI_EV_AUTH_COMPLETE: |
| 2442 | hci_auth_complete_evt(hdev, skb); |
| 2443 | break; |
| 2444 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2445 | case HCI_EV_REMOTE_NAME: |
| 2446 | hci_remote_name_evt(hdev, skb); |
| 2447 | break; |
| 2448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2449 | case HCI_EV_ENCRYPT_CHANGE: |
| 2450 | hci_encrypt_change_evt(hdev, skb); |
| 2451 | break; |
| 2452 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2453 | case HCI_EV_CHANGE_LINK_KEY_COMPLETE: |
| 2454 | hci_change_link_key_complete_evt(hdev, skb); |
| 2455 | break; |
| 2456 | |
| 2457 | case HCI_EV_REMOTE_FEATURES: |
| 2458 | hci_remote_features_evt(hdev, skb); |
| 2459 | break; |
| 2460 | |
| 2461 | case HCI_EV_REMOTE_VERSION: |
| 2462 | hci_remote_version_evt(hdev, skb); |
| 2463 | break; |
| 2464 | |
| 2465 | case HCI_EV_QOS_SETUP_COMPLETE: |
| 2466 | hci_qos_setup_complete_evt(hdev, skb); |
| 2467 | break; |
| 2468 | |
| 2469 | case HCI_EV_CMD_COMPLETE: |
| 2470 | hci_cmd_complete_evt(hdev, skb); |
| 2471 | break; |
| 2472 | |
| 2473 | case HCI_EV_CMD_STATUS: |
| 2474 | hci_cmd_status_evt(hdev, skb); |
| 2475 | break; |
| 2476 | |
| 2477 | case HCI_EV_ROLE_CHANGE: |
| 2478 | hci_role_change_evt(hdev, skb); |
| 2479 | break; |
| 2480 | |
| 2481 | case HCI_EV_NUM_COMP_PKTS: |
| 2482 | hci_num_comp_pkts_evt(hdev, skb); |
| 2483 | break; |
| 2484 | |
| 2485 | case HCI_EV_MODE_CHANGE: |
| 2486 | hci_mode_change_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | break; |
| 2488 | |
| 2489 | case HCI_EV_PIN_CODE_REQ: |
| 2490 | hci_pin_code_request_evt(hdev, skb); |
| 2491 | break; |
| 2492 | |
| 2493 | case HCI_EV_LINK_KEY_REQ: |
| 2494 | hci_link_key_request_evt(hdev, skb); |
| 2495 | break; |
| 2496 | |
| 2497 | case HCI_EV_LINK_KEY_NOTIFY: |
| 2498 | hci_link_key_notify_evt(hdev, skb); |
| 2499 | break; |
| 2500 | |
| 2501 | case HCI_EV_CLOCK_OFFSET: |
| 2502 | hci_clock_offset_evt(hdev, skb); |
| 2503 | break; |
| 2504 | |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 2505 | case HCI_EV_PKT_TYPE_CHANGE: |
| 2506 | hci_pkt_type_change_evt(hdev, skb); |
| 2507 | break; |
| 2508 | |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 2509 | case HCI_EV_PSCAN_REP_MODE: |
| 2510 | hci_pscan_rep_mode_evt(hdev, skb); |
| 2511 | break; |
| 2512 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2513 | case HCI_EV_INQUIRY_RESULT_WITH_RSSI: |
| 2514 | hci_inquiry_result_with_rssi_evt(hdev, skb); |
| 2515 | break; |
| 2516 | |
| 2517 | case HCI_EV_REMOTE_EXT_FEATURES: |
| 2518 | hci_remote_ext_features_evt(hdev, skb); |
| 2519 | break; |
| 2520 | |
| 2521 | case HCI_EV_SYNC_CONN_COMPLETE: |
| 2522 | hci_sync_conn_complete_evt(hdev, skb); |
| 2523 | break; |
| 2524 | |
| 2525 | case HCI_EV_SYNC_CONN_CHANGED: |
| 2526 | hci_sync_conn_changed_evt(hdev, skb); |
| 2527 | break; |
| 2528 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2529 | case HCI_EV_SNIFF_SUBRATE: |
| 2530 | hci_sniff_subrate_evt(hdev, skb); |
| 2531 | break; |
| 2532 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2533 | case HCI_EV_EXTENDED_INQUIRY_RESULT: |
| 2534 | hci_extended_inquiry_result_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | break; |
| 2536 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2537 | case HCI_EV_IO_CAPA_REQUEST: |
| 2538 | hci_io_capa_request_evt(hdev, skb); |
| 2539 | break; |
| 2540 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 2541 | case HCI_EV_IO_CAPA_REPLY: |
| 2542 | hci_io_capa_reply_evt(hdev, skb); |
| 2543 | break; |
| 2544 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2545 | case HCI_EV_SIMPLE_PAIR_COMPLETE: |
| 2546 | hci_simple_pair_complete_evt(hdev, skb); |
| 2547 | break; |
| 2548 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2549 | case HCI_EV_REMOTE_HOST_FEATURES: |
| 2550 | hci_remote_host_features_evt(hdev, skb); |
| 2551 | break; |
| 2552 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame^] | 2553 | case HCI_EV_LE_META: |
| 2554 | hci_le_meta_evt(hdev, skb); |
| 2555 | break; |
| 2556 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2557 | default: |
| 2558 | BT_DBG("%s event 0x%x", hdev->name, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | break; |
| 2560 | } |
| 2561 | |
| 2562 | kfree_skb(skb); |
| 2563 | hdev->stat.evt_rx++; |
| 2564 | } |
| 2565 | |
| 2566 | /* Generate internal stack event */ |
| 2567 | void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data) |
| 2568 | { |
| 2569 | struct hci_event_hdr *hdr; |
| 2570 | struct hci_ev_stack_internal *ev; |
| 2571 | struct sk_buff *skb; |
| 2572 | |
| 2573 | skb = bt_skb_alloc(HCI_EVENT_HDR_SIZE + sizeof(*ev) + dlen, GFP_ATOMIC); |
| 2574 | if (!skb) |
| 2575 | return; |
| 2576 | |
| 2577 | hdr = (void *) skb_put(skb, HCI_EVENT_HDR_SIZE); |
| 2578 | hdr->evt = HCI_EV_STACK_INTERNAL; |
| 2579 | hdr->plen = sizeof(*ev) + dlen; |
| 2580 | |
| 2581 | ev = (void *) skb_put(skb, sizeof(*ev) + dlen); |
| 2582 | ev->type = type; |
| 2583 | memcpy(ev->data, data, dlen); |
| 2584 | |
Marcel Holtmann | 576c7d8 | 2005-08-06 12:36:54 +0200 | [diff] [blame] | 2585 | bt_cb(skb)->incoming = 1; |
Patrick McHardy | a61bbcf | 2005-08-14 17:24:31 -0700 | [diff] [blame] | 2586 | __net_timestamp(skb); |
Marcel Holtmann | 576c7d8 | 2005-08-06 12:36:54 +0200 | [diff] [blame] | 2587 | |
Marcel Holtmann | 0d48d93 | 2005-08-09 20:30:28 -0700 | [diff] [blame] | 2588 | bt_cb(skb)->pkt_type = HCI_EVENT_PKT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2589 | skb->dev = (void *) hdev; |
Johan Hedberg | eec8d2b | 2010-12-16 10:17:38 +0200 | [diff] [blame] | 2590 | hci_send_to_sock(hdev, skb, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | kfree_skb(skb); |
| 2592 | } |