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