2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
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;
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
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
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22 SOFTWARE IS DISCLAIMED.
25 /* Bluetooth HCI event handling. */
27 #include <linux/module.h>
29 #include <linux/types.h>
30 #include <linux/errno.h>
31 #include <linux/kernel.h>
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>
41 #include <asm/system.h>
42 #include <linux/uaccess.h>
43 #include <asm/unaligned.h>
45 #include <net/bluetooth/bluetooth.h>
46 #include <net/bluetooth/hci_core.h>
48 /* Handle HCI Event packets */
50 static void hci_cc_inquiry_cancel(struct hci_dev
*hdev
, struct sk_buff
*skb
)
52 __u8 status
= *((__u8
*) skb
->data
);
54 BT_DBG("%s status 0x%x", hdev
->name
, status
);
59 clear_bit(HCI_INQUIRY
, &hdev
->flags
);
61 hci_req_complete(hdev
, HCI_OP_INQUIRY_CANCEL
, status
);
63 hci_conn_check_pending(hdev
);
66 static void hci_cc_exit_periodic_inq(struct hci_dev
*hdev
, struct sk_buff
*skb
)
68 __u8 status
= *((__u8
*) skb
->data
);
70 BT_DBG("%s status 0x%x", hdev
->name
, status
);
75 clear_bit(HCI_INQUIRY
, &hdev
->flags
);
77 hci_conn_check_pending(hdev
);
80 static void hci_cc_remote_name_req_cancel(struct hci_dev
*hdev
, struct sk_buff
*skb
)
82 BT_DBG("%s", hdev
->name
);
85 static void hci_cc_role_discovery(struct hci_dev
*hdev
, struct sk_buff
*skb
)
87 struct hci_rp_role_discovery
*rp
= (void *) skb
->data
;
88 struct hci_conn
*conn
;
90 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
97 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(rp
->handle
));
100 conn
->link_mode
&= ~HCI_LM_MASTER
;
102 conn
->link_mode
|= HCI_LM_MASTER
;
105 hci_dev_unlock(hdev
);
108 static void hci_cc_read_link_policy(struct hci_dev
*hdev
, struct sk_buff
*skb
)
110 struct hci_rp_read_link_policy
*rp
= (void *) skb
->data
;
111 struct hci_conn
*conn
;
113 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
120 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(rp
->handle
));
122 conn
->link_policy
= __le16_to_cpu(rp
->policy
);
124 hci_dev_unlock(hdev
);
127 static void hci_cc_write_link_policy(struct hci_dev
*hdev
, struct sk_buff
*skb
)
129 struct hci_rp_write_link_policy
*rp
= (void *) skb
->data
;
130 struct hci_conn
*conn
;
133 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
138 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_LINK_POLICY
);
144 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(rp
->handle
));
146 conn
->link_policy
= get_unaligned_le16(sent
+ 2);
148 hci_dev_unlock(hdev
);
151 static void hci_cc_read_def_link_policy(struct hci_dev
*hdev
, struct sk_buff
*skb
)
153 struct hci_rp_read_def_link_policy
*rp
= (void *) skb
->data
;
155 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
160 hdev
->link_policy
= __le16_to_cpu(rp
->policy
);
163 static void hci_cc_write_def_link_policy(struct hci_dev
*hdev
, struct sk_buff
*skb
)
165 __u8 status
= *((__u8
*) skb
->data
);
168 BT_DBG("%s status 0x%x", hdev
->name
, status
);
170 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_DEF_LINK_POLICY
);
175 hdev
->link_policy
= get_unaligned_le16(sent
);
177 hci_req_complete(hdev
, HCI_OP_WRITE_DEF_LINK_POLICY
, status
);
180 static void hci_cc_reset(struct hci_dev
*hdev
, struct sk_buff
*skb
)
182 __u8 status
= *((__u8
*) skb
->data
);
184 BT_DBG("%s status 0x%x", hdev
->name
, status
);
186 clear_bit(HCI_RESET
, &hdev
->flags
);
188 hci_req_complete(hdev
, HCI_OP_RESET
, status
);
191 static void hci_cc_write_local_name(struct hci_dev
*hdev
, struct sk_buff
*skb
)
193 __u8 status
= *((__u8
*) skb
->data
);
196 BT_DBG("%s status 0x%x", hdev
->name
, status
);
198 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_LOCAL_NAME
);
202 if (test_bit(HCI_MGMT
, &hdev
->flags
))
203 mgmt_set_local_name_complete(hdev
->id
, sent
, status
);
208 memcpy(hdev
->dev_name
, sent
, HCI_MAX_NAME_LENGTH
);
211 static void hci_cc_read_local_name(struct hci_dev
*hdev
, struct sk_buff
*skb
)
213 struct hci_rp_read_local_name
*rp
= (void *) skb
->data
;
215 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
220 memcpy(hdev
->dev_name
, rp
->name
, HCI_MAX_NAME_LENGTH
);
223 static void hci_cc_write_auth_enable(struct hci_dev
*hdev
, struct sk_buff
*skb
)
225 __u8 status
= *((__u8
*) skb
->data
);
228 BT_DBG("%s status 0x%x", hdev
->name
, status
);
230 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_AUTH_ENABLE
);
235 __u8 param
= *((__u8
*) sent
);
237 if (param
== AUTH_ENABLED
)
238 set_bit(HCI_AUTH
, &hdev
->flags
);
240 clear_bit(HCI_AUTH
, &hdev
->flags
);
243 hci_req_complete(hdev
, HCI_OP_WRITE_AUTH_ENABLE
, status
);
246 static void hci_cc_write_encrypt_mode(struct hci_dev
*hdev
, struct sk_buff
*skb
)
248 __u8 status
= *((__u8
*) skb
->data
);
251 BT_DBG("%s status 0x%x", hdev
->name
, status
);
253 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_ENCRYPT_MODE
);
258 __u8 param
= *((__u8
*) sent
);
261 set_bit(HCI_ENCRYPT
, &hdev
->flags
);
263 clear_bit(HCI_ENCRYPT
, &hdev
->flags
);
266 hci_req_complete(hdev
, HCI_OP_WRITE_ENCRYPT_MODE
, status
);
269 static void hci_cc_write_scan_enable(struct hci_dev
*hdev
, struct sk_buff
*skb
)
271 __u8 status
= *((__u8
*) skb
->data
);
274 BT_DBG("%s status 0x%x", hdev
->name
, status
);
276 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_SCAN_ENABLE
);
281 __u8 param
= *((__u8
*) sent
);
282 int old_pscan
, old_iscan
;
284 old_pscan
= test_and_clear_bit(HCI_PSCAN
, &hdev
->flags
);
285 old_iscan
= test_and_clear_bit(HCI_ISCAN
, &hdev
->flags
);
287 if (param
& SCAN_INQUIRY
) {
288 set_bit(HCI_ISCAN
, &hdev
->flags
);
290 mgmt_discoverable(hdev
->id
, 1);
291 } else if (old_iscan
)
292 mgmt_discoverable(hdev
->id
, 0);
294 if (param
& SCAN_PAGE
) {
295 set_bit(HCI_PSCAN
, &hdev
->flags
);
297 mgmt_connectable(hdev
->id
, 1);
298 } else if (old_pscan
)
299 mgmt_connectable(hdev
->id
, 0);
302 hci_req_complete(hdev
, HCI_OP_WRITE_SCAN_ENABLE
, status
);
305 static void hci_cc_read_class_of_dev(struct hci_dev
*hdev
, struct sk_buff
*skb
)
307 struct hci_rp_read_class_of_dev
*rp
= (void *) skb
->data
;
309 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
314 memcpy(hdev
->dev_class
, rp
->dev_class
, 3);
316 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev
->name
,
317 hdev
->dev_class
[2], hdev
->dev_class
[1], hdev
->dev_class
[0]);
320 static void hci_cc_write_class_of_dev(struct hci_dev
*hdev
, struct sk_buff
*skb
)
322 __u8 status
= *((__u8
*) skb
->data
);
325 BT_DBG("%s status 0x%x", hdev
->name
, status
);
330 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_CLASS_OF_DEV
);
334 memcpy(hdev
->dev_class
, sent
, 3);
337 static void hci_cc_read_voice_setting(struct hci_dev
*hdev
, struct sk_buff
*skb
)
339 struct hci_rp_read_voice_setting
*rp
= (void *) skb
->data
;
342 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
347 setting
= __le16_to_cpu(rp
->voice_setting
);
349 if (hdev
->voice_setting
== setting
)
352 hdev
->voice_setting
= setting
;
354 BT_DBG("%s voice setting 0x%04x", hdev
->name
, setting
);
357 tasklet_disable(&hdev
->tx_task
);
358 hdev
->notify(hdev
, HCI_NOTIFY_VOICE_SETTING
);
359 tasklet_enable(&hdev
->tx_task
);
363 static void hci_cc_write_voice_setting(struct hci_dev
*hdev
, struct sk_buff
*skb
)
365 __u8 status
= *((__u8
*) skb
->data
);
369 BT_DBG("%s status 0x%x", hdev
->name
, status
);
374 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_VOICE_SETTING
);
378 setting
= get_unaligned_le16(sent
);
380 if (hdev
->voice_setting
== setting
)
383 hdev
->voice_setting
= setting
;
385 BT_DBG("%s voice setting 0x%04x", hdev
->name
, setting
);
388 tasklet_disable(&hdev
->tx_task
);
389 hdev
->notify(hdev
, HCI_NOTIFY_VOICE_SETTING
);
390 tasklet_enable(&hdev
->tx_task
);
394 static void hci_cc_host_buffer_size(struct hci_dev
*hdev
, struct sk_buff
*skb
)
396 __u8 status
= *((__u8
*) skb
->data
);
398 BT_DBG("%s status 0x%x", hdev
->name
, status
);
400 hci_req_complete(hdev
, HCI_OP_HOST_BUFFER_SIZE
, status
);
403 static void hci_cc_read_ssp_mode(struct hci_dev
*hdev
, struct sk_buff
*skb
)
405 struct hci_rp_read_ssp_mode
*rp
= (void *) skb
->data
;
407 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
412 hdev
->ssp_mode
= rp
->mode
;
415 static void hci_cc_write_ssp_mode(struct hci_dev
*hdev
, struct sk_buff
*skb
)
417 __u8 status
= *((__u8
*) skb
->data
);
420 BT_DBG("%s status 0x%x", hdev
->name
, status
);
425 sent
= hci_sent_cmd_data(hdev
, HCI_OP_WRITE_SSP_MODE
);
429 hdev
->ssp_mode
= *((__u8
*) sent
);
432 static u8
hci_get_inquiry_mode(struct hci_dev
*hdev
)
434 if (hdev
->features
[6] & LMP_EXT_INQ
)
437 if (hdev
->features
[3] & LMP_RSSI_INQ
)
440 if (hdev
->manufacturer
== 11 && hdev
->hci_rev
== 0x00 &&
441 hdev
->lmp_subver
== 0x0757)
444 if (hdev
->manufacturer
== 15) {
445 if (hdev
->hci_rev
== 0x03 && hdev
->lmp_subver
== 0x6963)
447 if (hdev
->hci_rev
== 0x09 && hdev
->lmp_subver
== 0x6963)
449 if (hdev
->hci_rev
== 0x00 && hdev
->lmp_subver
== 0x6965)
453 if (hdev
->manufacturer
== 31 && hdev
->hci_rev
== 0x2005 &&
454 hdev
->lmp_subver
== 0x1805)
460 static void hci_setup_inquiry_mode(struct hci_dev
*hdev
)
464 mode
= hci_get_inquiry_mode(hdev
);
466 hci_send_cmd(hdev
, HCI_OP_WRITE_INQUIRY_MODE
, 1, &mode
);
469 static void hci_setup_event_mask(struct hci_dev
*hdev
)
471 /* The second byte is 0xff instead of 0x9f (two reserved bits
472 * disabled) since a Broadcom 1.2 dongle doesn't respond to the
473 * command otherwise */
474 u8 events
[8] = { 0xff, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x00 };
476 /* Events for 1.2 and newer controllers */
477 if (hdev
->lmp_ver
> 1) {
478 events
[4] |= 0x01; /* Flow Specification Complete */
479 events
[4] |= 0x02; /* Inquiry Result with RSSI */
480 events
[4] |= 0x04; /* Read Remote Extended Features Complete */
481 events
[5] |= 0x08; /* Synchronous Connection Complete */
482 events
[5] |= 0x10; /* Synchronous Connection Changed */
485 if (hdev
->features
[3] & LMP_RSSI_INQ
)
486 events
[4] |= 0x04; /* Inquiry Result with RSSI */
488 if (hdev
->features
[5] & LMP_SNIFF_SUBR
)
489 events
[5] |= 0x20; /* Sniff Subrating */
491 if (hdev
->features
[5] & LMP_PAUSE_ENC
)
492 events
[5] |= 0x80; /* Encryption Key Refresh Complete */
494 if (hdev
->features
[6] & LMP_EXT_INQ
)
495 events
[5] |= 0x40; /* Extended Inquiry Result */
497 if (hdev
->features
[6] & LMP_NO_FLUSH
)
498 events
[7] |= 0x01; /* Enhanced Flush Complete */
500 if (hdev
->features
[7] & LMP_LSTO
)
501 events
[6] |= 0x80; /* Link Supervision Timeout Changed */
503 if (hdev
->features
[6] & LMP_SIMPLE_PAIR
) {
504 events
[6] |= 0x01; /* IO Capability Request */
505 events
[6] |= 0x02; /* IO Capability Response */
506 events
[6] |= 0x04; /* User Confirmation Request */
507 events
[6] |= 0x08; /* User Passkey Request */
508 events
[6] |= 0x10; /* Remote OOB Data Request */
509 events
[6] |= 0x20; /* Simple Pairing Complete */
510 events
[7] |= 0x04; /* User Passkey Notification */
511 events
[7] |= 0x08; /* Keypress Notification */
512 events
[7] |= 0x10; /* Remote Host Supported
513 * Features Notification */
516 if (hdev
->features
[4] & LMP_LE
)
517 events
[7] |= 0x20; /* LE Meta-Event */
519 hci_send_cmd(hdev
, HCI_OP_SET_EVENT_MASK
, sizeof(events
), events
);
522 static void hci_setup(struct hci_dev
*hdev
)
524 hci_setup_event_mask(hdev
);
526 if (hdev
->lmp_ver
> 1)
527 hci_send_cmd(hdev
, HCI_OP_READ_LOCAL_COMMANDS
, 0, NULL
);
529 if (hdev
->features
[6] & LMP_SIMPLE_PAIR
) {
531 hci_send_cmd(hdev
, HCI_OP_WRITE_SSP_MODE
, sizeof(mode
), &mode
);
534 if (hdev
->features
[3] & LMP_RSSI_INQ
)
535 hci_setup_inquiry_mode(hdev
);
537 if (hdev
->features
[7] & LMP_INQ_TX_PWR
)
538 hci_send_cmd(hdev
, HCI_OP_READ_INQ_RSP_TX_POWER
, 0, NULL
);
541 static void hci_cc_read_local_version(struct hci_dev
*hdev
, struct sk_buff
*skb
)
543 struct hci_rp_read_local_version
*rp
= (void *) skb
->data
;
545 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
550 hdev
->hci_ver
= rp
->hci_ver
;
551 hdev
->hci_rev
= __le16_to_cpu(rp
->hci_rev
);
552 hdev
->lmp_ver
= rp
->lmp_ver
;
553 hdev
->manufacturer
= __le16_to_cpu(rp
->manufacturer
);
554 hdev
->lmp_subver
= __le16_to_cpu(rp
->lmp_subver
);
556 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev
->name
,
558 hdev
->hci_ver
, hdev
->hci_rev
);
560 if (test_bit(HCI_INIT
, &hdev
->flags
))
564 static void hci_setup_link_policy(struct hci_dev
*hdev
)
568 if (hdev
->features
[0] & LMP_RSWITCH
)
569 link_policy
|= HCI_LP_RSWITCH
;
570 if (hdev
->features
[0] & LMP_HOLD
)
571 link_policy
|= HCI_LP_HOLD
;
572 if (hdev
->features
[0] & LMP_SNIFF
)
573 link_policy
|= HCI_LP_SNIFF
;
574 if (hdev
->features
[1] & LMP_PARK
)
575 link_policy
|= HCI_LP_PARK
;
577 link_policy
= cpu_to_le16(link_policy
);
578 hci_send_cmd(hdev
, HCI_OP_WRITE_DEF_LINK_POLICY
,
579 sizeof(link_policy
), &link_policy
);
582 static void hci_cc_read_local_commands(struct hci_dev
*hdev
, struct sk_buff
*skb
)
584 struct hci_rp_read_local_commands
*rp
= (void *) skb
->data
;
586 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
591 memcpy(hdev
->commands
, rp
->commands
, sizeof(hdev
->commands
));
593 if (test_bit(HCI_INIT
, &hdev
->flags
) && (hdev
->commands
[5] & 0x10))
594 hci_setup_link_policy(hdev
);
597 hci_req_complete(hdev
, HCI_OP_READ_LOCAL_COMMANDS
, rp
->status
);
600 static void hci_cc_read_local_features(struct hci_dev
*hdev
, struct sk_buff
*skb
)
602 struct hci_rp_read_local_features
*rp
= (void *) skb
->data
;
604 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
609 memcpy(hdev
->features
, rp
->features
, 8);
611 /* Adjust default settings according to features
612 * supported by device. */
614 if (hdev
->features
[0] & LMP_3SLOT
)
615 hdev
->pkt_type
|= (HCI_DM3
| HCI_DH3
);
617 if (hdev
->features
[0] & LMP_5SLOT
)
618 hdev
->pkt_type
|= (HCI_DM5
| HCI_DH5
);
620 if (hdev
->features
[1] & LMP_HV2
) {
621 hdev
->pkt_type
|= (HCI_HV2
);
622 hdev
->esco_type
|= (ESCO_HV2
);
625 if (hdev
->features
[1] & LMP_HV3
) {
626 hdev
->pkt_type
|= (HCI_HV3
);
627 hdev
->esco_type
|= (ESCO_HV3
);
630 if (hdev
->features
[3] & LMP_ESCO
)
631 hdev
->esco_type
|= (ESCO_EV3
);
633 if (hdev
->features
[4] & LMP_EV4
)
634 hdev
->esco_type
|= (ESCO_EV4
);
636 if (hdev
->features
[4] & LMP_EV5
)
637 hdev
->esco_type
|= (ESCO_EV5
);
639 if (hdev
->features
[5] & LMP_EDR_ESCO_2M
)
640 hdev
->esco_type
|= (ESCO_2EV3
);
642 if (hdev
->features
[5] & LMP_EDR_ESCO_3M
)
643 hdev
->esco_type
|= (ESCO_3EV3
);
645 if (hdev
->features
[5] & LMP_EDR_3S_ESCO
)
646 hdev
->esco_type
|= (ESCO_2EV5
| ESCO_3EV5
);
648 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev
->name
,
649 hdev
->features
[0], hdev
->features
[1],
650 hdev
->features
[2], hdev
->features
[3],
651 hdev
->features
[4], hdev
->features
[5],
652 hdev
->features
[6], hdev
->features
[7]);
655 static void hci_cc_read_buffer_size(struct hci_dev
*hdev
, struct sk_buff
*skb
)
657 struct hci_rp_read_buffer_size
*rp
= (void *) skb
->data
;
659 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
664 hdev
->acl_mtu
= __le16_to_cpu(rp
->acl_mtu
);
665 hdev
->sco_mtu
= rp
->sco_mtu
;
666 hdev
->acl_pkts
= __le16_to_cpu(rp
->acl_max_pkt
);
667 hdev
->sco_pkts
= __le16_to_cpu(rp
->sco_max_pkt
);
669 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE
, &hdev
->quirks
)) {
674 hdev
->acl_cnt
= hdev
->acl_pkts
;
675 hdev
->sco_cnt
= hdev
->sco_pkts
;
677 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev
->name
,
678 hdev
->acl_mtu
, hdev
->acl_pkts
,
679 hdev
->sco_mtu
, hdev
->sco_pkts
);
682 static void hci_cc_read_bd_addr(struct hci_dev
*hdev
, struct sk_buff
*skb
)
684 struct hci_rp_read_bd_addr
*rp
= (void *) skb
->data
;
686 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
689 bacpy(&hdev
->bdaddr
, &rp
->bdaddr
);
691 hci_req_complete(hdev
, HCI_OP_READ_BD_ADDR
, rp
->status
);
694 static void hci_cc_write_ca_timeout(struct hci_dev
*hdev
, struct sk_buff
*skb
)
696 __u8 status
= *((__u8
*) skb
->data
);
698 BT_DBG("%s status 0x%x", hdev
->name
, status
);
700 hci_req_complete(hdev
, HCI_OP_WRITE_CA_TIMEOUT
, status
);
703 static void hci_cc_delete_stored_link_key(struct hci_dev
*hdev
,
706 __u8 status
= *((__u8
*) skb
->data
);
708 BT_DBG("%s status 0x%x", hdev
->name
, status
);
710 hci_req_complete(hdev
, HCI_OP_DELETE_STORED_LINK_KEY
, status
);
713 static void hci_cc_set_event_mask(struct hci_dev
*hdev
, struct sk_buff
*skb
)
715 __u8 status
= *((__u8
*) skb
->data
);
717 BT_DBG("%s status 0x%x", hdev
->name
, status
);
719 hci_req_complete(hdev
, HCI_OP_SET_EVENT_MASK
, status
);
722 static void hci_cc_write_inquiry_mode(struct hci_dev
*hdev
,
725 __u8 status
= *((__u8
*) skb
->data
);
727 BT_DBG("%s status 0x%x", hdev
->name
, status
);
729 hci_req_complete(hdev
, HCI_OP_WRITE_INQUIRY_MODE
, status
);
732 static void hci_cc_read_inq_rsp_tx_power(struct hci_dev
*hdev
,
735 __u8 status
= *((__u8
*) skb
->data
);
737 BT_DBG("%s status 0x%x", hdev
->name
, status
);
739 hci_req_complete(hdev
, HCI_OP_READ_INQ_RSP_TX_POWER
, status
);
742 static void hci_cc_set_event_flt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
744 __u8 status
= *((__u8
*) skb
->data
);
746 BT_DBG("%s status 0x%x", hdev
->name
, status
);
748 hci_req_complete(hdev
, HCI_OP_SET_EVENT_FLT
, status
);
751 static void hci_cc_pin_code_reply(struct hci_dev
*hdev
, struct sk_buff
*skb
)
753 struct hci_rp_pin_code_reply
*rp
= (void *) skb
->data
;
754 struct hci_cp_pin_code_reply
*cp
;
755 struct hci_conn
*conn
;
757 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
759 if (test_bit(HCI_MGMT
, &hdev
->flags
))
760 mgmt_pin_code_reply_complete(hdev
->id
, &rp
->bdaddr
, rp
->status
);
765 cp
= hci_sent_cmd_data(hdev
, HCI_OP_PIN_CODE_REPLY
);
769 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &cp
->bdaddr
);
771 conn
->pin_length
= cp
->pin_len
;
774 static void hci_cc_pin_code_neg_reply(struct hci_dev
*hdev
, struct sk_buff
*skb
)
776 struct hci_rp_pin_code_neg_reply
*rp
= (void *) skb
->data
;
778 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
780 if (test_bit(HCI_MGMT
, &hdev
->flags
))
781 mgmt_pin_code_neg_reply_complete(hdev
->id
, &rp
->bdaddr
,
784 static void hci_cc_le_read_buffer_size(struct hci_dev
*hdev
,
787 struct hci_rp_le_read_buffer_size
*rp
= (void *) skb
->data
;
789 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
794 hdev
->le_mtu
= __le16_to_cpu(rp
->le_mtu
);
795 hdev
->le_pkts
= rp
->le_max_pkt
;
797 hdev
->le_cnt
= hdev
->le_pkts
;
799 BT_DBG("%s le mtu %d:%d", hdev
->name
, hdev
->le_mtu
, hdev
->le_pkts
);
801 hci_req_complete(hdev
, HCI_OP_LE_READ_BUFFER_SIZE
, rp
->status
);
804 static void hci_cc_user_confirm_reply(struct hci_dev
*hdev
, struct sk_buff
*skb
)
806 struct hci_rp_user_confirm_reply
*rp
= (void *) skb
->data
;
808 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
810 if (test_bit(HCI_MGMT
, &hdev
->flags
))
811 mgmt_user_confirm_reply_complete(hdev
->id
, &rp
->bdaddr
,
815 static void hci_cc_user_confirm_neg_reply(struct hci_dev
*hdev
,
818 struct hci_rp_user_confirm_reply
*rp
= (void *) skb
->data
;
820 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
822 if (test_bit(HCI_MGMT
, &hdev
->flags
))
823 mgmt_user_confirm_neg_reply_complete(hdev
->id
, &rp
->bdaddr
,
827 static void hci_cc_read_local_oob_data_reply(struct hci_dev
*hdev
,
830 struct hci_rp_read_local_oob_data
*rp
= (void *) skb
->data
;
832 BT_DBG("%s status 0x%x", hdev
->name
, rp
->status
);
834 mgmt_read_local_oob_data_reply_complete(hdev
->id
, rp
->hash
,
835 rp
->randomizer
, rp
->status
);
838 static inline void hci_cs_inquiry(struct hci_dev
*hdev
, __u8 status
)
840 BT_DBG("%s status 0x%x", hdev
->name
, status
);
843 hci_req_complete(hdev
, HCI_OP_INQUIRY
, status
);
845 hci_conn_check_pending(hdev
);
847 set_bit(HCI_INQUIRY
, &hdev
->flags
);
850 static inline void hci_cs_create_conn(struct hci_dev
*hdev
, __u8 status
)
852 struct hci_cp_create_conn
*cp
;
853 struct hci_conn
*conn
;
855 BT_DBG("%s status 0x%x", hdev
->name
, status
);
857 cp
= hci_sent_cmd_data(hdev
, HCI_OP_CREATE_CONN
);
863 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &cp
->bdaddr
);
865 BT_DBG("%s bdaddr %s conn %p", hdev
->name
, batostr(&cp
->bdaddr
), conn
);
868 if (conn
&& conn
->state
== BT_CONNECT
) {
869 if (status
!= 0x0c || conn
->attempt
> 2) {
870 conn
->state
= BT_CLOSED
;
871 hci_proto_connect_cfm(conn
, status
);
874 conn
->state
= BT_CONNECT2
;
878 conn
= hci_conn_add(hdev
, ACL_LINK
, &cp
->bdaddr
);
881 conn
->link_mode
|= HCI_LM_MASTER
;
883 BT_ERR("No memory for new connection");
887 hci_dev_unlock(hdev
);
890 static void hci_cs_add_sco(struct hci_dev
*hdev
, __u8 status
)
892 struct hci_cp_add_sco
*cp
;
893 struct hci_conn
*acl
, *sco
;
896 BT_DBG("%s status 0x%x", hdev
->name
, status
);
901 cp
= hci_sent_cmd_data(hdev
, HCI_OP_ADD_SCO
);
905 handle
= __le16_to_cpu(cp
->handle
);
907 BT_DBG("%s handle %d", hdev
->name
, handle
);
911 acl
= hci_conn_hash_lookup_handle(hdev
, handle
);
915 sco
->state
= BT_CLOSED
;
917 hci_proto_connect_cfm(sco
, status
);
922 hci_dev_unlock(hdev
);
925 static void hci_cs_auth_requested(struct hci_dev
*hdev
, __u8 status
)
927 struct hci_cp_auth_requested
*cp
;
928 struct hci_conn
*conn
;
930 BT_DBG("%s status 0x%x", hdev
->name
, status
);
935 cp
= hci_sent_cmd_data(hdev
, HCI_OP_AUTH_REQUESTED
);
941 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(cp
->handle
));
943 if (conn
->state
== BT_CONFIG
) {
944 hci_proto_connect_cfm(conn
, status
);
949 hci_dev_unlock(hdev
);
952 static void hci_cs_set_conn_encrypt(struct hci_dev
*hdev
, __u8 status
)
954 struct hci_cp_set_conn_encrypt
*cp
;
955 struct hci_conn
*conn
;
957 BT_DBG("%s status 0x%x", hdev
->name
, status
);
962 cp
= hci_sent_cmd_data(hdev
, HCI_OP_SET_CONN_ENCRYPT
);
968 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(cp
->handle
));
970 if (conn
->state
== BT_CONFIG
) {
971 hci_proto_connect_cfm(conn
, status
);
976 hci_dev_unlock(hdev
);
979 static int hci_outgoing_auth_needed(struct hci_dev
*hdev
,
980 struct hci_conn
*conn
)
982 if (conn
->state
!= BT_CONFIG
|| !conn
->out
)
985 if (conn
->pending_sec_level
== BT_SECURITY_SDP
)
988 /* Only request authentication for SSP connections or non-SSP
989 * devices with sec_level HIGH */
990 if (!(hdev
->ssp_mode
> 0 && conn
->ssp_mode
> 0) &&
991 conn
->pending_sec_level
!= BT_SECURITY_HIGH
)
997 static void hci_cs_remote_name_req(struct hci_dev
*hdev
, __u8 status
)
999 struct hci_cp_remote_name_req
*cp
;
1000 struct hci_conn
*conn
;
1002 BT_DBG("%s status 0x%x", hdev
->name
, status
);
1004 /* If successful wait for the name req complete event before
1005 * checking for the need to do authentication */
1009 cp
= hci_sent_cmd_data(hdev
, HCI_OP_REMOTE_NAME_REQ
);
1015 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &cp
->bdaddr
);
1016 if (conn
&& hci_outgoing_auth_needed(hdev
, conn
)) {
1017 struct hci_cp_auth_requested cp
;
1018 cp
.handle
= __cpu_to_le16(conn
->handle
);
1019 hci_send_cmd(hdev
, HCI_OP_AUTH_REQUESTED
, sizeof(cp
), &cp
);
1022 hci_dev_unlock(hdev
);
1025 static void hci_cs_read_remote_features(struct hci_dev
*hdev
, __u8 status
)
1027 struct hci_cp_read_remote_features
*cp
;
1028 struct hci_conn
*conn
;
1030 BT_DBG("%s status 0x%x", hdev
->name
, status
);
1035 cp
= hci_sent_cmd_data(hdev
, HCI_OP_READ_REMOTE_FEATURES
);
1041 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(cp
->handle
));
1043 if (conn
->state
== BT_CONFIG
) {
1044 hci_proto_connect_cfm(conn
, status
);
1049 hci_dev_unlock(hdev
);
1052 static void hci_cs_read_remote_ext_features(struct hci_dev
*hdev
, __u8 status
)
1054 struct hci_cp_read_remote_ext_features
*cp
;
1055 struct hci_conn
*conn
;
1057 BT_DBG("%s status 0x%x", hdev
->name
, status
);
1062 cp
= hci_sent_cmd_data(hdev
, HCI_OP_READ_REMOTE_EXT_FEATURES
);
1068 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(cp
->handle
));
1070 if (conn
->state
== BT_CONFIG
) {
1071 hci_proto_connect_cfm(conn
, status
);
1076 hci_dev_unlock(hdev
);
1079 static void hci_cs_setup_sync_conn(struct hci_dev
*hdev
, __u8 status
)
1081 struct hci_cp_setup_sync_conn
*cp
;
1082 struct hci_conn
*acl
, *sco
;
1085 BT_DBG("%s status 0x%x", hdev
->name
, status
);
1090 cp
= hci_sent_cmd_data(hdev
, HCI_OP_SETUP_SYNC_CONN
);
1094 handle
= __le16_to_cpu(cp
->handle
);
1096 BT_DBG("%s handle %d", hdev
->name
, handle
);
1100 acl
= hci_conn_hash_lookup_handle(hdev
, handle
);
1104 sco
->state
= BT_CLOSED
;
1106 hci_proto_connect_cfm(sco
, status
);
1111 hci_dev_unlock(hdev
);
1114 static void hci_cs_sniff_mode(struct hci_dev
*hdev
, __u8 status
)
1116 struct hci_cp_sniff_mode
*cp
;
1117 struct hci_conn
*conn
;
1119 BT_DBG("%s status 0x%x", hdev
->name
, status
);
1124 cp
= hci_sent_cmd_data(hdev
, HCI_OP_SNIFF_MODE
);
1130 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(cp
->handle
));
1132 clear_bit(HCI_CONN_MODE_CHANGE_PEND
, &conn
->pend
);
1134 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND
, &conn
->pend
))
1135 hci_sco_setup(conn
, status
);
1138 hci_dev_unlock(hdev
);
1141 static void hci_cs_exit_sniff_mode(struct hci_dev
*hdev
, __u8 status
)
1143 struct hci_cp_exit_sniff_mode
*cp
;
1144 struct hci_conn
*conn
;
1146 BT_DBG("%s status 0x%x", hdev
->name
, status
);
1151 cp
= hci_sent_cmd_data(hdev
, HCI_OP_EXIT_SNIFF_MODE
);
1157 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(cp
->handle
));
1159 clear_bit(HCI_CONN_MODE_CHANGE_PEND
, &conn
->pend
);
1161 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND
, &conn
->pend
))
1162 hci_sco_setup(conn
, status
);
1165 hci_dev_unlock(hdev
);
1168 static void hci_cs_le_create_conn(struct hci_dev
*hdev
, __u8 status
)
1170 struct hci_cp_le_create_conn
*cp
;
1171 struct hci_conn
*conn
;
1173 BT_DBG("%s status 0x%x", hdev
->name
, status
);
1175 cp
= hci_sent_cmd_data(hdev
, HCI_OP_LE_CREATE_CONN
);
1181 conn
= hci_conn_hash_lookup_ba(hdev
, LE_LINK
, &cp
->peer_addr
);
1183 BT_DBG("%s bdaddr %s conn %p", hdev
->name
, batostr(&cp
->peer_addr
),
1187 if (conn
&& conn
->state
== BT_CONNECT
) {
1188 conn
->state
= BT_CLOSED
;
1189 hci_proto_connect_cfm(conn
, status
);
1194 conn
= hci_conn_add(hdev
, LE_LINK
, &cp
->peer_addr
);
1198 BT_ERR("No memory for new connection");
1202 hci_dev_unlock(hdev
);
1205 static inline void hci_inquiry_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1207 __u8 status
= *((__u8
*) skb
->data
);
1209 BT_DBG("%s status %d", hdev
->name
, status
);
1211 clear_bit(HCI_INQUIRY
, &hdev
->flags
);
1213 hci_req_complete(hdev
, HCI_OP_INQUIRY
, status
);
1215 hci_conn_check_pending(hdev
);
1218 static inline void hci_inquiry_result_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1220 struct inquiry_data data
;
1221 struct inquiry_info
*info
= (void *) (skb
->data
+ 1);
1222 int num_rsp
= *((__u8
*) skb
->data
);
1224 BT_DBG("%s num_rsp %d", hdev
->name
, num_rsp
);
1231 for (; num_rsp
; num_rsp
--, info
++) {
1232 bacpy(&data
.bdaddr
, &info
->bdaddr
);
1233 data
.pscan_rep_mode
= info
->pscan_rep_mode
;
1234 data
.pscan_period_mode
= info
->pscan_period_mode
;
1235 data
.pscan_mode
= info
->pscan_mode
;
1236 memcpy(data
.dev_class
, info
->dev_class
, 3);
1237 data
.clock_offset
= info
->clock_offset
;
1239 data
.ssp_mode
= 0x00;
1240 hci_inquiry_cache_update(hdev
, &data
);
1241 mgmt_device_found(hdev
->id
, &info
->bdaddr
, info
->dev_class
, 0,
1245 hci_dev_unlock(hdev
);
1248 static inline void hci_conn_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1250 struct hci_ev_conn_complete
*ev
= (void *) skb
->data
;
1251 struct hci_conn
*conn
;
1253 BT_DBG("%s", hdev
->name
);
1257 conn
= hci_conn_hash_lookup_ba(hdev
, ev
->link_type
, &ev
->bdaddr
);
1259 if (ev
->link_type
!= SCO_LINK
)
1262 conn
= hci_conn_hash_lookup_ba(hdev
, ESCO_LINK
, &ev
->bdaddr
);
1266 conn
->type
= SCO_LINK
;
1270 conn
->handle
= __le16_to_cpu(ev
->handle
);
1272 if (conn
->type
== ACL_LINK
) {
1273 conn
->state
= BT_CONFIG
;
1274 hci_conn_hold(conn
);
1275 conn
->disc_timeout
= HCI_DISCONN_TIMEOUT
;
1276 mgmt_connected(hdev
->id
, &ev
->bdaddr
);
1278 conn
->state
= BT_CONNECTED
;
1280 hci_conn_hold_device(conn
);
1281 hci_conn_add_sysfs(conn
);
1283 if (test_bit(HCI_AUTH
, &hdev
->flags
))
1284 conn
->link_mode
|= HCI_LM_AUTH
;
1286 if (test_bit(HCI_ENCRYPT
, &hdev
->flags
))
1287 conn
->link_mode
|= HCI_LM_ENCRYPT
;
1289 /* Get remote features */
1290 if (conn
->type
== ACL_LINK
) {
1291 struct hci_cp_read_remote_features cp
;
1292 cp
.handle
= ev
->handle
;
1293 hci_send_cmd(hdev
, HCI_OP_READ_REMOTE_FEATURES
,
1297 /* Set packet type for incoming connection */
1298 if (!conn
->out
&& hdev
->hci_ver
< 3) {
1299 struct hci_cp_change_conn_ptype cp
;
1300 cp
.handle
= ev
->handle
;
1301 cp
.pkt_type
= cpu_to_le16(conn
->pkt_type
);
1302 hci_send_cmd(hdev
, HCI_OP_CHANGE_CONN_PTYPE
,
1306 conn
->state
= BT_CLOSED
;
1307 if (conn
->type
== ACL_LINK
)
1308 mgmt_connect_failed(hdev
->id
, &ev
->bdaddr
, ev
->status
);
1311 if (conn
->type
== ACL_LINK
)
1312 hci_sco_setup(conn
, ev
->status
);
1315 hci_proto_connect_cfm(conn
, ev
->status
);
1317 } else if (ev
->link_type
!= ACL_LINK
)
1318 hci_proto_connect_cfm(conn
, ev
->status
);
1321 hci_dev_unlock(hdev
);
1323 hci_conn_check_pending(hdev
);
1326 static inline void hci_conn_request_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1328 struct hci_ev_conn_request
*ev
= (void *) skb
->data
;
1329 int mask
= hdev
->link_mode
;
1331 BT_DBG("%s bdaddr %s type 0x%x", hdev
->name
,
1332 batostr(&ev
->bdaddr
), ev
->link_type
);
1334 mask
|= hci_proto_connect_ind(hdev
, &ev
->bdaddr
, ev
->link_type
);
1336 if ((mask
& HCI_LM_ACCEPT
) &&
1337 !hci_blacklist_lookup(hdev
, &ev
->bdaddr
)) {
1338 /* Connection accepted */
1339 struct inquiry_entry
*ie
;
1340 struct hci_conn
*conn
;
1344 ie
= hci_inquiry_cache_lookup(hdev
, &ev
->bdaddr
);
1346 memcpy(ie
->data
.dev_class
, ev
->dev_class
, 3);
1348 conn
= hci_conn_hash_lookup_ba(hdev
, ev
->link_type
, &ev
->bdaddr
);
1350 conn
= hci_conn_add(hdev
, ev
->link_type
, &ev
->bdaddr
);
1352 BT_ERR("No memory for new connection");
1353 hci_dev_unlock(hdev
);
1358 memcpy(conn
->dev_class
, ev
->dev_class
, 3);
1359 conn
->state
= BT_CONNECT
;
1361 hci_dev_unlock(hdev
);
1363 if (ev
->link_type
== ACL_LINK
|| !lmp_esco_capable(hdev
)) {
1364 struct hci_cp_accept_conn_req cp
;
1366 bacpy(&cp
.bdaddr
, &ev
->bdaddr
);
1368 if (lmp_rswitch_capable(hdev
) && (mask
& HCI_LM_MASTER
))
1369 cp
.role
= 0x00; /* Become master */
1371 cp
.role
= 0x01; /* Remain slave */
1373 hci_send_cmd(hdev
, HCI_OP_ACCEPT_CONN_REQ
,
1376 struct hci_cp_accept_sync_conn_req cp
;
1378 bacpy(&cp
.bdaddr
, &ev
->bdaddr
);
1379 cp
.pkt_type
= cpu_to_le16(conn
->pkt_type
);
1381 cp
.tx_bandwidth
= cpu_to_le32(0x00001f40);
1382 cp
.rx_bandwidth
= cpu_to_le32(0x00001f40);
1383 cp
.max_latency
= cpu_to_le16(0xffff);
1384 cp
.content_format
= cpu_to_le16(hdev
->voice_setting
);
1385 cp
.retrans_effort
= 0xff;
1387 hci_send_cmd(hdev
, HCI_OP_ACCEPT_SYNC_CONN_REQ
,
1391 /* Connection rejected */
1392 struct hci_cp_reject_conn_req cp
;
1394 bacpy(&cp
.bdaddr
, &ev
->bdaddr
);
1396 hci_send_cmd(hdev
, HCI_OP_REJECT_CONN_REQ
, sizeof(cp
), &cp
);
1400 static inline void hci_disconn_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1402 struct hci_ev_disconn_complete
*ev
= (void *) skb
->data
;
1403 struct hci_conn
*conn
;
1405 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
1408 mgmt_disconnect_failed(hdev
->id
);
1414 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
1418 conn
->state
= BT_CLOSED
;
1420 if (conn
->type
== ACL_LINK
)
1421 mgmt_disconnected(hdev
->id
, &conn
->dst
);
1423 hci_proto_disconn_cfm(conn
, ev
->reason
);
1427 hci_dev_unlock(hdev
);
1430 static inline void hci_auth_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1432 struct hci_ev_auth_complete
*ev
= (void *) skb
->data
;
1433 struct hci_conn
*conn
;
1435 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
1439 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
1442 conn
->link_mode
|= HCI_LM_AUTH
;
1443 conn
->sec_level
= conn
->pending_sec_level
;
1445 mgmt_auth_failed(hdev
->id
, &conn
->dst
, ev
->status
);
1446 conn
->sec_level
= BT_SECURITY_LOW
;
1449 clear_bit(HCI_CONN_AUTH_PEND
, &conn
->pend
);
1451 if (conn
->state
== BT_CONFIG
) {
1452 if (!ev
->status
&& hdev
->ssp_mode
> 0 &&
1453 conn
->ssp_mode
> 0) {
1454 struct hci_cp_set_conn_encrypt cp
;
1455 cp
.handle
= ev
->handle
;
1457 hci_send_cmd(hdev
, HCI_OP_SET_CONN_ENCRYPT
,
1460 conn
->state
= BT_CONNECTED
;
1461 hci_proto_connect_cfm(conn
, ev
->status
);
1465 hci_auth_cfm(conn
, ev
->status
);
1467 hci_conn_hold(conn
);
1468 conn
->disc_timeout
= HCI_DISCONN_TIMEOUT
;
1472 if (test_bit(HCI_CONN_ENCRYPT_PEND
, &conn
->pend
)) {
1474 struct hci_cp_set_conn_encrypt cp
;
1475 cp
.handle
= ev
->handle
;
1477 hci_send_cmd(hdev
, HCI_OP_SET_CONN_ENCRYPT
,
1480 clear_bit(HCI_CONN_ENCRYPT_PEND
, &conn
->pend
);
1481 hci_encrypt_cfm(conn
, ev
->status
, 0x00);
1486 hci_dev_unlock(hdev
);
1489 static inline void hci_remote_name_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1491 struct hci_ev_remote_name
*ev
= (void *) skb
->data
;
1492 struct hci_conn
*conn
;
1494 BT_DBG("%s", hdev
->name
);
1496 hci_conn_check_pending(hdev
);
1500 if (ev
->status
== 0 && test_bit(HCI_MGMT
, &hdev
->flags
))
1501 mgmt_remote_name(hdev
->id
, &ev
->bdaddr
, ev
->name
);
1503 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &ev
->bdaddr
);
1504 if (conn
&& hci_outgoing_auth_needed(hdev
, conn
)) {
1505 struct hci_cp_auth_requested cp
;
1506 cp
.handle
= __cpu_to_le16(conn
->handle
);
1507 hci_send_cmd(hdev
, HCI_OP_AUTH_REQUESTED
, sizeof(cp
), &cp
);
1510 hci_dev_unlock(hdev
);
1513 static inline void hci_encrypt_change_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1515 struct hci_ev_encrypt_change
*ev
= (void *) skb
->data
;
1516 struct hci_conn
*conn
;
1518 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
1522 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
1526 /* Encryption implies authentication */
1527 conn
->link_mode
|= HCI_LM_AUTH
;
1528 conn
->link_mode
|= HCI_LM_ENCRYPT
;
1530 conn
->link_mode
&= ~HCI_LM_ENCRYPT
;
1533 clear_bit(HCI_CONN_ENCRYPT_PEND
, &conn
->pend
);
1535 if (conn
->state
== BT_CONFIG
) {
1537 conn
->state
= BT_CONNECTED
;
1539 hci_proto_connect_cfm(conn
, ev
->status
);
1542 hci_encrypt_cfm(conn
, ev
->status
, ev
->encrypt
);
1545 hci_dev_unlock(hdev
);
1548 static inline void hci_change_link_key_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1550 struct hci_ev_change_link_key_complete
*ev
= (void *) skb
->data
;
1551 struct hci_conn
*conn
;
1553 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
1557 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
1560 conn
->link_mode
|= HCI_LM_SECURE
;
1562 clear_bit(HCI_CONN_AUTH_PEND
, &conn
->pend
);
1564 hci_key_change_cfm(conn
, ev
->status
);
1567 hci_dev_unlock(hdev
);
1570 static inline void hci_remote_features_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1572 struct hci_ev_remote_features
*ev
= (void *) skb
->data
;
1573 struct hci_conn
*conn
;
1575 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
1579 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
1584 memcpy(conn
->features
, ev
->features
, 8);
1586 if (conn
->state
!= BT_CONFIG
)
1589 if (!ev
->status
&& lmp_ssp_capable(hdev
) && lmp_ssp_capable(conn
)) {
1590 struct hci_cp_read_remote_ext_features cp
;
1591 cp
.handle
= ev
->handle
;
1593 hci_send_cmd(hdev
, HCI_OP_READ_REMOTE_EXT_FEATURES
,
1599 struct hci_cp_remote_name_req cp
;
1600 memset(&cp
, 0, sizeof(cp
));
1601 bacpy(&cp
.bdaddr
, &conn
->dst
);
1602 cp
.pscan_rep_mode
= 0x02;
1603 hci_send_cmd(hdev
, HCI_OP_REMOTE_NAME_REQ
, sizeof(cp
), &cp
);
1606 if (!hci_outgoing_auth_needed(hdev
, conn
)) {
1607 conn
->state
= BT_CONNECTED
;
1608 hci_proto_connect_cfm(conn
, ev
->status
);
1613 hci_dev_unlock(hdev
);
1616 static inline void hci_remote_version_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1618 BT_DBG("%s", hdev
->name
);
1621 static inline void hci_qos_setup_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1623 BT_DBG("%s", hdev
->name
);
1626 static inline void hci_cmd_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1628 struct hci_ev_cmd_complete
*ev
= (void *) skb
->data
;
1631 skb_pull(skb
, sizeof(*ev
));
1633 opcode
= __le16_to_cpu(ev
->opcode
);
1636 case HCI_OP_INQUIRY_CANCEL
:
1637 hci_cc_inquiry_cancel(hdev
, skb
);
1640 case HCI_OP_EXIT_PERIODIC_INQ
:
1641 hci_cc_exit_periodic_inq(hdev
, skb
);
1644 case HCI_OP_REMOTE_NAME_REQ_CANCEL
:
1645 hci_cc_remote_name_req_cancel(hdev
, skb
);
1648 case HCI_OP_ROLE_DISCOVERY
:
1649 hci_cc_role_discovery(hdev
, skb
);
1652 case HCI_OP_READ_LINK_POLICY
:
1653 hci_cc_read_link_policy(hdev
, skb
);
1656 case HCI_OP_WRITE_LINK_POLICY
:
1657 hci_cc_write_link_policy(hdev
, skb
);
1660 case HCI_OP_READ_DEF_LINK_POLICY
:
1661 hci_cc_read_def_link_policy(hdev
, skb
);
1664 case HCI_OP_WRITE_DEF_LINK_POLICY
:
1665 hci_cc_write_def_link_policy(hdev
, skb
);
1669 hci_cc_reset(hdev
, skb
);
1672 case HCI_OP_WRITE_LOCAL_NAME
:
1673 hci_cc_write_local_name(hdev
, skb
);
1676 case HCI_OP_READ_LOCAL_NAME
:
1677 hci_cc_read_local_name(hdev
, skb
);
1680 case HCI_OP_WRITE_AUTH_ENABLE
:
1681 hci_cc_write_auth_enable(hdev
, skb
);
1684 case HCI_OP_WRITE_ENCRYPT_MODE
:
1685 hci_cc_write_encrypt_mode(hdev
, skb
);
1688 case HCI_OP_WRITE_SCAN_ENABLE
:
1689 hci_cc_write_scan_enable(hdev
, skb
);
1692 case HCI_OP_READ_CLASS_OF_DEV
:
1693 hci_cc_read_class_of_dev(hdev
, skb
);
1696 case HCI_OP_WRITE_CLASS_OF_DEV
:
1697 hci_cc_write_class_of_dev(hdev
, skb
);
1700 case HCI_OP_READ_VOICE_SETTING
:
1701 hci_cc_read_voice_setting(hdev
, skb
);
1704 case HCI_OP_WRITE_VOICE_SETTING
:
1705 hci_cc_write_voice_setting(hdev
, skb
);
1708 case HCI_OP_HOST_BUFFER_SIZE
:
1709 hci_cc_host_buffer_size(hdev
, skb
);
1712 case HCI_OP_READ_SSP_MODE
:
1713 hci_cc_read_ssp_mode(hdev
, skb
);
1716 case HCI_OP_WRITE_SSP_MODE
:
1717 hci_cc_write_ssp_mode(hdev
, skb
);
1720 case HCI_OP_READ_LOCAL_VERSION
:
1721 hci_cc_read_local_version(hdev
, skb
);
1724 case HCI_OP_READ_LOCAL_COMMANDS
:
1725 hci_cc_read_local_commands(hdev
, skb
);
1728 case HCI_OP_READ_LOCAL_FEATURES
:
1729 hci_cc_read_local_features(hdev
, skb
);
1732 case HCI_OP_READ_BUFFER_SIZE
:
1733 hci_cc_read_buffer_size(hdev
, skb
);
1736 case HCI_OP_READ_BD_ADDR
:
1737 hci_cc_read_bd_addr(hdev
, skb
);
1740 case HCI_OP_WRITE_CA_TIMEOUT
:
1741 hci_cc_write_ca_timeout(hdev
, skb
);
1744 case HCI_OP_DELETE_STORED_LINK_KEY
:
1745 hci_cc_delete_stored_link_key(hdev
, skb
);
1748 case HCI_OP_SET_EVENT_MASK
:
1749 hci_cc_set_event_mask(hdev
, skb
);
1752 case HCI_OP_WRITE_INQUIRY_MODE
:
1753 hci_cc_write_inquiry_mode(hdev
, skb
);
1756 case HCI_OP_READ_INQ_RSP_TX_POWER
:
1757 hci_cc_read_inq_rsp_tx_power(hdev
, skb
);
1760 case HCI_OP_SET_EVENT_FLT
:
1761 hci_cc_set_event_flt(hdev
, skb
);
1764 case HCI_OP_PIN_CODE_REPLY
:
1765 hci_cc_pin_code_reply(hdev
, skb
);
1768 case HCI_OP_PIN_CODE_NEG_REPLY
:
1769 hci_cc_pin_code_neg_reply(hdev
, skb
);
1772 case HCI_OP_READ_LOCAL_OOB_DATA
:
1773 hci_cc_read_local_oob_data_reply(hdev
, skb
);
1776 case HCI_OP_LE_READ_BUFFER_SIZE
:
1777 hci_cc_le_read_buffer_size(hdev
, skb
);
1780 case HCI_OP_USER_CONFIRM_REPLY
:
1781 hci_cc_user_confirm_reply(hdev
, skb
);
1784 case HCI_OP_USER_CONFIRM_NEG_REPLY
:
1785 hci_cc_user_confirm_neg_reply(hdev
, skb
);
1789 BT_DBG("%s opcode 0x%x", hdev
->name
, opcode
);
1793 if (ev
->opcode
!= HCI_OP_NOP
)
1794 del_timer(&hdev
->cmd_timer
);
1797 atomic_set(&hdev
->cmd_cnt
, 1);
1798 if (!skb_queue_empty(&hdev
->cmd_q
))
1799 tasklet_schedule(&hdev
->cmd_task
);
1803 static inline void hci_cmd_status_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1805 struct hci_ev_cmd_status
*ev
= (void *) skb
->data
;
1808 skb_pull(skb
, sizeof(*ev
));
1810 opcode
= __le16_to_cpu(ev
->opcode
);
1813 case HCI_OP_INQUIRY
:
1814 hci_cs_inquiry(hdev
, ev
->status
);
1817 case HCI_OP_CREATE_CONN
:
1818 hci_cs_create_conn(hdev
, ev
->status
);
1821 case HCI_OP_ADD_SCO
:
1822 hci_cs_add_sco(hdev
, ev
->status
);
1825 case HCI_OP_AUTH_REQUESTED
:
1826 hci_cs_auth_requested(hdev
, ev
->status
);
1829 case HCI_OP_SET_CONN_ENCRYPT
:
1830 hci_cs_set_conn_encrypt(hdev
, ev
->status
);
1833 case HCI_OP_REMOTE_NAME_REQ
:
1834 hci_cs_remote_name_req(hdev
, ev
->status
);
1837 case HCI_OP_READ_REMOTE_FEATURES
:
1838 hci_cs_read_remote_features(hdev
, ev
->status
);
1841 case HCI_OP_READ_REMOTE_EXT_FEATURES
:
1842 hci_cs_read_remote_ext_features(hdev
, ev
->status
);
1845 case HCI_OP_SETUP_SYNC_CONN
:
1846 hci_cs_setup_sync_conn(hdev
, ev
->status
);
1849 case HCI_OP_SNIFF_MODE
:
1850 hci_cs_sniff_mode(hdev
, ev
->status
);
1853 case HCI_OP_EXIT_SNIFF_MODE
:
1854 hci_cs_exit_sniff_mode(hdev
, ev
->status
);
1857 case HCI_OP_DISCONNECT
:
1858 if (ev
->status
!= 0)
1859 mgmt_disconnect_failed(hdev
->id
);
1862 case HCI_OP_LE_CREATE_CONN
:
1863 hci_cs_le_create_conn(hdev
, ev
->status
);
1867 BT_DBG("%s opcode 0x%x", hdev
->name
, opcode
);
1871 if (ev
->opcode
!= HCI_OP_NOP
)
1872 del_timer(&hdev
->cmd_timer
);
1874 if (ev
->ncmd
&& !test_bit(HCI_RESET
, &hdev
->flags
)) {
1875 atomic_set(&hdev
->cmd_cnt
, 1);
1876 if (!skb_queue_empty(&hdev
->cmd_q
))
1877 tasklet_schedule(&hdev
->cmd_task
);
1881 static inline void hci_role_change_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1883 struct hci_ev_role_change
*ev
= (void *) skb
->data
;
1884 struct hci_conn
*conn
;
1886 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
1890 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &ev
->bdaddr
);
1894 conn
->link_mode
&= ~HCI_LM_MASTER
;
1896 conn
->link_mode
|= HCI_LM_MASTER
;
1899 clear_bit(HCI_CONN_RSWITCH_PEND
, &conn
->pend
);
1901 hci_role_switch_cfm(conn
, ev
->status
, ev
->role
);
1904 hci_dev_unlock(hdev
);
1907 static inline void hci_num_comp_pkts_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1909 struct hci_ev_num_comp_pkts
*ev
= (void *) skb
->data
;
1913 skb_pull(skb
, sizeof(*ev
));
1915 BT_DBG("%s num_hndl %d", hdev
->name
, ev
->num_hndl
);
1917 if (skb
->len
< ev
->num_hndl
* 4) {
1918 BT_DBG("%s bad parameters", hdev
->name
);
1922 tasklet_disable(&hdev
->tx_task
);
1924 for (i
= 0, ptr
= (__le16
*) skb
->data
; i
< ev
->num_hndl
; i
++) {
1925 struct hci_conn
*conn
;
1926 __u16 handle
, count
;
1928 handle
= get_unaligned_le16(ptr
++);
1929 count
= get_unaligned_le16(ptr
++);
1931 conn
= hci_conn_hash_lookup_handle(hdev
, handle
);
1933 conn
->sent
-= count
;
1935 if (conn
->type
== ACL_LINK
) {
1936 hdev
->acl_cnt
+= count
;
1937 if (hdev
->acl_cnt
> hdev
->acl_pkts
)
1938 hdev
->acl_cnt
= hdev
->acl_pkts
;
1939 } else if (conn
->type
== LE_LINK
) {
1940 if (hdev
->le_pkts
) {
1941 hdev
->le_cnt
+= count
;
1942 if (hdev
->le_cnt
> hdev
->le_pkts
)
1943 hdev
->le_cnt
= hdev
->le_pkts
;
1945 hdev
->acl_cnt
+= count
;
1946 if (hdev
->acl_cnt
> hdev
->acl_pkts
)
1947 hdev
->acl_cnt
= hdev
->acl_pkts
;
1950 hdev
->sco_cnt
+= count
;
1951 if (hdev
->sco_cnt
> hdev
->sco_pkts
)
1952 hdev
->sco_cnt
= hdev
->sco_pkts
;
1957 tasklet_schedule(&hdev
->tx_task
);
1959 tasklet_enable(&hdev
->tx_task
);
1962 static inline void hci_mode_change_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1964 struct hci_ev_mode_change
*ev
= (void *) skb
->data
;
1965 struct hci_conn
*conn
;
1967 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
1971 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
1973 conn
->mode
= ev
->mode
;
1974 conn
->interval
= __le16_to_cpu(ev
->interval
);
1976 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND
, &conn
->pend
)) {
1977 if (conn
->mode
== HCI_CM_ACTIVE
)
1978 conn
->power_save
= 1;
1980 conn
->power_save
= 0;
1983 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND
, &conn
->pend
))
1984 hci_sco_setup(conn
, ev
->status
);
1987 hci_dev_unlock(hdev
);
1990 static inline void hci_pin_code_request_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
1992 struct hci_ev_pin_code_req
*ev
= (void *) skb
->data
;
1993 struct hci_conn
*conn
;
1995 BT_DBG("%s", hdev
->name
);
1999 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &ev
->bdaddr
);
2000 if (conn
&& conn
->state
== BT_CONNECTED
) {
2001 hci_conn_hold(conn
);
2002 conn
->disc_timeout
= HCI_PAIRING_TIMEOUT
;
2006 if (!test_bit(HCI_PAIRABLE
, &hdev
->flags
))
2007 hci_send_cmd(hdev
, HCI_OP_PIN_CODE_NEG_REPLY
,
2008 sizeof(ev
->bdaddr
), &ev
->bdaddr
);
2010 if (test_bit(HCI_MGMT
, &hdev
->flags
))
2011 mgmt_pin_code_request(hdev
->id
, &ev
->bdaddr
);
2013 hci_dev_unlock(hdev
);
2016 static inline void hci_link_key_request_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2018 struct hci_ev_link_key_req
*ev
= (void *) skb
->data
;
2019 struct hci_cp_link_key_reply cp
;
2020 struct hci_conn
*conn
;
2021 struct link_key
*key
;
2023 BT_DBG("%s", hdev
->name
);
2025 if (!test_bit(HCI_LINK_KEYS
, &hdev
->flags
))
2030 key
= hci_find_link_key(hdev
, &ev
->bdaddr
);
2032 BT_DBG("%s link key not found for %s", hdev
->name
,
2033 batostr(&ev
->bdaddr
));
2037 BT_DBG("%s found key type %u for %s", hdev
->name
, key
->type
,
2038 batostr(&ev
->bdaddr
));
2040 if (!test_bit(HCI_DEBUG_KEYS
, &hdev
->flags
) && key
->type
== 0x03) {
2041 BT_DBG("%s ignoring debug key", hdev
->name
);
2045 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &ev
->bdaddr
);
2047 if (key
->type
== 0x04 && conn
&& conn
->auth_type
!= 0xff &&
2048 (conn
->auth_type
& 0x01)) {
2049 BT_DBG("%s ignoring unauthenticated key", hdev
->name
);
2053 bacpy(&cp
.bdaddr
, &ev
->bdaddr
);
2054 memcpy(cp
.link_key
, key
->val
, 16);
2056 hci_send_cmd(hdev
, HCI_OP_LINK_KEY_REPLY
, sizeof(cp
), &cp
);
2058 hci_dev_unlock(hdev
);
2063 hci_send_cmd(hdev
, HCI_OP_LINK_KEY_NEG_REPLY
, 6, &ev
->bdaddr
);
2064 hci_dev_unlock(hdev
);
2067 static inline void hci_link_key_notify_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2069 struct hci_ev_link_key_notify
*ev
= (void *) skb
->data
;
2070 struct hci_conn
*conn
;
2073 BT_DBG("%s", hdev
->name
);
2077 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &ev
->bdaddr
);
2079 hci_conn_hold(conn
);
2080 conn
->disc_timeout
= HCI_DISCONN_TIMEOUT
;
2081 pin_len
= conn
->pin_length
;
2085 if (test_bit(HCI_LINK_KEYS
, &hdev
->flags
))
2086 hci_add_link_key(hdev
, 1, &ev
->bdaddr
, ev
->link_key
,
2087 ev
->key_type
, pin_len
);
2089 hci_dev_unlock(hdev
);
2092 static inline void hci_clock_offset_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2094 struct hci_ev_clock_offset
*ev
= (void *) skb
->data
;
2095 struct hci_conn
*conn
;
2097 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
2101 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
2102 if (conn
&& !ev
->status
) {
2103 struct inquiry_entry
*ie
;
2105 ie
= hci_inquiry_cache_lookup(hdev
, &conn
->dst
);
2107 ie
->data
.clock_offset
= ev
->clock_offset
;
2108 ie
->timestamp
= jiffies
;
2112 hci_dev_unlock(hdev
);
2115 static inline void hci_pkt_type_change_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2117 struct hci_ev_pkt_type_change
*ev
= (void *) skb
->data
;
2118 struct hci_conn
*conn
;
2120 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
2124 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
2125 if (conn
&& !ev
->status
)
2126 conn
->pkt_type
= __le16_to_cpu(ev
->pkt_type
);
2128 hci_dev_unlock(hdev
);
2131 static inline void hci_pscan_rep_mode_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2133 struct hci_ev_pscan_rep_mode
*ev
= (void *) skb
->data
;
2134 struct inquiry_entry
*ie
;
2136 BT_DBG("%s", hdev
->name
);
2140 ie
= hci_inquiry_cache_lookup(hdev
, &ev
->bdaddr
);
2142 ie
->data
.pscan_rep_mode
= ev
->pscan_rep_mode
;
2143 ie
->timestamp
= jiffies
;
2146 hci_dev_unlock(hdev
);
2149 static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2151 struct inquiry_data data
;
2152 int num_rsp
= *((__u8
*) skb
->data
);
2154 BT_DBG("%s num_rsp %d", hdev
->name
, num_rsp
);
2161 if ((skb
->len
- 1) / num_rsp
!= sizeof(struct inquiry_info_with_rssi
)) {
2162 struct inquiry_info_with_rssi_and_pscan_mode
*info
;
2163 info
= (void *) (skb
->data
+ 1);
2165 for (; num_rsp
; num_rsp
--, info
++) {
2166 bacpy(&data
.bdaddr
, &info
->bdaddr
);
2167 data
.pscan_rep_mode
= info
->pscan_rep_mode
;
2168 data
.pscan_period_mode
= info
->pscan_period_mode
;
2169 data
.pscan_mode
= info
->pscan_mode
;
2170 memcpy(data
.dev_class
, info
->dev_class
, 3);
2171 data
.clock_offset
= info
->clock_offset
;
2172 data
.rssi
= info
->rssi
;
2173 data
.ssp_mode
= 0x00;
2174 hci_inquiry_cache_update(hdev
, &data
);
2175 mgmt_device_found(hdev
->id
, &info
->bdaddr
,
2176 info
->dev_class
, info
->rssi
,
2180 struct inquiry_info_with_rssi
*info
= (void *) (skb
->data
+ 1);
2182 for (; num_rsp
; num_rsp
--, info
++) {
2183 bacpy(&data
.bdaddr
, &info
->bdaddr
);
2184 data
.pscan_rep_mode
= info
->pscan_rep_mode
;
2185 data
.pscan_period_mode
= info
->pscan_period_mode
;
2186 data
.pscan_mode
= 0x00;
2187 memcpy(data
.dev_class
, info
->dev_class
, 3);
2188 data
.clock_offset
= info
->clock_offset
;
2189 data
.rssi
= info
->rssi
;
2190 data
.ssp_mode
= 0x00;
2191 hci_inquiry_cache_update(hdev
, &data
);
2192 mgmt_device_found(hdev
->id
, &info
->bdaddr
,
2193 info
->dev_class
, info
->rssi
,
2198 hci_dev_unlock(hdev
);
2201 static inline void hci_remote_ext_features_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2203 struct hci_ev_remote_ext_features
*ev
= (void *) skb
->data
;
2204 struct hci_conn
*conn
;
2206 BT_DBG("%s", hdev
->name
);
2210 conn
= hci_conn_hash_lookup_handle(hdev
, __le16_to_cpu(ev
->handle
));
2214 if (!ev
->status
&& ev
->page
== 0x01) {
2215 struct inquiry_entry
*ie
;
2217 ie
= hci_inquiry_cache_lookup(hdev
, &conn
->dst
);
2219 ie
->data
.ssp_mode
= (ev
->features
[0] & 0x01);
2221 conn
->ssp_mode
= (ev
->features
[0] & 0x01);
2224 if (conn
->state
!= BT_CONFIG
)
2228 struct hci_cp_remote_name_req cp
;
2229 memset(&cp
, 0, sizeof(cp
));
2230 bacpy(&cp
.bdaddr
, &conn
->dst
);
2231 cp
.pscan_rep_mode
= 0x02;
2232 hci_send_cmd(hdev
, HCI_OP_REMOTE_NAME_REQ
, sizeof(cp
), &cp
);
2235 if (!hci_outgoing_auth_needed(hdev
, conn
)) {
2236 conn
->state
= BT_CONNECTED
;
2237 hci_proto_connect_cfm(conn
, ev
->status
);
2242 hci_dev_unlock(hdev
);
2245 static inline void hci_sync_conn_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2247 struct hci_ev_sync_conn_complete
*ev
= (void *) skb
->data
;
2248 struct hci_conn
*conn
;
2250 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
2254 conn
= hci_conn_hash_lookup_ba(hdev
, ev
->link_type
, &ev
->bdaddr
);
2256 if (ev
->link_type
== ESCO_LINK
)
2259 conn
= hci_conn_hash_lookup_ba(hdev
, ESCO_LINK
, &ev
->bdaddr
);
2263 conn
->type
= SCO_LINK
;
2266 switch (ev
->status
) {
2268 conn
->handle
= __le16_to_cpu(ev
->handle
);
2269 conn
->state
= BT_CONNECTED
;
2271 hci_conn_hold_device(conn
);
2272 hci_conn_add_sysfs(conn
);
2275 case 0x11: /* Unsupported Feature or Parameter Value */
2276 case 0x1c: /* SCO interval rejected */
2277 case 0x1a: /* Unsupported Remote Feature */
2278 case 0x1f: /* Unspecified error */
2279 if (conn
->out
&& conn
->attempt
< 2) {
2280 conn
->pkt_type
= (hdev
->esco_type
& SCO_ESCO_MASK
) |
2281 (hdev
->esco_type
& EDR_ESCO_MASK
);
2282 hci_setup_sync(conn
, conn
->link
->handle
);
2288 conn
->state
= BT_CLOSED
;
2292 hci_proto_connect_cfm(conn
, ev
->status
);
2297 hci_dev_unlock(hdev
);
2300 static inline void hci_sync_conn_changed_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2302 BT_DBG("%s", hdev
->name
);
2305 static inline void hci_sniff_subrate_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2307 struct hci_ev_sniff_subrate
*ev
= (void *) skb
->data
;
2309 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
2312 static inline void hci_extended_inquiry_result_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2314 struct inquiry_data data
;
2315 struct extended_inquiry_info
*info
= (void *) (skb
->data
+ 1);
2316 int num_rsp
= *((__u8
*) skb
->data
);
2318 BT_DBG("%s num_rsp %d", hdev
->name
, num_rsp
);
2325 for (; num_rsp
; num_rsp
--, info
++) {
2326 bacpy(&data
.bdaddr
, &info
->bdaddr
);
2327 data
.pscan_rep_mode
= info
->pscan_rep_mode
;
2328 data
.pscan_period_mode
= info
->pscan_period_mode
;
2329 data
.pscan_mode
= 0x00;
2330 memcpy(data
.dev_class
, info
->dev_class
, 3);
2331 data
.clock_offset
= info
->clock_offset
;
2332 data
.rssi
= info
->rssi
;
2333 data
.ssp_mode
= 0x01;
2334 hci_inquiry_cache_update(hdev
, &data
);
2335 mgmt_device_found(hdev
->id
, &info
->bdaddr
, info
->dev_class
,
2336 info
->rssi
, info
->data
);
2339 hci_dev_unlock(hdev
);
2342 static inline u8
hci_get_auth_req(struct hci_conn
*conn
)
2344 /* If remote requests dedicated bonding follow that lead */
2345 if (conn
->remote_auth
== 0x02 || conn
->remote_auth
== 0x03) {
2346 /* If both remote and local IO capabilities allow MITM
2347 * protection then require it, otherwise don't */
2348 if (conn
->remote_cap
== 0x03 || conn
->io_capability
== 0x03)
2354 /* If remote requests no-bonding follow that lead */
2355 if (conn
->remote_auth
== 0x00 || conn
->remote_auth
== 0x01)
2358 return conn
->auth_type
;
2361 static inline void hci_io_capa_request_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2363 struct hci_ev_io_capa_request
*ev
= (void *) skb
->data
;
2364 struct hci_conn
*conn
;
2366 BT_DBG("%s", hdev
->name
);
2370 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &ev
->bdaddr
);
2374 hci_conn_hold(conn
);
2376 if (!test_bit(HCI_MGMT
, &hdev
->flags
))
2379 if (test_bit(HCI_PAIRABLE
, &hdev
->flags
) ||
2380 (conn
->remote_auth
& ~0x01) == HCI_AT_NO_BONDING
) {
2381 struct hci_cp_io_capability_reply cp
;
2383 bacpy(&cp
.bdaddr
, &ev
->bdaddr
);
2384 cp
.capability
= conn
->io_capability
;
2385 cp
.authentication
= hci_get_auth_req(conn
);
2387 if ((conn
->out
== 0x01 || conn
->remote_oob
== 0x01) &&
2388 hci_find_remote_oob_data(hdev
, &conn
->dst
))
2393 hci_send_cmd(hdev
, HCI_OP_IO_CAPABILITY_REPLY
,
2396 struct hci_cp_io_capability_neg_reply cp
;
2398 bacpy(&cp
.bdaddr
, &ev
->bdaddr
);
2399 cp
.reason
= 0x16; /* Pairing not allowed */
2401 hci_send_cmd(hdev
, HCI_OP_IO_CAPABILITY_NEG_REPLY
,
2406 hci_dev_unlock(hdev
);
2409 static inline void hci_io_capa_reply_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2411 struct hci_ev_io_capa_reply
*ev
= (void *) skb
->data
;
2412 struct hci_conn
*conn
;
2414 BT_DBG("%s", hdev
->name
);
2418 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &ev
->bdaddr
);
2422 conn
->remote_cap
= ev
->capability
;
2423 conn
->remote_oob
= ev
->oob_data
;
2424 conn
->remote_auth
= ev
->authentication
;
2427 hci_dev_unlock(hdev
);
2430 static inline void hci_user_confirm_request_evt(struct hci_dev
*hdev
,
2431 struct sk_buff
*skb
)
2433 struct hci_ev_user_confirm_req
*ev
= (void *) skb
->data
;
2435 BT_DBG("%s", hdev
->name
);
2439 if (test_bit(HCI_MGMT
, &hdev
->flags
))
2440 mgmt_user_confirm_request(hdev
->id
, &ev
->bdaddr
, ev
->passkey
);
2442 hci_dev_unlock(hdev
);
2445 static inline void hci_simple_pair_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2447 struct hci_ev_simple_pair_complete
*ev
= (void *) skb
->data
;
2448 struct hci_conn
*conn
;
2450 BT_DBG("%s", hdev
->name
);
2454 conn
= hci_conn_hash_lookup_ba(hdev
, ACL_LINK
, &ev
->bdaddr
);
2458 /* To avoid duplicate auth_failed events to user space we check
2459 * the HCI_CONN_AUTH_PEND flag which will be set if we
2460 * initiated the authentication. A traditional auth_complete
2461 * event gets always produced as initiator and is also mapped to
2462 * the mgmt_auth_failed event */
2463 if (!test_bit(HCI_CONN_AUTH_PEND
, &conn
->pend
) && ev
->status
!= 0)
2464 mgmt_auth_failed(hdev
->id
, &conn
->dst
, ev
->status
);
2469 hci_dev_unlock(hdev
);
2472 static inline void hci_remote_host_features_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2474 struct hci_ev_remote_host_features
*ev
= (void *) skb
->data
;
2475 struct inquiry_entry
*ie
;
2477 BT_DBG("%s", hdev
->name
);
2481 ie
= hci_inquiry_cache_lookup(hdev
, &ev
->bdaddr
);
2483 ie
->data
.ssp_mode
= (ev
->features
[0] & 0x01);
2485 hci_dev_unlock(hdev
);
2488 static inline void hci_remote_oob_data_request_evt(struct hci_dev
*hdev
,
2489 struct sk_buff
*skb
)
2491 struct hci_ev_remote_oob_data_request
*ev
= (void *) skb
->data
;
2492 struct oob_data
*data
;
2494 BT_DBG("%s", hdev
->name
);
2498 if (!test_bit(HCI_MGMT
, &hdev
->flags
))
2501 data
= hci_find_remote_oob_data(hdev
, &ev
->bdaddr
);
2503 struct hci_cp_remote_oob_data_reply cp
;
2505 bacpy(&cp
.bdaddr
, &ev
->bdaddr
);
2506 memcpy(cp
.hash
, data
->hash
, sizeof(cp
.hash
));
2507 memcpy(cp
.randomizer
, data
->randomizer
, sizeof(cp
.randomizer
));
2509 hci_send_cmd(hdev
, HCI_OP_REMOTE_OOB_DATA_REPLY
, sizeof(cp
),
2512 struct hci_cp_remote_oob_data_neg_reply cp
;
2514 bacpy(&cp
.bdaddr
, &ev
->bdaddr
);
2515 hci_send_cmd(hdev
, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY
, sizeof(cp
),
2520 hci_dev_unlock(hdev
);
2523 static inline void hci_le_conn_complete_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2525 struct hci_ev_le_conn_complete
*ev
= (void *) skb
->data
;
2526 struct hci_conn
*conn
;
2528 BT_DBG("%s status %d", hdev
->name
, ev
->status
);
2532 conn
= hci_conn_hash_lookup_ba(hdev
, LE_LINK
, &ev
->bdaddr
);
2534 conn
= hci_conn_add(hdev
, LE_LINK
, &ev
->bdaddr
);
2536 BT_ERR("No memory for new connection");
2537 hci_dev_unlock(hdev
);
2543 hci_proto_connect_cfm(conn
, ev
->status
);
2544 conn
->state
= BT_CLOSED
;
2549 conn
->handle
= __le16_to_cpu(ev
->handle
);
2550 conn
->state
= BT_CONNECTED
;
2552 hci_conn_hold_device(conn
);
2553 hci_conn_add_sysfs(conn
);
2555 hci_proto_connect_cfm(conn
, ev
->status
);
2558 hci_dev_unlock(hdev
);
2561 static inline void hci_le_meta_evt(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2563 struct hci_ev_le_meta
*le_ev
= (void *) skb
->data
;
2565 skb_pull(skb
, sizeof(*le_ev
));
2567 switch (le_ev
->subevent
) {
2568 case HCI_EV_LE_CONN_COMPLETE
:
2569 hci_le_conn_complete_evt(hdev
, skb
);
2577 void hci_event_packet(struct hci_dev
*hdev
, struct sk_buff
*skb
)
2579 struct hci_event_hdr
*hdr
= (void *) skb
->data
;
2580 __u8 event
= hdr
->evt
;
2582 skb_pull(skb
, HCI_EVENT_HDR_SIZE
);
2585 case HCI_EV_INQUIRY_COMPLETE
:
2586 hci_inquiry_complete_evt(hdev
, skb
);
2589 case HCI_EV_INQUIRY_RESULT
:
2590 hci_inquiry_result_evt(hdev
, skb
);
2593 case HCI_EV_CONN_COMPLETE
:
2594 hci_conn_complete_evt(hdev
, skb
);
2597 case HCI_EV_CONN_REQUEST
:
2598 hci_conn_request_evt(hdev
, skb
);
2601 case HCI_EV_DISCONN_COMPLETE
:
2602 hci_disconn_complete_evt(hdev
, skb
);
2605 case HCI_EV_AUTH_COMPLETE
:
2606 hci_auth_complete_evt(hdev
, skb
);
2609 case HCI_EV_REMOTE_NAME
:
2610 hci_remote_name_evt(hdev
, skb
);
2613 case HCI_EV_ENCRYPT_CHANGE
:
2614 hci_encrypt_change_evt(hdev
, skb
);
2617 case HCI_EV_CHANGE_LINK_KEY_COMPLETE
:
2618 hci_change_link_key_complete_evt(hdev
, skb
);
2621 case HCI_EV_REMOTE_FEATURES
:
2622 hci_remote_features_evt(hdev
, skb
);
2625 case HCI_EV_REMOTE_VERSION
:
2626 hci_remote_version_evt(hdev
, skb
);
2629 case HCI_EV_QOS_SETUP_COMPLETE
:
2630 hci_qos_setup_complete_evt(hdev
, skb
);
2633 case HCI_EV_CMD_COMPLETE
:
2634 hci_cmd_complete_evt(hdev
, skb
);
2637 case HCI_EV_CMD_STATUS
:
2638 hci_cmd_status_evt(hdev
, skb
);
2641 case HCI_EV_ROLE_CHANGE
:
2642 hci_role_change_evt(hdev
, skb
);
2645 case HCI_EV_NUM_COMP_PKTS
:
2646 hci_num_comp_pkts_evt(hdev
, skb
);
2649 case HCI_EV_MODE_CHANGE
:
2650 hci_mode_change_evt(hdev
, skb
);
2653 case HCI_EV_PIN_CODE_REQ
:
2654 hci_pin_code_request_evt(hdev
, skb
);
2657 case HCI_EV_LINK_KEY_REQ
:
2658 hci_link_key_request_evt(hdev
, skb
);
2661 case HCI_EV_LINK_KEY_NOTIFY
:
2662 hci_link_key_notify_evt(hdev
, skb
);
2665 case HCI_EV_CLOCK_OFFSET
:
2666 hci_clock_offset_evt(hdev
, skb
);
2669 case HCI_EV_PKT_TYPE_CHANGE
:
2670 hci_pkt_type_change_evt(hdev
, skb
);
2673 case HCI_EV_PSCAN_REP_MODE
:
2674 hci_pscan_rep_mode_evt(hdev
, skb
);
2677 case HCI_EV_INQUIRY_RESULT_WITH_RSSI
:
2678 hci_inquiry_result_with_rssi_evt(hdev
, skb
);
2681 case HCI_EV_REMOTE_EXT_FEATURES
:
2682 hci_remote_ext_features_evt(hdev
, skb
);
2685 case HCI_EV_SYNC_CONN_COMPLETE
:
2686 hci_sync_conn_complete_evt(hdev
, skb
);
2689 case HCI_EV_SYNC_CONN_CHANGED
:
2690 hci_sync_conn_changed_evt(hdev
, skb
);
2693 case HCI_EV_SNIFF_SUBRATE
:
2694 hci_sniff_subrate_evt(hdev
, skb
);
2697 case HCI_EV_EXTENDED_INQUIRY_RESULT
:
2698 hci_extended_inquiry_result_evt(hdev
, skb
);
2701 case HCI_EV_IO_CAPA_REQUEST
:
2702 hci_io_capa_request_evt(hdev
, skb
);
2705 case HCI_EV_IO_CAPA_REPLY
:
2706 hci_io_capa_reply_evt(hdev
, skb
);
2709 case HCI_EV_USER_CONFIRM_REQUEST
:
2710 hci_user_confirm_request_evt(hdev
, skb
);
2713 case HCI_EV_SIMPLE_PAIR_COMPLETE
:
2714 hci_simple_pair_complete_evt(hdev
, skb
);
2717 case HCI_EV_REMOTE_HOST_FEATURES
:
2718 hci_remote_host_features_evt(hdev
, skb
);
2721 case HCI_EV_LE_META
:
2722 hci_le_meta_evt(hdev
, skb
);
2725 case HCI_EV_REMOTE_OOB_DATA_REQUEST
:
2726 hci_remote_oob_data_request_evt(hdev
, skb
);
2730 BT_DBG("%s event 0x%x", hdev
->name
, event
);
2735 hdev
->stat
.evt_rx
++;
2738 /* Generate internal stack event */
2739 void hci_si_event(struct hci_dev
*hdev
, int type
, int dlen
, void *data
)
2741 struct hci_event_hdr
*hdr
;
2742 struct hci_ev_stack_internal
*ev
;
2743 struct sk_buff
*skb
;
2745 skb
= bt_skb_alloc(HCI_EVENT_HDR_SIZE
+ sizeof(*ev
) + dlen
, GFP_ATOMIC
);
2749 hdr
= (void *) skb_put(skb
, HCI_EVENT_HDR_SIZE
);
2750 hdr
->evt
= HCI_EV_STACK_INTERNAL
;
2751 hdr
->plen
= sizeof(*ev
) + dlen
;
2753 ev
= (void *) skb_put(skb
, sizeof(*ev
) + dlen
);
2755 memcpy(ev
->data
, data
, dlen
);
2757 bt_cb(skb
)->incoming
= 1;
2758 __net_timestamp(skb
);
2760 bt_cb(skb
)->pkt_type
= HCI_EVENT_PKT
;
2761 skb
->dev
= (void *) hdev
;
2762 hci_send_to_sock(hdev
, skb
, NULL
);