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, |
Johan Hedberg | fe59a05 | 2014-07-01 19:14:12 +0300 | [diff] [blame^] | 539 | HCI_CONN_STK_ENCRYPT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | }; |
| 541 | |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 542 | static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) |
| 543 | { |
| 544 | struct hci_dev *hdev = conn->hdev; |
Gustavo Padovan | c3c7ea6 | 2012-05-23 04:04:20 -0300 | [diff] [blame] | 545 | return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) && |
| 546 | test_bit(HCI_CONN_SSP_ENABLED, &conn->flags); |
Johan Hedberg | aa64a8b | 2012-01-18 21:33:12 +0200 | [diff] [blame] | 547 | } |
| 548 | |
Marcel Holtmann | eb9a8f3 | 2014-01-15 22:37:38 -0800 | [diff] [blame] | 549 | static inline bool hci_conn_sc_enabled(struct hci_conn *conn) |
| 550 | { |
| 551 | struct hci_dev *hdev = conn->hdev; |
| 552 | return test_bit(HCI_SC_ENABLED, &hdev->dev_flags) && |
| 553 | test_bit(HCI_CONN_SC_ENABLED, &conn->flags); |
| 554 | } |
| 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) |
| 557 | { |
| 558 | struct hci_conn_hash *h = &hdev->conn_hash; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 559 | list_add_rcu(&c->list, &h->list); |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 560 | switch (c->type) { |
| 561 | case ACL_LINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | h->acl_num++; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 563 | break; |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 564 | case AMP_LINK: |
| 565 | h->amp_num++; |
| 566 | break; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 567 | case LE_LINK: |
| 568 | h->le_num++; |
| 569 | break; |
| 570 | case SCO_LINK: |
| 571 | case ESCO_LINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | h->sco_num++; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 573 | break; |
| 574 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) |
| 578 | { |
| 579 | struct hci_conn_hash *h = &hdev->conn_hash; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 580 | |
| 581 | list_del_rcu(&c->list); |
| 582 | synchronize_rcu(); |
| 583 | |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 584 | switch (c->type) { |
| 585 | case ACL_LINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | h->acl_num--; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 587 | break; |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 588 | case AMP_LINK: |
| 589 | h->amp_num--; |
| 590 | break; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 591 | case LE_LINK: |
| 592 | h->le_num--; |
| 593 | break; |
| 594 | case SCO_LINK: |
| 595 | case ESCO_LINK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | h->sco_num--; |
Ville Tervo | fcd89c0 | 2011-02-10 22:38:47 -0300 | [diff] [blame] | 597 | break; |
| 598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Luiz Augusto von Dentz | 52087a7 | 2011-08-17 16:23:00 +0300 | [diff] [blame] | 601 | static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type) |
| 602 | { |
| 603 | struct hci_conn_hash *h = &hdev->conn_hash; |
| 604 | switch (type) { |
| 605 | case ACL_LINK: |
| 606 | return h->acl_num; |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 607 | case AMP_LINK: |
| 608 | return h->amp_num; |
Luiz Augusto von Dentz | 52087a7 | 2011-08-17 16:23:00 +0300 | [diff] [blame] | 609 | case LE_LINK: |
| 610 | return h->le_num; |
| 611 | case SCO_LINK: |
| 612 | case ESCO_LINK: |
| 613 | return h->sco_num; |
| 614 | default: |
| 615 | return 0; |
| 616 | } |
| 617 | } |
| 618 | |
Johan Hedberg | f4f0750 | 2014-02-24 14:52:16 +0200 | [diff] [blame] | 619 | static inline unsigned int hci_conn_count(struct hci_dev *hdev) |
| 620 | { |
| 621 | struct hci_conn_hash *c = &hdev->conn_hash; |
| 622 | |
| 623 | return c->acl_num + c->amp_num + c->sco_num + c->le_num; |
| 624 | } |
| 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | 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] | 627 | __u16 handle) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | { |
| 629 | struct hci_conn_hash *h = &hdev->conn_hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | struct hci_conn *c; |
| 631 | |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 632 | rcu_read_lock(); |
| 633 | |
| 634 | list_for_each_entry_rcu(c, &h->list, list) { |
| 635 | if (c->handle == handle) { |
| 636 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | return c; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 640 | rcu_read_unlock(); |
| 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | return NULL; |
| 643 | } |
| 644 | |
| 645 | 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] | 646 | __u8 type, bdaddr_t *ba) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
| 648 | struct hci_conn_hash *h = &hdev->conn_hash; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | struct hci_conn *c; |
| 650 | |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 651 | rcu_read_lock(); |
| 652 | |
| 653 | list_for_each_entry_rcu(c, &h->list, list) { |
| 654 | if (c->type == type && !bacmp(&c->dst, ba)) { |
| 655 | rcu_read_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | return c; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 657 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 659 | |
| 660 | rcu_read_unlock(); |
| 661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | return NULL; |
| 663 | } |
| 664 | |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 665 | 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] | 666 | __u8 type, __u16 state) |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 667 | { |
| 668 | struct hci_conn_hash *h = &hdev->conn_hash; |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 669 | struct hci_conn *c; |
| 670 | |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 671 | rcu_read_lock(); |
| 672 | |
| 673 | list_for_each_entry_rcu(c, &h->list, list) { |
| 674 | if (c->type == type && c->state == state) { |
| 675 | rcu_read_unlock(); |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 676 | return c; |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 677 | } |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 678 | } |
Gustavo F. Padovan | bf4c632 | 2011-12-14 22:54:12 -0200 | [diff] [blame] | 679 | |
| 680 | rcu_read_unlock(); |
| 681 | |
Marcel Holtmann | 4c67bc7 | 2006-10-15 17:30:56 +0200 | [diff] [blame] | 682 | return NULL; |
| 683 | } |
| 684 | |
Andre Guedes | bed7174 | 2013-01-30 11:50:56 -0300 | [diff] [blame] | 685 | void hci_disconnect(struct hci_conn *conn, __u8 reason); |
Frédéric Dalleau | 2dea632 | 2013-08-19 14:24:03 +0200 | [diff] [blame] | 686 | bool hci_setup_sync(struct hci_conn *conn, __u16 handle); |
Marcel Holtmann | e73439d | 2010-07-26 10:06:00 -0400 | [diff] [blame] | 687 | void hci_sco_setup(struct hci_conn *conn, __u8 status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
| 689 | 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] | 690 | int hci_conn_del(struct hci_conn *conn); |
| 691 | void hci_conn_hash_flush(struct hci_dev *hdev); |
| 692 | void hci_conn_check_pending(struct hci_dev *hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 694 | struct hci_chan *hci_chan_create(struct hci_conn *conn); |
Andrei Emeltchenko | 9472007 | 2012-09-06 15:05:43 +0300 | [diff] [blame] | 695 | void hci_chan_del(struct hci_chan *chan); |
Gustavo F. Padovan | 2c33c06 | 2011-12-14 13:02:51 -0200 | [diff] [blame] | 696 | void hci_chan_list_flush(struct hci_conn *conn); |
Andrei Emeltchenko | 42c4e53 | 2012-10-10 17:38:28 +0300 | [diff] [blame] | 697 | 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] | 698 | |
Andre Guedes | 04a6c58 | 2014-02-26 20:21:44 -0300 | [diff] [blame] | 699 | struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, |
| 700 | u8 dst_type, u8 sec_level, u8 auth_type); |
| 701 | struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, |
| 702 | u8 sec_level, u8 auth_type); |
Frédéric Dalleau | 10c62dd | 2013-08-19 14:23:59 +0200 | [diff] [blame] | 703 | struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, |
| 704 | __u16 setting); |
Marcel Holtmann | e7c29cb | 2008-09-09 07:19:20 +0200 | [diff] [blame] | 705 | int hci_conn_check_link_mode(struct hci_conn *conn); |
Waldemar Rymarkiewicz | b3b1b06 | 2011-05-06 09:42:31 +0200 | [diff] [blame] | 706 | int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); |
Marcel Holtmann | 0684e5f | 2009-02-09 02:48:38 +0100 | [diff] [blame] | 707 | 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] | 708 | int hci_conn_change_link_key(struct hci_conn *conn); |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 709 | int hci_conn_switch_role(struct hci_conn *conn, __u8 role); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | |
Jaikumar Ganesh | 14b12d0 | 2011-05-23 18:06:04 -0700 | [diff] [blame] | 711 | 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] | 712 | |
Andre Guedes | 06c053f | 2014-02-26 20:21:41 -0300 | [diff] [blame] | 713 | void hci_le_conn_failed(struct hci_conn *conn, u8 status); |
| 714 | |
David Herrmann | 8d12356 | 2013-04-06 20:28:39 +0200 | [diff] [blame] | 715 | /* |
| 716 | * hci_conn_get() and hci_conn_put() are used to control the life-time of an |
| 717 | * "hci_conn" object. They do not guarantee that the hci_conn object is running, |
| 718 | * working or anything else. They just guarantee that the object is available |
| 719 | * and can be dereferenced. So you can use its locks, local variables and any |
| 720 | * other constant data. |
| 721 | * Before accessing runtime data, you _must_ lock the object and then check that |
| 722 | * it is still running. As soon as you release the locks, the connection might |
| 723 | * get dropped, though. |
| 724 | * |
| 725 | * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control |
| 726 | * how long the underlying connection is held. So every channel that runs on the |
| 727 | * hci_conn object calls this to prevent the connection from disappearing. As |
| 728 | * long as you hold a device, you must also guarantee that you have a valid |
| 729 | * reference to the device via hci_conn_get() (or the initial reference from |
| 730 | * hci_conn_add()). |
| 731 | * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't |
| 732 | * break because nobody cares for that. But this means, we cannot use |
| 733 | * _get()/_drop() in it, but require the caller to have a valid ref (FIXME). |
| 734 | */ |
| 735 | |
| 736 | static inline void hci_conn_get(struct hci_conn *conn) |
| 737 | { |
| 738 | get_device(&conn->dev); |
| 739 | } |
| 740 | |
| 741 | static inline void hci_conn_put(struct hci_conn *conn) |
| 742 | { |
| 743 | put_device(&conn->dev); |
| 744 | } |
| 745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | static inline void hci_conn_hold(struct hci_conn *conn) |
| 747 | { |
Andrei Emeltchenko | 71becf0 | 2012-07-19 17:03:42 +0300 | [diff] [blame] | 748 | BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); |
Andrei Emeltchenko | 38b3fef | 2012-06-15 11:50:28 +0300 | [diff] [blame] | 749 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | atomic_inc(&conn->refcnt); |
Andre Guedes | 2f304d1 | 2012-01-27 19:42:02 -0300 | [diff] [blame] | 751 | cancel_delayed_work(&conn->disc_work); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | } |
| 753 | |
David Herrmann | 76a68ba | 2013-04-06 20:28:37 +0200 | [diff] [blame] | 754 | static inline void hci_conn_drop(struct hci_conn *conn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | { |
Andrei Emeltchenko | 71becf0 | 2012-07-19 17:03:42 +0300 | [diff] [blame] | 756 | BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); |
Andrei Emeltchenko | 38b3fef | 2012-06-15 11:50:28 +0300 | [diff] [blame] | 757 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | if (atomic_dec_and_test(&conn->refcnt)) { |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 759 | unsigned long timeo; |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 760 | |
| 761 | switch (conn->type) { |
| 762 | case ACL_LINK: |
| 763 | case LE_LINK: |
Johan Hedberg | a74a84f | 2013-10-16 18:11:40 +0300 | [diff] [blame] | 764 | cancel_delayed_work(&conn->idle_work); |
Marcel Holtmann | 6ac5934 | 2006-09-26 09:43:48 +0200 | [diff] [blame] | 765 | if (conn->state == BT_CONNECTED) { |
Andrei Emeltchenko | 5f246e8 | 2012-06-11 11:13:07 +0300 | [diff] [blame] | 766 | timeo = conn->disc_timeout; |
Marcel Holtmann | 6ac5934 | 2006-09-26 09:43:48 +0200 | [diff] [blame] | 767 | if (!conn->out) |
Marcel Holtmann | 052b30b | 2009-04-26 20:01:22 +0200 | [diff] [blame] | 768 | timeo *= 2; |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 769 | } else { |
Marcel Holtmann | 6ac5934 | 2006-09-26 09:43:48 +0200 | [diff] [blame] | 770 | timeo = msecs_to_jiffies(10); |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 771 | } |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 772 | break; |
| 773 | |
| 774 | case AMP_LINK: |
| 775 | timeo = conn->disc_timeout; |
| 776 | break; |
| 777 | |
| 778 | default: |
Marcel Holtmann | 04837f6 | 2006-07-03 10:02:33 +0200 | [diff] [blame] | 779 | timeo = msecs_to_jiffies(10); |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 780 | break; |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 781 | } |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 782 | |
Andre Guedes | 2f304d1 | 2012-01-27 19:42:02 -0300 | [diff] [blame] | 783 | cancel_delayed_work(&conn->disc_work); |
Gustavo F. Padovan | 19c40e3 | 2011-06-17 13:03:21 -0300 | [diff] [blame] | 784 | queue_delayed_work(conn->hdev->workqueue, |
Andrei Emeltchenko | 716e4ab | 2012-10-10 17:38:31 +0300 | [diff] [blame] | 785 | &conn->disc_work, timeo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | /* ----- HCI Devices ----- */ |
David Herrmann | dc946bd | 2012-01-07 15:47:24 +0100 | [diff] [blame] | 790 | static inline void hci_dev_put(struct hci_dev *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | { |
Andrei Emeltchenko | 376261a | 2012-09-06 15:05:45 +0300 | [diff] [blame] | 792 | BT_DBG("%s orig refcnt %d", d->name, |
| 793 | atomic_read(&d->dev.kobj.kref.refcount)); |
| 794 | |
David Herrmann | 4c724c7 | 2012-01-07 15:47:23 +0100 | [diff] [blame] | 795 | put_device(&d->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | } |
| 797 | |
David Herrmann | dc946bd | 2012-01-07 15:47:24 +0100 | [diff] [blame] | 798 | static inline struct hci_dev *hci_dev_hold(struct hci_dev *d) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | { |
Andrei Emeltchenko | 376261a | 2012-09-06 15:05:45 +0300 | [diff] [blame] | 800 | BT_DBG("%s orig refcnt %d", d->name, |
| 801 | atomic_read(&d->dev.kobj.kref.refcount)); |
| 802 | |
David Herrmann | 4c724c7 | 2012-01-07 15:47:23 +0100 | [diff] [blame] | 803 | get_device(&d->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | return d; |
| 805 | } |
| 806 | |
Gustavo F. Padovan | 09fd0de | 2011-06-17 13:03:21 -0300 | [diff] [blame] | 807 | #define hci_dev_lock(d) mutex_lock(&d->lock) |
| 808 | #define hci_dev_unlock(d) mutex_unlock(&d->lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
David Herrmann | aa2b86d | 2012-02-09 21:58:30 +0100 | [diff] [blame] | 810 | #define to_hci_dev(d) container_of(d, struct hci_dev, dev) |
David Herrmann | 3dc0732 | 2012-02-09 21:58:33 +0100 | [diff] [blame] | 811 | #define to_hci_conn(c) container_of(c, struct hci_conn, dev) |
David Herrmann | aa2b86d | 2012-02-09 21:58:30 +0100 | [diff] [blame] | 812 | |
David Herrmann | 155961e | 2012-02-09 21:58:32 +0100 | [diff] [blame] | 813 | static inline void *hci_get_drvdata(struct hci_dev *hdev) |
| 814 | { |
| 815 | return dev_get_drvdata(&hdev->dev); |
| 816 | } |
| 817 | |
| 818 | static inline void hci_set_drvdata(struct hci_dev *hdev, void *data) |
| 819 | { |
| 820 | dev_set_drvdata(&hdev->dev, data); |
| 821 | } |
| 822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | struct hci_dev *hci_dev_get(int index); |
Johan Hedberg | 0c0afed | 2012-11-01 13:27:26 +0200 | [diff] [blame] | 824 | struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
| 826 | struct hci_dev *hci_alloc_dev(void); |
| 827 | void hci_free_dev(struct hci_dev *hdev); |
| 828 | int hci_register_dev(struct hci_dev *hdev); |
David Herrmann | 5973563 | 2011-10-26 10:43:19 +0200 | [diff] [blame] | 829 | void hci_unregister_dev(struct hci_dev *hdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | int hci_suspend_dev(struct hci_dev *hdev); |
| 831 | int hci_resume_dev(struct hci_dev *hdev); |
| 832 | int hci_dev_open(__u16 dev); |
| 833 | int hci_dev_close(__u16 dev); |
| 834 | int hci_dev_reset(__u16 dev); |
| 835 | int hci_dev_reset_stat(__u16 dev); |
| 836 | int hci_dev_cmd(unsigned int cmd, void __user *arg); |
| 837 | int hci_get_dev_list(void __user *arg); |
| 838 | int hci_get_dev_info(void __user *arg); |
| 839 | int hci_get_conn_list(void __user *arg); |
| 840 | int hci_get_conn_info(struct hci_dev *hdev, void __user *arg); |
Marcel Holtmann | 40be492 | 2008-07-14 20:13:50 +0200 | [diff] [blame] | 841 | int hci_get_auth_info(struct hci_dev *hdev, void __user *arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | int hci_inquiry(void __user *arg); |
| 843 | |
Gustavo Padovan | c3c7ea6 | 2012-05-23 04:04:20 -0300 | [diff] [blame] | 844 | struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, |
Marcel Holtmann | b9ee0a7 | 2013-10-17 17:24:13 -0700 | [diff] [blame] | 845 | bdaddr_t *bdaddr, u8 type); |
Johan Hedberg | 88c1fe4 | 2012-02-09 15:56:11 +0200 | [diff] [blame] | 846 | int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
| 847 | 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] | 848 | |
Marcel Holtmann | d2ab0ac | 2014-02-27 20:37:30 -0800 | [diff] [blame] | 849 | struct bdaddr_list *hci_white_list_lookup(struct hci_dev *hdev, |
| 850 | bdaddr_t *bdaddr, u8 type); |
| 851 | void hci_white_list_clear(struct hci_dev *hdev); |
| 852 | int hci_white_list_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
| 853 | int hci_white_list_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
| 854 | |
Andre Guedes | 15819a7 | 2014-02-03 13:56:18 -0300 | [diff] [blame] | 855 | struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, |
| 856 | bdaddr_t *addr, u8 addr_type); |
Marcel Holtmann | 51d167c | 2014-07-01 12:11:04 +0200 | [diff] [blame] | 857 | struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, |
| 858 | bdaddr_t *addr, u8 addr_type); |
Marcel Holtmann | bf5b3c8 | 2014-06-30 12:34:39 +0200 | [diff] [blame] | 859 | 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] | 860 | u8 auto_connect); |
Andre Guedes | 15819a7 | 2014-02-03 13:56:18 -0300 | [diff] [blame] | 861 | void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); |
| 862 | void hci_conn_params_clear(struct hci_dev *hdev); |
| 863 | |
Andre Guedes | 77a77a3 | 2014-02-26 20:21:46 -0300 | [diff] [blame] | 864 | struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev, |
| 865 | bdaddr_t *addr, u8 addr_type); |
| 866 | void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); |
| 867 | void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); |
| 868 | void hci_pend_le_conns_clear(struct hci_dev *hdev); |
| 869 | |
Andre Guedes | a4790db | 2014-02-26 20:21:47 -0300 | [diff] [blame] | 870 | void hci_update_background_scan(struct hci_dev *hdev); |
| 871 | |
Johan Hedberg | 35f7498 | 2014-02-18 17:14:32 +0200 | [diff] [blame] | 872 | void hci_uuids_clear(struct hci_dev *hdev); |
Johan Hedberg | 2aeb9a1 | 2011-01-04 12:08:51 +0200 | [diff] [blame] | 873 | |
Johan Hedberg | 35f7498 | 2014-02-18 17:14:32 +0200 | [diff] [blame] | 874 | void hci_link_keys_clear(struct hci_dev *hdev); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 875 | 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] | 876 | 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] | 877 | bdaddr_t *bdaddr, u8 *val, u8 type, |
| 878 | u8 pin_len, bool *persistent); |
Marcel Holtmann | fe39c7b | 2014-02-27 16:00:28 -0800 | [diff] [blame] | 879 | 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] | 880 | bool master); |
Johan Hedberg | ca9142b | 2014-02-19 14:57:44 +0200 | [diff] [blame] | 881 | 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] | 882 | u8 addr_type, u8 type, u8 authenticated, |
Marcel Holtmann | fe39c7b | 2014-02-27 16:00:28 -0800 | [diff] [blame] | 883 | u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand); |
Vinicius Costa Gomes | c9839a1 | 2012-02-02 21:08:01 -0300 | [diff] [blame] | 884 | 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] | 885 | u8 addr_type, bool master); |
Johan Hedberg | e0b2b27 | 2014-02-18 17:14:31 +0200 | [diff] [blame] | 886 | 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] | 887 | void hci_smp_ltks_clear(struct hci_dev *hdev); |
Johan Hedberg | 55ed8ca1 | 2011-01-17 14:41:05 +0200 | [diff] [blame] | 888 | int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); |
| 889 | |
Johan Hedberg | 970c4e4 | 2014-02-18 10:19:33 +0200 | [diff] [blame] | 890 | struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa); |
| 891 | struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 892 | u8 addr_type); |
Johan Hedberg | ca9142b | 2014-02-19 14:57:44 +0200 | [diff] [blame] | 893 | struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 894 | u8 addr_type, u8 val[16], bdaddr_t *rpa); |
Johan Hedberg | a7ec733 | 2014-02-18 17:14:35 +0200 | [diff] [blame] | 895 | 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] | 896 | void hci_smp_irks_clear(struct hci_dev *hdev); |
| 897 | |
Johan Hedberg | 35f7498 | 2014-02-18 17:14:32 +0200 | [diff] [blame] | 898 | void hci_remote_oob_data_clear(struct hci_dev *hdev); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 899 | struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, |
Marcel Holtmann | 0798872 | 2014-01-10 02:07:29 -0800 | [diff] [blame] | 900 | bdaddr_t *bdaddr); |
| 901 | int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 902 | u8 *hash, u8 *randomizer); |
| 903 | int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 904 | u8 *hash192, u8 *randomizer192, |
| 905 | u8 *hash256, u8 *randomizer256); |
Szymon Janc | 2763eda | 2011-03-22 13:12:22 +0100 | [diff] [blame] | 906 | int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr); |
| 907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); |
| 909 | |
Marcel Holtmann | e1a2617 | 2013-10-10 16:52:43 -0700 | [diff] [blame] | 910 | int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb); |
Marcel Holtmann | ef22201 | 2007-07-11 06:42:04 +0200 | [diff] [blame] | 911 | 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] | 912 | 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] | 913 | |
David Herrmann | 0ac7e70 | 2011-10-08 14:58:47 +0200 | [diff] [blame] | 914 | void hci_init_sysfs(struct hci_dev *hdev); |
Marcel Holtmann | a67e899 | 2009-05-02 18:24:06 -0700 | [diff] [blame] | 915 | void hci_conn_init_sysfs(struct hci_conn *conn); |
Marcel Holtmann | b219e3a | 2006-07-06 12:38:46 +0200 | [diff] [blame] | 916 | void hci_conn_add_sysfs(struct hci_conn *conn); |
| 917 | void hci_conn_del_sysfs(struct hci_conn *conn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | |
David Herrmann | 6935e0f | 2012-03-09 15:53:42 +0100 | [diff] [blame] | 919 | #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
| 921 | /* ----- LMP capabilities ----- */ |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 922 | #define lmp_encrypt_capable(dev) ((dev)->features[0][0] & LMP_ENCRYPT) |
| 923 | #define lmp_rswitch_capable(dev) ((dev)->features[0][0] & LMP_RSWITCH) |
| 924 | #define lmp_hold_capable(dev) ((dev)->features[0][0] & LMP_HOLD) |
| 925 | #define lmp_sniff_capable(dev) ((dev)->features[0][0] & LMP_SNIFF) |
| 926 | #define lmp_park_capable(dev) ((dev)->features[0][1] & LMP_PARK) |
| 927 | #define lmp_inq_rssi_capable(dev) ((dev)->features[0][3] & LMP_RSSI_INQ) |
| 928 | #define lmp_esco_capable(dev) ((dev)->features[0][3] & LMP_ESCO) |
| 929 | #define lmp_bredr_capable(dev) (!((dev)->features[0][4] & LMP_NO_BREDR)) |
| 930 | #define lmp_le_capable(dev) ((dev)->features[0][4] & LMP_LE) |
| 931 | #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR) |
| 932 | #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC) |
| 933 | #define lmp_ext_inq_capable(dev) ((dev)->features[0][6] & LMP_EXT_INQ) |
| 934 | #define lmp_le_br_capable(dev) (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR)) |
| 935 | #define lmp_ssp_capable(dev) ((dev)->features[0][6] & LMP_SIMPLE_PAIR) |
| 936 | #define lmp_no_flush_capable(dev) ((dev)->features[0][6] & LMP_NO_FLUSH) |
| 937 | #define lmp_lsto_capable(dev) ((dev)->features[0][7] & LMP_LSTO) |
| 938 | #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR) |
| 939 | #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] | 940 | #define lmp_transp_capable(dev) ((dev)->features[0][2] & LMP_TRANSPARENT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
Andre Guedes | eead27d | 2011-06-30 19:20:55 -0300 | [diff] [blame] | 942 | /* ----- Extended LMP capabilities ----- */ |
Marcel Holtmann | 53b834d2 | 2013-12-08 11:55:33 -0800 | [diff] [blame] | 943 | #define lmp_csb_master_capable(dev) ((dev)->features[2][0] & LMP_CSB_MASTER) |
| 944 | #define lmp_csb_slave_capable(dev) ((dev)->features[2][0] & LMP_CSB_SLAVE) |
| 945 | #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN) |
| 946 | #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] | 947 | #define lmp_sc_capable(dev) ((dev)->features[2][1] & LMP_SC) |
| 948 | #define lmp_ping_capable(dev) ((dev)->features[2][1] & LMP_PING) |
Marcel Holtmann | 53b834d2 | 2013-12-08 11:55:33 -0800 | [diff] [blame] | 949 | |
| 950 | /* ----- Host capabilities ----- */ |
Johan Hedberg | cad718e | 2013-04-17 15:00:51 +0300 | [diff] [blame] | 951 | #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] | 952 | #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] | 953 | #define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE)) |
| 954 | #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] | 955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | /* ----- HCI protocols ----- */ |
Frédéric Dalleau | 20714bf | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 957 | #define HCI_PROTO_DEFER 0x01 |
| 958 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 959 | 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] | 960 | __u8 type, __u8 *flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 962 | switch (type) { |
| 963 | case ACL_LINK: |
| 964 | return l2cap_connect_ind(hdev, bdaddr); |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 965 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 966 | case SCO_LINK: |
| 967 | case ESCO_LINK: |
Frédéric Dalleau | 20714bf | 2012-11-21 10:51:12 +0100 | [diff] [blame] | 968 | return sco_connect_ind(hdev, bdaddr, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 970 | default: |
| 971 | BT_ERR("unknown link type %d", type); |
| 972 | return -EINVAL; |
| 973 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status) |
| 977 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 978 | switch (conn->type) { |
| 979 | case ACL_LINK: |
| 980 | case LE_LINK: |
| 981 | l2cap_connect_cfm(conn, status); |
| 982 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 984 | case SCO_LINK: |
| 985 | case ESCO_LINK: |
| 986 | sco_connect_cfm(conn, status); |
| 987 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 989 | default: |
| 990 | BT_ERR("unknown link type %d", conn->type); |
| 991 | break; |
| 992 | } |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 993 | |
| 994 | if (conn->connect_cfm_cb) |
| 995 | conn->connect_cfm_cb(conn, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | } |
| 997 | |
Marcel Holtmann | 2950f21 | 2009-02-12 14:02:50 +0100 | [diff] [blame] | 998 | static inline int hci_proto_disconn_ind(struct hci_conn *conn) |
| 999 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1000 | if (conn->type != ACL_LINK && conn->type != LE_LINK) |
| 1001 | return HCI_ERROR_REMOTE_USER_TERM; |
Marcel Holtmann | 2950f21 | 2009-02-12 14:02:50 +0100 | [diff] [blame] | 1002 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1003 | return l2cap_disconn_ind(conn); |
Marcel Holtmann | 2950f21 | 2009-02-12 14:02:50 +0100 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | 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] | 1007 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1008 | switch (conn->type) { |
| 1009 | case ACL_LINK: |
| 1010 | case LE_LINK: |
| 1011 | l2cap_disconn_cfm(conn, reason); |
| 1012 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1014 | case SCO_LINK: |
| 1015 | case ESCO_LINK: |
| 1016 | sco_disconn_cfm(conn, reason); |
| 1017 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
Andrei Emeltchenko | bd1eb66 | 2012-10-10 17:38:30 +0300 | [diff] [blame] | 1019 | /* L2CAP would be handled for BREDR chan */ |
| 1020 | case AMP_LINK: |
| 1021 | break; |
| 1022 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1023 | default: |
| 1024 | BT_ERR("unknown link type %d", conn->type); |
| 1025 | break; |
| 1026 | } |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 1027 | |
| 1028 | if (conn->disconn_cfm_cb) |
| 1029 | conn->disconn_cfm_cb(conn, reason); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
| 1032 | static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status) |
| 1033 | { |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1034 | __u8 encrypt; |
| 1035 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1036 | if (conn->type != ACL_LINK && conn->type != LE_LINK) |
| 1037 | return; |
| 1038 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1039 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1040 | return; |
| 1041 | |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 1042 | encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00; |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1043 | l2cap_security_cfm(conn, status, encrypt); |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 1044 | |
| 1045 | if (conn->security_cfm_cb) |
| 1046 | conn->security_cfm_cb(conn, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | } |
| 1048 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 1049 | static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status, |
| 1050 | __u8 encrypt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | { |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1052 | if (conn->type != ACL_LINK && conn->type != LE_LINK) |
| 1053 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | |
Ulisses Furquim | 686ebf2 | 2011-12-21 10:11:33 -0200 | [diff] [blame] | 1055 | l2cap_security_cfm(conn, status, encrypt); |
Johan Hedberg | e9a416b | 2011-02-19 12:05:56 -0300 | [diff] [blame] | 1056 | |
| 1057 | if (conn->security_cfm_cb) |
| 1058 | conn->security_cfm_cb(conn, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1061 | /* ----- HCI callbacks ----- */ |
| 1062 | struct hci_cb { |
| 1063 | struct list_head list; |
| 1064 | |
| 1065 | char *name; |
| 1066 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 1067 | void (*security_cfm) (struct hci_conn *conn, __u8 status, |
| 1068 | __u8 encrypt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | void (*key_change_cfm) (struct hci_conn *conn, __u8 status); |
| 1070 | void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role); |
| 1071 | }; |
| 1072 | |
| 1073 | static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) |
| 1074 | { |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1075 | struct hci_cb *cb; |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1076 | __u8 encrypt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | |
| 1078 | hci_proto_auth_cfm(conn, status); |
| 1079 | |
Johan Hedberg | 51a8efd | 2012-01-16 06:10:31 +0200 | [diff] [blame] | 1080 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1081 | return; |
| 1082 | |
Johan Hedberg | 4dae279 | 2014-06-24 17:03:50 +0300 | [diff] [blame] | 1083 | encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00; |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1084 | |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1085 | read_lock(&hci_cb_list_lock); |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1086 | list_for_each_entry(cb, &hci_cb_list, list) { |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1087 | if (cb->security_cfm) |
| 1088 | cb->security_cfm(conn, status, encrypt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | } |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1090 | read_unlock(&hci_cb_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | } |
| 1092 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 1093 | static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, |
| 1094 | __u8 encrypt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | { |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1096 | struct hci_cb *cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
Marcel Holtmann | 435fef2 | 2009-02-09 03:55:28 +0100 | [diff] [blame] | 1098 | if (conn->sec_level == BT_SECURITY_SDP) |
| 1099 | conn->sec_level = BT_SECURITY_LOW; |
| 1100 | |
Vinicius Costa Gomes | 88167ae | 2011-06-09 18:50:51 -0300 | [diff] [blame] | 1101 | if (conn->pending_sec_level > conn->sec_level) |
| 1102 | conn->sec_level = conn->pending_sec_level; |
| 1103 | |
Marcel Holtmann | 9719f8a | 2008-07-14 20:13:45 +0200 | [diff] [blame] | 1104 | hci_proto_encrypt_cfm(conn, status, encrypt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1105 | |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1106 | read_lock(&hci_cb_list_lock); |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1107 | list_for_each_entry(cb, &hci_cb_list, list) { |
Marcel Holtmann | 8c1b235 | 2009-01-15 21:58:04 +0100 | [diff] [blame] | 1108 | if (cb->security_cfm) |
| 1109 | cb->security_cfm(conn, status, encrypt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | } |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1111 | read_unlock(&hci_cb_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status) |
| 1115 | { |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1116 | struct hci_cb *cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1118 | read_lock(&hci_cb_list_lock); |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1119 | list_for_each_entry(cb, &hci_cb_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | if (cb->key_change_cfm) |
| 1121 | cb->key_change_cfm(conn, status); |
| 1122 | } |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1123 | read_unlock(&hci_cb_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Waldemar Rymarkiewicz | 5a9d0a3 | 2011-06-07 11:18:06 +0200 | [diff] [blame] | 1126 | static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, |
| 1127 | __u8 role) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | { |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1129 | struct hci_cb *cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1131 | read_lock(&hci_cb_list_lock); |
Denis Kirjanov | 711584e | 2012-10-22 17:22:01 +0400 | [diff] [blame] | 1132 | list_for_each_entry(cb, &hci_cb_list, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | if (cb->role_switch_cfm) |
| 1134 | cb->role_switch_cfm(conn, status, role); |
| 1135 | } |
Gustavo F. Padovan | f20d09d | 2011-12-22 16:30:27 -0200 | [diff] [blame] | 1136 | read_unlock(&hci_cb_list_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | } |
| 1138 | |
Johan Hedberg | 6759a67 | 2012-01-15 20:51:14 +0200 | [diff] [blame] | 1139 | static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type) |
| 1140 | { |
Johan Hedberg | 84d9d07 | 2012-03-26 14:21:41 +0300 | [diff] [blame] | 1141 | size_t parsed = 0; |
Johan Hedberg | 6759a67 | 2012-01-15 20:51:14 +0200 | [diff] [blame] | 1142 | |
Johan Hedberg | 6c0c331 | 2012-03-26 14:21:42 +0300 | [diff] [blame] | 1143 | if (data_len < 2) |
| 1144 | return false; |
| 1145 | |
Johan Hedberg | 84d9d07 | 2012-03-26 14:21:41 +0300 | [diff] [blame] | 1146 | while (parsed < data_len - 1) { |
| 1147 | u8 field_len = data[0]; |
Johan Hedberg | 6759a67 | 2012-01-15 20:51:14 +0200 | [diff] [blame] | 1148 | |
| 1149 | if (field_len == 0) |
| 1150 | break; |
| 1151 | |
| 1152 | parsed += field_len + 1; |
| 1153 | |
| 1154 | if (parsed > data_len) |
| 1155 | break; |
| 1156 | |
| 1157 | if (data[1] == type) |
| 1158 | return true; |
| 1159 | |
| 1160 | data += field_len + 1; |
| 1161 | } |
| 1162 | |
| 1163 | return false; |
| 1164 | } |
| 1165 | |
Johan Hedberg | 301cb2d | 2014-02-18 10:19:34 +0200 | [diff] [blame] | 1166 | static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type) |
| 1167 | { |
Andre Guedes | dbbfa2a | 2014-06-25 16:44:45 -0300 | [diff] [blame] | 1168 | if (addr_type != ADDR_LE_DEV_RANDOM) |
Johan Hedberg | 301cb2d | 2014-02-18 10:19:34 +0200 | [diff] [blame] | 1169 | return false; |
| 1170 | |
| 1171 | if ((bdaddr->b[5] & 0xc0) == 0x40) |
| 1172 | return true; |
| 1173 | |
| 1174 | return false; |
| 1175 | } |
| 1176 | |
Johan Hedberg | 2426f3a | 2014-02-18 17:14:36 +0200 | [diff] [blame] | 1177 | static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev, |
| 1178 | bdaddr_t *bdaddr, u8 addr_type) |
| 1179 | { |
| 1180 | if (!hci_bdaddr_is_rpa(bdaddr, addr_type)) |
| 1181 | return NULL; |
| 1182 | |
| 1183 | return hci_find_irk_by_rpa(hdev, bdaddr); |
| 1184 | } |
| 1185 | |
Andre Guedes | d4905f2 | 2014-06-25 21:52:52 -0300 | [diff] [blame] | 1186 | static inline int hci_check_conn_params(u16 min, u16 max, u16 latency, |
| 1187 | u16 to_multiplier) |
| 1188 | { |
| 1189 | u16 max_latency; |
| 1190 | |
| 1191 | if (min > max || min < 6 || max > 3200) |
| 1192 | return -EINVAL; |
| 1193 | |
| 1194 | if (to_multiplier < 10 || to_multiplier > 3200) |
| 1195 | return -EINVAL; |
| 1196 | |
| 1197 | if (max >= to_multiplier * 8) |
| 1198 | return -EINVAL; |
| 1199 | |
| 1200 | max_latency = (to_multiplier * 8 / max) - 1; |
| 1201 | if (latency > 499 || latency > max_latency) |
| 1202 | return -EINVAL; |
| 1203 | |
| 1204 | return 0; |
| 1205 | } |
| 1206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | int hci_register_cb(struct hci_cb *hcb); |
| 1208 | int hci_unregister_cb(struct hci_cb *hcb); |
| 1209 | |
Johan Hedberg | 3119ae9 | 2013-03-05 20:37:44 +0200 | [diff] [blame] | 1210 | struct hci_request { |
| 1211 | struct hci_dev *hdev; |
| 1212 | struct sk_buff_head cmd_q; |
Andre Guedes | 5d73e03 | 2013-03-08 11:20:16 -0300 | [diff] [blame] | 1213 | |
| 1214 | /* If something goes wrong when building the HCI request, the error |
| 1215 | * value is stored in this field. |
| 1216 | */ |
| 1217 | int err; |
Johan Hedberg | 3119ae9 | 2013-03-05 20:37:44 +0200 | [diff] [blame] | 1218 | }; |
| 1219 | |
| 1220 | void hci_req_init(struct hci_request *req, struct hci_dev *hdev); |
| 1221 | 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] | 1222 | void hci_req_add(struct hci_request *req, u16 opcode, u32 plen, |
| 1223 | const void *param); |
| 1224 | void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen, |
| 1225 | const void *param, u8 event); |
Johan Hedberg | 9238f36 | 2013-03-05 20:37:48 +0200 | [diff] [blame] | 1226 | 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] | 1227 | |
Andre Guedes | b1efcc2 | 2014-02-26 20:21:40 -0300 | [diff] [blame] | 1228 | void hci_req_add_le_scan_disable(struct hci_request *req); |
Andre Guedes | 8ef30fd | 2014-02-26 20:21:55 -0300 | [diff] [blame] | 1229 | void hci_req_add_le_passive_scan(struct hci_request *req); |
Andre Guedes | b1efcc2 | 2014-02-26 20:21:40 -0300 | [diff] [blame] | 1230 | |
Johan Hedberg | 75e84b7 | 2013-04-02 13:35:04 +0300 | [diff] [blame] | 1231 | 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] | 1232 | const void *param, u32 timeout); |
Johan Hedberg | 7b1abbb | 2013-04-03 21:54:47 +0300 | [diff] [blame] | 1233 | 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] | 1234 | const void *param, u8 event, u32 timeout); |
Johan Hedberg | 75e84b7 | 2013-04-02 13:35:04 +0300 | [diff] [blame] | 1235 | |
Johan Hedberg | 07dc93d | 2013-04-19 10:14:51 +0300 | [diff] [blame] | 1236 | int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, |
| 1237 | const void *param); |
Luiz Augusto von Dentz | 73d80de | 2011-11-02 15:52:01 +0200 | [diff] [blame] | 1238 | 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] | 1239 | void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Marcel Holtmann | a9de924 | 2007-10-20 13:33:56 +0200 | [diff] [blame] | 1241 | void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | /* ----- HCI Sockets ----- */ |
Marcel Holtmann | 470fe1b | 2012-02-20 14:50:30 +0100 | [diff] [blame] | 1244 | void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); |
| 1245 | 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] | 1246 | 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] | 1247 | |
Marcel Holtmann | 040030e | 2012-02-20 14:50:37 +0100 | [diff] [blame] | 1248 | void hci_sock_dev_event(struct hci_dev *hdev, int event); |
| 1249 | |
Johan Hedberg | 0381101 | 2010-12-08 00:21:06 +0200 | [diff] [blame] | 1250 | /* Management interface */ |
Andre Guedes | 591f47f | 2012-04-24 21:02:49 -0300 | [diff] [blame] | 1251 | #define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR)) |
| 1252 | #define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \ |
| 1253 | BIT(BDADDR_LE_RANDOM)) |
| 1254 | #define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \ |
| 1255 | BIT(BDADDR_LE_PUBLIC) | \ |
| 1256 | BIT(BDADDR_LE_RANDOM)) |
Andre Guedes | f39799f | 2012-02-17 20:39:35 -0300 | [diff] [blame] | 1257 | |
Andre Guedes | 0d8cc93 | 2013-04-30 15:29:31 -0300 | [diff] [blame] | 1258 | /* These LE scan and inquiry parameters were chosen according to LE General |
| 1259 | * Discovery Procedure specification. |
| 1260 | */ |
| 1261 | #define DISCOV_LE_SCAN_WIN 0x12 |
| 1262 | #define DISCOV_LE_SCAN_INT 0x12 |
Lukasz Rymanowski | 3d5a76f | 2014-03-27 20:55:21 +0100 | [diff] [blame] | 1263 | #define DISCOV_LE_TIMEOUT 10240 /* msec */ |
Lukasz Rymanowski | ae55f59 | 2014-03-27 20:55:19 +0100 | [diff] [blame] | 1264 | #define DISCOV_INTERLEAVED_TIMEOUT 5120 /* msec */ |
Andre Guedes | 0d8cc93 | 2013-04-30 15:29:31 -0300 | [diff] [blame] | 1265 | #define DISCOV_INTERLEAVED_INQUIRY_LEN 0x04 |
| 1266 | #define DISCOV_BREDR_INQUIRY_LEN 0x08 |
| 1267 | |
Johan Hedberg | 0381101 | 2010-12-08 00:21:06 +0200 | [diff] [blame] | 1268 | int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len); |
Marcel Holtmann | bf6b56d | 2013-10-06 23:55:45 -0700 | [diff] [blame] | 1269 | void mgmt_index_added(struct hci_dev *hdev); |
| 1270 | void mgmt_index_removed(struct hci_dev *hdev); |
Marcel Holtmann | 3eec705 | 2013-10-06 23:55:46 -0700 | [diff] [blame] | 1271 | void mgmt_set_powered_failed(struct hci_dev *hdev, int err); |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1272 | int mgmt_powered(struct hci_dev *hdev, u8 powered); |
Marcel Holtmann | d1967ff | 2013-10-15 10:57:40 -0700 | [diff] [blame] | 1273 | void mgmt_discoverable_timeout(struct hci_dev *hdev); |
Marcel Holtmann | 86a7564 | 2013-10-15 06:33:54 -0700 | [diff] [blame] | 1274 | void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable); |
Marcel Holtmann | a330916 | 2013-10-15 06:33:55 -0700 | [diff] [blame] | 1275 | void mgmt_connectable(struct hci_dev *hdev, u8 connectable); |
Johan Hedberg | 778b235 | 2014-02-24 14:52:17 +0200 | [diff] [blame] | 1276 | void mgmt_advertising(struct hci_dev *hdev, u8 advertising); |
Marcel Holtmann | 4796e8a | 2013-10-15 06:33:56 -0700 | [diff] [blame] | 1277 | 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] | 1278 | void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, |
| 1279 | bool persistent); |
Marcel Holtmann | ecd90ae | 2013-10-06 23:55:49 -0700 | [diff] [blame] | 1280 | void mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
| 1281 | u8 addr_type, u32 flags, u8 *name, u8 name_len, |
| 1282 | u8 *dev_class); |
Marcel Holtmann | 9b80ec5 | 2013-10-06 23:55:50 -0700 | [diff] [blame] | 1283 | void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Johan Hedberg | 12d4a3b | 2014-02-24 14:52:18 +0200 | [diff] [blame] | 1284 | u8 link_type, u8 addr_type, u8 reason, |
| 1285 | bool mgmt_connected); |
Marcel Holtmann | 7892924 | 2013-10-06 23:55:47 -0700 | [diff] [blame] | 1286 | void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1287 | u8 link_type, u8 addr_type, u8 status); |
Marcel Holtmann | 445608d | 2013-10-06 23:55:48 -0700 | [diff] [blame] | 1288 | void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
| 1289 | u8 addr_type, u8 status); |
Marcel Holtmann | ce0e4a0 | 2013-10-15 14:26:20 -0700 | [diff] [blame] | 1290 | 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] | 1291 | void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1292 | u8 status); |
Marcel Holtmann | 3eb3852 | 2013-10-15 14:26:22 -0700 | [diff] [blame] | 1293 | void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1294 | u8 status); |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1295 | int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, |
Johan Hedberg | 39adbff | 2014-03-20 08:18:14 +0200 | [diff] [blame] | 1296 | u8 link_type, u8 addr_type, u32 value, |
Gustavo F. Padovan | 0412468 | 2012-03-08 01:25:00 -0300 | [diff] [blame] | 1297 | u8 confirm_hint); |
Johan Hedberg | 744cf19 | 2011-11-08 20:40:14 +0200 | [diff] [blame] | 1298 | 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] | 1299 | u8 link_type, u8 addr_type, u8 status); |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1300 | 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] | 1301 | u8 link_type, u8 addr_type, u8 status); |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1302 | 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] | 1303 | u8 link_type, u8 addr_type); |
Brian Gix | 604086b | 2011-11-23 08:28:33 -0800 | [diff] [blame] | 1304 | 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] | 1305 | u8 link_type, u8 addr_type, u8 status); |
Johan Hedberg | 272d90d | 2012-02-09 15:26:12 +0200 | [diff] [blame] | 1306 | 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] | 1307 | u8 link_type, u8 addr_type, u8 status); |
Johan Hedberg | 92a2525 | 2012-09-06 18:39:26 +0300 | [diff] [blame] | 1308 | int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1309 | u8 link_type, u8 addr_type, u32 passkey, |
| 1310 | u8 entered); |
Marcel Holtmann | e546099 | 2013-10-15 14:26:23 -0700 | [diff] [blame] | 1311 | void mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
| 1312 | u8 addr_type, u8 status); |
Marcel Holtmann | 464996a | 2013-10-15 14:26:24 -0700 | [diff] [blame] | 1313 | void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status); |
Marcel Holtmann | 3e24856 | 2013-10-15 14:26:25 -0700 | [diff] [blame] | 1314 | 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] | 1315 | 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] | 1316 | void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, |
| 1317 | u8 status); |
Marcel Holtmann | 7667da3 | 2013-10-15 14:26:27 -0700 | [diff] [blame] | 1318 | 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] | 1319 | void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192, |
| 1320 | u8 *randomizer192, u8 *hash256, |
| 1321 | u8 *randomizer256, u8 status); |
Marcel Holtmann | 901801b | 2013-10-06 23:55:51 -0700 | [diff] [blame] | 1322 | 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] | 1323 | u8 addr_type, u8 *dev_class, s8 rssi, u32 flags, |
| 1324 | u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len); |
Marcel Holtmann | 9cf12ae | 2013-10-06 23:55:52 -0700 | [diff] [blame] | 1325 | void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, |
| 1326 | u8 addr_type, s8 rssi, u8 *name, u8 name_len); |
Marcel Holtmann | 2f1e063 | 2013-10-06 23:55:53 -0700 | [diff] [blame] | 1327 | void mgmt_discovering(struct hci_dev *hdev, u8 discovering); |
Johan Hedberg | 88c1fe4 | 2012-02-09 15:56:11 +0200 | [diff] [blame] | 1328 | int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); |
| 1329 | 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] | 1330 | 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] | 1331 | void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk); |
Marcel Holtmann | 53ac6ab | 2014-03-09 23:38:42 -0700 | [diff] [blame] | 1332 | void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, |
| 1333 | bool persistent); |
Marcel Holtmann | 5976e60 | 2013-10-06 04:08:14 -0700 | [diff] [blame] | 1334 | void mgmt_reenable_advertising(struct hci_dev *hdev); |
Johan Hedberg | f4a407b | 2014-02-18 21:41:34 +0200 | [diff] [blame] | 1335 | void mgmt_smp_complete(struct hci_conn *conn, bool complete); |
Vinicius Costa Gomes | 346af67 | 2012-02-02 21:08:02 -0300 | [diff] [blame] | 1336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | /* HCI info for socket */ |
| 1338 | #define hci_pi(sk) ((struct hci_pinfo *) sk) |
| 1339 | |
| 1340 | struct hci_pinfo { |
| 1341 | struct bt_sock bt; |
| 1342 | struct hci_dev *hdev; |
| 1343 | struct hci_filter filter; |
| 1344 | __u32 cmsg_mask; |
Johan Hedberg | c02178d | 2010-12-08 00:21:05 +0200 | [diff] [blame] | 1345 | unsigned short channel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | }; |
| 1347 | |
| 1348 | /* HCI security filter */ |
| 1349 | #define HCI_SFLT_MAX_OGF 5 |
| 1350 | |
| 1351 | struct hci_sec_filter { |
| 1352 | __u32 type_mask; |
| 1353 | __u32 event_mask[2]; |
| 1354 | __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4]; |
| 1355 | }; |
| 1356 | |
| 1357 | /* ----- HCI requests ----- */ |
| 1358 | #define HCI_REQ_DONE 0 |
| 1359 | #define HCI_REQ_PEND 1 |
| 1360 | #define HCI_REQ_CANCELED 2 |
| 1361 | |
Thomas Gleixner | a6a67ef | 2009-07-26 08:18:19 +0000 | [diff] [blame] | 1362 | #define hci_req_lock(d) mutex_lock(&d->req_lock) |
| 1363 | #define hci_req_unlock(d) mutex_unlock(&d->req_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | |
Claudio Takahasi | 2ce603e | 2011-02-16 20:44:53 -0200 | [diff] [blame] | 1365 | void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, |
| 1366 | u16 latency, u16 to_multiplier); |
Marcel Holtmann | fe39c7b | 2014-02-27 16:00:28 -0800 | [diff] [blame] | 1367 | 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] | 1368 | __u8 ltk[16]); |
Andre Guedes | 2519a1f | 2011-11-07 11:45:24 -0300 | [diff] [blame] | 1369 | |
Marcel Holtmann | 94b1fc9 | 2014-02-23 20:25:54 -0800 | [diff] [blame] | 1370 | int hci_update_random_address(struct hci_request *req, bool require_privacy, |
| 1371 | u8 *own_addr_type); |
Johan Hedberg | a1f4c31 | 2014-02-27 14:05:41 +0200 | [diff] [blame] | 1372 | void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, |
| 1373 | u8 *bdaddr_type); |
Johan Hedberg | ebd3a74 | 2014-02-23 19:42:21 +0200 | [diff] [blame] | 1374 | |
Frédéric Dalleau | 5d4d62f | 2013-08-19 14:23:57 +0200 | [diff] [blame] | 1375 | #define SCO_AIRMODE_MASK 0x0003 |
| 1376 | #define SCO_AIRMODE_CVSD 0x0000 |
| 1377 | #define SCO_AIRMODE_TRANSP 0x0003 |
| 1378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | #endif /* __HCI_CORE_H */ |