YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | BlueZ - Bluetooth protocol stack for Linux |
Ron Shaffer | 2d0a034 | 2010-05-28 11:53:46 -0400 | [diff] [blame] | 3 | Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | |
| 5 | Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License version 2 as |
| 9 | published by the Free Software Foundation; |
| 10 | |
| 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 12 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 13 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. |
| 14 | IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 15 | CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES |
| 16 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 17 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 19 | |
YOSHIFUJI Hideaki | 8e87d14 | 2007-02-09 23:24:33 +0900 | [diff] [blame] | 20 | ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, |
| 21 | COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | SOFTWARE IS DISCLAIMED. |
| 23 | */ |
| 24 | |
| 25 | /* Bluetooth HCI event handling. */ |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/unaligned.h> |
| 28 | |
| 29 | #include <net/bluetooth/bluetooth.h> |
| 30 | #include <net/bluetooth/hci_core.h> |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 31 | #include <net/bluetooth/mgmt.h> |
Marcel Holtmann | 7ef9fbf | 2013-10-10 14:54:14 -0700 | [diff] [blame] | 32 | |
Johan Hedberg | 0857dd3 | 2014-12-19 13:40:20 +0200 | [diff] [blame] | 33 | #include "hci_request.h" |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 34 | #include "hci_debugfs.h" |
Marcel Holtmann | 7024728 | 2013-10-10 14:54:15 -0700 | [diff] [blame] | 35 | #include "a2mp.h" |
Marcel Holtmann | 7ef9fbf | 2013-10-10 14:54:14 -0700 | [diff] [blame] | 36 | #include "amp.h" |
Johan Hedberg | 2ceba53 | 2014-06-16 19:25:16 +0300 | [diff] [blame] | 37 | #include "smp.h" |
Miao-chen Chou | 145373c | 2020-04-03 21:44:01 +0200 | [diff] [blame] | 38 | #include "msft.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Marcel Holtmann | aa5b034 | 2015-01-27 16:04:33 -0800 | [diff] [blame] | 40 | #define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ |
| 41 | "\x00\x00\x00\x00\x00\x00\x00\x00" |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /* Handle HCI Event packets */ |
| 44 | |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 45 | static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb, |
| 46 | u8 *new_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 48 | __u8 status = *((__u8 *) skb->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 50 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 52 | /* It is possible that we receive Inquiry Complete event right |
| 53 | * before we receive Inquiry Cancel Command Complete event, in |
| 54 | * which case the latter event should have status of Command |
| 55 | * Disallowed (0x0c). This should not be treated as error, since |
| 56 | * we actually achieve what Inquiry Cancel wants to achieve, |
| 57 | * which is to end the last Inquiry session. |
| 58 | */ |
| 59 | if (status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) { |
| 60 | bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command"); |
| 61 | status = 0x00; |
| 62 | } |
| 63 | |
| 64 | *new_status = status; |
| 65 | |
Andre Guedes | 82f4785 | 2013-04-30 15:29:34 -0300 | [diff] [blame] | 66 | if (status) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 67 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 69 | clear_bit(HCI_INQUIRY, &hdev->flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 70 | smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */ |
Andre Guedes | 3e13fa1 | 2013-03-27 20:04:56 -0300 | [diff] [blame] | 71 | wake_up_bit(&hdev->flags, HCI_INQUIRY); |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 72 | |
Johan Hedberg | 50143a4 | 2014-06-10 14:05:57 +0300 | [diff] [blame] | 73 | hci_dev_lock(hdev); |
Jakub Pawlowski | 168b8a2 | 2015-10-16 10:07:49 +0300 | [diff] [blame] | 74 | /* Set discovery state to stopped if we're not doing LE active |
| 75 | * scanning. |
| 76 | */ |
| 77 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 78 | hdev->le_scan_type != LE_SCAN_ACTIVE) |
| 79 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 50143a4 | 2014-06-10 14:05:57 +0300 | [diff] [blame] | 80 | hci_dev_unlock(hdev); |
| 81 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 82 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 85 | static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb) |
| 86 | { |
| 87 | __u8 status = *((__u8 *) skb->data); |
| 88 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 89 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 90 | |
| 91 | if (status) |
| 92 | return; |
| 93 | |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 94 | hci_dev_set_flag(hdev, HCI_PERIODIC_INQ); |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 95 | } |
| 96 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 97 | static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 99 | __u8 status = *((__u8 *) skb->data); |
| 100 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 101 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 102 | |
| 103 | if (status) |
| 104 | return; |
| 105 | |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 106 | hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 107 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 108 | hci_conn_check_pending(hdev); |
| 109 | } |
| 110 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 111 | static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, |
| 112 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 113 | { |
| 114 | BT_DBG("%s", hdev->name); |
| 115 | } |
| 116 | |
| 117 | static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb) |
| 118 | { |
| 119 | struct hci_rp_role_discovery *rp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 122 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 124 | if (rp->status) |
| 125 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 127 | hci_dev_lock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 129 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 130 | if (conn) |
| 131 | conn->role = rp->role; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 132 | |
| 133 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 136 | static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
| 137 | { |
| 138 | struct hci_rp_read_link_policy *rp = (void *) skb->data; |
| 139 | struct hci_conn *conn; |
| 140 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 141 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 142 | |
| 143 | if (rp->status) |
| 144 | return; |
| 145 | |
| 146 | hci_dev_lock(hdev); |
| 147 | |
| 148 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 149 | if (conn) |
| 150 | conn->link_policy = __le16_to_cpu(rp->policy); |
| 151 | |
| 152 | hci_dev_unlock(hdev); |
| 153 | } |
| 154 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 155 | static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 157 | struct hci_rp_write_link_policy *rp = (void *) skb->data; |
| 158 | struct hci_conn *conn; |
| 159 | void *sent; |
| 160 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 161 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 162 | |
| 163 | if (rp->status) |
| 164 | return; |
| 165 | |
| 166 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY); |
| 167 | if (!sent) |
| 168 | return; |
| 169 | |
| 170 | hci_dev_lock(hdev); |
| 171 | |
| 172 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 173 | if (conn) |
Harvey Harrison | 8398531 | 2008-05-02 16:25:46 -0700 | [diff] [blame] | 174 | conn->link_policy = get_unaligned_le16(sent + 2); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 175 | |
| 176 | hci_dev_unlock(hdev); |
| 177 | } |
| 178 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 179 | static void hci_cc_read_def_link_policy(struct hci_dev *hdev, |
| 180 | struct sk_buff *skb) |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 181 | { |
| 182 | struct hci_rp_read_def_link_policy *rp = (void *) skb->data; |
| 183 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 184 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 185 | |
| 186 | if (rp->status) |
| 187 | return; |
| 188 | |
| 189 | hdev->link_policy = __le16_to_cpu(rp->policy); |
| 190 | } |
| 191 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 192 | static void hci_cc_write_def_link_policy(struct hci_dev *hdev, |
| 193 | struct sk_buff *skb) |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 194 | { |
| 195 | __u8 status = *((__u8 *) skb->data); |
| 196 | void *sent; |
| 197 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 198 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 199 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 200 | if (status) |
| 201 | return; |
| 202 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 203 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY); |
| 204 | if (!sent) |
| 205 | return; |
| 206 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 207 | hdev->link_policy = get_unaligned_le16(sent); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 210 | static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) |
| 211 | { |
| 212 | __u8 status = *((__u8 *) skb->data); |
| 213 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 214 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 215 | |
Gustavo F. Padovan | 1057213 | 2011-03-16 15:36:29 -0300 | [diff] [blame] | 216 | clear_bit(HCI_RESET, &hdev->flags); |
| 217 | |
Marcel Holtmann | 8761f9d | 2014-11-02 02:45:58 +0100 | [diff] [blame] | 218 | if (status) |
| 219 | return; |
| 220 | |
Johan Hedberg | a297e97 | 2012-02-21 17:55:47 +0200 | [diff] [blame] | 221 | /* Reset all non-persistent flags */ |
Marcel Holtmann | eacb44d | 2015-03-13 09:04:17 -0700 | [diff] [blame] | 222 | hci_dev_clear_volatile_flags(hdev); |
Andre Guedes | 69775ff | 2012-02-23 16:50:05 +0200 | [diff] [blame] | 223 | |
Johan Hedberg | 39c5d97 | 2015-01-28 19:56:01 +0200 | [diff] [blame] | 224 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 225 | |
Johan Hedberg | bbaf444 | 2012-11-08 01:22:59 +0100 | [diff] [blame] | 226 | hdev->inq_tx_power = HCI_TX_POWER_INVALID; |
| 227 | hdev->adv_tx_power = HCI_TX_POWER_INVALID; |
Johan Hedberg | 3f0f524 | 2012-11-08 01:23:00 +0100 | [diff] [blame] | 228 | |
| 229 | memset(hdev->adv_data, 0, sizeof(hdev->adv_data)); |
| 230 | hdev->adv_data_len = 0; |
Marcel Holtmann | f8e808b | 2013-10-16 00:16:47 -0700 | [diff] [blame] | 231 | |
| 232 | memset(hdev->scan_rsp_data, 0, sizeof(hdev->scan_rsp_data)); |
| 233 | hdev->scan_rsp_data_len = 0; |
Marcel Holtmann | 06f5b77 | 2013-10-19 07:09:11 -0700 | [diff] [blame] | 234 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 235 | hdev->le_scan_type = LE_SCAN_PASSIVE; |
| 236 | |
Marcel Holtmann | 06f5b77 | 2013-10-19 07:09:11 -0700 | [diff] [blame] | 237 | hdev->ssp_debug_mode = 0; |
Marcel Holtmann | a4d5504 | 2014-10-29 23:37:53 +0100 | [diff] [blame] | 238 | |
| 239 | hci_bdaddr_list_clear(&hdev->le_white_list); |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 240 | hci_bdaddr_list_clear(&hdev->le_resolv_list); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 241 | } |
| 242 | |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 243 | static void hci_cc_read_stored_link_key(struct hci_dev *hdev, |
| 244 | struct sk_buff *skb) |
| 245 | { |
| 246 | struct hci_rp_read_stored_link_key *rp = (void *)skb->data; |
| 247 | struct hci_cp_read_stored_link_key *sent; |
| 248 | |
| 249 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 250 | |
| 251 | sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY); |
| 252 | if (!sent) |
| 253 | return; |
| 254 | |
| 255 | if (!rp->status && sent->read_all == 0x01) { |
| 256 | hdev->stored_max_keys = rp->max_keys; |
| 257 | hdev->stored_num_keys = rp->num_keys; |
| 258 | } |
| 259 | } |
| 260 | |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 261 | static void hci_cc_delete_stored_link_key(struct hci_dev *hdev, |
| 262 | struct sk_buff *skb) |
| 263 | { |
| 264 | struct hci_rp_delete_stored_link_key *rp = (void *)skb->data; |
| 265 | |
| 266 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 267 | |
| 268 | if (rp->status) |
| 269 | return; |
| 270 | |
| 271 | if (rp->num_keys <= hdev->stored_num_keys) |
| 272 | hdev->stored_num_keys -= rp->num_keys; |
| 273 | else |
| 274 | hdev->stored_num_keys = 0; |
| 275 | } |
| 276 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 277 | static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 278 | { |
| 279 | __u8 status = *((__u8 *) skb->data); |
| 280 | void *sent; |
| 281 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 282 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 283 | |
| 284 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME); |
| 285 | if (!sent) |
| 286 | return; |
| 287 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 288 | hci_dev_lock(hdev); |
| 289 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 290 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | f51d5b2 | 2012-02-22 18:17:32 +0200 | [diff] [blame] | 291 | mgmt_set_local_name_complete(hdev, sent, status); |
Johan Hedberg | 28cc7bd | 2012-02-22 21:06:55 +0200 | [diff] [blame] | 292 | else if (!status) |
| 293 | memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH); |
Johan Hedberg | f51d5b2 | 2012-02-22 18:17:32 +0200 | [diff] [blame] | 294 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 295 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 299 | { |
| 300 | struct hci_rp_read_local_name *rp = (void *) skb->data; |
| 301 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 302 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 303 | |
| 304 | if (rp->status) |
| 305 | return; |
| 306 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 307 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 308 | hci_dev_test_flag(hdev, HCI_CONFIG)) |
Johan Hedberg | db99b5f | 2012-02-22 20:14:22 +0200 | [diff] [blame] | 309 | memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 313 | { |
| 314 | __u8 status = *((__u8 *) skb->data); |
| 315 | void *sent; |
| 316 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 317 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 318 | |
| 319 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE); |
| 320 | if (!sent) |
| 321 | return; |
| 322 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 323 | hci_dev_lock(hdev); |
| 324 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 325 | if (!status) { |
| 326 | __u8 param = *((__u8 *) sent); |
| 327 | |
| 328 | if (param == AUTH_ENABLED) |
| 329 | set_bit(HCI_AUTH, &hdev->flags); |
| 330 | else |
| 331 | clear_bit(HCI_AUTH, &hdev->flags); |
| 332 | } |
| 333 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 334 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 33ef95e | 2012-02-16 23:56:27 +0200 | [diff] [blame] | 335 | mgmt_auth_enable_complete(hdev, status); |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 336 | |
| 337 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 341 | { |
| 342 | __u8 status = *((__u8 *) skb->data); |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 343 | __u8 param; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 344 | void *sent; |
| 345 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 346 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 347 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 348 | if (status) |
| 349 | return; |
| 350 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 351 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE); |
| 352 | if (!sent) |
| 353 | return; |
| 354 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 355 | param = *((__u8 *) sent); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 356 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 357 | if (param) |
| 358 | set_bit(HCI_ENCRYPT, &hdev->flags); |
| 359 | else |
| 360 | clear_bit(HCI_ENCRYPT, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 364 | { |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 365 | __u8 status = *((__u8 *) skb->data); |
| 366 | __u8 param; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 367 | void *sent; |
| 368 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 369 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 370 | |
| 371 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); |
| 372 | if (!sent) |
| 373 | return; |
| 374 | |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 375 | param = *((__u8 *) sent); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 376 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 377 | hci_dev_lock(hdev); |
| 378 | |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 379 | if (status) { |
Johan Hedberg | 2d7cee5 | 2011-11-07 22:16:03 +0200 | [diff] [blame] | 380 | hdev->discov_timeout = 0; |
| 381 | goto done; |
| 382 | } |
| 383 | |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 384 | if (param & SCAN_INQUIRY) |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 385 | set_bit(HCI_ISCAN, &hdev->flags); |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 386 | else |
| 387 | clear_bit(HCI_ISCAN, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 388 | |
Johan Hedberg | 031547d | 2014-07-10 12:09:06 +0300 | [diff] [blame] | 389 | if (param & SCAN_PAGE) |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 390 | set_bit(HCI_PSCAN, &hdev->flags); |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 391 | else |
Johan Hedberg | 204e399 | 2014-07-28 15:45:31 +0300 | [diff] [blame] | 392 | clear_bit(HCI_PSCAN, &hdev->flags); |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 393 | |
| 394 | done: |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 395 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 396 | } |
| 397 | |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 398 | static void hci_cc_set_event_filter(struct hci_dev *hdev, struct sk_buff *skb) |
| 399 | { |
| 400 | __u8 status = *((__u8 *)skb->data); |
| 401 | struct hci_cp_set_event_filter *cp; |
| 402 | void *sent; |
| 403 | |
| 404 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 405 | |
| 406 | if (status) |
| 407 | return; |
| 408 | |
| 409 | sent = hci_sent_cmd_data(hdev, HCI_OP_SET_EVENT_FLT); |
| 410 | if (!sent) |
| 411 | return; |
| 412 | |
| 413 | cp = (struct hci_cp_set_event_filter *)sent; |
| 414 | |
| 415 | if (cp->flt_type == HCI_FLT_CLEAR_ALL) |
| 416 | hci_dev_clear_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); |
| 417 | else |
| 418 | hci_dev_set_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); |
| 419 | } |
| 420 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 421 | static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 422 | { |
| 423 | struct hci_rp_read_class_of_dev *rp = (void *) skb->data; |
| 424 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 425 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 426 | |
| 427 | if (rp->status) |
| 428 | return; |
| 429 | |
| 430 | memcpy(hdev->dev_class, rp->dev_class, 3); |
| 431 | |
| 432 | BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 433 | hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 437 | { |
| 438 | __u8 status = *((__u8 *) skb->data); |
| 439 | void *sent; |
| 440 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 441 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 442 | |
| 443 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV); |
| 444 | if (!sent) |
| 445 | return; |
| 446 | |
Marcel Holtmann | 7f9a903 | 2012-02-22 18:38:01 +0100 | [diff] [blame] | 447 | hci_dev_lock(hdev); |
| 448 | |
| 449 | if (status == 0) |
| 450 | memcpy(hdev->dev_class, sent, 3); |
| 451 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 452 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Marcel Holtmann | 7f9a903 | 2012-02-22 18:38:01 +0100 | [diff] [blame] | 453 | mgmt_set_class_of_dev_complete(hdev, sent, status); |
| 454 | |
| 455 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) |
| 459 | { |
| 460 | struct hci_rp_read_voice_setting *rp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | __u16 setting; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 462 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 463 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 464 | |
| 465 | if (rp->status) |
| 466 | return; |
| 467 | |
| 468 | setting = __le16_to_cpu(rp->voice_setting); |
| 469 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 470 | if (hdev->voice_setting == setting) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 471 | return; |
| 472 | |
| 473 | hdev->voice_setting = setting; |
| 474 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 475 | BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 476 | |
Gustavo F. Padovan | 3c54711 | 2011-12-14 22:58:44 -0200 | [diff] [blame] | 477 | if (hdev->notify) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 478 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 479 | } |
| 480 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 481 | static void hci_cc_write_voice_setting(struct hci_dev *hdev, |
| 482 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 483 | { |
| 484 | __u8 status = *((__u8 *) skb->data); |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 485 | __u16 setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | void *sent; |
| 487 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 488 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 490 | if (status) |
| 491 | return; |
| 492 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 493 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING); |
| 494 | if (!sent) |
| 495 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 497 | setting = get_unaligned_le16(sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 499 | if (hdev->voice_setting == setting) |
| 500 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 502 | hdev->voice_setting = setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 504 | BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting); |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 505 | |
Gustavo F. Padovan | 3c54711 | 2011-12-14 22:58:44 -0200 | [diff] [blame] | 506 | if (hdev->notify) |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 507 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 510 | static void hci_cc_read_num_supported_iac(struct hci_dev *hdev, |
| 511 | struct sk_buff *skb) |
| 512 | { |
| 513 | struct hci_rp_read_num_supported_iac *rp = (void *) skb->data; |
| 514 | |
| 515 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 516 | |
| 517 | if (rp->status) |
| 518 | return; |
| 519 | |
| 520 | hdev->num_iac = rp->num_iac; |
| 521 | |
| 522 | BT_DBG("%s num iac %d", hdev->name, hdev->num_iac); |
| 523 | } |
| 524 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 525 | static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 526 | { |
| 527 | __u8 status = *((__u8 *) skb->data); |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 528 | struct hci_cp_write_ssp_mode *sent; |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 529 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 530 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 531 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 532 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); |
| 533 | if (!sent) |
| 534 | return; |
| 535 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 536 | hci_dev_lock(hdev); |
| 537 | |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 538 | if (!status) { |
| 539 | if (sent->mode) |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 540 | hdev->features[1][0] |= LMP_HOST_SSP; |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 541 | else |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 542 | hdev->features[1][0] &= ~LMP_HOST_SSP; |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 543 | } |
| 544 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 545 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 546 | mgmt_ssp_enable_complete(hdev, sent->mode, status); |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 547 | else if (!status) { |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 548 | if (sent->mode) |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 549 | hci_dev_set_flag(hdev, HCI_SSP_ENABLED); |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 550 | else |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 551 | hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 552 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 553 | |
| 554 | hci_dev_unlock(hdev); |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 555 | } |
| 556 | |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 557 | static void hci_cc_write_sc_support(struct hci_dev *hdev, struct sk_buff *skb) |
| 558 | { |
| 559 | u8 status = *((u8 *) skb->data); |
| 560 | struct hci_cp_write_sc_support *sent; |
| 561 | |
| 562 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 563 | |
| 564 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SC_SUPPORT); |
| 565 | if (!sent) |
| 566 | return; |
| 567 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 568 | hci_dev_lock(hdev); |
| 569 | |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 570 | if (!status) { |
| 571 | if (sent->support) |
| 572 | hdev->features[1][0] |= LMP_HOST_SC; |
| 573 | else |
| 574 | hdev->features[1][0] &= ~LMP_HOST_SC; |
| 575 | } |
| 576 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 577 | if (!hci_dev_test_flag(hdev, HCI_MGMT) && !status) { |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 578 | if (sent->support) |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 579 | hci_dev_set_flag(hdev, HCI_SC_ENABLED); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 580 | else |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 581 | hci_dev_clear_flag(hdev, HCI_SC_ENABLED); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 582 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 583 | |
| 584 | hci_dev_unlock(hdev); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 587 | static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) |
| 588 | { |
| 589 | struct hci_rp_read_local_version *rp = (void *) skb->data; |
| 590 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 591 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 592 | |
| 593 | if (rp->status) |
Johan Hedberg | 42c6b12 | 2013-03-05 20:37:49 +0200 | [diff] [blame] | 594 | return; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 595 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 596 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 597 | hci_dev_test_flag(hdev, HCI_CONFIG)) { |
Marcel Holtmann | 0d5551f | 2013-10-18 12:04:50 -0700 | [diff] [blame] | 598 | hdev->hci_ver = rp->hci_ver; |
| 599 | hdev->hci_rev = __le16_to_cpu(rp->hci_rev); |
| 600 | hdev->lmp_ver = rp->lmp_ver; |
| 601 | hdev->manufacturer = __le16_to_cpu(rp->manufacturer); |
| 602 | hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver); |
| 603 | } |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 604 | } |
| 605 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 606 | static void hci_cc_read_local_commands(struct hci_dev *hdev, |
| 607 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 608 | { |
| 609 | struct hci_rp_read_local_commands *rp = (void *) skb->data; |
| 610 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 611 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 612 | |
Marcel Holtmann | 6a070e6 | 2013-10-31 04:54:33 -0700 | [diff] [blame] | 613 | if (rp->status) |
| 614 | return; |
| 615 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 616 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 617 | hci_dev_test_flag(hdev, HCI_CONFIG)) |
Johan Hedberg | 2177bab | 2013-03-05 20:37:43 +0200 | [diff] [blame] | 618 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 619 | } |
| 620 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 621 | static void hci_cc_read_auth_payload_timeout(struct hci_dev *hdev, |
| 622 | struct sk_buff *skb) |
| 623 | { |
| 624 | struct hci_rp_read_auth_payload_to *rp = (void *)skb->data; |
| 625 | struct hci_conn *conn; |
| 626 | |
| 627 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 628 | |
| 629 | if (rp->status) |
| 630 | return; |
| 631 | |
| 632 | hci_dev_lock(hdev); |
| 633 | |
| 634 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 635 | if (conn) |
| 636 | conn->auth_payload_timeout = __le16_to_cpu(rp->timeout); |
| 637 | |
| 638 | hci_dev_unlock(hdev); |
| 639 | } |
| 640 | |
| 641 | static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev, |
| 642 | struct sk_buff *skb) |
| 643 | { |
| 644 | struct hci_rp_write_auth_payload_to *rp = (void *)skb->data; |
| 645 | struct hci_conn *conn; |
| 646 | void *sent; |
| 647 | |
| 648 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 649 | |
| 650 | if (rp->status) |
| 651 | return; |
| 652 | |
| 653 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO); |
| 654 | if (!sent) |
| 655 | return; |
| 656 | |
| 657 | hci_dev_lock(hdev); |
| 658 | |
| 659 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 660 | if (conn) |
| 661 | conn->auth_payload_timeout = get_unaligned_le16(sent + 2); |
| 662 | |
| 663 | hci_dev_unlock(hdev); |
| 664 | } |
| 665 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 666 | static void hci_cc_read_local_features(struct hci_dev *hdev, |
| 667 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 668 | { |
| 669 | struct hci_rp_read_local_features *rp = (void *) skb->data; |
| 670 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 671 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 672 | |
| 673 | if (rp->status) |
| 674 | return; |
| 675 | |
| 676 | memcpy(hdev->features, rp->features, 8); |
| 677 | |
| 678 | /* Adjust default settings according to features |
| 679 | * supported by device. */ |
| 680 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 681 | if (hdev->features[0][0] & LMP_3SLOT) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 682 | hdev->pkt_type |= (HCI_DM3 | HCI_DH3); |
| 683 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 684 | if (hdev->features[0][0] & LMP_5SLOT) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 685 | hdev->pkt_type |= (HCI_DM5 | HCI_DH5); |
| 686 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 687 | if (hdev->features[0][1] & LMP_HV2) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 688 | hdev->pkt_type |= (HCI_HV2); |
| 689 | hdev->esco_type |= (ESCO_HV2); |
| 690 | } |
| 691 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 692 | if (hdev->features[0][1] & LMP_HV3) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 693 | hdev->pkt_type |= (HCI_HV3); |
| 694 | hdev->esco_type |= (ESCO_HV3); |
| 695 | } |
| 696 | |
Andre Guedes | 45db810f | 2012-07-24 15:03:49 -0300 | [diff] [blame] | 697 | if (lmp_esco_capable(hdev)) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 698 | hdev->esco_type |= (ESCO_EV3); |
| 699 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 700 | if (hdev->features[0][4] & LMP_EV4) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 701 | hdev->esco_type |= (ESCO_EV4); |
| 702 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 703 | if (hdev->features[0][4] & LMP_EV5) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 704 | hdev->esco_type |= (ESCO_EV5); |
| 705 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 706 | if (hdev->features[0][5] & LMP_EDR_ESCO_2M) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 707 | hdev->esco_type |= (ESCO_2EV3); |
| 708 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 709 | if (hdev->features[0][5] & LMP_EDR_ESCO_3M) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 710 | hdev->esco_type |= (ESCO_3EV3); |
| 711 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 712 | if (hdev->features[0][5] & LMP_EDR_3S_ESCO) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 713 | hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 714 | } |
| 715 | |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 716 | static void hci_cc_read_local_ext_features(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 717 | struct sk_buff *skb) |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 718 | { |
| 719 | struct hci_rp_read_local_ext_features *rp = (void *) skb->data; |
| 720 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 721 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 722 | |
| 723 | if (rp->status) |
Johan Hedberg | 42c6b12 | 2013-03-05 20:37:49 +0200 | [diff] [blame] | 724 | return; |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 725 | |
Marcel Holtmann | 57af75a | 2013-10-18 12:04:47 -0700 | [diff] [blame] | 726 | if (hdev->max_page < rp->max_page) |
| 727 | hdev->max_page = rp->max_page; |
Johan Hedberg | d2c5d77 | 2013-04-17 15:00:52 +0300 | [diff] [blame] | 728 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 729 | if (rp->page < HCI_MAX_PAGES) |
| 730 | memcpy(hdev->features[rp->page], rp->features, 8); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 731 | } |
| 732 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 733 | static void hci_cc_read_flow_control_mode(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 734 | struct sk_buff *skb) |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 735 | { |
| 736 | struct hci_rp_read_flow_control_mode *rp = (void *) skb->data; |
| 737 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 738 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 739 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 740 | if (rp->status) |
| 741 | return; |
| 742 | |
| 743 | hdev->flow_ctl_mode = rp->mode; |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 744 | } |
| 745 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 746 | static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) |
| 747 | { |
| 748 | struct hci_rp_read_buffer_size *rp = (void *) skb->data; |
| 749 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 750 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 751 | |
| 752 | if (rp->status) |
| 753 | return; |
| 754 | |
| 755 | hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu); |
| 756 | hdev->sco_mtu = rp->sco_mtu; |
| 757 | hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt); |
| 758 | hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt); |
| 759 | |
| 760 | if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) { |
| 761 | hdev->sco_mtu = 64; |
| 762 | hdev->sco_pkts = 8; |
| 763 | } |
| 764 | |
| 765 | hdev->acl_cnt = hdev->acl_pkts; |
| 766 | hdev->sco_cnt = hdev->sco_pkts; |
| 767 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 768 | BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu, |
| 769 | hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb) |
| 773 | { |
| 774 | struct hci_rp_read_bd_addr *rp = (void *) skb->data; |
| 775 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 776 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 777 | |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 778 | if (rp->status) |
| 779 | return; |
| 780 | |
| 781 | if (test_bit(HCI_INIT, &hdev->flags)) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 782 | bacpy(&hdev->bdaddr, &rp->bdaddr); |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 783 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 784 | if (hci_dev_test_flag(hdev, HCI_SETUP)) |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 785 | bacpy(&hdev->setup_addr, &rp->bdaddr); |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 786 | } |
| 787 | |
Marcel Holtmann | a479036 | 2020-04-03 21:44:04 +0200 | [diff] [blame] | 788 | static void hci_cc_read_local_pairing_opts(struct hci_dev *hdev, |
| 789 | struct sk_buff *skb) |
| 790 | { |
| 791 | struct hci_rp_read_local_pairing_opts *rp = (void *) skb->data; |
| 792 | |
| 793 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 794 | |
| 795 | if (rp->status) |
| 796 | return; |
| 797 | |
| 798 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 799 | hci_dev_test_flag(hdev, HCI_CONFIG)) { |
| 800 | hdev->pairing_opts = rp->pairing_opts; |
| 801 | hdev->max_enc_key_size = rp->max_key_size; |
| 802 | } |
| 803 | } |
| 804 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 805 | static void hci_cc_read_page_scan_activity(struct hci_dev *hdev, |
| 806 | struct sk_buff *skb) |
| 807 | { |
| 808 | struct hci_rp_read_page_scan_activity *rp = (void *) skb->data; |
| 809 | |
| 810 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 811 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 812 | if (rp->status) |
| 813 | return; |
| 814 | |
| 815 | if (test_bit(HCI_INIT, &hdev->flags)) { |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 816 | hdev->page_scan_interval = __le16_to_cpu(rp->interval); |
| 817 | hdev->page_scan_window = __le16_to_cpu(rp->window); |
| 818 | } |
| 819 | } |
| 820 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 821 | static void hci_cc_write_page_scan_activity(struct hci_dev *hdev, |
| 822 | struct sk_buff *skb) |
| 823 | { |
| 824 | u8 status = *((u8 *) skb->data); |
| 825 | struct hci_cp_write_page_scan_activity *sent; |
| 826 | |
| 827 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 828 | |
| 829 | if (status) |
| 830 | return; |
| 831 | |
| 832 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY); |
| 833 | if (!sent) |
| 834 | return; |
| 835 | |
| 836 | hdev->page_scan_interval = __le16_to_cpu(sent->interval); |
| 837 | hdev->page_scan_window = __le16_to_cpu(sent->window); |
| 838 | } |
| 839 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 840 | static void hci_cc_read_page_scan_type(struct hci_dev *hdev, |
| 841 | struct sk_buff *skb) |
| 842 | { |
| 843 | struct hci_rp_read_page_scan_type *rp = (void *) skb->data; |
| 844 | |
| 845 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 846 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 847 | if (rp->status) |
| 848 | return; |
| 849 | |
| 850 | if (test_bit(HCI_INIT, &hdev->flags)) |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 851 | hdev->page_scan_type = rp->type; |
| 852 | } |
| 853 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 854 | static void hci_cc_write_page_scan_type(struct hci_dev *hdev, |
| 855 | struct sk_buff *skb) |
| 856 | { |
| 857 | u8 status = *((u8 *) skb->data); |
| 858 | u8 *type; |
| 859 | |
| 860 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 861 | |
| 862 | if (status) |
| 863 | return; |
| 864 | |
| 865 | type = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE); |
| 866 | if (type) |
| 867 | hdev->page_scan_type = *type; |
| 868 | } |
| 869 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 870 | static void hci_cc_read_data_block_size(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 871 | struct sk_buff *skb) |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 872 | { |
| 873 | struct hci_rp_read_data_block_size *rp = (void *) skb->data; |
| 874 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 875 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 876 | |
| 877 | if (rp->status) |
| 878 | return; |
| 879 | |
| 880 | hdev->block_mtu = __le16_to_cpu(rp->max_acl_len); |
| 881 | hdev->block_len = __le16_to_cpu(rp->block_len); |
| 882 | hdev->num_blocks = __le16_to_cpu(rp->num_blocks); |
| 883 | |
| 884 | hdev->block_cnt = hdev->num_blocks; |
| 885 | |
| 886 | BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 887 | hdev->block_cnt, hdev->block_len); |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 888 | } |
| 889 | |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 890 | static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb) |
| 891 | { |
| 892 | struct hci_rp_read_clock *rp = (void *) skb->data; |
| 893 | struct hci_cp_read_clock *cp; |
| 894 | struct hci_conn *conn; |
| 895 | |
| 896 | BT_DBG("%s", hdev->name); |
| 897 | |
| 898 | if (skb->len < sizeof(*rp)) |
| 899 | return; |
| 900 | |
| 901 | if (rp->status) |
| 902 | return; |
| 903 | |
| 904 | hci_dev_lock(hdev); |
| 905 | |
| 906 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK); |
| 907 | if (!cp) |
| 908 | goto unlock; |
| 909 | |
| 910 | if (cp->which == 0x00) { |
| 911 | hdev->clock = le32_to_cpu(rp->clock); |
| 912 | goto unlock; |
| 913 | } |
| 914 | |
| 915 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 916 | if (conn) { |
| 917 | conn->clock = le32_to_cpu(rp->clock); |
| 918 | conn->clock_accuracy = le16_to_cpu(rp->accuracy); |
| 919 | } |
| 920 | |
| 921 | unlock: |
| 922 | hci_dev_unlock(hdev); |
| 923 | } |
| 924 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 925 | static void hci_cc_read_local_amp_info(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 926 | struct sk_buff *skb) |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 927 | { |
| 928 | struct hci_rp_read_local_amp_info *rp = (void *) skb->data; |
| 929 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 930 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 931 | |
| 932 | if (rp->status) |
Arron Wang | 8392788 | 2015-07-24 17:10:16 +0800 | [diff] [blame] | 933 | return; |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 934 | |
| 935 | hdev->amp_status = rp->amp_status; |
| 936 | hdev->amp_total_bw = __le32_to_cpu(rp->total_bw); |
| 937 | hdev->amp_max_bw = __le32_to_cpu(rp->max_bw); |
| 938 | hdev->amp_min_latency = __le32_to_cpu(rp->min_latency); |
| 939 | hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu); |
| 940 | hdev->amp_type = rp->amp_type; |
| 941 | hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap); |
| 942 | hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size); |
| 943 | hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to); |
| 944 | hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to); |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 945 | } |
| 946 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 947 | static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 948 | struct sk_buff *skb) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 949 | { |
Marcel Holtmann | 91c4e9b | 2012-03-11 19:27:21 -0700 | [diff] [blame] | 950 | struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 951 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 952 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 953 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 954 | if (rp->status) |
| 955 | return; |
| 956 | |
| 957 | hdev->inq_tx_power = rp->tx_power; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 958 | } |
| 959 | |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 960 | static void hci_cc_read_def_err_data_reporting(struct hci_dev *hdev, |
| 961 | struct sk_buff *skb) |
| 962 | { |
| 963 | struct hci_rp_read_def_err_data_reporting *rp = (void *)skb->data; |
| 964 | |
| 965 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 966 | |
| 967 | if (rp->status) |
| 968 | return; |
| 969 | |
| 970 | hdev->err_data_reporting = rp->err_data_reporting; |
| 971 | } |
| 972 | |
| 973 | static void hci_cc_write_def_err_data_reporting(struct hci_dev *hdev, |
| 974 | struct sk_buff *skb) |
| 975 | { |
| 976 | __u8 status = *((__u8 *)skb->data); |
| 977 | struct hci_cp_write_def_err_data_reporting *cp; |
| 978 | |
| 979 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 980 | |
| 981 | if (status) |
| 982 | return; |
| 983 | |
| 984 | cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING); |
| 985 | if (!cp) |
| 986 | return; |
| 987 | |
| 988 | hdev->err_data_reporting = cp->err_data_reporting; |
| 989 | } |
| 990 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 991 | static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 992 | { |
| 993 | struct hci_rp_pin_code_reply *rp = (void *) skb->data; |
| 994 | struct hci_cp_pin_code_reply *cp; |
| 995 | struct hci_conn *conn; |
| 996 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 997 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 998 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 999 | hci_dev_lock(hdev); |
| 1000 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1001 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1002 | mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1003 | |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 1004 | if (rp->status) |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1005 | goto unlock; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1006 | |
| 1007 | cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY); |
| 1008 | if (!cp) |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1009 | goto unlock; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1010 | |
| 1011 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 1012 | if (conn) |
| 1013 | conn->pin_length = cp->pin_len; |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1014 | |
| 1015 | unlock: |
| 1016 | hci_dev_unlock(hdev); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1020 | { |
| 1021 | struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data; |
| 1022 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1023 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1024 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1025 | hci_dev_lock(hdev); |
| 1026 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1027 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1028 | mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1029 | rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1030 | |
| 1031 | hci_dev_unlock(hdev); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1032 | } |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1033 | |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 1034 | static void hci_cc_le_read_buffer_size(struct hci_dev *hdev, |
| 1035 | struct sk_buff *skb) |
| 1036 | { |
| 1037 | struct hci_rp_le_read_buffer_size *rp = (void *) skb->data; |
| 1038 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1039 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 1040 | |
| 1041 | if (rp->status) |
| 1042 | return; |
| 1043 | |
| 1044 | hdev->le_mtu = __le16_to_cpu(rp->le_mtu); |
| 1045 | hdev->le_pkts = rp->le_max_pkt; |
| 1046 | |
| 1047 | hdev->le_cnt = hdev->le_pkts; |
| 1048 | |
| 1049 | BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts); |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 1050 | } |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1051 | |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 1052 | static void hci_cc_le_read_local_features(struct hci_dev *hdev, |
| 1053 | struct sk_buff *skb) |
| 1054 | { |
| 1055 | struct hci_rp_le_read_local_features *rp = (void *) skb->data; |
| 1056 | |
| 1057 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1058 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1059 | if (rp->status) |
| 1060 | return; |
| 1061 | |
| 1062 | memcpy(hdev->le_features, rp->features, 8); |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 1063 | } |
| 1064 | |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 1065 | static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev, |
| 1066 | struct sk_buff *skb) |
| 1067 | { |
| 1068 | struct hci_rp_le_read_adv_tx_power *rp = (void *) skb->data; |
| 1069 | |
| 1070 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1071 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1072 | if (rp->status) |
| 1073 | return; |
| 1074 | |
| 1075 | hdev->adv_tx_power = rp->tx_power; |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 1076 | } |
| 1077 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1078 | static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1079 | { |
| 1080 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1081 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1082 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1083 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1084 | hci_dev_lock(hdev); |
| 1085 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1086 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1087 | mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0, |
| 1088 | rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1089 | |
| 1090 | hci_dev_unlock(hdev); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1094 | struct sk_buff *skb) |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1095 | { |
| 1096 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1097 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1098 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1099 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1100 | hci_dev_lock(hdev); |
| 1101 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1102 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1103 | mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1104 | ACL_LINK, 0, rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1105 | |
| 1106 | hci_dev_unlock(hdev); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1107 | } |
| 1108 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1109 | static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1110 | { |
| 1111 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1112 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1113 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1114 | |
| 1115 | hci_dev_lock(hdev); |
| 1116 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1117 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1118 | mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1119 | 0, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1120 | |
| 1121 | hci_dev_unlock(hdev); |
| 1122 | } |
| 1123 | |
| 1124 | static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1125 | struct sk_buff *skb) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1126 | { |
| 1127 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1128 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1129 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1130 | |
| 1131 | hci_dev_lock(hdev); |
| 1132 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1133 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1134 | mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1135 | ACL_LINK, 0, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1136 | |
| 1137 | hci_dev_unlock(hdev); |
| 1138 | } |
| 1139 | |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 1140 | static void hci_cc_read_local_oob_data(struct hci_dev *hdev, |
| 1141 | struct sk_buff *skb) |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1142 | { |
| 1143 | struct hci_rp_read_local_oob_data *rp = (void *) skb->data; |
| 1144 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1145 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev, |
| 1149 | struct sk_buff *skb) |
| 1150 | { |
| 1151 | struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data; |
| 1152 | |
| 1153 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1154 | } |
| 1155 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1156 | static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb) |
| 1157 | { |
| 1158 | __u8 status = *((__u8 *) skb->data); |
| 1159 | bdaddr_t *sent; |
| 1160 | |
| 1161 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1162 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1163 | if (status) |
| 1164 | return; |
| 1165 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1166 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR); |
| 1167 | if (!sent) |
| 1168 | return; |
| 1169 | |
| 1170 | hci_dev_lock(hdev); |
| 1171 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1172 | bacpy(&hdev->random_addr, sent); |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1173 | |
| 1174 | hci_dev_unlock(hdev); |
| 1175 | } |
| 1176 | |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 1177 | static void hci_cc_le_set_default_phy(struct hci_dev *hdev, struct sk_buff *skb) |
| 1178 | { |
| 1179 | __u8 status = *((__u8 *) skb->data); |
| 1180 | struct hci_cp_le_set_default_phy *cp; |
| 1181 | |
| 1182 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1183 | |
| 1184 | if (status) |
| 1185 | return; |
| 1186 | |
| 1187 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_DEFAULT_PHY); |
| 1188 | if (!cp) |
| 1189 | return; |
| 1190 | |
| 1191 | hci_dev_lock(hdev); |
| 1192 | |
| 1193 | hdev->le_tx_def_phys = cp->tx_phys; |
| 1194 | hdev->le_rx_def_phys = cp->rx_phys; |
| 1195 | |
| 1196 | hci_dev_unlock(hdev); |
| 1197 | } |
| 1198 | |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1199 | static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, |
| 1200 | struct sk_buff *skb) |
| 1201 | { |
| 1202 | __u8 status = *((__u8 *) skb->data); |
| 1203 | struct hci_cp_le_set_adv_set_rand_addr *cp; |
| 1204 | struct adv_info *adv_instance; |
| 1205 | |
| 1206 | if (status) |
| 1207 | return; |
| 1208 | |
| 1209 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR); |
| 1210 | if (!cp) |
| 1211 | return; |
| 1212 | |
| 1213 | hci_dev_lock(hdev); |
| 1214 | |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 1215 | if (!cp->handle) { |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1216 | /* Store in hdev for instance 0 (Set adv and Directed advs) */ |
| 1217 | bacpy(&hdev->random_addr, &cp->bdaddr); |
| 1218 | } else { |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 1219 | adv_instance = hci_find_adv_instance(hdev, cp->handle); |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1220 | if (adv_instance) |
| 1221 | bacpy(&adv_instance->random_addr, &cp->bdaddr); |
| 1222 | } |
| 1223 | |
| 1224 | hci_dev_unlock(hdev); |
| 1225 | } |
| 1226 | |
Daniel Winkler | 7c395ea | 2020-12-03 12:12:51 -0800 | [diff] [blame] | 1227 | static void hci_cc_le_read_transmit_power(struct hci_dev *hdev, |
| 1228 | struct sk_buff *skb) |
| 1229 | { |
| 1230 | struct hci_rp_le_read_transmit_power *rp = (void *)skb->data; |
| 1231 | |
| 1232 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1233 | |
| 1234 | if (rp->status) |
| 1235 | return; |
| 1236 | |
| 1237 | hdev->min_le_tx_power = rp->min_le_tx_power; |
| 1238 | hdev->max_le_tx_power = rp->max_le_tx_power; |
| 1239 | } |
| 1240 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1241 | static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 1242 | { |
| 1243 | __u8 *sent, status = *((__u8 *) skb->data); |
| 1244 | |
| 1245 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1246 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1247 | if (status) |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1248 | return; |
| 1249 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1250 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE); |
| 1251 | if (!sent) |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1252 | return; |
| 1253 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1254 | hci_dev_lock(hdev); |
| 1255 | |
Stephen Hemminger | 49c922b | 2014-10-27 21:12:20 -0700 | [diff] [blame] | 1256 | /* If we're doing connection initiation as peripheral. Set a |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1257 | * timeout in case something goes wrong. |
| 1258 | */ |
| 1259 | if (*sent) { |
| 1260 | struct hci_conn *conn; |
| 1261 | |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 1262 | hci_dev_set_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | 66c417c | 2014-07-08 15:07:47 +0300 | [diff] [blame] | 1263 | |
Jakub Pawlowski | e7d9ab7 | 2015-08-07 20:22:52 +0200 | [diff] [blame] | 1264 | conn = hci_lookup_le_connect(hdev); |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1265 | if (conn) |
| 1266 | queue_delayed_work(hdev->workqueue, |
| 1267 | &conn->le_conn_timeout, |
Johan Hedberg | 09ae260 | 2014-07-06 13:41:15 +0300 | [diff] [blame] | 1268 | conn->conn_timeout); |
Johan Hedberg | 66c417c | 2014-07-08 15:07:47 +0300 | [diff] [blame] | 1269 | } else { |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 1270 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1271 | } |
| 1272 | |
Johan Hedberg | 04b4edc | 2013-03-15 17:07:01 -0500 | [diff] [blame] | 1273 | hci_dev_unlock(hdev); |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1274 | } |
| 1275 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1276 | static void hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, |
| 1277 | struct sk_buff *skb) |
| 1278 | { |
| 1279 | struct hci_cp_le_set_ext_adv_enable *cp; |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1280 | __u8 status = *((__u8 *) skb->data); |
| 1281 | |
| 1282 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1283 | |
| 1284 | if (status) |
| 1285 | return; |
| 1286 | |
| 1287 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE); |
| 1288 | if (!cp) |
| 1289 | return; |
| 1290 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1291 | hci_dev_lock(hdev); |
| 1292 | |
| 1293 | if (cp->enable) { |
| 1294 | struct hci_conn *conn; |
| 1295 | |
| 1296 | hci_dev_set_flag(hdev, HCI_LE_ADV); |
| 1297 | |
| 1298 | conn = hci_lookup_le_connect(hdev); |
| 1299 | if (conn) |
| 1300 | queue_delayed_work(hdev->workqueue, |
| 1301 | &conn->le_conn_timeout, |
| 1302 | conn->conn_timeout); |
Jaganath Kanakkassery | 45b7749 | 2018-07-19 17:09:43 +0530 | [diff] [blame] | 1303 | } else { |
| 1304 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | hci_dev_unlock(hdev); |
| 1308 | } |
| 1309 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1310 | static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 1311 | { |
| 1312 | struct hci_cp_le_set_scan_param *cp; |
| 1313 | __u8 status = *((__u8 *) skb->data); |
| 1314 | |
| 1315 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1316 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1317 | if (status) |
| 1318 | return; |
| 1319 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1320 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM); |
| 1321 | if (!cp) |
| 1322 | return; |
| 1323 | |
| 1324 | hci_dev_lock(hdev); |
| 1325 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1326 | hdev->le_scan_type = cp->type; |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1327 | |
| 1328 | hci_dev_unlock(hdev); |
| 1329 | } |
| 1330 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1331 | static void hci_cc_le_set_ext_scan_param(struct hci_dev *hdev, |
| 1332 | struct sk_buff *skb) |
| 1333 | { |
| 1334 | struct hci_cp_le_set_ext_scan_params *cp; |
| 1335 | __u8 status = *((__u8 *) skb->data); |
| 1336 | struct hci_cp_le_scan_phy_params *phy_param; |
| 1337 | |
| 1338 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1339 | |
| 1340 | if (status) |
| 1341 | return; |
| 1342 | |
| 1343 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS); |
| 1344 | if (!cp) |
| 1345 | return; |
| 1346 | |
| 1347 | phy_param = (void *)cp->data; |
| 1348 | |
| 1349 | hci_dev_lock(hdev); |
| 1350 | |
| 1351 | hdev->le_scan_type = phy_param->type; |
| 1352 | |
| 1353 | hci_dev_unlock(hdev); |
| 1354 | } |
| 1355 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1356 | static bool has_pending_adv_report(struct hci_dev *hdev) |
| 1357 | { |
| 1358 | struct discovery_state *d = &hdev->discovery; |
| 1359 | |
| 1360 | return bacmp(&d->last_adv_addr, BDADDR_ANY); |
| 1361 | } |
| 1362 | |
| 1363 | static void clear_pending_adv_report(struct hci_dev *hdev) |
| 1364 | { |
| 1365 | struct discovery_state *d = &hdev->discovery; |
| 1366 | |
| 1367 | bacpy(&d->last_adv_addr, BDADDR_ANY); |
| 1368 | d->last_adv_data_len = 0; |
| 1369 | } |
| 1370 | |
| 1371 | static void store_pending_adv_report(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 1372 | u8 bdaddr_type, s8 rssi, u32 flags, |
| 1373 | u8 *data, u8 len) |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1374 | { |
| 1375 | struct discovery_state *d = &hdev->discovery; |
| 1376 | |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 1377 | if (len > HCI_MAX_AD_LENGTH) |
| 1378 | return; |
| 1379 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1380 | bacpy(&d->last_adv_addr, bdaddr); |
| 1381 | d->last_adv_addr_type = bdaddr_type; |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 1382 | d->last_adv_rssi = rssi; |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 1383 | d->last_adv_flags = flags; |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1384 | memcpy(d->last_adv_data, data, len); |
| 1385 | d->last_adv_data_len = len; |
| 1386 | } |
| 1387 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1388 | static void le_set_scan_enable_complete(struct hci_dev *hdev, u8 enable) |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1389 | { |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1390 | hci_dev_lock(hdev); |
| 1391 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1392 | switch (enable) { |
Andre Guedes | 76a388be | 2013-04-04 20:21:02 -0300 | [diff] [blame] | 1393 | case LE_SCAN_ENABLE: |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 1394 | hci_dev_set_flag(hdev, HCI_LE_SCAN); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1395 | if (hdev->le_scan_type == LE_SCAN_ACTIVE) |
| 1396 | clear_pending_adv_report(hdev); |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1397 | break; |
| 1398 | |
Andre Guedes | 76a388be | 2013-04-04 20:21:02 -0300 | [diff] [blame] | 1399 | case LE_SCAN_DISABLE: |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1400 | /* We do this here instead of when setting DISCOVERY_STOPPED |
| 1401 | * since the latter would potentially require waiting for |
| 1402 | * inquiry to stop too. |
| 1403 | */ |
| 1404 | if (has_pending_adv_report(hdev)) { |
| 1405 | struct discovery_state *d = &hdev->discovery; |
| 1406 | |
| 1407 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Johan Hedberg | ab0aa43 | 2014-03-26 14:17:12 +0200 | [diff] [blame] | 1408 | d->last_adv_addr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 1409 | d->last_adv_rssi, d->last_adv_flags, |
Johan Hedberg | ab0aa43 | 2014-03-26 14:17:12 +0200 | [diff] [blame] | 1410 | d->last_adv_data, |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1411 | d->last_adv_data_len, NULL, 0); |
| 1412 | } |
| 1413 | |
Johan Hedberg | 317ac8c | 2014-02-28 20:26:12 +0200 | [diff] [blame] | 1414 | /* Cancel this timer so that we don't try to disable scanning |
| 1415 | * when it's already disabled. |
| 1416 | */ |
| 1417 | cancel_delayed_work(&hdev->le_scan_disable); |
| 1418 | |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 1419 | hci_dev_clear_flag(hdev, HCI_LE_SCAN); |
Johan Hedberg | e8bb6b9 | 2014-07-08 15:07:53 +0300 | [diff] [blame] | 1420 | |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1421 | /* The HCI_LE_SCAN_INTERRUPTED flag indicates that we |
| 1422 | * interrupted scanning due to a connect request. Mark |
Johan Hedberg | e8bb6b9 | 2014-07-08 15:07:53 +0300 | [diff] [blame] | 1423 | * therefore discovery as stopped. If this was not |
| 1424 | * because of a connect request advertising might have |
| 1425 | * been disabled because of active scanning, so |
| 1426 | * re-enable it again if necessary. |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1427 | */ |
Marcel Holtmann | a69d892 | 2015-03-13 02:11:05 -0700 | [diff] [blame] | 1428 | if (hci_dev_test_and_clear_flag(hdev, HCI_LE_SCAN_INTERRUPTED)) |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1429 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1430 | else if (!hci_dev_test_flag(hdev, HCI_LE_ADV) && |
Johan Hedberg | 3472227 | 2014-07-08 16:05:05 +0300 | [diff] [blame] | 1431 | hdev->discovery.state == DISCOVERY_FINDING) |
Johan Hedberg | f225257 | 2015-11-18 12:49:20 +0200 | [diff] [blame] | 1432 | hci_req_reenable_advertising(hdev); |
Johan Hedberg | e8bb6b9 | 2014-07-08 15:07:53 +0300 | [diff] [blame] | 1433 | |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1434 | break; |
| 1435 | |
| 1436 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1437 | bt_dev_err(hdev, "use of reserved LE_Scan_Enable param %d", |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1438 | enable); |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1439 | break; |
Andre Guedes | 3581508 | 2011-05-26 16:23:53 -0300 | [diff] [blame] | 1440 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1441 | |
| 1442 | hci_dev_unlock(hdev); |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1443 | } |
| 1444 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1445 | static void hci_cc_le_set_scan_enable(struct hci_dev *hdev, |
| 1446 | struct sk_buff *skb) |
| 1447 | { |
| 1448 | struct hci_cp_le_set_scan_enable *cp; |
| 1449 | __u8 status = *((__u8 *) skb->data); |
| 1450 | |
| 1451 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1452 | |
| 1453 | if (status) |
| 1454 | return; |
| 1455 | |
| 1456 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE); |
| 1457 | if (!cp) |
| 1458 | return; |
| 1459 | |
| 1460 | le_set_scan_enable_complete(hdev, cp->enable); |
| 1461 | } |
| 1462 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1463 | static void hci_cc_le_set_ext_scan_enable(struct hci_dev *hdev, |
| 1464 | struct sk_buff *skb) |
| 1465 | { |
| 1466 | struct hci_cp_le_set_ext_scan_enable *cp; |
| 1467 | __u8 status = *((__u8 *) skb->data); |
| 1468 | |
| 1469 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1470 | |
| 1471 | if (status) |
| 1472 | return; |
| 1473 | |
| 1474 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE); |
| 1475 | if (!cp) |
| 1476 | return; |
| 1477 | |
| 1478 | le_set_scan_enable_complete(hdev, cp->enable); |
| 1479 | } |
| 1480 | |
Jaganath Kanakkassery | 6b49bcb | 2018-07-19 17:09:40 +0530 | [diff] [blame] | 1481 | static void hci_cc_le_read_num_adv_sets(struct hci_dev *hdev, |
| 1482 | struct sk_buff *skb) |
| 1483 | { |
| 1484 | struct hci_rp_le_read_num_supported_adv_sets *rp = (void *) skb->data; |
| 1485 | |
| 1486 | BT_DBG("%s status 0x%2.2x No of Adv sets %u", hdev->name, rp->status, |
| 1487 | rp->num_of_sets); |
| 1488 | |
| 1489 | if (rp->status) |
| 1490 | return; |
| 1491 | |
| 1492 | hdev->le_num_of_adv_sets = rp->num_of_sets; |
| 1493 | } |
| 1494 | |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1495 | static void hci_cc_le_read_white_list_size(struct hci_dev *hdev, |
| 1496 | struct sk_buff *skb) |
| 1497 | { |
| 1498 | struct hci_rp_le_read_white_list_size *rp = (void *) skb->data; |
| 1499 | |
| 1500 | BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size); |
| 1501 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1502 | if (rp->status) |
| 1503 | return; |
| 1504 | |
| 1505 | hdev->le_white_list_size = rp->size; |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1506 | } |
| 1507 | |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1508 | static void hci_cc_le_clear_white_list(struct hci_dev *hdev, |
| 1509 | struct sk_buff *skb) |
| 1510 | { |
| 1511 | __u8 status = *((__u8 *) skb->data); |
| 1512 | |
| 1513 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1514 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1515 | if (status) |
| 1516 | return; |
| 1517 | |
Johan Hedberg | dcc36c1 | 2014-07-09 12:59:13 +0300 | [diff] [blame] | 1518 | hci_bdaddr_list_clear(&hdev->le_white_list); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | static void hci_cc_le_add_to_white_list(struct hci_dev *hdev, |
| 1522 | struct sk_buff *skb) |
| 1523 | { |
| 1524 | struct hci_cp_le_add_to_white_list *sent; |
| 1525 | __u8 status = *((__u8 *) skb->data); |
| 1526 | |
| 1527 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1528 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1529 | if (status) |
| 1530 | return; |
| 1531 | |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1532 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_WHITE_LIST); |
| 1533 | if (!sent) |
| 1534 | return; |
| 1535 | |
Johan Hedberg | dcc36c1 | 2014-07-09 12:59:13 +0300 | [diff] [blame] | 1536 | hci_bdaddr_list_add(&hdev->le_white_list, &sent->bdaddr, |
| 1537 | sent->bdaddr_type); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1538 | } |
| 1539 | |
| 1540 | static void hci_cc_le_del_from_white_list(struct hci_dev *hdev, |
| 1541 | struct sk_buff *skb) |
| 1542 | { |
| 1543 | struct hci_cp_le_del_from_white_list *sent; |
| 1544 | __u8 status = *((__u8 *) skb->data); |
| 1545 | |
| 1546 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1547 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1548 | if (status) |
| 1549 | return; |
| 1550 | |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1551 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_WHITE_LIST); |
| 1552 | if (!sent) |
| 1553 | return; |
| 1554 | |
Johan Hedberg | dcc36c1 | 2014-07-09 12:59:13 +0300 | [diff] [blame] | 1555 | hci_bdaddr_list_del(&hdev->le_white_list, &sent->bdaddr, |
| 1556 | sent->bdaddr_type); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1557 | } |
| 1558 | |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 1559 | static void hci_cc_le_read_supported_states(struct hci_dev *hdev, |
| 1560 | struct sk_buff *skb) |
| 1561 | { |
| 1562 | struct hci_rp_le_read_supported_states *rp = (void *) skb->data; |
| 1563 | |
| 1564 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1565 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1566 | if (rp->status) |
| 1567 | return; |
| 1568 | |
| 1569 | memcpy(hdev->le_states, rp->le_states, 8); |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 1570 | } |
| 1571 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 1572 | static void hci_cc_le_read_def_data_len(struct hci_dev *hdev, |
| 1573 | struct sk_buff *skb) |
| 1574 | { |
| 1575 | struct hci_rp_le_read_def_data_len *rp = (void *) skb->data; |
| 1576 | |
| 1577 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1578 | |
| 1579 | if (rp->status) |
| 1580 | return; |
| 1581 | |
| 1582 | hdev->le_def_tx_len = le16_to_cpu(rp->tx_len); |
| 1583 | hdev->le_def_tx_time = le16_to_cpu(rp->tx_time); |
| 1584 | } |
| 1585 | |
| 1586 | static void hci_cc_le_write_def_data_len(struct hci_dev *hdev, |
| 1587 | struct sk_buff *skb) |
| 1588 | { |
| 1589 | struct hci_cp_le_write_def_data_len *sent; |
| 1590 | __u8 status = *((__u8 *) skb->data); |
| 1591 | |
| 1592 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1593 | |
| 1594 | if (status) |
| 1595 | return; |
| 1596 | |
| 1597 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN); |
| 1598 | if (!sent) |
| 1599 | return; |
| 1600 | |
| 1601 | hdev->le_def_tx_len = le16_to_cpu(sent->tx_len); |
| 1602 | hdev->le_def_tx_time = le16_to_cpu(sent->tx_time); |
| 1603 | } |
| 1604 | |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 1605 | static void hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, |
| 1606 | struct sk_buff *skb) |
| 1607 | { |
| 1608 | struct hci_cp_le_add_to_resolv_list *sent; |
| 1609 | __u8 status = *((__u8 *) skb->data); |
| 1610 | |
| 1611 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1612 | |
| 1613 | if (status) |
| 1614 | return; |
| 1615 | |
| 1616 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST); |
| 1617 | if (!sent) |
| 1618 | return; |
| 1619 | |
| 1620 | hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr, |
| 1621 | sent->bdaddr_type, sent->peer_irk, |
| 1622 | sent->local_irk); |
| 1623 | } |
| 1624 | |
| 1625 | static void hci_cc_le_del_from_resolv_list(struct hci_dev *hdev, |
| 1626 | struct sk_buff *skb) |
| 1627 | { |
| 1628 | struct hci_cp_le_del_from_resolv_list *sent; |
| 1629 | __u8 status = *((__u8 *) skb->data); |
| 1630 | |
| 1631 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1632 | |
| 1633 | if (status) |
| 1634 | return; |
| 1635 | |
| 1636 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST); |
| 1637 | if (!sent) |
| 1638 | return; |
| 1639 | |
| 1640 | hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr, |
| 1641 | sent->bdaddr_type); |
| 1642 | } |
| 1643 | |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 1644 | static void hci_cc_le_clear_resolv_list(struct hci_dev *hdev, |
| 1645 | struct sk_buff *skb) |
| 1646 | { |
| 1647 | __u8 status = *((__u8 *) skb->data); |
| 1648 | |
| 1649 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1650 | |
| 1651 | if (status) |
| 1652 | return; |
| 1653 | |
| 1654 | hci_bdaddr_list_clear(&hdev->le_resolv_list); |
| 1655 | } |
| 1656 | |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 1657 | static void hci_cc_le_read_resolv_list_size(struct hci_dev *hdev, |
| 1658 | struct sk_buff *skb) |
| 1659 | { |
| 1660 | struct hci_rp_le_read_resolv_list_size *rp = (void *) skb->data; |
| 1661 | |
| 1662 | BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size); |
| 1663 | |
| 1664 | if (rp->status) |
| 1665 | return; |
| 1666 | |
| 1667 | hdev->le_resolv_list_size = rp->size; |
| 1668 | } |
| 1669 | |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 1670 | static void hci_cc_le_set_addr_resolution_enable(struct hci_dev *hdev, |
| 1671 | struct sk_buff *skb) |
| 1672 | { |
| 1673 | __u8 *sent, status = *((__u8 *) skb->data); |
| 1674 | |
| 1675 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1676 | |
| 1677 | if (status) |
| 1678 | return; |
| 1679 | |
| 1680 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE); |
| 1681 | if (!sent) |
| 1682 | return; |
| 1683 | |
| 1684 | hci_dev_lock(hdev); |
| 1685 | |
| 1686 | if (*sent) |
| 1687 | hci_dev_set_flag(hdev, HCI_LL_RPA_RESOLUTION); |
| 1688 | else |
| 1689 | hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION); |
| 1690 | |
| 1691 | hci_dev_unlock(hdev); |
| 1692 | } |
| 1693 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 1694 | static void hci_cc_le_read_max_data_len(struct hci_dev *hdev, |
| 1695 | struct sk_buff *skb) |
| 1696 | { |
| 1697 | struct hci_rp_le_read_max_data_len *rp = (void *) skb->data; |
| 1698 | |
| 1699 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1700 | |
| 1701 | if (rp->status) |
| 1702 | return; |
| 1703 | |
| 1704 | hdev->le_max_tx_len = le16_to_cpu(rp->tx_len); |
| 1705 | hdev->le_max_tx_time = le16_to_cpu(rp->tx_time); |
| 1706 | hdev->le_max_rx_len = le16_to_cpu(rp->rx_len); |
| 1707 | hdev->le_max_rx_time = le16_to_cpu(rp->rx_time); |
| 1708 | } |
| 1709 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1710 | static void hci_cc_write_le_host_supported(struct hci_dev *hdev, |
| 1711 | struct sk_buff *skb) |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1712 | { |
Johan Hedberg | 06199cf | 2012-02-22 16:37:11 +0200 | [diff] [blame] | 1713 | struct hci_cp_write_le_host_supported *sent; |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1714 | __u8 status = *((__u8 *) skb->data); |
| 1715 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1716 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1717 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1718 | if (status) |
| 1719 | return; |
| 1720 | |
Johan Hedberg | 06199cf | 2012-02-22 16:37:11 +0200 | [diff] [blame] | 1721 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED); |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 1722 | if (!sent) |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1723 | return; |
| 1724 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1725 | hci_dev_lock(hdev); |
| 1726 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1727 | if (sent->le) { |
| 1728 | hdev->features[1][0] |= LMP_HOST_LE; |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 1729 | hci_dev_set_flag(hdev, HCI_LE_ENABLED); |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1730 | } else { |
| 1731 | hdev->features[1][0] &= ~LMP_HOST_LE; |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 1732 | hci_dev_clear_flag(hdev, HCI_LE_ENABLED); |
| 1733 | hci_dev_clear_flag(hdev, HCI_ADVERTISING); |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 1734 | } |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1735 | |
| 1736 | if (sent->simul) |
| 1737 | hdev->features[1][0] |= LMP_HOST_LE_BREDR; |
| 1738 | else |
| 1739 | hdev->features[1][0] &= ~LMP_HOST_LE_BREDR; |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1740 | |
| 1741 | hci_dev_unlock(hdev); |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1742 | } |
| 1743 | |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 1744 | static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 1745 | { |
| 1746 | struct hci_cp_le_set_adv_param *cp; |
| 1747 | u8 status = *((u8 *) skb->data); |
| 1748 | |
| 1749 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1750 | |
| 1751 | if (status) |
| 1752 | return; |
| 1753 | |
| 1754 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM); |
| 1755 | if (!cp) |
| 1756 | return; |
| 1757 | |
| 1758 | hci_dev_lock(hdev); |
| 1759 | hdev->adv_addr_type = cp->own_address_type; |
| 1760 | hci_dev_unlock(hdev); |
| 1761 | } |
| 1762 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1763 | static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 1764 | { |
| 1765 | struct hci_rp_le_set_ext_adv_params *rp = (void *) skb->data; |
| 1766 | struct hci_cp_le_set_ext_adv_params *cp; |
| 1767 | struct adv_info *adv_instance; |
| 1768 | |
| 1769 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1770 | |
| 1771 | if (rp->status) |
| 1772 | return; |
| 1773 | |
| 1774 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS); |
| 1775 | if (!cp) |
| 1776 | return; |
| 1777 | |
| 1778 | hci_dev_lock(hdev); |
| 1779 | hdev->adv_addr_type = cp->own_addr_type; |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 1780 | if (!cp->handle) { |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1781 | /* Store in hdev for instance 0 */ |
| 1782 | hdev->adv_tx_power = rp->tx_power; |
| 1783 | } else { |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 1784 | adv_instance = hci_find_adv_instance(hdev, cp->handle); |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1785 | if (adv_instance) |
| 1786 | adv_instance->tx_power = rp->tx_power; |
| 1787 | } |
Jaganath Kanakkassery | a0fb372 | 2018-07-19 17:09:42 +0530 | [diff] [blame] | 1788 | /* Update adv data as tx power is known now */ |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 1789 | hci_req_update_adv_data(hdev, cp->handle); |
Daniel Winkler | 1241057 | 2020-12-03 12:12:49 -0800 | [diff] [blame] | 1790 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1791 | hci_dev_unlock(hdev); |
| 1792 | } |
| 1793 | |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 1794 | static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb) |
| 1795 | { |
| 1796 | struct hci_rp_read_rssi *rp = (void *) skb->data; |
| 1797 | struct hci_conn *conn; |
| 1798 | |
| 1799 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1800 | |
| 1801 | if (rp->status) |
| 1802 | return; |
| 1803 | |
| 1804 | hci_dev_lock(hdev); |
| 1805 | |
| 1806 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 1807 | if (conn) |
| 1808 | conn->rssi = rp->rssi; |
| 1809 | |
| 1810 | hci_dev_unlock(hdev); |
| 1811 | } |
| 1812 | |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 1813 | static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb) |
| 1814 | { |
| 1815 | struct hci_cp_read_tx_power *sent; |
| 1816 | struct hci_rp_read_tx_power *rp = (void *) skb->data; |
| 1817 | struct hci_conn *conn; |
| 1818 | |
| 1819 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1820 | |
| 1821 | if (rp->status) |
| 1822 | return; |
| 1823 | |
| 1824 | sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); |
| 1825 | if (!sent) |
| 1826 | return; |
| 1827 | |
| 1828 | hci_dev_lock(hdev); |
| 1829 | |
| 1830 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Andrzej Kaczmarek | d0455ed | 2014-05-14 13:43:05 +0200 | [diff] [blame] | 1831 | if (!conn) |
| 1832 | goto unlock; |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 1833 | |
Andrzej Kaczmarek | d0455ed | 2014-05-14 13:43:05 +0200 | [diff] [blame] | 1834 | switch (sent->type) { |
| 1835 | case 0x00: |
| 1836 | conn->tx_power = rp->tx_power; |
| 1837 | break; |
| 1838 | case 0x01: |
| 1839 | conn->max_tx_power = rp->tx_power; |
| 1840 | break; |
| 1841 | } |
| 1842 | |
| 1843 | unlock: |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 1844 | hci_dev_unlock(hdev); |
| 1845 | } |
| 1846 | |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 1847 | static void hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 1848 | { |
| 1849 | u8 status = *((u8 *) skb->data); |
| 1850 | u8 *mode; |
| 1851 | |
| 1852 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1853 | |
| 1854 | if (status) |
| 1855 | return; |
| 1856 | |
| 1857 | mode = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE); |
| 1858 | if (mode) |
| 1859 | hdev->ssp_debug_mode = *mode; |
| 1860 | } |
| 1861 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1862 | static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1863 | { |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1864 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1865 | |
| 1866 | if (status) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1867 | hci_conn_check_pending(hdev); |
Johan Hedberg | 314b238 | 2011-04-27 10:29:57 -0400 | [diff] [blame] | 1868 | return; |
| 1869 | } |
| 1870 | |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 1871 | set_bit(HCI_INQUIRY, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1872 | } |
| 1873 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1874 | static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1876 | struct hci_cp_create_conn *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1879 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1880 | |
| 1881 | cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | if (!cp) |
| 1883 | return; |
| 1884 | |
| 1885 | hci_dev_lock(hdev); |
| 1886 | |
| 1887 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 1888 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 1889 | BT_DBG("%s bdaddr %pMR hcon %p", hdev->name, &cp->bdaddr, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | |
| 1891 | if (status) { |
| 1892 | if (conn && conn->state == BT_CONNECT) { |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 1893 | if (status != 0x0c || conn->attempt > 2) { |
| 1894 | conn->state = BT_CLOSED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 1895 | hci_connect_cfm(conn, status); |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 1896 | hci_conn_del(conn); |
| 1897 | } else |
| 1898 | conn->state = BT_CONNECT2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | } |
| 1900 | } else { |
| 1901 | if (!conn) { |
Johan Hedberg | a5c4e30 | 2014-07-16 11:56:07 +0300 | [diff] [blame] | 1902 | conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr, |
| 1903 | HCI_ROLE_MASTER); |
| 1904 | if (!conn) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1905 | bt_dev_err(hdev, "no memory for new connection"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | hci_dev_unlock(hdev); |
| 1910 | } |
| 1911 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1912 | static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1914 | struct hci_cp_add_sco *cp; |
| 1915 | struct hci_conn *acl, *sco; |
| 1916 | __u16 handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1918 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1919 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1920 | if (!status) |
| 1921 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1922 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1923 | cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO); |
| 1924 | if (!cp) |
| 1925 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1927 | handle = __le16_to_cpu(cp->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1929 | BT_DBG("%s handle 0x%4.4x", hdev->name, handle); |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 1930 | |
| 1931 | hci_dev_lock(hdev); |
| 1932 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1933 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1934 | if (acl) { |
| 1935 | sco = acl->link; |
| 1936 | if (sco) { |
| 1937 | sco->state = BT_CLOSED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1938 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 1939 | hci_connect_cfm(sco, status); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1940 | hci_conn_del(sco); |
| 1941 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1942 | } |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 1943 | |
| 1944 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1947 | static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) |
| 1948 | { |
| 1949 | struct hci_cp_auth_requested *cp; |
| 1950 | struct hci_conn *conn; |
| 1951 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1952 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1953 | |
| 1954 | if (!status) |
| 1955 | return; |
| 1956 | |
| 1957 | cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED); |
| 1958 | if (!cp) |
| 1959 | return; |
| 1960 | |
| 1961 | hci_dev_lock(hdev); |
| 1962 | |
| 1963 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 1964 | if (conn) { |
| 1965 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 1966 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 1967 | hci_conn_drop(conn); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | hci_dev_unlock(hdev); |
| 1972 | } |
| 1973 | |
| 1974 | static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) |
| 1975 | { |
| 1976 | struct hci_cp_set_conn_encrypt *cp; |
| 1977 | struct hci_conn *conn; |
| 1978 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1979 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1980 | |
| 1981 | if (!status) |
| 1982 | return; |
| 1983 | |
| 1984 | cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT); |
| 1985 | if (!cp) |
| 1986 | return; |
| 1987 | |
| 1988 | hci_dev_lock(hdev); |
| 1989 | |
| 1990 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 1991 | if (conn) { |
| 1992 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 1993 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 1994 | hci_conn_drop(conn); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | hci_dev_unlock(hdev); |
| 1999 | } |
| 2000 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2001 | static int hci_outgoing_auth_needed(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2002 | struct hci_conn *conn) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2003 | { |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2004 | if (conn->state != BT_CONFIG || !conn->out) |
| 2005 | return 0; |
| 2006 | |
Johan Hedberg | 765c2a9 | 2011-01-19 12:06:52 +0530 | [diff] [blame] | 2007 | if (conn->pending_sec_level == BT_SECURITY_SDP) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2008 | return 0; |
| 2009 | |
| 2010 | /* Only request authentication for SSP connections or non-SSP |
Johan Hedberg | 264b8b4 | 2014-01-08 16:40:39 +0200 | [diff] [blame] | 2011 | * devices with sec_level MEDIUM or HIGH or if MITM protection |
| 2012 | * is requested. |
| 2013 | */ |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2014 | if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) && |
Johan Hedberg | 7e3691e | 2014-05-30 14:45:19 +0300 | [diff] [blame] | 2015 | conn->pending_sec_level != BT_SECURITY_FIPS && |
Johan Hedberg | 264b8b4 | 2014-01-08 16:40:39 +0200 | [diff] [blame] | 2016 | conn->pending_sec_level != BT_SECURITY_HIGH && |
| 2017 | conn->pending_sec_level != BT_SECURITY_MEDIUM) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2018 | return 0; |
| 2019 | |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2020 | return 1; |
| 2021 | } |
| 2022 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2023 | static int hci_resolve_name(struct hci_dev *hdev, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2024 | struct inquiry_entry *e) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2025 | { |
| 2026 | struct hci_cp_remote_name_req cp; |
| 2027 | |
| 2028 | memset(&cp, 0, sizeof(cp)); |
| 2029 | |
| 2030 | bacpy(&cp.bdaddr, &e->data.bdaddr); |
| 2031 | cp.pscan_rep_mode = e->data.pscan_rep_mode; |
| 2032 | cp.pscan_mode = e->data.pscan_mode; |
| 2033 | cp.clock_offset = e->data.clock_offset; |
| 2034 | |
| 2035 | return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
| 2036 | } |
| 2037 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2038 | static bool hci_resolve_next_name(struct hci_dev *hdev) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2039 | { |
| 2040 | struct discovery_state *discov = &hdev->discovery; |
| 2041 | struct inquiry_entry *e; |
| 2042 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2043 | if (list_empty(&discov->resolve)) |
| 2044 | return false; |
| 2045 | |
| 2046 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
Ram Malovany | c810089 | 2012-07-19 10:26:09 +0300 | [diff] [blame] | 2047 | if (!e) |
| 2048 | return false; |
| 2049 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2050 | if (hci_resolve_name(hdev, e) == 0) { |
| 2051 | e->name_state = NAME_PENDING; |
| 2052 | return true; |
| 2053 | } |
| 2054 | |
| 2055 | return false; |
| 2056 | } |
| 2057 | |
| 2058 | static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2059 | bdaddr_t *bdaddr, u8 *name, u8 name_len) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2060 | { |
| 2061 | struct discovery_state *discov = &hdev->discovery; |
| 2062 | struct inquiry_entry *e; |
| 2063 | |
Johan Hedberg | 60cb49d | 2014-11-11 11:33:24 +0200 | [diff] [blame] | 2064 | /* Update the mgmt connected state if necessary. Be careful with |
| 2065 | * conn objects that exist but are not (yet) connected however. |
| 2066 | * Only those in BT_CONFIG or BT_CONNECTED states can be |
| 2067 | * considered connected. |
| 2068 | */ |
| 2069 | if (conn && |
| 2070 | (conn->state == BT_CONFIG || conn->state == BT_CONNECTED) && |
Jaganath Kanakkassery | cb77c3e | 2014-11-07 16:39:09 +0530 | [diff] [blame] | 2071 | !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 2072 | mgmt_device_connected(hdev, conn, name, name_len); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2073 | |
| 2074 | if (discov->state == DISCOVERY_STOPPED) |
| 2075 | return; |
| 2076 | |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2077 | if (discov->state == DISCOVERY_STOPPING) |
| 2078 | goto discov_complete; |
| 2079 | |
| 2080 | if (discov->state != DISCOVERY_RESOLVING) |
| 2081 | return; |
| 2082 | |
| 2083 | e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING); |
Ram Malovany | 7cc8380 | 2012-07-19 10:26:10 +0300 | [diff] [blame] | 2084 | /* If the device was not found in a list of found devices names of which |
| 2085 | * are pending. there is no need to continue resolving a next name as it |
| 2086 | * will be done upon receiving another Remote Name Request Complete |
| 2087 | * Event */ |
| 2088 | if (!e) |
| 2089 | return; |
| 2090 | |
| 2091 | list_del(&e->list); |
| 2092 | if (name) { |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2093 | e->name_state = NAME_KNOWN; |
Ram Malovany | 7cc8380 | 2012-07-19 10:26:10 +0300 | [diff] [blame] | 2094 | mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, |
| 2095 | e->data.rssi, name, name_len); |
Ram Malovany | c3e7c0d | 2012-07-19 10:26:11 +0300 | [diff] [blame] | 2096 | } else { |
| 2097 | e->name_state = NAME_NOT_KNOWN; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2098 | } |
| 2099 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2100 | if (hci_resolve_next_name(hdev)) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2101 | return; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2102 | |
| 2103 | discov_complete: |
| 2104 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 2105 | } |
| 2106 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2107 | static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) |
| 2108 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2109 | struct hci_cp_remote_name_req *cp; |
| 2110 | struct hci_conn *conn; |
| 2111 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2112 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2113 | |
| 2114 | /* If successful wait for the name req complete event before |
| 2115 | * checking for the need to do authentication */ |
| 2116 | if (!status) |
| 2117 | return; |
| 2118 | |
| 2119 | cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ); |
| 2120 | if (!cp) |
| 2121 | return; |
| 2122 | |
| 2123 | hci_dev_lock(hdev); |
| 2124 | |
| 2125 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2126 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2127 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2128 | hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0); |
| 2129 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 2130 | if (!conn) |
| 2131 | goto unlock; |
| 2132 | |
| 2133 | if (!hci_outgoing_auth_needed(hdev, conn)) |
| 2134 | goto unlock; |
| 2135 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2136 | if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johannes Berg | c1f23a2 | 2013-10-07 18:19:16 +0200 | [diff] [blame] | 2137 | struct hci_cp_auth_requested auth_cp; |
| 2138 | |
Johan Hedberg | 977f8fc | 2014-07-17 15:35:39 +0300 | [diff] [blame] | 2139 | set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); |
| 2140 | |
Johannes Berg | c1f23a2 | 2013-10-07 18:19:16 +0200 | [diff] [blame] | 2141 | auth_cp.handle = __cpu_to_le16(conn->handle); |
| 2142 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, |
| 2143 | sizeof(auth_cp), &auth_cp); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2144 | } |
| 2145 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 2146 | unlock: |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2147 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2148 | } |
| 2149 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2150 | static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) |
| 2151 | { |
| 2152 | struct hci_cp_read_remote_features *cp; |
| 2153 | struct hci_conn *conn; |
| 2154 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2155 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2156 | |
| 2157 | if (!status) |
| 2158 | return; |
| 2159 | |
| 2160 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES); |
| 2161 | if (!cp) |
| 2162 | return; |
| 2163 | |
| 2164 | hci_dev_lock(hdev); |
| 2165 | |
| 2166 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2167 | if (conn) { |
| 2168 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2169 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2170 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | hci_dev_unlock(hdev); |
| 2175 | } |
| 2176 | |
| 2177 | static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status) |
| 2178 | { |
| 2179 | struct hci_cp_read_remote_ext_features *cp; |
| 2180 | struct hci_conn *conn; |
| 2181 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2182 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2183 | |
| 2184 | if (!status) |
| 2185 | return; |
| 2186 | |
| 2187 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES); |
| 2188 | if (!cp) |
| 2189 | return; |
| 2190 | |
| 2191 | hci_dev_lock(hdev); |
| 2192 | |
| 2193 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2194 | if (conn) { |
| 2195 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2196 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2197 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | hci_dev_unlock(hdev); |
| 2202 | } |
| 2203 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2204 | static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| 2205 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2206 | struct hci_cp_setup_sync_conn *cp; |
| 2207 | struct hci_conn *acl, *sco; |
| 2208 | __u16 handle; |
| 2209 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2210 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2211 | |
| 2212 | if (!status) |
| 2213 | return; |
| 2214 | |
| 2215 | cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN); |
| 2216 | if (!cp) |
| 2217 | return; |
| 2218 | |
| 2219 | handle = __le16_to_cpu(cp->handle); |
| 2220 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2221 | BT_DBG("%s handle 0x%4.4x", hdev->name, handle); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2222 | |
| 2223 | hci_dev_lock(hdev); |
| 2224 | |
| 2225 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 2226 | if (acl) { |
| 2227 | sco = acl->link; |
| 2228 | if (sco) { |
| 2229 | sco->state = BT_CLOSED; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2230 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2231 | hci_connect_cfm(sco, status); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 2232 | hci_conn_del(sco); |
| 2233 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2234 | } |
| 2235 | |
| 2236 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2237 | } |
| 2238 | |
| 2239 | static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 2240 | { |
| 2241 | struct hci_cp_sniff_mode *cp; |
| 2242 | struct hci_conn *conn; |
| 2243 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2244 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2245 | |
| 2246 | if (!status) |
| 2247 | return; |
| 2248 | |
| 2249 | cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE); |
| 2250 | if (!cp) |
| 2251 | return; |
| 2252 | |
| 2253 | hci_dev_lock(hdev); |
| 2254 | |
| 2255 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2256 | if (conn) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2257 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2258 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2259 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2260 | hci_sco_setup(conn, status); |
| 2261 | } |
| 2262 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2263 | hci_dev_unlock(hdev); |
| 2264 | } |
| 2265 | |
| 2266 | static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 2267 | { |
| 2268 | struct hci_cp_exit_sniff_mode *cp; |
| 2269 | struct hci_conn *conn; |
| 2270 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2271 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2272 | |
| 2273 | if (!status) |
| 2274 | return; |
| 2275 | |
| 2276 | cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE); |
| 2277 | if (!cp) |
| 2278 | return; |
| 2279 | |
| 2280 | hci_dev_lock(hdev); |
| 2281 | |
| 2282 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2283 | if (conn) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2284 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2285 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2286 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2287 | hci_sco_setup(conn, status); |
| 2288 | } |
| 2289 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2290 | hci_dev_unlock(hdev); |
| 2291 | } |
| 2292 | |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2293 | static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) |
| 2294 | { |
| 2295 | struct hci_cp_disconnect *cp; |
| 2296 | struct hci_conn *conn; |
| 2297 | |
| 2298 | if (!status) |
| 2299 | return; |
| 2300 | |
| 2301 | cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT); |
| 2302 | if (!cp) |
| 2303 | return; |
| 2304 | |
| 2305 | hci_dev_lock(hdev); |
| 2306 | |
| 2307 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Joseph Hwang | b8d2905 | 2020-03-11 19:20:14 -0700 | [diff] [blame] | 2308 | if (conn) { |
| 2309 | u8 type = conn->type; |
| 2310 | |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2311 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2312 | conn->dst_type, status); |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2313 | |
Joseph Hwang | b8d2905 | 2020-03-11 19:20:14 -0700 | [diff] [blame] | 2314 | /* If the disconnection failed for any reason, the upper layer |
| 2315 | * does not retry to disconnect in current implementation. |
| 2316 | * Hence, we need to do some basic cleanup here and re-enable |
| 2317 | * advertising if necessary. |
| 2318 | */ |
| 2319 | hci_conn_del(conn); |
| 2320 | if (type == LE_LINK) |
| 2321 | hci_req_reenable_advertising(hdev); |
| 2322 | } |
| 2323 | |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2324 | hci_dev_unlock(hdev); |
| 2325 | } |
| 2326 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2327 | static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, |
| 2328 | u8 peer_addr_type, u8 own_address_type, |
| 2329 | u8 filter_policy) |
| 2330 | { |
| 2331 | struct hci_conn *conn; |
| 2332 | |
| 2333 | conn = hci_conn_hash_lookup_le(hdev, peer_addr, |
| 2334 | peer_addr_type); |
| 2335 | if (!conn) |
| 2336 | return; |
| 2337 | |
Sathish Narasimman | b31bc00 | 2020-07-23 18:08:59 +0530 | [diff] [blame] | 2338 | /* When using controller based address resolution, then the new |
| 2339 | * address types 0x02 and 0x03 are used. These types need to be |
| 2340 | * converted back into either public address or random address type |
| 2341 | */ |
| 2342 | if (use_ll_privacy(hdev) && |
| 2343 | hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) { |
| 2344 | switch (own_address_type) { |
| 2345 | case ADDR_LE_DEV_PUBLIC_RESOLVED: |
| 2346 | own_address_type = ADDR_LE_DEV_PUBLIC; |
| 2347 | break; |
| 2348 | case ADDR_LE_DEV_RANDOM_RESOLVED: |
| 2349 | own_address_type = ADDR_LE_DEV_RANDOM; |
| 2350 | break; |
| 2351 | } |
| 2352 | } |
| 2353 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2354 | /* Store the initiator and responder address information which |
| 2355 | * is needed for SMP. These values will not change during the |
| 2356 | * lifetime of the connection. |
| 2357 | */ |
| 2358 | conn->init_addr_type = own_address_type; |
| 2359 | if (own_address_type == ADDR_LE_DEV_RANDOM) |
| 2360 | bacpy(&conn->init_addr, &hdev->random_addr); |
| 2361 | else |
| 2362 | bacpy(&conn->init_addr, &hdev->bdaddr); |
| 2363 | |
| 2364 | conn->resp_addr_type = peer_addr_type; |
| 2365 | bacpy(&conn->resp_addr, peer_addr); |
| 2366 | |
| 2367 | /* We don't want the connection attempt to stick around |
| 2368 | * indefinitely since LE doesn't have a page timeout concept |
| 2369 | * like BR/EDR. Set a timer for any connection that doesn't use |
| 2370 | * the white list for connecting. |
| 2371 | */ |
| 2372 | if (filter_policy == HCI_LE_USE_PEER_ADDR) |
| 2373 | queue_delayed_work(conn->hdev->workqueue, |
| 2374 | &conn->le_conn_timeout, |
| 2375 | conn->conn_timeout); |
| 2376 | } |
| 2377 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2378 | static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status) |
| 2379 | { |
| 2380 | struct hci_cp_le_create_conn *cp; |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2381 | |
| 2382 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2383 | |
| 2384 | /* All connection failure handling is taken care of by the |
| 2385 | * hci_le_conn_failed function which is triggered by the HCI |
| 2386 | * request completion callbacks used for connecting. |
| 2387 | */ |
| 2388 | if (status) |
| 2389 | return; |
| 2390 | |
| 2391 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN); |
| 2392 | if (!cp) |
| 2393 | return; |
| 2394 | |
| 2395 | hci_dev_lock(hdev); |
| 2396 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2397 | cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type, |
| 2398 | cp->own_address_type, cp->filter_policy); |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2399 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2400 | hci_dev_unlock(hdev); |
| 2401 | } |
| 2402 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 2403 | static void hci_cs_le_ext_create_conn(struct hci_dev *hdev, u8 status) |
| 2404 | { |
| 2405 | struct hci_cp_le_ext_create_conn *cp; |
| 2406 | |
| 2407 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2408 | |
| 2409 | /* All connection failure handling is taken care of by the |
| 2410 | * hci_le_conn_failed function which is triggered by the HCI |
| 2411 | * request completion callbacks used for connecting. |
| 2412 | */ |
| 2413 | if (status) |
| 2414 | return; |
| 2415 | |
| 2416 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_EXT_CREATE_CONN); |
| 2417 | if (!cp) |
| 2418 | return; |
| 2419 | |
| 2420 | hci_dev_lock(hdev); |
| 2421 | |
| 2422 | cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type, |
| 2423 | cp->own_addr_type, cp->filter_policy); |
| 2424 | |
| 2425 | hci_dev_unlock(hdev); |
| 2426 | } |
| 2427 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 2428 | static void hci_cs_le_read_remote_features(struct hci_dev *hdev, u8 status) |
| 2429 | { |
| 2430 | struct hci_cp_le_read_remote_features *cp; |
| 2431 | struct hci_conn *conn; |
| 2432 | |
| 2433 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2434 | |
| 2435 | if (!status) |
| 2436 | return; |
| 2437 | |
| 2438 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_READ_REMOTE_FEATURES); |
| 2439 | if (!cp) |
| 2440 | return; |
| 2441 | |
| 2442 | hci_dev_lock(hdev); |
| 2443 | |
| 2444 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2445 | if (conn) { |
| 2446 | if (conn->state == BT_CONFIG) { |
| 2447 | hci_connect_cfm(conn, status); |
| 2448 | hci_conn_drop(conn); |
| 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | hci_dev_unlock(hdev); |
| 2453 | } |
| 2454 | |
Johan Hedberg | 81d0c8a | 2014-03-24 14:39:04 +0200 | [diff] [blame] | 2455 | static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status) |
| 2456 | { |
| 2457 | struct hci_cp_le_start_enc *cp; |
| 2458 | struct hci_conn *conn; |
| 2459 | |
| 2460 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2461 | |
| 2462 | if (!status) |
| 2463 | return; |
| 2464 | |
| 2465 | hci_dev_lock(hdev); |
| 2466 | |
| 2467 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_START_ENC); |
| 2468 | if (!cp) |
| 2469 | goto unlock; |
| 2470 | |
| 2471 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2472 | if (!conn) |
| 2473 | goto unlock; |
| 2474 | |
| 2475 | if (conn->state != BT_CONNECTED) |
| 2476 | goto unlock; |
| 2477 | |
| 2478 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
| 2479 | hci_conn_drop(conn); |
| 2480 | |
| 2481 | unlock: |
| 2482 | hci_dev_unlock(hdev); |
| 2483 | } |
| 2484 | |
Kuba Pawlak | 50fc85f | 2014-11-06 19:36:52 +0100 | [diff] [blame] | 2485 | static void hci_cs_switch_role(struct hci_dev *hdev, u8 status) |
| 2486 | { |
| 2487 | struct hci_cp_switch_role *cp; |
| 2488 | struct hci_conn *conn; |
| 2489 | |
| 2490 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2491 | |
| 2492 | if (!status) |
| 2493 | return; |
| 2494 | |
| 2495 | cp = hci_sent_cmd_data(hdev, HCI_OP_SWITCH_ROLE); |
| 2496 | if (!cp) |
| 2497 | return; |
| 2498 | |
| 2499 | hci_dev_lock(hdev); |
| 2500 | |
| 2501 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 2502 | if (conn) |
| 2503 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
| 2504 | |
| 2505 | hci_dev_unlock(hdev); |
| 2506 | } |
| 2507 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2508 | static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2509 | { |
| 2510 | __u8 status = *((__u8 *) skb->data); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2511 | struct discovery_state *discov = &hdev->discovery; |
| 2512 | struct inquiry_entry *e; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2513 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2514 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2515 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2516 | hci_conn_check_pending(hdev); |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 2517 | |
| 2518 | if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) |
| 2519 | return; |
| 2520 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 2521 | smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */ |
Andre Guedes | 3e13fa1 | 2013-03-27 20:04:56 -0300 | [diff] [blame] | 2522 | wake_up_bit(&hdev->flags, HCI_INQUIRY); |
| 2523 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2524 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2525 | return; |
| 2526 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 2527 | hci_dev_lock(hdev); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2528 | |
Andre Guedes | 343f935 | 2012-02-17 20:39:37 -0300 | [diff] [blame] | 2529 | if (discov->state != DISCOVERY_FINDING) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2530 | goto unlock; |
| 2531 | |
| 2532 | if (list_empty(&discov->resolve)) { |
Jakub Pawlowski | 07d2334 | 2015-03-17 09:04:14 -0700 | [diff] [blame] | 2533 | /* When BR/EDR inquiry is active and no LE scanning is in |
| 2534 | * progress, then change discovery state to indicate completion. |
| 2535 | * |
| 2536 | * When running LE scanning and BR/EDR inquiry simultaneously |
| 2537 | * and the LE scan already finished, then change the discovery |
| 2538 | * state to indicate completion. |
| 2539 | */ |
| 2540 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 2541 | !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) |
| 2542 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2543 | goto unlock; |
| 2544 | } |
| 2545 | |
| 2546 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
| 2547 | if (e && hci_resolve_name(hdev, e) == 0) { |
| 2548 | e->name_state = NAME_PENDING; |
| 2549 | hci_discovery_set_state(hdev, DISCOVERY_RESOLVING); |
| 2550 | } else { |
Jakub Pawlowski | 07d2334 | 2015-03-17 09:04:14 -0700 | [diff] [blame] | 2551 | /* When BR/EDR inquiry is active and no LE scanning is in |
| 2552 | * progress, then change discovery state to indicate completion. |
| 2553 | * |
| 2554 | * When running LE scanning and BR/EDR inquiry simultaneously |
| 2555 | * and the LE scan already finished, then change the discovery |
| 2556 | * state to indicate completion. |
| 2557 | */ |
| 2558 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 2559 | !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) |
| 2560 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | unlock: |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 2564 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2565 | } |
| 2566 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2567 | static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | { |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2569 | struct inquiry_data data; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2570 | struct inquiry_info *info = (void *) (skb->data + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | int num_rsp = *((__u8 *) skb->data); |
| 2572 | |
| 2573 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 2574 | |
Peilin Ye | 75bbd2e | 2020-07-10 17:39:18 -0400 | [diff] [blame] | 2575 | if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1) |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2576 | return; |
| 2577 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2578 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 2579 | return; |
| 2580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2582 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 2583 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 2584 | u32 flags; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 2585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | bacpy(&data.bdaddr, &info->bdaddr); |
| 2587 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 2588 | data.pscan_period_mode = info->pscan_period_mode; |
| 2589 | data.pscan_mode = info->pscan_mode; |
| 2590 | memcpy(data.dev_class, info->dev_class, 3); |
| 2591 | data.clock_offset = info->clock_offset; |
Marcel Holtmann | efb2513 | 2014-12-05 13:03:34 +0100 | [diff] [blame] | 2592 | data.rssi = HCI_RSSI_INVALID; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2593 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 2594 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 2595 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 2596 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 2597 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Marcel Holtmann | efb2513 | 2014-12-05 13:03:34 +0100 | [diff] [blame] | 2598 | info->dev_class, HCI_RSSI_INVALID, |
| 2599 | flags, NULL, 0, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2601 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2602 | hci_dev_unlock(hdev); |
| 2603 | } |
| 2604 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2605 | static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2606 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2607 | struct hci_ev_conn_complete *ev = (void *) skb->data; |
| 2608 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2609 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2610 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2612 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2613 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2614 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9499237 | 2009-04-19 19:30:03 +0200 | [diff] [blame] | 2615 | if (!conn) { |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 2616 | /* Connection may not exist if auto-connected. Check the bredr |
| 2617 | * allowlist to see if this device is allowed to auto connect. |
| 2618 | * If link is an ACL type, create a connection class |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2619 | * automatically. |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 2620 | * |
| 2621 | * Auto-connect will only occur if the event filter is |
| 2622 | * programmed with a given address. Right now, event filter is |
| 2623 | * only used during suspend. |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2624 | */ |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 2625 | if (ev->link_type == ACL_LINK && |
| 2626 | hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, |
| 2627 | &ev->bdaddr, |
| 2628 | BDADDR_BREDR)) { |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2629 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr, |
| 2630 | HCI_ROLE_SLAVE); |
| 2631 | if (!conn) { |
| 2632 | bt_dev_err(hdev, "no memory for new conn"); |
| 2633 | goto unlock; |
| 2634 | } |
Abhishek Pandit-Subedi | 2d186fc | 2020-03-19 17:07:13 -0700 | [diff] [blame] | 2635 | } else { |
| 2636 | if (ev->link_type != SCO_LINK) |
| 2637 | goto unlock; |
| 2638 | |
| 2639 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, |
| 2640 | &ev->bdaddr); |
| 2641 | if (!conn) |
| 2642 | goto unlock; |
| 2643 | |
| 2644 | conn->type = SCO_LINK; |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2645 | } |
Marcel Holtmann | 9499237 | 2009-04-19 19:30:03 +0200 | [diff] [blame] | 2646 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2647 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2648 | if (!ev->status) { |
| 2649 | conn->handle = __le16_to_cpu(ev->handle); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2650 | |
| 2651 | if (conn->type == ACL_LINK) { |
| 2652 | conn->state = BT_CONFIG; |
| 2653 | hci_conn_hold(conn); |
Szymon Janc | a9ea3ed | 2012-07-19 14:46:08 +0200 | [diff] [blame] | 2654 | |
| 2655 | if (!conn->out && !hci_conn_ssp_enabled(conn) && |
| 2656 | !hci_find_link_key(hdev, &ev->bdaddr)) |
| 2657 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
| 2658 | else |
| 2659 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2660 | } else |
| 2661 | conn->state = BT_CONNECTED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2662 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 2663 | hci_debugfs_create_conn(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 2664 | hci_conn_add_sysfs(conn); |
| 2665 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2666 | if (test_bit(HCI_AUTH, &hdev->flags)) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 2667 | set_bit(HCI_CONN_AUTH, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2668 | |
| 2669 | if (test_bit(HCI_ENCRYPT, &hdev->flags)) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 2670 | set_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2671 | |
| 2672 | /* Get remote features */ |
| 2673 | if (conn->type == ACL_LINK) { |
| 2674 | struct hci_cp_read_remote_features cp; |
| 2675 | cp.handle = ev->handle; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2676 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2677 | sizeof(cp), &cp); |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 2678 | |
Johan Hedberg | 01b1cb8 | 2015-11-16 12:52:21 +0200 | [diff] [blame] | 2679 | hci_req_update_scan(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2680 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2681 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2682 | /* Set packet type for incoming connection */ |
Andrei Emeltchenko | d095c1e | 2011-12-01 14:33:27 +0200 | [diff] [blame] | 2683 | if (!conn->out && hdev->hci_ver < BLUETOOTH_VER_2_0) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2684 | struct hci_cp_change_conn_ptype cp; |
| 2685 | cp.handle = ev->handle; |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 2686 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2687 | hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp), |
| 2688 | &cp); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2689 | } |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 2690 | } else { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2691 | conn->state = BT_CLOSED; |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 2692 | if (conn->type == ACL_LINK) |
Marcel Holtmann | 64c7b77 | 2014-02-18 14:22:20 -0800 | [diff] [blame] | 2693 | mgmt_connect_failed(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2694 | conn->dst_type, ev->status); |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 2695 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2696 | |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2697 | if (conn->type == ACL_LINK) |
| 2698 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2699 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2700 | if (ev->status) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2701 | hci_connect_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2702 | hci_conn_del(conn); |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 2703 | } else if (ev->link_type == SCO_LINK) { |
| 2704 | switch (conn->setting & SCO_AIRMODE_MASK) { |
| 2705 | case SCO_AIRMODE_CVSD: |
| 2706 | if (hdev->notify) |
| 2707 | hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD); |
| 2708 | break; |
| 2709 | } |
| 2710 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2711 | hci_connect_cfm(conn, ev->status); |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 2712 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2713 | |
| 2714 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2716 | |
| 2717 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2718 | } |
| 2719 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2720 | static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) |
| 2721 | { |
| 2722 | struct hci_cp_reject_conn_req cp; |
| 2723 | |
| 2724 | bacpy(&cp.bdaddr, bdaddr); |
| 2725 | cp.reason = HCI_ERROR_REJ_BAD_ADDR; |
| 2726 | hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp); |
| 2727 | } |
| 2728 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2729 | static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2731 | struct hci_ev_conn_request *ev = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | int mask = hdev->link_mode; |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2733 | struct inquiry_entry *ie; |
| 2734 | struct hci_conn *conn; |
Frédéric Dalleau | 20714bfe | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 2735 | __u8 flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 2737 | BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2738 | ev->link_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | |
Frédéric Dalleau | 20714bfe | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 2740 | mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type, |
| 2741 | &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2742 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2743 | if (!(mask & HCI_LM_ACCEPT)) { |
| 2744 | hci_reject_conn(hdev, &ev->bdaddr); |
| 2745 | return; |
| 2746 | } |
| 2747 | |
Johan Hedberg | 46c4c94 | 2014-07-16 16:19:21 +0300 | [diff] [blame] | 2748 | if (hci_bdaddr_list_lookup(&hdev->blacklist, &ev->bdaddr, |
| 2749 | BDADDR_BREDR)) { |
| 2750 | hci_reject_conn(hdev, &ev->bdaddr); |
| 2751 | return; |
| 2752 | } |
| 2753 | |
Johan Hedberg | 6a8fc95 | 2014-12-24 20:43:11 +0200 | [diff] [blame] | 2754 | /* Require HCI_CONNECTABLE or a whitelist entry to accept the |
| 2755 | * connection. These features are only touched through mgmt so |
| 2756 | * only do the checks if HCI_MGMT is set. |
| 2757 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2758 | if (hci_dev_test_flag(hdev, HCI_MGMT) && |
| 2759 | !hci_dev_test_flag(hdev, HCI_CONNECTABLE) && |
Abhishek Pandit-Subedi | 8baaa40 | 2020-06-17 16:39:08 +0200 | [diff] [blame] | 2760 | !hci_bdaddr_list_lookup_with_flags(&hdev->whitelist, &ev->bdaddr, |
| 2761 | BDADDR_BREDR)) { |
| 2762 | hci_reject_conn(hdev, &ev->bdaddr); |
| 2763 | return; |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2764 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2765 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2766 | /* Connection accepted */ |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2767 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2768 | hci_dev_lock(hdev); |
Marcel Holtmann | c7bdd50 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 2769 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2770 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 2771 | if (ie) |
| 2772 | memcpy(ie->data.dev_class, ev->dev_class, 3); |
| 2773 | |
| 2774 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, |
| 2775 | &ev->bdaddr); |
| 2776 | if (!conn) { |
Johan Hedberg | a5c4e30 | 2014-07-16 11:56:07 +0300 | [diff] [blame] | 2777 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr, |
| 2778 | HCI_ROLE_SLAVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | if (!conn) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2780 | bt_dev_err(hdev, "no memory for new connection"); |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2781 | hci_dev_unlock(hdev); |
| 2782 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | } |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2784 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2785 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2786 | memcpy(conn->dev_class, ev->dev_class, 3); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2787 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2788 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2790 | if (ev->link_type == ACL_LINK || |
| 2791 | (!(flags & HCI_PROTO_DEFER) && !lmp_esco_capable(hdev))) { |
| 2792 | struct hci_cp_accept_conn_req cp; |
| 2793 | conn->state = BT_CONNECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2794 | |
| 2795 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2796 | |
| 2797 | if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) |
| 2798 | cp.role = 0x00; /* Become master */ |
| 2799 | else |
| 2800 | cp.role = 0x01; /* Remain slave */ |
| 2801 | |
| 2802 | hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp); |
| 2803 | } else if (!(flags & HCI_PROTO_DEFER)) { |
| 2804 | struct hci_cp_accept_sync_conn_req cp; |
| 2805 | conn->state = BT_CONNECT; |
| 2806 | |
| 2807 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 2808 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
| 2809 | |
| 2810 | cp.tx_bandwidth = cpu_to_le32(0x00001f40); |
| 2811 | cp.rx_bandwidth = cpu_to_le32(0x00001f40); |
| 2812 | cp.max_latency = cpu_to_le16(0xffff); |
| 2813 | cp.content_format = cpu_to_le16(hdev->voice_setting); |
| 2814 | cp.retrans_effort = 0xff; |
| 2815 | |
| 2816 | hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp), |
| 2817 | &cp); |
| 2818 | } else { |
| 2819 | conn->state = BT_CONNECT2; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2820 | hci_connect_cfm(conn, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | } |
| 2822 | } |
| 2823 | |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 2824 | static u8 hci_to_mgmt_reason(u8 err) |
| 2825 | { |
| 2826 | switch (err) { |
| 2827 | case HCI_ERROR_CONNECTION_TIMEOUT: |
| 2828 | return MGMT_DEV_DISCONN_TIMEOUT; |
| 2829 | case HCI_ERROR_REMOTE_USER_TERM: |
| 2830 | case HCI_ERROR_REMOTE_LOW_RESOURCES: |
| 2831 | case HCI_ERROR_REMOTE_POWER_OFF: |
| 2832 | return MGMT_DEV_DISCONN_REMOTE; |
| 2833 | case HCI_ERROR_LOCAL_HOST_TERM: |
| 2834 | return MGMT_DEV_DISCONN_LOCAL_HOST; |
| 2835 | default: |
| 2836 | return MGMT_DEV_DISCONN_UNKNOWN; |
| 2837 | } |
| 2838 | } |
| 2839 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2840 | static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2841 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2842 | struct hci_ev_disconn_complete *ev = (void *) skb->data; |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 2843 | u8 reason; |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2844 | struct hci_conn_params *params; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2845 | struct hci_conn *conn; |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 2846 | bool mgmt_connected; |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 2847 | u8 type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2848 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2849 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2850 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | hci_dev_lock(hdev); |
| 2852 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2853 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 2854 | if (!conn) |
| 2855 | goto unlock; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 2856 | |
Andre Guedes | abf54a5 | 2013-11-07 17:36:09 -0300 | [diff] [blame] | 2857 | if (ev->status) { |
| 2858 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
| 2859 | conn->dst_type, ev->status); |
| 2860 | goto unlock; |
Johan Hedberg | 37d9ef7 | 2011-11-10 15:54:39 +0200 | [diff] [blame] | 2861 | } |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 2862 | |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 2863 | conn->state = BT_CLOSED; |
| 2864 | |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 2865 | mgmt_connected = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 2866 | |
| 2867 | if (test_bit(HCI_CONN_AUTH_FAILURE, &conn->flags)) |
| 2868 | reason = MGMT_DEV_DISCONN_AUTH_FAILURE; |
| 2869 | else |
| 2870 | reason = hci_to_mgmt_reason(ev->reason); |
| 2871 | |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 2872 | mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type, |
| 2873 | reason, mgmt_connected); |
Andre Guedes | abf54a5 | 2013-11-07 17:36:09 -0300 | [diff] [blame] | 2874 | |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 2875 | if (conn->type == ACL_LINK) { |
| 2876 | if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) |
| 2877 | hci_remove_link_key(hdev, &conn->dst); |
| 2878 | |
Johan Hedberg | 01b1cb8 | 2015-11-16 12:52:21 +0200 | [diff] [blame] | 2879 | hci_req_update_scan(hdev); |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 2880 | } |
Johan Hedberg | 2210246 | 2013-10-05 12:01:06 +0200 | [diff] [blame] | 2881 | |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2882 | params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); |
| 2883 | if (params) { |
| 2884 | switch (params->auto_connect) { |
| 2885 | case HCI_AUTO_CONN_LINK_LOSS: |
| 2886 | if (ev->reason != HCI_ERROR_CONNECTION_TIMEOUT) |
| 2887 | break; |
Gustavo A. R. Silva | 19186c7 | 2020-07-08 15:18:23 -0500 | [diff] [blame] | 2888 | fallthrough; |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2889 | |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 2890 | case HCI_AUTO_CONN_DIRECT: |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2891 | case HCI_AUTO_CONN_ALWAYS: |
Johan Hedberg | 418025d | 2014-07-04 12:37:24 +0300 | [diff] [blame] | 2892 | list_del_init(¶ms->action); |
| 2893 | list_add(¶ms->action, &hdev->pend_le_conns); |
| 2894 | hci_update_background_scan(hdev); |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2895 | break; |
| 2896 | |
| 2897 | default: |
| 2898 | break; |
| 2899 | } |
| 2900 | } |
| 2901 | |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 2902 | type = conn->type; |
Johan Hedberg | 2210246 | 2013-10-05 12:01:06 +0200 | [diff] [blame] | 2903 | |
Johan Hedberg | 3a6d576 | 2015-02-18 14:53:58 +0200 | [diff] [blame] | 2904 | hci_disconn_cfm(conn, ev->reason); |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 2905 | hci_conn_del(conn); |
| 2906 | |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2907 | /* The suspend notifier is waiting for all devices to disconnect so |
| 2908 | * clear the bit from pending tasks and inform the wait queue. |
| 2909 | */ |
| 2910 | if (list_empty(&hdev->conn_hash.list) && |
| 2911 | test_and_clear_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks)) { |
| 2912 | wake_up(&hdev->suspend_wait_q); |
| 2913 | } |
| 2914 | |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 2915 | /* Re-enable advertising if necessary, since it might |
| 2916 | * have been disabled by the connection. From the |
| 2917 | * HCI_LE_Set_Advertise_Enable command description in |
| 2918 | * the core specification (v4.0): |
| 2919 | * "The Controller shall continue advertising until the Host |
| 2920 | * issues an LE_Set_Advertise_Enable command with |
| 2921 | * Advertising_Enable set to 0x00 (Advertising is disabled) |
| 2922 | * or until a connection is created or until the Advertising |
| 2923 | * is timed out due to Directed Advertising." |
| 2924 | */ |
| 2925 | if (type == LE_LINK) |
Johan Hedberg | f225257 | 2015-11-18 12:49:20 +0200 | [diff] [blame] | 2926 | hci_req_reenable_advertising(hdev); |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 2927 | |
| 2928 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | hci_dev_unlock(hdev); |
| 2930 | } |
| 2931 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2932 | static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2933 | { |
| 2934 | struct hci_ev_auth_complete *ev = (void *) skb->data; |
| 2935 | struct hci_conn *conn; |
| 2936 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2937 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2938 | |
| 2939 | hci_dev_lock(hdev); |
| 2940 | |
| 2941 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2942 | if (!conn) |
| 2943 | goto unlock; |
| 2944 | |
| 2945 | if (!ev->status) { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 2946 | clear_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 2947 | |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 2948 | if (!hci_conn_ssp_enabled(conn) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2949 | test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2950 | bt_dev_info(hdev, "re-auth of legacy device is not possible."); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 2951 | } else { |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 2952 | set_bit(HCI_CONN_AUTH, &conn->flags); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2953 | conn->sec_level = conn->pending_sec_level; |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 2954 | } |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2955 | } else { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 2956 | if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) |
| 2957 | set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 2958 | |
Johan Hedberg | e1e930f | 2014-09-08 17:09:49 -0700 | [diff] [blame] | 2959 | mgmt_auth_failed(conn, ev->status); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2960 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2961 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2962 | clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); |
| 2963 | clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2964 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2965 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 2966 | if (!ev->status && hci_conn_ssp_enabled(conn)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2967 | struct hci_cp_set_conn_encrypt cp; |
| 2968 | cp.handle = ev->handle; |
| 2969 | cp.encrypt = 0x01; |
| 2970 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2971 | &cp); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2972 | } else { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2973 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2974 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2975 | hci_conn_drop(conn); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2976 | } |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2977 | } else { |
| 2978 | hci_auth_cfm(conn, ev->status); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 2979 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2980 | hci_conn_hold(conn); |
| 2981 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2982 | hci_conn_drop(conn); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2983 | } |
| 2984 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2985 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2986 | if (!ev->status) { |
| 2987 | struct hci_cp_set_conn_encrypt cp; |
| 2988 | cp.handle = ev->handle; |
| 2989 | cp.encrypt = 0x01; |
| 2990 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2991 | &cp); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2992 | } else { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2993 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 2994 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2995 | } |
| 2996 | } |
| 2997 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 2998 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2999 | hci_dev_unlock(hdev); |
| 3000 | } |
| 3001 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3002 | static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3003 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3004 | struct hci_ev_remote_name *ev = (void *) skb->data; |
| 3005 | struct hci_conn *conn; |
| 3006 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3007 | BT_DBG("%s", hdev->name); |
| 3008 | |
| 3009 | hci_conn_check_pending(hdev); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3010 | |
| 3011 | hci_dev_lock(hdev); |
| 3012 | |
| 3013 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3014 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 3015 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3016 | goto check_auth; |
| 3017 | |
| 3018 | if (ev->status == 0) |
| 3019 | hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3020 | strnlen(ev->name, HCI_MAX_NAME_LENGTH)); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3021 | else |
| 3022 | hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0); |
| 3023 | |
| 3024 | check_auth: |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 3025 | if (!conn) |
| 3026 | goto unlock; |
| 3027 | |
| 3028 | if (!hci_outgoing_auth_needed(hdev, conn)) |
| 3029 | goto unlock; |
| 3030 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3031 | if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3032 | struct hci_cp_auth_requested cp; |
Johan Hedberg | 977f8fc | 2014-07-17 15:35:39 +0300 | [diff] [blame] | 3033 | |
| 3034 | set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); |
| 3035 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3036 | cp.handle = __cpu_to_le16(conn->handle); |
| 3037 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); |
| 3038 | } |
| 3039 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 3040 | unlock: |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3041 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3042 | } |
| 3043 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3044 | static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, |
| 3045 | u16 opcode, struct sk_buff *skb) |
| 3046 | { |
| 3047 | const struct hci_rp_read_enc_key_size *rp; |
| 3048 | struct hci_conn *conn; |
| 3049 | u16 handle; |
| 3050 | |
| 3051 | BT_DBG("%s status 0x%02x", hdev->name, status); |
| 3052 | |
| 3053 | if (!skb || skb->len < sizeof(*rp)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3054 | bt_dev_err(hdev, "invalid read key size response"); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3055 | return; |
| 3056 | } |
| 3057 | |
| 3058 | rp = (void *)skb->data; |
| 3059 | handle = le16_to_cpu(rp->handle); |
| 3060 | |
| 3061 | hci_dev_lock(hdev); |
| 3062 | |
| 3063 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
| 3064 | if (!conn) |
| 3065 | goto unlock; |
| 3066 | |
Alain Michaud | 32b5072 | 2020-03-25 14:48:34 +0000 | [diff] [blame] | 3067 | /* While unexpected, the read_enc_key_size command may fail. The most |
| 3068 | * secure approach is to then assume the key size is 0 to force a |
| 3069 | * disconnection. |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3070 | */ |
| 3071 | if (rp->status) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3072 | bt_dev_err(hdev, "failed to read key size for handle %u", |
| 3073 | handle); |
Alain Michaud | 32b5072 | 2020-03-25 14:48:34 +0000 | [diff] [blame] | 3074 | conn->enc_key_size = 0; |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3075 | } else { |
| 3076 | conn->enc_key_size = rp->key_size; |
| 3077 | } |
| 3078 | |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 3079 | hci_encrypt_cfm(conn, 0); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3080 | |
| 3081 | unlock: |
| 3082 | hci_dev_unlock(hdev); |
| 3083 | } |
| 3084 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3085 | static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3086 | { |
| 3087 | struct hci_ev_encrypt_change *ev = (void *) skb->data; |
| 3088 | struct hci_conn *conn; |
| 3089 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3090 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3091 | |
| 3092 | hci_dev_lock(hdev); |
| 3093 | |
| 3094 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3095 | if (!conn) |
| 3096 | goto unlock; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3097 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3098 | if (!ev->status) { |
| 3099 | if (ev->encrypt) { |
| 3100 | /* Encryption implies authentication */ |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3101 | set_bit(HCI_CONN_AUTH, &conn->flags); |
| 3102 | set_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3103 | conn->sec_level = conn->pending_sec_level; |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3104 | |
Marcel Holtmann | 914a6ff | 2014-02-01 11:52:02 -0800 | [diff] [blame] | 3105 | /* P-256 authentication key implies FIPS */ |
| 3106 | if (conn->key_type == HCI_LK_AUTH_COMBINATION_P256) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3107 | set_bit(HCI_CONN_FIPS, &conn->flags); |
Marcel Holtmann | 914a6ff | 2014-02-01 11:52:02 -0800 | [diff] [blame] | 3108 | |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3109 | if ((conn->type == ACL_LINK && ev->encrypt == 0x02) || |
| 3110 | conn->type == LE_LINK) |
| 3111 | set_bit(HCI_CONN_AES_CCM, &conn->flags); |
| 3112 | } else { |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3113 | clear_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3114 | clear_bit(HCI_CONN_AES_CCM, &conn->flags); |
| 3115 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3116 | } |
| 3117 | |
Johan Hedberg | 7ed3fa2 | 2014-09-10 22:16:35 -0700 | [diff] [blame] | 3118 | /* We should disregard the current RPA and generate a new one |
| 3119 | * whenever the encryption procedure fails. |
| 3120 | */ |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 3121 | if (ev->status && conn->type == LE_LINK) { |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 3122 | hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 3123 | hci_adv_instances_set_rpa_expired(hdev, true); |
| 3124 | } |
Johan Hedberg | 7ed3fa2 | 2014-09-10 22:16:35 -0700 | [diff] [blame] | 3125 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3126 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
| 3127 | |
Luiz Augusto von Dentz | 8746f13 | 2020-05-20 14:20:14 -0700 | [diff] [blame] | 3128 | /* Check link security requirements are met */ |
| 3129 | if (!hci_conn_check_link_mode(conn)) |
| 3130 | ev->status = HCI_ERROR_AUTH_FAILURE; |
| 3131 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3132 | if (ev->status && conn->state == BT_CONNECTED) { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3133 | if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) |
| 3134 | set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 3135 | |
Luiz Augusto von Dentz | 8746f13 | 2020-05-20 14:20:14 -0700 | [diff] [blame] | 3136 | /* Notify upper layers so they can cleanup before |
| 3137 | * disconnecting. |
| 3138 | */ |
| 3139 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3140 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
| 3141 | hci_conn_drop(conn); |
| 3142 | goto unlock; |
| 3143 | } |
| 3144 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3145 | /* Try reading the encryption key size for encrypted ACL links */ |
| 3146 | if (!ev->status && ev->encrypt && conn->type == ACL_LINK) { |
| 3147 | struct hci_cp_read_enc_key_size cp; |
| 3148 | struct hci_request req; |
| 3149 | |
| 3150 | /* Only send HCI_Read_Encryption_Key_Size if the |
| 3151 | * controller really supports it. If it doesn't, assume |
| 3152 | * the default size (16). |
| 3153 | */ |
| 3154 | if (!(hdev->commands[20] & 0x10)) { |
| 3155 | conn->enc_key_size = HCI_LINK_KEY_SIZE; |
| 3156 | goto notify; |
| 3157 | } |
| 3158 | |
| 3159 | hci_req_init(&req, hdev); |
| 3160 | |
| 3161 | cp.handle = cpu_to_le16(conn->handle); |
| 3162 | hci_req_add(&req, HCI_OP_READ_ENC_KEY_SIZE, sizeof(cp), &cp); |
| 3163 | |
| 3164 | if (hci_req_run_skb(&req, read_enc_key_size_complete)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3165 | bt_dev_err(hdev, "sending read key size failed"); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3166 | conn->enc_key_size = HCI_LINK_KEY_SIZE; |
| 3167 | goto notify; |
| 3168 | } |
| 3169 | |
| 3170 | goto unlock; |
| 3171 | } |
| 3172 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 3173 | /* Set the default Authenticated Payload Timeout after |
| 3174 | * an LE Link is established. As per Core Spec v5.0, Vol 2, Part B |
| 3175 | * Section 3.3, the HCI command WRITE_AUTH_PAYLOAD_TIMEOUT should be |
| 3176 | * sent when the link is active and Encryption is enabled, the conn |
| 3177 | * type can be either LE or ACL and controller must support LMP Ping. |
| 3178 | * Ensure for AES-CCM encryption as well. |
| 3179 | */ |
| 3180 | if (test_bit(HCI_CONN_ENCRYPT, &conn->flags) && |
| 3181 | test_bit(HCI_CONN_AES_CCM, &conn->flags) && |
| 3182 | ((conn->type == ACL_LINK && lmp_ping_capable(hdev)) || |
| 3183 | (conn->type == LE_LINK && (hdev->le_features[0] & HCI_LE_PING)))) { |
| 3184 | struct hci_cp_write_auth_payload_to cp; |
| 3185 | |
| 3186 | cp.handle = cpu_to_le16(conn->handle); |
| 3187 | cp.timeout = cpu_to_le16(hdev->auth_payload_timeout); |
| 3188 | hci_send_cmd(conn->hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO, |
| 3189 | sizeof(cp), &cp); |
| 3190 | } |
| 3191 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3192 | notify: |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 3193 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3194 | |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 3195 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3196 | hci_dev_unlock(hdev); |
| 3197 | } |
| 3198 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3199 | static void hci_change_link_key_complete_evt(struct hci_dev *hdev, |
| 3200 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3201 | { |
| 3202 | struct hci_ev_change_link_key_complete *ev = (void *) skb->data; |
| 3203 | struct hci_conn *conn; |
| 3204 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3205 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3206 | |
| 3207 | hci_dev_lock(hdev); |
| 3208 | |
| 3209 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 3210 | if (conn) { |
| 3211 | if (!ev->status) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3212 | set_bit(HCI_CONN_SECURE, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3213 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3214 | clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3215 | |
| 3216 | hci_key_change_cfm(conn, ev->status); |
| 3217 | } |
| 3218 | |
| 3219 | hci_dev_unlock(hdev); |
| 3220 | } |
| 3221 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3222 | static void hci_remote_features_evt(struct hci_dev *hdev, |
| 3223 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3224 | { |
| 3225 | struct hci_ev_remote_features *ev = (void *) skb->data; |
| 3226 | struct hci_conn *conn; |
| 3227 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3228 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3229 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3230 | hci_dev_lock(hdev); |
| 3231 | |
| 3232 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3233 | if (!conn) |
| 3234 | goto unlock; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3235 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3236 | if (!ev->status) |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 3237 | memcpy(conn->features[0], ev->features, 8); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3238 | |
| 3239 | if (conn->state != BT_CONFIG) |
| 3240 | goto unlock; |
| 3241 | |
Szymon Janc | ac363cf | 2015-01-29 16:36:59 +0100 | [diff] [blame] | 3242 | if (!ev->status && lmp_ext_feat_capable(hdev) && |
| 3243 | lmp_ext_feat_capable(conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3244 | struct hci_cp_read_remote_ext_features cp; |
| 3245 | cp.handle = ev->handle; |
| 3246 | cp.page = 0x01; |
| 3247 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3248 | sizeof(cp), &cp); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 3249 | goto unlock; |
| 3250 | } |
| 3251 | |
Johan Hedberg | 671267b | 2012-05-12 16:11:50 -0300 | [diff] [blame] | 3252 | if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3253 | struct hci_cp_remote_name_req cp; |
| 3254 | memset(&cp, 0, sizeof(cp)); |
| 3255 | bacpy(&cp.bdaddr, &conn->dst); |
| 3256 | cp.pscan_rep_mode = 0x02; |
| 3257 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3258 | } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 3259 | mgmt_device_connected(hdev, conn, NULL, 0); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 3260 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3261 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3262 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 3263 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 3264 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3265 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3266 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3267 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3268 | hci_dev_unlock(hdev); |
| 3269 | } |
| 3270 | |
Manish Mandlik | de75cd0 | 2021-04-29 10:24:22 -0700 | [diff] [blame^] | 3271 | static inline void handle_cmd_cnt_and_timer(struct hci_dev *hdev, |
| 3272 | u16 opcode, u8 ncmd) |
| 3273 | { |
| 3274 | if (opcode != HCI_OP_NOP) |
| 3275 | cancel_delayed_work(&hdev->cmd_timer); |
| 3276 | |
| 3277 | if (!test_bit(HCI_RESET, &hdev->flags)) { |
| 3278 | if (ncmd) { |
| 3279 | cancel_delayed_work(&hdev->ncmd_timer); |
| 3280 | atomic_set(&hdev->cmd_cnt, 1); |
| 3281 | } else { |
| 3282 | schedule_delayed_work(&hdev->ncmd_timer, |
| 3283 | HCI_NCMD_TIMEOUT); |
| 3284 | } |
| 3285 | } |
| 3286 | } |
| 3287 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3288 | static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, |
| 3289 | u16 *opcode, u8 *status, |
| 3290 | hci_req_complete_t *req_complete, |
| 3291 | hci_req_complete_skb_t *req_complete_skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3292 | { |
| 3293 | struct hci_ev_cmd_complete *ev = (void *) skb->data; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3294 | |
| 3295 | *opcode = __le16_to_cpu(ev->opcode); |
| 3296 | *status = skb->data[sizeof(*ev)]; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3297 | |
| 3298 | skb_pull(skb, sizeof(*ev)); |
| 3299 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3300 | switch (*opcode) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3301 | case HCI_OP_INQUIRY_CANCEL: |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 3302 | hci_cc_inquiry_cancel(hdev, skb, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3303 | break; |
| 3304 | |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 3305 | case HCI_OP_PERIODIC_INQ: |
| 3306 | hci_cc_periodic_inq(hdev, skb); |
| 3307 | break; |
| 3308 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3309 | case HCI_OP_EXIT_PERIODIC_INQ: |
| 3310 | hci_cc_exit_periodic_inq(hdev, skb); |
| 3311 | break; |
| 3312 | |
| 3313 | case HCI_OP_REMOTE_NAME_REQ_CANCEL: |
| 3314 | hci_cc_remote_name_req_cancel(hdev, skb); |
| 3315 | break; |
| 3316 | |
| 3317 | case HCI_OP_ROLE_DISCOVERY: |
| 3318 | hci_cc_role_discovery(hdev, skb); |
| 3319 | break; |
| 3320 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 3321 | case HCI_OP_READ_LINK_POLICY: |
| 3322 | hci_cc_read_link_policy(hdev, skb); |
| 3323 | break; |
| 3324 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3325 | case HCI_OP_WRITE_LINK_POLICY: |
| 3326 | hci_cc_write_link_policy(hdev, skb); |
| 3327 | break; |
| 3328 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 3329 | case HCI_OP_READ_DEF_LINK_POLICY: |
| 3330 | hci_cc_read_def_link_policy(hdev, skb); |
| 3331 | break; |
| 3332 | |
| 3333 | case HCI_OP_WRITE_DEF_LINK_POLICY: |
| 3334 | hci_cc_write_def_link_policy(hdev, skb); |
| 3335 | break; |
| 3336 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3337 | case HCI_OP_RESET: |
| 3338 | hci_cc_reset(hdev, skb); |
| 3339 | break; |
| 3340 | |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 3341 | case HCI_OP_READ_STORED_LINK_KEY: |
| 3342 | hci_cc_read_stored_link_key(hdev, skb); |
| 3343 | break; |
| 3344 | |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 3345 | case HCI_OP_DELETE_STORED_LINK_KEY: |
| 3346 | hci_cc_delete_stored_link_key(hdev, skb); |
| 3347 | break; |
| 3348 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3349 | case HCI_OP_WRITE_LOCAL_NAME: |
| 3350 | hci_cc_write_local_name(hdev, skb); |
| 3351 | break; |
| 3352 | |
| 3353 | case HCI_OP_READ_LOCAL_NAME: |
| 3354 | hci_cc_read_local_name(hdev, skb); |
| 3355 | break; |
| 3356 | |
| 3357 | case HCI_OP_WRITE_AUTH_ENABLE: |
| 3358 | hci_cc_write_auth_enable(hdev, skb); |
| 3359 | break; |
| 3360 | |
| 3361 | case HCI_OP_WRITE_ENCRYPT_MODE: |
| 3362 | hci_cc_write_encrypt_mode(hdev, skb); |
| 3363 | break; |
| 3364 | |
| 3365 | case HCI_OP_WRITE_SCAN_ENABLE: |
| 3366 | hci_cc_write_scan_enable(hdev, skb); |
| 3367 | break; |
| 3368 | |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 3369 | case HCI_OP_SET_EVENT_FLT: |
| 3370 | hci_cc_set_event_filter(hdev, skb); |
| 3371 | break; |
| 3372 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3373 | case HCI_OP_READ_CLASS_OF_DEV: |
| 3374 | hci_cc_read_class_of_dev(hdev, skb); |
| 3375 | break; |
| 3376 | |
| 3377 | case HCI_OP_WRITE_CLASS_OF_DEV: |
| 3378 | hci_cc_write_class_of_dev(hdev, skb); |
| 3379 | break; |
| 3380 | |
| 3381 | case HCI_OP_READ_VOICE_SETTING: |
| 3382 | hci_cc_read_voice_setting(hdev, skb); |
| 3383 | break; |
| 3384 | |
| 3385 | case HCI_OP_WRITE_VOICE_SETTING: |
| 3386 | hci_cc_write_voice_setting(hdev, skb); |
| 3387 | break; |
| 3388 | |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 3389 | case HCI_OP_READ_NUM_SUPPORTED_IAC: |
| 3390 | hci_cc_read_num_supported_iac(hdev, skb); |
| 3391 | break; |
| 3392 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3393 | case HCI_OP_WRITE_SSP_MODE: |
| 3394 | hci_cc_write_ssp_mode(hdev, skb); |
| 3395 | break; |
| 3396 | |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 3397 | case HCI_OP_WRITE_SC_SUPPORT: |
| 3398 | hci_cc_write_sc_support(hdev, skb); |
| 3399 | break; |
| 3400 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 3401 | case HCI_OP_READ_AUTH_PAYLOAD_TO: |
| 3402 | hci_cc_read_auth_payload_timeout(hdev, skb); |
| 3403 | break; |
| 3404 | |
| 3405 | case HCI_OP_WRITE_AUTH_PAYLOAD_TO: |
| 3406 | hci_cc_write_auth_payload_timeout(hdev, skb); |
| 3407 | break; |
| 3408 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3409 | case HCI_OP_READ_LOCAL_VERSION: |
| 3410 | hci_cc_read_local_version(hdev, skb); |
| 3411 | break; |
| 3412 | |
| 3413 | case HCI_OP_READ_LOCAL_COMMANDS: |
| 3414 | hci_cc_read_local_commands(hdev, skb); |
| 3415 | break; |
| 3416 | |
| 3417 | case HCI_OP_READ_LOCAL_FEATURES: |
| 3418 | hci_cc_read_local_features(hdev, skb); |
| 3419 | break; |
| 3420 | |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 3421 | case HCI_OP_READ_LOCAL_EXT_FEATURES: |
| 3422 | hci_cc_read_local_ext_features(hdev, skb); |
| 3423 | break; |
| 3424 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3425 | case HCI_OP_READ_BUFFER_SIZE: |
| 3426 | hci_cc_read_buffer_size(hdev, skb); |
| 3427 | break; |
| 3428 | |
| 3429 | case HCI_OP_READ_BD_ADDR: |
| 3430 | hci_cc_read_bd_addr(hdev, skb); |
| 3431 | break; |
| 3432 | |
Marcel Holtmann | a479036 | 2020-04-03 21:44:04 +0200 | [diff] [blame] | 3433 | case HCI_OP_READ_LOCAL_PAIRING_OPTS: |
| 3434 | hci_cc_read_local_pairing_opts(hdev, skb); |
| 3435 | break; |
| 3436 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 3437 | case HCI_OP_READ_PAGE_SCAN_ACTIVITY: |
| 3438 | hci_cc_read_page_scan_activity(hdev, skb); |
| 3439 | break; |
| 3440 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 3441 | case HCI_OP_WRITE_PAGE_SCAN_ACTIVITY: |
| 3442 | hci_cc_write_page_scan_activity(hdev, skb); |
| 3443 | break; |
| 3444 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 3445 | case HCI_OP_READ_PAGE_SCAN_TYPE: |
| 3446 | hci_cc_read_page_scan_type(hdev, skb); |
| 3447 | break; |
| 3448 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 3449 | case HCI_OP_WRITE_PAGE_SCAN_TYPE: |
| 3450 | hci_cc_write_page_scan_type(hdev, skb); |
| 3451 | break; |
| 3452 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 3453 | case HCI_OP_READ_DATA_BLOCK_SIZE: |
| 3454 | hci_cc_read_data_block_size(hdev, skb); |
| 3455 | break; |
| 3456 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 3457 | case HCI_OP_READ_FLOW_CONTROL_MODE: |
| 3458 | hci_cc_read_flow_control_mode(hdev, skb); |
| 3459 | break; |
| 3460 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 3461 | case HCI_OP_READ_LOCAL_AMP_INFO: |
| 3462 | hci_cc_read_local_amp_info(hdev, skb); |
| 3463 | break; |
| 3464 | |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 3465 | case HCI_OP_READ_CLOCK: |
| 3466 | hci_cc_read_clock(hdev, skb); |
| 3467 | break; |
| 3468 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 3469 | case HCI_OP_READ_INQ_RSP_TX_POWER: |
| 3470 | hci_cc_read_inq_rsp_tx_power(hdev, skb); |
| 3471 | break; |
| 3472 | |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 3473 | case HCI_OP_READ_DEF_ERR_DATA_REPORTING: |
| 3474 | hci_cc_read_def_err_data_reporting(hdev, skb); |
| 3475 | break; |
| 3476 | |
| 3477 | case HCI_OP_WRITE_DEF_ERR_DATA_REPORTING: |
| 3478 | hci_cc_write_def_err_data_reporting(hdev, skb); |
| 3479 | break; |
| 3480 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 3481 | case HCI_OP_PIN_CODE_REPLY: |
| 3482 | hci_cc_pin_code_reply(hdev, skb); |
| 3483 | break; |
| 3484 | |
| 3485 | case HCI_OP_PIN_CODE_NEG_REPLY: |
| 3486 | hci_cc_pin_code_neg_reply(hdev, skb); |
| 3487 | break; |
| 3488 | |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 3489 | case HCI_OP_READ_LOCAL_OOB_DATA: |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 3490 | hci_cc_read_local_oob_data(hdev, skb); |
| 3491 | break; |
| 3492 | |
| 3493 | case HCI_OP_READ_LOCAL_OOB_EXT_DATA: |
| 3494 | hci_cc_read_local_oob_ext_data(hdev, skb); |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 3495 | break; |
| 3496 | |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 3497 | case HCI_OP_LE_READ_BUFFER_SIZE: |
| 3498 | hci_cc_le_read_buffer_size(hdev, skb); |
| 3499 | break; |
| 3500 | |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 3501 | case HCI_OP_LE_READ_LOCAL_FEATURES: |
| 3502 | hci_cc_le_read_local_features(hdev, skb); |
| 3503 | break; |
| 3504 | |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 3505 | case HCI_OP_LE_READ_ADV_TX_POWER: |
| 3506 | hci_cc_le_read_adv_tx_power(hdev, skb); |
| 3507 | break; |
| 3508 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 3509 | case HCI_OP_USER_CONFIRM_REPLY: |
| 3510 | hci_cc_user_confirm_reply(hdev, skb); |
| 3511 | break; |
| 3512 | |
| 3513 | case HCI_OP_USER_CONFIRM_NEG_REPLY: |
| 3514 | hci_cc_user_confirm_neg_reply(hdev, skb); |
| 3515 | break; |
| 3516 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 3517 | case HCI_OP_USER_PASSKEY_REPLY: |
| 3518 | hci_cc_user_passkey_reply(hdev, skb); |
| 3519 | break; |
| 3520 | |
| 3521 | case HCI_OP_USER_PASSKEY_NEG_REPLY: |
| 3522 | hci_cc_user_passkey_neg_reply(hdev, skb); |
Szymon Janc | 16cde99 | 2012-04-13 12:32:42 +0200 | [diff] [blame] | 3523 | break; |
Andre Guedes | 07f7fa5 | 2011-12-02 21:13:31 +0900 | [diff] [blame] | 3524 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 3525 | case HCI_OP_LE_SET_RANDOM_ADDR: |
| 3526 | hci_cc_le_set_random_addr(hdev, skb); |
| 3527 | break; |
| 3528 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 3529 | case HCI_OP_LE_SET_ADV_ENABLE: |
| 3530 | hci_cc_le_set_adv_enable(hdev, skb); |
| 3531 | break; |
| 3532 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 3533 | case HCI_OP_LE_SET_SCAN_PARAM: |
| 3534 | hci_cc_le_set_scan_param(hdev, skb); |
| 3535 | break; |
| 3536 | |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 3537 | case HCI_OP_LE_SET_SCAN_ENABLE: |
| 3538 | hci_cc_le_set_scan_enable(hdev, skb); |
| 3539 | break; |
| 3540 | |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 3541 | case HCI_OP_LE_READ_WHITE_LIST_SIZE: |
| 3542 | hci_cc_le_read_white_list_size(hdev, skb); |
| 3543 | break; |
| 3544 | |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 3545 | case HCI_OP_LE_CLEAR_WHITE_LIST: |
| 3546 | hci_cc_le_clear_white_list(hdev, skb); |
| 3547 | break; |
| 3548 | |
| 3549 | case HCI_OP_LE_ADD_TO_WHITE_LIST: |
| 3550 | hci_cc_le_add_to_white_list(hdev, skb); |
| 3551 | break; |
| 3552 | |
| 3553 | case HCI_OP_LE_DEL_FROM_WHITE_LIST: |
| 3554 | hci_cc_le_del_from_white_list(hdev, skb); |
| 3555 | break; |
| 3556 | |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 3557 | case HCI_OP_LE_READ_SUPPORTED_STATES: |
| 3558 | hci_cc_le_read_supported_states(hdev, skb); |
| 3559 | break; |
| 3560 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 3561 | case HCI_OP_LE_READ_DEF_DATA_LEN: |
| 3562 | hci_cc_le_read_def_data_len(hdev, skb); |
| 3563 | break; |
| 3564 | |
| 3565 | case HCI_OP_LE_WRITE_DEF_DATA_LEN: |
| 3566 | hci_cc_le_write_def_data_len(hdev, skb); |
| 3567 | break; |
| 3568 | |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 3569 | case HCI_OP_LE_ADD_TO_RESOLV_LIST: |
| 3570 | hci_cc_le_add_to_resolv_list(hdev, skb); |
| 3571 | break; |
| 3572 | |
| 3573 | case HCI_OP_LE_DEL_FROM_RESOLV_LIST: |
| 3574 | hci_cc_le_del_from_resolv_list(hdev, skb); |
| 3575 | break; |
| 3576 | |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 3577 | case HCI_OP_LE_CLEAR_RESOLV_LIST: |
| 3578 | hci_cc_le_clear_resolv_list(hdev, skb); |
| 3579 | break; |
| 3580 | |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 3581 | case HCI_OP_LE_READ_RESOLV_LIST_SIZE: |
| 3582 | hci_cc_le_read_resolv_list_size(hdev, skb); |
| 3583 | break; |
| 3584 | |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 3585 | case HCI_OP_LE_SET_ADDR_RESOLV_ENABLE: |
| 3586 | hci_cc_le_set_addr_resolution_enable(hdev, skb); |
| 3587 | break; |
| 3588 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 3589 | case HCI_OP_LE_READ_MAX_DATA_LEN: |
| 3590 | hci_cc_le_read_max_data_len(hdev, skb); |
| 3591 | break; |
| 3592 | |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 3593 | case HCI_OP_WRITE_LE_HOST_SUPPORTED: |
| 3594 | hci_cc_write_le_host_supported(hdev, skb); |
| 3595 | break; |
| 3596 | |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 3597 | case HCI_OP_LE_SET_ADV_PARAM: |
| 3598 | hci_cc_set_adv_param(hdev, skb); |
| 3599 | break; |
| 3600 | |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 3601 | case HCI_OP_READ_RSSI: |
| 3602 | hci_cc_read_rssi(hdev, skb); |
| 3603 | break; |
| 3604 | |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 3605 | case HCI_OP_READ_TX_POWER: |
| 3606 | hci_cc_read_tx_power(hdev, skb); |
| 3607 | break; |
| 3608 | |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 3609 | case HCI_OP_WRITE_SSP_DEBUG_MODE: |
| 3610 | hci_cc_write_ssp_debug_mode(hdev, skb); |
| 3611 | break; |
| 3612 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 3613 | case HCI_OP_LE_SET_EXT_SCAN_PARAMS: |
| 3614 | hci_cc_le_set_ext_scan_param(hdev, skb); |
| 3615 | break; |
| 3616 | |
| 3617 | case HCI_OP_LE_SET_EXT_SCAN_ENABLE: |
| 3618 | hci_cc_le_set_ext_scan_enable(hdev, skb); |
| 3619 | break; |
| 3620 | |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 3621 | case HCI_OP_LE_SET_DEFAULT_PHY: |
| 3622 | hci_cc_le_set_default_phy(hdev, skb); |
| 3623 | break; |
| 3624 | |
Jaganath Kanakkassery | 6b49bcb | 2018-07-19 17:09:40 +0530 | [diff] [blame] | 3625 | case HCI_OP_LE_READ_NUM_SUPPORTED_ADV_SETS: |
| 3626 | hci_cc_le_read_num_adv_sets(hdev, skb); |
| 3627 | break; |
| 3628 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 3629 | case HCI_OP_LE_SET_EXT_ADV_PARAMS: |
| 3630 | hci_cc_set_ext_adv_param(hdev, skb); |
| 3631 | break; |
| 3632 | |
| 3633 | case HCI_OP_LE_SET_EXT_ADV_ENABLE: |
| 3634 | hci_cc_le_set_ext_adv_enable(hdev, skb); |
| 3635 | break; |
| 3636 | |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 3637 | case HCI_OP_LE_SET_ADV_SET_RAND_ADDR: |
| 3638 | hci_cc_le_set_adv_set_random_addr(hdev, skb); |
| 3639 | break; |
| 3640 | |
Daniel Winkler | 7c395ea | 2020-12-03 12:12:51 -0800 | [diff] [blame] | 3641 | case HCI_OP_LE_READ_TRANSMIT_POWER: |
| 3642 | hci_cc_le_read_transmit_power(hdev, skb); |
| 3643 | break; |
| 3644 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3645 | default: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3646 | BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3647 | break; |
| 3648 | } |
| 3649 | |
Manish Mandlik | de75cd0 | 2021-04-29 10:24:22 -0700 | [diff] [blame^] | 3650 | handle_cmd_cnt_and_timer(hdev, *opcode, ev->ncmd); |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 3651 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3652 | hci_req_cmd_complete(hdev, *opcode, *status, req_complete, |
| 3653 | req_complete_skb); |
Johan Hedberg | 9238f36 | 2013-03-05 20:37:48 +0200 | [diff] [blame] | 3654 | |
João Paulo Rechi Vita | f80c5da | 2019-05-02 10:01:52 +0800 | [diff] [blame] | 3655 | if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) { |
| 3656 | bt_dev_err(hdev, |
| 3657 | "unexpected event for opcode 0x%4.4x", *opcode); |
| 3658 | return; |
| 3659 | } |
| 3660 | |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 3661 | if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) |
| 3662 | queue_work(hdev->workqueue, &hdev->cmd_work); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3663 | } |
| 3664 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3665 | static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb, |
| 3666 | u16 *opcode, u8 *status, |
| 3667 | hci_req_complete_t *req_complete, |
| 3668 | hci_req_complete_skb_t *req_complete_skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3669 | { |
| 3670 | struct hci_ev_cmd_status *ev = (void *) skb->data; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3671 | |
| 3672 | skb_pull(skb, sizeof(*ev)); |
| 3673 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3674 | *opcode = __le16_to_cpu(ev->opcode); |
| 3675 | *status = ev->status; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3676 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3677 | switch (*opcode) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3678 | case HCI_OP_INQUIRY: |
| 3679 | hci_cs_inquiry(hdev, ev->status); |
| 3680 | break; |
| 3681 | |
| 3682 | case HCI_OP_CREATE_CONN: |
| 3683 | hci_cs_create_conn(hdev, ev->status); |
| 3684 | break; |
| 3685 | |
Kuba Pawlak | 9645c76 | 2014-11-06 19:36:53 +0100 | [diff] [blame] | 3686 | case HCI_OP_DISCONNECT: |
| 3687 | hci_cs_disconnect(hdev, ev->status); |
| 3688 | break; |
| 3689 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3690 | case HCI_OP_ADD_SCO: |
| 3691 | hci_cs_add_sco(hdev, ev->status); |
| 3692 | break; |
| 3693 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3694 | case HCI_OP_AUTH_REQUESTED: |
| 3695 | hci_cs_auth_requested(hdev, ev->status); |
| 3696 | break; |
| 3697 | |
| 3698 | case HCI_OP_SET_CONN_ENCRYPT: |
| 3699 | hci_cs_set_conn_encrypt(hdev, ev->status); |
| 3700 | break; |
| 3701 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3702 | case HCI_OP_REMOTE_NAME_REQ: |
| 3703 | hci_cs_remote_name_req(hdev, ev->status); |
| 3704 | break; |
| 3705 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3706 | case HCI_OP_READ_REMOTE_FEATURES: |
| 3707 | hci_cs_read_remote_features(hdev, ev->status); |
| 3708 | break; |
| 3709 | |
| 3710 | case HCI_OP_READ_REMOTE_EXT_FEATURES: |
| 3711 | hci_cs_read_remote_ext_features(hdev, ev->status); |
| 3712 | break; |
| 3713 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3714 | case HCI_OP_SETUP_SYNC_CONN: |
| 3715 | hci_cs_setup_sync_conn(hdev, ev->status); |
| 3716 | break; |
| 3717 | |
| 3718 | case HCI_OP_SNIFF_MODE: |
| 3719 | hci_cs_sniff_mode(hdev, ev->status); |
| 3720 | break; |
| 3721 | |
| 3722 | case HCI_OP_EXIT_SNIFF_MODE: |
| 3723 | hci_cs_exit_sniff_mode(hdev, ev->status); |
| 3724 | break; |
| 3725 | |
Kuba Pawlak | 50fc85f | 2014-11-06 19:36:52 +0100 | [diff] [blame] | 3726 | case HCI_OP_SWITCH_ROLE: |
| 3727 | hci_cs_switch_role(hdev, ev->status); |
| 3728 | break; |
| 3729 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 3730 | case HCI_OP_LE_CREATE_CONN: |
| 3731 | hci_cs_le_create_conn(hdev, ev->status); |
| 3732 | break; |
| 3733 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 3734 | case HCI_OP_LE_READ_REMOTE_FEATURES: |
| 3735 | hci_cs_le_read_remote_features(hdev, ev->status); |
| 3736 | break; |
| 3737 | |
Johan Hedberg | 81d0c8a | 2014-03-24 14:39:04 +0200 | [diff] [blame] | 3738 | case HCI_OP_LE_START_ENC: |
| 3739 | hci_cs_le_start_enc(hdev, ev->status); |
| 3740 | break; |
| 3741 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 3742 | case HCI_OP_LE_EXT_CREATE_CONN: |
| 3743 | hci_cs_le_ext_create_conn(hdev, ev->status); |
| 3744 | break; |
| 3745 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3746 | default: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3747 | BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3748 | break; |
| 3749 | } |
| 3750 | |
Manish Mandlik | de75cd0 | 2021-04-29 10:24:22 -0700 | [diff] [blame^] | 3751 | handle_cmd_cnt_and_timer(hdev, *opcode, ev->ncmd); |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 3752 | |
Johan Hedberg | 444c6dd | 2015-04-02 13:41:07 +0300 | [diff] [blame] | 3753 | /* Indicate request completion if the command failed. Also, if |
| 3754 | * we're not waiting for a special event and we get a success |
| 3755 | * command status we should try to flag the request as completed |
| 3756 | * (since for this kind of commands there will not be a command |
| 3757 | * complete event). |
| 3758 | */ |
Johan Hedberg | 02350a7 | 2013-04-03 21:50:29 +0300 | [diff] [blame] | 3759 | if (ev->status || |
Marcel Holtmann | 242c0eb | 2015-10-25 22:45:53 +0100 | [diff] [blame] | 3760 | (hdev->sent_cmd && !bt_cb(hdev->sent_cmd)->hci.req_event)) |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3761 | hci_req_cmd_complete(hdev, *opcode, ev->status, req_complete, |
| 3762 | req_complete_skb); |
Johan Hedberg | 9238f36 | 2013-03-05 20:37:48 +0200 | [diff] [blame] | 3763 | |
João Paulo Rechi Vita | f80c5da | 2019-05-02 10:01:52 +0800 | [diff] [blame] | 3764 | if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) { |
| 3765 | bt_dev_err(hdev, |
| 3766 | "unexpected event for opcode 0x%4.4x", *opcode); |
| 3767 | return; |
| 3768 | } |
| 3769 | |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 3770 | if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) |
| 3771 | queue_work(hdev->workqueue, &hdev->cmd_work); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3772 | } |
| 3773 | |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 3774 | static void hci_hardware_error_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 3775 | { |
| 3776 | struct hci_ev_hardware_error *ev = (void *) skb->data; |
| 3777 | |
Marcel Holtmann | c7741d1 | 2015-01-28 11:09:55 -0800 | [diff] [blame] | 3778 | hdev->hw_error_code = ev->code; |
| 3779 | |
| 3780 | queue_work(hdev->req_workqueue, &hdev->error_reset); |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 3781 | } |
| 3782 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3783 | static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3784 | { |
| 3785 | struct hci_ev_role_change *ev = (void *) skb->data; |
| 3786 | struct hci_conn *conn; |
| 3787 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3788 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3789 | |
| 3790 | hci_dev_lock(hdev); |
| 3791 | |
| 3792 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 3793 | if (conn) { |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 3794 | if (!ev->status) |
| 3795 | conn->role = ev->role; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3796 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3797 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3798 | |
| 3799 | hci_role_switch_cfm(conn, ev->status, ev->role); |
| 3800 | } |
| 3801 | |
| 3802 | hci_dev_unlock(hdev); |
| 3803 | } |
| 3804 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3805 | static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3806 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3807 | struct hci_ev_num_comp_pkts *ev = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3808 | int i; |
| 3809 | |
Andrei Emeltchenko | 32ac5b9 | 2011-12-19 16:31:29 +0200 | [diff] [blame] | 3810 | if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3811 | bt_dev_err(hdev, "wrong event for mode %d", hdev->flow_ctl_mode); |
Andrei Emeltchenko | 32ac5b9 | 2011-12-19 16:31:29 +0200 | [diff] [blame] | 3812 | return; |
| 3813 | } |
| 3814 | |
Gustavo A. R. Silva | 16e1834 | 2019-02-07 18:40:33 -0600 | [diff] [blame] | 3815 | if (skb->len < sizeof(*ev) || |
| 3816 | skb->len < struct_size(ev, handles, ev->num_hndl)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3817 | BT_DBG("%s bad parameters", hdev->name); |
| 3818 | return; |
| 3819 | } |
| 3820 | |
Andrei Emeltchenko | c5993de | 2011-12-30 12:07:47 +0200 | [diff] [blame] | 3821 | BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl); |
| 3822 | |
Andrei Emeltchenko | 613a1c0 | 2011-12-19 16:31:30 +0200 | [diff] [blame] | 3823 | for (i = 0; i < ev->num_hndl; i++) { |
| 3824 | struct hci_comp_pkts_info *info = &ev->handles[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3825 | struct hci_conn *conn; |
| 3826 | __u16 handle, count; |
| 3827 | |
Andrei Emeltchenko | 613a1c0 | 2011-12-19 16:31:30 +0200 | [diff] [blame] | 3828 | handle = __le16_to_cpu(info->handle); |
| 3829 | count = __le16_to_cpu(info->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3830 | |
| 3831 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 3832 | if (!conn) |
| 3833 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3834 | |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 3835 | conn->sent -= count; |
| 3836 | |
| 3837 | switch (conn->type) { |
| 3838 | case ACL_LINK: |
| 3839 | hdev->acl_cnt += count; |
| 3840 | if (hdev->acl_cnt > hdev->acl_pkts) |
| 3841 | hdev->acl_cnt = hdev->acl_pkts; |
| 3842 | break; |
| 3843 | |
| 3844 | case LE_LINK: |
| 3845 | if (hdev->le_pkts) { |
| 3846 | hdev->le_cnt += count; |
| 3847 | if (hdev->le_cnt > hdev->le_pkts) |
| 3848 | hdev->le_cnt = hdev->le_pkts; |
| 3849 | } else { |
Andrei Emeltchenko | 70f23020 | 2010-12-01 16:58:25 +0200 | [diff] [blame] | 3850 | hdev->acl_cnt += count; |
| 3851 | if (hdev->acl_cnt > hdev->acl_pkts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | hdev->acl_cnt = hdev->acl_pkts; |
| 3853 | } |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 3854 | break; |
| 3855 | |
| 3856 | case SCO_LINK: |
| 3857 | hdev->sco_cnt += count; |
| 3858 | if (hdev->sco_cnt > hdev->sco_pkts) |
| 3859 | hdev->sco_cnt = hdev->sco_pkts; |
| 3860 | break; |
| 3861 | |
| 3862 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3863 | bt_dev_err(hdev, "unknown type %d conn %p", |
| 3864 | conn->type, conn); |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 3865 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3866 | } |
| 3867 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3868 | |
Gustavo F. Padovan | 3eff45e | 2011-12-15 00:50:02 -0200 | [diff] [blame] | 3869 | queue_work(hdev->workqueue, &hdev->tx_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | } |
| 3871 | |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 3872 | static struct hci_conn *__hci_conn_lookup_handle(struct hci_dev *hdev, |
| 3873 | __u16 handle) |
| 3874 | { |
| 3875 | struct hci_chan *chan; |
| 3876 | |
| 3877 | switch (hdev->dev_type) { |
Marcel Holtmann | ca8bee5 | 2016-07-05 14:30:14 +0200 | [diff] [blame] | 3878 | case HCI_PRIMARY: |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 3879 | return hci_conn_hash_lookup_handle(hdev, handle); |
| 3880 | case HCI_AMP: |
| 3881 | chan = hci_chan_lookup_handle(hdev, handle); |
| 3882 | if (chan) |
| 3883 | return chan->conn; |
| 3884 | break; |
| 3885 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3886 | bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type); |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 3887 | break; |
| 3888 | } |
| 3889 | |
| 3890 | return NULL; |
| 3891 | } |
| 3892 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3893 | static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3894 | { |
| 3895 | struct hci_ev_num_comp_blocks *ev = (void *) skb->data; |
| 3896 | int i; |
| 3897 | |
| 3898 | if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3899 | bt_dev_err(hdev, "wrong event for mode %d", hdev->flow_ctl_mode); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3900 | return; |
| 3901 | } |
| 3902 | |
Gustavo A. R. Silva | 16e1834 | 2019-02-07 18:40:33 -0600 | [diff] [blame] | 3903 | if (skb->len < sizeof(*ev) || |
| 3904 | skb->len < struct_size(ev, handles, ev->num_hndl)) { |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3905 | BT_DBG("%s bad parameters", hdev->name); |
| 3906 | return; |
| 3907 | } |
| 3908 | |
| 3909 | BT_DBG("%s num_blocks %d num_hndl %d", hdev->name, ev->num_blocks, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3910 | ev->num_hndl); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3911 | |
| 3912 | for (i = 0; i < ev->num_hndl; i++) { |
| 3913 | struct hci_comp_blocks_info *info = &ev->handles[i]; |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 3914 | struct hci_conn *conn = NULL; |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3915 | __u16 handle, block_count; |
| 3916 | |
| 3917 | handle = __le16_to_cpu(info->handle); |
| 3918 | block_count = __le16_to_cpu(info->blocks); |
| 3919 | |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 3920 | conn = __hci_conn_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3921 | if (!conn) |
| 3922 | continue; |
| 3923 | |
| 3924 | conn->sent -= block_count; |
| 3925 | |
| 3926 | switch (conn->type) { |
| 3927 | case ACL_LINK: |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 3928 | case AMP_LINK: |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3929 | hdev->block_cnt += block_count; |
| 3930 | if (hdev->block_cnt > hdev->num_blocks) |
| 3931 | hdev->block_cnt = hdev->num_blocks; |
| 3932 | break; |
| 3933 | |
| 3934 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3935 | bt_dev_err(hdev, "unknown type %d conn %p", |
| 3936 | conn->type, conn); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3937 | break; |
| 3938 | } |
| 3939 | } |
| 3940 | |
| 3941 | queue_work(hdev->workqueue, &hdev->tx_work); |
| 3942 | } |
| 3943 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3944 | static void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3945 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3946 | struct hci_ev_mode_change *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3947 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3948 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3949 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3950 | |
| 3951 | hci_dev_lock(hdev); |
| 3952 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3953 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 3954 | if (conn) { |
| 3955 | conn->mode = ev->mode; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3956 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 3957 | if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, |
| 3958 | &conn->flags)) { |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3959 | if (conn->mode == HCI_CM_ACTIVE) |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 3960 | set_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3961 | else |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 3962 | clear_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3963 | } |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 3964 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3965 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 3966 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | hci_dev_unlock(hdev); |
| 3970 | } |
| 3971 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3972 | static void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3973 | { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3974 | struct hci_ev_pin_code_req *ev = (void *) skb->data; |
| 3975 | struct hci_conn *conn; |
| 3976 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3977 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3978 | |
| 3979 | hci_dev_lock(hdev); |
| 3980 | |
| 3981 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Waldemar Rymarkiewicz | b6f9804 | 2011-09-23 10:01:30 +0200 | [diff] [blame] | 3982 | if (!conn) |
| 3983 | goto unlock; |
| 3984 | |
| 3985 | if (conn->state == BT_CONNECTED) { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3986 | hci_conn_hold(conn); |
| 3987 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 3988 | hci_conn_drop(conn); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3989 | } |
| 3990 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 3991 | if (!hci_dev_test_flag(hdev, HCI_BONDABLE) && |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 3992 | !test_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags)) { |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 3993 | hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3994 | sizeof(ev->bdaddr), &ev->bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 3995 | } else if (hci_dev_test_flag(hdev, HCI_MGMT)) { |
Waldemar Rymarkiewicz | a770bb5 | 2011-04-28 12:07:59 +0200 | [diff] [blame] | 3996 | u8 secure; |
| 3997 | |
| 3998 | if (conn->pending_sec_level == BT_SECURITY_HIGH) |
| 3999 | secure = 1; |
| 4000 | else |
| 4001 | secure = 0; |
| 4002 | |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 4003 | mgmt_pin_code_request(hdev, &ev->bdaddr, secure); |
Waldemar Rymarkiewicz | a770bb5 | 2011-04-28 12:07:59 +0200 | [diff] [blame] | 4004 | } |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 4005 | |
Waldemar Rymarkiewicz | b6f9804 | 2011-09-23 10:01:30 +0200 | [diff] [blame] | 4006 | unlock: |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4007 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4008 | } |
| 4009 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4010 | static void conn_set_key(struct hci_conn *conn, u8 key_type, u8 pin_len) |
| 4011 | { |
| 4012 | if (key_type == HCI_LK_CHANGED_COMBINATION) |
| 4013 | return; |
| 4014 | |
| 4015 | conn->pin_length = pin_len; |
| 4016 | conn->key_type = key_type; |
| 4017 | |
| 4018 | switch (key_type) { |
| 4019 | case HCI_LK_LOCAL_UNIT: |
| 4020 | case HCI_LK_REMOTE_UNIT: |
| 4021 | case HCI_LK_DEBUG_COMBINATION: |
| 4022 | return; |
| 4023 | case HCI_LK_COMBINATION: |
| 4024 | if (pin_len == 16) |
| 4025 | conn->pending_sec_level = BT_SECURITY_HIGH; |
| 4026 | else |
| 4027 | conn->pending_sec_level = BT_SECURITY_MEDIUM; |
| 4028 | break; |
| 4029 | case HCI_LK_UNAUTH_COMBINATION_P192: |
| 4030 | case HCI_LK_UNAUTH_COMBINATION_P256: |
| 4031 | conn->pending_sec_level = BT_SECURITY_MEDIUM; |
| 4032 | break; |
| 4033 | case HCI_LK_AUTH_COMBINATION_P192: |
| 4034 | conn->pending_sec_level = BT_SECURITY_HIGH; |
| 4035 | break; |
| 4036 | case HCI_LK_AUTH_COMBINATION_P256: |
| 4037 | conn->pending_sec_level = BT_SECURITY_FIPS; |
| 4038 | break; |
| 4039 | } |
| 4040 | } |
| 4041 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4042 | static void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | { |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4044 | struct hci_ev_link_key_req *ev = (void *) skb->data; |
| 4045 | struct hci_cp_link_key_reply cp; |
| 4046 | struct hci_conn *conn; |
| 4047 | struct link_key *key; |
| 4048 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4049 | BT_DBG("%s", hdev->name); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4050 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4051 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4052 | return; |
| 4053 | |
| 4054 | hci_dev_lock(hdev); |
| 4055 | |
| 4056 | key = hci_find_link_key(hdev, &ev->bdaddr); |
| 4057 | if (!key) { |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 4058 | BT_DBG("%s link key not found for %pMR", hdev->name, |
| 4059 | &ev->bdaddr); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4060 | goto not_found; |
| 4061 | } |
| 4062 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 4063 | BT_DBG("%s found key type %u for %pMR", hdev->name, key->type, |
| 4064 | &ev->bdaddr); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4065 | |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4066 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4067 | if (conn) { |
Johan Hedberg | fe8bc5a | 2014-08-14 12:33:17 +0300 | [diff] [blame] | 4068 | clear_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags); |
| 4069 | |
Marcel Holtmann | 66138ce | 2014-01-10 02:07:20 -0800 | [diff] [blame] | 4070 | if ((key->type == HCI_LK_UNAUTH_COMBINATION_P192 || |
| 4071 | key->type == HCI_LK_UNAUTH_COMBINATION_P256) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4072 | conn->auth_type != 0xff && (conn->auth_type & 0x01)) { |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4073 | BT_DBG("%s ignoring unauthenticated key", hdev->name); |
| 4074 | goto not_found; |
| 4075 | } |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4076 | |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4077 | if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 && |
Johan Hedberg | f3fb0b5 | 2014-06-02 10:12:44 +0300 | [diff] [blame] | 4078 | (conn->pending_sec_level == BT_SECURITY_HIGH || |
| 4079 | conn->pending_sec_level == BT_SECURITY_FIPS)) { |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 4080 | BT_DBG("%s ignoring key unauthenticated for high security", |
| 4081 | hdev->name); |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4082 | goto not_found; |
| 4083 | } |
| 4084 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4085 | conn_set_key(conn, key->type, key->pin_len); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9b3b446 | 2012-05-23 11:31:20 +0300 | [diff] [blame] | 4089 | memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4090 | |
| 4091 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp); |
| 4092 | |
| 4093 | hci_dev_unlock(hdev); |
| 4094 | |
| 4095 | return; |
| 4096 | |
| 4097 | not_found: |
| 4098 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr); |
| 4099 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4100 | } |
| 4101 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4102 | static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4103 | { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4104 | struct hci_ev_link_key_notify *ev = (void *) skb->data; |
| 4105 | struct hci_conn *conn; |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4106 | struct link_key *key; |
| 4107 | bool persistent; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4108 | u8 pin_len = 0; |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4109 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4110 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4111 | |
| 4112 | hci_dev_lock(hdev); |
| 4113 | |
| 4114 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4115 | if (!conn) |
| 4116 | goto unlock; |
| 4117 | |
| 4118 | hci_conn_hold(conn); |
| 4119 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
| 4120 | hci_conn_drop(conn); |
| 4121 | |
Johan Hedberg | fe8bc5a | 2014-08-14 12:33:17 +0300 | [diff] [blame] | 4122 | set_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4123 | conn_set_key(conn, ev->key_type, conn->pin_length); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4124 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4125 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4126 | goto unlock; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4127 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4128 | key = hci_add_link_key(hdev, conn, &ev->bdaddr, ev->link_key, |
| 4129 | ev->key_type, pin_len, &persistent); |
| 4130 | if (!key) |
| 4131 | goto unlock; |
| 4132 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4133 | /* Update connection information since adding the key will have |
| 4134 | * fixed up the type in the case of changed combination keys. |
| 4135 | */ |
| 4136 | if (ev->key_type == HCI_LK_CHANGED_COMBINATION) |
| 4137 | conn_set_key(conn, key->type, key->pin_len); |
| 4138 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4139 | mgmt_new_link_key(hdev, key, persistent); |
| 4140 | |
Johan Hedberg | 6d5650c | 2014-06-24 13:15:51 +0300 | [diff] [blame] | 4141 | /* Keep debug keys around only if the HCI_KEEP_DEBUG_KEYS flag |
| 4142 | * is set. If it's not set simply remove the key from the kernel |
| 4143 | * list (we've still notified user space about it but with |
| 4144 | * store_hint being 0). |
| 4145 | */ |
| 4146 | if (key->type == HCI_LK_DEBUG_COMBINATION && |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4147 | !hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) { |
Johan Hedberg | 0378b59 | 2014-11-19 15:22:22 +0200 | [diff] [blame] | 4148 | list_del_rcu(&key->list); |
| 4149 | kfree_rcu(key, rcu); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4150 | goto unlock; |
Johan Hedberg | 6d5650c | 2014-06-24 13:15:51 +0300 | [diff] [blame] | 4151 | } |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4152 | |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4153 | if (persistent) |
| 4154 | clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags); |
| 4155 | else |
| 4156 | set_bit(HCI_CONN_FLUSH_KEY, &conn->flags); |
| 4157 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4158 | unlock: |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4159 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4160 | } |
| 4161 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4162 | static void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4163 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4164 | struct hci_ev_clock_offset *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4165 | struct hci_conn *conn; |
| 4166 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4167 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4168 | |
| 4169 | hci_dev_lock(hdev); |
| 4170 | |
| 4171 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | if (conn && !ev->status) { |
| 4173 | struct inquiry_entry *ie; |
| 4174 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4175 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 4176 | if (ie) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4177 | ie->data.clock_offset = ev->clock_offset; |
| 4178 | ie->timestamp = jiffies; |
| 4179 | } |
| 4180 | } |
| 4181 | |
| 4182 | hci_dev_unlock(hdev); |
| 4183 | } |
| 4184 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4185 | static void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4186 | { |
| 4187 | struct hci_ev_pkt_type_change *ev = (void *) skb->data; |
| 4188 | struct hci_conn *conn; |
| 4189 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4190 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4191 | |
| 4192 | hci_dev_lock(hdev); |
| 4193 | |
| 4194 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 4195 | if (conn && !ev->status) |
| 4196 | conn->pkt_type = __le16_to_cpu(ev->pkt_type); |
| 4197 | |
| 4198 | hci_dev_unlock(hdev); |
| 4199 | } |
| 4200 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4201 | static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 4202 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4203 | struct hci_ev_pscan_rep_mode *ev = (void *) skb->data; |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 4204 | struct inquiry_entry *ie; |
| 4205 | |
| 4206 | BT_DBG("%s", hdev->name); |
| 4207 | |
| 4208 | hci_dev_lock(hdev); |
| 4209 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4210 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 4211 | if (ie) { |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 4212 | ie->data.pscan_rep_mode = ev->pscan_rep_mode; |
| 4213 | ie->timestamp = jiffies; |
| 4214 | } |
| 4215 | |
| 4216 | hci_dev_unlock(hdev); |
| 4217 | } |
| 4218 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4219 | static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, |
| 4220 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4221 | { |
| 4222 | struct inquiry_data data; |
| 4223 | int num_rsp = *((__u8 *) skb->data); |
| 4224 | |
| 4225 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 4226 | |
| 4227 | if (!num_rsp) |
| 4228 | return; |
| 4229 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4230 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 4231 | return; |
| 4232 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4233 | hci_dev_lock(hdev); |
| 4234 | |
| 4235 | if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 4236 | struct inquiry_info_with_rssi_and_pscan_mode *info; |
| 4237 | info = (void *) (skb->data + 1); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4238 | |
Peilin Ye | 629b49c | 2020-07-10 17:45:26 -0400 | [diff] [blame] | 4239 | if (skb->len < num_rsp * sizeof(*info) + 1) |
| 4240 | goto unlock; |
| 4241 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 4242 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4243 | u32 flags; |
| 4244 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4245 | bacpy(&data.bdaddr, &info->bdaddr); |
| 4246 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4247 | data.pscan_period_mode = info->pscan_period_mode; |
| 4248 | data.pscan_mode = info->pscan_mode; |
| 4249 | memcpy(data.dev_class, info->dev_class, 3); |
| 4250 | data.clock_offset = info->clock_offset; |
| 4251 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4252 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 4253 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4254 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 4255 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 4256 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 4257 | info->dev_class, info->rssi, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4258 | flags, NULL, 0, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4259 | } |
| 4260 | } else { |
| 4261 | struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); |
| 4262 | |
Peilin Ye | 629b49c | 2020-07-10 17:45:26 -0400 | [diff] [blame] | 4263 | if (skb->len < num_rsp * sizeof(*info) + 1) |
| 4264 | goto unlock; |
| 4265 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 4266 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4267 | u32 flags; |
| 4268 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4269 | bacpy(&data.bdaddr, &info->bdaddr); |
| 4270 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4271 | data.pscan_period_mode = info->pscan_period_mode; |
| 4272 | data.pscan_mode = 0x00; |
| 4273 | memcpy(data.dev_class, info->dev_class, 3); |
| 4274 | data.clock_offset = info->clock_offset; |
| 4275 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4276 | data.ssp_mode = 0x00; |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4277 | |
| 4278 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 4279 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 4280 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 4281 | info->dev_class, info->rssi, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4282 | flags, NULL, 0, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4283 | } |
| 4284 | } |
| 4285 | |
Peilin Ye | 629b49c | 2020-07-10 17:45:26 -0400 | [diff] [blame] | 4286 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4287 | hci_dev_unlock(hdev); |
| 4288 | } |
| 4289 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4290 | static void hci_remote_ext_features_evt(struct hci_dev *hdev, |
| 4291 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4292 | { |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4293 | struct hci_ev_remote_ext_features *ev = (void *) skb->data; |
| 4294 | struct hci_conn *conn; |
| 4295 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4296 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4297 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4298 | hci_dev_lock(hdev); |
| 4299 | |
| 4300 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4301 | if (!conn) |
| 4302 | goto unlock; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4303 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 4304 | if (ev->page < HCI_MAX_PAGES) |
| 4305 | memcpy(conn->features[ev->page], ev->features, 8); |
| 4306 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4307 | if (!ev->status && ev->page == 0x01) { |
| 4308 | struct inquiry_entry *ie; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4309 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4310 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 4311 | if (ie) |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 4312 | ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 4313 | |
Jaganath Kanakkassery | bbb0ead | 2013-04-16 20:16:30 +0530 | [diff] [blame] | 4314 | if (ev->features[0] & LMP_HOST_SSP) { |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 4315 | set_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
Jaganath Kanakkassery | bbb0ead | 2013-04-16 20:16:30 +0530 | [diff] [blame] | 4316 | } else { |
| 4317 | /* It is mandatory by the Bluetooth specification that |
| 4318 | * Extended Inquiry Results are only used when Secure |
| 4319 | * Simple Pairing is enabled, but some devices violate |
| 4320 | * this. |
| 4321 | * |
| 4322 | * To make these devices work, the internal SSP |
| 4323 | * enabled flag needs to be cleared if the remote host |
| 4324 | * features do not indicate SSP support */ |
| 4325 | clear_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
| 4326 | } |
Marcel Holtmann | eb9a8f3 | 2014-01-15 22:37:38 -0800 | [diff] [blame] | 4327 | |
| 4328 | if (ev->features[0] & LMP_HOST_SC) |
| 4329 | set_bit(HCI_CONN_SC_ENABLED, &conn->flags); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4330 | } |
| 4331 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4332 | if (conn->state != BT_CONFIG) |
| 4333 | goto unlock; |
| 4334 | |
Johan Hedberg | 671267b | 2012-05-12 16:11:50 -0300 | [diff] [blame] | 4335 | if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 4336 | struct hci_cp_remote_name_req cp; |
| 4337 | memset(&cp, 0, sizeof(cp)); |
| 4338 | bacpy(&cp.bdaddr, &conn->dst); |
| 4339 | cp.pscan_rep_mode = 0x02; |
| 4340 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 4341 | } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 4342 | mgmt_device_connected(hdev, conn, NULL, 0); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 4343 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 4344 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4345 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 4346 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4347 | hci_conn_drop(conn); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | unlock: |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4351 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4352 | } |
| 4353 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4354 | static void hci_sync_conn_complete_evt(struct hci_dev *hdev, |
| 4355 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4356 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4357 | struct hci_ev_sync_conn_complete *ev = (void *) skb->data; |
| 4358 | struct hci_conn *conn; |
| 4359 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4360 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4361 | |
| 4362 | hci_dev_lock(hdev); |
| 4363 | |
| 4364 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4365 | if (!conn) { |
| 4366 | if (ev->link_type == ESCO_LINK) |
| 4367 | goto unlock; |
| 4368 | |
Kuba Pawlak | 618353b | 2015-08-28 13:05:22 +0100 | [diff] [blame] | 4369 | /* When the link type in the event indicates SCO connection |
| 4370 | * and lookup of the connection object fails, then check |
| 4371 | * if an eSCO connection object exists. |
| 4372 | * |
| 4373 | * The core limits the synchronous connections to either |
| 4374 | * SCO or eSCO. The eSCO connection is preferred and tried |
| 4375 | * to be setup first and until successfully established, |
| 4376 | * the link type will be hinted as eSCO. |
| 4377 | */ |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4378 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); |
| 4379 | if (!conn) |
| 4380 | goto unlock; |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4381 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4382 | |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4383 | switch (ev->status) { |
| 4384 | case 0x00: |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4385 | conn->handle = __le16_to_cpu(ev->handle); |
| 4386 | conn->state = BT_CONNECTED; |
Kuba Pawlak | 618353b | 2015-08-28 13:05:22 +0100 | [diff] [blame] | 4387 | conn->type = ev->link_type; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 4388 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 4389 | hci_debugfs_create_conn(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 4390 | hci_conn_add_sysfs(conn); |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4391 | break; |
| 4392 | |
Nick Pelly | 81218d2 | 2014-06-30 11:25:01 +0530 | [diff] [blame] | 4393 | case 0x10: /* Connection Accept Timeout */ |
Frédéric Dalleau | 1a4c958 | 2013-08-19 14:24:02 +0200 | [diff] [blame] | 4394 | case 0x0d: /* Connection Rejected due to Limited Resources */ |
Stephen Coe | 705e571 | 2010-02-16 11:29:44 -0500 | [diff] [blame] | 4395 | case 0x11: /* Unsupported Feature or Parameter Value */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4396 | case 0x1c: /* SCO interval rejected */ |
Nick Pelly | 1038a00 | 2010-02-03 11:42:26 -0800 | [diff] [blame] | 4397 | case 0x1a: /* Unsupported Remote Feature */ |
Hsin-Yu Chao | 56b5453 | 2020-05-15 17:27:04 +0800 | [diff] [blame] | 4398 | case 0x1e: /* Invalid LMP Parameters */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4399 | case 0x1f: /* Unspecified error */ |
Andrew Earl | 27539bc | 2014-03-10 10:31:04 +0000 | [diff] [blame] | 4400 | case 0x20: /* Unsupported LMP Parameter value */ |
Frédéric Dalleau | 2dea632 | 2013-08-19 14:24:03 +0200 | [diff] [blame] | 4401 | if (conn->out) { |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4402 | conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | |
| 4403 | (hdev->esco_type & EDR_ESCO_MASK); |
Frédéric Dalleau | 2dea632 | 2013-08-19 14:24:03 +0200 | [diff] [blame] | 4404 | if (hci_setup_sync(conn, conn->link->handle)) |
| 4405 | goto unlock; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4406 | } |
Gustavo A. R. Silva | 19186c7 | 2020-07-08 15:18:23 -0500 | [diff] [blame] | 4407 | fallthrough; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4408 | |
| 4409 | default: |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4410 | conn->state = BT_CLOSED; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4411 | break; |
| 4412 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4413 | |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 4414 | bt_dev_dbg(hdev, "SCO connected with air mode: %02x", ev->air_mode); |
| 4415 | |
| 4416 | switch (conn->setting & SCO_AIRMODE_MASK) { |
| 4417 | case SCO_AIRMODE_CVSD: |
| 4418 | if (hdev->notify) |
| 4419 | hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD); |
| 4420 | break; |
| 4421 | case SCO_AIRMODE_TRANSP: |
| 4422 | if (hdev->notify) |
| 4423 | hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_TRANSP); |
| 4424 | break; |
| 4425 | } |
| 4426 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 4427 | hci_connect_cfm(conn, ev->status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4428 | if (ev->status) |
| 4429 | hci_conn_del(conn); |
| 4430 | |
| 4431 | unlock: |
| 4432 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4433 | } |
| 4434 | |
Marcel Holtmann | efdcf8e | 2013-10-15 10:31:12 -0700 | [diff] [blame] | 4435 | static inline size_t eir_get_length(u8 *eir, size_t eir_len) |
| 4436 | { |
| 4437 | size_t parsed = 0; |
| 4438 | |
| 4439 | while (parsed < eir_len) { |
| 4440 | u8 field_len = eir[0]; |
| 4441 | |
| 4442 | if (field_len == 0) |
| 4443 | return parsed; |
| 4444 | |
| 4445 | parsed += field_len + 1; |
| 4446 | eir += field_len + 1; |
| 4447 | } |
| 4448 | |
| 4449 | return eir_len; |
| 4450 | } |
| 4451 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4452 | static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, |
| 4453 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4454 | { |
| 4455 | struct inquiry_data data; |
| 4456 | struct extended_inquiry_info *info = (void *) (skb->data + 1); |
| 4457 | int num_rsp = *((__u8 *) skb->data); |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 4458 | size_t eir_len; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4459 | |
| 4460 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 4461 | |
Peilin Ye | 51c19bf | 2020-07-10 12:09:15 -0400 | [diff] [blame] | 4462 | if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4463 | return; |
| 4464 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4465 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 4466 | return; |
| 4467 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4468 | hci_dev_lock(hdev); |
| 4469 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 4470 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4471 | u32 flags; |
| 4472 | bool name_known; |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 4473 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4474 | bacpy(&data.bdaddr, &info->bdaddr); |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 4475 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4476 | data.pscan_period_mode = info->pscan_period_mode; |
| 4477 | data.pscan_mode = 0x00; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4478 | memcpy(data.dev_class, info->dev_class, 3); |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 4479 | data.clock_offset = info->clock_offset; |
| 4480 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4481 | data.ssp_mode = 0x01; |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 4482 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4483 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 0d3b7f6 | 2016-01-05 13:19:31 +0200 | [diff] [blame] | 4484 | name_known = eir_get_data(info->data, |
| 4485 | sizeof(info->data), |
| 4486 | EIR_NAME_COMPLETE, NULL); |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 4487 | else |
| 4488 | name_known = true; |
| 4489 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4490 | flags = hci_inquiry_cache_update(hdev, &data, name_known); |
| 4491 | |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 4492 | eir_len = eir_get_length(info->data, sizeof(info->data)); |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4493 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 4494 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4495 | info->dev_class, info->rssi, |
| 4496 | flags, info->data, eir_len, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4497 | } |
| 4498 | |
| 4499 | hci_dev_unlock(hdev); |
| 4500 | } |
| 4501 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4502 | static void hci_key_refresh_complete_evt(struct hci_dev *hdev, |
| 4503 | struct sk_buff *skb) |
| 4504 | { |
| 4505 | struct hci_ev_key_refresh_complete *ev = (void *) skb->data; |
| 4506 | struct hci_conn *conn; |
| 4507 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4508 | BT_DBG("%s status 0x%2.2x handle 0x%4.4x", hdev->name, ev->status, |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4509 | __le16_to_cpu(ev->handle)); |
| 4510 | |
| 4511 | hci_dev_lock(hdev); |
| 4512 | |
| 4513 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 4514 | if (!conn) |
| 4515 | goto unlock; |
| 4516 | |
Johan Hedberg | 9eb1fbf | 2014-04-11 12:02:31 -0700 | [diff] [blame] | 4517 | /* For BR/EDR the necessary steps are taken through the |
| 4518 | * auth_complete event. |
| 4519 | */ |
| 4520 | if (conn->type != LE_LINK) |
| 4521 | goto unlock; |
| 4522 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4523 | if (!ev->status) |
| 4524 | conn->sec_level = conn->pending_sec_level; |
| 4525 | |
| 4526 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
| 4527 | |
| 4528 | if (ev->status && conn->state == BT_CONNECTED) { |
Andre Guedes | bed7174 | 2013-01-30 11:50:56 -0300 | [diff] [blame] | 4529 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4530 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4531 | goto unlock; |
| 4532 | } |
| 4533 | |
| 4534 | if (conn->state == BT_CONFIG) { |
| 4535 | if (!ev->status) |
| 4536 | conn->state = BT_CONNECTED; |
| 4537 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 4538 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4539 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4540 | } else { |
| 4541 | hci_auth_cfm(conn, ev->status); |
| 4542 | |
| 4543 | hci_conn_hold(conn); |
| 4544 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4545 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | unlock: |
| 4549 | hci_dev_unlock(hdev); |
| 4550 | } |
| 4551 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4552 | static u8 hci_get_auth_req(struct hci_conn *conn) |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4553 | { |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4554 | /* If remote requests no-bonding follow that lead */ |
Mikel Astiz | acabae9 | 2013-06-28 10:56:28 +0200 | [diff] [blame] | 4555 | if (conn->remote_auth == HCI_AT_NO_BONDING || |
| 4556 | conn->remote_auth == HCI_AT_NO_BONDING_MITM) |
Waldemar Rymarkiewicz | 58797bf | 2011-04-28 12:07:58 +0200 | [diff] [blame] | 4557 | return conn->remote_auth | (conn->auth_type & 0x01); |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4558 | |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 4559 | /* If both remote and local have enough IO capabilities, require |
| 4560 | * MITM protection |
| 4561 | */ |
| 4562 | if (conn->remote_cap != HCI_IO_NO_INPUT_OUTPUT && |
| 4563 | conn->io_capability != HCI_IO_NO_INPUT_OUTPUT) |
| 4564 | return conn->remote_auth | 0x01; |
| 4565 | |
Timo Mueller | 7e74170 | 2014-04-08 14:21:33 +0200 | [diff] [blame] | 4566 | /* No MITM protection possible so ignore remote requirement */ |
| 4567 | return (conn->remote_auth & ~0x01) | (conn->auth_type & 0x01); |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4568 | } |
| 4569 | |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 4570 | static u8 bredr_oob_data_present(struct hci_conn *conn) |
| 4571 | { |
| 4572 | struct hci_dev *hdev = conn->hdev; |
| 4573 | struct oob_data *data; |
| 4574 | |
| 4575 | data = hci_find_remote_oob_data(hdev, &conn->dst, BDADDR_BREDR); |
| 4576 | if (!data) |
| 4577 | return 0x00; |
| 4578 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 4579 | if (bredr_sc_enabled(hdev)) { |
| 4580 | /* When Secure Connections is enabled, then just |
| 4581 | * return the present value stored with the OOB |
| 4582 | * data. The stored value contains the right present |
| 4583 | * information. However it can only be trusted when |
| 4584 | * not in Secure Connection Only mode. |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 4585 | */ |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 4586 | if (!hci_dev_test_flag(hdev, HCI_SC_ONLY)) |
| 4587 | return data->present; |
| 4588 | |
| 4589 | /* When Secure Connections Only mode is enabled, then |
| 4590 | * the P-256 values are required. If they are not |
| 4591 | * available, then do not declare that OOB data is |
| 4592 | * present. |
| 4593 | */ |
| 4594 | if (!memcmp(data->rand256, ZERO_KEY, 16) || |
| 4595 | !memcmp(data->hash256, ZERO_KEY, 16)) |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 4596 | return 0x00; |
| 4597 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 4598 | return 0x02; |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 4599 | } |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 4600 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 4601 | /* When Secure Connections is not enabled or actually |
| 4602 | * not supported by the hardware, then check that if |
| 4603 | * P-192 data values are present. |
| 4604 | */ |
| 4605 | if (!memcmp(data->rand192, ZERO_KEY, 16) || |
| 4606 | !memcmp(data->hash192, ZERO_KEY, 16)) |
| 4607 | return 0x00; |
| 4608 | |
| 4609 | return 0x01; |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 4610 | } |
| 4611 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4612 | static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4613 | { |
| 4614 | struct hci_ev_io_capa_request *ev = (void *) skb->data; |
| 4615 | struct hci_conn *conn; |
| 4616 | |
| 4617 | BT_DBG("%s", hdev->name); |
| 4618 | |
| 4619 | hci_dev_lock(hdev); |
| 4620 | |
| 4621 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4622 | if (!conn) |
| 4623 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4624 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4625 | hci_conn_hold(conn); |
| 4626 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4627 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4628 | goto unlock; |
| 4629 | |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 4630 | /* Allow pairing if we're pairable, the initiators of the |
| 4631 | * pairing or if the remote is not requesting bonding. |
| 4632 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4633 | if (hci_dev_test_flag(hdev, HCI_BONDABLE) || |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 4634 | test_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags) || |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4635 | (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4636 | struct hci_cp_io_capability_reply cp; |
| 4637 | |
| 4638 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Hemant Gupta | 7a7f1e7 | 2012-01-16 13:34:29 +0530 | [diff] [blame] | 4639 | /* Change the IO capability from KeyboardDisplay |
| 4640 | * to DisplayYesNo as it is not supported by BT spec. */ |
| 4641 | cp.capability = (conn->io_capability == 0x04) ? |
Mikel Astiz | a767631 | 2013-06-28 10:56:29 +0200 | [diff] [blame] | 4642 | HCI_IO_DISPLAY_YESNO : conn->io_capability; |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 4643 | |
| 4644 | /* If we are initiators, there is no remote information yet */ |
| 4645 | if (conn->remote_auth == 0xff) { |
Mikel Astiz | b16c660 | 2014-04-08 14:21:34 +0200 | [diff] [blame] | 4646 | /* Request MITM protection if our IO caps allow it |
Johan Hedberg | 4ad51a7 | 2014-06-09 14:41:25 +0300 | [diff] [blame] | 4647 | * except for the no-bonding case. |
Mikel Astiz | b16c660 | 2014-04-08 14:21:34 +0200 | [diff] [blame] | 4648 | */ |
Mikel Astiz | 6fd6b91 | 2014-04-08 14:21:32 +0200 | [diff] [blame] | 4649 | if (conn->io_capability != HCI_IO_NO_INPUT_OUTPUT && |
Johan Hedberg | 9f743d7 | 2014-07-17 11:56:33 +0300 | [diff] [blame] | 4650 | conn->auth_type != HCI_AT_NO_BONDING) |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 4651 | conn->auth_type |= 0x01; |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 4652 | } else { |
| 4653 | conn->auth_type = hci_get_auth_req(conn); |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 4654 | } |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4655 | |
Johan Hedberg | 82c295b | 2014-07-30 09:22:24 +0300 | [diff] [blame] | 4656 | /* If we're not bondable, force one of the non-bondable |
| 4657 | * authentication requirement values. |
| 4658 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4659 | if (!hci_dev_test_flag(hdev, HCI_BONDABLE)) |
Johan Hedberg | 82c295b | 2014-07-30 09:22:24 +0300 | [diff] [blame] | 4660 | conn->auth_type &= HCI_AT_NO_BONDING_MITM; |
| 4661 | |
| 4662 | cp.authentication = conn->auth_type; |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 4663 | cp.oob_data = bredr_oob_data_present(conn); |
Szymon Janc | ce85ee1 | 2011-03-22 13:12:23 +0100 | [diff] [blame] | 4664 | |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4665 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4666 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4667 | } else { |
| 4668 | struct hci_cp_io_capability_neg_reply cp; |
| 4669 | |
| 4670 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9f5a0d7 | 2011-11-07 14:20:25 +0200 | [diff] [blame] | 4671 | cp.reason = HCI_ERROR_PAIRING_NOT_ALLOWED; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4672 | |
| 4673 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4674 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | unlock: |
| 4678 | hci_dev_unlock(hdev); |
| 4679 | } |
| 4680 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4681 | static void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4682 | { |
| 4683 | struct hci_ev_io_capa_reply *ev = (void *) skb->data; |
| 4684 | struct hci_conn *conn; |
| 4685 | |
| 4686 | BT_DBG("%s", hdev->name); |
| 4687 | |
| 4688 | hci_dev_lock(hdev); |
| 4689 | |
| 4690 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4691 | if (!conn) |
| 4692 | goto unlock; |
| 4693 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4694 | conn->remote_cap = ev->capability; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4695 | conn->remote_auth = ev->authentication; |
| 4696 | |
| 4697 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4698 | hci_dev_unlock(hdev); |
| 4699 | } |
| 4700 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4701 | static void hci_user_confirm_request_evt(struct hci_dev *hdev, |
| 4702 | struct sk_buff *skb) |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4703 | { |
| 4704 | struct hci_ev_user_confirm_req *ev = (void *) skb->data; |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 4705 | int loc_mitm, rem_mitm, confirm_hint = 0; |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4706 | struct hci_conn *conn; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4707 | |
| 4708 | BT_DBG("%s", hdev->name); |
| 4709 | |
| 4710 | hci_dev_lock(hdev); |
| 4711 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4712 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4713 | goto unlock; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4714 | |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4715 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4716 | if (!conn) |
| 4717 | goto unlock; |
| 4718 | |
| 4719 | loc_mitm = (conn->auth_type & 0x01); |
| 4720 | rem_mitm = (conn->remote_auth & 0x01); |
| 4721 | |
| 4722 | /* If we require MITM but the remote device can't provide that |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 4723 | * (it has NoInputNoOutput) then reject the confirmation |
| 4724 | * request. We check the security level here since it doesn't |
| 4725 | * necessarily match conn->auth_type. |
Mikel Astiz | 6fd6b91 | 2014-04-08 14:21:32 +0200 | [diff] [blame] | 4726 | */ |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 4727 | if (conn->pending_sec_level > BT_SECURITY_MEDIUM && |
| 4728 | conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) { |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4729 | BT_DBG("Rejecting request: remote device can't provide MITM"); |
| 4730 | hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4731 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4732 | goto unlock; |
| 4733 | } |
| 4734 | |
| 4735 | /* If no side requires MITM protection; auto-accept */ |
Mikel Astiz | a767631 | 2013-06-28 10:56:29 +0200 | [diff] [blame] | 4736 | if ((!loc_mitm || conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) && |
| 4737 | (!rem_mitm || conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)) { |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 4738 | |
| 4739 | /* If we're not the initiators request authorization to |
| 4740 | * proceed from user space (mgmt_user_confirm with |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 4741 | * confirm_hint set to 1). The exception is if neither |
Johan Hedberg | 02f3e25 | 2014-07-16 15:09:13 +0300 | [diff] [blame] | 4742 | * side had MITM or if the local IO capability is |
| 4743 | * NoInputNoOutput, in which case we do auto-accept |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 4744 | */ |
| 4745 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && |
Johan Hedberg | 02f3e25 | 2014-07-16 15:09:13 +0300 | [diff] [blame] | 4746 | conn->io_capability != HCI_IO_NO_INPUT_OUTPUT && |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 4747 | (loc_mitm || rem_mitm)) { |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 4748 | BT_DBG("Confirming auto-accept as acceptor"); |
| 4749 | confirm_hint = 1; |
| 4750 | goto confirm; |
| 4751 | } |
| 4752 | |
Howard Chung | cee5f20 | 2020-02-14 19:16:41 +0800 | [diff] [blame] | 4753 | /* If there already exists link key in local host, leave the |
| 4754 | * decision to user space since the remote device could be |
| 4755 | * legitimate or malicious. |
| 4756 | */ |
| 4757 | if (hci_find_link_key(hdev, &ev->bdaddr)) { |
| 4758 | bt_dev_dbg(hdev, "Local host already has link key"); |
| 4759 | confirm_hint = 1; |
| 4760 | goto confirm; |
| 4761 | } |
| 4762 | |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 4763 | BT_DBG("Auto-accept of user confirmation with %ums delay", |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4764 | hdev->auto_accept_delay); |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 4765 | |
| 4766 | if (hdev->auto_accept_delay > 0) { |
| 4767 | int delay = msecs_to_jiffies(hdev->auto_accept_delay); |
Johan Hedberg | 7bc18d9 | 2013-10-16 18:11:39 +0300 | [diff] [blame] | 4768 | queue_delayed_work(conn->hdev->workqueue, |
| 4769 | &conn->auto_accept_work, delay); |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 4770 | goto unlock; |
| 4771 | } |
| 4772 | |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4773 | hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4774 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4775 | goto unlock; |
| 4776 | } |
| 4777 | |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 4778 | confirm: |
Johan Hedberg | 39adbff | 2014-03-20 08:18:14 +0200 | [diff] [blame] | 4779 | mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0, |
| 4780 | le32_to_cpu(ev->passkey), confirm_hint); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4781 | |
| 4782 | unlock: |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4783 | hci_dev_unlock(hdev); |
| 4784 | } |
| 4785 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4786 | static void hci_user_passkey_request_evt(struct hci_dev *hdev, |
| 4787 | struct sk_buff *skb) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 4788 | { |
| 4789 | struct hci_ev_user_passkey_req *ev = (void *) skb->data; |
| 4790 | |
| 4791 | BT_DBG("%s", hdev->name); |
| 4792 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4793 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 4794 | mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 4795 | } |
| 4796 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 4797 | static void hci_user_passkey_notify_evt(struct hci_dev *hdev, |
| 4798 | struct sk_buff *skb) |
| 4799 | { |
| 4800 | struct hci_ev_user_passkey_notify *ev = (void *) skb->data; |
| 4801 | struct hci_conn *conn; |
| 4802 | |
| 4803 | BT_DBG("%s", hdev->name); |
| 4804 | |
| 4805 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4806 | if (!conn) |
| 4807 | return; |
| 4808 | |
| 4809 | conn->passkey_notify = __le32_to_cpu(ev->passkey); |
| 4810 | conn->passkey_entered = 0; |
| 4811 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4812 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 4813 | mgmt_user_passkey_notify(hdev, &conn->dst, conn->type, |
| 4814 | conn->dst_type, conn->passkey_notify, |
| 4815 | conn->passkey_entered); |
| 4816 | } |
| 4817 | |
| 4818 | static void hci_keypress_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 4819 | { |
| 4820 | struct hci_ev_keypress_notify *ev = (void *) skb->data; |
| 4821 | struct hci_conn *conn; |
| 4822 | |
| 4823 | BT_DBG("%s", hdev->name); |
| 4824 | |
| 4825 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4826 | if (!conn) |
| 4827 | return; |
| 4828 | |
| 4829 | switch (ev->type) { |
| 4830 | case HCI_KEYPRESS_STARTED: |
| 4831 | conn->passkey_entered = 0; |
| 4832 | return; |
| 4833 | |
| 4834 | case HCI_KEYPRESS_ENTERED: |
| 4835 | conn->passkey_entered++; |
| 4836 | break; |
| 4837 | |
| 4838 | case HCI_KEYPRESS_ERASED: |
| 4839 | conn->passkey_entered--; |
| 4840 | break; |
| 4841 | |
| 4842 | case HCI_KEYPRESS_CLEARED: |
| 4843 | conn->passkey_entered = 0; |
| 4844 | break; |
| 4845 | |
| 4846 | case HCI_KEYPRESS_COMPLETED: |
| 4847 | return; |
| 4848 | } |
| 4849 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4850 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 4851 | mgmt_user_passkey_notify(hdev, &conn->dst, conn->type, |
| 4852 | conn->dst_type, conn->passkey_notify, |
| 4853 | conn->passkey_entered); |
| 4854 | } |
| 4855 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4856 | static void hci_simple_pair_complete_evt(struct hci_dev *hdev, |
| 4857 | struct sk_buff *skb) |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4858 | { |
| 4859 | struct hci_ev_simple_pair_complete *ev = (void *) skb->data; |
| 4860 | struct hci_conn *conn; |
| 4861 | |
| 4862 | BT_DBG("%s", hdev->name); |
| 4863 | |
| 4864 | hci_dev_lock(hdev); |
| 4865 | |
| 4866 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 4867 | if (!conn) |
| 4868 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4869 | |
Johan Hedberg | c1d4fa7 | 2014-07-17 15:14:50 +0300 | [diff] [blame] | 4870 | /* Reset the authentication requirement to unknown */ |
| 4871 | conn->remote_auth = 0xff; |
| 4872 | |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 4873 | /* To avoid duplicate auth_failed events to user space we check |
| 4874 | * the HCI_CONN_AUTH_PEND flag which will be set if we |
| 4875 | * initiated the authentication. A traditional auth_complete |
| 4876 | * event gets always produced as initiator and is also mapped to |
| 4877 | * the mgmt_auth_failed event */ |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 4878 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status) |
Johan Hedberg | e1e930f | 2014-09-08 17:09:49 -0700 | [diff] [blame] | 4879 | mgmt_auth_failed(conn, ev->status); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 4880 | |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4881 | hci_conn_drop(conn); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 4882 | |
| 4883 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4884 | hci_dev_unlock(hdev); |
| 4885 | } |
| 4886 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4887 | static void hci_remote_host_features_evt(struct hci_dev *hdev, |
| 4888 | struct sk_buff *skb) |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4889 | { |
| 4890 | struct hci_ev_remote_host_features *ev = (void *) skb->data; |
| 4891 | struct inquiry_entry *ie; |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 4892 | struct hci_conn *conn; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4893 | |
| 4894 | BT_DBG("%s", hdev->name); |
| 4895 | |
| 4896 | hci_dev_lock(hdev); |
| 4897 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 4898 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4899 | if (conn) |
| 4900 | memcpy(conn->features[1], ev->features, 8); |
| 4901 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4902 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 4903 | if (ie) |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 4904 | ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4905 | |
| 4906 | hci_dev_unlock(hdev); |
| 4907 | } |
| 4908 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4909 | static void hci_remote_oob_data_request_evt(struct hci_dev *hdev, |
| 4910 | struct sk_buff *skb) |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 4911 | { |
| 4912 | struct hci_ev_remote_oob_data_request *ev = (void *) skb->data; |
| 4913 | struct oob_data *data; |
| 4914 | |
| 4915 | BT_DBG("%s", hdev->name); |
| 4916 | |
| 4917 | hci_dev_lock(hdev); |
| 4918 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4919 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Szymon Janc | e1ba1f1 | 2011-04-06 13:01:59 +0200 | [diff] [blame] | 4920 | goto unlock; |
| 4921 | |
Johan Hedberg | 6928a92 | 2014-10-26 20:46:09 +0100 | [diff] [blame] | 4922 | data = hci_find_remote_oob_data(hdev, &ev->bdaddr, BDADDR_BREDR); |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 4923 | if (!data) { |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 4924 | struct hci_cp_remote_oob_data_neg_reply cp; |
| 4925 | |
| 4926 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Marcel Holtmann | 519ca9d | 2014-01-10 02:07:28 -0800 | [diff] [blame] | 4927 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, |
| 4928 | sizeof(cp), &cp); |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 4929 | goto unlock; |
| 4930 | } |
| 4931 | |
| 4932 | if (bredr_sc_enabled(hdev)) { |
| 4933 | struct hci_cp_remote_oob_ext_data_reply cp; |
| 4934 | |
| 4935 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4936 | if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 4937 | memset(cp.hash192, 0, sizeof(cp.hash192)); |
| 4938 | memset(cp.rand192, 0, sizeof(cp.rand192)); |
| 4939 | } else { |
| 4940 | memcpy(cp.hash192, data->hash192, sizeof(cp.hash192)); |
| 4941 | memcpy(cp.rand192, data->rand192, sizeof(cp.rand192)); |
| 4942 | } |
| 4943 | memcpy(cp.hash256, data->hash256, sizeof(cp.hash256)); |
| 4944 | memcpy(cp.rand256, data->rand256, sizeof(cp.rand256)); |
| 4945 | |
| 4946 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_EXT_DATA_REPLY, |
| 4947 | sizeof(cp), &cp); |
| 4948 | } else { |
| 4949 | struct hci_cp_remote_oob_data_reply cp; |
| 4950 | |
| 4951 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 4952 | memcpy(cp.hash, data->hash192, sizeof(cp.hash)); |
| 4953 | memcpy(cp.rand, data->rand192, sizeof(cp.rand)); |
| 4954 | |
| 4955 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, |
| 4956 | sizeof(cp), &cp); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 4957 | } |
| 4958 | |
Szymon Janc | e1ba1f1 | 2011-04-06 13:01:59 +0200 | [diff] [blame] | 4959 | unlock: |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 4960 | hci_dev_unlock(hdev); |
| 4961 | } |
| 4962 | |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 4963 | #if IS_ENABLED(CONFIG_BT_HS) |
| 4964 | static void hci_chan_selected_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 4965 | { |
| 4966 | struct hci_ev_channel_selected *ev = (void *)skb->data; |
| 4967 | struct hci_conn *hcon; |
| 4968 | |
| 4969 | BT_DBG("%s handle 0x%2.2x", hdev->name, ev->phy_handle); |
| 4970 | |
| 4971 | skb_pull(skb, sizeof(*ev)); |
| 4972 | |
| 4973 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 4974 | if (!hcon) |
| 4975 | return; |
| 4976 | |
| 4977 | amp_read_loc_assoc_final_data(hdev, hcon); |
| 4978 | } |
| 4979 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 4980 | static void hci_phy_link_complete_evt(struct hci_dev *hdev, |
| 4981 | struct sk_buff *skb) |
| 4982 | { |
| 4983 | struct hci_ev_phy_link_complete *ev = (void *) skb->data; |
| 4984 | struct hci_conn *hcon, *bredr_hcon; |
| 4985 | |
| 4986 | BT_DBG("%s handle 0x%2.2x status 0x%2.2x", hdev->name, ev->phy_handle, |
| 4987 | ev->status); |
| 4988 | |
| 4989 | hci_dev_lock(hdev); |
| 4990 | |
| 4991 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 4992 | if (!hcon) |
| 4993 | goto unlock; |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 4994 | |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 4995 | if (!hcon->amp_mgr) |
| 4996 | goto unlock; |
Anmol Karn | 6dfccd1 | 2020-09-30 19:48:13 +0530 | [diff] [blame] | 4997 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 4998 | if (ev->status) { |
| 4999 | hci_conn_del(hcon); |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5000 | goto unlock; |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5001 | } |
| 5002 | |
| 5003 | bredr_hcon = hcon->amp_mgr->l2cap_conn->hcon; |
| 5004 | |
| 5005 | hcon->state = BT_CONNECTED; |
| 5006 | bacpy(&hcon->dst, &bredr_hcon->dst); |
| 5007 | |
| 5008 | hci_conn_hold(hcon); |
| 5009 | hcon->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 5010 | hci_conn_drop(hcon); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5011 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 5012 | hci_debugfs_create_conn(hcon); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5013 | hci_conn_add_sysfs(hcon); |
| 5014 | |
Andrei Emeltchenko | cf70ff2 | 2012-10-31 15:46:36 +0200 | [diff] [blame] | 5015 | amp_physical_cfm(bredr_hcon, hcon); |
| 5016 | |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5017 | unlock: |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5018 | hci_dev_unlock(hdev); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5019 | } |
| 5020 | |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 5021 | static void hci_loglink_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5022 | { |
| 5023 | struct hci_ev_logical_link_complete *ev = (void *) skb->data; |
| 5024 | struct hci_conn *hcon; |
| 5025 | struct hci_chan *hchan; |
| 5026 | struct amp_mgr *mgr; |
| 5027 | |
| 5028 | BT_DBG("%s log_handle 0x%4.4x phy_handle 0x%2.2x status 0x%2.2x", |
| 5029 | hdev->name, le16_to_cpu(ev->handle), ev->phy_handle, |
| 5030 | ev->status); |
| 5031 | |
| 5032 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 5033 | if (!hcon) |
| 5034 | return; |
| 5035 | |
| 5036 | /* Create AMP hchan */ |
| 5037 | hchan = hci_chan_create(hcon); |
| 5038 | if (!hchan) |
| 5039 | return; |
| 5040 | |
| 5041 | hchan->handle = le16_to_cpu(ev->handle); |
Archie Pusaka | 5c4c8c9 | 2021-03-22 14:03:11 +0800 | [diff] [blame] | 5042 | hchan->amp = true; |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 5043 | |
| 5044 | BT_DBG("hcon %p mgr %p hchan %p", hcon, hcon->amp_mgr, hchan); |
| 5045 | |
| 5046 | mgr = hcon->amp_mgr; |
| 5047 | if (mgr && mgr->bredr_chan) { |
| 5048 | struct l2cap_chan *bredr_chan = mgr->bredr_chan; |
| 5049 | |
| 5050 | l2cap_chan_lock(bredr_chan); |
| 5051 | |
| 5052 | bredr_chan->conn->mtu = hdev->block_mtu; |
| 5053 | l2cap_logical_cfm(bredr_chan, hchan, 0); |
| 5054 | hci_conn_hold(hcon); |
| 5055 | |
| 5056 | l2cap_chan_unlock(bredr_chan); |
| 5057 | } |
| 5058 | } |
| 5059 | |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 5060 | static void hci_disconn_loglink_complete_evt(struct hci_dev *hdev, |
| 5061 | struct sk_buff *skb) |
| 5062 | { |
| 5063 | struct hci_ev_disconn_logical_link_complete *ev = (void *) skb->data; |
| 5064 | struct hci_chan *hchan; |
| 5065 | |
| 5066 | BT_DBG("%s log handle 0x%4.4x status 0x%2.2x", hdev->name, |
| 5067 | le16_to_cpu(ev->handle), ev->status); |
| 5068 | |
| 5069 | if (ev->status) |
| 5070 | return; |
| 5071 | |
| 5072 | hci_dev_lock(hdev); |
| 5073 | |
| 5074 | hchan = hci_chan_lookup_handle(hdev, le16_to_cpu(ev->handle)); |
Archie Pusaka | 5c4c8c9 | 2021-03-22 14:03:11 +0800 | [diff] [blame] | 5075 | if (!hchan || !hchan->amp) |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 5076 | goto unlock; |
| 5077 | |
| 5078 | amp_destroy_logical_link(hchan, ev->reason); |
| 5079 | |
| 5080 | unlock: |
| 5081 | hci_dev_unlock(hdev); |
| 5082 | } |
| 5083 | |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 5084 | static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev, |
| 5085 | struct sk_buff *skb) |
| 5086 | { |
| 5087 | struct hci_ev_disconn_phy_link_complete *ev = (void *) skb->data; |
| 5088 | struct hci_conn *hcon; |
| 5089 | |
| 5090 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5091 | |
| 5092 | if (ev->status) |
| 5093 | return; |
| 5094 | |
| 5095 | hci_dev_lock(hdev); |
| 5096 | |
| 5097 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 5098 | if (hcon) { |
| 5099 | hcon->state = BT_CLOSED; |
| 5100 | hci_conn_del(hcon); |
| 5101 | } |
| 5102 | |
| 5103 | hci_dev_unlock(hdev); |
| 5104 | } |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 5105 | #endif |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 5106 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5107 | static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, |
| 5108 | bdaddr_t *bdaddr, u8 bdaddr_type, u8 role, u16 handle, |
| 5109 | u16 interval, u16 latency, u16 supervision_timeout) |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5110 | { |
Johan Hedberg | 912b42ef | 2014-07-03 19:33:49 +0300 | [diff] [blame] | 5111 | struct hci_conn_params *params; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5112 | struct hci_conn *conn; |
Johan Hedberg | 68d6f6d | 2014-02-18 21:41:32 +0200 | [diff] [blame] | 5113 | struct smp_irk *irk; |
Johan Hedberg | 837d502 | 2014-07-02 09:36:22 +0300 | [diff] [blame] | 5114 | u8 addr_type; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5115 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5116 | hci_dev_lock(hdev); |
| 5117 | |
Johan Hedberg | fbd96c1 | 2014-07-08 17:21:51 +0300 | [diff] [blame] | 5118 | /* All controllers implicitly stop advertising in the event of a |
| 5119 | * connection, so ensure that the state bit is cleared. |
| 5120 | */ |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 5121 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | fbd96c1 | 2014-07-08 17:21:51 +0300 | [diff] [blame] | 5122 | |
Jakub Pawlowski | e7d9ab7 | 2015-08-07 20:22:52 +0200 | [diff] [blame] | 5123 | conn = hci_lookup_le_connect(hdev); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5124 | if (!conn) { |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5125 | conn = hci_conn_add(hdev, LE_LINK, bdaddr, role); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5126 | if (!conn) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 5127 | bt_dev_err(hdev, "no memory for new connection"); |
Andre Guedes | 230fd16 | 2012-07-27 15:10:10 -0300 | [diff] [blame] | 5128 | goto unlock; |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5129 | } |
Andre Guedes | 29b7988 | 2011-05-31 14:20:54 -0300 | [diff] [blame] | 5130 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5131 | conn->dst_type = bdaddr_type; |
Andre Guedes | b9b343d | 2012-07-27 15:10:11 -0300 | [diff] [blame] | 5132 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5133 | /* If we didn't have a hci_conn object previously |
| 5134 | * but we're in master role this must be something |
| 5135 | * initiated using a white list. Since white list based |
| 5136 | * connections are not "first class citizens" we don't |
| 5137 | * have full tracking of them. Therefore, we go ahead |
| 5138 | * with a "best effort" approach of determining the |
| 5139 | * initiator address based on the HCI_PRIVACY flag. |
| 5140 | */ |
| 5141 | if (conn->out) { |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5142 | conn->resp_addr_type = bdaddr_type; |
| 5143 | bacpy(&conn->resp_addr, bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5144 | if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5145 | conn->init_addr_type = ADDR_LE_DEV_RANDOM; |
| 5146 | bacpy(&conn->init_addr, &hdev->rpa); |
| 5147 | } else { |
| 5148 | hci_copy_identity_address(hdev, |
| 5149 | &conn->init_addr, |
| 5150 | &conn->init_addr_type); |
| 5151 | } |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5152 | } |
Johan Hedberg | 9489eca | 2014-02-28 17:45:46 +0200 | [diff] [blame] | 5153 | } else { |
| 5154 | cancel_delayed_work(&conn->le_conn_timeout); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5155 | } |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5156 | |
Johan Hedberg | 80c24ab | 2014-03-24 20:21:51 +0200 | [diff] [blame] | 5157 | if (!conn->out) { |
| 5158 | /* Set the responder (our side) address type based on |
| 5159 | * the advertising address type. |
| 5160 | */ |
| 5161 | conn->resp_addr_type = hdev->adv_addr_type; |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5162 | if (hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) { |
| 5163 | /* In case of ext adv, resp_addr will be updated in |
| 5164 | * Adv Terminated event. |
| 5165 | */ |
| 5166 | if (!ext_adv_capable(hdev)) |
| 5167 | bacpy(&conn->resp_addr, &hdev->random_addr); |
| 5168 | } else { |
Johan Hedberg | 80c24ab | 2014-03-24 20:21:51 +0200 | [diff] [blame] | 5169 | bacpy(&conn->resp_addr, &hdev->bdaddr); |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5170 | } |
Johan Hedberg | 80c24ab | 2014-03-24 20:21:51 +0200 | [diff] [blame] | 5171 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5172 | conn->init_addr_type = bdaddr_type; |
| 5173 | bacpy(&conn->init_addr, bdaddr); |
Marcel Holtmann | a720d73 | 2014-06-23 12:14:51 +0200 | [diff] [blame] | 5174 | |
| 5175 | /* For incoming connections, set the default minimum |
| 5176 | * and maximum connection interval. They will be used |
| 5177 | * to check if the parameters are in range and if not |
| 5178 | * trigger the connection update procedure. |
| 5179 | */ |
| 5180 | conn->le_conn_min_interval = hdev->le_conn_min_interval; |
| 5181 | conn->le_conn_max_interval = hdev->le_conn_max_interval; |
Johan Hedberg | 80c24ab | 2014-03-24 20:21:51 +0200 | [diff] [blame] | 5182 | } |
Johan Hedberg | 7be2edb | 2014-02-23 19:42:17 +0200 | [diff] [blame] | 5183 | |
Marcel Holtmann | edb4b46 | 2014-02-18 15:13:43 -0800 | [diff] [blame] | 5184 | /* Lookup the identity address from the stored connection |
| 5185 | * address and address type. |
| 5186 | * |
| 5187 | * When establishing connections to an identity address, the |
| 5188 | * connection procedure will store the resolvable random |
| 5189 | * address first. Now if it can be converted back into the |
| 5190 | * identity address, start using the identity address from |
| 5191 | * now on. |
| 5192 | */ |
| 5193 | irk = hci_get_irk(hdev, &conn->dst, conn->dst_type); |
Johan Hedberg | 68d6f6d | 2014-02-18 21:41:32 +0200 | [diff] [blame] | 5194 | if (irk) { |
| 5195 | bacpy(&conn->dst, &irk->bdaddr); |
| 5196 | conn->dst_type = irk->addr_type; |
| 5197 | } |
| 5198 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5199 | if (status) { |
| 5200 | hci_le_conn_failed(conn, status); |
Johan Hedberg | 837d502 | 2014-07-02 09:36:22 +0300 | [diff] [blame] | 5201 | goto unlock; |
| 5202 | } |
| 5203 | |
Johan Hedberg | 08853f1 | 2014-08-15 21:06:55 +0300 | [diff] [blame] | 5204 | if (conn->dst_type == ADDR_LE_DEV_PUBLIC) |
| 5205 | addr_type = BDADDR_LE_PUBLIC; |
| 5206 | else |
| 5207 | addr_type = BDADDR_LE_RANDOM; |
| 5208 | |
Johan Hedberg | 2d3c226 | 2014-07-15 11:51:28 +0300 | [diff] [blame] | 5209 | /* Drop the connection if the device is blocked */ |
| 5210 | if (hci_bdaddr_list_lookup(&hdev->blacklist, &conn->dst, addr_type)) { |
| 5211 | hci_conn_drop(conn); |
Andre Guedes | cd17dec | 2012-07-27 15:10:16 -0300 | [diff] [blame] | 5212 | goto unlock; |
| 5213 | } |
| 5214 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 5215 | if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 5216 | mgmt_device_connected(hdev, conn, NULL, 0); |
Vinicius Costa Gomes | 83bc71b | 2011-05-06 18:41:43 -0300 | [diff] [blame] | 5217 | |
Vinicius Costa Gomes | 7b5c0d5 | 2011-06-09 18:50:50 -0300 | [diff] [blame] | 5218 | conn->sec_level = BT_SECURITY_LOW; |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5219 | conn->handle = handle; |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5220 | conn->state = BT_CONFIG; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5221 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5222 | conn->le_conn_interval = interval; |
| 5223 | conn->le_conn_latency = latency; |
| 5224 | conn->le_supv_timeout = supervision_timeout; |
Marcel Holtmann | e04fde6 | 2014-06-23 11:40:04 +0200 | [diff] [blame] | 5225 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 5226 | hci_debugfs_create_conn(conn); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5227 | hci_conn_add_sysfs(conn); |
| 5228 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5229 | /* The remote features procedure is defined for master |
| 5230 | * role only. So only in case of an initiated connection |
| 5231 | * request the remote features. |
| 5232 | * |
| 5233 | * If the local controller supports slave-initiated features |
| 5234 | * exchange, then requesting the remote features in slave |
| 5235 | * role is possible. Otherwise just transition into the |
| 5236 | * connected state without requesting the remote features. |
| 5237 | */ |
| 5238 | if (conn->out || |
| 5239 | (hdev->le_features[0] & HCI_LE_SLAVE_FEATURES)) { |
| 5240 | struct hci_cp_le_read_remote_features cp; |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5241 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5242 | cp.handle = __cpu_to_le16(conn->handle); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5243 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5244 | hci_send_cmd(hdev, HCI_OP_LE_READ_REMOTE_FEATURES, |
| 5245 | sizeof(cp), &cp); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5246 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5247 | hci_conn_hold(conn); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5248 | } else { |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5249 | conn->state = BT_CONNECTED; |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5250 | hci_connect_cfm(conn, status); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5251 | } |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5252 | |
Johan Hedberg | 5477610 | 2014-08-15 21:06:56 +0300 | [diff] [blame] | 5253 | params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst, |
| 5254 | conn->dst_type); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5255 | if (params) { |
Johan Hedberg | 95305ba | 2014-07-04 12:37:21 +0300 | [diff] [blame] | 5256 | list_del_init(¶ms->action); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5257 | if (params->conn) { |
| 5258 | hci_conn_drop(params->conn); |
Johan Hedberg | f8aaf9b | 2014-08-17 23:28:57 +0300 | [diff] [blame] | 5259 | hci_conn_put(params->conn); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5260 | params->conn = NULL; |
| 5261 | } |
| 5262 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5263 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5264 | unlock: |
Johan Hedberg | 223683a5 | 2014-07-06 15:44:23 +0300 | [diff] [blame] | 5265 | hci_update_background_scan(hdev); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5266 | hci_dev_unlock(hdev); |
| 5267 | } |
| 5268 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5269 | static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5270 | { |
| 5271 | struct hci_ev_le_conn_complete *ev = (void *) skb->data; |
| 5272 | |
| 5273 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5274 | |
| 5275 | le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type, |
| 5276 | ev->role, le16_to_cpu(ev->handle), |
| 5277 | le16_to_cpu(ev->interval), |
| 5278 | le16_to_cpu(ev->latency), |
| 5279 | le16_to_cpu(ev->supervision_timeout)); |
| 5280 | } |
| 5281 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 5282 | static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, |
| 5283 | struct sk_buff *skb) |
| 5284 | { |
| 5285 | struct hci_ev_le_enh_conn_complete *ev = (void *) skb->data; |
| 5286 | |
| 5287 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5288 | |
| 5289 | le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type, |
| 5290 | ev->role, le16_to_cpu(ev->handle), |
| 5291 | le16_to_cpu(ev->interval), |
| 5292 | le16_to_cpu(ev->latency), |
| 5293 | le16_to_cpu(ev->supervision_timeout)); |
Sathish Narasimman | 5c49bcc | 2020-07-23 18:09:01 +0530 | [diff] [blame] | 5294 | |
| 5295 | if (use_ll_privacy(hdev) && |
Sathish Narasimman | cbbdfa6 | 2020-07-23 18:09:03 +0530 | [diff] [blame] | 5296 | hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && |
Sathish Narasimman | 5c49bcc | 2020-07-23 18:09:01 +0530 | [diff] [blame] | 5297 | hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) |
| 5298 | hci_req_disable_address_resolution(hdev); |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 5299 | } |
| 5300 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5301 | static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5302 | { |
| 5303 | struct hci_evt_le_ext_adv_set_term *ev = (void *) skb->data; |
| 5304 | struct hci_conn *conn; |
| 5305 | |
| 5306 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5307 | |
| 5308 | if (ev->status) |
| 5309 | return; |
| 5310 | |
| 5311 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle)); |
| 5312 | if (conn) { |
| 5313 | struct adv_info *adv_instance; |
| 5314 | |
| 5315 | if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM) |
| 5316 | return; |
| 5317 | |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 5318 | if (!ev->handle) { |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5319 | bacpy(&conn->resp_addr, &hdev->random_addr); |
| 5320 | return; |
| 5321 | } |
| 5322 | |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 5323 | adv_instance = hci_find_adv_instance(hdev, ev->handle); |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5324 | if (adv_instance) |
| 5325 | bacpy(&conn->resp_addr, &adv_instance->random_addr); |
| 5326 | } |
| 5327 | } |
| 5328 | |
Marcel Holtmann | 1855d92 | 2014-06-23 11:40:05 +0200 | [diff] [blame] | 5329 | static void hci_le_conn_update_complete_evt(struct hci_dev *hdev, |
| 5330 | struct sk_buff *skb) |
| 5331 | { |
| 5332 | struct hci_ev_le_conn_update_complete *ev = (void *) skb->data; |
| 5333 | struct hci_conn *conn; |
| 5334 | |
| 5335 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5336 | |
| 5337 | if (ev->status) |
| 5338 | return; |
| 5339 | |
| 5340 | hci_dev_lock(hdev); |
| 5341 | |
| 5342 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 5343 | if (conn) { |
| 5344 | conn->le_conn_interval = le16_to_cpu(ev->interval); |
| 5345 | conn->le_conn_latency = le16_to_cpu(ev->latency); |
| 5346 | conn->le_supv_timeout = le16_to_cpu(ev->supervision_timeout); |
| 5347 | } |
| 5348 | |
| 5349 | hci_dev_unlock(hdev); |
| 5350 | } |
| 5351 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5352 | /* This function requires the caller holds hdev->lock */ |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5353 | static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev, |
| 5354 | bdaddr_t *addr, |
Szymon Janc | 082f230 | 2018-04-03 13:40:06 +0200 | [diff] [blame] | 5355 | u8 addr_type, u8 adv_type, |
| 5356 | bdaddr_t *direct_rpa) |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5357 | { |
| 5358 | struct hci_conn *conn; |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 5359 | struct hci_conn_params *params; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5360 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5361 | /* If the event is not connectable don't proceed further */ |
| 5362 | if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5363 | return NULL; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5364 | |
| 5365 | /* Ignore if the device is blocked */ |
Johan Hedberg | dcc36c1 | 2014-07-09 12:59:13 +0300 | [diff] [blame] | 5366 | if (hci_bdaddr_list_lookup(&hdev->blacklist, addr, addr_type)) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5367 | return NULL; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5368 | |
Johan Hedberg | f99353c | 2014-07-16 11:56:09 +0300 | [diff] [blame] | 5369 | /* Most controller will fail if we try to create new connections |
| 5370 | * while we have an existing one in slave role. |
| 5371 | */ |
Alain Michaud | 4364f2e | 2020-04-23 14:43:29 +0000 | [diff] [blame] | 5372 | if (hdev->conn_hash.le_num_slave > 0 && |
| 5373 | (!test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) || |
| 5374 | !(hdev->le_states[3] & 0x10))) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5375 | return NULL; |
Johan Hedberg | f99353c | 2014-07-16 11:56:09 +0300 | [diff] [blame] | 5376 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5377 | /* If we're not connectable only connect devices that we have in |
| 5378 | * our pend_le_conns list. |
| 5379 | */ |
Johan Hedberg | 49c5092 | 2015-10-16 10:07:51 +0300 | [diff] [blame] | 5380 | params = hci_pend_le_action_lookup(&hdev->pend_le_conns, addr, |
| 5381 | addr_type); |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 5382 | if (!params) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5383 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5384 | |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5385 | if (!params->explicit_connect) { |
| 5386 | switch (params->auto_connect) { |
| 5387 | case HCI_AUTO_CONN_DIRECT: |
| 5388 | /* Only devices advertising with ADV_DIRECT_IND are |
| 5389 | * triggering a connection attempt. This is allowing |
| 5390 | * incoming connections from slave devices. |
| 5391 | */ |
| 5392 | if (adv_type != LE_ADV_DIRECT_IND) |
| 5393 | return NULL; |
| 5394 | break; |
| 5395 | case HCI_AUTO_CONN_ALWAYS: |
| 5396 | /* Devices advertising with ADV_IND or ADV_DIRECT_IND |
| 5397 | * are triggering a connection attempt. This means |
Alain Michaud | 1e5479b | 2020-04-03 13:49:05 +0000 | [diff] [blame] | 5398 | * that incoming connections from slave device are |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5399 | * accepted and also outgoing connections to slave |
| 5400 | * devices are established when found. |
| 5401 | */ |
| 5402 | break; |
| 5403 | default: |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5404 | return NULL; |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5405 | } |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 5406 | } |
| 5407 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5408 | conn = hci_connect_le(hdev, addr, addr_type, BT_SECURITY_LOW, |
Alain Michaud | 49b020c | 2020-06-29 16:11:00 +0000 | [diff] [blame] | 5409 | hdev->def_le_autoconnect_timeout, HCI_ROLE_MASTER, |
Szymon Janc | 082f230 | 2018-04-03 13:40:06 +0200 | [diff] [blame] | 5410 | direct_rpa); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5411 | if (!IS_ERR(conn)) { |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5412 | /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned |
| 5413 | * by higher layer that tried to connect, if no then |
| 5414 | * store the pointer since we don't really have any |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5415 | * other owner of the object besides the params that |
| 5416 | * triggered it. This way we can abort the connection if |
| 5417 | * the parameters get removed and keep the reference |
| 5418 | * count consistent once the connection is established. |
| 5419 | */ |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5420 | |
| 5421 | if (!params->explicit_connect) |
| 5422 | params->conn = hci_conn_get(conn); |
| 5423 | |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5424 | return conn; |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5425 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5426 | |
| 5427 | switch (PTR_ERR(conn)) { |
| 5428 | case -EBUSY: |
| 5429 | /* If hci_connect() returns -EBUSY it means there is already |
| 5430 | * an LE connection attempt going on. Since controllers don't |
| 5431 | * support more than one connection attempt at the time, we |
| 5432 | * don't consider this an error case. |
| 5433 | */ |
| 5434 | break; |
| 5435 | default: |
| 5436 | BT_DBG("Failed to connect: err %ld", PTR_ERR(conn)); |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5437 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5438 | } |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5439 | |
| 5440 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5441 | } |
| 5442 | |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5443 | static void process_adv_report(struct hci_dev *hdev, u8 type, bdaddr_t *bdaddr, |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5444 | u8 bdaddr_type, bdaddr_t *direct_addr, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5445 | u8 direct_addr_type, s8 rssi, u8 *data, u8 len, |
| 5446 | bool ext_adv) |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5447 | { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5448 | struct discovery_state *d = &hdev->discovery; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5449 | struct smp_irk *irk; |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5450 | struct hci_conn *conn; |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 5451 | bool match; |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5452 | u32 flags; |
Szymon Janc | 6818375 | 2015-09-16 20:21:54 +0200 | [diff] [blame] | 5453 | u8 *ptr, real_len; |
| 5454 | |
Johan Hedberg | 56b40fb | 2016-04-07 21:01:27 +0300 | [diff] [blame] | 5455 | switch (type) { |
| 5456 | case LE_ADV_IND: |
| 5457 | case LE_ADV_DIRECT_IND: |
| 5458 | case LE_ADV_SCAN_IND: |
| 5459 | case LE_ADV_NONCONN_IND: |
| 5460 | case LE_ADV_SCAN_RSP: |
| 5461 | break; |
| 5462 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 5463 | bt_dev_err_ratelimited(hdev, "unknown advertising packet " |
| 5464 | "type: 0x%02x", type); |
Johan Hedberg | 56b40fb | 2016-04-07 21:01:27 +0300 | [diff] [blame] | 5465 | return; |
| 5466 | } |
| 5467 | |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5468 | if (!ext_adv && len > HCI_MAX_AD_LENGTH) { |
| 5469 | bt_dev_err_ratelimited(hdev, "legacy adv larger than 31 bytes"); |
| 5470 | return; |
| 5471 | } |
| 5472 | |
Szymon Janc | 6818375 | 2015-09-16 20:21:54 +0200 | [diff] [blame] | 5473 | /* Find the end of the data in case the report contains padded zero |
| 5474 | * bytes at the end causing an invalid length value. |
| 5475 | * |
| 5476 | * When data is NULL, len is 0 so there is no need for extra ptr |
| 5477 | * check as 'ptr < data + 0' is already false in such case. |
| 5478 | */ |
| 5479 | for (ptr = data; ptr < data + len && *ptr; ptr += *ptr + 1) { |
| 5480 | if (ptr + 1 + *ptr > data + len) |
| 5481 | break; |
| 5482 | } |
| 5483 | |
| 5484 | real_len = ptr - data; |
| 5485 | |
| 5486 | /* Adjust for actual length */ |
| 5487 | if (len != real_len) { |
Daniels Umanovskis | 943d5d92 | 2020-04-09 13:18:29 +0200 | [diff] [blame] | 5488 | bt_dev_err_ratelimited(hdev, "advertising data len corrected %u -> %u", |
| 5489 | len, real_len); |
Szymon Janc | 6818375 | 2015-09-16 20:21:54 +0200 | [diff] [blame] | 5490 | len = real_len; |
| 5491 | } |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5492 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5493 | /* If the direct address is present, then this report is from |
| 5494 | * a LE Direct Advertising Report event. In that case it is |
| 5495 | * important to see if the address is matching the local |
| 5496 | * controller address. |
| 5497 | */ |
| 5498 | if (direct_addr) { |
| 5499 | /* Only resolvable random addresses are valid for these |
| 5500 | * kind of reports and others can be ignored. |
| 5501 | */ |
| 5502 | if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type)) |
| 5503 | return; |
| 5504 | |
| 5505 | /* If the controller is not using resolvable random |
| 5506 | * addresses, then this report can be ignored. |
| 5507 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5508 | if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5509 | return; |
| 5510 | |
| 5511 | /* If the local IRK of the controller does not match |
| 5512 | * with the resolvable random address provided, then |
| 5513 | * this report can be ignored. |
| 5514 | */ |
| 5515 | if (!smp_irk_matches(hdev, hdev->irk, direct_addr)) |
| 5516 | return; |
| 5517 | } |
| 5518 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5519 | /* Check if we need to convert to identity address */ |
| 5520 | irk = hci_get_irk(hdev, bdaddr, bdaddr_type); |
| 5521 | if (irk) { |
| 5522 | bdaddr = &irk->bdaddr; |
| 5523 | bdaddr_type = irk->addr_type; |
| 5524 | } |
| 5525 | |
Szymon Janc | 082f230 | 2018-04-03 13:40:06 +0200 | [diff] [blame] | 5526 | /* Check if we have been requested to connect to this device. |
| 5527 | * |
| 5528 | * direct_addr is set only for directed advertising reports (it is NULL |
| 5529 | * for advertising reports) and is already verified to be RPA above. |
| 5530 | */ |
| 5531 | conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, type, |
| 5532 | direct_addr); |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5533 | if (!ext_adv && conn && type == LE_ADV_IND && len <= HCI_MAX_AD_LENGTH) { |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5534 | /* Store report for later inclusion by |
| 5535 | * mgmt_device_connected |
| 5536 | */ |
| 5537 | memcpy(conn->le_adv_data, data, len); |
| 5538 | conn->le_adv_data_len = len; |
| 5539 | } |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5540 | |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 5541 | /* Passive scanning shouldn't trigger any device found events, |
| 5542 | * except for devices marked as CONN_REPORT for which we do send |
Miao-chen Chou | 8208f5a | 2020-06-17 16:39:18 +0200 | [diff] [blame] | 5543 | * device found events, or advertisement monitoring requested. |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 5544 | */ |
Johan Hedberg | ca5c4be | 2014-03-25 10:30:46 +0200 | [diff] [blame] | 5545 | if (hdev->le_scan_type == LE_SCAN_PASSIVE) { |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 5546 | if (type == LE_ADV_DIRECT_IND) |
| 5547 | return; |
| 5548 | |
Johan Hedberg | 3a19b6f | 2014-07-15 08:07:59 +0300 | [diff] [blame] | 5549 | if (!hci_pend_le_action_lookup(&hdev->pend_le_reports, |
Miao-chen Chou | 8208f5a | 2020-06-17 16:39:18 +0200 | [diff] [blame] | 5550 | bdaddr, bdaddr_type) && |
| 5551 | idr_is_empty(&hdev->adv_monitors_idr)) |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 5552 | return; |
| 5553 | |
| 5554 | if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND) |
| 5555 | flags = MGMT_DEV_FOUND_NOT_CONNECTABLE; |
| 5556 | else |
| 5557 | flags = 0; |
| 5558 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
| 5559 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | 97bf2e9 | 2014-07-04 12:37:16 +0300 | [diff] [blame] | 5560 | return; |
Johan Hedberg | ca5c4be | 2014-03-25 10:30:46 +0200 | [diff] [blame] | 5561 | } |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5562 | |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5563 | /* When receiving non-connectable or scannable undirected |
| 5564 | * advertising reports, this means that the remote device is |
| 5565 | * not connectable and then clearly indicate this in the |
| 5566 | * device found event. |
| 5567 | * |
| 5568 | * When receiving a scan response, then there is no way to |
| 5569 | * know if the remote device is connectable or not. However |
| 5570 | * since scan responses are merged with a previously seen |
| 5571 | * advertising report, the flags field from that report |
| 5572 | * will be used. |
| 5573 | * |
| 5574 | * In the really unlikely case that a controller get confused |
| 5575 | * and just sends a scan response event, then it is marked as |
| 5576 | * not connectable as well. |
| 5577 | */ |
| 5578 | if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND || |
| 5579 | type == LE_ADV_SCAN_RSP) |
| 5580 | flags = MGMT_DEV_FOUND_NOT_CONNECTABLE; |
| 5581 | else |
| 5582 | flags = 0; |
| 5583 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5584 | /* If there's nothing pending either store the data from this |
| 5585 | * event or send an immediate device found event if the data |
| 5586 | * should not be stored for later. |
| 5587 | */ |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5588 | if (!ext_adv && !has_pending_adv_report(hdev)) { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5589 | /* If the report will trigger a SCAN_REQ store it for |
| 5590 | * later merging. |
| 5591 | */ |
| 5592 | if (type == LE_ADV_IND || type == LE_ADV_SCAN_IND) { |
| 5593 | store_pending_adv_report(hdev, bdaddr, bdaddr_type, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5594 | rssi, flags, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5595 | return; |
| 5596 | } |
| 5597 | |
| 5598 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5599 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5600 | return; |
| 5601 | } |
| 5602 | |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 5603 | /* Check if the pending report is for the same device as the new one */ |
| 5604 | match = (!bacmp(bdaddr, &d->last_adv_addr) && |
| 5605 | bdaddr_type == d->last_adv_addr_type); |
| 5606 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5607 | /* If the pending data doesn't match this report or this isn't a |
| 5608 | * scan response (e.g. we got a duplicate ADV_IND) then force |
| 5609 | * sending of the pending data. |
| 5610 | */ |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 5611 | if (type != LE_ADV_SCAN_RSP || !match) { |
| 5612 | /* Send out whatever is in the cache, but skip duplicates */ |
| 5613 | if (!match) |
| 5614 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 5615 | d->last_adv_addr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5616 | d->last_adv_rssi, d->last_adv_flags, |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 5617 | d->last_adv_data, |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 5618 | d->last_adv_data_len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5619 | |
| 5620 | /* If the new report will trigger a SCAN_REQ store it for |
| 5621 | * later merging. |
| 5622 | */ |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5623 | if (!ext_adv && (type == LE_ADV_IND || |
| 5624 | type == LE_ADV_SCAN_IND)) { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5625 | store_pending_adv_report(hdev, bdaddr, bdaddr_type, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5626 | rssi, flags, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5627 | return; |
| 5628 | } |
| 5629 | |
| 5630 | /* The advertising reports cannot be merged, so clear |
| 5631 | * the pending report and send out a device found event. |
| 5632 | */ |
| 5633 | clear_pending_adv_report(hdev); |
Johan Hedberg | 5c5b93e | 2014-03-29 08:39:53 +0200 | [diff] [blame] | 5634 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5635 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5636 | return; |
| 5637 | } |
| 5638 | |
| 5639 | /* If we get here we've got a pending ADV_IND or ADV_SCAN_IND and |
| 5640 | * the new event is a SCAN_RSP. We can therefore proceed with |
| 5641 | * sending a merged device found event. |
| 5642 | */ |
| 5643 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5644 | d->last_adv_addr_type, NULL, rssi, d->last_adv_flags, |
Marcel Holtmann | 42bd6a5 | 2014-07-01 14:11:19 +0200 | [diff] [blame] | 5645 | d->last_adv_data, d->last_adv_data_len, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5646 | clear_pending_adv_report(hdev); |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5647 | } |
| 5648 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5649 | static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 5650 | { |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 5651 | u8 num_reports = skb->data[0]; |
| 5652 | void *ptr = &skb->data[1]; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 5653 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5654 | hci_dev_lock(hdev); |
| 5655 | |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 5656 | while (num_reports--) { |
| 5657 | struct hci_ev_le_advertising_info *ev = ptr; |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5658 | s8 rssi; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5659 | |
Chriz Chow | ee64934 | 2018-04-20 15:46:24 +0800 | [diff] [blame] | 5660 | if (ev->length <= HCI_MAX_AD_LENGTH) { |
| 5661 | rssi = ev->data[ev->length]; |
| 5662 | process_adv_report(hdev, ev->evt_type, &ev->bdaddr, |
| 5663 | ev->bdaddr_type, NULL, 0, rssi, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5664 | ev->data, ev->length, false); |
Chriz Chow | ee64934 | 2018-04-20 15:46:24 +0800 | [diff] [blame] | 5665 | } else { |
| 5666 | bt_dev_err(hdev, "Dropping invalid advertising data"); |
| 5667 | } |
Andre Guedes | 3c9e919 | 2012-01-10 18:20:50 -0300 | [diff] [blame] | 5668 | |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 5669 | ptr += sizeof(*ev) + ev->length + 1; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 5670 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5671 | |
| 5672 | hci_dev_unlock(hdev); |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 5673 | } |
| 5674 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 5675 | static u8 ext_evt_type_to_legacy(struct hci_dev *hdev, u16 evt_type) |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5676 | { |
Jaganath Kanakkassery | b2cc976 | 2018-07-19 17:09:38 +0530 | [diff] [blame] | 5677 | if (evt_type & LE_EXT_ADV_LEGACY_PDU) { |
| 5678 | switch (evt_type) { |
| 5679 | case LE_LEGACY_ADV_IND: |
| 5680 | return LE_ADV_IND; |
| 5681 | case LE_LEGACY_ADV_DIRECT_IND: |
| 5682 | return LE_ADV_DIRECT_IND; |
| 5683 | case LE_LEGACY_ADV_SCAN_IND: |
| 5684 | return LE_ADV_SCAN_IND; |
| 5685 | case LE_LEGACY_NONCONN_IND: |
| 5686 | return LE_ADV_NONCONN_IND; |
| 5687 | case LE_LEGACY_SCAN_RSP_ADV: |
| 5688 | case LE_LEGACY_SCAN_RSP_ADV_SCAN: |
| 5689 | return LE_ADV_SCAN_RSP; |
| 5690 | } |
| 5691 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 5692 | goto invalid; |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5693 | } |
| 5694 | |
Jaganath Kanakkassery | b2cc976 | 2018-07-19 17:09:38 +0530 | [diff] [blame] | 5695 | if (evt_type & LE_EXT_ADV_CONN_IND) { |
| 5696 | if (evt_type & LE_EXT_ADV_DIRECT_IND) |
| 5697 | return LE_ADV_DIRECT_IND; |
| 5698 | |
| 5699 | return LE_ADV_IND; |
| 5700 | } |
| 5701 | |
| 5702 | if (evt_type & LE_EXT_ADV_SCAN_RSP) |
| 5703 | return LE_ADV_SCAN_RSP; |
| 5704 | |
| 5705 | if (evt_type & LE_EXT_ADV_SCAN_IND) |
| 5706 | return LE_ADV_SCAN_IND; |
| 5707 | |
| 5708 | if (evt_type == LE_EXT_ADV_NON_CONN_IND || |
| 5709 | evt_type & LE_EXT_ADV_DIRECT_IND) |
| 5710 | return LE_ADV_NONCONN_IND; |
| 5711 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 5712 | invalid: |
| 5713 | bt_dev_err_ratelimited(hdev, "Unknown advertising packet type: 0x%02x", |
| 5714 | evt_type); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5715 | |
| 5716 | return LE_ADV_INVALID; |
| 5717 | } |
| 5718 | |
| 5719 | static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5720 | { |
| 5721 | u8 num_reports = skb->data[0]; |
| 5722 | void *ptr = &skb->data[1]; |
| 5723 | |
| 5724 | hci_dev_lock(hdev); |
| 5725 | |
| 5726 | while (num_reports--) { |
| 5727 | struct hci_ev_le_ext_adv_report *ev = ptr; |
| 5728 | u8 legacy_evt_type; |
| 5729 | u16 evt_type; |
| 5730 | |
| 5731 | evt_type = __le16_to_cpu(ev->evt_type); |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 5732 | legacy_evt_type = ext_evt_type_to_legacy(hdev, evt_type); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5733 | if (legacy_evt_type != LE_ADV_INVALID) { |
| 5734 | process_adv_report(hdev, legacy_evt_type, &ev->bdaddr, |
| 5735 | ev->bdaddr_type, NULL, 0, ev->rssi, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5736 | ev->data, ev->length, |
| 5737 | !(evt_type & LE_EXT_ADV_LEGACY_PDU)); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5738 | } |
| 5739 | |
Jaganath Kanakkassery | cd9151b | 2019-04-03 12:11:44 +0530 | [diff] [blame] | 5740 | ptr += sizeof(*ev) + ev->length; |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5741 | } |
| 5742 | |
| 5743 | hci_dev_unlock(hdev); |
| 5744 | } |
| 5745 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5746 | static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, |
| 5747 | struct sk_buff *skb) |
| 5748 | { |
| 5749 | struct hci_ev_le_remote_feat_complete *ev = (void *)skb->data; |
| 5750 | struct hci_conn *conn; |
| 5751 | |
| 5752 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5753 | |
| 5754 | hci_dev_lock(hdev); |
| 5755 | |
| 5756 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 5757 | if (conn) { |
| 5758 | if (!ev->status) |
| 5759 | memcpy(conn->features[0], ev->features, 8); |
| 5760 | |
| 5761 | if (conn->state == BT_CONFIG) { |
| 5762 | __u8 status; |
| 5763 | |
| 5764 | /* If the local controller supports slave-initiated |
| 5765 | * features exchange, but the remote controller does |
| 5766 | * not, then it is possible that the error code 0x1a |
| 5767 | * for unsupported remote feature gets returned. |
| 5768 | * |
| 5769 | * In this specific case, allow the connection to |
| 5770 | * transition into connected state and mark it as |
| 5771 | * successful. |
| 5772 | */ |
| 5773 | if ((hdev->le_features[0] & HCI_LE_SLAVE_FEATURES) && |
| 5774 | !conn->out && ev->status == 0x1a) |
| 5775 | status = 0x00; |
| 5776 | else |
| 5777 | status = ev->status; |
| 5778 | |
| 5779 | conn->state = BT_CONNECTED; |
| 5780 | hci_connect_cfm(conn, status); |
| 5781 | hci_conn_drop(conn); |
| 5782 | } |
| 5783 | } |
| 5784 | |
| 5785 | hci_dev_unlock(hdev); |
| 5786 | } |
| 5787 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5788 | static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5789 | { |
| 5790 | struct hci_ev_le_ltk_req *ev = (void *) skb->data; |
| 5791 | struct hci_cp_le_ltk_reply cp; |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 5792 | struct hci_cp_le_ltk_neg_reply neg; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5793 | struct hci_conn *conn; |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 5794 | struct smp_ltk *ltk; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5795 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 5796 | BT_DBG("%s handle 0x%4.4x", hdev->name, __le16_to_cpu(ev->handle)); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5797 | |
| 5798 | hci_dev_lock(hdev); |
| 5799 | |
| 5800 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 5801 | if (conn == NULL) |
| 5802 | goto not_found; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5803 | |
Johan Hedberg | f3a73d9 | 2014-05-29 15:02:59 +0300 | [diff] [blame] | 5804 | ltk = hci_find_ltk(hdev, &conn->dst, conn->dst_type, conn->role); |
Johan Hedberg | 5378bc5 | 2014-05-29 14:00:39 +0300 | [diff] [blame] | 5805 | if (!ltk) |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 5806 | goto not_found; |
| 5807 | |
Johan Hedberg | 5378bc5 | 2014-05-29 14:00:39 +0300 | [diff] [blame] | 5808 | if (smp_ltk_is_sc(ltk)) { |
| 5809 | /* With SC both EDiv and Rand are set to zero */ |
| 5810 | if (ev->ediv || ev->rand) |
| 5811 | goto not_found; |
| 5812 | } else { |
| 5813 | /* For non-SC keys check that EDiv and Rand match */ |
| 5814 | if (ev->ediv != ltk->ediv || ev->rand != ltk->rand) |
| 5815 | goto not_found; |
| 5816 | } |
| 5817 | |
Johan Hedberg | 8b76ce3 | 2015-06-08 18:14:39 +0300 | [diff] [blame] | 5818 | memcpy(cp.ltk, ltk->val, ltk->enc_size); |
| 5819 | memset(cp.ltk + ltk->enc_size, 0, sizeof(cp.ltk) - ltk->enc_size); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5820 | cp.handle = cpu_to_le16(conn->handle); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 5821 | |
Johan Hedberg | a6f7833 | 2014-09-10 17:37:45 -0700 | [diff] [blame] | 5822 | conn->pending_sec_level = smp_ltk_sec_level(ltk); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5823 | |
Andre Guedes | 89cbb4d | 2013-07-31 16:25:29 -0300 | [diff] [blame] | 5824 | conn->enc_key_size = ltk->enc_size; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5825 | |
| 5826 | hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp); |
| 5827 | |
Claudio Takahasi | 5981a88 | 2013-07-25 16:34:24 -0300 | [diff] [blame] | 5828 | /* Ref. Bluetooth Core SPEC pages 1975 and 2004. STK is a |
| 5829 | * temporary key used to encrypt a connection following |
| 5830 | * pairing. It is used during the Encrypted Session Setup to |
| 5831 | * distribute the keys. Later, security can be re-established |
| 5832 | * using a distributed LTK. |
| 5833 | */ |
Johan Hedberg | 2ceba53 | 2014-06-16 19:25:16 +0300 | [diff] [blame] | 5834 | if (ltk->type == SMP_STK) { |
Johan Hedberg | fe59a05 | 2014-07-01 19:14:12 +0300 | [diff] [blame] | 5835 | set_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); |
Johan Hedberg | 970d0f1 | 2014-11-13 14:37:47 +0200 | [diff] [blame] | 5836 | list_del_rcu(<k->list); |
| 5837 | kfree_rcu(ltk, rcu); |
Johan Hedberg | fe59a05 | 2014-07-01 19:14:12 +0300 | [diff] [blame] | 5838 | } else { |
| 5839 | clear_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 5840 | } |
| 5841 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5842 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 5843 | |
| 5844 | return; |
| 5845 | |
| 5846 | not_found: |
| 5847 | neg.handle = ev->handle; |
| 5848 | hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg); |
| 5849 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5850 | } |
| 5851 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 5852 | static void send_conn_param_neg_reply(struct hci_dev *hdev, u16 handle, |
| 5853 | u8 reason) |
| 5854 | { |
| 5855 | struct hci_cp_le_conn_param_req_neg_reply cp; |
| 5856 | |
| 5857 | cp.handle = cpu_to_le16(handle); |
| 5858 | cp.reason = reason; |
| 5859 | |
| 5860 | hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY, sizeof(cp), |
| 5861 | &cp); |
| 5862 | } |
| 5863 | |
| 5864 | static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, |
| 5865 | struct sk_buff *skb) |
| 5866 | { |
| 5867 | struct hci_ev_le_remote_conn_param_req *ev = (void *) skb->data; |
| 5868 | struct hci_cp_le_conn_param_req_reply cp; |
| 5869 | struct hci_conn *hcon; |
| 5870 | u16 handle, min, max, latency, timeout; |
| 5871 | |
| 5872 | handle = le16_to_cpu(ev->handle); |
| 5873 | min = le16_to_cpu(ev->interval_min); |
| 5874 | max = le16_to_cpu(ev->interval_max); |
| 5875 | latency = le16_to_cpu(ev->latency); |
| 5876 | timeout = le16_to_cpu(ev->timeout); |
| 5877 | |
| 5878 | hcon = hci_conn_hash_lookup_handle(hdev, handle); |
| 5879 | if (!hcon || hcon->state != BT_CONNECTED) |
| 5880 | return send_conn_param_neg_reply(hdev, handle, |
| 5881 | HCI_ERROR_UNKNOWN_CONN_ID); |
| 5882 | |
| 5883 | if (hci_check_conn_params(min, max, latency, timeout)) |
| 5884 | return send_conn_param_neg_reply(hdev, handle, |
| 5885 | HCI_ERROR_INVALID_LL_PARAMS); |
| 5886 | |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 5887 | if (hcon->role == HCI_ROLE_MASTER) { |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 5888 | struct hci_conn_params *params; |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 5889 | u8 store_hint; |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 5890 | |
| 5891 | hci_dev_lock(hdev); |
| 5892 | |
| 5893 | params = hci_conn_params_lookup(hdev, &hcon->dst, |
| 5894 | hcon->dst_type); |
| 5895 | if (params) { |
| 5896 | params->conn_min_interval = min; |
| 5897 | params->conn_max_interval = max; |
| 5898 | params->conn_latency = latency; |
| 5899 | params->supervision_timeout = timeout; |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 5900 | store_hint = 0x01; |
Meng Yu | 149b3f1 | 2021-04-01 14:50:39 +0800 | [diff] [blame] | 5901 | } else { |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 5902 | store_hint = 0x00; |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | hci_dev_unlock(hdev); |
| 5906 | |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 5907 | mgmt_new_conn_param(hdev, &hcon->dst, hcon->dst_type, |
| 5908 | store_hint, min, max, latency, timeout); |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 5909 | } |
Andre Guedes | ffb5a827 | 2014-07-01 18:10:11 -0300 | [diff] [blame] | 5910 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 5911 | cp.handle = ev->handle; |
| 5912 | cp.interval_min = ev->interval_min; |
| 5913 | cp.interval_max = ev->interval_max; |
| 5914 | cp.latency = ev->latency; |
| 5915 | cp.timeout = ev->timeout; |
| 5916 | cp.min_ce_len = 0; |
| 5917 | cp.max_ce_len = 0; |
| 5918 | |
| 5919 | hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp); |
| 5920 | } |
| 5921 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5922 | static void hci_le_direct_adv_report_evt(struct hci_dev *hdev, |
| 5923 | struct sk_buff *skb) |
| 5924 | { |
| 5925 | u8 num_reports = skb->data[0]; |
Peilin Ye | f7e0e8b | 2020-09-09 03:17:00 -0400 | [diff] [blame] | 5926 | struct hci_ev_le_direct_adv_info *ev = (void *)&skb->data[1]; |
| 5927 | |
| 5928 | if (!num_reports || skb->len < num_reports * sizeof(*ev) + 1) |
| 5929 | return; |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5930 | |
| 5931 | hci_dev_lock(hdev); |
| 5932 | |
Peilin Ye | f7e0e8b | 2020-09-09 03:17:00 -0400 | [diff] [blame] | 5933 | for (; num_reports; num_reports--, ev++) |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5934 | process_adv_report(hdev, ev->evt_type, &ev->bdaddr, |
| 5935 | ev->bdaddr_type, &ev->direct_addr, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5936 | ev->direct_addr_type, ev->rssi, NULL, 0, |
| 5937 | false); |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5938 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5939 | hci_dev_unlock(hdev); |
| 5940 | } |
| 5941 | |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 5942 | static void hci_le_phy_update_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5943 | { |
| 5944 | struct hci_ev_le_phy_update_complete *ev = (void *) skb->data; |
| 5945 | struct hci_conn *conn; |
| 5946 | |
| 5947 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5948 | |
Ayush Garg | 87df8bc | 2021-03-17 16:52:14 +0530 | [diff] [blame] | 5949 | if (ev->status) |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 5950 | return; |
| 5951 | |
| 5952 | hci_dev_lock(hdev); |
| 5953 | |
| 5954 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 5955 | if (!conn) |
| 5956 | goto unlock; |
| 5957 | |
| 5958 | conn->le_tx_phy = ev->tx_phy; |
| 5959 | conn->le_rx_phy = ev->rx_phy; |
| 5960 | |
| 5961 | unlock: |
| 5962 | hci_dev_unlock(hdev); |
| 5963 | } |
| 5964 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5965 | static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb) |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5966 | { |
| 5967 | struct hci_ev_le_meta *le_ev = (void *) skb->data; |
| 5968 | |
| 5969 | skb_pull(skb, sizeof(*le_ev)); |
| 5970 | |
| 5971 | switch (le_ev->subevent) { |
| 5972 | case HCI_EV_LE_CONN_COMPLETE: |
| 5973 | hci_le_conn_complete_evt(hdev, skb); |
| 5974 | break; |
| 5975 | |
Marcel Holtmann | 1855d92 | 2014-06-23 11:40:05 +0200 | [diff] [blame] | 5976 | case HCI_EV_LE_CONN_UPDATE_COMPLETE: |
| 5977 | hci_le_conn_update_complete_evt(hdev, skb); |
| 5978 | break; |
| 5979 | |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 5980 | case HCI_EV_LE_ADVERTISING_REPORT: |
| 5981 | hci_le_adv_report_evt(hdev, skb); |
| 5982 | break; |
| 5983 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5984 | case HCI_EV_LE_REMOTE_FEAT_COMPLETE: |
| 5985 | hci_le_remote_feat_complete_evt(hdev, skb); |
| 5986 | break; |
| 5987 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5988 | case HCI_EV_LE_LTK_REQ: |
| 5989 | hci_le_ltk_request_evt(hdev, skb); |
| 5990 | break; |
| 5991 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 5992 | case HCI_EV_LE_REMOTE_CONN_PARAM_REQ: |
| 5993 | hci_le_remote_conn_param_req_evt(hdev, skb); |
| 5994 | break; |
| 5995 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5996 | case HCI_EV_LE_DIRECT_ADV_REPORT: |
| 5997 | hci_le_direct_adv_report_evt(hdev, skb); |
| 5998 | break; |
| 5999 | |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 6000 | case HCI_EV_LE_PHY_UPDATE_COMPLETE: |
| 6001 | hci_le_phy_update_evt(hdev, skb); |
| 6002 | break; |
| 6003 | |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 6004 | case HCI_EV_LE_EXT_ADV_REPORT: |
| 6005 | hci_le_ext_adv_report_evt(hdev, skb); |
| 6006 | break; |
| 6007 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 6008 | case HCI_EV_LE_ENHANCED_CONN_COMPLETE: |
| 6009 | hci_le_enh_conn_complete_evt(hdev, skb); |
| 6010 | break; |
| 6011 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6012 | case HCI_EV_LE_EXT_ADV_SET_TERM: |
| 6013 | hci_le_ext_adv_term_evt(hdev, skb); |
| 6014 | break; |
| 6015 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6016 | default: |
| 6017 | break; |
| 6018 | } |
| 6019 | } |
| 6020 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6021 | static bool hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode, |
| 6022 | u8 event, struct sk_buff *skb) |
| 6023 | { |
| 6024 | struct hci_ev_cmd_complete *ev; |
| 6025 | struct hci_event_hdr *hdr; |
| 6026 | |
| 6027 | if (!skb) |
| 6028 | return false; |
| 6029 | |
| 6030 | if (skb->len < sizeof(*hdr)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 6031 | bt_dev_err(hdev, "too short HCI event"); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6032 | return false; |
| 6033 | } |
| 6034 | |
| 6035 | hdr = (void *) skb->data; |
| 6036 | skb_pull(skb, HCI_EVENT_HDR_SIZE); |
| 6037 | |
| 6038 | if (event) { |
| 6039 | if (hdr->evt != event) |
| 6040 | return false; |
| 6041 | return true; |
| 6042 | } |
| 6043 | |
Zheng Yongjun | 91641b7 | 2021-06-02 14:54:58 +0800 | [diff] [blame] | 6044 | /* Check if request ended in Command Status - no way to retrieve |
Johan Hedberg | 1629db9c | 2018-11-27 11:37:46 +0200 | [diff] [blame] | 6045 | * any extra parameters in this case. |
| 6046 | */ |
| 6047 | if (hdr->evt == HCI_EV_CMD_STATUS) |
| 6048 | return false; |
| 6049 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6050 | if (hdr->evt != HCI_EV_CMD_COMPLETE) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 6051 | bt_dev_err(hdev, "last event is not cmd complete (0x%2.2x)", |
| 6052 | hdr->evt); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6053 | return false; |
| 6054 | } |
| 6055 | |
| 6056 | if (skb->len < sizeof(*ev)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 6057 | bt_dev_err(hdev, "too short cmd_complete event"); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6058 | return false; |
| 6059 | } |
| 6060 | |
| 6061 | ev = (void *) skb->data; |
| 6062 | skb_pull(skb, sizeof(*ev)); |
| 6063 | |
| 6064 | if (opcode != __le16_to_cpu(ev->opcode)) { |
| 6065 | BT_DBG("opcode doesn't match (0x%2.2x != 0x%2.2x)", opcode, |
| 6066 | __le16_to_cpu(ev->opcode)); |
| 6067 | return false; |
| 6068 | } |
| 6069 | |
| 6070 | return true; |
| 6071 | } |
| 6072 | |
Abhishek Pandit-Subedi | 2f20216 | 2020-09-11 14:07:13 -0700 | [diff] [blame] | 6073 | static void hci_store_wake_reason(struct hci_dev *hdev, u8 event, |
| 6074 | struct sk_buff *skb) |
| 6075 | { |
| 6076 | struct hci_ev_le_advertising_info *adv; |
| 6077 | struct hci_ev_le_direct_adv_info *direct_adv; |
| 6078 | struct hci_ev_le_ext_adv_report *ext_adv; |
| 6079 | const struct hci_ev_conn_complete *conn_complete = (void *)skb->data; |
| 6080 | const struct hci_ev_conn_request *conn_request = (void *)skb->data; |
| 6081 | |
| 6082 | hci_dev_lock(hdev); |
| 6083 | |
| 6084 | /* If we are currently suspended and this is the first BT event seen, |
| 6085 | * save the wake reason associated with the event. |
| 6086 | */ |
| 6087 | if (!hdev->suspended || hdev->wake_reason) |
| 6088 | goto unlock; |
| 6089 | |
| 6090 | /* Default to remote wake. Values for wake_reason are documented in the |
| 6091 | * Bluez mgmt api docs. |
| 6092 | */ |
| 6093 | hdev->wake_reason = MGMT_WAKE_REASON_REMOTE_WAKE; |
| 6094 | |
| 6095 | /* Once configured for remote wakeup, we should only wake up for |
| 6096 | * reconnections. It's useful to see which device is waking us up so |
| 6097 | * keep track of the bdaddr of the connection event that woke us up. |
| 6098 | */ |
| 6099 | if (event == HCI_EV_CONN_REQUEST) { |
| 6100 | bacpy(&hdev->wake_addr, &conn_complete->bdaddr); |
| 6101 | hdev->wake_addr_type = BDADDR_BREDR; |
| 6102 | } else if (event == HCI_EV_CONN_COMPLETE) { |
| 6103 | bacpy(&hdev->wake_addr, &conn_request->bdaddr); |
| 6104 | hdev->wake_addr_type = BDADDR_BREDR; |
| 6105 | } else if (event == HCI_EV_LE_META) { |
| 6106 | struct hci_ev_le_meta *le_ev = (void *)skb->data; |
| 6107 | u8 subevent = le_ev->subevent; |
| 6108 | u8 *ptr = &skb->data[sizeof(*le_ev)]; |
| 6109 | u8 num_reports = *ptr; |
| 6110 | |
| 6111 | if ((subevent == HCI_EV_LE_ADVERTISING_REPORT || |
| 6112 | subevent == HCI_EV_LE_DIRECT_ADV_REPORT || |
| 6113 | subevent == HCI_EV_LE_EXT_ADV_REPORT) && |
| 6114 | num_reports) { |
| 6115 | adv = (void *)(ptr + 1); |
| 6116 | direct_adv = (void *)(ptr + 1); |
| 6117 | ext_adv = (void *)(ptr + 1); |
| 6118 | |
| 6119 | switch (subevent) { |
| 6120 | case HCI_EV_LE_ADVERTISING_REPORT: |
| 6121 | bacpy(&hdev->wake_addr, &adv->bdaddr); |
| 6122 | hdev->wake_addr_type = adv->bdaddr_type; |
| 6123 | break; |
| 6124 | case HCI_EV_LE_DIRECT_ADV_REPORT: |
| 6125 | bacpy(&hdev->wake_addr, &direct_adv->bdaddr); |
| 6126 | hdev->wake_addr_type = direct_adv->bdaddr_type; |
| 6127 | break; |
| 6128 | case HCI_EV_LE_EXT_ADV_REPORT: |
| 6129 | bacpy(&hdev->wake_addr, &ext_adv->bdaddr); |
| 6130 | hdev->wake_addr_type = ext_adv->bdaddr_type; |
| 6131 | break; |
| 6132 | } |
| 6133 | } |
| 6134 | } else { |
| 6135 | hdev->wake_reason = MGMT_WAKE_REASON_UNEXPECTED; |
| 6136 | } |
| 6137 | |
| 6138 | unlock: |
| 6139 | hci_dev_unlock(hdev); |
| 6140 | } |
| 6141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6142 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) |
| 6143 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6144 | struct hci_event_hdr *hdr = (void *) skb->data; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6145 | hci_req_complete_t req_complete = NULL; |
| 6146 | hci_req_complete_skb_t req_complete_skb = NULL; |
| 6147 | struct sk_buff *orig_skb = NULL; |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6148 | u8 status = 0, event = hdr->evt, req_evt = 0; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6149 | u16 opcode = HCI_OP_NOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6150 | |
Alain Michaud | 08bb4da | 2020-03-03 15:55:34 +0000 | [diff] [blame] | 6151 | if (!event) { |
| 6152 | bt_dev_warn(hdev, "Received unexpected HCI Event 00000000"); |
| 6153 | goto done; |
| 6154 | } |
| 6155 | |
Marcel Holtmann | 242c0eb | 2015-10-25 22:45:53 +0100 | [diff] [blame] | 6156 | if (hdev->sent_cmd && bt_cb(hdev->sent_cmd)->hci.req_event == event) { |
Johannes Berg | c1f23a2 | 2013-10-07 18:19:16 +0200 | [diff] [blame] | 6157 | struct hci_command_hdr *cmd_hdr = (void *) hdev->sent_cmd->data; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6158 | opcode = __le16_to_cpu(cmd_hdr->opcode); |
| 6159 | hci_req_cmd_complete(hdev, opcode, status, &req_complete, |
| 6160 | &req_complete_skb); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6161 | req_evt = event; |
Johan Hedberg | 02350a7 | 2013-04-03 21:50:29 +0300 | [diff] [blame] | 6162 | } |
| 6163 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6164 | /* If it looks like we might end up having to call |
| 6165 | * req_complete_skb, store a pristine copy of the skb since the |
| 6166 | * various handlers may modify the original one through |
| 6167 | * skb_pull() calls, etc. |
| 6168 | */ |
| 6169 | if (req_complete_skb || event == HCI_EV_CMD_STATUS || |
| 6170 | event == HCI_EV_CMD_COMPLETE) |
| 6171 | orig_skb = skb_clone(skb, GFP_KERNEL); |
| 6172 | |
| 6173 | skb_pull(skb, HCI_EVENT_HDR_SIZE); |
| 6174 | |
Abhishek Pandit-Subedi | 2f20216 | 2020-09-11 14:07:13 -0700 | [diff] [blame] | 6175 | /* Store wake reason if we're suspended */ |
| 6176 | hci_store_wake_reason(hdev, event, skb); |
| 6177 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6178 | switch (event) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6179 | case HCI_EV_INQUIRY_COMPLETE: |
| 6180 | hci_inquiry_complete_evt(hdev, skb); |
| 6181 | break; |
| 6182 | |
| 6183 | case HCI_EV_INQUIRY_RESULT: |
| 6184 | hci_inquiry_result_evt(hdev, skb); |
| 6185 | break; |
| 6186 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6187 | case HCI_EV_CONN_COMPLETE: |
| 6188 | hci_conn_complete_evt(hdev, skb); |
Marcel Holtmann | 21d9e30 | 2005-09-13 01:32:25 +0200 | [diff] [blame] | 6189 | break; |
| 6190 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6191 | case HCI_EV_CONN_REQUEST: |
| 6192 | hci_conn_request_evt(hdev, skb); |
| 6193 | break; |
| 6194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6195 | case HCI_EV_DISCONN_COMPLETE: |
| 6196 | hci_disconn_complete_evt(hdev, skb); |
| 6197 | break; |
| 6198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6199 | case HCI_EV_AUTH_COMPLETE: |
| 6200 | hci_auth_complete_evt(hdev, skb); |
| 6201 | break; |
| 6202 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6203 | case HCI_EV_REMOTE_NAME: |
| 6204 | hci_remote_name_evt(hdev, skb); |
| 6205 | break; |
| 6206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6207 | case HCI_EV_ENCRYPT_CHANGE: |
| 6208 | hci_encrypt_change_evt(hdev, skb); |
| 6209 | break; |
| 6210 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6211 | case HCI_EV_CHANGE_LINK_KEY_COMPLETE: |
| 6212 | hci_change_link_key_complete_evt(hdev, skb); |
| 6213 | break; |
| 6214 | |
| 6215 | case HCI_EV_REMOTE_FEATURES: |
| 6216 | hci_remote_features_evt(hdev, skb); |
| 6217 | break; |
| 6218 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6219 | case HCI_EV_CMD_COMPLETE: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6220 | hci_cmd_complete_evt(hdev, skb, &opcode, &status, |
| 6221 | &req_complete, &req_complete_skb); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6222 | break; |
| 6223 | |
| 6224 | case HCI_EV_CMD_STATUS: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6225 | hci_cmd_status_evt(hdev, skb, &opcode, &status, &req_complete, |
| 6226 | &req_complete_skb); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6227 | break; |
| 6228 | |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 6229 | case HCI_EV_HARDWARE_ERROR: |
| 6230 | hci_hardware_error_evt(hdev, skb); |
| 6231 | break; |
| 6232 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6233 | case HCI_EV_ROLE_CHANGE: |
| 6234 | hci_role_change_evt(hdev, skb); |
| 6235 | break; |
| 6236 | |
| 6237 | case HCI_EV_NUM_COMP_PKTS: |
| 6238 | hci_num_comp_pkts_evt(hdev, skb); |
| 6239 | break; |
| 6240 | |
| 6241 | case HCI_EV_MODE_CHANGE: |
| 6242 | hci_mode_change_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6243 | break; |
| 6244 | |
| 6245 | case HCI_EV_PIN_CODE_REQ: |
| 6246 | hci_pin_code_request_evt(hdev, skb); |
| 6247 | break; |
| 6248 | |
| 6249 | case HCI_EV_LINK_KEY_REQ: |
| 6250 | hci_link_key_request_evt(hdev, skb); |
| 6251 | break; |
| 6252 | |
| 6253 | case HCI_EV_LINK_KEY_NOTIFY: |
| 6254 | hci_link_key_notify_evt(hdev, skb); |
| 6255 | break; |
| 6256 | |
| 6257 | case HCI_EV_CLOCK_OFFSET: |
| 6258 | hci_clock_offset_evt(hdev, skb); |
| 6259 | break; |
| 6260 | |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 6261 | case HCI_EV_PKT_TYPE_CHANGE: |
| 6262 | hci_pkt_type_change_evt(hdev, skb); |
| 6263 | break; |
| 6264 | |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 6265 | case HCI_EV_PSCAN_REP_MODE: |
| 6266 | hci_pscan_rep_mode_evt(hdev, skb); |
| 6267 | break; |
| 6268 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6269 | case HCI_EV_INQUIRY_RESULT_WITH_RSSI: |
| 6270 | hci_inquiry_result_with_rssi_evt(hdev, skb); |
| 6271 | break; |
| 6272 | |
| 6273 | case HCI_EV_REMOTE_EXT_FEATURES: |
| 6274 | hci_remote_ext_features_evt(hdev, skb); |
| 6275 | break; |
| 6276 | |
| 6277 | case HCI_EV_SYNC_CONN_COMPLETE: |
| 6278 | hci_sync_conn_complete_evt(hdev, skb); |
| 6279 | break; |
| 6280 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6281 | case HCI_EV_EXTENDED_INQUIRY_RESULT: |
| 6282 | hci_extended_inquiry_result_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6283 | break; |
| 6284 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 6285 | case HCI_EV_KEY_REFRESH_COMPLETE: |
| 6286 | hci_key_refresh_complete_evt(hdev, skb); |
| 6287 | break; |
| 6288 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 6289 | case HCI_EV_IO_CAPA_REQUEST: |
| 6290 | hci_io_capa_request_evt(hdev, skb); |
| 6291 | break; |
| 6292 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 6293 | case HCI_EV_IO_CAPA_REPLY: |
| 6294 | hci_io_capa_reply_evt(hdev, skb); |
| 6295 | break; |
| 6296 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 6297 | case HCI_EV_USER_CONFIRM_REQUEST: |
| 6298 | hci_user_confirm_request_evt(hdev, skb); |
| 6299 | break; |
| 6300 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 6301 | case HCI_EV_USER_PASSKEY_REQUEST: |
| 6302 | hci_user_passkey_request_evt(hdev, skb); |
| 6303 | break; |
| 6304 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 6305 | case HCI_EV_USER_PASSKEY_NOTIFY: |
| 6306 | hci_user_passkey_notify_evt(hdev, skb); |
| 6307 | break; |
| 6308 | |
| 6309 | case HCI_EV_KEYPRESS_NOTIFY: |
| 6310 | hci_keypress_notify_evt(hdev, skb); |
| 6311 | break; |
| 6312 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 6313 | case HCI_EV_SIMPLE_PAIR_COMPLETE: |
| 6314 | hci_simple_pair_complete_evt(hdev, skb); |
| 6315 | break; |
| 6316 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 6317 | case HCI_EV_REMOTE_HOST_FEATURES: |
| 6318 | hci_remote_host_features_evt(hdev, skb); |
| 6319 | break; |
| 6320 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6321 | case HCI_EV_LE_META: |
| 6322 | hci_le_meta_evt(hdev, skb); |
| 6323 | break; |
| 6324 | |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 6325 | case HCI_EV_REMOTE_OOB_DATA_REQUEST: |
| 6326 | hci_remote_oob_data_request_evt(hdev, skb); |
| 6327 | break; |
| 6328 | |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 6329 | #if IS_ENABLED(CONFIG_BT_HS) |
| 6330 | case HCI_EV_CHANNEL_SELECTED: |
| 6331 | hci_chan_selected_evt(hdev, skb); |
| 6332 | break; |
| 6333 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 6334 | case HCI_EV_PHY_LINK_COMPLETE: |
| 6335 | hci_phy_link_complete_evt(hdev, skb); |
| 6336 | break; |
| 6337 | |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 6338 | case HCI_EV_LOGICAL_LINK_COMPLETE: |
| 6339 | hci_loglink_complete_evt(hdev, skb); |
| 6340 | break; |
| 6341 | |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 6342 | case HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE: |
| 6343 | hci_disconn_loglink_complete_evt(hdev, skb); |
| 6344 | break; |
| 6345 | |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 6346 | case HCI_EV_DISCONN_PHY_LINK_COMPLETE: |
| 6347 | hci_disconn_phylink_complete_evt(hdev, skb); |
| 6348 | break; |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 6349 | #endif |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 6350 | |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 6351 | case HCI_EV_NUM_COMP_BLOCKS: |
| 6352 | hci_num_comp_blocks_evt(hdev, skb); |
| 6353 | break; |
| 6354 | |
Miao-chen Chou | 145373c | 2020-04-03 21:44:01 +0200 | [diff] [blame] | 6355 | case HCI_EV_VENDOR: |
| 6356 | msft_vendor_evt(hdev, skb); |
| 6357 | break; |
| 6358 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6359 | default: |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 6360 | BT_DBG("%s event 0x%2.2x", hdev->name, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6361 | break; |
| 6362 | } |
| 6363 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6364 | if (req_complete) { |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6365 | req_complete(hdev, status, opcode); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6366 | } else if (req_complete_skb) { |
| 6367 | if (!hci_get_cmd_complete(hdev, opcode, req_evt, orig_skb)) { |
| 6368 | kfree_skb(orig_skb); |
| 6369 | orig_skb = NULL; |
| 6370 | } |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6371 | req_complete_skb(hdev, status, opcode, orig_skb); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6372 | } |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6373 | |
Alain Michaud | 08bb4da | 2020-03-03 15:55:34 +0000 | [diff] [blame] | 6374 | done: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6375 | kfree_skb(orig_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6376 | kfree_skb(skb); |
| 6377 | hdev->stat.evt_rx++; |
| 6378 | } |