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