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