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