]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/bluetooth/hci_core.h
Bluetooth: Add LE Local Features reading support
[mirror_ubuntu-bionic-kernel.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;
1da177e4
LT
71};
72
73struct hci_conn_hash {
74 struct list_head list;
1da177e4 75 unsigned int acl_num;
bd1eb66b 76 unsigned int amp_num;
1da177e4 77 unsigned int sco_num;
fcd89c09 78 unsigned int le_num;
1da177e4
LT
79};
80
f0358568
JH
81struct bdaddr_list {
82 struct list_head list;
83 bdaddr_t bdaddr;
84};
2aeb9a1a
JH
85
86struct bt_uuid {
87 struct list_head list;
88 u8 uuid[16];
1aff6f09 89 u8 svc_hint;
2aeb9a1a
JH
90};
91
b899efaf
VCG
92struct smp_ltk {
93 struct list_head list;
94 bdaddr_t bdaddr;
95 u8 bdaddr_type;
96 u8 authenticated;
97 u8 type;
98 u8 enc_size;
99 __le16 ediv;
100 u8 rand[8];
101 u8 val[16];
102} __packed;
103
55ed8ca1
JH
104struct link_key {
105 struct list_head list;
106 bdaddr_t bdaddr;
107 u8 type;
9b3b4460 108 u8 val[HCI_LINK_KEY_SIZE];
55ed8ca1
JH
109 u8 pin_len;
110};
111
2763eda6
SJ
112struct oob_data {
113 struct list_head list;
114 bdaddr_t bdaddr;
115 u8 hash[16];
116 u8 randomizer[16];
117};
118
7ba8b4be
AG
119struct le_scan_params {
120 u8 type;
121 u16 interval;
122 u16 window;
28b75a89 123 int timeout;
7ba8b4be
AG
124};
125
490c5bab
JH
126#define HCI_MAX_SHORT_NAME_LENGTH 10
127
903e4541
AE
128struct amp_assoc {
129 __u16 len;
130 __u16 offset;
93c284ee
AE
131 __u16 rem_len;
132 __u16 len_so_far;
903e4541
AE
133 __u8 data[HCI_MAX_AMP_ASSOC_SIZE];
134};
135
cd4c5391 136#define NUM_REASSEMBLY 4
1da177e4
LT
137struct hci_dev {
138 struct list_head list;
09fd0de5 139 struct mutex lock;
1da177e4
LT
140
141 char name[8];
142 unsigned long flags;
143 __u16 id;
c13854ce 144 __u8 bus;
943da25d 145 __u8 dev_type;
1da177e4 146 bdaddr_t bdaddr;
1f6c6378 147 __u8 dev_name[HCI_MAX_NAME_LENGTH];
490c5bab 148 __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH];
80a1e1db 149 __u8 eir[HCI_MAX_EIR_LENGTH];
a9de9248 150 __u8 dev_class[3];
1aff6f09
JH
151 __u8 major_class;
152 __u8 minor_class;
1da177e4 153 __u8 features[8];
59e29406 154 __u8 host_features[8];
60e77321 155 __u8 le_features[8];
a9de9248 156 __u8 commands[64];
1143e5a6
MH
157 __u8 hci_ver;
158 __u16 hci_rev;
d5859e22 159 __u8 lmp_ver;
1143e5a6 160 __u16 manufacturer;
7d69230c 161 __u16 lmp_subver;
1da177e4 162 __u16 voice_setting;
17fa4b9d 163 __u8 io_capability;
91c4e9b1 164 __s8 inq_tx_power;
2b9be137
MH
165 __u16 devid_source;
166 __u16 devid_vendor;
167 __u16 devid_product;
168 __u16 devid_version;
1da177e4
LT
169
170 __u16 pkt_type;
5b7f9909 171 __u16 esco_type;
1da177e4
LT
172 __u16 link_policy;
173 __u16 link_mode;
174
04837f64
MH
175 __u32 idle_timeout;
176 __u16 sniff_min_interval;
177 __u16 sniff_max_interval;
178
928abaa7
AE
179 __u8 amp_status;
180 __u32 amp_total_bw;
181 __u32 amp_max_bw;
182 __u32 amp_min_latency;
183 __u32 amp_max_pdu;
184 __u8 amp_type;
185 __u16 amp_pal_cap;
186 __u16 amp_assoc_size;
187 __u32 amp_max_flush_to;
188 __u32 amp_be_flush_to;
189
903e4541
AE
190 struct amp_assoc loc_assoc;
191
1e89cffb
AE
192 __u8 flow_ctl_mode;
193
9f61656a
JH
194 unsigned int auto_accept_delay;
195
1da177e4
LT
196 unsigned long quirks;
197
198 atomic_t cmd_cnt;
199 unsigned int acl_cnt;
200 unsigned int sco_cnt;
6ed58ec5 201 unsigned int le_cnt;
1da177e4
LT
202
203 unsigned int acl_mtu;
204 unsigned int sco_mtu;
6ed58ec5 205 unsigned int le_mtu;
1da177e4
LT
206 unsigned int acl_pkts;
207 unsigned int sco_pkts;
6ed58ec5 208 unsigned int le_pkts;
1da177e4 209
350ee4cf
AE
210 __u16 block_len;
211 __u16 block_mtu;
212 __u16 num_blocks;
213 __u16 block_cnt;
214
1da177e4
LT
215 unsigned long acl_last_tx;
216 unsigned long sco_last_tx;
6ed58ec5 217 unsigned long le_last_tx;
1da177e4 218
f48fd9c8 219 struct workqueue_struct *workqueue;
6ead1bbc 220 struct workqueue_struct *req_workqueue;
f48fd9c8 221
ab81cbf9 222 struct work_struct power_on;
3243553f 223 struct delayed_work power_off;
ab81cbf9 224
16ab91ab
JH
225 __u16 discov_timeout;
226 struct delayed_work discov_off;
227
7d78525d
JH
228 struct delayed_work service_cache;
229
6bd32326 230 struct timer_list cmd_timer;
b78752cc
MH
231
232 struct work_struct rx_work;
c347b765 233 struct work_struct cmd_work;
3eff45ea 234 struct work_struct tx_work;
1da177e4
LT
235
236 struct sk_buff_head rx_q;
237 struct sk_buff_head raw_q;
238 struct sk_buff_head cmd_q;
239
240 struct sk_buff *sent_cmd;
cd4c5391 241 struct sk_buff *reassembly[NUM_REASSEMBLY];
1da177e4 242
a6a67efd 243 struct mutex req_lock;
1da177e4
LT
244 wait_queue_head_t req_wait_q;
245 __u32 req_status;
246 __u32 req_result;
a5040efa
JH
247
248 __u16 init_last_cmd;
1da177e4 249
2e58ef3e
JH
250 struct list_head mgmt_pending;
251
30883512 252 struct discovery_state discovery;
1da177e4 253 struct hci_conn_hash conn_hash;
ea4bd8ba 254 struct list_head blacklist;
1da177e4 255
2aeb9a1a
JH
256 struct list_head uuids;
257
55ed8ca1
JH
258 struct list_head link_keys;
259
b899efaf
VCG
260 struct list_head long_term_keys;
261
2763eda6
SJ
262 struct list_head remote_oob_data;
263
1da177e4
LT
264 struct hci_dev_stats stat;
265
266 struct sk_buff_head driver_init;
267
70f23020 268 atomic_t promisc;
1da177e4 269
ca325f69
MH
270 struct dentry *debugfs;
271
a91f2e39 272 struct device dev;
1da177e4 273
611b30f7
MH
274 struct rfkill *rfkill;
275
d23264a8
AG
276 unsigned long dev_flags;
277
7ba8b4be
AG
278 struct delayed_work le_scan_disable;
279
28b75a89
AG
280 struct work_struct le_scan;
281 struct le_scan_params le_scan_params;
282
8fa19098 283 __s8 adv_tx_power;
3f0f524b
JH
284 __u8 adv_data[HCI_MAX_AD_LENGTH];
285 __u8 adv_data_len;
8fa19098 286
1da177e4
LT
287 int (*open)(struct hci_dev *hdev);
288 int (*close)(struct hci_dev *hdev);
289 int (*flush)(struct hci_dev *hdev);
290 int (*send)(struct sk_buff *skb);
1da177e4
LT
291 void (*notify)(struct hci_dev *hdev, unsigned int evt);
292 int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
293};
294
53502d69
AE
295#define HCI_PHY_HANDLE(handle) (handle & 0xff)
296
1da177e4
LT
297struct hci_conn {
298 struct list_head list;
299
adc4266d 300 atomic_t refcnt;
adc4266d
SJ
301
302 bdaddr_t dst;
5a9d0a3f 303 __u8 dst_type;
adc4266d
SJ
304 __u16 handle;
305 __u16 state;
306 __u8 mode;
307 __u8 type;
a0c808b3 308 bool out;
adc4266d
SJ
309 __u8 attempt;
310 __u8 dev_class[3];
311 __u8 features[8];
adc4266d
SJ
312 __u16 interval;
313 __u16 pkt_type;
314 __u16 link_policy;
315 __u32 link_mode;
13d39315 316 __u8 key_type;
adc4266d
SJ
317 __u8 auth_type;
318 __u8 sec_level;
319 __u8 pending_sec_level;
320 __u8 pin_length;
726b4ffc 321 __u8 enc_key_size;
adc4266d 322 __u8 io_capability;
92a25256
JH
323 __u32 passkey_notify;
324 __u8 passkey_entered;
adc4266d 325 __u16 disc_timeout;
51a8efd7 326 unsigned long flags;
04837f64 327
03b555e1 328 __u8 remote_cap;
03b555e1 329 __u8 remote_auth;
3161ae1c 330 __u8 remote_id;
6ec5bcad 331 bool flush_key;
03b555e1 332
adc4266d 333 unsigned int sent;
04837f64 334
1da177e4 335 struct sk_buff_head data_q;
2c33c06a 336 struct list_head chan_list;
1da177e4 337
19c40e3b 338 struct delayed_work disc_work;
04837f64 339 struct timer_list idle_timer;
9f61656a 340 struct timer_list auto_accept_timer;
04837f64 341
b219e3ac 342 struct device dev;
9eba32b8 343 atomic_t devref;
b219e3ac 344
1da177e4
LT
345 struct hci_dev *hdev;
346 void *l2cap_data;
347 void *sco_data;
2b64d153 348 void *smp_conn;
9740e49d 349 struct amp_mgr *amp_mgr;
1da177e4
LT
350
351 struct hci_conn *link;
e9a416b5
JH
352
353 void (*connect_cfm_cb) (struct hci_conn *conn, u8 status);
354 void (*security_cfm_cb) (struct hci_conn *conn, u8 status);
355 void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason);
1da177e4
LT
356};
357
73d80deb
LAD
358struct hci_chan {
359 struct list_head list;
42c4e53e 360 __u16 handle;
73d80deb
LAD
361 struct hci_conn *conn;
362 struct sk_buff_head data_q;
363 unsigned int sent;
168df8e5 364 __u8 state;
73d80deb
LAD
365};
366
1da177e4
LT
367extern struct list_head hci_dev_list;
368extern struct list_head hci_cb_list;
369extern rwlock_t hci_dev_list_lock;
370extern rwlock_t hci_cb_list_lock;
371
686ebf28
UF
372/* ----- HCI interface to upper protocols ----- */
373extern int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
9e664631 374extern void l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
686ebf28 375extern int l2cap_disconn_ind(struct hci_conn *hcon);
9e664631 376extern void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
686ebf28 377extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
c3c7ea65
GP
378extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb,
379 u16 flags);
686ebf28 380
20714bfe 381extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
9e664631
AE
382extern void sco_connect_cfm(struct hci_conn *hcon, __u8 status);
383extern void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
686ebf28
UF
384extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
385
1da177e4 386/* ----- Inquiry cache ----- */
70f23020
AE
387#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */
388#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */
1da177e4 389
30883512 390static inline void discovery_init(struct hci_dev *hdev)
1da177e4 391{
ff9ef578 392 hdev->discovery.state = DISCOVERY_STOPPED;
30883512
JH
393 INIT_LIST_HEAD(&hdev->discovery.all);
394 INIT_LIST_HEAD(&hdev->discovery.unknown);
395 INIT_LIST_HEAD(&hdev->discovery.resolve);
1da177e4
LT
396}
397
30dc78e1
JH
398bool hci_discovery_active(struct hci_dev *hdev);
399
ff9ef578
JH
400void hci_discovery_set_state(struct hci_dev *hdev, int state);
401
1da177e4
LT
402static inline int inquiry_cache_empty(struct hci_dev *hdev)
403{
30883512 404 return list_empty(&hdev->discovery.all);
1da177e4
LT
405}
406
407static inline long inquiry_cache_age(struct hci_dev *hdev)
408{
30883512 409 struct discovery_state *c = &hdev->discovery;
1da177e4
LT
410 return jiffies - c->timestamp;
411}
412
413static inline long inquiry_entry_age(struct inquiry_entry *e)
414{
415 return jiffies - e->timestamp;
416}
417
5a9d0a3f 418struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
04124681 419 bdaddr_t *bdaddr);
561aafbc 420struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
04124681 421 bdaddr_t *bdaddr);
30dc78e1 422struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
04124681
GP
423 bdaddr_t *bdaddr,
424 int state);
a3d4e20a 425void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
04124681 426 struct inquiry_entry *ie);
3175405b 427bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
04124681 428 bool name_known, bool *ssp);
1da177e4
LT
429
430/* ----- HCI Connections ----- */
431enum {
432 HCI_CONN_AUTH_PEND,
19f8def0 433 HCI_CONN_REAUTH_PEND,
1da177e4 434 HCI_CONN_ENCRYPT_PEND,
04837f64
MH
435 HCI_CONN_RSWITCH_PEND,
436 HCI_CONN_MODE_CHANGE_PEND,
e73439d8 437 HCI_CONN_SCO_SETUP_PEND,
d26a2345 438 HCI_CONN_LE_SMP_PEND,
b644ba33 439 HCI_CONN_MGMT_CONNECTED,
58a681ef
JH
440 HCI_CONN_SSP_ENABLED,
441 HCI_CONN_POWER_SAVE,
442 HCI_CONN_REMOTE_OOB,
1da177e4
LT
443};
444
aa64a8b5
JH
445static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
446{
447 struct hci_dev *hdev = conn->hdev;
c3c7ea65
GP
448 return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
449 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
aa64a8b5
JH
450}
451
1da177e4
LT
452static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
453{
454 struct hci_conn_hash *h = &hdev->conn_hash;
bf4c6325 455 list_add_rcu(&c->list, &h->list);
fcd89c09
VT
456 switch (c->type) {
457 case ACL_LINK:
1da177e4 458 h->acl_num++;
fcd89c09 459 break;
bd1eb66b
AE
460 case AMP_LINK:
461 h->amp_num++;
462 break;
fcd89c09
VT
463 case LE_LINK:
464 h->le_num++;
465 break;
466 case SCO_LINK:
467 case ESCO_LINK:
1da177e4 468 h->sco_num++;
fcd89c09
VT
469 break;
470 }
1da177e4
LT
471}
472
473static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
474{
475 struct hci_conn_hash *h = &hdev->conn_hash;
bf4c6325
GP
476
477 list_del_rcu(&c->list);
478 synchronize_rcu();
479
fcd89c09
VT
480 switch (c->type) {
481 case ACL_LINK:
1da177e4 482 h->acl_num--;
fcd89c09 483 break;
bd1eb66b
AE
484 case AMP_LINK:
485 h->amp_num--;
486 break;
fcd89c09
VT
487 case LE_LINK:
488 h->le_num--;
489 break;
490 case SCO_LINK:
491 case ESCO_LINK:
1da177e4 492 h->sco_num--;
fcd89c09
VT
493 break;
494 }
1da177e4
LT
495}
496
52087a79
LAD
497static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
498{
499 struct hci_conn_hash *h = &hdev->conn_hash;
500 switch (type) {
501 case ACL_LINK:
502 return h->acl_num;
bd1eb66b
AE
503 case AMP_LINK:
504 return h->amp_num;
52087a79
LAD
505 case LE_LINK:
506 return h->le_num;
507 case SCO_LINK:
508 case ESCO_LINK:
509 return h->sco_num;
510 default:
511 return 0;
512 }
513}
514
1da177e4 515static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
adc4266d 516 __u16 handle)
1da177e4
LT
517{
518 struct hci_conn_hash *h = &hdev->conn_hash;
1da177e4
LT
519 struct hci_conn *c;
520
bf4c6325
GP
521 rcu_read_lock();
522
523 list_for_each_entry_rcu(c, &h->list, list) {
524 if (c->handle == handle) {
525 rcu_read_unlock();
1da177e4 526 return c;
bf4c6325 527 }
1da177e4 528 }
bf4c6325
GP
529 rcu_read_unlock();
530
1da177e4
LT
531 return NULL;
532}
533
534static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
adc4266d 535 __u8 type, bdaddr_t *ba)
1da177e4
LT
536{
537 struct hci_conn_hash *h = &hdev->conn_hash;
1da177e4
LT
538 struct hci_conn *c;
539
bf4c6325
GP
540 rcu_read_lock();
541
542 list_for_each_entry_rcu(c, &h->list, list) {
543 if (c->type == type && !bacmp(&c->dst, ba)) {
544 rcu_read_unlock();
1da177e4 545 return c;
bf4c6325 546 }
1da177e4 547 }
bf4c6325
GP
548
549 rcu_read_unlock();
550
1da177e4
LT
551 return NULL;
552}
553
4c67bc74 554static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
adc4266d 555 __u8 type, __u16 state)
4c67bc74
MH
556{
557 struct hci_conn_hash *h = &hdev->conn_hash;
4c67bc74
MH
558 struct hci_conn *c;
559
bf4c6325
GP
560 rcu_read_lock();
561
562 list_for_each_entry_rcu(c, &h->list, list) {
563 if (c->type == type && c->state == state) {
564 rcu_read_unlock();
4c67bc74 565 return c;
bf4c6325 566 }
4c67bc74 567 }
73d80deb 568
bf4c6325 569 rcu_read_unlock();
73d80deb 570
4c67bc74 571 return NULL;
73d80deb
LAD
572}
573
1da177e4 574void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
b6a0dc82 575void hci_setup_sync(struct hci_conn *conn, __u16 handle);
e73439d8 576void hci_sco_setup(struct hci_conn *conn, __u8 status);
1da177e4
LT
577
578struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
a9de9248
MH
579int hci_conn_del(struct hci_conn *conn);
580void hci_conn_hash_flush(struct hci_dev *hdev);
581void hci_conn_check_pending(struct hci_dev *hdev);
20714bfe 582void hci_conn_accept(struct hci_conn *conn, int mask);
1da177e4 583
73d80deb 584struct hci_chan *hci_chan_create(struct hci_conn *conn);
9472007c 585void hci_chan_del(struct hci_chan *chan);
2c33c06a 586void hci_chan_list_flush(struct hci_conn *conn);
42c4e53e 587struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
73d80deb 588
5a9d0a3f 589struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
b12f62cf 590 __u8 dst_type, __u8 sec_level, __u8 auth_type);
e7c29cb1 591int hci_conn_check_link_mode(struct hci_conn *conn);
b3b1b061 592int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
0684e5f9 593int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
1da177e4 594int hci_conn_change_link_key(struct hci_conn *conn);
8c1b2355 595int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
1da177e4 596
14b12d0b 597void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
1da177e4 598
9eba32b8
MH
599void hci_conn_hold_device(struct hci_conn *conn);
600void hci_conn_put_device(struct hci_conn *conn);
601
1da177e4
LT
602static inline void hci_conn_hold(struct hci_conn *conn)
603{
71becf0c 604 BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
38b3fef1 605
1da177e4 606 atomic_inc(&conn->refcnt);
2f304d1e 607 cancel_delayed_work(&conn->disc_work);
1da177e4
LT
608}
609
610static inline void hci_conn_put(struct hci_conn *conn)
611{
71becf0c 612 BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
38b3fef1 613
1da177e4 614 if (atomic_dec_and_test(&conn->refcnt)) {
04837f64 615 unsigned long timeo;
716e4ab5
AE
616
617 switch (conn->type) {
618 case ACL_LINK:
619 case LE_LINK:
04837f64 620 del_timer(&conn->idle_timer);
6ac59344 621 if (conn->state == BT_CONNECTED) {
5f246e89 622 timeo = conn->disc_timeout;
6ac59344 623 if (!conn->out)
052b30b0 624 timeo *= 2;
5a9d0a3f 625 } else {
6ac59344 626 timeo = msecs_to_jiffies(10);
5a9d0a3f 627 }
716e4ab5
AE
628 break;
629
630 case AMP_LINK:
631 timeo = conn->disc_timeout;
632 break;
633
634 default:
04837f64 635 timeo = msecs_to_jiffies(10);
716e4ab5 636 break;
5a9d0a3f 637 }
716e4ab5 638
2f304d1e 639 cancel_delayed_work(&conn->disc_work);
19c40e3b 640 queue_delayed_work(conn->hdev->workqueue,
716e4ab5 641 &conn->disc_work, timeo);
1da177e4
LT
642 }
643}
644
1da177e4 645/* ----- HCI Devices ----- */
dc946bd8 646static inline void hci_dev_put(struct hci_dev *d)
1da177e4 647{
376261ae
AE
648 BT_DBG("%s orig refcnt %d", d->name,
649 atomic_read(&d->dev.kobj.kref.refcount));
650
4c724c71 651 put_device(&d->dev);
1da177e4
LT
652}
653
dc946bd8 654static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
1da177e4 655{
376261ae
AE
656 BT_DBG("%s orig refcnt %d", d->name,
657 atomic_read(&d->dev.kobj.kref.refcount));
658
4c724c71 659 get_device(&d->dev);
1da177e4
LT
660 return d;
661}
662
09fd0de5
GP
663#define hci_dev_lock(d) mutex_lock(&d->lock)
664#define hci_dev_unlock(d) mutex_unlock(&d->lock)
1da177e4 665
aa2b86d7 666#define to_hci_dev(d) container_of(d, struct hci_dev, dev)
3dc07322 667#define to_hci_conn(c) container_of(c, struct hci_conn, dev)
aa2b86d7 668
155961e8
DH
669static inline void *hci_get_drvdata(struct hci_dev *hdev)
670{
671 return dev_get_drvdata(&hdev->dev);
672}
673
674static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
675{
676 dev_set_drvdata(&hdev->dev, data);
677}
678
8598d064
AE
679/* hci_dev_list shall be locked */
680static inline uint8_t __hci_num_ctrl(void)
681{
682 uint8_t count = 0;
683 struct list_head *p;
684
685 list_for_each(p, &hci_dev_list) {
686 count++;
687 }
688
689 return count;
690}
691
1da177e4 692struct hci_dev *hci_dev_get(int index);
0c0afedf 693struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src);
1da177e4
LT
694
695struct hci_dev *hci_alloc_dev(void);
696void hci_free_dev(struct hci_dev *hdev);
697int hci_register_dev(struct hci_dev *hdev);
59735631 698void hci_unregister_dev(struct hci_dev *hdev);
1da177e4
LT
699int hci_suspend_dev(struct hci_dev *hdev);
700int hci_resume_dev(struct hci_dev *hdev);
701int hci_dev_open(__u16 dev);
702int hci_dev_close(__u16 dev);
703int hci_dev_reset(__u16 dev);
704int hci_dev_reset_stat(__u16 dev);
705int hci_dev_cmd(unsigned int cmd, void __user *arg);
706int hci_get_dev_list(void __user *arg);
707int hci_get_dev_info(void __user *arg);
708int hci_get_conn_list(void __user *arg);
709int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
40be492f 710int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
1da177e4
LT
711int hci_inquiry(void __user *arg);
712
c3c7ea65
GP
713struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev,
714 bdaddr_t *bdaddr);
f0358568 715int hci_blacklist_clear(struct hci_dev *hdev);
88c1fe4b
JH
716int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
717int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
f0358568 718
2aeb9a1a
JH
719int hci_uuids_clear(struct hci_dev *hdev);
720
55ed8ca1
JH
721int hci_link_keys_clear(struct hci_dev *hdev);
722struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
d25e28ab 723int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
04124681 724 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
c9839a11
VCG
725struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
726int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
9a006657
AE
727 int new_key, u8 authenticated, u8 tk[16], u8 enc_size,
728 __le16 ediv, u8 rand[8]);
c9839a11 729struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 730 u8 addr_type);
b899efaf 731int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr);
b899efaf 732int hci_smp_ltks_clear(struct hci_dev *hdev);
55ed8ca1
JH
733int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
734
2763eda6
SJ
735int hci_remote_oob_data_clear(struct hci_dev *hdev);
736struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
737 bdaddr_t *bdaddr);
738int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
739 u8 *randomizer);
740int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
741
3f0f524b
JH
742int hci_update_ad(struct hci_dev *hdev);
743
1da177e4
LT
744void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
745
76bca880 746int hci_recv_frame(struct sk_buff *skb);
ef222013 747int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
99811510 748int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
ef222013 749
0ac7e700 750void hci_init_sysfs(struct hci_dev *hdev);
ce242970
DH
751int hci_add_sysfs(struct hci_dev *hdev);
752void hci_del_sysfs(struct hci_dev *hdev);
a67e899c 753void hci_conn_init_sysfs(struct hci_conn *conn);
b219e3ac
MH
754void hci_conn_add_sysfs(struct hci_conn *conn);
755void hci_conn_del_sysfs(struct hci_conn *conn);
1da177e4 756
6935e0f5 757#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
1da177e4
LT
758
759/* ----- LMP capabilities ----- */
04837f64 760#define lmp_encrypt_capable(dev) ((dev)->features[0] & LMP_ENCRYPT)
761f09e4
JH
761#define lmp_rswitch_capable(dev) ((dev)->features[0] & LMP_RSWITCH)
762#define lmp_hold_capable(dev) ((dev)->features[0] & LMP_HOLD)
04837f64 763#define lmp_sniff_capable(dev) ((dev)->features[0] & LMP_SNIFF)
761f09e4
JH
764#define lmp_park_capable(dev) ((dev)->features[1] & LMP_PARK)
765#define lmp_inq_rssi_capable(dev) ((dev)->features[3] & LMP_RSSI_INQ)
5b7f9909 766#define lmp_esco_capable(dev) ((dev)->features[3] & LMP_ESCO)
761f09e4
JH
767#define lmp_bredr_capable(dev) (!((dev)->features[4] & LMP_NO_BREDR))
768#define lmp_le_capable(dev) ((dev)->features[4] & LMP_LE)
769#define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR)
770#define lmp_pause_enc_capable(dev) ((dev)->features[5] & LMP_PAUSE_ENC)
771#define lmp_ext_inq_capable(dev) ((dev)->features[6] & LMP_EXT_INQ)
ffa88e02 772#define lmp_le_br_capable(dev) !!((dev)->features[6] & LMP_SIMUL_LE_BR)
769be974 773#define lmp_ssp_capable(dev) ((dev)->features[6] & LMP_SIMPLE_PAIR)
e702112f 774#define lmp_no_flush_capable(dev) ((dev)->features[6] & LMP_NO_FLUSH)
761f09e4
JH
775#define lmp_lsto_capable(dev) ((dev)->features[7] & LMP_LSTO)
776#define lmp_inq_tx_pwr_capable(dev) ((dev)->features[7] & LMP_INQ_TX_PWR)
777#define lmp_ext_feat_capable(dev) ((dev)->features[7] & LMP_EXTFEATURES)
1da177e4 778
eead27da 779/* ----- Extended LMP capabilities ----- */
6b4b73ee 780#define lmp_host_ssp_capable(dev) ((dev)->host_features[0] & LMP_HOST_SSP)
ffa88e02
GP
781#define lmp_host_le_capable(dev) !!((dev)->host_features[0] & LMP_HOST_LE)
782#define lmp_host_le_br_capable(dev) !!((dev)->host_features[0] & LMP_HOST_LE_BREDR)
eead27da 783
5d05416e
AE
784/* returns true if at least one AMP active */
785static inline bool hci_amp_capable(void)
786{
787 struct hci_dev *hdev;
788 bool ret = false;
789
790 read_lock(&hci_dev_list_lock);
791 list_for_each_entry(hdev, &hci_dev_list, list)
792 if (hdev->amp_type == HCI_AMP &&
793 test_bit(HCI_UP, &hdev->flags))
794 ret = true;
795 read_unlock(&hci_dev_list_lock);
796
797 return ret;
798}
799
1da177e4 800/* ----- HCI protocols ----- */
20714bfe
FD
801#define HCI_PROTO_DEFER 0x01
802
5a9d0a3f 803static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
20714bfe 804 __u8 type, __u8 *flags)
1da177e4 805{
686ebf28
UF
806 switch (type) {
807 case ACL_LINK:
808 return l2cap_connect_ind(hdev, bdaddr);
1da177e4 809
686ebf28
UF
810 case SCO_LINK:
811 case ESCO_LINK:
20714bfe 812 return sco_connect_ind(hdev, bdaddr, flags);
1da177e4 813
686ebf28
UF
814 default:
815 BT_ERR("unknown link type %d", type);
816 return -EINVAL;
817 }
1da177e4
LT
818}
819
820static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
821{
686ebf28
UF
822 switch (conn->type) {
823 case ACL_LINK:
824 case LE_LINK:
825 l2cap_connect_cfm(conn, status);
826 break;
1da177e4 827
686ebf28
UF
828 case SCO_LINK:
829 case ESCO_LINK:
830 sco_connect_cfm(conn, status);
831 break;
1da177e4 832
686ebf28
UF
833 default:
834 BT_ERR("unknown link type %d", conn->type);
835 break;
836 }
e9a416b5
JH
837
838 if (conn->connect_cfm_cb)
839 conn->connect_cfm_cb(conn, status);
1da177e4
LT
840}
841
2950f21a 842static inline int hci_proto_disconn_ind(struct hci_conn *conn)
1da177e4 843{
686ebf28
UF
844 if (conn->type != ACL_LINK && conn->type != LE_LINK)
845 return HCI_ERROR_REMOTE_USER_TERM;
1da177e4 846
686ebf28 847 return l2cap_disconn_ind(conn);
2950f21a
MH
848}
849
850static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
851{
686ebf28
UF
852 switch (conn->type) {
853 case ACL_LINK:
854 case LE_LINK:
855 l2cap_disconn_cfm(conn, reason);
856 break;
2950f21a 857
686ebf28
UF
858 case SCO_LINK:
859 case ESCO_LINK:
860 sco_disconn_cfm(conn, reason);
861 break;
2950f21a 862
bd1eb66b
AE
863 /* L2CAP would be handled for BREDR chan */
864 case AMP_LINK:
865 break;
866
686ebf28
UF
867 default:
868 BT_ERR("unknown link type %d", conn->type);
869 break;
870 }
e9a416b5
JH
871
872 if (conn->disconn_cfm_cb)
873 conn->disconn_cfm_cb(conn, reason);
1da177e4
LT
874}
875
876static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
877{
8c1b2355
MH
878 __u8 encrypt;
879
686ebf28
UF
880 if (conn->type != ACL_LINK && conn->type != LE_LINK)
881 return;
882
51a8efd7 883 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
8c1b2355
MH
884 return;
885
886 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
686ebf28 887 l2cap_security_cfm(conn, status, encrypt);
e9a416b5
JH
888
889 if (conn->security_cfm_cb)
890 conn->security_cfm_cb(conn, status);
1da177e4
LT
891}
892
5a9d0a3f
WR
893static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
894 __u8 encrypt)
1da177e4 895{
686ebf28
UF
896 if (conn->type != ACL_LINK && conn->type != LE_LINK)
897 return;
1da177e4 898
686ebf28 899 l2cap_security_cfm(conn, status, encrypt);
e9a416b5
JH
900
901 if (conn->security_cfm_cb)
902 conn->security_cfm_cb(conn, status);
1da177e4
LT
903}
904
1da177e4
LT
905/* ----- HCI callbacks ----- */
906struct hci_cb {
907 struct list_head list;
908
909 char *name;
910
5a9d0a3f
WR
911 void (*security_cfm) (struct hci_conn *conn, __u8 status,
912 __u8 encrypt);
1da177e4
LT
913 void (*key_change_cfm) (struct hci_conn *conn, __u8 status);
914 void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role);
915};
916
917static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
918{
711584ea 919 struct hci_cb *cb;
8c1b2355 920 __u8 encrypt;
1da177e4
LT
921
922 hci_proto_auth_cfm(conn, status);
923
51a8efd7 924 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
8c1b2355
MH
925 return;
926
927 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
928
f20d09d5 929 read_lock(&hci_cb_list_lock);
711584ea 930 list_for_each_entry(cb, &hci_cb_list, list) {
8c1b2355
MH
931 if (cb->security_cfm)
932 cb->security_cfm(conn, status, encrypt);
1da177e4 933 }
f20d09d5 934 read_unlock(&hci_cb_list_lock);
1da177e4
LT
935}
936
5a9d0a3f
WR
937static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
938 __u8 encrypt)
1da177e4 939{
711584ea 940 struct hci_cb *cb;
1da177e4 941
435fef20
MH
942 if (conn->sec_level == BT_SECURITY_SDP)
943 conn->sec_level = BT_SECURITY_LOW;
944
88167aed
VCG
945 if (conn->pending_sec_level > conn->sec_level)
946 conn->sec_level = conn->pending_sec_level;
947
9719f8af 948 hci_proto_encrypt_cfm(conn, status, encrypt);
1da177e4 949
f20d09d5 950 read_lock(&hci_cb_list_lock);
711584ea 951 list_for_each_entry(cb, &hci_cb_list, list) {
8c1b2355
MH
952 if (cb->security_cfm)
953 cb->security_cfm(conn, status, encrypt);
1da177e4 954 }
f20d09d5 955 read_unlock(&hci_cb_list_lock);
1da177e4
LT
956}
957
958static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
959{
711584ea 960 struct hci_cb *cb;
1da177e4 961
f20d09d5 962 read_lock(&hci_cb_list_lock);
711584ea 963 list_for_each_entry(cb, &hci_cb_list, list) {
1da177e4
LT
964 if (cb->key_change_cfm)
965 cb->key_change_cfm(conn, status);
966 }
f20d09d5 967 read_unlock(&hci_cb_list_lock);
1da177e4
LT
968}
969
5a9d0a3f
WR
970static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
971 __u8 role)
1da177e4 972{
711584ea 973 struct hci_cb *cb;
1da177e4 974
f20d09d5 975 read_lock(&hci_cb_list_lock);
711584ea 976 list_for_each_entry(cb, &hci_cb_list, list) {
1da177e4
LT
977 if (cb->role_switch_cfm)
978 cb->role_switch_cfm(conn, status, role);
979 }
f20d09d5 980 read_unlock(&hci_cb_list_lock);
1da177e4
LT
981}
982
6759a675
JH
983static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
984{
84d9d071 985 size_t parsed = 0;
6759a675 986
6c0c331e
JH
987 if (data_len < 2)
988 return false;
989
84d9d071
JH
990 while (parsed < data_len - 1) {
991 u8 field_len = data[0];
6759a675
JH
992
993 if (field_len == 0)
994 break;
995
996 parsed += field_len + 1;
997
998 if (parsed > data_len)
999 break;
1000
1001 if (data[1] == type)
1002 return true;
1003
1004 data += field_len + 1;
1005 }
1006
1007 return false;
1008}
1009
9d939d94
VA
1010static inline size_t eir_get_length(u8 *eir, size_t eir_len)
1011{
1012 size_t parsed = 0;
1013
1014 while (parsed < eir_len) {
1015 u8 field_len = eir[0];
1016
1017 if (field_len == 0)
1018 return parsed;
1019
1020 parsed += field_len + 1;
1021 eir += field_len + 1;
1022 }
1023
1024 return eir_len;
1025}
1026
1dc06093 1027static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
04124681 1028 u8 data_len)
1dc06093
JH
1029{
1030 eir[eir_len++] = sizeof(type) + data_len;
1031 eir[eir_len++] = type;
1032 memcpy(&eir[eir_len], data, data_len);
1033 eir_len += data_len;
1034
1035 return eir_len;
1036}
1037
1da177e4
LT
1038int hci_register_cb(struct hci_cb *hcb);
1039int hci_unregister_cb(struct hci_cb *hcb);
1040
a9de9248 1041int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
73d80deb 1042void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
0d861d8b 1043void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
1da177e4 1044
a9de9248 1045void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
1da177e4 1046
1da177e4 1047/* ----- HCI Sockets ----- */
470fe1b5
MH
1048void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
1049void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk);
cd82e61c 1050void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
1da177e4 1051
040030ef
MH
1052void hci_sock_dev_event(struct hci_dev *hdev, int event);
1053
0381101f 1054/* Management interface */
591f47f3
AG
1055#define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR))
1056#define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \
1057 BIT(BDADDR_LE_RANDOM))
1058#define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \
1059 BIT(BDADDR_LE_PUBLIC) | \
1060 BIT(BDADDR_LE_RANDOM))
f39799f5 1061
0381101f 1062int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
744cf19e
JH
1063int mgmt_index_added(struct hci_dev *hdev);
1064int mgmt_index_removed(struct hci_dev *hdev);
1065int mgmt_powered(struct hci_dev *hdev, u8 powered);
1066int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
1067int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
1068int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
1069int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
745c0ce3 1070 bool persistent);
afc747a6 1071int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
04124681
GP
1072 u8 addr_type, u32 flags, u8 *name, u8 name_len,
1073 u8 *dev_class);
afc747a6 1074int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
f0d6a0ea 1075 u8 link_type, u8 addr_type, u8 reason);
88c3df13 1076int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1077 u8 link_type, u8 addr_type, u8 status);
48264f06 1078int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
04124681 1079 u8 addr_type, u8 status);
744cf19e
JH
1080int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
1081int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1082 u8 status);
744cf19e 1083int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1084 u8 status);
744cf19e 1085int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681
GP
1086 u8 link_type, u8 addr_type, __le32 value,
1087 u8 confirm_hint);
744cf19e 1088int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1089 u8 link_type, u8 addr_type, u8 status);
272d90df 1090int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1091 u8 link_type, u8 addr_type, u8 status);
272d90df 1092int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1093 u8 link_type, u8 addr_type);
604086b7 1094int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1095 u8 link_type, u8 addr_type, u8 status);
272d90df 1096int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
04124681 1097 u8 link_type, u8 addr_type, u8 status);
92a25256
JH
1098int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
1099 u8 link_type, u8 addr_type, u32 passkey,
1100 u8 entered);
bab73cb6 1101int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
04124681 1102 u8 addr_type, u8 status);
33ef95ed 1103int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
c0ecddc2 1104int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
7f9a903c 1105int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
04124681 1106 u8 status);
744cf19e
JH
1107int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
1108int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
04124681 1109 u8 *randomizer, u8 status);
06199cf8 1110int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
48264f06 1111int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
04124681
GP
1112 u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
1113 u8 ssp, u8 *eir, u16 eir_len);
b644ba33 1114int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
04124681 1115 u8 addr_type, s8 rssi, u8 *name, u8 name_len);
7a135109 1116int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status);
e6d465cb 1117int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status);
744cf19e 1118int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
5e0452c0 1119int mgmt_interleaved_discovery(struct hci_dev *hdev);
88c1fe4b
JH
1120int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
1121int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
bb4b2a9a 1122bool mgmt_valid_hdev(struct hci_dev *hdev);
346af67b
VCG
1123int mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent);
1124
1da177e4
LT
1125/* HCI info for socket */
1126#define hci_pi(sk) ((struct hci_pinfo *) sk)
1127
1128struct hci_pinfo {
1129 struct bt_sock bt;
1130 struct hci_dev *hdev;
1131 struct hci_filter filter;
1132 __u32 cmsg_mask;
c02178d2 1133 unsigned short channel;
1da177e4
LT
1134};
1135
1136/* HCI security filter */
1137#define HCI_SFLT_MAX_OGF 5
1138
1139struct hci_sec_filter {
1140 __u32 type_mask;
1141 __u32 event_mask[2];
1142 __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4];
1143};
1144
1145/* ----- HCI requests ----- */
1146#define HCI_REQ_DONE 0
1147#define HCI_REQ_PEND 1
1148#define HCI_REQ_CANCELED 2
1149
a6a67efd
TG
1150#define hci_req_lock(d) mutex_lock(&d->req_lock)
1151#define hci_req_unlock(d) mutex_unlock(&d->req_lock)
1da177e4 1152
23bb5763 1153void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);
1da177e4 1154
2ce603eb
CT
1155void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
1156 u16 latency, u16 to_multiplier);
a7a595f6
VCG
1157void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
1158 __u8 ltk[16]);
2519a1fc 1159int hci_do_inquiry(struct hci_dev *hdev, u8 length);
023d5049 1160int hci_cancel_inquiry(struct hci_dev *hdev);
28b75a89 1161int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
04124681 1162 int timeout);
7dbfac1d 1163int hci_cancel_le_scan(struct hci_dev *hdev);
2519a1fc 1164
31f7956c
AG
1165u8 bdaddr_to_le(u8 bdaddr_type);
1166
1da177e4 1167#endif /* __HCI_CORE_H */