Bluetooth: Create per controller workqueue
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / net / bluetooth / hci_core.h
CommitLineData
1da177e4
LT
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2000-2001 Qualcomm Incorporated
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
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
18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
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
30/* HCI upper protocols */
31#define HCI_PROTO_L2CAP 0
32#define HCI_PROTO_SCO 1
33
1da177e4 34/* HCI Core structures */
1da177e4
LT
35struct inquiry_data {
36 bdaddr_t bdaddr;
37 __u8 pscan_rep_mode;
38 __u8 pscan_period_mode;
39 __u8 pscan_mode;
40 __u8 dev_class[3];
1ebb9252 41 __le16 clock_offset;
1da177e4 42 __s8 rssi;
41a96212 43 __u8 ssp_mode;
1da177e4
LT
44};
45
46struct inquiry_entry {
47 struct inquiry_entry *next;
48 __u32 timestamp;
49 struct inquiry_data data;
50};
51
52struct inquiry_cache {
53 spinlock_t lock;
54 __u32 timestamp;
55 struct inquiry_entry *list;
56};
57
58struct hci_conn_hash {
59 struct list_head list;
60 spinlock_t lock;
61 unsigned int acl_num;
62 unsigned int sco_num;
63};
64
65struct hci_dev {
66 struct list_head list;
67 spinlock_t lock;
68 atomic_t refcnt;
69
70 char name[8];
71 unsigned long flags;
72 __u16 id;
c13854ce 73 __u8 bus;
943da25d 74 __u8 dev_type;
1da177e4 75 bdaddr_t bdaddr;
a9de9248
MH
76 __u8 dev_name[248];
77 __u8 dev_class[3];
1da177e4 78 __u8 features[8];
a9de9248 79 __u8 commands[64];
333140b5 80 __u8 ssp_mode;
1143e5a6
MH
81 __u8 hci_ver;
82 __u16 hci_rev;
83 __u16 manufacturer;
1da177e4
LT
84 __u16 voice_setting;
85
86 __u16 pkt_type;
5b7f9909 87 __u16 esco_type;
1da177e4
LT
88 __u16 link_policy;
89 __u16 link_mode;
90
04837f64
MH
91 __u32 idle_timeout;
92 __u16 sniff_min_interval;
93 __u16 sniff_max_interval;
94
1da177e4
LT
95 unsigned long quirks;
96
97 atomic_t cmd_cnt;
98 unsigned int acl_cnt;
99 unsigned int sco_cnt;
100
101 unsigned int acl_mtu;
102 unsigned int sco_mtu;
103 unsigned int acl_pkts;
104 unsigned int sco_pkts;
105
106 unsigned long cmd_last_tx;
107 unsigned long acl_last_tx;
108 unsigned long sco_last_tx;
109
f48fd9c8
MH
110 struct workqueue_struct *workqueue;
111
1da177e4
LT
112 struct tasklet_struct cmd_task;
113 struct tasklet_struct rx_task;
114 struct tasklet_struct tx_task;
115
116 struct sk_buff_head rx_q;
117 struct sk_buff_head raw_q;
118 struct sk_buff_head cmd_q;
119
120 struct sk_buff *sent_cmd;
ef222013 121 struct sk_buff *reassembly[3];
1da177e4 122
a6a67efd 123 struct mutex req_lock;
1da177e4
LT
124 wait_queue_head_t req_wait_q;
125 __u32 req_status;
126 __u32 req_result;
127
128 struct inquiry_cache inq_cache;
129 struct hci_conn_hash conn_hash;
130
131 struct hci_dev_stats stat;
132
133 struct sk_buff_head driver_init;
134
135 void *driver_data;
136 void *core_data;
137
138 atomic_t promisc;
139
ca325f69
MH
140 struct dentry *debugfs;
141
a91f2e39
MH
142 struct device *parent;
143 struct device dev;
1da177e4 144
611b30f7
MH
145 struct rfkill *rfkill;
146
1da177e4
LT
147 struct module *owner;
148
149 int (*open)(struct hci_dev *hdev);
150 int (*close)(struct hci_dev *hdev);
151 int (*flush)(struct hci_dev *hdev);
152 int (*send)(struct sk_buff *skb);
153 void (*destruct)(struct hci_dev *hdev);
154 void (*notify)(struct hci_dev *hdev, unsigned int evt);
155 int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
156};
157
158struct hci_conn {
159 struct list_head list;
160
161 atomic_t refcnt;
162 spinlock_t lock;
163
164 bdaddr_t dst;
165 __u16 handle;
166 __u16 state;
04837f64 167 __u8 mode;
1da177e4
LT
168 __u8 type;
169 __u8 out;
4c67bc74 170 __u8 attempt;
1da177e4 171 __u8 dev_class[3];
04837f64 172 __u8 features[8];
41a96212 173 __u8 ssp_mode;
04837f64 174 __u16 interval;
a8746417 175 __u16 pkt_type;
04837f64 176 __u16 link_policy;
1da177e4 177 __u32 link_mode;
40be492f 178 __u8 auth_type;
8c1b2355 179 __u8 sec_level;
04837f64 180 __u8 power_save;
052b30b0 181 __u16 disc_timeout;
1da177e4 182 unsigned long pend;
04837f64 183
1da177e4 184 unsigned int sent;
04837f64 185
1da177e4
LT
186 struct sk_buff_head data_q;
187
04837f64
MH
188 struct timer_list disc_timer;
189 struct timer_list idle_timer;
190
f3784d83
RQ
191 struct work_struct work_add;
192 struct work_struct work_del;
b219e3ac
MH
193
194 struct device dev;
9eba32b8 195 atomic_t devref;
b219e3ac 196
1da177e4
LT
197 struct hci_dev *hdev;
198 void *l2cap_data;
199 void *sco_data;
200 void *priv;
201
202 struct hci_conn *link;
203};
204
205extern struct hci_proto *hci_proto[];
206extern struct list_head hci_dev_list;
207extern struct list_head hci_cb_list;
208extern rwlock_t hci_dev_list_lock;
209extern rwlock_t hci_cb_list_lock;
210
211/* ----- Inquiry cache ----- */
212#define INQUIRY_CACHE_AGE_MAX (HZ*30) // 30 seconds
213#define INQUIRY_ENTRY_AGE_MAX (HZ*60) // 60 seconds
214
215#define inquiry_cache_lock(c) spin_lock(&c->lock)
216#define inquiry_cache_unlock(c) spin_unlock(&c->lock)
217#define inquiry_cache_lock_bh(c) spin_lock_bh(&c->lock)
218#define inquiry_cache_unlock_bh(c) spin_unlock_bh(&c->lock)
219
220static inline void inquiry_cache_init(struct hci_dev *hdev)
221{
222 struct inquiry_cache *c = &hdev->inq_cache;
223 spin_lock_init(&c->lock);
224 c->list = NULL;
225}
226
227static inline int inquiry_cache_empty(struct hci_dev *hdev)
228{
229 struct inquiry_cache *c = &hdev->inq_cache;
230 return (c->list == NULL);
231}
232
233static inline long inquiry_cache_age(struct hci_dev *hdev)
234{
235 struct inquiry_cache *c = &hdev->inq_cache;
236 return jiffies - c->timestamp;
237}
238
239static inline long inquiry_entry_age(struct inquiry_entry *e)
240{
241 return jiffies - e->timestamp;
242}
243
244struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
245void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data);
246
247/* ----- HCI Connections ----- */
248enum {
249 HCI_CONN_AUTH_PEND,
250 HCI_CONN_ENCRYPT_PEND,
04837f64
MH
251 HCI_CONN_RSWITCH_PEND,
252 HCI_CONN_MODE_CHANGE_PEND,
1da177e4
LT
253};
254
255static inline void hci_conn_hash_init(struct hci_dev *hdev)
256{
257 struct hci_conn_hash *h = &hdev->conn_hash;
258 INIT_LIST_HEAD(&h->list);
259 spin_lock_init(&h->lock);
260 h->acl_num = 0;
261 h->sco_num = 0;
262}
263
264static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
265{
266 struct hci_conn_hash *h = &hdev->conn_hash;
267 list_add(&c->list, &h->list);
268 if (c->type == ACL_LINK)
269 h->acl_num++;
270 else
271 h->sco_num++;
272}
273
274static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
275{
276 struct hci_conn_hash *h = &hdev->conn_hash;
277 list_del(&c->list);
278 if (c->type == ACL_LINK)
279 h->acl_num--;
280 else
281 h->sco_num--;
282}
283
284static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
285 __u16 handle)
286{
287 struct hci_conn_hash *h = &hdev->conn_hash;
288 struct list_head *p;
289 struct hci_conn *c;
290
291 list_for_each(p, &h->list) {
292 c = list_entry(p, struct hci_conn, list);
293 if (c->handle == handle)
294 return c;
295 }
296 return NULL;
297}
298
299static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
300 __u8 type, bdaddr_t *ba)
301{
302 struct hci_conn_hash *h = &hdev->conn_hash;
303 struct list_head *p;
304 struct hci_conn *c;
305
306 list_for_each(p, &h->list) {
307 c = list_entry(p, struct hci_conn, list);
308 if (c->type == type && !bacmp(&c->dst, ba))
309 return c;
310 }
311 return NULL;
312}
313
4c67bc74
MH
314static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
315 __u8 type, __u16 state)
316{
317 struct hci_conn_hash *h = &hdev->conn_hash;
318 struct list_head *p;
319 struct hci_conn *c;
320
321 list_for_each(p, &h->list) {
322 c = list_entry(p, struct hci_conn, list);
323 if (c->type == type && c->state == state)
324 return c;
325 }
326 return NULL;
327}
328
329void hci_acl_connect(struct hci_conn *conn);
1da177e4
LT
330void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
331void hci_add_sco(struct hci_conn *conn, __u16 handle);
b6a0dc82 332void hci_setup_sync(struct hci_conn *conn, __u16 handle);
1da177e4
LT
333
334struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
a9de9248
MH
335int hci_conn_del(struct hci_conn *conn);
336void hci_conn_hash_flush(struct hci_dev *hdev);
337void hci_conn_check_pending(struct hci_dev *hdev);
1da177e4 338
8c1b2355 339struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8 sec_level, __u8 auth_type);
e7c29cb1 340int hci_conn_check_link_mode(struct hci_conn *conn);
0684e5f9 341int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
1da177e4 342int hci_conn_change_link_key(struct hci_conn *conn);
8c1b2355 343int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
1da177e4 344
04837f64
MH
345void hci_conn_enter_active_mode(struct hci_conn *conn);
346void hci_conn_enter_sniff_mode(struct hci_conn *conn);
1da177e4 347
9eba32b8
MH
348void hci_conn_hold_device(struct hci_conn *conn);
349void hci_conn_put_device(struct hci_conn *conn);
350
1da177e4
LT
351static inline void hci_conn_hold(struct hci_conn *conn)
352{
353 atomic_inc(&conn->refcnt);
04837f64 354 del_timer(&conn->disc_timer);
1da177e4
LT
355}
356
357static inline void hci_conn_put(struct hci_conn *conn)
358{
359 if (atomic_dec_and_test(&conn->refcnt)) {
04837f64 360 unsigned long timeo;
1da177e4 361 if (conn->type == ACL_LINK) {
04837f64 362 del_timer(&conn->idle_timer);
6ac59344 363 if (conn->state == BT_CONNECTED) {
052b30b0 364 timeo = msecs_to_jiffies(conn->disc_timeout);
6ac59344 365 if (!conn->out)
052b30b0 366 timeo *= 2;
6ac59344
MH
367 } else
368 timeo = msecs_to_jiffies(10);
1da177e4 369 } else
04837f64
MH
370 timeo = msecs_to_jiffies(10);
371 mod_timer(&conn->disc_timer, jiffies + timeo);
1da177e4
LT
372 }
373}
374
1da177e4
LT
375/* ----- HCI Devices ----- */
376static inline void __hci_dev_put(struct hci_dev *d)
377{
378 if (atomic_dec_and_test(&d->refcnt))
379 d->destruct(d);
380}
381
382static inline void hci_dev_put(struct hci_dev *d)
383{
384 __hci_dev_put(d);
385 module_put(d->owner);
386}
387
388static inline struct hci_dev *__hci_dev_hold(struct hci_dev *d)
389{
390 atomic_inc(&d->refcnt);
391 return d;
392}
393
394static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
395{
396 if (try_module_get(d->owner))
397 return __hci_dev_hold(d);
398 return NULL;
399}
400
401#define hci_dev_lock(d) spin_lock(&d->lock)
402#define hci_dev_unlock(d) spin_unlock(&d->lock)
403#define hci_dev_lock_bh(d) spin_lock_bh(&d->lock)
404#define hci_dev_unlock_bh(d) spin_unlock_bh(&d->lock)
405
406struct hci_dev *hci_dev_get(int index);
407struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);
408
409struct hci_dev *hci_alloc_dev(void);
410void hci_free_dev(struct hci_dev *hdev);
411int hci_register_dev(struct hci_dev *hdev);
412int hci_unregister_dev(struct hci_dev *hdev);
413int hci_suspend_dev(struct hci_dev *hdev);
414int hci_resume_dev(struct hci_dev *hdev);
415int hci_dev_open(__u16 dev);
416int hci_dev_close(__u16 dev);
417int hci_dev_reset(__u16 dev);
418int hci_dev_reset_stat(__u16 dev);
419int hci_dev_cmd(unsigned int cmd, void __user *arg);
420int hci_get_dev_list(void __user *arg);
421int hci_get_dev_info(void __user *arg);
422int hci_get_conn_list(void __user *arg);
423int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
40be492f 424int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
1da177e4
LT
425int hci_inquiry(void __user *arg);
426
427void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
428
76bca880 429int hci_recv_frame(struct sk_buff *skb);
ef222013
MH
430int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
431
1da177e4
LT
432int hci_register_sysfs(struct hci_dev *hdev);
433void hci_unregister_sysfs(struct hci_dev *hdev);
a67e899c 434void hci_conn_init_sysfs(struct hci_conn *conn);
b219e3ac
MH
435void hci_conn_add_sysfs(struct hci_conn *conn);
436void hci_conn_del_sysfs(struct hci_conn *conn);
1da177e4 437
a91f2e39 438#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->parent = (pdev))
1da177e4
LT
439
440/* ----- LMP capabilities ----- */
04837f64
MH
441#define lmp_rswitch_capable(dev) ((dev)->features[0] & LMP_RSWITCH)
442#define lmp_encrypt_capable(dev) ((dev)->features[0] & LMP_ENCRYPT)
443#define lmp_sniff_capable(dev) ((dev)->features[0] & LMP_SNIFF)
444#define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR)
5b7f9909 445#define lmp_esco_capable(dev) ((dev)->features[3] & LMP_ESCO)
769be974 446#define lmp_ssp_capable(dev) ((dev)->features[6] & LMP_SIMPLE_PAIR)
1da177e4
LT
447
448/* ----- HCI protocols ----- */
449struct hci_proto {
8c1b2355 450 char *name;
1da177e4
LT
451 unsigned int id;
452 unsigned long flags;
453
454 void *priv;
455
8c1b2355 456 int (*connect_ind) (struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type);
1da177e4 457 int (*connect_cfm) (struct hci_conn *conn, __u8 status);
2950f21a
MH
458 int (*disconn_ind) (struct hci_conn *conn);
459 int (*disconn_cfm) (struct hci_conn *conn, __u8 reason);
1da177e4
LT
460 int (*recv_acldata) (struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
461 int (*recv_scodata) (struct hci_conn *conn, struct sk_buff *skb);
8c1b2355 462 int (*security_cfm) (struct hci_conn *conn, __u8 status, __u8 encrypt);
1da177e4
LT
463};
464
465static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type)
466{
467 register struct hci_proto *hp;
468 int mask = 0;
8c1b2355 469
1da177e4
LT
470 hp = hci_proto[HCI_PROTO_L2CAP];
471 if (hp && hp->connect_ind)
472 mask |= hp->connect_ind(hdev, bdaddr, type);
473
474 hp = hci_proto[HCI_PROTO_SCO];
475 if (hp && hp->connect_ind)
476 mask |= hp->connect_ind(hdev, bdaddr, type);
477
478 return mask;
479}
480
481static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
482{
483 register struct hci_proto *hp;
484
485 hp = hci_proto[HCI_PROTO_L2CAP];
486 if (hp && hp->connect_cfm)
487 hp->connect_cfm(conn, status);
488
489 hp = hci_proto[HCI_PROTO_SCO];
490 if (hp && hp->connect_cfm)
491 hp->connect_cfm(conn, status);
492}
493
2950f21a 494static inline int hci_proto_disconn_ind(struct hci_conn *conn)
1da177e4
LT
495{
496 register struct hci_proto *hp;
2950f21a 497 int reason = 0x13;
1da177e4
LT
498
499 hp = hci_proto[HCI_PROTO_L2CAP];
500 if (hp && hp->disconn_ind)
2950f21a 501 reason = hp->disconn_ind(conn);
1da177e4
LT
502
503 hp = hci_proto[HCI_PROTO_SCO];
504 if (hp && hp->disconn_ind)
2950f21a
MH
505 reason = hp->disconn_ind(conn);
506
507 return reason;
508}
509
510static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
511{
512 register struct hci_proto *hp;
513
514 hp = hci_proto[HCI_PROTO_L2CAP];
515 if (hp && hp->disconn_cfm)
516 hp->disconn_cfm(conn, reason);
517
518 hp = hci_proto[HCI_PROTO_SCO];
519 if (hp && hp->disconn_cfm)
520 hp->disconn_cfm(conn, reason);
1da177e4
LT
521}
522
523static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
524{
525 register struct hci_proto *hp;
8c1b2355
MH
526 __u8 encrypt;
527
528 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend))
529 return;
530
531 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
1da177e4
LT
532
533 hp = hci_proto[HCI_PROTO_L2CAP];
8c1b2355
MH
534 if (hp && hp->security_cfm)
535 hp->security_cfm(conn, status, encrypt);
1da177e4
LT
536
537 hp = hci_proto[HCI_PROTO_SCO];
8c1b2355
MH
538 if (hp && hp->security_cfm)
539 hp->security_cfm(conn, status, encrypt);
1da177e4
LT
540}
541
9719f8af 542static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status, __u8 encrypt)
1da177e4
LT
543{
544 register struct hci_proto *hp;
545
546 hp = hci_proto[HCI_PROTO_L2CAP];
8c1b2355
MH
547 if (hp && hp->security_cfm)
548 hp->security_cfm(conn, status, encrypt);
1da177e4
LT
549
550 hp = hci_proto[HCI_PROTO_SCO];
8c1b2355
MH
551 if (hp && hp->security_cfm)
552 hp->security_cfm(conn, status, encrypt);
1da177e4
LT
553}
554
555int hci_register_proto(struct hci_proto *hproto);
556int hci_unregister_proto(struct hci_proto *hproto);
557
558/* ----- HCI callbacks ----- */
559struct hci_cb {
560 struct list_head list;
561
562 char *name;
563
8c1b2355 564 void (*security_cfm) (struct hci_conn *conn, __u8 status, __u8 encrypt);
1da177e4
LT
565 void (*key_change_cfm) (struct hci_conn *conn, __u8 status);
566 void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role);
567};
568
569static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
570{
571 struct list_head *p;
8c1b2355 572 __u8 encrypt;
1da177e4
LT
573
574 hci_proto_auth_cfm(conn, status);
575
8c1b2355
MH
576 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend))
577 return;
578
579 encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
580
1da177e4
LT
581 read_lock_bh(&hci_cb_list_lock);
582 list_for_each(p, &hci_cb_list) {
583 struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8c1b2355
MH
584 if (cb->security_cfm)
585 cb->security_cfm(conn, status, encrypt);
1da177e4
LT
586 }
587 read_unlock_bh(&hci_cb_list_lock);
588}
589
590static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, __u8 encrypt)
591{
592 struct list_head *p;
593
435fef20
MH
594 if (conn->sec_level == BT_SECURITY_SDP)
595 conn->sec_level = BT_SECURITY_LOW;
596
9719f8af 597 hci_proto_encrypt_cfm(conn, status, encrypt);
1da177e4
LT
598
599 read_lock_bh(&hci_cb_list_lock);
600 list_for_each(p, &hci_cb_list) {
601 struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8c1b2355
MH
602 if (cb->security_cfm)
603 cb->security_cfm(conn, status, encrypt);
1da177e4
LT
604 }
605 read_unlock_bh(&hci_cb_list_lock);
606}
607
608static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
609{
610 struct list_head *p;
611
612 read_lock_bh(&hci_cb_list_lock);
613 list_for_each(p, &hci_cb_list) {
614 struct hci_cb *cb = list_entry(p, struct hci_cb, list);
615 if (cb->key_change_cfm)
616 cb->key_change_cfm(conn, status);
617 }
618 read_unlock_bh(&hci_cb_list_lock);
619}
620
621static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, __u8 role)
622{
623 struct list_head *p;
624
625 read_lock_bh(&hci_cb_list_lock);
626 list_for_each(p, &hci_cb_list) {
627 struct hci_cb *cb = list_entry(p, struct hci_cb, list);
628 if (cb->role_switch_cfm)
629 cb->role_switch_cfm(conn, status, role);
630 }
631 read_unlock_bh(&hci_cb_list_lock);
632}
633
634int hci_register_cb(struct hci_cb *hcb);
635int hci_unregister_cb(struct hci_cb *hcb);
636
637int hci_register_notifier(struct notifier_block *nb);
638int hci_unregister_notifier(struct notifier_block *nb);
639
a9de9248 640int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
9a9c6a34 641void hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
0d861d8b 642void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
1da177e4 643
a9de9248 644void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
1da177e4
LT
645
646void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data);
647
648/* ----- HCI Sockets ----- */
649void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
650
651/* HCI info for socket */
652#define hci_pi(sk) ((struct hci_pinfo *) sk)
653
654struct hci_pinfo {
655 struct bt_sock bt;
656 struct hci_dev *hdev;
657 struct hci_filter filter;
658 __u32 cmsg_mask;
659};
660
661/* HCI security filter */
662#define HCI_SFLT_MAX_OGF 5
663
664struct hci_sec_filter {
665 __u32 type_mask;
666 __u32 event_mask[2];
667 __u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4];
668};
669
670/* ----- HCI requests ----- */
671#define HCI_REQ_DONE 0
672#define HCI_REQ_PEND 1
673#define HCI_REQ_CANCELED 2
674
a6a67efd
TG
675#define hci_req_lock(d) mutex_lock(&d->req_lock)
676#define hci_req_unlock(d) mutex_unlock(&d->req_lock)
1da177e4
LT
677
678void hci_req_complete(struct hci_dev *hdev, int result);
679
680#endif /* __HCI_CORE_H */