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