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