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