blob: 3fbb793e634d8d344d59e6a460de18d52f61c2fb [file] [log] [blame]
Ron Shaffer04fafe42010-05-28 11:53:45 -04001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 BlueZ - Bluetooth protocol stack for Linux
Ron Shaffer2d0a0342010-05-28 11:53:46 -04003 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
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 Shaffer04fafe42010-05-28 11:53:45 -040015 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 Torvalds1da177e2005-04-16 15:20:36 -070018 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
Ron Shaffer04fafe42010-05-28 11:53:45 -040020 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 SOFTWARE IS DISCLAIMED.
23*/
24
25#ifndef __HCI_CORE_H
26#define __HCI_CORE_H
27
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <net/bluetooth/hci.h>
Marcel Holtmannf49daa82014-07-11 04:58:29 +020029#include <net/bluetooth/hci_sock.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Luiz Augusto von Dentz5e59b792011-11-01 10:58:57 +020031/* HCI priority */
32#define HCI_PRIO_MAX 7
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/* HCI Core structures */
Linus Torvalds1da177e2005-04-16 15:20:36 -070035struct inquiry_data {
36 bdaddr_t bdaddr;
37 __u8 pscan_rep_mode;
38 __u8 pscan_period_mode;
39 __u8 pscan_mode;
40 __u8 dev_class[3];
Marcel Holtmann1ebb9252005-11-08 09:57:21 -080041 __le16 clock_offset;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 __s8 rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +020043 __u8 ssp_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070044};
45
46struct inquiry_entry {
Johan Hedberg561aafb2012-01-04 13:31:59 +020047 struct list_head all; /* inq_cache.all */
48 struct list_head list; /* unknown or resolve */
49 enum {
50 NAME_NOT_KNOWN,
51 NAME_NEEDED,
52 NAME_PENDING,
53 NAME_KNOWN,
54 } name_state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 __u32 timestamp;
56 struct inquiry_data data;
57};
58
Johan Hedberg30883512012-01-04 14:16:21 +020059struct discovery_state {
Gustavo F. Padovanf64b9932012-03-06 23:48:33 -030060 int type;
Johan Hedbergff9ef572012-01-04 14:23:45 +020061 enum {
62 DISCOVERY_STOPPED,
63 DISCOVERY_STARTING,
Andre Guedes343f9352012-02-17 20:39:37 -030064 DISCOVERY_FINDING,
Johan Hedberg30dc78e2012-01-04 15:44:20 +020065 DISCOVERY_RESOLVING,
Johan Hedbergff9ef572012-01-04 14:23:45 +020066 DISCOVERY_STOPPING,
67 } state;
Gustavo Padovanc3c7ea62012-05-23 04:04:20 -030068 struct list_head all; /* All devices found during inquiry */
Gustavo F. Padovanf64b9932012-03-06 23:48:33 -030069 struct list_head unknown; /* Name state not known */
70 struct list_head resolve; /* Name needs to be resolved */
71 __u32 timestamp;
Johan Hedbergb9a63282014-03-25 10:51:52 +020072 bdaddr_t last_adv_addr;
73 u8 last_adv_addr_type;
Johan Hedbergff5cd292014-03-25 14:40:52 +020074 s8 last_adv_rssi;
Marcel Holtmannc70a7e42014-07-01 14:11:21 +020075 u32 last_adv_flags;
Johan Hedbergb9a63282014-03-25 10:51:52 +020076 u8 last_adv_data[HCI_MAX_AD_LENGTH];
77 u8 last_adv_data_len;
Marcel Holtmannda25cf62014-12-05 13:03:35 +010078 bool report_invalid_rssi;
Jakub Pawlowski82f8b652015-03-04 16:24:26 -080079 bool result_filtering;
Jakub Pawlowski37eab042014-12-05 10:55:55 +010080 s8 rssi;
81 u16 uuid_count;
82 u8 (*uuids)[16];
Jakub Pawlowski2d28cfe2015-02-01 23:07:54 -080083 unsigned long scan_start;
84 unsigned long scan_duration;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
87struct hci_conn_hash {
88 struct list_head list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 unsigned int acl_num;
Andrei Emeltchenkobd1eb662012-10-10 17:38:30 +030090 unsigned int amp_num;
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 unsigned int sco_num;
Ville Tervofcd89c02011-02-10 22:38:47 -030092 unsigned int le_num;
Johan Hedbergf8218dc2014-07-16 11:56:08 +030093 unsigned int le_num_slave;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094};
95
Johan Hedbergf0358562010-05-18 13:20:32 +020096struct bdaddr_list {
97 struct list_head list;
98 bdaddr_t bdaddr;
Marcel Holtmannb9ee0a72013-10-17 17:24:13 -070099 u8 bdaddr_type;
Johan Hedbergf0358562010-05-18 13:20:32 +0200100};
Johan Hedberg2aeb9a12011-01-04 12:08:51 +0200101
102struct bt_uuid {
103 struct list_head list;
104 u8 uuid[16];
Johan Hedberg83be8ec2013-01-27 00:31:29 +0200105 u8 size;
Johan Hedberg1aff6f02011-01-13 21:56:52 +0200106 u8 svc_hint;
Johan Hedberg2aeb9a12011-01-04 12:08:51 +0200107};
108
Marcel Holtmann7ee4ea32014-03-09 12:19:17 -0700109struct smp_csrk {
110 bdaddr_t bdaddr;
111 u8 bdaddr_type;
Johan Hedberg4cd39282015-02-27 10:11:13 +0200112 u8 type;
Marcel Holtmann7ee4ea32014-03-09 12:19:17 -0700113 u8 val[16];
114};
115
Vinicius Costa Gomesb899efa2012-02-02 21:08:00 -0300116struct smp_ltk {
117 struct list_head list;
Johan Hedberg970d0f12014-11-13 14:37:47 +0200118 struct rcu_head rcu;
Vinicius Costa Gomesb899efa2012-02-02 21:08:00 -0300119 bdaddr_t bdaddr;
120 u8 bdaddr_type;
121 u8 authenticated;
122 u8 type;
123 u8 enc_size;
124 __le16 ediv;
Marcel Holtmannfe39c7b2014-02-27 16:00:28 -0800125 __le64 rand;
Vinicius Costa Gomesb899efa2012-02-02 21:08:00 -0300126 u8 val[16];
Marcel Holtmann03c515d2014-01-31 18:42:18 -0800127};
Vinicius Costa Gomesb899efa2012-02-02 21:08:00 -0300128
Johan Hedberg970c4e42014-02-18 10:19:33 +0200129struct smp_irk {
130 struct list_head list;
Johan Hedbergadae20c2014-11-13 14:37:48 +0200131 struct rcu_head rcu;
Johan Hedberg970c4e42014-02-18 10:19:33 +0200132 bdaddr_t rpa;
133 bdaddr_t bdaddr;
134 u8 addr_type;
135 u8 val[16];
136};
137
Johan Hedberg55ed8ca12011-01-17 14:41:05 +0200138struct link_key {
139 struct list_head list;
Johan Hedberg0378b592014-11-19 15:22:22 +0200140 struct rcu_head rcu;
Johan Hedberg55ed8ca12011-01-17 14:41:05 +0200141 bdaddr_t bdaddr;
142 u8 type;
Andrei Emeltchenko9b3b4462012-05-23 11:31:20 +0300143 u8 val[HCI_LINK_KEY_SIZE];
Johan Hedberg55ed8ca12011-01-17 14:41:05 +0200144 u8 pin_len;
145};
146
Szymon Janc2763eda2011-03-22 13:12:22 +0100147struct oob_data {
148 struct list_head list;
149 bdaddr_t bdaddr;
Johan Hedberg6928a922014-10-26 20:46:09 +0100150 u8 bdaddr_type;
Marcel Holtmannf7697b12015-01-30 23:20:55 -0800151 u8 present;
Marcel Holtmann519ca9d2014-01-10 02:07:28 -0800152 u8 hash192[16];
Johan Hedberg38da1702014-11-17 20:52:20 +0200153 u8 rand192[16];
Marcel Holtmann519ca9d2014-01-10 02:07:28 -0800154 u8 hash256[16];
Johan Hedberg38da1702014-11-17 20:52:20 +0200155 u8 rand256[16];
Szymon Janc2763eda2011-03-22 13:12:22 +0100156};
157
Arman Uguray203fea02015-03-23 15:57:11 -0700158struct adv_info {
Arman Uguray912098a2015-03-23 15:57:15 -0700159 struct delayed_work timeout_exp;
Arman Uguray203fea02015-03-23 15:57:11 -0700160 __u8 instance;
161 __u32 flags;
Arman Uguray912098a2015-03-23 15:57:15 -0700162 __u16 timeout;
Arman Uguray203fea02015-03-23 15:57:11 -0700163 __u16 adv_data_len;
164 __u8 adv_data[HCI_MAX_AD_LENGTH];
165 __u16 scan_rsp_len;
166 __u8 scan_rsp_data[HCI_MAX_AD_LENGTH];
167};
168
Johan Hedberg490c5ba2012-02-22 19:19:09 +0200169#define HCI_MAX_SHORT_NAME_LENGTH 10
170
Johan Hedbergd6bfd592014-02-23 19:42:20 +0200171/* Default LE RPA expiry time, 15 minutes */
172#define HCI_DEFAULT_RPA_TIMEOUT (15 * 60)
173
Andrzej Kaczmarek31ad1692014-05-14 13:43:02 +0200174/* Default min/max age of connection information (1s/3s) */
175#define DEFAULT_CONN_INFO_MIN_AGE 1000
176#define DEFAULT_CONN_INFO_MAX_AGE 3000
177
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300178struct amp_assoc {
179 __u16 len;
180 __u16 offset;
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +0300181 __u16 rem_len;
182 __u16 len_so_far;
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300183 __u8 data[HCI_MAX_AMP_ASSOC_SIZE];
184};
185
Johan Hedbergd2c5d772013-04-17 15:00:52 +0300186#define HCI_MAX_PAGES 3
Johan Hedbergcad718e2013-04-17 15:00:51 +0300187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188struct hci_dev {
189 struct list_head list;
Gustavo F. Padovan09fd0de2011-06-17 13:03:21 -0300190 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 char name[8];
193 unsigned long flags;
194 __u16 id;
Marcel Holtmannc13854c2010-02-08 15:27:07 +0100195 __u8 bus;
Marcel Holtmann943da252010-02-13 02:28:41 +0100196 __u8 dev_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 bdaddr_t bdaddr;
Marcel Holtmanne30d3f52014-07-05 10:48:03 +0200198 bdaddr_t setup_addr;
Marcel Holtmann24c457e2014-07-02 00:53:47 +0200199 bdaddr_t public_addr;
Marcel Holtmann7a4cd512014-02-19 19:52:13 -0800200 bdaddr_t random_addr;
Marcel Holtmannd13eafc2013-10-02 04:41:30 -0700201 bdaddr_t static_addr;
Johan Hedberg56ed2cb2014-02-27 14:05:40 +0200202 __u8 adv_addr_type;
Johan Hedberg1f6c6372011-03-16 14:29:35 +0200203 __u8 dev_name[HCI_MAX_NAME_LENGTH];
Johan Hedberg490c5ba2012-02-22 19:19:09 +0200204 __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH];
Johan Hedberg80a1e1d2011-03-28 14:07:23 +0300205 __u8 eir[HCI_MAX_EIR_LENGTH];
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200206 __u8 dev_class[3];
Johan Hedberg1aff6f02011-01-13 21:56:52 +0200207 __u8 major_class;
208 __u8 minor_class;
Johan Hedbergd2c5d772013-04-17 15:00:52 +0300209 __u8 max_page;
Johan Hedbergcad718e2013-04-17 15:00:51 +0300210 __u8 features[HCI_MAX_PAGES][8];
Johan Hedberg60e77322013-01-22 14:01:59 +0200211 __u8 le_features[8];
Johan Hedbergcf1d0812013-01-22 14:02:00 +0200212 __u8 le_white_list_size;
Johan Hedberg9b008c02013-01-22 14:02:01 +0200213 __u8 le_states[8];
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200214 __u8 commands[64];
Marcel Holtmann1143e5a2006-09-23 09:57:20 +0200215 __u8 hci_ver;
216 __u16 hci_rev;
Johan Hedbergd5859e22011-01-25 01:19:58 +0200217 __u8 lmp_ver;
Marcel Holtmann1143e5a2006-09-23 09:57:20 +0200218 __u16 manufacturer;
Andrei Emeltchenko7d692302012-03-09 11:46:49 +0200219 __u16 lmp_subver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 __u16 voice_setting;
Marcel Holtmannb4cb9fb2013-10-14 13:56:16 -0700221 __u8 num_iac;
Marcel Holtmannc2f0f972015-01-12 09:21:25 -0800222 __u8 stored_max_keys;
223 __u8 stored_num_keys;
Johan Hedberg17fa4b92011-01-25 13:28:33 +0200224 __u8 io_capability;
Marcel Holtmann91c4e9b2012-03-11 19:27:21 -0700225 __s8 inq_tx_power;
Johan Hedbergf332ec62013-03-15 17:07:11 -0500226 __u16 page_scan_interval;
227 __u16 page_scan_window;
228 __u8 page_scan_type;
Marcel Holtmann3f959d42014-02-20 11:55:56 -0800229 __u8 le_adv_channel_map;
Georg Lukas628531c2014-07-26 13:59:57 +0200230 __u16 le_adv_min_interval;
231 __u16 le_adv_max_interval;
Marcel Holtmann533553f2014-03-21 12:18:10 -0700232 __u8 le_scan_type;
Marcel Holtmannbef64732013-10-11 08:23:19 -0700233 __u16 le_scan_interval;
234 __u16 le_scan_window;
Marcel Holtmann4e70c7e2013-10-19 07:09:13 -0700235 __u16 le_conn_min_interval;
236 __u16 le_conn_max_interval;
Marcel Holtmann04fb7d92014-06-30 12:34:36 +0200237 __u16 le_conn_latency;
238 __u16 le_supv_timeout;
Marcel Holtmanna8e1bfa2014-12-20 16:28:40 +0100239 __u16 le_def_tx_len;
240 __u16 le_def_tx_time;
241 __u16 le_max_tx_len;
242 __u16 le_max_tx_time;
243 __u16 le_max_rx_len;
244 __u16 le_max_rx_time;
Lukasz Rymanowskib9a7a612014-03-27 20:55:20 +0100245 __u16 discov_interleaved_timeout;
Andrzej Kaczmarek31ad1692014-05-14 13:43:02 +0200246 __u16 conn_info_min_age;
247 __u16 conn_info_max_age;
Marcel Holtmann06f5b772013-10-19 07:09:11 -0700248 __u8 ssp_debug_mode;
Marcel Holtmannc7741d12015-01-28 11:09:55 -0800249 __u8 hw_error_code;
Johan Hedberg33f35722014-06-28 17:54:06 +0300250 __u32 clock;
Johan Hedbergf332ec62013-03-15 17:07:11 -0500251
Marcel Holtmann2b9be132012-03-11 19:32:12 -0700252 __u16 devid_source;
253 __u16 devid_vendor;
254 __u16 devid_product;
255 __u16 devid_version;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 __u16 pkt_type;
Marcel Holtmann5b7f9902007-07-11 09:51:55 +0200258 __u16 esco_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 __u16 link_policy;
260 __u16 link_mode;
261
Marcel Holtmann04837f62006-07-03 10:02:33 +0200262 __u32 idle_timeout;
263 __u16 sniff_min_interval;
264 __u16 sniff_max_interval;
265
Andrei Emeltchenko928abaa2011-10-12 10:53:57 +0300266 __u8 amp_status;
267 __u32 amp_total_bw;
268 __u32 amp_max_bw;
269 __u32 amp_min_latency;
270 __u32 amp_max_pdu;
271 __u8 amp_type;
272 __u16 amp_pal_cap;
273 __u16 amp_assoc_size;
274 __u32 amp_max_flush_to;
275 __u32 amp_be_flush_to;
276
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300277 struct amp_assoc loc_assoc;
278
Andrei Emeltchenko1e89cff2011-11-24 14:52:02 +0200279 __u8 flow_ctl_mode;
280
Johan Hedberg9f616562011-04-28 11:28:54 -0700281 unsigned int auto_accept_delay;
282
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 unsigned long quirks;
284
285 atomic_t cmd_cnt;
286 unsigned int acl_cnt;
287 unsigned int sco_cnt;
Ville Tervo6ed58ec2011-02-10 22:38:48 -0300288 unsigned int le_cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 unsigned int acl_mtu;
291 unsigned int sco_mtu;
Ville Tervo6ed58ec2011-02-10 22:38:48 -0300292 unsigned int le_mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 unsigned int acl_pkts;
294 unsigned int sco_pkts;
Ville Tervo6ed58ec2011-02-10 22:38:48 -0300295 unsigned int le_pkts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296
Andrei Emeltchenko350ee4c2011-12-07 15:56:51 +0200297 __u16 block_len;
298 __u16 block_mtu;
299 __u16 num_blocks;
300 __u16 block_cnt;
301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 unsigned long acl_last_tx;
303 unsigned long sco_last_tx;
Ville Tervo6ed58ec2011-02-10 22:38:48 -0300304 unsigned long le_last_tx;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305
Marcel Holtmannf48fd9c2010-03-20 15:20:04 +0100306 struct workqueue_struct *workqueue;
Johan Hedberg6ead1bb2013-01-14 22:33:50 +0200307 struct workqueue_struct *req_workqueue;
Marcel Holtmannf48fd9c2010-03-20 15:20:04 +0100308
Johan Hedbergab81cbf2010-12-15 13:53:18 +0200309 struct work_struct power_on;
Johan Hedberg32435532011-11-07 22:16:04 +0200310 struct delayed_work power_off;
Marcel Holtmannc7741d12015-01-28 11:09:55 -0800311 struct work_struct error_reset;
Johan Hedbergab81cbf2010-12-15 13:53:18 +0200312
Johan Hedberg16ab91a2011-11-07 22:16:02 +0200313 __u16 discov_timeout;
314 struct delayed_work discov_off;
315
Johan Hedberg7d785252011-12-15 00:47:39 +0200316 struct delayed_work service_cache;
317
Marcel Holtmann65cc2b42014-06-16 12:30:56 +0200318 struct delayed_work cmd_timer;
Marcel Holtmannb78752c2010-08-08 23:06:53 -0400319
320 struct work_struct rx_work;
Gustavo F. Padovanc347b762011-12-14 23:53:47 -0200321 struct work_struct cmd_work;
Gustavo F. Padovan3eff45e2011-12-15 00:50:02 -0200322 struct work_struct tx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 struct sk_buff_head rx_q;
325 struct sk_buff_head raw_q;
326 struct sk_buff_head cmd_q;
327
328 struct sk_buff *sent_cmd;
329
Thomas Gleixnera6a67ef2009-07-26 08:18:19 +0000330 struct mutex req_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 wait_queue_head_t req_wait_q;
332 __u32 req_status;
333 __u32 req_result;
Johan Hedbergf60cb302015-04-02 13:41:09 +0300334 struct sk_buff *req_skb;
Johan Hedberga5040ef2011-01-10 13:28:59 +0200335
Johan Hedberg70db83c2014-08-08 09:37:16 +0300336 void *smp_data;
Johan Hedbergef8efe42014-08-13 15:12:32 +0300337 void *smp_bredr_data;
Johan Hedberg2e58ef32011-11-08 20:40:15 +0200338
Johan Hedberg30883512012-01-04 14:16:21 +0200339 struct discovery_state discovery;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 struct hci_conn_hash conn_hash;
Andre Guedes5c136e92014-01-30 18:22:05 -0300341
342 struct list_head mgmt_pending;
David Millerea4bd8b2010-07-30 21:54:49 -0700343 struct list_head blacklist;
Johan Hedberg66593582014-07-09 12:59:14 +0300344 struct list_head whitelist;
Johan Hedberg2aeb9a12011-01-04 12:08:51 +0200345 struct list_head uuids;
Johan Hedberg55ed8ca12011-01-17 14:41:05 +0200346 struct list_head link_keys;
Vinicius Costa Gomesb899efa2012-02-02 21:08:00 -0300347 struct list_head long_term_keys;
Johan Hedberg970c4e42014-02-18 10:19:33 +0200348 struct list_head identity_resolving_keys;
Szymon Janc2763eda2011-03-22 13:12:22 +0100349 struct list_head remote_oob_data;
Marcel Holtmannd2ab0ac2014-02-27 20:37:30 -0800350 struct list_head le_white_list;
Andre Guedes15819a72014-02-03 13:56:18 -0300351 struct list_head le_conn_params;
Andre Guedes77a77a32014-02-26 20:21:46 -0300352 struct list_head pend_le_conns;
Johan Hedberg66f84552014-07-04 12:37:18 +0300353 struct list_head pend_le_reports;
Szymon Janc2763eda2011-03-22 13:12:22 +0100354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 struct hci_dev_stats stat;
356
Andrei Emeltchenko70f230202010-12-01 16:58:25 +0200357 atomic_t promisc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Marcel Holtmannca325f62010-02-08 16:22:31 +0100359 struct dentry *debugfs;
360
Marcel Holtmanna91f2e32006-07-03 10:02:41 +0200361 struct device dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Marcel Holtmann611b30f2009-06-08 14:41:38 +0200363 struct rfkill *rfkill;
364
Marcel Holtmanneacb44d2015-03-13 09:04:17 -0700365 DECLARE_BITMAP(dev_flags, __HCI_NUM_FLAGS);
Andre Guedesd23264a2011-11-25 20:53:38 -0300366
Andre Guedes7ba8b4b2012-02-03 17:47:59 -0300367 struct delayed_work le_scan_disable;
Jakub Pawlowski2d28cfe2015-02-01 23:07:54 -0800368 struct delayed_work le_scan_restart;
Andre Guedes7ba8b4b2012-02-03 17:47:59 -0300369
Johan Hedberg8fa19092012-10-19 20:57:49 +0300370 __s8 adv_tx_power;
Johan Hedberg3f0f5242012-11-08 01:23:00 +0100371 __u8 adv_data[HCI_MAX_AD_LENGTH];
372 __u8 adv_data_len;
Marcel Holtmannf8e808b2013-10-16 00:16:47 -0700373 __u8 scan_rsp_data[HCI_MAX_AD_LENGTH];
374 __u8 scan_rsp_data_len;
Johan Hedberg8fa19092012-10-19 20:57:49 +0300375
Arman Uguray203fea02015-03-23 15:57:11 -0700376 struct adv_info adv_instance;
377
Johan Hedberg863efaf2014-02-22 19:06:32 +0200378 __u8 irk[16];
Johan Hedbergd6bfd592014-02-23 19:42:20 +0200379 __u32 rpa_timeout;
380 struct delayed_work rpa_expired;
Marcel Holtmann2b5224d2014-02-23 20:39:22 -0800381 bdaddr_t rpa;
Johan Hedberg863efaf2014-02-22 19:06:32 +0200382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 int (*open)(struct hci_dev *hdev);
384 int (*close)(struct hci_dev *hdev);
385 int (*flush)(struct hci_dev *hdev);
Marcel Holtmannf41c70c2012-11-12 14:02:14 +0900386 int (*setup)(struct hci_dev *hdev);
Tedd Ho-Jeong Ana44fecb2015-02-13 09:20:50 -0800387 int (*shutdown)(struct hci_dev *hdev);
Marcel Holtmann7bd8f092013-10-11 06:19:18 -0700388 int (*send)(struct hci_dev *hdev, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 void (*notify)(struct hci_dev *hdev, unsigned int evt);
Marcel Holtmannc7741d12015-01-28 11:09:55 -0800390 void (*hw_error)(struct hci_dev *hdev, u8 code);
Marcel Holtmann24c457e2014-07-02 00:53:47 +0200391 int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392};
393
Andrei Emeltchenko53502d62012-10-10 17:38:27 +0300394#define HCI_PHY_HANDLE(handle) (handle & 0xff)
395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396struct hci_conn {
397 struct list_head list;
398
Szymon Jancadc42662011-02-17 16:42:00 +0100399 atomic_t refcnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Szymon Jancadc42662011-02-17 16:42:00 +0100401 bdaddr_t dst;
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +0200402 __u8 dst_type;
Marcel Holtmann662e8822013-10-13 05:23:59 -0700403 bdaddr_t src;
Marcel Holtmanne7c40962013-10-13 03:57:39 -0700404 __u8 src_type;
Johan Hedbergcb1d68f2014-02-28 12:54:16 +0200405 bdaddr_t init_addr;
406 __u8 init_addr_type;
407 bdaddr_t resp_addr;
408 __u8 resp_addr_type;
Szymon Jancadc42662011-02-17 16:42:00 +0100409 __u16 handle;
410 __u16 state;
411 __u8 mode;
412 __u8 type;
Johan Hedberg40bef302014-07-16 11:42:27 +0300413 __u8 role;
Johan Hedberga0c808b2012-01-16 09:49:58 +0200414 bool out;
Szymon Jancadc42662011-02-17 16:42:00 +0100415 __u8 attempt;
416 __u8 dev_class[3];
Johan Hedbergcad718e2013-04-17 15:00:51 +0300417 __u8 features[HCI_MAX_PAGES][8];
Szymon Jancadc42662011-02-17 16:42:00 +0100418 __u16 pkt_type;
419 __u16 link_policy;
Waldemar Rymarkiewicz13d39312011-04-28 12:07:55 +0200420 __u8 key_type;
Szymon Jancadc42662011-02-17 16:42:00 +0100421 __u8 auth_type;
422 __u8 sec_level;
423 __u8 pending_sec_level;
424 __u8 pin_length;
Vinicius Costa Gomes726b4ff2011-07-08 18:31:45 -0300425 __u8 enc_key_size;
Szymon Jancadc42662011-02-17 16:42:00 +0100426 __u8 io_capability;
Johan Hedberg92a25252012-09-06 18:39:26 +0300427 __u32 passkey_notify;
428 __u8 passkey_entered;
Szymon Jancadc42662011-02-17 16:42:00 +0100429 __u16 disc_timeout;
Johan Hedberg09ae2602014-07-06 13:41:15 +0300430 __u16 conn_timeout;
Frédéric Dalleau10c62dd2013-08-19 14:23:59 +0200431 __u16 setting;
Andre Guedes1e406ee2014-01-30 18:22:04 -0300432 __u16 le_conn_min_interval;
433 __u16 le_conn_max_interval;
Marcel Holtmanne04fde62014-06-23 11:40:04 +0200434 __u16 le_conn_interval;
435 __u16 le_conn_latency;
436 __u16 le_supv_timeout;
Alfonso Acostafd45ada2014-10-07 08:44:11 +0000437 __u8 le_adv_data[HCI_MAX_AD_LENGTH];
438 __u8 le_adv_data_len;
Andrzej Kaczmarek5ae76a92014-05-08 15:32:08 +0200439 __s8 rssi;
Andrzej Kaczmarek5a134fa2014-05-09 21:35:28 +0200440 __s8 tx_power;
Andrzej Kaczmarekd0455ed2014-05-14 13:43:05 +0200441 __s8 max_tx_power;
Johan Hedberg51a8efd2012-01-16 06:10:31 +0200442 unsigned long flags;
Marcel Holtmann04837f62006-07-03 10:02:33 +0200443
Johan Hedberg33f35722014-06-28 17:54:06 +0300444 __u32 clock;
445 __u16 clock_accuracy;
446
Andrzej Kaczmarekdd983802014-05-14 13:43:03 +0200447 unsigned long conn_info_timestamp;
448
Johan Hedberg03b555e2011-01-04 15:40:05 +0200449 __u8 remote_cap;
Johan Hedberg03b555e2011-01-04 15:40:05 +0200450 __u8 remote_auth;
Andrei Emeltchenko3161ae12012-09-27 17:26:11 +0300451 __u8 remote_id;
Johan Hedberg03b555e2011-01-04 15:40:05 +0200452
Szymon Jancadc42662011-02-17 16:42:00 +0100453 unsigned int sent;
Marcel Holtmann04837f62006-07-03 10:02:33 +0200454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 struct sk_buff_head data_q;
Gustavo F. Padovan2c33c062011-12-14 13:02:51 -0200456 struct list_head chan_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Gustavo F. Padovan19c40e32011-06-17 13:03:21 -0300458 struct delayed_work disc_work;
Johan Hedberg7bc18d92013-10-16 18:11:39 +0300459 struct delayed_work auto_accept_work;
Johan Hedberga74a84f2013-10-16 18:11:40 +0300460 struct delayed_work idle_work;
Johan Hedberg9489eca2014-02-28 17:45:46 +0200461 struct delayed_work le_conn_timeout;
Marcel Holtmann04837f62006-07-03 10:02:33 +0200462
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200463 struct device dev;
Marcel Holtmann23b9ceb2014-12-20 17:13:41 +0100464 struct dentry *debugfs;
Marcel Holtmannb219e3a2006-07-06 12:38:46 +0200465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 struct hci_dev *hdev;
467 void *l2cap_data;
468 void *sco_data;
Andrei Emeltchenko9740e492012-05-29 13:59:02 +0300469 struct amp_mgr *amp_mgr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 struct hci_conn *link;
Johan Hedberge9a416b2011-02-19 12:05:56 -0300472
473 void (*connect_cfm_cb) (struct hci_conn *conn, u8 status);
474 void (*security_cfm_cb) (struct hci_conn *conn, u8 status);
475 void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476};
477
Luiz Augusto von Dentz73d80de2011-11-02 15:52:01 +0200478struct hci_chan {
479 struct list_head list;
Andrei Emeltchenko42c4e532012-10-10 17:38:28 +0300480 __u16 handle;
Luiz Augusto von Dentz73d80de2011-11-02 15:52:01 +0200481 struct hci_conn *conn;
482 struct sk_buff_head data_q;
483 unsigned int sent;
Mat Martineau168df8e2012-10-23 15:24:13 -0700484 __u8 state;
Luiz Augusto von Dentz73d80de2011-11-02 15:52:01 +0200485};
486
Andre Guedes15819a72014-02-03 13:56:18 -0300487struct hci_conn_params {
488 struct list_head list;
Johan Hedberg93450c72014-07-04 12:37:17 +0300489 struct list_head action;
Andre Guedes15819a72014-02-03 13:56:18 -0300490
491 bdaddr_t addr;
492 u8 addr_type;
493
494 u16 conn_min_interval;
495 u16 conn_max_interval;
Marcel Holtmannf044eb02014-06-29 16:43:26 +0200496 u16 conn_latency;
497 u16 supervision_timeout;
Andre Guedes9fcb18e2014-02-26 20:21:48 -0300498
499 enum {
500 HCI_AUTO_CONN_DISABLED,
Johan Hedberga3451d22014-07-02 17:37:27 +0300501 HCI_AUTO_CONN_REPORT,
Marcel Holtmann4b9e7e72014-07-23 21:55:23 +0200502 HCI_AUTO_CONN_DIRECT,
Andre Guedes9fcb18e2014-02-26 20:21:48 -0300503 HCI_AUTO_CONN_ALWAYS,
504 HCI_AUTO_CONN_LINK_LOSS,
505 } auto_connect;
Johan Hedbergf161dd42014-08-15 21:06:54 +0300506
507 struct hci_conn *conn;
Andre Guedes15819a72014-02-03 13:56:18 -0300508};
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510extern struct list_head hci_dev_list;
511extern struct list_head hci_cb_list;
512extern rwlock_t hci_dev_list_lock;
Johan Hedbergfba7ecf2015-02-18 14:53:55 +0200513extern struct mutex hci_cb_list_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Marcel Holtmanneacb44d2015-03-13 09:04:17 -0700515#define hci_dev_set_flag(hdev, nr) set_bit((nr), (hdev)->dev_flags)
516#define hci_dev_clear_flag(hdev, nr) clear_bit((nr), (hdev)->dev_flags)
517#define hci_dev_change_flag(hdev, nr) change_bit((nr), (hdev)->dev_flags)
518#define hci_dev_test_flag(hdev, nr) test_bit((nr), (hdev)->dev_flags)
519#define hci_dev_test_and_set_flag(hdev, nr) test_and_set_bit((nr), (hdev)->dev_flags)
520#define hci_dev_test_and_clear_flag(hdev, nr) test_and_clear_bit((nr), (hdev)->dev_flags)
521#define hci_dev_test_and_change_flag(hdev, nr) test_and_change_bit((nr), (hdev)->dev_flags)
Marcel Holtmannd7a5a112015-03-13 02:11:00 -0700522
Marcel Holtmanneacb44d2015-03-13 09:04:17 -0700523#define hci_dev_clear_volatile_flags(hdev) \
524 do { \
525 hci_dev_clear_flag(hdev, HCI_LE_SCAN); \
526 hci_dev_clear_flag(hdev, HCI_LE_ADV); \
527 hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); \
528 } while (0)
Marcel Holtmann516018a2015-03-13 02:11:04 -0700529
Ulisses Furquim686ebf22011-12-21 10:11:33 -0200530/* ----- HCI interface to upper protocols ----- */
Joe Perchese74e58f2013-09-23 11:37:36 -0700531int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
Joe Perchese74e58f2013-09-23 11:37:36 -0700532int l2cap_disconn_ind(struct hci_conn *hcon);
Arron Wang9b4c3332015-06-09 17:47:22 +0800533void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
Ulisses Furquim686ebf22011-12-21 10:11:33 -0200534
Arron Wangff50e8a2015-06-09 17:47:23 +0800535#if IS_ENABLED(CONFIG_BT_BREDR)
Joe Perchese74e58f2013-09-23 11:37:36 -0700536int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
Arron Wang9b4c3332015-06-09 17:47:22 +0800537void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
Arron Wangff50e8a2015-06-09 17:47:23 +0800538#else
539static inline int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
540 __u8 *flags)
541{
542 return 0;
543}
544
545static inline void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb)
546{
547}
548#endif
Ulisses Furquim686ebf22011-12-21 10:11:33 -0200549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550/* ----- Inquiry cache ----- */
Andrei Emeltchenko70f230202010-12-01 16:58:25 +0200551#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */
552#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Johan Hedberg30883512012-01-04 14:16:21 +0200554static inline void discovery_init(struct hci_dev *hdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Johan Hedbergff9ef572012-01-04 14:23:45 +0200556 hdev->discovery.state = DISCOVERY_STOPPED;
Johan Hedberg30883512012-01-04 14:16:21 +0200557 INIT_LIST_HEAD(&hdev->discovery.all);
558 INIT_LIST_HEAD(&hdev->discovery.unknown);
559 INIT_LIST_HEAD(&hdev->discovery.resolve);
Marcel Holtmannda25cf62014-12-05 13:03:35 +0100560 hdev->discovery.report_invalid_rssi = true;
Jakub Pawlowski37eab042014-12-05 10:55:55 +0100561 hdev->discovery.rssi = HCI_RSSI_INVALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562}
563
Marcel Holtmann02563252014-12-05 11:45:21 +0100564static inline void hci_discovery_filter_clear(struct hci_dev *hdev)
565{
Jakub Pawlowski82f8b652015-03-04 16:24:26 -0800566 hdev->discovery.result_filtering = false;
Marcel Holtmannda25cf62014-12-05 13:03:35 +0100567 hdev->discovery.report_invalid_rssi = true;
Marcel Holtmann02563252014-12-05 11:45:21 +0100568 hdev->discovery.rssi = HCI_RSSI_INVALID;
569 hdev->discovery.uuid_count = 0;
570 kfree(hdev->discovery.uuids);
571 hdev->discovery.uuids = NULL;
Jakub Pawlowski2d28cfe2015-02-01 23:07:54 -0800572 hdev->discovery.scan_start = 0;
573 hdev->discovery.scan_duration = 0;
Marcel Holtmann02563252014-12-05 11:45:21 +0100574}
575
Arman Uguray203fea02015-03-23 15:57:11 -0700576static inline void adv_info_init(struct hci_dev *hdev)
577{
578 memset(&hdev->adv_instance, 0, sizeof(struct adv_info));
579}
580
Johan Hedberg30dc78e2012-01-04 15:44:20 +0200581bool hci_discovery_active(struct hci_dev *hdev);
582
Johan Hedbergff9ef572012-01-04 14:23:45 +0200583void hci_discovery_set_state(struct hci_dev *hdev, int state);
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585static inline int inquiry_cache_empty(struct hci_dev *hdev)
586{
Johan Hedberg30883512012-01-04 14:16:21 +0200587 return list_empty(&hdev->discovery.all);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
590static inline long inquiry_cache_age(struct hci_dev *hdev)
591{
Johan Hedberg30883512012-01-04 14:16:21 +0200592 struct discovery_state *c = &hdev->discovery;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 return jiffies - c->timestamp;
594}
595
596static inline long inquiry_entry_age(struct inquiry_entry *e)
597{
598 return jiffies - e->timestamp;
599}
600
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +0200601struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
Gustavo F. Padovan04124682012-03-08 01:25:00 -0300602 bdaddr_t *bdaddr);
Johan Hedberg561aafb2012-01-04 13:31:59 +0200603struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
Gustavo F. Padovan04124682012-03-08 01:25:00 -0300604 bdaddr_t *bdaddr);
Johan Hedberg30dc78e2012-01-04 15:44:20 +0200605struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
Gustavo F. Padovan04124682012-03-08 01:25:00 -0300606 bdaddr_t *bdaddr,
607 int state);
Johan Hedberga3d4e202012-01-09 00:53:02 +0200608void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
Gustavo F. Padovan04124682012-03-08 01:25:00 -0300609 struct inquiry_entry *ie);
Marcel Holtmannaf589252014-07-01 14:11:20 +0200610u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
611 bool name_known);
Andre Guedes1f9b9a52013-04-30 15:29:27 -0300612void hci_inquiry_cache_flush(struct hci_dev *hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614/* ----- HCI Connections ----- */
615enum {
616 HCI_CONN_AUTH_PEND,
Waldemar Rymarkiewicz19f8def2011-05-31 15:49:25 +0200617 HCI_CONN_REAUTH_PEND,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 HCI_CONN_ENCRYPT_PEND,
Marcel Holtmann04837f62006-07-03 10:02:33 +0200619 HCI_CONN_RSWITCH_PEND,
620 HCI_CONN_MODE_CHANGE_PEND,
Marcel Holtmanne73439d2010-07-26 10:06:00 -0400621 HCI_CONN_SCO_SETUP_PEND,
Johan Hedbergb644ba32012-01-17 21:48:47 +0200622 HCI_CONN_MGMT_CONNECTED,
Johan Hedberg58a681e2012-01-16 06:47:28 +0200623 HCI_CONN_SSP_ENABLED,
Marcel Holtmanneb9a8f32014-01-15 22:37:38 -0800624 HCI_CONN_SC_ENABLED,
Marcel Holtmannabf76ba2014-01-31 16:24:28 -0800625 HCI_CONN_AES_CCM,
Johan Hedberg58a681e2012-01-16 06:47:28 +0200626 HCI_CONN_POWER_SAVE,
Johan Hedbergaf6a9c32014-06-24 13:15:53 +0300627 HCI_CONN_FLUSH_KEY,
Johan Hedberg4dae2792014-06-24 17:03:50 +0300628 HCI_CONN_ENCRYPT,
629 HCI_CONN_AUTH,
630 HCI_CONN_SECURE,
631 HCI_CONN_FIPS,
Johan Hedbergfe59a052014-07-01 19:14:12 +0300632 HCI_CONN_STK_ENCRYPT,
Johan Hedberg977f8fc2014-07-17 15:35:39 +0300633 HCI_CONN_AUTH_INITIATOR,
Johan Hedbergf94b6652014-08-18 00:41:44 +0300634 HCI_CONN_DROP,
Alfonso Acosta89cbb062014-10-11 21:44:47 +0000635 HCI_CONN_PARAM_REMOVAL_PEND,
Johan Hedbergfe8bc5a2014-08-14 12:33:17 +0300636 HCI_CONN_NEW_LINK_KEY,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637};
638
Johan Hedbergaa64a8b2012-01-18 21:33:12 +0200639static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
640{
641 struct hci_dev *hdev = conn->hdev;
Marcel Holtmannd7a5a112015-03-13 02:11:00 -0700642 return hci_dev_test_flag(hdev, HCI_SSP_ENABLED) &&
Gustavo Padovanc3c7ea62012-05-23 04:04:20 -0300643 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
Johan Hedbergaa64a8b2012-01-18 21:33:12 +0200644}
645
Marcel Holtmanneb9a8f32014-01-15 22:37:38 -0800646static inline bool hci_conn_sc_enabled(struct hci_conn *conn)
647{
648 struct hci_dev *hdev = conn->hdev;
Marcel Holtmannd7a5a112015-03-13 02:11:00 -0700649 return hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
Marcel Holtmanneb9a8f32014-01-15 22:37:38 -0800650 test_bit(HCI_CONN_SC_ENABLED, &conn->flags);
651}
652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
654{
655 struct hci_conn_hash *h = &hdev->conn_hash;
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200656 list_add_rcu(&c->list, &h->list);
Ville Tervofcd89c02011-02-10 22:38:47 -0300657 switch (c->type) {
658 case ACL_LINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 h->acl_num++;
Ville Tervofcd89c02011-02-10 22:38:47 -0300660 break;
Andrei Emeltchenkobd1eb662012-10-10 17:38:30 +0300661 case AMP_LINK:
662 h->amp_num++;
663 break;
Ville Tervofcd89c02011-02-10 22:38:47 -0300664 case LE_LINK:
665 h->le_num++;
Johan Hedbergf8218dc2014-07-16 11:56:08 +0300666 if (c->role == HCI_ROLE_SLAVE)
667 h->le_num_slave++;
Ville Tervofcd89c02011-02-10 22:38:47 -0300668 break;
669 case SCO_LINK:
670 case ESCO_LINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 h->sco_num++;
Ville Tervofcd89c02011-02-10 22:38:47 -0300672 break;
673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674}
675
676static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
677{
678 struct hci_conn_hash *h = &hdev->conn_hash;
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200679
680 list_del_rcu(&c->list);
681 synchronize_rcu();
682
Ville Tervofcd89c02011-02-10 22:38:47 -0300683 switch (c->type) {
684 case ACL_LINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 h->acl_num--;
Ville Tervofcd89c02011-02-10 22:38:47 -0300686 break;
Andrei Emeltchenkobd1eb662012-10-10 17:38:30 +0300687 case AMP_LINK:
688 h->amp_num--;
689 break;
Ville Tervofcd89c02011-02-10 22:38:47 -0300690 case LE_LINK:
691 h->le_num--;
Johan Hedbergf8218dc2014-07-16 11:56:08 +0300692 if (c->role == HCI_ROLE_SLAVE)
693 h->le_num_slave--;
Ville Tervofcd89c02011-02-10 22:38:47 -0300694 break;
695 case SCO_LINK:
696 case ESCO_LINK:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 h->sco_num--;
Ville Tervofcd89c02011-02-10 22:38:47 -0300698 break;
699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700}
701
Luiz Augusto von Dentz52087a72011-08-17 16:23:00 +0300702static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
703{
704 struct hci_conn_hash *h = &hdev->conn_hash;
705 switch (type) {
706 case ACL_LINK:
707 return h->acl_num;
Andrei Emeltchenkobd1eb662012-10-10 17:38:30 +0300708 case AMP_LINK:
709 return h->amp_num;
Luiz Augusto von Dentz52087a72011-08-17 16:23:00 +0300710 case LE_LINK:
711 return h->le_num;
712 case SCO_LINK:
713 case ESCO_LINK:
714 return h->sco_num;
715 default:
716 return 0;
717 }
718}
719
Johan Hedbergf4f07502014-02-24 14:52:16 +0200720static inline unsigned int hci_conn_count(struct hci_dev *hdev)
721{
722 struct hci_conn_hash *c = &hdev->conn_hash;
723
724 return c->acl_num + c->amp_num + c->sco_num + c->le_num;
725}
726
Marcel Holtmann845472e82014-11-03 05:16:08 +0100727static inline __u8 hci_conn_lookup_type(struct hci_dev *hdev, __u16 handle)
728{
729 struct hci_conn_hash *h = &hdev->conn_hash;
730 struct hci_conn *c;
731 __u8 type = INVALID_LINK;
732
733 rcu_read_lock();
734
735 list_for_each_entry_rcu(c, &h->list, list) {
736 if (c->handle == handle) {
737 type = c->type;
738 break;
739 }
740 }
741
742 rcu_read_unlock();
743
744 return type;
745}
746
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
Szymon Jancadc42662011-02-17 16:42:00 +0100748 __u16 handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749{
750 struct hci_conn_hash *h = &hdev->conn_hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 struct hci_conn *c;
752
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200753 rcu_read_lock();
754
755 list_for_each_entry_rcu(c, &h->list, list) {
756 if (c->handle == handle) {
757 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 return c;
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200759 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200761 rcu_read_unlock();
762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 return NULL;
764}
765
766static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
Szymon Jancadc42662011-02-17 16:42:00 +0100767 __u8 type, bdaddr_t *ba)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768{
769 struct hci_conn_hash *h = &hdev->conn_hash;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 struct hci_conn *c;
771
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200772 rcu_read_lock();
773
774 list_for_each_entry_rcu(c, &h->list, list) {
775 if (c->type == type && !bacmp(&c->dst, ba)) {
776 rcu_read_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 return c;
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 }
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200780
781 rcu_read_unlock();
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return NULL;
784}
785
Marcel Holtmann4c67bc72006-10-15 17:30:56 +0200786static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
Szymon Jancadc42662011-02-17 16:42:00 +0100787 __u8 type, __u16 state)
Marcel Holtmann4c67bc72006-10-15 17:30:56 +0200788{
789 struct hci_conn_hash *h = &hdev->conn_hash;
Marcel Holtmann4c67bc72006-10-15 17:30:56 +0200790 struct hci_conn *c;
791
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200792 rcu_read_lock();
793
794 list_for_each_entry_rcu(c, &h->list, list) {
795 if (c->type == type && c->state == state) {
796 rcu_read_unlock();
Marcel Holtmann4c67bc72006-10-15 17:30:56 +0200797 return c;
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200798 }
Marcel Holtmann4c67bc72006-10-15 17:30:56 +0200799 }
Gustavo F. Padovanbf4c6322011-12-14 22:54:12 -0200800
801 rcu_read_unlock();
802
Marcel Holtmann4c67bc72006-10-15 17:30:56 +0200803 return NULL;
804}
805
Johan Hedberge3b679d2014-08-18 20:33:32 +0300806int hci_disconnect(struct hci_conn *conn, __u8 reason);
Frédéric Dalleau2dea6322013-08-19 14:24:03 +0200807bool hci_setup_sync(struct hci_conn *conn, __u16 handle);
Marcel Holtmanne73439d2010-07-26 10:06:00 -0400808void hci_sco_setup(struct hci_conn *conn, __u8 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809
Johan Hedberga5c4e302014-07-16 11:56:07 +0300810struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
811 u8 role);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200812int hci_conn_del(struct hci_conn *conn);
813void hci_conn_hash_flush(struct hci_dev *hdev);
814void hci_conn_check_pending(struct hci_dev *hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Luiz Augusto von Dentz73d80de2011-11-02 15:52:01 +0200816struct hci_chan *hci_chan_create(struct hci_conn *conn);
Andrei Emeltchenko94720072012-09-06 15:05:43 +0300817void hci_chan_del(struct hci_chan *chan);
Gustavo F. Padovan2c33c062011-12-14 13:02:51 -0200818void hci_chan_list_flush(struct hci_conn *conn);
Andrei Emeltchenko42c4e532012-10-10 17:38:28 +0300819struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
Luiz Augusto von Dentz73d80de2011-11-02 15:52:01 +0200820
Andre Guedes04a6c582014-02-26 20:21:44 -0300821struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
Johan Hedbergcdd62752014-07-07 15:02:28 +0300822 u8 dst_type, u8 sec_level, u16 conn_timeout,
Johan Hedberge804d252014-07-16 11:42:28 +0300823 u8 role);
Andre Guedes04a6c582014-02-26 20:21:44 -0300824struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
825 u8 sec_level, u8 auth_type);
Frédéric Dalleau10c62dd2013-08-19 14:23:59 +0200826struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
827 __u16 setting);
Marcel Holtmanne7c29cb2008-09-09 07:19:20 +0200828int hci_conn_check_link_mode(struct hci_conn *conn);
Waldemar Rymarkiewiczb3b1b062011-05-06 09:42:31 +0200829int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
Johan Hedberge7cafc42014-07-17 15:35:38 +0300830int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type,
831 bool initiator);
Marcel Holtmann8c1b2352009-01-15 21:58:04 +0100832int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Jaikumar Ganesh14b12d02011-05-23 18:06:04 -0700834void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
Andre Guedes06c053f2014-02-26 20:21:41 -0300836void hci_le_conn_failed(struct hci_conn *conn, u8 status);
837
David Herrmann8d123562013-04-06 20:28:39 +0200838/*
839 * hci_conn_get() and hci_conn_put() are used to control the life-time of an
840 * "hci_conn" object. They do not guarantee that the hci_conn object is running,
841 * working or anything else. They just guarantee that the object is available
842 * and can be dereferenced. So you can use its locks, local variables and any
843 * other constant data.
844 * Before accessing runtime data, you _must_ lock the object and then check that
845 * it is still running. As soon as you release the locks, the connection might
846 * get dropped, though.
847 *
848 * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control
849 * how long the underlying connection is held. So every channel that runs on the
850 * hci_conn object calls this to prevent the connection from disappearing. As
851 * long as you hold a device, you must also guarantee that you have a valid
852 * reference to the device via hci_conn_get() (or the initial reference from
853 * hci_conn_add()).
854 * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't
855 * break because nobody cares for that. But this means, we cannot use
856 * _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
857 */
858
Johan Hedberg51bb84572014-08-15 21:06:57 +0300859static inline struct hci_conn *hci_conn_get(struct hci_conn *conn)
David Herrmann8d123562013-04-06 20:28:39 +0200860{
861 get_device(&conn->dev);
Johan Hedberg51bb84572014-08-15 21:06:57 +0300862 return conn;
David Herrmann8d123562013-04-06 20:28:39 +0200863}
864
865static inline void hci_conn_put(struct hci_conn *conn)
866{
867 put_device(&conn->dev);
868}
869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870static inline void hci_conn_hold(struct hci_conn *conn)
871{
Andrei Emeltchenko71becf02012-07-19 17:03:42 +0300872 BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
Andrei Emeltchenko38b3fef2012-06-15 11:50:28 +0300873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 atomic_inc(&conn->refcnt);
Andre Guedes2f304d12012-01-27 19:42:02 -0300875 cancel_delayed_work(&conn->disc_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876}
877
David Herrmann76a68ba2013-04-06 20:28:37 +0200878static inline void hci_conn_drop(struct hci_conn *conn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879{
Andrei Emeltchenko71becf02012-07-19 17:03:42 +0300880 BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
Andrei Emeltchenko38b3fef2012-06-15 11:50:28 +0300881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 if (atomic_dec_and_test(&conn->refcnt)) {
Marcel Holtmann04837f62006-07-03 10:02:33 +0200883 unsigned long timeo;
Andrei Emeltchenko716e4ab2012-10-10 17:38:31 +0300884
885 switch (conn->type) {
886 case ACL_LINK:
887 case LE_LINK:
Johan Hedberga74a84f2013-10-16 18:11:40 +0300888 cancel_delayed_work(&conn->idle_work);
Marcel Holtmann6ac59342006-09-26 09:43:48 +0200889 if (conn->state == BT_CONNECTED) {
Andrei Emeltchenko5f246e82012-06-11 11:13:07 +0300890 timeo = conn->disc_timeout;
Marcel Holtmann6ac59342006-09-26 09:43:48 +0200891 if (!conn->out)
Marcel Holtmann052b30b2009-04-26 20:01:22 +0200892 timeo *= 2;
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +0200893 } else {
Johan Hedbergeb78d7e2014-08-18 00:41:41 +0300894 timeo = 0;
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +0200895 }
Andrei Emeltchenko716e4ab2012-10-10 17:38:31 +0300896 break;
897
898 case AMP_LINK:
899 timeo = conn->disc_timeout;
900 break;
901
902 default:
Johan Hedbergeb78d7e2014-08-18 00:41:41 +0300903 timeo = 0;
Andrei Emeltchenko716e4ab2012-10-10 17:38:31 +0300904 break;
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +0200905 }
Andrei Emeltchenko716e4ab2012-10-10 17:38:31 +0300906
Andre Guedes2f304d12012-01-27 19:42:02 -0300907 cancel_delayed_work(&conn->disc_work);
Gustavo F. Padovan19c40e32011-06-17 13:03:21 -0300908 queue_delayed_work(conn->hdev->workqueue,
Andrei Emeltchenko716e4ab2012-10-10 17:38:31 +0300909 &conn->disc_work, timeo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 }
911}
912
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913/* ----- HCI Devices ----- */
David Herrmanndc946bd2012-01-07 15:47:24 +0100914static inline void hci_dev_put(struct hci_dev *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915{
Andrei Emeltchenko376261a2012-09-06 15:05:45 +0300916 BT_DBG("%s orig refcnt %d", d->name,
917 atomic_read(&d->dev.kobj.kref.refcount));
918
David Herrmann4c724c72012-01-07 15:47:23 +0100919 put_device(&d->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920}
921
David Herrmanndc946bd2012-01-07 15:47:24 +0100922static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923{
Andrei Emeltchenko376261a2012-09-06 15:05:45 +0300924 BT_DBG("%s orig refcnt %d", d->name,
925 atomic_read(&d->dev.kobj.kref.refcount));
926
David Herrmann4c724c72012-01-07 15:47:23 +0100927 get_device(&d->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 return d;
929}
930
Gustavo F. Padovan09fd0de2011-06-17 13:03:21 -0300931#define hci_dev_lock(d) mutex_lock(&d->lock)
932#define hci_dev_unlock(d) mutex_unlock(&d->lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
David Herrmannaa2b86d2012-02-09 21:58:30 +0100934#define to_hci_dev(d) container_of(d, struct hci_dev, dev)
David Herrmann3dc07322012-02-09 21:58:33 +0100935#define to_hci_conn(c) container_of(c, struct hci_conn, dev)
David Herrmannaa2b86d2012-02-09 21:58:30 +0100936
David Herrmann155961e2012-02-09 21:58:32 +0100937static inline void *hci_get_drvdata(struct hci_dev *hdev)
938{
939 return dev_get_drvdata(&hdev->dev);
940}
941
942static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
943{
944 dev_set_drvdata(&hdev->dev, data);
945}
946
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947struct hci_dev *hci_dev_get(int index);
Johan Hedberg0c0afed2012-11-01 13:27:26 +0200948struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950struct hci_dev *hci_alloc_dev(void);
951void hci_free_dev(struct hci_dev *hdev);
952int hci_register_dev(struct hci_dev *hdev);
David Herrmann59735632011-10-26 10:43:19 +0200953void hci_unregister_dev(struct hci_dev *hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954int hci_suspend_dev(struct hci_dev *hdev);
955int hci_resume_dev(struct hci_dev *hdev);
Marcel Holtmann75e05692014-11-02 08:15:38 +0100956int hci_reset_dev(struct hci_dev *hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957int hci_dev_open(__u16 dev);
958int hci_dev_close(__u16 dev);
959int hci_dev_reset(__u16 dev);
960int hci_dev_reset_stat(__u16 dev);
961int hci_dev_cmd(unsigned int cmd, void __user *arg);
962int hci_get_dev_list(void __user *arg);
963int hci_get_dev_info(void __user *arg);
964int hci_get_conn_list(void __user *arg);
965int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
Marcel Holtmann40be4922008-07-14 20:13:50 +0200966int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967int hci_inquiry(void __user *arg);
968
Johan Hedbergdcc36c12014-07-09 12:59:13 +0300969struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list,
970 bdaddr_t *bdaddr, u8 type);
971int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type);
972int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type);
973void hci_bdaddr_list_clear(struct list_head *list);
Marcel Holtmannd2ab0ac2014-02-27 20:37:30 -0800974
Andre Guedes15819a72014-02-03 13:56:18 -0300975struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
976 bdaddr_t *addr, u8 addr_type);
Marcel Holtmann51d167c2014-07-01 12:11:04 +0200977struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
978 bdaddr_t *addr, u8 addr_type);
Andre Guedes15819a72014-02-03 13:56:18 -0300979void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
Johan Hedberg373110c2014-07-02 17:37:25 +0300980void hci_conn_params_clear_all(struct hci_dev *hdev);
Johan Hedberg55af49a2014-07-02 17:37:26 +0300981void hci_conn_params_clear_disabled(struct hci_dev *hdev);
Andre Guedes15819a72014-02-03 13:56:18 -0300982
Johan Hedberg501f8822014-07-04 12:37:26 +0300983struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
984 bdaddr_t *addr,
985 u8 addr_type);
Andre Guedes77a77a32014-02-26 20:21:46 -0300986
Johan Hedberg35f74982014-02-18 17:14:32 +0200987void hci_uuids_clear(struct hci_dev *hdev);
Johan Hedberg2aeb9a12011-01-04 12:08:51 +0200988
Johan Hedberg35f74982014-02-18 17:14:32 +0200989void hci_link_keys_clear(struct hci_dev *hdev);
Johan Hedberg55ed8ca12011-01-17 14:41:05 +0200990struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
Johan Hedberg567fa2a2014-06-24 13:15:48 +0300991struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
Johan Hedberg7652ff62014-06-24 13:15:49 +0300992 bdaddr_t *bdaddr, u8 *val, u8 type,
993 u8 pin_len, bool *persistent);
Johan Hedbergca9142b2014-02-19 14:57:44 +0200994struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
Johan Hedberg35d70272014-02-19 14:57:47 +0200995 u8 addr_type, u8 type, u8 authenticated,
Marcel Holtmannfe39c7b2014-02-27 16:00:28 -0800996 u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand);
Johan Hedbergf3a73d92014-05-29 15:02:59 +0300997struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
998 u8 addr_type, u8 role);
Johan Hedberge0b2b272014-02-18 17:14:31 +0200999int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type);
Johan Hedberg35f74982014-02-18 17:14:32 +02001000void hci_smp_ltks_clear(struct hci_dev *hdev);
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02001001int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
1002
Johan Hedberg970c4e42014-02-18 10:19:33 +02001003struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa);
1004struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1005 u8 addr_type);
Johan Hedbergca9142b2014-02-19 14:57:44 +02001006struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1007 u8 addr_type, u8 val[16], bdaddr_t *rpa);
Johan Hedberga7ec7332014-02-18 17:14:35 +02001008void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
Johan Hedberg970c4e42014-02-18 10:19:33 +02001009void hci_smp_irks_clear(struct hci_dev *hdev);
1010
Johan Hedberg55e76b32015-03-10 22:34:40 +02001011bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
1012
Johan Hedberg35f74982014-02-18 17:14:32 +02001013void hci_remote_oob_data_clear(struct hci_dev *hdev);
Szymon Janc2763eda2011-03-22 13:12:22 +01001014struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
Johan Hedberg6928a922014-10-26 20:46:09 +01001015 bdaddr_t *bdaddr, u8 bdaddr_type);
Marcel Holtmann07988722014-01-10 02:07:29 -08001016int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
Johan Hedberg6928a922014-10-26 20:46:09 +01001017 u8 bdaddr_type, u8 *hash192, u8 *rand192,
Johan Hedberg81328d52014-10-26 20:33:47 +01001018 u8 *hash256, u8 *rand256);
Johan Hedberg6928a922014-10-26 20:46:09 +01001019int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
1020 u8 bdaddr_type);
Szymon Janc2763eda2011-03-22 13:12:22 +01001021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
1023
Marcel Holtmanne1a26172013-10-10 16:52:43 -07001024int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
Marcel Holtmannef222012007-07-11 06:42:04 +02001025
David Herrmann0ac7e702011-10-08 14:58:47 +02001026void hci_init_sysfs(struct hci_dev *hdev);
Marcel Holtmanna67e8992009-05-02 18:24:06 -07001027void hci_conn_init_sysfs(struct hci_conn *conn);
Marcel Holtmannb219e3a2006-07-06 12:38:46 +02001028void hci_conn_add_sysfs(struct hci_conn *conn);
1029void hci_conn_del_sysfs(struct hci_conn *conn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030
David Herrmann6935e0f2012-03-09 15:53:42 +01001031#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
1033/* ----- LMP capabilities ----- */
Johan Hedbergcad718e2013-04-17 15:00:51 +03001034#define lmp_encrypt_capable(dev) ((dev)->features[0][0] & LMP_ENCRYPT)
1035#define lmp_rswitch_capable(dev) ((dev)->features[0][0] & LMP_RSWITCH)
1036#define lmp_hold_capable(dev) ((dev)->features[0][0] & LMP_HOLD)
1037#define lmp_sniff_capable(dev) ((dev)->features[0][0] & LMP_SNIFF)
1038#define lmp_park_capable(dev) ((dev)->features[0][1] & LMP_PARK)
1039#define lmp_inq_rssi_capable(dev) ((dev)->features[0][3] & LMP_RSSI_INQ)
1040#define lmp_esco_capable(dev) ((dev)->features[0][3] & LMP_ESCO)
1041#define lmp_bredr_capable(dev) (!((dev)->features[0][4] & LMP_NO_BREDR))
1042#define lmp_le_capable(dev) ((dev)->features[0][4] & LMP_LE)
1043#define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR)
1044#define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC)
1045#define lmp_ext_inq_capable(dev) ((dev)->features[0][6] & LMP_EXT_INQ)
1046#define lmp_le_br_capable(dev) (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR))
1047#define lmp_ssp_capable(dev) ((dev)->features[0][6] & LMP_SIMPLE_PAIR)
1048#define lmp_no_flush_capable(dev) ((dev)->features[0][6] & LMP_NO_FLUSH)
1049#define lmp_lsto_capable(dev) ((dev)->features[0][7] & LMP_LSTO)
1050#define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR)
1051#define lmp_ext_feat_capable(dev) ((dev)->features[0][7] & LMP_EXTFEATURES)
Frédéric Dalleau07a5c612013-08-19 14:24:00 +02001052#define lmp_transp_capable(dev) ((dev)->features[0][2] & LMP_TRANSPARENT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Andre Guedeseead27d2011-06-30 19:20:55 -03001054/* ----- Extended LMP capabilities ----- */
Marcel Holtmann53b834d22013-12-08 11:55:33 -08001055#define lmp_csb_master_capable(dev) ((dev)->features[2][0] & LMP_CSB_MASTER)
1056#define lmp_csb_slave_capable(dev) ((dev)->features[2][0] & LMP_CSB_SLAVE)
1057#define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN)
1058#define lmp_sync_scan_capable(dev) ((dev)->features[2][0] & LMP_SYNC_SCAN)
Marcel Holtmannd5991582014-01-10 02:07:16 -08001059#define lmp_sc_capable(dev) ((dev)->features[2][1] & LMP_SC)
1060#define lmp_ping_capable(dev) ((dev)->features[2][1] & LMP_PING)
Marcel Holtmann53b834d22013-12-08 11:55:33 -08001061
1062/* ----- Host capabilities ----- */
Johan Hedbergcad718e2013-04-17 15:00:51 +03001063#define lmp_host_ssp_capable(dev) ((dev)->features[1][0] & LMP_HOST_SSP)
Marcel Holtmannd5991582014-01-10 02:07:16 -08001064#define lmp_host_sc_capable(dev) ((dev)->features[1][0] & LMP_HOST_SC)
Johan Hedbergcad718e2013-04-17 15:00:51 +03001065#define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE))
1066#define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
Andre Guedeseead27d2011-06-30 19:20:55 -03001067
Marcel Holtmannd7a5a112015-03-13 02:11:00 -07001068#define hdev_is_powered(dev) (test_bit(HCI_UP, &(dev)->flags) && \
1069 !hci_dev_test_flag(dev, HCI_AUTO_OFF))
1070#define bredr_sc_enabled(dev) (lmp_sc_capable(dev) && \
1071 hci_dev_test_flag(dev, HCI_SC_ENABLED))
Johan Hedberg432df052014-08-01 11:13:31 +03001072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073/* ----- HCI protocols ----- */
Frédéric Dalleau20714bf2012-11-21 10:51:12 +01001074#define HCI_PROTO_DEFER 0x01
1075
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +02001076static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
Frédéric Dalleau20714bf2012-11-21 10:51:12 +01001077 __u8 type, __u8 *flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078{
Ulisses Furquim686ebf22011-12-21 10:11:33 -02001079 switch (type) {
1080 case ACL_LINK:
1081 return l2cap_connect_ind(hdev, bdaddr);
Marcel Holtmann8c1b2352009-01-15 21:58:04 +01001082
Ulisses Furquim686ebf22011-12-21 10:11:33 -02001083 case SCO_LINK:
1084 case ESCO_LINK:
Frédéric Dalleau20714bf2012-11-21 10:51:12 +01001085 return sco_connect_ind(hdev, bdaddr, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
Ulisses Furquim686ebf22011-12-21 10:11:33 -02001087 default:
1088 BT_ERR("unknown link type %d", type);
1089 return -EINVAL;
1090 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091}
1092
Marcel Holtmann2950f212009-02-12 14:02:50 +01001093static inline int hci_proto_disconn_ind(struct hci_conn *conn)
1094{
Ulisses Furquim686ebf22011-12-21 10:11:33 -02001095 if (conn->type != ACL_LINK && conn->type != LE_LINK)
1096 return HCI_ERROR_REMOTE_USER_TERM;
Marcel Holtmann2950f212009-02-12 14:02:50 +01001097
Ulisses Furquim686ebf22011-12-21 10:11:33 -02001098 return l2cap_disconn_ind(conn);
Marcel Holtmann2950f212009-02-12 14:02:50 +01001099}
1100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101/* ----- HCI callbacks ----- */
1102struct hci_cb {
1103 struct list_head list;
1104
1105 char *name;
1106
Johan Hedberg539c4962015-02-18 14:53:57 +02001107 void (*connect_cfm) (struct hci_conn *conn, __u8 status);
Johan Hedberg3a6d5762015-02-18 14:53:58 +02001108 void (*disconn_cfm) (struct hci_conn *conn, __u8 status);
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +02001109 void (*security_cfm) (struct hci_conn *conn, __u8 status,
1110 __u8 encrypt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 void (*key_change_cfm) (struct hci_conn *conn, __u8 status);
1112 void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role);
1113};
1114
Johan Hedberg539c4962015-02-18 14:53:57 +02001115static inline void hci_connect_cfm(struct hci_conn *conn, __u8 status)
1116{
1117 struct hci_cb *cb;
1118
1119 mutex_lock(&hci_cb_list_lock);
1120 list_for_each_entry(cb, &hci_cb_list, list) {
1121 if (cb->connect_cfm)
1122 cb->connect_cfm(conn, status);
1123 }
1124 mutex_unlock(&hci_cb_list_lock);
1125
1126 if (conn->connect_cfm_cb)
1127 conn->connect_cfm_cb(conn, status);
1128}
1129
Johan Hedberg3a6d5762015-02-18 14:53:58 +02001130static inline void hci_disconn_cfm(struct hci_conn *conn, __u8 reason)
1131{
1132 struct hci_cb *cb;
1133
1134 mutex_lock(&hci_cb_list_lock);
1135 list_for_each_entry(cb, &hci_cb_list, list) {
1136 if (cb->disconn_cfm)
1137 cb->disconn_cfm(conn, reason);
1138 }
1139 mutex_unlock(&hci_cb_list_lock);
1140
1141 if (conn->disconn_cfm_cb)
1142 conn->disconn_cfm_cb(conn, reason);
1143}
1144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
1146{
Denis Kirjanov711584e2012-10-22 17:22:01 +04001147 struct hci_cb *cb;
Marcel Holtmann8c1b2352009-01-15 21:58:04 +01001148 __u8 encrypt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Johan Hedberg51a8efd2012-01-16 06:10:31 +02001150 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
Marcel Holtmann8c1b2352009-01-15 21:58:04 +01001151 return;
1152
Johan Hedberg4dae2792014-06-24 17:03:50 +03001153 encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
Marcel Holtmann8c1b2352009-01-15 21:58:04 +01001154
Johan Hedbergfba7ecf2015-02-18 14:53:55 +02001155 mutex_lock(&hci_cb_list_lock);
Denis Kirjanov711584e2012-10-22 17:22:01 +04001156 list_for_each_entry(cb, &hci_cb_list, list) {
Marcel Holtmann8c1b2352009-01-15 21:58:04 +01001157 if (cb->security_cfm)
1158 cb->security_cfm(conn, status, encrypt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 }
Johan Hedbergfba7ecf2015-02-18 14:53:55 +02001160 mutex_unlock(&hci_cb_list_lock);
Johan Hedberg354fe802015-02-18 14:53:56 +02001161
1162 if (conn->security_cfm_cb)
1163 conn->security_cfm_cb(conn, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164}
1165
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +02001166static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
1167 __u8 encrypt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168{
Denis Kirjanov711584e2012-10-22 17:22:01 +04001169 struct hci_cb *cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Marcel Holtmann435fef22009-02-09 03:55:28 +01001171 if (conn->sec_level == BT_SECURITY_SDP)
1172 conn->sec_level = BT_SECURITY_LOW;
1173
Vinicius Costa Gomes88167ae2011-06-09 18:50:51 -03001174 if (conn->pending_sec_level > conn->sec_level)
1175 conn->sec_level = conn->pending_sec_level;
1176
Johan Hedbergfba7ecf2015-02-18 14:53:55 +02001177 mutex_lock(&hci_cb_list_lock);
Denis Kirjanov711584e2012-10-22 17:22:01 +04001178 list_for_each_entry(cb, &hci_cb_list, list) {
Marcel Holtmann8c1b2352009-01-15 21:58:04 +01001179 if (cb->security_cfm)
1180 cb->security_cfm(conn, status, encrypt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 }
Johan Hedbergfba7ecf2015-02-18 14:53:55 +02001182 mutex_unlock(&hci_cb_list_lock);
Johan Hedberg354fe802015-02-18 14:53:56 +02001183
1184 if (conn->security_cfm_cb)
1185 conn->security_cfm_cb(conn, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186}
1187
1188static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
1189{
Denis Kirjanov711584e2012-10-22 17:22:01 +04001190 struct hci_cb *cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Johan Hedbergfba7ecf2015-02-18 14:53:55 +02001192 mutex_lock(&hci_cb_list_lock);
Denis Kirjanov711584e2012-10-22 17:22:01 +04001193 list_for_each_entry(cb, &hci_cb_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 if (cb->key_change_cfm)
1195 cb->key_change_cfm(conn, status);
1196 }
Johan Hedbergfba7ecf2015-02-18 14:53:55 +02001197 mutex_unlock(&hci_cb_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
Waldemar Rymarkiewicz5a9d0a32011-06-07 11:18:06 +02001200static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
1201 __u8 role)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202{
Denis Kirjanov711584e2012-10-22 17:22:01 +04001203 struct hci_cb *cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
Johan Hedbergfba7ecf2015-02-18 14:53:55 +02001205 mutex_lock(&hci_cb_list_lock);
Denis Kirjanov711584e2012-10-22 17:22:01 +04001206 list_for_each_entry(cb, &hci_cb_list, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 if (cb->role_switch_cfm)
1208 cb->role_switch_cfm(conn, status, role);
1209 }
Johan Hedbergfba7ecf2015-02-18 14:53:55 +02001210 mutex_unlock(&hci_cb_list_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211}
1212
Johan Hedberg6759a672012-01-15 20:51:14 +02001213static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
1214{
Johan Hedberg84d9d072012-03-26 14:21:41 +03001215 size_t parsed = 0;
Johan Hedberg6759a672012-01-15 20:51:14 +02001216
Johan Hedberg6c0c3312012-03-26 14:21:42 +03001217 if (data_len < 2)
1218 return false;
1219
Johan Hedberg84d9d072012-03-26 14:21:41 +03001220 while (parsed < data_len - 1) {
1221 u8 field_len = data[0];
Johan Hedberg6759a672012-01-15 20:51:14 +02001222
1223 if (field_len == 0)
1224 break;
1225
1226 parsed += field_len + 1;
1227
1228 if (parsed > data_len)
1229 break;
1230
1231 if (data[1] == type)
1232 return true;
1233
1234 data += field_len + 1;
1235 }
1236
1237 return false;
1238}
1239
Johan Hedberg301cb2d2014-02-18 10:19:34 +02001240static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
1241{
Andre Guedesdbbfa2a2014-06-25 16:44:45 -03001242 if (addr_type != ADDR_LE_DEV_RANDOM)
Johan Hedberg301cb2d2014-02-18 10:19:34 +02001243 return false;
1244
1245 if ((bdaddr->b[5] & 0xc0) == 0x40)
1246 return true;
1247
1248 return false;
1249}
1250
Johan Hedbergc46245b2014-07-02 17:37:33 +03001251static inline bool hci_is_identity_address(bdaddr_t *addr, u8 addr_type)
1252{
1253 if (addr_type == ADDR_LE_DEV_PUBLIC)
1254 return true;
1255
1256 /* Check for Random Static address type */
1257 if ((addr->b[5] & 0xc0) == 0xc0)
1258 return true;
1259
1260 return false;
1261}
1262
Johan Hedberg2426f3a2014-02-18 17:14:36 +02001263static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
1264 bdaddr_t *bdaddr, u8 addr_type)
1265{
1266 if (!hci_bdaddr_is_rpa(bdaddr, addr_type))
1267 return NULL;
1268
1269 return hci_find_irk_by_rpa(hdev, bdaddr);
1270}
1271
Andre Guedesd4905f22014-06-25 21:52:52 -03001272static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
1273 u16 to_multiplier)
1274{
1275 u16 max_latency;
1276
1277 if (min > max || min < 6 || max > 3200)
1278 return -EINVAL;
1279
1280 if (to_multiplier < 10 || to_multiplier > 3200)
1281 return -EINVAL;
1282
1283 if (max >= to_multiplier * 8)
1284 return -EINVAL;
1285
1286 max_latency = (to_multiplier * 8 / max) - 1;
1287 if (latency > 499 || latency > max_latency)
1288 return -EINVAL;
1289
1290 return 0;
1291}
1292
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293int hci_register_cb(struct hci_cb *hcb);
1294int hci_unregister_cb(struct hci_cb *hcb);
1295
Johan Hedberg75e84b72013-04-02 13:35:04 +03001296struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
Johan Hedberg07dc93d2013-04-19 10:14:51 +03001297 const void *param, u32 timeout);
Johan Hedberg7b1abbb2013-04-03 21:54:47 +03001298struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
Johan Hedberg07dc93d2013-04-19 10:14:51 +03001299 const void *param, u8 event, u32 timeout);
Johan Hedberg75e84b72013-04-02 13:35:04 +03001300
Johan Hedberg07dc93d2013-04-19 10:14:51 +03001301int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
1302 const void *param);
Luiz Augusto von Dentz73d80de2011-11-02 15:52:01 +02001303void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
Gustavo F. Padovan0d861d82010-05-01 16:15:35 -03001304void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001306void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308/* ----- HCI Sockets ----- */
Marcel Holtmann470fe1b2012-02-20 14:50:30 +01001309void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
Johan Hedberg71290692015-02-20 13:26:23 +02001310void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
Marcel Holtmannc08b1a12015-03-14 19:27:59 -07001311 int flag, struct sock *skip_sk);
Marcel Holtmanncd82e612012-02-20 20:34:38 +01001312void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Marcel Holtmann040030e2012-02-20 14:50:37 +01001314void hci_sock_dev_event(struct hci_dev *hdev, int event);
1315
Marcel Holtmanna9584522015-03-14 19:28:06 -07001316#define HCI_MGMT_VAR_LEN BIT(0)
1317#define HCI_MGMT_NO_HDEV BIT(1)
1318#define HCI_MGMT_UNTRUSTED BIT(2)
1319#define HCI_MGMT_UNCONFIGURED BIT(3)
Johan Hedbergb9a245fb2015-03-06 21:08:52 +02001320
Johan Hedberg801c1e82015-03-06 21:08:50 +02001321struct hci_mgmt_handler {
1322 int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
1323 u16 data_len);
Johan Hedberg801c1e82015-03-06 21:08:50 +02001324 size_t data_len;
Johan Hedbergb9a245fb2015-03-06 21:08:52 +02001325 unsigned long flags;
Johan Hedberg801c1e82015-03-06 21:08:50 +02001326};
1327
1328struct hci_mgmt_chan {
1329 struct list_head list;
1330 unsigned short channel;
1331 size_t handler_count;
1332 const struct hci_mgmt_handler *handlers;
Johan Hedberg88b94ce2015-03-17 13:48:49 +02001333 void (*hdev_init) (struct sock *sk, struct hci_dev *hdev);
Johan Hedberg801c1e82015-03-06 21:08:50 +02001334};
1335
1336int hci_mgmt_chan_register(struct hci_mgmt_chan *c);
1337void hci_mgmt_chan_unregister(struct hci_mgmt_chan *c);
1338
Johan Hedberg03811012010-12-08 00:21:06 +02001339/* Management interface */
Andre Guedes591f47f2012-04-24 21:02:49 -03001340#define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR))
1341#define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \
1342 BIT(BDADDR_LE_RANDOM))
1343#define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \
1344 BIT(BDADDR_LE_PUBLIC) | \
1345 BIT(BDADDR_LE_RANDOM))
Andre Guedesf39799f2012-02-17 20:39:35 -03001346
Andre Guedes0d8cc932013-04-30 15:29:31 -03001347/* These LE scan and inquiry parameters were chosen according to LE General
1348 * Discovery Procedure specification.
1349 */
1350#define DISCOV_LE_SCAN_WIN 0x12
1351#define DISCOV_LE_SCAN_INT 0x12
Lukasz Rymanowski3d5a76f2014-03-27 20:55:21 +01001352#define DISCOV_LE_TIMEOUT 10240 /* msec */
Lukasz Rymanowskiae55f592014-03-27 20:55:19 +01001353#define DISCOV_INTERLEAVED_TIMEOUT 5120 /* msec */
Andre Guedes0d8cc932013-04-30 15:29:31 -03001354#define DISCOV_INTERLEAVED_INQUIRY_LEN 0x04
1355#define DISCOV_BREDR_INQUIRY_LEN 0x08
Jakub Pawlowski4b0e0ce2015-02-01 23:07:55 -08001356#define DISCOV_LE_RESTART_DELAY msecs_to_jiffies(200) /* msec */
Andre Guedes0d8cc932013-04-30 15:29:31 -03001357
Johan Hedberg91a668b2014-07-09 13:28:26 +03001358int mgmt_new_settings(struct hci_dev *hdev);
Marcel Holtmannbf6b56d2013-10-06 23:55:45 -07001359void mgmt_index_added(struct hci_dev *hdev);
1360void mgmt_index_removed(struct hci_dev *hdev);
Marcel Holtmann3eec7052013-10-06 23:55:46 -07001361void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
Johan Hedberg744cf192011-11-08 20:40:14 +02001362int mgmt_powered(struct hci_dev *hdev, u8 powered);
Johan Hedbergbc6d2d02014-07-10 12:09:08 +03001363int mgmt_update_adv_data(struct hci_dev *hdev);
Marcel Holtmannd1967ff2013-10-15 10:57:40 -07001364void mgmt_discoverable_timeout(struct hci_dev *hdev);
Marcel Holtmanndc4a5ee2013-10-15 10:15:57 -07001365void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
1366 bool persistent);
Alfonso Acosta48ec92f2014-10-07 08:44:10 +00001367void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
1368 u32 flags, u8 *name, u8 name_len);
Marcel Holtmann9b80ec52013-10-06 23:55:50 -07001369void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
Johan Hedberg12d4a3b2014-02-24 14:52:18 +02001370 u8 link_type, u8 addr_type, u8 reason,
1371 bool mgmt_connected);
Marcel Holtmann78929242013-10-06 23:55:47 -07001372void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
1373 u8 link_type, u8 addr_type, u8 status);
Marcel Holtmann445608d2013-10-06 23:55:48 -07001374void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1375 u8 addr_type, u8 status);
Marcel Holtmannce0e4a02013-10-15 14:26:20 -07001376void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
Marcel Holtmanne669cf82013-10-15 14:26:21 -07001377void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1378 u8 status);
Marcel Holtmann3eb38522013-10-15 14:26:22 -07001379void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1380 u8 status);
Johan Hedberg744cf192011-11-08 20:40:14 +02001381int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
Johan Hedberg39adbff2014-03-20 08:18:14 +02001382 u8 link_type, u8 addr_type, u32 value,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001383 u8 confirm_hint);
Johan Hedberg744cf192011-11-08 20:40:14 +02001384int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001385 u8 link_type, u8 addr_type, u8 status);
Johan Hedberg272d90d2012-02-09 15:26:12 +02001386int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001387 u8 link_type, u8 addr_type, u8 status);
Johan Hedberg272d90d2012-02-09 15:26:12 +02001388int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001389 u8 link_type, u8 addr_type);
Brian Gix604086b2011-11-23 08:28:33 -08001390int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001391 u8 link_type, u8 addr_type, u8 status);
Johan Hedberg272d90d2012-02-09 15:26:12 +02001392int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001393 u8 link_type, u8 addr_type, u8 status);
Johan Hedberg92a25252012-09-06 18:39:26 +03001394int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
1395 u8 link_type, u8 addr_type, u32 passkey,
1396 u8 entered);
Johan Hedberge1e930f2014-09-08 17:09:49 -07001397void mgmt_auth_failed(struct hci_conn *conn, u8 status);
Marcel Holtmann464996a2013-10-15 14:26:24 -07001398void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
Marcel Holtmann3e248562013-10-15 14:26:25 -07001399void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
Marcel Holtmann4e1b0242013-10-15 14:26:26 -07001400void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
1401 u8 status);
Marcel Holtmann7667da32013-10-15 14:26:27 -07001402void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
Marcel Holtmann901801b2013-10-06 23:55:51 -07001403void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
Marcel Holtmannaf589252014-07-01 14:11:20 +02001404 u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
1405 u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len);
Marcel Holtmann9cf12ae2013-10-06 23:55:52 -07001406void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1407 u8 addr_type, s8 rssi, u8 *name, u8 name_len);
Marcel Holtmann2f1e0632013-10-06 23:55:53 -07001408void mgmt_discovering(struct hci_dev *hdev, u8 discovering);
Johan Hedberg84c61d92014-08-01 11:13:30 +03001409bool mgmt_powering_down(struct hci_dev *hdev);
Marcel Holtmann53ac6ab2014-03-09 23:38:42 -07001410void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent);
Johan Hedberg95fbac82014-02-19 15:18:31 +02001411void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk);
Marcel Holtmann53ac6ab2014-03-09 23:38:42 -07001412void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
1413 bool persistent);
Andre Guedesffb5a8272014-07-01 18:10:11 -03001414void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
Johan Hedbergf4869e22014-07-02 17:37:32 +03001415 u8 bdaddr_type, u8 store_hint, u16 min_interval,
1416 u16 max_interval, u16 latency, u16 timeout);
Marcel Holtmann5976e602013-10-06 04:08:14 -07001417void mgmt_reenable_advertising(struct hci_dev *hdev);
Johan Hedbergf4a407b2014-02-18 21:41:34 +02001418void mgmt_smp_complete(struct hci_conn *conn, bool complete);
Vinicius Costa Gomes346af672012-02-02 21:08:02 -03001419
Johan Hedberg7d6ca692014-07-02 17:37:31 +03001420u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
1421 u16 to_multiplier);
Marcel Holtmannfe39c7b2014-02-27 16:00:28 -08001422void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
Johan Hedberg8b76ce32015-06-08 18:14:39 +03001423 __u8 ltk[16], __u8 key_size);
Andre Guedes2519a1f2011-11-07 11:45:24 -03001424
Johan Hedberga1f4c312014-02-27 14:05:41 +02001425void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
1426 u8 *bdaddr_type);
Johan Hedbergebd3a742014-02-23 19:42:21 +02001427
Frédéric Dalleau5d4d62f2013-08-19 14:23:57 +02001428#define SCO_AIRMODE_MASK 0x0003
1429#define SCO_AIRMODE_CVSD 0x0000
1430#define SCO_AIRMODE_TRANSP 0x0003
1431
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432#endif /* __HCI_CORE_H */