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