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