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" |
Luiz Augusto von Dentz | 01ce70b | 2021-09-20 15:59:37 -0700 | [diff] [blame] | 39 | #include "eir.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Marcel Holtmann | aa5b034 | 2015-01-27 16:04:33 -0800 | [diff] [blame] | 41 | #define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \ |
| 42 | "\x00\x00\x00\x00\x00\x00\x00\x00" |
| 43 | |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 44 | #define secs_to_jiffies(_secs) msecs_to_jiffies((_secs) * 1000) |
| 45 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | /* Handle HCI Event packets */ |
| 47 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 48 | static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb, |
| 49 | u8 ev, size_t len) |
| 50 | { |
| 51 | void *data; |
| 52 | |
| 53 | data = skb_pull_data(skb, len); |
| 54 | if (!data) |
| 55 | bt_dev_err(hdev, "Malformed Event: 0x%2.2x", ev); |
| 56 | |
| 57 | return data; |
| 58 | } |
| 59 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 60 | static void *hci_cc_skb_pull(struct hci_dev *hdev, struct sk_buff *skb, |
| 61 | u16 op, size_t len) |
| 62 | { |
| 63 | void *data; |
| 64 | |
| 65 | data = skb_pull_data(skb, len); |
| 66 | if (!data) |
| 67 | bt_dev_err(hdev, "Malformed Command Complete: 0x%4.4x", op); |
| 68 | |
| 69 | return data; |
| 70 | } |
| 71 | |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 72 | static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb, |
| 73 | u8 *new_status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 75 | struct hci_ev_status *rp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 77 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_INQUIRY_CANCEL, sizeof(*rp)); |
| 78 | if (!rp) |
| 79 | return; |
| 80 | |
| 81 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 83 | /* It is possible that we receive Inquiry Complete event right |
| 84 | * before we receive Inquiry Cancel Command Complete event, in |
| 85 | * which case the latter event should have status of Command |
| 86 | * Disallowed (0x0c). This should not be treated as error, since |
| 87 | * we actually achieve what Inquiry Cancel wants to achieve, |
| 88 | * which is to end the last Inquiry session. |
| 89 | */ |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 90 | if (rp->status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) { |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 91 | bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command"); |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 92 | rp->status = 0x00; |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 95 | *new_status = rp->status; |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 96 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 97 | if (rp->status) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 98 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 100 | clear_bit(HCI_INQUIRY, &hdev->flags); |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 101 | smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */ |
Andre Guedes | 3e13fa1 | 2013-03-27 20:04:56 -0300 | [diff] [blame] | 102 | wake_up_bit(&hdev->flags, HCI_INQUIRY); |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 103 | |
Johan Hedberg | 50143a4 | 2014-06-10 14:05:57 +0300 | [diff] [blame] | 104 | hci_dev_lock(hdev); |
Jakub Pawlowski | 168b8a2 | 2015-10-16 10:07:49 +0300 | [diff] [blame] | 105 | /* Set discovery state to stopped if we're not doing LE active |
| 106 | * scanning. |
| 107 | */ |
| 108 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 109 | hdev->le_scan_type != LE_SCAN_ACTIVE) |
| 110 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 50143a4 | 2014-06-10 14:05:57 +0300 | [diff] [blame] | 111 | hci_dev_unlock(hdev); |
| 112 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 113 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 116 | static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb) |
| 117 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 118 | struct hci_ev_status *rp; |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 119 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 120 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_PERIODIC_INQ, sizeof(*rp)); |
| 121 | if (!rp) |
| 122 | return; |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 123 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 124 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 125 | |
| 126 | if (rp->status) |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 127 | return; |
| 128 | |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 129 | hci_dev_set_flag(hdev, HCI_PERIODIC_INQ); |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 130 | } |
| 131 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 132 | 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] | 133 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 134 | struct hci_ev_status *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 135 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 136 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_EXIT_PERIODIC_INQ, sizeof(*rp)); |
| 137 | if (!rp) |
| 138 | return; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 139 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 140 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 141 | |
| 142 | if (rp->status) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 143 | return; |
| 144 | |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 145 | hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); |
Andre Guedes | ae854a7 | 2012-03-21 00:03:36 -0300 | [diff] [blame] | 146 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 147 | hci_conn_check_pending(hdev); |
| 148 | } |
| 149 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 150 | static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, |
| 151 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 152 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 153 | struct hci_ev_status *rp; |
| 154 | |
| 155 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_REMOTE_NAME_REQ_CANCEL, |
| 156 | sizeof(*rp)); |
| 157 | if (!rp) |
| 158 | return; |
| 159 | |
| 160 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb) |
| 164 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 165 | struct hci_rp_role_discovery *rp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 168 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_ROLE_DISCOVERY, sizeof(*rp)); |
| 169 | if (!rp) |
| 170 | return; |
| 171 | |
| 172 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 174 | if (rp->status) |
| 175 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 177 | hci_dev_lock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 179 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 180 | if (conn) |
| 181 | conn->role = rp->role; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 182 | |
| 183 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 186 | static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
| 187 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 188 | struct hci_rp_read_link_policy *rp; |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 189 | struct hci_conn *conn; |
| 190 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 191 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LINK_POLICY, sizeof(*rp)); |
| 192 | if (!rp) |
| 193 | return; |
| 194 | |
| 195 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 196 | |
| 197 | if (rp->status) |
| 198 | return; |
| 199 | |
| 200 | hci_dev_lock(hdev); |
| 201 | |
| 202 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 203 | if (conn) |
| 204 | conn->link_policy = __le16_to_cpu(rp->policy); |
| 205 | |
| 206 | hci_dev_unlock(hdev); |
| 207 | } |
| 208 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 209 | 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] | 210 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 211 | struct hci_rp_write_link_policy *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 212 | struct hci_conn *conn; |
| 213 | void *sent; |
| 214 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 215 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_LINK_POLICY, sizeof(*rp)); |
| 216 | if (!rp) |
| 217 | return; |
| 218 | |
| 219 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 220 | |
| 221 | if (rp->status) |
| 222 | return; |
| 223 | |
| 224 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY); |
| 225 | if (!sent) |
| 226 | return; |
| 227 | |
| 228 | hci_dev_lock(hdev); |
| 229 | |
| 230 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 231 | if (conn) |
Harvey Harrison | 8398531 | 2008-05-02 16:25:46 -0700 | [diff] [blame] | 232 | conn->link_policy = get_unaligned_le16(sent + 2); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 233 | |
| 234 | hci_dev_unlock(hdev); |
| 235 | } |
| 236 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 237 | static void hci_cc_read_def_link_policy(struct hci_dev *hdev, |
| 238 | struct sk_buff *skb) |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 239 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 240 | struct hci_rp_read_def_link_policy *rp; |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 241 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 242 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_DEF_LINK_POLICY, |
| 243 | sizeof(*rp)); |
| 244 | if (!rp) |
| 245 | return; |
| 246 | |
| 247 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 248 | |
| 249 | if (rp->status) |
| 250 | return; |
| 251 | |
| 252 | hdev->link_policy = __le16_to_cpu(rp->policy); |
| 253 | } |
| 254 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 255 | static void hci_cc_write_def_link_policy(struct hci_dev *hdev, |
| 256 | struct sk_buff *skb) |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 257 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 258 | struct hci_ev_status *rp; |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 259 | void *sent; |
| 260 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 261 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_DEF_LINK_POLICY, |
| 262 | sizeof(*rp)); |
| 263 | if (!rp) |
| 264 | return; |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 265 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 266 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 267 | |
| 268 | if (rp->status) |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 269 | return; |
| 270 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 271 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY); |
| 272 | if (!sent) |
| 273 | return; |
| 274 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 275 | hdev->link_policy = get_unaligned_le16(sent); |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 276 | } |
| 277 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 278 | static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) |
| 279 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 280 | struct hci_ev_status *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 281 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 282 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_RESET, sizeof(*rp)); |
| 283 | if (!rp) |
| 284 | return; |
| 285 | |
| 286 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 287 | |
Gustavo F. Padovan | 1057213 | 2011-03-16 15:36:29 -0300 | [diff] [blame] | 288 | clear_bit(HCI_RESET, &hdev->flags); |
| 289 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 290 | if (rp->status) |
Marcel Holtmann | 8761f9d | 2014-11-02 02:45:58 +0100 | [diff] [blame] | 291 | return; |
| 292 | |
Johan Hedberg | a297e97 | 2012-02-21 17:55:47 +0200 | [diff] [blame] | 293 | /* Reset all non-persistent flags */ |
Marcel Holtmann | eacb44d | 2015-03-13 09:04:17 -0700 | [diff] [blame] | 294 | hci_dev_clear_volatile_flags(hdev); |
Andre Guedes | 69775ff | 2012-02-23 16:50:05 +0200 | [diff] [blame] | 295 | |
Johan Hedberg | 39c5d97 | 2015-01-28 19:56:01 +0200 | [diff] [blame] | 296 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 297 | |
Johan Hedberg | bbaf444 | 2012-11-08 01:22:59 +0100 | [diff] [blame] | 298 | hdev->inq_tx_power = HCI_TX_POWER_INVALID; |
| 299 | hdev->adv_tx_power = HCI_TX_POWER_INVALID; |
Johan Hedberg | 3f0f524 | 2012-11-08 01:23:00 +0100 | [diff] [blame] | 300 | |
| 301 | memset(hdev->adv_data, 0, sizeof(hdev->adv_data)); |
| 302 | hdev->adv_data_len = 0; |
Marcel Holtmann | f8e808b | 2013-10-16 00:16:47 -0700 | [diff] [blame] | 303 | |
| 304 | memset(hdev->scan_rsp_data, 0, sizeof(hdev->scan_rsp_data)); |
| 305 | hdev->scan_rsp_data_len = 0; |
Marcel Holtmann | 06f5b77 | 2013-10-19 07:09:11 -0700 | [diff] [blame] | 306 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 307 | hdev->le_scan_type = LE_SCAN_PASSIVE; |
| 308 | |
Marcel Holtmann | 06f5b77 | 2013-10-19 07:09:11 -0700 | [diff] [blame] | 309 | hdev->ssp_debug_mode = 0; |
Marcel Holtmann | a4d5504 | 2014-10-29 23:37:53 +0100 | [diff] [blame] | 310 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 311 | hci_bdaddr_list_clear(&hdev->le_accept_list); |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 312 | hci_bdaddr_list_clear(&hdev->le_resolv_list); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 315 | static void hci_cc_read_stored_link_key(struct hci_dev *hdev, |
| 316 | struct sk_buff *skb) |
| 317 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 318 | struct hci_rp_read_stored_link_key *rp; |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 319 | struct hci_cp_read_stored_link_key *sent; |
| 320 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 321 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_STORED_LINK_KEY, |
| 322 | sizeof(*rp)); |
| 323 | if (!rp) |
| 324 | return; |
| 325 | |
| 326 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 327 | |
| 328 | sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY); |
| 329 | if (!sent) |
| 330 | return; |
| 331 | |
| 332 | if (!rp->status && sent->read_all == 0x01) { |
Luiz Augusto von Dentz | e88422b | 2021-11-24 16:16:12 -0800 | [diff] [blame] | 333 | hdev->stored_max_keys = le16_to_cpu(rp->max_keys); |
| 334 | hdev->stored_num_keys = le16_to_cpu(rp->num_keys); |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 338 | static void hci_cc_delete_stored_link_key(struct hci_dev *hdev, |
| 339 | struct sk_buff *skb) |
| 340 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 341 | struct hci_rp_delete_stored_link_key *rp; |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 342 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 343 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_DELETE_STORED_LINK_KEY, |
| 344 | sizeof(*rp)); |
| 345 | if (!rp) |
| 346 | return; |
| 347 | |
| 348 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 349 | |
| 350 | if (rp->status) |
| 351 | return; |
| 352 | |
| 353 | if (rp->num_keys <= hdev->stored_num_keys) |
Luiz Augusto von Dentz | 7978656 | 2021-11-24 16:16:13 -0800 | [diff] [blame] | 354 | hdev->stored_num_keys -= le16_to_cpu(rp->num_keys); |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 355 | else |
| 356 | hdev->stored_num_keys = 0; |
| 357 | } |
| 358 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 359 | static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 360 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 361 | struct hci_ev_status *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 362 | void *sent; |
| 363 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 364 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_LOCAL_NAME, sizeof(*rp)); |
| 365 | if (!rp) |
| 366 | return; |
| 367 | |
| 368 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 369 | |
| 370 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME); |
| 371 | if (!sent) |
| 372 | return; |
| 373 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 374 | hci_dev_lock(hdev); |
| 375 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 376 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 377 | mgmt_set_local_name_complete(hdev, sent, rp->status); |
| 378 | else if (!rp->status) |
Johan Hedberg | 28cc7bd | 2012-02-22 21:06:55 +0200 | [diff] [blame] | 379 | memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH); |
Johan Hedberg | f51d5b2 | 2012-02-22 18:17:32 +0200 | [diff] [blame] | 380 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 381 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
| 385 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 386 | struct hci_rp_read_local_name *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 387 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 388 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_NAME, sizeof(*rp)); |
| 389 | if (!rp) |
| 390 | return; |
| 391 | |
| 392 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 393 | |
| 394 | if (rp->status) |
| 395 | return; |
| 396 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 397 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 398 | hci_dev_test_flag(hdev, HCI_CONFIG)) |
Johan Hedberg | db99b5f | 2012-02-22 20:14:22 +0200 | [diff] [blame] | 399 | memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 403 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 404 | struct hci_ev_status *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 405 | void *sent; |
| 406 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 407 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_AUTH_ENABLE, sizeof(*rp)); |
| 408 | if (!rp) |
| 409 | return; |
| 410 | |
| 411 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 412 | |
| 413 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE); |
| 414 | if (!sent) |
| 415 | return; |
| 416 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 417 | hci_dev_lock(hdev); |
| 418 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 419 | if (!rp->status) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 420 | __u8 param = *((__u8 *) sent); |
| 421 | |
| 422 | if (param == AUTH_ENABLED) |
| 423 | set_bit(HCI_AUTH, &hdev->flags); |
| 424 | else |
| 425 | clear_bit(HCI_AUTH, &hdev->flags); |
| 426 | } |
| 427 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 428 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 429 | mgmt_auth_enable_complete(hdev, rp->status); |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 430 | |
| 431 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 435 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 436 | struct hci_ev_status *rp; |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 437 | __u8 param; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 438 | void *sent; |
| 439 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 440 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_ENCRYPT_MODE, sizeof(*rp)); |
| 441 | if (!rp) |
| 442 | return; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 443 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 444 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 445 | |
| 446 | if (rp->status) |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 447 | return; |
| 448 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 449 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE); |
| 450 | if (!sent) |
| 451 | return; |
| 452 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 453 | param = *((__u8 *) sent); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 454 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 455 | if (param) |
| 456 | set_bit(HCI_ENCRYPT, &hdev->flags); |
| 457 | else |
| 458 | clear_bit(HCI_ENCRYPT, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 462 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 463 | struct hci_ev_status *rp; |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 464 | __u8 param; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 465 | void *sent; |
| 466 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 467 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_SCAN_ENABLE, sizeof(*rp)); |
| 468 | if (!rp) |
| 469 | return; |
| 470 | |
| 471 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 472 | |
| 473 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); |
| 474 | if (!sent) |
| 475 | return; |
| 476 | |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 477 | param = *((__u8 *) sent); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 478 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 479 | hci_dev_lock(hdev); |
| 480 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 481 | if (rp->status) { |
Johan Hedberg | 2d7cee5 | 2011-11-07 22:16:03 +0200 | [diff] [blame] | 482 | hdev->discov_timeout = 0; |
| 483 | goto done; |
| 484 | } |
| 485 | |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 486 | if (param & SCAN_INQUIRY) |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 487 | set_bit(HCI_ISCAN, &hdev->flags); |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 488 | else |
| 489 | clear_bit(HCI_ISCAN, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 490 | |
Johan Hedberg | 031547d | 2014-07-10 12:09:06 +0300 | [diff] [blame] | 491 | if (param & SCAN_PAGE) |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 492 | set_bit(HCI_PSCAN, &hdev->flags); |
Johan Hedberg | bc6d2d0 | 2014-07-10 12:09:08 +0300 | [diff] [blame] | 493 | else |
Johan Hedberg | 204e399 | 2014-07-28 15:45:31 +0300 | [diff] [blame] | 494 | clear_bit(HCI_PSCAN, &hdev->flags); |
Johan Hedberg | 36f7fc7 | 2011-11-04 00:17:45 +0200 | [diff] [blame] | 495 | |
| 496 | done: |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 497 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 498 | } |
| 499 | |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 500 | static void hci_cc_set_event_filter(struct hci_dev *hdev, struct sk_buff *skb) |
| 501 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 502 | struct hci_ev_status *rp; |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 503 | struct hci_cp_set_event_filter *cp; |
| 504 | void *sent; |
| 505 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 506 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_SCAN_ENABLE, sizeof(*rp)); |
| 507 | if (!rp) |
| 508 | return; |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 509 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 510 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 511 | |
| 512 | if (rp->status) |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 513 | return; |
| 514 | |
| 515 | sent = hci_sent_cmd_data(hdev, HCI_OP_SET_EVENT_FLT); |
| 516 | if (!sent) |
| 517 | return; |
| 518 | |
| 519 | cp = (struct hci_cp_set_event_filter *)sent; |
| 520 | |
| 521 | if (cp->flt_type == HCI_FLT_CLEAR_ALL) |
| 522 | hci_dev_clear_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); |
| 523 | else |
| 524 | hci_dev_set_flag(hdev, HCI_EVENT_FILTER_CONFIGURED); |
| 525 | } |
| 526 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 527 | static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 528 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 529 | struct hci_rp_read_class_of_dev *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 530 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 531 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_CLASS_OF_DEV, sizeof(*rp)); |
| 532 | if (!rp) |
| 533 | return; |
| 534 | |
| 535 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 536 | |
| 537 | if (rp->status) |
| 538 | return; |
| 539 | |
| 540 | memcpy(hdev->dev_class, rp->dev_class, 3); |
| 541 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 542 | bt_dev_dbg(hdev, "class 0x%.2x%.2x%.2x", hdev->dev_class[2], |
| 543 | hdev->dev_class[1], hdev->dev_class[0]); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
| 547 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 548 | struct hci_ev_status *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 549 | void *sent; |
| 550 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 551 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_CLASS_OF_DEV, sizeof(*rp)); |
| 552 | if (!rp) |
| 553 | return; |
| 554 | |
| 555 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 556 | |
| 557 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV); |
| 558 | if (!sent) |
| 559 | return; |
| 560 | |
Marcel Holtmann | 7f9a903 | 2012-02-22 18:38:01 +0100 | [diff] [blame] | 561 | hci_dev_lock(hdev); |
| 562 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 563 | if (!rp->status) |
Marcel Holtmann | 7f9a903 | 2012-02-22 18:38:01 +0100 | [diff] [blame] | 564 | memcpy(hdev->dev_class, sent, 3); |
| 565 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 566 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 567 | mgmt_set_class_of_dev_complete(hdev, sent, rp->status); |
Marcel Holtmann | 7f9a903 | 2012-02-22 18:38:01 +0100 | [diff] [blame] | 568 | |
| 569 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) |
| 573 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 574 | struct hci_rp_read_voice_setting *rp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | __u16 setting; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 576 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 577 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_VOICE_SETTING, sizeof(*rp)); |
| 578 | if (!rp) |
| 579 | return; |
| 580 | |
| 581 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 582 | |
| 583 | if (rp->status) |
| 584 | return; |
| 585 | |
| 586 | setting = __le16_to_cpu(rp->voice_setting); |
| 587 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 588 | if (hdev->voice_setting == setting) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 589 | return; |
| 590 | |
| 591 | hdev->voice_setting = setting; |
| 592 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 593 | bt_dev_dbg(hdev, "voice setting 0x%4.4x", setting); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 594 | |
Gustavo F. Padovan | 3c54711 | 2011-12-14 22:58:44 -0200 | [diff] [blame] | 595 | if (hdev->notify) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 596 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 597 | } |
| 598 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 599 | static void hci_cc_write_voice_setting(struct hci_dev *hdev, |
| 600 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 601 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 602 | struct hci_ev_status *rp; |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 603 | __u16 setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | void *sent; |
| 605 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 606 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_VOICE_SETTING, |
| 607 | sizeof(*rp)); |
| 608 | if (!rp) |
| 609 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 611 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 612 | |
| 613 | if (rp->status) |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 614 | return; |
| 615 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 616 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING); |
| 617 | if (!sent) |
| 618 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 620 | setting = get_unaligned_le16(sent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 622 | if (hdev->voice_setting == setting) |
| 623 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 625 | hdev->voice_setting = setting; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 627 | bt_dev_dbg(hdev, "voice setting 0x%4.4x", setting); |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 628 | |
Gustavo F. Padovan | 3c54711 | 2011-12-14 22:58:44 -0200 | [diff] [blame] | 629 | if (hdev->notify) |
Marcel Holtmann | f383f27 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 630 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 633 | static void hci_cc_read_num_supported_iac(struct hci_dev *hdev, |
| 634 | struct sk_buff *skb) |
| 635 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 636 | struct hci_rp_read_num_supported_iac *rp; |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 637 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 638 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_NUM_SUPPORTED_IAC, |
| 639 | sizeof(*rp)); |
| 640 | if (!rp) |
| 641 | return; |
| 642 | |
| 643 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 644 | |
| 645 | if (rp->status) |
| 646 | return; |
| 647 | |
| 648 | hdev->num_iac = rp->num_iac; |
| 649 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 650 | bt_dev_dbg(hdev, "num iac %d", hdev->num_iac); |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 653 | static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 654 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 655 | struct hci_ev_status *rp; |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 656 | struct hci_cp_write_ssp_mode *sent; |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 657 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 658 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_SSP_MODE, sizeof(*rp)); |
| 659 | if (!rp) |
| 660 | return; |
| 661 | |
| 662 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 663 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 664 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); |
| 665 | if (!sent) |
| 666 | return; |
| 667 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 668 | hci_dev_lock(hdev); |
| 669 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 670 | if (!rp->status) { |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 671 | if (sent->mode) |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 672 | hdev->features[1][0] |= LMP_HOST_SSP; |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 673 | else |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 674 | hdev->features[1][0] &= ~LMP_HOST_SSP; |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 675 | } |
| 676 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 677 | if (!rp->status) { |
Johan Hedberg | 5ed8eb2 | 2012-10-25 00:09:51 +0300 | [diff] [blame] | 678 | if (sent->mode) |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 679 | hci_dev_set_flag(hdev, HCI_SSP_ENABLED); |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 680 | else |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 681 | hci_dev_clear_flag(hdev, HCI_SSP_ENABLED); |
Johan Hedberg | c0ecddc | 2012-02-22 12:38:31 +0200 | [diff] [blame] | 682 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 683 | |
| 684 | hci_dev_unlock(hdev); |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 685 | } |
| 686 | |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 687 | static void hci_cc_write_sc_support(struct hci_dev *hdev, struct sk_buff *skb) |
| 688 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 689 | struct hci_ev_status *rp; |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 690 | struct hci_cp_write_sc_support *sent; |
| 691 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 692 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_SC_SUPPORT, sizeof(*rp)); |
| 693 | if (!rp) |
| 694 | return; |
| 695 | |
| 696 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 697 | |
| 698 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SC_SUPPORT); |
| 699 | if (!sent) |
| 700 | return; |
| 701 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 702 | hci_dev_lock(hdev); |
| 703 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 704 | if (!rp->status) { |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 705 | if (sent->support) |
| 706 | hdev->features[1][0] |= LMP_HOST_SC; |
| 707 | else |
| 708 | hdev->features[1][0] &= ~LMP_HOST_SC; |
| 709 | } |
| 710 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 711 | if (!hci_dev_test_flag(hdev, HCI_MGMT) && !rp->status) { |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 712 | if (sent->support) |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 713 | hci_dev_set_flag(hdev, HCI_SC_ENABLED); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 714 | else |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 715 | hci_dev_clear_flag(hdev, HCI_SC_ENABLED); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 716 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 717 | |
| 718 | hci_dev_unlock(hdev); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 719 | } |
| 720 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 721 | static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) |
| 722 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 723 | struct hci_rp_read_local_version *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 724 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 725 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_VERSION, sizeof(*rp)); |
| 726 | if (!rp) |
| 727 | return; |
| 728 | |
| 729 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 730 | |
| 731 | if (rp->status) |
Johan Hedberg | 42c6b12 | 2013-03-05 20:37:49 +0200 | [diff] [blame] | 732 | return; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 733 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 734 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 735 | hci_dev_test_flag(hdev, HCI_CONFIG)) { |
Marcel Holtmann | 0d5551f | 2013-10-18 12:04:50 -0700 | [diff] [blame] | 736 | hdev->hci_ver = rp->hci_ver; |
| 737 | hdev->hci_rev = __le16_to_cpu(rp->hci_rev); |
| 738 | hdev->lmp_ver = rp->lmp_ver; |
| 739 | hdev->manufacturer = __le16_to_cpu(rp->manufacturer); |
| 740 | hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver); |
| 741 | } |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 742 | } |
| 743 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 744 | static void hci_cc_read_local_commands(struct hci_dev *hdev, |
| 745 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 746 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 747 | struct hci_rp_read_local_commands *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 748 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 749 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_COMMANDS, |
| 750 | sizeof(*rp)); |
| 751 | if (!rp) |
| 752 | return; |
| 753 | |
| 754 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 755 | |
Marcel Holtmann | 6a070e6 | 2013-10-31 04:54:33 -0700 | [diff] [blame] | 756 | if (rp->status) |
| 757 | return; |
| 758 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 759 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 760 | hci_dev_test_flag(hdev, HCI_CONFIG)) |
Johan Hedberg | 2177bab | 2013-03-05 20:37:43 +0200 | [diff] [blame] | 761 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 762 | } |
| 763 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 764 | static void hci_cc_read_auth_payload_timeout(struct hci_dev *hdev, |
| 765 | struct sk_buff *skb) |
| 766 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 767 | struct hci_rp_read_auth_payload_to *rp; |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 768 | struct hci_conn *conn; |
| 769 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 770 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_AUTH_PAYLOAD_TO, |
| 771 | sizeof(*rp)); |
| 772 | if (!rp) |
| 773 | return; |
| 774 | |
| 775 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 776 | |
| 777 | if (rp->status) |
| 778 | return; |
| 779 | |
| 780 | hci_dev_lock(hdev); |
| 781 | |
| 782 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 783 | if (conn) |
| 784 | conn->auth_payload_timeout = __le16_to_cpu(rp->timeout); |
| 785 | |
| 786 | hci_dev_unlock(hdev); |
| 787 | } |
| 788 | |
| 789 | static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev, |
| 790 | struct sk_buff *skb) |
| 791 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 792 | struct hci_rp_write_auth_payload_to *rp; |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 793 | struct hci_conn *conn; |
| 794 | void *sent; |
| 795 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 796 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_AUTH_PAYLOAD_TO, sizeof(*rp)); |
| 797 | if (!rp) |
| 798 | return; |
| 799 | |
| 800 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 801 | |
| 802 | if (rp->status) |
| 803 | return; |
| 804 | |
| 805 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO); |
| 806 | if (!sent) |
| 807 | return; |
| 808 | |
| 809 | hci_dev_lock(hdev); |
| 810 | |
| 811 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 812 | if (conn) |
| 813 | conn->auth_payload_timeout = get_unaligned_le16(sent + 2); |
| 814 | |
| 815 | hci_dev_unlock(hdev); |
| 816 | } |
| 817 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 818 | static void hci_cc_read_local_features(struct hci_dev *hdev, |
| 819 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 820 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 821 | struct hci_rp_read_local_features *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 822 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 823 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_FEATURES, |
| 824 | sizeof(*rp)); |
| 825 | if (!rp) |
| 826 | return; |
| 827 | |
| 828 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 829 | |
| 830 | if (rp->status) |
| 831 | return; |
| 832 | |
| 833 | memcpy(hdev->features, rp->features, 8); |
| 834 | |
| 835 | /* Adjust default settings according to features |
| 836 | * supported by device. */ |
| 837 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 838 | if (hdev->features[0][0] & LMP_3SLOT) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 839 | hdev->pkt_type |= (HCI_DM3 | HCI_DH3); |
| 840 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 841 | if (hdev->features[0][0] & LMP_5SLOT) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 842 | hdev->pkt_type |= (HCI_DM5 | HCI_DH5); |
| 843 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 844 | if (hdev->features[0][1] & LMP_HV2) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 845 | hdev->pkt_type |= (HCI_HV2); |
| 846 | hdev->esco_type |= (ESCO_HV2); |
| 847 | } |
| 848 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 849 | if (hdev->features[0][1] & LMP_HV3) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 850 | hdev->pkt_type |= (HCI_HV3); |
| 851 | hdev->esco_type |= (ESCO_HV3); |
| 852 | } |
| 853 | |
Andre Guedes | 45db810f | 2012-07-24 15:03:49 -0300 | [diff] [blame] | 854 | if (lmp_esco_capable(hdev)) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 855 | hdev->esco_type |= (ESCO_EV3); |
| 856 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 857 | if (hdev->features[0][4] & LMP_EV4) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 858 | hdev->esco_type |= (ESCO_EV4); |
| 859 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 860 | if (hdev->features[0][4] & LMP_EV5) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 861 | hdev->esco_type |= (ESCO_EV5); |
| 862 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 863 | if (hdev->features[0][5] & LMP_EDR_ESCO_2M) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 864 | hdev->esco_type |= (ESCO_2EV3); |
| 865 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 866 | if (hdev->features[0][5] & LMP_EDR_ESCO_3M) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 867 | hdev->esco_type |= (ESCO_3EV3); |
| 868 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 869 | if (hdev->features[0][5] & LMP_EDR_3S_ESCO) |
Marcel Holtmann | efc7688 | 2009-02-06 09:13:37 +0100 | [diff] [blame] | 870 | hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 871 | } |
| 872 | |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 873 | static void hci_cc_read_local_ext_features(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 874 | struct sk_buff *skb) |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 875 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 876 | struct hci_rp_read_local_ext_features *rp; |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 877 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 878 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_EXT_FEATURES, |
| 879 | sizeof(*rp)); |
| 880 | if (!rp) |
| 881 | return; |
| 882 | |
| 883 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 884 | |
| 885 | if (rp->status) |
Johan Hedberg | 42c6b12 | 2013-03-05 20:37:49 +0200 | [diff] [blame] | 886 | return; |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 887 | |
Marcel Holtmann | 57af75a | 2013-10-18 12:04:47 -0700 | [diff] [blame] | 888 | if (hdev->max_page < rp->max_page) |
| 889 | hdev->max_page = rp->max_page; |
Johan Hedberg | d2c5d77 | 2013-04-17 15:00:52 +0300 | [diff] [blame] | 890 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 891 | if (rp->page < HCI_MAX_PAGES) |
| 892 | memcpy(hdev->features[rp->page], rp->features, 8); |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 893 | } |
| 894 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 895 | static void hci_cc_read_flow_control_mode(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 896 | struct sk_buff *skb) |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 897 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 898 | struct hci_rp_read_flow_control_mode *rp; |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 899 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 900 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_FLOW_CONTROL_MODE, |
| 901 | sizeof(*rp)); |
| 902 | if (!rp) |
| 903 | return; |
| 904 | |
| 905 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 906 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 907 | if (rp->status) |
| 908 | return; |
| 909 | |
| 910 | hdev->flow_ctl_mode = rp->mode; |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 911 | } |
| 912 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 913 | static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) |
| 914 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 915 | struct hci_rp_read_buffer_size *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 916 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 917 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_BUFFER_SIZE, sizeof(*rp)); |
| 918 | if (!rp) |
| 919 | return; |
| 920 | |
| 921 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 922 | |
| 923 | if (rp->status) |
| 924 | return; |
| 925 | |
| 926 | hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu); |
| 927 | hdev->sco_mtu = rp->sco_mtu; |
| 928 | hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt); |
| 929 | hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt); |
| 930 | |
| 931 | if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) { |
| 932 | hdev->sco_mtu = 64; |
| 933 | hdev->sco_pkts = 8; |
| 934 | } |
| 935 | |
| 936 | hdev->acl_cnt = hdev->acl_pkts; |
| 937 | hdev->sco_cnt = hdev->sco_pkts; |
| 938 | |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 939 | BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu, |
| 940 | hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 941 | } |
| 942 | |
| 943 | static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb) |
| 944 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 945 | struct hci_rp_read_bd_addr *rp; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 946 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 947 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_BD_ADDR, sizeof(*rp)); |
| 948 | if (!rp) |
| 949 | return; |
| 950 | |
| 951 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 952 | |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 953 | if (rp->status) |
| 954 | return; |
| 955 | |
| 956 | if (test_bit(HCI_INIT, &hdev->flags)) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 957 | bacpy(&hdev->bdaddr, &rp->bdaddr); |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 958 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 959 | if (hci_dev_test_flag(hdev, HCI_SETUP)) |
Marcel Holtmann | e30d3f5 | 2014-07-05 10:48:03 +0200 | [diff] [blame] | 960 | bacpy(&hdev->setup_addr, &rp->bdaddr); |
Johan Hedberg | 23bb576 | 2010-12-21 23:01:27 +0200 | [diff] [blame] | 961 | } |
| 962 | |
Marcel Holtmann | a479036 | 2020-04-03 21:44:04 +0200 | [diff] [blame] | 963 | static void hci_cc_read_local_pairing_opts(struct hci_dev *hdev, |
| 964 | struct sk_buff *skb) |
| 965 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 966 | struct hci_rp_read_local_pairing_opts *rp; |
Marcel Holtmann | a479036 | 2020-04-03 21:44:04 +0200 | [diff] [blame] | 967 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 968 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_PAIRING_OPTS, |
| 969 | sizeof(*rp)); |
| 970 | if (!rp) |
| 971 | return; |
| 972 | |
| 973 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a479036 | 2020-04-03 21:44:04 +0200 | [diff] [blame] | 974 | |
| 975 | if (rp->status) |
| 976 | return; |
| 977 | |
| 978 | if (hci_dev_test_flag(hdev, HCI_SETUP) || |
| 979 | hci_dev_test_flag(hdev, HCI_CONFIG)) { |
| 980 | hdev->pairing_opts = rp->pairing_opts; |
| 981 | hdev->max_enc_key_size = rp->max_key_size; |
| 982 | } |
| 983 | } |
| 984 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 985 | static void hci_cc_read_page_scan_activity(struct hci_dev *hdev, |
| 986 | struct sk_buff *skb) |
| 987 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 988 | struct hci_rp_read_page_scan_activity *rp; |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 989 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 990 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_PAGE_SCAN_ACTIVITY, |
| 991 | sizeof(*rp)); |
| 992 | if (!rp) |
| 993 | return; |
| 994 | |
| 995 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 996 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 997 | if (rp->status) |
| 998 | return; |
| 999 | |
| 1000 | if (test_bit(HCI_INIT, &hdev->flags)) { |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 1001 | hdev->page_scan_interval = __le16_to_cpu(rp->interval); |
| 1002 | hdev->page_scan_window = __le16_to_cpu(rp->window); |
| 1003 | } |
| 1004 | } |
| 1005 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 1006 | static void hci_cc_write_page_scan_activity(struct hci_dev *hdev, |
| 1007 | struct sk_buff *skb) |
| 1008 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1009 | struct hci_ev_status *rp; |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 1010 | struct hci_cp_write_page_scan_activity *sent; |
| 1011 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1012 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_PAGE_SCAN_ACTIVITY, |
| 1013 | sizeof(*rp)); |
| 1014 | if (!rp) |
| 1015 | return; |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 1016 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1017 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1018 | |
| 1019 | if (rp->status) |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 1020 | return; |
| 1021 | |
| 1022 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY); |
| 1023 | if (!sent) |
| 1024 | return; |
| 1025 | |
| 1026 | hdev->page_scan_interval = __le16_to_cpu(sent->interval); |
| 1027 | hdev->page_scan_window = __le16_to_cpu(sent->window); |
| 1028 | } |
| 1029 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 1030 | static void hci_cc_read_page_scan_type(struct hci_dev *hdev, |
| 1031 | struct sk_buff *skb) |
| 1032 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1033 | struct hci_rp_read_page_scan_type *rp; |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 1034 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1035 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_PAGE_SCAN_TYPE, |
| 1036 | sizeof(*rp)); |
| 1037 | if (!rp) |
| 1038 | return; |
| 1039 | |
| 1040 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 1041 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1042 | if (rp->status) |
| 1043 | return; |
| 1044 | |
| 1045 | if (test_bit(HCI_INIT, &hdev->flags)) |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 1046 | hdev->page_scan_type = rp->type; |
| 1047 | } |
| 1048 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 1049 | static void hci_cc_write_page_scan_type(struct hci_dev *hdev, |
| 1050 | struct sk_buff *skb) |
| 1051 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1052 | struct hci_ev_status *rp; |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 1053 | u8 *type; |
| 1054 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1055 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_PAGE_SCAN_TYPE, |
| 1056 | sizeof(*rp)); |
| 1057 | if (!rp) |
| 1058 | return; |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 1059 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1060 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1061 | |
| 1062 | if (rp->status) |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 1063 | return; |
| 1064 | |
| 1065 | type = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE); |
| 1066 | if (type) |
| 1067 | hdev->page_scan_type = *type; |
| 1068 | } |
| 1069 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 1070 | static void hci_cc_read_data_block_size(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1071 | struct sk_buff *skb) |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 1072 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1073 | struct hci_rp_read_data_block_size *rp; |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 1074 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1075 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_DATA_BLOCK_SIZE, |
| 1076 | sizeof(*rp)); |
| 1077 | if (!rp) |
| 1078 | return; |
| 1079 | |
| 1080 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 1081 | |
| 1082 | if (rp->status) |
| 1083 | return; |
| 1084 | |
| 1085 | hdev->block_mtu = __le16_to_cpu(rp->max_acl_len); |
| 1086 | hdev->block_len = __le16_to_cpu(rp->block_len); |
| 1087 | hdev->num_blocks = __le16_to_cpu(rp->num_blocks); |
| 1088 | |
| 1089 | hdev->block_cnt = hdev->num_blocks; |
| 1090 | |
| 1091 | 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] | 1092 | hdev->block_cnt, hdev->block_len); |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 1093 | } |
| 1094 | |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 1095 | static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb) |
| 1096 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1097 | struct hci_rp_read_clock *rp; |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 1098 | struct hci_cp_read_clock *cp; |
| 1099 | struct hci_conn *conn; |
| 1100 | |
| 1101 | BT_DBG("%s", hdev->name); |
| 1102 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1103 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_CLOCK, sizeof(*rp)); |
| 1104 | if (!rp) |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 1105 | return; |
| 1106 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1107 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1108 | |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 1109 | if (rp->status) |
| 1110 | return; |
| 1111 | |
| 1112 | hci_dev_lock(hdev); |
| 1113 | |
| 1114 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK); |
| 1115 | if (!cp) |
| 1116 | goto unlock; |
| 1117 | |
| 1118 | if (cp->which == 0x00) { |
| 1119 | hdev->clock = le32_to_cpu(rp->clock); |
| 1120 | goto unlock; |
| 1121 | } |
| 1122 | |
| 1123 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 1124 | if (conn) { |
| 1125 | conn->clock = le32_to_cpu(rp->clock); |
| 1126 | conn->clock_accuracy = le16_to_cpu(rp->accuracy); |
| 1127 | } |
| 1128 | |
| 1129 | unlock: |
| 1130 | hci_dev_unlock(hdev); |
| 1131 | } |
| 1132 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 1133 | static void hci_cc_read_local_amp_info(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1134 | struct sk_buff *skb) |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 1135 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1136 | struct hci_rp_read_local_amp_info *rp; |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 1137 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1138 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_AMP_INFO, |
| 1139 | sizeof(*rp)); |
| 1140 | if (!rp) |
| 1141 | return; |
| 1142 | |
| 1143 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 1144 | |
| 1145 | if (rp->status) |
Arron Wang | 8392788 | 2015-07-24 17:10:16 +0800 | [diff] [blame] | 1146 | return; |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 1147 | |
| 1148 | hdev->amp_status = rp->amp_status; |
| 1149 | hdev->amp_total_bw = __le32_to_cpu(rp->total_bw); |
| 1150 | hdev->amp_max_bw = __le32_to_cpu(rp->max_bw); |
| 1151 | hdev->amp_min_latency = __le32_to_cpu(rp->min_latency); |
| 1152 | hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu); |
| 1153 | hdev->amp_type = rp->amp_type; |
| 1154 | hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap); |
| 1155 | hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size); |
| 1156 | hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to); |
| 1157 | hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to); |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 1158 | } |
| 1159 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 1160 | 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] | 1161 | struct sk_buff *skb) |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 1162 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1163 | struct hci_rp_read_inq_rsp_tx_power *rp; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 1164 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1165 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_INQ_RSP_TX_POWER, |
| 1166 | sizeof(*rp)); |
| 1167 | if (!rp) |
| 1168 | return; |
| 1169 | |
| 1170 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 1171 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1172 | if (rp->status) |
| 1173 | return; |
| 1174 | |
| 1175 | hdev->inq_tx_power = rp->tx_power; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 1176 | } |
| 1177 | |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 1178 | static void hci_cc_read_def_err_data_reporting(struct hci_dev *hdev, |
| 1179 | struct sk_buff *skb) |
| 1180 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1181 | struct hci_rp_read_def_err_data_reporting *rp; |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 1182 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1183 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_DEF_ERR_DATA_REPORTING, |
| 1184 | sizeof(*rp)); |
| 1185 | if (!rp) |
| 1186 | return; |
| 1187 | |
| 1188 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 1189 | |
| 1190 | if (rp->status) |
| 1191 | return; |
| 1192 | |
| 1193 | hdev->err_data_reporting = rp->err_data_reporting; |
| 1194 | } |
| 1195 | |
| 1196 | static void hci_cc_write_def_err_data_reporting(struct hci_dev *hdev, |
| 1197 | struct sk_buff *skb) |
| 1198 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1199 | struct hci_ev_status *rp; |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 1200 | struct hci_cp_write_def_err_data_reporting *cp; |
| 1201 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1202 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING, |
| 1203 | sizeof(*rp)); |
| 1204 | if (!rp) |
| 1205 | return; |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 1206 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1207 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1208 | |
| 1209 | if (rp->status) |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 1210 | return; |
| 1211 | |
| 1212 | cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING); |
| 1213 | if (!cp) |
| 1214 | return; |
| 1215 | |
| 1216 | hdev->err_data_reporting = cp->err_data_reporting; |
| 1217 | } |
| 1218 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1219 | static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1220 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1221 | struct hci_rp_pin_code_reply *rp; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1222 | struct hci_cp_pin_code_reply *cp; |
| 1223 | struct hci_conn *conn; |
| 1224 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1225 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_PIN_CODE_REPLY, sizeof(*rp)); |
| 1226 | if (!rp) |
| 1227 | return; |
| 1228 | |
| 1229 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1230 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1231 | hci_dev_lock(hdev); |
| 1232 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1233 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1234 | mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1235 | |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 1236 | if (rp->status) |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1237 | goto unlock; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1238 | |
| 1239 | cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY); |
| 1240 | if (!cp) |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1241 | goto unlock; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1242 | |
| 1243 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 1244 | if (conn) |
| 1245 | conn->pin_length = cp->pin_len; |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1246 | |
| 1247 | unlock: |
| 1248 | hci_dev_unlock(hdev); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1252 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1253 | struct hci_rp_pin_code_neg_reply *rp; |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1254 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1255 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_PIN_CODE_NEG_REPLY, sizeof(*rp)); |
| 1256 | if (!rp) |
| 1257 | return; |
| 1258 | |
| 1259 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1260 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1261 | hci_dev_lock(hdev); |
| 1262 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1263 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1264 | mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1265 | rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1266 | |
| 1267 | hci_dev_unlock(hdev); |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1268 | } |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1269 | |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 1270 | static void hci_cc_le_read_buffer_size(struct hci_dev *hdev, |
| 1271 | struct sk_buff *skb) |
| 1272 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1273 | struct hci_rp_le_read_buffer_size *rp; |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 1274 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1275 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_BUFFER_SIZE, |
| 1276 | sizeof(*rp)); |
| 1277 | if (!rp) |
| 1278 | return; |
| 1279 | |
| 1280 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 1281 | |
| 1282 | if (rp->status) |
| 1283 | return; |
| 1284 | |
| 1285 | hdev->le_mtu = __le16_to_cpu(rp->le_mtu); |
| 1286 | hdev->le_pkts = rp->le_max_pkt; |
| 1287 | |
| 1288 | hdev->le_cnt = hdev->le_pkts; |
| 1289 | |
| 1290 | 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] | 1291 | } |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 1292 | |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 1293 | static void hci_cc_le_read_local_features(struct hci_dev *hdev, |
| 1294 | struct sk_buff *skb) |
| 1295 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1296 | struct hci_rp_le_read_local_features *rp; |
| 1297 | |
| 1298 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_LOCAL_FEATURES, |
| 1299 | sizeof(*rp)); |
| 1300 | if (!rp) |
| 1301 | return; |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 1302 | |
| 1303 | BT_DBG("%s status 0x%2.2x", hdev->name, rp->status); |
| 1304 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1305 | if (rp->status) |
| 1306 | return; |
| 1307 | |
| 1308 | memcpy(hdev->le_features, rp->features, 8); |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 1309 | } |
| 1310 | |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 1311 | static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev, |
| 1312 | struct sk_buff *skb) |
| 1313 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1314 | struct hci_rp_le_read_adv_tx_power *rp; |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 1315 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1316 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_ADV_TX_POWER, |
| 1317 | sizeof(*rp)); |
| 1318 | if (!rp) |
| 1319 | return; |
| 1320 | |
| 1321 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 1322 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1323 | if (rp->status) |
| 1324 | return; |
| 1325 | |
| 1326 | hdev->adv_tx_power = rp->tx_power; |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 1327 | } |
| 1328 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1329 | static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1330 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1331 | struct hci_rp_user_confirm_reply *rp; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1332 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1333 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_USER_CONFIRM_REPLY, sizeof(*rp)); |
| 1334 | if (!rp) |
| 1335 | return; |
| 1336 | |
| 1337 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1338 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1339 | hci_dev_lock(hdev); |
| 1340 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1341 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1342 | mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0, |
| 1343 | rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1344 | |
| 1345 | hci_dev_unlock(hdev); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1346 | } |
| 1347 | |
| 1348 | static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1349 | struct sk_buff *skb) |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1350 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1351 | struct hci_rp_user_confirm_reply *rp; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1352 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1353 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_USER_CONFIRM_NEG_REPLY, |
| 1354 | sizeof(*rp)); |
| 1355 | if (!rp) |
| 1356 | return; |
| 1357 | |
| 1358 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1359 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1360 | hci_dev_lock(hdev); |
| 1361 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1362 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1363 | mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1364 | ACL_LINK, 0, rp->status); |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 1365 | |
| 1366 | hci_dev_unlock(hdev); |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 1367 | } |
| 1368 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1369 | static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb) |
| 1370 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1371 | struct hci_rp_user_confirm_reply *rp; |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1372 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1373 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_USER_PASSKEY_REPLY, sizeof(*rp)); |
| 1374 | if (!rp) |
| 1375 | return; |
| 1376 | |
| 1377 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1378 | |
| 1379 | hci_dev_lock(hdev); |
| 1380 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1381 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1382 | mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1383 | 0, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1384 | |
| 1385 | hci_dev_unlock(hdev); |
| 1386 | } |
| 1387 | |
| 1388 | static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 1389 | struct sk_buff *skb) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1390 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1391 | struct hci_rp_user_confirm_reply *rp; |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1392 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1393 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_USER_PASSKEY_NEG_REPLY, sizeof(*rp)); |
| 1394 | if (!rp) |
| 1395 | return; |
| 1396 | |
| 1397 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1398 | |
| 1399 | hci_dev_lock(hdev); |
| 1400 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 1401 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1402 | mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1403 | ACL_LINK, 0, rp->status); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 1404 | |
| 1405 | hci_dev_unlock(hdev); |
| 1406 | } |
| 1407 | |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 1408 | static void hci_cc_read_local_oob_data(struct hci_dev *hdev, |
| 1409 | struct sk_buff *skb) |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1410 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1411 | struct hci_rp_read_local_oob_data *rp; |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1412 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1413 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_OOB_DATA, sizeof(*rp)); |
| 1414 | if (!rp) |
| 1415 | return; |
| 1416 | |
| 1417 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 1418 | } |
| 1419 | |
| 1420 | static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev, |
| 1421 | struct sk_buff *skb) |
| 1422 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1423 | struct hci_rp_read_local_oob_ext_data *rp; |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 1424 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1425 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_LOCAL_OOB_EXT_DATA, sizeof(*rp)); |
| 1426 | if (!rp) |
| 1427 | return; |
| 1428 | |
| 1429 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 1430 | } |
| 1431 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1432 | static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb) |
| 1433 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1434 | struct hci_ev_status *rp; |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1435 | bdaddr_t *sent; |
| 1436 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1437 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_RANDOM_ADDR, sizeof(*rp)); |
| 1438 | if (!rp) |
| 1439 | return; |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1440 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1441 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1442 | |
| 1443 | if (rp->status) |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1444 | return; |
| 1445 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1446 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR); |
| 1447 | if (!sent) |
| 1448 | return; |
| 1449 | |
| 1450 | hci_dev_lock(hdev); |
| 1451 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1452 | bacpy(&hdev->random_addr, sent); |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1453 | |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 1454 | if (!bacmp(&hdev->rpa, sent)) { |
| 1455 | hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED); |
| 1456 | queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, |
| 1457 | secs_to_jiffies(hdev->rpa_timeout)); |
| 1458 | } |
| 1459 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 1460 | hci_dev_unlock(hdev); |
| 1461 | } |
| 1462 | |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 1463 | static void hci_cc_le_set_default_phy(struct hci_dev *hdev, struct sk_buff *skb) |
| 1464 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1465 | struct hci_ev_status *rp; |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 1466 | struct hci_cp_le_set_default_phy *cp; |
| 1467 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1468 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_DEFAULT_PHY, sizeof(*rp)); |
| 1469 | if (!rp) |
| 1470 | return; |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 1471 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1472 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1473 | |
| 1474 | if (rp->status) |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 1475 | return; |
| 1476 | |
| 1477 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_DEFAULT_PHY); |
| 1478 | if (!cp) |
| 1479 | return; |
| 1480 | |
| 1481 | hci_dev_lock(hdev); |
| 1482 | |
| 1483 | hdev->le_tx_def_phys = cp->tx_phys; |
| 1484 | hdev->le_rx_def_phys = cp->rx_phys; |
| 1485 | |
| 1486 | hci_dev_unlock(hdev); |
| 1487 | } |
| 1488 | |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1489 | static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, |
| 1490 | struct sk_buff *skb) |
| 1491 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1492 | struct hci_ev_status *rp; |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1493 | struct hci_cp_le_set_adv_set_rand_addr *cp; |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 1494 | struct adv_info *adv; |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1495 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1496 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, |
| 1497 | sizeof(*rp)); |
| 1498 | if (!rp) |
| 1499 | return; |
| 1500 | |
| 1501 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1502 | |
| 1503 | if (rp->status) |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1504 | return; |
| 1505 | |
| 1506 | 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] | 1507 | /* Update only in case the adv instance since handle 0x00 shall be using |
| 1508 | * HCI_OP_LE_SET_RANDOM_ADDR since that allows both extended and |
| 1509 | * non-extended adverting. |
| 1510 | */ |
| 1511 | if (!cp || !cp->handle) |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1512 | return; |
| 1513 | |
| 1514 | hci_dev_lock(hdev); |
| 1515 | |
Luiz Augusto von Dentz | c45074d | 2021-08-02 16:56:19 -0700 | [diff] [blame] | 1516 | adv = hci_find_adv_instance(hdev, cp->handle); |
| 1517 | if (adv) { |
| 1518 | bacpy(&adv->random_addr, &cp->bdaddr); |
| 1519 | if (!bacmp(&hdev->rpa, &cp->bdaddr)) { |
| 1520 | adv->rpa_expired = false; |
| 1521 | queue_delayed_work(hdev->workqueue, |
| 1522 | &adv->rpa_expired_cb, |
| 1523 | secs_to_jiffies(hdev->rpa_timeout)); |
| 1524 | } |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | hci_dev_unlock(hdev); |
| 1528 | } |
| 1529 | |
Luiz Augusto von Dentz | cba6b75 | 2021-10-27 16:58:40 -0700 | [diff] [blame] | 1530 | static void hci_cc_le_remove_adv_set(struct hci_dev *hdev, struct sk_buff *skb) |
| 1531 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1532 | struct hci_ev_status *rp; |
Luiz Augusto von Dentz | cba6b75 | 2021-10-27 16:58:40 -0700 | [diff] [blame] | 1533 | u8 *instance; |
| 1534 | int err; |
| 1535 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1536 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_REMOVE_ADV_SET, sizeof(*rp)); |
| 1537 | if (!rp) |
| 1538 | return; |
| 1539 | |
| 1540 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1541 | |
| 1542 | if (rp->status) |
Luiz Augusto von Dentz | cba6b75 | 2021-10-27 16:58:40 -0700 | [diff] [blame] | 1543 | return; |
| 1544 | |
| 1545 | instance = hci_sent_cmd_data(hdev, HCI_OP_LE_REMOVE_ADV_SET); |
| 1546 | if (!instance) |
| 1547 | return; |
| 1548 | |
| 1549 | hci_dev_lock(hdev); |
| 1550 | |
| 1551 | err = hci_remove_adv_instance(hdev, *instance); |
| 1552 | if (!err) |
| 1553 | mgmt_advertising_removed(hci_skb_sk(hdev->sent_cmd), hdev, |
| 1554 | *instance); |
| 1555 | |
| 1556 | hci_dev_unlock(hdev); |
| 1557 | } |
| 1558 | |
| 1559 | static void hci_cc_le_clear_adv_sets(struct hci_dev *hdev, struct sk_buff *skb) |
| 1560 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1561 | struct hci_ev_status *rp; |
Luiz Augusto von Dentz | cba6b75 | 2021-10-27 16:58:40 -0700 | [diff] [blame] | 1562 | struct adv_info *adv, *n; |
| 1563 | int err; |
| 1564 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1565 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_CLEAR_ADV_SETS, sizeof(*rp)); |
| 1566 | if (!rp) |
| 1567 | return; |
| 1568 | |
| 1569 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1570 | |
| 1571 | if (rp->status) |
Luiz Augusto von Dentz | cba6b75 | 2021-10-27 16:58:40 -0700 | [diff] [blame] | 1572 | return; |
| 1573 | |
| 1574 | if (!hci_sent_cmd_data(hdev, HCI_OP_LE_CLEAR_ADV_SETS)) |
| 1575 | return; |
| 1576 | |
| 1577 | hci_dev_lock(hdev); |
| 1578 | |
| 1579 | list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { |
| 1580 | u8 instance = adv->instance; |
| 1581 | |
| 1582 | err = hci_remove_adv_instance(hdev, instance); |
| 1583 | if (!err) |
| 1584 | mgmt_advertising_removed(hci_skb_sk(hdev->sent_cmd), |
| 1585 | hdev, instance); |
| 1586 | } |
| 1587 | |
| 1588 | hci_dev_unlock(hdev); |
| 1589 | } |
| 1590 | |
Daniel Winkler | 7c395ea | 2020-12-03 12:12:51 -0800 | [diff] [blame] | 1591 | static void hci_cc_le_read_transmit_power(struct hci_dev *hdev, |
| 1592 | struct sk_buff *skb) |
| 1593 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1594 | struct hci_rp_le_read_transmit_power *rp; |
Daniel Winkler | 7c395ea | 2020-12-03 12:12:51 -0800 | [diff] [blame] | 1595 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1596 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_TRANSMIT_POWER, |
| 1597 | sizeof(*rp)); |
| 1598 | if (!rp) |
| 1599 | return; |
| 1600 | |
| 1601 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Daniel Winkler | 7c395ea | 2020-12-03 12:12:51 -0800 | [diff] [blame] | 1602 | |
| 1603 | if (rp->status) |
| 1604 | return; |
| 1605 | |
| 1606 | hdev->min_le_tx_power = rp->min_le_tx_power; |
| 1607 | hdev->max_le_tx_power = rp->max_le_tx_power; |
| 1608 | } |
| 1609 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1610 | static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb) |
| 1611 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1612 | struct hci_ev_status *rp; |
| 1613 | __u8 *sent; |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1614 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1615 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_ADV_ENABLE, sizeof(*rp)); |
| 1616 | if (!rp) |
| 1617 | return; |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1618 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1619 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1620 | |
| 1621 | if (rp->status) |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1622 | return; |
| 1623 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1624 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE); |
| 1625 | if (!sent) |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1626 | return; |
| 1627 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1628 | hci_dev_lock(hdev); |
| 1629 | |
Stephen Hemminger | 49c922b | 2014-10-27 21:12:20 -0700 | [diff] [blame] | 1630 | /* If we're doing connection initiation as peripheral. Set a |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1631 | * timeout in case something goes wrong. |
| 1632 | */ |
| 1633 | if (*sent) { |
| 1634 | struct hci_conn *conn; |
| 1635 | |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 1636 | hci_dev_set_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | 66c417c | 2014-07-08 15:07:47 +0300 | [diff] [blame] | 1637 | |
Jakub Pawlowski | e7d9ab7 | 2015-08-07 20:22:52 +0200 | [diff] [blame] | 1638 | conn = hci_lookup_le_connect(hdev); |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1639 | if (conn) |
| 1640 | queue_delayed_work(hdev->workqueue, |
| 1641 | &conn->le_conn_timeout, |
Johan Hedberg | 09ae260 | 2014-07-06 13:41:15 +0300 | [diff] [blame] | 1642 | conn->conn_timeout); |
Johan Hedberg | 66c417c | 2014-07-08 15:07:47 +0300 | [diff] [blame] | 1643 | } else { |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 1644 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | 3c85775 | 2014-03-25 10:30:49 +0200 | [diff] [blame] | 1645 | } |
| 1646 | |
Johan Hedberg | 04b4edc | 2013-03-15 17:07:01 -0500 | [diff] [blame] | 1647 | hci_dev_unlock(hdev); |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 1648 | } |
| 1649 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1650 | static void hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, |
| 1651 | struct sk_buff *skb) |
| 1652 | { |
| 1653 | struct hci_cp_le_set_ext_adv_enable *cp; |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1654 | struct hci_cp_ext_adv_set *set; |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1655 | struct adv_info *adv = NULL, *n; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1656 | struct hci_ev_status *rp; |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1657 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1658 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_EXT_ADV_ENABLE, |
| 1659 | sizeof(*rp)); |
| 1660 | if (!rp) |
| 1661 | return; |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1662 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1663 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1664 | |
| 1665 | if (rp->status) |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1666 | return; |
| 1667 | |
| 1668 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE); |
| 1669 | if (!cp) |
| 1670 | return; |
| 1671 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1672 | set = (void *)cp->data; |
| 1673 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1674 | hci_dev_lock(hdev); |
| 1675 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1676 | if (cp->num_of_sets) |
| 1677 | adv = hci_find_adv_instance(hdev, set->handle); |
| 1678 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1679 | if (cp->enable) { |
| 1680 | struct hci_conn *conn; |
| 1681 | |
| 1682 | hci_dev_set_flag(hdev, HCI_LE_ADV); |
| 1683 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1684 | if (adv) |
| 1685 | adv->enabled = true; |
| 1686 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1687 | conn = hci_lookup_le_connect(hdev); |
| 1688 | if (conn) |
| 1689 | queue_delayed_work(hdev->workqueue, |
| 1690 | &conn->le_conn_timeout, |
| 1691 | conn->conn_timeout); |
Jaganath Kanakkassery | 45b7749 | 2018-07-19 17:09:43 +0530 | [diff] [blame] | 1692 | } else { |
Archie Pusaka | 2128939 | 2021-10-28 19:17:25 +0800 | [diff] [blame] | 1693 | if (cp->num_of_sets) { |
| 1694 | if (adv) |
| 1695 | adv->enabled = false; |
| 1696 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1697 | /* If just one instance was disabled check if there are |
| 1698 | * any other instance enabled before clearing HCI_LE_ADV |
| 1699 | */ |
| 1700 | list_for_each_entry_safe(adv, n, &hdev->adv_instances, |
| 1701 | list) { |
| 1702 | if (adv->enabled) |
| 1703 | goto unlock; |
| 1704 | } |
| 1705 | } else { |
| 1706 | /* All instances shall be considered disabled */ |
| 1707 | list_for_each_entry_safe(adv, n, &hdev->adv_instances, |
| 1708 | list) |
| 1709 | adv->enabled = false; |
| 1710 | } |
| 1711 | |
Jaganath Kanakkassery | 45b7749 | 2018-07-19 17:09:43 +0530 | [diff] [blame] | 1712 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1713 | } |
| 1714 | |
Luiz Augusto von Dentz | 1027931 | 2021-08-02 16:56:18 -0700 | [diff] [blame] | 1715 | unlock: |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 1716 | hci_dev_unlock(hdev); |
| 1717 | } |
| 1718 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1719 | static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 1720 | { |
| 1721 | struct hci_cp_le_set_scan_param *cp; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1722 | struct hci_ev_status *rp; |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1723 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1724 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_SCAN_PARAM, sizeof(*rp)); |
| 1725 | if (!rp) |
| 1726 | return; |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1727 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1728 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1729 | |
| 1730 | if (rp->status) |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1731 | return; |
| 1732 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1733 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM); |
| 1734 | if (!cp) |
| 1735 | return; |
| 1736 | |
| 1737 | hci_dev_lock(hdev); |
| 1738 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1739 | hdev->le_scan_type = cp->type; |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 1740 | |
| 1741 | hci_dev_unlock(hdev); |
| 1742 | } |
| 1743 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1744 | static void hci_cc_le_set_ext_scan_param(struct hci_dev *hdev, |
| 1745 | struct sk_buff *skb) |
| 1746 | { |
| 1747 | struct hci_cp_le_set_ext_scan_params *cp; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1748 | struct hci_ev_status *rp; |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1749 | struct hci_cp_le_scan_phy_params *phy_param; |
| 1750 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1751 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_EXT_SCAN_PARAMS, |
| 1752 | sizeof(*rp)); |
| 1753 | if (!rp) |
| 1754 | return; |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1755 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1756 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1757 | |
| 1758 | if (rp->status) |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1759 | return; |
| 1760 | |
| 1761 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS); |
| 1762 | if (!cp) |
| 1763 | return; |
| 1764 | |
| 1765 | phy_param = (void *)cp->data; |
| 1766 | |
| 1767 | hci_dev_lock(hdev); |
| 1768 | |
| 1769 | hdev->le_scan_type = phy_param->type; |
| 1770 | |
| 1771 | hci_dev_unlock(hdev); |
| 1772 | } |
| 1773 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1774 | static bool has_pending_adv_report(struct hci_dev *hdev) |
| 1775 | { |
| 1776 | struct discovery_state *d = &hdev->discovery; |
| 1777 | |
| 1778 | return bacmp(&d->last_adv_addr, BDADDR_ANY); |
| 1779 | } |
| 1780 | |
| 1781 | static void clear_pending_adv_report(struct hci_dev *hdev) |
| 1782 | { |
| 1783 | struct discovery_state *d = &hdev->discovery; |
| 1784 | |
| 1785 | bacpy(&d->last_adv_addr, BDADDR_ANY); |
| 1786 | d->last_adv_data_len = 0; |
| 1787 | } |
| 1788 | |
| 1789 | 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] | 1790 | u8 bdaddr_type, s8 rssi, u32 flags, |
| 1791 | u8 *data, u8 len) |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1792 | { |
| 1793 | struct discovery_state *d = &hdev->discovery; |
| 1794 | |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 1795 | if (len > HCI_MAX_AD_LENGTH) |
| 1796 | return; |
| 1797 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1798 | bacpy(&d->last_adv_addr, bdaddr); |
| 1799 | d->last_adv_addr_type = bdaddr_type; |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 1800 | d->last_adv_rssi = rssi; |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 1801 | d->last_adv_flags = flags; |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1802 | memcpy(d->last_adv_data, data, len); |
| 1803 | d->last_adv_data_len = len; |
| 1804 | } |
| 1805 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1806 | 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] | 1807 | { |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1808 | hci_dev_lock(hdev); |
| 1809 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1810 | switch (enable) { |
Andre Guedes | 76a388be | 2013-04-04 20:21:02 -0300 | [diff] [blame] | 1811 | case LE_SCAN_ENABLE: |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 1812 | hci_dev_set_flag(hdev, HCI_LE_SCAN); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1813 | if (hdev->le_scan_type == LE_SCAN_ACTIVE) |
| 1814 | clear_pending_adv_report(hdev); |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1815 | break; |
| 1816 | |
Andre Guedes | 76a388be | 2013-04-04 20:21:02 -0300 | [diff] [blame] | 1817 | case LE_SCAN_DISABLE: |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1818 | /* We do this here instead of when setting DISCOVERY_STOPPED |
| 1819 | * since the latter would potentially require waiting for |
| 1820 | * inquiry to stop too. |
| 1821 | */ |
| 1822 | if (has_pending_adv_report(hdev)) { |
| 1823 | struct discovery_state *d = &hdev->discovery; |
| 1824 | |
| 1825 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Johan Hedberg | ab0aa43 | 2014-03-26 14:17:12 +0200 | [diff] [blame] | 1826 | d->last_adv_addr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 1827 | d->last_adv_rssi, d->last_adv_flags, |
Johan Hedberg | ab0aa43 | 2014-03-26 14:17:12 +0200 | [diff] [blame] | 1828 | d->last_adv_data, |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 1829 | d->last_adv_data_len, NULL, 0); |
| 1830 | } |
| 1831 | |
Johan Hedberg | 317ac8c | 2014-02-28 20:26:12 +0200 | [diff] [blame] | 1832 | /* Cancel this timer so that we don't try to disable scanning |
| 1833 | * when it's already disabled. |
| 1834 | */ |
| 1835 | cancel_delayed_work(&hdev->le_scan_disable); |
| 1836 | |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 1837 | hci_dev_clear_flag(hdev, HCI_LE_SCAN); |
Johan Hedberg | e8bb6b9 | 2014-07-08 15:07:53 +0300 | [diff] [blame] | 1838 | |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1839 | /* The HCI_LE_SCAN_INTERRUPTED flag indicates that we |
| 1840 | * interrupted scanning due to a connect request. Mark |
Luiz Augusto von Dentz | abfeea4 | 2021-10-27 16:58:45 -0700 | [diff] [blame] | 1841 | * therefore discovery as stopped. |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1842 | */ |
Marcel Holtmann | a69d892 | 2015-03-13 02:11:05 -0700 | [diff] [blame] | 1843 | if (hci_dev_test_and_clear_flag(hdev, HCI_LE_SCAN_INTERRUPTED)) |
Johan Hedberg | 81ad6fd | 2014-02-28 20:26:13 +0200 | [diff] [blame] | 1844 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | e8bb6b9 | 2014-07-08 15:07:53 +0300 | [diff] [blame] | 1845 | |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1846 | break; |
| 1847 | |
| 1848 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 1849 | bt_dev_err(hdev, "use of reserved LE_Scan_Enable param %d", |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1850 | enable); |
Andrei Emeltchenko | 68a8aea | 2011-12-19 16:14:18 +0200 | [diff] [blame] | 1851 | break; |
Andre Guedes | 3581508 | 2011-05-26 16:23:53 -0300 | [diff] [blame] | 1852 | } |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 1853 | |
| 1854 | hci_dev_unlock(hdev); |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 1855 | } |
| 1856 | |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1857 | static void hci_cc_le_set_scan_enable(struct hci_dev *hdev, |
| 1858 | struct sk_buff *skb) |
| 1859 | { |
| 1860 | struct hci_cp_le_set_scan_enable *cp; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1861 | struct hci_ev_status *rp; |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1862 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1863 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_SCAN_ENABLE, |
| 1864 | sizeof(*rp)); |
| 1865 | if (!rp) |
| 1866 | return; |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1867 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1868 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1869 | |
| 1870 | if (rp->status) |
Jaganath Kanakkassery | 3baef81 | 2018-07-06 17:05:27 +0530 | [diff] [blame] | 1871 | return; |
| 1872 | |
| 1873 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE); |
| 1874 | if (!cp) |
| 1875 | return; |
| 1876 | |
| 1877 | le_set_scan_enable_complete(hdev, cp->enable); |
| 1878 | } |
| 1879 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1880 | static void hci_cc_le_set_ext_scan_enable(struct hci_dev *hdev, |
| 1881 | struct sk_buff *skb) |
| 1882 | { |
| 1883 | struct hci_cp_le_set_ext_scan_enable *cp; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1884 | struct hci_ev_status *rp; |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1885 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1886 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_EXT_SCAN_ENABLE, |
| 1887 | sizeof(*rp)); |
| 1888 | if (!rp) |
| 1889 | return; |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1890 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1891 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1892 | |
| 1893 | if (rp->status) |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 1894 | return; |
| 1895 | |
| 1896 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE); |
| 1897 | if (!cp) |
| 1898 | return; |
| 1899 | |
| 1900 | le_set_scan_enable_complete(hdev, cp->enable); |
| 1901 | } |
| 1902 | |
Jaganath Kanakkassery | 6b49bcb | 2018-07-19 17:09:40 +0530 | [diff] [blame] | 1903 | static void hci_cc_le_read_num_adv_sets(struct hci_dev *hdev, |
| 1904 | struct sk_buff *skb) |
| 1905 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1906 | struct hci_rp_le_read_num_supported_adv_sets *rp; |
Jaganath Kanakkassery | 6b49bcb | 2018-07-19 17:09:40 +0530 | [diff] [blame] | 1907 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1908 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_NUM_SUPPORTED_ADV_SETS, |
| 1909 | sizeof(*rp)); |
| 1910 | if (!rp) |
| 1911 | return; |
| 1912 | |
| 1913 | bt_dev_dbg(hdev, "status 0x%2.2x No of Adv sets %u", rp->status, |
| 1914 | rp->num_of_sets); |
Jaganath Kanakkassery | 6b49bcb | 2018-07-19 17:09:40 +0530 | [diff] [blame] | 1915 | |
| 1916 | if (rp->status) |
| 1917 | return; |
| 1918 | |
| 1919 | hdev->le_num_of_adv_sets = rp->num_of_sets; |
| 1920 | } |
| 1921 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1922 | static void hci_cc_le_read_accept_list_size(struct hci_dev *hdev, |
| 1923 | struct sk_buff *skb) |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1924 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1925 | struct hci_rp_le_read_accept_list_size *rp; |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1926 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1927 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_ACCEPT_LIST_SIZE, |
| 1928 | sizeof(*rp)); |
| 1929 | if (!rp) |
| 1930 | return; |
| 1931 | |
| 1932 | bt_dev_dbg(hdev, "status 0x%2.2x size %u", rp->status, rp->size); |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1933 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1934 | if (rp->status) |
| 1935 | return; |
| 1936 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1937 | hdev->le_accept_list_size = rp->size; |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 1938 | } |
| 1939 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1940 | static void hci_cc_le_clear_accept_list(struct hci_dev *hdev, |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1941 | struct sk_buff *skb) |
| 1942 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1943 | struct hci_ev_status *rp; |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1944 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1945 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_CLEAR_ACCEPT_LIST, |
| 1946 | sizeof(*rp)); |
| 1947 | if (!rp) |
| 1948 | return; |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1949 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1950 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1951 | |
| 1952 | if (rp->status) |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1953 | return; |
| 1954 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1955 | hci_bdaddr_list_clear(&hdev->le_accept_list); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1956 | } |
| 1957 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1958 | static void hci_cc_le_add_to_accept_list(struct hci_dev *hdev, |
| 1959 | struct sk_buff *skb) |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1960 | { |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1961 | struct hci_cp_le_add_to_accept_list *sent; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1962 | struct hci_ev_status *rp; |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1963 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1964 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_ADD_TO_ACCEPT_LIST, |
| 1965 | sizeof(*rp)); |
| 1966 | if (!rp) |
| 1967 | return; |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 1968 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1969 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1970 | |
| 1971 | if (rp->status) |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 1972 | return; |
| 1973 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1974 | 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] | 1975 | if (!sent) |
| 1976 | return; |
| 1977 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1978 | hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr, |
| 1979 | sent->bdaddr_type); |
| 1980 | } |
| 1981 | |
| 1982 | static void hci_cc_le_del_from_accept_list(struct hci_dev *hdev, |
| 1983 | struct sk_buff *skb) |
| 1984 | { |
| 1985 | struct hci_cp_le_del_from_accept_list *sent; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1986 | struct hci_ev_status *rp; |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1987 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1988 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_DEL_FROM_ACCEPT_LIST, |
| 1989 | sizeof(*rp)); |
| 1990 | if (!rp) |
| 1991 | return; |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1992 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 1993 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 1994 | |
| 1995 | if (rp->status) |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 1996 | return; |
| 1997 | |
| 1998 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST); |
| 1999 | if (!sent) |
| 2000 | return; |
| 2001 | |
| 2002 | hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr, |
Johan Hedberg | dcc36c1 | 2014-07-09 12:59:13 +0300 | [diff] [blame] | 2003 | sent->bdaddr_type); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 2004 | } |
| 2005 | |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 2006 | static void hci_cc_le_read_supported_states(struct hci_dev *hdev, |
| 2007 | struct sk_buff *skb) |
| 2008 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2009 | struct hci_rp_le_read_supported_states *rp; |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 2010 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2011 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_SUPPORTED_STATES, |
| 2012 | sizeof(*rp)); |
| 2013 | if (!rp) |
| 2014 | return; |
| 2015 | |
| 2016 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 2017 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 2018 | if (rp->status) |
| 2019 | return; |
| 2020 | |
| 2021 | memcpy(hdev->le_states, rp->le_states, 8); |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 2022 | } |
| 2023 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2024 | static void hci_cc_le_read_def_data_len(struct hci_dev *hdev, |
| 2025 | struct sk_buff *skb) |
| 2026 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2027 | struct hci_rp_le_read_def_data_len *rp; |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2028 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2029 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_DEF_DATA_LEN, |
| 2030 | sizeof(*rp)); |
| 2031 | if (!rp) |
| 2032 | return; |
| 2033 | |
| 2034 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2035 | |
| 2036 | if (rp->status) |
| 2037 | return; |
| 2038 | |
| 2039 | hdev->le_def_tx_len = le16_to_cpu(rp->tx_len); |
| 2040 | hdev->le_def_tx_time = le16_to_cpu(rp->tx_time); |
| 2041 | } |
| 2042 | |
| 2043 | static void hci_cc_le_write_def_data_len(struct hci_dev *hdev, |
| 2044 | struct sk_buff *skb) |
| 2045 | { |
| 2046 | struct hci_cp_le_write_def_data_len *sent; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2047 | struct hci_ev_status *rp; |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2048 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2049 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_WRITE_DEF_DATA_LEN, |
| 2050 | sizeof(*rp)); |
| 2051 | if (!rp) |
| 2052 | return; |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2053 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2054 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 2055 | |
| 2056 | if (rp->status) |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2057 | return; |
| 2058 | |
| 2059 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN); |
| 2060 | if (!sent) |
| 2061 | return; |
| 2062 | |
| 2063 | hdev->le_def_tx_len = le16_to_cpu(sent->tx_len); |
| 2064 | hdev->le_def_tx_time = le16_to_cpu(sent->tx_time); |
| 2065 | } |
| 2066 | |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 2067 | static void hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, |
| 2068 | struct sk_buff *skb) |
| 2069 | { |
| 2070 | struct hci_cp_le_add_to_resolv_list *sent; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2071 | struct hci_ev_status *rp; |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 2072 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2073 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_ADD_TO_RESOLV_LIST, |
| 2074 | sizeof(*rp)); |
| 2075 | if (!rp) |
| 2076 | return; |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 2077 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2078 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 2079 | |
| 2080 | if (rp->status) |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 2081 | return; |
| 2082 | |
| 2083 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST); |
| 2084 | if (!sent) |
| 2085 | return; |
| 2086 | |
| 2087 | hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr, |
| 2088 | sent->bdaddr_type, sent->peer_irk, |
| 2089 | sent->local_irk); |
| 2090 | } |
| 2091 | |
| 2092 | static void hci_cc_le_del_from_resolv_list(struct hci_dev *hdev, |
| 2093 | struct sk_buff *skb) |
| 2094 | { |
| 2095 | struct hci_cp_le_del_from_resolv_list *sent; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2096 | struct hci_ev_status *rp; |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 2097 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2098 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_DEL_FROM_RESOLV_LIST, |
| 2099 | sizeof(*rp)); |
| 2100 | if (!rp) |
| 2101 | return; |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 2102 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2103 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 2104 | |
| 2105 | if (rp->status) |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 2106 | return; |
| 2107 | |
| 2108 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST); |
| 2109 | if (!sent) |
| 2110 | return; |
| 2111 | |
| 2112 | hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr, |
| 2113 | sent->bdaddr_type); |
| 2114 | } |
| 2115 | |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 2116 | static void hci_cc_le_clear_resolv_list(struct hci_dev *hdev, |
| 2117 | struct sk_buff *skb) |
| 2118 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2119 | struct hci_ev_status *rp; |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 2120 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2121 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_CLEAR_RESOLV_LIST, |
| 2122 | sizeof(*rp)); |
| 2123 | if (!rp) |
| 2124 | return; |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 2125 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2126 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 2127 | |
| 2128 | if (rp->status) |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 2129 | return; |
| 2130 | |
| 2131 | hci_bdaddr_list_clear(&hdev->le_resolv_list); |
| 2132 | } |
| 2133 | |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 2134 | static void hci_cc_le_read_resolv_list_size(struct hci_dev *hdev, |
| 2135 | struct sk_buff *skb) |
| 2136 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2137 | struct hci_rp_le_read_resolv_list_size *rp; |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 2138 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2139 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_RESOLV_LIST_SIZE, |
| 2140 | sizeof(*rp)); |
| 2141 | if (!rp) |
| 2142 | return; |
| 2143 | |
| 2144 | bt_dev_dbg(hdev, "status 0x%2.2x size %u", rp->status, rp->size); |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 2145 | |
| 2146 | if (rp->status) |
| 2147 | return; |
| 2148 | |
| 2149 | hdev->le_resolv_list_size = rp->size; |
| 2150 | } |
| 2151 | |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 2152 | static void hci_cc_le_set_addr_resolution_enable(struct hci_dev *hdev, |
| 2153 | struct sk_buff *skb) |
| 2154 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2155 | struct hci_ev_status *rp; |
| 2156 | __u8 *sent; |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 2157 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2158 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, |
| 2159 | sizeof(*rp)); |
| 2160 | if (!rp) |
| 2161 | return; |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 2162 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2163 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 2164 | |
| 2165 | if (rp->status) |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 2166 | return; |
| 2167 | |
| 2168 | sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE); |
| 2169 | if (!sent) |
| 2170 | return; |
| 2171 | |
| 2172 | hci_dev_lock(hdev); |
| 2173 | |
| 2174 | if (*sent) |
| 2175 | hci_dev_set_flag(hdev, HCI_LL_RPA_RESOLUTION); |
| 2176 | else |
| 2177 | hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION); |
| 2178 | |
| 2179 | hci_dev_unlock(hdev); |
| 2180 | } |
| 2181 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2182 | static void hci_cc_le_read_max_data_len(struct hci_dev *hdev, |
| 2183 | struct sk_buff *skb) |
| 2184 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2185 | struct hci_rp_le_read_max_data_len *rp; |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2186 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2187 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_READ_MAX_DATA_LEN, |
| 2188 | sizeof(*rp)); |
| 2189 | if (!rp) |
| 2190 | return; |
| 2191 | |
| 2192 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 2193 | |
| 2194 | if (rp->status) |
| 2195 | return; |
| 2196 | |
| 2197 | hdev->le_max_tx_len = le16_to_cpu(rp->tx_len); |
| 2198 | hdev->le_max_tx_time = le16_to_cpu(rp->tx_time); |
| 2199 | hdev->le_max_rx_len = le16_to_cpu(rp->rx_len); |
| 2200 | hdev->le_max_rx_time = le16_to_cpu(rp->rx_time); |
| 2201 | } |
| 2202 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2203 | static void hci_cc_write_le_host_supported(struct hci_dev *hdev, |
| 2204 | struct sk_buff *skb) |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 2205 | { |
Johan Hedberg | 06199cf | 2012-02-22 16:37:11 +0200 | [diff] [blame] | 2206 | struct hci_cp_write_le_host_supported *sent; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2207 | struct hci_ev_status *rp; |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 2208 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2209 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_LE_HOST_SUPPORTED, |
| 2210 | sizeof(*rp)); |
| 2211 | if (!rp) |
| 2212 | return; |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 2213 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2214 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 2215 | |
| 2216 | if (rp->status) |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 2217 | return; |
| 2218 | |
Johan Hedberg | 06199cf | 2012-02-22 16:37:11 +0200 | [diff] [blame] | 2219 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED); |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 2220 | if (!sent) |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 2221 | return; |
| 2222 | |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 2223 | hci_dev_lock(hdev); |
| 2224 | |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 2225 | if (sent->le) { |
| 2226 | hdev->features[1][0] |= LMP_HOST_LE; |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 2227 | hci_dev_set_flag(hdev, HCI_LE_ENABLED); |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 2228 | } else { |
| 2229 | hdev->features[1][0] &= ~LMP_HOST_LE; |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 2230 | hci_dev_clear_flag(hdev, HCI_LE_ENABLED); |
| 2231 | hci_dev_clear_flag(hdev, HCI_ADVERTISING); |
Johan Hedberg | 8f984df | 2012-02-28 01:07:22 +0200 | [diff] [blame] | 2232 | } |
Marcel Holtmann | 45296ac | 2014-07-05 10:48:01 +0200 | [diff] [blame] | 2233 | |
| 2234 | if (sent->simul) |
| 2235 | hdev->features[1][0] |= LMP_HOST_LE_BREDR; |
| 2236 | else |
| 2237 | hdev->features[1][0] &= ~LMP_HOST_LE_BREDR; |
Jaganath Kanakkassery | 5c1a4c8 | 2014-12-11 18:58:15 +0530 | [diff] [blame] | 2238 | |
| 2239 | hci_dev_unlock(hdev); |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 2240 | } |
| 2241 | |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 2242 | static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 2243 | { |
| 2244 | struct hci_cp_le_set_adv_param *cp; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2245 | struct hci_ev_status *rp; |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 2246 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2247 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_ADV_PARAM, sizeof(*rp)); |
| 2248 | if (!rp) |
| 2249 | return; |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 2250 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2251 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 2252 | |
| 2253 | if (rp->status) |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 2254 | return; |
| 2255 | |
| 2256 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM); |
| 2257 | if (!cp) |
| 2258 | return; |
| 2259 | |
| 2260 | hci_dev_lock(hdev); |
| 2261 | hdev->adv_addr_type = cp->own_address_type; |
| 2262 | hci_dev_unlock(hdev); |
| 2263 | } |
| 2264 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 2265 | static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb) |
| 2266 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2267 | struct hci_rp_le_set_ext_adv_params *rp; |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 2268 | struct hci_cp_le_set_ext_adv_params *cp; |
| 2269 | struct adv_info *adv_instance; |
| 2270 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2271 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_LE_SET_EXT_ADV_PARAMS, |
| 2272 | sizeof(*rp)); |
| 2273 | if (!rp) |
| 2274 | return; |
| 2275 | |
| 2276 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 2277 | |
| 2278 | if (rp->status) |
| 2279 | return; |
| 2280 | |
| 2281 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS); |
| 2282 | if (!cp) |
| 2283 | return; |
| 2284 | |
| 2285 | hci_dev_lock(hdev); |
| 2286 | hdev->adv_addr_type = cp->own_addr_type; |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 2287 | if (!cp->handle) { |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 2288 | /* Store in hdev for instance 0 */ |
| 2289 | hdev->adv_tx_power = rp->tx_power; |
| 2290 | } else { |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 2291 | adv_instance = hci_find_adv_instance(hdev, cp->handle); |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 2292 | if (adv_instance) |
| 2293 | adv_instance->tx_power = rp->tx_power; |
| 2294 | } |
Jaganath Kanakkassery | a0fb372 | 2018-07-19 17:09:42 +0530 | [diff] [blame] | 2295 | /* Update adv data as tx power is known now */ |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 2296 | hci_req_update_adv_data(hdev, cp->handle); |
Daniel Winkler | 1241057 | 2020-12-03 12:12:49 -0800 | [diff] [blame] | 2297 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 2298 | hci_dev_unlock(hdev); |
| 2299 | } |
| 2300 | |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 2301 | static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb) |
| 2302 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2303 | struct hci_rp_read_rssi *rp; |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 2304 | struct hci_conn *conn; |
| 2305 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2306 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_RSSI, sizeof(*rp)); |
| 2307 | if (!rp) |
| 2308 | return; |
| 2309 | |
| 2310 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 2311 | |
| 2312 | if (rp->status) |
| 2313 | return; |
| 2314 | |
| 2315 | hci_dev_lock(hdev); |
| 2316 | |
| 2317 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
| 2318 | if (conn) |
| 2319 | conn->rssi = rp->rssi; |
| 2320 | |
| 2321 | hci_dev_unlock(hdev); |
| 2322 | } |
| 2323 | |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 2324 | static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb) |
| 2325 | { |
| 2326 | struct hci_cp_read_tx_power *sent; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2327 | struct hci_rp_read_tx_power *rp; |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 2328 | struct hci_conn *conn; |
| 2329 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2330 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_READ_TX_POWER, sizeof(*rp)); |
| 2331 | if (!rp) |
| 2332 | return; |
| 2333 | |
| 2334 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 2335 | |
| 2336 | if (rp->status) |
| 2337 | return; |
| 2338 | |
| 2339 | sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER); |
| 2340 | if (!sent) |
| 2341 | return; |
| 2342 | |
| 2343 | hci_dev_lock(hdev); |
| 2344 | |
| 2345 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
Andrzej Kaczmarek | d0455ed | 2014-05-14 13:43:05 +0200 | [diff] [blame] | 2346 | if (!conn) |
| 2347 | goto unlock; |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 2348 | |
Andrzej Kaczmarek | d0455ed | 2014-05-14 13:43:05 +0200 | [diff] [blame] | 2349 | switch (sent->type) { |
| 2350 | case 0x00: |
| 2351 | conn->tx_power = rp->tx_power; |
| 2352 | break; |
| 2353 | case 0x01: |
| 2354 | conn->max_tx_power = rp->tx_power; |
| 2355 | break; |
| 2356 | } |
| 2357 | |
| 2358 | unlock: |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 2359 | hci_dev_unlock(hdev); |
| 2360 | } |
| 2361 | |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 2362 | static void hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, struct sk_buff *skb) |
| 2363 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2364 | struct hci_ev_status *rp; |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 2365 | u8 *mode; |
| 2366 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2367 | rp = hci_cc_skb_pull(hdev, skb, HCI_OP_WRITE_SSP_DEBUG_MODE, |
| 2368 | sizeof(*rp)); |
| 2369 | if (!rp) |
| 2370 | return; |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 2371 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 2372 | bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); |
| 2373 | |
| 2374 | if (rp->status) |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 2375 | return; |
| 2376 | |
| 2377 | mode = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE); |
| 2378 | if (mode) |
| 2379 | hdev->ssp_debug_mode = *mode; |
| 2380 | } |
| 2381 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2382 | static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2383 | { |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2384 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2385 | |
| 2386 | if (status) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2387 | hci_conn_check_pending(hdev); |
Johan Hedberg | 314b238 | 2011-04-27 10:29:57 -0400 | [diff] [blame] | 2388 | return; |
| 2389 | } |
| 2390 | |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 2391 | set_bit(HCI_INQUIRY, &hdev->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2392 | } |
| 2393 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2394 | static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2396 | struct hci_cp_create_conn *cp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2399 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2400 | |
| 2401 | cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | if (!cp) |
| 2403 | return; |
| 2404 | |
| 2405 | hci_dev_lock(hdev); |
| 2406 | |
| 2407 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 2408 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 2409 | BT_DBG("%s bdaddr %pMR hcon %p", hdev->name, &cp->bdaddr, conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | |
| 2411 | if (status) { |
| 2412 | if (conn && conn->state == BT_CONNECT) { |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 2413 | if (status != 0x0c || conn->attempt > 2) { |
| 2414 | conn->state = BT_CLOSED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2415 | hci_connect_cfm(conn, status); |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 2416 | hci_conn_del(conn); |
| 2417 | } else |
| 2418 | conn->state = BT_CONNECT2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | } |
| 2420 | } else { |
| 2421 | if (!conn) { |
Johan Hedberg | a5c4e30 | 2014-07-16 11:56:07 +0300 | [diff] [blame] | 2422 | conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr, |
| 2423 | HCI_ROLE_MASTER); |
| 2424 | if (!conn) |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 2425 | bt_dev_err(hdev, "no memory for new connection"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2426 | } |
| 2427 | } |
| 2428 | |
| 2429 | hci_dev_unlock(hdev); |
| 2430 | } |
| 2431 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2432 | static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2433 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2434 | struct hci_cp_add_sco *cp; |
| 2435 | struct hci_conn *acl, *sco; |
| 2436 | __u16 handle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2438 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2439 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2440 | if (!status) |
| 2441 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2443 | cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO); |
| 2444 | if (!cp) |
| 2445 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2447 | handle = __le16_to_cpu(cp->handle); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2449 | BT_DBG("%s handle 0x%4.4x", hdev->name, handle); |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 2450 | |
| 2451 | hci_dev_lock(hdev); |
| 2452 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2453 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 2454 | if (acl) { |
| 2455 | sco = acl->link; |
| 2456 | if (sco) { |
| 2457 | sco->state = BT_CLOSED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2458 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2459 | hci_connect_cfm(sco, status); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 2460 | hci_conn_del(sco); |
| 2461 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2462 | } |
Marcel Holtmann | 6bd5741 | 2006-11-18 22:14:22 +0100 | [diff] [blame] | 2463 | |
| 2464 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2465 | } |
| 2466 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2467 | static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) |
| 2468 | { |
| 2469 | struct hci_cp_auth_requested *cp; |
| 2470 | struct hci_conn *conn; |
| 2471 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2472 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2473 | |
| 2474 | if (!status) |
| 2475 | return; |
| 2476 | |
| 2477 | cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED); |
| 2478 | if (!cp) |
| 2479 | return; |
| 2480 | |
| 2481 | hci_dev_lock(hdev); |
| 2482 | |
| 2483 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2484 | if (conn) { |
| 2485 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2486 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2487 | hci_conn_drop(conn); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2488 | } |
| 2489 | } |
| 2490 | |
| 2491 | hci_dev_unlock(hdev); |
| 2492 | } |
| 2493 | |
| 2494 | static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) |
| 2495 | { |
| 2496 | struct hci_cp_set_conn_encrypt *cp; |
| 2497 | struct hci_conn *conn; |
| 2498 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2499 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2500 | |
| 2501 | if (!status) |
| 2502 | return; |
| 2503 | |
| 2504 | cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT); |
| 2505 | if (!cp) |
| 2506 | return; |
| 2507 | |
| 2508 | hci_dev_lock(hdev); |
| 2509 | |
| 2510 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2511 | if (conn) { |
| 2512 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2513 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2514 | hci_conn_drop(conn); |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2515 | } |
| 2516 | } |
| 2517 | |
| 2518 | hci_dev_unlock(hdev); |
| 2519 | } |
| 2520 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2521 | static int hci_outgoing_auth_needed(struct hci_dev *hdev, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2522 | struct hci_conn *conn) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2523 | { |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2524 | if (conn->state != BT_CONFIG || !conn->out) |
| 2525 | return 0; |
| 2526 | |
Johan Hedberg | 765c2a9 | 2011-01-19 12:06:52 +0530 | [diff] [blame] | 2527 | if (conn->pending_sec_level == BT_SECURITY_SDP) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2528 | return 0; |
| 2529 | |
| 2530 | /* Only request authentication for SSP connections or non-SSP |
Johan Hedberg | 264b8b4 | 2014-01-08 16:40:39 +0200 | [diff] [blame] | 2531 | * devices with sec_level MEDIUM or HIGH or if MITM protection |
| 2532 | * is requested. |
| 2533 | */ |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 2534 | if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) && |
Johan Hedberg | 7e3691e | 2014-05-30 14:45:19 +0300 | [diff] [blame] | 2535 | conn->pending_sec_level != BT_SECURITY_FIPS && |
Johan Hedberg | 264b8b4 | 2014-01-08 16:40:39 +0200 | [diff] [blame] | 2536 | conn->pending_sec_level != BT_SECURITY_HIGH && |
| 2537 | conn->pending_sec_level != BT_SECURITY_MEDIUM) |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2538 | return 0; |
| 2539 | |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 2540 | return 1; |
| 2541 | } |
| 2542 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 2543 | static int hci_resolve_name(struct hci_dev *hdev, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2544 | struct inquiry_entry *e) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2545 | { |
| 2546 | struct hci_cp_remote_name_req cp; |
| 2547 | |
| 2548 | memset(&cp, 0, sizeof(cp)); |
| 2549 | |
| 2550 | bacpy(&cp.bdaddr, &e->data.bdaddr); |
| 2551 | cp.pscan_rep_mode = e->data.pscan_rep_mode; |
| 2552 | cp.pscan_mode = e->data.pscan_mode; |
| 2553 | cp.clock_offset = e->data.clock_offset; |
| 2554 | |
| 2555 | return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
| 2556 | } |
| 2557 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2558 | static bool hci_resolve_next_name(struct hci_dev *hdev) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2559 | { |
| 2560 | struct discovery_state *discov = &hdev->discovery; |
| 2561 | struct inquiry_entry *e; |
| 2562 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2563 | if (list_empty(&discov->resolve)) |
| 2564 | return false; |
| 2565 | |
Archie Pusaka | dbf6811 | 2021-11-25 15:04:37 +0800 | [diff] [blame] | 2566 | /* We should stop if we already spent too much time resolving names. */ |
| 2567 | if (time_after(jiffies, discov->name_resolve_timeout)) { |
| 2568 | bt_dev_warn_ratelimited(hdev, "Name resolve takes too long."); |
| 2569 | return false; |
| 2570 | } |
| 2571 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2572 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
Ram Malovany | c810089 | 2012-07-19 10:26:09 +0300 | [diff] [blame] | 2573 | if (!e) |
| 2574 | return false; |
| 2575 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2576 | if (hci_resolve_name(hdev, e) == 0) { |
| 2577 | e->name_state = NAME_PENDING; |
| 2578 | return true; |
| 2579 | } |
| 2580 | |
| 2581 | return false; |
| 2582 | } |
| 2583 | |
| 2584 | 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] | 2585 | bdaddr_t *bdaddr, u8 *name, u8 name_len) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2586 | { |
| 2587 | struct discovery_state *discov = &hdev->discovery; |
| 2588 | struct inquiry_entry *e; |
| 2589 | |
Johan Hedberg | 60cb49d | 2014-11-11 11:33:24 +0200 | [diff] [blame] | 2590 | /* Update the mgmt connected state if necessary. Be careful with |
| 2591 | * conn objects that exist but are not (yet) connected however. |
| 2592 | * Only those in BT_CONFIG or BT_CONNECTED states can be |
| 2593 | * considered connected. |
| 2594 | */ |
| 2595 | if (conn && |
| 2596 | (conn->state == BT_CONFIG || conn->state == BT_CONNECTED) && |
Jaganath Kanakkassery | cb77c3e | 2014-11-07 16:39:09 +0530 | [diff] [blame] | 2597 | !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 2598 | mgmt_device_connected(hdev, conn, name, name_len); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2599 | |
| 2600 | if (discov->state == DISCOVERY_STOPPED) |
| 2601 | return; |
| 2602 | |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2603 | if (discov->state == DISCOVERY_STOPPING) |
| 2604 | goto discov_complete; |
| 2605 | |
| 2606 | if (discov->state != DISCOVERY_RESOLVING) |
| 2607 | return; |
| 2608 | |
| 2609 | e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING); |
Ram Malovany | 7cc8380 | 2012-07-19 10:26:10 +0300 | [diff] [blame] | 2610 | /* If the device was not found in a list of found devices names of which |
| 2611 | * are pending. there is no need to continue resolving a next name as it |
| 2612 | * will be done upon receiving another Remote Name Request Complete |
| 2613 | * Event */ |
| 2614 | if (!e) |
| 2615 | return; |
| 2616 | |
| 2617 | list_del(&e->list); |
Archie Pusaka | ea13aed | 2021-11-25 15:04:36 +0800 | [diff] [blame] | 2618 | |
| 2619 | e->name_state = name ? NAME_KNOWN : NAME_NOT_KNOWN; |
| 2620 | mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, e->data.rssi, |
| 2621 | name, name_len); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2622 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2623 | if (hci_resolve_next_name(hdev)) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2624 | return; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 2625 | |
| 2626 | discov_complete: |
| 2627 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
| 2628 | } |
| 2629 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2630 | static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) |
| 2631 | { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2632 | struct hci_cp_remote_name_req *cp; |
| 2633 | struct hci_conn *conn; |
| 2634 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2635 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2636 | |
| 2637 | /* If successful wait for the name req complete event before |
| 2638 | * checking for the need to do authentication */ |
| 2639 | if (!status) |
| 2640 | return; |
| 2641 | |
| 2642 | cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ); |
| 2643 | if (!cp) |
| 2644 | return; |
| 2645 | |
| 2646 | hci_dev_lock(hdev); |
| 2647 | |
| 2648 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2649 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 2650 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 2651 | hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0); |
| 2652 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 2653 | if (!conn) |
| 2654 | goto unlock; |
| 2655 | |
| 2656 | if (!hci_outgoing_auth_needed(hdev, conn)) |
| 2657 | goto unlock; |
| 2658 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2659 | if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johannes Berg | c1f23a2 | 2013-10-07 18:19:16 +0200 | [diff] [blame] | 2660 | struct hci_cp_auth_requested auth_cp; |
| 2661 | |
Johan Hedberg | 977f8fc | 2014-07-17 15:35:39 +0300 | [diff] [blame] | 2662 | set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); |
| 2663 | |
Johannes Berg | c1f23a2 | 2013-10-07 18:19:16 +0200 | [diff] [blame] | 2664 | auth_cp.handle = __cpu_to_le16(conn->handle); |
| 2665 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, |
| 2666 | sizeof(auth_cp), &auth_cp); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2667 | } |
| 2668 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 2669 | unlock: |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 2670 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2671 | } |
| 2672 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2673 | static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) |
| 2674 | { |
| 2675 | struct hci_cp_read_remote_features *cp; |
| 2676 | struct hci_conn *conn; |
| 2677 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2678 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2679 | |
| 2680 | if (!status) |
| 2681 | return; |
| 2682 | |
| 2683 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES); |
| 2684 | if (!cp) |
| 2685 | return; |
| 2686 | |
| 2687 | hci_dev_lock(hdev); |
| 2688 | |
| 2689 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2690 | if (conn) { |
| 2691 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2692 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2693 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2694 | } |
| 2695 | } |
| 2696 | |
| 2697 | hci_dev_unlock(hdev); |
| 2698 | } |
| 2699 | |
| 2700 | static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status) |
| 2701 | { |
| 2702 | struct hci_cp_read_remote_ext_features *cp; |
| 2703 | struct hci_conn *conn; |
| 2704 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2705 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2706 | |
| 2707 | if (!status) |
| 2708 | return; |
| 2709 | |
| 2710 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES); |
| 2711 | if (!cp) |
| 2712 | return; |
| 2713 | |
| 2714 | hci_dev_lock(hdev); |
| 2715 | |
| 2716 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 2717 | if (conn) { |
| 2718 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2719 | hci_connect_cfm(conn, status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 2720 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | hci_dev_unlock(hdev); |
| 2725 | } |
| 2726 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2727 | static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| 2728 | { |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2729 | struct hci_cp_setup_sync_conn *cp; |
| 2730 | struct hci_conn *acl, *sco; |
| 2731 | __u16 handle; |
| 2732 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2733 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2734 | |
| 2735 | if (!status) |
| 2736 | return; |
| 2737 | |
| 2738 | cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN); |
| 2739 | if (!cp) |
| 2740 | return; |
| 2741 | |
| 2742 | handle = __le16_to_cpu(cp->handle); |
| 2743 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2744 | BT_DBG("%s handle 0x%4.4x", hdev->name, handle); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2745 | |
| 2746 | hci_dev_lock(hdev); |
| 2747 | |
| 2748 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 2749 | if (acl) { |
| 2750 | sco = acl->link; |
| 2751 | if (sco) { |
| 2752 | sco->state = BT_CLOSED; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2753 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 2754 | hci_connect_cfm(sco, status); |
Andrei Emeltchenko | 5a08ecc | 2011-01-11 17:20:20 +0200 | [diff] [blame] | 2755 | hci_conn_del(sco); |
| 2756 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2760 | } |
| 2761 | |
Kiran K | b2af264 | 2021-09-07 15:42:43 +0530 | [diff] [blame] | 2762 | static void hci_cs_enhanced_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
| 2763 | { |
| 2764 | struct hci_cp_enhanced_setup_sync_conn *cp; |
| 2765 | struct hci_conn *acl, *sco; |
| 2766 | __u16 handle; |
| 2767 | |
| 2768 | bt_dev_dbg(hdev, "status 0x%2.2x", status); |
| 2769 | |
| 2770 | if (!status) |
| 2771 | return; |
| 2772 | |
| 2773 | cp = hci_sent_cmd_data(hdev, HCI_OP_ENHANCED_SETUP_SYNC_CONN); |
| 2774 | if (!cp) |
| 2775 | return; |
| 2776 | |
| 2777 | handle = __le16_to_cpu(cp->handle); |
| 2778 | |
| 2779 | bt_dev_dbg(hdev, "handle 0x%4.4x", handle); |
| 2780 | |
| 2781 | hci_dev_lock(hdev); |
| 2782 | |
| 2783 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
| 2784 | if (acl) { |
| 2785 | sco = acl->link; |
| 2786 | if (sco) { |
| 2787 | sco->state = BT_CLOSED; |
| 2788 | |
| 2789 | hci_connect_cfm(sco, status); |
| 2790 | hci_conn_del(sco); |
| 2791 | } |
| 2792 | } |
| 2793 | |
| 2794 | hci_dev_unlock(hdev); |
| 2795 | } |
| 2796 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2797 | static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 2798 | { |
| 2799 | struct hci_cp_sniff_mode *cp; |
| 2800 | struct hci_conn *conn; |
| 2801 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2802 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2803 | |
| 2804 | if (!status) |
| 2805 | return; |
| 2806 | |
| 2807 | cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE); |
| 2808 | if (!cp) |
| 2809 | return; |
| 2810 | |
| 2811 | hci_dev_lock(hdev); |
| 2812 | |
| 2813 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2814 | if (conn) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2815 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2816 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2817 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2818 | hci_sco_setup(conn, status); |
| 2819 | } |
| 2820 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2821 | hci_dev_unlock(hdev); |
| 2822 | } |
| 2823 | |
| 2824 | static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) |
| 2825 | { |
| 2826 | struct hci_cp_exit_sniff_mode *cp; |
| 2827 | struct hci_conn *conn; |
| 2828 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 2829 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2830 | |
| 2831 | if (!status) |
| 2832 | return; |
| 2833 | |
| 2834 | cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE); |
| 2835 | if (!cp) |
| 2836 | return; |
| 2837 | |
| 2838 | hci_dev_lock(hdev); |
| 2839 | |
| 2840 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2841 | if (conn) { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2842 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2843 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 2844 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 2845 | hci_sco_setup(conn, status); |
| 2846 | } |
| 2847 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 2848 | hci_dev_unlock(hdev); |
| 2849 | } |
| 2850 | |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2851 | static void hci_cs_disconnect(struct hci_dev *hdev, u8 status) |
| 2852 | { |
| 2853 | struct hci_cp_disconnect *cp; |
Luiz Augusto von Dentz | 182ee45 | 2021-10-27 16:59:00 -0700 | [diff] [blame] | 2854 | struct hci_conn_params *params; |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2855 | struct hci_conn *conn; |
Luiz Augusto von Dentz | 182ee45 | 2021-10-27 16:59:00 -0700 | [diff] [blame] | 2856 | bool mgmt_conn; |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2857 | |
Luiz Augusto von Dentz | 182ee45 | 2021-10-27 16:59:00 -0700 | [diff] [blame] | 2858 | /* Wait for HCI_EV_DISCONN_COMPLETE if status 0x00 and not suspended |
| 2859 | * otherwise cleanup the connection immediately. |
| 2860 | */ |
| 2861 | if (!status && !hdev->suspended) |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2862 | return; |
| 2863 | |
| 2864 | cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT); |
| 2865 | if (!cp) |
| 2866 | return; |
| 2867 | |
| 2868 | hci_dev_lock(hdev); |
| 2869 | |
| 2870 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
Luiz Augusto von Dentz | 182ee45 | 2021-10-27 16:59:00 -0700 | [diff] [blame] | 2871 | if (!conn) |
| 2872 | goto unlock; |
| 2873 | |
| 2874 | if (status) { |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2875 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 2876 | conn->dst_type, status); |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2877 | |
Luiz Augusto von Dentz | 1eeaa1a | 2021-08-20 16:40:38 -0700 | [diff] [blame] | 2878 | if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) { |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 2879 | hdev->cur_adv_instance = conn->adv_instance; |
Luiz Augusto von Dentz | abfeea4 | 2021-10-27 16:58:45 -0700 | [diff] [blame] | 2880 | hci_enable_advertising(hdev); |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 2881 | } |
| 2882 | |
Luiz Augusto von Dentz | 182ee45 | 2021-10-27 16:59:00 -0700 | [diff] [blame] | 2883 | goto done; |
Joseph Hwang | b8d2905 | 2020-03-11 19:20:14 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
Luiz Augusto von Dentz | 182ee45 | 2021-10-27 16:59:00 -0700 | [diff] [blame] | 2886 | mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); |
| 2887 | |
| 2888 | if (conn->type == ACL_LINK) { |
| 2889 | if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) |
| 2890 | hci_remove_link_key(hdev, &conn->dst); |
| 2891 | } |
| 2892 | |
| 2893 | params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); |
| 2894 | if (params) { |
| 2895 | switch (params->auto_connect) { |
| 2896 | case HCI_AUTO_CONN_LINK_LOSS: |
| 2897 | if (cp->reason != HCI_ERROR_CONNECTION_TIMEOUT) |
| 2898 | break; |
| 2899 | fallthrough; |
| 2900 | |
| 2901 | case HCI_AUTO_CONN_DIRECT: |
| 2902 | case HCI_AUTO_CONN_ALWAYS: |
| 2903 | list_del_init(¶ms->action); |
| 2904 | list_add(¶ms->action, &hdev->pend_le_conns); |
| 2905 | break; |
| 2906 | |
| 2907 | default: |
| 2908 | break; |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type, |
| 2913 | cp->reason, mgmt_conn); |
| 2914 | |
| 2915 | hci_disconn_cfm(conn, cp->reason); |
| 2916 | |
| 2917 | done: |
| 2918 | /* If the disconnection failed for any reason, the upper layer |
| 2919 | * does not retry to disconnect in current implementation. |
| 2920 | * Hence, we need to do some basic cleanup here and re-enable |
| 2921 | * advertising if necessary. |
| 2922 | */ |
| 2923 | hci_conn_del(conn); |
| 2924 | unlock: |
Johan Hedberg | 88c3df1 | 2012-02-09 14:27:38 +0200 | [diff] [blame] | 2925 | hci_dev_unlock(hdev); |
| 2926 | } |
| 2927 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2928 | 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] | 2929 | { |
| 2930 | /* When using controller based address resolution, then the new |
| 2931 | * address types 0x02 and 0x03 are used. These types need to be |
| 2932 | * converted back into either public address or random address type |
| 2933 | */ |
| 2934 | switch (type) { |
| 2935 | case ADDR_LE_DEV_PUBLIC_RESOLVED: |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2936 | if (resolved) |
| 2937 | *resolved = true; |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 2938 | return ADDR_LE_DEV_PUBLIC; |
| 2939 | case ADDR_LE_DEV_RANDOM_RESOLVED: |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2940 | if (resolved) |
| 2941 | *resolved = true; |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 2942 | return ADDR_LE_DEV_RANDOM; |
| 2943 | } |
| 2944 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2945 | if (resolved) |
| 2946 | *resolved = false; |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 2947 | return type; |
| 2948 | } |
| 2949 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2950 | static void cs_le_create_conn(struct hci_dev *hdev, bdaddr_t *peer_addr, |
| 2951 | u8 peer_addr_type, u8 own_address_type, |
| 2952 | u8 filter_policy) |
| 2953 | { |
| 2954 | struct hci_conn *conn; |
| 2955 | |
| 2956 | conn = hci_conn_hash_lookup_le(hdev, peer_addr, |
| 2957 | peer_addr_type); |
| 2958 | if (!conn) |
| 2959 | return; |
| 2960 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 2961 | own_address_type = ev_bdaddr_type(hdev, own_address_type, NULL); |
Sathish Narasimman | b31bc00 | 2020-07-23 18:08:59 +0530 | [diff] [blame] | 2962 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2963 | /* Store the initiator and responder address information which |
| 2964 | * is needed for SMP. These values will not change during the |
| 2965 | * lifetime of the connection. |
| 2966 | */ |
| 2967 | conn->init_addr_type = own_address_type; |
| 2968 | if (own_address_type == ADDR_LE_DEV_RANDOM) |
| 2969 | bacpy(&conn->init_addr, &hdev->random_addr); |
| 2970 | else |
| 2971 | bacpy(&conn->init_addr, &hdev->bdaddr); |
| 2972 | |
| 2973 | conn->resp_addr_type = peer_addr_type; |
| 2974 | bacpy(&conn->resp_addr, peer_addr); |
| 2975 | |
| 2976 | /* We don't want the connection attempt to stick around |
| 2977 | * indefinitely since LE doesn't have a page timeout concept |
| 2978 | * 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] | 2979 | * the accept list for connecting. |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 2980 | */ |
| 2981 | if (filter_policy == HCI_LE_USE_PEER_ADDR) |
| 2982 | queue_delayed_work(conn->hdev->workqueue, |
| 2983 | &conn->le_conn_timeout, |
| 2984 | conn->conn_timeout); |
| 2985 | } |
| 2986 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2987 | static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status) |
| 2988 | { |
| 2989 | struct hci_cp_le_create_conn *cp; |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 2990 | |
| 2991 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 2992 | |
| 2993 | /* All connection failure handling is taken care of by the |
| 2994 | * hci_le_conn_failed function which is triggered by the HCI |
| 2995 | * request completion callbacks used for connecting. |
| 2996 | */ |
| 2997 | if (status) |
| 2998 | return; |
| 2999 | |
| 3000 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN); |
| 3001 | if (!cp) |
| 3002 | return; |
| 3003 | |
| 3004 | hci_dev_lock(hdev); |
| 3005 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 3006 | cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type, |
| 3007 | cp->own_address_type, cp->filter_policy); |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 3008 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 3009 | hci_dev_unlock(hdev); |
| 3010 | } |
| 3011 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 3012 | static void hci_cs_le_ext_create_conn(struct hci_dev *hdev, u8 status) |
| 3013 | { |
| 3014 | struct hci_cp_le_ext_create_conn *cp; |
| 3015 | |
| 3016 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 3017 | |
| 3018 | /* All connection failure handling is taken care of by the |
| 3019 | * hci_le_conn_failed function which is triggered by the HCI |
| 3020 | * request completion callbacks used for connecting. |
| 3021 | */ |
| 3022 | if (status) |
| 3023 | return; |
| 3024 | |
| 3025 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_EXT_CREATE_CONN); |
| 3026 | if (!cp) |
| 3027 | return; |
| 3028 | |
| 3029 | hci_dev_lock(hdev); |
| 3030 | |
| 3031 | cs_le_create_conn(hdev, &cp->peer_addr, cp->peer_addr_type, |
| 3032 | cp->own_addr_type, cp->filter_policy); |
| 3033 | |
| 3034 | hci_dev_unlock(hdev); |
| 3035 | } |
| 3036 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 3037 | static void hci_cs_le_read_remote_features(struct hci_dev *hdev, u8 status) |
| 3038 | { |
| 3039 | struct hci_cp_le_read_remote_features *cp; |
| 3040 | struct hci_conn *conn; |
| 3041 | |
| 3042 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 3043 | |
| 3044 | if (!status) |
| 3045 | return; |
| 3046 | |
| 3047 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_READ_REMOTE_FEATURES); |
| 3048 | if (!cp) |
| 3049 | return; |
| 3050 | |
| 3051 | hci_dev_lock(hdev); |
| 3052 | |
| 3053 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 3054 | if (conn) { |
| 3055 | if (conn->state == BT_CONFIG) { |
| 3056 | hci_connect_cfm(conn, status); |
| 3057 | hci_conn_drop(conn); |
| 3058 | } |
| 3059 | } |
| 3060 | |
| 3061 | hci_dev_unlock(hdev); |
| 3062 | } |
| 3063 | |
Johan Hedberg | 81d0c8a | 2014-03-24 14:39:04 +0200 | [diff] [blame] | 3064 | static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status) |
| 3065 | { |
| 3066 | struct hci_cp_le_start_enc *cp; |
| 3067 | struct hci_conn *conn; |
| 3068 | |
| 3069 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 3070 | |
| 3071 | if (!status) |
| 3072 | return; |
| 3073 | |
| 3074 | hci_dev_lock(hdev); |
| 3075 | |
| 3076 | cp = hci_sent_cmd_data(hdev, HCI_OP_LE_START_ENC); |
| 3077 | if (!cp) |
| 3078 | goto unlock; |
| 3079 | |
| 3080 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
| 3081 | if (!conn) |
| 3082 | goto unlock; |
| 3083 | |
| 3084 | if (conn->state != BT_CONNECTED) |
| 3085 | goto unlock; |
| 3086 | |
| 3087 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
| 3088 | hci_conn_drop(conn); |
| 3089 | |
| 3090 | unlock: |
| 3091 | hci_dev_unlock(hdev); |
| 3092 | } |
| 3093 | |
Kuba Pawlak | 50fc85f | 2014-11-06 19:36:52 +0100 | [diff] [blame] | 3094 | static void hci_cs_switch_role(struct hci_dev *hdev, u8 status) |
| 3095 | { |
| 3096 | struct hci_cp_switch_role *cp; |
| 3097 | struct hci_conn *conn; |
| 3098 | |
| 3099 | BT_DBG("%s status 0x%2.2x", hdev->name, status); |
| 3100 | |
| 3101 | if (!status) |
| 3102 | return; |
| 3103 | |
| 3104 | cp = hci_sent_cmd_data(hdev, HCI_OP_SWITCH_ROLE); |
| 3105 | if (!cp) |
| 3106 | return; |
| 3107 | |
| 3108 | hci_dev_lock(hdev); |
| 3109 | |
| 3110 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); |
| 3111 | if (conn) |
| 3112 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
| 3113 | |
| 3114 | hci_dev_unlock(hdev); |
| 3115 | } |
| 3116 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3117 | 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] | 3118 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3119 | struct hci_ev_status *ev; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 3120 | struct discovery_state *discov = &hdev->discovery; |
| 3121 | struct inquiry_entry *e; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3122 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3123 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_COMPLETE, sizeof(*ev)); |
| 3124 | if (!ev) |
| 3125 | return; |
| 3126 | |
| 3127 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3128 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3129 | hci_conn_check_pending(hdev); |
Andre Guedes | 89352e7 | 2011-11-04 14:16:53 -0300 | [diff] [blame] | 3130 | |
| 3131 | if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags)) |
| 3132 | return; |
| 3133 | |
Peter Zijlstra | 4e857c5 | 2014-03-17 18:06:10 +0100 | [diff] [blame] | 3134 | smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */ |
Andre Guedes | 3e13fa1 | 2013-03-27 20:04:56 -0300 | [diff] [blame] | 3135 | wake_up_bit(&hdev->flags, HCI_INQUIRY); |
| 3136 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 3137 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 3138 | return; |
| 3139 | |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 3140 | hci_dev_lock(hdev); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 3141 | |
Andre Guedes | 343f935 | 2012-02-17 20:39:37 -0300 | [diff] [blame] | 3142 | if (discov->state != DISCOVERY_FINDING) |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 3143 | goto unlock; |
| 3144 | |
| 3145 | if (list_empty(&discov->resolve)) { |
Jakub Pawlowski | 07d2334 | 2015-03-17 09:04:14 -0700 | [diff] [blame] | 3146 | /* When BR/EDR inquiry is active and no LE scanning is in |
| 3147 | * progress, then change discovery state to indicate completion. |
| 3148 | * |
| 3149 | * When running LE scanning and BR/EDR inquiry simultaneously |
| 3150 | * and the LE scan already finished, then change the discovery |
| 3151 | * state to indicate completion. |
| 3152 | */ |
| 3153 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 3154 | !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) |
| 3155 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 3156 | goto unlock; |
| 3157 | } |
| 3158 | |
| 3159 | e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED); |
| 3160 | if (e && hci_resolve_name(hdev, e) == 0) { |
| 3161 | e->name_state = NAME_PENDING; |
| 3162 | hci_discovery_set_state(hdev, DISCOVERY_RESOLVING); |
Archie Pusaka | dbf6811 | 2021-11-25 15:04:37 +0800 | [diff] [blame] | 3163 | discov->name_resolve_timeout = jiffies + NAME_RESOLVE_DURATION; |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 3164 | } else { |
Jakub Pawlowski | 07d2334 | 2015-03-17 09:04:14 -0700 | [diff] [blame] | 3165 | /* When BR/EDR inquiry is active and no LE scanning is in |
| 3166 | * progress, then change discovery state to indicate completion. |
| 3167 | * |
| 3168 | * When running LE scanning and BR/EDR inquiry simultaneously |
| 3169 | * and the LE scan already finished, then change the discovery |
| 3170 | * state to indicate completion. |
| 3171 | */ |
| 3172 | if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) || |
| 3173 | !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) |
| 3174 | hci_discovery_set_state(hdev, DISCOVERY_STOPPED); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | unlock: |
Johan Hedberg | 56e5cb8 | 2011-11-08 20:40:16 +0200 | [diff] [blame] | 3178 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3179 | } |
| 3180 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3181 | 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] | 3182 | { |
Luiz Augusto von Dentz | 27d9eb4 | 2021-12-01 10:54:56 -0800 | [diff] [blame] | 3183 | struct hci_ev_inquiry_result *ev; |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3184 | struct inquiry_data data; |
Luiz Augusto von Dentz | 27d9eb4 | 2021-12-01 10:54:56 -0800 | [diff] [blame] | 3185 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3186 | |
Luiz Augusto von Dentz | 27d9eb4 | 2021-12-01 10:54:56 -0800 | [diff] [blame] | 3187 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT, sizeof(*ev)); |
| 3188 | if (!ev) |
| 3189 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3190 | |
Luiz Augusto von Dentz | 27d9eb4 | 2021-12-01 10:54:56 -0800 | [diff] [blame] | 3191 | if (!hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT, |
| 3192 | flex_array_size(ev, info, ev->num))) |
| 3193 | return; |
| 3194 | |
| 3195 | BT_DBG("%s num %d", hdev->name, ev->num); |
| 3196 | |
| 3197 | if (!ev->num) |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3198 | return; |
| 3199 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 3200 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 3201 | return; |
| 3202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3204 | |
Luiz Augusto von Dentz | 27d9eb4 | 2021-12-01 10:54:56 -0800 | [diff] [blame] | 3205 | for (i = 0; i < ev->num; i++) { |
| 3206 | struct inquiry_info *info = &ev->info[i]; |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 3207 | u32 flags; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 3208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3209 | bacpy(&data.bdaddr, &info->bdaddr); |
| 3210 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 3211 | data.pscan_period_mode = info->pscan_period_mode; |
| 3212 | data.pscan_mode = info->pscan_mode; |
| 3213 | memcpy(data.dev_class, info->dev_class, 3); |
| 3214 | data.clock_offset = info->clock_offset; |
Marcel Holtmann | efb2513 | 2014-12-05 13:03:34 +0100 | [diff] [blame] | 3215 | data.rssi = HCI_RSSI_INVALID; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 3216 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 3217 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 3218 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 3219 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 3220 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Marcel Holtmann | efb2513 | 2014-12-05 13:03:34 +0100 | [diff] [blame] | 3221 | info->dev_class, HCI_RSSI_INVALID, |
| 3222 | flags, NULL, 0, NULL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3223 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3224 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3225 | hci_dev_unlock(hdev); |
| 3226 | } |
| 3227 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3228 | 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] | 3229 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3230 | struct hci_ev_conn_complete *ev; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3231 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3232 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3233 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_CONN_COMPLETE, sizeof(*ev)); |
| 3234 | if (!ev) |
| 3235 | return; |
| 3236 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3237 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | hci_dev_lock(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3240 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3241 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9499237 | 2009-04-19 19:30:03 +0200 | [diff] [blame] | 3242 | if (!conn) { |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 3243 | /* Connection may not exist if auto-connected. Check the bredr |
| 3244 | * allowlist to see if this device is allowed to auto connect. |
| 3245 | * If link is an ACL type, create a connection class |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 3246 | * automatically. |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 3247 | * |
| 3248 | * Auto-connect will only occur if the event filter is |
| 3249 | * programmed with a given address. Right now, event filter is |
| 3250 | * only used during suspend. |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 3251 | */ |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 3252 | if (ev->link_type == ACL_LINK && |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 3253 | hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, |
Sonny Sasaka | a46b7ed | 2020-08-14 12:09:09 -0700 | [diff] [blame] | 3254 | &ev->bdaddr, |
| 3255 | BDADDR_BREDR)) { |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 3256 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr, |
| 3257 | HCI_ROLE_SLAVE); |
| 3258 | if (!conn) { |
| 3259 | bt_dev_err(hdev, "no memory for new conn"); |
| 3260 | goto unlock; |
| 3261 | } |
Abhishek Pandit-Subedi | 2d186fc | 2020-03-19 17:07:13 -0700 | [diff] [blame] | 3262 | } else { |
| 3263 | if (ev->link_type != SCO_LINK) |
| 3264 | goto unlock; |
| 3265 | |
| 3266 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, |
| 3267 | &ev->bdaddr); |
| 3268 | if (!conn) |
| 3269 | goto unlock; |
| 3270 | |
| 3271 | conn->type = SCO_LINK; |
Abhishek Pandit-Subedi | 4f40afc | 2020-03-11 08:54:01 -0700 | [diff] [blame] | 3272 | } |
Marcel Holtmann | 9499237 | 2009-04-19 19:30:03 +0200 | [diff] [blame] | 3273 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3274 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3275 | if (!ev->status) { |
| 3276 | conn->handle = __le16_to_cpu(ev->handle); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3277 | |
| 3278 | if (conn->type == ACL_LINK) { |
| 3279 | conn->state = BT_CONFIG; |
| 3280 | hci_conn_hold(conn); |
Szymon Janc | a9ea3ed | 2012-07-19 14:46:08 +0200 | [diff] [blame] | 3281 | |
| 3282 | if (!conn->out && !hci_conn_ssp_enabled(conn) && |
| 3283 | !hci_find_link_key(hdev, &ev->bdaddr)) |
| 3284 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
| 3285 | else |
| 3286 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3287 | } else |
| 3288 | conn->state = BT_CONNECTED; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3289 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 3290 | hci_debugfs_create_conn(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 3291 | hci_conn_add_sysfs(conn); |
| 3292 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3293 | if (test_bit(HCI_AUTH, &hdev->flags)) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3294 | set_bit(HCI_CONN_AUTH, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3295 | |
| 3296 | if (test_bit(HCI_ENCRYPT, &hdev->flags)) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3297 | set_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3298 | |
| 3299 | /* Get remote features */ |
| 3300 | if (conn->type == ACL_LINK) { |
| 3301 | struct hci_cp_read_remote_features cp; |
| 3302 | cp.handle = ev->handle; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3303 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3304 | sizeof(cp), &cp); |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 3305 | |
Johan Hedberg | 01b1cb8 | 2015-11-16 12:52:21 +0200 | [diff] [blame] | 3306 | hci_req_update_scan(hdev); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3307 | } |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3308 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3309 | /* Set packet type for incoming connection */ |
Andrei Emeltchenko | d095c1e | 2011-12-01 14:33:27 +0200 | [diff] [blame] | 3310 | if (!conn->out && hdev->hci_ver < BLUETOOTH_VER_2_0) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3311 | struct hci_cp_change_conn_ptype cp; |
| 3312 | cp.handle = ev->handle; |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 3313 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3314 | hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp), |
| 3315 | &cp); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3316 | } |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 3317 | } else { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3318 | conn->state = BT_CLOSED; |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 3319 | if (conn->type == ACL_LINK) |
Marcel Holtmann | 64c7b77 | 2014-02-18 14:22:20 -0800 | [diff] [blame] | 3320 | mgmt_connect_failed(hdev, &conn->dst, conn->type, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3321 | conn->dst_type, ev->status); |
Johan Hedberg | 17d5c04 | 2011-01-22 06:09:08 +0200 | [diff] [blame] | 3322 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3323 | |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 3324 | if (conn->type == ACL_LINK) |
| 3325 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 45bb4bf | 2005-08-09 20:27:49 -0700 | [diff] [blame] | 3326 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3327 | if (ev->status) { |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 3328 | hci_connect_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3329 | hci_conn_del(conn); |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 3330 | } else if (ev->link_type == SCO_LINK) { |
| 3331 | switch (conn->setting & SCO_AIRMODE_MASK) { |
| 3332 | case SCO_AIRMODE_CVSD: |
| 3333 | if (hdev->notify) |
| 3334 | hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD); |
| 3335 | break; |
| 3336 | } |
| 3337 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 3338 | hci_connect_cfm(conn, ev->status); |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 3339 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3340 | |
| 3341 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3343 | |
| 3344 | hci_conn_check_pending(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3347 | static void hci_reject_conn(struct hci_dev *hdev, bdaddr_t *bdaddr) |
| 3348 | { |
| 3349 | struct hci_cp_reject_conn_req cp; |
| 3350 | |
| 3351 | bacpy(&cp.bdaddr, bdaddr); |
| 3352 | cp.reason = HCI_ERROR_REJ_BAD_ADDR; |
| 3353 | hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp); |
| 3354 | } |
| 3355 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3356 | 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] | 3357 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3358 | struct hci_ev_conn_request *ev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3359 | int mask = hdev->link_mode; |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3360 | struct inquiry_entry *ie; |
| 3361 | struct hci_conn *conn; |
Frédéric Dalleau | 20714bfe | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 3362 | __u8 flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3364 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_CONN_REQUEST, sizeof(*ev)); |
| 3365 | if (!ev) |
| 3366 | return; |
| 3367 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 3368 | BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3369 | ev->link_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | |
Frédéric Dalleau | 20714bfe | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 3371 | mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type, |
| 3372 | &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3374 | if (!(mask & HCI_LM_ACCEPT)) { |
| 3375 | hci_reject_conn(hdev, &ev->bdaddr); |
| 3376 | return; |
| 3377 | } |
| 3378 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 3379 | if (hci_bdaddr_list_lookup(&hdev->reject_list, &ev->bdaddr, |
Johan Hedberg | 46c4c94 | 2014-07-16 16:19:21 +0300 | [diff] [blame] | 3380 | BDADDR_BREDR)) { |
| 3381 | hci_reject_conn(hdev, &ev->bdaddr); |
| 3382 | return; |
| 3383 | } |
| 3384 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 3385 | /* Require HCI_CONNECTABLE or an accept list entry to accept the |
Johan Hedberg | 6a8fc95 | 2014-12-24 20:43:11 +0200 | [diff] [blame] | 3386 | * connection. These features are only touched through mgmt so |
| 3387 | * only do the checks if HCI_MGMT is set. |
| 3388 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 3389 | if (hci_dev_test_flag(hdev, HCI_MGMT) && |
| 3390 | !hci_dev_test_flag(hdev, HCI_CONNECTABLE) && |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 3391 | !hci_bdaddr_list_lookup_with_flags(&hdev->accept_list, &ev->bdaddr, |
Abhishek Pandit-Subedi | 8baaa40 | 2020-06-17 16:39:08 +0200 | [diff] [blame] | 3392 | BDADDR_BREDR)) { |
| 3393 | hci_reject_conn(hdev, &ev->bdaddr); |
| 3394 | return; |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3396 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3397 | /* Connection accepted */ |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 3398 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3399 | hci_dev_lock(hdev); |
Marcel Holtmann | c7bdd50 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 3400 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3401 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 3402 | if (ie) |
| 3403 | memcpy(ie->data.dev_class, ev->dev_class, 3); |
| 3404 | |
| 3405 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, |
| 3406 | &ev->bdaddr); |
| 3407 | if (!conn) { |
Johan Hedberg | a5c4e30 | 2014-07-16 11:56:07 +0300 | [diff] [blame] | 3408 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr, |
| 3409 | HCI_ROLE_SLAVE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3410 | if (!conn) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3411 | bt_dev_err(hdev, "no memory for new connection"); |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3412 | hci_dev_unlock(hdev); |
| 3413 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3414 | } |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3415 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 3416 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3417 | memcpy(conn->dev_class, ev->dev_class, 3); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 3418 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3419 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3421 | if (ev->link_type == ACL_LINK || |
| 3422 | (!(flags & HCI_PROTO_DEFER) && !lmp_esco_capable(hdev))) { |
| 3423 | struct hci_cp_accept_conn_req cp; |
| 3424 | conn->state = BT_CONNECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | |
| 3426 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3427 | |
| 3428 | if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) |
Archie Pusaka | 74be523 | 2021-06-04 16:26:25 +0800 | [diff] [blame] | 3429 | cp.role = 0x00; /* Become central */ |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3430 | else |
Archie Pusaka | 74be523 | 2021-06-04 16:26:25 +0800 | [diff] [blame] | 3431 | cp.role = 0x01; /* Remain peripheral */ |
Johan Hedberg | 70c4642 | 2014-07-09 12:59:17 +0300 | [diff] [blame] | 3432 | |
| 3433 | hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp), &cp); |
| 3434 | } else if (!(flags & HCI_PROTO_DEFER)) { |
| 3435 | struct hci_cp_accept_sync_conn_req cp; |
| 3436 | conn->state = BT_CONNECT; |
| 3437 | |
| 3438 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 3439 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
| 3440 | |
| 3441 | cp.tx_bandwidth = cpu_to_le32(0x00001f40); |
| 3442 | cp.rx_bandwidth = cpu_to_le32(0x00001f40); |
| 3443 | cp.max_latency = cpu_to_le16(0xffff); |
| 3444 | cp.content_format = cpu_to_le16(hdev->voice_setting); |
| 3445 | cp.retrans_effort = 0xff; |
| 3446 | |
| 3447 | hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, sizeof(cp), |
| 3448 | &cp); |
| 3449 | } else { |
| 3450 | conn->state = BT_CONNECT2; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 3451 | hci_connect_cfm(conn, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | } |
| 3453 | } |
| 3454 | |
Mikel Astiz | f0d6a0e | 2012-08-09 09:52:30 +0200 | [diff] [blame] | 3455 | static u8 hci_to_mgmt_reason(u8 err) |
| 3456 | { |
| 3457 | switch (err) { |
| 3458 | case HCI_ERROR_CONNECTION_TIMEOUT: |
| 3459 | return MGMT_DEV_DISCONN_TIMEOUT; |
| 3460 | case HCI_ERROR_REMOTE_USER_TERM: |
| 3461 | case HCI_ERROR_REMOTE_LOW_RESOURCES: |
| 3462 | case HCI_ERROR_REMOTE_POWER_OFF: |
| 3463 | return MGMT_DEV_DISCONN_REMOTE; |
| 3464 | case HCI_ERROR_LOCAL_HOST_TERM: |
| 3465 | return MGMT_DEV_DISCONN_LOCAL_HOST; |
| 3466 | default: |
| 3467 | return MGMT_DEV_DISCONN_UNKNOWN; |
| 3468 | } |
| 3469 | } |
| 3470 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3471 | 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] | 3472 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3473 | struct hci_ev_disconn_complete *ev; |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3474 | u8 reason; |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 3475 | struct hci_conn_params *params; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3476 | struct hci_conn *conn; |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 3477 | bool mgmt_connected; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3478 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3479 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_DISCONN_COMPLETE, sizeof(*ev)); |
| 3480 | if (!ev) |
| 3481 | return; |
| 3482 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3483 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3485 | hci_dev_lock(hdev); |
| 3486 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 3487 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 3488 | if (!conn) |
| 3489 | goto unlock; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 3490 | |
Andre Guedes | abf54a5 | 2013-11-07 17:36:09 -0300 | [diff] [blame] | 3491 | if (ev->status) { |
| 3492 | mgmt_disconnect_failed(hdev, &conn->dst, conn->type, |
| 3493 | conn->dst_type, ev->status); |
| 3494 | goto unlock; |
Johan Hedberg | 37d9ef7 | 2011-11-10 15:54:39 +0200 | [diff] [blame] | 3495 | } |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 3496 | |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 3497 | conn->state = BT_CLOSED; |
| 3498 | |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 3499 | mgmt_connected = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags); |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3500 | |
| 3501 | if (test_bit(HCI_CONN_AUTH_FAILURE, &conn->flags)) |
| 3502 | reason = MGMT_DEV_DISCONN_AUTH_FAILURE; |
| 3503 | else |
| 3504 | reason = hci_to_mgmt_reason(ev->reason); |
| 3505 | |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 3506 | mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type, |
| 3507 | reason, mgmt_connected); |
Andre Guedes | abf54a5 | 2013-11-07 17:36:09 -0300 | [diff] [blame] | 3508 | |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 3509 | if (conn->type == ACL_LINK) { |
| 3510 | if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags)) |
| 3511 | hci_remove_link_key(hdev, &conn->dst); |
| 3512 | |
Johan Hedberg | 01b1cb8 | 2015-11-16 12:52:21 +0200 | [diff] [blame] | 3513 | hci_req_update_scan(hdev); |
Johan Hedberg | 22f433d | 2014-08-01 11:13:32 +0300 | [diff] [blame] | 3514 | } |
Johan Hedberg | 2210246 | 2013-10-05 12:01:06 +0200 | [diff] [blame] | 3515 | |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 3516 | params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); |
| 3517 | if (params) { |
| 3518 | switch (params->auto_connect) { |
| 3519 | case HCI_AUTO_CONN_LINK_LOSS: |
| 3520 | if (ev->reason != HCI_ERROR_CONNECTION_TIMEOUT) |
| 3521 | break; |
Gustavo A. R. Silva | 19186c7 | 2020-07-08 15:18:23 -0500 | [diff] [blame] | 3522 | fallthrough; |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 3523 | |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 3524 | case HCI_AUTO_CONN_DIRECT: |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 3525 | case HCI_AUTO_CONN_ALWAYS: |
Johan Hedberg | 418025d | 2014-07-04 12:37:24 +0300 | [diff] [blame] | 3526 | list_del_init(¶ms->action); |
| 3527 | list_add(¶ms->action, &hdev->pend_le_conns); |
Luiz Augusto von Dentz | 5bee2fd | 2021-10-27 16:58:43 -0700 | [diff] [blame] | 3528 | hci_update_passive_scan(hdev); |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 3529 | break; |
| 3530 | |
| 3531 | default: |
| 3532 | break; |
| 3533 | } |
| 3534 | } |
| 3535 | |
Johan Hedberg | 3a6d576 | 2015-02-18 14:53:58 +0200 | [diff] [blame] | 3536 | hci_disconn_cfm(conn, ev->reason); |
Andre Guedes | 3846220 | 2013-11-07 17:36:10 -0300 | [diff] [blame] | 3537 | |
| 3538 | /* Re-enable advertising if necessary, since it might |
| 3539 | * have been disabled by the connection. From the |
| 3540 | * HCI_LE_Set_Advertise_Enable command description in |
| 3541 | * the core specification (v4.0): |
| 3542 | * "The Controller shall continue advertising until the Host |
| 3543 | * issues an LE_Set_Advertise_Enable command with |
| 3544 | * Advertising_Enable set to 0x00 (Advertising is disabled) |
| 3545 | * or until a connection is created or until the Advertising |
| 3546 | * is timed out due to Directed Advertising." |
| 3547 | */ |
Luiz Augusto von Dentz | 1eeaa1a | 2021-08-20 16:40:38 -0700 | [diff] [blame] | 3548 | if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) { |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 3549 | hdev->cur_adv_instance = conn->adv_instance; |
Luiz Augusto von Dentz | abfeea4 | 2021-10-27 16:58:45 -0700 | [diff] [blame] | 3550 | hci_enable_advertising(hdev); |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 3551 | } |
| 3552 | |
| 3553 | hci_conn_del(conn); |
Johan Hedberg | f752054 | 2011-01-20 12:34:39 +0200 | [diff] [blame] | 3554 | |
| 3555 | unlock: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3556 | hci_dev_unlock(hdev); |
| 3557 | } |
| 3558 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3559 | 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] | 3560 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3561 | struct hci_ev_auth_complete *ev; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3562 | struct hci_conn *conn; |
| 3563 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3564 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_AUTH_COMPLETE, sizeof(*ev)); |
| 3565 | if (!ev) |
| 3566 | return; |
| 3567 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3568 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3569 | |
| 3570 | hci_dev_lock(hdev); |
| 3571 | |
| 3572 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3573 | if (!conn) |
| 3574 | goto unlock; |
| 3575 | |
| 3576 | if (!ev->status) { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3577 | clear_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 3578 | |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 3579 | if (!hci_conn_ssp_enabled(conn) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3580 | test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3581 | bt_dev_info(hdev, "re-auth of legacy device is not possible."); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 3582 | } else { |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3583 | set_bit(HCI_CONN_AUTH, &conn->flags); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3584 | conn->sec_level = conn->pending_sec_level; |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 3585 | } |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3586 | } else { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3587 | if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) |
| 3588 | set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 3589 | |
Johan Hedberg | e1e930f | 2014-09-08 17:09:49 -0700 | [diff] [blame] | 3590 | mgmt_auth_failed(conn, ev->status); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3591 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3592 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3593 | clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); |
| 3594 | clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3595 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3596 | if (conn->state == BT_CONFIG) { |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 3597 | if (!ev->status && hci_conn_ssp_enabled(conn)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3598 | struct hci_cp_set_conn_encrypt cp; |
| 3599 | cp.handle = ev->handle; |
| 3600 | cp.encrypt = 0x01; |
| 3601 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3602 | &cp); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3603 | } else { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3604 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 3605 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 3606 | hci_conn_drop(conn); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3607 | } |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3608 | } else { |
| 3609 | hci_auth_cfm(conn, ev->status); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 3610 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3611 | hci_conn_hold(conn); |
| 3612 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 3613 | hci_conn_drop(conn); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3614 | } |
| 3615 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3616 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) { |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3617 | if (!ev->status) { |
| 3618 | struct hci_cp_set_conn_encrypt cp; |
| 3619 | cp.handle = ev->handle; |
| 3620 | cp.encrypt = 0x01; |
| 3621 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp), |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3622 | &cp); |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3623 | } else { |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3624 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 3625 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3626 | } |
| 3627 | } |
| 3628 | |
Waldemar Rymarkiewicz | d7556e2 | 2011-05-31 15:49:26 +0200 | [diff] [blame] | 3629 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3630 | hci_dev_unlock(hdev); |
| 3631 | } |
| 3632 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3633 | 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] | 3634 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3635 | struct hci_ev_remote_name *ev; |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3636 | struct hci_conn *conn; |
| 3637 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3638 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_REMOTE_NAME, sizeof(*ev)); |
| 3639 | if (!ev) |
| 3640 | return; |
| 3641 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3642 | BT_DBG("%s", hdev->name); |
| 3643 | |
| 3644 | hci_conn_check_pending(hdev); |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3645 | |
| 3646 | hci_dev_lock(hdev); |
| 3647 | |
| 3648 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3649 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 3650 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3651 | goto check_auth; |
| 3652 | |
| 3653 | if (ev->status == 0) |
| 3654 | hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 3655 | strnlen(ev->name, HCI_MAX_NAME_LENGTH)); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3656 | else |
| 3657 | hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0); |
| 3658 | |
| 3659 | check_auth: |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 3660 | if (!conn) |
| 3661 | goto unlock; |
| 3662 | |
| 3663 | if (!hci_outgoing_auth_needed(hdev, conn)) |
| 3664 | goto unlock; |
| 3665 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3666 | if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3667 | struct hci_cp_auth_requested cp; |
Johan Hedberg | 977f8fc | 2014-07-17 15:35:39 +0300 | [diff] [blame] | 3668 | |
| 3669 | set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags); |
| 3670 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3671 | cp.handle = __cpu_to_le16(conn->handle); |
| 3672 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); |
| 3673 | } |
| 3674 | |
Johan Hedberg | 79c6c70 | 2011-04-28 11:28:55 -0700 | [diff] [blame] | 3675 | unlock: |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3676 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3677 | } |
| 3678 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3679 | static void read_enc_key_size_complete(struct hci_dev *hdev, u8 status, |
| 3680 | u16 opcode, struct sk_buff *skb) |
| 3681 | { |
| 3682 | const struct hci_rp_read_enc_key_size *rp; |
| 3683 | struct hci_conn *conn; |
| 3684 | u16 handle; |
| 3685 | |
| 3686 | BT_DBG("%s status 0x%02x", hdev->name, status); |
| 3687 | |
| 3688 | if (!skb || skb->len < sizeof(*rp)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3689 | bt_dev_err(hdev, "invalid read key size response"); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3690 | return; |
| 3691 | } |
| 3692 | |
| 3693 | rp = (void *)skb->data; |
| 3694 | handle = le16_to_cpu(rp->handle); |
| 3695 | |
| 3696 | hci_dev_lock(hdev); |
| 3697 | |
| 3698 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
| 3699 | if (!conn) |
| 3700 | goto unlock; |
| 3701 | |
Alain Michaud | 32b5072 | 2020-03-25 14:48:34 +0000 | [diff] [blame] | 3702 | /* While unexpected, the read_enc_key_size command may fail. The most |
| 3703 | * secure approach is to then assume the key size is 0 to force a |
| 3704 | * disconnection. |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3705 | */ |
| 3706 | if (rp->status) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3707 | bt_dev_err(hdev, "failed to read key size for handle %u", |
| 3708 | handle); |
Alain Michaud | 32b5072 | 2020-03-25 14:48:34 +0000 | [diff] [blame] | 3709 | conn->enc_key_size = 0; |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3710 | } else { |
| 3711 | conn->enc_key_size = rp->key_size; |
| 3712 | } |
| 3713 | |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 3714 | hci_encrypt_cfm(conn, 0); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3715 | |
| 3716 | unlock: |
| 3717 | hci_dev_unlock(hdev); |
| 3718 | } |
| 3719 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3720 | 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] | 3721 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3722 | struct hci_ev_encrypt_change *ev; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3723 | struct hci_conn *conn; |
| 3724 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3725 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_ENCRYPT_CHANGE, sizeof(*ev)); |
| 3726 | if (!ev) |
| 3727 | return; |
| 3728 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3729 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3730 | |
| 3731 | hci_dev_lock(hdev); |
| 3732 | |
| 3733 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3734 | if (!conn) |
| 3735 | goto unlock; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3736 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3737 | if (!ev->status) { |
| 3738 | if (ev->encrypt) { |
| 3739 | /* Encryption implies authentication */ |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3740 | set_bit(HCI_CONN_AUTH, &conn->flags); |
| 3741 | set_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3742 | conn->sec_level = conn->pending_sec_level; |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3743 | |
Marcel Holtmann | 914a6ff | 2014-02-01 11:52:02 -0800 | [diff] [blame] | 3744 | /* P-256 authentication key implies FIPS */ |
| 3745 | if (conn->key_type == HCI_LK_AUTH_COMBINATION_P256) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3746 | set_bit(HCI_CONN_FIPS, &conn->flags); |
Marcel Holtmann | 914a6ff | 2014-02-01 11:52:02 -0800 | [diff] [blame] | 3747 | |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3748 | if ((conn->type == ACL_LINK && ev->encrypt == 0x02) || |
| 3749 | conn->type == LE_LINK) |
| 3750 | set_bit(HCI_CONN_AES_CCM, &conn->flags); |
| 3751 | } else { |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3752 | clear_bit(HCI_CONN_ENCRYPT, &conn->flags); |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 3753 | clear_bit(HCI_CONN_AES_CCM, &conn->flags); |
| 3754 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3755 | } |
| 3756 | |
Johan Hedberg | 7ed3fa2 | 2014-09-10 22:16:35 -0700 | [diff] [blame] | 3757 | /* We should disregard the current RPA and generate a new one |
| 3758 | * whenever the encryption procedure fails. |
| 3759 | */ |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 3760 | if (ev->status && conn->type == LE_LINK) { |
Marcel Holtmann | a1536da | 2015-03-13 02:11:01 -0700 | [diff] [blame] | 3761 | hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 3762 | hci_adv_instances_set_rpa_expired(hdev, true); |
| 3763 | } |
Johan Hedberg | 7ed3fa2 | 2014-09-10 22:16:35 -0700 | [diff] [blame] | 3764 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3765 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
| 3766 | |
Luiz Augusto von Dentz | 8746f13 | 2020-05-20 14:20:14 -0700 | [diff] [blame] | 3767 | /* Check link security requirements are met */ |
| 3768 | if (!hci_conn_check_link_mode(conn)) |
| 3769 | ev->status = HCI_ERROR_AUTH_FAILURE; |
| 3770 | |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3771 | if (ev->status && conn->state == BT_CONNECTED) { |
Szymon Janc | 160b925 | 2016-07-12 02:12:16 +0200 | [diff] [blame] | 3772 | if (ev->status == HCI_ERROR_PIN_OR_KEY_MISSING) |
| 3773 | set_bit(HCI_CONN_AUTH_FAILURE, &conn->flags); |
| 3774 | |
Luiz Augusto von Dentz | 8746f13 | 2020-05-20 14:20:14 -0700 | [diff] [blame] | 3775 | /* Notify upper layers so they can cleanup before |
| 3776 | * disconnecting. |
| 3777 | */ |
| 3778 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3779 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
| 3780 | hci_conn_drop(conn); |
| 3781 | goto unlock; |
| 3782 | } |
| 3783 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3784 | /* Try reading the encryption key size for encrypted ACL links */ |
| 3785 | if (!ev->status && ev->encrypt && conn->type == ACL_LINK) { |
| 3786 | struct hci_cp_read_enc_key_size cp; |
| 3787 | struct hci_request req; |
| 3788 | |
| 3789 | /* Only send HCI_Read_Encryption_Key_Size if the |
| 3790 | * controller really supports it. If it doesn't, assume |
| 3791 | * the default size (16). |
| 3792 | */ |
| 3793 | if (!(hdev->commands[20] & 0x10)) { |
| 3794 | conn->enc_key_size = HCI_LINK_KEY_SIZE; |
| 3795 | goto notify; |
| 3796 | } |
| 3797 | |
| 3798 | hci_req_init(&req, hdev); |
| 3799 | |
| 3800 | cp.handle = cpu_to_le16(conn->handle); |
| 3801 | hci_req_add(&req, HCI_OP_READ_ENC_KEY_SIZE, sizeof(cp), &cp); |
| 3802 | |
| 3803 | if (hci_req_run_skb(&req, read_enc_key_size_complete)) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 3804 | bt_dev_err(hdev, "sending read key size failed"); |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3805 | conn->enc_key_size = HCI_LINK_KEY_SIZE; |
| 3806 | goto notify; |
| 3807 | } |
| 3808 | |
| 3809 | goto unlock; |
| 3810 | } |
| 3811 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 3812 | /* Set the default Authenticated Payload Timeout after |
| 3813 | * an LE Link is established. As per Core Spec v5.0, Vol 2, Part B |
| 3814 | * Section 3.3, the HCI command WRITE_AUTH_PAYLOAD_TIMEOUT should be |
| 3815 | * sent when the link is active and Encryption is enabled, the conn |
| 3816 | * type can be either LE or ACL and controller must support LMP Ping. |
| 3817 | * Ensure for AES-CCM encryption as well. |
| 3818 | */ |
| 3819 | if (test_bit(HCI_CONN_ENCRYPT, &conn->flags) && |
| 3820 | test_bit(HCI_CONN_AES_CCM, &conn->flags) && |
| 3821 | ((conn->type == ACL_LINK && lmp_ping_capable(hdev)) || |
| 3822 | (conn->type == LE_LINK && (hdev->le_features[0] & HCI_LE_PING)))) { |
| 3823 | struct hci_cp_write_auth_payload_to cp; |
| 3824 | |
| 3825 | cp.handle = cpu_to_le16(conn->handle); |
| 3826 | cp.timeout = cpu_to_le16(hdev->auth_payload_timeout); |
| 3827 | hci_send_cmd(conn->hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO, |
| 3828 | sizeof(cp), &cp); |
| 3829 | } |
| 3830 | |
Johan Hedberg | 821f376 | 2015-06-11 13:52:29 +0300 | [diff] [blame] | 3831 | notify: |
Luiz Augusto von Dentz | 3ca44c1 | 2020-05-19 13:25:19 -0700 | [diff] [blame] | 3832 | hci_encrypt_cfm(conn, ev->status); |
Marcel Holtmann | dc8357c | 2014-01-31 16:24:27 -0800 | [diff] [blame] | 3833 | |
Gustavo Padovan | a7d7723 | 2012-05-13 03:20:07 -0300 | [diff] [blame] | 3834 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3835 | hci_dev_unlock(hdev); |
| 3836 | } |
| 3837 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3838 | static void hci_change_link_key_complete_evt(struct hci_dev *hdev, |
| 3839 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3840 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3841 | struct hci_ev_change_link_key_complete *ev; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3842 | struct hci_conn *conn; |
| 3843 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3844 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_CHANGE_LINK_KEY_COMPLETE, |
| 3845 | sizeof(*ev)); |
| 3846 | if (!ev) |
| 3847 | return; |
| 3848 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 3849 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3850 | |
| 3851 | hci_dev_lock(hdev); |
| 3852 | |
| 3853 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 3854 | if (conn) { |
| 3855 | if (!ev->status) |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 3856 | set_bit(HCI_CONN_SECURE, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3857 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 3858 | clear_bit(HCI_CONN_AUTH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3859 | |
| 3860 | hci_key_change_cfm(conn, ev->status); |
| 3861 | } |
| 3862 | |
| 3863 | hci_dev_unlock(hdev); |
| 3864 | } |
| 3865 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 3866 | static void hci_remote_features_evt(struct hci_dev *hdev, |
| 3867 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3868 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3869 | struct hci_ev_remote_features *ev; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3870 | struct hci_conn *conn; |
| 3871 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 3872 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_REMOTE_FEATURES, sizeof(*ev)); |
| 3873 | if (!ev) |
| 3874 | return; |
| 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 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3878 | hci_dev_lock(hdev); |
| 3879 | |
| 3880 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3881 | if (!conn) |
| 3882 | goto unlock; |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3883 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3884 | if (!ev->status) |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 3885 | memcpy(conn->features[0], ev->features, 8); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3886 | |
| 3887 | if (conn->state != BT_CONFIG) |
| 3888 | goto unlock; |
| 3889 | |
Szymon Janc | ac363cf | 2015-01-29 16:36:59 +0100 | [diff] [blame] | 3890 | if (!ev->status && lmp_ext_feat_capable(hdev) && |
| 3891 | lmp_ext_feat_capable(conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3892 | struct hci_cp_read_remote_ext_features cp; |
| 3893 | cp.handle = ev->handle; |
| 3894 | cp.page = 0x01; |
| 3895 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 3896 | sizeof(cp), &cp); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 3897 | goto unlock; |
| 3898 | } |
| 3899 | |
Johan Hedberg | 671267b | 2012-05-12 16:11:50 -0300 | [diff] [blame] | 3900 | if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3901 | struct hci_cp_remote_name_req cp; |
| 3902 | memset(&cp, 0, sizeof(cp)); |
| 3903 | bacpy(&cp.bdaddr, &conn->dst); |
| 3904 | cp.pscan_rep_mode = 0x02; |
| 3905 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 3906 | } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 3907 | mgmt_device_connected(hdev, conn, NULL, 0); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 3908 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 3909 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3910 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 3911 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 3912 | hci_conn_drop(conn); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 3913 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3914 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 3915 | unlock: |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3916 | hci_dev_unlock(hdev); |
| 3917 | } |
| 3918 | |
Kiran K | ecb71f25 | 2021-08-16 05:07:47 +0530 | [diff] [blame] | 3919 | 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] | 3920 | { |
Kiran K | ecb71f25 | 2021-08-16 05:07:47 +0530 | [diff] [blame] | 3921 | cancel_delayed_work(&hdev->cmd_timer); |
Manish Mandlik | de75cd0 | 2021-04-29 10:24:22 -0700 | [diff] [blame] | 3922 | |
| 3923 | if (!test_bit(HCI_RESET, &hdev->flags)) { |
| 3924 | if (ncmd) { |
| 3925 | cancel_delayed_work(&hdev->ncmd_timer); |
| 3926 | atomic_set(&hdev->cmd_cnt, 1); |
| 3927 | } else { |
| 3928 | schedule_delayed_work(&hdev->ncmd_timer, |
| 3929 | HCI_NCMD_TIMEOUT); |
| 3930 | } |
| 3931 | } |
| 3932 | } |
| 3933 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3934 | static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, |
| 3935 | u16 *opcode, u8 *status, |
| 3936 | hci_req_complete_t *req_complete, |
| 3937 | hci_req_complete_skb_t *req_complete_skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3938 | { |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 3939 | struct hci_ev_cmd_complete *ev; |
| 3940 | |
| 3941 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_CMD_COMPLETE, sizeof(*ev)); |
| 3942 | if (!ev) |
| 3943 | return; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3944 | |
| 3945 | *opcode = __le16_to_cpu(ev->opcode); |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 3946 | *status = skb->data[0]; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3947 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 3948 | switch (*opcode) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3949 | case HCI_OP_INQUIRY_CANCEL: |
Sonny Sasaka | adf1d69 | 2020-05-06 12:55:03 -0700 | [diff] [blame] | 3950 | hci_cc_inquiry_cancel(hdev, skb, status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3951 | break; |
| 3952 | |
Andre Guedes | 4d93483 | 2012-03-21 00:03:35 -0300 | [diff] [blame] | 3953 | case HCI_OP_PERIODIC_INQ: |
| 3954 | hci_cc_periodic_inq(hdev, skb); |
| 3955 | break; |
| 3956 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3957 | case HCI_OP_EXIT_PERIODIC_INQ: |
| 3958 | hci_cc_exit_periodic_inq(hdev, skb); |
| 3959 | break; |
| 3960 | |
| 3961 | case HCI_OP_REMOTE_NAME_REQ_CANCEL: |
| 3962 | hci_cc_remote_name_req_cancel(hdev, skb); |
| 3963 | break; |
| 3964 | |
| 3965 | case HCI_OP_ROLE_DISCOVERY: |
| 3966 | hci_cc_role_discovery(hdev, skb); |
| 3967 | break; |
| 3968 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 3969 | case HCI_OP_READ_LINK_POLICY: |
| 3970 | hci_cc_read_link_policy(hdev, skb); |
| 3971 | break; |
| 3972 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3973 | case HCI_OP_WRITE_LINK_POLICY: |
| 3974 | hci_cc_write_link_policy(hdev, skb); |
| 3975 | break; |
| 3976 | |
Marcel Holtmann | e4e8e37 | 2008-07-14 20:13:47 +0200 | [diff] [blame] | 3977 | case HCI_OP_READ_DEF_LINK_POLICY: |
| 3978 | hci_cc_read_def_link_policy(hdev, skb); |
| 3979 | break; |
| 3980 | |
| 3981 | case HCI_OP_WRITE_DEF_LINK_POLICY: |
| 3982 | hci_cc_write_def_link_policy(hdev, skb); |
| 3983 | break; |
| 3984 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3985 | case HCI_OP_RESET: |
| 3986 | hci_cc_reset(hdev, skb); |
| 3987 | break; |
| 3988 | |
Marcel Holtmann | c2f0f97 | 2015-01-12 09:21:25 -0800 | [diff] [blame] | 3989 | case HCI_OP_READ_STORED_LINK_KEY: |
| 3990 | hci_cc_read_stored_link_key(hdev, skb); |
| 3991 | break; |
| 3992 | |
Marcel Holtmann | a9366120 | 2015-01-12 09:21:28 -0800 | [diff] [blame] | 3993 | case HCI_OP_DELETE_STORED_LINK_KEY: |
| 3994 | hci_cc_delete_stored_link_key(hdev, skb); |
| 3995 | break; |
| 3996 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 3997 | case HCI_OP_WRITE_LOCAL_NAME: |
| 3998 | hci_cc_write_local_name(hdev, skb); |
| 3999 | break; |
| 4000 | |
| 4001 | case HCI_OP_READ_LOCAL_NAME: |
| 4002 | hci_cc_read_local_name(hdev, skb); |
| 4003 | break; |
| 4004 | |
| 4005 | case HCI_OP_WRITE_AUTH_ENABLE: |
| 4006 | hci_cc_write_auth_enable(hdev, skb); |
| 4007 | break; |
| 4008 | |
| 4009 | case HCI_OP_WRITE_ENCRYPT_MODE: |
| 4010 | hci_cc_write_encrypt_mode(hdev, skb); |
| 4011 | break; |
| 4012 | |
| 4013 | case HCI_OP_WRITE_SCAN_ENABLE: |
| 4014 | hci_cc_write_scan_enable(hdev, skb); |
| 4015 | break; |
| 4016 | |
Abhishek Pandit-Subedi | e5b0ad6 | 2021-03-03 08:34:04 -0800 | [diff] [blame] | 4017 | case HCI_OP_SET_EVENT_FLT: |
| 4018 | hci_cc_set_event_filter(hdev, skb); |
| 4019 | break; |
| 4020 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4021 | case HCI_OP_READ_CLASS_OF_DEV: |
| 4022 | hci_cc_read_class_of_dev(hdev, skb); |
| 4023 | break; |
| 4024 | |
| 4025 | case HCI_OP_WRITE_CLASS_OF_DEV: |
| 4026 | hci_cc_write_class_of_dev(hdev, skb); |
| 4027 | break; |
| 4028 | |
| 4029 | case HCI_OP_READ_VOICE_SETTING: |
| 4030 | hci_cc_read_voice_setting(hdev, skb); |
| 4031 | break; |
| 4032 | |
| 4033 | case HCI_OP_WRITE_VOICE_SETTING: |
| 4034 | hci_cc_write_voice_setting(hdev, skb); |
| 4035 | break; |
| 4036 | |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 4037 | case HCI_OP_READ_NUM_SUPPORTED_IAC: |
| 4038 | hci_cc_read_num_supported_iac(hdev, skb); |
| 4039 | break; |
| 4040 | |
Marcel Holtmann | 333140b | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4041 | case HCI_OP_WRITE_SSP_MODE: |
| 4042 | hci_cc_write_ssp_mode(hdev, skb); |
| 4043 | break; |
| 4044 | |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 4045 | case HCI_OP_WRITE_SC_SUPPORT: |
| 4046 | hci_cc_write_sc_support(hdev, skb); |
| 4047 | break; |
| 4048 | |
Spoorthi Ravishankar Koppad | 302975c | 2019-06-21 14:51:56 +0530 | [diff] [blame] | 4049 | case HCI_OP_READ_AUTH_PAYLOAD_TO: |
| 4050 | hci_cc_read_auth_payload_timeout(hdev, skb); |
| 4051 | break; |
| 4052 | |
| 4053 | case HCI_OP_WRITE_AUTH_PAYLOAD_TO: |
| 4054 | hci_cc_write_auth_payload_timeout(hdev, skb); |
| 4055 | break; |
| 4056 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4057 | case HCI_OP_READ_LOCAL_VERSION: |
| 4058 | hci_cc_read_local_version(hdev, skb); |
| 4059 | break; |
| 4060 | |
| 4061 | case HCI_OP_READ_LOCAL_COMMANDS: |
| 4062 | hci_cc_read_local_commands(hdev, skb); |
| 4063 | break; |
| 4064 | |
| 4065 | case HCI_OP_READ_LOCAL_FEATURES: |
| 4066 | hci_cc_read_local_features(hdev, skb); |
| 4067 | break; |
| 4068 | |
Andre Guedes | 971e3a4 | 2011-06-30 19:20:52 -0300 | [diff] [blame] | 4069 | case HCI_OP_READ_LOCAL_EXT_FEATURES: |
| 4070 | hci_cc_read_local_ext_features(hdev, skb); |
| 4071 | break; |
| 4072 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4073 | case HCI_OP_READ_BUFFER_SIZE: |
| 4074 | hci_cc_read_buffer_size(hdev, skb); |
| 4075 | break; |
| 4076 | |
| 4077 | case HCI_OP_READ_BD_ADDR: |
| 4078 | hci_cc_read_bd_addr(hdev, skb); |
| 4079 | break; |
| 4080 | |
Marcel Holtmann | a479036 | 2020-04-03 21:44:04 +0200 | [diff] [blame] | 4081 | case HCI_OP_READ_LOCAL_PAIRING_OPTS: |
| 4082 | hci_cc_read_local_pairing_opts(hdev, skb); |
| 4083 | break; |
| 4084 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 4085 | case HCI_OP_READ_PAGE_SCAN_ACTIVITY: |
| 4086 | hci_cc_read_page_scan_activity(hdev, skb); |
| 4087 | break; |
| 4088 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 4089 | case HCI_OP_WRITE_PAGE_SCAN_ACTIVITY: |
| 4090 | hci_cc_write_page_scan_activity(hdev, skb); |
| 4091 | break; |
| 4092 | |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 4093 | case HCI_OP_READ_PAGE_SCAN_TYPE: |
| 4094 | hci_cc_read_page_scan_type(hdev, skb); |
| 4095 | break; |
| 4096 | |
Johan Hedberg | 4a3ee76 | 2013-03-15 17:07:12 -0500 | [diff] [blame] | 4097 | case HCI_OP_WRITE_PAGE_SCAN_TYPE: |
| 4098 | hci_cc_write_page_scan_type(hdev, skb); |
| 4099 | break; |
| 4100 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 4101 | case HCI_OP_READ_DATA_BLOCK_SIZE: |
| 4102 | hci_cc_read_data_block_size(hdev, skb); |
| 4103 | break; |
| 4104 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 4105 | case HCI_OP_READ_FLOW_CONTROL_MODE: |
| 4106 | hci_cc_read_flow_control_mode(hdev, skb); |
| 4107 | break; |
| 4108 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 4109 | case HCI_OP_READ_LOCAL_AMP_INFO: |
| 4110 | hci_cc_read_local_amp_info(hdev, skb); |
| 4111 | break; |
| 4112 | |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 4113 | case HCI_OP_READ_CLOCK: |
| 4114 | hci_cc_read_clock(hdev, skb); |
| 4115 | break; |
| 4116 | |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 4117 | case HCI_OP_READ_INQ_RSP_TX_POWER: |
| 4118 | hci_cc_read_inq_rsp_tx_power(hdev, skb); |
| 4119 | break; |
| 4120 | |
Alain Michaud | 00bce3f | 2020-03-05 16:14:59 +0000 | [diff] [blame] | 4121 | case HCI_OP_READ_DEF_ERR_DATA_REPORTING: |
| 4122 | hci_cc_read_def_err_data_reporting(hdev, skb); |
| 4123 | break; |
| 4124 | |
| 4125 | case HCI_OP_WRITE_DEF_ERR_DATA_REPORTING: |
| 4126 | hci_cc_write_def_err_data_reporting(hdev, skb); |
| 4127 | break; |
| 4128 | |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 4129 | case HCI_OP_PIN_CODE_REPLY: |
| 4130 | hci_cc_pin_code_reply(hdev, skb); |
| 4131 | break; |
| 4132 | |
| 4133 | case HCI_OP_PIN_CODE_NEG_REPLY: |
| 4134 | hci_cc_pin_code_neg_reply(hdev, skb); |
| 4135 | break; |
| 4136 | |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 4137 | case HCI_OP_READ_LOCAL_OOB_DATA: |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 4138 | hci_cc_read_local_oob_data(hdev, skb); |
| 4139 | break; |
| 4140 | |
| 4141 | case HCI_OP_READ_LOCAL_OOB_EXT_DATA: |
| 4142 | hci_cc_read_local_oob_ext_data(hdev, skb); |
Szymon Janc | c35938b | 2011-03-22 13:12:21 +0100 | [diff] [blame] | 4143 | break; |
| 4144 | |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 4145 | case HCI_OP_LE_READ_BUFFER_SIZE: |
| 4146 | hci_cc_le_read_buffer_size(hdev, skb); |
| 4147 | break; |
| 4148 | |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 4149 | case HCI_OP_LE_READ_LOCAL_FEATURES: |
| 4150 | hci_cc_le_read_local_features(hdev, skb); |
| 4151 | break; |
| 4152 | |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 4153 | case HCI_OP_LE_READ_ADV_TX_POWER: |
| 4154 | hci_cc_le_read_adv_tx_power(hdev, skb); |
| 4155 | break; |
| 4156 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 4157 | case HCI_OP_USER_CONFIRM_REPLY: |
| 4158 | hci_cc_user_confirm_reply(hdev, skb); |
| 4159 | break; |
| 4160 | |
| 4161 | case HCI_OP_USER_CONFIRM_NEG_REPLY: |
| 4162 | hci_cc_user_confirm_neg_reply(hdev, skb); |
| 4163 | break; |
| 4164 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 4165 | case HCI_OP_USER_PASSKEY_REPLY: |
| 4166 | hci_cc_user_passkey_reply(hdev, skb); |
| 4167 | break; |
| 4168 | |
| 4169 | case HCI_OP_USER_PASSKEY_NEG_REPLY: |
| 4170 | hci_cc_user_passkey_neg_reply(hdev, skb); |
Szymon Janc | 16cde99 | 2012-04-13 12:32:42 +0200 | [diff] [blame] | 4171 | break; |
Andre Guedes | 07f7fa5 | 2011-12-02 21:13:31 +0900 | [diff] [blame] | 4172 | |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 4173 | case HCI_OP_LE_SET_RANDOM_ADDR: |
| 4174 | hci_cc_le_set_random_addr(hdev, skb); |
| 4175 | break; |
| 4176 | |
Johan Hedberg | c1d5dc4 | 2012-11-08 01:23:01 +0100 | [diff] [blame] | 4177 | case HCI_OP_LE_SET_ADV_ENABLE: |
| 4178 | hci_cc_le_set_adv_enable(hdev, skb); |
| 4179 | break; |
| 4180 | |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 4181 | case HCI_OP_LE_SET_SCAN_PARAM: |
| 4182 | hci_cc_le_set_scan_param(hdev, skb); |
| 4183 | break; |
| 4184 | |
Andre Guedes | eb9d91f | 2011-05-26 16:23:52 -0300 | [diff] [blame] | 4185 | case HCI_OP_LE_SET_SCAN_ENABLE: |
| 4186 | hci_cc_le_set_scan_enable(hdev, skb); |
| 4187 | break; |
| 4188 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 4189 | case HCI_OP_LE_READ_ACCEPT_LIST_SIZE: |
| 4190 | hci_cc_le_read_accept_list_size(hdev, skb); |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 4191 | break; |
| 4192 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 4193 | case HCI_OP_LE_CLEAR_ACCEPT_LIST: |
| 4194 | hci_cc_le_clear_accept_list(hdev, skb); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 4195 | break; |
| 4196 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 4197 | case HCI_OP_LE_ADD_TO_ACCEPT_LIST: |
| 4198 | hci_cc_le_add_to_accept_list(hdev, skb); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 4199 | break; |
| 4200 | |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 4201 | case HCI_OP_LE_DEL_FROM_ACCEPT_LIST: |
| 4202 | hci_cc_le_del_from_accept_list(hdev, skb); |
Marcel Holtmann | 0f36b58 | 2014-02-27 20:37:31 -0800 | [diff] [blame] | 4203 | break; |
| 4204 | |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 4205 | case HCI_OP_LE_READ_SUPPORTED_STATES: |
| 4206 | hci_cc_le_read_supported_states(hdev, skb); |
| 4207 | break; |
| 4208 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 4209 | case HCI_OP_LE_READ_DEF_DATA_LEN: |
| 4210 | hci_cc_le_read_def_data_len(hdev, skb); |
| 4211 | break; |
| 4212 | |
| 4213 | case HCI_OP_LE_WRITE_DEF_DATA_LEN: |
| 4214 | hci_cc_le_write_def_data_len(hdev, skb); |
| 4215 | break; |
| 4216 | |
Ankit Navik | b950aa8 | 2018-08-17 07:29:19 +0530 | [diff] [blame] | 4217 | case HCI_OP_LE_ADD_TO_RESOLV_LIST: |
| 4218 | hci_cc_le_add_to_resolv_list(hdev, skb); |
| 4219 | break; |
| 4220 | |
| 4221 | case HCI_OP_LE_DEL_FROM_RESOLV_LIST: |
| 4222 | hci_cc_le_del_from_resolv_list(hdev, skb); |
| 4223 | break; |
| 4224 | |
Ankit Navik | 545f259 | 2018-06-29 12:13:20 +0530 | [diff] [blame] | 4225 | case HCI_OP_LE_CLEAR_RESOLV_LIST: |
| 4226 | hci_cc_le_clear_resolv_list(hdev, skb); |
| 4227 | break; |
| 4228 | |
Ankit Navik | cfdb0c2 | 2018-06-29 12:12:50 +0530 | [diff] [blame] | 4229 | case HCI_OP_LE_READ_RESOLV_LIST_SIZE: |
| 4230 | hci_cc_le_read_resolv_list_size(hdev, skb); |
| 4231 | break; |
| 4232 | |
Ankit Navik | aa12af7 | 2018-08-07 13:16:35 +0530 | [diff] [blame] | 4233 | case HCI_OP_LE_SET_ADDR_RESOLV_ENABLE: |
| 4234 | hci_cc_le_set_addr_resolution_enable(hdev, skb); |
| 4235 | break; |
| 4236 | |
Marcel Holtmann | a8e1bfa | 2014-12-20 16:28:40 +0100 | [diff] [blame] | 4237 | case HCI_OP_LE_READ_MAX_DATA_LEN: |
| 4238 | hci_cc_le_read_max_data_len(hdev, skb); |
| 4239 | break; |
| 4240 | |
Andre Guedes | f9b4930 | 2011-06-30 19:20:53 -0300 | [diff] [blame] | 4241 | case HCI_OP_WRITE_LE_HOST_SUPPORTED: |
| 4242 | hci_cc_write_le_host_supported(hdev, skb); |
| 4243 | break; |
| 4244 | |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 4245 | case HCI_OP_LE_SET_ADV_PARAM: |
| 4246 | hci_cc_set_adv_param(hdev, skb); |
| 4247 | break; |
| 4248 | |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 4249 | case HCI_OP_READ_RSSI: |
| 4250 | hci_cc_read_rssi(hdev, skb); |
| 4251 | break; |
| 4252 | |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 4253 | case HCI_OP_READ_TX_POWER: |
| 4254 | hci_cc_read_tx_power(hdev, skb); |
| 4255 | break; |
| 4256 | |
Marcel Holtmann | c50b33c | 2015-01-31 15:07:52 -0800 | [diff] [blame] | 4257 | case HCI_OP_WRITE_SSP_DEBUG_MODE: |
| 4258 | hci_cc_write_ssp_debug_mode(hdev, skb); |
| 4259 | break; |
| 4260 | |
Jaganath Kanakkassery | a2344b9 | 2018-07-06 17:05:28 +0530 | [diff] [blame] | 4261 | case HCI_OP_LE_SET_EXT_SCAN_PARAMS: |
| 4262 | hci_cc_le_set_ext_scan_param(hdev, skb); |
| 4263 | break; |
| 4264 | |
| 4265 | case HCI_OP_LE_SET_EXT_SCAN_ENABLE: |
| 4266 | hci_cc_le_set_ext_scan_enable(hdev, skb); |
| 4267 | break; |
| 4268 | |
Jaganath Kanakkassery | 0314f28 | 2018-07-19 17:09:35 +0530 | [diff] [blame] | 4269 | case HCI_OP_LE_SET_DEFAULT_PHY: |
| 4270 | hci_cc_le_set_default_phy(hdev, skb); |
| 4271 | break; |
| 4272 | |
Jaganath Kanakkassery | 6b49bcb | 2018-07-19 17:09:40 +0530 | [diff] [blame] | 4273 | case HCI_OP_LE_READ_NUM_SUPPORTED_ADV_SETS: |
| 4274 | hci_cc_le_read_num_adv_sets(hdev, skb); |
| 4275 | break; |
| 4276 | |
Jaganath Kanakkassery | de181e8 | 2018-07-19 17:09:41 +0530 | [diff] [blame] | 4277 | case HCI_OP_LE_SET_EXT_ADV_PARAMS: |
| 4278 | hci_cc_set_ext_adv_param(hdev, skb); |
| 4279 | break; |
| 4280 | |
| 4281 | case HCI_OP_LE_SET_EXT_ADV_ENABLE: |
| 4282 | hci_cc_le_set_ext_adv_enable(hdev, skb); |
| 4283 | break; |
| 4284 | |
Jaganath Kanakkassery | a73c046 | 2018-07-19 17:09:45 +0530 | [diff] [blame] | 4285 | case HCI_OP_LE_SET_ADV_SET_RAND_ADDR: |
| 4286 | hci_cc_le_set_adv_set_random_addr(hdev, skb); |
| 4287 | break; |
| 4288 | |
Luiz Augusto von Dentz | cba6b75 | 2021-10-27 16:58:40 -0700 | [diff] [blame] | 4289 | case HCI_OP_LE_REMOVE_ADV_SET: |
| 4290 | hci_cc_le_remove_adv_set(hdev, skb); |
| 4291 | break; |
| 4292 | |
| 4293 | case HCI_OP_LE_CLEAR_ADV_SETS: |
| 4294 | hci_cc_le_clear_adv_sets(hdev, skb); |
| 4295 | break; |
| 4296 | |
Daniel Winkler | 7c395ea | 2020-12-03 12:12:51 -0800 | [diff] [blame] | 4297 | case HCI_OP_LE_READ_TRANSMIT_POWER: |
| 4298 | hci_cc_le_read_transmit_power(hdev, skb); |
| 4299 | break; |
| 4300 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4301 | default: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 4302 | BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4303 | break; |
| 4304 | } |
| 4305 | |
Kiran K | ecb71f25 | 2021-08-16 05:07:47 +0530 | [diff] [blame] | 4306 | handle_cmd_cnt_and_timer(hdev, ev->ncmd); |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 4307 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 4308 | hci_req_cmd_complete(hdev, *opcode, *status, req_complete, |
| 4309 | req_complete_skb); |
Johan Hedberg | 9238f36 | 2013-03-05 20:37:48 +0200 | [diff] [blame] | 4310 | |
João Paulo Rechi Vita | f80c5da | 2019-05-02 10:01:52 +0800 | [diff] [blame] | 4311 | if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) { |
| 4312 | bt_dev_err(hdev, |
| 4313 | "unexpected event for opcode 0x%4.4x", *opcode); |
| 4314 | return; |
| 4315 | } |
| 4316 | |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 4317 | if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) |
| 4318 | queue_work(hdev->workqueue, &hdev->cmd_work); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4319 | } |
| 4320 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 4321 | static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb, |
| 4322 | u16 *opcode, u8 *status, |
| 4323 | hci_req_complete_t *req_complete, |
| 4324 | hci_req_complete_skb_t *req_complete_skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4325 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4326 | struct hci_ev_cmd_status *ev; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4327 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4328 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_CMD_STATUS, sizeof(*ev)); |
| 4329 | if (!ev) |
| 4330 | return; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4331 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 4332 | *opcode = __le16_to_cpu(ev->opcode); |
| 4333 | *status = ev->status; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4334 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 4335 | switch (*opcode) { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4336 | case HCI_OP_INQUIRY: |
| 4337 | hci_cs_inquiry(hdev, ev->status); |
| 4338 | break; |
| 4339 | |
| 4340 | case HCI_OP_CREATE_CONN: |
| 4341 | hci_cs_create_conn(hdev, ev->status); |
| 4342 | break; |
| 4343 | |
Kuba Pawlak | 9645c76 | 2014-11-06 19:36:53 +0100 | [diff] [blame] | 4344 | case HCI_OP_DISCONNECT: |
| 4345 | hci_cs_disconnect(hdev, ev->status); |
| 4346 | break; |
| 4347 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4348 | case HCI_OP_ADD_SCO: |
| 4349 | hci_cs_add_sco(hdev, ev->status); |
| 4350 | break; |
| 4351 | |
Marcel Holtmann | f855855 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 4352 | case HCI_OP_AUTH_REQUESTED: |
| 4353 | hci_cs_auth_requested(hdev, ev->status); |
| 4354 | break; |
| 4355 | |
| 4356 | case HCI_OP_SET_CONN_ENCRYPT: |
| 4357 | hci_cs_set_conn_encrypt(hdev, ev->status); |
| 4358 | break; |
| 4359 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4360 | case HCI_OP_REMOTE_NAME_REQ: |
| 4361 | hci_cs_remote_name_req(hdev, ev->status); |
| 4362 | break; |
| 4363 | |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 4364 | case HCI_OP_READ_REMOTE_FEATURES: |
| 4365 | hci_cs_read_remote_features(hdev, ev->status); |
| 4366 | break; |
| 4367 | |
| 4368 | case HCI_OP_READ_REMOTE_EXT_FEATURES: |
| 4369 | hci_cs_read_remote_ext_features(hdev, ev->status); |
| 4370 | break; |
| 4371 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4372 | case HCI_OP_SETUP_SYNC_CONN: |
| 4373 | hci_cs_setup_sync_conn(hdev, ev->status); |
| 4374 | break; |
| 4375 | |
Kiran K | b2af264 | 2021-09-07 15:42:43 +0530 | [diff] [blame] | 4376 | case HCI_OP_ENHANCED_SETUP_SYNC_CONN: |
| 4377 | hci_cs_enhanced_setup_sync_conn(hdev, ev->status); |
| 4378 | break; |
| 4379 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4380 | case HCI_OP_SNIFF_MODE: |
| 4381 | hci_cs_sniff_mode(hdev, ev->status); |
| 4382 | break; |
| 4383 | |
| 4384 | case HCI_OP_EXIT_SNIFF_MODE: |
| 4385 | hci_cs_exit_sniff_mode(hdev, ev->status); |
| 4386 | break; |
| 4387 | |
Kuba Pawlak | 50fc85f | 2014-11-06 19:36:52 +0100 | [diff] [blame] | 4388 | case HCI_OP_SWITCH_ROLE: |
| 4389 | hci_cs_switch_role(hdev, ev->status); |
| 4390 | break; |
| 4391 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 4392 | case HCI_OP_LE_CREATE_CONN: |
| 4393 | hci_cs_le_create_conn(hdev, ev->status); |
| 4394 | break; |
| 4395 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 4396 | case HCI_OP_LE_READ_REMOTE_FEATURES: |
| 4397 | hci_cs_le_read_remote_features(hdev, ev->status); |
| 4398 | break; |
| 4399 | |
Johan Hedberg | 81d0c8a | 2014-03-24 14:39:04 +0200 | [diff] [blame] | 4400 | case HCI_OP_LE_START_ENC: |
| 4401 | hci_cs_le_start_enc(hdev, ev->status); |
| 4402 | break; |
| 4403 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 4404 | case HCI_OP_LE_EXT_CREATE_CONN: |
| 4405 | hci_cs_le_ext_create_conn(hdev, ev->status); |
| 4406 | break; |
| 4407 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4408 | default: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 4409 | BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4410 | break; |
| 4411 | } |
| 4412 | |
Kiran K | ecb71f25 | 2021-08-16 05:07:47 +0530 | [diff] [blame] | 4413 | handle_cmd_cnt_and_timer(hdev, ev->ncmd); |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 4414 | |
Johan Hedberg | 444c6dd | 2015-04-02 13:41:07 +0300 | [diff] [blame] | 4415 | /* Indicate request completion if the command failed. Also, if |
| 4416 | * we're not waiting for a special event and we get a success |
| 4417 | * command status we should try to flag the request as completed |
| 4418 | * (since for this kind of commands there will not be a command |
| 4419 | * complete event). |
| 4420 | */ |
Johan Hedberg | 02350a7 | 2013-04-03 21:50:29 +0300 | [diff] [blame] | 4421 | if (ev->status || |
Marcel Holtmann | 242c0eb | 2015-10-25 22:45:53 +0100 | [diff] [blame] | 4422 | (hdev->sent_cmd && !bt_cb(hdev->sent_cmd)->hci.req_event)) |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 4423 | hci_req_cmd_complete(hdev, *opcode, ev->status, req_complete, |
| 4424 | req_complete_skb); |
Johan Hedberg | 9238f36 | 2013-03-05 20:37:48 +0200 | [diff] [blame] | 4425 | |
João Paulo Rechi Vita | f80c5da | 2019-05-02 10:01:52 +0800 | [diff] [blame] | 4426 | if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) { |
| 4427 | bt_dev_err(hdev, |
| 4428 | "unexpected event for opcode 0x%4.4x", *opcode); |
| 4429 | return; |
| 4430 | } |
| 4431 | |
Johan Hedberg | 600b215 | 2015-03-28 11:17:36 +0200 | [diff] [blame] | 4432 | if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q)) |
| 4433 | queue_work(hdev->workqueue, &hdev->cmd_work); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4434 | } |
| 4435 | |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 4436 | static void hci_hardware_error_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 4437 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4438 | struct hci_ev_hardware_error *ev; |
| 4439 | |
| 4440 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_HARDWARE_ERROR, sizeof(*ev)); |
| 4441 | if (!ev) |
| 4442 | return; |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 4443 | |
Marcel Holtmann | c7741d1 | 2015-01-28 11:09:55 -0800 | [diff] [blame] | 4444 | hdev->hw_error_code = ev->code; |
| 4445 | |
| 4446 | queue_work(hdev->req_workqueue, &hdev->error_reset); |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 4447 | } |
| 4448 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4449 | 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] | 4450 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4451 | struct hci_ev_role_change *ev; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4452 | struct hci_conn *conn; |
| 4453 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4454 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_ROLE_CHANGE, sizeof(*ev)); |
| 4455 | if (!ev) |
| 4456 | return; |
| 4457 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4458 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4459 | |
| 4460 | hci_dev_lock(hdev); |
| 4461 | |
| 4462 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 4463 | if (conn) { |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 4464 | if (!ev->status) |
| 4465 | conn->role = ev->role; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4466 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 4467 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4468 | |
| 4469 | hci_role_switch_cfm(conn, ev->status, ev->role); |
| 4470 | } |
| 4471 | |
| 4472 | hci_dev_unlock(hdev); |
| 4473 | } |
| 4474 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4475 | 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] | 4476 | { |
Luiz Augusto von Dentz | aadc3d2 | 2021-12-01 10:54:55 -0800 | [diff] [blame] | 4477 | struct hci_ev_num_comp_pkts *ev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4478 | int i; |
| 4479 | |
Luiz Augusto von Dentz | aadc3d2 | 2021-12-01 10:54:55 -0800 | [diff] [blame] | 4480 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_NUM_COMP_PKTS, sizeof(*ev)); |
| 4481 | if (!ev) |
| 4482 | return; |
| 4483 | |
| 4484 | if (!hci_ev_skb_pull(hdev, skb, HCI_EV_NUM_COMP_PKTS, |
| 4485 | flex_array_size(ev, handles, ev->num))) |
| 4486 | return; |
| 4487 | |
Andrei Emeltchenko | 32ac5b9 | 2011-12-19 16:31:29 +0200 | [diff] [blame] | 4488 | if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4489 | 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] | 4490 | return; |
| 4491 | } |
| 4492 | |
Luiz Augusto von Dentz | aadc3d2 | 2021-12-01 10:54:55 -0800 | [diff] [blame] | 4493 | BT_DBG("%s num %d", hdev->name, ev->num); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4494 | |
Luiz Augusto von Dentz | aadc3d2 | 2021-12-01 10:54:55 -0800 | [diff] [blame] | 4495 | for (i = 0; i < ev->num; i++) { |
Andrei Emeltchenko | 613a1c0 | 2011-12-19 16:31:30 +0200 | [diff] [blame] | 4496 | struct hci_comp_pkts_info *info = &ev->handles[i]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4497 | struct hci_conn *conn; |
| 4498 | __u16 handle, count; |
| 4499 | |
Andrei Emeltchenko | 613a1c0 | 2011-12-19 16:31:30 +0200 | [diff] [blame] | 4500 | handle = __le16_to_cpu(info->handle); |
| 4501 | count = __le16_to_cpu(info->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4502 | |
| 4503 | conn = hci_conn_hash_lookup_handle(hdev, handle); |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 4504 | if (!conn) |
| 4505 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4506 | |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 4507 | conn->sent -= count; |
| 4508 | |
| 4509 | switch (conn->type) { |
| 4510 | case ACL_LINK: |
| 4511 | hdev->acl_cnt += count; |
| 4512 | if (hdev->acl_cnt > hdev->acl_pkts) |
| 4513 | hdev->acl_cnt = hdev->acl_pkts; |
| 4514 | break; |
| 4515 | |
| 4516 | case LE_LINK: |
| 4517 | if (hdev->le_pkts) { |
| 4518 | hdev->le_cnt += count; |
| 4519 | if (hdev->le_cnt > hdev->le_pkts) |
| 4520 | hdev->le_cnt = hdev->le_pkts; |
| 4521 | } else { |
Andrei Emeltchenko | 70f23020 | 2010-12-01 16:58:25 +0200 | [diff] [blame] | 4522 | hdev->acl_cnt += count; |
| 4523 | if (hdev->acl_cnt > hdev->acl_pkts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | hdev->acl_cnt = hdev->acl_pkts; |
| 4525 | } |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 4526 | break; |
| 4527 | |
| 4528 | case SCO_LINK: |
| 4529 | hdev->sco_cnt += count; |
| 4530 | if (hdev->sco_cnt > hdev->sco_pkts) |
| 4531 | hdev->sco_cnt = hdev->sco_pkts; |
| 4532 | break; |
| 4533 | |
| 4534 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4535 | bt_dev_err(hdev, "unknown type %d conn %p", |
| 4536 | conn->type, conn); |
Andrei Emeltchenko | f428091 | 2011-12-07 15:56:52 +0200 | [diff] [blame] | 4537 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | } |
| 4539 | } |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4540 | |
Gustavo F. Padovan | 3eff45e | 2011-12-15 00:50:02 -0200 | [diff] [blame] | 4541 | queue_work(hdev->workqueue, &hdev->tx_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4542 | } |
| 4543 | |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 4544 | static struct hci_conn *__hci_conn_lookup_handle(struct hci_dev *hdev, |
| 4545 | __u16 handle) |
| 4546 | { |
| 4547 | struct hci_chan *chan; |
| 4548 | |
| 4549 | switch (hdev->dev_type) { |
Marcel Holtmann | ca8bee5 | 2016-07-05 14:30:14 +0200 | [diff] [blame] | 4550 | case HCI_PRIMARY: |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 4551 | return hci_conn_hash_lookup_handle(hdev, handle); |
| 4552 | case HCI_AMP: |
| 4553 | chan = hci_chan_lookup_handle(hdev, handle); |
| 4554 | if (chan) |
| 4555 | return chan->conn; |
| 4556 | break; |
| 4557 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4558 | bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type); |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 4559 | break; |
| 4560 | } |
| 4561 | |
| 4562 | return NULL; |
| 4563 | } |
| 4564 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4565 | 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] | 4566 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4567 | struct hci_ev_num_comp_blocks *ev; |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4568 | int i; |
| 4569 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4570 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_NUM_COMP_BLOCKS, sizeof(*ev)); |
| 4571 | if (!ev) |
| 4572 | return; |
| 4573 | |
| 4574 | if (!hci_ev_skb_pull(hdev, skb, HCI_EV_NUM_COMP_BLOCKS, |
| 4575 | flex_array_size(ev, handles, ev->num_hndl))) |
| 4576 | return; |
| 4577 | |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4578 | if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4579 | 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] | 4580 | return; |
| 4581 | } |
| 4582 | |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4583 | 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] | 4584 | ev->num_hndl); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4585 | |
| 4586 | for (i = 0; i < ev->num_hndl; i++) { |
| 4587 | struct hci_comp_blocks_info *info = &ev->handles[i]; |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 4588 | struct hci_conn *conn = NULL; |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4589 | __u16 handle, block_count; |
| 4590 | |
| 4591 | handle = __le16_to_cpu(info->handle); |
| 4592 | block_count = __le16_to_cpu(info->blocks); |
| 4593 | |
Andrei Emeltchenko | 76ef7cf | 2012-10-10 17:38:29 +0300 | [diff] [blame] | 4594 | conn = __hci_conn_lookup_handle(hdev, handle); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4595 | if (!conn) |
| 4596 | continue; |
| 4597 | |
| 4598 | conn->sent -= block_count; |
| 4599 | |
| 4600 | switch (conn->type) { |
| 4601 | case ACL_LINK: |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 4602 | case AMP_LINK: |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4603 | hdev->block_cnt += block_count; |
| 4604 | if (hdev->block_cnt > hdev->num_blocks) |
| 4605 | hdev->block_cnt = hdev->num_blocks; |
| 4606 | break; |
| 4607 | |
| 4608 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 4609 | bt_dev_err(hdev, "unknown type %d conn %p", |
| 4610 | conn->type, conn); |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 4611 | break; |
| 4612 | } |
| 4613 | } |
| 4614 | |
| 4615 | queue_work(hdev->workqueue, &hdev->tx_work); |
| 4616 | } |
| 4617 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4618 | 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] | 4619 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4620 | struct hci_ev_mode_change *ev; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4621 | struct hci_conn *conn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4622 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4623 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_MODE_CHANGE, sizeof(*ev)); |
| 4624 | if (!ev) |
| 4625 | return; |
| 4626 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4627 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4628 | |
| 4629 | hci_dev_lock(hdev); |
| 4630 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4631 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 4632 | if (conn) { |
| 4633 | conn->mode = ev->mode; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4634 | |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 4635 | if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, |
| 4636 | &conn->flags)) { |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4637 | if (conn->mode == HCI_CM_ACTIVE) |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 4638 | set_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4639 | else |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 4640 | clear_bit(HCI_CONN_POWER_SAVE, &conn->flags); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4641 | } |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 4642 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 4643 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags)) |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 4644 | hci_sco_setup(conn, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | hci_dev_unlock(hdev); |
| 4648 | } |
| 4649 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4650 | 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] | 4651 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4652 | struct hci_ev_pin_code_req *ev; |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4653 | struct hci_conn *conn; |
| 4654 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4655 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_PIN_CODE_REQ, sizeof(*ev)); |
| 4656 | if (!ev) |
| 4657 | return; |
| 4658 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4659 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4660 | |
| 4661 | hci_dev_lock(hdev); |
| 4662 | |
| 4663 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Waldemar Rymarkiewicz | b6f9804 | 2011-09-23 10:01:30 +0200 | [diff] [blame] | 4664 | if (!conn) |
| 4665 | goto unlock; |
| 4666 | |
| 4667 | if (conn->state == BT_CONNECTED) { |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4668 | hci_conn_hold(conn); |
| 4669 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 4670 | hci_conn_drop(conn); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4671 | } |
| 4672 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4673 | if (!hci_dev_test_flag(hdev, HCI_BONDABLE) && |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 4674 | !test_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags)) { |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 4675 | hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4676 | sizeof(ev->bdaddr), &ev->bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4677 | } else if (hci_dev_test_flag(hdev, HCI_MGMT)) { |
Waldemar Rymarkiewicz | a770bb5 | 2011-04-28 12:07:59 +0200 | [diff] [blame] | 4678 | u8 secure; |
| 4679 | |
| 4680 | if (conn->pending_sec_level == BT_SECURITY_HIGH) |
| 4681 | secure = 1; |
| 4682 | else |
| 4683 | secure = 0; |
| 4684 | |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 4685 | mgmt_pin_code_request(hdev, &ev->bdaddr, secure); |
Waldemar Rymarkiewicz | a770bb5 | 2011-04-28 12:07:59 +0200 | [diff] [blame] | 4686 | } |
Johan Hedberg | 980e1a5 | 2011-01-22 06:10:07 +0200 | [diff] [blame] | 4687 | |
Waldemar Rymarkiewicz | b6f9804 | 2011-09-23 10:01:30 +0200 | [diff] [blame] | 4688 | unlock: |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4689 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4690 | } |
| 4691 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4692 | static void conn_set_key(struct hci_conn *conn, u8 key_type, u8 pin_len) |
| 4693 | { |
| 4694 | if (key_type == HCI_LK_CHANGED_COMBINATION) |
| 4695 | return; |
| 4696 | |
| 4697 | conn->pin_length = pin_len; |
| 4698 | conn->key_type = key_type; |
| 4699 | |
| 4700 | switch (key_type) { |
| 4701 | case HCI_LK_LOCAL_UNIT: |
| 4702 | case HCI_LK_REMOTE_UNIT: |
| 4703 | case HCI_LK_DEBUG_COMBINATION: |
| 4704 | return; |
| 4705 | case HCI_LK_COMBINATION: |
| 4706 | if (pin_len == 16) |
| 4707 | conn->pending_sec_level = BT_SECURITY_HIGH; |
| 4708 | else |
| 4709 | conn->pending_sec_level = BT_SECURITY_MEDIUM; |
| 4710 | break; |
| 4711 | case HCI_LK_UNAUTH_COMBINATION_P192: |
| 4712 | case HCI_LK_UNAUTH_COMBINATION_P256: |
| 4713 | conn->pending_sec_level = BT_SECURITY_MEDIUM; |
| 4714 | break; |
| 4715 | case HCI_LK_AUTH_COMBINATION_P192: |
| 4716 | conn->pending_sec_level = BT_SECURITY_HIGH; |
| 4717 | break; |
| 4718 | case HCI_LK_AUTH_COMBINATION_P256: |
| 4719 | conn->pending_sec_level = BT_SECURITY_FIPS; |
| 4720 | break; |
| 4721 | } |
| 4722 | } |
| 4723 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4724 | 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] | 4725 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4726 | struct hci_ev_link_key_req *ev; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4727 | struct hci_cp_link_key_reply cp; |
| 4728 | struct hci_conn *conn; |
| 4729 | struct link_key *key; |
| 4730 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4731 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_LINK_KEY_REQ, sizeof(*ev)); |
| 4732 | if (!ev) |
| 4733 | return; |
| 4734 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4735 | BT_DBG("%s", hdev->name); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4736 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4737 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4738 | return; |
| 4739 | |
| 4740 | hci_dev_lock(hdev); |
| 4741 | |
| 4742 | key = hci_find_link_key(hdev, &ev->bdaddr); |
| 4743 | if (!key) { |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 4744 | BT_DBG("%s link key not found for %pMR", hdev->name, |
| 4745 | &ev->bdaddr); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4746 | goto not_found; |
| 4747 | } |
| 4748 | |
Andrei Emeltchenko | 6ed93dc | 2012-09-25 12:49:43 +0300 | [diff] [blame] | 4749 | BT_DBG("%s found key type %u for %pMR", hdev->name, key->type, |
| 4750 | &ev->bdaddr); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4751 | |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4752 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4753 | if (conn) { |
Johan Hedberg | fe8bc5a | 2014-08-14 12:33:17 +0300 | [diff] [blame] | 4754 | clear_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags); |
| 4755 | |
Marcel Holtmann | 66138ce | 2014-01-10 02:07:20 -0800 | [diff] [blame] | 4756 | if ((key->type == HCI_LK_UNAUTH_COMBINATION_P192 || |
| 4757 | key->type == HCI_LK_UNAUTH_COMBINATION_P256) && |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 4758 | conn->auth_type != 0xff && (conn->auth_type & 0x01)) { |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4759 | BT_DBG("%s ignoring unauthenticated key", hdev->name); |
| 4760 | goto not_found; |
| 4761 | } |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4762 | |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4763 | if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 && |
Johan Hedberg | f3fb0b5 | 2014-06-02 10:12:44 +0300 | [diff] [blame] | 4764 | (conn->pending_sec_level == BT_SECURITY_HIGH || |
| 4765 | conn->pending_sec_level == BT_SECURITY_FIPS)) { |
Gustavo Padovan | 8fc9ced | 2012-05-23 04:04:21 -0300 | [diff] [blame] | 4766 | BT_DBG("%s ignoring key unauthenticated for high security", |
| 4767 | hdev->name); |
Waldemar Rymarkiewicz | 60b83f5 | 2011-04-28 12:07:56 +0200 | [diff] [blame] | 4768 | goto not_found; |
| 4769 | } |
| 4770 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4771 | conn_set_key(conn, key->type, key->pin_len); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4772 | } |
| 4773 | |
| 4774 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9b3b446 | 2012-05-23 11:31:20 +0300 | [diff] [blame] | 4775 | memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4776 | |
| 4777 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp); |
| 4778 | |
| 4779 | hci_dev_unlock(hdev); |
| 4780 | |
| 4781 | return; |
| 4782 | |
| 4783 | not_found: |
| 4784 | hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr); |
| 4785 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4786 | } |
| 4787 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4788 | 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] | 4789 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4790 | struct hci_ev_link_key_notify *ev; |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4791 | struct hci_conn *conn; |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4792 | struct link_key *key; |
| 4793 | bool persistent; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4794 | u8 pin_len = 0; |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4795 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4796 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_LINK_KEY_NOTIFY, sizeof(*ev)); |
| 4797 | if (!ev) |
| 4798 | return; |
| 4799 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4800 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4801 | |
| 4802 | hci_dev_lock(hdev); |
| 4803 | |
| 4804 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4805 | if (!conn) |
| 4806 | goto unlock; |
| 4807 | |
| 4808 | hci_conn_hold(conn); |
| 4809 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
| 4810 | hci_conn_drop(conn); |
| 4811 | |
Johan Hedberg | fe8bc5a | 2014-08-14 12:33:17 +0300 | [diff] [blame] | 4812 | set_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4813 | conn_set_key(conn, ev->key_type, conn->pin_length); |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4814 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4815 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4816 | goto unlock; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 4817 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4818 | key = hci_add_link_key(hdev, conn, &ev->bdaddr, ev->link_key, |
| 4819 | ev->key_type, pin_len, &persistent); |
| 4820 | if (!key) |
| 4821 | goto unlock; |
| 4822 | |
Johan Hedberg | cb6f3f7 | 2014-11-19 14:53:04 +0200 | [diff] [blame] | 4823 | /* Update connection information since adding the key will have |
| 4824 | * fixed up the type in the case of changed combination keys. |
| 4825 | */ |
| 4826 | if (ev->key_type == HCI_LK_CHANGED_COMBINATION) |
| 4827 | conn_set_key(conn, key->type, key->pin_len); |
| 4828 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4829 | mgmt_new_link_key(hdev, key, persistent); |
| 4830 | |
Johan Hedberg | 6d5650c | 2014-06-24 13:15:51 +0300 | [diff] [blame] | 4831 | /* Keep debug keys around only if the HCI_KEEP_DEBUG_KEYS flag |
| 4832 | * is set. If it's not set simply remove the key from the kernel |
| 4833 | * list (we've still notified user space about it but with |
| 4834 | * store_hint being 0). |
| 4835 | */ |
| 4836 | if (key->type == HCI_LK_DEBUG_COMBINATION && |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4837 | !hci_dev_test_flag(hdev, HCI_KEEP_DEBUG_KEYS)) { |
Johan Hedberg | 0378b59 | 2014-11-19 15:22:22 +0200 | [diff] [blame] | 4838 | list_del_rcu(&key->list); |
| 4839 | kfree_rcu(key, rcu); |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4840 | goto unlock; |
Johan Hedberg | 6d5650c | 2014-06-24 13:15:51 +0300 | [diff] [blame] | 4841 | } |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4842 | |
Johan Hedberg | 82c13d4 | 2014-12-03 11:03:06 +0200 | [diff] [blame] | 4843 | if (persistent) |
| 4844 | clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags); |
| 4845 | else |
| 4846 | set_bit(HCI_CONN_FLUSH_KEY, &conn->flags); |
| 4847 | |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 4848 | unlock: |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 4849 | hci_dev_unlock(hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4850 | } |
| 4851 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4852 | 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] | 4853 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4854 | struct hci_ev_clock_offset *ev; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4855 | struct hci_conn *conn; |
| 4856 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4857 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_CLOCK_OFFSET, sizeof(*ev)); |
| 4858 | if (!ev) |
| 4859 | return; |
| 4860 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4861 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 4862 | |
| 4863 | hci_dev_lock(hdev); |
| 4864 | |
| 4865 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4866 | if (conn && !ev->status) { |
| 4867 | struct inquiry_entry *ie; |
| 4868 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4869 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 4870 | if (ie) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4871 | ie->data.clock_offset = ev->clock_offset; |
| 4872 | ie->timestamp = jiffies; |
| 4873 | } |
| 4874 | } |
| 4875 | |
| 4876 | hci_dev_unlock(hdev); |
| 4877 | } |
| 4878 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4879 | 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] | 4880 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4881 | struct hci_ev_pkt_type_change *ev; |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4882 | struct hci_conn *conn; |
| 4883 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4884 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_PKT_TYPE_CHANGE, sizeof(*ev)); |
| 4885 | if (!ev) |
| 4886 | return; |
| 4887 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 4888 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 4889 | |
| 4890 | hci_dev_lock(hdev); |
| 4891 | |
| 4892 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 4893 | if (conn && !ev->status) |
| 4894 | conn->pkt_type = __le16_to_cpu(ev->pkt_type); |
| 4895 | |
| 4896 | hci_dev_unlock(hdev); |
| 4897 | } |
| 4898 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4899 | 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] | 4900 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4901 | struct hci_ev_pscan_rep_mode *ev; |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 4902 | struct inquiry_entry *ie; |
| 4903 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 4904 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_PSCAN_REP_MODE, sizeof(*ev)); |
| 4905 | if (!ev) |
| 4906 | return; |
| 4907 | |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 4908 | BT_DBG("%s", hdev->name); |
| 4909 | |
| 4910 | hci_dev_lock(hdev); |
| 4911 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 4912 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 4913 | if (ie) { |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 4914 | ie->data.pscan_rep_mode = ev->pscan_rep_mode; |
| 4915 | ie->timestamp = jiffies; |
| 4916 | } |
| 4917 | |
| 4918 | hci_dev_unlock(hdev); |
| 4919 | } |
| 4920 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4921 | static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, |
| 4922 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4923 | { |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4924 | union { |
| 4925 | struct hci_ev_inquiry_result_rssi *res1; |
| 4926 | struct hci_ev_inquiry_result_rssi_pscan *res2; |
| 4927 | } *ev; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4928 | struct inquiry_data data; |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4929 | int i; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4930 | |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4931 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT_WITH_RSSI, |
| 4932 | sizeof(*ev)); |
| 4933 | if (!ev) |
| 4934 | return; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4935 | |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4936 | BT_DBG("%s num_rsp %d", hdev->name, ev->res1->num); |
| 4937 | |
| 4938 | if (!ev->res1->num) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4939 | return; |
| 4940 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 4941 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 4942 | return; |
| 4943 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4944 | hci_dev_lock(hdev); |
| 4945 | |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4946 | if (skb->len == flex_array_size(ev, res2->info, ev->res2->num)) { |
| 4947 | struct inquiry_info_rssi_pscan *info; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4948 | |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4949 | for (i = 0; i < ev->res2->num; i++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4950 | u32 flags; |
| 4951 | |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4952 | info = &ev->res2->info[i]; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4953 | bacpy(&data.bdaddr, &info->bdaddr); |
| 4954 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4955 | data.pscan_period_mode = info->pscan_period_mode; |
| 4956 | data.pscan_mode = info->pscan_mode; |
| 4957 | memcpy(data.dev_class, info->dev_class, 3); |
| 4958 | data.clock_offset = info->clock_offset; |
| 4959 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4960 | data.ssp_mode = 0x00; |
Johan Hedberg | 3175405 | 2012-01-04 13:39:52 +0200 | [diff] [blame] | 4961 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4962 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 4963 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 4964 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 4965 | info->dev_class, info->rssi, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4966 | flags, NULL, 0, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4967 | } |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4968 | } else if (skb->len == flex_array_size(ev, res1->info, ev->res1->num)) { |
| 4969 | struct inquiry_info_rssi *info; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4970 | |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4971 | for (i = 0; i < ev->res1->num; i++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4972 | u32 flags; |
| 4973 | |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4974 | info = &ev->res1->info[i]; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4975 | bacpy(&data.bdaddr, &info->bdaddr); |
| 4976 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 4977 | data.pscan_period_mode = info->pscan_period_mode; |
| 4978 | data.pscan_mode = 0x00; |
| 4979 | memcpy(data.dev_class, info->dev_class, 3); |
| 4980 | data.clock_offset = info->clock_offset; |
| 4981 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 4982 | data.ssp_mode = 0x00; |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4983 | |
| 4984 | flags = hci_inquiry_cache_update(hdev, &data, false); |
| 4985 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 4986 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 4987 | info->dev_class, info->rssi, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 4988 | flags, NULL, 0, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4989 | } |
Luiz Augusto von Dentz | 8d08d32 | 2021-12-01 10:54:57 -0800 | [diff] [blame^] | 4990 | } else { |
| 4991 | bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x", |
| 4992 | HCI_EV_INQUIRY_RESULT_WITH_RSSI); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | hci_dev_unlock(hdev); |
| 4996 | } |
| 4997 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 4998 | static void hci_remote_ext_features_evt(struct hci_dev *hdev, |
| 4999 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5000 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5001 | struct hci_ev_remote_ext_features *ev; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5002 | struct hci_conn *conn; |
| 5003 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5004 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_REMOTE_EXT_FEATURES, |
| 5005 | sizeof(*ev)); |
| 5006 | if (!ev) |
| 5007 | return; |
| 5008 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5009 | BT_DBG("%s", hdev->name); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5010 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5011 | hci_dev_lock(hdev); |
| 5012 | |
| 5013 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 5014 | if (!conn) |
| 5015 | goto unlock; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5016 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 5017 | if (ev->page < HCI_MAX_PAGES) |
| 5018 | memcpy(conn->features[ev->page], ev->features, 8); |
| 5019 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 5020 | if (!ev->status && ev->page == 0x01) { |
| 5021 | struct inquiry_entry *ie; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5022 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 5023 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
| 5024 | if (ie) |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 5025 | ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); |
Marcel Holtmann | 769be97 | 2008-07-14 20:13:49 +0200 | [diff] [blame] | 5026 | |
Jaganath Kanakkassery | bbb0ead | 2013-04-16 20:16:30 +0530 | [diff] [blame] | 5027 | if (ev->features[0] & LMP_HOST_SSP) { |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 5028 | set_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
Jaganath Kanakkassery | bbb0ead | 2013-04-16 20:16:30 +0530 | [diff] [blame] | 5029 | } else { |
| 5030 | /* It is mandatory by the Bluetooth specification that |
| 5031 | * Extended Inquiry Results are only used when Secure |
| 5032 | * Simple Pairing is enabled, but some devices violate |
| 5033 | * this. |
| 5034 | * |
| 5035 | * To make these devices work, the internal SSP |
| 5036 | * enabled flag needs to be cleared if the remote host |
| 5037 | * features do not indicate SSP support */ |
| 5038 | clear_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
| 5039 | } |
Marcel Holtmann | eb9a8f3 | 2014-01-15 22:37:38 -0800 | [diff] [blame] | 5040 | |
| 5041 | if (ev->features[0] & LMP_HOST_SC) |
| 5042 | set_bit(HCI_CONN_SC_ENABLED, &conn->flags); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5043 | } |
| 5044 | |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 5045 | if (conn->state != BT_CONFIG) |
| 5046 | goto unlock; |
| 5047 | |
Johan Hedberg | 671267b | 2012-05-12 16:11:50 -0300 | [diff] [blame] | 5048 | if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) { |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 5049 | struct hci_cp_remote_name_req cp; |
| 5050 | memset(&cp, 0, sizeof(cp)); |
| 5051 | bacpy(&cp.bdaddr, &conn->dst); |
| 5052 | cp.pscan_rep_mode = 0x02; |
| 5053 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 5054 | } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 5055 | mgmt_device_connected(hdev, conn, NULL, 0); |
Johan Hedberg | 392599b | 2010-11-18 22:22:28 +0200 | [diff] [blame] | 5056 | |
Johan Hedberg | 127178d | 2010-11-18 22:22:29 +0200 | [diff] [blame] | 5057 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 5058 | conn->state = BT_CONNECTED; |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 5059 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 5060 | hci_conn_drop(conn); |
Johan Hedberg | ccd556f | 2010-11-10 17:11:51 +0200 | [diff] [blame] | 5061 | } |
| 5062 | |
| 5063 | unlock: |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5064 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5065 | } |
| 5066 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5067 | static void hci_sync_conn_complete_evt(struct hci_dev *hdev, |
| 5068 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5069 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5070 | struct hci_ev_sync_conn_complete *ev; |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 5071 | struct hci_conn *conn; |
| 5072 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5073 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_SYNC_CONN_COMPLETE, sizeof(*ev)); |
| 5074 | if (!ev) |
| 5075 | return; |
| 5076 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 5077 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 5078 | |
| 5079 | hci_dev_lock(hdev); |
| 5080 | |
| 5081 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 5082 | if (!conn) { |
| 5083 | if (ev->link_type == ESCO_LINK) |
| 5084 | goto unlock; |
| 5085 | |
Kuba Pawlak | 618353b | 2015-08-28 13:05:22 +0100 | [diff] [blame] | 5086 | /* When the link type in the event indicates SCO connection |
| 5087 | * and lookup of the connection object fails, then check |
| 5088 | * if an eSCO connection object exists. |
| 5089 | * |
| 5090 | * The core limits the synchronous connections to either |
| 5091 | * SCO or eSCO. The eSCO connection is preferred and tried |
| 5092 | * to be setup first and until successfully established, |
| 5093 | * the link type will be hinted as eSCO. |
| 5094 | */ |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 5095 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); |
| 5096 | if (!conn) |
| 5097 | goto unlock; |
Marcel Holtmann | 9dc0a3a | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 5098 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 5099 | |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 5100 | switch (ev->status) { |
| 5101 | case 0x00: |
Desmond Cheong Zhi Xi | 92fe24a | 2021-07-28 15:51:04 +0800 | [diff] [blame] | 5102 | /* The synchronous connection complete event should only be |
| 5103 | * sent once per new connection. Receiving a successful |
| 5104 | * complete event when the connection status is already |
| 5105 | * BT_CONNECTED means that the device is misbehaving and sent |
| 5106 | * multiple complete event packets for the same new connection. |
| 5107 | * |
| 5108 | * Registering the device more than once can corrupt kernel |
| 5109 | * memory, hence upon detecting this invalid event, we report |
| 5110 | * an error and ignore the packet. |
| 5111 | */ |
| 5112 | if (conn->state == BT_CONNECTED) { |
| 5113 | bt_dev_err(hdev, "Ignoring connect complete event for existing connection"); |
| 5114 | goto unlock; |
| 5115 | } |
| 5116 | |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 5117 | conn->handle = __le16_to_cpu(ev->handle); |
| 5118 | conn->state = BT_CONNECTED; |
Kuba Pawlak | 618353b | 2015-08-28 13:05:22 +0100 | [diff] [blame] | 5119 | conn->type = ev->link_type; |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 5120 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 5121 | hci_debugfs_create_conn(conn); |
Marcel Holtmann | 7d0db0a | 2008-07-14 20:13:51 +0200 | [diff] [blame] | 5122 | hci_conn_add_sysfs(conn); |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 5123 | break; |
| 5124 | |
Nick Pelly | 81218d2 | 2014-06-30 11:25:01 +0530 | [diff] [blame] | 5125 | case 0x10: /* Connection Accept Timeout */ |
Frédéric Dalleau | 1a4c958 | 2013-08-19 14:24:02 +0200 | [diff] [blame] | 5126 | case 0x0d: /* Connection Rejected due to Limited Resources */ |
Stephen Coe | 705e571 | 2010-02-16 11:29:44 -0500 | [diff] [blame] | 5127 | case 0x11: /* Unsupported Feature or Parameter Value */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 5128 | case 0x1c: /* SCO interval rejected */ |
Nick Pelly | 1038a00 | 2010-02-03 11:42:26 -0800 | [diff] [blame] | 5129 | case 0x1a: /* Unsupported Remote Feature */ |
Hsin-Yu Chao | 56b5453 | 2020-05-15 17:27:04 +0800 | [diff] [blame] | 5130 | case 0x1e: /* Invalid LMP Parameters */ |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 5131 | case 0x1f: /* Unspecified error */ |
Andrew Earl | 27539bc | 2014-03-10 10:31:04 +0000 | [diff] [blame] | 5132 | case 0x20: /* Unsupported LMP Parameter value */ |
Frédéric Dalleau | 2dea632 | 2013-08-19 14:24:03 +0200 | [diff] [blame] | 5133 | if (conn->out) { |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 5134 | conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | |
| 5135 | (hdev->esco_type & EDR_ESCO_MASK); |
Frédéric Dalleau | 2dea632 | 2013-08-19 14:24:03 +0200 | [diff] [blame] | 5136 | if (hci_setup_sync(conn, conn->link->handle)) |
| 5137 | goto unlock; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 5138 | } |
Gustavo A. R. Silva | 19186c7 | 2020-07-08 15:18:23 -0500 | [diff] [blame] | 5139 | fallthrough; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 5140 | |
| 5141 | default: |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 5142 | conn->state = BT_CLOSED; |
Marcel Holtmann | 732547f | 2009-04-19 19:14:14 +0200 | [diff] [blame] | 5143 | break; |
| 5144 | } |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 5145 | |
Sathish Narsimman | 1f8330e | 2020-04-03 21:43:58 +0200 | [diff] [blame] | 5146 | bt_dev_dbg(hdev, "SCO connected with air mode: %02x", ev->air_mode); |
Chethan T N | f4f9fa0 | 2021-09-07 15:42:48 +0530 | [diff] [blame] | 5147 | /* Notify only in case of SCO over HCI transport data path which |
| 5148 | * is zero and non-zero value shall be non-HCI transport data path |
| 5149 | */ |
Jackie Liu | a27c519 | 2021-11-16 09:17:17 +0800 | [diff] [blame] | 5150 | if (conn->codec.data_path == 0 && hdev->notify) { |
| 5151 | switch (ev->air_mode) { |
| 5152 | case 0x02: |
| 5153 | hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD); |
| 5154 | break; |
| 5155 | case 0x03: |
| 5156 | hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_TRANSP); |
| 5157 | break; |
| 5158 | } |
Chethan T N | f4f9fa0 | 2021-09-07 15:42:48 +0530 | [diff] [blame] | 5159 | } |
| 5160 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 5161 | hci_connect_cfm(conn, ev->status); |
Marcel Holtmann | b6a0dc8 | 2007-10-20 14:55:10 +0200 | [diff] [blame] | 5162 | if (ev->status) |
| 5163 | hci_conn_del(conn); |
| 5164 | |
| 5165 | unlock: |
| 5166 | hci_dev_unlock(hdev); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5167 | } |
| 5168 | |
Marcel Holtmann | efdcf8e | 2013-10-15 10:31:12 -0700 | [diff] [blame] | 5169 | static inline size_t eir_get_length(u8 *eir, size_t eir_len) |
| 5170 | { |
| 5171 | size_t parsed = 0; |
| 5172 | |
| 5173 | while (parsed < eir_len) { |
| 5174 | u8 field_len = eir[0]; |
| 5175 | |
| 5176 | if (field_len == 0) |
| 5177 | return parsed; |
| 5178 | |
| 5179 | parsed += field_len + 1; |
| 5180 | eir += field_len + 1; |
| 5181 | } |
| 5182 | |
| 5183 | return eir_len; |
| 5184 | } |
| 5185 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5186 | static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, |
| 5187 | struct sk_buff *skb) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5188 | { |
| 5189 | struct inquiry_data data; |
| 5190 | struct extended_inquiry_info *info = (void *) (skb->data + 1); |
| 5191 | int num_rsp = *((__u8 *) skb->data); |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 5192 | size_t eir_len; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5193 | |
| 5194 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
| 5195 | |
Peilin Ye | 51c19bf | 2020-07-10 12:09:15 -0400 | [diff] [blame] | 5196 | if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1) |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5197 | return; |
| 5198 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5199 | if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ)) |
Andre Guedes | 1519cc1 | 2012-03-21 00:03:38 -0300 | [diff] [blame] | 5200 | return; |
| 5201 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5202 | hci_dev_lock(hdev); |
| 5203 | |
Johan Hedberg | e17acd4 | 2011-03-30 23:57:16 +0300 | [diff] [blame] | 5204 | for (; num_rsp; num_rsp--, info++) { |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 5205 | u32 flags; |
| 5206 | bool name_known; |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 5207 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5208 | bacpy(&data.bdaddr, &info->bdaddr); |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 5209 | data.pscan_rep_mode = info->pscan_rep_mode; |
| 5210 | data.pscan_period_mode = info->pscan_period_mode; |
| 5211 | data.pscan_mode = 0x00; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5212 | memcpy(data.dev_class, info->dev_class, 3); |
Szymon Janc | 138d22e | 2011-02-17 16:44:23 +0100 | [diff] [blame] | 5213 | data.clock_offset = info->clock_offset; |
| 5214 | data.rssi = info->rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5215 | data.ssp_mode = 0x01; |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 5216 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5217 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 0d3b7f6 | 2016-01-05 13:19:31 +0200 | [diff] [blame] | 5218 | name_known = eir_get_data(info->data, |
| 5219 | sizeof(info->data), |
| 5220 | EIR_NAME_COMPLETE, NULL); |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 5221 | else |
| 5222 | name_known = true; |
| 5223 | |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 5224 | flags = hci_inquiry_cache_update(hdev, &data, name_known); |
| 5225 | |
Vishal Agarwal | 9d939d9 | 2012-04-26 19:19:56 +0530 | [diff] [blame] | 5226 | eir_len = eir_get_length(info->data, sizeof(info->data)); |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 5227 | |
Johan Hedberg | 48264f0 | 2011-11-09 13:58:58 +0200 | [diff] [blame] | 5228 | mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 5229 | info->dev_class, info->rssi, |
| 5230 | flags, info->data, eir_len, NULL, 0); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | hci_dev_unlock(hdev); |
| 5234 | } |
| 5235 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 5236 | static void hci_key_refresh_complete_evt(struct hci_dev *hdev, |
| 5237 | struct sk_buff *skb) |
| 5238 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5239 | struct hci_ev_key_refresh_complete *ev; |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 5240 | struct hci_conn *conn; |
| 5241 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5242 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_KEY_REFRESH_COMPLETE, |
| 5243 | sizeof(*ev)); |
| 5244 | if (!ev) |
| 5245 | return; |
| 5246 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 5247 | 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] | 5248 | __le16_to_cpu(ev->handle)); |
| 5249 | |
| 5250 | hci_dev_lock(hdev); |
| 5251 | |
| 5252 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 5253 | if (!conn) |
| 5254 | goto unlock; |
| 5255 | |
Johan Hedberg | 9eb1fbf | 2014-04-11 12:02:31 -0700 | [diff] [blame] | 5256 | /* For BR/EDR the necessary steps are taken through the |
| 5257 | * auth_complete event. |
| 5258 | */ |
| 5259 | if (conn->type != LE_LINK) |
| 5260 | goto unlock; |
| 5261 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 5262 | if (!ev->status) |
| 5263 | conn->sec_level = conn->pending_sec_level; |
| 5264 | |
| 5265 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags); |
| 5266 | |
| 5267 | if (ev->status && conn->state == BT_CONNECTED) { |
Andre Guedes | bed7174 | 2013-01-30 11:50:56 -0300 | [diff] [blame] | 5268 | hci_disconnect(conn, HCI_ERROR_AUTH_FAILURE); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 5269 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 5270 | goto unlock; |
| 5271 | } |
| 5272 | |
| 5273 | if (conn->state == BT_CONFIG) { |
| 5274 | if (!ev->status) |
| 5275 | conn->state = BT_CONNECTED; |
| 5276 | |
Johan Hedberg | 539c496 | 2015-02-18 14:53:57 +0200 | [diff] [blame] | 5277 | hci_connect_cfm(conn, ev->status); |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 5278 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 5279 | } else { |
| 5280 | hci_auth_cfm(conn, ev->status); |
| 5281 | |
| 5282 | hci_conn_hold(conn); |
| 5283 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 5284 | hci_conn_drop(conn); |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 5285 | } |
| 5286 | |
| 5287 | unlock: |
| 5288 | hci_dev_unlock(hdev); |
| 5289 | } |
| 5290 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5291 | static u8 hci_get_auth_req(struct hci_conn *conn) |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 5292 | { |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 5293 | /* If remote requests no-bonding follow that lead */ |
Mikel Astiz | acabae9 | 2013-06-28 10:56:28 +0200 | [diff] [blame] | 5294 | if (conn->remote_auth == HCI_AT_NO_BONDING || |
| 5295 | conn->remote_auth == HCI_AT_NO_BONDING_MITM) |
Waldemar Rymarkiewicz | 58797bf | 2011-04-28 12:07:58 +0200 | [diff] [blame] | 5296 | return conn->remote_auth | (conn->auth_type & 0x01); |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 5297 | |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 5298 | /* If both remote and local have enough IO capabilities, require |
| 5299 | * MITM protection |
| 5300 | */ |
| 5301 | if (conn->remote_cap != HCI_IO_NO_INPUT_OUTPUT && |
| 5302 | conn->io_capability != HCI_IO_NO_INPUT_OUTPUT) |
| 5303 | return conn->remote_auth | 0x01; |
| 5304 | |
Timo Mueller | 7e74170 | 2014-04-08 14:21:33 +0200 | [diff] [blame] | 5305 | /* No MITM protection possible so ignore remote requirement */ |
| 5306 | return (conn->remote_auth & ~0x01) | (conn->auth_type & 0x01); |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 5307 | } |
| 5308 | |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 5309 | static u8 bredr_oob_data_present(struct hci_conn *conn) |
| 5310 | { |
| 5311 | struct hci_dev *hdev = conn->hdev; |
| 5312 | struct oob_data *data; |
| 5313 | |
| 5314 | data = hci_find_remote_oob_data(hdev, &conn->dst, BDADDR_BREDR); |
| 5315 | if (!data) |
| 5316 | return 0x00; |
| 5317 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 5318 | if (bredr_sc_enabled(hdev)) { |
| 5319 | /* When Secure Connections is enabled, then just |
| 5320 | * return the present value stored with the OOB |
| 5321 | * data. The stored value contains the right present |
| 5322 | * information. However it can only be trusted when |
| 5323 | * not in Secure Connection Only mode. |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 5324 | */ |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 5325 | if (!hci_dev_test_flag(hdev, HCI_SC_ONLY)) |
| 5326 | return data->present; |
| 5327 | |
| 5328 | /* When Secure Connections Only mode is enabled, then |
| 5329 | * the P-256 values are required. If they are not |
| 5330 | * available, then do not declare that OOB data is |
| 5331 | * present. |
| 5332 | */ |
| 5333 | if (!memcmp(data->rand256, ZERO_KEY, 16) || |
| 5334 | !memcmp(data->hash256, ZERO_KEY, 16)) |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 5335 | return 0x00; |
| 5336 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 5337 | return 0x02; |
Marcel Holtmann | 659c7fb | 2015-01-30 23:20:56 -0800 | [diff] [blame] | 5338 | } |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 5339 | |
Marcel Holtmann | 455c2ff | 2015-03-15 16:42:53 -0700 | [diff] [blame] | 5340 | /* When Secure Connections is not enabled or actually |
| 5341 | * not supported by the hardware, then check that if |
| 5342 | * P-192 data values are present. |
| 5343 | */ |
| 5344 | if (!memcmp(data->rand192, ZERO_KEY, 16) || |
| 5345 | !memcmp(data->hash192, ZERO_KEY, 16)) |
| 5346 | return 0x00; |
| 5347 | |
| 5348 | return 0x01; |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 5349 | } |
| 5350 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5351 | 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] | 5352 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5353 | struct hci_ev_io_capa_request *ev; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5354 | struct hci_conn *conn; |
| 5355 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5356 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_IO_CAPA_REQUEST, sizeof(*ev)); |
| 5357 | if (!ev) |
| 5358 | return; |
| 5359 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5360 | BT_DBG("%s", hdev->name); |
| 5361 | |
| 5362 | hci_dev_lock(hdev); |
| 5363 | |
| 5364 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5365 | if (!conn) |
| 5366 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5367 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5368 | hci_conn_hold(conn); |
| 5369 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5370 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5371 | goto unlock; |
| 5372 | |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 5373 | /* Allow pairing if we're pairable, the initiators of the |
| 5374 | * pairing or if the remote is not requesting bonding. |
| 5375 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5376 | if (hci_dev_test_flag(hdev, HCI_BONDABLE) || |
Johan Hedberg | 2f407f0 | 2014-07-17 15:35:40 +0300 | [diff] [blame] | 5377 | test_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags) || |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 5378 | (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) { |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 5379 | struct hci_cp_io_capability_reply cp; |
| 5380 | |
| 5381 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Hemant Gupta | 7a7f1e7 | 2012-01-16 13:34:29 +0530 | [diff] [blame] | 5382 | /* Change the IO capability from KeyboardDisplay |
| 5383 | * to DisplayYesNo as it is not supported by BT spec. */ |
| 5384 | cp.capability = (conn->io_capability == 0x04) ? |
Mikel Astiz | a767631 | 2013-06-28 10:56:29 +0200 | [diff] [blame] | 5385 | HCI_IO_DISPLAY_YESNO : conn->io_capability; |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 5386 | |
| 5387 | /* If we are initiators, there is no remote information yet */ |
| 5388 | if (conn->remote_auth == 0xff) { |
Mikel Astiz | b16c660 | 2014-04-08 14:21:34 +0200 | [diff] [blame] | 5389 | /* Request MITM protection if our IO caps allow it |
Johan Hedberg | 4ad51a7 | 2014-06-09 14:41:25 +0300 | [diff] [blame] | 5390 | * except for the no-bonding case. |
Mikel Astiz | b16c660 | 2014-04-08 14:21:34 +0200 | [diff] [blame] | 5391 | */ |
Mikel Astiz | 6fd6b91 | 2014-04-08 14:21:32 +0200 | [diff] [blame] | 5392 | if (conn->io_capability != HCI_IO_NO_INPUT_OUTPUT && |
Johan Hedberg | 9f743d7 | 2014-07-17 11:56:33 +0300 | [diff] [blame] | 5393 | conn->auth_type != HCI_AT_NO_BONDING) |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 5394 | conn->auth_type |= 0x01; |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 5395 | } else { |
| 5396 | conn->auth_type = hci_get_auth_req(conn); |
Mikel Astiz | b7f94c8 | 2014-04-08 14:21:31 +0200 | [diff] [blame] | 5397 | } |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 5398 | |
Johan Hedberg | 82c295b | 2014-07-30 09:22:24 +0300 | [diff] [blame] | 5399 | /* If we're not bondable, force one of the non-bondable |
| 5400 | * authentication requirement values. |
| 5401 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5402 | if (!hci_dev_test_flag(hdev, HCI_BONDABLE)) |
Johan Hedberg | 82c295b | 2014-07-30 09:22:24 +0300 | [diff] [blame] | 5403 | conn->auth_type &= HCI_AT_NO_BONDING_MITM; |
| 5404 | |
| 5405 | cp.authentication = conn->auth_type; |
Marcel Holtmann | a83ed81e | 2015-01-27 16:04:32 -0800 | [diff] [blame] | 5406 | cp.oob_data = bredr_oob_data_present(conn); |
Szymon Janc | ce85ee1 | 2011-03-22 13:12:23 +0100 | [diff] [blame] | 5407 | |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 5408 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 5409 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5410 | } else { |
| 5411 | struct hci_cp_io_capability_neg_reply cp; |
| 5412 | |
| 5413 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Andrei Emeltchenko | 9f5a0d7 | 2011-11-07 14:20:25 +0200 | [diff] [blame] | 5414 | cp.reason = HCI_ERROR_PAIRING_NOT_ALLOWED; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5415 | |
| 5416 | hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 5417 | sizeof(cp), &cp); |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5418 | } |
| 5419 | |
| 5420 | unlock: |
| 5421 | hci_dev_unlock(hdev); |
| 5422 | } |
| 5423 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5424 | 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] | 5425 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5426 | struct hci_ev_io_capa_reply *ev; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5427 | struct hci_conn *conn; |
| 5428 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5429 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_IO_CAPA_REPLY, sizeof(*ev)); |
| 5430 | if (!ev) |
| 5431 | return; |
| 5432 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5433 | BT_DBG("%s", hdev->name); |
| 5434 | |
| 5435 | hci_dev_lock(hdev); |
| 5436 | |
| 5437 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 5438 | if (!conn) |
| 5439 | goto unlock; |
| 5440 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5441 | conn->remote_cap = ev->capability; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 5442 | conn->remote_auth = ev->authentication; |
| 5443 | |
| 5444 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5445 | hci_dev_unlock(hdev); |
| 5446 | } |
| 5447 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5448 | static void hci_user_confirm_request_evt(struct hci_dev *hdev, |
| 5449 | struct sk_buff *skb) |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 5450 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5451 | struct hci_ev_user_confirm_req *ev; |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 5452 | int loc_mitm, rem_mitm, confirm_hint = 0; |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 5453 | struct hci_conn *conn; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 5454 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5455 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_USER_CONFIRM_REQUEST, |
| 5456 | sizeof(*ev)); |
| 5457 | if (!ev) |
| 5458 | return; |
| 5459 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 5460 | BT_DBG("%s", hdev->name); |
| 5461 | |
| 5462 | hci_dev_lock(hdev); |
| 5463 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5464 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 5465 | goto unlock; |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 5466 | |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 5467 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 5468 | if (!conn) |
| 5469 | goto unlock; |
| 5470 | |
| 5471 | loc_mitm = (conn->auth_type & 0x01); |
| 5472 | rem_mitm = (conn->remote_auth & 0x01); |
| 5473 | |
| 5474 | /* If we require MITM but the remote device can't provide that |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 5475 | * (it has NoInputNoOutput) then reject the confirmation |
| 5476 | * request. We check the security level here since it doesn't |
| 5477 | * necessarily match conn->auth_type. |
Mikel Astiz | 6fd6b91 | 2014-04-08 14:21:32 +0200 | [diff] [blame] | 5478 | */ |
Johan Hedberg | 6c53823 | 2014-07-11 15:32:23 +0300 | [diff] [blame] | 5479 | if (conn->pending_sec_level > BT_SECURITY_MEDIUM && |
| 5480 | conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) { |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 5481 | BT_DBG("Rejecting request: remote device can't provide MITM"); |
| 5482 | hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 5483 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 5484 | goto unlock; |
| 5485 | } |
| 5486 | |
| 5487 | /* If no side requires MITM protection; auto-accept */ |
Mikel Astiz | a767631 | 2013-06-28 10:56:29 +0200 | [diff] [blame] | 5488 | if ((!loc_mitm || conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) && |
| 5489 | (!rem_mitm || conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)) { |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 5490 | |
| 5491 | /* If we're not the initiators request authorization to |
| 5492 | * proceed from user space (mgmt_user_confirm with |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 5493 | * confirm_hint set to 1). The exception is if neither |
Johan Hedberg | 02f3e25 | 2014-07-16 15:09:13 +0300 | [diff] [blame] | 5494 | * side had MITM or if the local IO capability is |
| 5495 | * NoInputNoOutput, in which case we do auto-accept |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 5496 | */ |
| 5497 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && |
Johan Hedberg | 02f3e25 | 2014-07-16 15:09:13 +0300 | [diff] [blame] | 5498 | conn->io_capability != HCI_IO_NO_INPUT_OUTPUT && |
Johan Hedberg | ba15a58 | 2014-06-09 13:58:14 +0300 | [diff] [blame] | 5499 | (loc_mitm || rem_mitm)) { |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 5500 | BT_DBG("Confirming auto-accept as acceptor"); |
| 5501 | confirm_hint = 1; |
| 5502 | goto confirm; |
| 5503 | } |
| 5504 | |
Howard Chung | cee5f20 | 2020-02-14 19:16:41 +0800 | [diff] [blame] | 5505 | /* If there already exists link key in local host, leave the |
| 5506 | * decision to user space since the remote device could be |
| 5507 | * legitimate or malicious. |
| 5508 | */ |
| 5509 | if (hci_find_link_key(hdev, &ev->bdaddr)) { |
| 5510 | bt_dev_dbg(hdev, "Local host already has link key"); |
| 5511 | confirm_hint = 1; |
| 5512 | goto confirm; |
| 5513 | } |
| 5514 | |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 5515 | BT_DBG("Auto-accept of user confirmation with %ums delay", |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 5516 | hdev->auto_accept_delay); |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 5517 | |
| 5518 | if (hdev->auto_accept_delay > 0) { |
| 5519 | int delay = msecs_to_jiffies(hdev->auto_accept_delay); |
Johan Hedberg | 7bc18d9 | 2013-10-16 18:11:39 +0300 | [diff] [blame] | 5520 | queue_delayed_work(conn->hdev->workqueue, |
| 5521 | &conn->auto_accept_work, delay); |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 5522 | goto unlock; |
| 5523 | } |
| 5524 | |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 5525 | hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY, |
Gustavo Padovan | 807deac | 2012-05-17 00:36:24 -0300 | [diff] [blame] | 5526 | sizeof(ev->bdaddr), &ev->bdaddr); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 5527 | goto unlock; |
| 5528 | } |
| 5529 | |
Johan Hedberg | 55bc1a3 | 2011-04-28 11:28:56 -0700 | [diff] [blame] | 5530 | confirm: |
Johan Hedberg | 39adbff | 2014-03-20 08:18:14 +0200 | [diff] [blame] | 5531 | mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0, |
| 5532 | le32_to_cpu(ev->passkey), confirm_hint); |
Johan Hedberg | 7a82890 | 2011-04-28 11:28:53 -0700 | [diff] [blame] | 5533 | |
| 5534 | unlock: |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 5535 | hci_dev_unlock(hdev); |
| 5536 | } |
| 5537 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5538 | static void hci_user_passkey_request_evt(struct hci_dev *hdev, |
| 5539 | struct sk_buff *skb) |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 5540 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5541 | struct hci_ev_user_passkey_req *ev; |
| 5542 | |
| 5543 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_USER_PASSKEY_REQUEST, |
| 5544 | sizeof(*ev)); |
| 5545 | if (!ev) |
| 5546 | return; |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 5547 | |
| 5548 | BT_DBG("%s", hdev->name); |
| 5549 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5550 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 5551 | mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0); |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 5552 | } |
| 5553 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 5554 | static void hci_user_passkey_notify_evt(struct hci_dev *hdev, |
| 5555 | struct sk_buff *skb) |
| 5556 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5557 | struct hci_ev_user_passkey_notify *ev; |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 5558 | struct hci_conn *conn; |
| 5559 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5560 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_USER_PASSKEY_NOTIFY, |
| 5561 | sizeof(*ev)); |
| 5562 | if (!ev) |
| 5563 | return; |
| 5564 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 5565 | BT_DBG("%s", hdev->name); |
| 5566 | |
| 5567 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 5568 | if (!conn) |
| 5569 | return; |
| 5570 | |
| 5571 | conn->passkey_notify = __le32_to_cpu(ev->passkey); |
| 5572 | conn->passkey_entered = 0; |
| 5573 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5574 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 5575 | mgmt_user_passkey_notify(hdev, &conn->dst, conn->type, |
| 5576 | conn->dst_type, conn->passkey_notify, |
| 5577 | conn->passkey_entered); |
| 5578 | } |
| 5579 | |
| 5580 | static void hci_keypress_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5581 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5582 | struct hci_ev_keypress_notify *ev; |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 5583 | struct hci_conn *conn; |
| 5584 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5585 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_KEYPRESS_NOTIFY, sizeof(*ev)); |
| 5586 | if (!ev) |
| 5587 | return; |
| 5588 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 5589 | BT_DBG("%s", hdev->name); |
| 5590 | |
| 5591 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 5592 | if (!conn) |
| 5593 | return; |
| 5594 | |
| 5595 | switch (ev->type) { |
| 5596 | case HCI_KEYPRESS_STARTED: |
| 5597 | conn->passkey_entered = 0; |
| 5598 | return; |
| 5599 | |
| 5600 | case HCI_KEYPRESS_ENTERED: |
| 5601 | conn->passkey_entered++; |
| 5602 | break; |
| 5603 | |
| 5604 | case HCI_KEYPRESS_ERASED: |
| 5605 | conn->passkey_entered--; |
| 5606 | break; |
| 5607 | |
| 5608 | case HCI_KEYPRESS_CLEARED: |
| 5609 | conn->passkey_entered = 0; |
| 5610 | break; |
| 5611 | |
| 5612 | case HCI_KEYPRESS_COMPLETED: |
| 5613 | return; |
| 5614 | } |
| 5615 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5616 | if (hci_dev_test_flag(hdev, HCI_MGMT)) |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 5617 | mgmt_user_passkey_notify(hdev, &conn->dst, conn->type, |
| 5618 | conn->dst_type, conn->passkey_notify, |
| 5619 | conn->passkey_entered); |
| 5620 | } |
| 5621 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5622 | static void hci_simple_pair_complete_evt(struct hci_dev *hdev, |
| 5623 | struct sk_buff *skb) |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5624 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5625 | struct hci_ev_simple_pair_complete *ev; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5626 | struct hci_conn *conn; |
| 5627 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5628 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_SIMPLE_PAIR_COMPLETE, |
| 5629 | sizeof(*ev)); |
| 5630 | if (!ev) |
| 5631 | return; |
| 5632 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5633 | BT_DBG("%s", hdev->name); |
| 5634 | |
| 5635 | hci_dev_lock(hdev); |
| 5636 | |
| 5637 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 5638 | if (!conn) |
| 5639 | goto unlock; |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5640 | |
Johan Hedberg | c1d4fa7 | 2014-07-17 15:14:50 +0300 | [diff] [blame] | 5641 | /* Reset the authentication requirement to unknown */ |
| 5642 | conn->remote_auth = 0xff; |
| 5643 | |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 5644 | /* To avoid duplicate auth_failed events to user space we check |
| 5645 | * the HCI_CONN_AUTH_PEND flag which will be set if we |
| 5646 | * initiated the authentication. A traditional auth_complete |
| 5647 | * event gets always produced as initiator and is also mapped to |
| 5648 | * the mgmt_auth_failed event */ |
Mikel Astiz | fa1bd91 | 2012-08-09 09:52:29 +0200 | [diff] [blame] | 5649 | if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status) |
Johan Hedberg | e1e930f | 2014-09-08 17:09:49 -0700 | [diff] [blame] | 5650 | mgmt_auth_failed(conn, ev->status); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 5651 | |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 5652 | hci_conn_drop(conn); |
Johan Hedberg | 2a61169 | 2011-02-19 12:06:00 -0300 | [diff] [blame] | 5653 | |
| 5654 | unlock: |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5655 | hci_dev_unlock(hdev); |
| 5656 | } |
| 5657 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5658 | static void hci_remote_host_features_evt(struct hci_dev *hdev, |
| 5659 | struct sk_buff *skb) |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5660 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5661 | struct hci_ev_remote_host_features *ev; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5662 | struct inquiry_entry *ie; |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 5663 | struct hci_conn *conn; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5664 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5665 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_REMOTE_HOST_FEATURES, |
| 5666 | sizeof(*ev)); |
| 5667 | if (!ev) |
| 5668 | return; |
| 5669 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5670 | BT_DBG("%s", hdev->name); |
| 5671 | |
| 5672 | hci_dev_lock(hdev); |
| 5673 | |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 5674 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); |
| 5675 | if (conn) |
| 5676 | memcpy(conn->features[1], ev->features, 8); |
| 5677 | |
Andrei Emeltchenko | cc11b9c | 2010-11-22 13:21:37 +0200 | [diff] [blame] | 5678 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
| 5679 | if (ie) |
Johan Hedberg | 02b7cc6 | 2012-02-28 02:28:43 +0200 | [diff] [blame] | 5680 | ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP); |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 5681 | |
| 5682 | hci_dev_unlock(hdev); |
| 5683 | } |
| 5684 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 5685 | static void hci_remote_oob_data_request_evt(struct hci_dev *hdev, |
| 5686 | struct sk_buff *skb) |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5687 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5688 | struct hci_ev_remote_oob_data_request *ev; |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5689 | struct oob_data *data; |
| 5690 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5691 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_REMOTE_OOB_DATA_REQUEST, |
| 5692 | sizeof(*ev)); |
| 5693 | if (!ev) |
| 5694 | return; |
| 5695 | |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5696 | BT_DBG("%s", hdev->name); |
| 5697 | |
| 5698 | hci_dev_lock(hdev); |
| 5699 | |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5700 | if (!hci_dev_test_flag(hdev, HCI_MGMT)) |
Szymon Janc | e1ba1f1 | 2011-04-06 13:01:59 +0200 | [diff] [blame] | 5701 | goto unlock; |
| 5702 | |
Johan Hedberg | 6928a92 | 2014-10-26 20:46:09 +0100 | [diff] [blame] | 5703 | data = hci_find_remote_oob_data(hdev, &ev->bdaddr, BDADDR_BREDR); |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 5704 | if (!data) { |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5705 | struct hci_cp_remote_oob_data_neg_reply cp; |
| 5706 | |
| 5707 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Marcel Holtmann | 519ca9d | 2014-01-10 02:07:28 -0800 | [diff] [blame] | 5708 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, |
| 5709 | sizeof(cp), &cp); |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 5710 | goto unlock; |
| 5711 | } |
| 5712 | |
| 5713 | if (bredr_sc_enabled(hdev)) { |
| 5714 | struct hci_cp_remote_oob_ext_data_reply cp; |
| 5715 | |
| 5716 | bacpy(&cp.bdaddr, &ev->bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 5717 | if (hci_dev_test_flag(hdev, HCI_SC_ONLY)) { |
Marcel Holtmann | 6665d05 | 2015-01-27 16:04:31 -0800 | [diff] [blame] | 5718 | memset(cp.hash192, 0, sizeof(cp.hash192)); |
| 5719 | memset(cp.rand192, 0, sizeof(cp.rand192)); |
| 5720 | } else { |
| 5721 | memcpy(cp.hash192, data->hash192, sizeof(cp.hash192)); |
| 5722 | memcpy(cp.rand192, data->rand192, sizeof(cp.rand192)); |
| 5723 | } |
| 5724 | memcpy(cp.hash256, data->hash256, sizeof(cp.hash256)); |
| 5725 | memcpy(cp.rand256, data->rand256, sizeof(cp.rand256)); |
| 5726 | |
| 5727 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_EXT_DATA_REPLY, |
| 5728 | sizeof(cp), &cp); |
| 5729 | } else { |
| 5730 | struct hci_cp_remote_oob_data_reply cp; |
| 5731 | |
| 5732 | bacpy(&cp.bdaddr, &ev->bdaddr); |
| 5733 | memcpy(cp.hash, data->hash192, sizeof(cp.hash)); |
| 5734 | memcpy(cp.rand, data->rand192, sizeof(cp.rand)); |
| 5735 | |
| 5736 | hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, |
| 5737 | sizeof(cp), &cp); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5738 | } |
| 5739 | |
Szymon Janc | e1ba1f1 | 2011-04-06 13:01:59 +0200 | [diff] [blame] | 5740 | unlock: |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 5741 | hci_dev_unlock(hdev); |
| 5742 | } |
| 5743 | |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 5744 | #if IS_ENABLED(CONFIG_BT_HS) |
| 5745 | static void hci_chan_selected_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5746 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5747 | struct hci_ev_channel_selected *ev; |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 5748 | struct hci_conn *hcon; |
| 5749 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5750 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_CHANNEL_SELECTED, sizeof(*ev)); |
| 5751 | if (!ev) |
| 5752 | return; |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 5753 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5754 | BT_DBG("%s handle 0x%2.2x", hdev->name, ev->phy_handle); |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 5755 | |
| 5756 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 5757 | if (!hcon) |
| 5758 | return; |
| 5759 | |
| 5760 | amp_read_loc_assoc_final_data(hdev, hcon); |
| 5761 | } |
| 5762 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5763 | static void hci_phy_link_complete_evt(struct hci_dev *hdev, |
| 5764 | struct sk_buff *skb) |
| 5765 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5766 | struct hci_ev_phy_link_complete *ev; |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5767 | struct hci_conn *hcon, *bredr_hcon; |
| 5768 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5769 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_PHY_LINK_COMPLETE, sizeof(*ev)); |
| 5770 | if (!ev) |
| 5771 | return; |
| 5772 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5773 | BT_DBG("%s handle 0x%2.2x status 0x%2.2x", hdev->name, ev->phy_handle, |
| 5774 | ev->status); |
| 5775 | |
| 5776 | hci_dev_lock(hdev); |
| 5777 | |
| 5778 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5779 | if (!hcon) |
| 5780 | goto unlock; |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5781 | |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5782 | if (!hcon->amp_mgr) |
| 5783 | goto unlock; |
Anmol Karn | 6dfccd1 | 2020-09-30 19:48:13 +0530 | [diff] [blame] | 5784 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5785 | if (ev->status) { |
| 5786 | hci_conn_del(hcon); |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5787 | goto unlock; |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5788 | } |
| 5789 | |
| 5790 | bredr_hcon = hcon->amp_mgr->l2cap_conn->hcon; |
| 5791 | |
| 5792 | hcon->state = BT_CONNECTED; |
| 5793 | bacpy(&hcon->dst, &bredr_hcon->dst); |
| 5794 | |
| 5795 | hci_conn_hold(hcon); |
| 5796 | hcon->disc_timeout = HCI_DISCONN_TIMEOUT; |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 5797 | hci_conn_drop(hcon); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5798 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 5799 | hci_debugfs_create_conn(hcon); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5800 | hci_conn_add_sysfs(hcon); |
| 5801 | |
Andrei Emeltchenko | cf70ff2 | 2012-10-31 15:46:36 +0200 | [diff] [blame] | 5802 | amp_physical_cfm(bredr_hcon, hcon); |
| 5803 | |
Sergey Shtylyov | 3ae1dc7 | 2020-10-07 18:54:15 +0300 | [diff] [blame] | 5804 | unlock: |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5805 | hci_dev_unlock(hdev); |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 5806 | } |
| 5807 | |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 5808 | static void hci_loglink_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 5809 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5810 | struct hci_ev_logical_link_complete *ev; |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 5811 | struct hci_conn *hcon; |
| 5812 | struct hci_chan *hchan; |
| 5813 | struct amp_mgr *mgr; |
| 5814 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5815 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_LOGICAL_LINK_COMPLETE, |
| 5816 | sizeof(*ev)); |
| 5817 | if (!ev) |
| 5818 | return; |
| 5819 | |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 5820 | BT_DBG("%s log_handle 0x%4.4x phy_handle 0x%2.2x status 0x%2.2x", |
| 5821 | hdev->name, le16_to_cpu(ev->handle), ev->phy_handle, |
| 5822 | ev->status); |
| 5823 | |
| 5824 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 5825 | if (!hcon) |
| 5826 | return; |
| 5827 | |
| 5828 | /* Create AMP hchan */ |
| 5829 | hchan = hci_chan_create(hcon); |
| 5830 | if (!hchan) |
| 5831 | return; |
| 5832 | |
| 5833 | hchan->handle = le16_to_cpu(ev->handle); |
Archie Pusaka | 5c4c8c9 | 2021-03-22 14:03:11 +0800 | [diff] [blame] | 5834 | hchan->amp = true; |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 5835 | |
| 5836 | BT_DBG("hcon %p mgr %p hchan %p", hcon, hcon->amp_mgr, hchan); |
| 5837 | |
| 5838 | mgr = hcon->amp_mgr; |
| 5839 | if (mgr && mgr->bredr_chan) { |
| 5840 | struct l2cap_chan *bredr_chan = mgr->bredr_chan; |
| 5841 | |
| 5842 | l2cap_chan_lock(bredr_chan); |
| 5843 | |
| 5844 | bredr_chan->conn->mtu = hdev->block_mtu; |
| 5845 | l2cap_logical_cfm(bredr_chan, hchan, 0); |
| 5846 | hci_conn_hold(hcon); |
| 5847 | |
| 5848 | l2cap_chan_unlock(bredr_chan); |
| 5849 | } |
| 5850 | } |
| 5851 | |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 5852 | static void hci_disconn_loglink_complete_evt(struct hci_dev *hdev, |
| 5853 | struct sk_buff *skb) |
| 5854 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5855 | struct hci_ev_disconn_logical_link_complete *ev; |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 5856 | struct hci_chan *hchan; |
| 5857 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5858 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE, |
| 5859 | sizeof(*ev)); |
| 5860 | if (!ev) |
| 5861 | return; |
| 5862 | |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 5863 | BT_DBG("%s log handle 0x%4.4x status 0x%2.2x", hdev->name, |
| 5864 | le16_to_cpu(ev->handle), ev->status); |
| 5865 | |
| 5866 | if (ev->status) |
| 5867 | return; |
| 5868 | |
| 5869 | hci_dev_lock(hdev); |
| 5870 | |
| 5871 | hchan = hci_chan_lookup_handle(hdev, le16_to_cpu(ev->handle)); |
Archie Pusaka | 5c4c8c9 | 2021-03-22 14:03:11 +0800 | [diff] [blame] | 5872 | if (!hchan || !hchan->amp) |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 5873 | goto unlock; |
| 5874 | |
| 5875 | amp_destroy_logical_link(hchan, ev->reason); |
| 5876 | |
| 5877 | unlock: |
| 5878 | hci_dev_unlock(hdev); |
| 5879 | } |
| 5880 | |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 5881 | static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev, |
| 5882 | struct sk_buff *skb) |
| 5883 | { |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5884 | struct hci_ev_disconn_phy_link_complete *ev; |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 5885 | struct hci_conn *hcon; |
| 5886 | |
Luiz Augusto von Dentz | ae61a10 | 2021-12-01 10:54:53 -0800 | [diff] [blame] | 5887 | ev = hci_ev_skb_pull(hdev, skb, HCI_EV_DISCONN_PHY_LINK_COMPLETE, |
| 5888 | sizeof(*ev)); |
| 5889 | if (!ev) |
| 5890 | return; |
| 5891 | |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 5892 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 5893 | |
| 5894 | if (ev->status) |
| 5895 | return; |
| 5896 | |
| 5897 | hci_dev_lock(hdev); |
| 5898 | |
| 5899 | hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle); |
| 5900 | if (hcon) { |
| 5901 | hcon->state = BT_CLOSED; |
| 5902 | hci_conn_del(hcon); |
| 5903 | } |
| 5904 | |
| 5905 | hci_dev_unlock(hdev); |
| 5906 | } |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 5907 | #endif |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 5908 | |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 5909 | static void le_conn_update_addr(struct hci_conn *conn, bdaddr_t *bdaddr, |
| 5910 | u8 bdaddr_type, bdaddr_t *local_rpa) |
| 5911 | { |
| 5912 | if (conn->out) { |
| 5913 | conn->dst_type = bdaddr_type; |
| 5914 | conn->resp_addr_type = bdaddr_type; |
| 5915 | bacpy(&conn->resp_addr, bdaddr); |
| 5916 | |
| 5917 | /* Check if the controller has set a Local RPA then it must be |
| 5918 | * used instead or hdev->rpa. |
| 5919 | */ |
| 5920 | if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) { |
| 5921 | conn->init_addr_type = ADDR_LE_DEV_RANDOM; |
| 5922 | bacpy(&conn->init_addr, local_rpa); |
| 5923 | } else if (hci_dev_test_flag(conn->hdev, HCI_PRIVACY)) { |
| 5924 | conn->init_addr_type = ADDR_LE_DEV_RANDOM; |
| 5925 | bacpy(&conn->init_addr, &conn->hdev->rpa); |
| 5926 | } else { |
| 5927 | hci_copy_identity_address(conn->hdev, &conn->init_addr, |
| 5928 | &conn->init_addr_type); |
| 5929 | } |
| 5930 | } else { |
| 5931 | conn->resp_addr_type = conn->hdev->adv_addr_type; |
| 5932 | /* Check if the controller has set a Local RPA then it must be |
| 5933 | * used instead or hdev->rpa. |
| 5934 | */ |
| 5935 | if (local_rpa && bacmp(local_rpa, BDADDR_ANY)) { |
| 5936 | conn->resp_addr_type = ADDR_LE_DEV_RANDOM; |
| 5937 | bacpy(&conn->resp_addr, local_rpa); |
| 5938 | } else if (conn->hdev->adv_addr_type == ADDR_LE_DEV_RANDOM) { |
| 5939 | /* In case of ext adv, resp_addr will be updated in |
| 5940 | * Adv Terminated event. |
| 5941 | */ |
| 5942 | if (!ext_adv_capable(conn->hdev)) |
| 5943 | bacpy(&conn->resp_addr, |
| 5944 | &conn->hdev->random_addr); |
| 5945 | } else { |
| 5946 | bacpy(&conn->resp_addr, &conn->hdev->bdaddr); |
| 5947 | } |
| 5948 | |
| 5949 | conn->init_addr_type = bdaddr_type; |
| 5950 | bacpy(&conn->init_addr, bdaddr); |
| 5951 | |
| 5952 | /* For incoming connections, set the default minimum |
| 5953 | * and maximum connection interval. They will be used |
| 5954 | * to check if the parameters are in range and if not |
| 5955 | * trigger the connection update procedure. |
| 5956 | */ |
| 5957 | conn->le_conn_min_interval = conn->hdev->le_conn_min_interval; |
| 5958 | conn->le_conn_max_interval = conn->hdev->le_conn_max_interval; |
| 5959 | } |
| 5960 | } |
| 5961 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5962 | 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] | 5963 | bdaddr_t *bdaddr, u8 bdaddr_type, |
| 5964 | bdaddr_t *local_rpa, u8 role, u16 handle, |
| 5965 | u16 interval, u16 latency, |
| 5966 | u16 supervision_timeout) |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5967 | { |
Johan Hedberg | 912b42ef | 2014-07-03 19:33:49 +0300 | [diff] [blame] | 5968 | struct hci_conn_params *params; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5969 | struct hci_conn *conn; |
Johan Hedberg | 68d6f6d | 2014-02-18 21:41:32 +0200 | [diff] [blame] | 5970 | struct smp_irk *irk; |
Johan Hedberg | 837d502 | 2014-07-02 09:36:22 +0300 | [diff] [blame] | 5971 | u8 addr_type; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5972 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 5973 | hci_dev_lock(hdev); |
| 5974 | |
Johan Hedberg | fbd96c1 | 2014-07-08 17:21:51 +0300 | [diff] [blame] | 5975 | /* All controllers implicitly stop advertising in the event of a |
| 5976 | * connection, so ensure that the state bit is cleared. |
| 5977 | */ |
Marcel Holtmann | a358dc1 | 2015-03-13 02:11:02 -0700 | [diff] [blame] | 5978 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Johan Hedberg | fbd96c1 | 2014-07-08 17:21:51 +0300 | [diff] [blame] | 5979 | |
Jakub Pawlowski | e7d9ab7 | 2015-08-07 20:22:52 +0200 | [diff] [blame] | 5980 | conn = hci_lookup_le_connect(hdev); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5981 | if (!conn) { |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5982 | conn = hci_conn_add(hdev, LE_LINK, bdaddr, role); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5983 | if (!conn) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 5984 | bt_dev_err(hdev, "no memory for new connection"); |
Andre Guedes | 230fd16 | 2012-07-27 15:10:10 -0300 | [diff] [blame] | 5985 | goto unlock; |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 5986 | } |
Andre Guedes | 29b7988 | 2011-05-31 14:20:54 -0300 | [diff] [blame] | 5987 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5988 | conn->dst_type = bdaddr_type; |
Andre Guedes | b9b343d | 2012-07-27 15:10:11 -0300 | [diff] [blame] | 5989 | |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5990 | /* If we didn't have a hci_conn object previously |
Archie Pusaka | 74be523 | 2021-06-04 16:26:25 +0800 | [diff] [blame] | 5991 | * but we're in central role this must be something |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 5992 | * initiated using an accept list. Since accept list based |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 5993 | * connections are not "first class citizens" we don't |
| 5994 | * have full tracking of them. Therefore, we go ahead |
| 5995 | * with a "best effort" approach of determining the |
| 5996 | * initiator address based on the HCI_PRIVACY flag. |
| 5997 | */ |
| 5998 | if (conn->out) { |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 5999 | conn->resp_addr_type = bdaddr_type; |
| 6000 | bacpy(&conn->resp_addr, bdaddr); |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 6001 | if (hci_dev_test_flag(hdev, HCI_PRIVACY)) { |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 6002 | conn->init_addr_type = ADDR_LE_DEV_RANDOM; |
| 6003 | bacpy(&conn->init_addr, &hdev->rpa); |
| 6004 | } else { |
| 6005 | hci_copy_identity_address(hdev, |
| 6006 | &conn->init_addr, |
| 6007 | &conn->init_addr_type); |
| 6008 | } |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 6009 | } |
Johan Hedberg | 9489eca | 2014-02-28 17:45:46 +0200 | [diff] [blame] | 6010 | } else { |
| 6011 | cancel_delayed_work(&conn->le_conn_timeout); |
Ville Tervo | b62f328 | 2011-02-10 22:38:50 -0300 | [diff] [blame] | 6012 | } |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6013 | |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 6014 | le_conn_update_addr(conn, bdaddr, bdaddr_type, local_rpa); |
Johan Hedberg | 7be2edb | 2014-02-23 19:42:17 +0200 | [diff] [blame] | 6015 | |
Marcel Holtmann | edb4b46 | 2014-02-18 15:13:43 -0800 | [diff] [blame] | 6016 | /* Lookup the identity address from the stored connection |
| 6017 | * address and address type. |
| 6018 | * |
| 6019 | * When establishing connections to an identity address, the |
| 6020 | * connection procedure will store the resolvable random |
| 6021 | * address first. Now if it can be converted back into the |
| 6022 | * identity address, start using the identity address from |
| 6023 | * now on. |
| 6024 | */ |
| 6025 | irk = hci_get_irk(hdev, &conn->dst, conn->dst_type); |
Johan Hedberg | 68d6f6d | 2014-02-18 21:41:32 +0200 | [diff] [blame] | 6026 | if (irk) { |
| 6027 | bacpy(&conn->dst, &irk->bdaddr); |
| 6028 | conn->dst_type = irk->addr_type; |
| 6029 | } |
| 6030 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 6031 | conn->dst_type = ev_bdaddr_type(hdev, conn->dst_type, NULL); |
Sathish Narasimman | 79699a7 | 2021-05-20 17:12:01 +0530 | [diff] [blame] | 6032 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 6033 | if (status) { |
| 6034 | hci_le_conn_failed(conn, status); |
Johan Hedberg | 837d502 | 2014-07-02 09:36:22 +0300 | [diff] [blame] | 6035 | goto unlock; |
| 6036 | } |
| 6037 | |
Johan Hedberg | 08853f1 | 2014-08-15 21:06:55 +0300 | [diff] [blame] | 6038 | if (conn->dst_type == ADDR_LE_DEV_PUBLIC) |
| 6039 | addr_type = BDADDR_LE_PUBLIC; |
| 6040 | else |
| 6041 | addr_type = BDADDR_LE_RANDOM; |
| 6042 | |
Johan Hedberg | 2d3c226 | 2014-07-15 11:51:28 +0300 | [diff] [blame] | 6043 | /* Drop the connection if the device is blocked */ |
Archie Pusaka | 3d4f9c0 | 2021-06-04 16:26:27 +0800 | [diff] [blame] | 6044 | if (hci_bdaddr_list_lookup(&hdev->reject_list, &conn->dst, addr_type)) { |
Johan Hedberg | 2d3c226 | 2014-07-15 11:51:28 +0300 | [diff] [blame] | 6045 | hci_conn_drop(conn); |
Andre Guedes | cd17dec | 2012-07-27 15:10:16 -0300 | [diff] [blame] | 6046 | goto unlock; |
| 6047 | } |
| 6048 | |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 6049 | if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) |
Yu Liu | 1c6ed31 | 2021-04-09 15:04:06 -0700 | [diff] [blame] | 6050 | mgmt_device_connected(hdev, conn, NULL, 0); |
Vinicius Costa Gomes | 83bc71b | 2011-05-06 18:41:43 -0300 | [diff] [blame] | 6051 | |
Vinicius Costa Gomes | 7b5c0d5 | 2011-06-09 18:50:50 -0300 | [diff] [blame] | 6052 | conn->sec_level = BT_SECURITY_LOW; |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 6053 | conn->handle = handle; |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6054 | conn->state = BT_CONFIG; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6055 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 6056 | /* Store current advertising instance as connection advertising instance |
| 6057 | * when sotfware rotation is in use so it can be re-enabled when |
| 6058 | * disconnected. |
| 6059 | */ |
| 6060 | if (!ext_adv_capable(hdev)) |
| 6061 | conn->adv_instance = hdev->cur_adv_instance; |
| 6062 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 6063 | conn->le_conn_interval = interval; |
| 6064 | conn->le_conn_latency = latency; |
| 6065 | conn->le_supv_timeout = supervision_timeout; |
Marcel Holtmann | e04fde6 | 2014-06-23 11:40:04 +0200 | [diff] [blame] | 6066 | |
Marcel Holtmann | 23b9ceb | 2014-12-20 17:13:41 +0100 | [diff] [blame] | 6067 | hci_debugfs_create_conn(conn); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6068 | hci_conn_add_sysfs(conn); |
| 6069 | |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 6070 | /* The remote features procedure is defined for central |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 6071 | * role only. So only in case of an initiated connection |
| 6072 | * request the remote features. |
| 6073 | * |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 6074 | * If the local controller supports peripheral-initiated features |
| 6075 | * exchange, then requesting the remote features in peripheral |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 6076 | * role is possible. Otherwise just transition into the |
| 6077 | * connected state without requesting the remote features. |
| 6078 | */ |
| 6079 | if (conn->out || |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 6080 | (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) { |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 6081 | struct hci_cp_le_read_remote_features cp; |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6082 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 6083 | cp.handle = __cpu_to_le16(conn->handle); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6084 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 6085 | hci_send_cmd(hdev, HCI_OP_LE_READ_REMOTE_FEATURES, |
| 6086 | sizeof(cp), &cp); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6087 | |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 6088 | hci_conn_hold(conn); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6089 | } else { |
Colin Ian King | d17010b | 2018-10-10 15:37:31 +0100 | [diff] [blame] | 6090 | conn->state = BT_CONNECTED; |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 6091 | hci_connect_cfm(conn, status); |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6092 | } |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6093 | |
Johan Hedberg | 5477610 | 2014-08-15 21:06:56 +0300 | [diff] [blame] | 6094 | params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst, |
| 6095 | conn->dst_type); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 6096 | if (params) { |
Johan Hedberg | 95305ba | 2014-07-04 12:37:21 +0300 | [diff] [blame] | 6097 | list_del_init(¶ms->action); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 6098 | if (params->conn) { |
| 6099 | hci_conn_drop(params->conn); |
Johan Hedberg | f8aaf9b | 2014-08-17 23:28:57 +0300 | [diff] [blame] | 6100 | hci_conn_put(params->conn); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 6101 | params->conn = NULL; |
| 6102 | } |
| 6103 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6104 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6105 | unlock: |
Luiz Augusto von Dentz | 5bee2fd | 2021-10-27 16:58:43 -0700 | [diff] [blame] | 6106 | hci_update_passive_scan(hdev); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6107 | hci_dev_unlock(hdev); |
| 6108 | } |
| 6109 | |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 6110 | static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 6111 | { |
| 6112 | struct hci_ev_le_conn_complete *ev = (void *) skb->data; |
| 6113 | |
| 6114 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 6115 | |
| 6116 | 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] | 6117 | NULL, ev->role, le16_to_cpu(ev->handle), |
Jaganath Kanakkassery | d12fb05 | 2018-07-06 17:05:30 +0530 | [diff] [blame] | 6118 | le16_to_cpu(ev->interval), |
| 6119 | le16_to_cpu(ev->latency), |
| 6120 | le16_to_cpu(ev->supervision_timeout)); |
| 6121 | } |
| 6122 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 6123 | static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, |
| 6124 | struct sk_buff *skb) |
| 6125 | { |
| 6126 | struct hci_ev_le_enh_conn_complete *ev = (void *) skb->data; |
| 6127 | |
| 6128 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 6129 | |
| 6130 | 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] | 6131 | &ev->local_rpa, ev->role, le16_to_cpu(ev->handle), |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 6132 | le16_to_cpu(ev->interval), |
| 6133 | le16_to_cpu(ev->latency), |
| 6134 | le16_to_cpu(ev->supervision_timeout)); |
| 6135 | } |
| 6136 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6137 | static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 6138 | { |
| 6139 | struct hci_evt_le_ext_adv_set_term *ev = (void *) skb->data; |
| 6140 | struct hci_conn *conn; |
Archie Pusaka | 1f9d565 | 2021-11-11 13:20:54 +0800 | [diff] [blame] | 6141 | struct adv_info *adv, *n; |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6142 | |
| 6143 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 6144 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 6145 | adv = hci_find_adv_instance(hdev, ev->handle); |
Luiz Augusto von Dentz | 23837a6 | 2021-06-22 20:59:02 -0700 | [diff] [blame] | 6146 | |
Archie Pusaka | 0f281a5 | 2021-11-11 13:20:53 +0800 | [diff] [blame] | 6147 | /* The Bluetooth Core 5.3 specification clearly states that this event |
| 6148 | * shall not be sent when the Host disables the advertising set. So in |
| 6149 | * case of HCI_ERROR_CANCELLED_BY_HOST, just ignore the event. |
| 6150 | * |
| 6151 | * When the Host disables an advertising set, all cleanup is done via |
| 6152 | * its command callback and not needed to be duplicated here. |
| 6153 | */ |
| 6154 | if (ev->status == HCI_ERROR_CANCELLED_BY_HOST) { |
| 6155 | bt_dev_warn_ratelimited(hdev, "Unexpected advertising set terminated event"); |
| 6156 | return; |
| 6157 | } |
| 6158 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 6159 | if (ev->status) { |
Luiz Augusto von Dentz | 23837a6 | 2021-06-22 20:59:02 -0700 | [diff] [blame] | 6160 | if (!adv) |
| 6161 | return; |
| 6162 | |
| 6163 | /* Remove advertising as it has been terminated */ |
| 6164 | hci_remove_adv_instance(hdev, ev->handle); |
| 6165 | mgmt_advertising_removed(NULL, hdev, ev->handle); |
| 6166 | |
Archie Pusaka | 1f9d565 | 2021-11-11 13:20:54 +0800 | [diff] [blame] | 6167 | list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { |
| 6168 | if (adv->enabled) |
| 6169 | return; |
| 6170 | } |
| 6171 | |
| 6172 | /* We are no longer advertising, clear HCI_LE_ADV */ |
| 6173 | hci_dev_clear_flag(hdev, HCI_LE_ADV); |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6174 | return; |
Luiz Augusto von Dentz | 23837a6 | 2021-06-22 20:59:02 -0700 | [diff] [blame] | 6175 | } |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6176 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 6177 | if (adv) |
| 6178 | adv->enabled = false; |
| 6179 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6180 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle)); |
| 6181 | if (conn) { |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 6182 | /* Store handle in the connection so the correct advertising |
| 6183 | * instance can be re-enabled when disconnected. |
| 6184 | */ |
| 6185 | conn->adv_instance = ev->handle; |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6186 | |
Luiz Augusto von Dentz | cafae4c | 2021-08-11 16:20:15 -0700 | [diff] [blame] | 6187 | if (hdev->adv_addr_type != ADDR_LE_DEV_RANDOM || |
| 6188 | bacmp(&conn->resp_addr, BDADDR_ANY)) |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6189 | return; |
| 6190 | |
Daniel Winkler | 25e7088 | 2021-04-05 16:33:04 -0700 | [diff] [blame] | 6191 | if (!ev->handle) { |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6192 | bacpy(&conn->resp_addr, &hdev->random_addr); |
| 6193 | return; |
| 6194 | } |
| 6195 | |
Luiz Augusto von Dentz | 7087c4f | 2021-08-11 16:20:16 -0700 | [diff] [blame] | 6196 | if (adv) |
| 6197 | bacpy(&conn->resp_addr, &adv->random_addr); |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6198 | } |
| 6199 | } |
| 6200 | |
Marcel Holtmann | 1855d92 | 2014-06-23 11:40:05 +0200 | [diff] [blame] | 6201 | static void hci_le_conn_update_complete_evt(struct hci_dev *hdev, |
| 6202 | struct sk_buff *skb) |
| 6203 | { |
| 6204 | struct hci_ev_le_conn_update_complete *ev = (void *) skb->data; |
| 6205 | struct hci_conn *conn; |
| 6206 | |
| 6207 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 6208 | |
| 6209 | if (ev->status) |
| 6210 | return; |
| 6211 | |
| 6212 | hci_dev_lock(hdev); |
| 6213 | |
| 6214 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 6215 | if (conn) { |
| 6216 | conn->le_conn_interval = le16_to_cpu(ev->interval); |
| 6217 | conn->le_conn_latency = le16_to_cpu(ev->latency); |
| 6218 | conn->le_supv_timeout = le16_to_cpu(ev->supervision_timeout); |
| 6219 | } |
| 6220 | |
| 6221 | hci_dev_unlock(hdev); |
| 6222 | } |
| 6223 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6224 | /* This function requires the caller holds hdev->lock */ |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6225 | static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev, |
| 6226 | bdaddr_t *addr, |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 6227 | u8 addr_type, bool addr_resolved, |
| 6228 | u8 adv_type, bdaddr_t *direct_rpa) |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6229 | { |
| 6230 | struct hci_conn *conn; |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 6231 | struct hci_conn_params *params; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6232 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 6233 | /* If the event is not connectable don't proceed further */ |
| 6234 | if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6235 | return NULL; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 6236 | |
Luiz Augusto von Dentz | 182ee45 | 2021-10-27 16:59:00 -0700 | [diff] [blame] | 6237 | /* Ignore if the device is blocked or hdev is suspended */ |
| 6238 | if (hci_bdaddr_list_lookup(&hdev->reject_list, addr, addr_type) || |
| 6239 | hdev->suspended) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6240 | return NULL; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 6241 | |
Johan Hedberg | f99353c | 2014-07-16 11:56:09 +0300 | [diff] [blame] | 6242 | /* Most controller will fail if we try to create new connections |
Archie Pusaka | 39bc74c | 2021-06-04 16:26:26 +0800 | [diff] [blame] | 6243 | * while we have an existing one in peripheral role. |
Johan Hedberg | f99353c | 2014-07-16 11:56:09 +0300 | [diff] [blame] | 6244 | */ |
Archie Pusaka | 39bc74c | 2021-06-04 16:26:26 +0800 | [diff] [blame] | 6245 | if (hdev->conn_hash.le_num_peripheral > 0 && |
Alain Michaud | 4364f2e | 2020-04-23 14:43:29 +0000 | [diff] [blame] | 6246 | (!test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) || |
| 6247 | !(hdev->le_states[3] & 0x10))) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6248 | return NULL; |
Johan Hedberg | f99353c | 2014-07-16 11:56:09 +0300 | [diff] [blame] | 6249 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 6250 | /* If we're not connectable only connect devices that we have in |
| 6251 | * our pend_le_conns list. |
| 6252 | */ |
Johan Hedberg | 49c5092 | 2015-10-16 10:07:51 +0300 | [diff] [blame] | 6253 | params = hci_pend_le_action_lookup(&hdev->pend_le_conns, addr, |
| 6254 | addr_type); |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 6255 | if (!params) |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6256 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6257 | |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 6258 | if (!params->explicit_connect) { |
| 6259 | switch (params->auto_connect) { |
| 6260 | case HCI_AUTO_CONN_DIRECT: |
| 6261 | /* Only devices advertising with ADV_DIRECT_IND are |
| 6262 | * triggering a connection attempt. This is allowing |
Archie Pusaka | 67ffb18 | 2021-05-31 16:37:28 +0800 | [diff] [blame] | 6263 | * incoming connections from peripheral devices. |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 6264 | */ |
| 6265 | if (adv_type != LE_ADV_DIRECT_IND) |
| 6266 | return NULL; |
| 6267 | break; |
| 6268 | case HCI_AUTO_CONN_ALWAYS: |
| 6269 | /* Devices advertising with ADV_IND or ADV_DIRECT_IND |
| 6270 | * are triggering a connection attempt. This means |
Archie Pusaka | 67ffb18 | 2021-05-31 16:37:28 +0800 | [diff] [blame] | 6271 | * that incoming connections from peripheral device are |
| 6272 | * accepted and also outgoing connections to peripheral |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 6273 | * devices are established when found. |
| 6274 | */ |
| 6275 | break; |
| 6276 | default: |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6277 | return NULL; |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 6278 | } |
Marcel Holtmann | 4b9e7e7 | 2014-07-23 21:55:23 +0200 | [diff] [blame] | 6279 | } |
| 6280 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 6281 | conn = hci_connect_le(hdev, addr, addr_type, addr_resolved, |
| 6282 | BT_SECURITY_LOW, hdev->def_le_autoconnect_timeout, |
| 6283 | HCI_ROLE_MASTER, direct_rpa); |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 6284 | if (!IS_ERR(conn)) { |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 6285 | /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned |
| 6286 | * by higher layer that tried to connect, if no then |
| 6287 | * store the pointer since we don't really have any |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 6288 | * other owner of the object besides the params that |
| 6289 | * triggered it. This way we can abort the connection if |
| 6290 | * the parameters get removed and keep the reference |
| 6291 | * count consistent once the connection is established. |
| 6292 | */ |
Jakub Pawlowski | 28a667c | 2015-08-07 20:22:54 +0200 | [diff] [blame] | 6293 | |
| 6294 | if (!params->explicit_connect) |
| 6295 | params->conn = hci_conn_get(conn); |
| 6296 | |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6297 | return conn; |
Johan Hedberg | f161dd4 | 2014-08-15 21:06:54 +0300 | [diff] [blame] | 6298 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6299 | |
| 6300 | switch (PTR_ERR(conn)) { |
| 6301 | case -EBUSY: |
| 6302 | /* If hci_connect() returns -EBUSY it means there is already |
| 6303 | * an LE connection attempt going on. Since controllers don't |
| 6304 | * support more than one connection attempt at the time, we |
| 6305 | * don't consider this an error case. |
| 6306 | */ |
| 6307 | break; |
| 6308 | default: |
| 6309 | BT_DBG("Failed to connect: err %ld", PTR_ERR(conn)); |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6310 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6311 | } |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6312 | |
| 6313 | return NULL; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6314 | } |
| 6315 | |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 6316 | 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] | 6317 | u8 bdaddr_type, bdaddr_t *direct_addr, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6318 | u8 direct_addr_type, s8 rssi, u8 *data, u8 len, |
| 6319 | bool ext_adv) |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 6320 | { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6321 | struct discovery_state *d = &hdev->discovery; |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 6322 | struct smp_irk *irk; |
Alfonso Acosta | fd45ada | 2014-10-07 08:44:11 +0000 | [diff] [blame] | 6323 | struct hci_conn *conn; |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 6324 | bool match, bdaddr_resolved; |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 6325 | u32 flags; |
Szymon Janc | 1c58e93 | 2021-05-18 16:54:36 +0200 | [diff] [blame] | 6326 | u8 *ptr; |
Szymon Janc | 6818375 | 2015-09-16 20:21:54 +0200 | [diff] [blame] | 6327 | |
Johan Hedberg | 56b40fb | 2016-04-07 21:01:27 +0300 | [diff] [blame] | 6328 | switch (type) { |
| 6329 | case LE_ADV_IND: |
| 6330 | case LE_ADV_DIRECT_IND: |
| 6331 | case LE_ADV_SCAN_IND: |
| 6332 | case LE_ADV_NONCONN_IND: |
| 6333 | case LE_ADV_SCAN_RSP: |
| 6334 | break; |
| 6335 | default: |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 6336 | bt_dev_err_ratelimited(hdev, "unknown advertising packet " |
| 6337 | "type: 0x%02x", type); |
Johan Hedberg | 56b40fb | 2016-04-07 21:01:27 +0300 | [diff] [blame] | 6338 | return; |
| 6339 | } |
| 6340 | |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6341 | if (!ext_adv && len > HCI_MAX_AD_LENGTH) { |
| 6342 | bt_dev_err_ratelimited(hdev, "legacy adv larger than 31 bytes"); |
| 6343 | return; |
| 6344 | } |
| 6345 | |
Szymon Janc | 6818375 | 2015-09-16 20:21:54 +0200 | [diff] [blame] | 6346 | /* Find the end of the data in case the report contains padded zero |
| 6347 | * bytes at the end causing an invalid length value. |
| 6348 | * |
| 6349 | * When data is NULL, len is 0 so there is no need for extra ptr |
| 6350 | * check as 'ptr < data + 0' is already false in such case. |
| 6351 | */ |
| 6352 | for (ptr = data; ptr < data + len && *ptr; ptr += *ptr + 1) { |
| 6353 | if (ptr + 1 + *ptr > data + len) |
| 6354 | break; |
| 6355 | } |
| 6356 | |
Szymon Janc | 1c58e93 | 2021-05-18 16:54:36 +0200 | [diff] [blame] | 6357 | /* Adjust for actual length. This handles the case when remote |
| 6358 | * device is advertising with incorrect data length. |
| 6359 | */ |
| 6360 | len = ptr - data; |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6361 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6362 | /* If the direct address is present, then this report is from |
| 6363 | * a LE Direct Advertising Report event. In that case it is |
| 6364 | * important to see if the address is matching the local |
| 6365 | * controller address. |
| 6366 | */ |
| 6367 | if (direct_addr) { |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 6368 | direct_addr_type = ev_bdaddr_type(hdev, direct_addr_type, |
| 6369 | &bdaddr_resolved); |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 6370 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6371 | /* Only resolvable random addresses are valid for these |
| 6372 | * kind of reports and others can be ignored. |
| 6373 | */ |
| 6374 | if (!hci_bdaddr_is_rpa(direct_addr, direct_addr_type)) |
| 6375 | return; |
| 6376 | |
| 6377 | /* If the controller is not using resolvable random |
| 6378 | * addresses, then this report can be ignored. |
| 6379 | */ |
Marcel Holtmann | d7a5a11 | 2015-03-13 02:11:00 -0700 | [diff] [blame] | 6380 | if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6381 | return; |
| 6382 | |
| 6383 | /* If the local IRK of the controller does not match |
| 6384 | * with the resolvable random address provided, then |
| 6385 | * this report can be ignored. |
| 6386 | */ |
| 6387 | if (!smp_irk_matches(hdev, hdev->irk, direct_addr)) |
| 6388 | return; |
| 6389 | } |
| 6390 | |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 6391 | /* Check if we need to convert to identity address */ |
| 6392 | irk = hci_get_irk(hdev, bdaddr, bdaddr_type); |
| 6393 | if (irk) { |
| 6394 | bdaddr = &irk->bdaddr; |
| 6395 | bdaddr_type = irk->addr_type; |
| 6396 | } |
| 6397 | |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 6398 | bdaddr_type = ev_bdaddr_type(hdev, bdaddr_type, &bdaddr_resolved); |
Luiz Augusto von Dentz | 4ec4d63 | 2021-08-30 13:55:36 -0700 | [diff] [blame] | 6399 | |
Szymon Janc | 082f230 | 2018-04-03 13:40:06 +0200 | [diff] [blame] | 6400 | /* Check if we have been requested to connect to this device. |
| 6401 | * |
| 6402 | * direct_addr is set only for directed advertising reports (it is NULL |
| 6403 | * for advertising reports) and is already verified to be RPA above. |
| 6404 | */ |
Luiz Augusto von Dentz | d850bf0 | 2021-08-30 13:55:37 -0700 | [diff] [blame] | 6405 | conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, bdaddr_resolved, |
| 6406 | type, direct_addr); |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6407 | 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] | 6408 | /* Store report for later inclusion by |
| 6409 | * mgmt_device_connected |
| 6410 | */ |
| 6411 | memcpy(conn->le_adv_data, data, len); |
| 6412 | conn->le_adv_data_len = len; |
| 6413 | } |
Johan Hedberg | 1c1abca | 2014-07-07 12:45:53 +0300 | [diff] [blame] | 6414 | |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 6415 | /* Passive scanning shouldn't trigger any device found events, |
| 6416 | * 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] | 6417 | * device found events, or advertisement monitoring requested. |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 6418 | */ |
Johan Hedberg | ca5c4be | 2014-03-25 10:30:46 +0200 | [diff] [blame] | 6419 | if (hdev->le_scan_type == LE_SCAN_PASSIVE) { |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 6420 | if (type == LE_ADV_DIRECT_IND) |
| 6421 | return; |
| 6422 | |
Johan Hedberg | 3a19b6f | 2014-07-15 08:07:59 +0300 | [diff] [blame] | 6423 | if (!hci_pend_le_action_lookup(&hdev->pend_le_reports, |
Miao-chen Chou | 8208f5a | 2020-06-17 16:39:18 +0200 | [diff] [blame] | 6424 | bdaddr, bdaddr_type) && |
| 6425 | idr_is_empty(&hdev->adv_monitors_idr)) |
Johan Hedberg | 0d2bf13 | 2014-07-02 22:42:02 +0300 | [diff] [blame] | 6426 | return; |
| 6427 | |
| 6428 | if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND) |
| 6429 | flags = MGMT_DEV_FOUND_NOT_CONNECTABLE; |
| 6430 | else |
| 6431 | flags = 0; |
| 6432 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
| 6433 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | 97bf2e9 | 2014-07-04 12:37:16 +0300 | [diff] [blame] | 6434 | return; |
Johan Hedberg | ca5c4be | 2014-03-25 10:30:46 +0200 | [diff] [blame] | 6435 | } |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 6436 | |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 6437 | /* When receiving non-connectable or scannable undirected |
| 6438 | * advertising reports, this means that the remote device is |
| 6439 | * not connectable and then clearly indicate this in the |
| 6440 | * device found event. |
| 6441 | * |
| 6442 | * When receiving a scan response, then there is no way to |
| 6443 | * know if the remote device is connectable or not. However |
| 6444 | * since scan responses are merged with a previously seen |
| 6445 | * advertising report, the flags field from that report |
| 6446 | * will be used. |
| 6447 | * |
| 6448 | * In the really unlikely case that a controller get confused |
| 6449 | * and just sends a scan response event, then it is marked as |
| 6450 | * not connectable as well. |
| 6451 | */ |
| 6452 | if (type == LE_ADV_NONCONN_IND || type == LE_ADV_SCAN_IND || |
| 6453 | type == LE_ADV_SCAN_RSP) |
| 6454 | flags = MGMT_DEV_FOUND_NOT_CONNECTABLE; |
| 6455 | else |
| 6456 | flags = 0; |
| 6457 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6458 | /* If there's nothing pending either store the data from this |
| 6459 | * event or send an immediate device found event if the data |
| 6460 | * should not be stored for later. |
| 6461 | */ |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6462 | if (!ext_adv && !has_pending_adv_report(hdev)) { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6463 | /* If the report will trigger a SCAN_REQ store it for |
| 6464 | * later merging. |
| 6465 | */ |
| 6466 | if (type == LE_ADV_IND || type == LE_ADV_SCAN_IND) { |
| 6467 | store_pending_adv_report(hdev, bdaddr, bdaddr_type, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 6468 | rssi, flags, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6469 | return; |
| 6470 | } |
| 6471 | |
| 6472 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 6473 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6474 | return; |
| 6475 | } |
| 6476 | |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 6477 | /* Check if the pending report is for the same device as the new one */ |
| 6478 | match = (!bacmp(bdaddr, &d->last_adv_addr) && |
| 6479 | bdaddr_type == d->last_adv_addr_type); |
| 6480 | |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6481 | /* If the pending data doesn't match this report or this isn't a |
| 6482 | * scan response (e.g. we got a duplicate ADV_IND) then force |
| 6483 | * sending of the pending data. |
| 6484 | */ |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 6485 | if (type != LE_ADV_SCAN_RSP || !match) { |
| 6486 | /* Send out whatever is in the cache, but skip duplicates */ |
| 6487 | if (!match) |
| 6488 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 6489 | d->last_adv_addr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 6490 | d->last_adv_rssi, d->last_adv_flags, |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 6491 | d->last_adv_data, |
Johan Hedberg | 474ee06 | 2014-03-25 14:34:59 +0200 | [diff] [blame] | 6492 | d->last_adv_data_len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6493 | |
| 6494 | /* If the new report will trigger a SCAN_REQ store it for |
| 6495 | * later merging. |
| 6496 | */ |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6497 | if (!ext_adv && (type == LE_ADV_IND || |
| 6498 | type == LE_ADV_SCAN_IND)) { |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6499 | store_pending_adv_report(hdev, bdaddr, bdaddr_type, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 6500 | rssi, flags, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6501 | return; |
| 6502 | } |
| 6503 | |
| 6504 | /* The advertising reports cannot be merged, so clear |
| 6505 | * the pending report and send out a device found event. |
| 6506 | */ |
| 6507 | clear_pending_adv_report(hdev); |
Johan Hedberg | 5c5b93e | 2014-03-29 08:39:53 +0200 | [diff] [blame] | 6508 | mgmt_device_found(hdev, bdaddr, LE_LINK, bdaddr_type, NULL, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 6509 | rssi, flags, data, len, NULL, 0); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6510 | return; |
| 6511 | } |
| 6512 | |
| 6513 | /* If we get here we've got a pending ADV_IND or ADV_SCAN_IND and |
| 6514 | * the new event is a SCAN_RSP. We can therefore proceed with |
| 6515 | * sending a merged device found event. |
| 6516 | */ |
| 6517 | mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK, |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 6518 | d->last_adv_addr_type, NULL, rssi, d->last_adv_flags, |
Marcel Holtmann | 42bd6a5 | 2014-07-01 14:11:19 +0200 | [diff] [blame] | 6519 | d->last_adv_data, d->last_adv_data_len, data, len); |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 6520 | clear_pending_adv_report(hdev); |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 6521 | } |
| 6522 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 6523 | 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] | 6524 | { |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 6525 | u8 num_reports = skb->data[0]; |
| 6526 | void *ptr = &skb->data[1]; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 6527 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6528 | hci_dev_lock(hdev); |
| 6529 | |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 6530 | while (num_reports--) { |
| 6531 | struct hci_ev_le_advertising_info *ev = ptr; |
Johan Hedberg | 4af605d | 2014-03-24 10:48:00 +0200 | [diff] [blame] | 6532 | s8 rssi; |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6533 | |
Brian Gix | 899663b | 2021-11-24 12:16:28 -0800 | [diff] [blame] | 6534 | if (ptr > (void *)skb_tail_pointer(skb) - sizeof(*ev)) { |
| 6535 | bt_dev_err(hdev, "Malicious advertising data."); |
| 6536 | break; |
| 6537 | } |
| 6538 | |
Pavel Skripkin | 3a56ef7 | 2021-11-01 10:12:12 +0300 | [diff] [blame] | 6539 | if (ev->length <= HCI_MAX_AD_LENGTH && |
| 6540 | ev->data + ev->length <= skb_tail_pointer(skb)) { |
Chriz Chow | ee64934 | 2018-04-20 15:46:24 +0800 | [diff] [blame] | 6541 | rssi = ev->data[ev->length]; |
| 6542 | process_adv_report(hdev, ev->evt_type, &ev->bdaddr, |
| 6543 | ev->bdaddr_type, NULL, 0, rssi, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6544 | ev->data, ev->length, false); |
Chriz Chow | ee64934 | 2018-04-20 15:46:24 +0800 | [diff] [blame] | 6545 | } else { |
| 6546 | bt_dev_err(hdev, "Dropping invalid advertising data"); |
| 6547 | } |
Andre Guedes | 3c9e919 | 2012-01-10 18:20:50 -0300 | [diff] [blame] | 6548 | |
Andre Guedes | e95beb4 | 2011-09-26 20:48:35 -0300 | [diff] [blame] | 6549 | ptr += sizeof(*ev) + ev->length + 1; |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 6550 | } |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 6551 | |
| 6552 | hci_dev_unlock(hdev); |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 6553 | } |
| 6554 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 6555 | 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] | 6556 | { |
Jaganath Kanakkassery | b2cc976 | 2018-07-19 17:09:38 +0530 | [diff] [blame] | 6557 | if (evt_type & LE_EXT_ADV_LEGACY_PDU) { |
| 6558 | switch (evt_type) { |
| 6559 | case LE_LEGACY_ADV_IND: |
| 6560 | return LE_ADV_IND; |
| 6561 | case LE_LEGACY_ADV_DIRECT_IND: |
| 6562 | return LE_ADV_DIRECT_IND; |
| 6563 | case LE_LEGACY_ADV_SCAN_IND: |
| 6564 | return LE_ADV_SCAN_IND; |
| 6565 | case LE_LEGACY_NONCONN_IND: |
| 6566 | return LE_ADV_NONCONN_IND; |
| 6567 | case LE_LEGACY_SCAN_RSP_ADV: |
| 6568 | case LE_LEGACY_SCAN_RSP_ADV_SCAN: |
| 6569 | return LE_ADV_SCAN_RSP; |
| 6570 | } |
| 6571 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 6572 | goto invalid; |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 6573 | } |
| 6574 | |
Jaganath Kanakkassery | b2cc976 | 2018-07-19 17:09:38 +0530 | [diff] [blame] | 6575 | if (evt_type & LE_EXT_ADV_CONN_IND) { |
| 6576 | if (evt_type & LE_EXT_ADV_DIRECT_IND) |
| 6577 | return LE_ADV_DIRECT_IND; |
| 6578 | |
| 6579 | return LE_ADV_IND; |
| 6580 | } |
| 6581 | |
| 6582 | if (evt_type & LE_EXT_ADV_SCAN_RSP) |
| 6583 | return LE_ADV_SCAN_RSP; |
| 6584 | |
| 6585 | if (evt_type & LE_EXT_ADV_SCAN_IND) |
| 6586 | return LE_ADV_SCAN_IND; |
| 6587 | |
| 6588 | if (evt_type == LE_EXT_ADV_NON_CONN_IND || |
| 6589 | evt_type & LE_EXT_ADV_DIRECT_IND) |
| 6590 | return LE_ADV_NONCONN_IND; |
| 6591 | |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 6592 | invalid: |
| 6593 | bt_dev_err_ratelimited(hdev, "Unknown advertising packet type: 0x%02x", |
| 6594 | evt_type); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 6595 | |
| 6596 | return LE_ADV_INVALID; |
| 6597 | } |
| 6598 | |
| 6599 | static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 6600 | { |
| 6601 | u8 num_reports = skb->data[0]; |
| 6602 | void *ptr = &skb->data[1]; |
| 6603 | |
| 6604 | hci_dev_lock(hdev); |
| 6605 | |
| 6606 | while (num_reports--) { |
| 6607 | struct hci_ev_le_ext_adv_report *ev = ptr; |
| 6608 | u8 legacy_evt_type; |
| 6609 | u16 evt_type; |
| 6610 | |
| 6611 | evt_type = __le16_to_cpu(ev->evt_type); |
Marcel Holtmann | 657cc64 | 2019-12-11 11:34:36 +0100 | [diff] [blame] | 6612 | legacy_evt_type = ext_evt_type_to_legacy(hdev, evt_type); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 6613 | if (legacy_evt_type != LE_ADV_INVALID) { |
| 6614 | process_adv_report(hdev, legacy_evt_type, &ev->bdaddr, |
| 6615 | ev->bdaddr_type, NULL, 0, ev->rssi, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6616 | ev->data, ev->length, |
| 6617 | !(evt_type & LE_EXT_ADV_LEGACY_PDU)); |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 6618 | } |
| 6619 | |
Jaganath Kanakkassery | cd9151b | 2019-04-03 12:11:44 +0530 | [diff] [blame] | 6620 | ptr += sizeof(*ev) + ev->length; |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | hci_dev_unlock(hdev); |
| 6624 | } |
| 6625 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6626 | static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, |
| 6627 | struct sk_buff *skb) |
| 6628 | { |
| 6629 | struct hci_ev_le_remote_feat_complete *ev = (void *)skb->data; |
| 6630 | struct hci_conn *conn; |
| 6631 | |
| 6632 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 6633 | |
| 6634 | hci_dev_lock(hdev); |
| 6635 | |
| 6636 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 6637 | if (conn) { |
| 6638 | if (!ev->status) |
| 6639 | memcpy(conn->features[0], ev->features, 8); |
| 6640 | |
| 6641 | if (conn->state == BT_CONFIG) { |
| 6642 | __u8 status; |
| 6643 | |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 6644 | /* If the local controller supports peripheral-initiated |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6645 | * features exchange, but the remote controller does |
| 6646 | * not, then it is possible that the error code 0x1a |
| 6647 | * for unsupported remote feature gets returned. |
| 6648 | * |
| 6649 | * In this specific case, allow the connection to |
| 6650 | * transition into connected state and mark it as |
| 6651 | * successful. |
| 6652 | */ |
Archie Pusaka | ef365da | 2021-05-31 16:37:23 +0800 | [diff] [blame] | 6653 | if (!conn->out && ev->status == 0x1a && |
| 6654 | (hdev->le_features[0] & HCI_LE_PERIPHERAL_FEATURES)) |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6655 | status = 0x00; |
| 6656 | else |
| 6657 | status = ev->status; |
| 6658 | |
| 6659 | conn->state = BT_CONNECTED; |
| 6660 | hci_connect_cfm(conn, status); |
| 6661 | hci_conn_drop(conn); |
| 6662 | } |
| 6663 | } |
| 6664 | |
| 6665 | hci_dev_unlock(hdev); |
| 6666 | } |
| 6667 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 6668 | 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] | 6669 | { |
| 6670 | struct hci_ev_le_ltk_req *ev = (void *) skb->data; |
| 6671 | struct hci_cp_le_ltk_reply cp; |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 6672 | struct hci_cp_le_ltk_neg_reply neg; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6673 | struct hci_conn *conn; |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 6674 | struct smp_ltk *ltk; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6675 | |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 6676 | 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] | 6677 | |
| 6678 | hci_dev_lock(hdev); |
| 6679 | |
| 6680 | 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] | 6681 | if (conn == NULL) |
| 6682 | goto not_found; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6683 | |
Johan Hedberg | f3a73d9 | 2014-05-29 15:02:59 +0300 | [diff] [blame] | 6684 | ltk = hci_find_ltk(hdev, &conn->dst, conn->dst_type, conn->role); |
Johan Hedberg | 5378bc5 | 2014-05-29 14:00:39 +0300 | [diff] [blame] | 6685 | if (!ltk) |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 6686 | goto not_found; |
| 6687 | |
Johan Hedberg | 5378bc5 | 2014-05-29 14:00:39 +0300 | [diff] [blame] | 6688 | if (smp_ltk_is_sc(ltk)) { |
| 6689 | /* With SC both EDiv and Rand are set to zero */ |
| 6690 | if (ev->ediv || ev->rand) |
| 6691 | goto not_found; |
| 6692 | } else { |
| 6693 | /* For non-SC keys check that EDiv and Rand match */ |
| 6694 | if (ev->ediv != ltk->ediv || ev->rand != ltk->rand) |
| 6695 | goto not_found; |
| 6696 | } |
| 6697 | |
Johan Hedberg | 8b76ce3 | 2015-06-08 18:14:39 +0300 | [diff] [blame] | 6698 | memcpy(cp.ltk, ltk->val, ltk->enc_size); |
| 6699 | 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] | 6700 | cp.handle = cpu_to_le16(conn->handle); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 6701 | |
Johan Hedberg | a6f7833 | 2014-09-10 17:37:45 -0700 | [diff] [blame] | 6702 | conn->pending_sec_level = smp_ltk_sec_level(ltk); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6703 | |
Andre Guedes | 89cbb4d | 2013-07-31 16:25:29 -0300 | [diff] [blame] | 6704 | conn->enc_key_size = ltk->enc_size; |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6705 | |
| 6706 | hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp); |
| 6707 | |
Claudio Takahasi | 5981a88 | 2013-07-25 16:34:24 -0300 | [diff] [blame] | 6708 | /* Ref. Bluetooth Core SPEC pages 1975 and 2004. STK is a |
| 6709 | * temporary key used to encrypt a connection following |
| 6710 | * pairing. It is used during the Encrypted Session Setup to |
| 6711 | * distribute the keys. Later, security can be re-established |
| 6712 | * using a distributed LTK. |
| 6713 | */ |
Johan Hedberg | 2ceba53 | 2014-06-16 19:25:16 +0300 | [diff] [blame] | 6714 | if (ltk->type == SMP_STK) { |
Johan Hedberg | fe59a05 | 2014-07-01 19:14:12 +0300 | [diff] [blame] | 6715 | set_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); |
Johan Hedberg | 970d0f1 | 2014-11-13 14:37:47 +0200 | [diff] [blame] | 6716 | list_del_rcu(<k->list); |
| 6717 | kfree_rcu(ltk, rcu); |
Johan Hedberg | fe59a05 | 2014-07-01 19:14:12 +0300 | [diff] [blame] | 6718 | } else { |
| 6719 | clear_bit(HCI_CONN_STK_ENCRYPT, &conn->flags); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 6720 | } |
| 6721 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6722 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | bea710f | 2011-07-07 18:59:37 -0300 | [diff] [blame] | 6723 | |
| 6724 | return; |
| 6725 | |
| 6726 | not_found: |
| 6727 | neg.handle = ev->handle; |
| 6728 | hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg); |
| 6729 | hci_dev_unlock(hdev); |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6730 | } |
| 6731 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 6732 | static void send_conn_param_neg_reply(struct hci_dev *hdev, u16 handle, |
| 6733 | u8 reason) |
| 6734 | { |
| 6735 | struct hci_cp_le_conn_param_req_neg_reply cp; |
| 6736 | |
| 6737 | cp.handle = cpu_to_le16(handle); |
| 6738 | cp.reason = reason; |
| 6739 | |
| 6740 | hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY, sizeof(cp), |
| 6741 | &cp); |
| 6742 | } |
| 6743 | |
| 6744 | static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, |
| 6745 | struct sk_buff *skb) |
| 6746 | { |
| 6747 | struct hci_ev_le_remote_conn_param_req *ev = (void *) skb->data; |
| 6748 | struct hci_cp_le_conn_param_req_reply cp; |
| 6749 | struct hci_conn *hcon; |
| 6750 | u16 handle, min, max, latency, timeout; |
| 6751 | |
| 6752 | handle = le16_to_cpu(ev->handle); |
| 6753 | min = le16_to_cpu(ev->interval_min); |
| 6754 | max = le16_to_cpu(ev->interval_max); |
| 6755 | latency = le16_to_cpu(ev->latency); |
| 6756 | timeout = le16_to_cpu(ev->timeout); |
| 6757 | |
| 6758 | hcon = hci_conn_hash_lookup_handle(hdev, handle); |
| 6759 | if (!hcon || hcon->state != BT_CONNECTED) |
| 6760 | return send_conn_param_neg_reply(hdev, handle, |
| 6761 | HCI_ERROR_UNKNOWN_CONN_ID); |
| 6762 | |
| 6763 | if (hci_check_conn_params(min, max, latency, timeout)) |
| 6764 | return send_conn_param_neg_reply(hdev, handle, |
| 6765 | HCI_ERROR_INVALID_LL_PARAMS); |
| 6766 | |
Johan Hedberg | 40bef30 | 2014-07-16 11:42:27 +0300 | [diff] [blame] | 6767 | if (hcon->role == HCI_ROLE_MASTER) { |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 6768 | struct hci_conn_params *params; |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 6769 | u8 store_hint; |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 6770 | |
| 6771 | hci_dev_lock(hdev); |
| 6772 | |
| 6773 | params = hci_conn_params_lookup(hdev, &hcon->dst, |
| 6774 | hcon->dst_type); |
| 6775 | if (params) { |
| 6776 | params->conn_min_interval = min; |
| 6777 | params->conn_max_interval = max; |
| 6778 | params->conn_latency = latency; |
| 6779 | params->supervision_timeout = timeout; |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 6780 | store_hint = 0x01; |
Meng Yu | 149b3f1 | 2021-04-01 14:50:39 +0800 | [diff] [blame] | 6781 | } else { |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 6782 | store_hint = 0x00; |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 6783 | } |
| 6784 | |
| 6785 | hci_dev_unlock(hdev); |
| 6786 | |
Johan Hedberg | f4869e2 | 2014-07-02 17:37:32 +0300 | [diff] [blame] | 6787 | mgmt_new_conn_param(hdev, &hcon->dst, hcon->dst_type, |
| 6788 | store_hint, min, max, latency, timeout); |
Johan Hedberg | 348d50b | 2014-07-02 17:37:30 +0300 | [diff] [blame] | 6789 | } |
Andre Guedes | ffb5a827 | 2014-07-01 18:10:11 -0300 | [diff] [blame] | 6790 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 6791 | cp.handle = ev->handle; |
| 6792 | cp.interval_min = ev->interval_min; |
| 6793 | cp.interval_max = ev->interval_max; |
| 6794 | cp.latency = ev->latency; |
| 6795 | cp.timeout = ev->timeout; |
| 6796 | cp.min_ce_len = 0; |
| 6797 | cp.max_ce_len = 0; |
| 6798 | |
| 6799 | hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp); |
| 6800 | } |
| 6801 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6802 | static void hci_le_direct_adv_report_evt(struct hci_dev *hdev, |
| 6803 | struct sk_buff *skb) |
| 6804 | { |
| 6805 | u8 num_reports = skb->data[0]; |
Peilin Ye | f7e0e8b | 2020-09-09 03:17:00 -0400 | [diff] [blame] | 6806 | struct hci_ev_le_direct_adv_info *ev = (void *)&skb->data[1]; |
| 6807 | |
| 6808 | if (!num_reports || skb->len < num_reports * sizeof(*ev) + 1) |
| 6809 | return; |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6810 | |
| 6811 | hci_dev_lock(hdev); |
| 6812 | |
Peilin Ye | f7e0e8b | 2020-09-09 03:17:00 -0400 | [diff] [blame] | 6813 | for (; num_reports; num_reports--, ev++) |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6814 | process_adv_report(hdev, ev->evt_type, &ev->bdaddr, |
| 6815 | ev->bdaddr_type, &ev->direct_addr, |
Alain Michaud | a2ec905 | 2020-07-27 20:48:55 +0000 | [diff] [blame] | 6816 | ev->direct_addr_type, ev->rssi, NULL, 0, |
| 6817 | false); |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6818 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6819 | hci_dev_unlock(hdev); |
| 6820 | } |
| 6821 | |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 6822 | static void hci_le_phy_update_evt(struct hci_dev *hdev, struct sk_buff *skb) |
| 6823 | { |
| 6824 | struct hci_ev_le_phy_update_complete *ev = (void *) skb->data; |
| 6825 | struct hci_conn *conn; |
| 6826 | |
| 6827 | BT_DBG("%s status 0x%2.2x", hdev->name, ev->status); |
| 6828 | |
Ayush Garg | 87df8bc | 2021-03-17 16:52:14 +0530 | [diff] [blame] | 6829 | if (ev->status) |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 6830 | return; |
| 6831 | |
| 6832 | hci_dev_lock(hdev); |
| 6833 | |
| 6834 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
| 6835 | if (!conn) |
| 6836 | goto unlock; |
| 6837 | |
| 6838 | conn->le_tx_phy = ev->tx_phy; |
| 6839 | conn->le_rx_phy = ev->rx_phy; |
| 6840 | |
| 6841 | unlock: |
| 6842 | hci_dev_unlock(hdev); |
| 6843 | } |
| 6844 | |
Gustavo Padovan | 6039aa7 | 2012-05-23 04:04:18 -0300 | [diff] [blame] | 6845 | 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] | 6846 | { |
| 6847 | struct hci_ev_le_meta *le_ev = (void *) skb->data; |
| 6848 | |
| 6849 | skb_pull(skb, sizeof(*le_ev)); |
| 6850 | |
| 6851 | switch (le_ev->subevent) { |
| 6852 | case HCI_EV_LE_CONN_COMPLETE: |
| 6853 | hci_le_conn_complete_evt(hdev, skb); |
| 6854 | break; |
| 6855 | |
Marcel Holtmann | 1855d92 | 2014-06-23 11:40:05 +0200 | [diff] [blame] | 6856 | case HCI_EV_LE_CONN_UPDATE_COMPLETE: |
| 6857 | hci_le_conn_update_complete_evt(hdev, skb); |
| 6858 | break; |
| 6859 | |
Andre Guedes | 9aa04c9 | 2011-05-26 16:23:51 -0300 | [diff] [blame] | 6860 | case HCI_EV_LE_ADVERTISING_REPORT: |
| 6861 | hci_le_adv_report_evt(hdev, skb); |
| 6862 | break; |
| 6863 | |
Marcel Holtmann | 0fe29fd | 2015-04-08 09:05:27 -0700 | [diff] [blame] | 6864 | case HCI_EV_LE_REMOTE_FEAT_COMPLETE: |
| 6865 | hci_le_remote_feat_complete_evt(hdev, skb); |
| 6866 | break; |
| 6867 | |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 6868 | case HCI_EV_LE_LTK_REQ: |
| 6869 | hci_le_ltk_request_evt(hdev, skb); |
| 6870 | break; |
| 6871 | |
Andre Guedes | 8e75b46 | 2014-07-01 18:10:08 -0300 | [diff] [blame] | 6872 | case HCI_EV_LE_REMOTE_CONN_PARAM_REQ: |
| 6873 | hci_le_remote_conn_param_req_evt(hdev, skb); |
| 6874 | break; |
| 6875 | |
Marcel Holtmann | 2f010b5 | 2014-12-05 16:20:13 +0100 | [diff] [blame] | 6876 | case HCI_EV_LE_DIRECT_ADV_REPORT: |
| 6877 | hci_le_direct_adv_report_evt(hdev, skb); |
| 6878 | break; |
| 6879 | |
Luiz Augusto von Dentz | 1efd927 | 2020-01-02 15:00:55 -0800 | [diff] [blame] | 6880 | case HCI_EV_LE_PHY_UPDATE_COMPLETE: |
| 6881 | hci_le_phy_update_evt(hdev, skb); |
| 6882 | break; |
| 6883 | |
Jaganath Kanakkassery | c215e93 | 2018-07-06 17:05:29 +0530 | [diff] [blame] | 6884 | case HCI_EV_LE_EXT_ADV_REPORT: |
| 6885 | hci_le_ext_adv_report_evt(hdev, skb); |
| 6886 | break; |
| 6887 | |
Jaganath Kanakkassery | 4d94f95 | 2018-07-06 22:50:32 +0200 | [diff] [blame] | 6888 | case HCI_EV_LE_ENHANCED_CONN_COMPLETE: |
| 6889 | hci_le_enh_conn_complete_evt(hdev, skb); |
| 6890 | break; |
| 6891 | |
Jaganath Kanakkassery | acf0aea | 2018-07-19 17:09:46 +0530 | [diff] [blame] | 6892 | case HCI_EV_LE_EXT_ADV_SET_TERM: |
| 6893 | hci_le_ext_adv_term_evt(hdev, skb); |
| 6894 | break; |
| 6895 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 6896 | default: |
| 6897 | break; |
| 6898 | } |
| 6899 | } |
| 6900 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6901 | static bool hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode, |
| 6902 | u8 event, struct sk_buff *skb) |
| 6903 | { |
| 6904 | struct hci_ev_cmd_complete *ev; |
| 6905 | struct hci_event_hdr *hdr; |
| 6906 | |
| 6907 | if (!skb) |
| 6908 | return false; |
| 6909 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 6910 | hdr = hci_ev_skb_pull(hdev, skb, event, sizeof(*hdr)); |
| 6911 | if (!hdr) |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6912 | return false; |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6913 | |
| 6914 | if (event) { |
| 6915 | if (hdr->evt != event) |
| 6916 | return false; |
| 6917 | return true; |
| 6918 | } |
| 6919 | |
Zheng Yongjun | 91641b7 | 2021-06-02 14:54:58 +0800 | [diff] [blame] | 6920 | /* Check if request ended in Command Status - no way to retrieve |
Johan Hedberg | 1629db9c | 2018-11-27 11:37:46 +0200 | [diff] [blame] | 6921 | * any extra parameters in this case. |
| 6922 | */ |
| 6923 | if (hdr->evt == HCI_EV_CMD_STATUS) |
| 6924 | return false; |
| 6925 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6926 | if (hdr->evt != HCI_EV_CMD_COMPLETE) { |
Marcel Holtmann | 2064ee3 | 2017-10-30 10:42:59 +0100 | [diff] [blame] | 6927 | bt_dev_err(hdev, "last event is not cmd complete (0x%2.2x)", |
| 6928 | hdr->evt); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6929 | return false; |
| 6930 | } |
| 6931 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 6932 | ev = hci_cc_skb_pull(hdev, skb, opcode, sizeof(*ev)); |
| 6933 | if (!ev) |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6934 | return false; |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 6935 | |
| 6936 | if (opcode != __le16_to_cpu(ev->opcode)) { |
| 6937 | BT_DBG("opcode doesn't match (0x%2.2x != 0x%2.2x)", opcode, |
| 6938 | __le16_to_cpu(ev->opcode)); |
| 6939 | return false; |
| 6940 | } |
| 6941 | |
| 6942 | return true; |
| 6943 | } |
| 6944 | |
Abhishek Pandit-Subedi | 2f20216 | 2020-09-11 14:07:13 -0700 | [diff] [blame] | 6945 | static void hci_store_wake_reason(struct hci_dev *hdev, u8 event, |
| 6946 | struct sk_buff *skb) |
| 6947 | { |
| 6948 | struct hci_ev_le_advertising_info *adv; |
| 6949 | struct hci_ev_le_direct_adv_info *direct_adv; |
| 6950 | struct hci_ev_le_ext_adv_report *ext_adv; |
| 6951 | const struct hci_ev_conn_complete *conn_complete = (void *)skb->data; |
| 6952 | const struct hci_ev_conn_request *conn_request = (void *)skb->data; |
| 6953 | |
| 6954 | hci_dev_lock(hdev); |
| 6955 | |
| 6956 | /* If we are currently suspended and this is the first BT event seen, |
| 6957 | * save the wake reason associated with the event. |
| 6958 | */ |
| 6959 | if (!hdev->suspended || hdev->wake_reason) |
| 6960 | goto unlock; |
| 6961 | |
| 6962 | /* Default to remote wake. Values for wake_reason are documented in the |
| 6963 | * Bluez mgmt api docs. |
| 6964 | */ |
| 6965 | hdev->wake_reason = MGMT_WAKE_REASON_REMOTE_WAKE; |
| 6966 | |
| 6967 | /* Once configured for remote wakeup, we should only wake up for |
| 6968 | * reconnections. It's useful to see which device is waking us up so |
| 6969 | * keep track of the bdaddr of the connection event that woke us up. |
| 6970 | */ |
| 6971 | if (event == HCI_EV_CONN_REQUEST) { |
| 6972 | bacpy(&hdev->wake_addr, &conn_complete->bdaddr); |
| 6973 | hdev->wake_addr_type = BDADDR_BREDR; |
| 6974 | } else if (event == HCI_EV_CONN_COMPLETE) { |
| 6975 | bacpy(&hdev->wake_addr, &conn_request->bdaddr); |
| 6976 | hdev->wake_addr_type = BDADDR_BREDR; |
| 6977 | } else if (event == HCI_EV_LE_META) { |
| 6978 | struct hci_ev_le_meta *le_ev = (void *)skb->data; |
| 6979 | u8 subevent = le_ev->subevent; |
| 6980 | u8 *ptr = &skb->data[sizeof(*le_ev)]; |
| 6981 | u8 num_reports = *ptr; |
| 6982 | |
| 6983 | if ((subevent == HCI_EV_LE_ADVERTISING_REPORT || |
| 6984 | subevent == HCI_EV_LE_DIRECT_ADV_REPORT || |
| 6985 | subevent == HCI_EV_LE_EXT_ADV_REPORT) && |
| 6986 | num_reports) { |
| 6987 | adv = (void *)(ptr + 1); |
| 6988 | direct_adv = (void *)(ptr + 1); |
| 6989 | ext_adv = (void *)(ptr + 1); |
| 6990 | |
| 6991 | switch (subevent) { |
| 6992 | case HCI_EV_LE_ADVERTISING_REPORT: |
| 6993 | bacpy(&hdev->wake_addr, &adv->bdaddr); |
| 6994 | hdev->wake_addr_type = adv->bdaddr_type; |
| 6995 | break; |
| 6996 | case HCI_EV_LE_DIRECT_ADV_REPORT: |
| 6997 | bacpy(&hdev->wake_addr, &direct_adv->bdaddr); |
| 6998 | hdev->wake_addr_type = direct_adv->bdaddr_type; |
| 6999 | break; |
| 7000 | case HCI_EV_LE_EXT_ADV_REPORT: |
| 7001 | bacpy(&hdev->wake_addr, &ext_adv->bdaddr); |
| 7002 | hdev->wake_addr_type = ext_adv->bdaddr_type; |
| 7003 | break; |
| 7004 | } |
| 7005 | } |
| 7006 | } else { |
| 7007 | hdev->wake_reason = MGMT_WAKE_REASON_UNEXPECTED; |
| 7008 | } |
| 7009 | |
| 7010 | unlock: |
| 7011 | hci_dev_unlock(hdev); |
| 7012 | } |
| 7013 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7014 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) |
| 7015 | { |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7016 | struct hci_event_hdr *hdr = (void *) skb->data; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7017 | hci_req_complete_t req_complete = NULL; |
| 7018 | hci_req_complete_skb_t req_complete_skb = NULL; |
| 7019 | struct sk_buff *orig_skb = NULL; |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 7020 | u8 status = 0, event, req_evt = 0; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7021 | u16 opcode = HCI_OP_NOP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7022 | |
Luiz Augusto von Dentz | e3f3a1a | 2021-12-01 10:54:54 -0800 | [diff] [blame] | 7023 | if (skb->len < sizeof(*hdr)) { |
| 7024 | bt_dev_err(hdev, "Malformed HCI Event"); |
| 7025 | goto done; |
| 7026 | } |
| 7027 | |
| 7028 | event = hdr->evt; |
Alain Michaud | 08bb4da | 2020-03-03 15:55:34 +0000 | [diff] [blame] | 7029 | if (!event) { |
| 7030 | bt_dev_warn(hdev, "Received unexpected HCI Event 00000000"); |
| 7031 | goto done; |
| 7032 | } |
| 7033 | |
Marcel Holtmann | 242c0eb | 2015-10-25 22:45:53 +0100 | [diff] [blame] | 7034 | 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] | 7035 | struct hci_command_hdr *cmd_hdr = (void *) hdev->sent_cmd->data; |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7036 | opcode = __le16_to_cpu(cmd_hdr->opcode); |
| 7037 | hci_req_cmd_complete(hdev, opcode, status, &req_complete, |
| 7038 | &req_complete_skb); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 7039 | req_evt = event; |
Johan Hedberg | 02350a7 | 2013-04-03 21:50:29 +0300 | [diff] [blame] | 7040 | } |
| 7041 | |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7042 | /* If it looks like we might end up having to call |
| 7043 | * req_complete_skb, store a pristine copy of the skb since the |
| 7044 | * various handlers may modify the original one through |
| 7045 | * skb_pull() calls, etc. |
| 7046 | */ |
| 7047 | if (req_complete_skb || event == HCI_EV_CMD_STATUS || |
| 7048 | event == HCI_EV_CMD_COMPLETE) |
| 7049 | orig_skb = skb_clone(skb, GFP_KERNEL); |
| 7050 | |
| 7051 | skb_pull(skb, HCI_EVENT_HDR_SIZE); |
| 7052 | |
Abhishek Pandit-Subedi | 2f20216 | 2020-09-11 14:07:13 -0700 | [diff] [blame] | 7053 | /* Store wake reason if we're suspended */ |
| 7054 | hci_store_wake_reason(hdev, event, skb); |
| 7055 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7056 | switch (event) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7057 | case HCI_EV_INQUIRY_COMPLETE: |
| 7058 | hci_inquiry_complete_evt(hdev, skb); |
| 7059 | break; |
| 7060 | |
| 7061 | case HCI_EV_INQUIRY_RESULT: |
| 7062 | hci_inquiry_result_evt(hdev, skb); |
| 7063 | break; |
| 7064 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7065 | case HCI_EV_CONN_COMPLETE: |
| 7066 | hci_conn_complete_evt(hdev, skb); |
Marcel Holtmann | 21d9e30 | 2005-09-13 01:32:25 +0200 | [diff] [blame] | 7067 | break; |
| 7068 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7069 | case HCI_EV_CONN_REQUEST: |
| 7070 | hci_conn_request_evt(hdev, skb); |
| 7071 | break; |
| 7072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7073 | case HCI_EV_DISCONN_COMPLETE: |
| 7074 | hci_disconn_complete_evt(hdev, skb); |
| 7075 | break; |
| 7076 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7077 | case HCI_EV_AUTH_COMPLETE: |
| 7078 | hci_auth_complete_evt(hdev, skb); |
| 7079 | break; |
| 7080 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7081 | case HCI_EV_REMOTE_NAME: |
| 7082 | hci_remote_name_evt(hdev, skb); |
| 7083 | break; |
| 7084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7085 | case HCI_EV_ENCRYPT_CHANGE: |
| 7086 | hci_encrypt_change_evt(hdev, skb); |
| 7087 | break; |
| 7088 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7089 | case HCI_EV_CHANGE_LINK_KEY_COMPLETE: |
| 7090 | hci_change_link_key_complete_evt(hdev, skb); |
| 7091 | break; |
| 7092 | |
| 7093 | case HCI_EV_REMOTE_FEATURES: |
| 7094 | hci_remote_features_evt(hdev, skb); |
| 7095 | break; |
| 7096 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7097 | case HCI_EV_CMD_COMPLETE: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7098 | hci_cmd_complete_evt(hdev, skb, &opcode, &status, |
| 7099 | &req_complete, &req_complete_skb); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7100 | break; |
| 7101 | |
| 7102 | case HCI_EV_CMD_STATUS: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7103 | hci_cmd_status_evt(hdev, skb, &opcode, &status, &req_complete, |
| 7104 | &req_complete_skb); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7105 | break; |
| 7106 | |
Marcel Holtmann | 24dfa34 | 2014-11-02 02:56:41 +0100 | [diff] [blame] | 7107 | case HCI_EV_HARDWARE_ERROR: |
| 7108 | hci_hardware_error_evt(hdev, skb); |
| 7109 | break; |
| 7110 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7111 | case HCI_EV_ROLE_CHANGE: |
| 7112 | hci_role_change_evt(hdev, skb); |
| 7113 | break; |
| 7114 | |
| 7115 | case HCI_EV_NUM_COMP_PKTS: |
| 7116 | hci_num_comp_pkts_evt(hdev, skb); |
| 7117 | break; |
| 7118 | |
| 7119 | case HCI_EV_MODE_CHANGE: |
| 7120 | hci_mode_change_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7121 | break; |
| 7122 | |
| 7123 | case HCI_EV_PIN_CODE_REQ: |
| 7124 | hci_pin_code_request_evt(hdev, skb); |
| 7125 | break; |
| 7126 | |
| 7127 | case HCI_EV_LINK_KEY_REQ: |
| 7128 | hci_link_key_request_evt(hdev, skb); |
| 7129 | break; |
| 7130 | |
| 7131 | case HCI_EV_LINK_KEY_NOTIFY: |
| 7132 | hci_link_key_notify_evt(hdev, skb); |
| 7133 | break; |
| 7134 | |
| 7135 | case HCI_EV_CLOCK_OFFSET: |
| 7136 | hci_clock_offset_evt(hdev, skb); |
| 7137 | break; |
| 7138 | |
Marcel Holtmann | a874641 | 2008-07-14 20:13:46 +0200 | [diff] [blame] | 7139 | case HCI_EV_PKT_TYPE_CHANGE: |
| 7140 | hci_pkt_type_change_evt(hdev, skb); |
| 7141 | break; |
| 7142 | |
Marcel Holtmann | 85a1e93 | 2005-08-09 20:28:02 -0700 | [diff] [blame] | 7143 | case HCI_EV_PSCAN_REP_MODE: |
| 7144 | hci_pscan_rep_mode_evt(hdev, skb); |
| 7145 | break; |
| 7146 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7147 | case HCI_EV_INQUIRY_RESULT_WITH_RSSI: |
| 7148 | hci_inquiry_result_with_rssi_evt(hdev, skb); |
| 7149 | break; |
| 7150 | |
| 7151 | case HCI_EV_REMOTE_EXT_FEATURES: |
| 7152 | hci_remote_ext_features_evt(hdev, skb); |
| 7153 | break; |
| 7154 | |
| 7155 | case HCI_EV_SYNC_CONN_COMPLETE: |
| 7156 | hci_sync_conn_complete_evt(hdev, skb); |
| 7157 | break; |
| 7158 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7159 | case HCI_EV_EXTENDED_INQUIRY_RESULT: |
| 7160 | hci_extended_inquiry_result_evt(hdev, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7161 | break; |
| 7162 | |
Johan Hedberg | 1c2e004 | 2012-06-08 23:31:13 +0800 | [diff] [blame] | 7163 | case HCI_EV_KEY_REFRESH_COMPLETE: |
| 7164 | hci_key_refresh_complete_evt(hdev, skb); |
| 7165 | break; |
| 7166 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 7167 | case HCI_EV_IO_CAPA_REQUEST: |
| 7168 | hci_io_capa_request_evt(hdev, skb); |
| 7169 | break; |
| 7170 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 7171 | case HCI_EV_IO_CAPA_REPLY: |
| 7172 | hci_io_capa_reply_evt(hdev, skb); |
| 7173 | break; |
| 7174 | |
Johan Hedberg | a5c2968 | 2011-02-19 12:05:57 -0300 | [diff] [blame] | 7175 | case HCI_EV_USER_CONFIRM_REQUEST: |
| 7176 | hci_user_confirm_request_evt(hdev, skb); |
| 7177 | break; |
| 7178 | |
Brian Gix | 1143d45 | 2011-11-23 08:28:34 -0800 | [diff] [blame] | 7179 | case HCI_EV_USER_PASSKEY_REQUEST: |
| 7180 | hci_user_passkey_request_evt(hdev, skb); |
| 7181 | break; |
| 7182 | |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 7183 | case HCI_EV_USER_PASSKEY_NOTIFY: |
| 7184 | hci_user_passkey_notify_evt(hdev, skb); |
| 7185 | break; |
| 7186 | |
| 7187 | case HCI_EV_KEYPRESS_NOTIFY: |
| 7188 | hci_keypress_notify_evt(hdev, skb); |
| 7189 | break; |
| 7190 | |
Marcel Holtmann | 0493684 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 7191 | case HCI_EV_SIMPLE_PAIR_COMPLETE: |
| 7192 | hci_simple_pair_complete_evt(hdev, skb); |
| 7193 | break; |
| 7194 | |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 7195 | case HCI_EV_REMOTE_HOST_FEATURES: |
| 7196 | hci_remote_host_features_evt(hdev, skb); |
| 7197 | break; |
| 7198 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 7199 | case HCI_EV_LE_META: |
| 7200 | hci_le_meta_evt(hdev, skb); |
| 7201 | break; |
| 7202 | |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 7203 | case HCI_EV_REMOTE_OOB_DATA_REQUEST: |
| 7204 | hci_remote_oob_data_request_evt(hdev, skb); |
| 7205 | break; |
| 7206 | |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 7207 | #if IS_ENABLED(CONFIG_BT_HS) |
| 7208 | case HCI_EV_CHANNEL_SELECTED: |
| 7209 | hci_chan_selected_evt(hdev, skb); |
| 7210 | break; |
| 7211 | |
Andrei Emeltchenko | d5e9119 | 2012-10-25 15:20:44 +0300 | [diff] [blame] | 7212 | case HCI_EV_PHY_LINK_COMPLETE: |
| 7213 | hci_phy_link_complete_evt(hdev, skb); |
| 7214 | break; |
| 7215 | |
Andrei Emeltchenko | 27695fb | 2012-10-25 15:20:45 +0300 | [diff] [blame] | 7216 | case HCI_EV_LOGICAL_LINK_COMPLETE: |
| 7217 | hci_loglink_complete_evt(hdev, skb); |
| 7218 | break; |
| 7219 | |
Andrei Emeltchenko | 606e2a1 | 2012-10-31 15:46:31 +0200 | [diff] [blame] | 7220 | case HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE: |
| 7221 | hci_disconn_loglink_complete_evt(hdev, skb); |
| 7222 | break; |
| 7223 | |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 7224 | case HCI_EV_DISCONN_PHY_LINK_COMPLETE: |
| 7225 | hci_disconn_phylink_complete_evt(hdev, skb); |
| 7226 | break; |
Arron Wang | a77a6a1 | 2015-07-24 17:13:15 +0800 | [diff] [blame] | 7227 | #endif |
Andrei Emeltchenko | 9eef6b3 | 2012-10-31 15:46:32 +0200 | [diff] [blame] | 7228 | |
Andrei Emeltchenko | 25e89e9 | 2012-01-04 12:41:58 +0200 | [diff] [blame] | 7229 | case HCI_EV_NUM_COMP_BLOCKS: |
| 7230 | hci_num_comp_blocks_evt(hdev, skb); |
| 7231 | break; |
| 7232 | |
Miao-chen Chou | 145373c | 2020-04-03 21:44:01 +0200 | [diff] [blame] | 7233 | case HCI_EV_VENDOR: |
| 7234 | msft_vendor_evt(hdev, skb); |
| 7235 | break; |
| 7236 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 7237 | default: |
Andrei Emeltchenko | 9f1db00 | 2012-07-11 14:32:43 +0300 | [diff] [blame] | 7238 | BT_DBG("%s event 0x%2.2x", hdev->name, event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7239 | break; |
| 7240 | } |
| 7241 | |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 7242 | if (req_complete) { |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7243 | req_complete(hdev, status, opcode); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 7244 | } else if (req_complete_skb) { |
| 7245 | if (!hci_get_cmd_complete(hdev, opcode, req_evt, orig_skb)) { |
| 7246 | kfree_skb(orig_skb); |
| 7247 | orig_skb = NULL; |
| 7248 | } |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7249 | req_complete_skb(hdev, status, opcode, orig_skb); |
Johan Hedberg | 757aa0b | 2015-04-02 13:41:12 +0300 | [diff] [blame] | 7250 | } |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7251 | |
Alain Michaud | 08bb4da | 2020-03-03 15:55:34 +0000 | [diff] [blame] | 7252 | done: |
Johan Hedberg | e6214487 | 2015-04-02 13:41:08 +0300 | [diff] [blame] | 7253 | kfree_skb(orig_skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7254 | kfree_skb(skb); |
| 7255 | hdev->stat.evt_rx++; |
| 7256 | } |