Commit | Line | Data |
---|---|---|
8e87d142 | 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 | |
8e87d142 YH |
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 | ||
8e87d142 YH |
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 | /* Bluetooth HCI event handling. */ | |
26 | ||
1da177e4 LT |
27 | #include <linux/module.h> |
28 | ||
29 | #include <linux/types.h> | |
30 | #include <linux/errno.h> | |
31 | #include <linux/kernel.h> | |
1da177e4 LT |
32 | #include <linux/slab.h> |
33 | #include <linux/poll.h> | |
34 | #include <linux/fcntl.h> | |
35 | #include <linux/init.h> | |
36 | #include <linux/skbuff.h> | |
37 | #include <linux/interrupt.h> | |
38 | #include <linux/notifier.h> | |
39 | #include <net/sock.h> | |
40 | ||
41 | #include <asm/system.h> | |
70f23020 | 42 | #include <linux/uaccess.h> |
1da177e4 LT |
43 | #include <asm/unaligned.h> |
44 | ||
45 | #include <net/bluetooth/bluetooth.h> | |
46 | #include <net/bluetooth/hci_core.h> | |
47 | ||
1da177e4 LT |
48 | /* Handle HCI Event packets */ |
49 | ||
a9de9248 | 50 | static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 51 | { |
a9de9248 | 52 | __u8 status = *((__u8 *) skb->data); |
1da177e4 | 53 | |
a9de9248 | 54 | BT_DBG("%s status 0x%x", hdev->name, status); |
1da177e4 | 55 | |
a9de9248 MH |
56 | if (status) |
57 | return; | |
1da177e4 | 58 | |
a9de9248 | 59 | clear_bit(HCI_INQUIRY, &hdev->flags); |
6bd57416 | 60 | |
23bb5763 | 61 | hci_req_complete(hdev, HCI_OP_INQUIRY_CANCEL, status); |
a9de9248 MH |
62 | |
63 | hci_conn_check_pending(hdev); | |
64 | } | |
6bd57416 | 65 | |
a9de9248 MH |
66 | static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb) |
67 | { | |
68 | __u8 status = *((__u8 *) skb->data); | |
6bd57416 | 69 | |
a9de9248 | 70 | BT_DBG("%s status 0x%x", hdev->name, status); |
6bd57416 | 71 | |
a9de9248 MH |
72 | if (status) |
73 | return; | |
1da177e4 | 74 | |
a9de9248 MH |
75 | clear_bit(HCI_INQUIRY, &hdev->flags); |
76 | ||
77 | hci_conn_check_pending(hdev); | |
78 | } | |
79 | ||
80 | static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, struct sk_buff *skb) | |
81 | { | |
82 | BT_DBG("%s", hdev->name); | |
83 | } | |
84 | ||
85 | static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb) | |
86 | { | |
87 | struct hci_rp_role_discovery *rp = (void *) skb->data; | |
88 | struct hci_conn *conn; | |
89 | ||
90 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | |
91 | ||
92 | if (rp->status) | |
93 | return; | |
94 | ||
95 | hci_dev_lock(hdev); | |
96 | ||
97 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); | |
98 | if (conn) { | |
99 | if (rp->role) | |
100 | conn->link_mode &= ~HCI_LM_MASTER; | |
101 | else | |
102 | conn->link_mode |= HCI_LM_MASTER; | |
1da177e4 | 103 | } |
a9de9248 MH |
104 | |
105 | hci_dev_unlock(hdev); | |
1da177e4 LT |
106 | } |
107 | ||
e4e8e37c MH |
108 | static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
109 | { | |
110 | struct hci_rp_read_link_policy *rp = (void *) skb->data; | |
111 | struct hci_conn *conn; | |
112 | ||
113 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | |
114 | ||
115 | if (rp->status) | |
116 | return; | |
117 | ||
118 | hci_dev_lock(hdev); | |
119 | ||
120 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); | |
121 | if (conn) | |
122 | conn->link_policy = __le16_to_cpu(rp->policy); | |
123 | ||
124 | hci_dev_unlock(hdev); | |
125 | } | |
126 | ||
a9de9248 | 127 | static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 128 | { |
a9de9248 | 129 | struct hci_rp_write_link_policy *rp = (void *) skb->data; |
1da177e4 | 130 | struct hci_conn *conn; |
04837f64 | 131 | void *sent; |
1da177e4 | 132 | |
a9de9248 | 133 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
1da177e4 | 134 | |
a9de9248 MH |
135 | if (rp->status) |
136 | return; | |
1da177e4 | 137 | |
a9de9248 MH |
138 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY); |
139 | if (!sent) | |
140 | return; | |
1da177e4 | 141 | |
a9de9248 | 142 | hci_dev_lock(hdev); |
1da177e4 | 143 | |
a9de9248 | 144 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle)); |
e4e8e37c | 145 | if (conn) |
83985319 | 146 | conn->link_policy = get_unaligned_le16(sent + 2); |
1da177e4 | 147 | |
a9de9248 MH |
148 | hci_dev_unlock(hdev); |
149 | } | |
1da177e4 | 150 | |
e4e8e37c MH |
151 | static void hci_cc_read_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb) |
152 | { | |
153 | struct hci_rp_read_def_link_policy *rp = (void *) skb->data; | |
154 | ||
155 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | |
156 | ||
157 | if (rp->status) | |
158 | return; | |
159 | ||
160 | hdev->link_policy = __le16_to_cpu(rp->policy); | |
161 | } | |
162 | ||
163 | static void hci_cc_write_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb) | |
164 | { | |
165 | __u8 status = *((__u8 *) skb->data); | |
166 | void *sent; | |
167 | ||
168 | BT_DBG("%s status 0x%x", hdev->name, status); | |
169 | ||
170 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY); | |
171 | if (!sent) | |
172 | return; | |
173 | ||
174 | if (!status) | |
175 | hdev->link_policy = get_unaligned_le16(sent); | |
176 | ||
23bb5763 | 177 | hci_req_complete(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, status); |
e4e8e37c MH |
178 | } |
179 | ||
a9de9248 MH |
180 | static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb) |
181 | { | |
182 | __u8 status = *((__u8 *) skb->data); | |
04837f64 | 183 | |
a9de9248 | 184 | BT_DBG("%s status 0x%x", hdev->name, status); |
04837f64 | 185 | |
23bb5763 | 186 | hci_req_complete(hdev, HCI_OP_RESET, status); |
a9de9248 | 187 | } |
04837f64 | 188 | |
a9de9248 MH |
189 | static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb) |
190 | { | |
191 | __u8 status = *((__u8 *) skb->data); | |
192 | void *sent; | |
04837f64 | 193 | |
a9de9248 | 194 | BT_DBG("%s status 0x%x", hdev->name, status); |
04837f64 | 195 | |
f383f275 MH |
196 | if (status) |
197 | return; | |
198 | ||
a9de9248 MH |
199 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME); |
200 | if (!sent) | |
201 | return; | |
04837f64 | 202 | |
f383f275 | 203 | memcpy(hdev->dev_name, sent, 248); |
a9de9248 MH |
204 | } |
205 | ||
206 | static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb) | |
207 | { | |
208 | struct hci_rp_read_local_name *rp = (void *) skb->data; | |
209 | ||
210 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | |
211 | ||
212 | if (rp->status) | |
213 | return; | |
214 | ||
215 | memcpy(hdev->dev_name, rp->name, 248); | |
216 | } | |
217 | ||
218 | static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb) | |
219 | { | |
220 | __u8 status = *((__u8 *) skb->data); | |
221 | void *sent; | |
222 | ||
223 | BT_DBG("%s status 0x%x", hdev->name, status); | |
224 | ||
225 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE); | |
226 | if (!sent) | |
227 | return; | |
228 | ||
229 | if (!status) { | |
230 | __u8 param = *((__u8 *) sent); | |
231 | ||
232 | if (param == AUTH_ENABLED) | |
233 | set_bit(HCI_AUTH, &hdev->flags); | |
234 | else | |
235 | clear_bit(HCI_AUTH, &hdev->flags); | |
1da177e4 | 236 | } |
a9de9248 | 237 | |
23bb5763 | 238 | hci_req_complete(hdev, HCI_OP_WRITE_AUTH_ENABLE, status); |
1da177e4 LT |
239 | } |
240 | ||
a9de9248 | 241 | static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 242 | { |
a9de9248 | 243 | __u8 status = *((__u8 *) skb->data); |
1da177e4 LT |
244 | void *sent; |
245 | ||
a9de9248 | 246 | BT_DBG("%s status 0x%x", hdev->name, status); |
1da177e4 | 247 | |
a9de9248 MH |
248 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE); |
249 | if (!sent) | |
250 | return; | |
1da177e4 | 251 | |
a9de9248 MH |
252 | if (!status) { |
253 | __u8 param = *((__u8 *) sent); | |
254 | ||
255 | if (param) | |
256 | set_bit(HCI_ENCRYPT, &hdev->flags); | |
257 | else | |
258 | clear_bit(HCI_ENCRYPT, &hdev->flags); | |
259 | } | |
1da177e4 | 260 | |
23bb5763 | 261 | hci_req_complete(hdev, HCI_OP_WRITE_ENCRYPT_MODE, status); |
a9de9248 | 262 | } |
1da177e4 | 263 | |
a9de9248 MH |
264 | static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb) |
265 | { | |
266 | __u8 status = *((__u8 *) skb->data); | |
267 | void *sent; | |
1da177e4 | 268 | |
a9de9248 | 269 | BT_DBG("%s status 0x%x", hdev->name, status); |
1da177e4 | 270 | |
a9de9248 MH |
271 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE); |
272 | if (!sent) | |
273 | return; | |
1da177e4 | 274 | |
a9de9248 MH |
275 | if (!status) { |
276 | __u8 param = *((__u8 *) sent); | |
1da177e4 | 277 | |
a9de9248 MH |
278 | clear_bit(HCI_PSCAN, &hdev->flags); |
279 | clear_bit(HCI_ISCAN, &hdev->flags); | |
1da177e4 | 280 | |
73f22f62 | 281 | if (param & SCAN_INQUIRY) { |
a9de9248 | 282 | set_bit(HCI_ISCAN, &hdev->flags); |
73f22f62 JH |
283 | mgmt_discoverable(hdev->id, 1); |
284 | } else | |
285 | mgmt_discoverable(hdev->id, 0); | |
1da177e4 | 286 | |
a9de9248 MH |
287 | if (param & SCAN_PAGE) |
288 | set_bit(HCI_PSCAN, &hdev->flags); | |
289 | } | |
1da177e4 | 290 | |
23bb5763 | 291 | hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status); |
a9de9248 | 292 | } |
1da177e4 | 293 | |
a9de9248 MH |
294 | static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
295 | { | |
296 | struct hci_rp_read_class_of_dev *rp = (void *) skb->data; | |
1da177e4 | 297 | |
a9de9248 | 298 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
1da177e4 | 299 | |
a9de9248 MH |
300 | if (rp->status) |
301 | return; | |
1da177e4 | 302 | |
a9de9248 | 303 | memcpy(hdev->dev_class, rp->dev_class, 3); |
1da177e4 | 304 | |
a9de9248 MH |
305 | BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name, |
306 | hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]); | |
307 | } | |
1da177e4 | 308 | |
a9de9248 MH |
309 | static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb) |
310 | { | |
311 | __u8 status = *((__u8 *) skb->data); | |
312 | void *sent; | |
1da177e4 | 313 | |
a9de9248 | 314 | BT_DBG("%s status 0x%x", hdev->name, status); |
1da177e4 | 315 | |
f383f275 MH |
316 | if (status) |
317 | return; | |
318 | ||
a9de9248 MH |
319 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV); |
320 | if (!sent) | |
321 | return; | |
1da177e4 | 322 | |
f383f275 | 323 | memcpy(hdev->dev_class, sent, 3); |
a9de9248 | 324 | } |
1da177e4 | 325 | |
a9de9248 MH |
326 | static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) |
327 | { | |
328 | struct hci_rp_read_voice_setting *rp = (void *) skb->data; | |
329 | __u16 setting; | |
330 | ||
331 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | |
332 | ||
333 | if (rp->status) | |
334 | return; | |
335 | ||
336 | setting = __le16_to_cpu(rp->voice_setting); | |
337 | ||
f383f275 | 338 | if (hdev->voice_setting == setting) |
a9de9248 MH |
339 | return; |
340 | ||
341 | hdev->voice_setting = setting; | |
342 | ||
343 | BT_DBG("%s voice setting 0x%04x", hdev->name, setting); | |
344 | ||
345 | if (hdev->notify) { | |
346 | tasklet_disable(&hdev->tx_task); | |
347 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); | |
348 | tasklet_enable(&hdev->tx_task); | |
349 | } | |
350 | } | |
351 | ||
352 | static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb) | |
353 | { | |
354 | __u8 status = *((__u8 *) skb->data); | |
f383f275 | 355 | __u16 setting; |
a9de9248 MH |
356 | void *sent; |
357 | ||
358 | BT_DBG("%s status 0x%x", hdev->name, status); | |
1da177e4 | 359 | |
f383f275 MH |
360 | if (status) |
361 | return; | |
362 | ||
a9de9248 MH |
363 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING); |
364 | if (!sent) | |
365 | return; | |
1da177e4 | 366 | |
f383f275 | 367 | setting = get_unaligned_le16(sent); |
1da177e4 | 368 | |
f383f275 MH |
369 | if (hdev->voice_setting == setting) |
370 | return; | |
371 | ||
372 | hdev->voice_setting = setting; | |
1da177e4 | 373 | |
f383f275 | 374 | BT_DBG("%s voice setting 0x%04x", hdev->name, setting); |
1da177e4 | 375 | |
f383f275 MH |
376 | if (hdev->notify) { |
377 | tasklet_disable(&hdev->tx_task); | |
378 | hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING); | |
379 | tasklet_enable(&hdev->tx_task); | |
1da177e4 LT |
380 | } |
381 | } | |
382 | ||
a9de9248 | 383 | static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 384 | { |
a9de9248 | 385 | __u8 status = *((__u8 *) skb->data); |
1da177e4 | 386 | |
a9de9248 | 387 | BT_DBG("%s status 0x%x", hdev->name, status); |
1da177e4 | 388 | |
23bb5763 | 389 | hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status); |
a9de9248 | 390 | } |
1143e5a6 | 391 | |
333140b5 MH |
392 | static void hci_cc_read_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) |
393 | { | |
394 | struct hci_rp_read_ssp_mode *rp = (void *) skb->data; | |
395 | ||
396 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | |
397 | ||
398 | if (rp->status) | |
399 | return; | |
400 | ||
401 | hdev->ssp_mode = rp->mode; | |
402 | } | |
403 | ||
404 | static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb) | |
405 | { | |
406 | __u8 status = *((__u8 *) skb->data); | |
407 | void *sent; | |
408 | ||
409 | BT_DBG("%s status 0x%x", hdev->name, status); | |
410 | ||
411 | if (status) | |
412 | return; | |
413 | ||
414 | sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE); | |
415 | if (!sent) | |
416 | return; | |
417 | ||
418 | hdev->ssp_mode = *((__u8 *) sent); | |
419 | } | |
420 | ||
a9de9248 MH |
421 | static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb) |
422 | { | |
423 | struct hci_rp_read_local_version *rp = (void *) skb->data; | |
1143e5a6 | 424 | |
a9de9248 | 425 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
1143e5a6 | 426 | |
a9de9248 MH |
427 | if (rp->status) |
428 | return; | |
1143e5a6 | 429 | |
a9de9248 | 430 | hdev->hci_ver = rp->hci_ver; |
e4e8e37c MH |
431 | hdev->hci_rev = __le16_to_cpu(rp->hci_rev); |
432 | hdev->manufacturer = __le16_to_cpu(rp->manufacturer); | |
1143e5a6 | 433 | |
a9de9248 MH |
434 | BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name, |
435 | hdev->manufacturer, | |
436 | hdev->hci_ver, hdev->hci_rev); | |
437 | } | |
1da177e4 | 438 | |
a9de9248 MH |
439 | static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb) |
440 | { | |
441 | struct hci_rp_read_local_commands *rp = (void *) skb->data; | |
1da177e4 | 442 | |
a9de9248 | 443 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
1da177e4 | 444 | |
a9de9248 MH |
445 | if (rp->status) |
446 | return; | |
1da177e4 | 447 | |
a9de9248 MH |
448 | memcpy(hdev->commands, rp->commands, sizeof(hdev->commands)); |
449 | } | |
1da177e4 | 450 | |
a9de9248 MH |
451 | static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb) |
452 | { | |
453 | struct hci_rp_read_local_features *rp = (void *) skb->data; | |
5b7f9909 | 454 | |
a9de9248 | 455 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
1da177e4 | 456 | |
a9de9248 MH |
457 | if (rp->status) |
458 | return; | |
5b7f9909 | 459 | |
a9de9248 | 460 | memcpy(hdev->features, rp->features, 8); |
5b7f9909 | 461 | |
a9de9248 MH |
462 | /* Adjust default settings according to features |
463 | * supported by device. */ | |
1da177e4 | 464 | |
a9de9248 MH |
465 | if (hdev->features[0] & LMP_3SLOT) |
466 | hdev->pkt_type |= (HCI_DM3 | HCI_DH3); | |
1da177e4 | 467 | |
a9de9248 MH |
468 | if (hdev->features[0] & LMP_5SLOT) |
469 | hdev->pkt_type |= (HCI_DM5 | HCI_DH5); | |
1da177e4 | 470 | |
a9de9248 MH |
471 | if (hdev->features[1] & LMP_HV2) { |
472 | hdev->pkt_type |= (HCI_HV2); | |
473 | hdev->esco_type |= (ESCO_HV2); | |
474 | } | |
1da177e4 | 475 | |
a9de9248 MH |
476 | if (hdev->features[1] & LMP_HV3) { |
477 | hdev->pkt_type |= (HCI_HV3); | |
478 | hdev->esco_type |= (ESCO_HV3); | |
479 | } | |
1da177e4 | 480 | |
a9de9248 MH |
481 | if (hdev->features[3] & LMP_ESCO) |
482 | hdev->esco_type |= (ESCO_EV3); | |
da1f5198 | 483 | |
a9de9248 MH |
484 | if (hdev->features[4] & LMP_EV4) |
485 | hdev->esco_type |= (ESCO_EV4); | |
da1f5198 | 486 | |
a9de9248 MH |
487 | if (hdev->features[4] & LMP_EV5) |
488 | hdev->esco_type |= (ESCO_EV5); | |
1da177e4 | 489 | |
efc7688b MH |
490 | if (hdev->features[5] & LMP_EDR_ESCO_2M) |
491 | hdev->esco_type |= (ESCO_2EV3); | |
492 | ||
493 | if (hdev->features[5] & LMP_EDR_ESCO_3M) | |
494 | hdev->esco_type |= (ESCO_3EV3); | |
495 | ||
496 | if (hdev->features[5] & LMP_EDR_3S_ESCO) | |
497 | hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5); | |
498 | ||
a9de9248 MH |
499 | BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name, |
500 | hdev->features[0], hdev->features[1], | |
501 | hdev->features[2], hdev->features[3], | |
502 | hdev->features[4], hdev->features[5], | |
503 | hdev->features[6], hdev->features[7]); | |
504 | } | |
1da177e4 | 505 | |
a9de9248 MH |
506 | static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb) |
507 | { | |
508 | struct hci_rp_read_buffer_size *rp = (void *) skb->data; | |
1da177e4 | 509 | |
a9de9248 | 510 | BT_DBG("%s status 0x%x", hdev->name, rp->status); |
1da177e4 | 511 | |
a9de9248 MH |
512 | if (rp->status) |
513 | return; | |
1da177e4 | 514 | |
a9de9248 MH |
515 | hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu); |
516 | hdev->sco_mtu = rp->sco_mtu; | |
517 | hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt); | |
518 | hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt); | |
519 | ||
520 | if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) { | |
521 | hdev->sco_mtu = 64; | |
522 | hdev->sco_pkts = 8; | |
1da177e4 | 523 | } |
a9de9248 MH |
524 | |
525 | hdev->acl_cnt = hdev->acl_pkts; | |
526 | hdev->sco_cnt = hdev->sco_pkts; | |
527 | ||
528 | BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, | |
529 | hdev->acl_mtu, hdev->acl_pkts, | |
530 | hdev->sco_mtu, hdev->sco_pkts); | |
531 | } | |
532 | ||
533 | static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb) | |
534 | { | |
535 | struct hci_rp_read_bd_addr *rp = (void *) skb->data; | |
536 | ||
537 | BT_DBG("%s status 0x%x", hdev->name, rp->status); | |
538 | ||
539 | if (!rp->status) | |
540 | bacpy(&hdev->bdaddr, &rp->bdaddr); | |
541 | ||
23bb5763 JH |
542 | hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status); |
543 | } | |
544 | ||
545 | static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb) | |
546 | { | |
547 | __u8 status = *((__u8 *) skb->data); | |
548 | ||
549 | BT_DBG("%s status 0x%x", hdev->name, status); | |
550 | ||
551 | hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status); | |
a9de9248 MH |
552 | } |
553 | ||
554 | static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status) | |
555 | { | |
556 | BT_DBG("%s status 0x%x", hdev->name, status); | |
557 | ||
558 | if (status) { | |
23bb5763 | 559 | hci_req_complete(hdev, HCI_OP_INQUIRY, status); |
a9de9248 MH |
560 | |
561 | hci_conn_check_pending(hdev); | |
562 | } else | |
563 | set_bit(HCI_INQUIRY, &hdev->flags); | |
1da177e4 LT |
564 | } |
565 | ||
1da177e4 LT |
566 | static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) |
567 | { | |
a9de9248 | 568 | struct hci_cp_create_conn *cp; |
1da177e4 | 569 | struct hci_conn *conn; |
1da177e4 | 570 | |
a9de9248 MH |
571 | BT_DBG("%s status 0x%x", hdev->name, status); |
572 | ||
573 | cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN); | |
1da177e4 LT |
574 | if (!cp) |
575 | return; | |
576 | ||
577 | hci_dev_lock(hdev); | |
578 | ||
579 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); | |
580 | ||
a9de9248 | 581 | BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->bdaddr), conn); |
1da177e4 LT |
582 | |
583 | if (status) { | |
584 | if (conn && conn->state == BT_CONNECT) { | |
4c67bc74 MH |
585 | if (status != 0x0c || conn->attempt > 2) { |
586 | conn->state = BT_CLOSED; | |
587 | hci_proto_connect_cfm(conn, status); | |
588 | hci_conn_del(conn); | |
589 | } else | |
590 | conn->state = BT_CONNECT2; | |
1da177e4 LT |
591 | } |
592 | } else { | |
593 | if (!conn) { | |
594 | conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr); | |
595 | if (conn) { | |
596 | conn->out = 1; | |
597 | conn->link_mode |= HCI_LM_MASTER; | |
598 | } else | |
893ef971 | 599 | BT_ERR("No memory for new connection"); |
1da177e4 LT |
600 | } |
601 | } | |
602 | ||
603 | hci_dev_unlock(hdev); | |
604 | } | |
605 | ||
a9de9248 | 606 | static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status) |
1da177e4 | 607 | { |
a9de9248 MH |
608 | struct hci_cp_add_sco *cp; |
609 | struct hci_conn *acl, *sco; | |
610 | __u16 handle; | |
1da177e4 | 611 | |
b6a0dc82 MH |
612 | BT_DBG("%s status 0x%x", hdev->name, status); |
613 | ||
a9de9248 MH |
614 | if (!status) |
615 | return; | |
1da177e4 | 616 | |
a9de9248 MH |
617 | cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO); |
618 | if (!cp) | |
619 | return; | |
1da177e4 | 620 | |
a9de9248 | 621 | handle = __le16_to_cpu(cp->handle); |
1da177e4 | 622 | |
a9de9248 | 623 | BT_DBG("%s handle %d", hdev->name, handle); |
1da177e4 | 624 | |
a9de9248 | 625 | hci_dev_lock(hdev); |
1da177e4 | 626 | |
a9de9248 MH |
627 | acl = hci_conn_hash_lookup_handle(hdev, handle); |
628 | if (acl && (sco = acl->link)) { | |
629 | sco->state = BT_CLOSED; | |
1da177e4 | 630 | |
a9de9248 MH |
631 | hci_proto_connect_cfm(sco, status); |
632 | hci_conn_del(sco); | |
633 | } | |
1da177e4 | 634 | |
a9de9248 MH |
635 | hci_dev_unlock(hdev); |
636 | } | |
1da177e4 | 637 | |
f8558555 MH |
638 | static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status) |
639 | { | |
640 | struct hci_cp_auth_requested *cp; | |
641 | struct hci_conn *conn; | |
642 | ||
643 | BT_DBG("%s status 0x%x", hdev->name, status); | |
644 | ||
645 | if (!status) | |
646 | return; | |
647 | ||
648 | cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED); | |
649 | if (!cp) | |
650 | return; | |
651 | ||
652 | hci_dev_lock(hdev); | |
653 | ||
654 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); | |
655 | if (conn) { | |
656 | if (conn->state == BT_CONFIG) { | |
657 | hci_proto_connect_cfm(conn, status); | |
658 | hci_conn_put(conn); | |
659 | } | |
660 | } | |
661 | ||
662 | hci_dev_unlock(hdev); | |
663 | } | |
664 | ||
665 | static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status) | |
666 | { | |
667 | struct hci_cp_set_conn_encrypt *cp; | |
668 | struct hci_conn *conn; | |
669 | ||
670 | BT_DBG("%s status 0x%x", hdev->name, status); | |
671 | ||
672 | if (!status) | |
673 | return; | |
674 | ||
675 | cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT); | |
676 | if (!cp) | |
677 | return; | |
678 | ||
679 | hci_dev_lock(hdev); | |
680 | ||
681 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); | |
682 | if (conn) { | |
683 | if (conn->state == BT_CONFIG) { | |
684 | hci_proto_connect_cfm(conn, status); | |
685 | hci_conn_put(conn); | |
686 | } | |
687 | } | |
688 | ||
689 | hci_dev_unlock(hdev); | |
690 | } | |
691 | ||
127178d2 | 692 | static int hci_outgoing_auth_needed(struct hci_dev *hdev, |
392599b9 JH |
693 | struct hci_conn *conn) |
694 | { | |
392599b9 JH |
695 | if (conn->state != BT_CONFIG || !conn->out) |
696 | return 0; | |
697 | ||
765c2a96 | 698 | if (conn->pending_sec_level == BT_SECURITY_SDP) |
392599b9 JH |
699 | return 0; |
700 | ||
701 | /* Only request authentication for SSP connections or non-SSP | |
702 | * devices with sec_level HIGH */ | |
703 | if (!(hdev->ssp_mode > 0 && conn->ssp_mode > 0) && | |
765c2a96 | 704 | conn->pending_sec_level != BT_SECURITY_HIGH) |
392599b9 JH |
705 | return 0; |
706 | ||
392599b9 JH |
707 | return 1; |
708 | } | |
709 | ||
a9de9248 MH |
710 | static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status) |
711 | { | |
127178d2 JH |
712 | struct hci_cp_remote_name_req *cp; |
713 | struct hci_conn *conn; | |
714 | ||
a9de9248 | 715 | BT_DBG("%s status 0x%x", hdev->name, status); |
127178d2 JH |
716 | |
717 | /* If successful wait for the name req complete event before | |
718 | * checking for the need to do authentication */ | |
719 | if (!status) | |
720 | return; | |
721 | ||
722 | cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ); | |
723 | if (!cp) | |
724 | return; | |
725 | ||
726 | hci_dev_lock(hdev); | |
727 | ||
728 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr); | |
729 | if (conn && hci_outgoing_auth_needed(hdev, conn)) { | |
730 | struct hci_cp_auth_requested cp; | |
731 | cp.handle = __cpu_to_le16(conn->handle); | |
732 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); | |
733 | } | |
734 | ||
735 | hci_dev_unlock(hdev); | |
a9de9248 | 736 | } |
1da177e4 | 737 | |
769be974 MH |
738 | static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status) |
739 | { | |
740 | struct hci_cp_read_remote_features *cp; | |
741 | struct hci_conn *conn; | |
742 | ||
743 | BT_DBG("%s status 0x%x", hdev->name, status); | |
744 | ||
745 | if (!status) | |
746 | return; | |
747 | ||
748 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES); | |
749 | if (!cp) | |
750 | return; | |
751 | ||
752 | hci_dev_lock(hdev); | |
753 | ||
754 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); | |
755 | if (conn) { | |
756 | if (conn->state == BT_CONFIG) { | |
769be974 MH |
757 | hci_proto_connect_cfm(conn, status); |
758 | hci_conn_put(conn); | |
759 | } | |
760 | } | |
761 | ||
762 | hci_dev_unlock(hdev); | |
763 | } | |
764 | ||
765 | static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status) | |
766 | { | |
767 | struct hci_cp_read_remote_ext_features *cp; | |
768 | struct hci_conn *conn; | |
769 | ||
770 | BT_DBG("%s status 0x%x", hdev->name, status); | |
771 | ||
772 | if (!status) | |
773 | return; | |
774 | ||
775 | cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES); | |
776 | if (!cp) | |
777 | return; | |
778 | ||
779 | hci_dev_lock(hdev); | |
780 | ||
781 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); | |
782 | if (conn) { | |
783 | if (conn->state == BT_CONFIG) { | |
769be974 MH |
784 | hci_proto_connect_cfm(conn, status); |
785 | hci_conn_put(conn); | |
786 | } | |
787 | } | |
788 | ||
789 | hci_dev_unlock(hdev); | |
790 | } | |
791 | ||
a9de9248 MH |
792 | static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status) |
793 | { | |
b6a0dc82 MH |
794 | struct hci_cp_setup_sync_conn *cp; |
795 | struct hci_conn *acl, *sco; | |
796 | __u16 handle; | |
797 | ||
a9de9248 | 798 | BT_DBG("%s status 0x%x", hdev->name, status); |
b6a0dc82 MH |
799 | |
800 | if (!status) | |
801 | return; | |
802 | ||
803 | cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN); | |
804 | if (!cp) | |
805 | return; | |
806 | ||
807 | handle = __le16_to_cpu(cp->handle); | |
808 | ||
809 | BT_DBG("%s handle %d", hdev->name, handle); | |
810 | ||
811 | hci_dev_lock(hdev); | |
812 | ||
813 | acl = hci_conn_hash_lookup_handle(hdev, handle); | |
814 | if (acl && (sco = acl->link)) { | |
815 | sco->state = BT_CLOSED; | |
816 | ||
817 | hci_proto_connect_cfm(sco, status); | |
818 | hci_conn_del(sco); | |
819 | } | |
820 | ||
821 | hci_dev_unlock(hdev); | |
1da177e4 LT |
822 | } |
823 | ||
a9de9248 | 824 | static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status) |
1da177e4 | 825 | { |
a9de9248 MH |
826 | struct hci_cp_sniff_mode *cp; |
827 | struct hci_conn *conn; | |
1da177e4 | 828 | |
a9de9248 | 829 | BT_DBG("%s status 0x%x", hdev->name, status); |
04837f64 | 830 | |
a9de9248 MH |
831 | if (!status) |
832 | return; | |
04837f64 | 833 | |
a9de9248 MH |
834 | cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE); |
835 | if (!cp) | |
836 | return; | |
04837f64 | 837 | |
a9de9248 | 838 | hci_dev_lock(hdev); |
04837f64 | 839 | |
a9de9248 | 840 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
e73439d8 | 841 | if (conn) { |
a9de9248 | 842 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend); |
04837f64 | 843 | |
e73439d8 MH |
844 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend)) |
845 | hci_sco_setup(conn, status); | |
846 | } | |
847 | ||
a9de9248 MH |
848 | hci_dev_unlock(hdev); |
849 | } | |
04837f64 | 850 | |
a9de9248 MH |
851 | static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status) |
852 | { | |
853 | struct hci_cp_exit_sniff_mode *cp; | |
854 | struct hci_conn *conn; | |
04837f64 | 855 | |
a9de9248 | 856 | BT_DBG("%s status 0x%x", hdev->name, status); |
04837f64 | 857 | |
a9de9248 MH |
858 | if (!status) |
859 | return; | |
04837f64 | 860 | |
a9de9248 MH |
861 | cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE); |
862 | if (!cp) | |
863 | return; | |
04837f64 | 864 | |
a9de9248 | 865 | hci_dev_lock(hdev); |
1da177e4 | 866 | |
a9de9248 | 867 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle)); |
e73439d8 | 868 | if (conn) { |
a9de9248 | 869 | clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend); |
1da177e4 | 870 | |
e73439d8 MH |
871 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend)) |
872 | hci_sco_setup(conn, status); | |
873 | } | |
874 | ||
a9de9248 | 875 | hci_dev_unlock(hdev); |
1da177e4 LT |
876 | } |
877 | ||
1da177e4 LT |
878 | static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
879 | { | |
880 | __u8 status = *((__u8 *) skb->data); | |
881 | ||
882 | BT_DBG("%s status %d", hdev->name, status); | |
883 | ||
884 | clear_bit(HCI_INQUIRY, &hdev->flags); | |
6bd57416 | 885 | |
23bb5763 | 886 | hci_req_complete(hdev, HCI_OP_INQUIRY, status); |
6bd57416 | 887 | |
a9de9248 | 888 | hci_conn_check_pending(hdev); |
1da177e4 LT |
889 | } |
890 | ||
1da177e4 LT |
891 | static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) |
892 | { | |
45bb4bf0 | 893 | struct inquiry_data data; |
a9de9248 | 894 | struct inquiry_info *info = (void *) (skb->data + 1); |
1da177e4 LT |
895 | int num_rsp = *((__u8 *) skb->data); |
896 | ||
897 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); | |
898 | ||
45bb4bf0 MH |
899 | if (!num_rsp) |
900 | return; | |
901 | ||
1da177e4 | 902 | hci_dev_lock(hdev); |
45bb4bf0 | 903 | |
1da177e4 | 904 | for (; num_rsp; num_rsp--) { |
1da177e4 LT |
905 | bacpy(&data.bdaddr, &info->bdaddr); |
906 | data.pscan_rep_mode = info->pscan_rep_mode; | |
907 | data.pscan_period_mode = info->pscan_period_mode; | |
908 | data.pscan_mode = info->pscan_mode; | |
909 | memcpy(data.dev_class, info->dev_class, 3); | |
910 | data.clock_offset = info->clock_offset; | |
911 | data.rssi = 0x00; | |
41a96212 | 912 | data.ssp_mode = 0x00; |
1da177e4 LT |
913 | info++; |
914 | hci_inquiry_cache_update(hdev, &data); | |
915 | } | |
45bb4bf0 | 916 | |
1da177e4 LT |
917 | hci_dev_unlock(hdev); |
918 | } | |
919 | ||
1da177e4 LT |
920 | static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
921 | { | |
a9de9248 MH |
922 | struct hci_ev_conn_complete *ev = (void *) skb->data; |
923 | struct hci_conn *conn; | |
1da177e4 LT |
924 | |
925 | BT_DBG("%s", hdev->name); | |
926 | ||
927 | hci_dev_lock(hdev); | |
928 | ||
929 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); | |
9499237a MH |
930 | if (!conn) { |
931 | if (ev->link_type != SCO_LINK) | |
932 | goto unlock; | |
933 | ||
934 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); | |
935 | if (!conn) | |
936 | goto unlock; | |
937 | ||
938 | conn->type = SCO_LINK; | |
939 | } | |
1da177e4 LT |
940 | |
941 | if (!ev->status) { | |
942 | conn->handle = __le16_to_cpu(ev->handle); | |
769be974 MH |
943 | |
944 | if (conn->type == ACL_LINK) { | |
945 | conn->state = BT_CONFIG; | |
946 | hci_conn_hold(conn); | |
052b30b0 | 947 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; |
769be974 MH |
948 | } else |
949 | conn->state = BT_CONNECTED; | |
1da177e4 | 950 | |
9eba32b8 | 951 | hci_conn_hold_device(conn); |
7d0db0a3 MH |
952 | hci_conn_add_sysfs(conn); |
953 | ||
1da177e4 LT |
954 | if (test_bit(HCI_AUTH, &hdev->flags)) |
955 | conn->link_mode |= HCI_LM_AUTH; | |
956 | ||
957 | if (test_bit(HCI_ENCRYPT, &hdev->flags)) | |
958 | conn->link_mode |= HCI_LM_ENCRYPT; | |
959 | ||
04837f64 MH |
960 | /* Get remote features */ |
961 | if (conn->type == ACL_LINK) { | |
962 | struct hci_cp_read_remote_features cp; | |
963 | cp.handle = ev->handle; | |
769be974 MH |
964 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES, |
965 | sizeof(cp), &cp); | |
04837f64 MH |
966 | } |
967 | ||
1da177e4 | 968 | /* Set packet type for incoming connection */ |
a8746417 | 969 | if (!conn->out && hdev->hci_ver < 3) { |
1da177e4 LT |
970 | struct hci_cp_change_conn_ptype cp; |
971 | cp.handle = ev->handle; | |
a8746417 MH |
972 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
973 | hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, | |
974 | sizeof(cp), &cp); | |
1da177e4 LT |
975 | } |
976 | } else | |
977 | conn->state = BT_CLOSED; | |
978 | ||
e73439d8 MH |
979 | if (conn->type == ACL_LINK) |
980 | hci_sco_setup(conn, ev->status); | |
1da177e4 | 981 | |
769be974 MH |
982 | if (ev->status) { |
983 | hci_proto_connect_cfm(conn, ev->status); | |
1da177e4 | 984 | hci_conn_del(conn); |
c89b6e6b MH |
985 | } else if (ev->link_type != ACL_LINK) |
986 | hci_proto_connect_cfm(conn, ev->status); | |
1da177e4 | 987 | |
a9de9248 | 988 | unlock: |
1da177e4 | 989 | hci_dev_unlock(hdev); |
1da177e4 | 990 | |
a9de9248 | 991 | hci_conn_check_pending(hdev); |
1da177e4 LT |
992 | } |
993 | ||
a9de9248 | 994 | static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 995 | { |
a9de9248 MH |
996 | struct hci_ev_conn_request *ev = (void *) skb->data; |
997 | int mask = hdev->link_mode; | |
1da177e4 | 998 | |
a9de9248 MH |
999 | BT_DBG("%s bdaddr %s type 0x%x", hdev->name, |
1000 | batostr(&ev->bdaddr), ev->link_type); | |
1da177e4 | 1001 | |
a9de9248 | 1002 | mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type); |
1da177e4 | 1003 | |
f0358568 | 1004 | if ((mask & HCI_LM_ACCEPT) && !hci_blacklist_lookup(hdev, &ev->bdaddr)) { |
a9de9248 | 1005 | /* Connection accepted */ |
c7bdd502 | 1006 | struct inquiry_entry *ie; |
1da177e4 | 1007 | struct hci_conn *conn; |
1da177e4 | 1008 | |
a9de9248 | 1009 | hci_dev_lock(hdev); |
b6a0dc82 | 1010 | |
cc11b9c1 AE |
1011 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
1012 | if (ie) | |
c7bdd502 MH |
1013 | memcpy(ie->data.dev_class, ev->dev_class, 3); |
1014 | ||
a9de9248 MH |
1015 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); |
1016 | if (!conn) { | |
cc11b9c1 AE |
1017 | conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr); |
1018 | if (!conn) { | |
893ef971 | 1019 | BT_ERR("No memory for new connection"); |
a9de9248 MH |
1020 | hci_dev_unlock(hdev); |
1021 | return; | |
1da177e4 LT |
1022 | } |
1023 | } | |
b6a0dc82 | 1024 | |
a9de9248 MH |
1025 | memcpy(conn->dev_class, ev->dev_class, 3); |
1026 | conn->state = BT_CONNECT; | |
b6a0dc82 | 1027 | |
a9de9248 | 1028 | hci_dev_unlock(hdev); |
1da177e4 | 1029 | |
b6a0dc82 MH |
1030 | if (ev->link_type == ACL_LINK || !lmp_esco_capable(hdev)) { |
1031 | struct hci_cp_accept_conn_req cp; | |
1da177e4 | 1032 | |
b6a0dc82 MH |
1033 | bacpy(&cp.bdaddr, &ev->bdaddr); |
1034 | ||
1035 | if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER)) | |
1036 | cp.role = 0x00; /* Become master */ | |
1037 | else | |
1038 | cp.role = 0x01; /* Remain slave */ | |
1039 | ||
1040 | hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, | |
1041 | sizeof(cp), &cp); | |
1042 | } else { | |
1043 | struct hci_cp_accept_sync_conn_req cp; | |
1044 | ||
1045 | bacpy(&cp.bdaddr, &ev->bdaddr); | |
a8746417 | 1046 | cp.pkt_type = cpu_to_le16(conn->pkt_type); |
b6a0dc82 MH |
1047 | |
1048 | cp.tx_bandwidth = cpu_to_le32(0x00001f40); | |
1049 | cp.rx_bandwidth = cpu_to_le32(0x00001f40); | |
1050 | cp.max_latency = cpu_to_le16(0xffff); | |
1051 | cp.content_format = cpu_to_le16(hdev->voice_setting); | |
1052 | cp.retrans_effort = 0xff; | |
1da177e4 | 1053 | |
b6a0dc82 MH |
1054 | hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ, |
1055 | sizeof(cp), &cp); | |
1056 | } | |
a9de9248 MH |
1057 | } else { |
1058 | /* Connection rejected */ | |
1059 | struct hci_cp_reject_conn_req cp; | |
1da177e4 | 1060 | |
a9de9248 MH |
1061 | bacpy(&cp.bdaddr, &ev->bdaddr); |
1062 | cp.reason = 0x0f; | |
1063 | hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp); | |
1da177e4 | 1064 | } |
1da177e4 LT |
1065 | } |
1066 | ||
a9de9248 | 1067 | static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
04837f64 | 1068 | { |
a9de9248 | 1069 | struct hci_ev_disconn_complete *ev = (void *) skb->data; |
04837f64 MH |
1070 | struct hci_conn *conn; |
1071 | ||
1072 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1073 | ||
a9de9248 MH |
1074 | if (ev->status) |
1075 | return; | |
1076 | ||
04837f64 MH |
1077 | hci_dev_lock(hdev); |
1078 | ||
1079 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | |
1080 | if (conn) { | |
a9de9248 | 1081 | conn->state = BT_CLOSED; |
7d0db0a3 | 1082 | |
2950f21a | 1083 | hci_proto_disconn_cfm(conn, ev->reason); |
a9de9248 | 1084 | hci_conn_del(conn); |
04837f64 MH |
1085 | } |
1086 | ||
1087 | hci_dev_unlock(hdev); | |
1088 | } | |
1089 | ||
1da177e4 LT |
1090 | static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1091 | { | |
a9de9248 | 1092 | struct hci_ev_auth_complete *ev = (void *) skb->data; |
04837f64 | 1093 | struct hci_conn *conn; |
1da177e4 LT |
1094 | |
1095 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1096 | ||
1097 | hci_dev_lock(hdev); | |
1098 | ||
04837f64 | 1099 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
1da177e4 | 1100 | if (conn) { |
765c2a96 | 1101 | if (!ev->status) { |
1da177e4 | 1102 | conn->link_mode |= HCI_LM_AUTH; |
765c2a96 JH |
1103 | conn->sec_level = conn->pending_sec_level; |
1104 | } else | |
da213f41 | 1105 | conn->sec_level = BT_SECURITY_LOW; |
1da177e4 LT |
1106 | |
1107 | clear_bit(HCI_CONN_AUTH_PEND, &conn->pend); | |
1108 | ||
f8558555 MH |
1109 | if (conn->state == BT_CONFIG) { |
1110 | if (!ev->status && hdev->ssp_mode > 0 && | |
1111 | conn->ssp_mode > 0) { | |
1112 | struct hci_cp_set_conn_encrypt cp; | |
1113 | cp.handle = ev->handle; | |
1114 | cp.encrypt = 0x01; | |
1115 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, | |
1116 | sizeof(cp), &cp); | |
1117 | } else { | |
1118 | conn->state = BT_CONNECTED; | |
1119 | hci_proto_connect_cfm(conn, ev->status); | |
1120 | hci_conn_put(conn); | |
1121 | } | |
052b30b0 | 1122 | } else { |
f8558555 | 1123 | hci_auth_cfm(conn, ev->status); |
1da177e4 | 1124 | |
052b30b0 MH |
1125 | hci_conn_hold(conn); |
1126 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; | |
1127 | hci_conn_put(conn); | |
1128 | } | |
1129 | ||
1da177e4 LT |
1130 | if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) { |
1131 | if (!ev->status) { | |
1132 | struct hci_cp_set_conn_encrypt cp; | |
f8558555 MH |
1133 | cp.handle = ev->handle; |
1134 | cp.encrypt = 0x01; | |
1135 | hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, | |
1136 | sizeof(cp), &cp); | |
1da177e4 LT |
1137 | } else { |
1138 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); | |
1139 | hci_encrypt_cfm(conn, ev->status, 0x00); | |
1140 | } | |
1141 | } | |
1142 | } | |
1143 | ||
1144 | hci_dev_unlock(hdev); | |
1145 | } | |
1146 | ||
a9de9248 | 1147 | static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 1148 | { |
127178d2 JH |
1149 | struct hci_ev_remote_name *ev = (void *) skb->data; |
1150 | struct hci_conn *conn; | |
1151 | ||
a9de9248 | 1152 | BT_DBG("%s", hdev->name); |
1da177e4 | 1153 | |
a9de9248 | 1154 | hci_conn_check_pending(hdev); |
127178d2 JH |
1155 | |
1156 | hci_dev_lock(hdev); | |
1157 | ||
1158 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | |
1159 | if (conn && hci_outgoing_auth_needed(hdev, conn)) { | |
1160 | struct hci_cp_auth_requested cp; | |
1161 | cp.handle = __cpu_to_le16(conn->handle); | |
1162 | hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp); | |
1163 | } | |
1164 | ||
1165 | hci_dev_unlock(hdev); | |
a9de9248 MH |
1166 | } |
1167 | ||
1168 | static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1169 | { | |
1170 | struct hci_ev_encrypt_change *ev = (void *) skb->data; | |
1171 | struct hci_conn *conn; | |
1172 | ||
1173 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1da177e4 LT |
1174 | |
1175 | hci_dev_lock(hdev); | |
1176 | ||
04837f64 | 1177 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
1da177e4 LT |
1178 | if (conn) { |
1179 | if (!ev->status) { | |
ae293196 MH |
1180 | if (ev->encrypt) { |
1181 | /* Encryption implies authentication */ | |
1182 | conn->link_mode |= HCI_LM_AUTH; | |
1da177e4 | 1183 | conn->link_mode |= HCI_LM_ENCRYPT; |
ae293196 | 1184 | } else |
1da177e4 LT |
1185 | conn->link_mode &= ~HCI_LM_ENCRYPT; |
1186 | } | |
1187 | ||
1188 | clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend); | |
1189 | ||
f8558555 MH |
1190 | if (conn->state == BT_CONFIG) { |
1191 | if (!ev->status) | |
1192 | conn->state = BT_CONNECTED; | |
1193 | ||
1194 | hci_proto_connect_cfm(conn, ev->status); | |
1195 | hci_conn_put(conn); | |
1196 | } else | |
1197 | hci_encrypt_cfm(conn, ev->status, ev->encrypt); | |
1da177e4 LT |
1198 | } |
1199 | ||
1200 | hci_dev_unlock(hdev); | |
1201 | } | |
1202 | ||
a9de9248 | 1203 | static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 1204 | { |
a9de9248 | 1205 | struct hci_ev_change_link_key_complete *ev = (void *) skb->data; |
04837f64 | 1206 | struct hci_conn *conn; |
1da177e4 LT |
1207 | |
1208 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1209 | ||
1210 | hci_dev_lock(hdev); | |
1211 | ||
04837f64 | 1212 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
1da177e4 LT |
1213 | if (conn) { |
1214 | if (!ev->status) | |
1215 | conn->link_mode |= HCI_LM_SECURE; | |
1216 | ||
1217 | clear_bit(HCI_CONN_AUTH_PEND, &conn->pend); | |
1218 | ||
1219 | hci_key_change_cfm(conn, ev->status); | |
1220 | } | |
1221 | ||
1222 | hci_dev_unlock(hdev); | |
1223 | } | |
1224 | ||
a9de9248 | 1225 | static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 1226 | { |
a9de9248 MH |
1227 | struct hci_ev_remote_features *ev = (void *) skb->data; |
1228 | struct hci_conn *conn; | |
1229 | ||
1230 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1231 | ||
a9de9248 MH |
1232 | hci_dev_lock(hdev); |
1233 | ||
1234 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | |
ccd556fe JH |
1235 | if (!conn) |
1236 | goto unlock; | |
769be974 | 1237 | |
ccd556fe JH |
1238 | if (!ev->status) |
1239 | memcpy(conn->features, ev->features, 8); | |
1240 | ||
1241 | if (conn->state != BT_CONFIG) | |
1242 | goto unlock; | |
1243 | ||
1244 | if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) { | |
1245 | struct hci_cp_read_remote_ext_features cp; | |
1246 | cp.handle = ev->handle; | |
1247 | cp.page = 0x01; | |
1248 | hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES, | |
bdb7524a | 1249 | sizeof(cp), &cp); |
392599b9 JH |
1250 | goto unlock; |
1251 | } | |
1252 | ||
127178d2 JH |
1253 | if (!ev->status) { |
1254 | struct hci_cp_remote_name_req cp; | |
1255 | memset(&cp, 0, sizeof(cp)); | |
1256 | bacpy(&cp.bdaddr, &conn->dst); | |
1257 | cp.pscan_rep_mode = 0x02; | |
1258 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); | |
1259 | } | |
392599b9 | 1260 | |
127178d2 | 1261 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
ccd556fe JH |
1262 | conn->state = BT_CONNECTED; |
1263 | hci_proto_connect_cfm(conn, ev->status); | |
1264 | hci_conn_put(conn); | |
769be974 | 1265 | } |
a9de9248 | 1266 | |
ccd556fe | 1267 | unlock: |
a9de9248 | 1268 | hci_dev_unlock(hdev); |
1da177e4 LT |
1269 | } |
1270 | ||
a9de9248 | 1271 | static inline void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 1272 | { |
a9de9248 | 1273 | BT_DBG("%s", hdev->name); |
1da177e4 LT |
1274 | } |
1275 | ||
a9de9248 | 1276 | static inline void hci_qos_setup_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 1277 | { |
a9de9248 | 1278 | BT_DBG("%s", hdev->name); |
1da177e4 LT |
1279 | } |
1280 | ||
a9de9248 MH |
1281 | static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1282 | { | |
1283 | struct hci_ev_cmd_complete *ev = (void *) skb->data; | |
1284 | __u16 opcode; | |
1285 | ||
1286 | skb_pull(skb, sizeof(*ev)); | |
1287 | ||
1288 | opcode = __le16_to_cpu(ev->opcode); | |
1289 | ||
1290 | switch (opcode) { | |
1291 | case HCI_OP_INQUIRY_CANCEL: | |
1292 | hci_cc_inquiry_cancel(hdev, skb); | |
1293 | break; | |
1294 | ||
1295 | case HCI_OP_EXIT_PERIODIC_INQ: | |
1296 | hci_cc_exit_periodic_inq(hdev, skb); | |
1297 | break; | |
1298 | ||
1299 | case HCI_OP_REMOTE_NAME_REQ_CANCEL: | |
1300 | hci_cc_remote_name_req_cancel(hdev, skb); | |
1301 | break; | |
1302 | ||
1303 | case HCI_OP_ROLE_DISCOVERY: | |
1304 | hci_cc_role_discovery(hdev, skb); | |
1305 | break; | |
1306 | ||
e4e8e37c MH |
1307 | case HCI_OP_READ_LINK_POLICY: |
1308 | hci_cc_read_link_policy(hdev, skb); | |
1309 | break; | |
1310 | ||
a9de9248 MH |
1311 | case HCI_OP_WRITE_LINK_POLICY: |
1312 | hci_cc_write_link_policy(hdev, skb); | |
1313 | break; | |
1314 | ||
e4e8e37c MH |
1315 | case HCI_OP_READ_DEF_LINK_POLICY: |
1316 | hci_cc_read_def_link_policy(hdev, skb); | |
1317 | break; | |
1318 | ||
1319 | case HCI_OP_WRITE_DEF_LINK_POLICY: | |
1320 | hci_cc_write_def_link_policy(hdev, skb); | |
1321 | break; | |
1322 | ||
a9de9248 MH |
1323 | case HCI_OP_RESET: |
1324 | hci_cc_reset(hdev, skb); | |
1325 | break; | |
1326 | ||
1327 | case HCI_OP_WRITE_LOCAL_NAME: | |
1328 | hci_cc_write_local_name(hdev, skb); | |
1329 | break; | |
1330 | ||
1331 | case HCI_OP_READ_LOCAL_NAME: | |
1332 | hci_cc_read_local_name(hdev, skb); | |
1333 | break; | |
1334 | ||
1335 | case HCI_OP_WRITE_AUTH_ENABLE: | |
1336 | hci_cc_write_auth_enable(hdev, skb); | |
1337 | break; | |
1338 | ||
1339 | case HCI_OP_WRITE_ENCRYPT_MODE: | |
1340 | hci_cc_write_encrypt_mode(hdev, skb); | |
1341 | break; | |
1342 | ||
1343 | case HCI_OP_WRITE_SCAN_ENABLE: | |
1344 | hci_cc_write_scan_enable(hdev, skb); | |
1345 | break; | |
1346 | ||
1347 | case HCI_OP_READ_CLASS_OF_DEV: | |
1348 | hci_cc_read_class_of_dev(hdev, skb); | |
1349 | break; | |
1350 | ||
1351 | case HCI_OP_WRITE_CLASS_OF_DEV: | |
1352 | hci_cc_write_class_of_dev(hdev, skb); | |
1353 | break; | |
1354 | ||
1355 | case HCI_OP_READ_VOICE_SETTING: | |
1356 | hci_cc_read_voice_setting(hdev, skb); | |
1357 | break; | |
1358 | ||
1359 | case HCI_OP_WRITE_VOICE_SETTING: | |
1360 | hci_cc_write_voice_setting(hdev, skb); | |
1361 | break; | |
1362 | ||
1363 | case HCI_OP_HOST_BUFFER_SIZE: | |
1364 | hci_cc_host_buffer_size(hdev, skb); | |
1365 | break; | |
1366 | ||
333140b5 MH |
1367 | case HCI_OP_READ_SSP_MODE: |
1368 | hci_cc_read_ssp_mode(hdev, skb); | |
1369 | break; | |
1370 | ||
1371 | case HCI_OP_WRITE_SSP_MODE: | |
1372 | hci_cc_write_ssp_mode(hdev, skb); | |
1373 | break; | |
1374 | ||
a9de9248 MH |
1375 | case HCI_OP_READ_LOCAL_VERSION: |
1376 | hci_cc_read_local_version(hdev, skb); | |
1377 | break; | |
1378 | ||
1379 | case HCI_OP_READ_LOCAL_COMMANDS: | |
1380 | hci_cc_read_local_commands(hdev, skb); | |
1381 | break; | |
1382 | ||
1383 | case HCI_OP_READ_LOCAL_FEATURES: | |
1384 | hci_cc_read_local_features(hdev, skb); | |
1385 | break; | |
1386 | ||
1387 | case HCI_OP_READ_BUFFER_SIZE: | |
1388 | hci_cc_read_buffer_size(hdev, skb); | |
1389 | break; | |
1390 | ||
1391 | case HCI_OP_READ_BD_ADDR: | |
1392 | hci_cc_read_bd_addr(hdev, skb); | |
1393 | break; | |
1394 | ||
23bb5763 JH |
1395 | case HCI_OP_WRITE_CA_TIMEOUT: |
1396 | hci_cc_write_ca_timeout(hdev, skb); | |
1397 | break; | |
1398 | ||
a9de9248 MH |
1399 | default: |
1400 | BT_DBG("%s opcode 0x%x", hdev->name, opcode); | |
1401 | break; | |
1402 | } | |
1403 | ||
1404 | if (ev->ncmd) { | |
1405 | atomic_set(&hdev->cmd_cnt, 1); | |
1406 | if (!skb_queue_empty(&hdev->cmd_q)) | |
c78ae283 | 1407 | tasklet_schedule(&hdev->cmd_task); |
a9de9248 MH |
1408 | } |
1409 | } | |
1410 | ||
1411 | static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1412 | { | |
1413 | struct hci_ev_cmd_status *ev = (void *) skb->data; | |
1414 | __u16 opcode; | |
1415 | ||
1416 | skb_pull(skb, sizeof(*ev)); | |
1417 | ||
1418 | opcode = __le16_to_cpu(ev->opcode); | |
1419 | ||
1420 | switch (opcode) { | |
1421 | case HCI_OP_INQUIRY: | |
1422 | hci_cs_inquiry(hdev, ev->status); | |
1423 | break; | |
1424 | ||
1425 | case HCI_OP_CREATE_CONN: | |
1426 | hci_cs_create_conn(hdev, ev->status); | |
1427 | break; | |
1428 | ||
1429 | case HCI_OP_ADD_SCO: | |
1430 | hci_cs_add_sco(hdev, ev->status); | |
1431 | break; | |
1432 | ||
f8558555 MH |
1433 | case HCI_OP_AUTH_REQUESTED: |
1434 | hci_cs_auth_requested(hdev, ev->status); | |
1435 | break; | |
1436 | ||
1437 | case HCI_OP_SET_CONN_ENCRYPT: | |
1438 | hci_cs_set_conn_encrypt(hdev, ev->status); | |
1439 | break; | |
1440 | ||
a9de9248 MH |
1441 | case HCI_OP_REMOTE_NAME_REQ: |
1442 | hci_cs_remote_name_req(hdev, ev->status); | |
1443 | break; | |
1444 | ||
769be974 MH |
1445 | case HCI_OP_READ_REMOTE_FEATURES: |
1446 | hci_cs_read_remote_features(hdev, ev->status); | |
1447 | break; | |
1448 | ||
1449 | case HCI_OP_READ_REMOTE_EXT_FEATURES: | |
1450 | hci_cs_read_remote_ext_features(hdev, ev->status); | |
1451 | break; | |
1452 | ||
a9de9248 MH |
1453 | case HCI_OP_SETUP_SYNC_CONN: |
1454 | hci_cs_setup_sync_conn(hdev, ev->status); | |
1455 | break; | |
1456 | ||
1457 | case HCI_OP_SNIFF_MODE: | |
1458 | hci_cs_sniff_mode(hdev, ev->status); | |
1459 | break; | |
1460 | ||
1461 | case HCI_OP_EXIT_SNIFF_MODE: | |
1462 | hci_cs_exit_sniff_mode(hdev, ev->status); | |
1463 | break; | |
1464 | ||
1465 | default: | |
1466 | BT_DBG("%s opcode 0x%x", hdev->name, opcode); | |
1467 | break; | |
1468 | } | |
1469 | ||
1470 | if (ev->ncmd) { | |
1471 | atomic_set(&hdev->cmd_cnt, 1); | |
1472 | if (!skb_queue_empty(&hdev->cmd_q)) | |
c78ae283 | 1473 | tasklet_schedule(&hdev->cmd_task); |
a9de9248 MH |
1474 | } |
1475 | } | |
1476 | ||
1477 | static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1478 | { | |
1479 | struct hci_ev_role_change *ev = (void *) skb->data; | |
1480 | struct hci_conn *conn; | |
1481 | ||
1482 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1483 | ||
1484 | hci_dev_lock(hdev); | |
1485 | ||
1486 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | |
1487 | if (conn) { | |
1488 | if (!ev->status) { | |
1489 | if (ev->role) | |
1490 | conn->link_mode &= ~HCI_LM_MASTER; | |
1491 | else | |
1492 | conn->link_mode |= HCI_LM_MASTER; | |
1493 | } | |
1494 | ||
1495 | clear_bit(HCI_CONN_RSWITCH_PEND, &conn->pend); | |
1496 | ||
1497 | hci_role_switch_cfm(conn, ev->status, ev->role); | |
1498 | } | |
1499 | ||
1500 | hci_dev_unlock(hdev); | |
1501 | } | |
1502 | ||
1503 | static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1504 | { | |
1505 | struct hci_ev_num_comp_pkts *ev = (void *) skb->data; | |
1506 | __le16 *ptr; | |
1507 | int i; | |
1508 | ||
1509 | skb_pull(skb, sizeof(*ev)); | |
1510 | ||
1511 | BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl); | |
1512 | ||
1513 | if (skb->len < ev->num_hndl * 4) { | |
1514 | BT_DBG("%s bad parameters", hdev->name); | |
1515 | return; | |
1516 | } | |
1517 | ||
1518 | tasklet_disable(&hdev->tx_task); | |
1519 | ||
1520 | for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) { | |
1521 | struct hci_conn *conn; | |
1522 | __u16 handle, count; | |
1523 | ||
83985319 HH |
1524 | handle = get_unaligned_le16(ptr++); |
1525 | count = get_unaligned_le16(ptr++); | |
a9de9248 MH |
1526 | |
1527 | conn = hci_conn_hash_lookup_handle(hdev, handle); | |
1528 | if (conn) { | |
1529 | conn->sent -= count; | |
1530 | ||
1531 | if (conn->type == ACL_LINK) { | |
70f23020 AE |
1532 | hdev->acl_cnt += count; |
1533 | if (hdev->acl_cnt > hdev->acl_pkts) | |
a9de9248 MH |
1534 | hdev->acl_cnt = hdev->acl_pkts; |
1535 | } else { | |
70f23020 AE |
1536 | hdev->sco_cnt += count; |
1537 | if (hdev->sco_cnt > hdev->sco_pkts) | |
a9de9248 MH |
1538 | hdev->sco_cnt = hdev->sco_pkts; |
1539 | } | |
1540 | } | |
1541 | } | |
1542 | ||
c78ae283 | 1543 | tasklet_schedule(&hdev->tx_task); |
a9de9248 MH |
1544 | |
1545 | tasklet_enable(&hdev->tx_task); | |
1546 | } | |
1547 | ||
1548 | static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
04837f64 | 1549 | { |
a9de9248 | 1550 | struct hci_ev_mode_change *ev = (void *) skb->data; |
04837f64 MH |
1551 | struct hci_conn *conn; |
1552 | ||
1553 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1554 | ||
1555 | hci_dev_lock(hdev); | |
1556 | ||
1557 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | |
a9de9248 MH |
1558 | if (conn) { |
1559 | conn->mode = ev->mode; | |
1560 | conn->interval = __le16_to_cpu(ev->interval); | |
1561 | ||
1562 | if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) { | |
1563 | if (conn->mode == HCI_CM_ACTIVE) | |
1564 | conn->power_save = 1; | |
1565 | else | |
1566 | conn->power_save = 0; | |
1567 | } | |
e73439d8 MH |
1568 | |
1569 | if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend)) | |
1570 | hci_sco_setup(conn, ev->status); | |
04837f64 MH |
1571 | } |
1572 | ||
1573 | hci_dev_unlock(hdev); | |
1574 | } | |
1575 | ||
a9de9248 MH |
1576 | static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1577 | { | |
052b30b0 MH |
1578 | struct hci_ev_pin_code_req *ev = (void *) skb->data; |
1579 | struct hci_conn *conn; | |
1580 | ||
a9de9248 | 1581 | BT_DBG("%s", hdev->name); |
052b30b0 MH |
1582 | |
1583 | hci_dev_lock(hdev); | |
1584 | ||
1585 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | |
3d7a9d1c | 1586 | if (conn && conn->state == BT_CONNECTED) { |
052b30b0 MH |
1587 | hci_conn_hold(conn); |
1588 | conn->disc_timeout = HCI_PAIRING_TIMEOUT; | |
1589 | hci_conn_put(conn); | |
1590 | } | |
1591 | ||
1592 | hci_dev_unlock(hdev); | |
a9de9248 MH |
1593 | } |
1594 | ||
1595 | static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1596 | { | |
1597 | BT_DBG("%s", hdev->name); | |
1598 | } | |
1599 | ||
1600 | static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1601 | { | |
052b30b0 MH |
1602 | struct hci_ev_link_key_notify *ev = (void *) skb->data; |
1603 | struct hci_conn *conn; | |
1604 | ||
a9de9248 | 1605 | BT_DBG("%s", hdev->name); |
052b30b0 MH |
1606 | |
1607 | hci_dev_lock(hdev); | |
1608 | ||
1609 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | |
1610 | if (conn) { | |
1611 | hci_conn_hold(conn); | |
1612 | conn->disc_timeout = HCI_DISCONN_TIMEOUT; | |
1613 | hci_conn_put(conn); | |
1614 | } | |
1615 | ||
1616 | hci_dev_unlock(hdev); | |
a9de9248 MH |
1617 | } |
1618 | ||
1da177e4 LT |
1619 | static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1620 | { | |
a9de9248 | 1621 | struct hci_ev_clock_offset *ev = (void *) skb->data; |
04837f64 | 1622 | struct hci_conn *conn; |
1da177e4 LT |
1623 | |
1624 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1625 | ||
1626 | hci_dev_lock(hdev); | |
1627 | ||
04837f64 | 1628 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); |
1da177e4 LT |
1629 | if (conn && !ev->status) { |
1630 | struct inquiry_entry *ie; | |
1631 | ||
cc11b9c1 AE |
1632 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
1633 | if (ie) { | |
1da177e4 LT |
1634 | ie->data.clock_offset = ev->clock_offset; |
1635 | ie->timestamp = jiffies; | |
1636 | } | |
1637 | } | |
1638 | ||
1639 | hci_dev_unlock(hdev); | |
1640 | } | |
1641 | ||
a8746417 MH |
1642 | static inline void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1643 | { | |
1644 | struct hci_ev_pkt_type_change *ev = (void *) skb->data; | |
1645 | struct hci_conn *conn; | |
1646 | ||
1647 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1648 | ||
1649 | hci_dev_lock(hdev); | |
1650 | ||
1651 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | |
1652 | if (conn && !ev->status) | |
1653 | conn->pkt_type = __le16_to_cpu(ev->pkt_type); | |
1654 | ||
1655 | hci_dev_unlock(hdev); | |
1656 | } | |
1657 | ||
85a1e930 MH |
1658 | static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1659 | { | |
a9de9248 | 1660 | struct hci_ev_pscan_rep_mode *ev = (void *) skb->data; |
85a1e930 MH |
1661 | struct inquiry_entry *ie; |
1662 | ||
1663 | BT_DBG("%s", hdev->name); | |
1664 | ||
1665 | hci_dev_lock(hdev); | |
1666 | ||
cc11b9c1 AE |
1667 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
1668 | if (ie) { | |
85a1e930 MH |
1669 | ie->data.pscan_rep_mode = ev->pscan_rep_mode; |
1670 | ie->timestamp = jiffies; | |
1671 | } | |
1672 | ||
1673 | hci_dev_unlock(hdev); | |
1674 | } | |
1675 | ||
a9de9248 MH |
1676 | static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1677 | { | |
1678 | struct inquiry_data data; | |
1679 | int num_rsp = *((__u8 *) skb->data); | |
1680 | ||
1681 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); | |
1682 | ||
1683 | if (!num_rsp) | |
1684 | return; | |
1685 | ||
1686 | hci_dev_lock(hdev); | |
1687 | ||
1688 | if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) { | |
1689 | struct inquiry_info_with_rssi_and_pscan_mode *info = (void *) (skb->data + 1); | |
1690 | ||
1691 | for (; num_rsp; num_rsp--) { | |
1692 | bacpy(&data.bdaddr, &info->bdaddr); | |
1693 | data.pscan_rep_mode = info->pscan_rep_mode; | |
1694 | data.pscan_period_mode = info->pscan_period_mode; | |
1695 | data.pscan_mode = info->pscan_mode; | |
1696 | memcpy(data.dev_class, info->dev_class, 3); | |
1697 | data.clock_offset = info->clock_offset; | |
1698 | data.rssi = info->rssi; | |
41a96212 | 1699 | data.ssp_mode = 0x00; |
a9de9248 MH |
1700 | info++; |
1701 | hci_inquiry_cache_update(hdev, &data); | |
1702 | } | |
1703 | } else { | |
1704 | struct inquiry_info_with_rssi *info = (void *) (skb->data + 1); | |
1705 | ||
1706 | for (; num_rsp; num_rsp--) { | |
1707 | bacpy(&data.bdaddr, &info->bdaddr); | |
1708 | data.pscan_rep_mode = info->pscan_rep_mode; | |
1709 | data.pscan_period_mode = info->pscan_period_mode; | |
1710 | data.pscan_mode = 0x00; | |
1711 | memcpy(data.dev_class, info->dev_class, 3); | |
1712 | data.clock_offset = info->clock_offset; | |
1713 | data.rssi = info->rssi; | |
41a96212 | 1714 | data.ssp_mode = 0x00; |
a9de9248 MH |
1715 | info++; |
1716 | hci_inquiry_cache_update(hdev, &data); | |
1717 | } | |
1718 | } | |
1719 | ||
1720 | hci_dev_unlock(hdev); | |
1721 | } | |
1722 | ||
1723 | static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1724 | { | |
41a96212 MH |
1725 | struct hci_ev_remote_ext_features *ev = (void *) skb->data; |
1726 | struct hci_conn *conn; | |
1727 | ||
a9de9248 | 1728 | BT_DBG("%s", hdev->name); |
41a96212 | 1729 | |
41a96212 MH |
1730 | hci_dev_lock(hdev); |
1731 | ||
1732 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | |
ccd556fe JH |
1733 | if (!conn) |
1734 | goto unlock; | |
41a96212 | 1735 | |
ccd556fe JH |
1736 | if (!ev->status && ev->page == 0x01) { |
1737 | struct inquiry_entry *ie; | |
41a96212 | 1738 | |
cc11b9c1 AE |
1739 | ie = hci_inquiry_cache_lookup(hdev, &conn->dst); |
1740 | if (ie) | |
ccd556fe | 1741 | ie->data.ssp_mode = (ev->features[0] & 0x01); |
769be974 | 1742 | |
ccd556fe JH |
1743 | conn->ssp_mode = (ev->features[0] & 0x01); |
1744 | } | |
1745 | ||
1746 | if (conn->state != BT_CONFIG) | |
1747 | goto unlock; | |
1748 | ||
127178d2 JH |
1749 | if (!ev->status) { |
1750 | struct hci_cp_remote_name_req cp; | |
1751 | memset(&cp, 0, sizeof(cp)); | |
1752 | bacpy(&cp.bdaddr, &conn->dst); | |
1753 | cp.pscan_rep_mode = 0x02; | |
1754 | hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp); | |
1755 | } | |
392599b9 | 1756 | |
127178d2 | 1757 | if (!hci_outgoing_auth_needed(hdev, conn)) { |
ccd556fe JH |
1758 | conn->state = BT_CONNECTED; |
1759 | hci_proto_connect_cfm(conn, ev->status); | |
1760 | hci_conn_put(conn); | |
41a96212 MH |
1761 | } |
1762 | ||
ccd556fe | 1763 | unlock: |
41a96212 | 1764 | hci_dev_unlock(hdev); |
a9de9248 MH |
1765 | } |
1766 | ||
1767 | static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1768 | { | |
b6a0dc82 MH |
1769 | struct hci_ev_sync_conn_complete *ev = (void *) skb->data; |
1770 | struct hci_conn *conn; | |
1771 | ||
1772 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1773 | ||
1774 | hci_dev_lock(hdev); | |
1775 | ||
1776 | conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr); | |
9dc0a3af MH |
1777 | if (!conn) { |
1778 | if (ev->link_type == ESCO_LINK) | |
1779 | goto unlock; | |
1780 | ||
1781 | conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr); | |
1782 | if (!conn) | |
1783 | goto unlock; | |
1784 | ||
1785 | conn->type = SCO_LINK; | |
1786 | } | |
b6a0dc82 | 1787 | |
732547f9 MH |
1788 | switch (ev->status) { |
1789 | case 0x00: | |
b6a0dc82 MH |
1790 | conn->handle = __le16_to_cpu(ev->handle); |
1791 | conn->state = BT_CONNECTED; | |
7d0db0a3 | 1792 | |
9eba32b8 | 1793 | hci_conn_hold_device(conn); |
7d0db0a3 | 1794 | hci_conn_add_sysfs(conn); |
732547f9 MH |
1795 | break; |
1796 | ||
705e5711 | 1797 | case 0x11: /* Unsupported Feature or Parameter Value */ |
732547f9 | 1798 | case 0x1c: /* SCO interval rejected */ |
1038a00b | 1799 | case 0x1a: /* Unsupported Remote Feature */ |
732547f9 MH |
1800 | case 0x1f: /* Unspecified error */ |
1801 | if (conn->out && conn->attempt < 2) { | |
1802 | conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) | | |
1803 | (hdev->esco_type & EDR_ESCO_MASK); | |
1804 | hci_setup_sync(conn, conn->link->handle); | |
1805 | goto unlock; | |
1806 | } | |
1807 | /* fall through */ | |
1808 | ||
1809 | default: | |
b6a0dc82 | 1810 | conn->state = BT_CLOSED; |
732547f9 MH |
1811 | break; |
1812 | } | |
b6a0dc82 MH |
1813 | |
1814 | hci_proto_connect_cfm(conn, ev->status); | |
1815 | if (ev->status) | |
1816 | hci_conn_del(conn); | |
1817 | ||
1818 | unlock: | |
1819 | hci_dev_unlock(hdev); | |
a9de9248 MH |
1820 | } |
1821 | ||
1822 | static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1823 | { | |
1824 | BT_DBG("%s", hdev->name); | |
1825 | } | |
1826 | ||
04837f64 MH |
1827 | static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1828 | { | |
a9de9248 | 1829 | struct hci_ev_sniff_subrate *ev = (void *) skb->data; |
04837f64 MH |
1830 | struct hci_conn *conn; |
1831 | ||
1832 | BT_DBG("%s status %d", hdev->name, ev->status); | |
1833 | ||
1834 | hci_dev_lock(hdev); | |
1835 | ||
1836 | conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle)); | |
1837 | if (conn) { | |
1838 | } | |
1839 | ||
1840 | hci_dev_unlock(hdev); | |
1841 | } | |
1842 | ||
a9de9248 | 1843 | static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1da177e4 | 1844 | { |
a9de9248 MH |
1845 | struct inquiry_data data; |
1846 | struct extended_inquiry_info *info = (void *) (skb->data + 1); | |
1847 | int num_rsp = *((__u8 *) skb->data); | |
1da177e4 | 1848 | |
a9de9248 | 1849 | BT_DBG("%s num_rsp %d", hdev->name, num_rsp); |
1da177e4 | 1850 | |
a9de9248 MH |
1851 | if (!num_rsp) |
1852 | return; | |
1da177e4 | 1853 | |
a9de9248 MH |
1854 | hci_dev_lock(hdev); |
1855 | ||
1856 | for (; num_rsp; num_rsp--) { | |
1857 | bacpy(&data.bdaddr, &info->bdaddr); | |
1858 | data.pscan_rep_mode = info->pscan_rep_mode; | |
1859 | data.pscan_period_mode = info->pscan_period_mode; | |
1860 | data.pscan_mode = 0x00; | |
1861 | memcpy(data.dev_class, info->dev_class, 3); | |
1862 | data.clock_offset = info->clock_offset; | |
1863 | data.rssi = info->rssi; | |
41a96212 | 1864 | data.ssp_mode = 0x01; |
a9de9248 MH |
1865 | info++; |
1866 | hci_inquiry_cache_update(hdev, &data); | |
1867 | } | |
1868 | ||
1869 | hci_dev_unlock(hdev); | |
1870 | } | |
1da177e4 | 1871 | |
0493684e MH |
1872 | static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1873 | { | |
1874 | struct hci_ev_io_capa_request *ev = (void *) skb->data; | |
1875 | struct hci_conn *conn; | |
1876 | ||
1877 | BT_DBG("%s", hdev->name); | |
1878 | ||
1879 | hci_dev_lock(hdev); | |
1880 | ||
1881 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | |
1882 | if (conn) | |
1883 | hci_conn_hold(conn); | |
1884 | ||
1885 | hci_dev_unlock(hdev); | |
1886 | } | |
1887 | ||
1888 | static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb) | |
1889 | { | |
1890 | struct hci_ev_simple_pair_complete *ev = (void *) skb->data; | |
1891 | struct hci_conn *conn; | |
1892 | ||
1893 | BT_DBG("%s", hdev->name); | |
1894 | ||
1895 | hci_dev_lock(hdev); | |
1896 | ||
1897 | conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr); | |
1898 | if (conn) | |
1899 | hci_conn_put(conn); | |
1900 | ||
1901 | hci_dev_unlock(hdev); | |
1902 | } | |
1903 | ||
41a96212 MH |
1904 | static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_buff *skb) |
1905 | { | |
1906 | struct hci_ev_remote_host_features *ev = (void *) skb->data; | |
1907 | struct inquiry_entry *ie; | |
1908 | ||
1909 | BT_DBG("%s", hdev->name); | |
1910 | ||
1911 | hci_dev_lock(hdev); | |
1912 | ||
cc11b9c1 AE |
1913 | ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr); |
1914 | if (ie) | |
41a96212 MH |
1915 | ie->data.ssp_mode = (ev->features[0] & 0x01); |
1916 | ||
1917 | hci_dev_unlock(hdev); | |
1918 | } | |
1919 | ||
a9de9248 MH |
1920 | void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) |
1921 | { | |
1922 | struct hci_event_hdr *hdr = (void *) skb->data; | |
1923 | __u8 event = hdr->evt; | |
1924 | ||
1925 | skb_pull(skb, HCI_EVENT_HDR_SIZE); | |
1926 | ||
1927 | switch (event) { | |
1da177e4 LT |
1928 | case HCI_EV_INQUIRY_COMPLETE: |
1929 | hci_inquiry_complete_evt(hdev, skb); | |
1930 | break; | |
1931 | ||
1932 | case HCI_EV_INQUIRY_RESULT: | |
1933 | hci_inquiry_result_evt(hdev, skb); | |
1934 | break; | |
1935 | ||
a9de9248 MH |
1936 | case HCI_EV_CONN_COMPLETE: |
1937 | hci_conn_complete_evt(hdev, skb); | |
21d9e30e MH |
1938 | break; |
1939 | ||
1da177e4 LT |
1940 | case HCI_EV_CONN_REQUEST: |
1941 | hci_conn_request_evt(hdev, skb); | |
1942 | break; | |
1943 | ||
1da177e4 LT |
1944 | case HCI_EV_DISCONN_COMPLETE: |
1945 | hci_disconn_complete_evt(hdev, skb); | |
1946 | break; | |
1947 | ||
1da177e4 LT |
1948 | case HCI_EV_AUTH_COMPLETE: |
1949 | hci_auth_complete_evt(hdev, skb); | |
1950 | break; | |
1951 | ||
a9de9248 MH |
1952 | case HCI_EV_REMOTE_NAME: |
1953 | hci_remote_name_evt(hdev, skb); | |
1954 | break; | |
1955 | ||
1da177e4 LT |
1956 | case HCI_EV_ENCRYPT_CHANGE: |
1957 | hci_encrypt_change_evt(hdev, skb); | |
1958 | break; | |
1959 | ||
a9de9248 MH |
1960 | case HCI_EV_CHANGE_LINK_KEY_COMPLETE: |
1961 | hci_change_link_key_complete_evt(hdev, skb); | |
1962 | break; | |
1963 | ||
1964 | case HCI_EV_REMOTE_FEATURES: | |
1965 | hci_remote_features_evt(hdev, skb); | |
1966 | break; | |
1967 | ||
1968 | case HCI_EV_REMOTE_VERSION: | |
1969 | hci_remote_version_evt(hdev, skb); | |
1970 | break; | |
1971 | ||
1972 | case HCI_EV_QOS_SETUP_COMPLETE: | |
1973 | hci_qos_setup_complete_evt(hdev, skb); | |
1974 | break; | |
1975 | ||
1976 | case HCI_EV_CMD_COMPLETE: | |
1977 | hci_cmd_complete_evt(hdev, skb); | |
1978 | break; | |
1979 | ||
1980 | case HCI_EV_CMD_STATUS: | |
1981 | hci_cmd_status_evt(hdev, skb); | |
1982 | break; | |
1983 | ||
1984 | case HCI_EV_ROLE_CHANGE: | |
1985 | hci_role_change_evt(hdev, skb); | |
1986 | break; | |
1987 | ||
1988 | case HCI_EV_NUM_COMP_PKTS: | |
1989 | hci_num_comp_pkts_evt(hdev, skb); | |
1990 | break; | |
1991 | ||
1992 | case HCI_EV_MODE_CHANGE: | |
1993 | hci_mode_change_evt(hdev, skb); | |
1da177e4 LT |
1994 | break; |
1995 | ||
1996 | case HCI_EV_PIN_CODE_REQ: | |
1997 | hci_pin_code_request_evt(hdev, skb); | |
1998 | break; | |
1999 | ||
2000 | case HCI_EV_LINK_KEY_REQ: | |
2001 | hci_link_key_request_evt(hdev, skb); | |
2002 | break; | |
2003 | ||
2004 | case HCI_EV_LINK_KEY_NOTIFY: | |
2005 | hci_link_key_notify_evt(hdev, skb); | |
2006 | break; | |
2007 | ||
2008 | case HCI_EV_CLOCK_OFFSET: | |
2009 | hci_clock_offset_evt(hdev, skb); | |
2010 | break; | |
2011 | ||
a8746417 MH |
2012 | case HCI_EV_PKT_TYPE_CHANGE: |
2013 | hci_pkt_type_change_evt(hdev, skb); | |
2014 | break; | |
2015 | ||
85a1e930 MH |
2016 | case HCI_EV_PSCAN_REP_MODE: |
2017 | hci_pscan_rep_mode_evt(hdev, skb); | |
2018 | break; | |
2019 | ||
a9de9248 MH |
2020 | case HCI_EV_INQUIRY_RESULT_WITH_RSSI: |
2021 | hci_inquiry_result_with_rssi_evt(hdev, skb); | |
04837f64 MH |
2022 | break; |
2023 | ||
a9de9248 MH |
2024 | case HCI_EV_REMOTE_EXT_FEATURES: |
2025 | hci_remote_ext_features_evt(hdev, skb); | |
1da177e4 LT |
2026 | break; |
2027 | ||
a9de9248 MH |
2028 | case HCI_EV_SYNC_CONN_COMPLETE: |
2029 | hci_sync_conn_complete_evt(hdev, skb); | |
2030 | break; | |
1da177e4 | 2031 | |
a9de9248 MH |
2032 | case HCI_EV_SYNC_CONN_CHANGED: |
2033 | hci_sync_conn_changed_evt(hdev, skb); | |
2034 | break; | |
1da177e4 | 2035 | |
a9de9248 MH |
2036 | case HCI_EV_SNIFF_SUBRATE: |
2037 | hci_sniff_subrate_evt(hdev, skb); | |
2038 | break; | |
1da177e4 | 2039 | |
a9de9248 MH |
2040 | case HCI_EV_EXTENDED_INQUIRY_RESULT: |
2041 | hci_extended_inquiry_result_evt(hdev, skb); | |
2042 | break; | |
1da177e4 | 2043 | |
0493684e MH |
2044 | case HCI_EV_IO_CAPA_REQUEST: |
2045 | hci_io_capa_request_evt(hdev, skb); | |
2046 | break; | |
2047 | ||
2048 | case HCI_EV_SIMPLE_PAIR_COMPLETE: | |
2049 | hci_simple_pair_complete_evt(hdev, skb); | |
2050 | break; | |
2051 | ||
41a96212 MH |
2052 | case HCI_EV_REMOTE_HOST_FEATURES: |
2053 | hci_remote_host_features_evt(hdev, skb); | |
2054 | break; | |
2055 | ||
a9de9248 MH |
2056 | default: |
2057 | BT_DBG("%s event 0x%x", hdev->name, event); | |
1da177e4 LT |
2058 | break; |
2059 | } | |
2060 | ||
2061 | kfree_skb(skb); | |
2062 | hdev->stat.evt_rx++; | |
2063 | } | |
2064 | ||
2065 | /* Generate internal stack event */ | |
2066 | void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data) | |
2067 | { | |
2068 | struct hci_event_hdr *hdr; | |
2069 | struct hci_ev_stack_internal *ev; | |
2070 | struct sk_buff *skb; | |
2071 | ||
2072 | skb = bt_skb_alloc(HCI_EVENT_HDR_SIZE + sizeof(*ev) + dlen, GFP_ATOMIC); | |
2073 | if (!skb) | |
2074 | return; | |
2075 | ||
2076 | hdr = (void *) skb_put(skb, HCI_EVENT_HDR_SIZE); | |
2077 | hdr->evt = HCI_EV_STACK_INTERNAL; | |
2078 | hdr->plen = sizeof(*ev) + dlen; | |
2079 | ||
2080 | ev = (void *) skb_put(skb, sizeof(*ev) + dlen); | |
2081 | ev->type = type; | |
2082 | memcpy(ev->data, data, dlen); | |
2083 | ||
576c7d85 | 2084 | bt_cb(skb)->incoming = 1; |
a61bbcf2 | 2085 | __net_timestamp(skb); |
576c7d85 | 2086 | |
0d48d939 | 2087 | bt_cb(skb)->pkt_type = HCI_EVENT_PKT; |
1da177e4 | 2088 | skb->dev = (void *) hdev; |
eec8d2bc | 2089 | hci_send_to_sock(hdev, skb, NULL); |
1da177e4 LT |
2090 | kfree_skb(skb); |
2091 | } |