at86rf230: assign wait_for_completion_timeout to appropriately typed var
[deliverable/linux.git] / include / net / bluetooth / hci_core.h
CommitLineData
04fafe4e 1/*
1da177e4 2 BlueZ - Bluetooth protocol stack for Linux
2d0a0346 3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
1da177e4
LT
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
04fafe4e
RS
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
1da177e4
LT
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
04fafe4e
RS
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
1da177e4
LT
22 SOFTWARE IS DISCLAIMED.
23*/
24
25#ifndef __HCI_CORE_H
26#define __HCI_CORE_H
27
1da177e4 28#include <net/bluetooth/hci.h>
f49daa81 29#include <net/bluetooth/hci_sock.h>
1da177e4 30
5e59b791
LAD
31/* HCI priority */
32#define HCI_PRIO_MAX 7
33
1da177e4 34/* HCI Core structures */
1da177e4
LT
35struct 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];
1ebb9252 41 __le16 clock_offset;
1da177e4 42 __s8 rssi;
41a96212 43 __u8 ssp_mode;
1da177e4
LT
44};
45
46struct inquiry_entry {
561aafbc
JH
47 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;
1da177e4
LT
55 __u32 timestamp;
56 struct inquiry_data data;
57};
58
30883512 59struct discovery_state {
f64b993f 60 int type;
ff9ef578
JH
61 enum {
62 DISCOVERY_STOPPED,
63 DISCOVERY_STARTING,
343f935b 64 DISCOVERY_FINDING,
30dc78e1 65 DISCOVERY_RESOLVING,
ff9ef578
JH
66 DISCOVERY_STOPPING,
67 } state;
c3c7ea65 68 struct list_head all; /* All devices found during inquiry */
f64b993f
GP
69 struct list_head unknown; /* Name state not known */
70 struct list_head resolve; /* Name needs to be resolved */
71 __u32 timestamp;
b9a6328f
JH
72 bdaddr_t last_adv_addr;
73 u8 last_adv_addr_type;
ff5cd29f 74 s8 last_adv_rssi;
c70a7e4c 75 u32 last_adv_flags;
b9a6328f
JH
76 u8 last_adv_data[HCI_MAX_AD_LENGTH];
77 u8 last_adv_data_len;
da25cf6a 78 bool report_invalid_rssi;
37eab042
JP
79 s8 rssi;
80 u16 uuid_count;
81 u8 (*uuids)[16];
2d28cfe7
JP
82 unsigned long scan_start;
83 unsigned long scan_duration;
1da177e4
LT
84};
85
86struct hci_conn_hash {
87 struct list_head list;
1da177e4 88 unsigned int acl_num;
bd1eb66b 89 unsigned int amp_num;
1da177e4 90 unsigned int sco_num;
fcd89c09 91 unsigned int le_num;
f8218dc6 92 unsigned int le_num_slave;
1da177e4
LT
93};
94
f0358568
JH
95struct bdaddr_list {
96 struct list_head list;
97 bdaddr_t bdaddr;
b9ee0a78 98 u8 bdaddr_type;
f0358568 99};
2aeb9a1a
JH
100
101struct bt_uuid {
102 struct list_head list;
103 u8 uuid[16];
83be8eca 104 u8 size;
1aff6f09 105 u8 svc_hint;
2aeb9a1a
JH
106};
107
7ee4ea36
MH
108struct smp_csrk {
109 bdaddr_t bdaddr;
110 u8 bdaddr_type;
111 u8 master;
112 u8 val[16];
113};
114
b899efaf
VCG
115struct smp_ltk {
116 struct list_head list;
970d0f1b 117 struct rcu_head rcu;
b899efaf
VCG
118 bdaddr_t bdaddr;
119 u8 bdaddr_type;
120 u8 authenticated;
121 u8 type;
122 u8 enc_size;
123 __le16 ediv;
fe39c7b2 124 __le64 rand;
b899efaf 125 u8 val[16];
03c515d7 126};
b899efaf 127
970c4e46
JH
128struct smp_irk {
129 struct list_head list;
adae20cb 130 struct rcu_head rcu;
970c4e46
JH
131 bdaddr_t rpa;
132 bdaddr_t bdaddr;
133 u8 addr_type;
134 u8 val[16];
135};
136
55ed8ca1
JH
137struct link_key {
138 struct list_head list;
0378b597 139 struct rcu_head rcu;
55ed8ca1
JH
140 bdaddr_t bdaddr;
141 u8 type;
9b3b4460 142 u8 val[HCI_LINK_KEY_SIZE];
55ed8ca1
JH
143 u8 pin_len;
144};
145
2763eda6
SJ
146struct oob_data {
147 struct list_head list;
148 bdaddr_t bdaddr;
6928a924 149 u8 bdaddr_type;
f7697b16 150 u8 present;
519ca9d0 151 u8 hash192[16];
38da1703 152 u8 rand192[16];
519ca9d0 153 u8 hash256[16];
38da1703 154 u8 rand256[16];
2763eda6
SJ
155};
156
490c5bab
JH
157#define HCI_MAX_SHORT_NAME_LENGTH 10
158
d6bfd59c
JH
159/* Default LE RPA expiry time, 15 minutes */
160#define HCI_DEFAULT_RPA_TIMEOUT (15 * 60)
161
31ad1691
AK
162/* Default min/max age of connection information (1s/3s) */
163#define DEFAULT_CONN_INFO_MIN_AGE 1000
164#define DEFAULT_CONN_INFO_MAX_AGE 3000
165
903e4541
AE
166struct amp_assoc {
167 __u16 len;
168 __u16 offset;
93c284ee
AE
169 __u16 rem_len;
170 __u16 len_so_far;
903e4541
AE
171 __u8 data[HCI_MAX_AMP_ASSOC_SIZE];
172};
173
d2c5d77f 174#define HCI_MAX_PAGES 3
cad718ed 175
cd4c5391 176#define NUM_REASSEMBLY 4
1da177e4
LT
177struct hci_dev {
178 struct list_head list;
09fd0de5 179 struct mutex lock;
1da177e4
LT
180
181 char name[8];
182 unsigned long flags;
183 __u16 id;
c13854ce 184 __u8 bus;
943da25d 185 __u8 dev_type;
1da177e4 186 bdaddr_t bdaddr;
e30d3f5f 187 bdaddr_t setup_addr;
24c457e2 188 bdaddr_t public_addr;
7a4cd51d 189 bdaddr_t random_addr;
d13eafce 190 bdaddr_t static_addr;
56ed2cb8 191 __u8 adv_addr_type;
1f6c6378 192 __u8 dev_name[HCI_MAX_NAME_LENGTH];
490c5bab 193 __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH];
80a1e1db 194 __u8 eir[HCI_MAX_EIR_LENGTH];
a9de9248 195 __u8 dev_class[3];
1aff6f09
JH
196 __u8 major_class;
197 __u8 minor_class;
d2c5d77f 198 __u8 max_page;
cad718ed 199 __u8 features[HCI_MAX_PAGES][8];
60e77321 200 __u8 le_features[8];
cf1d081f 201 __u8 le_white_list_size;
9b008c04 202 __u8 le_states[8];
a9de9248 203 __u8 commands[64];
1143e5a6
MH
204 __u8 hci_ver;
205 __u16 hci_rev;
d5859e22 206 __u8 lmp_ver;
1143e5a6 207 __u16 manufacturer;
7d69230c 208 __u16 lmp_subver;
1da177e4 209 __u16 voice_setting;
b4cb9fb2 210 __u8 num_iac;
c2f0f979
MH
211 __u8 stored_max_keys;
212 __u8 stored_num_keys;
17fa4b9d 213 __u8 io_capability;
91c4e9b1 214 __s8 inq_tx_power;
f332ec66
JH
215 __u16 page_scan_interval;
216 __u16 page_scan_window;
217 __u8 page_scan_type;
3f959d46 218 __u8 le_adv_channel_map;
628531c9
GL
219 __u16 le_adv_min_interval;
220 __u16 le_adv_max_interval;
533553f8 221 __u8 le_scan_type;
bef64738
MH
222 __u16 le_scan_interval;
223 __u16 le_scan_window;
4e70c7e7
MH
224 __u16 le_conn_min_interval;
225 __u16 le_conn_max_interval;
04fb7d90
MH
226 __u16 le_conn_latency;
227 __u16 le_supv_timeout;
a8e1bfaa
MH
228 __u16 le_def_tx_len;
229 __u16 le_def_tx_time;
230 __u16 le_max_tx_len;
231 __u16 le_max_tx_time;
232 __u16 le_max_rx_len;
233 __u16 le_max_rx_time;
b9a7a61e 234 __u16 discov_interleaved_timeout;
31ad1691
AK
235 __u16 conn_info_min_age;
236 __u16 conn_info_max_age;
06f5b778 237 __u8 ssp_debug_mode;
c7741d16 238 __u8 hw_error_code;
33f35721 239 __u32 clock;
f332ec66 240
2b9be137
MH
241 __u16 devid_source;
242 __u16 devid_vendor;
243 __u16 devid_product;
244 __u16 devid_version;
1da177e4
LT
245
246 __u16 pkt_type;
5b7f9909 247 __u16 esco_type;
1da177e4
LT
248 __u16 link_policy;
249 __u16 link_mode;
250
04837f64
MH
251 __u32 idle_timeout;
252 __u16 sniff_min_interval;
253 __u16 sniff_max_interval;
254
928abaa7
AE
255 __u8 amp_status;
256 __u32 amp_total_bw;
257 __u32 amp_max_bw;
258 __u32 amp_min_latency;
259 __u32 amp_max_pdu;
260 __u8 amp_type;
261 __u16 amp_pal_cap;
262 __u16 amp_assoc_size;
263 __u32 amp_max_flush_to;
264 __u32 amp_be_flush_to;
265
903e4541
AE
266 struct amp_assoc loc_assoc;
267
1e89cffb
AE
268 __u8 flow_ctl_mode;
269
9f61656a
JH
270 unsigned int auto_accept_delay;
271
1da177e4
LT
272 unsigned long quirks;
273
274 atomic_t cmd_cnt;
275 unsigned int acl_cnt;
276 unsigned int sco_cnt;
6ed58ec5 277 unsigned int le_cnt;
1da177e4
LT
278
279 unsigned int acl_mtu;
280 unsigned int sco_mtu;
6ed58ec5 281 unsigned int le_mtu;
1da177e4
LT
282 unsigned int acl_pkts;
283 unsigned int sco_pkts;
6ed58ec5 284 unsigned int le_pkts;
1da177e4 285
350ee4cf
AE
286 __u16 block_len;
287 __u16 block_mtu;
288 __u16 num_blocks;
289 __u16 block_cnt;
290
1da177e4
LT
291 unsigned long acl_last_tx;
292 unsigned long sco_last_tx;
6ed58ec5 293 unsigned long le_last_tx;
1da177e4 294
f48fd9c8 295 struct workqueue_struct *workqueue;
6ead1bbc 296 struct workqueue_struct *req_workqueue;
f48fd9c8 297
ab81cbf9 298 struct work_struct power_on;
3243553f 299 struct delayed_work power_off;
c7741d16 300 struct work_struct error_reset;
ab81cbf9 301
16ab91ab
JH
302 __u16 discov_timeout;
303 struct delayed_work discov_off;
304
7d78525d
JH
305 struct delayed_work service_cache;
306
65cc2b49 307 struct delayed_work cmd_timer;
b78752cc
MH
308
309 struct work_struct rx_work;
c347b765 310 struct work_struct cmd_work;
3eff45ea 311 struct work_struct tx_work;
1da177e4
LT
312
313 struct sk_buff_head rx_q;
314 struct sk_buff_head raw_q;
315 struct sk_buff_head cmd_q;
316
b6ddb638 317 struct sk_buff *recv_evt;
1da177e4 318 struct sk_buff *sent_cmd;
cd4c5391 319 struct sk_buff *reassembly[NUM_REASSEMBLY];
1da177e4 320
a6a67efd 321 struct mutex req_lock;
1da177e4
LT
322 wait_queue_head_t req_wait_q;
323 __u32 req_status;
324 __u32 req_result;
a5040efa 325
70db83c4 326 void *smp_data;
ef8efe4b 327 void *smp_bredr_data;
2e58ef3e 328
30883512 329 struct discovery_state discovery;
1da177e4
LT
330 struct hci_conn_hash conn_hash;
331
5c136e90
AG
332 struct list_head mgmt_pending;
333 struct list_head blacklist;
6659358e 334 struct list_head whitelist;
2aeb9a1a 335 struct list_head uuids;
55ed8ca1 336 struct list_head link_keys;
b899efaf 337 struct list_head long_term_keys;
970c4e46 338 struct list_head identity_resolving_keys;
2763eda6 339 struct list_head remote_oob_data;
d2ab0ac1 340 struct list_head le_white_list;
15819a70 341 struct list_head le_conn_params;
77a77a30 342 struct list_head pend_le_conns;
66f8455a 343 struct list_head pend_le_reports;
2763eda6 344
1da177e4
LT
345 struct hci_dev_stats stat;
346
70f23020 347 atomic_t promisc;
1da177e4 348
ca325f69
MH
349 struct dentry *debugfs;
350
a91f2e39 351 struct device dev;
1da177e4 352
611b30f7
MH
353 struct rfkill *rfkill;
354
111902f7 355 unsigned long dbg_flags;
d23264a8
AG
356 unsigned long dev_flags;
357
7ba8b4be 358 struct delayed_work le_scan_disable;
2d28cfe7 359 struct delayed_work le_scan_restart;
7ba8b4be 360
8fa19098 361 __s8 adv_tx_power;
3f0f524b
JH
362 __u8 adv_data[HCI_MAX_AD_LENGTH];
363 __u8 adv_data_len;
f8e808bd
MH
364 __u8 scan_rsp_data[HCI_MAX_AD_LENGTH];
365 __u8 scan_rsp_data_len;
8fa19098 366
863efaf2 367 __u8 irk[16];
d6bfd59c
JH
368 __u32 rpa_timeout;
369 struct delayed_work rpa_expired;
2b5224dc 370 bdaddr_t rpa;
863efaf2 371
1da177e4
LT
372 int (*open)(struct hci_dev *hdev);
373 int (*close)(struct hci_dev *hdev);
374 int (*flush)(struct hci_dev *hdev);
f41c70c4 375 int (*setup)(struct hci_dev *hdev);
7bd8f09f 376 int (*send)(struct hci_dev *hdev, struct sk_buff *skb);
1da177e4 377 void (*notify)(struct hci_dev *hdev, unsigned int evt);
c7741d16 378 void (*hw_error)(struct hci_dev *hdev, u8 code);
24c457e2 379 int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
1da177e4
LT
380};
381
53502d69
AE
382#define HCI_PHY_HANDLE(handle) (handle & 0xff)
383
1da177e4
LT
384struct hci_conn {
385 struct list_head list;
386
adc4266d 387 atomic_t refcnt;
adc4266d
SJ
388
389 bdaddr_t dst;
5a9d0a3f 390 __u8 dst_type;
662e8820 391 bdaddr_t src;
e7c4096e 392 __u8 src_type;
cb1d68f7
JH
393 bdaddr_t init_addr;
394 __u8 init_addr_type;
395 bdaddr_t resp_addr;
396 __u8 resp_addr_type;
adc4266d
SJ
397 __u16 handle;
398 __u16 state;
399 __u8 mode;
400 __u8 type;
40bef302 401 __u8 role;
a0c808b3 402 bool out;
adc4266d
SJ
403 __u8 attempt;
404 __u8 dev_class[3];
cad718ed 405 __u8 features[HCI_MAX_PAGES][8];
adc4266d
SJ
406 __u16 pkt_type;
407 __u16 link_policy;
13d39315 408 __u8 key_type;
adc4266d
SJ
409 __u8 auth_type;
410 __u8 sec_level;
411 __u8 pending_sec_level;
412 __u8 pin_length;
726b4ffc 413 __u8 enc_key_size;
adc4266d 414 __u8 io_capability;
92a25256
JH
415 __u32 passkey_notify;
416 __u8 passkey_entered;
adc4266d 417 __u16 disc_timeout;
09ae260b 418 __u16 conn_timeout;
10c62ddc 419 __u16 setting;
1e406eef
AG
420 __u16 le_conn_min_interval;
421 __u16 le_conn_max_interval;
e04fde60
MH
422 __u16 le_conn_interval;
423 __u16 le_conn_latency;
424 __u16 le_supv_timeout;
fd45ada9
AA
425 __u8 le_adv_data[HCI_MAX_AD_LENGTH];
426 __u8 le_adv_data_len;
5ae76a94 427 __s8 rssi;
5a134fae 428 __s8 tx_power;
d0455ed9 429 __s8 max_tx_power;
51a8efd7 430 unsigned long flags;
04837f64 431
33f35721
JH
432 __u32 clock;
433 __u16 clock_accuracy;
434
dd983808
AK
435 unsigned long conn_info_timestamp;
436
03b555e1 437 __u8 remote_cap;
03b555e1 438 __u8 remote_auth;
3161ae1c 439 __u8 remote_id;
03b555e1 440
adc4266d 441 unsigned int sent;
04837f64 442
1da177e4 443 struct sk_buff_head data_q;
2c33c06a 444 struct list_head chan_list;
1da177e4 445
19c40e3b 446 struct delayed_work disc_work;
7bc18d9d 447 struct delayed_work auto_accept_work;
a74a84f6 448 struct delayed_work idle_work;
9489eca4 449 struct delayed_work le_conn_timeout;
04837f64 450
b219e3ac 451 struct device dev;
23b9ceb7 452 struct dentry *debugfs;
b219e3ac 453
1da177e4
LT
454 struct hci_dev *hdev;
455 void *l2cap_data;
456 void *sco_data;
9740e49d 457 struct amp_mgr *amp_mgr;
1da177e4
LT
458
459 struct hci_conn *link;
e9a416b5
JH
460
461 void (*connect_cfm_cb) (struct hci_conn *conn, u8 status);
462 void (*security_cfm_cb) (struct hci_conn *conn, u8 status);
463 void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason);
1da177e4
LT
464};
465
73d80deb
LAD
466struct hci_chan {
467 struct list_head list;
42c4e53e 468 __u16 handle;
73d80deb
LAD
469 struct hci_conn *conn;
470 struct sk_buff_head data_q;
471 unsigned int sent;
168df8e5 472 __u8 state;
73d80deb
LAD
473};
474
15819a70
AG
475struct hci_conn_params {
476 struct list_head list;
93450c75 477 struct list_head action;
15819a70
AG
478
479 bdaddr_t addr;
480 u8 addr_type;
481
482 u16 conn_min_interval;
483 u16 conn_max_interval;
f044eb05
MH
484 u16 conn_latency;
485 u16 supervision_timeout;
9fcb18ef
AG
486
487 enum {
488 HCI_AUTO_CONN_DISABLED,
a3451d27 489 HCI_AUTO_CONN_REPORT,
4b9e7e75 490 HCI_AUTO_CONN_DIRECT,
9fcb18ef
AG
491 HCI_AUTO_CONN_ALWAYS,
492 HCI_AUTO_CONN_LINK_LOSS,
493 } auto_connect;
f161dd41
JH
494
495 struct hci_conn *conn;
15819a70
AG
496};
497
1da177e4
LT
498extern struct list_head hci_dev_list;
499extern struct list_head hci_cb_list;
500extern rwlock_t hci_dev_list_lock;
501extern rwlock_t hci_cb_list_lock;
502
686ebf28 503/* ----- HCI interface to upper protocols ----- */
e74e58f8
JP
504int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
505void l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
506int l2cap_disconn_ind(struct hci_conn *hcon);
507void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
508int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
509int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
510
511int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
512void sco_connect_cfm(struct hci_conn *hcon, __u8 status);
513void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
514int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
686ebf28 515
1da177e4 516/* ----- Inquiry cache ----- */
70f23020
AE
517#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */
518#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */
1da177e4 519
30883512 520static inline void discovery_init(struct hci_dev *hdev)
1da177e4 521{
ff9ef578 522 hdev->discovery.state = DISCOVERY_STOPPED;
30883512
JH
523 INIT_LIST_HEAD(&hdev->discovery.all);
524 INIT_LIST_HEAD(&hdev->discovery.unknown);
525 INIT_LIST_HEAD(&hdev->discovery.resolve);
da25cf6a 526 hdev->discovery.report_invalid_rssi = true;
37eab042 527 hdev->discovery.rssi = HCI_RSSI_INVALID;
1da177e4
LT
528}
529
0256325e
MH
530static inline void hci_discovery_filter_clear(struct hci_dev *hdev)
531{
da25cf6a 532 hdev->discovery.report_invalid_rssi = true;
0256325e
MH
533 hdev->discovery.rssi = HCI_RSSI_INVALID;
534 hdev->discovery.uuid_count = 0;
535 kfree(hdev->discovery.uuids);
536 hdev->discovery.uuids = NULL;
2d28cfe7
JP
537 hdev->discovery.scan_start = 0;
538 hdev->discovery.scan_duration = 0;
0256325e
MH
539}
540
30dc78e1
JH
541bool hci_discovery_active(struct hci_dev *hdev);
542
ff9ef578
JH
543void hci_discovery_set_state(struct hci_dev *hdev, int state);
544
1da177e4
LT
545static inline int inquiry_cache_empty(struct hci_dev *hdev)
546{
30883512 547 return list_empty(&hdev->discovery.all);
1da177e4
LT
548}
549
550static inline long inquiry_cache_age(struct hci_dev *hdev)
551{
30883512 552 struct discovery_state *c = &hdev->discovery;
1da177e4
LT
553 return jiffies - c->timestamp;
554}
555
556static inline long inquiry_entry_age(struct inquiry_entry *e)
557{
558 return jiffies - e->timestamp;
559}
560
5a9d0a3f 561struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
04124681 562 bdaddr_t *bdaddr);
561aafbc 563struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
04124681 564 bdaddr_t *bdaddr);
30dc78e1 565struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
04124681
GP
566 bdaddr_t *bdaddr,
567 int state);
a3d4e20a 568void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
04124681 569 struct inquiry_entry *ie);
af58925c
MH
570u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
571 bool name_known);
1f9b9a5d 572void hci_inquiry_cache_flush(struct hci_dev *hdev);
1da177e4
LT
573
574/* ----- HCI Connections ----- */
575enum {
576 HCI_CONN_AUTH_PEND,
19f8def0 577 HCI_CONN_REAUTH_PEND,
1da177e4 578 HCI_CONN_ENCRYPT_PEND,
04837f64
MH
579 HCI_CONN_RSWITCH_PEND,
580 HCI_CONN_MODE_CHANGE_PEND,
e73439d8 581 HCI_CONN_SCO_SETUP_PEND,
b644ba33 582 HCI_CONN_MGMT_CONNECTED,
58a681ef 583 HCI_CONN_SSP_ENABLED,
eb9a8f3f 584 HCI_CONN_SC_ENABLED,
abf76bad 585 HCI_CONN_AES_CCM,
58a681ef
JH
586 HCI_CONN_POWER_SAVE,
587 HCI_CONN_REMOTE_OOB,
af6a9c32 588 HCI_CONN_FLUSH_KEY,
4dae2798
JH
589 HCI_CONN_ENCRYPT,
590 HCI_CONN_AUTH,
591 HCI_CONN_SECURE,
592 HCI_CONN_FIPS,
fe59a05f 593 HCI_CONN_STK_ENCRYPT,
977f8fce 594 HCI_CONN_AUTH_INITIATOR,
f94b665d 595 HCI_CONN_DROP,
89cbb063 596 HCI_CONN_PARAM_REMOVAL_PEND,
fe8bc5ac 597 HCI_CONN_NEW_LINK_KEY,
1da177e4
LT
598};
599
aa64a8b5
JH
600static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
601{
602 struct hci_dev *hdev = conn->hdev;
c3c7ea65
GP
603 return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
604 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
aa64a8b5
JH
605}
606
eb9a8f3f
MH
607static inline bool hci_conn_sc_enabled(struct hci_conn *conn)
608{
609 struct hci_dev *hdev = conn->hdev;
610 return test_bit(HCI_SC_ENABLED, &hdev->dev_flags) &&
611 test_bit(HCI_CONN_SC_ENABLED, &conn->flags);
612}
613
1da177e4
LT
614static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
615{
616 struct hci_conn_hash *h = &hdev->conn_hash;
bf4c6325 617 list_add_rcu(&c->list, &h->list);
fcd89c09
VT
618 switch (c->type) {
619 case ACL_LINK:
1da177e4 620 h->acl_num++;
fcd89c09 621 break;
bd1eb66b
AE
622 case AMP_LINK:
623 h->amp_num++;
624 break;
fcd89c09
VT
625 case LE_LINK:
626 h->le_num++;
f8218dc6
JH
627 if (c->role == HCI_ROLE_SLAVE)
628 h->le_num_slave++;
fcd89c09
VT
629 break;
630 case SCO_LINK:
631 case ESCO_LINK:
1da177e4 632 h->sco_num++;
fcd89c09
VT
633 break;
634 }
1da177e4
LT
635}
636
637static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
638{
639 struct hci_conn_hash *h = &hdev->conn_hash;
bf4c6325
GP
640
641 list_del_rcu(&c->list);
642 synchronize_rcu();
643
fcd89c09
VT
644 switch (c->type) {
645 case ACL_LINK:
1da177e4 646 h->acl_num--;
fcd89c09 647 break;
bd1eb66b
AE
648 case AMP_LINK:
649 h->amp_num--;
650 break;
fcd89c09
VT
651 case LE_LINK:
652 h->le_num--;
f8218dc6
JH
653 if (c->role == HCI_ROLE_SLAVE)
654 h->le_num_slave--;
fcd89c09
VT
655 break;
656 case SCO_LINK:
657 case ESCO_LINK:
1da177e4 658 h->sco_num--;
fcd89c09
VT
659 break;
660 }
1da177e4
LT
661}
662
52087a79
LAD
663static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
664{
665 struct hci_conn_hash *h = &hdev->conn_hash;
666 switch (type) {
667 case ACL_LINK:
668 return h->acl_num;
bd1eb66b
AE
669 case AMP_LINK:
670 return h->amp_num;
52087a79
LAD
671 case LE_LINK:
672 return h->le_num;
673 case SCO_LINK:
674 case ESCO_LINK:
675 return h->sco_num;
676 default:
677 return 0;
678 }
679}
680
f4f07505
JH
681static inline unsigned int hci_conn_count(struct hci_dev *hdev)
682{
683 struct hci_conn_hash *c = &hdev->conn_hash;
684
685 return c->acl_num + c->amp_num + c->sco_num + c->le_num;
686}
687
845472e8
MH
688static inline __u8 hci_conn_lookup_type(struct hci_dev *hdev, __u16 handle)
689{
690 struct hci_conn_hash *h = &hdev->conn_hash;
691 struct hci_conn *c;
692 __u8 type = INVALID_LINK;
693
694 rcu_read_lock();
695
696 list_for_each_entry_rcu(c, &h->list, list) {
697 if (c->handle == handle) {
698 type = c->type;
699 break;
700 }
701 }
702
703 rcu_read_unlock();
704
705 return type;
706}
707
1da177e4 708static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
adc4266d 709 __u16 handle)
1da177e4
LT
710{
711 struct hci_conn_hash *h = &hdev->conn_hash;
1da177e4
LT
712 struct hci_conn *c;
713
bf4c6325
GP
714 rcu_read_lock();
715
716 list_for_each_entry_rcu(c, &h->list, list) {
717 if (c->handle == handle) {
718 rcu_read_unlock();
1da177e4 719 return c;
bf4c6325 720 }
1da177e4 721 }
bf4c6325
GP
722 rcu_read_unlock();
723
1da177e4
LT
724 return NULL;
725}
726
727static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
adc4266d 728 __u8 type, bdaddr_t *ba)
1da177e4
LT
729{
730 struct hci_conn_hash *h = &hdev->conn_hash;
1da177e4
LT
731 struct hci_conn *c;
732
bf4c6325
GP
733 rcu_read_lock();
734
735 list_for_each_entry_rcu(c, &h->list, list) {
736 if (c->type == type && !bacmp(&c->dst, ba)) {
737 rcu_read_unlock();
1da177e4 738 return c;
bf4c6325 739 }
1da177e4 740 }
bf4c6325
GP
741
742 rcu_read_unlock();
743
1da177e4
LT
744 return NULL;
745}
746
4c67bc74 747static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
adc4266d 748 __u8 type, __u16 state)
4c67bc74
MH
749{
750 struct hci_conn_hash *h = &hdev->conn_hash;
4c67bc74
MH
751 struct hci_conn *c;
752
bf4c6325
GP
753 rcu_read_lock();
754
755 list_for_each_entry_rcu(c, &h->list, list) {
756 if (c->type == type && c->state == state) {
757 rcu_read_unlock();
4c67bc74 758 return c;
bf4c6325 759 }
4c67bc74 760 }
73d80deb 761
bf4c6325 762 rcu_read_unlock();
73d80deb 763
4c67bc74 764 return NULL;
73d80deb
LAD
765}
766
e3b679d5 767int hci_disconnect(struct hci_conn *conn, __u8 reason);
2dea632f 768bool hci_setup_sync(struct hci_conn *conn, __u16 handle);
e73439d8 769void hci_sco_setup(struct hci_conn *conn, __u8 status);
1da177e4 770
a5c4e309
JH
771struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
772 u8 role);
a9de9248
MH
773int hci_conn_del(struct hci_conn *conn);
774void hci_conn_hash_flush(struct hci_dev *hdev);
775void hci_conn_check_pending(struct hci_dev *hdev);
1da177e4 776
73d80deb 777struct hci_chan *hci_chan_create(struct hci_conn *conn);
9472007c 778void hci_chan_del(struct hci_chan *chan);
2c33c06a 779void hci_chan_list_flush(struct hci_conn *conn);
42c4e53e 780struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
73d80deb 781
04a6c589 782struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
cdd6275e 783 u8 dst_type, u8 sec_level, u16 conn_timeout,
e804d25d 784 u8 role);
04a6c589
AG
785struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
786 u8 sec_level, u8 auth_type);
10c62ddc
FD
787struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
788 __u16 setting);
e7c29cb1 789int hci_conn_check_link_mode(struct hci_conn *conn);
b3b1b061 790int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
e7cafc45
JH
791int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type,
792 bool initiator);
8c1b2355 793int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
1da177e4 794
14b12d0b 795void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
1da177e4 796
06c053fb
AG
797void hci_le_conn_failed(struct hci_conn *conn, u8 status);
798
8d12356f
DH
799/*
800 * hci_conn_get() and hci_conn_put() are used to control the life-time of an
801 * "hci_conn" object. They do not guarantee that the hci_conn object is running,
802 * working or anything else. They just guarantee that the object is available
803 * and can be dereferenced. So you can use its locks, local variables and any
804 * other constant data.
805 * Before accessing runtime data, you _must_ lock the object and then check that
806 * it is still running. As soon as you release the locks, the connection might
807 * get dropped, though.
808 *
809 * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control
810 * how long the underlying connection is held. So every channel that runs on the
811 * hci_conn object calls this to prevent the connection from disappearing. As
812 * long as you hold a device, you must also guarantee that you have a valid
813 * reference to the device via hci_conn_get() (or the initial reference from
814 * hci_conn_add()).
815 * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't
816 * break because nobody cares for that. But this means, we cannot use
817 * _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
818 */
819
51bb8457 820static inline struct hci_conn *hci_conn_get(struct hci_conn *conn)
8d12356f
DH
821{
822 get_device(&conn->dev);
51bb8457 823 return conn;
8d12356f
DH
824}
825
826static inline void hci_conn_put(struct hci_conn *conn)
827{
828 put_device(&conn->dev);
829}
830
1da177e4
LT
831static inline void hci_conn_hold(struct hci_conn *conn)
832{
71becf0c 833 BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
38b3fef1 834
1da177e4 835 atomic_inc(&conn->refcnt);
2f304d1e 836 cancel_delayed_work(&conn->disc_work);
1da177e4
LT
837}
838
76a68ba0 839static inline void hci_conn_drop(struct hci_conn *conn)
1da177e4 840{
71becf0c 841 BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
38b3fef1 842
1da177e4 843 if (atomic_dec_and_test(&conn->refcnt)) {
04837f64 844 unsigned long timeo;
716e4ab5
AE
845
846 switch (conn->type) {
847 case ACL_LINK:
848 case LE_LINK:
a74a84f6 849 cancel_delayed_work(&conn->idle_work);
6ac59344 850 if (conn->state == BT_CONNECTED) {
5f246e89 851 timeo = conn->disc_timeout;
6ac59344 852 if (!conn->out)
052b30b0 853 timeo *= 2;
5a9d0a3f 854 } else {
eb78d7e5 855 timeo = 0;
5a9d0a3f 856 }
716e4ab5
AE
857 break;
858
859 case AMP_LINK:
860 timeo = conn->disc_timeout;
861 break;
862
863 default:
eb78d7e5 864 timeo = 0;
716e4ab5 865 break;
5a9d0a3f 866 }
716e4ab5 867
2f304d1e 868 cancel_delayed_work(&conn->disc_work);
19c40e3b 869 queue_delayed_work(conn->hdev->workqueue,
716e4ab5 870 &conn->disc_work, timeo);
1da177e4
LT
871 }
872}
873
1da177e4 874/* ----- HCI Devices ----- */
dc946bd8 875static inline void hci_dev_put(struct hci_dev *d)
1da177e4 876{
376261ae
AE
877 BT_DBG("%s orig refcnt %d", d->name,
878 atomic_read(&d->dev.kobj.kref.refcount));
879
4c724c71 880 put_device(&d->dev);
1da177e4
LT
881}
882
dc946bd8 883static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
1da177e4 884{
376261ae
AE
885 BT_DBG("%s orig refcnt %d", d->name,
886 atomic_read(&d->dev.kobj.kref.refcount));
887
4c724c71 888 get_device(&d->dev);
1da177e4
LT
889 return d;
890}
891
09fd0de5
GP
892#define hci_dev_lock(d) mutex_lock(&d->lock)
893#define hci_dev_unlock(d) mutex_unlock(&d->lock)
1da177e4 894
aa2b86d7 895#define to_hci_dev(d) container_of(d, struct hci_dev, dev)
3dc07322 896#define to_hci_conn(c) container_of(c, struct hci_conn, dev)
aa2b86d7 897
155961e8
DH
898static inline void *hci_get_drvdata(struct hci_dev *hdev)
899{
900 return dev_get_drvdata(&hdev->dev);
901}
902
903static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
904{
905 dev_set_drvdata(&hdev->dev, data);
906}
907
1da177e4 908struct hci_dev *hci_dev_get(int index);
0c0afedf 909struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src);
1da177e4
LT
910
911struct hci_dev *hci_alloc_dev(void);
912void hci_free_dev(struct hci_dev *hdev);
913int hci_register_dev(struct hci_dev *hdev);
59735631 914void hci_unregister_dev(struct hci_dev *hdev);
1da177e4
LT
915int hci_suspend_dev(struct hci_dev *hdev);
916int hci_resume_dev(struct hci_dev *hdev);
75e0569f 917int hci_reset_dev(struct hci_dev *hdev);
1da177e4
LT
918int hci_dev_open(__u16 dev);
919int hci_dev_close(__u16 dev);
920int hci_dev_reset(__u16 dev);
921int hci_dev_reset_stat(__u16 dev);
922int hci_dev_cmd(unsigned int cmd, void __user *arg);
923int hci_get_dev_list(void __user *arg);
924int hci_get_dev_info(void __user *arg);
925int hci_get_conn_list(void __user *arg);
926int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
40be492f 927int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
1da177e4
LT
928int hci_inquiry(void __user *arg);
929
dcc36c16
JH
930struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list,
931 bdaddr_t *bdaddr, u8 type);
932int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type);
933int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type);
934void hci_bdaddr_list_clear(struct list_head *list);
d2ab0ac1 935
15819a70
AG
936struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
937 bdaddr_t *addr, u8 addr_type);
51d167c0
MH
938struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
939 bdaddr_t *addr, u8 addr_type);
15819a70 940void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
373110c5 941void hci_conn_params_clear_all(struct hci_dev *hdev);
55af49a8 942void hci_conn_params_clear_disabled(struct hci_dev *hdev);
15819a70 943
501f8827
JH
944struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
945 bdaddr_t *addr,
946 u8 addr_type);
77a77a30 947
35f7498a 948void hci_uuids_clear(struct hci_dev *hdev);
2aeb9a1a 949
35f7498a 950void hci_link_keys_clear(struct hci_dev *hdev);
55ed8ca1 951struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
567fa2aa 952struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
7652ff6a
JH
953 bdaddr_t *bdaddr, u8 *val, u8 type,
954 u8 pin_len, bool *persistent);
ca9142b8 955struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
35d70271 956 u8 addr_type, u8 type, u8 authenticated,
fe39c7b2 957 u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand);
f3a73d97
JH
958struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
959 u8 addr_type, u8 role);
e0b2b27e 960int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type);
35f7498a 961void hci_smp_ltks_clear(struct hci_dev *hdev);
55ed8ca1
JH
962int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
963
970c4e46
JH
964struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa);
965struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
966 u8 addr_type);
ca9142b8
JH
967struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
968 u8 addr_type, u8 val[16], bdaddr_t *rpa);
a7ec7338 969void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
970c4e46
JH
970void hci_smp_irks_clear(struct hci_dev *hdev);
971
35f7498a 972void hci_remote_oob_data_clear(struct hci_dev *hdev);
2763eda6 973struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
6928a924 974 bdaddr_t *bdaddr, u8 bdaddr_type);
0798872e 975int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
6928a924 976 u8 bdaddr_type, u8 *hash192, u8 *rand192,
81328d5c 977 u8 *hash256, u8 *rand256);
6928a924
JH
978int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
979 u8 bdaddr_type);
2763eda6 980
1da177e4
LT
981void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
982
e1a26170 983int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
99811510 984int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
ef222013 985
0ac7e700 986void hci_init_sysfs(struct hci_dev *hdev);
a67e899c 987void hci_conn_init_sysfs(struct hci_conn *conn);
b219e3ac
MH
988void hci_conn_add_sysfs(struct hci_conn *conn);
989void hci_conn_del_sysfs(struct hci_conn *conn);
1da177e4 990
6935e0f5 991#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
1da177e4
LT
992
993/* ----- LMP capabilities ----- */
cad718ed
JH
994#define lmp_encrypt_capable(dev) ((dev)->features[0][0] & LMP_ENCRYPT)
995#define lmp_rswitch_capable(dev) ((dev)->features[0][0] & LMP_RSWITCH)
996#define lmp_hold_capable(dev) ((dev)->features[0][0] & LMP_HOLD)
997#define lmp_sniff_capable(dev) ((dev)->features[0][0] & LMP_SNIFF)
998#define lmp_park_capable(dev) ((dev)->features[0][1] & LMP_PARK)
999#define lmp_inq_rssi_capable(dev) ((dev)->features[0][3] & LMP_RSSI_INQ)
1000#define lmp_esco_capable(dev) ((dev)->features[0][3] & LMP_ESCO)
1001#define lmp_bredr_capable(dev) (!((dev)->features[0][4] & LMP_NO_BREDR))
1002#define lmp_le_capable(dev) ((dev)->features[0][4] & LMP_LE)
1003#define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR)
1004#define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC)
1005#define lmp_ext_inq_capable(dev) ((dev)->features[0][6] & LMP_EXT_INQ)
1006#define lmp_le_br_capable(dev) (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR))
1007#define lmp_ssp_capable(dev) ((dev)->features[0][6] & LMP_SIMPLE_PAIR)
1008#define lmp_no_flush_capable(dev) ((dev)->features[0][6] & LMP_NO_FLUSH)
1009#define lmp_lsto_capable(dev) ((dev)->features[0][7] & LMP_LSTO)
1010#define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR)
1011#define lmp_ext_feat_capable(dev) ((dev)->features[0][7] & LMP_EXTFEATURES)
07a5c61e 1012#define lmp_transp_capable(dev) ((dev)->features[0][2] & LMP_TRANSPARENT)
1da177e4 1013
eead27da 1014/* ----- Extended LMP capabilities ----- */
53b834d2
MH
1015#define lmp_csb_master_capable(dev) ((dev)->features[2][0] & LMP_CSB_MASTER)
1016#define lmp_csb_slave_capable(dev) ((dev)->features[2][0] & LMP_CSB_SLAVE)
1017#define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN)
1018#define lmp_sync_scan_capable(dev) ((dev)->features[2][0] & LMP_SYNC_SCAN)
d5991585
MH
1019#define lmp_sc_capable(dev) ((dev)->features[2][1] & LMP_SC)
1020#define lmp_ping_capable(dev) ((dev)->features[2][1] & LMP_PING)
53b834d2
MH
1021
1022/* ----- Host capabilities ----- */
cad718ed 1023#define lmp_host_ssp_capable(dev) ((dev)->features[1][0] & LMP_HOST_SSP)
d5991585 1024#define lmp_host_sc_capable(dev) ((dev)->features[1][0] & LMP_HOST_SC)
cad718ed
JH
1025#define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE))
1026#define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
eead27da 1027
432df05e
JH
1028#define hdev_is_powered(hdev) (test_bit(HCI_UP, &hdev->flags) && \
1029 !test_bit(HCI_AUTO_OFF, &hdev->dev_flags))
05b3c3e7 1030#define bredr_sc_enabled(dev) (lmp_sc_capable(dev) && \
710f11c0 1031 test_bit(HCI_SC_ENABLED, &(dev)->dev_flags))
432df05e 1032
1da177e4 1033/* ----- HCI protocols ----- */
20714bfe
FD
1034#define HCI_PROTO_DEFER 0x01
1035
5a9d0a3f 1036static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
20714bfe 1037 __u8 type, __u8 *flags)
1da177e4 1038{
686ebf28
UF
1039 switch (type) {
1040 case ACL_LINK:
1041 return l2cap_connect_ind(hdev, bdaddr);
1da177e4 1042
686ebf28
UF
1043 case SCO_LINK:
1044 case ESCO_LINK:
20714bfe 1045 return sco_connect_ind(hdev, bdaddr, flags);
1da177e4 1046
686ebf28
UF
1047 default:
1048 BT_ERR("unknown link type %d", type);
1049 return -EINVAL;
1050 }
1da177e4
LT
1051}
1052
1053static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
1054{
686ebf28
UF
1055 switch (conn->type) {
1056 case ACL_LINK:
1057 case LE_LINK:
1058 l2cap_connect_cfm(conn, status);
1059 break;
1da177e4 1060
686ebf28
UF
1061 case SCO_LINK:
1062 case ESCO_LINK:
1063 sco_connect_cfm(conn, status);
1064 break;
1da177e4 1065
686ebf28
UF
1066 default:
1067 BT_ERR("unknown link type %d", conn->type);
1068 break;
1069 }
e9a416b5
JH
1070
1071 if (conn->connect_cfm_cb)
1072 conn->connect_cfm_cb(conn, status);
1da177e4
LT
1073}
1074
2950f21a 1075static inline int hci_proto_disconn_ind(struct hci_conn *conn)
1da177e4 1076{
686ebf28
UF
1077 if (conn->type != ACL_LINK && conn->type != LE_LINK)
1078 return HCI_ERROR_REMOTE_USER_TERM;
1da177e4 1079
686ebf28 1080 return l2cap_disconn_ind(conn);
2950f21a
MH
1081}
1082
1083static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
1084{
686ebf28
UF
1085 switch (conn->type) {
1086 case ACL_LINK:
1087 case LE_LINK:
1088 l2cap_disconn_cfm(conn, reason);
1089 break;
2950f21a 1090
686ebf28
UF
1091 case SCO_LINK:
1092 case ESCO_LINK:
1093 sco_disconn_cfm(conn, reason);
1094 break;
2950f21a 1095
bd1eb66b
AE
1096 /* L2CAP would be handled for BREDR chan */
1097 case AMP_LINK:
1098 break;
1099
686ebf28
UF
1100 default:
1101 BT_ERR("unknown link type %d", conn->type);
1102 break;
1103 }
e9a416b5
JH
1104
1105 if (conn->disconn_cfm_cb)
1106 conn->disconn_cfm_cb(conn, reason);
1da177e4
LT
1107}
1108
1109static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
1110{
8c1b2355
MH
1111 __u8 encrypt;
1112
686ebf28
UF
1113 if (conn->type != ACL_LINK && conn->type != LE_LINK)
1114 return;
1115
51a8efd7 1116 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
8c1b2355
MH
1117 return;
1118
4dae2798 1119 encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
686ebf28 1120 l2cap_security_cfm(conn, status, encrypt);
e9a416b5
JH
1121
1122 if (conn->security_cfm_cb)
1123 conn->security_cfm_cb(conn, status);
1da177e4
LT
1124}
1125
5a9d0a3f
WR
1126static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
1127 __u8 encrypt)
1da177e4 1128{
686ebf28
UF
1129 if (conn->type != ACL_LINK && conn->type != LE_LINK)
1130 return;
1da177e4 1131
686ebf28 1132 l2cap_security_cfm(conn, status, encrypt);
e9a416b5
JH
1133
1134 if (conn->security_cfm_cb)
1135 conn->security_cfm_cb(conn, status);
1da177e4
LT
1136}
1137
1da177e4
LT
1138/* ----- HCI callbacks ----- */
1139struct hci_cb {
1140 struct list_head list;
1141
1142 char *name;
1143
5a9d0a3f
WR
1144 void (*security_cfm) (struct hci_conn *conn, __u8 status,
1145 __u8 encrypt);
1da177e4
LT
1146 void (*key_change_cfm) (struct hci_conn *conn, __u8 status);
1147 void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role);
1148};
1149
1150static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
1151{
711584ea 1152 struct hci_cb *cb;
8c1b2355 1153 __u8 encrypt;
1da177e4
LT
1154
1155 hci_proto_auth_cfm(conn, status);
1156
51a8efd7 1157 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
8c1b2355
MH
1158 return;
1159
4dae2798 1160 encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
8c1b2355 1161
f20d09d5 1162 read_lock(&hci_cb_list_lock);
711584ea 1163 list_for_each_entry(cb, &hci_cb_list, list) {
8c1b2355
MH
1164 if (cb->security_cfm)
1165 cb->security_cfm(conn, status, encrypt);
1da177e4 1166 }
f20d09d5 1167 read_unlock(&hci_cb_list_lock);
1da177e4
LT
1168}
1169
5a9d0a3f
WR
1170static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
1171 __u8 encrypt)
1da177e4 1172{
711584ea 1173 struct hci_cb *cb;
1da177e4 1174
435fef20
MH
1175 if (conn->sec_level == BT_SECURITY_SDP)
1176 conn->sec_level = BT_SECURITY_LOW;
1177
88167aed
VCG
1178 if (conn->pending_sec_level > conn->sec_level)
1179 conn->sec_level = conn->pending_sec_level;
1180
9719f8af 1181 hci_proto_encrypt_cfm(conn, status, encrypt);
1da177e4 1182
f20d09d5 1183 read_lock(&hci_cb_list_lock);
711584ea 1184 list_for_each_entry(cb, &hci_cb_list, list) {
8c1b2355
MH
1185 if (cb->security_cfm)
1186 cb->security_cfm(conn, status, encrypt);
1da177e4 1187 }
f20d09d5 1188 read_unlock(&hci_cb_list_lock);
1da177e4
LT
1189}
1190
1191static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
1192{
711584ea 1193 struct hci_cb *cb;
1da177e4 1194
f20d09d5 1195 read_lock(&hci_cb_list_lock);
711584ea 1196 list_for_each_entry(cb, &hci_cb_list, list) {
1da177e4
LT
1197 if (cb->key_change_cfm)
1198 cb->key_change_cfm(conn, status);
1199 }
f20d09d5 1200 read_unlock(&hci_cb_list_lock);
1da177e4
LT
1201}
1202
5a9d0a3f
WR
1203static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
1204 __u8 role)
1da177e4 1205{
711584ea 1206 struct hci_cb *cb;
1da177e4 1207
f20d09d5 1208 read_lock(&hci_cb_list_lock);
711584ea 1209 list_for_each_entry(cb, &hci_cb_list, list) {
1da177e4
LT
1210 if (cb->role_switch_cfm)
1211 cb->role_switch_cfm(conn, status, role);
1212 }
f20d09d5 1213 read_unlock(&hci_cb_list_lock);
1da177e4
LT
1214}
1215
6759a675
JH
1216static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
1217{
84d9d071 1218 size_t parsed = 0;
6759a675 1219
6c0c331e
JH
1220 if (data_len < 2)
1221 return false;
1222
84d9d071
JH
1223 while (parsed < data_len - 1) {
1224 u8 field_len = data[0];
6759a675
JH
1225
1226 if (field_len == 0)
1227 break;
1228
1229 parsed += field_len + 1;
1230
1231 if (parsed > data_len)
1232 break;
1233
1234 if (data[1] == type)
1235 return true;
1236
1237 data += field_len + 1;
1238 }
1239
1240 return false;
1241}
1242
301cb2d8
JH
1243static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
1244{
dbbfa2ab 1245 if (addr_type != ADDR_LE_DEV_RANDOM)
301cb2d8
JH
1246 return false;
1247
1248 if ((bdaddr->b[5] & 0xc0) == 0x40)
1249 return true;
1250
1251 return false;
1252}
1253
c46245b3
JH
1254static inline bool hci_is_identity_address(bdaddr_t *addr, u8 addr_type)
1255{
1256 if (addr_type == ADDR_LE_DEV_PUBLIC)
1257 return true;
1258
1259 /* Check for Random Static address type */
1260 if ((addr->b[5] & 0xc0) == 0xc0)
1261 return true;
1262
1263 return false;
1264}
1265
2426f3a5
JH
1266static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
1267 bdaddr_t *bdaddr, u8 addr_type)
1268{
1269 if (!hci_bdaddr_is_rpa(bdaddr, addr_type))
1270 return NULL;
1271
1272 return hci_find_irk_by_rpa(hdev, bdaddr);
1273}
1274
d4905f24
AG
1275static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
1276 u16 to_multiplier)
1277{
1278 u16 max_latency;
1279
1280 if (min > max || min < 6 || max > 3200)
1281 return -EINVAL;
1282
1283 if (to_multiplier < 10 || to_multiplier > 3200)
1284 return -EINVAL;
1285
1286 if (max >= to_multiplier * 8)
1287 return -EINVAL;
1288
1289 max_latency = (to_multiplier * 8 / max) - 1;
1290 if (latency > 499 || latency > max_latency)
1291 return -EINVAL;
1292
1293 return 0;
1294}
1295
1da177e4
LT
1296int hci_register_cb(struct hci_cb *hcb);
1297int hci_unregister_cb(struct hci_cb *hcb);
1298
899de765 1299bool hci_req_pending(struct hci_dev *hdev);
3119ae95 1300
75e84b7c 1301struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
07dc93dd 1302 const void *param, u32 timeout);
7b1abbbe 1303struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
07dc93dd 1304 const void *param, u8 event, u32 timeout);
75e84b7c 1305
07dc93dd
JH
1306int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
1307 const void *param);
73d80deb 1308void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
0d861d8b 1309void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
1da177e4 1310
a9de9248 1311void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
1da177e4 1312
1da177e4 1313/* ----- HCI Sockets ----- */
470fe1b5
MH
1314void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
1315void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk);
cd82e61c 1316void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
1da177e4 1317
040030ef
MH
1318void hci_sock_dev_event(struct hci_dev *hdev, int event);
1319
0381101f 1320/* Management interface */
591f47f3
AG
1321#define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR))
1322#define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \
1323 BIT(BDADDR_LE_RANDOM))
1324#define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \
1325 BIT(BDADDR_LE_PUBLIC) | \
1326 BIT(BDADDR_LE_RANDOM))
f39799f5 1327
0d8cc935
AG
1328/* These LE scan and inquiry parameters were chosen according to LE General
1329 * Discovery Procedure specification.
1330 */
1331#define DISCOV_LE_SCAN_WIN 0x12
1332#define DISCOV_LE_SCAN_INT 0x12
3d5a76f0 1333#define DISCOV_LE_TIMEOUT 10240 /* msec */
ae55f598 1334#define DISCOV_INTERLEAVED_TIMEOUT 5120 /* msec */
0d8cc935
AG
1335#define DISCOV_INTERLEAVED_INQUIRY_LEN 0x04
1336#define DISCOV_BREDR_INQUIRY_LEN 0x08
4b0e0ced 1337#define DISCOV_LE_RESTART_DELAY msecs_to_jiffies(200) /* msec */
0d8cc935 1338
0381101f 1339int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
91a668b0 1340int mgmt_new_settings(struct hci_dev *hdev);
bf6b56db
MH
1341void mgmt_index_added(struct hci_dev *hdev);
1342void mgmt_index_removed(struct hci_dev *hdev);
3eec705e 1343void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
744cf19e 1344int mgmt_powered(struct hci_dev *hdev, u8 powered);
bc6d2d04 1345int mgmt_update_adv_data(struct hci_dev *hdev);
d1967ff8 1346void mgmt_discoverable_timeout(struct hci_dev *hdev);
dc4a5ee2
MH
1347void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
1348 bool persistent);
48ec92fa
AA
1349void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
1350 u32 flags, u8 *name, u8 name_len);
9b80ec5e 1351void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
12d4a3b2
JH
1352 u8 link_type, u8 addr_type, u8 reason,
1353 bool mgmt_connected);
7892924c
MH
1354void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
1355 u8 link_type, u8 addr_type, u8 status);
445608d0
MH
1356void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1357 u8 addr_type, u8 status);
ce0e4a0d 1358void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
e669cf80
MH
1359void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1360 u8 status);
3eb38528
MH
1361void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1362 u8 status);
744cf19e 1363int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
39adbffe 1364 u8 link_type, u8 addr_type, u32 value,
04124681 1365 u8 confirm_hint);
744cf19e 1366int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1367 u8 link_type, u8 addr_type, u8 status);
272d90df 1368int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1369 u8 link_type, u8 addr_type, u8 status);
272d90df 1370int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1371 u8 link_type, u8 addr_type);
604086b7 1372int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1373 u8 link_type, u8 addr_type, u8 status);
272d90df 1374int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1375 u8 link_type, u8 addr_type, u8 status);
92a25256
JH
1376int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
1377 u8 link_type, u8 addr_type, u32 passkey,
1378 u8 entered);
e1e930f5 1379void mgmt_auth_failed(struct hci_conn *conn, u8 status);
464996ae 1380void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
3e248560 1381void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
4e1b0245
MH
1382void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
1383 u8 status);
7667da34 1384void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
4d2d2796 1385void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,
38da1703
JH
1386 u8 *rand192, u8 *hash256, u8 *rand256,
1387 u8 status);
901801b9 1388void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
af58925c
MH
1389 u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
1390 u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len);
9cf12aee
MH
1391void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1392 u8 addr_type, s8 rssi, u8 *name, u8 name_len);
2f1e063b 1393void mgmt_discovering(struct hci_dev *hdev, u8 discovering);
84c61d92 1394bool mgmt_powering_down(struct hci_dev *hdev);
53ac6ab6 1395void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent);
95fbac8a 1396void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk);
53ac6ab6
MH
1397void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
1398 bool persistent);
ffb5a827 1399void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
f4869e2a
JH
1400 u8 bdaddr_type, u8 store_hint, u16 min_interval,
1401 u16 max_interval, u16 latency, u16 timeout);
5976e608 1402void mgmt_reenable_advertising(struct hci_dev *hdev);
f4a407be 1403void mgmt_smp_complete(struct hci_conn *conn, bool complete);
346af67b 1404
7d6ca693
JH
1405u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
1406 u16 to_multiplier);
fe39c7b2 1407void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
a7a595f6 1408 __u8 ltk[16]);
2519a1fc 1409
a1f4c318
JH
1410void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
1411 u8 *bdaddr_type);
ebd3a747 1412
5d4d62f6
FD
1413#define SCO_AIRMODE_MASK 0x0003
1414#define SCO_AIRMODE_CVSD 0x0000
1415#define SCO_AIRMODE_TRANSP 0x0003
1416
1da177e4 1417#endif /* __HCI_CORE_H */
This page took 0.896077 seconds and 5 git commands to generate.