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