Ron Shaffer | 04fafe4 | 2010-05-28 11:53:45 -0400 | [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 |
Ron Shaffer | 04fafe4 | 2010-05-28 11:53:45 -0400 | [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 | |
Ron Shaffer | 04fafe4 | 2010-05-28 11:53:45 -0400 | [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 | #ifndef __HCI_CORE_H |
| 26 | #define __HCI_CORE_H |
| 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <net/bluetooth/hci.h> |
| 29 | |
Luiz Augusto von Dentz | 5e59b79 | 2011-11-01 10:58:57 +0200 | [diff] [blame] | 30 | /* HCI priority */ |
| 31 | #define HCI_PRIO_MAX 7 |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | /* HCI Core structures */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | struct inquiry_data { |
| 35 | bdaddr_t bdaddr; |
| 36 | __u8 pscan_rep_mode; |
| 37 | __u8 pscan_period_mode; |
| 38 | __u8 pscan_mode; |
| 39 | __u8 dev_class[3]; |
Marcel Holtmann | 1ebb925 | 2005-11-08 09:57:21 -0800 | [diff] [blame] | 40 | __le16 clock_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | __s8 rssi; |
Marcel Holtmann | 41a9621 | 2008-07-14 20:13:48 +0200 | [diff] [blame] | 42 | __u8 ssp_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | struct inquiry_entry { |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 46 | struct list_head all; /* inq_cache.all */ |
| 47 | struct list_head list; /* unknown or resolve */ |
| 48 | enum { |
| 49 | NAME_NOT_KNOWN, |
| 50 | NAME_NEEDED, |
| 51 | NAME_PENDING, |
| 52 | NAME_KNOWN, |
| 53 | } name_state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | __u32 timestamp; |
| 55 | struct inquiry_data data; |
| 56 | }; |
| 57 | |
Johan Hedberg | 3088351 | 2012-01-04 14:16:21 +0200 | [diff] [blame] | 58 | struct discovery_state { |
Gustavo F. Padovan | f64b993 | 2012-03-06 23:48:33 -0300 | [diff] [blame] | 59 | int type; |
Johan Hedberg | ff9ef57 | 2012-01-04 14:23:45 +0200 | [diff] [blame] | 60 | enum { |
| 61 | DISCOVERY_STOPPED, |
| 62 | DISCOVERY_STARTING, |
Andre Guedes | 343f935 | 2012-02-17 20:39:37 -0300 | [diff] [blame] | 63 | DISCOVERY_FINDING, |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 64 | DISCOVERY_RESOLVING, |
Johan Hedberg | ff9ef57 | 2012-01-04 14:23:45 +0200 | [diff] [blame] | 65 | DISCOVERY_STOPPING, |
| 66 | } state; |
Gustavo Padovan | c3c7ea6 | 2012-05-23 04:04:20 -0300 | [diff] [blame] | 67 | struct list_head all; /* All devices found during inquiry */ |
Gustavo F. Padovan | f64b993 | 2012-03-06 23:48:33 -0300 | [diff] [blame] | 68 | struct list_head unknown; /* Name state not known */ |
| 69 | struct list_head resolve; /* Name needs to be resolved */ |
| 70 | __u32 timestamp; |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 71 | bdaddr_t last_adv_addr; |
| 72 | u8 last_adv_addr_type; |
Johan Hedberg | ff5cd29 | 2014-03-25 14:40:52 +0200 | [diff] [blame] | 73 | s8 last_adv_rssi; |
Marcel Holtmann | c70a7e4 | 2014-07-01 14:11:21 +0200 | [diff] [blame] | 74 | u32 last_adv_flags; |
Johan Hedberg | b9a6328 | 2014-03-25 10:51:52 +0200 | [diff] [blame] | 75 | u8 last_adv_data[HCI_MAX_AD_LENGTH]; |
| 76 | u8 last_adv_data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | struct hci_conn_hash { |
| 80 | struct list_head list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | unsigned int acl_num; |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 82 | unsigned int amp_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | unsigned int sco_num; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 84 | unsigned int le_num; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
Johan Hedberg | f035856 | 2010-05-18 13:20:32 +0200 | [diff] [blame] | 87 | struct bdaddr_list { |
| 88 | struct list_head list; |
| 89 | bdaddr_t bdaddr; |
Marcel Holtmann | b9ee0a7 | 2013-10-17 17:24:13 -0700 | [diff] [blame] | 90 | u8 bdaddr_type; |
Johan Hedberg | f035856 | 2010-05-18 13:20:32 +0200 | [diff] [blame] | 91 | }; |
Johan Hedberg | 2aeb9a1 | 2011-01-04 12:08:51 +0200 | [diff] [blame] | 92 | |
| 93 | struct bt_uuid { |
| 94 | struct list_head list; |
| 95 | u8 uuid[16]; |
Johan Hedberg | 83be8ec | 2013-01-27 00:31:29 +0200 | [diff] [blame] | 96 | u8 size; |
Johan Hedberg | 1aff6f0 | 2011-01-13 21:56:52 +0200 | [diff] [blame] | 97 | u8 svc_hint; |
Johan Hedberg | 2aeb9a1 | 2011-01-04 12:08:51 +0200 | [diff] [blame] | 98 | }; |
| 99 | |
Marcel Holtmann | 7ee4ea3 | 2014-03-09 12:19:17 -0700 | [diff] [blame] | 100 | struct smp_csrk { |
| 101 | bdaddr_t bdaddr; |
| 102 | u8 bdaddr_type; |
| 103 | u8 master; |
| 104 | u8 val[16]; |
| 105 | }; |
| 106 | |
Vinicius Costa Gomes | b899efa | 2012-02-02 21:08:00 -0300 | [diff] [blame] | 107 | struct smp_ltk { |
| 108 | struct list_head list; |
| 109 | bdaddr_t bdaddr; |
| 110 | u8 bdaddr_type; |
| 111 | u8 authenticated; |
| 112 | u8 type; |
| 113 | u8 enc_size; |
| 114 | __le16 ediv; |
Marcel Holtmann | fe39c7b | 2014-02-27 16:00:28 -0800 | [diff] [blame] | 115 | __le64 rand; |
Vinicius Costa Gomes | b899efa | 2012-02-02 21:08:00 -0300 | [diff] [blame] | 116 | u8 val[16]; |
Marcel Holtmann | 03c515d | 2014-01-31 18:42:18 -0800 | [diff] [blame] | 117 | }; |
Vinicius Costa Gomes | b899efa | 2012-02-02 21:08:00 -0300 | [diff] [blame] | 118 | |
Johan Hedberg | 970c4e4 | 2014-02-18 10:19:33 +0200 | [diff] [blame] | 119 | struct smp_irk { |
| 120 | struct list_head list; |
| 121 | bdaddr_t rpa; |
| 122 | bdaddr_t bdaddr; |
| 123 | u8 addr_type; |
| 124 | u8 val[16]; |
| 125 | }; |
| 126 | |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 127 | struct link_key { |
| 128 | struct list_head list; |
| 129 | bdaddr_t bdaddr; |
| 130 | u8 type; |
Andrei Emeltchenko | 9b3b446 | 2012-05-23 11:31:20 +0300 | [diff] [blame] | 131 | u8 val[HCI_LINK_KEY_SIZE]; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 132 | u8 pin_len; |
| 133 | }; |
| 134 | |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 135 | struct oob_data { |
| 136 | struct list_head list; |
| 137 | bdaddr_t bdaddr; |
Marcel Holtmann | 519ca9d | 2014-01-10 02:07:28 -0800 | [diff] [blame] | 138 | u8 hash192[16]; |
| 139 | u8 randomizer192[16]; |
| 140 | u8 hash256[16]; |
| 141 | u8 randomizer256[16]; |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 142 | }; |
| 143 | |
Johan Hedberg | 490c5ba | 2012-02-22 19:19:09 +0200 | [diff] [blame] | 144 | #define HCI_MAX_SHORT_NAME_LENGTH 10 |
| 145 | |
Johan Hedberg | d6bfd59 | 2014-02-23 19:42:20 +0200 | [diff] [blame] | 146 | /* Default LE RPA expiry time, 15 minutes */ |
| 147 | #define HCI_DEFAULT_RPA_TIMEOUT (15 * 60) |
| 148 | |
Andrzej Kaczmarek | 31ad169 | 2014-05-14 13:43:02 +0200 | [diff] [blame] | 149 | /* Default min/max age of connection information (1s/3s) */ |
| 150 | #define DEFAULT_CONN_INFO_MIN_AGE 1000 |
| 151 | #define DEFAULT_CONN_INFO_MAX_AGE 3000 |
| 152 | |
Andrei Emeltchenko | 903e454 | 2012-09-27 17:26:09 +0300 | [diff] [blame] | 153 | struct amp_assoc { |
| 154 | __u16 len; |
| 155 | __u16 offset; |
Andrei Emeltchenko | 93c284e | 2012-09-27 17:26:20 +0300 | [diff] [blame] | 156 | __u16 rem_len; |
| 157 | __u16 len_so_far; |
Andrei Emeltchenko | 903e454 | 2012-09-27 17:26:09 +0300 | [diff] [blame] | 158 | __u8 data[HCI_MAX_AMP_ASSOC_SIZE]; |
| 159 | }; |
| 160 | |
Johan Hedberg | d2c5d77 | 2013-04-17 15:00:52 +0300 | [diff] [blame] | 161 | #define HCI_MAX_PAGES 3 |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 162 | |
Suraj Sumangala | cd4c539 | 2010-07-14 13:02:16 +0530 | [diff] [blame] | 163 | #define NUM_REASSEMBLY 4 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | struct hci_dev { |
| 165 | struct list_head list; |
Gustavo F. Padovan | 09fd0de | 2011-06-17 13:03:21 -0300 | [diff] [blame] | 166 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | char name[8]; |
| 169 | unsigned long flags; |
| 170 | __u16 id; |
Marcel Holtmann | c13854c | 2010-02-08 15:27:07 +0100 | [diff] [blame] | 171 | __u8 bus; |
Marcel Holtmann | 943da25 | 2010-02-13 02:28:41 +0100 | [diff] [blame] | 172 | __u8 dev_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | bdaddr_t bdaddr; |
Marcel Holtmann | 7a4cd51 | 2014-02-19 19:52:13 -0800 | [diff] [blame] | 174 | bdaddr_t random_addr; |
Marcel Holtmann | d13eafc | 2013-10-02 04:41:30 -0700 | [diff] [blame] | 175 | bdaddr_t static_addr; |
Johan Hedberg | 56ed2cb | 2014-02-27 14:05:40 +0200 | [diff] [blame] | 176 | __u8 adv_addr_type; |
Johan Hedberg | 1f6c637 | 2011-03-16 14:29:35 +0200 | [diff] [blame] | 177 | __u8 dev_name[HCI_MAX_NAME_LENGTH]; |
Johan Hedberg | 490c5ba | 2012-02-22 19:19:09 +0200 | [diff] [blame] | 178 | __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH]; |
Johan Hedberg | 80a1e1d | 2011-03-28 14:07:23 +0300 | [diff] [blame] | 179 | __u8 eir[HCI_MAX_EIR_LENGTH]; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 180 | __u8 dev_class[3]; |
Johan Hedberg | 1aff6f0 | 2011-01-13 21:56:52 +0200 | [diff] [blame] | 181 | __u8 major_class; |
| 182 | __u8 minor_class; |
Johan Hedberg | d2c5d77 | 2013-04-17 15:00:52 +0300 | [diff] [blame] | 183 | __u8 max_page; |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 184 | __u8 features[HCI_MAX_PAGES][8]; |
Johan Hedberg | 60e7732 | 2013-01-22 14:01:59 +0200 | [diff] [blame] | 185 | __u8 le_features[8]; |
Johan Hedberg | cf1d081 | 2013-01-22 14:02:00 +0200 | [diff] [blame] | 186 | __u8 le_white_list_size; |
Johan Hedberg | 9b008c0 | 2013-01-22 14:02:01 +0200 | [diff] [blame] | 187 | __u8 le_states[8]; |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 188 | __u8 commands[64]; |
Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 189 | __u8 hci_ver; |
| 190 | __u16 hci_rev; |
Johan Hedberg | d5859e2 | 2011-01-25 01:19:58 +0200 | [diff] [blame] | 191 | __u8 lmp_ver; |
Marcel Holtmann | 1143e5a | 2006-09-23 09:57:20 +0200 | [diff] [blame] | 192 | __u16 manufacturer; |
Andrei Emeltchenko | 7d69230 | 2012-03-09 11:46:49 +0200 | [diff] [blame] | 193 | __u16 lmp_subver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | __u16 voice_setting; |
Marcel Holtmann | b4cb9fb | 2013-10-14 13:56:16 -0700 | [diff] [blame] | 195 | __u8 num_iac; |
Johan Hedberg | 17fa4b9 | 2011-01-25 13:28:33 +0200 | [diff] [blame] | 196 | __u8 io_capability; |
Marcel Holtmann | 91c4e9b | 2012-03-11 19:27:21 -0700 | [diff] [blame] | 197 | __s8 inq_tx_power; |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 198 | __u16 page_scan_interval; |
| 199 | __u16 page_scan_window; |
| 200 | __u8 page_scan_type; |
Marcel Holtmann | 3f959d4 | 2014-02-20 11:55:56 -0800 | [diff] [blame] | 201 | __u8 le_adv_channel_map; |
Marcel Holtmann | 533553f | 2014-03-21 12:18:10 -0700 | [diff] [blame] | 202 | __u8 le_scan_type; |
Marcel Holtmann | bef6473 | 2013-10-11 08:23:19 -0700 | [diff] [blame] | 203 | __u16 le_scan_interval; |
| 204 | __u16 le_scan_window; |
Marcel Holtmann | 4e70c7e | 2013-10-19 07:09:13 -0700 | [diff] [blame] | 205 | __u16 le_conn_min_interval; |
| 206 | __u16 le_conn_max_interval; |
Marcel Holtmann | 04fb7d9 | 2014-06-30 12:34:36 +0200 | [diff] [blame] | 207 | __u16 le_conn_latency; |
| 208 | __u16 le_supv_timeout; |
Lukasz Rymanowski | b9a7a61 | 2014-03-27 20:55:20 +0100 | [diff] [blame] | 209 | __u16 discov_interleaved_timeout; |
Andrzej Kaczmarek | 31ad169 | 2014-05-14 13:43:02 +0200 | [diff] [blame] | 210 | __u16 conn_info_min_age; |
| 211 | __u16 conn_info_max_age; |
Marcel Holtmann | 06f5b77 | 2013-10-19 07:09:11 -0700 | [diff] [blame] | 212 | __u8 ssp_debug_mode; |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 213 | __u32 clock; |
Johan Hedberg | f332ec6 | 2013-03-15 17:07:11 -0500 | [diff] [blame] | 214 | |
Marcel Holtmann | 2b9be13 | 2012-03-11 19:32:12 -0700 | [diff] [blame] | 215 | __u16 devid_source; |
| 216 | __u16 devid_vendor; |
| 217 | __u16 devid_product; |
| 218 | __u16 devid_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | __u16 pkt_type; |
Marcel Holtmann | 5b7f990 | 2007-07-11 09:51:55 +0200 | [diff] [blame] | 221 | __u16 esco_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | __u16 link_policy; |
| 223 | __u16 link_mode; |
| 224 | |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 225 | __u32 idle_timeout; |
| 226 | __u16 sniff_min_interval; |
| 227 | __u16 sniff_max_interval; |
| 228 | |
Andrei Emeltchenko | 928abaa | 2011-10-12 10:53:57 +0300 | [diff] [blame] | 229 | __u8 amp_status; |
| 230 | __u32 amp_total_bw; |
| 231 | __u32 amp_max_bw; |
| 232 | __u32 amp_min_latency; |
| 233 | __u32 amp_max_pdu; |
| 234 | __u8 amp_type; |
| 235 | __u16 amp_pal_cap; |
| 236 | __u16 amp_assoc_size; |
| 237 | __u32 amp_max_flush_to; |
| 238 | __u32 amp_be_flush_to; |
| 239 | |
Andrei Emeltchenko | 903e454 | 2012-09-27 17:26:09 +0300 | [diff] [blame] | 240 | struct amp_assoc loc_assoc; |
| 241 | |
Andrei Emeltchenko | 1e89cff | 2011-11-24 14:52:02 +0200 | [diff] [blame] | 242 | __u8 flow_ctl_mode; |
| 243 | |
Johan Hedberg | 9f61656 | 2011-04-28 11:28:54 -0700 | [diff] [blame] | 244 | unsigned int auto_accept_delay; |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | unsigned long quirks; |
| 247 | |
| 248 | atomic_t cmd_cnt; |
| 249 | unsigned int acl_cnt; |
| 250 | unsigned int sco_cnt; |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 251 | unsigned int le_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | unsigned int acl_mtu; |
| 254 | unsigned int sco_mtu; |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 255 | unsigned int le_mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | unsigned int acl_pkts; |
| 257 | unsigned int sco_pkts; |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 258 | unsigned int le_pkts; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Andrei Emeltchenko | 350ee4c | 2011-12-07 15:56:51 +0200 | [diff] [blame] | 260 | __u16 block_len; |
| 261 | __u16 block_mtu; |
| 262 | __u16 num_blocks; |
| 263 | __u16 block_cnt; |
| 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | unsigned long acl_last_tx; |
| 266 | unsigned long sco_last_tx; |
Ville Tervo | 6ed58ec | 2011-02-10 22:38:48 -0300 | [diff] [blame] | 267 | unsigned long le_last_tx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Marcel Holtmann | f48fd9c | 2010-03-20 15:20:04 +0100 | [diff] [blame] | 269 | struct workqueue_struct *workqueue; |
Johan Hedberg | 6ead1bb | 2013-01-14 22:33:50 +0200 | [diff] [blame] | 270 | struct workqueue_struct *req_workqueue; |
Marcel Holtmann | f48fd9c | 2010-03-20 15:20:04 +0100 | [diff] [blame] | 271 | |
Johan Hedberg | ab81cbf | 2010-12-15 13:53:18 +0200 | [diff] [blame] | 272 | struct work_struct power_on; |
Johan Hedberg | 3243553 | 2011-11-07 22:16:04 +0200 | [diff] [blame] | 273 | struct delayed_work power_off; |
Johan Hedberg | ab81cbf | 2010-12-15 13:53:18 +0200 | [diff] [blame] | 274 | |
Johan Hedberg | 16ab91a | 2011-11-07 22:16:02 +0200 | [diff] [blame] | 275 | __u16 discov_timeout; |
| 276 | struct delayed_work discov_off; |
| 277 | |
Johan Hedberg | 7d78525 | 2011-12-15 00:47:39 +0200 | [diff] [blame] | 278 | struct delayed_work service_cache; |
| 279 | |
Marcel Holtmann | 65cc2b4 | 2014-06-16 12:30:56 +0200 | [diff] [blame] | 280 | struct delayed_work cmd_timer; |
Marcel Holtmann | b78752c | 2010-08-08 23:06:53 -0400 | [diff] [blame] | 281 | |
| 282 | struct work_struct rx_work; |
Gustavo F. Padovan | c347b76 | 2011-12-14 23:53:47 -0200 | [diff] [blame] | 283 | struct work_struct cmd_work; |
Gustavo F. Padovan | 3eff45e | 2011-12-15 00:50:02 -0200 | [diff] [blame] | 284 | struct work_struct tx_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | struct sk_buff_head rx_q; |
| 287 | struct sk_buff_head raw_q; |
| 288 | struct sk_buff_head cmd_q; |
| 289 | |
Johan Hedberg | b6ddb63 | 2013-04-02 13:34:31 +0300 | [diff] [blame] | 290 | struct sk_buff *recv_evt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | struct sk_buff *sent_cmd; |
Suraj Sumangala | cd4c539 | 2010-07-14 13:02:16 +0530 | [diff] [blame] | 292 | struct sk_buff *reassembly[NUM_REASSEMBLY]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Thomas Gleixner | a6a67ef | 2009-07-26 08:18:19 +0000 | [diff] [blame] | 294 | struct mutex req_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | wait_queue_head_t req_wait_q; |
| 296 | __u32 req_status; |
| 297 | __u32 req_result; |
Johan Hedberg | a5040ef | 2011-01-10 13:28:59 +0200 | [diff] [blame] | 298 | |
Johan Hedberg | 99780a7 | 2014-02-18 10:40:07 +0200 | [diff] [blame] | 299 | struct crypto_blkcipher *tfm_aes; |
Johan Hedberg | 2e58ef3 | 2011-11-08 20:40:15 +0200 | [diff] [blame] | 300 | |
Johan Hedberg | 3088351 | 2012-01-04 14:16:21 +0200 | [diff] [blame] | 301 | struct discovery_state discovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | struct hci_conn_hash conn_hash; |
Andre Guedes | 5c136e9 | 2014-01-30 18:22:05 -0300 | [diff] [blame] | 303 | |
| 304 | struct list_head mgmt_pending; |
David Miller | ea4bd8b | 2010-07-30 21:54:49 -0700 | [diff] [blame] | 305 | struct list_head blacklist; |
Johan Hedberg | 2aeb9a1 | 2011-01-04 12:08:51 +0200 | [diff] [blame] | 306 | struct list_head uuids; |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 307 | struct list_head link_keys; |
Vinicius Costa Gomes | b899efa | 2012-02-02 21:08:00 -0300 | [diff] [blame] | 308 | struct list_head long_term_keys; |
Johan Hedberg | 970c4e4 | 2014-02-18 10:19:33 +0200 | [diff] [blame] | 309 | struct list_head identity_resolving_keys; |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 310 | struct list_head remote_oob_data; |
Marcel Holtmann | d2ab0ac | 2014-02-27 20:37:30 -0800 | [diff] [blame] | 311 | struct list_head le_white_list; |
Andre Guedes | 15819a7 | 2014-02-03 13:56:18 -0300 | [diff] [blame] | 312 | struct list_head le_conn_params; |
Andre Guedes | 77a77a3 | 2014-02-26 20:21:46 -0300 | [diff] [blame] | 313 | struct list_head pend_le_conns; |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | struct hci_dev_stats stat; |
| 316 | |
Andrei Emeltchenko | 70f23020 | 2010-12-01 16:58:25 +0200 | [diff] [blame] | 317 | atomic_t promisc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Marcel Holtmann | ca325f6 | 2010-02-08 16:22:31 +0100 | [diff] [blame] | 319 | struct dentry *debugfs; |
| 320 | |
Marcel Holtmann | a91f2e3 | 2006-07-03 10:02:41 +0200 | [diff] [blame] | 321 | struct device dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
Marcel Holtmann | 611b30f | 2009-06-08 14:41:38 +0200 | [diff] [blame] | 323 | struct rfkill *rfkill; |
| 324 | |
Marcel Holtmann | 111902f | 2014-06-21 04:53:17 +0200 | [diff] [blame] | 325 | unsigned long dbg_flags; |
Andre Guedes | d23264a | 2011-11-25 20:53:38 -0300 | [diff] [blame] | 326 | unsigned long dev_flags; |
| 327 | |
Andre Guedes | 7ba8b4b | 2012-02-03 17:47:59 -0300 | [diff] [blame] | 328 | struct delayed_work le_scan_disable; |
| 329 | |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 330 | __s8 adv_tx_power; |
Johan Hedberg | 3f0f524 | 2012-11-08 01:23:00 +0100 | [diff] [blame] | 331 | __u8 adv_data[HCI_MAX_AD_LENGTH]; |
| 332 | __u8 adv_data_len; |
Marcel Holtmann | f8e808b | 2013-10-16 00:16:47 -0700 | [diff] [blame] | 333 | __u8 scan_rsp_data[HCI_MAX_AD_LENGTH]; |
| 334 | __u8 scan_rsp_data_len; |
Johan Hedberg | 8fa1909 | 2012-10-19 20:57:49 +0300 | [diff] [blame] | 335 | |
Johan Hedberg | 863efaf | 2014-02-22 19:06:32 +0200 | [diff] [blame] | 336 | __u8 irk[16]; |
Johan Hedberg | d6bfd59 | 2014-02-23 19:42:20 +0200 | [diff] [blame] | 337 | __u32 rpa_timeout; |
| 338 | struct delayed_work rpa_expired; |
Marcel Holtmann | 2b5224d | 2014-02-23 20:39:22 -0800 | [diff] [blame] | 339 | bdaddr_t rpa; |
Johan Hedberg | 863efaf | 2014-02-22 19:06:32 +0200 | [diff] [blame] | 340 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | int (*open)(struct hci_dev *hdev); |
| 342 | int (*close)(struct hci_dev *hdev); |
| 343 | int (*flush)(struct hci_dev *hdev); |
Marcel Holtmann | f41c70c | 2012-11-12 14:02:14 +0900 | [diff] [blame] | 344 | int (*setup)(struct hci_dev *hdev); |
Marcel Holtmann | 7bd8f09 | 2013-10-11 06:19:18 -0700 | [diff] [blame] | 345 | int (*send)(struct hci_dev *hdev, struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | void (*notify)(struct hci_dev *hdev, unsigned int evt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | }; |
| 348 | |
Andrei Emeltchenko | 53502d6 | 2012-10-10 17:38:27 +0300 | [diff] [blame] | 349 | #define HCI_PHY_HANDLE(handle) (handle & 0xff) |
| 350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | struct hci_conn { |
| 352 | struct list_head list; |
| 353 | |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 354 | atomic_t refcnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 356 | bdaddr_t dst; |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 357 | __u8 dst_type; |
Marcel Holtmann | 662e882 | 2013-10-13 05:23:59 -0700 | [diff] [blame] | 358 | bdaddr_t src; |
Marcel Holtmann | e7c4096 | 2013-10-13 03:57:39 -0700 | [diff] [blame] | 359 | __u8 src_type; |
Johan Hedberg | cb1d68f | 2014-02-28 12:54:16 +0200 | [diff] [blame] | 360 | bdaddr_t init_addr; |
| 361 | __u8 init_addr_type; |
| 362 | bdaddr_t resp_addr; |
| 363 | __u8 resp_addr_type; |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 364 | __u16 handle; |
| 365 | __u16 state; |
| 366 | __u8 mode; |
| 367 | __u8 type; |
Johan Hedberg | a0c808b | 2012-01-16 09:49:58 +0200 | [diff] [blame] | 368 | bool out; |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 369 | __u8 attempt; |
| 370 | __u8 dev_class[3]; |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 371 | __u8 features[HCI_MAX_PAGES][8]; |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 372 | __u16 pkt_type; |
| 373 | __u16 link_policy; |
Waldemar Rymarkiewicz | 13d3931 | 2011-04-28 12:07:55 +0200 | [diff] [blame] | 374 | __u8 key_type; |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 375 | __u8 auth_type; |
| 376 | __u8 sec_level; |
| 377 | __u8 pending_sec_level; |
| 378 | __u8 pin_length; |
Vinicius Costa Gomes | 726b4ff | 2011-07-08 18:31:45 -0300 | [diff] [blame] | 379 | __u8 enc_key_size; |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 380 | __u8 io_capability; |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 381 | __u32 passkey_notify; |
| 382 | __u8 passkey_entered; |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 383 | __u16 disc_timeout; |
Frédéric Dalleau | 10c62dd | 2013-08-19 14:23:59 +0200 | [diff] [blame] | 384 | __u16 setting; |
Andre Guedes | 1e406ee | 2014-01-30 18:22:04 -0300 | [diff] [blame] | 385 | __u16 le_conn_min_interval; |
| 386 | __u16 le_conn_max_interval; |
Marcel Holtmann | e04fde6 | 2014-06-23 11:40:04 +0200 | [diff] [blame] | 387 | __u16 le_conn_interval; |
| 388 | __u16 le_conn_latency; |
| 389 | __u16 le_supv_timeout; |
Andrzej Kaczmarek | 5ae76a9 | 2014-05-08 15:32:08 +0200 | [diff] [blame] | 390 | __s8 rssi; |
Andrzej Kaczmarek | 5a134fa | 2014-05-09 21:35:28 +0200 | [diff] [blame] | 391 | __s8 tx_power; |
Andrzej Kaczmarek | d0455ed | 2014-05-14 13:43:05 +0200 | [diff] [blame] | 392 | __s8 max_tx_power; |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 393 | unsigned long flags; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 394 | |
Johan Hedberg | 33f3572 | 2014-06-28 17:54:06 +0300 | [diff] [blame] | 395 | __u32 clock; |
| 396 | __u16 clock_accuracy; |
| 397 | |
Andrzej Kaczmarek | dd98380 | 2014-05-14 13:43:03 +0200 | [diff] [blame] | 398 | unsigned long conn_info_timestamp; |
| 399 | |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 400 | __u8 remote_cap; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 401 | __u8 remote_auth; |
Andrei Emeltchenko | 3161ae1 | 2012-09-27 17:26:11 +0300 | [diff] [blame] | 402 | __u8 remote_id; |
Johan Hedberg | 03b555e | 2011-01-04 15:40:05 +0200 | [diff] [blame] | 403 | |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 404 | unsigned int sent; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | struct sk_buff_head data_q; |
Gustavo F. Padovan | 2c33c06 | 2011-12-14 13:02:51 -0200 | [diff] [blame] | 407 | struct list_head chan_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Gustavo F. Padovan | 19c40e3 | 2011-06-17 13:03:21 -0300 | [diff] [blame] | 409 | struct delayed_work disc_work; |
Johan Hedberg | 7bc18d9 | 2013-10-16 18:11:39 +0300 | [diff] [blame] | 410 | struct delayed_work auto_accept_work; |
Johan Hedberg | a74a84f | 2013-10-16 18:11:40 +0300 | [diff] [blame] | 411 | struct delayed_work idle_work; |
Johan Hedberg | 9489eca | 2014-02-28 17:45:46 +0200 | [diff] [blame] | 412 | struct delayed_work le_conn_timeout; |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 413 | |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 414 | struct device dev; |
| 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | struct hci_dev *hdev; |
| 417 | void *l2cap_data; |
| 418 | void *sco_data; |
Andrei Emeltchenko | 9740e49 | 2012-05-29 13:59:02 +0300 | [diff] [blame] | 419 | struct amp_mgr *amp_mgr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | struct hci_conn *link; |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 422 | |
| 423 | void (*connect_cfm_cb) (struct hci_conn *conn, u8 status); |
| 424 | void (*security_cfm_cb) (struct hci_conn *conn, u8 status); |
| 425 | void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | }; |
| 427 | |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 428 | struct hci_chan { |
| 429 | struct list_head list; |
Andrei Emeltchenko | 42c4e53 | 2012-10-10 17:38:28 +0300 | [diff] [blame] | 430 | __u16 handle; |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 431 | struct hci_conn *conn; |
| 432 | struct sk_buff_head data_q; |
| 433 | unsigned int sent; |
Mat Martineau | 168df8e | 2012-10-23 15:24:13 -0700 | [diff] [blame] | 434 | __u8 state; |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 435 | }; |
| 436 | |
Andre Guedes | 15819a7 | 2014-02-03 13:56:18 -0300 | [diff] [blame] | 437 | struct hci_conn_params { |
| 438 | struct list_head list; |
| 439 | |
| 440 | bdaddr_t addr; |
| 441 | u8 addr_type; |
| 442 | |
| 443 | u16 conn_min_interval; |
| 444 | u16 conn_max_interval; |
Marcel Holtmann | f044eb0 | 2014-06-29 16:43:26 +0200 | [diff] [blame] | 445 | u16 conn_latency; |
| 446 | u16 supervision_timeout; |
Andre Guedes | 9fcb18e | 2014-02-26 20:21:48 -0300 | [diff] [blame] | 447 | |
| 448 | enum { |
| 449 | HCI_AUTO_CONN_DISABLED, |
| 450 | HCI_AUTO_CONN_ALWAYS, |
| 451 | HCI_AUTO_CONN_LINK_LOSS, |
| 452 | } auto_connect; |
Andre Guedes | 15819a7 | 2014-02-03 13:56:18 -0300 | [diff] [blame] | 453 | }; |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | extern struct list_head hci_dev_list; |
| 456 | extern struct list_head hci_cb_list; |
| 457 | extern rwlock_t hci_dev_list_lock; |
| 458 | extern rwlock_t hci_cb_list_lock; |
| 459 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 460 | /* ----- HCI interface to upper protocols ----- */ |
Joe Perches | e74e58f | 2013-09-23 11:37:36 -0700 | [diff] [blame] | 461 | int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); |
| 462 | void l2cap_connect_cfm(struct hci_conn *hcon, u8 status); |
| 463 | int l2cap_disconn_ind(struct hci_conn *hcon); |
| 464 | void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason); |
| 465 | int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt); |
| 466 | int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 467 | |
Joe Perches | e74e58f | 2013-09-23 11:37:36 -0700 | [diff] [blame] | 468 | int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags); |
| 469 | void sco_connect_cfm(struct hci_conn *hcon, __u8 status); |
| 470 | void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason); |
| 471 | int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb); |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /* ----- Inquiry cache ----- */ |
Andrei Emeltchenko | 70f23020 | 2010-12-01 16:58:25 +0200 | [diff] [blame] | 474 | #define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */ |
| 475 | #define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Johan Hedberg | 3088351 | 2012-01-04 14:16:21 +0200 | [diff] [blame] | 477 | static inline void discovery_init(struct hci_dev *hdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | { |
Johan Hedberg | ff9ef57 | 2012-01-04 14:23:45 +0200 | [diff] [blame] | 479 | hdev->discovery.state = DISCOVERY_STOPPED; |
Johan Hedberg | 3088351 | 2012-01-04 14:16:21 +0200 | [diff] [blame] | 480 | INIT_LIST_HEAD(&hdev->discovery.all); |
| 481 | INIT_LIST_HEAD(&hdev->discovery.unknown); |
| 482 | INIT_LIST_HEAD(&hdev->discovery.resolve); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | } |
| 484 | |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 485 | bool hci_discovery_active(struct hci_dev *hdev); |
| 486 | |
Johan Hedberg | ff9ef57 | 2012-01-04 14:23:45 +0200 | [diff] [blame] | 487 | void hci_discovery_set_state(struct hci_dev *hdev, int state); |
| 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | static inline int inquiry_cache_empty(struct hci_dev *hdev) |
| 490 | { |
Johan Hedberg | 3088351 | 2012-01-04 14:16:21 +0200 | [diff] [blame] | 491 | return list_empty(&hdev->discovery.all); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | static inline long inquiry_cache_age(struct hci_dev *hdev) |
| 495 | { |
Johan Hedberg | 3088351 | 2012-01-04 14:16:21 +0200 | [diff] [blame] | 496 | struct discovery_state *c = &hdev->discovery; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return jiffies - c->timestamp; |
| 498 | } |
| 499 | |
| 500 | static inline long inquiry_entry_age(struct inquiry_entry *e) |
| 501 | { |
| 502 | return jiffies - e->timestamp; |
| 503 | } |
| 504 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 505 | struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 506 | bdaddr_t *bdaddr); |
Johan Hedberg | 561aafb | 2012-01-04 13:31:59 +0200 | [diff] [blame] | 507 | struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 508 | bdaddr_t *bdaddr); |
Johan Hedberg | 30dc78e | 2012-01-04 15:44:20 +0200 | [diff] [blame] | 509 | struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 510 | bdaddr_t *bdaddr, |
| 511 | int state); |
Johan Hedberg | a3d4e20 | 2012-01-09 00:53:02 +0200 | [diff] [blame] | 512 | void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 513 | struct inquiry_entry *ie); |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 514 | u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, |
| 515 | bool name_known); |
Andre Guedes | 1f9b9a5 | 2013-04-30 15:29:27 -0300 | [diff] [blame] | 516 | void hci_inquiry_cache_flush(struct hci_dev *hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | |
| 518 | /* ----- HCI Connections ----- */ |
| 519 | enum { |
| 520 | HCI_CONN_AUTH_PEND, |
Waldemar Rymarkiewicz | 19f8def | 2011-05-31 15:49:25 +0200 | [diff] [blame] | 521 | HCI_CONN_REAUTH_PEND, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | HCI_CONN_ENCRYPT_PEND, |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 523 | HCI_CONN_RSWITCH_PEND, |
| 524 | HCI_CONN_MODE_CHANGE_PEND, |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 525 | HCI_CONN_SCO_SETUP_PEND, |
Vinicius Costa Gomes | d26a234 | 2011-08-19 21:06:51 -0300 | [diff] [blame] | 526 | HCI_CONN_LE_SMP_PEND, |
Johan Hedberg | b644ba3 | 2012-01-17 21:48:47 +0200 | [diff] [blame] | 527 | HCI_CONN_MGMT_CONNECTED, |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 528 | HCI_CONN_SSP_ENABLED, |
Marcel Holtmann | eb9a8f3 | 2014-01-15 22:37:38 -0800 | [diff] [blame] | 529 | HCI_CONN_SC_ENABLED, |
Marcel Holtmann | abf76ba | 2014-01-31 16:24:28 -0800 | [diff] [blame] | 530 | HCI_CONN_AES_CCM, |
Johan Hedberg | 58a681e | 2012-01-16 06:47:28 +0200 | [diff] [blame] | 531 | HCI_CONN_POWER_SAVE, |
| 532 | HCI_CONN_REMOTE_OOB, |
Johan Hedberg | af6a9c3 | 2014-06-24 13:15:53 +0300 | [diff] [blame] | 533 | HCI_CONN_FLUSH_KEY, |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 534 | HCI_CONN_MASTER, |
| 535 | HCI_CONN_ENCRYPT, |
| 536 | HCI_CONN_AUTH, |
| 537 | HCI_CONN_SECURE, |
| 538 | HCI_CONN_FIPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | }; |
| 540 | |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 541 | static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) |
| 542 | { |
| 543 | struct hci_dev *hdev = conn->hdev; |
Gustavo Padovan | c3c7ea6 | 2012-05-23 04:04:20 -0300 | [diff] [blame] | 544 | return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && |
| 545 | test_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 546 | } |
| 547 | |
Marcel Holtmann | eb9a8f3 | 2014-01-15 22:37:38 -0800 | [diff] [blame] | 548 | static inline bool hci_conn_sc_enabled(struct hci_conn *conn) |
| 549 | { |
| 550 | struct hci_dev *hdev = conn->hdev; |
| 551 | return test_bit(HCI_SC_ENABLED, &hdev->dev_flags) && |
| 552 | test_bit(HCI_CONN_SC_ENABLED, &conn->flags); |
| 553 | } |
| 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) |
| 556 | { |
| 557 | struct hci_conn_hash *h = &hdev->conn_hash; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 558 | list_add_rcu(&c->list, &h->list); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 559 | switch (c->type) { |
| 560 | case ACL_LINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | h->acl_num++; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 562 | break; |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 563 | case AMP_LINK: |
| 564 | h->amp_num++; |
| 565 | break; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 566 | case LE_LINK: |
| 567 | h->le_num++; |
| 568 | break; |
| 569 | case SCO_LINK: |
| 570 | case ESCO_LINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | h->sco_num++; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 572 | break; |
| 573 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) |
| 577 | { |
| 578 | struct hci_conn_hash *h = &hdev->conn_hash; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 579 | |
| 580 | list_del_rcu(&c->list); |
| 581 | synchronize_rcu(); |
| 582 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 583 | switch (c->type) { |
| 584 | case ACL_LINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | h->acl_num--; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 586 | break; |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 587 | case AMP_LINK: |
| 588 | h->amp_num--; |
| 589 | break; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 590 | case LE_LINK: |
| 591 | h->le_num--; |
| 592 | break; |
| 593 | case SCO_LINK: |
| 594 | case ESCO_LINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | h->sco_num--; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 596 | break; |
| 597 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
Luiz Augusto von Dentz | 52087a7 | 2011-08-17 16:23:00 +0300 | [diff] [blame] | 600 | static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type) |
| 601 | { |
| 602 | struct hci_conn_hash *h = &hdev->conn_hash; |
| 603 | switch (type) { |
| 604 | case ACL_LINK: |
| 605 | return h->acl_num; |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 606 | case AMP_LINK: |
| 607 | return h->amp_num; |
Luiz Augusto von Dentz | 52087a7 | 2011-08-17 16:23:00 +0300 | [diff] [blame] | 608 | case LE_LINK: |
| 609 | return h->le_num; |
| 610 | case SCO_LINK: |
| 611 | case ESCO_LINK: |
| 612 | return h->sco_num; |
| 613 | default: |
| 614 | return 0; |
| 615 | } |
| 616 | } |
| 617 | |
Johan Hedberg | f4f0750 | 2014-02-24 14:52:16 +0200 | [diff] [blame] | 618 | static inline unsigned int hci_conn_count(struct hci_dev *hdev) |
| 619 | { |
| 620 | struct hci_conn_hash *c = &hdev->conn_hash; |
| 621 | |
| 622 | return c->acl_num + c->amp_num + c->sco_num + c->le_num; |
| 623 | } |
| 624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 626 | __u16 handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | { |
| 628 | struct hci_conn_hash *h = &hdev->conn_hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | struct hci_conn *c; |
| 630 | |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 631 | rcu_read_lock(); |
| 632 | |
| 633 | list_for_each_entry_rcu(c, &h->list, list) { |
| 634 | if (c->handle == handle) { |
| 635 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | return c; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 639 | rcu_read_unlock(); |
| 640 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return NULL; |
| 642 | } |
| 643 | |
| 644 | static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 645 | __u8 type, bdaddr_t *ba) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | { |
| 647 | struct hci_conn_hash *h = &hdev->conn_hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | struct hci_conn *c; |
| 649 | |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 650 | rcu_read_lock(); |
| 651 | |
| 652 | list_for_each_entry_rcu(c, &h->list, list) { |
| 653 | if (c->type == type && !bacmp(&c->dst, ba)) { |
| 654 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | return c; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 658 | |
| 659 | rcu_read_unlock(); |
| 660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | return NULL; |
| 662 | } |
| 663 | |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 664 | static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, |
Szymon Janc | adc4266 | 2011-02-17 16:42:00 +0100 | [diff] [blame] | 665 | __u8 type, __u16 state) |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 666 | { |
| 667 | struct hci_conn_hash *h = &hdev->conn_hash; |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 668 | struct hci_conn *c; |
| 669 | |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 670 | rcu_read_lock(); |
| 671 | |
| 672 | list_for_each_entry_rcu(c, &h->list, list) { |
| 673 | if (c->type == type && c->state == state) { |
| 674 | rcu_read_unlock(); |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 675 | return c; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 676 | } |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 677 | } |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 678 | |
| 679 | rcu_read_unlock(); |
| 680 | |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 681 | return NULL; |
| 682 | } |
| 683 | |
Andre Guedes | bed7174 | 2013-01-30 11:50:56 -0300 | [diff] [blame] | 684 | void hci_disconnect(struct hci_conn *conn, __u8 reason); |
Frédéric Dalleau | 2dea632 | 2013-08-19 14:24:03 +0200 | [diff] [blame] | 685 | bool hci_setup_sync(struct hci_conn *conn, __u16 handle); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 686 | void hci_sco_setup(struct hci_conn *conn, __u8 status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
| 688 | struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst); |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 689 | int hci_conn_del(struct hci_conn *conn); |
| 690 | void hci_conn_hash_flush(struct hci_dev *hdev); |
| 691 | void hci_conn_check_pending(struct hci_dev *hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 693 | struct hci_chan *hci_chan_create(struct hci_conn *conn); |
Andrei Emeltchenko | 9472007 | 2012-09-06 15:05:43 +0300 | [diff] [blame] | 694 | void hci_chan_del(struct hci_chan *chan); |
Gustavo F. Padovan | 2c33c06 | 2011-12-14 13:02:51 -0200 | [diff] [blame] | 695 | void hci_chan_list_flush(struct hci_conn *conn); |
Andrei Emeltchenko | 42c4e53 | 2012-10-10 17:38:28 +0300 | [diff] [blame] | 696 | struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle); |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 697 | |
Andre Guedes | 04a6c58 | 2014-02-26 20:21:44 -0300 | [diff] [blame] | 698 | struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, |
| 699 | u8 dst_type, u8 sec_level, u8 auth_type); |
| 700 | struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, |
| 701 | u8 sec_level, u8 auth_type); |
Frédéric Dalleau | 10c62dd | 2013-08-19 14:23:59 +0200 | [diff] [blame] | 702 | struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, |
| 703 | __u16 setting); |
Marcel Holtmann | e7c29cb | 2008-09-09 07:19:20 +0200 | [diff] [blame] | 704 | int hci_conn_check_link_mode(struct hci_conn *conn); |
Waldemar Rymarkiewicz | b3b1b06 | 2011-05-06 09:42:31 +0200 | [diff] [blame] | 705 | int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); |
Marcel Holtmann | 0684e5f | 2009-02-09 02:48:38 +0100 | [diff] [blame] | 706 | int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | int hci_conn_change_link_key(struct hci_conn *conn); |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 708 | int hci_conn_switch_role(struct hci_conn *conn, __u8 role); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 710 | void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Andre Guedes | 06c053f | 2014-02-26 20:21:41 -0300 | [diff] [blame] | 712 | void hci_le_conn_failed(struct hci_conn *conn, u8 status); |
| 713 | |
David Herrmann | 8d12356 | 2013-04-06 20:28:39 +0200 | [diff] [blame] | 714 | /* |
| 715 | * hci_conn_get() and hci_conn_put() are used to control the life-time of an |
| 716 | * "hci_conn" object. They do not guarantee that the hci_conn object is running, |
| 717 | * working or anything else. They just guarantee that the object is available |
| 718 | * and can be dereferenced. So you can use its locks, local variables and any |
| 719 | * other constant data. |
| 720 | * Before accessing runtime data, you _must_ lock the object and then check that |
| 721 | * it is still running. As soon as you release the locks, the connection might |
| 722 | * get dropped, though. |
| 723 | * |
| 724 | * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control |
| 725 | * how long the underlying connection is held. So every channel that runs on the |
| 726 | * hci_conn object calls this to prevent the connection from disappearing. As |
| 727 | * long as you hold a device, you must also guarantee that you have a valid |
| 728 | * reference to the device via hci_conn_get() (or the initial reference from |
| 729 | * hci_conn_add()). |
| 730 | * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't |
| 731 | * break because nobody cares for that. But this means, we cannot use |
| 732 | * _get()/_drop() in it, but require the caller to have a valid ref (FIXME). |
| 733 | */ |
| 734 | |
| 735 | static inline void hci_conn_get(struct hci_conn *conn) |
| 736 | { |
| 737 | get_device(&conn->dev); |
| 738 | } |
| 739 | |
| 740 | static inline void hci_conn_put(struct hci_conn *conn) |
| 741 | { |
| 742 | put_device(&conn->dev); |
| 743 | } |
| 744 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | static inline void hci_conn_hold(struct hci_conn *conn) |
| 746 | { |
Andrei Emeltchenko | 71becf0 | 2012-07-19 17:03:42 +0300 | [diff] [blame] | 747 | BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); |
Andrei Emeltchenko | 38b3fef | 2012-06-15 11:50:28 +0300 | [diff] [blame] | 748 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | atomic_inc(&conn->refcnt); |
Andre Guedes | 2f304d1 | 2012-01-27 19:42:02 -0300 | [diff] [blame] | 750 | cancel_delayed_work(&conn->disc_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 753 | static inline void hci_conn_drop(struct hci_conn *conn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | { |
Andrei Emeltchenko | 71becf0 | 2012-07-19 17:03:42 +0300 | [diff] [blame] | 755 | BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); |
Andrei Emeltchenko | 38b3fef | 2012-06-15 11:50:28 +0300 | [diff] [blame] | 756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | if (atomic_dec_and_test(&conn->refcnt)) { |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 758 | unsigned long timeo; |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 759 | |
| 760 | switch (conn->type) { |
| 761 | case ACL_LINK: |
| 762 | case LE_LINK: |
Johan Hedberg | a74a84f | 2013-10-16 18:11:40 +0300 | [diff] [blame] | 763 | cancel_delayed_work(&conn->idle_work); |
Marcel Holtmann | 6ac5934 | 2006-09-26 09:43:48 +0200 | [diff] [blame] | 764 | if (conn->state == BT_CONNECTED) { |
Andrei Emeltchenko | 5f246e8 | 2012-06-11 11:13:07 +0300 | [diff] [blame] | 765 | timeo = conn->disc_timeout; |
Marcel Holtmann | 6ac5934 | 2006-09-26 09:43:48 +0200 | [diff] [blame] | 766 | if (!conn->out) |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 767 | timeo *= 2; |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 768 | } else { |
Marcel Holtmann | 6ac5934 | 2006-09-26 09:43:48 +0200 | [diff] [blame] | 769 | timeo = msecs_to_jiffies(10); |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 770 | } |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case AMP_LINK: |
| 774 | timeo = conn->disc_timeout; |
| 775 | break; |
| 776 | |
| 777 | default: |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 778 | timeo = msecs_to_jiffies(10); |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 779 | break; |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 780 | } |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 781 | |
Andre Guedes | 2f304d1 | 2012-01-27 19:42:02 -0300 | [diff] [blame] | 782 | cancel_delayed_work(&conn->disc_work); |
Gustavo F. Padovan | 19c40e3 | 2011-06-17 13:03:21 -0300 | [diff] [blame] | 783 | queue_delayed_work(conn->hdev->workqueue, |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 784 | &conn->disc_work, timeo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | /* ----- HCI Devices ----- */ |
David Herrmann | dc946bd | 2012-01-07 15:47:24 +0100 | [diff] [blame] | 789 | static inline void hci_dev_put(struct hci_dev *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | { |
Andrei Emeltchenko | 376261a | 2012-09-06 15:05:45 +0300 | [diff] [blame] | 791 | BT_DBG("%s orig refcnt %d", d->name, |
| 792 | atomic_read(&d->dev.kobj.kref.refcount)); |
| 793 | |
David Herrmann | 4c724c7 | 2012-01-07 15:47:23 +0100 | [diff] [blame] | 794 | put_device(&d->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | } |
| 796 | |
David Herrmann | dc946bd | 2012-01-07 15:47:24 +0100 | [diff] [blame] | 797 | static inline struct hci_dev *hci_dev_hold(struct hci_dev *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | { |
Andrei Emeltchenko | 376261a | 2012-09-06 15:05:45 +0300 | [diff] [blame] | 799 | BT_DBG("%s orig refcnt %d", d->name, |
| 800 | atomic_read(&d->dev.kobj.kref.refcount)); |
| 801 | |
David Herrmann | 4c724c7 | 2012-01-07 15:47:23 +0100 | [diff] [blame] | 802 | get_device(&d->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | return d; |
| 804 | } |
| 805 | |
Gustavo F. Padovan | 09fd0de | 2011-06-17 13:03:21 -0300 | [diff] [blame] | 806 | #define hci_dev_lock(d) mutex_lock(&d->lock) |
| 807 | #define hci_dev_unlock(d) mutex_unlock(&d->lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
David Herrmann | aa2b86d | 2012-02-09 21:58:30 +0100 | [diff] [blame] | 809 | #define to_hci_dev(d) container_of(d, struct hci_dev, dev) |
David Herrmann | 3dc0732 | 2012-02-09 21:58:33 +0100 | [diff] [blame] | 810 | #define to_hci_conn(c) container_of(c, struct hci_conn, dev) |
David Herrmann | aa2b86d | 2012-02-09 21:58:30 +0100 | [diff] [blame] | 811 | |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 812 | static inline void *hci_get_drvdata(struct hci_dev *hdev) |
| 813 | { |
| 814 | return dev_get_drvdata(&hdev->dev); |
| 815 | } |
| 816 | |
| 817 | static inline void hci_set_drvdata(struct hci_dev *hdev, void *data) |
| 818 | { |
| 819 | dev_set_drvdata(&hdev->dev, data); |
| 820 | } |
| 821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | struct hci_dev *hci_dev_get(int index); |
Johan Hedberg | 0c0afed | 2012-11-01 13:27:26 +0200 | [diff] [blame] | 823 | struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | struct hci_dev *hci_alloc_dev(void); |
| 826 | void hci_free_dev(struct hci_dev *hdev); |
| 827 | int hci_register_dev(struct hci_dev *hdev); |
David Herrmann | 5973563 | 2011-10-26 10:43:19 +0200 | [diff] [blame] | 828 | void hci_unregister_dev(struct hci_dev *hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | int hci_suspend_dev(struct hci_dev *hdev); |
| 830 | int hci_resume_dev(struct hci_dev *hdev); |
| 831 | int hci_dev_open(__u16 dev); |
| 832 | int hci_dev_close(__u16 dev); |
| 833 | int hci_dev_reset(__u16 dev); |
| 834 | int hci_dev_reset_stat(__u16 dev); |
| 835 | int hci_dev_cmd(unsigned int cmd, void __user *arg); |
| 836 | int hci_get_dev_list(void __user *arg); |
| 837 | int hci_get_dev_info(void __user *arg); |
| 838 | int hci_get_conn_list(void __user *arg); |
| 839 | int hci_get_conn_info(struct hci_dev *hdev, void __user *arg); |
Marcel Holtmann | 40be492 | 2008-07-14 20:13:50 +0200 | [diff] [blame] | 840 | int hci_get_auth_info(struct hci_dev *hdev, void __user *arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | int hci_inquiry(void __user *arg); |
| 842 | |
Gustavo Padovan | c3c7ea6 | 2012-05-23 04:04:20 -0300 | [diff] [blame] | 843 | struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, |
Marcel Holtmann | b9ee0a7 | 2013-10-17 17:24:13 -0700 | [diff] [blame] | 844 | bdaddr_t *bdaddr, u8 type); |
Johan Hedberg | 88c1fe4 | 2012-02-09 15:56:11 +0200 | [diff] [blame] | 845 | int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
| 846 | int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
Johan Hedberg | f035856 | 2010-05-18 13:20:32 +0200 | [diff] [blame] | 847 | |
Marcel Holtmann | d2ab0ac | 2014-02-27 20:37:30 -0800 | [diff] [blame] | 848 | struct bdaddr_list *hci_white_list_lookup(struct hci_dev *hdev, |
| 849 | bdaddr_t *bdaddr, u8 type); |
| 850 | void hci_white_list_clear(struct hci_dev *hdev); |
| 851 | int hci_white_list_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
| 852 | int hci_white_list_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
| 853 | |
Andre Guedes | 15819a7 | 2014-02-03 13:56:18 -0300 | [diff] [blame] | 854 | struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, |
| 855 | bdaddr_t *addr, u8 addr_type); |
Marcel Holtmann | 51d167c | 2014-07-01 12:11:04 +0200 | [diff] [blame] | 856 | struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, |
| 857 | bdaddr_t *addr, u8 addr_type); |
Marcel Holtmann | bf5b3c8 | 2014-06-30 12:34:39 +0200 | [diff] [blame] | 858 | int hci_conn_params_set(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type, |
Marcel Holtmann | d06b50c | 2014-07-01 12:11:06 +0200 | [diff] [blame] | 859 | u8 auto_connect); |
Andre Guedes | 15819a7 | 2014-02-03 13:56:18 -0300 | [diff] [blame] | 860 | void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); |
| 861 | void hci_conn_params_clear(struct hci_dev *hdev); |
| 862 | |
Andre Guedes | 77a77a3 | 2014-02-26 20:21:46 -0300 | [diff] [blame] | 863 | struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev, |
| 864 | bdaddr_t *addr, u8 addr_type); |
| 865 | void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); |
| 866 | void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); |
| 867 | void hci_pend_le_conns_clear(struct hci_dev *hdev); |
| 868 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 869 | void hci_update_background_scan(struct hci_dev *hdev); |
| 870 | |
Johan Hedberg | 35f7498 | 2014-02-18 17:14:32 +0200 | [diff] [blame] | 871 | void hci_uuids_clear(struct hci_dev *hdev); |
Johan Hedberg | 2aeb9a1 | 2011-01-04 12:08:51 +0200 | [diff] [blame] | 872 | |
Johan Hedberg | 35f7498 | 2014-02-18 17:14:32 +0200 | [diff] [blame] | 873 | void hci_link_keys_clear(struct hci_dev *hdev); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 874 | struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); |
Johan Hedberg | 567fa2a | 2014-06-24 13:15:48 +0300 | [diff] [blame] | 875 | struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, |
Johan Hedberg | 7652ff6 | 2014-06-24 13:15:49 +0300 | [diff] [blame] | 876 | bdaddr_t *bdaddr, u8 *val, u8 type, |
| 877 | u8 pin_len, bool *persistent); |
Marcel Holtmann | fe39c7b | 2014-02-27 16:00:28 -0800 | [diff] [blame] | 878 | struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand, |
Johan Hedberg | 98a0b84 | 2014-01-30 19:40:00 -0800 | [diff] [blame] | 879 | bool master); |
Johan Hedberg | ca9142b | 2014-02-19 14:57:44 +0200 | [diff] [blame] | 880 | struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Johan Hedberg | 35d7027 | 2014-02-19 14:57:47 +0200 | [diff] [blame] | 881 | u8 addr_type, u8 type, u8 authenticated, |
Marcel Holtmann | fe39c7b | 2014-02-27 16:00:28 -0800 | [diff] [blame] | 882 | u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 883 | struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Johan Hedberg | 98a0b84 | 2014-01-30 19:40:00 -0800 | [diff] [blame] | 884 | u8 addr_type, bool master); |
Johan Hedberg | e0b2b27 | 2014-02-18 17:14:31 +0200 | [diff] [blame] | 885 | int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type); |
Johan Hedberg | 35f7498 | 2014-02-18 17:14:32 +0200 | [diff] [blame] | 886 | void hci_smp_ltks_clear(struct hci_dev *hdev); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 887 | int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); |
| 888 | |
Johan Hedberg | 970c4e4 | 2014-02-18 10:19:33 +0200 | [diff] [blame] | 889 | struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa); |
| 890 | struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 891 | u8 addr_type); |
Johan Hedberg | ca9142b | 2014-02-19 14:57:44 +0200 | [diff] [blame] | 892 | struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 893 | u8 addr_type, u8 val[16], bdaddr_t *rpa); |
Johan Hedberg | a7ec733 | 2014-02-18 17:14:35 +0200 | [diff] [blame] | 894 | void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type); |
Johan Hedberg | 970c4e4 | 2014-02-18 10:19:33 +0200 | [diff] [blame] | 895 | void hci_smp_irks_clear(struct hci_dev *hdev); |
| 896 | |
Johan Hedberg | 35f7498 | 2014-02-18 17:14:32 +0200 | [diff] [blame] | 897 | void hci_remote_oob_data_clear(struct hci_dev *hdev); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 898 | struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, |
Marcel Holtmann | 0798872 | 2014-01-10 02:07:29 -0800 | [diff] [blame] | 899 | bdaddr_t *bdaddr); |
| 900 | int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 901 | u8 *hash, u8 *randomizer); |
| 902 | int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 903 | u8 *hash192, u8 *randomizer192, |
| 904 | u8 *hash256, u8 *randomizer256); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 905 | int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); |
| 906 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); |
| 908 | |
Marcel Holtmann | e1a2617 | 2013-10-10 16:52:43 -0700 | [diff] [blame] | 909 | int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb); |
Marcel Holtmann | ef22201 | 2007-07-11 06:42:04 +0200 | [diff] [blame] | 910 | int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count); |
Suraj Sumangala | 9981151 | 2010-07-14 13:02:19 +0530 | [diff] [blame] | 911 | int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count); |
Marcel Holtmann | ef22201 | 2007-07-11 06:42:04 +0200 | [diff] [blame] | 912 | |
David Herrmann | 0ac7e70 | 2011-10-08 14:58:47 +0200 | [diff] [blame] | 913 | void hci_init_sysfs(struct hci_dev *hdev); |
Marcel Holtmann | a67e899 | 2009-05-02 18:24:06 -0700 | [diff] [blame] | 914 | void hci_conn_init_sysfs(struct hci_conn *conn); |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 915 | void hci_conn_add_sysfs(struct hci_conn *conn); |
| 916 | void hci_conn_del_sysfs(struct hci_conn *conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
David Herrmann | 6935e0f | 2012-03-09 15:53:42 +0100 | [diff] [blame] | 918 | #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | |
| 920 | /* ----- LMP capabilities ----- */ |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 921 | #define lmp_encrypt_capable(dev) ((dev)->features[0][0] & LMP_ENCRYPT) |
| 922 | #define lmp_rswitch_capable(dev) ((dev)->features[0][0] & LMP_RSWITCH) |
| 923 | #define lmp_hold_capable(dev) ((dev)->features[0][0] & LMP_HOLD) |
| 924 | #define lmp_sniff_capable(dev) ((dev)->features[0][0] & LMP_SNIFF) |
| 925 | #define lmp_park_capable(dev) ((dev)->features[0][1] & LMP_PARK) |
| 926 | #define lmp_inq_rssi_capable(dev) ((dev)->features[0][3] & LMP_RSSI_INQ) |
| 927 | #define lmp_esco_capable(dev) ((dev)->features[0][3] & LMP_ESCO) |
| 928 | #define lmp_bredr_capable(dev) (!((dev)->features[0][4] & LMP_NO_BREDR)) |
| 929 | #define lmp_le_capable(dev) ((dev)->features[0][4] & LMP_LE) |
| 930 | #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR) |
| 931 | #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC) |
| 932 | #define lmp_ext_inq_capable(dev) ((dev)->features[0][6] & LMP_EXT_INQ) |
| 933 | #define lmp_le_br_capable(dev) (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR)) |
| 934 | #define lmp_ssp_capable(dev) ((dev)->features[0][6] & LMP_SIMPLE_PAIR) |
| 935 | #define lmp_no_flush_capable(dev) ((dev)->features[0][6] & LMP_NO_FLUSH) |
| 936 | #define lmp_lsto_capable(dev) ((dev)->features[0][7] & LMP_LSTO) |
| 937 | #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR) |
| 938 | #define lmp_ext_feat_capable(dev) ((dev)->features[0][7] & LMP_EXTFEATURES) |
Frédéric Dalleau | 07a5c61 | 2013-08-19 14:24:00 +0200 | [diff] [blame] | 939 | #define lmp_transp_capable(dev) ((dev)->features[0][2] & LMP_TRANSPARENT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | |
Andre Guedes | eead27d | 2011-06-30 19:20:55 -0300 | [diff] [blame] | 941 | /* ----- Extended LMP capabilities ----- */ |
Marcel Holtmann | 53b834d2 | 2013-12-08 11:55:33 -0800 | [diff] [blame] | 942 | #define lmp_csb_master_capable(dev) ((dev)->features[2][0] & LMP_CSB_MASTER) |
| 943 | #define lmp_csb_slave_capable(dev) ((dev)->features[2][0] & LMP_CSB_SLAVE) |
| 944 | #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN) |
| 945 | #define lmp_sync_scan_capable(dev) ((dev)->features[2][0] & LMP_SYNC_SCAN) |
Marcel Holtmann | d599158 | 2014-01-10 02:07:16 -0800 | [diff] [blame] | 946 | #define lmp_sc_capable(dev) ((dev)->features[2][1] & LMP_SC) |
| 947 | #define lmp_ping_capable(dev) ((dev)->features[2][1] & LMP_PING) |
Marcel Holtmann | 53b834d2 | 2013-12-08 11:55:33 -0800 | [diff] [blame] | 948 | |
| 949 | /* ----- Host capabilities ----- */ |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 950 | #define lmp_host_ssp_capable(dev) ((dev)->features[1][0] & LMP_HOST_SSP) |
Marcel Holtmann | d599158 | 2014-01-10 02:07:16 -0800 | [diff] [blame] | 951 | #define lmp_host_sc_capable(dev) ((dev)->features[1][0] & LMP_HOST_SC) |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 952 | #define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE)) |
| 953 | #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR)) |
Andre Guedes | eead27d | 2011-06-30 19:20:55 -0300 | [diff] [blame] | 954 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | /* ----- HCI protocols ----- */ |
Frédéric Dalleau | 20714bf | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 956 | #define HCI_PROTO_DEFER 0x01 |
| 957 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 958 | static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Frédéric Dalleau | 20714bf | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 959 | __u8 type, __u8 *flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 961 | switch (type) { |
| 962 | case ACL_LINK: |
| 963 | return l2cap_connect_ind(hdev, bdaddr); |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 964 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 965 | case SCO_LINK: |
| 966 | case ESCO_LINK: |
Frédéric Dalleau | 20714bf | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 967 | return sco_connect_ind(hdev, bdaddr, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 969 | default: |
| 970 | BT_ERR("unknown link type %d", type); |
| 971 | return -EINVAL; |
| 972 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | } |
| 974 | |
| 975 | static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status) |
| 976 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 977 | switch (conn->type) { |
| 978 | case ACL_LINK: |
| 979 | case LE_LINK: |
| 980 | l2cap_connect_cfm(conn, status); |
| 981 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 983 | case SCO_LINK: |
| 984 | case ESCO_LINK: |
| 985 | sco_connect_cfm(conn, status); |
| 986 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 988 | default: |
| 989 | BT_ERR("unknown link type %d", conn->type); |
| 990 | break; |
| 991 | } |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 992 | |
| 993 | if (conn->connect_cfm_cb) |
| 994 | conn->connect_cfm_cb(conn, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
| 996 | |
Marcel Holtmann | 2950f21 | 2009-02-12 14:02:50 +0100 | [diff] [blame] | 997 | static inline int hci_proto_disconn_ind(struct hci_conn *conn) |
| 998 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 999 | if (conn->type != ACL_LINK && conn->type != LE_LINK) |
| 1000 | return HCI_ERROR_REMOTE_USER_TERM; |
Marcel Holtmann | 2950f21 | 2009-02-12 14:02:50 +0100 | [diff] [blame] | 1001 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1002 | return l2cap_disconn_ind(conn); |
Marcel Holtmann | 2950f21 | 2009-02-12 14:02:50 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1007 | switch (conn->type) { |
| 1008 | case ACL_LINK: |
| 1009 | case LE_LINK: |
| 1010 | l2cap_disconn_cfm(conn, reason); |
| 1011 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1013 | case SCO_LINK: |
| 1014 | case ESCO_LINK: |
| 1015 | sco_disconn_cfm(conn, reason); |
| 1016 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 1018 | /* L2CAP would be handled for BREDR chan */ |
| 1019 | case AMP_LINK: |
| 1020 | break; |
| 1021 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1022 | default: |
| 1023 | BT_ERR("unknown link type %d", conn->type); |
| 1024 | break; |
| 1025 | } |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 1026 | |
| 1027 | if (conn->disconn_cfm_cb) |
| 1028 | conn->disconn_cfm_cb(conn, reason); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status) |
| 1032 | { |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1033 | __u8 encrypt; |
| 1034 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1035 | if (conn->type != ACL_LINK && conn->type != LE_LINK) |
| 1036 | return; |
| 1037 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1038 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1039 | return; |
| 1040 | |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 1041 | encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00; |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1042 | l2cap_security_cfm(conn, status, encrypt); |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 1043 | |
| 1044 | if (conn->security_cfm_cb) |
| 1045 | conn->security_cfm_cb(conn, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 1048 | static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status, |
| 1049 | __u8 encrypt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1051 | if (conn->type != ACL_LINK && conn->type != LE_LINK) |
| 1052 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1054 | l2cap_security_cfm(conn, status, encrypt); |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 1055 | |
| 1056 | if (conn->security_cfm_cb) |
| 1057 | conn->security_cfm_cb(conn, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | /* ----- HCI callbacks ----- */ |
| 1061 | struct hci_cb { |
| 1062 | struct list_head list; |
| 1063 | |
| 1064 | char *name; |
| 1065 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 1066 | void (*security_cfm) (struct hci_conn *conn, __u8 status, |
| 1067 | __u8 encrypt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | void (*key_change_cfm) (struct hci_conn *conn, __u8 status); |
| 1069 | void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role); |
| 1070 | }; |
| 1071 | |
| 1072 | static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) |
| 1073 | { |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1074 | struct hci_cb *cb; |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1075 | __u8 encrypt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
| 1077 | hci_proto_auth_cfm(conn, status); |
| 1078 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1079 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1080 | return; |
| 1081 | |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 1082 | encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00; |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1083 | |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1084 | read_lock(&hci_cb_list_lock); |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1085 | list_for_each_entry(cb, &hci_cb_list, list) { |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1086 | if (cb->security_cfm) |
| 1087 | cb->security_cfm(conn, status, encrypt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | } |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1089 | read_unlock(&hci_cb_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 1092 | static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, |
| 1093 | __u8 encrypt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | { |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1095 | struct hci_cb *cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
Marcel Holtmann | 435fef2 | 2009-02-09 03:55:28 +0100 | [diff] [blame] | 1097 | if (conn->sec_level == BT_SECURITY_SDP) |
| 1098 | conn->sec_level = BT_SECURITY_LOW; |
| 1099 | |
Vinicius Costa Gomes | 88167ae | 2011-06-09 18:50:51 -0300 | [diff] [blame] | 1100 | if (conn->pending_sec_level > conn->sec_level) |
| 1101 | conn->sec_level = conn->pending_sec_level; |
| 1102 | |
Marcel Holtmann | 9719f8a | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 1103 | hci_proto_encrypt_cfm(conn, status, encrypt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1105 | read_lock(&hci_cb_list_lock); |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1106 | list_for_each_entry(cb, &hci_cb_list, list) { |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1107 | if (cb->security_cfm) |
| 1108 | cb->security_cfm(conn, status, encrypt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | } |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1110 | read_unlock(&hci_cb_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status) |
| 1114 | { |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1115 | struct hci_cb *cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1117 | read_lock(&hci_cb_list_lock); |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1118 | list_for_each_entry(cb, &hci_cb_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | if (cb->key_change_cfm) |
| 1120 | cb->key_change_cfm(conn, status); |
| 1121 | } |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1122 | read_unlock(&hci_cb_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 1125 | static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, |
| 1126 | __u8 role) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | { |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1128 | struct hci_cb *cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1130 | read_lock(&hci_cb_list_lock); |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1131 | list_for_each_entry(cb, &hci_cb_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1132 | if (cb->role_switch_cfm) |
| 1133 | cb->role_switch_cfm(conn, status, role); |
| 1134 | } |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1135 | read_unlock(&hci_cb_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
Johan Hedberg | 6759a67 | 2012-01-15 20:51:14 +0200 | [diff] [blame] | 1138 | static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) |
| 1139 | { |
Johan Hedberg | 84d9d07 | 2012-03-26 14:21:41 +0300 | [diff] [blame] | 1140 | size_t parsed = 0; |
Johan Hedberg | 6759a67 | 2012-01-15 20:51:14 +0200 | [diff] [blame] | 1141 | |
Johan Hedberg | 6c0c331 | 2012-03-26 14:21:42 +0300 | [diff] [blame] | 1142 | if (data_len < 2) |
| 1143 | return false; |
| 1144 | |
Johan Hedberg | 84d9d07 | 2012-03-26 14:21:41 +0300 | [diff] [blame] | 1145 | while (parsed < data_len - 1) { |
| 1146 | u8 field_len = data[0]; |
Johan Hedberg | 6759a67 | 2012-01-15 20:51:14 +0200 | [diff] [blame] | 1147 | |
| 1148 | if (field_len == 0) |
| 1149 | break; |
| 1150 | |
| 1151 | parsed += field_len + 1; |
| 1152 | |
| 1153 | if (parsed > data_len) |
| 1154 | break; |
| 1155 | |
| 1156 | if (data[1] == type) |
| 1157 | return true; |
| 1158 | |
| 1159 | data += field_len + 1; |
| 1160 | } |
| 1161 | |
| 1162 | return false; |
| 1163 | } |
| 1164 | |
Johan Hedberg | 301cb2d | 2014-02-18 10:19:34 +0200 | [diff] [blame] | 1165 | static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type) |
| 1166 | { |
Andre Guedes | dbbfa2a | 2014-06-25 16:44:45 -0300 | [diff] [blame] | 1167 | if (addr_type != ADDR_LE_DEV_RANDOM) |
Johan Hedberg | 301cb2d | 2014-02-18 10:19:34 +0200 | [diff] [blame] | 1168 | return false; |
| 1169 | |
| 1170 | if ((bdaddr->b[5] & 0xc0) == 0x40) |
| 1171 | return true; |
| 1172 | |
| 1173 | return false; |
| 1174 | } |
| 1175 | |
Johan Hedberg | 2426f3a | 2014-02-18 17:14:36 +0200 | [diff] [blame] | 1176 | static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev, |
| 1177 | bdaddr_t *bdaddr, u8 addr_type) |
| 1178 | { |
| 1179 | if (!hci_bdaddr_is_rpa(bdaddr, addr_type)) |
| 1180 | return NULL; |
| 1181 | |
| 1182 | return hci_find_irk_by_rpa(hdev, bdaddr); |
| 1183 | } |
| 1184 | |
Andre Guedes | d4905f2 | 2014-06-25 21:52:52 -0300 | [diff] [blame] | 1185 | static inline int hci_check_conn_params(u16 min, u16 max, u16 latency, |
| 1186 | u16 to_multiplier) |
| 1187 | { |
| 1188 | u16 max_latency; |
| 1189 | |
| 1190 | if (min > max || min < 6 || max > 3200) |
| 1191 | return -EINVAL; |
| 1192 | |
| 1193 | if (to_multiplier < 10 || to_multiplier > 3200) |
| 1194 | return -EINVAL; |
| 1195 | |
| 1196 | if (max >= to_multiplier * 8) |
| 1197 | return -EINVAL; |
| 1198 | |
| 1199 | max_latency = (to_multiplier * 8 / max) - 1; |
| 1200 | if (latency > 499 || latency > max_latency) |
| 1201 | return -EINVAL; |
| 1202 | |
| 1203 | return 0; |
| 1204 | } |
| 1205 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | int hci_register_cb(struct hci_cb *hcb); |
| 1207 | int hci_unregister_cb(struct hci_cb *hcb); |
| 1208 | |
Johan Hedberg | 3119ae9 | 2013-03-05 20:37:44 +0200 | [diff] [blame] | 1209 | struct hci_request { |
| 1210 | struct hci_dev *hdev; |
| 1211 | struct sk_buff_head cmd_q; |
Andre Guedes | 5d73e03 | 2013-03-08 11:20:16 -0300 | [diff] [blame] | 1212 | |
| 1213 | /* If something goes wrong when building the HCI request, the error |
| 1214 | * value is stored in this field. |
| 1215 | */ |
| 1216 | int err; |
Johan Hedberg | 3119ae9 | 2013-03-05 20:37:44 +0200 | [diff] [blame] | 1217 | }; |
| 1218 | |
| 1219 | void hci_req_init(struct hci_request *req, struct hci_dev *hdev); |
| 1220 | int hci_req_run(struct hci_request *req, hci_req_complete_t complete); |
Johan Hedberg | 07dc93d | 2013-04-19 10:14:51 +0300 | [diff] [blame] | 1221 | void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, |
| 1222 | const void *param); |
| 1223 | void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen, |
| 1224 | const void *param, u8 event); |
Johan Hedberg | 9238f36 | 2013-03-05 20:37:48 +0200 | [diff] [blame] | 1225 | void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status); |
Johan Hedberg | 3119ae9 | 2013-03-05 20:37:44 +0200 | [diff] [blame] | 1226 | |
Andre Guedes | b1efcc2 | 2014-02-26 20:21:40 -0300 | [diff] [blame] | 1227 | void hci_req_add_le_scan_disable(struct hci_request *req); |
Andre Guedes | 8ef30fd | 2014-02-26 20:21:55 -0300 | [diff] [blame] | 1228 | void hci_req_add_le_passive_scan(struct hci_request *req); |
Andre Guedes | b1efcc2 | 2014-02-26 20:21:40 -0300 | [diff] [blame] | 1229 | |
Johan Hedberg | 75e84b7 | 2013-04-02 13:35:04 +0300 | [diff] [blame] | 1230 | struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, |
Johan Hedberg | 07dc93d | 2013-04-19 10:14:51 +0300 | [diff] [blame] | 1231 | const void *param, u32 timeout); |
Johan Hedberg | 7b1abbb | 2013-04-03 21:54:47 +0300 | [diff] [blame] | 1232 | struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, |
Johan Hedberg | 07dc93d | 2013-04-19 10:14:51 +0300 | [diff] [blame] | 1233 | const void *param, u8 event, u32 timeout); |
Johan Hedberg | 75e84b7 | 2013-04-02 13:35:04 +0300 | [diff] [blame] | 1234 | |
Johan Hedberg | 07dc93d | 2013-04-19 10:14:51 +0300 | [diff] [blame] | 1235 | int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, |
| 1236 | const void *param); |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 1237 | void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); |
Gustavo F. Padovan | 0d861d8 | 2010-05-01 16:15:35 -0300 | [diff] [blame] | 1238 | void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1240 | void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | /* ----- HCI Sockets ----- */ |
Marcel Holtmann | 470fe1b | 2012-02-20 14:50:30 +0100 | [diff] [blame] | 1243 | void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); |
| 1244 | void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk); |
Marcel Holtmann | cd82e61 | 2012-02-20 20:34:38 +0100 | [diff] [blame] | 1245 | void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Marcel Holtmann | 040030e | 2012-02-20 14:50:37 +0100 | [diff] [blame] | 1247 | void hci_sock_dev_event(struct hci_dev *hdev, int event); |
| 1248 | |
Johan Hedberg | 0381101 | 2010-12-08 00:21:06 +0200 | [diff] [blame] | 1249 | /* Management interface */ |
Andre Guedes | 591f47f | 2012-04-24 21:02:49 -0300 | [diff] [blame] | 1250 | #define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR)) |
| 1251 | #define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \ |
| 1252 | BIT(BDADDR_LE_RANDOM)) |
| 1253 | #define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \ |
| 1254 | BIT(BDADDR_LE_PUBLIC) | \ |
| 1255 | BIT(BDADDR_LE_RANDOM)) |
Andre Guedes | f39799f | 2012-02-17 20:39:35 -0300 | [diff] [blame] | 1256 | |
Andre Guedes | 0d8cc93 | 2013-04-30 15:29:31 -0300 | [diff] [blame] | 1257 | /* These LE scan and inquiry parameters were chosen according to LE General |
| 1258 | * Discovery Procedure specification. |
| 1259 | */ |
| 1260 | #define DISCOV_LE_SCAN_WIN 0x12 |
| 1261 | #define DISCOV_LE_SCAN_INT 0x12 |
Lukasz Rymanowski | 3d5a76f | 2014-03-27 20:55:21 +0100 | [diff] [blame] | 1262 | #define DISCOV_LE_TIMEOUT 10240 /* msec */ |
Lukasz Rymanowski | ae55f59 | 2014-03-27 20:55:19 +0100 | [diff] [blame] | 1263 | #define DISCOV_INTERLEAVED_TIMEOUT 5120 /* msec */ |
Andre Guedes | 0d8cc93 | 2013-04-30 15:29:31 -0300 | [diff] [blame] | 1264 | #define DISCOV_INTERLEAVED_INQUIRY_LEN 0x04 |
| 1265 | #define DISCOV_BREDR_INQUIRY_LEN 0x08 |
| 1266 | |
Johan Hedberg | 0381101 | 2010-12-08 00:21:06 +0200 | [diff] [blame] | 1267 | int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len); |
Marcel Holtmann | bf6b56d | 2013-10-06 23:55:45 -0700 | [diff] [blame] | 1268 | void mgmt_index_added(struct hci_dev *hdev); |
| 1269 | void mgmt_index_removed(struct hci_dev *hdev); |
Marcel Holtmann | 3eec705 | 2013-10-06 23:55:46 -0700 | [diff] [blame] | 1270 | void mgmt_set_powered_failed(struct hci_dev *hdev, int err); |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1271 | int mgmt_powered(struct hci_dev *hdev, u8 powered); |
Marcel Holtmann | d1967ff | 2013-10-15 10:57:40 -0700 | [diff] [blame] | 1272 | void mgmt_discoverable_timeout(struct hci_dev *hdev); |
Marcel Holtmann | 86a7564 | 2013-10-15 06:33:54 -0700 | [diff] [blame] | 1273 | void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable); |
Marcel Holtmann | a330916 | 2013-10-15 06:33:55 -0700 | [diff] [blame] | 1274 | void mgmt_connectable(struct hci_dev *hdev, u8 connectable); |
Johan Hedberg | 778b235 | 2014-02-24 14:52:17 +0200 | [diff] [blame] | 1275 | void mgmt_advertising(struct hci_dev *hdev, u8 advertising); |
Marcel Holtmann | 4796e8a | 2013-10-15 06:33:56 -0700 | [diff] [blame] | 1276 | void mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status); |
Marcel Holtmann | dc4a5ee | 2013-10-15 10:15:57 -0700 | [diff] [blame] | 1277 | void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, |
| 1278 | bool persistent); |
Marcel Holtmann | ecd90ae | 2013-10-06 23:55:49 -0700 | [diff] [blame] | 1279 | void mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
| 1280 | u8 addr_type, u32 flags, u8 *name, u8 name_len, |
| 1281 | u8 *dev_class); |
Marcel Holtmann | 9b80ec5 | 2013-10-06 23:55:50 -0700 | [diff] [blame] | 1282 | void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 1283 | u8 link_type, u8 addr_type, u8 reason, |
| 1284 | bool mgmt_connected); |
Marcel Holtmann | 7892924 | 2013-10-06 23:55:47 -0700 | [diff] [blame] | 1285 | void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1286 | u8 link_type, u8 addr_type, u8 status); |
Marcel Holtmann | 445608d | 2013-10-06 23:55:48 -0700 | [diff] [blame] | 1287 | void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
| 1288 | u8 addr_type, u8 status); |
Marcel Holtmann | ce0e4a0 | 2013-10-15 14:26:20 -0700 | [diff] [blame] | 1289 | void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); |
Marcel Holtmann | e669cf8 | 2013-10-15 14:26:21 -0700 | [diff] [blame] | 1290 | void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1291 | u8 status); |
Marcel Holtmann | 3eb3852 | 2013-10-15 14:26:22 -0700 | [diff] [blame] | 1292 | void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1293 | u8 status); |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1294 | int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Johan Hedberg | 39adbff | 2014-03-20 08:18:14 +0200 | [diff] [blame] | 1295 | u8 link_type, u8 addr_type, u32 value, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1296 | u8 confirm_hint); |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1297 | int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1298 | u8 link_type, u8 addr_type, u8 status); |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1299 | int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1300 | u8 link_type, u8 addr_type, u8 status); |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1301 | int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1302 | u8 link_type, u8 addr_type); |
Brian Gix | 604086b | 2011-11-23 08:28:33 -0800 | [diff] [blame] | 1303 | int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1304 | u8 link_type, u8 addr_type, u8 status); |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1305 | int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1306 | u8 link_type, u8 addr_type, u8 status); |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 1307 | int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1308 | u8 link_type, u8 addr_type, u32 passkey, |
| 1309 | u8 entered); |
Marcel Holtmann | e546099 | 2013-10-15 14:26:23 -0700 | [diff] [blame] | 1310 | void mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
| 1311 | u8 addr_type, u8 status); |
Marcel Holtmann | 464996a | 2013-10-15 14:26:24 -0700 | [diff] [blame] | 1312 | void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status); |
Marcel Holtmann | 3e24856 | 2013-10-15 14:26:25 -0700 | [diff] [blame] | 1313 | void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); |
Marcel Holtmann | eac83dc | 2014-01-10 02:07:23 -0800 | [diff] [blame] | 1314 | void mgmt_sc_enable_complete(struct hci_dev *hdev, u8 enable, u8 status); |
Marcel Holtmann | 4e1b024 | 2013-10-15 14:26:26 -0700 | [diff] [blame] | 1315 | void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, |
| 1316 | u8 status); |
Marcel Holtmann | 7667da3 | 2013-10-15 14:26:27 -0700 | [diff] [blame] | 1317 | void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); |
Marcel Holtmann | 4d2d279 | 2014-01-10 02:07:26 -0800 | [diff] [blame] | 1318 | void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192, |
| 1319 | u8 *randomizer192, u8 *hash256, |
| 1320 | u8 *randomizer256, u8 status); |
Marcel Holtmann | 901801b | 2013-10-06 23:55:51 -0700 | [diff] [blame] | 1321 | void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
Marcel Holtmann | af58925 | 2014-07-01 14:11:20 +0200 | [diff] [blame] | 1322 | u8 addr_type, u8 *dev_class, s8 rssi, u32 flags, |
| 1323 | u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len); |
Marcel Holtmann | 9cf12ae | 2013-10-06 23:55:52 -0700 | [diff] [blame] | 1324 | void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
| 1325 | u8 addr_type, s8 rssi, u8 *name, u8 name_len); |
Marcel Holtmann | 2f1e063 | 2013-10-06 23:55:53 -0700 | [diff] [blame] | 1326 | void mgmt_discovering(struct hci_dev *hdev, u8 discovering); |
Johan Hedberg | 88c1fe4 | 2012-02-09 15:56:11 +0200 | [diff] [blame] | 1327 | int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
| 1328 | int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
Marcel Holtmann | 53ac6ab | 2014-03-09 23:38:42 -0700 | [diff] [blame] | 1329 | void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent); |
Johan Hedberg | 95fbac8 | 2014-02-19 15:18:31 +0200 | [diff] [blame] | 1330 | void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk); |
Marcel Holtmann | 53ac6ab | 2014-03-09 23:38:42 -0700 | [diff] [blame] | 1331 | void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, |
| 1332 | bool persistent); |
Marcel Holtmann | 5976e60 | 2013-10-06 04:08:14 -0700 | [diff] [blame] | 1333 | void mgmt_reenable_advertising(struct hci_dev *hdev); |
Johan Hedberg | f4a407b | 2014-02-18 21:41:34 +0200 | [diff] [blame] | 1334 | void mgmt_smp_complete(struct hci_conn *conn, bool complete); |
Vinicius Costa Gomes | 346af67 | 2012-02-02 21:08:02 -0300 | [diff] [blame] | 1335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | /* HCI info for socket */ |
| 1337 | #define hci_pi(sk) ((struct hci_pinfo *) sk) |
| 1338 | |
| 1339 | struct hci_pinfo { |
| 1340 | struct bt_sock bt; |
| 1341 | struct hci_dev *hdev; |
| 1342 | struct hci_filter filter; |
| 1343 | __u32 cmsg_mask; |
Johan Hedberg | c02178d | 2010-12-08 00:21:05 +0200 | [diff] [blame] | 1344 | unsigned short channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | }; |
| 1346 | |
| 1347 | /* HCI security filter */ |
| 1348 | #define HCI_SFLT_MAX_OGF 5 |
| 1349 | |
| 1350 | struct hci_sec_filter { |
| 1351 | __u32 type_mask; |
| 1352 | __u32 event_mask[2]; |
| 1353 | __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4]; |
| 1354 | }; |
| 1355 | |
| 1356 | /* ----- HCI requests ----- */ |
| 1357 | #define HCI_REQ_DONE 0 |
| 1358 | #define HCI_REQ_PEND 1 |
| 1359 | #define HCI_REQ_CANCELED 2 |
| 1360 | |
Thomas Gleixner | a6a67ef | 2009-07-26 08:18:19 +0000 | [diff] [blame] | 1361 | #define hci_req_lock(d) mutex_lock(&d->req_lock) |
| 1362 | #define hci_req_unlock(d) mutex_unlock(&d->req_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | |
Claudio Takahasi | 2ce603e | 2011-02-16 20:44:53 -0200 | [diff] [blame] | 1364 | void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, |
| 1365 | u16 latency, u16 to_multiplier); |
Marcel Holtmann | fe39c7b | 2014-02-27 16:00:28 -0800 | [diff] [blame] | 1366 | void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand, |
Vinicius Costa Gomes | a7a595f | 2011-06-09 18:50:47 -0300 | [diff] [blame] | 1367 | __u8 ltk[16]); |
Andre Guedes | 2519a1f | 2011-11-07 11:45:24 -0300 | [diff] [blame] | 1368 | |
Marcel Holtmann | 94b1fc9 | 2014-02-23 20:25:54 -0800 | [diff] [blame] | 1369 | int hci_update_random_address(struct hci_request *req, bool require_privacy, |
| 1370 | u8 *own_addr_type); |
Johan Hedberg | a1f4c31 | 2014-02-27 14:05:41 +0200 | [diff] [blame] | 1371 | void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1372 | u8 *bdaddr_type); |
Johan Hedberg | ebd3a74 | 2014-02-23 19:42:21 +0200 | [diff] [blame] | 1373 | |
Frédéric Dalleau | 5d4d62f | 2013-08-19 14:23:57 +0200 | [diff] [blame] | 1374 | #define SCO_AIRMODE_MASK 0x0003 |
| 1375 | #define SCO_AIRMODE_CVSD 0x0000 |
| 1376 | #define SCO_AIRMODE_TRANSP 0x0003 |
| 1377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | #endif /* __HCI_CORE_H */ |