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