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