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