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