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