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