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