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 | |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 43 | #define secs_to_jiffies(_secs) msecs_to_jiffies((_secs) * 1000) |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* Handle HCI Event packets */ |
| 46 | |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 47 | static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb, |
| 48 | u8 *new_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 50 | __u8 status = *((__u8 *) skb->data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 52 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 54 | /* It is possible that we receive Inquiry Complete event right |
| 55 | * before we receive Inquiry Cancel Command Complete event, in |
| 56 | * which case the latter event should have status of Command |
| 57 | * Disallowed (0x0c). This should not be treated as error, since |
| 58 | * we actually achieve what Inquiry Cancel wants to achieve, |
| 59 | * which is to end the last Inquiry session. |
| 60 | */ |
| 61 | if (status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) { |
| 62 | bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command"); |
| 63 | status = 0x00; |
| 64 | } |
| 65 | |
| 66 | *new_status = status; |
| 67 | |
Andre Guedes | 82f4785 | 2013-04-30 15:29:34 -0300 | [diff] [blame] | 68 | if (status) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 69 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 71 | clear_bit(HCI_INQUIRY, &hdev->flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 72 | smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */ |
Andre Guedes | 3e13fa1 | 2013-03-27 20:04:56 -0300 | [diff] [blame] | 73 | wake_up_bit(&hdev->flags, HCI_INQUIRY); |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 74 | |
Johan Hedberg | 50143a4 | 2014-06-10 14:05:57 +0300 | [diff] [blame] | 75 | hci_dev_lock(hdev); |
Jakub Pawlowski | 168b8a2 | 2015-10-16 10:07:49 +0300 | [diff] [blame] | 76 | /* Set discovery state to stopped if we're not doing LE active |
| 77 | * scanning. |
| 78 | */ |
| 79 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 80 | hdev->le_scan_type != LE_SCAN_ACTIVE) |
| 81 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 50143a4 | 2014-06-10 14:05:57 +0300 | [diff] [blame] | 82 | hci_dev_unlock(hdev); |
| 83 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 84 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 87 | static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb) |
| 88 | { |
| 89 | __u8 status = *((__u8 *) skb->data); |
| 90 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 91 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 92 | |
| 93 | if (status) |
| 94 | return; |
| 95 | |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 96 | hci_dev_set_flag(hdev, HCI_PERIODIC_INQ); |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 97 | } |
| 98 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 99 | 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] | 100 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 101 | __u8 status = *((__u8 *) skb->data); |
| 102 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 103 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 104 | |
| 105 | if (status) |
| 106 | return; |
| 107 | |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 108 | hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 109 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 110 | hci_conn_check_pending(hdev); |
| 111 | } |
| 112 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 113 | static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, |
| 114 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 115 | { |
| 116 | BT_DBG("%s", hdev->name); |
| 117 | } |
| 118 | |
| 119 | static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb) |
| 120 | { |
| 121 | struct hci_rp_role_discovery *rp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 124 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 126 | if (rp->status) |
| 127 | return; |
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 | hci_dev_lock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 131 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 132 | if (conn) |
| 133 | conn->role = rp->role; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 134 | |
| 135 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 138 | static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
| 139 | { |
| 140 | struct hci_rp_read_link_policy *rp = (void *) skb->data; |
| 141 | struct hci_conn *conn; |
| 142 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 143 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 144 | |
| 145 | if (rp->status) |
| 146 | return; |
| 147 | |
| 148 | hci_dev_lock(hdev); |
| 149 | |
| 150 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 151 | if (conn) |
| 152 | conn->link_policy = __le16_to_cpu(rp->policy); |
| 153 | |
| 154 | hci_dev_unlock(hdev); |
| 155 | } |
| 156 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 157 | 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] | 158 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 159 | struct hci_rp_write_link_policy *rp = (void *) skb->data; |
| 160 | struct hci_conn *conn; |
| 161 | void *sent; |
| 162 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 163 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 164 | |
| 165 | if (rp->status) |
| 166 | return; |
| 167 | |
| 168 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY); |
| 169 | if (!sent) |
| 170 | return; |
| 171 | |
| 172 | hci_dev_lock(hdev); |
| 173 | |
| 174 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 175 | if (conn) |
Harvey Harrison | 8398531 | 2008-05-02 16:25:46 -0700 | [diff] [blame] | 176 | conn->link_policy = get_unaligned_le16(sent + 2); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 177 | |
| 178 | hci_dev_unlock(hdev); |
| 179 | } |
| 180 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 181 | static void hci_cc_read_def_link_policy(struct hci_dev *hdev, |
| 182 | struct sk_buff *skb) |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 183 | { |
| 184 | struct hci_rp_read_def_link_policy *rp = (void *) skb->data; |
| 185 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 186 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 187 | |
| 188 | if (rp->status) |
| 189 | return; |
| 190 | |
| 191 | hdev->link_policy = __le16_to_cpu(rp->policy); |
| 192 | } |
| 193 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 194 | static void hci_cc_write_def_link_policy(struct hci_dev *hdev, |
| 195 | struct sk_buff *skb) |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 196 | { |
| 197 | __u8 status = *((__u8 *) skb->data); |
| 198 | void *sent; |
| 199 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 200 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 201 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 202 | if (status) |
| 203 | return; |
| 204 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 205 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY); |
| 206 | if (!sent) |
| 207 | return; |
| 208 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 209 | hdev->link_policy = get_unaligned_le16(sent); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 212 | static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) |
| 213 | { |
| 214 | __u8 status = *((__u8 *) skb->data); |
| 215 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 216 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 217 | |
Gustavo F. Padovan | 1057213 | 2011-03-16 15:36:29 -0300 | [diff] [blame] | 218 | clear_bit(HCI_RESET, &hdev->flags); |
| 219 | |
Marcel Holtmann | 8761f9d | 2014-11-02 02:45:58 +0100 | [diff] [blame] | 220 | if (status) |
| 221 | return; |
| 222 | |
Johan Hedberg | a297e97 | 2012-02-21 17:55:47 +0200 | [diff] [blame] | 223 | /* Reset all non-persistent flags */ |
Marcel Holtmann | eacb44d | 2015-03-13 09:04:17 -0700 | [diff] [blame] | 224 | hci_dev_clear_volatile_flags(hdev); |
Andre Guedes | 69775ff | 2012-02-23 16:50:05 +0200 | [diff] [blame] | 225 | |
Johan Hedberg | 39c5d97 | 2015-01-28 19:56:01 +0200 | [diff] [blame] | 226 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 227 | |
Johan Hedberg | bbaf444 | 2012-11-08 01:22:59 +0100 | [diff] [blame] | 228 | hdev->inq_tx_power = HCI_TX_POWER_INVALID; |
| 229 | hdev->adv_tx_power = HCI_TX_POWER_INVALID; |
Johan Hedberg | 3f0f524 | 2012-11-08 01:23:00 +0100 | [diff] [blame] | 230 | |
| 231 | memset(hdev->adv_data, 0, sizeof(hdev->adv_data)); |
| 232 | hdev->adv_data_len = 0; |
Marcel Holtmann | f8e808b | 2013-10-16 00:16:47 -0700 | [diff] [blame] | 233 | |
| 234 | memset(hdev->scan_rsp_data, 0, sizeof(hdev->scan_rsp_data)); |
| 235 | hdev->scan_rsp_data_len = 0; |
Marcel Holtmann | 06f5b77 | 2013-10-19 07:09:11 -0700 | [diff] [blame] | 236 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 237 | hdev->le_scan_type = LE_SCAN_PASSIVE; |
| 238 | |
Marcel Holtmann | 06f5b77 | 2013-10-19 07:09:11 -0700 | [diff] [blame] | 239 | hdev->ssp_debug_mode = 0; |
Marcel Holtmann | a4d5504 | 2014-10-29 23:37:53 +0100 | [diff] [blame] | 240 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 241 | hci_bdaddr_list_clear(&hdev->le_accept_list); |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 242 | hci_bdaddr_list_clear(&hdev->le_resolv_list); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 245 | static void hci_cc_read_stored_link_key(struct hci_dev *hdev, |
| 246 | struct sk_buff *skb) |
| 247 | { |
| 248 | struct hci_rp_read_stored_link_key *rp = (void *)skb->data; |
| 249 | struct hci_cp_read_stored_link_key *sent; |
| 250 | |
| 251 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 252 | |
| 253 | sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY); |
| 254 | if (!sent) |
| 255 | return; |
| 256 | |
| 257 | if (!rp->status && sent->read_all == 0x01) { |
| 258 | hdev->stored_max_keys = rp->max_keys; |
| 259 | hdev->stored_num_keys = rp->num_keys; |
| 260 | } |
| 261 | } |
| 262 | |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 263 | static void hci_cc_delete_stored_link_key(struct hci_dev *hdev, |
| 264 | struct sk_buff *skb) |
| 265 | { |
| 266 | struct hci_rp_delete_stored_link_key *rp = (void *)skb->data; |
| 267 | |
| 268 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 269 | |
| 270 | if (rp->status) |
| 271 | return; |
| 272 | |
| 273 | if (rp->num_keys <= hdev->stored_num_keys) |
| 274 | hdev->stored_num_keys -= rp->num_keys; |
| 275 | else |
| 276 | hdev->stored_num_keys = 0; |
| 277 | } |
| 278 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 279 | static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 280 | { |
| 281 | __u8 status = *((__u8 *) skb->data); |
| 282 | void *sent; |
| 283 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 284 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 285 | |
| 286 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME); |
| 287 | if (!sent) |
| 288 | return; |
| 289 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 290 | hci_dev_lock(hdev); |
| 291 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 292 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | f51d5b2 | 2012-02-22 18:17:32 +0200 | [diff] [blame] | 293 | mgmt_set_local_name_complete(hdev, sent, status); |
Johan Hedberg | 28cc7bd | 2012-02-22 21:06:55 +0200 | [diff] [blame] | 294 | else if (!status) |
| 295 | memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH); |
Johan Hedberg | f51d5b2 | 2012-02-22 18:17:32 +0200 | [diff] [blame] | 296 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 297 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 301 | { |
| 302 | struct hci_rp_read_local_name *rp = (void *) skb->data; |
| 303 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 304 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 305 | |
| 306 | if (rp->status) |
| 307 | return; |
| 308 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 309 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 310 | hci_dev_test_flag(hdev, HCI_CONFIG)) |
Johan Hedberg | db99b5f | 2012-02-22 20:14:22 +0200 | [diff] [blame] | 311 | memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 315 | { |
| 316 | __u8 status = *((__u8 *) skb->data); |
| 317 | void *sent; |
| 318 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 319 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 320 | |
| 321 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE); |
| 322 | if (!sent) |
| 323 | return; |
| 324 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 325 | hci_dev_lock(hdev); |
| 326 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 327 | if (!status) { |
| 328 | __u8 param = *((__u8 *) sent); |
| 329 | |
| 330 | if (param == AUTH_ENABLED) |
| 331 | set_bit(HCI_AUTH, &hdev->flags); |
| 332 | else |
| 333 | clear_bit(HCI_AUTH, &hdev->flags); |
| 334 | } |
| 335 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 336 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 33ef95e | 2012-02-16 23:56:27 +0200 | [diff] [blame] | 337 | mgmt_auth_enable_complete(hdev, status); |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 338 | |
| 339 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 343 | { |
| 344 | __u8 status = *((__u8 *) skb->data); |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 345 | __u8 param; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 346 | void *sent; |
| 347 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 348 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 349 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 350 | if (status) |
| 351 | return; |
| 352 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 353 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE); |
| 354 | if (!sent) |
| 355 | return; |
| 356 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 357 | param = *((__u8 *) sent); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 358 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 359 | if (param) |
| 360 | set_bit(HCI_ENCRYPT, &hdev->flags); |
| 361 | else |
| 362 | clear_bit(HCI_ENCRYPT, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 366 | { |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 367 | __u8 status = *((__u8 *) skb->data); |
| 368 | __u8 param; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 369 | void *sent; |
| 370 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 371 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 372 | |
| 373 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); |
| 374 | if (!sent) |
| 375 | return; |
| 376 | |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 377 | param = *((__u8 *) sent); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 378 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 379 | hci_dev_lock(hdev); |
| 380 | |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 381 | if (status) { |
Johan Hedberg | 2d7cee5 | 2011-11-07 22:16:03 +0200 | [diff] [blame] | 382 | hdev->discov_timeout = 0; |
| 383 | goto done; |
| 384 | } |
| 385 | |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 386 | if (param & SCAN_INQUIRY) |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 387 | set_bit(HCI_ISCAN, &hdev->flags); |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 388 | else |
| 389 | clear_bit(HCI_ISCAN, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 390 | |
Johan Hedberg | 031547d | 2014-07-10 12:09:06 +0300 | [diff] [blame] | 391 | if (param & SCAN_PAGE) |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 392 | set_bit(HCI_PSCAN, &hdev->flags); |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 393 | else |
Johan Hedberg | 204e399 | 2014-07-28 15:45:31 +0300 | [diff] [blame] | 394 | clear_bit(HCI_PSCAN, &hdev->flags); |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 395 | |
| 396 | done: |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 397 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 398 | } |
| 399 | |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 400 | static void hci_cc_set_event_filter(struct hci_dev *hdev, struct sk_buff *skb) |
| 401 | { |
| 402 | __u8 status = *((__u8 *)skb->data); |
| 403 | struct hci_cp_set_event_filter *cp; |
| 404 | void *sent; |
| 405 | |
| 406 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 407 | |
| 408 | if (status) |
| 409 | return; |
| 410 | |
| 411 | sent = hci_sent_cmd_data(hdev, HCI_OP_SET_EVENT_FLT); |
| 412 | if (!sent) |
| 413 | return; |
| 414 | |
| 415 | cp = (struct hci_cp_set_event_filter *)sent; |
| 416 | |
| 417 | if (cp->flt_type == HCI_FLT_CLEAR_ALL) |
| 418 | hci_dev_clear_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); |
| 419 | else |
| 420 | hci_dev_set_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); |
| 421 | } |
| 422 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 423 | static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 424 | { |
| 425 | struct hci_rp_read_class_of_dev *rp = (void *) skb->data; |
| 426 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 427 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 428 | |
| 429 | if (rp->status) |
| 430 | return; |
| 431 | |
| 432 | memcpy(hdev->dev_class, rp->dev_class, 3); |
| 433 | |
| 434 | BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 435 | hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 439 | { |
| 440 | __u8 status = *((__u8 *) skb->data); |
| 441 | void *sent; |
| 442 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 443 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 444 | |
| 445 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV); |
| 446 | if (!sent) |
| 447 | return; |
| 448 | |
Marcel Holtmann | 7f9a903 | 2012-02-22 18:38:01 +0100 | [diff] [blame] | 449 | hci_dev_lock(hdev); |
| 450 | |
| 451 | if (status == 0) |
| 452 | memcpy(hdev->dev_class, sent, 3); |
| 453 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 454 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Marcel Holtmann | 7f9a903 | 2012-02-22 18:38:01 +0100 | [diff] [blame] | 455 | mgmt_set_class_of_dev_complete(hdev, sent, status); |
| 456 | |
| 457 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) |
| 461 | { |
| 462 | struct hci_rp_read_voice_setting *rp = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | __u16 setting; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 464 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 465 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 466 | |
| 467 | if (rp->status) |
| 468 | return; |
| 469 | |
| 470 | setting = __le16_to_cpu(rp->voice_setting); |
| 471 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 472 | if (hdev->voice_setting == setting) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 473 | return; |
| 474 | |
| 475 | hdev->voice_setting = setting; |
| 476 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 477 | BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 478 | |
Gustavo F. Padovan | 3c54711 | 2011-12-14 22:58:44 -0200 | [diff] [blame] | 479 | if (hdev->notify) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 480 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 481 | } |
| 482 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 483 | static void hci_cc_write_voice_setting(struct hci_dev *hdev, |
| 484 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 485 | { |
| 486 | __u8 status = *((__u8 *) skb->data); |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 487 | __u16 setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | void *sent; |
| 489 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 490 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 492 | if (status) |
| 493 | return; |
| 494 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 495 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING); |
| 496 | if (!sent) |
| 497 | return; |
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 | setting = get_unaligned_le16(sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 501 | if (hdev->voice_setting == setting) |
| 502 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 504 | hdev->voice_setting = setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 506 | BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting); |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 507 | |
Gustavo F. Padovan | 3c54711 | 2011-12-14 22:58:44 -0200 | [diff] [blame] | 508 | if (hdev->notify) |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 509 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 512 | static void hci_cc_read_num_supported_iac(struct hci_dev *hdev, |
| 513 | struct sk_buff *skb) |
| 514 | { |
| 515 | struct hci_rp_read_num_supported_iac *rp = (void *) skb->data; |
| 516 | |
| 517 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 518 | |
| 519 | if (rp->status) |
| 520 | return; |
| 521 | |
| 522 | hdev->num_iac = rp->num_iac; |
| 523 | |
| 524 | BT_DBG("%s num iac %d", hdev->name, hdev->num_iac); |
| 525 | } |
| 526 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 527 | static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 528 | { |
| 529 | __u8 status = *((__u8 *) skb->data); |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 530 | struct hci_cp_write_ssp_mode *sent; |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 531 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 532 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 533 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 534 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); |
| 535 | if (!sent) |
| 536 | return; |
| 537 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 538 | hci_dev_lock(hdev); |
| 539 | |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 540 | if (!status) { |
| 541 | if (sent->mode) |
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 | else |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 544 | hdev->features[1][0] &= ~LMP_HOST_SSP; |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 545 | } |
| 546 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 547 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 548 | mgmt_ssp_enable_complete(hdev, sent->mode, status); |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 549 | else if (!status) { |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 550 | if (sent->mode) |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 551 | hci_dev_set_flag(hdev, HCI_SSP_ENABLED); |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 552 | else |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 553 | hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 554 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 555 | |
| 556 | hci_dev_unlock(hdev); |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 557 | } |
| 558 | |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 559 | static void hci_cc_write_sc_support(struct hci_dev *hdev, struct sk_buff *skb) |
| 560 | { |
| 561 | u8 status = *((u8 *) skb->data); |
| 562 | struct hci_cp_write_sc_support *sent; |
| 563 | |
| 564 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 565 | |
| 566 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SC_SUPPORT); |
| 567 | if (!sent) |
| 568 | return; |
| 569 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 570 | hci_dev_lock(hdev); |
| 571 | |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 572 | if (!status) { |
| 573 | if (sent->support) |
| 574 | hdev->features[1][0] |= LMP_HOST_SC; |
| 575 | else |
| 576 | hdev->features[1][0] &= ~LMP_HOST_SC; |
| 577 | } |
| 578 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 579 | if (!hci_dev_test_flag(hdev, HCI_MGMT) && !status) { |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 580 | if (sent->support) |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 581 | hci_dev_set_flag(hdev, HCI_SC_ENABLED); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 582 | else |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 583 | hci_dev_clear_flag(hdev, HCI_SC_ENABLED); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 584 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 585 | |
| 586 | hci_dev_unlock(hdev); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 587 | } |
| 588 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 589 | static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) |
| 590 | { |
| 591 | struct hci_rp_read_local_version *rp = (void *) skb->data; |
| 592 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 593 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 594 | |
| 595 | if (rp->status) |
Johan Hedberg | 42c6b12 | 2013-03-05 20:37:49 +0200 | [diff] [blame] | 596 | return; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 597 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 598 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 599 | hci_dev_test_flag(hdev, HCI_CONFIG)) { |
Marcel Holtmann | 0d5551f | 2013-10-18 12:04:50 -0700 | [diff] [blame] | 600 | hdev->hci_ver = rp->hci_ver; |
| 601 | hdev->hci_rev = __le16_to_cpu(rp->hci_rev); |
| 602 | hdev->lmp_ver = rp->lmp_ver; |
| 603 | hdev->manufacturer = __le16_to_cpu(rp->manufacturer); |
| 604 | hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver); |
| 605 | } |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 606 | } |
| 607 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 608 | static void hci_cc_read_local_commands(struct hci_dev *hdev, |
| 609 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 610 | { |
| 611 | struct hci_rp_read_local_commands *rp = (void *) skb->data; |
| 612 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 613 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 614 | |
Marcel Holtmann | 6a070e6 | 2013-10-31 04:54:33 -0700 | [diff] [blame] | 615 | if (rp->status) |
| 616 | return; |
| 617 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 618 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 619 | hci_dev_test_flag(hdev, HCI_CONFIG)) |
Johan Hedberg | 2177bab | 2013-03-05 20:37:43 +0200 | [diff] [blame] | 620 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 621 | } |
| 622 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 623 | static void hci_cc_read_auth_payload_timeout(struct hci_dev *hdev, |
| 624 | struct sk_buff *skb) |
| 625 | { |
| 626 | struct hci_rp_read_auth_payload_to *rp = (void *)skb->data; |
| 627 | struct hci_conn *conn; |
| 628 | |
| 629 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 630 | |
| 631 | if (rp->status) |
| 632 | return; |
| 633 | |
| 634 | hci_dev_lock(hdev); |
| 635 | |
| 636 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 637 | if (conn) |
| 638 | conn->auth_payload_timeout = __le16_to_cpu(rp->timeout); |
| 639 | |
| 640 | hci_dev_unlock(hdev); |
| 641 | } |
| 642 | |
| 643 | static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev, |
| 644 | struct sk_buff *skb) |
| 645 | { |
| 646 | struct hci_rp_write_auth_payload_to *rp = (void *)skb->data; |
| 647 | struct hci_conn *conn; |
| 648 | void *sent; |
| 649 | |
| 650 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 651 | |
| 652 | if (rp->status) |
| 653 | return; |
| 654 | |
| 655 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO); |
| 656 | if (!sent) |
| 657 | return; |
| 658 | |
| 659 | hci_dev_lock(hdev); |
| 660 | |
| 661 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 662 | if (conn) |
| 663 | conn->auth_payload_timeout = get_unaligned_le16(sent + 2); |
| 664 | |
| 665 | hci_dev_unlock(hdev); |
| 666 | } |
| 667 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 668 | static void hci_cc_read_local_features(struct hci_dev *hdev, |
| 669 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 670 | { |
| 671 | struct hci_rp_read_local_features *rp = (void *) skb->data; |
| 672 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 673 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 674 | |
| 675 | if (rp->status) |
| 676 | return; |
| 677 | |
| 678 | memcpy(hdev->features, rp->features, 8); |
| 679 | |
| 680 | /* Adjust default settings according to features |
| 681 | * supported by device. */ |
| 682 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 683 | if (hdev->features[0][0] & LMP_3SLOT) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 684 | hdev->pkt_type |= (HCI_DM3 | HCI_DH3); |
| 685 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 686 | if (hdev->features[0][0] & LMP_5SLOT) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 687 | hdev->pkt_type |= (HCI_DM5 | HCI_DH5); |
| 688 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 689 | if (hdev->features[0][1] & LMP_HV2) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 690 | hdev->pkt_type |= (HCI_HV2); |
| 691 | hdev->esco_type |= (ESCO_HV2); |
| 692 | } |
| 693 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 694 | if (hdev->features[0][1] & LMP_HV3) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 695 | hdev->pkt_type |= (HCI_HV3); |
| 696 | hdev->esco_type |= (ESCO_HV3); |
| 697 | } |
| 698 | |
Andre Guedes | 45db810f | 2012-07-24 15:03:49 -0300 | [diff] [blame] | 699 | if (lmp_esco_capable(hdev)) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 700 | hdev->esco_type |= (ESCO_EV3); |
| 701 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 702 | if (hdev->features[0][4] & LMP_EV4) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 703 | hdev->esco_type |= (ESCO_EV4); |
| 704 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 705 | if (hdev->features[0][4] & LMP_EV5) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 706 | hdev->esco_type |= (ESCO_EV5); |
| 707 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 708 | if (hdev->features[0][5] & LMP_EDR_ESCO_2M) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 709 | hdev->esco_type |= (ESCO_2EV3); |
| 710 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 711 | if (hdev->features[0][5] & LMP_EDR_ESCO_3M) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 712 | hdev->esco_type |= (ESCO_3EV3); |
| 713 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 714 | if (hdev->features[0][5] & LMP_EDR_3S_ESCO) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 715 | hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 716 | } |
| 717 | |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 718 | static void hci_cc_read_local_ext_features(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 719 | struct sk_buff *skb) |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 720 | { |
| 721 | struct hci_rp_read_local_ext_features *rp = (void *) skb->data; |
| 722 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 723 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 724 | |
| 725 | if (rp->status) |
Johan Hedberg | 42c6b12 | 2013-03-05 20:37:49 +0200 | [diff] [blame] | 726 | return; |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 727 | |
Marcel Holtmann | 57af75a | 2013-10-18 12:04:47 -0700 | [diff] [blame] | 728 | if (hdev->max_page < rp->max_page) |
| 729 | hdev->max_page = rp->max_page; |
Johan Hedberg | d2c5d77 | 2013-04-17 15:00:52 +0300 | [diff] [blame] | 730 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 731 | if (rp->page < HCI_MAX_PAGES) |
| 732 | memcpy(hdev->features[rp->page], rp->features, 8); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 733 | } |
| 734 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 735 | static void hci_cc_read_flow_control_mode(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 736 | struct sk_buff *skb) |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 737 | { |
| 738 | struct hci_rp_read_flow_control_mode *rp = (void *) skb->data; |
| 739 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 740 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 741 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 742 | if (rp->status) |
| 743 | return; |
| 744 | |
| 745 | hdev->flow_ctl_mode = rp->mode; |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 746 | } |
| 747 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 748 | static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) |
| 749 | { |
| 750 | struct hci_rp_read_buffer_size *rp = (void *) skb->data; |
| 751 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 752 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 753 | |
| 754 | if (rp->status) |
| 755 | return; |
| 756 | |
| 757 | hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu); |
| 758 | hdev->sco_mtu = rp->sco_mtu; |
| 759 | hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt); |
| 760 | hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt); |
| 761 | |
| 762 | if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) { |
| 763 | hdev->sco_mtu = 64; |
| 764 | hdev->sco_pkts = 8; |
| 765 | } |
| 766 | |
| 767 | hdev->acl_cnt = hdev->acl_pkts; |
| 768 | hdev->sco_cnt = hdev->sco_pkts; |
| 769 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 770 | BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu, |
| 771 | hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb) |
| 775 | { |
| 776 | struct hci_rp_read_bd_addr *rp = (void *) skb->data; |
| 777 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 778 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 779 | |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 780 | if (rp->status) |
| 781 | return; |
| 782 | |
| 783 | if (test_bit(HCI_INIT, &hdev->flags)) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 784 | bacpy(&hdev->bdaddr, &rp->bdaddr); |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 785 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 786 | if (hci_dev_test_flag(hdev, HCI_SETUP)) |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 787 | bacpy(&hdev->setup_addr, &rp->bdaddr); |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 788 | } |
| 789 | |
Marcel Holtmann | a479036 | 2020-04-03 21:44:04 +0200 | [diff] [blame] | 790 | static void hci_cc_read_local_pairing_opts(struct hci_dev *hdev, |
| 791 | struct sk_buff *skb) |
| 792 | { |
| 793 | struct hci_rp_read_local_pairing_opts *rp = (void *) skb->data; |
| 794 | |
| 795 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 796 | |
| 797 | if (rp->status) |
| 798 | return; |
| 799 | |
| 800 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 801 | hci_dev_test_flag(hdev, HCI_CONFIG)) { |
| 802 | hdev->pairing_opts = rp->pairing_opts; |
| 803 | hdev->max_enc_key_size = rp->max_key_size; |
| 804 | } |
| 805 | } |
| 806 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 807 | static void hci_cc_read_page_scan_activity(struct hci_dev *hdev, |
| 808 | struct sk_buff *skb) |
| 809 | { |
| 810 | struct hci_rp_read_page_scan_activity *rp = (void *) skb->data; |
| 811 | |
| 812 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 813 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 814 | if (rp->status) |
| 815 | return; |
| 816 | |
| 817 | if (test_bit(HCI_INIT, &hdev->flags)) { |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 818 | hdev->page_scan_interval = __le16_to_cpu(rp->interval); |
| 819 | hdev->page_scan_window = __le16_to_cpu(rp->window); |
| 820 | } |
| 821 | } |
| 822 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 823 | static void hci_cc_write_page_scan_activity(struct hci_dev *hdev, |
| 824 | struct sk_buff *skb) |
| 825 | { |
| 826 | u8 status = *((u8 *) skb->data); |
| 827 | struct hci_cp_write_page_scan_activity *sent; |
| 828 | |
| 829 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 830 | |
| 831 | if (status) |
| 832 | return; |
| 833 | |
| 834 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY); |
| 835 | if (!sent) |
| 836 | return; |
| 837 | |
| 838 | hdev->page_scan_interval = __le16_to_cpu(sent->interval); |
| 839 | hdev->page_scan_window = __le16_to_cpu(sent->window); |
| 840 | } |
| 841 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 842 | static void hci_cc_read_page_scan_type(struct hci_dev *hdev, |
| 843 | struct sk_buff *skb) |
| 844 | { |
| 845 | struct hci_rp_read_page_scan_type *rp = (void *) skb->data; |
| 846 | |
| 847 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 848 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 849 | if (rp->status) |
| 850 | return; |
| 851 | |
| 852 | if (test_bit(HCI_INIT, &hdev->flags)) |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 853 | hdev->page_scan_type = rp->type; |
| 854 | } |
| 855 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 856 | static void hci_cc_write_page_scan_type(struct hci_dev *hdev, |
| 857 | struct sk_buff *skb) |
| 858 | { |
| 859 | u8 status = *((u8 *) skb->data); |
| 860 | u8 *type; |
| 861 | |
| 862 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 863 | |
| 864 | if (status) |
| 865 | return; |
| 866 | |
| 867 | type = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE); |
| 868 | if (type) |
| 869 | hdev->page_scan_type = *type; |
| 870 | } |
| 871 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 872 | static void hci_cc_read_data_block_size(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 873 | struct sk_buff *skb) |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 874 | { |
| 875 | struct hci_rp_read_data_block_size *rp = (void *) skb->data; |
| 876 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 877 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 878 | |
| 879 | if (rp->status) |
| 880 | return; |
| 881 | |
| 882 | hdev->block_mtu = __le16_to_cpu(rp->max_acl_len); |
| 883 | hdev->block_len = __le16_to_cpu(rp->block_len); |
| 884 | hdev->num_blocks = __le16_to_cpu(rp->num_blocks); |
| 885 | |
| 886 | hdev->block_cnt = hdev->num_blocks; |
| 887 | |
| 888 | 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] | 889 | hdev->block_cnt, hdev->block_len); |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 890 | } |
| 891 | |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 892 | static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb) |
| 893 | { |
| 894 | struct hci_rp_read_clock *rp = (void *) skb->data; |
| 895 | struct hci_cp_read_clock *cp; |
| 896 | struct hci_conn *conn; |
| 897 | |
| 898 | BT_DBG("%s", hdev->name); |
| 899 | |
| 900 | if (skb->len < sizeof(*rp)) |
| 901 | return; |
| 902 | |
| 903 | if (rp->status) |
| 904 | return; |
| 905 | |
| 906 | hci_dev_lock(hdev); |
| 907 | |
| 908 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK); |
| 909 | if (!cp) |
| 910 | goto unlock; |
| 911 | |
| 912 | if (cp->which == 0x00) { |
| 913 | hdev->clock = le32_to_cpu(rp->clock); |
| 914 | goto unlock; |
| 915 | } |
| 916 | |
| 917 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 918 | if (conn) { |
| 919 | conn->clock = le32_to_cpu(rp->clock); |
| 920 | conn->clock_accuracy = le16_to_cpu(rp->accuracy); |
| 921 | } |
| 922 | |
| 923 | unlock: |
| 924 | hci_dev_unlock(hdev); |
| 925 | } |
| 926 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 927 | static void hci_cc_read_local_amp_info(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 928 | struct sk_buff *skb) |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 929 | { |
| 930 | struct hci_rp_read_local_amp_info *rp = (void *) skb->data; |
| 931 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 932 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 933 | |
| 934 | if (rp->status) |
Arron Wang | 8392788 | 2015-07-24 17:10:16 +0800 | [diff] [blame] | 935 | return; |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 936 | |
| 937 | hdev->amp_status = rp->amp_status; |
| 938 | hdev->amp_total_bw = __le32_to_cpu(rp->total_bw); |
| 939 | hdev->amp_max_bw = __le32_to_cpu(rp->max_bw); |
| 940 | hdev->amp_min_latency = __le32_to_cpu(rp->min_latency); |
| 941 | hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu); |
| 942 | hdev->amp_type = rp->amp_type; |
| 943 | hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap); |
| 944 | hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size); |
| 945 | hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to); |
| 946 | hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to); |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 947 | } |
| 948 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 949 | 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] | 950 | struct sk_buff *skb) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 951 | { |
Marcel Holtmann | 91c4e9b | 2012-03-11 19:27:21 -0700 | [diff] [blame] | 952 | struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 953 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 954 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 955 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 956 | if (rp->status) |
| 957 | return; |
| 958 | |
| 959 | hdev->inq_tx_power = rp->tx_power; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 960 | } |
| 961 | |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 962 | static void hci_cc_read_def_err_data_reporting(struct hci_dev *hdev, |
| 963 | struct sk_buff *skb) |
| 964 | { |
| 965 | struct hci_rp_read_def_err_data_reporting *rp = (void *)skb->data; |
| 966 | |
| 967 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 968 | |
| 969 | if (rp->status) |
| 970 | return; |
| 971 | |
| 972 | hdev->err_data_reporting = rp->err_data_reporting; |
| 973 | } |
| 974 | |
| 975 | static void hci_cc_write_def_err_data_reporting(struct hci_dev *hdev, |
| 976 | struct sk_buff *skb) |
| 977 | { |
| 978 | __u8 status = *((__u8 *)skb->data); |
| 979 | struct hci_cp_write_def_err_data_reporting *cp; |
| 980 | |
| 981 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 982 | |
| 983 | if (status) |
| 984 | return; |
| 985 | |
| 986 | cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING); |
| 987 | if (!cp) |
| 988 | return; |
| 989 | |
| 990 | hdev->err_data_reporting = cp->err_data_reporting; |
| 991 | } |
| 992 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 993 | static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 994 | { |
| 995 | struct hci_rp_pin_code_reply *rp = (void *) skb->data; |
| 996 | struct hci_cp_pin_code_reply *cp; |
| 997 | struct hci_conn *conn; |
| 998 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 999 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1000 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1001 | hci_dev_lock(hdev); |
| 1002 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1003 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1004 | mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1005 | |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 1006 | if (rp->status) |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1007 | goto unlock; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1008 | |
| 1009 | cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY); |
| 1010 | if (!cp) |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1011 | goto unlock; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1012 | |
| 1013 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 1014 | if (conn) |
| 1015 | conn->pin_length = cp->pin_len; |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1016 | |
| 1017 | unlock: |
| 1018 | hci_dev_unlock(hdev); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1022 | { |
| 1023 | struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data; |
| 1024 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1025 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1026 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1027 | hci_dev_lock(hdev); |
| 1028 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1029 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1030 | mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1031 | rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1032 | |
| 1033 | hci_dev_unlock(hdev); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1034 | } |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1035 | |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 1036 | static void hci_cc_le_read_buffer_size(struct hci_dev *hdev, |
| 1037 | struct sk_buff *skb) |
| 1038 | { |
| 1039 | struct hci_rp_le_read_buffer_size *rp = (void *) skb->data; |
| 1040 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1041 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 1042 | |
| 1043 | if (rp->status) |
| 1044 | return; |
| 1045 | |
| 1046 | hdev->le_mtu = __le16_to_cpu(rp->le_mtu); |
| 1047 | hdev->le_pkts = rp->le_max_pkt; |
| 1048 | |
| 1049 | hdev->le_cnt = hdev->le_pkts; |
| 1050 | |
| 1051 | 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] | 1052 | } |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1053 | |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 1054 | static void hci_cc_le_read_local_features(struct hci_dev *hdev, |
| 1055 | struct sk_buff *skb) |
| 1056 | { |
| 1057 | struct hci_rp_le_read_local_features *rp = (void *) skb->data; |
| 1058 | |
| 1059 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1060 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1061 | if (rp->status) |
| 1062 | return; |
| 1063 | |
| 1064 | memcpy(hdev->le_features, rp->features, 8); |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 1065 | } |
| 1066 | |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 1067 | static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev, |
| 1068 | struct sk_buff *skb) |
| 1069 | { |
| 1070 | struct hci_rp_le_read_adv_tx_power *rp = (void *) skb->data; |
| 1071 | |
| 1072 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1073 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1074 | if (rp->status) |
| 1075 | return; |
| 1076 | |
| 1077 | hdev->adv_tx_power = rp->tx_power; |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 1078 | } |
| 1079 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1080 | static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1081 | { |
| 1082 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1083 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1084 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1085 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1086 | hci_dev_lock(hdev); |
| 1087 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1088 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1089 | mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0, |
| 1090 | rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1091 | |
| 1092 | hci_dev_unlock(hdev); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1096 | struct sk_buff *skb) |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1097 | { |
| 1098 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1099 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1100 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1101 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1102 | hci_dev_lock(hdev); |
| 1103 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1104 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1105 | mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1106 | ACL_LINK, 0, rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1107 | |
| 1108 | hci_dev_unlock(hdev); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1109 | } |
| 1110 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1111 | static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1112 | { |
| 1113 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1114 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1115 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1116 | |
| 1117 | hci_dev_lock(hdev); |
| 1118 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1119 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1120 | mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1121 | 0, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1122 | |
| 1123 | hci_dev_unlock(hdev); |
| 1124 | } |
| 1125 | |
| 1126 | static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1127 | struct sk_buff *skb) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1128 | { |
| 1129 | struct hci_rp_user_confirm_reply *rp = (void *) skb->data; |
| 1130 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1131 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1132 | |
| 1133 | hci_dev_lock(hdev); |
| 1134 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1135 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1136 | mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1137 | ACL_LINK, 0, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1138 | |
| 1139 | hci_dev_unlock(hdev); |
| 1140 | } |
| 1141 | |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 1142 | static void hci_cc_read_local_oob_data(struct hci_dev *hdev, |
| 1143 | struct sk_buff *skb) |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1144 | { |
| 1145 | struct hci_rp_read_local_oob_data *rp = (void *) skb->data; |
| 1146 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1147 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev, |
| 1151 | struct sk_buff *skb) |
| 1152 | { |
| 1153 | struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data; |
| 1154 | |
| 1155 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1156 | } |
| 1157 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1158 | static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb) |
| 1159 | { |
| 1160 | __u8 status = *((__u8 *) skb->data); |
| 1161 | bdaddr_t *sent; |
| 1162 | |
| 1163 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1164 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1165 | if (status) |
| 1166 | return; |
| 1167 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1168 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR); |
| 1169 | if (!sent) |
| 1170 | return; |
| 1171 | |
| 1172 | hci_dev_lock(hdev); |
| 1173 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1174 | bacpy(&hdev->random_addr, sent); |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1175 | |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 1176 | if (!bacmp(&hdev->rpa, sent)) { |
| 1177 | hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); |
| 1178 | queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, |
| 1179 | secs_to_jiffies(hdev->rpa_timeout)); |
| 1180 | } |
| 1181 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1182 | hci_dev_unlock(hdev); |
| 1183 | } |
| 1184 | |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 1185 | static void hci_cc_le_set_default_phy(struct hci_dev *hdev, struct sk_buff *skb) |
| 1186 | { |
| 1187 | __u8 status = *((__u8 *) skb->data); |
| 1188 | struct hci_cp_le_set_default_phy *cp; |
| 1189 | |
| 1190 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1191 | |
| 1192 | if (status) |
| 1193 | return; |
| 1194 | |
| 1195 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_DEFAULT_PHY); |
| 1196 | if (!cp) |
| 1197 | return; |
| 1198 | |
| 1199 | hci_dev_lock(hdev); |
| 1200 | |
| 1201 | hdev->le_tx_def_phys = cp->tx_phys; |
| 1202 | hdev->le_rx_def_phys = cp->rx_phys; |
| 1203 | |
| 1204 | hci_dev_unlock(hdev); |
| 1205 | } |
| 1206 | |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1207 | static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, |
| 1208 | struct sk_buff *skb) |
| 1209 | { |
| 1210 | __u8 status = *((__u8 *) skb->data); |
| 1211 | struct hci_cp_le_set_adv_set_rand_addr *cp; |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 1212 | struct adv_info *adv; |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1213 | |
| 1214 | if (status) |
| 1215 | return; |
| 1216 | |
| 1217 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR); |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 1218 | /* Update only in case the adv instance since handle 0x00 shall be using |
| 1219 | * HCI_OP_LE_SET_RANDOM_ADDR since that allows both extended and |
| 1220 | * non-extended adverting. |
| 1221 | */ |
| 1222 | if (!cp || !cp->handle) |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1223 | return; |
| 1224 | |
| 1225 | hci_dev_lock(hdev); |
| 1226 | |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 1227 | adv = hci_find_adv_instance(hdev, cp->handle); |
| 1228 | if (adv) { |
| 1229 | bacpy(&adv->random_addr, &cp->bdaddr); |
| 1230 | if (!bacmp(&hdev->rpa, &cp->bdaddr)) { |
| 1231 | adv->rpa_expired = false; |
| 1232 | queue_delayed_work(hdev->workqueue, |
| 1233 | &adv->rpa_expired_cb, |
| 1234 | secs_to_jiffies(hdev->rpa_timeout)); |
| 1235 | } |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | hci_dev_unlock(hdev); |
| 1239 | } |
| 1240 | |
Daniel Winkler | 7c395ea | 2020-12-03 12:12:51 -0800 | [diff] [blame] | 1241 | static void hci_cc_le_read_transmit_power(struct hci_dev *hdev, |
| 1242 | struct sk_buff *skb) |
| 1243 | { |
| 1244 | struct hci_rp_le_read_transmit_power *rp = (void *)skb->data; |
| 1245 | |
| 1246 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1247 | |
| 1248 | if (rp->status) |
| 1249 | return; |
| 1250 | |
| 1251 | hdev->min_le_tx_power = rp->min_le_tx_power; |
| 1252 | hdev->max_le_tx_power = rp->max_le_tx_power; |
| 1253 | } |
| 1254 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1255 | static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 1256 | { |
| 1257 | __u8 *sent, status = *((__u8 *) skb->data); |
| 1258 | |
| 1259 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1260 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1261 | if (status) |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1262 | return; |
| 1263 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1264 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE); |
| 1265 | if (!sent) |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1266 | return; |
| 1267 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1268 | hci_dev_lock(hdev); |
| 1269 | |
Stephen Hemminger | 49c922b | 2014-10-27 21:12:20 -0700 | [diff] [blame] | 1270 | /* If we're doing connection initiation as peripheral. Set a |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1271 | * timeout in case something goes wrong. |
| 1272 | */ |
| 1273 | if (*sent) { |
| 1274 | struct hci_conn *conn; |
| 1275 | |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 1276 | hci_dev_set_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | 66c417c | 2014-07-08 15:07:47 +0300 | [diff] [blame] | 1277 | |
Jakub Pawlowski | e7d9ab7 | 2015-08-07 20:22:52 +0200 | [diff] [blame] | 1278 | conn = hci_lookup_le_connect(hdev); |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1279 | if (conn) |
| 1280 | queue_delayed_work(hdev->workqueue, |
| 1281 | &conn->le_conn_timeout, |
Johan Hedberg | 09ae260 | 2014-07-06 13:41:15 +0300 | [diff] [blame] | 1282 | conn->conn_timeout); |
Johan Hedberg | 66c417c | 2014-07-08 15:07:47 +0300 | [diff] [blame] | 1283 | } else { |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 1284 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1285 | } |
| 1286 | |
Johan Hedberg | 04b4edc | 2013-03-15 17:07:01 -0500 | [diff] [blame] | 1287 | hci_dev_unlock(hdev); |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1288 | } |
| 1289 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1290 | static void hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, |
| 1291 | struct sk_buff *skb) |
| 1292 | { |
| 1293 | struct hci_cp_le_set_ext_adv_enable *cp; |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1294 | struct hci_cp_ext_adv_set *set; |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1295 | __u8 status = *((__u8 *) skb->data); |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1296 | struct adv_info *adv = NULL, *n; |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1297 | |
| 1298 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1299 | |
| 1300 | if (status) |
| 1301 | return; |
| 1302 | |
| 1303 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE); |
| 1304 | if (!cp) |
| 1305 | return; |
| 1306 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1307 | set = (void *)cp->data; |
| 1308 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1309 | hci_dev_lock(hdev); |
| 1310 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1311 | if (cp->num_of_sets) |
| 1312 | adv = hci_find_adv_instance(hdev, set->handle); |
| 1313 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1314 | if (cp->enable) { |
| 1315 | struct hci_conn *conn; |
| 1316 | |
| 1317 | hci_dev_set_flag(hdev, HCI_LE_ADV); |
| 1318 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1319 | if (adv) |
| 1320 | adv->enabled = true; |
| 1321 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1322 | conn = hci_lookup_le_connect(hdev); |
| 1323 | if (conn) |
| 1324 | queue_delayed_work(hdev->workqueue, |
| 1325 | &conn->le_conn_timeout, |
| 1326 | conn->conn_timeout); |
Jaganath Kanakkassery | 45b7749 | 2018-07-19 17:09:43 +0530 | [diff] [blame] | 1327 | } else { |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1328 | if (adv) { |
| 1329 | adv->enabled = false; |
| 1330 | /* If just one instance was disabled check if there are |
| 1331 | * any other instance enabled before clearing HCI_LE_ADV |
| 1332 | */ |
| 1333 | list_for_each_entry_safe(adv, n, &hdev->adv_instances, |
| 1334 | list) { |
| 1335 | if (adv->enabled) |
| 1336 | goto unlock; |
| 1337 | } |
| 1338 | } else { |
| 1339 | /* All instances shall be considered disabled */ |
| 1340 | list_for_each_entry_safe(adv, n, &hdev->adv_instances, |
| 1341 | list) |
| 1342 | adv->enabled = false; |
| 1343 | } |
| 1344 | |
Jaganath Kanakkassery | 45b7749 | 2018-07-19 17:09:43 +0530 | [diff] [blame] | 1345 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1346 | } |
| 1347 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1348 | unlock: |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1349 | hci_dev_unlock(hdev); |
| 1350 | } |
| 1351 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1352 | static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 1353 | { |
| 1354 | struct hci_cp_le_set_scan_param *cp; |
| 1355 | __u8 status = *((__u8 *) skb->data); |
| 1356 | |
| 1357 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1358 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1359 | if (status) |
| 1360 | return; |
| 1361 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1362 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM); |
| 1363 | if (!cp) |
| 1364 | return; |
| 1365 | |
| 1366 | hci_dev_lock(hdev); |
| 1367 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1368 | hdev->le_scan_type = cp->type; |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1369 | |
| 1370 | hci_dev_unlock(hdev); |
| 1371 | } |
| 1372 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1373 | static void hci_cc_le_set_ext_scan_param(struct hci_dev *hdev, |
| 1374 | struct sk_buff *skb) |
| 1375 | { |
| 1376 | struct hci_cp_le_set_ext_scan_params *cp; |
| 1377 | __u8 status = *((__u8 *) skb->data); |
| 1378 | struct hci_cp_le_scan_phy_params *phy_param; |
| 1379 | |
| 1380 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1381 | |
| 1382 | if (status) |
| 1383 | return; |
| 1384 | |
| 1385 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS); |
| 1386 | if (!cp) |
| 1387 | return; |
| 1388 | |
| 1389 | phy_param = (void *)cp->data; |
| 1390 | |
| 1391 | hci_dev_lock(hdev); |
| 1392 | |
| 1393 | hdev->le_scan_type = phy_param->type; |
| 1394 | |
| 1395 | hci_dev_unlock(hdev); |
| 1396 | } |
| 1397 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1398 | static bool has_pending_adv_report(struct hci_dev *hdev) |
| 1399 | { |
| 1400 | struct discovery_state *d = &hdev->discovery; |
| 1401 | |
| 1402 | return bacmp(&d->last_adv_addr, BDADDR_ANY); |
| 1403 | } |
| 1404 | |
| 1405 | static void clear_pending_adv_report(struct hci_dev *hdev) |
| 1406 | { |
| 1407 | struct discovery_state *d = &hdev->discovery; |
| 1408 | |
| 1409 | bacpy(&d->last_adv_addr, BDADDR_ANY); |
| 1410 | d->last_adv_data_len = 0; |
| 1411 | } |
| 1412 | |
| 1413 | 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] | 1414 | u8 bdaddr_type, s8 rssi, u32 flags, |
| 1415 | u8 *data, u8 len) |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1416 | { |
| 1417 | struct discovery_state *d = &hdev->discovery; |
| 1418 | |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 1419 | if (len > HCI_MAX_AD_LENGTH) |
| 1420 | return; |
| 1421 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1422 | bacpy(&d->last_adv_addr, bdaddr); |
| 1423 | d->last_adv_addr_type = bdaddr_type; |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 1424 | d->last_adv_rssi = rssi; |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 1425 | d->last_adv_flags = flags; |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1426 | memcpy(d->last_adv_data, data, len); |
| 1427 | d->last_adv_data_len = len; |
| 1428 | } |
| 1429 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1430 | 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] | 1431 | { |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1432 | hci_dev_lock(hdev); |
| 1433 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1434 | switch (enable) { |
Andre Guedes | 76a388be | 2013-04-04 20:21:02 -0300 | [diff] [blame] | 1435 | case LE_SCAN_ENABLE: |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 1436 | hci_dev_set_flag(hdev, HCI_LE_SCAN); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1437 | if (hdev->le_scan_type == LE_SCAN_ACTIVE) |
| 1438 | clear_pending_adv_report(hdev); |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1439 | break; |
| 1440 | |
Andre Guedes | 76a388be | 2013-04-04 20:21:02 -0300 | [diff] [blame] | 1441 | case LE_SCAN_DISABLE: |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1442 | /* We do this here instead of when setting DISCOVERY_STOPPED |
| 1443 | * since the latter would potentially require waiting for |
| 1444 | * inquiry to stop too. |
| 1445 | */ |
| 1446 | if (has_pending_adv_report(hdev)) { |
| 1447 | struct discovery_state *d = &hdev->discovery; |
| 1448 | |
| 1449 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Johan Hedberg | ab0aa43 | 2014-03-26 14:17:12 +0200 | [diff] [blame] | 1450 | d->last_adv_addr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 1451 | d->last_adv_rssi, d->last_adv_flags, |
Johan Hedberg | ab0aa43 | 2014-03-26 14:17:12 +0200 | [diff] [blame] | 1452 | d->last_adv_data, |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1453 | d->last_adv_data_len, NULL, 0); |
| 1454 | } |
| 1455 | |
Johan Hedberg | 317ac8c | 2014-02-28 20:26:12 +0200 | [diff] [blame] | 1456 | /* Cancel this timer so that we don't try to disable scanning |
| 1457 | * when it's already disabled. |
| 1458 | */ |
| 1459 | cancel_delayed_work(&hdev->le_scan_disable); |
| 1460 | |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 1461 | hci_dev_clear_flag(hdev, HCI_LE_SCAN); |
Johan Hedberg | e8bb6b9 | 2014-07-08 15:07:53 +0300 | [diff] [blame] | 1462 | |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1463 | /* The HCI_LE_SCAN_INTERRUPTED flag indicates that we |
| 1464 | * interrupted scanning due to a connect request. Mark |
Johan Hedberg | e8bb6b9 | 2014-07-08 15:07:53 +0300 | [diff] [blame] | 1465 | * therefore discovery as stopped. If this was not |
| 1466 | * because of a connect request advertising might have |
| 1467 | * been disabled because of active scanning, so |
| 1468 | * re-enable it again if necessary. |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1469 | */ |
Marcel Holtmann | a69d892 | 2015-03-13 02:11:05 -0700 | [diff] [blame] | 1470 | if (hci_dev_test_and_clear_flag(hdev, HCI_LE_SCAN_INTERRUPTED)) |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1471 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1472 | else if (!hci_dev_test_flag(hdev, HCI_LE_ADV) && |
Johan Hedberg | 3472227 | 2014-07-08 16:05:05 +0300 | [diff] [blame] | 1473 | hdev->discovery.state == DISCOVERY_FINDING) |
Johan Hedberg | f225257 | 2015-11-18 12:49:20 +0200 | [diff] [blame] | 1474 | hci_req_reenable_advertising(hdev); |
Johan Hedberg | e8bb6b9 | 2014-07-08 15:07:53 +0300 | [diff] [blame] | 1475 | |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1476 | break; |
| 1477 | |
| 1478 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1479 | bt_dev_err(hdev, "use of reserved LE_Scan_Enable param %d", |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1480 | enable); |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1481 | break; |
Andre Guedes | 3581508 | 2011-05-26 16:23:53 -0300 | [diff] [blame] | 1482 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1483 | |
| 1484 | hci_dev_unlock(hdev); |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1485 | } |
| 1486 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1487 | static void hci_cc_le_set_scan_enable(struct hci_dev *hdev, |
| 1488 | struct sk_buff *skb) |
| 1489 | { |
| 1490 | struct hci_cp_le_set_scan_enable *cp; |
| 1491 | __u8 status = *((__u8 *) skb->data); |
| 1492 | |
| 1493 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1494 | |
| 1495 | if (status) |
| 1496 | return; |
| 1497 | |
| 1498 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE); |
| 1499 | if (!cp) |
| 1500 | return; |
| 1501 | |
| 1502 | le_set_scan_enable_complete(hdev, cp->enable); |
| 1503 | } |
| 1504 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1505 | static void hci_cc_le_set_ext_scan_enable(struct hci_dev *hdev, |
| 1506 | struct sk_buff *skb) |
| 1507 | { |
| 1508 | struct hci_cp_le_set_ext_scan_enable *cp; |
| 1509 | __u8 status = *((__u8 *) skb->data); |
| 1510 | |
| 1511 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1512 | |
| 1513 | if (status) |
| 1514 | return; |
| 1515 | |
| 1516 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE); |
| 1517 | if (!cp) |
| 1518 | return; |
| 1519 | |
| 1520 | le_set_scan_enable_complete(hdev, cp->enable); |
| 1521 | } |
| 1522 | |
Jaganath Kanakkassery | 6b49bcb | 2018-07-19 17:09:40 +0530 | [diff] [blame] | 1523 | static void hci_cc_le_read_num_adv_sets(struct hci_dev *hdev, |
| 1524 | struct sk_buff *skb) |
| 1525 | { |
| 1526 | struct hci_rp_le_read_num_supported_adv_sets *rp = (void *) skb->data; |
| 1527 | |
| 1528 | BT_DBG("%s status 0x%2.2x No of Adv sets %u", hdev->name, rp->status, |
| 1529 | rp->num_of_sets); |
| 1530 | |
| 1531 | if (rp->status) |
| 1532 | return; |
| 1533 | |
| 1534 | hdev->le_num_of_adv_sets = rp->num_of_sets; |
| 1535 | } |
| 1536 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1537 | static void hci_cc_le_read_accept_list_size(struct hci_dev *hdev, |
| 1538 | struct sk_buff *skb) |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1539 | { |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1540 | struct hci_rp_le_read_accept_list_size *rp = (void *)skb->data; |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1541 | |
| 1542 | BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size); |
| 1543 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1544 | if (rp->status) |
| 1545 | return; |
| 1546 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1547 | hdev->le_accept_list_size = rp->size; |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1548 | } |
| 1549 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1550 | static void hci_cc_le_clear_accept_list(struct hci_dev *hdev, |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1551 | struct sk_buff *skb) |
| 1552 | { |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1553 | __u8 status = *((__u8 *) skb->data); |
| 1554 | |
| 1555 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1556 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1557 | if (status) |
| 1558 | return; |
| 1559 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1560 | hci_bdaddr_list_clear(&hdev->le_accept_list); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1561 | } |
| 1562 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1563 | static void hci_cc_le_add_to_accept_list(struct hci_dev *hdev, |
| 1564 | struct sk_buff *skb) |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1565 | { |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1566 | struct hci_cp_le_add_to_accept_list *sent; |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1567 | __u8 status = *((__u8 *) skb->data); |
| 1568 | |
| 1569 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1570 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1571 | if (status) |
| 1572 | return; |
| 1573 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1574 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1575 | if (!sent) |
| 1576 | return; |
| 1577 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1578 | hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr, |
| 1579 | sent->bdaddr_type); |
| 1580 | } |
| 1581 | |
| 1582 | static void hci_cc_le_del_from_accept_list(struct hci_dev *hdev, |
| 1583 | struct sk_buff *skb) |
| 1584 | { |
| 1585 | struct hci_cp_le_del_from_accept_list *sent; |
| 1586 | __u8 status = *((__u8 *) skb->data); |
| 1587 | |
| 1588 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1589 | |
| 1590 | if (status) |
| 1591 | return; |
| 1592 | |
| 1593 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST); |
| 1594 | if (!sent) |
| 1595 | return; |
| 1596 | |
| 1597 | hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr, |
Johan Hedberg | dcc36c1 | 2014-07-09 12:59:13 +0300 | [diff] [blame] | 1598 | sent->bdaddr_type); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1599 | } |
| 1600 | |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 1601 | static void hci_cc_le_read_supported_states(struct hci_dev *hdev, |
| 1602 | struct sk_buff *skb) |
| 1603 | { |
| 1604 | struct hci_rp_le_read_supported_states *rp = (void *) skb->data; |
| 1605 | |
| 1606 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1607 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1608 | if (rp->status) |
| 1609 | return; |
| 1610 | |
| 1611 | memcpy(hdev->le_states, rp->le_states, 8); |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 1612 | } |
| 1613 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 1614 | static void hci_cc_le_read_def_data_len(struct hci_dev *hdev, |
| 1615 | struct sk_buff *skb) |
| 1616 | { |
| 1617 | struct hci_rp_le_read_def_data_len *rp = (void *) skb->data; |
| 1618 | |
| 1619 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1620 | |
| 1621 | if (rp->status) |
| 1622 | return; |
| 1623 | |
| 1624 | hdev->le_def_tx_len = le16_to_cpu(rp->tx_len); |
| 1625 | hdev->le_def_tx_time = le16_to_cpu(rp->tx_time); |
| 1626 | } |
| 1627 | |
| 1628 | static void hci_cc_le_write_def_data_len(struct hci_dev *hdev, |
| 1629 | struct sk_buff *skb) |
| 1630 | { |
| 1631 | struct hci_cp_le_write_def_data_len *sent; |
| 1632 | __u8 status = *((__u8 *) skb->data); |
| 1633 | |
| 1634 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1635 | |
| 1636 | if (status) |
| 1637 | return; |
| 1638 | |
| 1639 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN); |
| 1640 | if (!sent) |
| 1641 | return; |
| 1642 | |
| 1643 | hdev->le_def_tx_len = le16_to_cpu(sent->tx_len); |
| 1644 | hdev->le_def_tx_time = le16_to_cpu(sent->tx_time); |
| 1645 | } |
| 1646 | |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 1647 | static void hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, |
| 1648 | struct sk_buff *skb) |
| 1649 | { |
| 1650 | struct hci_cp_le_add_to_resolv_list *sent; |
| 1651 | __u8 status = *((__u8 *) skb->data); |
| 1652 | |
| 1653 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1654 | |
| 1655 | if (status) |
| 1656 | return; |
| 1657 | |
| 1658 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST); |
| 1659 | if (!sent) |
| 1660 | return; |
| 1661 | |
| 1662 | hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr, |
| 1663 | sent->bdaddr_type, sent->peer_irk, |
| 1664 | sent->local_irk); |
| 1665 | } |
| 1666 | |
| 1667 | static void hci_cc_le_del_from_resolv_list(struct hci_dev *hdev, |
| 1668 | struct sk_buff *skb) |
| 1669 | { |
| 1670 | struct hci_cp_le_del_from_resolv_list *sent; |
| 1671 | __u8 status = *((__u8 *) skb->data); |
| 1672 | |
| 1673 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1674 | |
| 1675 | if (status) |
| 1676 | return; |
| 1677 | |
| 1678 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST); |
| 1679 | if (!sent) |
| 1680 | return; |
| 1681 | |
| 1682 | hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr, |
| 1683 | sent->bdaddr_type); |
| 1684 | } |
| 1685 | |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 1686 | static void hci_cc_le_clear_resolv_list(struct hci_dev *hdev, |
| 1687 | struct sk_buff *skb) |
| 1688 | { |
| 1689 | __u8 status = *((__u8 *) skb->data); |
| 1690 | |
| 1691 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1692 | |
| 1693 | if (status) |
| 1694 | return; |
| 1695 | |
| 1696 | hci_bdaddr_list_clear(&hdev->le_resolv_list); |
| 1697 | } |
| 1698 | |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 1699 | static void hci_cc_le_read_resolv_list_size(struct hci_dev *hdev, |
| 1700 | struct sk_buff *skb) |
| 1701 | { |
| 1702 | struct hci_rp_le_read_resolv_list_size *rp = (void *) skb->data; |
| 1703 | |
| 1704 | BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size); |
| 1705 | |
| 1706 | if (rp->status) |
| 1707 | return; |
| 1708 | |
| 1709 | hdev->le_resolv_list_size = rp->size; |
| 1710 | } |
| 1711 | |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 1712 | static void hci_cc_le_set_addr_resolution_enable(struct hci_dev *hdev, |
| 1713 | struct sk_buff *skb) |
| 1714 | { |
| 1715 | __u8 *sent, status = *((__u8 *) skb->data); |
| 1716 | |
| 1717 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1718 | |
| 1719 | if (status) |
| 1720 | return; |
| 1721 | |
| 1722 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE); |
| 1723 | if (!sent) |
| 1724 | return; |
| 1725 | |
| 1726 | hci_dev_lock(hdev); |
| 1727 | |
| 1728 | if (*sent) |
| 1729 | hci_dev_set_flag(hdev, HCI_LL_RPA_RESOLUTION); |
| 1730 | else |
| 1731 | hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION); |
| 1732 | |
| 1733 | hci_dev_unlock(hdev); |
| 1734 | } |
| 1735 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 1736 | static void hci_cc_le_read_max_data_len(struct hci_dev *hdev, |
| 1737 | struct sk_buff *skb) |
| 1738 | { |
| 1739 | struct hci_rp_le_read_max_data_len *rp = (void *) skb->data; |
| 1740 | |
| 1741 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1742 | |
| 1743 | if (rp->status) |
| 1744 | return; |
| 1745 | |
| 1746 | hdev->le_max_tx_len = le16_to_cpu(rp->tx_len); |
| 1747 | hdev->le_max_tx_time = le16_to_cpu(rp->tx_time); |
| 1748 | hdev->le_max_rx_len = le16_to_cpu(rp->rx_len); |
| 1749 | hdev->le_max_rx_time = le16_to_cpu(rp->rx_time); |
| 1750 | } |
| 1751 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1752 | static void hci_cc_write_le_host_supported(struct hci_dev *hdev, |
| 1753 | struct sk_buff *skb) |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1754 | { |
Johan Hedberg | 06199cf | 2012-02-22 16:37:11 +0200 | [diff] [blame] | 1755 | struct hci_cp_write_le_host_supported *sent; |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1756 | __u8 status = *((__u8 *) skb->data); |
| 1757 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1758 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1759 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1760 | if (status) |
| 1761 | return; |
| 1762 | |
Johan Hedberg | 06199cf | 2012-02-22 16:37:11 +0200 | [diff] [blame] | 1763 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED); |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 1764 | if (!sent) |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1765 | return; |
| 1766 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1767 | hci_dev_lock(hdev); |
| 1768 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1769 | if (sent->le) { |
| 1770 | hdev->features[1][0] |= LMP_HOST_LE; |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 1771 | hci_dev_set_flag(hdev, HCI_LE_ENABLED); |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1772 | } else { |
| 1773 | hdev->features[1][0] &= ~LMP_HOST_LE; |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 1774 | hci_dev_clear_flag(hdev, HCI_LE_ENABLED); |
| 1775 | hci_dev_clear_flag(hdev, HCI_ADVERTISING); |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 1776 | } |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1777 | |
| 1778 | if (sent->simul) |
| 1779 | hdev->features[1][0] |= LMP_HOST_LE_BREDR; |
| 1780 | else |
| 1781 | hdev->features[1][0] &= ~LMP_HOST_LE_BREDR; |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1782 | |
| 1783 | hci_dev_unlock(hdev); |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 1784 | } |
| 1785 | |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 1786 | static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 1787 | { |
| 1788 | struct hci_cp_le_set_adv_param *cp; |
| 1789 | u8 status = *((u8 *) skb->data); |
| 1790 | |
| 1791 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1792 | |
| 1793 | if (status) |
| 1794 | return; |
| 1795 | |
| 1796 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM); |
| 1797 | if (!cp) |
| 1798 | return; |
| 1799 | |
| 1800 | hci_dev_lock(hdev); |
| 1801 | hdev->adv_addr_type = cp->own_address_type; |
| 1802 | hci_dev_unlock(hdev); |
| 1803 | } |
| 1804 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1805 | static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 1806 | { |
| 1807 | struct hci_rp_le_set_ext_adv_params *rp = (void *) skb->data; |
| 1808 | struct hci_cp_le_set_ext_adv_params *cp; |
| 1809 | struct adv_info *adv_instance; |
| 1810 | |
| 1811 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1812 | |
| 1813 | if (rp->status) |
| 1814 | return; |
| 1815 | |
| 1816 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS); |
| 1817 | if (!cp) |
| 1818 | return; |
| 1819 | |
| 1820 | hci_dev_lock(hdev); |
| 1821 | hdev->adv_addr_type = cp->own_addr_type; |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 1822 | if (!cp->handle) { |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1823 | /* Store in hdev for instance 0 */ |
| 1824 | hdev->adv_tx_power = rp->tx_power; |
| 1825 | } else { |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 1826 | adv_instance = hci_find_adv_instance(hdev, cp->handle); |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1827 | if (adv_instance) |
| 1828 | adv_instance->tx_power = rp->tx_power; |
| 1829 | } |
Jaganath Kanakkassery | a0fb372 | 2018-07-19 17:09:42 +0530 | [diff] [blame] | 1830 | /* Update adv data as tx power is known now */ |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 1831 | hci_req_update_adv_data(hdev, cp->handle); |
Daniel Winkler | 1241057 | 2020-12-03 12:12:49 -0800 | [diff] [blame] | 1832 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1833 | hci_dev_unlock(hdev); |
| 1834 | } |
| 1835 | |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 1836 | static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb) |
| 1837 | { |
| 1838 | struct hci_rp_read_rssi *rp = (void *) skb->data; |
| 1839 | struct hci_conn *conn; |
| 1840 | |
| 1841 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1842 | |
| 1843 | if (rp->status) |
| 1844 | return; |
| 1845 | |
| 1846 | hci_dev_lock(hdev); |
| 1847 | |
| 1848 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 1849 | if (conn) |
| 1850 | conn->rssi = rp->rssi; |
| 1851 | |
| 1852 | hci_dev_unlock(hdev); |
| 1853 | } |
| 1854 | |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 1855 | static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb) |
| 1856 | { |
| 1857 | struct hci_cp_read_tx_power *sent; |
| 1858 | struct hci_rp_read_tx_power *rp = (void *) skb->data; |
| 1859 | struct hci_conn *conn; |
| 1860 | |
| 1861 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1862 | |
| 1863 | if (rp->status) |
| 1864 | return; |
| 1865 | |
| 1866 | sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); |
| 1867 | if (!sent) |
| 1868 | return; |
| 1869 | |
| 1870 | hci_dev_lock(hdev); |
| 1871 | |
| 1872 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Andrzej Kaczmarek | d0455ed | 2014-05-14 13:43:05 +0200 | [diff] [blame] | 1873 | if (!conn) |
| 1874 | goto unlock; |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 1875 | |
Andrzej Kaczmarek | d0455ed | 2014-05-14 13:43:05 +0200 | [diff] [blame] | 1876 | switch (sent->type) { |
| 1877 | case 0x00: |
| 1878 | conn->tx_power = rp->tx_power; |
| 1879 | break; |
| 1880 | case 0x01: |
| 1881 | conn->max_tx_power = rp->tx_power; |
| 1882 | break; |
| 1883 | } |
| 1884 | |
| 1885 | unlock: |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 1886 | hci_dev_unlock(hdev); |
| 1887 | } |
| 1888 | |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 1889 | static void hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 1890 | { |
| 1891 | u8 status = *((u8 *) skb->data); |
| 1892 | u8 *mode; |
| 1893 | |
| 1894 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 1895 | |
| 1896 | if (status) |
| 1897 | return; |
| 1898 | |
| 1899 | mode = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE); |
| 1900 | if (mode) |
| 1901 | hdev->ssp_debug_mode = *mode; |
| 1902 | } |
| 1903 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1904 | static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1905 | { |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1906 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1907 | |
| 1908 | if (status) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1909 | hci_conn_check_pending(hdev); |
Johan Hedberg | 314b238 | 2011-04-27 10:29:57 -0400 | [diff] [blame] | 1910 | return; |
| 1911 | } |
| 1912 | |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 1913 | set_bit(HCI_INQUIRY, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1914 | } |
| 1915 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 1916 | static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1918 | struct hci_cp_create_conn *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1921 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1922 | |
| 1923 | cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1924 | if (!cp) |
| 1925 | return; |
| 1926 | |
| 1927 | hci_dev_lock(hdev); |
| 1928 | |
| 1929 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 1930 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 1931 | BT_DBG("%s bdaddr %pMR hcon %p", hdev->name, &cp->bdaddr, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | |
| 1933 | if (status) { |
| 1934 | if (conn && conn->state == BT_CONNECT) { |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 1935 | if (status != 0x0c || conn->attempt > 2) { |
| 1936 | conn->state = BT_CLOSED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 1937 | hci_connect_cfm(conn, status); |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 1938 | hci_conn_del(conn); |
| 1939 | } else |
| 1940 | conn->state = BT_CONNECT2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | } |
| 1942 | } else { |
| 1943 | if (!conn) { |
Johan Hedberg | a5c4e30 | 2014-07-16 11:56:07 +0300 | [diff] [blame] | 1944 | conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr, |
| 1945 | HCI_ROLE_MASTER); |
| 1946 | if (!conn) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1947 | bt_dev_err(hdev, "no memory for new connection"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | } |
| 1949 | } |
| 1950 | |
| 1951 | hci_dev_unlock(hdev); |
| 1952 | } |
| 1953 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1954 | static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1956 | struct hci_cp_add_sco *cp; |
| 1957 | struct hci_conn *acl, *sco; |
| 1958 | __u16 handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1960 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 1961 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1962 | if (!status) |
| 1963 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1965 | cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO); |
| 1966 | if (!cp) |
| 1967 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1969 | handle = __le16_to_cpu(cp->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1971 | BT_DBG("%s handle 0x%4.4x", hdev->name, handle); |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 1972 | |
| 1973 | hci_dev_lock(hdev); |
| 1974 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1975 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1976 | if (acl) { |
| 1977 | sco = acl->link; |
| 1978 | if (sco) { |
| 1979 | sco->state = BT_CLOSED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1980 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 1981 | hci_connect_cfm(sco, status); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 1982 | hci_conn_del(sco); |
| 1983 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1984 | } |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 1985 | |
| 1986 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | } |
| 1988 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1989 | static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) |
| 1990 | { |
| 1991 | struct hci_cp_auth_requested *cp; |
| 1992 | struct hci_conn *conn; |
| 1993 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 1994 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 1995 | |
| 1996 | if (!status) |
| 1997 | return; |
| 1998 | |
| 1999 | cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED); |
| 2000 | if (!cp) |
| 2001 | return; |
| 2002 | |
| 2003 | hci_dev_lock(hdev); |
| 2004 | |
| 2005 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2006 | if (conn) { |
| 2007 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2008 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2009 | hci_conn_drop(conn); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | hci_dev_unlock(hdev); |
| 2014 | } |
| 2015 | |
| 2016 | static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) |
| 2017 | { |
| 2018 | struct hci_cp_set_conn_encrypt *cp; |
| 2019 | struct hci_conn *conn; |
| 2020 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2021 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2022 | |
| 2023 | if (!status) |
| 2024 | return; |
| 2025 | |
| 2026 | cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT); |
| 2027 | if (!cp) |
| 2028 | return; |
| 2029 | |
| 2030 | hci_dev_lock(hdev); |
| 2031 | |
| 2032 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2033 | if (conn) { |
| 2034 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2035 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2036 | hci_conn_drop(conn); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | hci_dev_unlock(hdev); |
| 2041 | } |
| 2042 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2043 | static int hci_outgoing_auth_needed(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2044 | struct hci_conn *conn) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2045 | { |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2046 | if (conn->state != BT_CONFIG || !conn->out) |
| 2047 | return 0; |
| 2048 | |
Johan Hedberg | 765c2a9 | 2011-01-19 12:06:52 +0530 | [diff] [blame] | 2049 | if (conn->pending_sec_level == BT_SECURITY_SDP) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2050 | return 0; |
| 2051 | |
| 2052 | /* Only request authentication for SSP connections or non-SSP |
Johan Hedberg | 264b8b4 | 2014-01-08 16:40:39 +0200 | [diff] [blame] | 2053 | * devices with sec_level MEDIUM or HIGH or if MITM protection |
| 2054 | * is requested. |
| 2055 | */ |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2056 | if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) && |
Johan Hedberg | 7e3691e | 2014-05-30 14:45:19 +0300 | [diff] [blame] | 2057 | conn->pending_sec_level != BT_SECURITY_FIPS && |
Johan Hedberg | 264b8b4 | 2014-01-08 16:40:39 +0200 | [diff] [blame] | 2058 | conn->pending_sec_level != BT_SECURITY_HIGH && |
| 2059 | conn->pending_sec_level != BT_SECURITY_MEDIUM) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2060 | return 0; |
| 2061 | |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2062 | return 1; |
| 2063 | } |
| 2064 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2065 | static int hci_resolve_name(struct hci_dev *hdev, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2066 | struct inquiry_entry *e) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2067 | { |
| 2068 | struct hci_cp_remote_name_req cp; |
| 2069 | |
| 2070 | memset(&cp, 0, sizeof(cp)); |
| 2071 | |
| 2072 | bacpy(&cp.bdaddr, &e->data.bdaddr); |
| 2073 | cp.pscan_rep_mode = e->data.pscan_rep_mode; |
| 2074 | cp.pscan_mode = e->data.pscan_mode; |
| 2075 | cp.clock_offset = e->data.clock_offset; |
| 2076 | |
| 2077 | return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
| 2078 | } |
| 2079 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2080 | static bool hci_resolve_next_name(struct hci_dev *hdev) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2081 | { |
| 2082 | struct discovery_state *discov = &hdev->discovery; |
| 2083 | struct inquiry_entry *e; |
| 2084 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2085 | if (list_empty(&discov->resolve)) |
| 2086 | return false; |
| 2087 | |
| 2088 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
Ram Malovany | c810089 | 2012-07-19 10:26:09 +0300 | [diff] [blame] | 2089 | if (!e) |
| 2090 | return false; |
| 2091 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2092 | if (hci_resolve_name(hdev, e) == 0) { |
| 2093 | e->name_state = NAME_PENDING; |
| 2094 | return true; |
| 2095 | } |
| 2096 | |
| 2097 | return false; |
| 2098 | } |
| 2099 | |
| 2100 | 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] | 2101 | bdaddr_t *bdaddr, u8 *name, u8 name_len) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2102 | { |
| 2103 | struct discovery_state *discov = &hdev->discovery; |
| 2104 | struct inquiry_entry *e; |
| 2105 | |
Johan Hedberg | 60cb49d | 2014-11-11 11:33:24 +0200 | [diff] [blame] | 2106 | /* Update the mgmt connected state if necessary. Be careful with |
| 2107 | * conn objects that exist but are not (yet) connected however. |
| 2108 | * Only those in BT_CONFIG or BT_CONNECTED states can be |
| 2109 | * considered connected. |
| 2110 | */ |
| 2111 | if (conn && |
| 2112 | (conn->state == BT_CONFIG || conn->state == BT_CONNECTED) && |
Jaganath Kanakkassery | cb77c3e | 2014-11-07 16:39:09 +0530 | [diff] [blame] | 2113 | !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 2114 | mgmt_device_connected(hdev, conn, name, name_len); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2115 | |
| 2116 | if (discov->state == DISCOVERY_STOPPED) |
| 2117 | return; |
| 2118 | |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2119 | if (discov->state == DISCOVERY_STOPPING) |
| 2120 | goto discov_complete; |
| 2121 | |
| 2122 | if (discov->state != DISCOVERY_RESOLVING) |
| 2123 | return; |
| 2124 | |
| 2125 | e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING); |
Ram Malovany | 7cc8380 | 2012-07-19 10:26:10 +0300 | [diff] [blame] | 2126 | /* If the device was not found in a list of found devices names of which |
| 2127 | * are pending. there is no need to continue resolving a next name as it |
| 2128 | * will be done upon receiving another Remote Name Request Complete |
| 2129 | * Event */ |
| 2130 | if (!e) |
| 2131 | return; |
| 2132 | |
| 2133 | list_del(&e->list); |
| 2134 | if (name) { |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2135 | e->name_state = NAME_KNOWN; |
Ram Malovany | 7cc8380 | 2012-07-19 10:26:10 +0300 | [diff] [blame] | 2136 | mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, |
| 2137 | e->data.rssi, name, name_len); |
Ram Malovany | c3e7c0d | 2012-07-19 10:26:11 +0300 | [diff] [blame] | 2138 | } else { |
| 2139 | e->name_state = NAME_NOT_KNOWN; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2140 | } |
| 2141 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2142 | if (hci_resolve_next_name(hdev)) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2143 | return; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2144 | |
| 2145 | discov_complete: |
| 2146 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 2147 | } |
| 2148 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2149 | static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) |
| 2150 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2151 | struct hci_cp_remote_name_req *cp; |
| 2152 | struct hci_conn *conn; |
| 2153 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2154 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2155 | |
| 2156 | /* If successful wait for the name req complete event before |
| 2157 | * checking for the need to do authentication */ |
| 2158 | if (!status) |
| 2159 | return; |
| 2160 | |
| 2161 | cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ); |
| 2162 | if (!cp) |
| 2163 | return; |
| 2164 | |
| 2165 | hci_dev_lock(hdev); |
| 2166 | |
| 2167 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2168 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2169 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2170 | hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0); |
| 2171 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 2172 | if (!conn) |
| 2173 | goto unlock; |
| 2174 | |
| 2175 | if (!hci_outgoing_auth_needed(hdev, conn)) |
| 2176 | goto unlock; |
| 2177 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2178 | if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johannes Berg | c1f23a2 | 2013-10-07 18:19:16 +0200 | [diff] [blame] | 2179 | struct hci_cp_auth_requested auth_cp; |
| 2180 | |
Johan Hedberg | 977f8fc | 2014-07-17 15:35:39 +0300 | [diff] [blame] | 2181 | set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); |
| 2182 | |
Johannes Berg | c1f23a2 | 2013-10-07 18:19:16 +0200 | [diff] [blame] | 2183 | auth_cp.handle = __cpu_to_le16(conn->handle); |
| 2184 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, |
| 2185 | sizeof(auth_cp), &auth_cp); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2186 | } |
| 2187 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 2188 | unlock: |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2189 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2190 | } |
| 2191 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2192 | static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) |
| 2193 | { |
| 2194 | struct hci_cp_read_remote_features *cp; |
| 2195 | struct hci_conn *conn; |
| 2196 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2197 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2198 | |
| 2199 | if (!status) |
| 2200 | return; |
| 2201 | |
| 2202 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES); |
| 2203 | if (!cp) |
| 2204 | return; |
| 2205 | |
| 2206 | hci_dev_lock(hdev); |
| 2207 | |
| 2208 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2209 | if (conn) { |
| 2210 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2211 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2212 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2213 | } |
| 2214 | } |
| 2215 | |
| 2216 | hci_dev_unlock(hdev); |
| 2217 | } |
| 2218 | |
| 2219 | static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status) |
| 2220 | { |
| 2221 | struct hci_cp_read_remote_ext_features *cp; |
| 2222 | struct hci_conn *conn; |
| 2223 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2224 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2225 | |
| 2226 | if (!status) |
| 2227 | return; |
| 2228 | |
| 2229 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES); |
| 2230 | if (!cp) |
| 2231 | return; |
| 2232 | |
| 2233 | hci_dev_lock(hdev); |
| 2234 | |
| 2235 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2236 | if (conn) { |
| 2237 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2238 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2239 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2240 | } |
| 2241 | } |
| 2242 | |
| 2243 | hci_dev_unlock(hdev); |
| 2244 | } |
| 2245 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2246 | static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| 2247 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2248 | struct hci_cp_setup_sync_conn *cp; |
| 2249 | struct hci_conn *acl, *sco; |
| 2250 | __u16 handle; |
| 2251 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2252 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2253 | |
| 2254 | if (!status) |
| 2255 | return; |
| 2256 | |
| 2257 | cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN); |
| 2258 | if (!cp) |
| 2259 | return; |
| 2260 | |
| 2261 | handle = __le16_to_cpu(cp->handle); |
| 2262 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2263 | BT_DBG("%s handle 0x%4.4x", hdev->name, handle); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2264 | |
| 2265 | hci_dev_lock(hdev); |
| 2266 | |
| 2267 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 2268 | if (acl) { |
| 2269 | sco = acl->link; |
| 2270 | if (sco) { |
| 2271 | sco->state = BT_CLOSED; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2272 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2273 | hci_connect_cfm(sco, status); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 2274 | hci_conn_del(sco); |
| 2275 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2279 | } |
| 2280 | |
Kiran K | b2af264 | 2021-09-07 15:42:43 +0530 | [diff] [blame] | 2281 | static void hci_cs_enhanced_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| 2282 | { |
| 2283 | struct hci_cp_enhanced_setup_sync_conn *cp; |
| 2284 | struct hci_conn *acl, *sco; |
| 2285 | __u16 handle; |
| 2286 | |
| 2287 | bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| 2288 | |
| 2289 | if (!status) |
| 2290 | return; |
| 2291 | |
| 2292 | cp = hci_sent_cmd_data(hdev, HCI_OP_ENHANCED_SETUP_SYNC_CONN); |
| 2293 | if (!cp) |
| 2294 | return; |
| 2295 | |
| 2296 | handle = __le16_to_cpu(cp->handle); |
| 2297 | |
| 2298 | bt_dev_dbg(hdev, "handle 0x%4.4x", handle); |
| 2299 | |
| 2300 | hci_dev_lock(hdev); |
| 2301 | |
| 2302 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
| 2303 | if (acl) { |
| 2304 | sco = acl->link; |
| 2305 | if (sco) { |
| 2306 | sco->state = BT_CLOSED; |
| 2307 | |
| 2308 | hci_connect_cfm(sco, status); |
| 2309 | hci_conn_del(sco); |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | hci_dev_unlock(hdev); |
| 2314 | } |
| 2315 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2316 | static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 2317 | { |
| 2318 | struct hci_cp_sniff_mode *cp; |
| 2319 | struct hci_conn *conn; |
| 2320 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2321 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2322 | |
| 2323 | if (!status) |
| 2324 | return; |
| 2325 | |
| 2326 | cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE); |
| 2327 | if (!cp) |
| 2328 | return; |
| 2329 | |
| 2330 | hci_dev_lock(hdev); |
| 2331 | |
| 2332 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2333 | if (conn) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2334 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2335 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2336 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2337 | hci_sco_setup(conn, status); |
| 2338 | } |
| 2339 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2340 | hci_dev_unlock(hdev); |
| 2341 | } |
| 2342 | |
| 2343 | static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 2344 | { |
| 2345 | struct hci_cp_exit_sniff_mode *cp; |
| 2346 | struct hci_conn *conn; |
| 2347 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2348 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2349 | |
| 2350 | if (!status) |
| 2351 | return; |
| 2352 | |
| 2353 | cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE); |
| 2354 | if (!cp) |
| 2355 | return; |
| 2356 | |
| 2357 | hci_dev_lock(hdev); |
| 2358 | |
| 2359 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2360 | if (conn) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2361 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2362 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2363 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2364 | hci_sco_setup(conn, status); |
| 2365 | } |
| 2366 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2367 | hci_dev_unlock(hdev); |
| 2368 | } |
| 2369 | |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2370 | static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) |
| 2371 | { |
| 2372 | struct hci_cp_disconnect *cp; |
| 2373 | struct hci_conn *conn; |
| 2374 | |
| 2375 | if (!status) |
| 2376 | return; |
| 2377 | |
| 2378 | cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT); |
| 2379 | if (!cp) |
| 2380 | return; |
| 2381 | |
| 2382 | hci_dev_lock(hdev); |
| 2383 | |
| 2384 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Joseph Hwang | b8d2905 | 2020-03-11 19:20:14 -0700 | [diff] [blame] | 2385 | if (conn) { |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2386 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2387 | conn->dst_type, status); |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2388 | |
Luiz Augusto von Dentz | 1eeaa1a | 2021-08-20 16:40:38 -0700 | [diff] [blame] | 2389 | if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) { |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 2390 | hdev->cur_adv_instance = conn->adv_instance; |
| 2391 | hci_req_reenable_advertising(hdev); |
| 2392 | } |
| 2393 | |
Joseph Hwang | b8d2905 | 2020-03-11 19:20:14 -0700 | [diff] [blame] | 2394 | /* If the disconnection failed for any reason, the upper layer |
| 2395 | * does not retry to disconnect in current implementation. |
| 2396 | * Hence, we need to do some basic cleanup here and re-enable |
| 2397 | * advertising if necessary. |
| 2398 | */ |
| 2399 | hci_conn_del(conn); |
Joseph Hwang | b8d2905 | 2020-03-11 19:20:14 -0700 | [diff] [blame] | 2400 | } |
| 2401 | |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2402 | hci_dev_unlock(hdev); |
| 2403 | } |
| 2404 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2405 | static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type, bool *resolved) |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 2406 | { |
| 2407 | /* When using controller based address resolution, then the new |
| 2408 | * address types 0x02 and 0x03 are used. These types need to be |
| 2409 | * converted back into either public address or random address type |
| 2410 | */ |
| 2411 | switch (type) { |
| 2412 | case ADDR_LE_DEV_PUBLIC_RESOLVED: |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2413 | if (resolved) |
| 2414 | *resolved = true; |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 2415 | return ADDR_LE_DEV_PUBLIC; |
| 2416 | case ADDR_LE_DEV_RANDOM_RESOLVED: |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2417 | if (resolved) |
| 2418 | *resolved = true; |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 2419 | return ADDR_LE_DEV_RANDOM; |
| 2420 | } |
| 2421 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2422 | if (resolved) |
| 2423 | *resolved = false; |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 2424 | return type; |
| 2425 | } |
| 2426 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2427 | static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, |
| 2428 | u8 peer_addr_type, u8 own_address_type, |
| 2429 | u8 filter_policy) |
| 2430 | { |
| 2431 | struct hci_conn *conn; |
| 2432 | |
| 2433 | conn = hci_conn_hash_lookup_le(hdev, peer_addr, |
| 2434 | peer_addr_type); |
| 2435 | if (!conn) |
| 2436 | return; |
| 2437 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2438 | own_address_type = ev_bdaddr_type(hdev, own_address_type, NULL); |
Sathish Narasimman | b31bc00 | 2020-07-23 18:08:59 +0530 | [diff] [blame] | 2439 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2440 | /* Store the initiator and responder address information which |
| 2441 | * is needed for SMP. These values will not change during the |
| 2442 | * lifetime of the connection. |
| 2443 | */ |
| 2444 | conn->init_addr_type = own_address_type; |
| 2445 | if (own_address_type == ADDR_LE_DEV_RANDOM) |
| 2446 | bacpy(&conn->init_addr, &hdev->random_addr); |
| 2447 | else |
| 2448 | bacpy(&conn->init_addr, &hdev->bdaddr); |
| 2449 | |
| 2450 | conn->resp_addr_type = peer_addr_type; |
| 2451 | bacpy(&conn->resp_addr, peer_addr); |
| 2452 | |
| 2453 | /* We don't want the connection attempt to stick around |
| 2454 | * indefinitely since LE doesn't have a page timeout concept |
| 2455 | * like BR/EDR. Set a timer for any connection that doesn't use |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 2456 | * the accept list for connecting. |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2457 | */ |
| 2458 | if (filter_policy == HCI_LE_USE_PEER_ADDR) |
| 2459 | queue_delayed_work(conn->hdev->workqueue, |
| 2460 | &conn->le_conn_timeout, |
| 2461 | conn->conn_timeout); |
| 2462 | } |
| 2463 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2464 | static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status) |
| 2465 | { |
| 2466 | struct hci_cp_le_create_conn *cp; |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2467 | |
| 2468 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2469 | |
| 2470 | /* All connection failure handling is taken care of by the |
| 2471 | * hci_le_conn_failed function which is triggered by the HCI |
| 2472 | * request completion callbacks used for connecting. |
| 2473 | */ |
| 2474 | if (status) |
| 2475 | return; |
| 2476 | |
| 2477 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN); |
| 2478 | if (!cp) |
| 2479 | return; |
| 2480 | |
| 2481 | hci_dev_lock(hdev); |
| 2482 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2483 | cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type, |
| 2484 | cp->own_address_type, cp->filter_policy); |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2485 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2486 | hci_dev_unlock(hdev); |
| 2487 | } |
| 2488 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 2489 | static void hci_cs_le_ext_create_conn(struct hci_dev *hdev, u8 status) |
| 2490 | { |
| 2491 | struct hci_cp_le_ext_create_conn *cp; |
| 2492 | |
| 2493 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2494 | |
| 2495 | /* All connection failure handling is taken care of by the |
| 2496 | * hci_le_conn_failed function which is triggered by the HCI |
| 2497 | * request completion callbacks used for connecting. |
| 2498 | */ |
| 2499 | if (status) |
| 2500 | return; |
| 2501 | |
| 2502 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_EXT_CREATE_CONN); |
| 2503 | if (!cp) |
| 2504 | return; |
| 2505 | |
| 2506 | hci_dev_lock(hdev); |
| 2507 | |
| 2508 | cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type, |
| 2509 | cp->own_addr_type, cp->filter_policy); |
| 2510 | |
| 2511 | hci_dev_unlock(hdev); |
| 2512 | } |
| 2513 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 2514 | static void hci_cs_le_read_remote_features(struct hci_dev *hdev, u8 status) |
| 2515 | { |
| 2516 | struct hci_cp_le_read_remote_features *cp; |
| 2517 | struct hci_conn *conn; |
| 2518 | |
| 2519 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2520 | |
| 2521 | if (!status) |
| 2522 | return; |
| 2523 | |
| 2524 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_READ_REMOTE_FEATURES); |
| 2525 | if (!cp) |
| 2526 | return; |
| 2527 | |
| 2528 | hci_dev_lock(hdev); |
| 2529 | |
| 2530 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2531 | if (conn) { |
| 2532 | if (conn->state == BT_CONFIG) { |
| 2533 | hci_connect_cfm(conn, status); |
| 2534 | hci_conn_drop(conn); |
| 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | hci_dev_unlock(hdev); |
| 2539 | } |
| 2540 | |
Johan Hedberg | 81d0c8a | 2014-03-24 14:39:04 +0200 | [diff] [blame] | 2541 | static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status) |
| 2542 | { |
| 2543 | struct hci_cp_le_start_enc *cp; |
| 2544 | struct hci_conn *conn; |
| 2545 | |
| 2546 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2547 | |
| 2548 | if (!status) |
| 2549 | return; |
| 2550 | |
| 2551 | hci_dev_lock(hdev); |
| 2552 | |
| 2553 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_START_ENC); |
| 2554 | if (!cp) |
| 2555 | goto unlock; |
| 2556 | |
| 2557 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2558 | if (!conn) |
| 2559 | goto unlock; |
| 2560 | |
| 2561 | if (conn->state != BT_CONNECTED) |
| 2562 | goto unlock; |
| 2563 | |
| 2564 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
| 2565 | hci_conn_drop(conn); |
| 2566 | |
| 2567 | unlock: |
| 2568 | hci_dev_unlock(hdev); |
| 2569 | } |
| 2570 | |
Kuba Pawlak | 50fc85f | 2014-11-06 19:36:52 +0100 | [diff] [blame] | 2571 | static void hci_cs_switch_role(struct hci_dev *hdev, u8 status) |
| 2572 | { |
| 2573 | struct hci_cp_switch_role *cp; |
| 2574 | struct hci_conn *conn; |
| 2575 | |
| 2576 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2577 | |
| 2578 | if (!status) |
| 2579 | return; |
| 2580 | |
| 2581 | cp = hci_sent_cmd_data(hdev, HCI_OP_SWITCH_ROLE); |
| 2582 | if (!cp) |
| 2583 | return; |
| 2584 | |
| 2585 | hci_dev_lock(hdev); |
| 2586 | |
| 2587 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 2588 | if (conn) |
| 2589 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
| 2590 | |
| 2591 | hci_dev_unlock(hdev); |
| 2592 | } |
| 2593 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2594 | 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] | 2595 | { |
| 2596 | __u8 status = *((__u8 *) skb->data); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2597 | struct discovery_state *discov = &hdev->discovery; |
| 2598 | struct inquiry_entry *e; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2599 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2600 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2601 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2602 | hci_conn_check_pending(hdev); |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 2603 | |
| 2604 | if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) |
| 2605 | return; |
| 2606 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 2607 | smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */ |
Andre Guedes | 3e13fa1 | 2013-03-27 20:04:56 -0300 | [diff] [blame] | 2608 | wake_up_bit(&hdev->flags, HCI_INQUIRY); |
| 2609 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2610 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2611 | return; |
| 2612 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 2613 | hci_dev_lock(hdev); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2614 | |
Andre Guedes | 343f935 | 2012-02-17 20:39:37 -0300 | [diff] [blame] | 2615 | if (discov->state != DISCOVERY_FINDING) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2616 | goto unlock; |
| 2617 | |
| 2618 | if (list_empty(&discov->resolve)) { |
Jakub Pawlowski | 07d2334 | 2015-03-17 09:04:14 -0700 | [diff] [blame] | 2619 | /* When BR/EDR inquiry is active and no LE scanning is in |
| 2620 | * progress, then change discovery state to indicate completion. |
| 2621 | * |
| 2622 | * When running LE scanning and BR/EDR inquiry simultaneously |
| 2623 | * and the LE scan already finished, then change the discovery |
| 2624 | * state to indicate completion. |
| 2625 | */ |
| 2626 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 2627 | !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) |
| 2628 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2629 | goto unlock; |
| 2630 | } |
| 2631 | |
| 2632 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
| 2633 | if (e && hci_resolve_name(hdev, e) == 0) { |
| 2634 | e->name_state = NAME_PENDING; |
| 2635 | hci_discovery_set_state(hdev, DISCOVERY_RESOLVING); |
| 2636 | } else { |
Jakub Pawlowski | 07d2334 | 2015-03-17 09:04:14 -0700 | [diff] [blame] | 2637 | /* When BR/EDR inquiry is active and no LE scanning is in |
| 2638 | * progress, then change discovery state to indicate completion. |
| 2639 | * |
| 2640 | * When running LE scanning and BR/EDR inquiry simultaneously |
| 2641 | * and the LE scan already finished, then change the discovery |
| 2642 | * state to indicate completion. |
| 2643 | */ |
| 2644 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 2645 | !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) |
| 2646 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2647 | } |
| 2648 | |
| 2649 | unlock: |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 2650 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2651 | } |
| 2652 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2653 | 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] | 2654 | { |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2655 | struct inquiry_data data; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2656 | struct inquiry_info *info = (void *) (skb->data + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | int num_rsp = *((__u8 *) skb->data); |
| 2658 | |
| 2659 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 2660 | |
Peilin Ye | 75bbd2e | 2020-07-10 17:39:18 -0400 | [diff] [blame] | 2661 | if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1) |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2662 | return; |
| 2663 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2664 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 2665 | return; |
| 2666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2668 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 2669 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 2670 | u32 flags; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 2671 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | bacpy(&data.bdaddr, &info->bdaddr); |
| 2673 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 2674 | data.pscan_period_mode = info->pscan_period_mode; |
| 2675 | data.pscan_mode = info->pscan_mode; |
| 2676 | memcpy(data.dev_class, info->dev_class, 3); |
| 2677 | data.clock_offset = info->clock_offset; |
Marcel Holtmann | efb2513 | 2014-12-05 13:03:34 +0100 | [diff] [blame] | 2678 | data.rssi = HCI_RSSI_INVALID; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 2679 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 2680 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 2681 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 2682 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 2683 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Marcel Holtmann | efb2513 | 2014-12-05 13:03:34 +0100 | [diff] [blame] | 2684 | info->dev_class, HCI_RSSI_INVALID, |
| 2685 | flags, NULL, 0, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2686 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | hci_dev_unlock(hdev); |
| 2689 | } |
| 2690 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2691 | 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] | 2692 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2693 | struct hci_ev_conn_complete *ev = (void *) skb->data; |
| 2694 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2696 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2698 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2699 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2700 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9499237 | 2009-04-19 19:30:03 +0200 | [diff] [blame] | 2701 | if (!conn) { |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 2702 | /* Connection may not exist if auto-connected. Check the bredr |
| 2703 | * allowlist to see if this device is allowed to auto connect. |
| 2704 | * If link is an ACL type, create a connection class |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2705 | * automatically. |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 2706 | * |
| 2707 | * Auto-connect will only occur if the event filter is |
| 2708 | * programmed with a given address. Right now, event filter is |
| 2709 | * only used during suspend. |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2710 | */ |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 2711 | if (ev->link_type == ACL_LINK && |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 2712 | hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 2713 | &ev->bdaddr, |
| 2714 | BDADDR_BREDR)) { |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2715 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr, |
| 2716 | HCI_ROLE_SLAVE); |
| 2717 | if (!conn) { |
| 2718 | bt_dev_err(hdev, "no memory for new conn"); |
| 2719 | goto unlock; |
| 2720 | } |
Abhishek Pandit-Subedi | 2d186fc | 2020-03-19 17:07:13 -0700 | [diff] [blame] | 2721 | } else { |
| 2722 | if (ev->link_type != SCO_LINK) |
| 2723 | goto unlock; |
| 2724 | |
| 2725 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, |
| 2726 | &ev->bdaddr); |
| 2727 | if (!conn) |
| 2728 | goto unlock; |
| 2729 | |
| 2730 | conn->type = SCO_LINK; |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2731 | } |
Marcel Holtmann | 9499237 | 2009-04-19 19:30:03 +0200 | [diff] [blame] | 2732 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2733 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2734 | if (!ev->status) { |
| 2735 | conn->handle = __le16_to_cpu(ev->handle); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2736 | |
| 2737 | if (conn->type == ACL_LINK) { |
| 2738 | conn->state = BT_CONFIG; |
| 2739 | hci_conn_hold(conn); |
Szymon Janc | a9ea3ed | 2012-07-19 14:46:08 +0200 | [diff] [blame] | 2740 | |
| 2741 | if (!conn->out && !hci_conn_ssp_enabled(conn) && |
| 2742 | !hci_find_link_key(hdev, &ev->bdaddr)) |
| 2743 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
| 2744 | else |
| 2745 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2746 | } else |
| 2747 | conn->state = BT_CONNECTED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2748 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 2749 | hci_debugfs_create_conn(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 2750 | hci_conn_add_sysfs(conn); |
| 2751 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2752 | if (test_bit(HCI_AUTH, &hdev->flags)) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 2753 | set_bit(HCI_CONN_AUTH, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2754 | |
| 2755 | if (test_bit(HCI_ENCRYPT, &hdev->flags)) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 2756 | set_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2757 | |
| 2758 | /* Get remote features */ |
| 2759 | if (conn->type == ACL_LINK) { |
| 2760 | struct hci_cp_read_remote_features cp; |
| 2761 | cp.handle = ev->handle; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2762 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2763 | sizeof(cp), &cp); |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 2764 | |
Johan Hedberg | 01b1cb8 | 2015-11-16 12:52:21 +0200 | [diff] [blame] | 2765 | hci_req_update_scan(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2766 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2767 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2768 | /* Set packet type for incoming connection */ |
Andrei Emeltchenko | d095c1e | 2011-12-01 14:33:27 +0200 | [diff] [blame] | 2769 | if (!conn->out && hdev->hci_ver < BLUETOOTH_VER_2_0) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2770 | struct hci_cp_change_conn_ptype cp; |
| 2771 | cp.handle = ev->handle; |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 2772 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2773 | hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp), |
| 2774 | &cp); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2775 | } |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 2776 | } else { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2777 | conn->state = BT_CLOSED; |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 2778 | if (conn->type == ACL_LINK) |
Marcel Holtmann | 64c7b77 | 2014-02-18 14:22:20 -0800 | [diff] [blame] | 2779 | mgmt_connect_failed(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2780 | conn->dst_type, ev->status); |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 2781 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2782 | |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2783 | if (conn->type == ACL_LINK) |
| 2784 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 2785 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2786 | if (ev->status) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2787 | hci_connect_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2788 | hci_conn_del(conn); |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 2789 | } else if (ev->link_type == SCO_LINK) { |
| 2790 | switch (conn->setting & SCO_AIRMODE_MASK) { |
| 2791 | case SCO_AIRMODE_CVSD: |
| 2792 | if (hdev->notify) |
| 2793 | hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD); |
| 2794 | break; |
| 2795 | } |
| 2796 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2797 | hci_connect_cfm(conn, ev->status); |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 2798 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2799 | |
| 2800 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2802 | |
| 2803 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2804 | } |
| 2805 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2806 | static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) |
| 2807 | { |
| 2808 | struct hci_cp_reject_conn_req cp; |
| 2809 | |
| 2810 | bacpy(&cp.bdaddr, bdaddr); |
| 2811 | cp.reason = HCI_ERROR_REJ_BAD_ADDR; |
| 2812 | hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp); |
| 2813 | } |
| 2814 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2815 | 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] | 2816 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2817 | struct hci_ev_conn_request *ev = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | int mask = hdev->link_mode; |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2819 | struct inquiry_entry *ie; |
| 2820 | struct hci_conn *conn; |
Frédéric Dalleau | 20714bfe | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 2821 | __u8 flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 2823 | BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2824 | ev->link_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2825 | |
Frédéric Dalleau | 20714bfe | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 2826 | mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type, |
| 2827 | &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2828 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2829 | if (!(mask & HCI_LM_ACCEPT)) { |
| 2830 | hci_reject_conn(hdev, &ev->bdaddr); |
| 2831 | return; |
| 2832 | } |
| 2833 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 2834 | if (hci_bdaddr_list_lookup(&hdev->reject_list, &ev->bdaddr, |
Johan Hedberg | 46c4c94 | 2014-07-16 16:19:21 +0300 | [diff] [blame] | 2835 | BDADDR_BREDR)) { |
| 2836 | hci_reject_conn(hdev, &ev->bdaddr); |
| 2837 | return; |
| 2838 | } |
| 2839 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 2840 | /* Require HCI_CONNECTABLE or an accept list entry to accept the |
Johan Hedberg | 6a8fc95 | 2014-12-24 20:43:11 +0200 | [diff] [blame] | 2841 | * connection. These features are only touched through mgmt so |
| 2842 | * only do the checks if HCI_MGMT is set. |
| 2843 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2844 | if (hci_dev_test_flag(hdev, HCI_MGMT) && |
| 2845 | !hci_dev_test_flag(hdev, HCI_CONNECTABLE) && |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 2846 | !hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, &ev->bdaddr, |
Abhishek Pandit-Subedi | 8baaa40 | 2020-06-17 16:39:08 +0200 | [diff] [blame] | 2847 | BDADDR_BREDR)) { |
| 2848 | hci_reject_conn(hdev, &ev->bdaddr); |
| 2849 | return; |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2850 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2851 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2852 | /* Connection accepted */ |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2853 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2854 | hci_dev_lock(hdev); |
Marcel Holtmann | c7bdd50 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 2855 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2856 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 2857 | if (ie) |
| 2858 | memcpy(ie->data.dev_class, ev->dev_class, 3); |
| 2859 | |
| 2860 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, |
| 2861 | &ev->bdaddr); |
| 2862 | if (!conn) { |
Johan Hedberg | a5c4e30 | 2014-07-16 11:56:07 +0300 | [diff] [blame] | 2863 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr, |
| 2864 | HCI_ROLE_SLAVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2865 | if (!conn) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2866 | bt_dev_err(hdev, "no memory for new connection"); |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2867 | hci_dev_unlock(hdev); |
| 2868 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2869 | } |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2870 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2871 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2872 | memcpy(conn->dev_class, ev->dev_class, 3); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2873 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2874 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2875 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2876 | if (ev->link_type == ACL_LINK || |
| 2877 | (!(flags & HCI_PROTO_DEFER) && !lmp_esco_capable(hdev))) { |
| 2878 | struct hci_cp_accept_conn_req cp; |
| 2879 | conn->state = BT_CONNECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | |
| 2881 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2882 | |
| 2883 | if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) |
Archie Pusaka | 74be523 | 2021-06-04 16:26:25 +0800 | [diff] [blame] | 2884 | cp.role = 0x00; /* Become central */ |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2885 | else |
Archie Pusaka | 74be523 | 2021-06-04 16:26:25 +0800 | [diff] [blame] | 2886 | cp.role = 0x01; /* Remain peripheral */ |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 2887 | |
| 2888 | hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp); |
| 2889 | } else if (!(flags & HCI_PROTO_DEFER)) { |
| 2890 | struct hci_cp_accept_sync_conn_req cp; |
| 2891 | conn->state = BT_CONNECT; |
| 2892 | |
| 2893 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 2894 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
| 2895 | |
| 2896 | cp.tx_bandwidth = cpu_to_le32(0x00001f40); |
| 2897 | cp.rx_bandwidth = cpu_to_le32(0x00001f40); |
| 2898 | cp.max_latency = cpu_to_le16(0xffff); |
| 2899 | cp.content_format = cpu_to_le16(hdev->voice_setting); |
| 2900 | cp.retrans_effort = 0xff; |
| 2901 | |
| 2902 | hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp), |
| 2903 | &cp); |
| 2904 | } else { |
| 2905 | conn->state = BT_CONNECT2; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2906 | hci_connect_cfm(conn, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | } |
| 2908 | } |
| 2909 | |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 2910 | static u8 hci_to_mgmt_reason(u8 err) |
| 2911 | { |
| 2912 | switch (err) { |
| 2913 | case HCI_ERROR_CONNECTION_TIMEOUT: |
| 2914 | return MGMT_DEV_DISCONN_TIMEOUT; |
| 2915 | case HCI_ERROR_REMOTE_USER_TERM: |
| 2916 | case HCI_ERROR_REMOTE_LOW_RESOURCES: |
| 2917 | case HCI_ERROR_REMOTE_POWER_OFF: |
| 2918 | return MGMT_DEV_DISCONN_REMOTE; |
| 2919 | case HCI_ERROR_LOCAL_HOST_TERM: |
| 2920 | return MGMT_DEV_DISCONN_LOCAL_HOST; |
| 2921 | default: |
| 2922 | return MGMT_DEV_DISCONN_UNKNOWN; |
| 2923 | } |
| 2924 | } |
| 2925 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2926 | 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] | 2927 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2928 | struct hci_ev_disconn_complete *ev = (void *) skb->data; |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 2929 | u8 reason; |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2930 | struct hci_conn_params *params; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2931 | struct hci_conn *conn; |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 2932 | bool mgmt_connected; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2933 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2934 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2936 | hci_dev_lock(hdev); |
| 2937 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 2938 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 2939 | if (!conn) |
| 2940 | goto unlock; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 2941 | |
Andre Guedes | abf54a5 | 2013-11-07 17:36:09 -0300 | [diff] [blame] | 2942 | if (ev->status) { |
| 2943 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
| 2944 | conn->dst_type, ev->status); |
| 2945 | goto unlock; |
Johan Hedberg | 37d9ef7 | 2011-11-10 15:54:39 +0200 | [diff] [blame] | 2946 | } |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 2947 | |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 2948 | conn->state = BT_CLOSED; |
| 2949 | |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 2950 | mgmt_connected = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 2951 | |
| 2952 | if (test_bit(HCI_CONN_AUTH_FAILURE, &conn->flags)) |
| 2953 | reason = MGMT_DEV_DISCONN_AUTH_FAILURE; |
| 2954 | else |
| 2955 | reason = hci_to_mgmt_reason(ev->reason); |
| 2956 | |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 2957 | mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type, |
| 2958 | reason, mgmt_connected); |
Andre Guedes | abf54a5 | 2013-11-07 17:36:09 -0300 | [diff] [blame] | 2959 | |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 2960 | if (conn->type == ACL_LINK) { |
| 2961 | if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) |
| 2962 | hci_remove_link_key(hdev, &conn->dst); |
| 2963 | |
Johan Hedberg | 01b1cb8 | 2015-11-16 12:52:21 +0200 | [diff] [blame] | 2964 | hci_req_update_scan(hdev); |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 2965 | } |
Johan Hedberg | 2210246 | 2013-10-05 12:01:06 +0200 | [diff] [blame] | 2966 | |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2967 | params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); |
| 2968 | if (params) { |
| 2969 | switch (params->auto_connect) { |
| 2970 | case HCI_AUTO_CONN_LINK_LOSS: |
| 2971 | if (ev->reason != HCI_ERROR_CONNECTION_TIMEOUT) |
| 2972 | break; |
Gustavo A. R. Silva | 19186c7 | 2020-07-08 15:18:23 -0500 | [diff] [blame] | 2973 | fallthrough; |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2974 | |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 2975 | case HCI_AUTO_CONN_DIRECT: |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2976 | case HCI_AUTO_CONN_ALWAYS: |
Johan Hedberg | 418025d | 2014-07-04 12:37:24 +0300 | [diff] [blame] | 2977 | list_del_init(¶ms->action); |
| 2978 | list_add(¶ms->action, &hdev->pend_le_conns); |
| 2979 | hci_update_background_scan(hdev); |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 2980 | break; |
| 2981 | |
| 2982 | default: |
| 2983 | break; |
| 2984 | } |
| 2985 | } |
| 2986 | |
Johan Hedberg | 3a6d576 | 2015-02-18 14:53:58 +0200 | [diff] [blame] | 2987 | hci_disconn_cfm(conn, ev->reason); |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 2988 | |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 2989 | /* The suspend notifier is waiting for all devices to disconnect so |
| 2990 | * clear the bit from pending tasks and inform the wait queue. |
| 2991 | */ |
| 2992 | if (list_empty(&hdev->conn_hash.list) && |
| 2993 | test_and_clear_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks)) { |
| 2994 | wake_up(&hdev->suspend_wait_q); |
| 2995 | } |
| 2996 | |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 2997 | /* Re-enable advertising if necessary, since it might |
| 2998 | * have been disabled by the connection. From the |
| 2999 | * HCI_LE_Set_Advertise_Enable command description in |
| 3000 | * the core specification (v4.0): |
| 3001 | * "The Controller shall continue advertising until the Host |
| 3002 | * issues an LE_Set_Advertise_Enable command with |
| 3003 | * Advertising_Enable set to 0x00 (Advertising is disabled) |
| 3004 | * or until a connection is created or until the Advertising |
| 3005 | * is timed out due to Directed Advertising." |
| 3006 | */ |
Luiz Augusto von Dentz | 1eeaa1a | 2021-08-20 16:40:38 -0700 | [diff] [blame] | 3007 | if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) { |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 3008 | hdev->cur_adv_instance = conn->adv_instance; |
Johan Hedberg | f225257 | 2015-11-18 12:49:20 +0200 | [diff] [blame] | 3009 | hci_req_reenable_advertising(hdev); |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 3010 | } |
| 3011 | |
| 3012 | hci_conn_del(conn); |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 3013 | |
| 3014 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | hci_dev_unlock(hdev); |
| 3016 | } |
| 3017 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3018 | 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] | 3019 | { |
| 3020 | struct hci_ev_auth_complete *ev = (void *) skb->data; |
| 3021 | struct hci_conn *conn; |
| 3022 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3023 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3024 | |
| 3025 | hci_dev_lock(hdev); |
| 3026 | |
| 3027 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3028 | if (!conn) |
| 3029 | goto unlock; |
| 3030 | |
| 3031 | if (!ev->status) { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3032 | clear_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 3033 | |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 3034 | if (!hci_conn_ssp_enabled(conn) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3035 | test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3036 | bt_dev_info(hdev, "re-auth of legacy device is not possible."); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 3037 | } else { |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3038 | set_bit(HCI_CONN_AUTH, &conn->flags); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3039 | conn->sec_level = conn->pending_sec_level; |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 3040 | } |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3041 | } else { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3042 | if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) |
| 3043 | set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 3044 | |
Johan Hedberg | e1e930f | 2014-09-08 17:09:49 -0700 | [diff] [blame] | 3045 | mgmt_auth_failed(conn, ev->status); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3046 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3047 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3048 | clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); |
| 3049 | clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3050 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3051 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 3052 | if (!ev->status && hci_conn_ssp_enabled(conn)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3053 | struct hci_cp_set_conn_encrypt cp; |
| 3054 | cp.handle = ev->handle; |
| 3055 | cp.encrypt = 0x01; |
| 3056 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3057 | &cp); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3058 | } else { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3059 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 3060 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 3061 | hci_conn_drop(conn); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3062 | } |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3063 | } else { |
| 3064 | hci_auth_cfm(conn, ev->status); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3065 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3066 | hci_conn_hold(conn); |
| 3067 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 3068 | hci_conn_drop(conn); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3069 | } |
| 3070 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3071 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3072 | if (!ev->status) { |
| 3073 | struct hci_cp_set_conn_encrypt cp; |
| 3074 | cp.handle = ev->handle; |
| 3075 | cp.encrypt = 0x01; |
| 3076 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3077 | &cp); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3078 | } else { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3079 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 3080 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3081 | } |
| 3082 | } |
| 3083 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3084 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3085 | hci_dev_unlock(hdev); |
| 3086 | } |
| 3087 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3088 | 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] | 3089 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3090 | struct hci_ev_remote_name *ev = (void *) skb->data; |
| 3091 | struct hci_conn *conn; |
| 3092 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3093 | BT_DBG("%s", hdev->name); |
| 3094 | |
| 3095 | hci_conn_check_pending(hdev); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3096 | |
| 3097 | hci_dev_lock(hdev); |
| 3098 | |
| 3099 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3100 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 3101 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3102 | goto check_auth; |
| 3103 | |
| 3104 | if (ev->status == 0) |
| 3105 | hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3106 | strnlen(ev->name, HCI_MAX_NAME_LENGTH)); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3107 | else |
| 3108 | hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0); |
| 3109 | |
| 3110 | check_auth: |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 3111 | if (!conn) |
| 3112 | goto unlock; |
| 3113 | |
| 3114 | if (!hci_outgoing_auth_needed(hdev, conn)) |
| 3115 | goto unlock; |
| 3116 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3117 | if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3118 | struct hci_cp_auth_requested cp; |
Johan Hedberg | 977f8fc | 2014-07-17 15:35:39 +0300 | [diff] [blame] | 3119 | |
| 3120 | set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); |
| 3121 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3122 | cp.handle = __cpu_to_le16(conn->handle); |
| 3123 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); |
| 3124 | } |
| 3125 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 3126 | unlock: |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3127 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3128 | } |
| 3129 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3130 | static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, |
| 3131 | u16 opcode, struct sk_buff *skb) |
| 3132 | { |
| 3133 | const struct hci_rp_read_enc_key_size *rp; |
| 3134 | struct hci_conn *conn; |
| 3135 | u16 handle; |
| 3136 | |
| 3137 | BT_DBG("%s status 0x%02x", hdev->name, status); |
| 3138 | |
| 3139 | if (!skb || skb->len < sizeof(*rp)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3140 | bt_dev_err(hdev, "invalid read key size response"); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3141 | return; |
| 3142 | } |
| 3143 | |
| 3144 | rp = (void *)skb->data; |
| 3145 | handle = le16_to_cpu(rp->handle); |
| 3146 | |
| 3147 | hci_dev_lock(hdev); |
| 3148 | |
| 3149 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
| 3150 | if (!conn) |
| 3151 | goto unlock; |
| 3152 | |
Alain Michaud | 32b5072 | 2020-03-25 14:48:34 +0000 | [diff] [blame] | 3153 | /* While unexpected, the read_enc_key_size command may fail. The most |
| 3154 | * secure approach is to then assume the key size is 0 to force a |
| 3155 | * disconnection. |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3156 | */ |
| 3157 | if (rp->status) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3158 | bt_dev_err(hdev, "failed to read key size for handle %u", |
| 3159 | handle); |
Alain Michaud | 32b5072 | 2020-03-25 14:48:34 +0000 | [diff] [blame] | 3160 | conn->enc_key_size = 0; |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3161 | } else { |
| 3162 | conn->enc_key_size = rp->key_size; |
| 3163 | } |
| 3164 | |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 3165 | hci_encrypt_cfm(conn, 0); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3166 | |
| 3167 | unlock: |
| 3168 | hci_dev_unlock(hdev); |
| 3169 | } |
| 3170 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3171 | 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] | 3172 | { |
| 3173 | struct hci_ev_encrypt_change *ev = (void *) skb->data; |
| 3174 | struct hci_conn *conn; |
| 3175 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3176 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3177 | |
| 3178 | hci_dev_lock(hdev); |
| 3179 | |
| 3180 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3181 | if (!conn) |
| 3182 | goto unlock; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3183 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3184 | if (!ev->status) { |
| 3185 | if (ev->encrypt) { |
| 3186 | /* Encryption implies authentication */ |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3187 | set_bit(HCI_CONN_AUTH, &conn->flags); |
| 3188 | set_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3189 | conn->sec_level = conn->pending_sec_level; |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3190 | |
Marcel Holtmann | 914a6ff | 2014-02-01 11:52:02 -0800 | [diff] [blame] | 3191 | /* P-256 authentication key implies FIPS */ |
| 3192 | if (conn->key_type == HCI_LK_AUTH_COMBINATION_P256) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3193 | set_bit(HCI_CONN_FIPS, &conn->flags); |
Marcel Holtmann | 914a6ff | 2014-02-01 11:52:02 -0800 | [diff] [blame] | 3194 | |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3195 | if ((conn->type == ACL_LINK && ev->encrypt == 0x02) || |
| 3196 | conn->type == LE_LINK) |
| 3197 | set_bit(HCI_CONN_AES_CCM, &conn->flags); |
| 3198 | } else { |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3199 | clear_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3200 | clear_bit(HCI_CONN_AES_CCM, &conn->flags); |
| 3201 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3202 | } |
| 3203 | |
Johan Hedberg | 7ed3fa2 | 2014-09-10 22:16:35 -0700 | [diff] [blame] | 3204 | /* We should disregard the current RPA and generate a new one |
| 3205 | * whenever the encryption procedure fails. |
| 3206 | */ |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 3207 | if (ev->status && conn->type == LE_LINK) { |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 3208 | hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 3209 | hci_adv_instances_set_rpa_expired(hdev, true); |
| 3210 | } |
Johan Hedberg | 7ed3fa2 | 2014-09-10 22:16:35 -0700 | [diff] [blame] | 3211 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3212 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
| 3213 | |
Luiz Augusto von Dentz | 8746f13 | 2020-05-20 14:20:14 -0700 | [diff] [blame] | 3214 | /* Check link security requirements are met */ |
| 3215 | if (!hci_conn_check_link_mode(conn)) |
| 3216 | ev->status = HCI_ERROR_AUTH_FAILURE; |
| 3217 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3218 | if (ev->status && conn->state == BT_CONNECTED) { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3219 | if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) |
| 3220 | set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 3221 | |
Luiz Augusto von Dentz | 8746f13 | 2020-05-20 14:20:14 -0700 | [diff] [blame] | 3222 | /* Notify upper layers so they can cleanup before |
| 3223 | * disconnecting. |
| 3224 | */ |
| 3225 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3226 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
| 3227 | hci_conn_drop(conn); |
| 3228 | goto unlock; |
| 3229 | } |
| 3230 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3231 | /* Try reading the encryption key size for encrypted ACL links */ |
| 3232 | if (!ev->status && ev->encrypt && conn->type == ACL_LINK) { |
| 3233 | struct hci_cp_read_enc_key_size cp; |
| 3234 | struct hci_request req; |
| 3235 | |
| 3236 | /* Only send HCI_Read_Encryption_Key_Size if the |
| 3237 | * controller really supports it. If it doesn't, assume |
| 3238 | * the default size (16). |
| 3239 | */ |
| 3240 | if (!(hdev->commands[20] & 0x10)) { |
| 3241 | conn->enc_key_size = HCI_LINK_KEY_SIZE; |
| 3242 | goto notify; |
| 3243 | } |
| 3244 | |
| 3245 | hci_req_init(&req, hdev); |
| 3246 | |
| 3247 | cp.handle = cpu_to_le16(conn->handle); |
| 3248 | hci_req_add(&req, HCI_OP_READ_ENC_KEY_SIZE, sizeof(cp), &cp); |
| 3249 | |
| 3250 | if (hci_req_run_skb(&req, read_enc_key_size_complete)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3251 | bt_dev_err(hdev, "sending read key size failed"); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3252 | conn->enc_key_size = HCI_LINK_KEY_SIZE; |
| 3253 | goto notify; |
| 3254 | } |
| 3255 | |
| 3256 | goto unlock; |
| 3257 | } |
| 3258 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 3259 | /* Set the default Authenticated Payload Timeout after |
| 3260 | * an LE Link is established. As per Core Spec v5.0, Vol 2, Part B |
| 3261 | * Section 3.3, the HCI command WRITE_AUTH_PAYLOAD_TIMEOUT should be |
| 3262 | * sent when the link is active and Encryption is enabled, the conn |
| 3263 | * type can be either LE or ACL and controller must support LMP Ping. |
| 3264 | * Ensure for AES-CCM encryption as well. |
| 3265 | */ |
| 3266 | if (test_bit(HCI_CONN_ENCRYPT, &conn->flags) && |
| 3267 | test_bit(HCI_CONN_AES_CCM, &conn->flags) && |
| 3268 | ((conn->type == ACL_LINK && lmp_ping_capable(hdev)) || |
| 3269 | (conn->type == LE_LINK && (hdev->le_features[0] & HCI_LE_PING)))) { |
| 3270 | struct hci_cp_write_auth_payload_to cp; |
| 3271 | |
| 3272 | cp.handle = cpu_to_le16(conn->handle); |
| 3273 | cp.timeout = cpu_to_le16(hdev->auth_payload_timeout); |
| 3274 | hci_send_cmd(conn->hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO, |
| 3275 | sizeof(cp), &cp); |
| 3276 | } |
| 3277 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3278 | notify: |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 3279 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3280 | |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 3281 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3282 | hci_dev_unlock(hdev); |
| 3283 | } |
| 3284 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3285 | static void hci_change_link_key_complete_evt(struct hci_dev *hdev, |
| 3286 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3287 | { |
| 3288 | struct hci_ev_change_link_key_complete *ev = (void *) skb->data; |
| 3289 | struct hci_conn *conn; |
| 3290 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3291 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3292 | |
| 3293 | hci_dev_lock(hdev); |
| 3294 | |
| 3295 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 3296 | if (conn) { |
| 3297 | if (!ev->status) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3298 | set_bit(HCI_CONN_SECURE, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3299 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3300 | clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3301 | |
| 3302 | hci_key_change_cfm(conn, ev->status); |
| 3303 | } |
| 3304 | |
| 3305 | hci_dev_unlock(hdev); |
| 3306 | } |
| 3307 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3308 | static void hci_remote_features_evt(struct hci_dev *hdev, |
| 3309 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3310 | { |
| 3311 | struct hci_ev_remote_features *ev = (void *) skb->data; |
| 3312 | struct hci_conn *conn; |
| 3313 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3314 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3315 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3316 | hci_dev_lock(hdev); |
| 3317 | |
| 3318 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3319 | if (!conn) |
| 3320 | goto unlock; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3321 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3322 | if (!ev->status) |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 3323 | memcpy(conn->features[0], ev->features, 8); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3324 | |
| 3325 | if (conn->state != BT_CONFIG) |
| 3326 | goto unlock; |
| 3327 | |
Szymon Janc | ac363cf | 2015-01-29 16:36:59 +0100 | [diff] [blame] | 3328 | if (!ev->status && lmp_ext_feat_capable(hdev) && |
| 3329 | lmp_ext_feat_capable(conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3330 | struct hci_cp_read_remote_ext_features cp; |
| 3331 | cp.handle = ev->handle; |
| 3332 | cp.page = 0x01; |
| 3333 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3334 | sizeof(cp), &cp); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 3335 | goto unlock; |
| 3336 | } |
| 3337 | |
Johan Hedberg | 671267b | 2012-05-12 16:11:50 -0300 | [diff] [blame] | 3338 | if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3339 | struct hci_cp_remote_name_req cp; |
| 3340 | memset(&cp, 0, sizeof(cp)); |
| 3341 | bacpy(&cp.bdaddr, &conn->dst); |
| 3342 | cp.pscan_rep_mode = 0x02; |
| 3343 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3344 | } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 3345 | mgmt_device_connected(hdev, conn, NULL, 0); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 3346 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3347 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3348 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 3349 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 3350 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3351 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3352 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3353 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3354 | hci_dev_unlock(hdev); |
| 3355 | } |
| 3356 | |
Kiran K | ecb71f25 | 2021-08-16 05:07:47 +0530 | [diff] [blame] | 3357 | static inline void handle_cmd_cnt_and_timer(struct hci_dev *hdev, u8 ncmd) |
Manish Mandlik | de75cd0 | 2021-04-29 10:24:22 -0700 | [diff] [blame] | 3358 | { |
Kiran K | ecb71f25 | 2021-08-16 05:07:47 +0530 | [diff] [blame] | 3359 | cancel_delayed_work(&hdev->cmd_timer); |
Manish Mandlik | de75cd0 | 2021-04-29 10:24:22 -0700 | [diff] [blame] | 3360 | |
| 3361 | if (!test_bit(HCI_RESET, &hdev->flags)) { |
| 3362 | if (ncmd) { |
| 3363 | cancel_delayed_work(&hdev->ncmd_timer); |
| 3364 | atomic_set(&hdev->cmd_cnt, 1); |
| 3365 | } else { |
| 3366 | schedule_delayed_work(&hdev->ncmd_timer, |
| 3367 | HCI_NCMD_TIMEOUT); |
| 3368 | } |
| 3369 | } |
| 3370 | } |
| 3371 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3372 | static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, |
| 3373 | u16 *opcode, u8 *status, |
| 3374 | hci_req_complete_t *req_complete, |
| 3375 | hci_req_complete_skb_t *req_complete_skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3376 | { |
| 3377 | struct hci_ev_cmd_complete *ev = (void *) skb->data; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3378 | |
| 3379 | *opcode = __le16_to_cpu(ev->opcode); |
| 3380 | *status = skb->data[sizeof(*ev)]; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3381 | |
| 3382 | skb_pull(skb, sizeof(*ev)); |
| 3383 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3384 | switch (*opcode) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3385 | case HCI_OP_INQUIRY_CANCEL: |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 3386 | hci_cc_inquiry_cancel(hdev, skb, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3387 | break; |
| 3388 | |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 3389 | case HCI_OP_PERIODIC_INQ: |
| 3390 | hci_cc_periodic_inq(hdev, skb); |
| 3391 | break; |
| 3392 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3393 | case HCI_OP_EXIT_PERIODIC_INQ: |
| 3394 | hci_cc_exit_periodic_inq(hdev, skb); |
| 3395 | break; |
| 3396 | |
| 3397 | case HCI_OP_REMOTE_NAME_REQ_CANCEL: |
| 3398 | hci_cc_remote_name_req_cancel(hdev, skb); |
| 3399 | break; |
| 3400 | |
| 3401 | case HCI_OP_ROLE_DISCOVERY: |
| 3402 | hci_cc_role_discovery(hdev, skb); |
| 3403 | break; |
| 3404 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 3405 | case HCI_OP_READ_LINK_POLICY: |
| 3406 | hci_cc_read_link_policy(hdev, skb); |
| 3407 | break; |
| 3408 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3409 | case HCI_OP_WRITE_LINK_POLICY: |
| 3410 | hci_cc_write_link_policy(hdev, skb); |
| 3411 | break; |
| 3412 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 3413 | case HCI_OP_READ_DEF_LINK_POLICY: |
| 3414 | hci_cc_read_def_link_policy(hdev, skb); |
| 3415 | break; |
| 3416 | |
| 3417 | case HCI_OP_WRITE_DEF_LINK_POLICY: |
| 3418 | hci_cc_write_def_link_policy(hdev, skb); |
| 3419 | break; |
| 3420 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3421 | case HCI_OP_RESET: |
| 3422 | hci_cc_reset(hdev, skb); |
| 3423 | break; |
| 3424 | |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 3425 | case HCI_OP_READ_STORED_LINK_KEY: |
| 3426 | hci_cc_read_stored_link_key(hdev, skb); |
| 3427 | break; |
| 3428 | |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 3429 | case HCI_OP_DELETE_STORED_LINK_KEY: |
| 3430 | hci_cc_delete_stored_link_key(hdev, skb); |
| 3431 | break; |
| 3432 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3433 | case HCI_OP_WRITE_LOCAL_NAME: |
| 3434 | hci_cc_write_local_name(hdev, skb); |
| 3435 | break; |
| 3436 | |
| 3437 | case HCI_OP_READ_LOCAL_NAME: |
| 3438 | hci_cc_read_local_name(hdev, skb); |
| 3439 | break; |
| 3440 | |
| 3441 | case HCI_OP_WRITE_AUTH_ENABLE: |
| 3442 | hci_cc_write_auth_enable(hdev, skb); |
| 3443 | break; |
| 3444 | |
| 3445 | case HCI_OP_WRITE_ENCRYPT_MODE: |
| 3446 | hci_cc_write_encrypt_mode(hdev, skb); |
| 3447 | break; |
| 3448 | |
| 3449 | case HCI_OP_WRITE_SCAN_ENABLE: |
| 3450 | hci_cc_write_scan_enable(hdev, skb); |
| 3451 | break; |
| 3452 | |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 3453 | case HCI_OP_SET_EVENT_FLT: |
| 3454 | hci_cc_set_event_filter(hdev, skb); |
| 3455 | break; |
| 3456 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3457 | case HCI_OP_READ_CLASS_OF_DEV: |
| 3458 | hci_cc_read_class_of_dev(hdev, skb); |
| 3459 | break; |
| 3460 | |
| 3461 | case HCI_OP_WRITE_CLASS_OF_DEV: |
| 3462 | hci_cc_write_class_of_dev(hdev, skb); |
| 3463 | break; |
| 3464 | |
| 3465 | case HCI_OP_READ_VOICE_SETTING: |
| 3466 | hci_cc_read_voice_setting(hdev, skb); |
| 3467 | break; |
| 3468 | |
| 3469 | case HCI_OP_WRITE_VOICE_SETTING: |
| 3470 | hci_cc_write_voice_setting(hdev, skb); |
| 3471 | break; |
| 3472 | |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 3473 | case HCI_OP_READ_NUM_SUPPORTED_IAC: |
| 3474 | hci_cc_read_num_supported_iac(hdev, skb); |
| 3475 | break; |
| 3476 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3477 | case HCI_OP_WRITE_SSP_MODE: |
| 3478 | hci_cc_write_ssp_mode(hdev, skb); |
| 3479 | break; |
| 3480 | |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 3481 | case HCI_OP_WRITE_SC_SUPPORT: |
| 3482 | hci_cc_write_sc_support(hdev, skb); |
| 3483 | break; |
| 3484 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 3485 | case HCI_OP_READ_AUTH_PAYLOAD_TO: |
| 3486 | hci_cc_read_auth_payload_timeout(hdev, skb); |
| 3487 | break; |
| 3488 | |
| 3489 | case HCI_OP_WRITE_AUTH_PAYLOAD_TO: |
| 3490 | hci_cc_write_auth_payload_timeout(hdev, skb); |
| 3491 | break; |
| 3492 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3493 | case HCI_OP_READ_LOCAL_VERSION: |
| 3494 | hci_cc_read_local_version(hdev, skb); |
| 3495 | break; |
| 3496 | |
| 3497 | case HCI_OP_READ_LOCAL_COMMANDS: |
| 3498 | hci_cc_read_local_commands(hdev, skb); |
| 3499 | break; |
| 3500 | |
| 3501 | case HCI_OP_READ_LOCAL_FEATURES: |
| 3502 | hci_cc_read_local_features(hdev, skb); |
| 3503 | break; |
| 3504 | |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 3505 | case HCI_OP_READ_LOCAL_EXT_FEATURES: |
| 3506 | hci_cc_read_local_ext_features(hdev, skb); |
| 3507 | break; |
| 3508 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3509 | case HCI_OP_READ_BUFFER_SIZE: |
| 3510 | hci_cc_read_buffer_size(hdev, skb); |
| 3511 | break; |
| 3512 | |
| 3513 | case HCI_OP_READ_BD_ADDR: |
| 3514 | hci_cc_read_bd_addr(hdev, skb); |
| 3515 | break; |
| 3516 | |
Marcel Holtmann | a479036 | 2020-04-03 21:44:04 +0200 | [diff] [blame] | 3517 | case HCI_OP_READ_LOCAL_PAIRING_OPTS: |
| 3518 | hci_cc_read_local_pairing_opts(hdev, skb); |
| 3519 | break; |
| 3520 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 3521 | case HCI_OP_READ_PAGE_SCAN_ACTIVITY: |
| 3522 | hci_cc_read_page_scan_activity(hdev, skb); |
| 3523 | break; |
| 3524 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 3525 | case HCI_OP_WRITE_PAGE_SCAN_ACTIVITY: |
| 3526 | hci_cc_write_page_scan_activity(hdev, skb); |
| 3527 | break; |
| 3528 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 3529 | case HCI_OP_READ_PAGE_SCAN_TYPE: |
| 3530 | hci_cc_read_page_scan_type(hdev, skb); |
| 3531 | break; |
| 3532 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 3533 | case HCI_OP_WRITE_PAGE_SCAN_TYPE: |
| 3534 | hci_cc_write_page_scan_type(hdev, skb); |
| 3535 | break; |
| 3536 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 3537 | case HCI_OP_READ_DATA_BLOCK_SIZE: |
| 3538 | hci_cc_read_data_block_size(hdev, skb); |
| 3539 | break; |
| 3540 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 3541 | case HCI_OP_READ_FLOW_CONTROL_MODE: |
| 3542 | hci_cc_read_flow_control_mode(hdev, skb); |
| 3543 | break; |
| 3544 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 3545 | case HCI_OP_READ_LOCAL_AMP_INFO: |
| 3546 | hci_cc_read_local_amp_info(hdev, skb); |
| 3547 | break; |
| 3548 | |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 3549 | case HCI_OP_READ_CLOCK: |
| 3550 | hci_cc_read_clock(hdev, skb); |
| 3551 | break; |
| 3552 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 3553 | case HCI_OP_READ_INQ_RSP_TX_POWER: |
| 3554 | hci_cc_read_inq_rsp_tx_power(hdev, skb); |
| 3555 | break; |
| 3556 | |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 3557 | case HCI_OP_READ_DEF_ERR_DATA_REPORTING: |
| 3558 | hci_cc_read_def_err_data_reporting(hdev, skb); |
| 3559 | break; |
| 3560 | |
| 3561 | case HCI_OP_WRITE_DEF_ERR_DATA_REPORTING: |
| 3562 | hci_cc_write_def_err_data_reporting(hdev, skb); |
| 3563 | break; |
| 3564 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 3565 | case HCI_OP_PIN_CODE_REPLY: |
| 3566 | hci_cc_pin_code_reply(hdev, skb); |
| 3567 | break; |
| 3568 | |
| 3569 | case HCI_OP_PIN_CODE_NEG_REPLY: |
| 3570 | hci_cc_pin_code_neg_reply(hdev, skb); |
| 3571 | break; |
| 3572 | |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 3573 | case HCI_OP_READ_LOCAL_OOB_DATA: |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 3574 | hci_cc_read_local_oob_data(hdev, skb); |
| 3575 | break; |
| 3576 | |
| 3577 | case HCI_OP_READ_LOCAL_OOB_EXT_DATA: |
| 3578 | hci_cc_read_local_oob_ext_data(hdev, skb); |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 3579 | break; |
| 3580 | |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 3581 | case HCI_OP_LE_READ_BUFFER_SIZE: |
| 3582 | hci_cc_le_read_buffer_size(hdev, skb); |
| 3583 | break; |
| 3584 | |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 3585 | case HCI_OP_LE_READ_LOCAL_FEATURES: |
| 3586 | hci_cc_le_read_local_features(hdev, skb); |
| 3587 | break; |
| 3588 | |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 3589 | case HCI_OP_LE_READ_ADV_TX_POWER: |
| 3590 | hci_cc_le_read_adv_tx_power(hdev, skb); |
| 3591 | break; |
| 3592 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 3593 | case HCI_OP_USER_CONFIRM_REPLY: |
| 3594 | hci_cc_user_confirm_reply(hdev, skb); |
| 3595 | break; |
| 3596 | |
| 3597 | case HCI_OP_USER_CONFIRM_NEG_REPLY: |
| 3598 | hci_cc_user_confirm_neg_reply(hdev, skb); |
| 3599 | break; |
| 3600 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 3601 | case HCI_OP_USER_PASSKEY_REPLY: |
| 3602 | hci_cc_user_passkey_reply(hdev, skb); |
| 3603 | break; |
| 3604 | |
| 3605 | case HCI_OP_USER_PASSKEY_NEG_REPLY: |
| 3606 | hci_cc_user_passkey_neg_reply(hdev, skb); |
Szymon Janc | 16cde99 | 2012-04-13 12:32:42 +0200 | [diff] [blame] | 3607 | break; |
Andre Guedes | 07f7fa5 | 2011-12-02 21:13:31 +0900 | [diff] [blame] | 3608 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 3609 | case HCI_OP_LE_SET_RANDOM_ADDR: |
| 3610 | hci_cc_le_set_random_addr(hdev, skb); |
| 3611 | break; |
| 3612 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 3613 | case HCI_OP_LE_SET_ADV_ENABLE: |
| 3614 | hci_cc_le_set_adv_enable(hdev, skb); |
| 3615 | break; |
| 3616 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 3617 | case HCI_OP_LE_SET_SCAN_PARAM: |
| 3618 | hci_cc_le_set_scan_param(hdev, skb); |
| 3619 | break; |
| 3620 | |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 3621 | case HCI_OP_LE_SET_SCAN_ENABLE: |
| 3622 | hci_cc_le_set_scan_enable(hdev, skb); |
| 3623 | break; |
| 3624 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 3625 | case HCI_OP_LE_READ_ACCEPT_LIST_SIZE: |
| 3626 | hci_cc_le_read_accept_list_size(hdev, skb); |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 3627 | break; |
| 3628 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 3629 | case HCI_OP_LE_CLEAR_ACCEPT_LIST: |
| 3630 | hci_cc_le_clear_accept_list(hdev, skb); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 3631 | break; |
| 3632 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 3633 | case HCI_OP_LE_ADD_TO_ACCEPT_LIST: |
| 3634 | hci_cc_le_add_to_accept_list(hdev, skb); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 3635 | break; |
| 3636 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 3637 | case HCI_OP_LE_DEL_FROM_ACCEPT_LIST: |
| 3638 | hci_cc_le_del_from_accept_list(hdev, skb); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 3639 | break; |
| 3640 | |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 3641 | case HCI_OP_LE_READ_SUPPORTED_STATES: |
| 3642 | hci_cc_le_read_supported_states(hdev, skb); |
| 3643 | break; |
| 3644 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 3645 | case HCI_OP_LE_READ_DEF_DATA_LEN: |
| 3646 | hci_cc_le_read_def_data_len(hdev, skb); |
| 3647 | break; |
| 3648 | |
| 3649 | case HCI_OP_LE_WRITE_DEF_DATA_LEN: |
| 3650 | hci_cc_le_write_def_data_len(hdev, skb); |
| 3651 | break; |
| 3652 | |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 3653 | case HCI_OP_LE_ADD_TO_RESOLV_LIST: |
| 3654 | hci_cc_le_add_to_resolv_list(hdev, skb); |
| 3655 | break; |
| 3656 | |
| 3657 | case HCI_OP_LE_DEL_FROM_RESOLV_LIST: |
| 3658 | hci_cc_le_del_from_resolv_list(hdev, skb); |
| 3659 | break; |
| 3660 | |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 3661 | case HCI_OP_LE_CLEAR_RESOLV_LIST: |
| 3662 | hci_cc_le_clear_resolv_list(hdev, skb); |
| 3663 | break; |
| 3664 | |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 3665 | case HCI_OP_LE_READ_RESOLV_LIST_SIZE: |
| 3666 | hci_cc_le_read_resolv_list_size(hdev, skb); |
| 3667 | break; |
| 3668 | |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 3669 | case HCI_OP_LE_SET_ADDR_RESOLV_ENABLE: |
| 3670 | hci_cc_le_set_addr_resolution_enable(hdev, skb); |
| 3671 | break; |
| 3672 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 3673 | case HCI_OP_LE_READ_MAX_DATA_LEN: |
| 3674 | hci_cc_le_read_max_data_len(hdev, skb); |
| 3675 | break; |
| 3676 | |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 3677 | case HCI_OP_WRITE_LE_HOST_SUPPORTED: |
| 3678 | hci_cc_write_le_host_supported(hdev, skb); |
| 3679 | break; |
| 3680 | |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 3681 | case HCI_OP_LE_SET_ADV_PARAM: |
| 3682 | hci_cc_set_adv_param(hdev, skb); |
| 3683 | break; |
| 3684 | |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 3685 | case HCI_OP_READ_RSSI: |
| 3686 | hci_cc_read_rssi(hdev, skb); |
| 3687 | break; |
| 3688 | |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 3689 | case HCI_OP_READ_TX_POWER: |
| 3690 | hci_cc_read_tx_power(hdev, skb); |
| 3691 | break; |
| 3692 | |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 3693 | case HCI_OP_WRITE_SSP_DEBUG_MODE: |
| 3694 | hci_cc_write_ssp_debug_mode(hdev, skb); |
| 3695 | break; |
| 3696 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 3697 | case HCI_OP_LE_SET_EXT_SCAN_PARAMS: |
| 3698 | hci_cc_le_set_ext_scan_param(hdev, skb); |
| 3699 | break; |
| 3700 | |
| 3701 | case HCI_OP_LE_SET_EXT_SCAN_ENABLE: |
| 3702 | hci_cc_le_set_ext_scan_enable(hdev, skb); |
| 3703 | break; |
| 3704 | |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 3705 | case HCI_OP_LE_SET_DEFAULT_PHY: |
| 3706 | hci_cc_le_set_default_phy(hdev, skb); |
| 3707 | break; |
| 3708 | |
Jaganath Kanakkassery | 6b49bcb | 2018-07-19 17:09:40 +0530 | [diff] [blame] | 3709 | case HCI_OP_LE_READ_NUM_SUPPORTED_ADV_SETS: |
| 3710 | hci_cc_le_read_num_adv_sets(hdev, skb); |
| 3711 | break; |
| 3712 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 3713 | case HCI_OP_LE_SET_EXT_ADV_PARAMS: |
| 3714 | hci_cc_set_ext_adv_param(hdev, skb); |
| 3715 | break; |
| 3716 | |
| 3717 | case HCI_OP_LE_SET_EXT_ADV_ENABLE: |
| 3718 | hci_cc_le_set_ext_adv_enable(hdev, skb); |
| 3719 | break; |
| 3720 | |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 3721 | case HCI_OP_LE_SET_ADV_SET_RAND_ADDR: |
| 3722 | hci_cc_le_set_adv_set_random_addr(hdev, skb); |
| 3723 | break; |
| 3724 | |
Daniel Winkler | 7c395ea | 2020-12-03 12:12:51 -0800 | [diff] [blame] | 3725 | case HCI_OP_LE_READ_TRANSMIT_POWER: |
| 3726 | hci_cc_le_read_transmit_power(hdev, skb); |
| 3727 | break; |
| 3728 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3729 | default: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3730 | BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3731 | break; |
| 3732 | } |
| 3733 | |
Kiran K | ecb71f25 | 2021-08-16 05:07:47 +0530 | [diff] [blame] | 3734 | handle_cmd_cnt_and_timer(hdev, ev->ncmd); |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 3735 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3736 | hci_req_cmd_complete(hdev, *opcode, *status, req_complete, |
| 3737 | req_complete_skb); |
Johan Hedberg | 9238f36 | 2013-03-05 20:37:48 +0200 | [diff] [blame] | 3738 | |
João Paulo Rechi Vita | f80c5da | 2019-05-02 10:01:52 +0800 | [diff] [blame] | 3739 | if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) { |
| 3740 | bt_dev_err(hdev, |
| 3741 | "unexpected event for opcode 0x%4.4x", *opcode); |
| 3742 | return; |
| 3743 | } |
| 3744 | |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 3745 | if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) |
| 3746 | queue_work(hdev->workqueue, &hdev->cmd_work); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3747 | } |
| 3748 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3749 | static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb, |
| 3750 | u16 *opcode, u8 *status, |
| 3751 | hci_req_complete_t *req_complete, |
| 3752 | hci_req_complete_skb_t *req_complete_skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3753 | { |
| 3754 | struct hci_ev_cmd_status *ev = (void *) skb->data; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3755 | |
| 3756 | skb_pull(skb, sizeof(*ev)); |
| 3757 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3758 | *opcode = __le16_to_cpu(ev->opcode); |
| 3759 | *status = ev->status; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3760 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3761 | switch (*opcode) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3762 | case HCI_OP_INQUIRY: |
| 3763 | hci_cs_inquiry(hdev, ev->status); |
| 3764 | break; |
| 3765 | |
| 3766 | case HCI_OP_CREATE_CONN: |
| 3767 | hci_cs_create_conn(hdev, ev->status); |
| 3768 | break; |
| 3769 | |
Kuba Pawlak | 9645c76 | 2014-11-06 19:36:53 +0100 | [diff] [blame] | 3770 | case HCI_OP_DISCONNECT: |
| 3771 | hci_cs_disconnect(hdev, ev->status); |
| 3772 | break; |
| 3773 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3774 | case HCI_OP_ADD_SCO: |
| 3775 | hci_cs_add_sco(hdev, ev->status); |
| 3776 | break; |
| 3777 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3778 | case HCI_OP_AUTH_REQUESTED: |
| 3779 | hci_cs_auth_requested(hdev, ev->status); |
| 3780 | break; |
| 3781 | |
| 3782 | case HCI_OP_SET_CONN_ENCRYPT: |
| 3783 | hci_cs_set_conn_encrypt(hdev, ev->status); |
| 3784 | break; |
| 3785 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3786 | case HCI_OP_REMOTE_NAME_REQ: |
| 3787 | hci_cs_remote_name_req(hdev, ev->status); |
| 3788 | break; |
| 3789 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3790 | case HCI_OP_READ_REMOTE_FEATURES: |
| 3791 | hci_cs_read_remote_features(hdev, ev->status); |
| 3792 | break; |
| 3793 | |
| 3794 | case HCI_OP_READ_REMOTE_EXT_FEATURES: |
| 3795 | hci_cs_read_remote_ext_features(hdev, ev->status); |
| 3796 | break; |
| 3797 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3798 | case HCI_OP_SETUP_SYNC_CONN: |
| 3799 | hci_cs_setup_sync_conn(hdev, ev->status); |
| 3800 | break; |
| 3801 | |
Kiran K | b2af264 | 2021-09-07 15:42:43 +0530 | [diff] [blame] | 3802 | case HCI_OP_ENHANCED_SETUP_SYNC_CONN: |
| 3803 | hci_cs_enhanced_setup_sync_conn(hdev, ev->status); |
| 3804 | break; |
| 3805 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3806 | case HCI_OP_SNIFF_MODE: |
| 3807 | hci_cs_sniff_mode(hdev, ev->status); |
| 3808 | break; |
| 3809 | |
| 3810 | case HCI_OP_EXIT_SNIFF_MODE: |
| 3811 | hci_cs_exit_sniff_mode(hdev, ev->status); |
| 3812 | break; |
| 3813 | |
Kuba Pawlak | 50fc85f | 2014-11-06 19:36:52 +0100 | [diff] [blame] | 3814 | case HCI_OP_SWITCH_ROLE: |
| 3815 | hci_cs_switch_role(hdev, ev->status); |
| 3816 | break; |
| 3817 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 3818 | case HCI_OP_LE_CREATE_CONN: |
| 3819 | hci_cs_le_create_conn(hdev, ev->status); |
| 3820 | break; |
| 3821 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 3822 | case HCI_OP_LE_READ_REMOTE_FEATURES: |
| 3823 | hci_cs_le_read_remote_features(hdev, ev->status); |
| 3824 | break; |
| 3825 | |
Johan Hedberg | 81d0c8a | 2014-03-24 14:39:04 +0200 | [diff] [blame] | 3826 | case HCI_OP_LE_START_ENC: |
| 3827 | hci_cs_le_start_enc(hdev, ev->status); |
| 3828 | break; |
| 3829 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 3830 | case HCI_OP_LE_EXT_CREATE_CONN: |
| 3831 | hci_cs_le_ext_create_conn(hdev, ev->status); |
| 3832 | break; |
| 3833 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3834 | default: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3835 | BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3836 | break; |
| 3837 | } |
| 3838 | |
Kiran K | ecb71f25 | 2021-08-16 05:07:47 +0530 | [diff] [blame] | 3839 | handle_cmd_cnt_and_timer(hdev, ev->ncmd); |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 3840 | |
Johan Hedberg | 444c6dd | 2015-04-02 13:41:07 +0300 | [diff] [blame] | 3841 | /* Indicate request completion if the command failed. Also, if |
| 3842 | * we're not waiting for a special event and we get a success |
| 3843 | * command status we should try to flag the request as completed |
| 3844 | * (since for this kind of commands there will not be a command |
| 3845 | * complete event). |
| 3846 | */ |
Johan Hedberg | 02350a7 | 2013-04-03 21:50:29 +0300 | [diff] [blame] | 3847 | if (ev->status || |
Marcel Holtmann | 242c0eb | 2015-10-25 22:45:53 +0100 | [diff] [blame] | 3848 | (hdev->sent_cmd && !bt_cb(hdev->sent_cmd)->hci.req_event)) |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3849 | hci_req_cmd_complete(hdev, *opcode, ev->status, req_complete, |
| 3850 | req_complete_skb); |
Johan Hedberg | 9238f36 | 2013-03-05 20:37:48 +0200 | [diff] [blame] | 3851 | |
João Paulo Rechi Vita | f80c5da | 2019-05-02 10:01:52 +0800 | [diff] [blame] | 3852 | if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) { |
| 3853 | bt_dev_err(hdev, |
| 3854 | "unexpected event for opcode 0x%4.4x", *opcode); |
| 3855 | return; |
| 3856 | } |
| 3857 | |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 3858 | if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) |
| 3859 | queue_work(hdev->workqueue, &hdev->cmd_work); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3860 | } |
| 3861 | |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 3862 | static void hci_hardware_error_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 3863 | { |
| 3864 | struct hci_ev_hardware_error *ev = (void *) skb->data; |
| 3865 | |
Marcel Holtmann | c7741d1 | 2015-01-28 11:09:55 -0800 | [diff] [blame] | 3866 | hdev->hw_error_code = ev->code; |
| 3867 | |
| 3868 | queue_work(hdev->req_workqueue, &hdev->error_reset); |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 3869 | } |
| 3870 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3871 | 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] | 3872 | { |
| 3873 | struct hci_ev_role_change *ev = (void *) skb->data; |
| 3874 | struct hci_conn *conn; |
| 3875 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3876 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3877 | |
| 3878 | hci_dev_lock(hdev); |
| 3879 | |
| 3880 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 3881 | if (conn) { |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 3882 | if (!ev->status) |
| 3883 | conn->role = ev->role; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3884 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3885 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3886 | |
| 3887 | hci_role_switch_cfm(conn, ev->status, ev->role); |
| 3888 | } |
| 3889 | |
| 3890 | hci_dev_unlock(hdev); |
| 3891 | } |
| 3892 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3893 | 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] | 3894 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3895 | struct hci_ev_num_comp_pkts *ev = (void *) skb->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3896 | int i; |
| 3897 | |
Andrei Emeltchenko | 32ac5b9 | 2011-12-19 16:31:29 +0200 | [diff] [blame] | 3898 | if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_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 | 32ac5b9 | 2011-12-19 16:31:29 +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)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3905 | BT_DBG("%s bad parameters", hdev->name); |
| 3906 | return; |
| 3907 | } |
| 3908 | |
Andrei Emeltchenko | c5993de | 2011-12-30 12:07:47 +0200 | [diff] [blame] | 3909 | BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl); |
| 3910 | |
Andrei Emeltchenko | 613a1c0 | 2011-12-19 16:31:30 +0200 | [diff] [blame] | 3911 | for (i = 0; i < ev->num_hndl; i++) { |
| 3912 | struct hci_comp_pkts_info *info = &ev->handles[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3913 | struct hci_conn *conn; |
| 3914 | __u16 handle, count; |
| 3915 | |
Andrei Emeltchenko | 613a1c0 | 2011-12-19 16:31:30 +0200 | [diff] [blame] | 3916 | handle = __le16_to_cpu(info->handle); |
| 3917 | count = __le16_to_cpu(info->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | |
| 3919 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 3920 | if (!conn) |
| 3921 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 3923 | conn->sent -= count; |
| 3924 | |
| 3925 | switch (conn->type) { |
| 3926 | case ACL_LINK: |
| 3927 | hdev->acl_cnt += count; |
| 3928 | if (hdev->acl_cnt > hdev->acl_pkts) |
| 3929 | hdev->acl_cnt = hdev->acl_pkts; |
| 3930 | break; |
| 3931 | |
| 3932 | case LE_LINK: |
| 3933 | if (hdev->le_pkts) { |
| 3934 | hdev->le_cnt += count; |
| 3935 | if (hdev->le_cnt > hdev->le_pkts) |
| 3936 | hdev->le_cnt = hdev->le_pkts; |
| 3937 | } else { |
Andrei Emeltchenko | 70f23020 | 2010-12-01 16:58:25 +0200 | [diff] [blame] | 3938 | hdev->acl_cnt += count; |
| 3939 | if (hdev->acl_cnt > hdev->acl_pkts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | hdev->acl_cnt = hdev->acl_pkts; |
| 3941 | } |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 3942 | break; |
| 3943 | |
| 3944 | case SCO_LINK: |
| 3945 | hdev->sco_cnt += count; |
| 3946 | if (hdev->sco_cnt > hdev->sco_pkts) |
| 3947 | hdev->sco_cnt = hdev->sco_pkts; |
| 3948 | break; |
| 3949 | |
| 3950 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3951 | bt_dev_err(hdev, "unknown type %d conn %p", |
| 3952 | conn->type, conn); |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 3953 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3954 | } |
| 3955 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3956 | |
Gustavo F. Padovan | 3eff45e | 2011-12-15 00:50:02 -0200 | [diff] [blame] | 3957 | queue_work(hdev->workqueue, &hdev->tx_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | } |
| 3959 | |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 3960 | static struct hci_conn *__hci_conn_lookup_handle(struct hci_dev *hdev, |
| 3961 | __u16 handle) |
| 3962 | { |
| 3963 | struct hci_chan *chan; |
| 3964 | |
| 3965 | switch (hdev->dev_type) { |
Marcel Holtmann | ca8bee5 | 2016-07-05 14:30:14 +0200 | [diff] [blame] | 3966 | case HCI_PRIMARY: |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 3967 | return hci_conn_hash_lookup_handle(hdev, handle); |
| 3968 | case HCI_AMP: |
| 3969 | chan = hci_chan_lookup_handle(hdev, handle); |
| 3970 | if (chan) |
| 3971 | return chan->conn; |
| 3972 | break; |
| 3973 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3974 | bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type); |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 3975 | break; |
| 3976 | } |
| 3977 | |
| 3978 | return NULL; |
| 3979 | } |
| 3980 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3981 | 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] | 3982 | { |
| 3983 | struct hci_ev_num_comp_blocks *ev = (void *) skb->data; |
| 3984 | int i; |
| 3985 | |
| 3986 | if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3987 | 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] | 3988 | return; |
| 3989 | } |
| 3990 | |
Gustavo A. R. Silva | 16e1834 | 2019-02-07 18:40:33 -0600 | [diff] [blame] | 3991 | if (skb->len < sizeof(*ev) || |
| 3992 | skb->len < struct_size(ev, handles, ev->num_hndl)) { |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3993 | BT_DBG("%s bad parameters", hdev->name); |
| 3994 | return; |
| 3995 | } |
| 3996 | |
| 3997 | 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] | 3998 | ev->num_hndl); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 3999 | |
| 4000 | for (i = 0; i < ev->num_hndl; i++) { |
| 4001 | struct hci_comp_blocks_info *info = &ev->handles[i]; |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 4002 | struct hci_conn *conn = NULL; |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4003 | __u16 handle, block_count; |
| 4004 | |
| 4005 | handle = __le16_to_cpu(info->handle); |
| 4006 | block_count = __le16_to_cpu(info->blocks); |
| 4007 | |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 4008 | conn = __hci_conn_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4009 | if (!conn) |
| 4010 | continue; |
| 4011 | |
| 4012 | conn->sent -= block_count; |
| 4013 | |
| 4014 | switch (conn->type) { |
| 4015 | case ACL_LINK: |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 4016 | case AMP_LINK: |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4017 | hdev->block_cnt += block_count; |
| 4018 | if (hdev->block_cnt > hdev->num_blocks) |
| 4019 | hdev->block_cnt = hdev->num_blocks; |
| 4020 | break; |
| 4021 | |
| 4022 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4023 | bt_dev_err(hdev, "unknown type %d conn %p", |
| 4024 | conn->type, conn); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4025 | break; |
| 4026 | } |
| 4027 | } |
| 4028 | |
| 4029 | queue_work(hdev->workqueue, &hdev->tx_work); |
| 4030 | } |
| 4031 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4032 | 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] | 4033 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4034 | struct hci_ev_mode_change *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4035 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4036 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4037 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4038 | |
| 4039 | hci_dev_lock(hdev); |
| 4040 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4041 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 4042 | if (conn) { |
| 4043 | conn->mode = ev->mode; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4044 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 4045 | if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, |
| 4046 | &conn->flags)) { |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4047 | if (conn->mode == HCI_CM_ACTIVE) |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 4048 | set_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4049 | else |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 4050 | clear_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4051 | } |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 4052 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 4053 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 4054 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | hci_dev_unlock(hdev); |
| 4058 | } |
| 4059 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4060 | 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] | 4061 | { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4062 | struct hci_ev_pin_code_req *ev = (void *) skb->data; |
| 4063 | struct hci_conn *conn; |
| 4064 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4065 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4066 | |
| 4067 | hci_dev_lock(hdev); |
| 4068 | |
| 4069 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Waldemar Rymarkiewicz | b6f9804 | 2011-09-23 10:01:30 +0200 | [diff] [blame] | 4070 | if (!conn) |
| 4071 | goto unlock; |
| 4072 | |
| 4073 | if (conn->state == BT_CONNECTED) { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4074 | hci_conn_hold(conn); |
| 4075 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4076 | hci_conn_drop(conn); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4077 | } |
| 4078 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4079 | if (!hci_dev_test_flag(hdev, HCI_BONDABLE) && |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 4080 | !test_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags)) { |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4081 | hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4082 | sizeof(ev->bdaddr), &ev->bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4083 | } else if (hci_dev_test_flag(hdev, HCI_MGMT)) { |
Waldemar Rymarkiewicz | a770bb5 | 2011-04-28 12:07:59 +0200 | [diff] [blame] | 4084 | u8 secure; |
| 4085 | |
| 4086 | if (conn->pending_sec_level == BT_SECURITY_HIGH) |
| 4087 | secure = 1; |
| 4088 | else |
| 4089 | secure = 0; |
| 4090 | |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 4091 | mgmt_pin_code_request(hdev, &ev->bdaddr, secure); |
Waldemar Rymarkiewicz | a770bb5 | 2011-04-28 12:07:59 +0200 | [diff] [blame] | 4092 | } |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 4093 | |
Waldemar Rymarkiewicz | b6f9804 | 2011-09-23 10:01:30 +0200 | [diff] [blame] | 4094 | unlock: |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4095 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4096 | } |
| 4097 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4098 | static void conn_set_key(struct hci_conn *conn, u8 key_type, u8 pin_len) |
| 4099 | { |
| 4100 | if (key_type == HCI_LK_CHANGED_COMBINATION) |
| 4101 | return; |
| 4102 | |
| 4103 | conn->pin_length = pin_len; |
| 4104 | conn->key_type = key_type; |
| 4105 | |
| 4106 | switch (key_type) { |
| 4107 | case HCI_LK_LOCAL_UNIT: |
| 4108 | case HCI_LK_REMOTE_UNIT: |
| 4109 | case HCI_LK_DEBUG_COMBINATION: |
| 4110 | return; |
| 4111 | case HCI_LK_COMBINATION: |
| 4112 | if (pin_len == 16) |
| 4113 | conn->pending_sec_level = BT_SECURITY_HIGH; |
| 4114 | else |
| 4115 | conn->pending_sec_level = BT_SECURITY_MEDIUM; |
| 4116 | break; |
| 4117 | case HCI_LK_UNAUTH_COMBINATION_P192: |
| 4118 | case HCI_LK_UNAUTH_COMBINATION_P256: |
| 4119 | conn->pending_sec_level = BT_SECURITY_MEDIUM; |
| 4120 | break; |
| 4121 | case HCI_LK_AUTH_COMBINATION_P192: |
| 4122 | conn->pending_sec_level = BT_SECURITY_HIGH; |
| 4123 | break; |
| 4124 | case HCI_LK_AUTH_COMBINATION_P256: |
| 4125 | conn->pending_sec_level = BT_SECURITY_FIPS; |
| 4126 | break; |
| 4127 | } |
| 4128 | } |
| 4129 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4130 | 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] | 4131 | { |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4132 | struct hci_ev_link_key_req *ev = (void *) skb->data; |
| 4133 | struct hci_cp_link_key_reply cp; |
| 4134 | struct hci_conn *conn; |
| 4135 | struct link_key *key; |
| 4136 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4137 | BT_DBG("%s", hdev->name); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4138 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4139 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4140 | return; |
| 4141 | |
| 4142 | hci_dev_lock(hdev); |
| 4143 | |
| 4144 | key = hci_find_link_key(hdev, &ev->bdaddr); |
| 4145 | if (!key) { |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 4146 | BT_DBG("%s link key not found for %pMR", hdev->name, |
| 4147 | &ev->bdaddr); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4148 | goto not_found; |
| 4149 | } |
| 4150 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 4151 | BT_DBG("%s found key type %u for %pMR", hdev->name, key->type, |
| 4152 | &ev->bdaddr); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4153 | |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4154 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4155 | if (conn) { |
Johan Hedberg | fe8bc5a | 2014-08-14 12:33:17 +0300 | [diff] [blame] | 4156 | clear_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags); |
| 4157 | |
Marcel Holtmann | 66138ce | 2014-01-10 02:07:20 -0800 | [diff] [blame] | 4158 | if ((key->type == HCI_LK_UNAUTH_COMBINATION_P192 || |
| 4159 | key->type == HCI_LK_UNAUTH_COMBINATION_P256) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4160 | conn->auth_type != 0xff && (conn->auth_type & 0x01)) { |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4161 | BT_DBG("%s ignoring unauthenticated key", hdev->name); |
| 4162 | goto not_found; |
| 4163 | } |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4164 | |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4165 | if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 && |
Johan Hedberg | f3fb0b5 | 2014-06-02 10:12:44 +0300 | [diff] [blame] | 4166 | (conn->pending_sec_level == BT_SECURITY_HIGH || |
| 4167 | conn->pending_sec_level == BT_SECURITY_FIPS)) { |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 4168 | BT_DBG("%s ignoring key unauthenticated for high security", |
| 4169 | hdev->name); |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4170 | goto not_found; |
| 4171 | } |
| 4172 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4173 | conn_set_key(conn, key->type, key->pin_len); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9b3b446 | 2012-05-23 11:31:20 +0300 | [diff] [blame] | 4177 | memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4178 | |
| 4179 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp); |
| 4180 | |
| 4181 | hci_dev_unlock(hdev); |
| 4182 | |
| 4183 | return; |
| 4184 | |
| 4185 | not_found: |
| 4186 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr); |
| 4187 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4188 | } |
| 4189 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4190 | 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] | 4191 | { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4192 | struct hci_ev_link_key_notify *ev = (void *) skb->data; |
| 4193 | struct hci_conn *conn; |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4194 | struct link_key *key; |
| 4195 | bool persistent; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4196 | u8 pin_len = 0; |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4197 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4198 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4199 | |
| 4200 | hci_dev_lock(hdev); |
| 4201 | |
| 4202 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4203 | if (!conn) |
| 4204 | goto unlock; |
| 4205 | |
| 4206 | hci_conn_hold(conn); |
| 4207 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
| 4208 | hci_conn_drop(conn); |
| 4209 | |
Johan Hedberg | fe8bc5a | 2014-08-14 12:33:17 +0300 | [diff] [blame] | 4210 | set_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4211 | conn_set_key(conn, ev->key_type, conn->pin_length); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4212 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4213 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4214 | goto unlock; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4215 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4216 | key = hci_add_link_key(hdev, conn, &ev->bdaddr, ev->link_key, |
| 4217 | ev->key_type, pin_len, &persistent); |
| 4218 | if (!key) |
| 4219 | goto unlock; |
| 4220 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4221 | /* Update connection information since adding the key will have |
| 4222 | * fixed up the type in the case of changed combination keys. |
| 4223 | */ |
| 4224 | if (ev->key_type == HCI_LK_CHANGED_COMBINATION) |
| 4225 | conn_set_key(conn, key->type, key->pin_len); |
| 4226 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4227 | mgmt_new_link_key(hdev, key, persistent); |
| 4228 | |
Johan Hedberg | 6d5650c | 2014-06-24 13:15:51 +0300 | [diff] [blame] | 4229 | /* Keep debug keys around only if the HCI_KEEP_DEBUG_KEYS flag |
| 4230 | * is set. If it's not set simply remove the key from the kernel |
| 4231 | * list (we've still notified user space about it but with |
| 4232 | * store_hint being 0). |
| 4233 | */ |
| 4234 | if (key->type == HCI_LK_DEBUG_COMBINATION && |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4235 | !hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) { |
Johan Hedberg | 0378b59 | 2014-11-19 15:22:22 +0200 | [diff] [blame] | 4236 | list_del_rcu(&key->list); |
| 4237 | kfree_rcu(key, rcu); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4238 | goto unlock; |
Johan Hedberg | 6d5650c | 2014-06-24 13:15:51 +0300 | [diff] [blame] | 4239 | } |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4240 | |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4241 | if (persistent) |
| 4242 | clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags); |
| 4243 | else |
| 4244 | set_bit(HCI_CONN_FLUSH_KEY, &conn->flags); |
| 4245 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4246 | unlock: |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4247 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4248 | } |
| 4249 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4250 | 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] | 4251 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4252 | struct hci_ev_clock_offset *ev = (void *) skb->data; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4253 | struct hci_conn *conn; |
| 4254 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4255 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4256 | |
| 4257 | hci_dev_lock(hdev); |
| 4258 | |
| 4259 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4260 | if (conn && !ev->status) { |
| 4261 | struct inquiry_entry *ie; |
| 4262 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4263 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 4264 | if (ie) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | ie->data.clock_offset = ev->clock_offset; |
| 4266 | ie->timestamp = jiffies; |
| 4267 | } |
| 4268 | } |
| 4269 | |
| 4270 | hci_dev_unlock(hdev); |
| 4271 | } |
| 4272 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4273 | 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] | 4274 | { |
| 4275 | struct hci_ev_pkt_type_change *ev = (void *) skb->data; |
| 4276 | struct hci_conn *conn; |
| 4277 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4278 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4279 | |
| 4280 | hci_dev_lock(hdev); |
| 4281 | |
| 4282 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 4283 | if (conn && !ev->status) |
| 4284 | conn->pkt_type = __le16_to_cpu(ev->pkt_type); |
| 4285 | |
| 4286 | hci_dev_unlock(hdev); |
| 4287 | } |
| 4288 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4289 | 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] | 4290 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4291 | struct hci_ev_pscan_rep_mode *ev = (void *) skb->data; |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 4292 | struct inquiry_entry *ie; |
| 4293 | |
| 4294 | BT_DBG("%s", hdev->name); |
| 4295 | |
| 4296 | hci_dev_lock(hdev); |
| 4297 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4298 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 4299 | if (ie) { |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 4300 | ie->data.pscan_rep_mode = ev->pscan_rep_mode; |
| 4301 | ie->timestamp = jiffies; |
| 4302 | } |
| 4303 | |
| 4304 | hci_dev_unlock(hdev); |
| 4305 | } |
| 4306 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4307 | static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, |
| 4308 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4309 | { |
| 4310 | struct inquiry_data data; |
| 4311 | int num_rsp = *((__u8 *) skb->data); |
| 4312 | |
| 4313 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 4314 | |
| 4315 | if (!num_rsp) |
| 4316 | return; |
| 4317 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4318 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 4319 | return; |
| 4320 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4321 | hci_dev_lock(hdev); |
| 4322 | |
| 4323 | if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 4324 | struct inquiry_info_with_rssi_and_pscan_mode *info; |
| 4325 | info = (void *) (skb->data + 1); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4326 | |
Peilin Ye | 629b49c | 2020-07-10 17:45:26 -0400 | [diff] [blame] | 4327 | if (skb->len < num_rsp * sizeof(*info) + 1) |
| 4328 | goto unlock; |
| 4329 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 4330 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4331 | u32 flags; |
| 4332 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4333 | bacpy(&data.bdaddr, &info->bdaddr); |
| 4334 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4335 | data.pscan_period_mode = info->pscan_period_mode; |
| 4336 | data.pscan_mode = info->pscan_mode; |
| 4337 | memcpy(data.dev_class, info->dev_class, 3); |
| 4338 | data.clock_offset = info->clock_offset; |
| 4339 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4340 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 4341 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4342 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 4343 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 4344 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 4345 | info->dev_class, info->rssi, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4346 | flags, NULL, 0, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4347 | } |
| 4348 | } else { |
| 4349 | struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); |
| 4350 | |
Peilin Ye | 629b49c | 2020-07-10 17:45:26 -0400 | [diff] [blame] | 4351 | if (skb->len < num_rsp * sizeof(*info) + 1) |
| 4352 | goto unlock; |
| 4353 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 4354 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4355 | u32 flags; |
| 4356 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4357 | bacpy(&data.bdaddr, &info->bdaddr); |
| 4358 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4359 | data.pscan_period_mode = info->pscan_period_mode; |
| 4360 | data.pscan_mode = 0x00; |
| 4361 | memcpy(data.dev_class, info->dev_class, 3); |
| 4362 | data.clock_offset = info->clock_offset; |
| 4363 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4364 | data.ssp_mode = 0x00; |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4365 | |
| 4366 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 4367 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 4368 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 4369 | info->dev_class, info->rssi, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4370 | flags, NULL, 0, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4371 | } |
| 4372 | } |
| 4373 | |
Peilin Ye | 629b49c | 2020-07-10 17:45:26 -0400 | [diff] [blame] | 4374 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4375 | hci_dev_unlock(hdev); |
| 4376 | } |
| 4377 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4378 | static void hci_remote_ext_features_evt(struct hci_dev *hdev, |
| 4379 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4380 | { |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4381 | struct hci_ev_remote_ext_features *ev = (void *) skb->data; |
| 4382 | struct hci_conn *conn; |
| 4383 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4384 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4385 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4386 | hci_dev_lock(hdev); |
| 4387 | |
| 4388 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4389 | if (!conn) |
| 4390 | goto unlock; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4391 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 4392 | if (ev->page < HCI_MAX_PAGES) |
| 4393 | memcpy(conn->features[ev->page], ev->features, 8); |
| 4394 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4395 | if (!ev->status && ev->page == 0x01) { |
| 4396 | struct inquiry_entry *ie; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4397 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4398 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 4399 | if (ie) |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 4400 | ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 4401 | |
Jaganath Kanakkassery | bbb0ead | 2013-04-16 20:16:30 +0530 | [diff] [blame] | 4402 | if (ev->features[0] & LMP_HOST_SSP) { |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 4403 | set_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
Jaganath Kanakkassery | bbb0ead | 2013-04-16 20:16:30 +0530 | [diff] [blame] | 4404 | } else { |
| 4405 | /* It is mandatory by the Bluetooth specification that |
| 4406 | * Extended Inquiry Results are only used when Secure |
| 4407 | * Simple Pairing is enabled, but some devices violate |
| 4408 | * this. |
| 4409 | * |
| 4410 | * To make these devices work, the internal SSP |
| 4411 | * enabled flag needs to be cleared if the remote host |
| 4412 | * features do not indicate SSP support */ |
| 4413 | clear_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
| 4414 | } |
Marcel Holtmann | eb9a8f3 | 2014-01-15 22:37:38 -0800 | [diff] [blame] | 4415 | |
| 4416 | if (ev->features[0] & LMP_HOST_SC) |
| 4417 | set_bit(HCI_CONN_SC_ENABLED, &conn->flags); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4418 | } |
| 4419 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4420 | if (conn->state != BT_CONFIG) |
| 4421 | goto unlock; |
| 4422 | |
Johan Hedberg | 671267b | 2012-05-12 16:11:50 -0300 | [diff] [blame] | 4423 | if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 4424 | struct hci_cp_remote_name_req cp; |
| 4425 | memset(&cp, 0, sizeof(cp)); |
| 4426 | bacpy(&cp.bdaddr, &conn->dst); |
| 4427 | cp.pscan_rep_mode = 0x02; |
| 4428 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 4429 | } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 4430 | mgmt_device_connected(hdev, conn, NULL, 0); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 4431 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 4432 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4433 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 4434 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4435 | hci_conn_drop(conn); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 4436 | } |
| 4437 | |
| 4438 | unlock: |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4439 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4440 | } |
| 4441 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4442 | static void hci_sync_conn_complete_evt(struct hci_dev *hdev, |
| 4443 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4444 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4445 | struct hci_ev_sync_conn_complete *ev = (void *) skb->data; |
| 4446 | struct hci_conn *conn; |
Chethan T N | f4f9fa0 | 2021-09-07 15:42:48 +0530 | [diff] [blame^] | 4447 | unsigned int notify_evt; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4448 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4449 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4450 | |
| 4451 | hci_dev_lock(hdev); |
| 4452 | |
| 4453 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4454 | if (!conn) { |
| 4455 | if (ev->link_type == ESCO_LINK) |
| 4456 | goto unlock; |
| 4457 | |
Kuba Pawlak | 618353b | 2015-08-28 13:05:22 +0100 | [diff] [blame] | 4458 | /* When the link type in the event indicates SCO connection |
| 4459 | * and lookup of the connection object fails, then check |
| 4460 | * if an eSCO connection object exists. |
| 4461 | * |
| 4462 | * The core limits the synchronous connections to either |
| 4463 | * SCO or eSCO. The eSCO connection is preferred and tried |
| 4464 | * to be setup first and until successfully established, |
| 4465 | * the link type will be hinted as eSCO. |
| 4466 | */ |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4467 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); |
| 4468 | if (!conn) |
| 4469 | goto unlock; |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4470 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4471 | |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4472 | switch (ev->status) { |
| 4473 | case 0x00: |
Desmond Cheong Zhi Xi | 92fe24a | 2021-07-28 15:51:04 +0800 | [diff] [blame] | 4474 | /* The synchronous connection complete event should only be |
| 4475 | * sent once per new connection. Receiving a successful |
| 4476 | * complete event when the connection status is already |
| 4477 | * BT_CONNECTED means that the device is misbehaving and sent |
| 4478 | * multiple complete event packets for the same new connection. |
| 4479 | * |
| 4480 | * Registering the device more than once can corrupt kernel |
| 4481 | * memory, hence upon detecting this invalid event, we report |
| 4482 | * an error and ignore the packet. |
| 4483 | */ |
| 4484 | if (conn->state == BT_CONNECTED) { |
| 4485 | bt_dev_err(hdev, "Ignoring connect complete event for existing connection"); |
| 4486 | goto unlock; |
| 4487 | } |
| 4488 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4489 | conn->handle = __le16_to_cpu(ev->handle); |
| 4490 | conn->state = BT_CONNECTED; |
Kuba Pawlak | 618353b | 2015-08-28 13:05:22 +0100 | [diff] [blame] | 4491 | conn->type = ev->link_type; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 4492 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 4493 | hci_debugfs_create_conn(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 4494 | hci_conn_add_sysfs(conn); |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4495 | break; |
| 4496 | |
Nick Pelly | 81218d2 | 2014-06-30 11:25:01 +0530 | [diff] [blame] | 4497 | case 0x10: /* Connection Accept Timeout */ |
Frédéric Dalleau | 1a4c958 | 2013-08-19 14:24:02 +0200 | [diff] [blame] | 4498 | case 0x0d: /* Connection Rejected due to Limited Resources */ |
Stephen Coe | 705e571 | 2010-02-16 11:29:44 -0500 | [diff] [blame] | 4499 | case 0x11: /* Unsupported Feature or Parameter Value */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4500 | case 0x1c: /* SCO interval rejected */ |
Nick Pelly | 1038a00 | 2010-02-03 11:42:26 -0800 | [diff] [blame] | 4501 | case 0x1a: /* Unsupported Remote Feature */ |
Hsin-Yu Chao | 56b5453 | 2020-05-15 17:27:04 +0800 | [diff] [blame] | 4502 | case 0x1e: /* Invalid LMP Parameters */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4503 | case 0x1f: /* Unspecified error */ |
Andrew Earl | 27539bc | 2014-03-10 10:31:04 +0000 | [diff] [blame] | 4504 | case 0x20: /* Unsupported LMP Parameter value */ |
Frédéric Dalleau | 2dea632 | 2013-08-19 14:24:03 +0200 | [diff] [blame] | 4505 | if (conn->out) { |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4506 | conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | |
| 4507 | (hdev->esco_type & EDR_ESCO_MASK); |
Frédéric Dalleau | 2dea632 | 2013-08-19 14:24:03 +0200 | [diff] [blame] | 4508 | if (hci_setup_sync(conn, conn->link->handle)) |
| 4509 | goto unlock; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4510 | } |
Gustavo A. R. Silva | 19186c7 | 2020-07-08 15:18:23 -0500 | [diff] [blame] | 4511 | fallthrough; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4512 | |
| 4513 | default: |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4514 | conn->state = BT_CLOSED; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 4515 | break; |
| 4516 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4517 | |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 4518 | bt_dev_dbg(hdev, "SCO connected with air mode: %02x", ev->air_mode); |
| 4519 | |
Kiran K | 06d213d8 | 2021-04-08 22:31:59 +0530 | [diff] [blame] | 4520 | switch (ev->air_mode) { |
| 4521 | case 0x02: |
Chethan T N | f4f9fa0 | 2021-09-07 15:42:48 +0530 | [diff] [blame^] | 4522 | notify_evt = HCI_NOTIFY_ENABLE_SCO_CVSD; |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 4523 | break; |
Kiran K | 06d213d8 | 2021-04-08 22:31:59 +0530 | [diff] [blame] | 4524 | case 0x03: |
Chethan T N | f4f9fa0 | 2021-09-07 15:42:48 +0530 | [diff] [blame^] | 4525 | notify_evt = HCI_NOTIFY_ENABLE_SCO_TRANSP; |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 4526 | break; |
| 4527 | } |
| 4528 | |
Chethan T N | f4f9fa0 | 2021-09-07 15:42:48 +0530 | [diff] [blame^] | 4529 | /* Notify only in case of SCO over HCI transport data path which |
| 4530 | * is zero and non-zero value shall be non-HCI transport data path |
| 4531 | */ |
| 4532 | if (conn->codec.data_path == 0) { |
| 4533 | if (hdev->notify) |
| 4534 | hdev->notify(hdev, notify_evt); |
| 4535 | } |
| 4536 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 4537 | hci_connect_cfm(conn, ev->status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 4538 | if (ev->status) |
| 4539 | hci_conn_del(conn); |
| 4540 | |
| 4541 | unlock: |
| 4542 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4543 | } |
| 4544 | |
Marcel Holtmann | efdcf8e | 2013-10-15 10:31:12 -0700 | [diff] [blame] | 4545 | static inline size_t eir_get_length(u8 *eir, size_t eir_len) |
| 4546 | { |
| 4547 | size_t parsed = 0; |
| 4548 | |
| 4549 | while (parsed < eir_len) { |
| 4550 | u8 field_len = eir[0]; |
| 4551 | |
| 4552 | if (field_len == 0) |
| 4553 | return parsed; |
| 4554 | |
| 4555 | parsed += field_len + 1; |
| 4556 | eir += field_len + 1; |
| 4557 | } |
| 4558 | |
| 4559 | return eir_len; |
| 4560 | } |
| 4561 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4562 | static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, |
| 4563 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4564 | { |
| 4565 | struct inquiry_data data; |
| 4566 | struct extended_inquiry_info *info = (void *) (skb->data + 1); |
| 4567 | int num_rsp = *((__u8 *) skb->data); |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 4568 | size_t eir_len; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4569 | |
| 4570 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 4571 | |
Peilin Ye | 51c19bf | 2020-07-10 12:09:15 -0400 | [diff] [blame] | 4572 | if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4573 | return; |
| 4574 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4575 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 4576 | return; |
| 4577 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4578 | hci_dev_lock(hdev); |
| 4579 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 4580 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4581 | u32 flags; |
| 4582 | bool name_known; |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 4583 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4584 | bacpy(&data.bdaddr, &info->bdaddr); |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 4585 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4586 | data.pscan_period_mode = info->pscan_period_mode; |
| 4587 | data.pscan_mode = 0x00; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4588 | memcpy(data.dev_class, info->dev_class, 3); |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 4589 | data.clock_offset = info->clock_offset; |
| 4590 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4591 | data.ssp_mode = 0x01; |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 4592 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4593 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 0d3b7f6 | 2016-01-05 13:19:31 +0200 | [diff] [blame] | 4594 | name_known = eir_get_data(info->data, |
| 4595 | sizeof(info->data), |
| 4596 | EIR_NAME_COMPLETE, NULL); |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 4597 | else |
| 4598 | name_known = true; |
| 4599 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4600 | flags = hci_inquiry_cache_update(hdev, &data, name_known); |
| 4601 | |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 4602 | eir_len = eir_get_length(info->data, sizeof(info->data)); |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4603 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 4604 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4605 | info->dev_class, info->rssi, |
| 4606 | flags, info->data, eir_len, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4607 | } |
| 4608 | |
| 4609 | hci_dev_unlock(hdev); |
| 4610 | } |
| 4611 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4612 | static void hci_key_refresh_complete_evt(struct hci_dev *hdev, |
| 4613 | struct sk_buff *skb) |
| 4614 | { |
| 4615 | struct hci_ev_key_refresh_complete *ev = (void *) skb->data; |
| 4616 | struct hci_conn *conn; |
| 4617 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4618 | 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] | 4619 | __le16_to_cpu(ev->handle)); |
| 4620 | |
| 4621 | hci_dev_lock(hdev); |
| 4622 | |
| 4623 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 4624 | if (!conn) |
| 4625 | goto unlock; |
| 4626 | |
Johan Hedberg | 9eb1fbf | 2014-04-11 12:02:31 -0700 | [diff] [blame] | 4627 | /* For BR/EDR the necessary steps are taken through the |
| 4628 | * auth_complete event. |
| 4629 | */ |
| 4630 | if (conn->type != LE_LINK) |
| 4631 | goto unlock; |
| 4632 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4633 | if (!ev->status) |
| 4634 | conn->sec_level = conn->pending_sec_level; |
| 4635 | |
| 4636 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
| 4637 | |
| 4638 | if (ev->status && conn->state == BT_CONNECTED) { |
Andre Guedes | bed7174 | 2013-01-30 11:50:56 -0300 | [diff] [blame] | 4639 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4640 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4641 | goto unlock; |
| 4642 | } |
| 4643 | |
| 4644 | if (conn->state == BT_CONFIG) { |
| 4645 | if (!ev->status) |
| 4646 | conn->state = BT_CONNECTED; |
| 4647 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 4648 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4649 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4650 | } else { |
| 4651 | hci_auth_cfm(conn, ev->status); |
| 4652 | |
| 4653 | hci_conn_hold(conn); |
| 4654 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4655 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | unlock: |
| 4659 | hci_dev_unlock(hdev); |
| 4660 | } |
| 4661 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4662 | static u8 hci_get_auth_req(struct hci_conn *conn) |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4663 | { |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4664 | /* If remote requests no-bonding follow that lead */ |
Mikel Astiz | acabae9 | 2013-06-28 10:56:28 +0200 | [diff] [blame] | 4665 | if (conn->remote_auth == HCI_AT_NO_BONDING || |
| 4666 | conn->remote_auth == HCI_AT_NO_BONDING_MITM) |
Waldemar Rymarkiewicz | 58797bf | 2011-04-28 12:07:58 +0200 | [diff] [blame] | 4667 | return conn->remote_auth | (conn->auth_type & 0x01); |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4668 | |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 4669 | /* If both remote and local have enough IO capabilities, require |
| 4670 | * MITM protection |
| 4671 | */ |
| 4672 | if (conn->remote_cap != HCI_IO_NO_INPUT_OUTPUT && |
| 4673 | conn->io_capability != HCI_IO_NO_INPUT_OUTPUT) |
| 4674 | return conn->remote_auth | 0x01; |
| 4675 | |
Timo Mueller | 7e74170 | 2014-04-08 14:21:33 +0200 | [diff] [blame] | 4676 | /* No MITM protection possible so ignore remote requirement */ |
| 4677 | return (conn->remote_auth & ~0x01) | (conn->auth_type & 0x01); |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4678 | } |
| 4679 | |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 4680 | static u8 bredr_oob_data_present(struct hci_conn *conn) |
| 4681 | { |
| 4682 | struct hci_dev *hdev = conn->hdev; |
| 4683 | struct oob_data *data; |
| 4684 | |
| 4685 | data = hci_find_remote_oob_data(hdev, &conn->dst, BDADDR_BREDR); |
| 4686 | if (!data) |
| 4687 | return 0x00; |
| 4688 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 4689 | if (bredr_sc_enabled(hdev)) { |
| 4690 | /* When Secure Connections is enabled, then just |
| 4691 | * return the present value stored with the OOB |
| 4692 | * data. The stored value contains the right present |
| 4693 | * information. However it can only be trusted when |
| 4694 | * not in Secure Connection Only mode. |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 4695 | */ |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 4696 | if (!hci_dev_test_flag(hdev, HCI_SC_ONLY)) |
| 4697 | return data->present; |
| 4698 | |
| 4699 | /* When Secure Connections Only mode is enabled, then |
| 4700 | * the P-256 values are required. If they are not |
| 4701 | * available, then do not declare that OOB data is |
| 4702 | * present. |
| 4703 | */ |
| 4704 | if (!memcmp(data->rand256, ZERO_KEY, 16) || |
| 4705 | !memcmp(data->hash256, ZERO_KEY, 16)) |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 4706 | return 0x00; |
| 4707 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 4708 | return 0x02; |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 4709 | } |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 4710 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 4711 | /* When Secure Connections is not enabled or actually |
| 4712 | * not supported by the hardware, then check that if |
| 4713 | * P-192 data values are present. |
| 4714 | */ |
| 4715 | if (!memcmp(data->rand192, ZERO_KEY, 16) || |
| 4716 | !memcmp(data->hash192, ZERO_KEY, 16)) |
| 4717 | return 0x00; |
| 4718 | |
| 4719 | return 0x01; |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 4720 | } |
| 4721 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4722 | 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] | 4723 | { |
| 4724 | struct hci_ev_io_capa_request *ev = (void *) skb->data; |
| 4725 | struct hci_conn *conn; |
| 4726 | |
| 4727 | BT_DBG("%s", hdev->name); |
| 4728 | |
| 4729 | hci_dev_lock(hdev); |
| 4730 | |
| 4731 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4732 | if (!conn) |
| 4733 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4734 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4735 | hci_conn_hold(conn); |
| 4736 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4737 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4738 | goto unlock; |
| 4739 | |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 4740 | /* Allow pairing if we're pairable, the initiators of the |
| 4741 | * pairing or if the remote is not requesting bonding. |
| 4742 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4743 | if (hci_dev_test_flag(hdev, HCI_BONDABLE) || |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 4744 | test_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags) || |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4745 | (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4746 | struct hci_cp_io_capability_reply cp; |
| 4747 | |
| 4748 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Hemant Gupta | 7a7f1e7 | 2012-01-16 13:34:29 +0530 | [diff] [blame] | 4749 | /* Change the IO capability from KeyboardDisplay |
| 4750 | * to DisplayYesNo as it is not supported by BT spec. */ |
| 4751 | cp.capability = (conn->io_capability == 0x04) ? |
Mikel Astiz | a767631 | 2013-06-28 10:56:29 +0200 | [diff] [blame] | 4752 | HCI_IO_DISPLAY_YESNO : conn->io_capability; |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 4753 | |
| 4754 | /* If we are initiators, there is no remote information yet */ |
| 4755 | if (conn->remote_auth == 0xff) { |
Mikel Astiz | b16c660 | 2014-04-08 14:21:34 +0200 | [diff] [blame] | 4756 | /* Request MITM protection if our IO caps allow it |
Johan Hedberg | 4ad51a7 | 2014-06-09 14:41:25 +0300 | [diff] [blame] | 4757 | * except for the no-bonding case. |
Mikel Astiz | b16c660 | 2014-04-08 14:21:34 +0200 | [diff] [blame] | 4758 | */ |
Mikel Astiz | 6fd6b91 | 2014-04-08 14:21:32 +0200 | [diff] [blame] | 4759 | if (conn->io_capability != HCI_IO_NO_INPUT_OUTPUT && |
Johan Hedberg | 9f743d7 | 2014-07-17 11:56:33 +0300 | [diff] [blame] | 4760 | conn->auth_type != HCI_AT_NO_BONDING) |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 4761 | conn->auth_type |= 0x01; |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 4762 | } else { |
| 4763 | conn->auth_type = hci_get_auth_req(conn); |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 4764 | } |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4765 | |
Johan Hedberg | 82c295b | 2014-07-30 09:22:24 +0300 | [diff] [blame] | 4766 | /* If we're not bondable, force one of the non-bondable |
| 4767 | * authentication requirement values. |
| 4768 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4769 | if (!hci_dev_test_flag(hdev, HCI_BONDABLE)) |
Johan Hedberg | 82c295b | 2014-07-30 09:22:24 +0300 | [diff] [blame] | 4770 | conn->auth_type &= HCI_AT_NO_BONDING_MITM; |
| 4771 | |
| 4772 | cp.authentication = conn->auth_type; |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 4773 | cp.oob_data = bredr_oob_data_present(conn); |
Szymon Janc | ce85ee1 | 2011-03-22 13:12:23 +0100 | [diff] [blame] | 4774 | |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 4775 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4776 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4777 | } else { |
| 4778 | struct hci_cp_io_capability_neg_reply cp; |
| 4779 | |
| 4780 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9f5a0d7 | 2011-11-07 14:20:25 +0200 | [diff] [blame] | 4781 | cp.reason = HCI_ERROR_PAIRING_NOT_ALLOWED; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4782 | |
| 4783 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4784 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | unlock: |
| 4788 | hci_dev_unlock(hdev); |
| 4789 | } |
| 4790 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4791 | 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] | 4792 | { |
| 4793 | struct hci_ev_io_capa_reply *ev = (void *) skb->data; |
| 4794 | struct hci_conn *conn; |
| 4795 | |
| 4796 | BT_DBG("%s", hdev->name); |
| 4797 | |
| 4798 | hci_dev_lock(hdev); |
| 4799 | |
| 4800 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4801 | if (!conn) |
| 4802 | goto unlock; |
| 4803 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4804 | conn->remote_cap = ev->capability; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4805 | conn->remote_auth = ev->authentication; |
| 4806 | |
| 4807 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4808 | hci_dev_unlock(hdev); |
| 4809 | } |
| 4810 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4811 | static void hci_user_confirm_request_evt(struct hci_dev *hdev, |
| 4812 | struct sk_buff *skb) |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4813 | { |
| 4814 | struct hci_ev_user_confirm_req *ev = (void *) skb->data; |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 4815 | int loc_mitm, rem_mitm, confirm_hint = 0; |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4816 | struct hci_conn *conn; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4817 | |
| 4818 | BT_DBG("%s", hdev->name); |
| 4819 | |
| 4820 | hci_dev_lock(hdev); |
| 4821 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4822 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4823 | goto unlock; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4824 | |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4825 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4826 | if (!conn) |
| 4827 | goto unlock; |
| 4828 | |
| 4829 | loc_mitm = (conn->auth_type & 0x01); |
| 4830 | rem_mitm = (conn->remote_auth & 0x01); |
| 4831 | |
| 4832 | /* If we require MITM but the remote device can't provide that |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 4833 | * (it has NoInputNoOutput) then reject the confirmation |
| 4834 | * request. We check the security level here since it doesn't |
| 4835 | * necessarily match conn->auth_type. |
Mikel Astiz | 6fd6b91 | 2014-04-08 14:21:32 +0200 | [diff] [blame] | 4836 | */ |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 4837 | if (conn->pending_sec_level > BT_SECURITY_MEDIUM && |
| 4838 | conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) { |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4839 | BT_DBG("Rejecting request: remote device can't provide MITM"); |
| 4840 | hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4841 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4842 | goto unlock; |
| 4843 | } |
| 4844 | |
| 4845 | /* If no side requires MITM protection; auto-accept */ |
Mikel Astiz | a767631 | 2013-06-28 10:56:29 +0200 | [diff] [blame] | 4846 | if ((!loc_mitm || conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) && |
| 4847 | (!rem_mitm || conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)) { |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 4848 | |
| 4849 | /* If we're not the initiators request authorization to |
| 4850 | * proceed from user space (mgmt_user_confirm with |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 4851 | * confirm_hint set to 1). The exception is if neither |
Johan Hedberg | 02f3e25 | 2014-07-16 15:09:13 +0300 | [diff] [blame] | 4852 | * side had MITM or if the local IO capability is |
| 4853 | * NoInputNoOutput, in which case we do auto-accept |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 4854 | */ |
| 4855 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && |
Johan Hedberg | 02f3e25 | 2014-07-16 15:09:13 +0300 | [diff] [blame] | 4856 | conn->io_capability != HCI_IO_NO_INPUT_OUTPUT && |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 4857 | (loc_mitm || rem_mitm)) { |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 4858 | BT_DBG("Confirming auto-accept as acceptor"); |
| 4859 | confirm_hint = 1; |
| 4860 | goto confirm; |
| 4861 | } |
| 4862 | |
Howard Chung | cee5f20 | 2020-02-14 19:16:41 +0800 | [diff] [blame] | 4863 | /* If there already exists link key in local host, leave the |
| 4864 | * decision to user space since the remote device could be |
| 4865 | * legitimate or malicious. |
| 4866 | */ |
| 4867 | if (hci_find_link_key(hdev, &ev->bdaddr)) { |
| 4868 | bt_dev_dbg(hdev, "Local host already has link key"); |
| 4869 | confirm_hint = 1; |
| 4870 | goto confirm; |
| 4871 | } |
| 4872 | |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 4873 | BT_DBG("Auto-accept of user confirmation with %ums delay", |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4874 | hdev->auto_accept_delay); |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 4875 | |
| 4876 | if (hdev->auto_accept_delay > 0) { |
| 4877 | int delay = msecs_to_jiffies(hdev->auto_accept_delay); |
Johan Hedberg | 7bc18d9 | 2013-10-16 18:11:39 +0300 | [diff] [blame] | 4878 | queue_delayed_work(conn->hdev->workqueue, |
| 4879 | &conn->auto_accept_work, delay); |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 4880 | goto unlock; |
| 4881 | } |
| 4882 | |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4883 | hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4884 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4885 | goto unlock; |
| 4886 | } |
| 4887 | |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 4888 | confirm: |
Johan Hedberg | 39adbff | 2014-03-20 08:18:14 +0200 | [diff] [blame] | 4889 | mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0, |
| 4890 | le32_to_cpu(ev->passkey), confirm_hint); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 4891 | |
| 4892 | unlock: |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4893 | hci_dev_unlock(hdev); |
| 4894 | } |
| 4895 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4896 | static void hci_user_passkey_request_evt(struct hci_dev *hdev, |
| 4897 | struct sk_buff *skb) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 4898 | { |
| 4899 | struct hci_ev_user_passkey_req *ev = (void *) skb->data; |
| 4900 | |
| 4901 | BT_DBG("%s", hdev->name); |
| 4902 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4903 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 4904 | mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 4905 | } |
| 4906 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 4907 | static void hci_user_passkey_notify_evt(struct hci_dev *hdev, |
| 4908 | struct sk_buff *skb) |
| 4909 | { |
| 4910 | struct hci_ev_user_passkey_notify *ev = (void *) skb->data; |
| 4911 | struct hci_conn *conn; |
| 4912 | |
| 4913 | BT_DBG("%s", hdev->name); |
| 4914 | |
| 4915 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4916 | if (!conn) |
| 4917 | return; |
| 4918 | |
| 4919 | conn->passkey_notify = __le32_to_cpu(ev->passkey); |
| 4920 | conn->passkey_entered = 0; |
| 4921 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4922 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 4923 | mgmt_user_passkey_notify(hdev, &conn->dst, conn->type, |
| 4924 | conn->dst_type, conn->passkey_notify, |
| 4925 | conn->passkey_entered); |
| 4926 | } |
| 4927 | |
| 4928 | static void hci_keypress_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 4929 | { |
| 4930 | struct hci_ev_keypress_notify *ev = (void *) skb->data; |
| 4931 | struct hci_conn *conn; |
| 4932 | |
| 4933 | BT_DBG("%s", hdev->name); |
| 4934 | |
| 4935 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4936 | if (!conn) |
| 4937 | return; |
| 4938 | |
| 4939 | switch (ev->type) { |
| 4940 | case HCI_KEYPRESS_STARTED: |
| 4941 | conn->passkey_entered = 0; |
| 4942 | return; |
| 4943 | |
| 4944 | case HCI_KEYPRESS_ENTERED: |
| 4945 | conn->passkey_entered++; |
| 4946 | break; |
| 4947 | |
| 4948 | case HCI_KEYPRESS_ERASED: |
| 4949 | conn->passkey_entered--; |
| 4950 | break; |
| 4951 | |
| 4952 | case HCI_KEYPRESS_CLEARED: |
| 4953 | conn->passkey_entered = 0; |
| 4954 | break; |
| 4955 | |
| 4956 | case HCI_KEYPRESS_COMPLETED: |
| 4957 | return; |
| 4958 | } |
| 4959 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4960 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 4961 | mgmt_user_passkey_notify(hdev, &conn->dst, conn->type, |
| 4962 | conn->dst_type, conn->passkey_notify, |
| 4963 | conn->passkey_entered); |
| 4964 | } |
| 4965 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4966 | static void hci_simple_pair_complete_evt(struct hci_dev *hdev, |
| 4967 | struct sk_buff *skb) |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4968 | { |
| 4969 | struct hci_ev_simple_pair_complete *ev = (void *) skb->data; |
| 4970 | struct hci_conn *conn; |
| 4971 | |
| 4972 | BT_DBG("%s", hdev->name); |
| 4973 | |
| 4974 | hci_dev_lock(hdev); |
| 4975 | |
| 4976 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 4977 | if (!conn) |
| 4978 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4979 | |
Johan Hedberg | c1d4fa7 | 2014-07-17 15:14:50 +0300 | [diff] [blame] | 4980 | /* Reset the authentication requirement to unknown */ |
| 4981 | conn->remote_auth = 0xff; |
| 4982 | |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 4983 | /* To avoid duplicate auth_failed events to user space we check |
| 4984 | * the HCI_CONN_AUTH_PEND flag which will be set if we |
| 4985 | * initiated the authentication. A traditional auth_complete |
| 4986 | * event gets always produced as initiator and is also mapped to |
| 4987 | * the mgmt_auth_failed event */ |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 4988 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status) |
Johan Hedberg | e1e930f | 2014-09-08 17:09:49 -0700 | [diff] [blame] | 4989 | mgmt_auth_failed(conn, ev->status); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 4990 | |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4991 | hci_conn_drop(conn); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 4992 | |
| 4993 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4994 | hci_dev_unlock(hdev); |
| 4995 | } |
| 4996 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4997 | static void hci_remote_host_features_evt(struct hci_dev *hdev, |
| 4998 | struct sk_buff *skb) |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4999 | { |
| 5000 | struct hci_ev_remote_host_features *ev = (void *) skb->data; |
| 5001 | struct inquiry_entry *ie; |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 5002 | struct hci_conn *conn; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5003 | |
| 5004 | BT_DBG("%s", hdev->name); |
| 5005 | |
| 5006 | hci_dev_lock(hdev); |
| 5007 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 5008 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 5009 | if (conn) |
| 5010 | memcpy(conn->features[1], ev->features, 8); |
| 5011 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 5012 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 5013 | if (ie) |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 5014 | ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5015 | |
| 5016 | hci_dev_unlock(hdev); |
| 5017 | } |
| 5018 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5019 | static void hci_remote_oob_data_request_evt(struct hci_dev *hdev, |
| 5020 | struct sk_buff *skb) |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5021 | { |
| 5022 | struct hci_ev_remote_oob_data_request *ev = (void *) skb->data; |
| 5023 | struct oob_data *data; |
| 5024 | |
| 5025 | BT_DBG("%s", hdev->name); |
| 5026 | |
| 5027 | hci_dev_lock(hdev); |
| 5028 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5029 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Szymon Janc | e1ba1f1 | 2011-04-06 13:01:59 +0200 | [diff] [blame] | 5030 | goto unlock; |
| 5031 | |
Johan Hedberg | 6928a92 | 2014-10-26 20:46:09 +0100 | [diff] [blame] | 5032 | data = hci_find_remote_oob_data(hdev, &ev->bdaddr, BDADDR_BREDR); |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 5033 | if (!data) { |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5034 | struct hci_cp_remote_oob_data_neg_reply cp; |
| 5035 | |
| 5036 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Marcel Holtmann | 519ca9d | 2014-01-10 02:07:28 -0800 | [diff] [blame] | 5037 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, |
| 5038 | sizeof(cp), &cp); |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 5039 | goto unlock; |
| 5040 | } |
| 5041 | |
| 5042 | if (bredr_sc_enabled(hdev)) { |
| 5043 | struct hci_cp_remote_oob_ext_data_reply cp; |
| 5044 | |
| 5045 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5046 | if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 5047 | memset(cp.hash192, 0, sizeof(cp.hash192)); |
| 5048 | memset(cp.rand192, 0, sizeof(cp.rand192)); |
| 5049 | } else { |
| 5050 | memcpy(cp.hash192, data->hash192, sizeof(cp.hash192)); |
| 5051 | memcpy(cp.rand192, data->rand192, sizeof(cp.rand192)); |
| 5052 | } |
| 5053 | memcpy(cp.hash256, data->hash256, sizeof(cp.hash256)); |
| 5054 | memcpy(cp.rand256, data->rand256, sizeof(cp.rand256)); |
| 5055 | |
| 5056 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_EXT_DATA_REPLY, |
| 5057 | sizeof(cp), &cp); |
| 5058 | } else { |
| 5059 | struct hci_cp_remote_oob_data_reply cp; |
| 5060 | |
| 5061 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 5062 | memcpy(cp.hash, data->hash192, sizeof(cp.hash)); |
| 5063 | memcpy(cp.rand, data->rand192, sizeof(cp.rand)); |
| 5064 | |
| 5065 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, |
| 5066 | sizeof(cp), &cp); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5067 | } |
| 5068 | |
Szymon Janc | e1ba1f1 | 2011-04-06 13:01:59 +0200 | [diff] [blame] | 5069 | unlock: |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5070 | hci_dev_unlock(hdev); |
| 5071 | } |
| 5072 | |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 5073 | #if IS_ENABLED(CONFIG_BT_HS) |
| 5074 | static void hci_chan_selected_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5075 | { |
| 5076 | struct hci_ev_channel_selected *ev = (void *)skb->data; |
| 5077 | struct hci_conn *hcon; |
| 5078 | |
| 5079 | BT_DBG("%s handle 0x%2.2x", hdev->name, ev->phy_handle); |
| 5080 | |
| 5081 | skb_pull(skb, sizeof(*ev)); |
| 5082 | |
| 5083 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 5084 | if (!hcon) |
| 5085 | return; |
| 5086 | |
| 5087 | amp_read_loc_assoc_final_data(hdev, hcon); |
| 5088 | } |
| 5089 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5090 | static void hci_phy_link_complete_evt(struct hci_dev *hdev, |
| 5091 | struct sk_buff *skb) |
| 5092 | { |
| 5093 | struct hci_ev_phy_link_complete *ev = (void *) skb->data; |
| 5094 | struct hci_conn *hcon, *bredr_hcon; |
| 5095 | |
| 5096 | BT_DBG("%s handle 0x%2.2x status 0x%2.2x", hdev->name, ev->phy_handle, |
| 5097 | ev->status); |
| 5098 | |
| 5099 | hci_dev_lock(hdev); |
| 5100 | |
| 5101 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5102 | if (!hcon) |
| 5103 | goto unlock; |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5104 | |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5105 | if (!hcon->amp_mgr) |
| 5106 | goto unlock; |
Anmol Karn | 6dfccd1 | 2020-09-30 19:48:13 +0530 | [diff] [blame] | 5107 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5108 | if (ev->status) { |
| 5109 | hci_conn_del(hcon); |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5110 | goto unlock; |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5111 | } |
| 5112 | |
| 5113 | bredr_hcon = hcon->amp_mgr->l2cap_conn->hcon; |
| 5114 | |
| 5115 | hcon->state = BT_CONNECTED; |
| 5116 | bacpy(&hcon->dst, &bredr_hcon->dst); |
| 5117 | |
| 5118 | hci_conn_hold(hcon); |
| 5119 | hcon->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 5120 | hci_conn_drop(hcon); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5121 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 5122 | hci_debugfs_create_conn(hcon); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5123 | hci_conn_add_sysfs(hcon); |
| 5124 | |
Andrei Emeltchenko | cf70ff2 | 2012-10-31 15:46:36 +0200 | [diff] [blame] | 5125 | amp_physical_cfm(bredr_hcon, hcon); |
| 5126 | |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5127 | unlock: |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5128 | hci_dev_unlock(hdev); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5129 | } |
| 5130 | |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 5131 | static void hci_loglink_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5132 | { |
| 5133 | struct hci_ev_logical_link_complete *ev = (void *) skb->data; |
| 5134 | struct hci_conn *hcon; |
| 5135 | struct hci_chan *hchan; |
| 5136 | struct amp_mgr *mgr; |
| 5137 | |
| 5138 | BT_DBG("%s log_handle 0x%4.4x phy_handle 0x%2.2x status 0x%2.2x", |
| 5139 | hdev->name, le16_to_cpu(ev->handle), ev->phy_handle, |
| 5140 | ev->status); |
| 5141 | |
| 5142 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 5143 | if (!hcon) |
| 5144 | return; |
| 5145 | |
| 5146 | /* Create AMP hchan */ |
| 5147 | hchan = hci_chan_create(hcon); |
| 5148 | if (!hchan) |
| 5149 | return; |
| 5150 | |
| 5151 | hchan->handle = le16_to_cpu(ev->handle); |
Archie Pusaka | 5c4c8c9 | 2021-03-22 14:03:11 +0800 | [diff] [blame] | 5152 | hchan->amp = true; |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 5153 | |
| 5154 | BT_DBG("hcon %p mgr %p hchan %p", hcon, hcon->amp_mgr, hchan); |
| 5155 | |
| 5156 | mgr = hcon->amp_mgr; |
| 5157 | if (mgr && mgr->bredr_chan) { |
| 5158 | struct l2cap_chan *bredr_chan = mgr->bredr_chan; |
| 5159 | |
| 5160 | l2cap_chan_lock(bredr_chan); |
| 5161 | |
| 5162 | bredr_chan->conn->mtu = hdev->block_mtu; |
| 5163 | l2cap_logical_cfm(bredr_chan, hchan, 0); |
| 5164 | hci_conn_hold(hcon); |
| 5165 | |
| 5166 | l2cap_chan_unlock(bredr_chan); |
| 5167 | } |
| 5168 | } |
| 5169 | |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 5170 | static void hci_disconn_loglink_complete_evt(struct hci_dev *hdev, |
| 5171 | struct sk_buff *skb) |
| 5172 | { |
| 5173 | struct hci_ev_disconn_logical_link_complete *ev = (void *) skb->data; |
| 5174 | struct hci_chan *hchan; |
| 5175 | |
| 5176 | BT_DBG("%s log handle 0x%4.4x status 0x%2.2x", hdev->name, |
| 5177 | le16_to_cpu(ev->handle), ev->status); |
| 5178 | |
| 5179 | if (ev->status) |
| 5180 | return; |
| 5181 | |
| 5182 | hci_dev_lock(hdev); |
| 5183 | |
| 5184 | hchan = hci_chan_lookup_handle(hdev, le16_to_cpu(ev->handle)); |
Archie Pusaka | 5c4c8c9 | 2021-03-22 14:03:11 +0800 | [diff] [blame] | 5185 | if (!hchan || !hchan->amp) |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 5186 | goto unlock; |
| 5187 | |
| 5188 | amp_destroy_logical_link(hchan, ev->reason); |
| 5189 | |
| 5190 | unlock: |
| 5191 | hci_dev_unlock(hdev); |
| 5192 | } |
| 5193 | |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 5194 | static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev, |
| 5195 | struct sk_buff *skb) |
| 5196 | { |
| 5197 | struct hci_ev_disconn_phy_link_complete *ev = (void *) skb->data; |
| 5198 | struct hci_conn *hcon; |
| 5199 | |
| 5200 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5201 | |
| 5202 | if (ev->status) |
| 5203 | return; |
| 5204 | |
| 5205 | hci_dev_lock(hdev); |
| 5206 | |
| 5207 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 5208 | if (hcon) { |
| 5209 | hcon->state = BT_CLOSED; |
| 5210 | hci_conn_del(hcon); |
| 5211 | } |
| 5212 | |
| 5213 | hci_dev_unlock(hdev); |
| 5214 | } |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 5215 | #endif |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 5216 | |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 5217 | static void le_conn_update_addr(struct hci_conn *conn, bdaddr_t *bdaddr, |
| 5218 | u8 bdaddr_type, bdaddr_t *local_rpa) |
| 5219 | { |
| 5220 | if (conn->out) { |
| 5221 | conn->dst_type = bdaddr_type; |
| 5222 | conn->resp_addr_type = bdaddr_type; |
| 5223 | bacpy(&conn->resp_addr, bdaddr); |
| 5224 | |
| 5225 | /* Check if the controller has set a Local RPA then it must be |
| 5226 | * used instead or hdev->rpa. |
| 5227 | */ |
| 5228 | if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) { |
| 5229 | conn->init_addr_type = ADDR_LE_DEV_RANDOM; |
| 5230 | bacpy(&conn->init_addr, local_rpa); |
| 5231 | } else if (hci_dev_test_flag(conn->hdev, HCI_PRIVACY)) { |
| 5232 | conn->init_addr_type = ADDR_LE_DEV_RANDOM; |
| 5233 | bacpy(&conn->init_addr, &conn->hdev->rpa); |
| 5234 | } else { |
| 5235 | hci_copy_identity_address(conn->hdev, &conn->init_addr, |
| 5236 | &conn->init_addr_type); |
| 5237 | } |
| 5238 | } else { |
| 5239 | conn->resp_addr_type = conn->hdev->adv_addr_type; |
| 5240 | /* Check if the controller has set a Local RPA then it must be |
| 5241 | * used instead or hdev->rpa. |
| 5242 | */ |
| 5243 | if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) { |
| 5244 | conn->resp_addr_type = ADDR_LE_DEV_RANDOM; |
| 5245 | bacpy(&conn->resp_addr, local_rpa); |
| 5246 | } else if (conn->hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) { |
| 5247 | /* In case of ext adv, resp_addr will be updated in |
| 5248 | * Adv Terminated event. |
| 5249 | */ |
| 5250 | if (!ext_adv_capable(conn->hdev)) |
| 5251 | bacpy(&conn->resp_addr, |
| 5252 | &conn->hdev->random_addr); |
| 5253 | } else { |
| 5254 | bacpy(&conn->resp_addr, &conn->hdev->bdaddr); |
| 5255 | } |
| 5256 | |
| 5257 | conn->init_addr_type = bdaddr_type; |
| 5258 | bacpy(&conn->init_addr, bdaddr); |
| 5259 | |
| 5260 | /* For incoming connections, set the default minimum |
| 5261 | * and maximum connection interval. They will be used |
| 5262 | * to check if the parameters are in range and if not |
| 5263 | * trigger the connection update procedure. |
| 5264 | */ |
| 5265 | conn->le_conn_min_interval = conn->hdev->le_conn_min_interval; |
| 5266 | conn->le_conn_max_interval = conn->hdev->le_conn_max_interval; |
| 5267 | } |
| 5268 | } |
| 5269 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5270 | static void le_conn_complete_evt(struct hci_dev *hdev, u8 status, |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 5271 | bdaddr_t *bdaddr, u8 bdaddr_type, |
| 5272 | bdaddr_t *local_rpa, u8 role, u16 handle, |
| 5273 | u16 interval, u16 latency, |
| 5274 | u16 supervision_timeout) |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5275 | { |
Johan Hedberg | 912b42ef | 2014-07-03 19:33:49 +0300 | [diff] [blame] | 5276 | struct hci_conn_params *params; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5277 | struct hci_conn *conn; |
Johan Hedberg | 68d6f6d | 2014-02-18 21:41:32 +0200 | [diff] [blame] | 5278 | struct smp_irk *irk; |
Johan Hedberg | 837d502 | 2014-07-02 09:36:22 +0300 | [diff] [blame] | 5279 | u8 addr_type; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5280 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5281 | hci_dev_lock(hdev); |
| 5282 | |
Johan Hedberg | fbd96c1 | 2014-07-08 17:21:51 +0300 | [diff] [blame] | 5283 | /* All controllers implicitly stop advertising in the event of a |
| 5284 | * connection, so ensure that the state bit is cleared. |
| 5285 | */ |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 5286 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | fbd96c1 | 2014-07-08 17:21:51 +0300 | [diff] [blame] | 5287 | |
Jakub Pawlowski | e7d9ab7 | 2015-08-07 20:22:52 +0200 | [diff] [blame] | 5288 | conn = hci_lookup_le_connect(hdev); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5289 | if (!conn) { |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5290 | conn = hci_conn_add(hdev, LE_LINK, bdaddr, role); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5291 | if (!conn) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 5292 | bt_dev_err(hdev, "no memory for new connection"); |
Andre Guedes | 230fd16 | 2012-07-27 15:10:10 -0300 | [diff] [blame] | 5293 | goto unlock; |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5294 | } |
Andre Guedes | 29b7988 | 2011-05-31 14:20:54 -0300 | [diff] [blame] | 5295 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5296 | conn->dst_type = bdaddr_type; |
Andre Guedes | b9b343d | 2012-07-27 15:10:11 -0300 | [diff] [blame] | 5297 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5298 | /* If we didn't have a hci_conn object previously |
Archie Pusaka | 74be523 | 2021-06-04 16:26:25 +0800 | [diff] [blame] | 5299 | * but we're in central role this must be something |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 5300 | * initiated using an accept list. Since accept list based |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5301 | * connections are not "first class citizens" we don't |
| 5302 | * have full tracking of them. Therefore, we go ahead |
| 5303 | * with a "best effort" approach of determining the |
| 5304 | * initiator address based on the HCI_PRIVACY flag. |
| 5305 | */ |
| 5306 | if (conn->out) { |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5307 | conn->resp_addr_type = bdaddr_type; |
| 5308 | bacpy(&conn->resp_addr, bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5309 | if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5310 | conn->init_addr_type = ADDR_LE_DEV_RANDOM; |
| 5311 | bacpy(&conn->init_addr, &hdev->rpa); |
| 5312 | } else { |
| 5313 | hci_copy_identity_address(hdev, |
| 5314 | &conn->init_addr, |
| 5315 | &conn->init_addr_type); |
| 5316 | } |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5317 | } |
Johan Hedberg | 9489eca | 2014-02-28 17:45:46 +0200 | [diff] [blame] | 5318 | } else { |
| 5319 | cancel_delayed_work(&conn->le_conn_timeout); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5320 | } |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5321 | |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 5322 | le_conn_update_addr(conn, bdaddr, bdaddr_type, local_rpa); |
Johan Hedberg | 7be2edb | 2014-02-23 19:42:17 +0200 | [diff] [blame] | 5323 | |
Marcel Holtmann | edb4b46 | 2014-02-18 15:13:43 -0800 | [diff] [blame] | 5324 | /* Lookup the identity address from the stored connection |
| 5325 | * address and address type. |
| 5326 | * |
| 5327 | * When establishing connections to an identity address, the |
| 5328 | * connection procedure will store the resolvable random |
| 5329 | * address first. Now if it can be converted back into the |
| 5330 | * identity address, start using the identity address from |
| 5331 | * now on. |
| 5332 | */ |
| 5333 | irk = hci_get_irk(hdev, &conn->dst, conn->dst_type); |
Johan Hedberg | 68d6f6d | 2014-02-18 21:41:32 +0200 | [diff] [blame] | 5334 | if (irk) { |
| 5335 | bacpy(&conn->dst, &irk->bdaddr); |
| 5336 | conn->dst_type = irk->addr_type; |
| 5337 | } |
| 5338 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 5339 | conn->dst_type = ev_bdaddr_type(hdev, conn->dst_type, NULL); |
Sathish Narasimman | 79699a7 | 2021-05-20 17:12:01 +0530 | [diff] [blame] | 5340 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5341 | if (status) { |
| 5342 | hci_le_conn_failed(conn, status); |
Johan Hedberg | 837d502 | 2014-07-02 09:36:22 +0300 | [diff] [blame] | 5343 | goto unlock; |
| 5344 | } |
| 5345 | |
Johan Hedberg | 08853f1 | 2014-08-15 21:06:55 +0300 | [diff] [blame] | 5346 | if (conn->dst_type == ADDR_LE_DEV_PUBLIC) |
| 5347 | addr_type = BDADDR_LE_PUBLIC; |
| 5348 | else |
| 5349 | addr_type = BDADDR_LE_RANDOM; |
| 5350 | |
Johan Hedberg | 2d3c226 | 2014-07-15 11:51:28 +0300 | [diff] [blame] | 5351 | /* Drop the connection if the device is blocked */ |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 5352 | if (hci_bdaddr_list_lookup(&hdev->reject_list, &conn->dst, addr_type)) { |
Johan Hedberg | 2d3c226 | 2014-07-15 11:51:28 +0300 | [diff] [blame] | 5353 | hci_conn_drop(conn); |
Andre Guedes | cd17dec | 2012-07-27 15:10:16 -0300 | [diff] [blame] | 5354 | goto unlock; |
| 5355 | } |
| 5356 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 5357 | if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 5358 | mgmt_device_connected(hdev, conn, NULL, 0); |
Vinicius Costa Gomes | 83bc71b | 2011-05-06 18:41:43 -0300 | [diff] [blame] | 5359 | |
Vinicius Costa Gomes | 7b5c0d5 | 2011-06-09 18:50:50 -0300 | [diff] [blame] | 5360 | conn->sec_level = BT_SECURITY_LOW; |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5361 | conn->handle = handle; |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5362 | conn->state = BT_CONFIG; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5363 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 5364 | /* Store current advertising instance as connection advertising instance |
| 5365 | * when sotfware rotation is in use so it can be re-enabled when |
| 5366 | * disconnected. |
| 5367 | */ |
| 5368 | if (!ext_adv_capable(hdev)) |
| 5369 | conn->adv_instance = hdev->cur_adv_instance; |
| 5370 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5371 | conn->le_conn_interval = interval; |
| 5372 | conn->le_conn_latency = latency; |
| 5373 | conn->le_supv_timeout = supervision_timeout; |
Marcel Holtmann | e04fde6 | 2014-06-23 11:40:04 +0200 | [diff] [blame] | 5374 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 5375 | hci_debugfs_create_conn(conn); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5376 | hci_conn_add_sysfs(conn); |
| 5377 | |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 5378 | /* The remote features procedure is defined for central |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5379 | * role only. So only in case of an initiated connection |
| 5380 | * request the remote features. |
| 5381 | * |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 5382 | * If the local controller supports peripheral-initiated features |
| 5383 | * exchange, then requesting the remote features in peripheral |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5384 | * role is possible. Otherwise just transition into the |
| 5385 | * connected state without requesting the remote features. |
| 5386 | */ |
| 5387 | if (conn->out || |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 5388 | (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) { |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5389 | struct hci_cp_le_read_remote_features cp; |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5390 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5391 | cp.handle = __cpu_to_le16(conn->handle); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5392 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5393 | hci_send_cmd(hdev, HCI_OP_LE_READ_REMOTE_FEATURES, |
| 5394 | sizeof(cp), &cp); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5395 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5396 | hci_conn_hold(conn); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5397 | } else { |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 5398 | conn->state = BT_CONNECTED; |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5399 | hci_connect_cfm(conn, status); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5400 | } |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5401 | |
Johan Hedberg | 5477610 | 2014-08-15 21:06:56 +0300 | [diff] [blame] | 5402 | params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst, |
| 5403 | conn->dst_type); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5404 | if (params) { |
Johan Hedberg | 95305ba | 2014-07-04 12:37:21 +0300 | [diff] [blame] | 5405 | list_del_init(¶ms->action); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5406 | if (params->conn) { |
| 5407 | hci_conn_drop(params->conn); |
Johan Hedberg | f8aaf9b | 2014-08-17 23:28:57 +0300 | [diff] [blame] | 5408 | hci_conn_put(params->conn); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5409 | params->conn = NULL; |
| 5410 | } |
| 5411 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5412 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5413 | unlock: |
Johan Hedberg | 223683a5 | 2014-07-06 15:44:23 +0300 | [diff] [blame] | 5414 | hci_update_background_scan(hdev); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5415 | hci_dev_unlock(hdev); |
| 5416 | } |
| 5417 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5418 | static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5419 | { |
| 5420 | struct hci_ev_le_conn_complete *ev = (void *) skb->data; |
| 5421 | |
| 5422 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5423 | |
| 5424 | le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type, |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 5425 | NULL, ev->role, le16_to_cpu(ev->handle), |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5426 | le16_to_cpu(ev->interval), |
| 5427 | le16_to_cpu(ev->latency), |
| 5428 | le16_to_cpu(ev->supervision_timeout)); |
| 5429 | } |
| 5430 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 5431 | static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, |
| 5432 | struct sk_buff *skb) |
| 5433 | { |
| 5434 | struct hci_ev_le_enh_conn_complete *ev = (void *) skb->data; |
| 5435 | |
| 5436 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5437 | |
| 5438 | le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type, |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 5439 | &ev->local_rpa, ev->role, le16_to_cpu(ev->handle), |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 5440 | le16_to_cpu(ev->interval), |
| 5441 | le16_to_cpu(ev->latency), |
| 5442 | le16_to_cpu(ev->supervision_timeout)); |
Sathish Narasimman | 5c49bcc | 2020-07-23 18:09:01 +0530 | [diff] [blame] | 5443 | |
| 5444 | if (use_ll_privacy(hdev) && |
Sathish Narasimman | cbbdfa6 | 2020-07-23 18:09:03 +0530 | [diff] [blame] | 5445 | hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && |
Sathish Narasimman | 5c49bcc | 2020-07-23 18:09:01 +0530 | [diff] [blame] | 5446 | hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) |
| 5447 | hci_req_disable_address_resolution(hdev); |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 5448 | } |
| 5449 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5450 | static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5451 | { |
| 5452 | struct hci_evt_le_ext_adv_set_term *ev = (void *) skb->data; |
| 5453 | struct hci_conn *conn; |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 5454 | struct adv_info *adv; |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5455 | |
| 5456 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5457 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 5458 | adv = hci_find_adv_instance(hdev, ev->handle); |
Luiz Augusto von Dentz | 23837a6 | 2021-06-22 20:59:02 -0700 | [diff] [blame] | 5459 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 5460 | if (ev->status) { |
Luiz Augusto von Dentz | 23837a6 | 2021-06-22 20:59:02 -0700 | [diff] [blame] | 5461 | if (!adv) |
| 5462 | return; |
| 5463 | |
| 5464 | /* Remove advertising as it has been terminated */ |
| 5465 | hci_remove_adv_instance(hdev, ev->handle); |
| 5466 | mgmt_advertising_removed(NULL, hdev, ev->handle); |
| 5467 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5468 | return; |
Luiz Augusto von Dentz | 23837a6 | 2021-06-22 20:59:02 -0700 | [diff] [blame] | 5469 | } |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5470 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 5471 | if (adv) |
| 5472 | adv->enabled = false; |
| 5473 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5474 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle)); |
| 5475 | if (conn) { |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 5476 | /* Store handle in the connection so the correct advertising |
| 5477 | * instance can be re-enabled when disconnected. |
| 5478 | */ |
| 5479 | conn->adv_instance = ev->handle; |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5480 | |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 5481 | if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM || |
| 5482 | bacmp(&conn->resp_addr, BDADDR_ANY)) |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5483 | return; |
| 5484 | |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 5485 | if (!ev->handle) { |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5486 | bacpy(&conn->resp_addr, &hdev->random_addr); |
| 5487 | return; |
| 5488 | } |
| 5489 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 5490 | if (adv) |
| 5491 | bacpy(&conn->resp_addr, &adv->random_addr); |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 5492 | } |
| 5493 | } |
| 5494 | |
Marcel Holtmann | 1855d92 | 2014-06-23 11:40:05 +0200 | [diff] [blame] | 5495 | static void hci_le_conn_update_complete_evt(struct hci_dev *hdev, |
| 5496 | struct sk_buff *skb) |
| 5497 | { |
| 5498 | struct hci_ev_le_conn_update_complete *ev = (void *) skb->data; |
| 5499 | struct hci_conn *conn; |
| 5500 | |
| 5501 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5502 | |
| 5503 | if (ev->status) |
| 5504 | return; |
| 5505 | |
| 5506 | hci_dev_lock(hdev); |
| 5507 | |
| 5508 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 5509 | if (conn) { |
| 5510 | conn->le_conn_interval = le16_to_cpu(ev->interval); |
| 5511 | conn->le_conn_latency = le16_to_cpu(ev->latency); |
| 5512 | conn->le_supv_timeout = le16_to_cpu(ev->supervision_timeout); |
| 5513 | } |
| 5514 | |
| 5515 | hci_dev_unlock(hdev); |
| 5516 | } |
| 5517 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5518 | /* This function requires the caller holds hdev->lock */ |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5519 | static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev, |
| 5520 | bdaddr_t *addr, |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 5521 | u8 addr_type, bool addr_resolved, |
| 5522 | u8 adv_type, bdaddr_t *direct_rpa) |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5523 | { |
| 5524 | struct hci_conn *conn; |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 5525 | struct hci_conn_params *params; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5526 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5527 | /* If the event is not connectable don't proceed further */ |
| 5528 | if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5529 | return NULL; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5530 | |
| 5531 | /* Ignore if the device is blocked */ |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 5532 | if (hci_bdaddr_list_lookup(&hdev->reject_list, addr, addr_type)) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5533 | return NULL; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5534 | |
Johan Hedberg | f99353c | 2014-07-16 11:56:09 +0300 | [diff] [blame] | 5535 | /* Most controller will fail if we try to create new connections |
Archie Pusaka | 39bc74c | 2021-06-04 16:26:26 +0800 | [diff] [blame] | 5536 | * while we have an existing one in peripheral role. |
Johan Hedberg | f99353c | 2014-07-16 11:56:09 +0300 | [diff] [blame] | 5537 | */ |
Archie Pusaka | 39bc74c | 2021-06-04 16:26:26 +0800 | [diff] [blame] | 5538 | if (hdev->conn_hash.le_num_peripheral > 0 && |
Alain Michaud | 4364f2e | 2020-04-23 14:43:29 +0000 | [diff] [blame] | 5539 | (!test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) || |
| 5540 | !(hdev->le_states[3] & 0x10))) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5541 | return NULL; |
Johan Hedberg | f99353c | 2014-07-16 11:56:09 +0300 | [diff] [blame] | 5542 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5543 | /* If we're not connectable only connect devices that we have in |
| 5544 | * our pend_le_conns list. |
| 5545 | */ |
Johan Hedberg | 49c5092 | 2015-10-16 10:07:51 +0300 | [diff] [blame] | 5546 | params = hci_pend_le_action_lookup(&hdev->pend_le_conns, addr, |
| 5547 | addr_type); |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 5548 | if (!params) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5549 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5550 | |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5551 | if (!params->explicit_connect) { |
| 5552 | switch (params->auto_connect) { |
| 5553 | case HCI_AUTO_CONN_DIRECT: |
| 5554 | /* Only devices advertising with ADV_DIRECT_IND are |
| 5555 | * triggering a connection attempt. This is allowing |
Archie Pusaka | 67ffb18 | 2021-05-31 16:37:28 +0800 | [diff] [blame] | 5556 | * incoming connections from peripheral devices. |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5557 | */ |
| 5558 | if (adv_type != LE_ADV_DIRECT_IND) |
| 5559 | return NULL; |
| 5560 | break; |
| 5561 | case HCI_AUTO_CONN_ALWAYS: |
| 5562 | /* Devices advertising with ADV_IND or ADV_DIRECT_IND |
| 5563 | * are triggering a connection attempt. This means |
Archie Pusaka | 67ffb18 | 2021-05-31 16:37:28 +0800 | [diff] [blame] | 5564 | * that incoming connections from peripheral device are |
| 5565 | * accepted and also outgoing connections to peripheral |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5566 | * devices are established when found. |
| 5567 | */ |
| 5568 | break; |
| 5569 | default: |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5570 | return NULL; |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5571 | } |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 5572 | } |
| 5573 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 5574 | conn = hci_connect_le(hdev, addr, addr_type, addr_resolved, |
| 5575 | BT_SECURITY_LOW, hdev->def_le_autoconnect_timeout, |
| 5576 | HCI_ROLE_MASTER, direct_rpa); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5577 | if (!IS_ERR(conn)) { |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5578 | /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned |
| 5579 | * by higher layer that tried to connect, if no then |
| 5580 | * store the pointer since we don't really have any |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5581 | * other owner of the object besides the params that |
| 5582 | * triggered it. This way we can abort the connection if |
| 5583 | * the parameters get removed and keep the reference |
| 5584 | * count consistent once the connection is established. |
| 5585 | */ |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 5586 | |
| 5587 | if (!params->explicit_connect) |
| 5588 | params->conn = hci_conn_get(conn); |
| 5589 | |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5590 | return conn; |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 5591 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5592 | |
| 5593 | switch (PTR_ERR(conn)) { |
| 5594 | case -EBUSY: |
| 5595 | /* If hci_connect() returns -EBUSY it means there is already |
| 5596 | * an LE connection attempt going on. Since controllers don't |
| 5597 | * support more than one connection attempt at the time, we |
| 5598 | * don't consider this an error case. |
| 5599 | */ |
| 5600 | break; |
| 5601 | default: |
| 5602 | BT_DBG("Failed to connect: err %ld", PTR_ERR(conn)); |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5603 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5604 | } |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5605 | |
| 5606 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5607 | } |
| 5608 | |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5609 | 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] | 5610 | u8 bdaddr_type, bdaddr_t *direct_addr, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5611 | u8 direct_addr_type, s8 rssi, u8 *data, u8 len, |
| 5612 | bool ext_adv) |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5613 | { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5614 | struct discovery_state *d = &hdev->discovery; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5615 | struct smp_irk *irk; |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 5616 | struct hci_conn *conn; |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 5617 | bool match, bdaddr_resolved; |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5618 | u32 flags; |
Szymon Janc | 1c58e93 | 2021-05-18 16:54:36 +0200 | [diff] [blame] | 5619 | u8 *ptr; |
Szymon Janc | 6818375 | 2015-09-16 20:21:54 +0200 | [diff] [blame] | 5620 | |
Johan Hedberg | 56b40fb | 2016-04-07 21:01:27 +0300 | [diff] [blame] | 5621 | switch (type) { |
| 5622 | case LE_ADV_IND: |
| 5623 | case LE_ADV_DIRECT_IND: |
| 5624 | case LE_ADV_SCAN_IND: |
| 5625 | case LE_ADV_NONCONN_IND: |
| 5626 | case LE_ADV_SCAN_RSP: |
| 5627 | break; |
| 5628 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 5629 | bt_dev_err_ratelimited(hdev, "unknown advertising packet " |
| 5630 | "type: 0x%02x", type); |
Johan Hedberg | 56b40fb | 2016-04-07 21:01:27 +0300 | [diff] [blame] | 5631 | return; |
| 5632 | } |
| 5633 | |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5634 | if (!ext_adv && len > HCI_MAX_AD_LENGTH) { |
| 5635 | bt_dev_err_ratelimited(hdev, "legacy adv larger than 31 bytes"); |
| 5636 | return; |
| 5637 | } |
| 5638 | |
Szymon Janc | 6818375 | 2015-09-16 20:21:54 +0200 | [diff] [blame] | 5639 | /* Find the end of the data in case the report contains padded zero |
| 5640 | * bytes at the end causing an invalid length value. |
| 5641 | * |
| 5642 | * When data is NULL, len is 0 so there is no need for extra ptr |
| 5643 | * check as 'ptr < data + 0' is already false in such case. |
| 5644 | */ |
| 5645 | for (ptr = data; ptr < data + len && *ptr; ptr += *ptr + 1) { |
| 5646 | if (ptr + 1 + *ptr > data + len) |
| 5647 | break; |
| 5648 | } |
| 5649 | |
Szymon Janc | 1c58e93 | 2021-05-18 16:54:36 +0200 | [diff] [blame] | 5650 | /* Adjust for actual length. This handles the case when remote |
| 5651 | * device is advertising with incorrect data length. |
| 5652 | */ |
| 5653 | len = ptr - data; |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5654 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5655 | /* If the direct address is present, then this report is from |
| 5656 | * a LE Direct Advertising Report event. In that case it is |
| 5657 | * important to see if the address is matching the local |
| 5658 | * controller address. |
| 5659 | */ |
| 5660 | if (direct_addr) { |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 5661 | direct_addr_type = ev_bdaddr_type(hdev, direct_addr_type, |
| 5662 | &bdaddr_resolved); |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 5663 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5664 | /* Only resolvable random addresses are valid for these |
| 5665 | * kind of reports and others can be ignored. |
| 5666 | */ |
| 5667 | if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type)) |
| 5668 | return; |
| 5669 | |
| 5670 | /* If the controller is not using resolvable random |
| 5671 | * addresses, then this report can be ignored. |
| 5672 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5673 | if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 5674 | return; |
| 5675 | |
| 5676 | /* If the local IRK of the controller does not match |
| 5677 | * with the resolvable random address provided, then |
| 5678 | * this report can be ignored. |
| 5679 | */ |
| 5680 | if (!smp_irk_matches(hdev, hdev->irk, direct_addr)) |
| 5681 | return; |
| 5682 | } |
| 5683 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5684 | /* Check if we need to convert to identity address */ |
| 5685 | irk = hci_get_irk(hdev, bdaddr, bdaddr_type); |
| 5686 | if (irk) { |
| 5687 | bdaddr = &irk->bdaddr; |
| 5688 | bdaddr_type = irk->addr_type; |
| 5689 | } |
| 5690 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 5691 | bdaddr_type = ev_bdaddr_type(hdev, bdaddr_type, &bdaddr_resolved); |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 5692 | |
Szymon Janc | 082f230 | 2018-04-03 13:40:06 +0200 | [diff] [blame] | 5693 | /* Check if we have been requested to connect to this device. |
| 5694 | * |
| 5695 | * direct_addr is set only for directed advertising reports (it is NULL |
| 5696 | * for advertising reports) and is already verified to be RPA above. |
| 5697 | */ |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 5698 | conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, bdaddr_resolved, |
| 5699 | type, direct_addr); |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5700 | 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] | 5701 | /* Store report for later inclusion by |
| 5702 | * mgmt_device_connected |
| 5703 | */ |
| 5704 | memcpy(conn->le_adv_data, data, len); |
| 5705 | conn->le_adv_data_len = len; |
| 5706 | } |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 5707 | |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 5708 | /* Passive scanning shouldn't trigger any device found events, |
| 5709 | * 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] | 5710 | * device found events, or advertisement monitoring requested. |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 5711 | */ |
Johan Hedberg | ca5c4be | 2014-03-25 10:30:46 +0200 | [diff] [blame] | 5712 | if (hdev->le_scan_type == LE_SCAN_PASSIVE) { |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 5713 | if (type == LE_ADV_DIRECT_IND) |
| 5714 | return; |
| 5715 | |
Johan Hedberg | 3a19b6f | 2014-07-15 08:07:59 +0300 | [diff] [blame] | 5716 | if (!hci_pend_le_action_lookup(&hdev->pend_le_reports, |
Miao-chen Chou | 8208f5a | 2020-06-17 16:39:18 +0200 | [diff] [blame] | 5717 | bdaddr, bdaddr_type) && |
| 5718 | idr_is_empty(&hdev->adv_monitors_idr)) |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 5719 | return; |
| 5720 | |
| 5721 | if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND) |
| 5722 | flags = MGMT_DEV_FOUND_NOT_CONNECTABLE; |
| 5723 | else |
| 5724 | flags = 0; |
| 5725 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
| 5726 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | 97bf2e9 | 2014-07-04 12:37:16 +0300 | [diff] [blame] | 5727 | return; |
Johan Hedberg | ca5c4be | 2014-03-25 10:30:46 +0200 | [diff] [blame] | 5728 | } |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5729 | |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5730 | /* When receiving non-connectable or scannable undirected |
| 5731 | * advertising reports, this means that the remote device is |
| 5732 | * not connectable and then clearly indicate this in the |
| 5733 | * device found event. |
| 5734 | * |
| 5735 | * When receiving a scan response, then there is no way to |
| 5736 | * know if the remote device is connectable or not. However |
| 5737 | * since scan responses are merged with a previously seen |
| 5738 | * advertising report, the flags field from that report |
| 5739 | * will be used. |
| 5740 | * |
| 5741 | * In the really unlikely case that a controller get confused |
| 5742 | * and just sends a scan response event, then it is marked as |
| 5743 | * not connectable as well. |
| 5744 | */ |
| 5745 | if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND || |
| 5746 | type == LE_ADV_SCAN_RSP) |
| 5747 | flags = MGMT_DEV_FOUND_NOT_CONNECTABLE; |
| 5748 | else |
| 5749 | flags = 0; |
| 5750 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5751 | /* If there's nothing pending either store the data from this |
| 5752 | * event or send an immediate device found event if the data |
| 5753 | * should not be stored for later. |
| 5754 | */ |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5755 | if (!ext_adv && !has_pending_adv_report(hdev)) { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5756 | /* If the report will trigger a SCAN_REQ store it for |
| 5757 | * later merging. |
| 5758 | */ |
| 5759 | if (type == LE_ADV_IND || type == LE_ADV_SCAN_IND) { |
| 5760 | store_pending_adv_report(hdev, bdaddr, bdaddr_type, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5761 | rssi, flags, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5762 | return; |
| 5763 | } |
| 5764 | |
| 5765 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5766 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5767 | return; |
| 5768 | } |
| 5769 | |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 5770 | /* Check if the pending report is for the same device as the new one */ |
| 5771 | match = (!bacmp(bdaddr, &d->last_adv_addr) && |
| 5772 | bdaddr_type == d->last_adv_addr_type); |
| 5773 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5774 | /* If the pending data doesn't match this report or this isn't a |
| 5775 | * scan response (e.g. we got a duplicate ADV_IND) then force |
| 5776 | * sending of the pending data. |
| 5777 | */ |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 5778 | if (type != LE_ADV_SCAN_RSP || !match) { |
| 5779 | /* Send out whatever is in the cache, but skip duplicates */ |
| 5780 | if (!match) |
| 5781 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 5782 | d->last_adv_addr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5783 | d->last_adv_rssi, d->last_adv_flags, |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 5784 | d->last_adv_data, |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 5785 | d->last_adv_data_len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5786 | |
| 5787 | /* If the new report will trigger a SCAN_REQ store it for |
| 5788 | * later merging. |
| 5789 | */ |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5790 | if (!ext_adv && (type == LE_ADV_IND || |
| 5791 | type == LE_ADV_SCAN_IND)) { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5792 | store_pending_adv_report(hdev, bdaddr, bdaddr_type, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5793 | rssi, flags, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5794 | return; |
| 5795 | } |
| 5796 | |
| 5797 | /* The advertising reports cannot be merged, so clear |
| 5798 | * the pending report and send out a device found event. |
| 5799 | */ |
| 5800 | clear_pending_adv_report(hdev); |
Johan Hedberg | 5c5b93e | 2014-03-29 08:39:53 +0200 | [diff] [blame] | 5801 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5802 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5803 | return; |
| 5804 | } |
| 5805 | |
| 5806 | /* If we get here we've got a pending ADV_IND or ADV_SCAN_IND and |
| 5807 | * the new event is a SCAN_RSP. We can therefore proceed with |
| 5808 | * sending a merged device found event. |
| 5809 | */ |
| 5810 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 5811 | d->last_adv_addr_type, NULL, rssi, d->last_adv_flags, |
Marcel Holtmann | 42bd6a5 | 2014-07-01 14:11:19 +0200 | [diff] [blame] | 5812 | d->last_adv_data, d->last_adv_data_len, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 5813 | clear_pending_adv_report(hdev); |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5814 | } |
| 5815 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5816 | 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] | 5817 | { |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 5818 | u8 num_reports = skb->data[0]; |
| 5819 | void *ptr = &skb->data[1]; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 5820 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5821 | hci_dev_lock(hdev); |
| 5822 | |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 5823 | while (num_reports--) { |
| 5824 | struct hci_ev_le_advertising_info *ev = ptr; |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 5825 | s8 rssi; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5826 | |
Chriz Chow | ee64934 | 2018-04-20 15:46:24 +0800 | [diff] [blame] | 5827 | if (ev->length <= HCI_MAX_AD_LENGTH) { |
| 5828 | rssi = ev->data[ev->length]; |
| 5829 | process_adv_report(hdev, ev->evt_type, &ev->bdaddr, |
| 5830 | ev->bdaddr_type, NULL, 0, rssi, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5831 | ev->data, ev->length, false); |
Chriz Chow | ee64934 | 2018-04-20 15:46:24 +0800 | [diff] [blame] | 5832 | } else { |
| 5833 | bt_dev_err(hdev, "Dropping invalid advertising data"); |
| 5834 | } |
Andre Guedes | 3c9e919 | 2012-01-10 18:20:50 -0300 | [diff] [blame] | 5835 | |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 5836 | ptr += sizeof(*ev) + ev->length + 1; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 5837 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 5838 | |
| 5839 | hci_dev_unlock(hdev); |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 5840 | } |
| 5841 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 5842 | 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] | 5843 | { |
Jaganath Kanakkassery | b2cc976 | 2018-07-19 17:09:38 +0530 | [diff] [blame] | 5844 | if (evt_type & LE_EXT_ADV_LEGACY_PDU) { |
| 5845 | switch (evt_type) { |
| 5846 | case LE_LEGACY_ADV_IND: |
| 5847 | return LE_ADV_IND; |
| 5848 | case LE_LEGACY_ADV_DIRECT_IND: |
| 5849 | return LE_ADV_DIRECT_IND; |
| 5850 | case LE_LEGACY_ADV_SCAN_IND: |
| 5851 | return LE_ADV_SCAN_IND; |
| 5852 | case LE_LEGACY_NONCONN_IND: |
| 5853 | return LE_ADV_NONCONN_IND; |
| 5854 | case LE_LEGACY_SCAN_RSP_ADV: |
| 5855 | case LE_LEGACY_SCAN_RSP_ADV_SCAN: |
| 5856 | return LE_ADV_SCAN_RSP; |
| 5857 | } |
| 5858 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 5859 | goto invalid; |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5860 | } |
| 5861 | |
Jaganath Kanakkassery | b2cc976 | 2018-07-19 17:09:38 +0530 | [diff] [blame] | 5862 | if (evt_type & LE_EXT_ADV_CONN_IND) { |
| 5863 | if (evt_type & LE_EXT_ADV_DIRECT_IND) |
| 5864 | return LE_ADV_DIRECT_IND; |
| 5865 | |
| 5866 | return LE_ADV_IND; |
| 5867 | } |
| 5868 | |
| 5869 | if (evt_type & LE_EXT_ADV_SCAN_RSP) |
| 5870 | return LE_ADV_SCAN_RSP; |
| 5871 | |
| 5872 | if (evt_type & LE_EXT_ADV_SCAN_IND) |
| 5873 | return LE_ADV_SCAN_IND; |
| 5874 | |
| 5875 | if (evt_type == LE_EXT_ADV_NON_CONN_IND || |
| 5876 | evt_type & LE_EXT_ADV_DIRECT_IND) |
| 5877 | return LE_ADV_NONCONN_IND; |
| 5878 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 5879 | invalid: |
| 5880 | bt_dev_err_ratelimited(hdev, "Unknown advertising packet type: 0x%02x", |
| 5881 | evt_type); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5882 | |
| 5883 | return LE_ADV_INVALID; |
| 5884 | } |
| 5885 | |
| 5886 | static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5887 | { |
| 5888 | u8 num_reports = skb->data[0]; |
| 5889 | void *ptr = &skb->data[1]; |
| 5890 | |
| 5891 | hci_dev_lock(hdev); |
| 5892 | |
| 5893 | while (num_reports--) { |
| 5894 | struct hci_ev_le_ext_adv_report *ev = ptr; |
| 5895 | u8 legacy_evt_type; |
| 5896 | u16 evt_type; |
| 5897 | |
| 5898 | evt_type = __le16_to_cpu(ev->evt_type); |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 5899 | legacy_evt_type = ext_evt_type_to_legacy(hdev, evt_type); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5900 | if (legacy_evt_type != LE_ADV_INVALID) { |
| 5901 | process_adv_report(hdev, legacy_evt_type, &ev->bdaddr, |
| 5902 | ev->bdaddr_type, NULL, 0, ev->rssi, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 5903 | ev->data, ev->length, |
| 5904 | !(evt_type & LE_EXT_ADV_LEGACY_PDU)); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5905 | } |
| 5906 | |
Jaganath Kanakkassery | cd9151b | 2019-04-03 12:11:44 +0530 | [diff] [blame] | 5907 | ptr += sizeof(*ev) + ev->length; |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | hci_dev_unlock(hdev); |
| 5911 | } |
| 5912 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5913 | static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, |
| 5914 | struct sk_buff *skb) |
| 5915 | { |
| 5916 | struct hci_ev_le_remote_feat_complete *ev = (void *)skb->data; |
| 5917 | struct hci_conn *conn; |
| 5918 | |
| 5919 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5920 | |
| 5921 | hci_dev_lock(hdev); |
| 5922 | |
| 5923 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 5924 | if (conn) { |
| 5925 | if (!ev->status) |
| 5926 | memcpy(conn->features[0], ev->features, 8); |
| 5927 | |
| 5928 | if (conn->state == BT_CONFIG) { |
| 5929 | __u8 status; |
| 5930 | |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 5931 | /* If the local controller supports peripheral-initiated |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5932 | * features exchange, but the remote controller does |
| 5933 | * not, then it is possible that the error code 0x1a |
| 5934 | * for unsupported remote feature gets returned. |
| 5935 | * |
| 5936 | * In this specific case, allow the connection to |
| 5937 | * transition into connected state and mark it as |
| 5938 | * successful. |
| 5939 | */ |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 5940 | if (!conn->out && ev->status == 0x1a && |
| 5941 | (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 5942 | status = 0x00; |
| 5943 | else |
| 5944 | status = ev->status; |
| 5945 | |
| 5946 | conn->state = BT_CONNECTED; |
| 5947 | hci_connect_cfm(conn, status); |
| 5948 | hci_conn_drop(conn); |
| 5949 | } |
| 5950 | } |
| 5951 | |
| 5952 | hci_dev_unlock(hdev); |
| 5953 | } |
| 5954 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5955 | 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] | 5956 | { |
| 5957 | struct hci_ev_le_ltk_req *ev = (void *) skb->data; |
| 5958 | struct hci_cp_le_ltk_reply cp; |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 5959 | struct hci_cp_le_ltk_neg_reply neg; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5960 | struct hci_conn *conn; |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 5961 | struct smp_ltk *ltk; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5962 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 5963 | 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] | 5964 | |
| 5965 | hci_dev_lock(hdev); |
| 5966 | |
| 5967 | 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] | 5968 | if (conn == NULL) |
| 5969 | goto not_found; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5970 | |
Johan Hedberg | f3a73d9 | 2014-05-29 15:02:59 +0300 | [diff] [blame] | 5971 | ltk = hci_find_ltk(hdev, &conn->dst, conn->dst_type, conn->role); |
Johan Hedberg | 5378bc5 | 2014-05-29 14:00:39 +0300 | [diff] [blame] | 5972 | if (!ltk) |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 5973 | goto not_found; |
| 5974 | |
Johan Hedberg | 5378bc5 | 2014-05-29 14:00:39 +0300 | [diff] [blame] | 5975 | if (smp_ltk_is_sc(ltk)) { |
| 5976 | /* With SC both EDiv and Rand are set to zero */ |
| 5977 | if (ev->ediv || ev->rand) |
| 5978 | goto not_found; |
| 5979 | } else { |
| 5980 | /* For non-SC keys check that EDiv and Rand match */ |
| 5981 | if (ev->ediv != ltk->ediv || ev->rand != ltk->rand) |
| 5982 | goto not_found; |
| 5983 | } |
| 5984 | |
Johan Hedberg | 8b76ce3 | 2015-06-08 18:14:39 +0300 | [diff] [blame] | 5985 | memcpy(cp.ltk, ltk->val, ltk->enc_size); |
| 5986 | 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] | 5987 | cp.handle = cpu_to_le16(conn->handle); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 5988 | |
Johan Hedberg | a6f7833 | 2014-09-10 17:37:45 -0700 | [diff] [blame] | 5989 | conn->pending_sec_level = smp_ltk_sec_level(ltk); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5990 | |
Andre Guedes | 89cbb4d | 2013-07-31 16:25:29 -0300 | [diff] [blame] | 5991 | conn->enc_key_size = ltk->enc_size; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 5992 | |
| 5993 | hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp); |
| 5994 | |
Claudio Takahasi | 5981a88 | 2013-07-25 16:34:24 -0300 | [diff] [blame] | 5995 | /* Ref. Bluetooth Core SPEC pages 1975 and 2004. STK is a |
| 5996 | * temporary key used to encrypt a connection following |
| 5997 | * pairing. It is used during the Encrypted Session Setup to |
| 5998 | * distribute the keys. Later, security can be re-established |
| 5999 | * using a distributed LTK. |
| 6000 | */ |
Johan Hedberg | 2ceba53 | 2014-06-16 19:25:16 +0300 | [diff] [blame] | 6001 | if (ltk->type == SMP_STK) { |
Johan Hedberg | fe59a05 | 2014-07-01 19:14:12 +0300 | [diff] [blame] | 6002 | set_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); |
Johan Hedberg | 970d0f1 | 2014-11-13 14:37:47 +0200 | [diff] [blame] | 6003 | list_del_rcu(<k->list); |
| 6004 | kfree_rcu(ltk, rcu); |
Johan Hedberg | fe59a05 | 2014-07-01 19:14:12 +0300 | [diff] [blame] | 6005 | } else { |
| 6006 | clear_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 6007 | } |
| 6008 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6009 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 6010 | |
| 6011 | return; |
| 6012 | |
| 6013 | not_found: |
| 6014 | neg.handle = ev->handle; |
| 6015 | hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg); |
| 6016 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6017 | } |
| 6018 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 6019 | static void send_conn_param_neg_reply(struct hci_dev *hdev, u16 handle, |
| 6020 | u8 reason) |
| 6021 | { |
| 6022 | struct hci_cp_le_conn_param_req_neg_reply cp; |
| 6023 | |
| 6024 | cp.handle = cpu_to_le16(handle); |
| 6025 | cp.reason = reason; |
| 6026 | |
| 6027 | hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY, sizeof(cp), |
| 6028 | &cp); |
| 6029 | } |
| 6030 | |
| 6031 | static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, |
| 6032 | struct sk_buff *skb) |
| 6033 | { |
| 6034 | struct hci_ev_le_remote_conn_param_req *ev = (void *) skb->data; |
| 6035 | struct hci_cp_le_conn_param_req_reply cp; |
| 6036 | struct hci_conn *hcon; |
| 6037 | u16 handle, min, max, latency, timeout; |
| 6038 | |
| 6039 | handle = le16_to_cpu(ev->handle); |
| 6040 | min = le16_to_cpu(ev->interval_min); |
| 6041 | max = le16_to_cpu(ev->interval_max); |
| 6042 | latency = le16_to_cpu(ev->latency); |
| 6043 | timeout = le16_to_cpu(ev->timeout); |
| 6044 | |
| 6045 | hcon = hci_conn_hash_lookup_handle(hdev, handle); |
| 6046 | if (!hcon || hcon->state != BT_CONNECTED) |
| 6047 | return send_conn_param_neg_reply(hdev, handle, |
| 6048 | HCI_ERROR_UNKNOWN_CONN_ID); |
| 6049 | |
| 6050 | if (hci_check_conn_params(min, max, latency, timeout)) |
| 6051 | return send_conn_param_neg_reply(hdev, handle, |
| 6052 | HCI_ERROR_INVALID_LL_PARAMS); |
| 6053 | |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 6054 | if (hcon->role == HCI_ROLE_MASTER) { |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 6055 | struct hci_conn_params *params; |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 6056 | u8 store_hint; |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 6057 | |
| 6058 | hci_dev_lock(hdev); |
| 6059 | |
| 6060 | params = hci_conn_params_lookup(hdev, &hcon->dst, |
| 6061 | hcon->dst_type); |
| 6062 | if (params) { |
| 6063 | params->conn_min_interval = min; |
| 6064 | params->conn_max_interval = max; |
| 6065 | params->conn_latency = latency; |
| 6066 | params->supervision_timeout = timeout; |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 6067 | store_hint = 0x01; |
Meng Yu | 149b3f1 | 2021-04-01 14:50:39 +0800 | [diff] [blame] | 6068 | } else { |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 6069 | store_hint = 0x00; |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | hci_dev_unlock(hdev); |
| 6073 | |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 6074 | mgmt_new_conn_param(hdev, &hcon->dst, hcon->dst_type, |
| 6075 | store_hint, min, max, latency, timeout); |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 6076 | } |
Andre Guedes | ffb5a827 | 2014-07-01 18:10:11 -0300 | [diff] [blame] | 6077 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 6078 | cp.handle = ev->handle; |
| 6079 | cp.interval_min = ev->interval_min; |
| 6080 | cp.interval_max = ev->interval_max; |
| 6081 | cp.latency = ev->latency; |
| 6082 | cp.timeout = ev->timeout; |
| 6083 | cp.min_ce_len = 0; |
| 6084 | cp.max_ce_len = 0; |
| 6085 | |
| 6086 | hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp); |
| 6087 | } |
| 6088 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6089 | static void hci_le_direct_adv_report_evt(struct hci_dev *hdev, |
| 6090 | struct sk_buff *skb) |
| 6091 | { |
| 6092 | u8 num_reports = skb->data[0]; |
Peilin Ye | f7e0e8b | 2020-09-09 03:17:00 -0400 | [diff] [blame] | 6093 | struct hci_ev_le_direct_adv_info *ev = (void *)&skb->data[1]; |
| 6094 | |
| 6095 | if (!num_reports || skb->len < num_reports * sizeof(*ev) + 1) |
| 6096 | return; |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6097 | |
| 6098 | hci_dev_lock(hdev); |
| 6099 | |
Peilin Ye | f7e0e8b | 2020-09-09 03:17:00 -0400 | [diff] [blame] | 6100 | for (; num_reports; num_reports--, ev++) |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6101 | process_adv_report(hdev, ev->evt_type, &ev->bdaddr, |
| 6102 | ev->bdaddr_type, &ev->direct_addr, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6103 | ev->direct_addr_type, ev->rssi, NULL, 0, |
| 6104 | false); |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6105 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6106 | hci_dev_unlock(hdev); |
| 6107 | } |
| 6108 | |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 6109 | static void hci_le_phy_update_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 6110 | { |
| 6111 | struct hci_ev_le_phy_update_complete *ev = (void *) skb->data; |
| 6112 | struct hci_conn *conn; |
| 6113 | |
| 6114 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 6115 | |
Ayush Garg | 87df8bc | 2021-03-17 16:52:14 +0530 | [diff] [blame] | 6116 | if (ev->status) |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 6117 | return; |
| 6118 | |
| 6119 | hci_dev_lock(hdev); |
| 6120 | |
| 6121 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 6122 | if (!conn) |
| 6123 | goto unlock; |
| 6124 | |
| 6125 | conn->le_tx_phy = ev->tx_phy; |
| 6126 | conn->le_rx_phy = ev->rx_phy; |
| 6127 | |
| 6128 | unlock: |
| 6129 | hci_dev_unlock(hdev); |
| 6130 | } |
| 6131 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 6132 | 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] | 6133 | { |
| 6134 | struct hci_ev_le_meta *le_ev = (void *) skb->data; |
| 6135 | |
| 6136 | skb_pull(skb, sizeof(*le_ev)); |
| 6137 | |
| 6138 | switch (le_ev->subevent) { |
| 6139 | case HCI_EV_LE_CONN_COMPLETE: |
| 6140 | hci_le_conn_complete_evt(hdev, skb); |
| 6141 | break; |
| 6142 | |
Marcel Holtmann | 1855d92 | 2014-06-23 11:40:05 +0200 | [diff] [blame] | 6143 | case HCI_EV_LE_CONN_UPDATE_COMPLETE: |
| 6144 | hci_le_conn_update_complete_evt(hdev, skb); |
| 6145 | break; |
| 6146 | |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 6147 | case HCI_EV_LE_ADVERTISING_REPORT: |
| 6148 | hci_le_adv_report_evt(hdev, skb); |
| 6149 | break; |
| 6150 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6151 | case HCI_EV_LE_REMOTE_FEAT_COMPLETE: |
| 6152 | hci_le_remote_feat_complete_evt(hdev, skb); |
| 6153 | break; |
| 6154 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6155 | case HCI_EV_LE_LTK_REQ: |
| 6156 | hci_le_ltk_request_evt(hdev, skb); |
| 6157 | break; |
| 6158 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 6159 | case HCI_EV_LE_REMOTE_CONN_PARAM_REQ: |
| 6160 | hci_le_remote_conn_param_req_evt(hdev, skb); |
| 6161 | break; |
| 6162 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6163 | case HCI_EV_LE_DIRECT_ADV_REPORT: |
| 6164 | hci_le_direct_adv_report_evt(hdev, skb); |
| 6165 | break; |
| 6166 | |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 6167 | case HCI_EV_LE_PHY_UPDATE_COMPLETE: |
| 6168 | hci_le_phy_update_evt(hdev, skb); |
| 6169 | break; |
| 6170 | |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 6171 | case HCI_EV_LE_EXT_ADV_REPORT: |
| 6172 | hci_le_ext_adv_report_evt(hdev, skb); |
| 6173 | break; |
| 6174 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 6175 | case HCI_EV_LE_ENHANCED_CONN_COMPLETE: |
| 6176 | hci_le_enh_conn_complete_evt(hdev, skb); |
| 6177 | break; |
| 6178 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6179 | case HCI_EV_LE_EXT_ADV_SET_TERM: |
| 6180 | hci_le_ext_adv_term_evt(hdev, skb); |
| 6181 | break; |
| 6182 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6183 | default: |
| 6184 | break; |
| 6185 | } |
| 6186 | } |
| 6187 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6188 | static bool hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode, |
| 6189 | u8 event, struct sk_buff *skb) |
| 6190 | { |
| 6191 | struct hci_ev_cmd_complete *ev; |
| 6192 | struct hci_event_hdr *hdr; |
| 6193 | |
| 6194 | if (!skb) |
| 6195 | return false; |
| 6196 | |
| 6197 | if (skb->len < sizeof(*hdr)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 6198 | bt_dev_err(hdev, "too short HCI event"); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6199 | return false; |
| 6200 | } |
| 6201 | |
| 6202 | hdr = (void *) skb->data; |
| 6203 | skb_pull(skb, HCI_EVENT_HDR_SIZE); |
| 6204 | |
| 6205 | if (event) { |
| 6206 | if (hdr->evt != event) |
| 6207 | return false; |
| 6208 | return true; |
| 6209 | } |
| 6210 | |
Zheng Yongjun | 91641b7 | 2021-06-02 14:54:58 +0800 | [diff] [blame] | 6211 | /* Check if request ended in Command Status - no way to retrieve |
Johan Hedberg | 1629db9c | 2018-11-27 11:37:46 +0200 | [diff] [blame] | 6212 | * any extra parameters in this case. |
| 6213 | */ |
| 6214 | if (hdr->evt == HCI_EV_CMD_STATUS) |
| 6215 | return false; |
| 6216 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6217 | if (hdr->evt != HCI_EV_CMD_COMPLETE) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 6218 | bt_dev_err(hdev, "last event is not cmd complete (0x%2.2x)", |
| 6219 | hdr->evt); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6220 | return false; |
| 6221 | } |
| 6222 | |
| 6223 | if (skb->len < sizeof(*ev)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 6224 | bt_dev_err(hdev, "too short cmd_complete event"); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6225 | return false; |
| 6226 | } |
| 6227 | |
| 6228 | ev = (void *) skb->data; |
| 6229 | skb_pull(skb, sizeof(*ev)); |
| 6230 | |
| 6231 | if (opcode != __le16_to_cpu(ev->opcode)) { |
| 6232 | BT_DBG("opcode doesn't match (0x%2.2x != 0x%2.2x)", opcode, |
| 6233 | __le16_to_cpu(ev->opcode)); |
| 6234 | return false; |
| 6235 | } |
| 6236 | |
| 6237 | return true; |
| 6238 | } |
| 6239 | |
Abhishek Pandit-Subedi | 2f20216 | 2020-09-11 14:07:13 -0700 | [diff] [blame] | 6240 | static void hci_store_wake_reason(struct hci_dev *hdev, u8 event, |
| 6241 | struct sk_buff *skb) |
| 6242 | { |
| 6243 | struct hci_ev_le_advertising_info *adv; |
| 6244 | struct hci_ev_le_direct_adv_info *direct_adv; |
| 6245 | struct hci_ev_le_ext_adv_report *ext_adv; |
| 6246 | const struct hci_ev_conn_complete *conn_complete = (void *)skb->data; |
| 6247 | const struct hci_ev_conn_request *conn_request = (void *)skb->data; |
| 6248 | |
| 6249 | hci_dev_lock(hdev); |
| 6250 | |
| 6251 | /* If we are currently suspended and this is the first BT event seen, |
| 6252 | * save the wake reason associated with the event. |
| 6253 | */ |
| 6254 | if (!hdev->suspended || hdev->wake_reason) |
| 6255 | goto unlock; |
| 6256 | |
| 6257 | /* Default to remote wake. Values for wake_reason are documented in the |
| 6258 | * Bluez mgmt api docs. |
| 6259 | */ |
| 6260 | hdev->wake_reason = MGMT_WAKE_REASON_REMOTE_WAKE; |
| 6261 | |
| 6262 | /* Once configured for remote wakeup, we should only wake up for |
| 6263 | * reconnections. It's useful to see which device is waking us up so |
| 6264 | * keep track of the bdaddr of the connection event that woke us up. |
| 6265 | */ |
| 6266 | if (event == HCI_EV_CONN_REQUEST) { |
| 6267 | bacpy(&hdev->wake_addr, &conn_complete->bdaddr); |
| 6268 | hdev->wake_addr_type = BDADDR_BREDR; |
| 6269 | } else if (event == HCI_EV_CONN_COMPLETE) { |
| 6270 | bacpy(&hdev->wake_addr, &conn_request->bdaddr); |
| 6271 | hdev->wake_addr_type = BDADDR_BREDR; |
| 6272 | } else if (event == HCI_EV_LE_META) { |
| 6273 | struct hci_ev_le_meta *le_ev = (void *)skb->data; |
| 6274 | u8 subevent = le_ev->subevent; |
| 6275 | u8 *ptr = &skb->data[sizeof(*le_ev)]; |
| 6276 | u8 num_reports = *ptr; |
| 6277 | |
| 6278 | if ((subevent == HCI_EV_LE_ADVERTISING_REPORT || |
| 6279 | subevent == HCI_EV_LE_DIRECT_ADV_REPORT || |
| 6280 | subevent == HCI_EV_LE_EXT_ADV_REPORT) && |
| 6281 | num_reports) { |
| 6282 | adv = (void *)(ptr + 1); |
| 6283 | direct_adv = (void *)(ptr + 1); |
| 6284 | ext_adv = (void *)(ptr + 1); |
| 6285 | |
| 6286 | switch (subevent) { |
| 6287 | case HCI_EV_LE_ADVERTISING_REPORT: |
| 6288 | bacpy(&hdev->wake_addr, &adv->bdaddr); |
| 6289 | hdev->wake_addr_type = adv->bdaddr_type; |
| 6290 | break; |
| 6291 | case HCI_EV_LE_DIRECT_ADV_REPORT: |
| 6292 | bacpy(&hdev->wake_addr, &direct_adv->bdaddr); |
| 6293 | hdev->wake_addr_type = direct_adv->bdaddr_type; |
| 6294 | break; |
| 6295 | case HCI_EV_LE_EXT_ADV_REPORT: |
| 6296 | bacpy(&hdev->wake_addr, &ext_adv->bdaddr); |
| 6297 | hdev->wake_addr_type = ext_adv->bdaddr_type; |
| 6298 | break; |
| 6299 | } |
| 6300 | } |
| 6301 | } else { |
| 6302 | hdev->wake_reason = MGMT_WAKE_REASON_UNEXPECTED; |
| 6303 | } |
| 6304 | |
| 6305 | unlock: |
| 6306 | hci_dev_unlock(hdev); |
| 6307 | } |
| 6308 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) |
| 6310 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6311 | struct hci_event_hdr *hdr = (void *) skb->data; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6312 | hci_req_complete_t req_complete = NULL; |
| 6313 | hci_req_complete_skb_t req_complete_skb = NULL; |
| 6314 | struct sk_buff *orig_skb = NULL; |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6315 | u8 status = 0, event = hdr->evt, req_evt = 0; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6316 | u16 opcode = HCI_OP_NOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6317 | |
Alain Michaud | 08bb4da | 2020-03-03 15:55:34 +0000 | [diff] [blame] | 6318 | if (!event) { |
| 6319 | bt_dev_warn(hdev, "Received unexpected HCI Event 00000000"); |
| 6320 | goto done; |
| 6321 | } |
| 6322 | |
Marcel Holtmann | 242c0eb | 2015-10-25 22:45:53 +0100 | [diff] [blame] | 6323 | 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] | 6324 | struct hci_command_hdr *cmd_hdr = (void *) hdev->sent_cmd->data; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6325 | opcode = __le16_to_cpu(cmd_hdr->opcode); |
| 6326 | hci_req_cmd_complete(hdev, opcode, status, &req_complete, |
| 6327 | &req_complete_skb); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6328 | req_evt = event; |
Johan Hedberg | 02350a7 | 2013-04-03 21:50:29 +0300 | [diff] [blame] | 6329 | } |
| 6330 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6331 | /* If it looks like we might end up having to call |
| 6332 | * req_complete_skb, store a pristine copy of the skb since the |
| 6333 | * various handlers may modify the original one through |
| 6334 | * skb_pull() calls, etc. |
| 6335 | */ |
| 6336 | if (req_complete_skb || event == HCI_EV_CMD_STATUS || |
| 6337 | event == HCI_EV_CMD_COMPLETE) |
| 6338 | orig_skb = skb_clone(skb, GFP_KERNEL); |
| 6339 | |
| 6340 | skb_pull(skb, HCI_EVENT_HDR_SIZE); |
| 6341 | |
Abhishek Pandit-Subedi | 2f20216 | 2020-09-11 14:07:13 -0700 | [diff] [blame] | 6342 | /* Store wake reason if we're suspended */ |
| 6343 | hci_store_wake_reason(hdev, event, skb); |
| 6344 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6345 | switch (event) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6346 | case HCI_EV_INQUIRY_COMPLETE: |
| 6347 | hci_inquiry_complete_evt(hdev, skb); |
| 6348 | break; |
| 6349 | |
| 6350 | case HCI_EV_INQUIRY_RESULT: |
| 6351 | hci_inquiry_result_evt(hdev, skb); |
| 6352 | break; |
| 6353 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6354 | case HCI_EV_CONN_COMPLETE: |
| 6355 | hci_conn_complete_evt(hdev, skb); |
Marcel Holtmann | 21d9e30 | 2005-09-13 01:32:25 +0200 | [diff] [blame] | 6356 | break; |
| 6357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6358 | case HCI_EV_CONN_REQUEST: |
| 6359 | hci_conn_request_evt(hdev, skb); |
| 6360 | break; |
| 6361 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6362 | case HCI_EV_DISCONN_COMPLETE: |
| 6363 | hci_disconn_complete_evt(hdev, skb); |
| 6364 | break; |
| 6365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6366 | case HCI_EV_AUTH_COMPLETE: |
| 6367 | hci_auth_complete_evt(hdev, skb); |
| 6368 | break; |
| 6369 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6370 | case HCI_EV_REMOTE_NAME: |
| 6371 | hci_remote_name_evt(hdev, skb); |
| 6372 | break; |
| 6373 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6374 | case HCI_EV_ENCRYPT_CHANGE: |
| 6375 | hci_encrypt_change_evt(hdev, skb); |
| 6376 | break; |
| 6377 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6378 | case HCI_EV_CHANGE_LINK_KEY_COMPLETE: |
| 6379 | hci_change_link_key_complete_evt(hdev, skb); |
| 6380 | break; |
| 6381 | |
| 6382 | case HCI_EV_REMOTE_FEATURES: |
| 6383 | hci_remote_features_evt(hdev, skb); |
| 6384 | break; |
| 6385 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6386 | case HCI_EV_CMD_COMPLETE: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6387 | hci_cmd_complete_evt(hdev, skb, &opcode, &status, |
| 6388 | &req_complete, &req_complete_skb); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6389 | break; |
| 6390 | |
| 6391 | case HCI_EV_CMD_STATUS: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6392 | hci_cmd_status_evt(hdev, skb, &opcode, &status, &req_complete, |
| 6393 | &req_complete_skb); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6394 | break; |
| 6395 | |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 6396 | case HCI_EV_HARDWARE_ERROR: |
| 6397 | hci_hardware_error_evt(hdev, skb); |
| 6398 | break; |
| 6399 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6400 | case HCI_EV_ROLE_CHANGE: |
| 6401 | hci_role_change_evt(hdev, skb); |
| 6402 | break; |
| 6403 | |
| 6404 | case HCI_EV_NUM_COMP_PKTS: |
| 6405 | hci_num_comp_pkts_evt(hdev, skb); |
| 6406 | break; |
| 6407 | |
| 6408 | case HCI_EV_MODE_CHANGE: |
| 6409 | hci_mode_change_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6410 | break; |
| 6411 | |
| 6412 | case HCI_EV_PIN_CODE_REQ: |
| 6413 | hci_pin_code_request_evt(hdev, skb); |
| 6414 | break; |
| 6415 | |
| 6416 | case HCI_EV_LINK_KEY_REQ: |
| 6417 | hci_link_key_request_evt(hdev, skb); |
| 6418 | break; |
| 6419 | |
| 6420 | case HCI_EV_LINK_KEY_NOTIFY: |
| 6421 | hci_link_key_notify_evt(hdev, skb); |
| 6422 | break; |
| 6423 | |
| 6424 | case HCI_EV_CLOCK_OFFSET: |
| 6425 | hci_clock_offset_evt(hdev, skb); |
| 6426 | break; |
| 6427 | |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 6428 | case HCI_EV_PKT_TYPE_CHANGE: |
| 6429 | hci_pkt_type_change_evt(hdev, skb); |
| 6430 | break; |
| 6431 | |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 6432 | case HCI_EV_PSCAN_REP_MODE: |
| 6433 | hci_pscan_rep_mode_evt(hdev, skb); |
| 6434 | break; |
| 6435 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6436 | case HCI_EV_INQUIRY_RESULT_WITH_RSSI: |
| 6437 | hci_inquiry_result_with_rssi_evt(hdev, skb); |
| 6438 | break; |
| 6439 | |
| 6440 | case HCI_EV_REMOTE_EXT_FEATURES: |
| 6441 | hci_remote_ext_features_evt(hdev, skb); |
| 6442 | break; |
| 6443 | |
| 6444 | case HCI_EV_SYNC_CONN_COMPLETE: |
| 6445 | hci_sync_conn_complete_evt(hdev, skb); |
| 6446 | break; |
| 6447 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6448 | case HCI_EV_EXTENDED_INQUIRY_RESULT: |
| 6449 | hci_extended_inquiry_result_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6450 | break; |
| 6451 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 6452 | case HCI_EV_KEY_REFRESH_COMPLETE: |
| 6453 | hci_key_refresh_complete_evt(hdev, skb); |
| 6454 | break; |
| 6455 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 6456 | case HCI_EV_IO_CAPA_REQUEST: |
| 6457 | hci_io_capa_request_evt(hdev, skb); |
| 6458 | break; |
| 6459 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 6460 | case HCI_EV_IO_CAPA_REPLY: |
| 6461 | hci_io_capa_reply_evt(hdev, skb); |
| 6462 | break; |
| 6463 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 6464 | case HCI_EV_USER_CONFIRM_REQUEST: |
| 6465 | hci_user_confirm_request_evt(hdev, skb); |
| 6466 | break; |
| 6467 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 6468 | case HCI_EV_USER_PASSKEY_REQUEST: |
| 6469 | hci_user_passkey_request_evt(hdev, skb); |
| 6470 | break; |
| 6471 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 6472 | case HCI_EV_USER_PASSKEY_NOTIFY: |
| 6473 | hci_user_passkey_notify_evt(hdev, skb); |
| 6474 | break; |
| 6475 | |
| 6476 | case HCI_EV_KEYPRESS_NOTIFY: |
| 6477 | hci_keypress_notify_evt(hdev, skb); |
| 6478 | break; |
| 6479 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 6480 | case HCI_EV_SIMPLE_PAIR_COMPLETE: |
| 6481 | hci_simple_pair_complete_evt(hdev, skb); |
| 6482 | break; |
| 6483 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 6484 | case HCI_EV_REMOTE_HOST_FEATURES: |
| 6485 | hci_remote_host_features_evt(hdev, skb); |
| 6486 | break; |
| 6487 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6488 | case HCI_EV_LE_META: |
| 6489 | hci_le_meta_evt(hdev, skb); |
| 6490 | break; |
| 6491 | |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 6492 | case HCI_EV_REMOTE_OOB_DATA_REQUEST: |
| 6493 | hci_remote_oob_data_request_evt(hdev, skb); |
| 6494 | break; |
| 6495 | |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 6496 | #if IS_ENABLED(CONFIG_BT_HS) |
| 6497 | case HCI_EV_CHANNEL_SELECTED: |
| 6498 | hci_chan_selected_evt(hdev, skb); |
| 6499 | break; |
| 6500 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 6501 | case HCI_EV_PHY_LINK_COMPLETE: |
| 6502 | hci_phy_link_complete_evt(hdev, skb); |
| 6503 | break; |
| 6504 | |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 6505 | case HCI_EV_LOGICAL_LINK_COMPLETE: |
| 6506 | hci_loglink_complete_evt(hdev, skb); |
| 6507 | break; |
| 6508 | |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 6509 | case HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE: |
| 6510 | hci_disconn_loglink_complete_evt(hdev, skb); |
| 6511 | break; |
| 6512 | |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 6513 | case HCI_EV_DISCONN_PHY_LINK_COMPLETE: |
| 6514 | hci_disconn_phylink_complete_evt(hdev, skb); |
| 6515 | break; |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 6516 | #endif |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 6517 | |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 6518 | case HCI_EV_NUM_COMP_BLOCKS: |
| 6519 | hci_num_comp_blocks_evt(hdev, skb); |
| 6520 | break; |
| 6521 | |
Miao-chen Chou | 145373c | 2020-04-03 21:44:01 +0200 | [diff] [blame] | 6522 | case HCI_EV_VENDOR: |
| 6523 | msft_vendor_evt(hdev, skb); |
| 6524 | break; |
| 6525 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 6526 | default: |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 6527 | BT_DBG("%s event 0x%2.2x", hdev->name, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6528 | break; |
| 6529 | } |
| 6530 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6531 | if (req_complete) { |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6532 | req_complete(hdev, status, opcode); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6533 | } else if (req_complete_skb) { |
| 6534 | if (!hci_get_cmd_complete(hdev, opcode, req_evt, orig_skb)) { |
| 6535 | kfree_skb(orig_skb); |
| 6536 | orig_skb = NULL; |
| 6537 | } |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6538 | req_complete_skb(hdev, status, opcode, orig_skb); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6539 | } |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6540 | |
Alain Michaud | 08bb4da | 2020-03-03 15:55:34 +0000 | [diff] [blame] | 6541 | done: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 6542 | kfree_skb(orig_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6543 | kfree_skb(skb); |
| 6544 | hdev->stat.evt_rx++; |
| 6545 | } |