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