]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/bluetooth/hci_core.h
Bluetooth: Fix hidp_get_connection()
[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
a6b7a407 28#include <linux/interrupt.h>
1da177e4
LT
29#include <net/bluetooth/hci.h>
30
31/* HCI upper protocols */
32#define HCI_PROTO_L2CAP 0
33#define HCI_PROTO_SCO 1
34
5e59b791
LAD
35/* HCI priority */
36#define HCI_PRIO_MAX 7
37
1da177e4 38/* HCI Core structures */
1da177e4
LT
39struct inquiry_data {
40 bdaddr_t bdaddr;
41 __u8 pscan_rep_mode;
42 __u8 pscan_period_mode;
43 __u8 pscan_mode;
44 __u8 dev_class[3];
1ebb9252 45 __le16 clock_offset;
1da177e4 46 __s8 rssi;
41a96212 47 __u8 ssp_mode;
1da177e4
LT
48};
49
50struct inquiry_entry {
70f23020 51 struct inquiry_entry *next;
1da177e4
LT
52 __u32 timestamp;
53 struct inquiry_data data;
54};
55
56struct inquiry_cache {
70f23020 57 spinlock_t lock;
1da177e4 58 __u32 timestamp;
70f23020 59 struct inquiry_entry *list;
1da177e4
LT
60};
61
62struct hci_conn_hash {
63 struct list_head list;
64 spinlock_t lock;
65 unsigned int acl_num;
66 unsigned int sco_num;
fcd89c09 67 unsigned int le_num;
1da177e4
LT
68};
69
f0358568
JH
70struct bdaddr_list {
71 struct list_head list;
72 bdaddr_t bdaddr;
73};
2aeb9a1a
JH
74
75struct bt_uuid {
76 struct list_head list;
77 u8 uuid[16];
1aff6f09 78 u8 svc_hint;
2aeb9a1a
JH
79};
80
34918cd7
VCG
81struct key_master_id {
82 __le16 ediv;
83 u8 rand[8];
84} __packed;
85
86struct link_key_data {
87 bdaddr_t bdaddr;
88 u8 type;
89 u8 val[16];
90 u8 pin_len;
91 u8 dlen;
92 u8 data[0];
93} __packed;
94
55ed8ca1
JH
95struct link_key {
96 struct list_head list;
97 bdaddr_t bdaddr;
98 u8 type;
99 u8 val[16];
100 u8 pin_len;
34918cd7
VCG
101 u8 dlen;
102 u8 data[0];
55ed8ca1
JH
103};
104
2763eda6
SJ
105struct oob_data {
106 struct list_head list;
107 bdaddr_t bdaddr;
108 u8 hash[16];
109 u8 randomizer[16];
110};
111
76c8686f
AG
112struct adv_entry {
113 struct list_head list;
114 bdaddr_t bdaddr;
115 u8 bdaddr_type;
116};
117
cd4c5391 118#define NUM_REASSEMBLY 4
1da177e4
LT
119struct hci_dev {
120 struct list_head list;
121 spinlock_t lock;
122 atomic_t refcnt;
123
124 char name[8];
125 unsigned long flags;
126 __u16 id;
c13854ce 127 __u8 bus;
943da25d 128 __u8 dev_type;
1da177e4 129 bdaddr_t bdaddr;
1f6c6378 130 __u8 dev_name[HCI_MAX_NAME_LENGTH];
80a1e1db 131 __u8 eir[HCI_MAX_EIR_LENGTH];
a9de9248 132 __u8 dev_class[3];
1aff6f09
JH
133 __u8 major_class;
134 __u8 minor_class;
1da177e4 135 __u8 features[8];
971e3a4b 136 __u8 extfeatures[8];
a9de9248 137 __u8 commands[64];
333140b5 138 __u8 ssp_mode;
1143e5a6
MH
139 __u8 hci_ver;
140 __u16 hci_rev;
d5859e22 141 __u8 lmp_ver;
1143e5a6 142 __u16 manufacturer;
d5859e22 143 __le16 lmp_subver;
1da177e4 144 __u16 voice_setting;
17fa4b9d 145 __u8 io_capability;
1da177e4
LT
146
147 __u16 pkt_type;
5b7f9909 148 __u16 esco_type;
1da177e4
LT
149 __u16 link_policy;
150 __u16 link_mode;
151
04837f64
MH
152 __u32 idle_timeout;
153 __u16 sniff_min_interval;
154 __u16 sniff_max_interval;
155
928abaa7
AE
156 __u8 amp_status;
157 __u32 amp_total_bw;
158 __u32 amp_max_bw;
159 __u32 amp_min_latency;
160 __u32 amp_max_pdu;
161 __u8 amp_type;
162 __u16 amp_pal_cap;
163 __u16 amp_assoc_size;
164 __u32 amp_max_flush_to;
165 __u32 amp_be_flush_to;
166
9f61656a
JH
167 unsigned int auto_accept_delay;
168
1da177e4
LT
169 unsigned long quirks;
170
171 atomic_t cmd_cnt;
172 unsigned int acl_cnt;
173 unsigned int sco_cnt;
6ed58ec5 174 unsigned int le_cnt;
1da177e4
LT
175
176 unsigned int acl_mtu;
177 unsigned int sco_mtu;
6ed58ec5 178 unsigned int le_mtu;
1da177e4
LT
179 unsigned int acl_pkts;
180 unsigned int sco_pkts;
6ed58ec5 181 unsigned int le_pkts;
1da177e4 182
1da177e4
LT
183 unsigned long acl_last_tx;
184 unsigned long sco_last_tx;
6ed58ec5 185 unsigned long le_last_tx;
1da177e4 186
f48fd9c8
MH
187 struct workqueue_struct *workqueue;
188
ab81cbf9
JH
189 struct work_struct power_on;
190 struct work_struct power_off;
191 struct timer_list off_timer;
192
6bd32326 193 struct timer_list cmd_timer;
1da177e4
LT
194 struct tasklet_struct cmd_task;
195 struct tasklet_struct rx_task;
196 struct tasklet_struct tx_task;
197
198 struct sk_buff_head rx_q;
199 struct sk_buff_head raw_q;
200 struct sk_buff_head cmd_q;
201
202 struct sk_buff *sent_cmd;
cd4c5391 203 struct sk_buff *reassembly[NUM_REASSEMBLY];
1da177e4 204
a6a67efd 205 struct mutex req_lock;
1da177e4
LT
206 wait_queue_head_t req_wait_q;
207 __u32 req_status;
208 __u32 req_result;
a5040efa
JH
209
210 __u16 init_last_cmd;
1da177e4
LT
211
212 struct inquiry_cache inq_cache;
213 struct hci_conn_hash conn_hash;
ea4bd8ba 214 struct list_head blacklist;
1da177e4 215
2aeb9a1a
JH
216 struct list_head uuids;
217
55ed8ca1
JH
218 struct list_head link_keys;
219
2763eda6
SJ
220 struct list_head remote_oob_data;
221
76c8686f 222 struct list_head adv_entries;
35815085 223 struct timer_list adv_timer;
76c8686f 224
1da177e4
LT
225 struct hci_dev_stats stat;
226
227 struct sk_buff_head driver_init;
228
229 void *driver_data;
230 void *core_data;
231
70f23020 232 atomic_t promisc;
1da177e4 233
ca325f69
MH
234 struct dentry *debugfs;
235
a91f2e39
MH
236 struct device *parent;
237 struct device dev;
1da177e4 238
611b30f7
MH
239 struct rfkill *rfkill;
240
70f23020 241 struct module *owner;
1da177e4
LT
242
243 int (*open)(struct hci_dev *hdev);
244 int (*close)(struct hci_dev *hdev);
245 int (*flush)(struct hci_dev *hdev);
246 int (*send)(struct sk_buff *skb);
247 void (*destruct)(struct hci_dev *hdev);
248 void (*notify)(struct hci_dev *hdev, unsigned int evt);
249 int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
250};
251
252struct hci_conn {
253 struct list_head list;
254
adc4266d 255 atomic_t refcnt;
adc4266d
SJ
256
257 bdaddr_t dst;
5a9d0a3f 258 __u8 dst_type;
adc4266d
SJ
259 __u16 handle;
260 __u16 state;
261 __u8 mode;
262 __u8 type;
263 __u8 out;
264 __u8 attempt;
265 __u8 dev_class[3];
266 __u8 features[8];
267 __u8 ssp_mode;
268 __u16 interval;
269 __u16 pkt_type;
270 __u16 link_policy;
271 __u32 link_mode;
13d39315 272 __u8 key_type;
adc4266d
SJ
273 __u8 auth_type;
274 __u8 sec_level;
275 __u8 pending_sec_level;
276 __u8 pin_length;
726b4ffc 277 __u8 enc_key_size;
adc4266d
SJ
278 __u8 io_capability;
279 __u8 power_save;
280 __u16 disc_timeout;
281 unsigned long pend;
04837f64 282
03b555e1
JH
283 __u8 remote_cap;
284 __u8 remote_oob;
285 __u8 remote_auth;
286
adc4266d 287 unsigned int sent;
04837f64 288
1da177e4
LT
289 struct sk_buff_head data_q;
290
04837f64
MH
291 struct timer_list disc_timer;
292 struct timer_list idle_timer;
9f61656a 293 struct timer_list auto_accept_timer;
04837f64 294
f3784d83
RQ
295 struct work_struct work_add;
296 struct work_struct work_del;
b219e3ac
MH
297
298 struct device dev;
9eba32b8 299 atomic_t devref;
b219e3ac 300
1da177e4
LT
301 struct hci_dev *hdev;
302 void *l2cap_data;
303 void *sco_data;
1da177e4
LT
304
305 struct hci_conn *link;
e9a416b5
JH
306
307 void (*connect_cfm_cb) (struct hci_conn *conn, u8 status);
308 void (*security_cfm_cb) (struct hci_conn *conn, u8 status);
309 void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason);
1da177e4
LT
310};
311
312extern struct hci_proto *hci_proto[];
313extern struct list_head hci_dev_list;
314extern struct list_head hci_cb_list;
315extern rwlock_t hci_dev_list_lock;
316extern rwlock_t hci_cb_list_lock;
317
318/* ----- Inquiry cache ----- */
70f23020
AE
319#define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */
320#define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */
1da177e4
LT
321
322#define inquiry_cache_lock(c) spin_lock(&c->lock)
323#define inquiry_cache_unlock(c) spin_unlock(&c->lock)
324#define inquiry_cache_lock_bh(c) spin_lock_bh(&c->lock)
325#define inquiry_cache_unlock_bh(c) spin_unlock_bh(&c->lock)
326
327static inline void inquiry_cache_init(struct hci_dev *hdev)
328{
329 struct inquiry_cache *c = &hdev->inq_cache;
330 spin_lock_init(&c->lock);
331 c->list = NULL;
332}
333
334static inline int inquiry_cache_empty(struct hci_dev *hdev)
335{
336 struct inquiry_cache *c = &hdev->inq_cache;
a02cec21 337 return c->list == NULL;
1da177e4
LT
338}
339
340static inline long inquiry_cache_age(struct hci_dev *hdev)
341{
342 struct inquiry_cache *c = &hdev->inq_cache;
343 return jiffies - c->timestamp;
344}
345
346static inline long inquiry_entry_age(struct inquiry_entry *e)
347{
348 return jiffies - e->timestamp;
349}
350
5a9d0a3f
WR
351struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
352 bdaddr_t *bdaddr);
1da177e4
LT
353void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data);
354
355/* ----- HCI Connections ----- */
356enum {
357 HCI_CONN_AUTH_PEND,
19f8def0 358 HCI_CONN_REAUTH_PEND,
1da177e4 359 HCI_CONN_ENCRYPT_PEND,
04837f64
MH
360 HCI_CONN_RSWITCH_PEND,
361 HCI_CONN_MODE_CHANGE_PEND,
e73439d8 362 HCI_CONN_SCO_SETUP_PEND,
d26a2345 363 HCI_CONN_LE_SMP_PEND,
1da177e4
LT
364};
365
366static inline void hci_conn_hash_init(struct hci_dev *hdev)
367{
368 struct hci_conn_hash *h = &hdev->conn_hash;
369 INIT_LIST_HEAD(&h->list);
370 spin_lock_init(&h->lock);
371 h->acl_num = 0;
372 h->sco_num = 0;
373}
374
375static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
376{
377 struct hci_conn_hash *h = &hdev->conn_hash;
378 list_add(&c->list, &h->list);
fcd89c09
VT
379 switch (c->type) {
380 case ACL_LINK:
1da177e4 381 h->acl_num++;
fcd89c09
VT
382 break;
383 case LE_LINK:
384 h->le_num++;
385 break;
386 case SCO_LINK:
387 case ESCO_LINK:
1da177e4 388 h->sco_num++;
fcd89c09
VT
389 break;
390 }
1da177e4
LT
391}
392
393static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
394{
395 struct hci_conn_hash *h = &hdev->conn_hash;
396 list_del(&c->list);
fcd89c09
VT
397 switch (c->type) {
398 case ACL_LINK:
1da177e4 399 h->acl_num--;
fcd89c09
VT
400 break;
401 case LE_LINK:
402 h->le_num--;
403 break;
404 case SCO_LINK:
405 case ESCO_LINK:
1da177e4 406 h->sco_num--;
fcd89c09
VT
407 break;
408 }
1da177e4
LT
409}
410
52087a79
LAD
411static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
412{
413 struct hci_conn_hash *h = &hdev->conn_hash;
414 switch (type) {
415 case ACL_LINK:
416 return h->acl_num;
417 case LE_LINK:
418 return h->le_num;
419 case SCO_LINK:
420 case ESCO_LINK:
421 return h->sco_num;
422 default:
423 return 0;
424 }
425}
426
1da177e4 427static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
adc4266d 428 __u16 handle)
1da177e4
LT
429{
430 struct hci_conn_hash *h = &hdev->conn_hash;
431 struct list_head *p;
432 struct hci_conn *c;
433
434 list_for_each(p, &h->list) {
435 c = list_entry(p, struct hci_conn, list);
436 if (c->handle == handle)
437 return c;
438 }
439 return NULL;
440}
441
442static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
adc4266d 443 __u8 type, bdaddr_t *ba)
1da177e4
LT
444{
445 struct hci_conn_hash *h = &hdev->conn_hash;
446 struct list_head *p;
447 struct hci_conn *c;
448
449 list_for_each(p, &h->list) {
450 c = list_entry(p, struct hci_conn, list);
451 if (c->type == type && !bacmp(&c->dst, ba))
452 return c;
453 }
454 return NULL;
455}
456
4c67bc74 457static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
adc4266d 458 __u8 type, __u16 state)
4c67bc74
MH
459{
460 struct hci_conn_hash *h = &hdev->conn_hash;
461 struct list_head *p;
462 struct hci_conn *c;
463
464 list_for_each(p, &h->list) {
465 c = list_entry(p, struct hci_conn, list);
466 if (c->type == type && c->state == state)
467 return c;
468 }
469 return NULL;
470}
471
472void hci_acl_connect(struct hci_conn *conn);
1da177e4
LT
473void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
474void hci_add_sco(struct hci_conn *conn, __u16 handle);
b6a0dc82 475void hci_setup_sync(struct hci_conn *conn, __u16 handle);
e73439d8 476void hci_sco_setup(struct hci_conn *conn, __u8 status);
1da177e4
LT
477
478struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
a9de9248
MH
479int hci_conn_del(struct hci_conn *conn);
480void hci_conn_hash_flush(struct hci_dev *hdev);
481void hci_conn_check_pending(struct hci_dev *hdev);
1da177e4 482
5a9d0a3f
WR
483struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
484 __u8 sec_level, __u8 auth_type);
e7c29cb1 485int hci_conn_check_link_mode(struct hci_conn *conn);
b3b1b061 486int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
0684e5f9 487int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
1da177e4 488int hci_conn_change_link_key(struct hci_conn *conn);
8c1b2355 489int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
1da177e4 490
14b12d0b 491void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
04837f64 492void hci_conn_enter_sniff_mode(struct hci_conn *conn);
1da177e4 493
9eba32b8
MH
494void hci_conn_hold_device(struct hci_conn *conn);
495void hci_conn_put_device(struct hci_conn *conn);
496
1da177e4
LT
497static inline void hci_conn_hold(struct hci_conn *conn)
498{
499 atomic_inc(&conn->refcnt);
04837f64 500 del_timer(&conn->disc_timer);
1da177e4
LT
501}
502
503static inline void hci_conn_put(struct hci_conn *conn)
504{
505 if (atomic_dec_and_test(&conn->refcnt)) {
04837f64 506 unsigned long timeo;
454d48ff 507 if (conn->type == ACL_LINK || conn->type == LE_LINK) {
04837f64 508 del_timer(&conn->idle_timer);
6ac59344 509 if (conn->state == BT_CONNECTED) {
052b30b0 510 timeo = msecs_to_jiffies(conn->disc_timeout);
6ac59344 511 if (!conn->out)
052b30b0 512 timeo *= 2;
5a9d0a3f 513 } else {
6ac59344 514 timeo = msecs_to_jiffies(10);
5a9d0a3f
WR
515 }
516 } else {
04837f64 517 timeo = msecs_to_jiffies(10);
5a9d0a3f 518 }
04837f64 519 mod_timer(&conn->disc_timer, jiffies + timeo);
1da177e4
LT
520 }
521}
522
1da177e4
LT
523/* ----- HCI Devices ----- */
524static inline void __hci_dev_put(struct hci_dev *d)
525{
526 if (atomic_dec_and_test(&d->refcnt))
527 d->destruct(d);
528}
529
530static inline void hci_dev_put(struct hci_dev *d)
04fafe4e 531{
1da177e4
LT
532 __hci_dev_put(d);
533 module_put(d->owner);
534}
535
536static inline struct hci_dev *__hci_dev_hold(struct hci_dev *d)
537{
538 atomic_inc(&d->refcnt);
539 return d;
540}
541
542static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
543{
544 if (try_module_get(d->owner))
545 return __hci_dev_hold(d);
546 return NULL;
547}
548
549#define hci_dev_lock(d) spin_lock(&d->lock)
550#define hci_dev_unlock(d) spin_unlock(&d->lock)
551#define hci_dev_lock_bh(d) spin_lock_bh(&d->lock)
552#define hci_dev_unlock_bh(d) spin_unlock_bh(&d->lock)
553
554struct hci_dev *hci_dev_get(int index);
555struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);
556
557struct hci_dev *hci_alloc_dev(void);
558void hci_free_dev(struct hci_dev *hdev);
559int hci_register_dev(struct hci_dev *hdev);
59735631 560void hci_unregister_dev(struct hci_dev *hdev);
1da177e4
LT
561int hci_suspend_dev(struct hci_dev *hdev);
562int hci_resume_dev(struct hci_dev *hdev);
563int hci_dev_open(__u16 dev);
564int hci_dev_close(__u16 dev);
565int hci_dev_reset(__u16 dev);
566int hci_dev_reset_stat(__u16 dev);
567int hci_dev_cmd(unsigned int cmd, void __user *arg);
568int hci_get_dev_list(void __user *arg);
569int hci_get_dev_info(void __user *arg);
570int hci_get_conn_list(void __user *arg);
571int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
40be492f 572int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
1da177e4
LT
573int hci_inquiry(void __user *arg);
574
f0358568
JH
575struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
576int hci_blacklist_clear(struct hci_dev *hdev);
b2a66aad
AJ
577int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr);
578int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr);
f0358568 579
2aeb9a1a
JH
580int hci_uuids_clear(struct hci_dev *hdev);
581
55ed8ca1
JH
582int hci_link_keys_clear(struct hci_dev *hdev);
583struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
d25e28ab
JH
584int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
585 bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
75d262c2
VCG
586struct link_key *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
587struct link_key *hci_find_link_key_type(struct hci_dev *hdev,
588 bdaddr_t *bdaddr, u8 type);
589int hci_add_ltk(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr,
726b4ffc 590 u8 key_size, __le16 ediv, u8 rand[8], u8 ltk[16]);
55ed8ca1
JH
591int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
592
2763eda6
SJ
593int hci_remote_oob_data_clear(struct hci_dev *hdev);
594struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
595 bdaddr_t *bdaddr);
596int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
597 u8 *randomizer);
598int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
599
35815085 600#define ADV_CLEAR_TIMEOUT (3*60*HZ) /* Three minutes */
76c8686f
AG
601int hci_adv_entries_clear(struct hci_dev *hdev);
602struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr);
603int hci_add_adv_entry(struct hci_dev *hdev,
604 struct hci_ev_le_advertising_info *ev);
605
ab81cbf9
JH
606void hci_del_off_timer(struct hci_dev *hdev);
607
1da177e4
LT
608void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
609
76bca880 610int hci_recv_frame(struct sk_buff *skb);
ef222013 611int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
99811510 612int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
ef222013 613
0ac7e700 614void hci_init_sysfs(struct hci_dev *hdev);
ce242970
DH
615int hci_add_sysfs(struct hci_dev *hdev);
616void hci_del_sysfs(struct hci_dev *hdev);
a67e899c 617void hci_conn_init_sysfs(struct hci_conn *conn);
b219e3ac
MH
618void hci_conn_add_sysfs(struct hci_conn *conn);
619void hci_conn_del_sysfs(struct hci_conn *conn);
1da177e4 620
a91f2e39 621#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->parent = (pdev))
1da177e4
LT
622
623/* ----- LMP capabilities ----- */
04837f64
MH
624#define lmp_rswitch_capable(dev) ((dev)->features[0] & LMP_RSWITCH)
625#define lmp_encrypt_capable(dev) ((dev)->features[0] & LMP_ENCRYPT)
626#define lmp_sniff_capable(dev) ((dev)->features[0] & LMP_SNIFF)
627#define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR)
5b7f9909 628#define lmp_esco_capable(dev) ((dev)->features[3] & LMP_ESCO)
769be974 629#define lmp_ssp_capable(dev) ((dev)->features[6] & LMP_SIMPLE_PAIR)
e702112f 630#define lmp_no_flush_capable(dev) ((dev)->features[6] & LMP_NO_FLUSH)
6ed58ec5 631#define lmp_le_capable(dev) ((dev)->features[4] & LMP_LE)
1da177e4 632
eead27da
AG
633/* ----- Extended LMP capabilities ----- */
634#define lmp_host_le_capable(dev) ((dev)->extfeatures[0] & LMP_HOST_LE)
635
1da177e4
LT
636/* ----- HCI protocols ----- */
637struct hci_proto {
8c1b2355 638 char *name;
1da177e4
LT
639 unsigned int id;
640 unsigned long flags;
641
642 void *priv;
643
5a9d0a3f
WR
644 int (*connect_ind) (struct hci_dev *hdev, bdaddr_t *bdaddr,
645 __u8 type);
1da177e4 646 int (*connect_cfm) (struct hci_conn *conn, __u8 status);
2950f21a
MH
647 int (*disconn_ind) (struct hci_conn *conn);
648 int (*disconn_cfm) (struct hci_conn *conn, __u8 reason);
5a9d0a3f
WR
649 int (*recv_acldata) (struct hci_conn *conn, struct sk_buff *skb,
650 __u16 flags);
1da177e4 651 int (*recv_scodata) (struct hci_conn *conn, struct sk_buff *skb);
5a9d0a3f
WR
652 int (*security_cfm) (struct hci_conn *conn, __u8 status,
653 __u8 encrypt);
1da177e4
LT
654};
655
5a9d0a3f
WR
656static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
657 __u8 type)
1da177e4
LT
658{
659 register struct hci_proto *hp;
660 int mask = 0;
8c1b2355 661
1da177e4
LT
662 hp = hci_proto[HCI_PROTO_L2CAP];
663 if (hp && hp->connect_ind)
664 mask |= hp->connect_ind(hdev, bdaddr, type);
665
666 hp = hci_proto[HCI_PROTO_SCO];
667 if (hp && hp->connect_ind)
668 mask |= hp->connect_ind(hdev, bdaddr, type);
669
670 return mask;
671}
672
673static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
674{
675 register struct hci_proto *hp;
676
677 hp = hci_proto[HCI_PROTO_L2CAP];
678 if (hp && hp->connect_cfm)
679 hp->connect_cfm(conn, status);
680
681 hp = hci_proto[HCI_PROTO_SCO];
682 if (hp && hp->connect_cfm)
683 hp->connect_cfm(conn, status);
e9a416b5
JH
684
685 if (conn->connect_cfm_cb)
686 conn->connect_cfm_cb(conn, status);
1da177e4
LT
687}
688
2950f21a 689static inline int hci_proto_disconn_ind(struct hci_conn *conn)
1da177e4
LT
690{
691 register struct hci_proto *hp;
2950f21a 692 int reason = 0x13;
1da177e4
LT
693
694 hp = hci_proto[HCI_PROTO_L2CAP];
695 if (hp && hp->disconn_ind)
2950f21a 696 reason = hp->disconn_ind(conn);
1da177e4
LT
697
698 hp = hci_proto[HCI_PROTO_SCO];
699 if (hp && hp->disconn_ind)
2950f21a
MH
700 reason = hp->disconn_ind(conn);
701
702 return reason;
703}
704
705static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
706{
707 register struct hci_proto *hp;
708
709 hp = hci_proto[HCI_PROTO_L2CAP];
710 if (hp && hp->disconn_cfm)
711 hp->disconn_cfm(conn, reason);
712
713 hp = hci_proto[HCI_PROTO_SCO];
714 if (hp && hp->disconn_cfm)
715 hp->disconn_cfm(conn, reason);
e9a416b5
JH
716
717 if (conn->disconn_cfm_cb)
718 conn->disconn_cfm_cb(conn, reason);
1da177e4
LT
719}
720
721static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
722{
723 register struct hci_proto *hp;
8c1b2355
MH
724 __u8 encrypt;
725
726 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend))
727 return;
728
729 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
1da177e4
LT
730
731 hp = hci_proto[HCI_PROTO_L2CAP];
8c1b2355
MH
732 if (hp && hp->security_cfm)
733 hp->security_cfm(conn, status, encrypt);
1da177e4
LT
734
735 hp = hci_proto[HCI_PROTO_SCO];
8c1b2355
MH
736 if (hp && hp->security_cfm)
737 hp->security_cfm(conn, status, encrypt);
e9a416b5
JH
738
739 if (conn->security_cfm_cb)
740 conn->security_cfm_cb(conn, status);
1da177e4
LT
741}
742
5a9d0a3f
WR
743static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
744 __u8 encrypt)
1da177e4
LT
745{
746 register struct hci_proto *hp;
747
748 hp = hci_proto[HCI_PROTO_L2CAP];
8c1b2355
MH
749 if (hp && hp->security_cfm)
750 hp->security_cfm(conn, status, encrypt);
1da177e4
LT
751
752 hp = hci_proto[HCI_PROTO_SCO];
8c1b2355
MH
753 if (hp && hp->security_cfm)
754 hp->security_cfm(conn, status, encrypt);
e9a416b5
JH
755
756 if (conn->security_cfm_cb)
757 conn->security_cfm_cb(conn, status);
1da177e4
LT
758}
759
760int hci_register_proto(struct hci_proto *hproto);
761int hci_unregister_proto(struct hci_proto *hproto);
762
763/* ----- HCI callbacks ----- */
764struct hci_cb {
765 struct list_head list;
766
767 char *name;
768
5a9d0a3f
WR
769 void (*security_cfm) (struct hci_conn *conn, __u8 status,
770 __u8 encrypt);
1da177e4
LT
771 void (*key_change_cfm) (struct hci_conn *conn, __u8 status);
772 void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role);
773};
774
775static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
776{
777 struct list_head *p;
8c1b2355 778 __u8 encrypt;
1da177e4
LT
779
780 hci_proto_auth_cfm(conn, status);
781
8c1b2355
MH
782 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend))
783 return;
784
785 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
786
1da177e4
LT
787 read_lock_bh(&hci_cb_list_lock);
788 list_for_each(p, &hci_cb_list) {
789 struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8c1b2355
MH
790 if (cb->security_cfm)
791 cb->security_cfm(conn, status, encrypt);
1da177e4
LT
792 }
793 read_unlock_bh(&hci_cb_list_lock);
794}
795
5a9d0a3f
WR
796static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
797 __u8 encrypt)
1da177e4
LT
798{
799 struct list_head *p;
800
435fef20
MH
801 if (conn->sec_level == BT_SECURITY_SDP)
802 conn->sec_level = BT_SECURITY_LOW;
803
88167aed
VCG
804 if (conn->pending_sec_level > conn->sec_level)
805 conn->sec_level = conn->pending_sec_level;
806
9719f8af 807 hci_proto_encrypt_cfm(conn, status, encrypt);
1da177e4
LT
808
809 read_lock_bh(&hci_cb_list_lock);
810 list_for_each(p, &hci_cb_list) {
811 struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8c1b2355
MH
812 if (cb->security_cfm)
813 cb->security_cfm(conn, status, encrypt);
1da177e4
LT
814 }
815 read_unlock_bh(&hci_cb_list_lock);
816}
817
818static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
819{
820 struct list_head *p;
821
822 read_lock_bh(&hci_cb_list_lock);
823 list_for_each(p, &hci_cb_list) {
824 struct hci_cb *cb = list_entry(p, struct hci_cb, list);
825 if (cb->key_change_cfm)
826 cb->key_change_cfm(conn, status);
827 }
828 read_unlock_bh(&hci_cb_list_lock);
829}
830
5a9d0a3f
WR
831static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
832 __u8 role)
1da177e4
LT
833{
834 struct list_head *p;
835
836 read_lock_bh(&hci_cb_list_lock);
837 list_for_each(p, &hci_cb_list) {
838 struct hci_cb *cb = list_entry(p, struct hci_cb, list);
839 if (cb->role_switch_cfm)
840 cb->role_switch_cfm(conn, status, role);
841 }
842 read_unlock_bh(&hci_cb_list_lock);
843}
844
845int hci_register_cb(struct hci_cb *hcb);
846int hci_unregister_cb(struct hci_cb *hcb);
847
848int hci_register_notifier(struct notifier_block *nb);
849int hci_unregister_notifier(struct notifier_block *nb);
850
a9de9248 851int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
9a9c6a34 852void hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
0d861d8b 853void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
1da177e4 854
a9de9248 855void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
1da177e4
LT
856
857void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data);
858
859/* ----- HCI Sockets ----- */
eec8d2bc
JH
860void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb,
861 struct sock *skip_sk);
1da177e4 862
0381101f
JH
863/* Management interface */
864int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
c71e97bf
JH
865int mgmt_index_added(u16 index);
866int mgmt_index_removed(u16 index);
5add6af8 867int mgmt_powered(u16 index, u8 powered);
73f22f62 868int mgmt_discoverable(u16 index, u8 discoverable);
9fbcbb45 869int mgmt_connectable(u16 index, u8 connectable);
4df378a1 870int mgmt_new_key(u16 index, struct link_key *key, u8 persistent);
cfafccf7 871int mgmt_connected(u16 index, bdaddr_t *bdaddr, u8 link_type);
f7520543 872int mgmt_disconnected(u16 index, bdaddr_t *bdaddr);
8962ee74 873int mgmt_disconnect_failed(u16 index);
17d5c04c 874int mgmt_connect_failed(u16 index, bdaddr_t *bdaddr, u8 status);
a770bb5a 875int mgmt_pin_code_request(u16 index, bdaddr_t *bdaddr, u8 secure);
980e1a53
JH
876int mgmt_pin_code_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status);
877int mgmt_pin_code_neg_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status);
55bc1a37
JH
878int mgmt_user_confirm_request(u16 index, bdaddr_t *bdaddr, __le32 value,
879 u8 confirm_hint);
a5c29683
JH
880int mgmt_user_confirm_reply_complete(u16 index, bdaddr_t *bdaddr, u8 status);
881int mgmt_user_confirm_neg_reply_complete(u16 index, bdaddr_t *bdaddr,
882 u8 status);
2a611692 883int mgmt_auth_failed(u16 index, bdaddr_t *bdaddr, u8 status);
b312b161 884int mgmt_set_local_name_complete(u16 index, u8 *name, u8 status);
c35938b2
SJ
885int mgmt_read_local_oob_data_reply_complete(u16 index, u8 *hash, u8 *randomizer,
886 u8 status);
e17acd40
JH
887int mgmt_device_found(u16 index, bdaddr_t *bdaddr, u8 *dev_class, s8 rssi,
888 u8 *eir);
a88a9652 889int mgmt_remote_name(u16 index, bdaddr_t *bdaddr, u8 *name);
164a6e78 890int mgmt_inquiry_failed(u16 index, u8 status);
314b2381 891int mgmt_discovering(u16 index, u8 discovering);
5e762444
AJ
892int mgmt_device_blocked(u16 index, bdaddr_t *bdaddr);
893int mgmt_device_unblocked(u16 index, bdaddr_t *bdaddr);
0381101f 894
1da177e4
LT
895/* HCI info for socket */
896#define hci_pi(sk) ((struct hci_pinfo *) sk)
897
898struct hci_pinfo {
899 struct bt_sock bt;
900 struct hci_dev *hdev;
901 struct hci_filter filter;
902 __u32 cmsg_mask;
c02178d2 903 unsigned short channel;
1da177e4
LT
904};
905
906/* HCI security filter */
907#define HCI_SFLT_MAX_OGF 5
908
909struct hci_sec_filter {
910 __u32 type_mask;
911 __u32 event_mask[2];
912 __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4];
913};
914
915/* ----- HCI requests ----- */
916#define HCI_REQ_DONE 0
917#define HCI_REQ_PEND 1
918#define HCI_REQ_CANCELED 2
919
a6a67efd
TG
920#define hci_req_lock(d) mutex_lock(&d->req_lock)
921#define hci_req_unlock(d) mutex_unlock(&d->req_lock)
1da177e4 922
23bb5763 923void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);
1da177e4 924
2ce603eb
CT
925void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
926 u16 latency, u16 to_multiplier);
a7a595f6
VCG
927void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
928 __u8 ltk[16]);
929void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16]);
930void hci_le_ltk_neg_reply(struct hci_conn *conn);
931
1da177e4 932#endif /* __HCI_CORE_H */