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