blob: bbb637d13735577f8c911ae9f831de2bc1aa64f6 [file] [log] [blame]
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +09001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 BlueZ - Bluetooth protocol stack for Linux
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003 Copyright (c) 2000-2001, 2010-2011, Code Aurora Forum. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
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
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +090015 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +090020 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 SOFTWARE IS DISCLAIMED.
23*/
24
25/* Bluetooth HCI event handling. */
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/module.h>
28
29#include <linux/types.h>
30#include <linux/errno.h>
31#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#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>
Andrei Emeltchenko70f230202010-12-01 16:58:25 +020042#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/unaligned.h>
44
45#include <net/bluetooth/bluetooth.h>
46#include <net/bluetooth/hci_core.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* Handle HCI Event packets */
49
Marcel Holtmanna9de9242007-10-20 13:33:56 +020050static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Marcel Holtmanna9de9242007-10-20 13:33:56 +020052 __u8 status = *((__u8 *) skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Marcel Holtmanna9de9242007-10-20 13:33:56 +020054 BT_DBG("%s status 0x%x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Marcel Holtmanna9de9242007-10-20 13:33:56 +020056 if (status)
57 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059 clear_bit(HCI_INQUIRY, &hdev->flags);
Marcel Holtmann6bd57412006-11-18 22:14:22 +010060
Johan Hedberg23bb5762010-12-21 23:01:27 +020061 hci_req_complete(hdev, HCI_OP_INQUIRY_CANCEL, status);
Marcel Holtmann6bd57412006-11-18 22:14:22 +010062
Marcel Holtmanna9de9242007-10-20 13:33:56 +020063 hci_conn_check_pending(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Marcel Holtmanna9de9242007-10-20 13:33:56 +020066static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Marcel Holtmanna9de9242007-10-20 13:33:56 +020068 __u8 status = *((__u8 *) skb->data);
69
70 BT_DBG("%s status 0x%x", hdev->name, status);
71
72 if (status)
73 return;
74
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075 clear_bit(HCI_INQUIRY, &hdev->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +020076
77 hci_conn_check_pending(hdev);
78}
79
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080static void hci_cc_link_key_reply(struct hci_dev *hdev, struct sk_buff *skb)
81{
82 struct hci_rp_link_key_reply *rp = (void *) skb->data;
83 struct hci_conn *conn;
84 struct hci_cp_link_key_reply *cp;
85
86 BT_DBG("%s status 0x%x", hdev->name, rp->status);
87 if (rp->status)
88 return;
89
90 cp = hci_sent_cmd_data(hdev, HCI_OP_LINK_KEY_REPLY);
91 if (!cp)
92 return;
93
94 hci_dev_lock(hdev);
95 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
96 if (conn) {
97 hci_conn_hold(conn);
98 memcpy(conn->link_key, cp->link_key, sizeof(conn->link_key));
99 conn->key_type = 5;
100 hci_conn_put(conn);
101 }
102 hci_dev_unlock(hdev);
103}
104
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200105static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, struct sk_buff *skb)
106{
107 BT_DBG("%s", hdev->name);
108}
109
110static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
111{
112 struct hci_rp_role_discovery *rp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200115 BT_DBG("%s status 0x%x", hdev->name, rp->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200117 if (rp->status)
118 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200120 hci_dev_lock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200122 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
123 if (conn) {
124 if (rp->role)
125 conn->link_mode &= ~HCI_LM_MASTER;
126 else
127 conn->link_mode |= HCI_LM_MASTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200129
130 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200133static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
134{
135 struct hci_rp_read_link_policy *rp = (void *) skb->data;
136 struct hci_conn *conn;
137
138 BT_DBG("%s status 0x%x", hdev->name, rp->status);
139
140 if (rp->status)
141 return;
142
143 hci_dev_lock(hdev);
144
145 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
146 if (conn)
147 conn->link_policy = __le16_to_cpu(rp->policy);
148
149 hci_dev_unlock(hdev);
150}
151
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200152static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200154 struct hci_rp_write_link_policy *rp = (void *) skb->data;
155 struct hci_conn *conn;
156 void *sent;
157
158 BT_DBG("%s status 0x%x", hdev->name, rp->status);
159
160 if (rp->status)
161 return;
162
163 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
164 if (!sent)
165 return;
166
167 hci_dev_lock(hdev);
168
169 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200170 if (conn)
Harvey Harrison83985312008-05-02 16:25:46 -0700171 conn->link_policy = get_unaligned_le16(sent + 2);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200172
173 hci_dev_unlock(hdev);
174}
175
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200176static void hci_cc_read_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
177{
178 struct hci_rp_read_def_link_policy *rp = (void *) skb->data;
179
180 BT_DBG("%s status 0x%x", hdev->name, rp->status);
181
182 if (rp->status)
183 return;
184
185 hdev->link_policy = __le16_to_cpu(rp->policy);
186}
187
188static void hci_cc_write_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
189{
190 __u8 status = *((__u8 *) skb->data);
191 void *sent;
192
193 BT_DBG("%s status 0x%x", hdev->name, status);
194
195 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
196 if (!sent)
197 return;
198
199 if (!status)
200 hdev->link_policy = get_unaligned_le16(sent);
201
Johan Hedberg23bb5762010-12-21 23:01:27 +0200202 hci_req_complete(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, status);
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200203}
204
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200205static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
206{
207 __u8 status = *((__u8 *) skb->data);
208
209 BT_DBG("%s status 0x%x", hdev->name, status);
210
Gustavo F. Padovan10572132011-03-16 15:36:29 -0300211 clear_bit(HCI_RESET, &hdev->flags);
212
Johan Hedberg23bb5762010-12-21 23:01:27 +0200213 hci_req_complete(hdev, HCI_OP_RESET, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200214}
215
216static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
217{
218 __u8 status = *((__u8 *) skb->data);
219 void *sent;
220
221 BT_DBG("%s status 0x%x", hdev->name, status);
222
223 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
224 if (!sent)
225 return;
226
Johan Hedbergb312b1612011-03-16 14:29:37 +0200227 if (test_bit(HCI_MGMT, &hdev->flags))
228 mgmt_set_local_name_complete(hdev->id, sent, status);
229
230 if (status)
231 return;
232
Johan Hedberg1f6c6372011-03-16 14:29:35 +0200233 memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200234}
235
236static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
237{
238 struct hci_rp_read_local_name *rp = (void *) skb->data;
239
240 BT_DBG("%s status 0x%x", hdev->name, rp->status);
241
242 if (rp->status)
243 return;
244
Johan Hedberg1f6c6372011-03-16 14:29:35 +0200245 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200246}
247
248static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
249{
250 __u8 status = *((__u8 *) skb->data);
251 void *sent;
252
253 BT_DBG("%s status 0x%x", hdev->name, status);
254
255 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
256 if (!sent)
257 return;
258
259 if (!status) {
260 __u8 param = *((__u8 *) sent);
261
262 if (param == AUTH_ENABLED)
263 set_bit(HCI_AUTH, &hdev->flags);
264 else
265 clear_bit(HCI_AUTH, &hdev->flags);
266 }
267
Johan Hedberg23bb5762010-12-21 23:01:27 +0200268 hci_req_complete(hdev, HCI_OP_WRITE_AUTH_ENABLE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200269}
270
271static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
272{
273 __u8 status = *((__u8 *) skb->data);
274 void *sent;
275
276 BT_DBG("%s status 0x%x", hdev->name, status);
277
278 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
279 if (!sent)
280 return;
281
282 if (!status) {
283 __u8 param = *((__u8 *) sent);
284
285 if (param)
286 set_bit(HCI_ENCRYPT, &hdev->flags);
287 else
288 clear_bit(HCI_ENCRYPT, &hdev->flags);
289 }
290
Johan Hedberg23bb5762010-12-21 23:01:27 +0200291 hci_req_complete(hdev, HCI_OP_WRITE_ENCRYPT_MODE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200292}
293
294static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
295{
296 __u8 status = *((__u8 *) skb->data);
297 void *sent;
298
299 BT_DBG("%s status 0x%x", hdev->name, status);
300
301 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
302 if (!sent)
303 return;
304
305 if (!status) {
306 __u8 param = *((__u8 *) sent);
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200307 int old_pscan, old_iscan;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200308
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200309 old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags);
310 old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200311
Johan Hedberg73f22f62010-12-29 16:00:25 +0200312 if (param & SCAN_INQUIRY) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200313 set_bit(HCI_ISCAN, &hdev->flags);
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200314 if (!old_iscan)
315 mgmt_discoverable(hdev->id, 1);
316 } else if (old_iscan)
Johan Hedberg73f22f62010-12-29 16:00:25 +0200317 mgmt_discoverable(hdev->id, 0);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200318
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200319 if (param & SCAN_PAGE) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200320 set_bit(HCI_PSCAN, &hdev->flags);
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200321 if (!old_pscan)
322 mgmt_connectable(hdev->id, 1);
323 } else if (old_pscan)
324 mgmt_connectable(hdev->id, 0);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200325 }
326
Johan Hedberg23bb5762010-12-21 23:01:27 +0200327 hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200328}
329
330static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
331{
332 struct hci_rp_read_class_of_dev *rp = (void *) skb->data;
333
334 BT_DBG("%s status 0x%x", hdev->name, rp->status);
335
336 if (rp->status)
337 return;
338
339 memcpy(hdev->dev_class, rp->dev_class, 3);
340
341 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
342 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
343}
344
345static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
346{
347 __u8 status = *((__u8 *) skb->data);
348 void *sent;
349
350 BT_DBG("%s status 0x%x", hdev->name, status);
351
Marcel Holtmannf383f272008-07-14 20:13:47 +0200352 if (status)
353 return;
354
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200355 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
356 if (!sent)
357 return;
358
Marcel Holtmannf383f272008-07-14 20:13:47 +0200359 memcpy(hdev->dev_class, sent, 3);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200360}
361
362static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
363{
364 struct hci_rp_read_voice_setting *rp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 __u16 setting;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200366
367 BT_DBG("%s status 0x%x", hdev->name, rp->status);
368
369 if (rp->status)
370 return;
371
372 setting = __le16_to_cpu(rp->voice_setting);
373
Marcel Holtmannf383f272008-07-14 20:13:47 +0200374 if (hdev->voice_setting == setting)
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200375 return;
376
377 hdev->voice_setting = setting;
378
379 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
380
381 if (hdev->notify) {
382 tasklet_disable(&hdev->tx_task);
383 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
384 tasklet_enable(&hdev->tx_task);
385 }
386}
387
388static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
389{
390 __u8 status = *((__u8 *) skb->data);
Marcel Holtmannf383f272008-07-14 20:13:47 +0200391 __u16 setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 void *sent;
393
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200394 BT_DBG("%s status 0x%x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Marcel Holtmannf383f272008-07-14 20:13:47 +0200396 if (status)
397 return;
398
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200399 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
400 if (!sent)
401 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Marcel Holtmannf383f272008-07-14 20:13:47 +0200403 setting = get_unaligned_le16(sent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
Marcel Holtmannf383f272008-07-14 20:13:47 +0200405 if (hdev->voice_setting == setting)
406 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Marcel Holtmannf383f272008-07-14 20:13:47 +0200408 hdev->voice_setting = setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Marcel Holtmannf383f272008-07-14 20:13:47 +0200410 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
411
412 if (hdev->notify) {
413 tasklet_disable(&hdev->tx_task);
414 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
415 tasklet_enable(&hdev->tx_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417}
418
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200419static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200421 __u8 status = *((__u8 *) skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200423 BT_DBG("%s status 0x%x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Johan Hedberg23bb5762010-12-21 23:01:27 +0200425 hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426}
427
Marcel Holtmann333140b2008-07-14 20:13:48 +0200428static void hci_cc_read_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
429{
430 struct hci_rp_read_ssp_mode *rp = (void *) skb->data;
431
432 BT_DBG("%s status 0x%x", hdev->name, rp->status);
433
434 if (rp->status)
435 return;
436
437 hdev->ssp_mode = rp->mode;
438}
439
440static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
441{
442 __u8 status = *((__u8 *) skb->data);
443 void *sent;
444
445 BT_DBG("%s status 0x%x", hdev->name, status);
446
447 if (status)
448 return;
449
450 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
451 if (!sent)
452 return;
453
454 hdev->ssp_mode = *((__u8 *) sent);
455}
456
Johan Hedbergd5859e22011-01-25 01:19:58 +0200457static u8 hci_get_inquiry_mode(struct hci_dev *hdev)
458{
459 if (hdev->features[6] & LMP_EXT_INQ)
460 return 2;
461
462 if (hdev->features[3] & LMP_RSSI_INQ)
463 return 1;
464
465 if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 &&
466 hdev->lmp_subver == 0x0757)
467 return 1;
468
469 if (hdev->manufacturer == 15) {
470 if (hdev->hci_rev == 0x03 && hdev->lmp_subver == 0x6963)
471 return 1;
472 if (hdev->hci_rev == 0x09 && hdev->lmp_subver == 0x6963)
473 return 1;
474 if (hdev->hci_rev == 0x00 && hdev->lmp_subver == 0x6965)
475 return 1;
476 }
477
478 if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 &&
479 hdev->lmp_subver == 0x1805)
480 return 1;
481
482 return 0;
483}
484
485static void hci_setup_inquiry_mode(struct hci_dev *hdev)
486{
487 u8 mode;
488
489 mode = hci_get_inquiry_mode(hdev);
490
491 hci_send_cmd(hdev, HCI_OP_WRITE_INQUIRY_MODE, 1, &mode);
492}
493
494static void hci_setup_event_mask(struct hci_dev *hdev)
495{
496 /* The second byte is 0xff instead of 0x9f (two reserved bits
497 * disabled) since a Broadcom 1.2 dongle doesn't respond to the
498 * command otherwise */
499 u8 events[8] = { 0xff, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x00 };
500
Brian Gixa68668b2011-08-11 15:49:36 -0700501 BT_DBG("");
502
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700503 /* Events for 1.2 and newer controllers */
504 if (hdev->lmp_ver > 1) {
505 events[4] |= 0x01; /* Flow Specification Complete */
506 events[4] |= 0x02; /* Inquiry Result with RSSI */
507 events[4] |= 0x04; /* Read Remote Extended Features Complete */
508 events[5] |= 0x08; /* Synchronous Connection Complete */
509 events[5] |= 0x10; /* Synchronous Connection Changed */
510 }
Johan Hedbergd5859e22011-01-25 01:19:58 +0200511
512 if (hdev->features[3] & LMP_RSSI_INQ)
513 events[4] |= 0x04; /* Inquiry Result with RSSI */
514
515 if (hdev->features[5] & LMP_SNIFF_SUBR)
516 events[5] |= 0x20; /* Sniff Subrating */
517
518 if (hdev->features[5] & LMP_PAUSE_ENC)
519 events[5] |= 0x80; /* Encryption Key Refresh Complete */
520
521 if (hdev->features[6] & LMP_EXT_INQ)
522 events[5] |= 0x40; /* Extended Inquiry Result */
523
524 if (hdev->features[6] & LMP_NO_FLUSH)
525 events[7] |= 0x01; /* Enhanced Flush Complete */
526
527 if (hdev->features[7] & LMP_LSTO)
528 events[6] |= 0x80; /* Link Supervision Timeout Changed */
529
530 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
531 events[6] |= 0x01; /* IO Capability Request */
532 events[6] |= 0x02; /* IO Capability Response */
533 events[6] |= 0x04; /* User Confirmation Request */
534 events[6] |= 0x08; /* User Passkey Request */
535 events[6] |= 0x10; /* Remote OOB Data Request */
536 events[6] |= 0x20; /* Simple Pairing Complete */
537 events[7] |= 0x04; /* User Passkey Notification */
538 events[7] |= 0x08; /* Keypress Notification */
539 events[7] |= 0x10; /* Remote Host Supported
540 * Features Notification */
541 }
542
543 if (hdev->features[4] & LMP_LE)
544 events[7] |= 0x20; /* LE Meta-Event */
545
546 hci_send_cmd(hdev, HCI_OP_SET_EVENT_MASK, sizeof(events), events);
547}
548
549static void hci_setup(struct hci_dev *hdev)
550{
Johan Hedbergd5859e22011-01-25 01:19:58 +0200551 if (hdev->lmp_ver > 1)
552 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL);
553
554 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
555 u8 mode = 0x01;
556 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, sizeof(mode), &mode);
557 }
558
559 if (hdev->features[3] & LMP_RSSI_INQ)
560 hci_setup_inquiry_mode(hdev);
561
562 if (hdev->features[7] & LMP_INQ_TX_PWR)
563 hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, 0, NULL);
564}
565
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200566static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
567{
568 struct hci_rp_read_local_version *rp = (void *) skb->data;
569
570 BT_DBG("%s status 0x%x", hdev->name, rp->status);
571
572 if (rp->status)
573 return;
574
575 hdev->hci_ver = rp->hci_ver;
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200576 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200577 hdev->lmp_ver = rp->lmp_ver;
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200578 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200579 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200580
581 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name,
582 hdev->manufacturer,
583 hdev->hci_ver, hdev->hci_rev);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200584
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700585 if (hdev->dev_type == HCI_BREDR && test_bit(HCI_INIT, &hdev->flags))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200586 hci_setup(hdev);
587}
588
589static void hci_setup_link_policy(struct hci_dev *hdev)
590{
591 u16 link_policy = 0;
592
593 if (hdev->features[0] & LMP_RSWITCH)
594 link_policy |= HCI_LP_RSWITCH;
595 if (hdev->features[0] & LMP_HOLD)
596 link_policy |= HCI_LP_HOLD;
597 if (hdev->features[0] & LMP_SNIFF)
598 link_policy |= HCI_LP_SNIFF;
599 if (hdev->features[1] & LMP_PARK)
600 link_policy |= HCI_LP_PARK;
601
602 link_policy = cpu_to_le16(link_policy);
603 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY,
604 sizeof(link_policy), &link_policy);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200605}
606
607static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb)
608{
609 struct hci_rp_read_local_commands *rp = (void *) skb->data;
610
611 BT_DBG("%s status 0x%x", hdev->name, rp->status);
612
613 if (rp->status)
Johan Hedbergd5859e22011-01-25 01:19:58 +0200614 goto done;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200615
616 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
Johan Hedbergd5859e22011-01-25 01:19:58 +0200617
618 if (test_bit(HCI_INIT, &hdev->flags) && (hdev->commands[5] & 0x10))
619 hci_setup_link_policy(hdev);
620
621done:
622 hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200623}
624
625static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb)
626{
627 struct hci_rp_read_local_features *rp = (void *) skb->data;
628
629 BT_DBG("%s status 0x%x", hdev->name, rp->status);
630
631 if (rp->status)
632 return;
633
634 memcpy(hdev->features, rp->features, 8);
635
Brian Gixa68668b2011-08-11 15:49:36 -0700636 if (hdev->dev_type == HCI_BREDR && test_bit(HCI_INIT, &hdev->flags)) {
637 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
638 u8 mode = 0x01;
639 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE,
640 sizeof(mode), &mode);
641 }
642
643 if (hdev->features[3] & LMP_RSSI_INQ)
644 hci_setup_inquiry_mode(hdev);
645
646 if (hdev->features[7] & LMP_INQ_TX_PWR)
647 hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER,
648 0, NULL);
649
650 hci_setup_event_mask(hdev);
651 }
652
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200653 /* Adjust default settings according to features
654 * supported by device. */
655
656 if (hdev->features[0] & LMP_3SLOT)
657 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
658
659 if (hdev->features[0] & LMP_5SLOT)
660 hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
661
662 if (hdev->features[1] & LMP_HV2) {
663 hdev->pkt_type |= (HCI_HV2);
664 hdev->esco_type |= (ESCO_HV2);
665 }
666
667 if (hdev->features[1] & LMP_HV3) {
668 hdev->pkt_type |= (HCI_HV3);
669 hdev->esco_type |= (ESCO_HV3);
670 }
671
672 if (hdev->features[3] & LMP_ESCO)
673 hdev->esco_type |= (ESCO_EV3);
674
675 if (hdev->features[4] & LMP_EV4)
676 hdev->esco_type |= (ESCO_EV4);
677
678 if (hdev->features[4] & LMP_EV5)
679 hdev->esco_type |= (ESCO_EV5);
680
Marcel Holtmannefc76882009-02-06 09:13:37 +0100681 if (hdev->features[5] & LMP_EDR_ESCO_2M)
682 hdev->esco_type |= (ESCO_2EV3);
683
684 if (hdev->features[5] & LMP_EDR_ESCO_3M)
685 hdev->esco_type |= (ESCO_3EV3);
686
687 if (hdev->features[5] & LMP_EDR_3S_ESCO)
688 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
689
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200690 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name,
691 hdev->features[0], hdev->features[1],
692 hdev->features[2], hdev->features[3],
693 hdev->features[4], hdev->features[5],
694 hdev->features[6], hdev->features[7]);
695}
696
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700697static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
698 struct sk_buff *skb)
Andre Guedesd5fa5132011-06-30 19:20:52 -0300699{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700700 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
Andre Guedesd5fa5132011-06-30 19:20:52 -0300701
702 BT_DBG("%s status 0x%x", hdev->name, rp->status);
703
704 if (rp->status)
705 return;
706
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700707 hdev->flow_ctl_mode = rp->mode;
Andre Guedesd5fa5132011-06-30 19:20:52 -0300708}
709
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200710static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
711{
712 struct hci_rp_read_buffer_size *rp = (void *) skb->data;
713
714 BT_DBG("%s status 0x%x", hdev->name, rp->status);
715
716 if (rp->status)
717 return;
718
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700719 if (hdev->flow_ctl_mode == HCI_PACKET_BASED_FLOW_CTL_MODE) {
720 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
721 hdev->sco_mtu = rp->sco_mtu;
722 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
723 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
724 hdev->acl_cnt = hdev->acl_pkts;
725 hdev->sco_cnt = hdev->sco_pkts;
726 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200727
728 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
729 hdev->sco_mtu = 64;
730 hdev->sco_pkts = 8;
731 }
732
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200733
734 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name,
735 hdev->acl_mtu, hdev->acl_pkts,
736 hdev->sco_mtu, hdev->sco_pkts);
737}
738
739static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
740{
741 struct hci_rp_read_bd_addr *rp = (void *) skb->data;
742
743 BT_DBG("%s status 0x%x", hdev->name, rp->status);
744
745 if (!rp->status)
746 bacpy(&hdev->bdaddr, &rp->bdaddr);
747
Johan Hedberg23bb5762010-12-21 23:01:27 +0200748 hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status);
749}
750
751static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb)
752{
753 __u8 status = *((__u8 *) skb->data);
754
755 BT_DBG("%s status 0x%x", hdev->name, status);
756
757 hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200758}
759
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700760static void hci_cc_read_data_block_size(struct hci_dev *hdev,
761 struct sk_buff *skb)
762{
763 struct hci_rp_read_data_block_size *rp = (void *) skb->data;
764
765 BT_DBG("%s status 0x%x", hdev->name, rp->status);
766
767 if (rp->status)
768 return;
769
770 if (hdev->flow_ctl_mode == HCI_BLOCK_BASED_FLOW_CTL_MODE) {
771 hdev->acl_mtu = __le16_to_cpu(rp->max_acl_len);
772 hdev->sco_mtu = 0;
773 hdev->data_block_len = __le16_to_cpu(rp->data_block_len);
774 /* acl_pkts indicates the number of blocks */
775 hdev->acl_pkts = __le16_to_cpu(rp->num_blocks);
776 hdev->sco_pkts = 0;
777 hdev->acl_cnt = hdev->acl_pkts;
778 hdev->sco_cnt = 0;
779 }
780
781 BT_DBG("%s acl mtu %d:%d, data block len %d", hdev->name,
782 hdev->acl_mtu, hdev->acl_cnt, hdev->data_block_len);
783}
784
785static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
786 struct sk_buff *skb)
787{
788 struct hci_rp_read_local_amp_info *rp = (void *) skb->data;
789
790 BT_DBG("%s status 0x%x", hdev->name, rp->status);
791
792 if (rp->status)
793 return;
794
795 hdev->amp_status = rp->amp_status;
796 hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
797 hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
798 hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
799 hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
800 hdev->amp_type = rp->amp_type;
801 hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
802 hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
803 hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
804 hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
805
806 hci_req_complete(hdev, HCI_OP_READ_LOCAL_AMP_INFO, rp->status);
807}
808
Johan Hedbergb0916ea2011-01-10 13:44:55 +0200809static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
810 struct sk_buff *skb)
811{
812 __u8 status = *((__u8 *) skb->data);
813
814 BT_DBG("%s status 0x%x", hdev->name, status);
815
816 hci_req_complete(hdev, HCI_OP_DELETE_STORED_LINK_KEY, status);
817}
818
Johan Hedbergd5859e22011-01-25 01:19:58 +0200819static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb)
820{
821 __u8 status = *((__u8 *) skb->data);
822
823 BT_DBG("%s status 0x%x", hdev->name, status);
824
825 hci_req_complete(hdev, HCI_OP_SET_EVENT_MASK, status);
826}
827
828static void hci_cc_write_inquiry_mode(struct hci_dev *hdev,
829 struct sk_buff *skb)
830{
831 __u8 status = *((__u8 *) skb->data);
832
833 BT_DBG("%s status 0x%x", hdev->name, status);
834
835 hci_req_complete(hdev, HCI_OP_WRITE_INQUIRY_MODE, status);
836}
837
838static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
839 struct sk_buff *skb)
840{
841 __u8 status = *((__u8 *) skb->data);
842
843 BT_DBG("%s status 0x%x", hdev->name, status);
844
845 hci_req_complete(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, status);
846}
847
848static void hci_cc_set_event_flt(struct hci_dev *hdev, struct sk_buff *skb)
849{
850 __u8 status = *((__u8 *) skb->data);
851
852 BT_DBG("%s status 0x%x", hdev->name, status);
853
854 hci_req_complete(hdev, HCI_OP_SET_EVENT_FLT, status);
855}
856
Johan Hedberg980e1a52011-01-22 06:10:07 +0200857static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb)
858{
859 struct hci_rp_pin_code_reply *rp = (void *) skb->data;
860 struct hci_cp_pin_code_reply *cp;
861 struct hci_conn *conn;
862
863 BT_DBG("%s status 0x%x", hdev->name, rp->status);
864
865 if (test_bit(HCI_MGMT, &hdev->flags))
866 mgmt_pin_code_reply_complete(hdev->id, &rp->bdaddr, rp->status);
867
868 if (rp->status != 0)
869 return;
870
871 cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
872 if (!cp)
873 return;
874
875 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
876 if (conn)
877 conn->pin_length = cp->pin_len;
878}
879
880static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
881{
882 struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data;
883
884 BT_DBG("%s status 0x%x", hdev->name, rp->status);
885
886 if (test_bit(HCI_MGMT, &hdev->flags))
887 mgmt_pin_code_neg_reply_complete(hdev->id, &rp->bdaddr,
888 rp->status);
889}
Ville Tervo6ed58ec2011-02-10 22:38:48 -0300890static void hci_cc_le_read_buffer_size(struct hci_dev *hdev,
891 struct sk_buff *skb)
892{
893 struct hci_rp_le_read_buffer_size *rp = (void *) skb->data;
894
895 BT_DBG("%s status 0x%x", hdev->name, rp->status);
896
897 if (rp->status)
898 return;
899
900 hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
901 hdev->le_pkts = rp->le_max_pkt;
902
903 hdev->le_cnt = hdev->le_pkts;
904
905 BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
906
907 hci_req_complete(hdev, HCI_OP_LE_READ_BUFFER_SIZE, rp->status);
908}
Johan Hedberg980e1a52011-01-22 06:10:07 +0200909
Johan Hedberga5c29682011-02-19 12:05:57 -0300910static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
911{
912 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
913
914 BT_DBG("%s status 0x%x", hdev->name, rp->status);
915
916 if (test_bit(HCI_MGMT, &hdev->flags))
917 mgmt_user_confirm_reply_complete(hdev->id, &rp->bdaddr,
918 rp->status);
919}
920
921static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
922 struct sk_buff *skb)
923{
924 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
925
926 BT_DBG("%s status 0x%x", hdev->name, rp->status);
927
928 if (test_bit(HCI_MGMT, &hdev->flags))
929 mgmt_user_confirm_neg_reply_complete(hdev->id, &rp->bdaddr,
930 rp->status);
931}
932
Szymon Jancc35938b2011-03-22 13:12:21 +0100933static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
934 struct sk_buff *skb)
935{
936 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
937
938 BT_DBG("%s status 0x%x", hdev->name, rp->status);
939
940 mgmt_read_local_oob_data_reply_complete(hdev->id, rp->hash,
941 rp->randomizer, rp->status);
942}
943
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -0300944static void hci_cc_le_ltk_reply(struct hci_dev *hdev, struct sk_buff *skb)
945{
946 struct hci_rp_le_ltk_reply *rp = (void *) skb->data;
947
948 BT_DBG("%s status 0x%x", hdev->name, rp->status);
949
950 if (rp->status)
951 return;
952
953 hci_req_complete(hdev, HCI_OP_LE_LTK_REPLY, rp->status);
954}
955
956static void hci_cc_le_ltk_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
957{
958 struct hci_rp_le_ltk_neg_reply *rp = (void *) skb->data;
959
960 BT_DBG("%s status 0x%x", hdev->name, rp->status);
961
962 if (rp->status)
963 return;
964
965 hci_req_complete(hdev, HCI_OP_LE_LTK_NEG_REPLY, rp->status);
966}
967
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700968static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
969 struct sk_buff *skb)
Andre Guedese326af42011-06-30 19:20:53 -0300970{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700971 void *sent;
972 __u8 param_scan_enable;
Andre Guedese326af42011-06-30 19:20:53 -0300973 __u8 status = *((__u8 *) skb->data);
974
Andre Guedese326af42011-06-30 19:20:53 -0300975 if (status)
976 return;
977
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700978 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
979 if (!sent)
980 return;
981
982 param_scan_enable = *((__u8 *) sent);
983 if (param_scan_enable == 0x01) {
984 del_timer(&hdev->adv_timer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700985 } else if (param_scan_enable == 0x00) {
986 mod_timer(&hdev->adv_timer, jiffies + ADV_CLEAR_TIMEOUT);
987 }
Andre Guedese326af42011-06-30 19:20:53 -0300988}
989
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200990static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
991{
992 BT_DBG("%s status 0x%x", hdev->name, status);
993
994 if (status) {
Johan Hedberg23bb5762010-12-21 23:01:27 +0200995 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
Johan Hedberg314b2382011-04-27 10:29:57 -0400996
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700997 hci_conn_check_pending(hdev);
Brian Gixa68668b2011-08-11 15:49:36 -0700998 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700999 set_bit(HCI_INQUIRY, &hdev->flags);
Brian Gixa68668b2011-08-11 15:49:36 -07001000 if (test_bit(HCI_MGMT, &hdev->flags))
1001 mgmt_inquiry_started(hdev->id);
1002 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001003}
1004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
1006{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001007 struct hci_cp_create_conn *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001010 BT_DBG("%s status 0x%x", hdev->name, status);
1011
1012 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if (!cp)
1014 return;
1015
1016 hci_dev_lock(hdev);
1017
1018 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1019
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001020 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->bdaddr), conn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021
1022 if (status) {
1023 if (conn && conn->state == BT_CONNECT) {
Marcel Holtmann4c67bc72006-10-15 17:30:56 +02001024 if (status != 0x0c || conn->attempt > 2) {
1025 conn->state = BT_CLOSED;
1026 hci_proto_connect_cfm(conn, status);
1027 hci_conn_del(conn);
1028 } else
1029 conn->state = BT_CONNECT2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031 } else {
1032 if (!conn) {
Nick Pellybbcda3b2010-02-11 11:54:28 -08001033 conn = hci_conn_add(hdev, ACL_LINK, 0, &cp->bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (conn) {
1035 conn->out = 1;
1036 conn->link_mode |= HCI_LM_MASTER;
1037 } else
Gustavo F. Padovan893ef972010-07-18 15:13:37 -03001038 BT_ERR("No memory for new connection");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
1040 }
1041
1042 hci_dev_unlock(hdev);
1043}
1044
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001045static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001047 struct hci_cp_add_sco *cp;
1048 struct hci_conn *acl, *sco;
1049 __u16 handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001051 BT_DBG("%s status 0x%x", hdev->name, status);
1052
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001053 if (!status)
1054 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001056 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
1057 if (!cp)
1058 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001060 handle = __le16_to_cpu(cp->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001062 BT_DBG("%s handle %d", hdev->name, handle);
Marcel Holtmann6bd57412006-11-18 22:14:22 +01001063
1064 hci_dev_lock(hdev);
1065
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001066 acl = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001067 if (acl) {
1068 sco = acl->link;
1069 if (sco) {
1070 sco->state = BT_CLOSED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001071
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001072 hci_proto_connect_cfm(sco, status);
1073 hci_conn_del(sco);
1074 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001075 }
Marcel Holtmann6bd57412006-11-18 22:14:22 +01001076
1077 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078}
1079
Marcel Holtmannf8558552008-07-14 20:13:49 +02001080static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
1081{
1082 struct hci_cp_auth_requested *cp;
1083 struct hci_conn *conn;
1084
1085 BT_DBG("%s status 0x%x", hdev->name, status);
1086
1087 if (!status)
1088 return;
1089
1090 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
1091 if (!cp)
1092 return;
1093
1094 hci_dev_lock(hdev);
1095
1096 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1097 if (conn) {
1098 if (conn->state == BT_CONFIG) {
1099 hci_proto_connect_cfm(conn, status);
1100 hci_conn_put(conn);
1101 }
1102 }
1103
1104 hci_dev_unlock(hdev);
1105}
1106
1107static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
1108{
1109 struct hci_cp_set_conn_encrypt *cp;
1110 struct hci_conn *conn;
1111
1112 BT_DBG("%s status 0x%x", hdev->name, status);
1113
1114 if (!status)
1115 return;
1116
1117 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
1118 if (!cp)
1119 return;
1120
1121 hci_dev_lock(hdev);
1122
1123 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1124 if (conn) {
1125 if (conn->state == BT_CONFIG) {
1126 hci_proto_connect_cfm(conn, status);
1127 hci_conn_put(conn);
1128 }
1129 }
1130
1131 hci_dev_unlock(hdev);
1132}
1133
Johan Hedberg127178d2010-11-18 22:22:29 +02001134static int hci_outgoing_auth_needed(struct hci_dev *hdev,
Szymon Janc138d22e2011-02-17 16:44:23 +01001135 struct hci_conn *conn)
Johan Hedberg392599b2010-11-18 22:22:28 +02001136{
Johan Hedberg392599b2010-11-18 22:22:28 +02001137 if (conn->state != BT_CONFIG || !conn->out)
1138 return 0;
1139
Johan Hedberg765c2a92011-01-19 12:06:52 +05301140 if (conn->pending_sec_level == BT_SECURITY_SDP)
Johan Hedberg392599b2010-11-18 22:22:28 +02001141 return 0;
1142
1143 /* Only request authentication for SSP connections or non-SSP
Prabhakaran Mc6001a712011-09-06 11:56:25 +05301144 * devices with sec_level >= BT_SECURITY_MEDIUM*/
1145 BT_DBG("Pending sec level is %d", conn->pending_sec_level);
Johan Hedberg392599b2010-11-18 22:22:28 +02001146 if (!(hdev->ssp_mode > 0 && conn->ssp_mode > 0) &&
Prabhakaran Mc6001a712011-09-06 11:56:25 +05301147 conn->pending_sec_level < BT_SECURITY_MEDIUM)
Johan Hedberg392599b2010-11-18 22:22:28 +02001148 return 0;
1149
Johan Hedberg392599b2010-11-18 22:22:28 +02001150 return 1;
1151}
1152
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001153static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
1154{
Johan Hedberg127178d2010-11-18 22:22:29 +02001155 struct hci_cp_remote_name_req *cp;
1156 struct hci_conn *conn;
1157
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001158 BT_DBG("%s status 0x%x", hdev->name, status);
Johan Hedberg127178d2010-11-18 22:22:29 +02001159
1160 /* If successful wait for the name req complete event before
1161 * checking for the need to do authentication */
1162 if (!status)
1163 return;
1164
1165 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
1166 if (!cp)
1167 return;
1168
1169 hci_dev_lock(hdev);
1170
1171 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001172 if (conn && hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02001173 struct hci_cp_auth_requested cp;
1174 cp.handle = __cpu_to_le16(conn->handle);
1175 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1176 }
1177
1178 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001179}
1180
Marcel Holtmann769be972008-07-14 20:13:49 +02001181static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
1182{
1183 struct hci_cp_read_remote_features *cp;
1184 struct hci_conn *conn;
1185
1186 BT_DBG("%s status 0x%x", hdev->name, status);
1187
1188 if (!status)
1189 return;
1190
1191 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
1192 if (!cp)
1193 return;
1194
1195 hci_dev_lock(hdev);
1196
1197 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1198 if (conn) {
1199 if (conn->state == BT_CONFIG) {
Marcel Holtmann769be972008-07-14 20:13:49 +02001200 hci_proto_connect_cfm(conn, status);
1201 hci_conn_put(conn);
1202 }
1203 }
1204
1205 hci_dev_unlock(hdev);
1206}
1207
1208static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
1209{
1210 struct hci_cp_read_remote_ext_features *cp;
1211 struct hci_conn *conn;
1212
1213 BT_DBG("%s status 0x%x", hdev->name, status);
1214
1215 if (!status)
1216 return;
1217
1218 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
1219 if (!cp)
1220 return;
1221
1222 hci_dev_lock(hdev);
1223
1224 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1225 if (conn) {
1226 if (conn->state == BT_CONFIG) {
Marcel Holtmann769be972008-07-14 20:13:49 +02001227 hci_proto_connect_cfm(conn, status);
1228 hci_conn_put(conn);
1229 }
1230 }
1231
1232 hci_dev_unlock(hdev);
1233}
1234
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001235static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
1236{
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001237 struct hci_cp_setup_sync_conn *cp;
1238 struct hci_conn *acl, *sco;
1239 __u16 handle;
1240
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001241 BT_DBG("%s status 0x%x", hdev->name, status);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001242
1243 if (!status)
1244 return;
1245
1246 cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
1247 if (!cp)
1248 return;
1249
1250 handle = __le16_to_cpu(cp->handle);
1251
1252 BT_DBG("%s handle %d", hdev->name, handle);
1253
1254 hci_dev_lock(hdev);
1255
1256 acl = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001257 if (acl) {
1258 sco = acl->link;
1259 if (sco) {
1260 sco->state = BT_CLOSED;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001261
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001262 hci_proto_connect_cfm(sco, status);
1263 hci_conn_del(sco);
1264 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001265 }
1266
1267 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001268}
1269
1270static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
1271{
1272 struct hci_cp_sniff_mode *cp;
1273 struct hci_conn *conn;
1274
1275 BT_DBG("%s status 0x%x", hdev->name, status);
1276
1277 if (!status)
1278 return;
1279
1280 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
1281 if (!cp)
1282 return;
1283
1284 hci_dev_lock(hdev);
1285
1286 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001287 if (conn) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001288 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
1289
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001290 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
1291 hci_sco_setup(conn, status);
1292 }
1293
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001294 hci_dev_unlock(hdev);
1295}
1296
1297static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
1298{
1299 struct hci_cp_exit_sniff_mode *cp;
1300 struct hci_conn *conn;
1301
1302 BT_DBG("%s status 0x%x", hdev->name, status);
1303
1304 if (!status)
1305 return;
1306
1307 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
1308 if (!cp)
1309 return;
1310
1311 hci_dev_lock(hdev);
1312
1313 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001314 if (conn) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001315 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
1316
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001317 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
1318 hci_sco_setup(conn, status);
1319 }
1320
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001321 hci_dev_unlock(hdev);
1322}
1323
Ville Tervofcd89c02011-02-10 22:38:47 -03001324static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
1325{
1326 struct hci_cp_le_create_conn *cp;
1327 struct hci_conn *conn;
1328
1329 BT_DBG("%s status 0x%x", hdev->name, status);
1330
1331 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN);
1332 if (!cp)
1333 return;
1334
1335 hci_dev_lock(hdev);
1336
1337 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr);
1338
1339 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr),
1340 conn);
1341
1342 if (status) {
1343 if (conn && conn->state == BT_CONNECT) {
1344 conn->state = BT_CLOSED;
1345 hci_proto_connect_cfm(conn, status);
1346 hci_conn_del(conn);
1347 }
1348 } else {
1349 if (!conn) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001350 conn = hci_le_conn_add(hdev, &cp->peer_addr,
1351 cp->peer_addr_type);
1352 if (conn)
Ville Tervofcd89c02011-02-10 22:38:47 -03001353 conn->out = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001354 else
Ville Tervofcd89c02011-02-10 22:38:47 -03001355 BT_ERR("No memory for new connection");
1356 }
1357 }
1358
1359 hci_dev_unlock(hdev);
1360}
1361
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001362static void hci_cs_accept_logical_link(struct hci_dev *hdev, __u8 status)
1363{
1364 struct hci_cp_create_logical_link *ap;
1365 struct hci_chan *chan;
1366
1367 BT_DBG("%s status 0x%x", hdev->name, status);
1368
1369 ap = hci_sent_cmd_data(hdev, HCI_OP_ACCEPT_LOGICAL_LINK);
1370 if (!ap)
1371 return;
1372
1373 hci_dev_lock(hdev);
1374
1375 chan = hci_chan_list_lookup_id(hdev, ap->phy_handle);
1376
1377 BT_DBG("%s chan %p", hdev->name, chan);
1378
1379 if (status) {
1380 if (chan && chan->state == BT_CONNECT) {
1381 chan->state = BT_CLOSED;
1382 hci_proto_create_cfm(chan, status);
1383 hci_chan_del(chan);
1384 }
1385 } else if (chan)
1386 chan->state = BT_CONNECT2;
1387
1388 hci_dev_unlock(hdev);
1389}
1390
1391static void hci_cs_create_logical_link(struct hci_dev *hdev, __u8 status)
1392{
1393 struct hci_cp_create_logical_link *cp;
1394 struct hci_chan *chan;
1395
1396 BT_DBG("%s status 0x%x", hdev->name, status);
1397
1398 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_LOGICAL_LINK);
1399 if (!cp)
1400 return;
1401
1402 hci_dev_lock(hdev);
1403
1404 chan = hci_chan_list_lookup_id(hdev, cp->phy_handle);
1405
1406 BT_DBG("%s chan %p", hdev->name, chan);
1407
1408 if (status) {
1409 if (chan && chan->state == BT_CONNECT) {
1410 chan->state = BT_CLOSED;
1411 hci_proto_create_cfm(chan, status);
1412 hci_chan_del(chan);
1413 }
1414 } else if (chan)
1415 chan->state = BT_CONNECT2;
1416
1417 hci_dev_unlock(hdev);
1418}
1419
1420static void hci_cs_flow_spec_modify(struct hci_dev *hdev, __u8 status)
1421{
1422 struct hci_cp_flow_spec_modify *cp;
1423 struct hci_chan *chan;
1424
1425 BT_DBG("%s status 0x%x", hdev->name, status);
1426
1427 cp = hci_sent_cmd_data(hdev, HCI_OP_FLOW_SPEC_MODIFY);
1428 if (!cp)
1429 return;
1430
1431 hci_dev_lock(hdev);
1432
1433 chan = hci_chan_list_lookup_handle(hdev, cp->log_handle);
1434 if (chan) {
1435 if (status)
1436 hci_proto_modify_cfm(chan, status);
1437 else {
1438 chan->tx_fs = cp->tx_fs;
1439 chan->rx_fs = cp->rx_fs;
1440 }
1441 }
1442
1443 hci_dev_unlock(hdev);
1444}
1445
1446static void hci_cs_disconn_logical_link(struct hci_dev *hdev, __u8 status)
1447{
1448 struct hci_cp_disconn_logical_link *cp;
1449 struct hci_chan *chan;
1450
1451 if (!status)
1452 return;
1453
1454 BT_DBG("%s status 0x%x", hdev->name, status);
1455
1456 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONN_LOGICAL_LINK);
1457 if (!cp)
1458 return;
1459
1460 hci_dev_lock(hdev);
1461
1462 chan = hci_chan_list_lookup_handle(hdev, cp->log_handle);
1463 if (chan)
1464 hci_chan_del(chan);
1465
1466 hci_dev_unlock(hdev);
1467}
1468
1469static void hci_cs_disconn_physical_link(struct hci_dev *hdev, __u8 status)
1470{
1471 struct hci_cp_disconn_phys_link *cp;
1472 struct hci_conn *conn;
1473
1474 if (!status)
1475 return;
1476
1477 BT_DBG("%s status 0x%x", hdev->name, status);
1478
1479 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONN_PHYS_LINK);
1480 if (!cp)
1481 return;
1482
1483 hci_dev_lock(hdev);
1484
1485 conn = hci_conn_hash_lookup_handle(hdev, cp->phy_handle);
1486 if (conn) {
1487 conn->state = BT_CLOSED;
1488 hci_conn_del(conn);
1489 }
1490
1491 hci_dev_unlock(hdev);
1492}
1493
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03001494static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
1495{
1496 BT_DBG("%s status 0x%x", hdev->name, status);
1497}
1498
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001499static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1500{
1501 __u8 status = *((__u8 *) skb->data);
1502
1503 BT_DBG("%s status %d", hdev->name, status);
1504
Brian Gixa68668b2011-08-11 15:49:36 -07001505 if (!lmp_le_capable(hdev))
1506 clear_bit(HCI_INQUIRY, &hdev->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001507
Johan Hedberg23bb5762010-12-21 23:01:27 +02001508 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001509
Brian Gixa68668b2011-08-11 15:49:36 -07001510 if (test_bit(HCI_MGMT, &hdev->flags))
1511 mgmt_inquiry_complete_evt(hdev->id, status);
1512
1513 if (!lmp_le_capable(hdev))
1514 hci_conn_check_pending(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001515}
1516
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
1518{
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001519 struct inquiry_data data;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001520 struct inquiry_info *info = (void *) (skb->data + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 int num_rsp = *((__u8 *) skb->data);
1522
1523 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
1524
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001525 if (!num_rsp)
1526 return;
1527
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 hci_dev_lock(hdev);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001529
Johan Hedberge17acd42011-03-30 23:57:16 +03001530 for (; num_rsp; num_rsp--, info++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 bacpy(&data.bdaddr, &info->bdaddr);
1532 data.pscan_rep_mode = info->pscan_rep_mode;
1533 data.pscan_period_mode = info->pscan_period_mode;
1534 data.pscan_mode = info->pscan_mode;
1535 memcpy(data.dev_class, info->dev_class, 3);
1536 data.clock_offset = info->clock_offset;
1537 data.rssi = 0x00;
Marcel Holtmann41a96212008-07-14 20:13:48 +02001538 data.ssp_mode = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07001540 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
1541 info->dev_class, 0, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001543
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 hci_dev_unlock(hdev);
1545}
1546
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001547static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001549 struct hci_ev_conn_complete *ev = (void *) skb->data;
1550 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001552 BT_DBG("%s", hdev->name);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001553
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 hci_dev_lock(hdev);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001555
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001556 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
Marcel Holtmann94992372009-04-19 19:30:03 +02001557 if (!conn) {
1558 if (ev->link_type != SCO_LINK)
1559 goto unlock;
1560
1561 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
1562 if (!conn)
1563 goto unlock;
1564
1565 conn->type = SCO_LINK;
1566 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001567
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001568 if (!ev->status) {
1569 conn->handle = __le16_to_cpu(ev->handle);
Marcel Holtmann769be972008-07-14 20:13:49 +02001570
1571 if (conn->type == ACL_LINK) {
1572 conn->state = BT_CONFIG;
1573 hci_conn_hold(conn);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001574 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07001575 mgmt_connected(hdev->id, &ev->bdaddr, 0);
Brian Gixa68668b2011-08-11 15:49:36 -07001576 } else if (conn->type == LE_LINK) {
1577 conn->state = BT_CONNECTED;
1578 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07001579 mgmt_connected(hdev->id, &ev->bdaddr, 1);
Marcel Holtmann769be972008-07-14 20:13:49 +02001580 } else
1581 conn->state = BT_CONNECTED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001582
Marcel Holtmann9eba32b2009-08-22 14:19:26 -07001583 hci_conn_hold_device(conn);
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02001584 hci_conn_add_sysfs(conn);
1585
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001586 if (test_bit(HCI_AUTH, &hdev->flags))
1587 conn->link_mode |= HCI_LM_AUTH;
1588
1589 if (test_bit(HCI_ENCRYPT, &hdev->flags))
1590 conn->link_mode |= HCI_LM_ENCRYPT;
1591
1592 /* Get remote features */
1593 if (conn->type == ACL_LINK) {
1594 struct hci_cp_read_remote_features cp;
1595 cp.handle = ev->handle;
Marcel Holtmann769be972008-07-14 20:13:49 +02001596 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES,
1597 sizeof(cp), &cp);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001598 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001599
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001600 /* Set packet type for incoming connection */
Marcel Holtmanna8746412008-07-14 20:13:46 +02001601 if (!conn->out && hdev->hci_ver < 3) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001602 struct hci_cp_change_conn_ptype cp;
1603 cp.handle = ev->handle;
Marcel Holtmanna8746412008-07-14 20:13:46 +02001604 cp.pkt_type = cpu_to_le16(conn->pkt_type);
1605 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE,
1606 sizeof(cp), &cp);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001607 }
Johan Hedberg17d5c042011-01-22 06:09:08 +02001608 } else {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001609 conn->state = BT_CLOSED;
Brian Gixa68668b2011-08-11 15:49:36 -07001610 if (conn->type == ACL_LINK || conn->type == LE_LINK)
Johan Hedberg17d5c042011-01-22 06:09:08 +02001611 mgmt_connect_failed(hdev->id, &ev->bdaddr, ev->status);
1612 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001613
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001614 if (conn->type == ACL_LINK)
1615 hci_sco_setup(conn, ev->status);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001616
Marcel Holtmann769be972008-07-14 20:13:49 +02001617 if (ev->status) {
1618 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001619 hci_conn_del(conn);
Marcel Holtmannc89b6e62009-01-15 21:57:03 +01001620 } else if (ev->link_type != ACL_LINK)
1621 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001622
1623unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001625
1626 hci_conn_check_pending(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1630{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001631 struct hci_ev_conn_request *ev = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 int mask = hdev->link_mode;
1633
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001634 BT_DBG("%s bdaddr %s type 0x%x", hdev->name,
1635 batostr(&ev->bdaddr), ev->link_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
1638
Szymon Janc138d22e2011-02-17 16:44:23 +01001639 if ((mask & HCI_LM_ACCEPT) &&
1640 !hci_blacklist_lookup(hdev, &ev->bdaddr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 /* Connection accepted */
Marcel Holtmannc7bdd502008-07-14 20:13:47 +02001642 struct inquiry_entry *ie;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
1645 hci_dev_lock(hdev);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001646
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02001647 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
1648 if (ie)
Marcel Holtmannc7bdd502008-07-14 20:13:47 +02001649 memcpy(ie->data.dev_class, ev->dev_class, 3);
1650
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
1652 if (!conn) {
Nick Pellybbcda3b2010-02-11 11:54:28 -08001653 /* pkt_type not yet used for incoming connections */
1654 conn = hci_conn_add(hdev, ev->link_type, 0, &ev->bdaddr);
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02001655 if (!conn) {
Gustavo F. Padovan893ef972010-07-18 15:13:37 -03001656 BT_ERR("No memory for new connection");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 hci_dev_unlock(hdev);
1658 return;
1659 }
1660 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001661
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 memcpy(conn->dev_class, ev->dev_class, 3);
1663 conn->state = BT_CONNECT;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001664
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 hci_dev_unlock(hdev);
1666
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001667 if (ev->link_type == ACL_LINK || !lmp_esco_capable(hdev)) {
1668 struct hci_cp_accept_conn_req cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001670 bacpy(&cp.bdaddr, &ev->bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001672 if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
1673 cp.role = 0x00; /* Become master */
1674 else
1675 cp.role = 0x01; /* Remain slave */
1676
1677 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ,
1678 sizeof(cp), &cp);
1679 } else {
1680 struct hci_cp_accept_sync_conn_req cp;
1681
1682 bacpy(&cp.bdaddr, &ev->bdaddr);
Marcel Holtmanna8746412008-07-14 20:13:46 +02001683 cp.pkt_type = cpu_to_le16(conn->pkt_type);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001684
1685 cp.tx_bandwidth = cpu_to_le32(0x00001f40);
1686 cp.rx_bandwidth = cpu_to_le32(0x00001f40);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001687 cp.max_latency = cpu_to_le16(0x000A);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001688 cp.content_format = cpu_to_le16(hdev->voice_setting);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001689 cp.retrans_effort = 0x01;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001690
1691 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
1692 sizeof(cp), &cp);
1693 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 } else {
1695 /* Connection rejected */
1696 struct hci_cp_reject_conn_req cp;
1697
1698 bacpy(&cp.bdaddr, &ev->bdaddr);
1699 cp.reason = 0x0f;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001700 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
1702}
1703
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1705{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001706 struct hci_ev_disconn_complete *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02001707 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 BT_DBG("%s status %d", hdev->name, ev->status);
1710
Johan Hedberg8962ee72011-01-20 12:40:27 +02001711 if (ev->status) {
1712 mgmt_disconnect_failed(hdev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 return;
Johan Hedberg8962ee72011-01-20 12:40:27 +02001714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
1716 hci_dev_lock(hdev);
1717
Marcel Holtmann04837f62006-07-03 10:02:33 +02001718 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergf7520542011-01-20 12:34:39 +02001719 if (!conn)
1720 goto unlock;
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02001721
Johan Hedbergf7520542011-01-20 12:34:39 +02001722 conn->state = BT_CLOSED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
Brian Gixa68668b2011-08-11 15:49:36 -07001724 if (conn->type == ACL_LINK || conn->type == LE_LINK)
Johan Hedbergf7520542011-01-20 12:34:39 +02001725 mgmt_disconnected(hdev->id, &conn->dst);
1726
1727 hci_proto_disconn_cfm(conn, ev->reason);
1728 hci_conn_del(conn);
1729
1730unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 hci_dev_unlock(hdev);
1732}
1733
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001734static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1735{
1736 struct hci_ev_auth_complete *ev = (void *) skb->data;
1737 struct hci_conn *conn;
1738
1739 BT_DBG("%s status %d", hdev->name, ev->status);
1740
1741 hci_dev_lock(hdev);
1742
1743 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001744 if (conn) {
1745 if (ev->status == 0x06 && hdev->ssp_mode > 0 &&
1746 conn->ssp_mode > 0) {
1747 struct hci_cp_auth_requested cp;
Prabhakaran Mcb04401d2011-09-20 17:37:55 +05301748 hci_remove_link_key(hdev, &conn->dst);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001749 cp.handle = cpu_to_le16(conn->handle);
1750 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED,
1751 sizeof(cp), &cp);
1752 hci_dev_unlock(hdev);
1753 BT_INFO("Pin or key missing");
1754 return;
1755 }
Waldemar Rymarkiewicz54444292011-05-31 15:49:26 +02001756
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001757 if (!ev->status) {
Waldemar Rymarkiewicz54444292011-05-31 15:49:26 +02001758 conn->link_mode |= HCI_LM_AUTH;
1759 conn->sec_level = conn->pending_sec_level;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001760 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001761 mgmt_auth_failed(hdev->id, &conn->dst, ev->status);
1762 conn->sec_level = BT_SECURITY_LOW;
1763 }
1764
1765 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
1766
1767 if (conn->state == BT_CONFIG) {
1768 if (!ev->status && hdev->ssp_mode > 0 &&
1769 conn->ssp_mode > 0) {
1770 struct hci_cp_set_conn_encrypt cp;
1771 cp.handle = ev->handle;
1772 cp.encrypt = 0x01;
1773 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT,
1774 sizeof(cp), &cp);
1775 } else {
1776 conn->state = BT_CONNECTED;
1777 hci_proto_connect_cfm(conn, ev->status);
1778 hci_conn_put(conn);
1779 }
1780 } else {
1781 hci_auth_cfm(conn, ev->status);
1782
1783 hci_conn_hold(conn);
1784 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001785 hci_conn_put(conn);
1786 }
1787
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001788 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) {
1789 if (!ev->status) {
1790 struct hci_cp_set_conn_encrypt cp;
1791 cp.handle = ev->handle;
1792 cp.encrypt = 0x01;
1793 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT,
1794 sizeof(cp), &cp);
1795 } else {
1796 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
1797 hci_encrypt_cfm(conn, ev->status, 0x00);
1798 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001799 }
1800 }
1801
1802 hci_dev_unlock(hdev);
1803}
1804
1805static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
1806{
Johan Hedberg127178d2010-11-18 22:22:29 +02001807 struct hci_ev_remote_name *ev = (void *) skb->data;
1808 struct hci_conn *conn;
1809
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001810 BT_DBG("%s", hdev->name);
1811
1812 hci_conn_check_pending(hdev);
Johan Hedberg127178d2010-11-18 22:22:29 +02001813
1814 hci_dev_lock(hdev);
1815
Brian Gixa68668b2011-08-11 15:49:36 -07001816 if (test_bit(HCI_MGMT, &hdev->flags))
1817 mgmt_remote_name(hdev->id, &ev->bdaddr, ev->status, ev->name);
Johan Hedberga88a9652011-03-30 13:18:12 +03001818
Johan Hedberg127178d2010-11-18 22:22:29 +02001819 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001820 if (conn && hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02001821 struct hci_cp_auth_requested cp;
1822 cp.handle = __cpu_to_le16(conn->handle);
1823 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1824 }
1825
1826 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001827}
1828
1829static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
1830{
1831 struct hci_ev_encrypt_change *ev = (void *) skb->data;
1832 struct hci_conn *conn;
1833
1834 BT_DBG("%s status %d", hdev->name, ev->status);
1835
1836 hci_dev_lock(hdev);
1837
1838 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1839 if (conn) {
1840 if (!ev->status) {
Marcel Holtmannae293192008-07-14 20:13:45 +02001841 if (ev->encrypt) {
1842 /* Encryption implies authentication */
1843 conn->link_mode |= HCI_LM_AUTH;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001844 conn->link_mode |= HCI_LM_ENCRYPT;
Vinicius Costa Gomes64532ec2011-06-09 18:50:53 -03001845 conn->sec_level = conn->pending_sec_level;
Marcel Holtmannae293192008-07-14 20:13:45 +02001846 } else
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001847 conn->link_mode &= ~HCI_LM_ENCRYPT;
1848 }
1849
1850 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
1851
Marcel Holtmannf8558552008-07-14 20:13:49 +02001852 if (conn->state == BT_CONFIG) {
1853 if (!ev->status)
1854 conn->state = BT_CONNECTED;
1855
1856 hci_proto_connect_cfm(conn, ev->status);
1857 hci_conn_put(conn);
1858 } else
1859 hci_encrypt_cfm(conn, ev->status, ev->encrypt);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001860 }
1861
1862 hci_dev_unlock(hdev);
1863}
1864
1865static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1866{
1867 struct hci_ev_change_link_key_complete *ev = (void *) skb->data;
1868 struct hci_conn *conn;
1869
1870 BT_DBG("%s status %d", hdev->name, ev->status);
1871
1872 hci_dev_lock(hdev);
1873
1874 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1875 if (conn) {
1876 if (!ev->status)
1877 conn->link_mode |= HCI_LM_SECURE;
1878
1879 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
1880
1881 hci_key_change_cfm(conn, ev->status);
1882 }
1883
1884 hci_dev_unlock(hdev);
1885}
1886
1887static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
1888{
1889 struct hci_ev_remote_features *ev = (void *) skb->data;
1890 struct hci_conn *conn;
1891
1892 BT_DBG("%s status %d", hdev->name, ev->status);
1893
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001894 hci_dev_lock(hdev);
1895
1896 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergccd556f2010-11-10 17:11:51 +02001897 if (!conn)
1898 goto unlock;
Marcel Holtmann769be972008-07-14 20:13:49 +02001899
Johan Hedbergccd556f2010-11-10 17:11:51 +02001900 if (!ev->status)
1901 memcpy(conn->features, ev->features, 8);
1902
1903 if (conn->state != BT_CONFIG)
1904 goto unlock;
1905
1906 if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) {
1907 struct hci_cp_read_remote_ext_features cp;
1908 cp.handle = ev->handle;
1909 cp.page = 0x01;
1910 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
Marcel Holtmann769be972008-07-14 20:13:49 +02001911 sizeof(cp), &cp);
Johan Hedberg392599b2010-11-18 22:22:28 +02001912 goto unlock;
1913 }
1914
Johan Hedberg127178d2010-11-18 22:22:29 +02001915 if (!ev->status) {
1916 struct hci_cp_remote_name_req cp;
1917 memset(&cp, 0, sizeof(cp));
1918 bacpy(&cp.bdaddr, &conn->dst);
1919 cp.pscan_rep_mode = 0x02;
1920 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
1921 }
Johan Hedberg392599b2010-11-18 22:22:28 +02001922
Johan Hedberg127178d2010-11-18 22:22:29 +02001923 if (!hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02001924 conn->state = BT_CONNECTED;
1925 hci_proto_connect_cfm(conn, ev->status);
1926 hci_conn_put(conn);
Marcel Holtmann769be972008-07-14 20:13:49 +02001927 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001928
Johan Hedbergccd556f2010-11-10 17:11:51 +02001929unlock:
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001930 hci_dev_unlock(hdev);
1931}
1932
1933static inline void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb)
1934{
1935 BT_DBG("%s", hdev->name);
1936}
1937
1938static inline void hci_qos_setup_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1939{
1940 BT_DBG("%s", hdev->name);
1941}
1942
1943static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1944{
1945 struct hci_ev_cmd_complete *ev = (void *) skb->data;
1946 __u16 opcode;
1947
1948 skb_pull(skb, sizeof(*ev));
1949
1950 opcode = __le16_to_cpu(ev->opcode);
1951
1952 switch (opcode) {
1953 case HCI_OP_INQUIRY_CANCEL:
1954 hci_cc_inquiry_cancel(hdev, skb);
1955 break;
1956
1957 case HCI_OP_EXIT_PERIODIC_INQ:
1958 hci_cc_exit_periodic_inq(hdev, skb);
1959 break;
1960
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001961 case HCI_OP_LINK_KEY_REPLY:
1962 hci_cc_link_key_reply(hdev, skb);
1963 break;
1964
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001965 case HCI_OP_REMOTE_NAME_REQ_CANCEL:
1966 hci_cc_remote_name_req_cancel(hdev, skb);
1967 break;
1968
1969 case HCI_OP_ROLE_DISCOVERY:
1970 hci_cc_role_discovery(hdev, skb);
1971 break;
1972
Marcel Holtmanne4e8e372008-07-14 20:13:47 +02001973 case HCI_OP_READ_LINK_POLICY:
1974 hci_cc_read_link_policy(hdev, skb);
1975 break;
1976
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001977 case HCI_OP_WRITE_LINK_POLICY:
1978 hci_cc_write_link_policy(hdev, skb);
1979 break;
1980
Marcel Holtmanne4e8e372008-07-14 20:13:47 +02001981 case HCI_OP_READ_DEF_LINK_POLICY:
1982 hci_cc_read_def_link_policy(hdev, skb);
1983 break;
1984
1985 case HCI_OP_WRITE_DEF_LINK_POLICY:
1986 hci_cc_write_def_link_policy(hdev, skb);
1987 break;
1988
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001989 case HCI_OP_RESET:
1990 hci_cc_reset(hdev, skb);
1991 break;
1992
1993 case HCI_OP_WRITE_LOCAL_NAME:
1994 hci_cc_write_local_name(hdev, skb);
1995 break;
1996
1997 case HCI_OP_READ_LOCAL_NAME:
1998 hci_cc_read_local_name(hdev, skb);
1999 break;
2000
2001 case HCI_OP_WRITE_AUTH_ENABLE:
2002 hci_cc_write_auth_enable(hdev, skb);
2003 break;
2004
2005 case HCI_OP_WRITE_ENCRYPT_MODE:
2006 hci_cc_write_encrypt_mode(hdev, skb);
2007 break;
2008
2009 case HCI_OP_WRITE_SCAN_ENABLE:
2010 hci_cc_write_scan_enable(hdev, skb);
2011 break;
2012
2013 case HCI_OP_READ_CLASS_OF_DEV:
2014 hci_cc_read_class_of_dev(hdev, skb);
2015 break;
2016
2017 case HCI_OP_WRITE_CLASS_OF_DEV:
2018 hci_cc_write_class_of_dev(hdev, skb);
2019 break;
2020
2021 case HCI_OP_READ_VOICE_SETTING:
2022 hci_cc_read_voice_setting(hdev, skb);
2023 break;
2024
2025 case HCI_OP_WRITE_VOICE_SETTING:
2026 hci_cc_write_voice_setting(hdev, skb);
2027 break;
2028
2029 case HCI_OP_HOST_BUFFER_SIZE:
2030 hci_cc_host_buffer_size(hdev, skb);
2031 break;
2032
Marcel Holtmann333140b2008-07-14 20:13:48 +02002033 case HCI_OP_READ_SSP_MODE:
2034 hci_cc_read_ssp_mode(hdev, skb);
2035 break;
2036
2037 case HCI_OP_WRITE_SSP_MODE:
2038 hci_cc_write_ssp_mode(hdev, skb);
2039 break;
2040
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002041 case HCI_OP_READ_LOCAL_VERSION:
2042 hci_cc_read_local_version(hdev, skb);
2043 break;
2044
2045 case HCI_OP_READ_LOCAL_COMMANDS:
2046 hci_cc_read_local_commands(hdev, skb);
2047 break;
2048
2049 case HCI_OP_READ_LOCAL_FEATURES:
2050 hci_cc_read_local_features(hdev, skb);
2051 break;
2052
2053 case HCI_OP_READ_BUFFER_SIZE:
2054 hci_cc_read_buffer_size(hdev, skb);
2055 break;
2056
2057 case HCI_OP_READ_BD_ADDR:
2058 hci_cc_read_bd_addr(hdev, skb);
2059 break;
2060
Johan Hedberg23bb5762010-12-21 23:01:27 +02002061 case HCI_OP_WRITE_CA_TIMEOUT:
2062 hci_cc_write_ca_timeout(hdev, skb);
2063 break;
2064
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002065 case HCI_OP_READ_FLOW_CONTROL_MODE:
2066 hci_cc_read_flow_control_mode(hdev, skb);
2067 break;
2068
2069 case HCI_OP_READ_DATA_BLOCK_SIZE:
2070 hci_cc_read_data_block_size(hdev, skb);
2071 break;
2072
2073 case HCI_OP_READ_LOCAL_AMP_INFO:
2074 hci_cc_read_local_amp_info(hdev, skb);
2075 break;
2076
2077 case HCI_OP_READ_LOCAL_AMP_ASSOC:
2078 case HCI_OP_WRITE_REMOTE_AMP_ASSOC:
2079 hci_amp_cmd_complete(hdev, opcode, skb);
2080 break;
2081
Johan Hedbergb0916ea2011-01-10 13:44:55 +02002082 case HCI_OP_DELETE_STORED_LINK_KEY:
2083 hci_cc_delete_stored_link_key(hdev, skb);
2084 break;
2085
Johan Hedbergd5859e22011-01-25 01:19:58 +02002086 case HCI_OP_SET_EVENT_MASK:
2087 hci_cc_set_event_mask(hdev, skb);
2088 break;
2089
2090 case HCI_OP_WRITE_INQUIRY_MODE:
2091 hci_cc_write_inquiry_mode(hdev, skb);
2092 break;
2093
2094 case HCI_OP_READ_INQ_RSP_TX_POWER:
2095 hci_cc_read_inq_rsp_tx_power(hdev, skb);
2096 break;
2097
2098 case HCI_OP_SET_EVENT_FLT:
2099 hci_cc_set_event_flt(hdev, skb);
2100 break;
2101
Johan Hedberg980e1a52011-01-22 06:10:07 +02002102 case HCI_OP_PIN_CODE_REPLY:
2103 hci_cc_pin_code_reply(hdev, skb);
2104 break;
2105
2106 case HCI_OP_PIN_CODE_NEG_REPLY:
2107 hci_cc_pin_code_neg_reply(hdev, skb);
2108 break;
2109
Szymon Jancc35938b2011-03-22 13:12:21 +01002110 case HCI_OP_READ_LOCAL_OOB_DATA:
2111 hci_cc_read_local_oob_data_reply(hdev, skb);
2112 break;
2113
Ville Tervo6ed58ec2011-02-10 22:38:48 -03002114 case HCI_OP_LE_READ_BUFFER_SIZE:
2115 hci_cc_le_read_buffer_size(hdev, skb);
2116 break;
2117
Johan Hedberga5c29682011-02-19 12:05:57 -03002118 case HCI_OP_USER_CONFIRM_REPLY:
2119 hci_cc_user_confirm_reply(hdev, skb);
2120 break;
2121
2122 case HCI_OP_USER_CONFIRM_NEG_REPLY:
2123 hci_cc_user_confirm_neg_reply(hdev, skb);
2124 break;
2125
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03002126 case HCI_OP_LE_LTK_REPLY:
2127 hci_cc_le_ltk_reply(hdev, skb);
2128 break;
2129
2130 case HCI_OP_LE_LTK_NEG_REPLY:
2131 hci_cc_le_ltk_neg_reply(hdev, skb);
2132 break;
2133
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002134 case HCI_OP_LE_SET_SCAN_ENABLE:
2135 hci_cc_le_set_scan_enable(hdev, skb);
Andre Guedese326af42011-06-30 19:20:53 -03002136 break;
2137
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002138 default:
2139 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
2140 break;
2141 }
2142
Ville Tervo6bd32322011-02-16 16:32:41 +02002143 if (ev->opcode != HCI_OP_NOP)
2144 del_timer(&hdev->cmd_timer);
2145
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002146 if (ev->ncmd) {
2147 atomic_set(&hdev->cmd_cnt, 1);
2148 if (!skb_queue_empty(&hdev->cmd_q))
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002149 tasklet_schedule(&hdev->cmd_task);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002150 }
2151}
2152
2153static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2154{
2155 struct hci_ev_cmd_status *ev = (void *) skb->data;
2156 __u16 opcode;
2157
2158 skb_pull(skb, sizeof(*ev));
2159
2160 opcode = __le16_to_cpu(ev->opcode);
2161
2162 switch (opcode) {
2163 case HCI_OP_INQUIRY:
2164 hci_cs_inquiry(hdev, ev->status);
2165 break;
2166
2167 case HCI_OP_CREATE_CONN:
2168 hci_cs_create_conn(hdev, ev->status);
2169 break;
2170
2171 case HCI_OP_ADD_SCO:
2172 hci_cs_add_sco(hdev, ev->status);
2173 break;
2174
Marcel Holtmannf8558552008-07-14 20:13:49 +02002175 case HCI_OP_AUTH_REQUESTED:
2176 hci_cs_auth_requested(hdev, ev->status);
2177 break;
2178
2179 case HCI_OP_SET_CONN_ENCRYPT:
2180 hci_cs_set_conn_encrypt(hdev, ev->status);
2181 break;
2182
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002183 case HCI_OP_REMOTE_NAME_REQ:
2184 hci_cs_remote_name_req(hdev, ev->status);
2185 break;
2186
Marcel Holtmann769be972008-07-14 20:13:49 +02002187 case HCI_OP_READ_REMOTE_FEATURES:
2188 hci_cs_read_remote_features(hdev, ev->status);
2189 break;
2190
2191 case HCI_OP_READ_REMOTE_EXT_FEATURES:
2192 hci_cs_read_remote_ext_features(hdev, ev->status);
2193 break;
2194
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002195 case HCI_OP_SETUP_SYNC_CONN:
2196 hci_cs_setup_sync_conn(hdev, ev->status);
2197 break;
2198
2199 case HCI_OP_SNIFF_MODE:
2200 hci_cs_sniff_mode(hdev, ev->status);
2201 break;
2202
2203 case HCI_OP_EXIT_SNIFF_MODE:
2204 hci_cs_exit_sniff_mode(hdev, ev->status);
2205 break;
2206
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002207 case HCI_OP_CREATE_LOGICAL_LINK:
2208 hci_cs_create_logical_link(hdev, ev->status);
2209 break;
2210
2211 case HCI_OP_ACCEPT_LOGICAL_LINK:
2212 hci_cs_accept_logical_link(hdev, ev->status);
2213 break;
2214
2215 case HCI_OP_DISCONN_LOGICAL_LINK:
2216 hci_cs_disconn_logical_link(hdev, ev->status);
2217 break;
2218
2219 case HCI_OP_FLOW_SPEC_MODIFY:
2220 hci_cs_flow_spec_modify(hdev, ev->status);
2221 break;
2222
2223 case HCI_OP_CREATE_PHYS_LINK:
2224 case HCI_OP_ACCEPT_PHYS_LINK:
2225 hci_amp_cmd_status(hdev, opcode, ev->status);
2226 break;
2227
2228 case HCI_OP_DISCONN_PHYS_LINK:
2229 hci_cs_disconn_physical_link(hdev, ev->status);
2230
Johan Hedberg8962ee72011-01-20 12:40:27 +02002231 case HCI_OP_DISCONNECT:
2232 if (ev->status != 0)
2233 mgmt_disconnect_failed(hdev->id);
2234 break;
2235
Ville Tervofcd89c02011-02-10 22:38:47 -03002236 case HCI_OP_LE_CREATE_CONN:
2237 hci_cs_le_create_conn(hdev, ev->status);
2238 break;
2239
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03002240 case HCI_OP_LE_START_ENC:
2241 hci_cs_le_start_enc(hdev, ev->status);
2242 break;
2243
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002244 default:
2245 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
2246 break;
2247 }
2248
Ville Tervo6bd32322011-02-16 16:32:41 +02002249 if (ev->opcode != HCI_OP_NOP)
2250 del_timer(&hdev->cmd_timer);
2251
Gustavo F. Padovan10572132011-03-16 15:36:29 -03002252 if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002253 atomic_set(&hdev->cmd_cnt, 1);
2254 if (!skb_queue_empty(&hdev->cmd_q))
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002255 tasklet_schedule(&hdev->cmd_task);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002256 }
2257}
2258
2259static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2260{
2261 struct hci_ev_role_change *ev = (void *) skb->data;
2262 struct hci_conn *conn;
2263
2264 BT_DBG("%s status %d", hdev->name, ev->status);
2265
2266 hci_dev_lock(hdev);
2267
2268 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2269 if (conn) {
2270 if (!ev->status) {
2271 if (ev->role)
2272 conn->link_mode &= ~HCI_LM_MASTER;
2273 else
2274 conn->link_mode |= HCI_LM_MASTER;
2275 }
2276
2277 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->pend);
2278
2279 hci_role_switch_cfm(conn, ev->status, ev->role);
2280 }
2281
2282 hci_dev_unlock(hdev);
2283}
2284
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
2286{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002287 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
Marcel Holtmann1ebb9252005-11-08 09:57:21 -08002288 __le16 *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 int i;
2290
2291 skb_pull(skb, sizeof(*ev));
2292
2293 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
2294
2295 if (skb->len < ev->num_hndl * 4) {
2296 BT_DBG("%s bad parameters", hdev->name);
2297 return;
2298 }
2299
2300 tasklet_disable(&hdev->tx_task);
2301
Marcel Holtmann1ebb9252005-11-08 09:57:21 -08002302 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002303 struct hci_conn *conn = NULL;
2304 struct hci_chan *chan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 __u16 handle, count;
2306
Harvey Harrison83985312008-05-02 16:25:46 -07002307 handle = get_unaligned_le16(ptr++);
2308 count = get_unaligned_le16(ptr++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002310 if (hdev->dev_type == HCI_BREDR)
2311 conn = hci_conn_hash_lookup_handle(hdev, handle);
2312 else {
2313 chan = hci_chan_list_lookup_handle(hdev, handle);
2314 if (chan)
2315 conn = chan->conn;
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 if (conn) {
2318 conn->sent -= count;
2319
Marcel Holtmann5b7f9902007-07-11 09:51:55 +02002320 if (conn->type == ACL_LINK) {
Andrei Emeltchenko70f230202010-12-01 16:58:25 +02002321 hdev->acl_cnt += count;
2322 if (hdev->acl_cnt > hdev->acl_pkts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 hdev->acl_cnt = hdev->acl_pkts;
Ville Tervo6ed58ec2011-02-10 22:38:48 -03002324 } else if (conn->type == LE_LINK) {
2325 if (hdev->le_pkts) {
2326 hdev->le_cnt += count;
2327 if (hdev->le_cnt > hdev->le_pkts)
2328 hdev->le_cnt = hdev->le_pkts;
2329 } else {
2330 hdev->acl_cnt += count;
2331 if (hdev->acl_cnt > hdev->acl_pkts)
2332 hdev->acl_cnt = hdev->acl_pkts;
2333 }
Marcel Holtmann5b7f9902007-07-11 09:51:55 +02002334 } else {
Andrei Emeltchenko70f230202010-12-01 16:58:25 +02002335 hdev->sco_cnt += count;
2336 if (hdev->sco_cnt > hdev->sco_pkts)
Marcel Holtmann5b7f9902007-07-11 09:51:55 +02002337 hdev->sco_cnt = hdev->sco_pkts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 }
2339 }
2340 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002341
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002342 tasklet_schedule(&hdev->tx_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343
2344 tasklet_enable(&hdev->tx_task);
2345}
2346
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002347static inline void hci_num_comp_blocks_evt(struct hci_dev *hdev,
2348 struct sk_buff *skb)
2349{
2350 struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
2351 __le16 *ptr;
2352 int i;
2353
2354 skb_pull(skb, sizeof(*ev));
2355
2356 BT_DBG("%s total_num_blocks %d num_hndl %d",
2357 hdev->name, ev->total_num_blocks, ev->num_hndl);
2358
2359 if (skb->len < ev->num_hndl * 6) {
2360 BT_DBG("%s bad parameters", hdev->name);
2361 return;
2362 }
2363
2364 tasklet_disable(&hdev->tx_task);
2365
2366 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) {
2367 struct hci_conn *conn = NULL;
2368 struct hci_chan *chan;
2369 __u16 handle, block_count;
2370
2371 handle = get_unaligned_le16(ptr++);
2372
2373 /* Skip packet count */
2374 ptr++;
2375 block_count = get_unaligned_le16(ptr++);
2376
2377 BT_DBG("%s handle %d count %d", hdev->name, handle,
2378 block_count);
2379
2380 if (hdev->dev_type == HCI_BREDR)
2381 conn = hci_conn_hash_lookup_handle(hdev, handle);
2382 else {
2383 chan = hci_chan_list_lookup_handle(hdev, handle);
2384 if (chan)
2385 conn = chan->conn;
2386 }
2387 if (conn) {
2388 BT_DBG("%s conn %p sent %d", hdev->name,
2389 conn, conn->sent);
2390
2391 conn->sent -= block_count;
2392
2393 if (conn->type == ACL_LINK) {
2394 hdev->acl_cnt += block_count;
2395 if (hdev->acl_cnt > hdev->acl_pkts)
2396 hdev->acl_cnt = hdev->acl_pkts;
2397 } else {
2398 /* We should not find ourselves here */
2399 BT_DBG("Unexpected event for SCO connection");
2400 }
2401 }
2402 }
2403
2404 tasklet_schedule(&hdev->tx_task);
2405
2406 tasklet_enable(&hdev->tx_task);
2407}
2408
Marcel Holtmann04837f62006-07-03 10:02:33 +02002409static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002411 struct hci_ev_mode_change *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002412 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
2414 BT_DBG("%s status %d", hdev->name, ev->status);
2415
2416 hci_dev_lock(hdev);
2417
Marcel Holtmann04837f62006-07-03 10:02:33 +02002418 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2419 if (conn) {
2420 conn->mode = ev->mode;
2421 conn->interval = __le16_to_cpu(ev->interval);
2422
2423 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) {
2424 if (conn->mode == HCI_CM_ACTIVE)
2425 conn->power_save = 1;
2426 else
2427 conn->power_save = 0;
2428 }
Marcel Holtmanne73439d2010-07-26 10:06:00 -04002429
2430 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
2431 hci_sco_setup(conn, ev->status);
Marcel Holtmann04837f62006-07-03 10:02:33 +02002432 }
2433
2434 hci_dev_unlock(hdev);
2435}
2436
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2438{
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002439 struct hci_ev_pin_code_req *ev = (void *) skb->data;
2440 struct hci_conn *conn;
2441
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002442 BT_DBG("%s", hdev->name);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002443
2444 hci_dev_lock(hdev);
2445
2446 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Marcel Holtmann3d7a9d12009-05-09 12:09:21 -07002447 if (conn && conn->state == BT_CONNECTED) {
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002448 hci_conn_hold(conn);
2449 conn->disc_timeout = HCI_PAIRING_TIMEOUT;
2450 hci_conn_put(conn);
2451 }
2452
Johan Hedberg03b555e2011-01-04 15:40:05 +02002453 if (!test_bit(HCI_PAIRABLE, &hdev->flags))
2454 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY,
2455 sizeof(ev->bdaddr), &ev->bdaddr);
Waldemar Rymarkiewicza770bb52011-04-28 12:07:59 +02002456
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002457 if (test_bit(HCI_MGMT, &hdev->flags))
2458 mgmt_pin_code_request(hdev->id, &ev->bdaddr);
Johan Hedberg980e1a52011-01-22 06:10:07 +02002459
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002460 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461}
2462
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2464{
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002465 struct hci_ev_link_key_req *ev = (void *) skb->data;
2466 struct hci_cp_link_key_reply cp;
2467 struct hci_conn *conn;
2468 struct link_key *key;
2469
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002470 BT_DBG("%s", hdev->name);
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002471
2472 if (!test_bit(HCI_LINK_KEYS, &hdev->flags))
2473 return;
2474
2475 hci_dev_lock(hdev);
2476
2477 key = hci_find_link_key(hdev, &ev->bdaddr);
2478 if (!key) {
2479 BT_DBG("%s link key not found for %s", hdev->name,
2480 batostr(&ev->bdaddr));
2481 goto not_found;
2482 }
2483
2484 BT_DBG("%s found key type %u for %s", hdev->name, key->type,
2485 batostr(&ev->bdaddr));
2486
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002487 if (!test_bit(HCI_DEBUG_KEYS, &hdev->flags) && key->type == 0x03) {
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002488 BT_DBG("%s ignoring debug key", hdev->name);
2489 goto not_found;
2490 }
2491
2492 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2493
Prabhakaran Mc6001a712011-09-06 11:56:25 +05302494 if (conn) {
2495 BT_DBG("Conn pending sec level is %d, ssp is %d, key len is %d",
2496 conn->pending_sec_level, conn->ssp_mode, key->pin_len);
2497 }
2498 if (conn && (conn->ssp_mode == 0) &&
2499 (conn->pending_sec_level == BT_SECURITY_HIGH) &&
2500 (key->pin_len != 16)) {
2501 BT_DBG("Security is high ignoring this key");
2502 goto not_found;
2503 }
2504
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002505 if (key->type == 0x04 && conn && conn->auth_type != 0xff &&
2506 (conn->auth_type & 0x01)) {
2507 BT_DBG("%s ignoring unauthenticated key", hdev->name);
2508 goto not_found;
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002509 }
2510
2511 bacpy(&cp.bdaddr, &ev->bdaddr);
2512 memcpy(cp.link_key, key->val, 16);
2513
2514 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp);
2515
2516 hci_dev_unlock(hdev);
2517
2518 return;
2519
2520not_found:
2521 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr);
2522 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523}
2524
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
2526{
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002527 struct hci_ev_link_key_notify *ev = (void *) skb->data;
2528 struct hci_conn *conn;
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002529 u8 pin_len = 0;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002530
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002531 BT_DBG("%s type %d", hdev->name, ev->key_type);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002532
2533 hci_dev_lock(hdev);
2534
2535 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2536 if (conn) {
2537 hci_conn_hold(conn);
2538 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002539
2540 memcpy(conn->link_key, ev->link_key, 16);
2541 conn->key_type = ev->key_type;
2542 hci_disconnect_amp(conn, 0x06);
2543
Johan Hedberg980e1a52011-01-22 06:10:07 +02002544 pin_len = conn->pin_length;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002545 hci_conn_put(conn);
2546 }
2547
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002548 if (test_bit(HCI_LINK_KEYS, &hdev->flags))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002549 hci_add_link_key(hdev, 1, &ev->bdaddr, ev->link_key,
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002550 ev->key_type, pin_len);
2551
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002552 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553}
2554
Marcel Holtmann04837f62006-07-03 10:02:33 +02002555static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb)
2556{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002557 struct hci_ev_clock_offset *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002558 struct hci_conn *conn;
2559
2560 BT_DBG("%s status %d", hdev->name, ev->status);
2561
2562 hci_dev_lock(hdev);
2563
2564 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 if (conn && !ev->status) {
2566 struct inquiry_entry *ie;
2567
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002568 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
2569 if (ie) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 ie->data.clock_offset = ev->clock_offset;
2571 ie->timestamp = jiffies;
2572 }
2573 }
2574
2575 hci_dev_unlock(hdev);
2576}
2577
Marcel Holtmanna8746412008-07-14 20:13:46 +02002578static inline void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2579{
2580 struct hci_ev_pkt_type_change *ev = (void *) skb->data;
2581 struct hci_conn *conn;
2582
2583 BT_DBG("%s status %d", hdev->name, ev->status);
2584
2585 hci_dev_lock(hdev);
2586
2587 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2588 if (conn && !ev->status)
2589 conn->pkt_type = __le16_to_cpu(ev->pkt_type);
2590
2591 hci_dev_unlock(hdev);
2592}
2593
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002594static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
2595{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002596 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002597 struct inquiry_entry *ie;
2598
2599 BT_DBG("%s", hdev->name);
2600
2601 hci_dev_lock(hdev);
2602
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002603 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
2604 if (ie) {
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002605 ie->data.pscan_rep_mode = ev->pscan_rep_mode;
2606 ie->timestamp = jiffies;
2607 }
2608
2609 hci_dev_unlock(hdev);
2610}
2611
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002612static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct sk_buff *skb)
2613{
2614 struct inquiry_data data;
2615 int num_rsp = *((__u8 *) skb->data);
2616
2617 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
2618
2619 if (!num_rsp)
2620 return;
2621
2622 hci_dev_lock(hdev);
2623
2624 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {
Szymon Janc138d22e2011-02-17 16:44:23 +01002625 struct inquiry_info_with_rssi_and_pscan_mode *info;
2626 info = (void *) (skb->data + 1);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002627
Johan Hedberge17acd42011-03-30 23:57:16 +03002628 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002629 bacpy(&data.bdaddr, &info->bdaddr);
2630 data.pscan_rep_mode = info->pscan_rep_mode;
2631 data.pscan_period_mode = info->pscan_period_mode;
2632 data.pscan_mode = info->pscan_mode;
2633 memcpy(data.dev_class, info->dev_class, 3);
2634 data.clock_offset = info->clock_offset;
2635 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002636 data.ssp_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002637 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07002638 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
Johan Hedberge17acd42011-03-30 23:57:16 +03002639 info->dev_class, info->rssi,
Brian Gixa68668b2011-08-11 15:49:36 -07002640 0, NULL);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002641 }
2642 } else {
2643 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
2644
Johan Hedberge17acd42011-03-30 23:57:16 +03002645 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002646 bacpy(&data.bdaddr, &info->bdaddr);
2647 data.pscan_rep_mode = info->pscan_rep_mode;
2648 data.pscan_period_mode = info->pscan_period_mode;
2649 data.pscan_mode = 0x00;
2650 memcpy(data.dev_class, info->dev_class, 3);
2651 data.clock_offset = info->clock_offset;
2652 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002653 data.ssp_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002654 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07002655 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
Johan Hedberge17acd42011-03-30 23:57:16 +03002656 info->dev_class, info->rssi,
Brian Gixa68668b2011-08-11 15:49:36 -07002657 0, NULL);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002658 }
2659 }
2660
2661 hci_dev_unlock(hdev);
2662}
2663
2664static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
2665{
Marcel Holtmann41a96212008-07-14 20:13:48 +02002666 struct hci_ev_remote_ext_features *ev = (void *) skb->data;
2667 struct hci_conn *conn;
2668
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002669 BT_DBG("%s", hdev->name);
Marcel Holtmann41a96212008-07-14 20:13:48 +02002670
Marcel Holtmann41a96212008-07-14 20:13:48 +02002671 hci_dev_lock(hdev);
2672
2673 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergccd556f2010-11-10 17:11:51 +02002674 if (!conn)
2675 goto unlock;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002676
Johan Hedbergccd556f2010-11-10 17:11:51 +02002677 if (!ev->status && ev->page == 0x01) {
2678 struct inquiry_entry *ie;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002679
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002680 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
2681 if (ie)
Johan Hedbergccd556f2010-11-10 17:11:51 +02002682 ie->data.ssp_mode = (ev->features[0] & 0x01);
Marcel Holtmann769be972008-07-14 20:13:49 +02002683
Johan Hedbergccd556f2010-11-10 17:11:51 +02002684 conn->ssp_mode = (ev->features[0] & 0x01);
Marcel Holtmann41a96212008-07-14 20:13:48 +02002685 }
2686
Johan Hedbergccd556f2010-11-10 17:11:51 +02002687 if (conn->state != BT_CONFIG)
2688 goto unlock;
2689
Johan Hedberg127178d2010-11-18 22:22:29 +02002690 if (!ev->status) {
2691 struct hci_cp_remote_name_req cp;
2692 memset(&cp, 0, sizeof(cp));
2693 bacpy(&cp.bdaddr, &conn->dst);
2694 cp.pscan_rep_mode = 0x02;
2695 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2696 }
Johan Hedberg392599b2010-11-18 22:22:28 +02002697
Johan Hedberg127178d2010-11-18 22:22:29 +02002698 if (!hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02002699 conn->state = BT_CONNECTED;
2700 hci_proto_connect_cfm(conn, ev->status);
2701 hci_conn_put(conn);
2702 }
2703
2704unlock:
Marcel Holtmann41a96212008-07-14 20:13:48 +02002705 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002706}
2707
2708static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2709{
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002710 struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
2711 struct hci_conn *conn;
2712
2713 BT_DBG("%s status %d", hdev->name, ev->status);
2714
2715 hci_dev_lock(hdev);
2716
2717 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
Marcel Holtmann9dc0a3a2008-07-14 20:13:46 +02002718 if (!conn) {
2719 if (ev->link_type == ESCO_LINK)
2720 goto unlock;
2721
2722 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
2723 if (!conn)
2724 goto unlock;
2725
2726 conn->type = SCO_LINK;
2727 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002728
Marcel Holtmann732547f2009-04-19 19:14:14 +02002729 switch (ev->status) {
2730 case 0x00:
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002731 conn->handle = __le16_to_cpu(ev->handle);
2732 conn->state = BT_CONNECTED;
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02002733
Marcel Holtmann9eba32b2009-08-22 14:19:26 -07002734 hci_conn_hold_device(conn);
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02002735 hci_conn_add_sysfs(conn);
Marcel Holtmann732547f2009-04-19 19:14:14 +02002736 break;
2737
Stephen Coe705e5712010-02-16 11:29:44 -05002738 case 0x11: /* Unsupported Feature or Parameter Value */
Marcel Holtmann732547f2009-04-19 19:14:14 +02002739 case 0x1c: /* SCO interval rejected */
Nick Pelly1038a002010-02-03 11:42:26 -08002740 case 0x1a: /* Unsupported Remote Feature */
Marcel Holtmann732547f2009-04-19 19:14:14 +02002741 case 0x1f: /* Unspecified error */
2742 if (conn->out && conn->attempt < 2) {
Kun Han Kim15b911f2011-07-08 09:30:28 -07002743 if (!conn->hdev->is_wbs)
2744 conn->pkt_type =
2745 (hdev->esco_type & SCO_ESCO_MASK) |
Marcel Holtmann732547f2009-04-19 19:14:14 +02002746 (hdev->esco_type & EDR_ESCO_MASK);
2747 hci_setup_sync(conn, conn->link->handle);
2748 goto unlock;
2749 }
2750 /* fall through */
2751
2752 default:
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002753 conn->state = BT_CLOSED;
Marcel Holtmann732547f2009-04-19 19:14:14 +02002754 break;
2755 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002756
2757 hci_proto_connect_cfm(conn, ev->status);
2758 if (ev->status)
2759 hci_conn_del(conn);
2760
2761unlock:
2762 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002763}
2764
2765static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb)
2766{
2767 BT_DBG("%s", hdev->name);
2768}
2769
Marcel Holtmann04837f62006-07-03 10:02:33 +02002770static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb)
2771{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002772 struct hci_ev_sniff_subrate *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002773
2774 BT_DBG("%s status %d", hdev->name, ev->status);
Marcel Holtmann04837f62006-07-03 10:02:33 +02002775}
2776
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002777static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
2778{
2779 struct inquiry_data data;
2780 struct extended_inquiry_info *info = (void *) (skb->data + 1);
2781 int num_rsp = *((__u8 *) skb->data);
2782
2783 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
2784
2785 if (!num_rsp)
2786 return;
2787
2788 hci_dev_lock(hdev);
2789
Johan Hedberge17acd42011-03-30 23:57:16 +03002790 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002791 bacpy(&data.bdaddr, &info->bdaddr);
Szymon Janc138d22e2011-02-17 16:44:23 +01002792 data.pscan_rep_mode = info->pscan_rep_mode;
2793 data.pscan_period_mode = info->pscan_period_mode;
2794 data.pscan_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002795 memcpy(data.dev_class, info->dev_class, 3);
Szymon Janc138d22e2011-02-17 16:44:23 +01002796 data.clock_offset = info->clock_offset;
2797 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002798 data.ssp_mode = 0x01;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002799 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07002800 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
2801 info->dev_class, info->rssi,
2802 HCI_MAX_EIR_LENGTH, info->data);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002803 }
2804
2805 hci_dev_unlock(hdev);
2806}
2807
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002808static inline u8 hci_get_auth_req(struct hci_conn *conn)
2809{
Brian Gixa68668b2011-08-11 15:49:36 -07002810 BT_DBG("%p", conn);
2811
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002812 /* If remote requests dedicated bonding follow that lead */
2813 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) {
2814 /* If both remote and local IO capabilities allow MITM
2815 * protection then require it, otherwise don't */
Brian Gixa68668b2011-08-11 15:49:36 -07002816 if (conn->remote_cap == 0x03 || conn->io_capability == 0x03) {
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002817 return 0x02;
Brian Gixa68668b2011-08-11 15:49:36 -07002818 } else {
2819 conn->auth_type |= 0x01;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002820 return 0x03;
Brian Gixa68668b2011-08-11 15:49:36 -07002821 }
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002822 }
2823
2824 /* If remote requests no-bonding follow that lead */
Brian Gixa68668b2011-08-11 15:49:36 -07002825 if (conn->remote_auth <= 0x01)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002826 return 0x00;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002827
2828 return conn->auth_type;
2829}
2830
Marcel Holtmann04936842008-07-14 20:13:48 +02002831static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2832{
2833 struct hci_ev_io_capa_request *ev = (void *) skb->data;
2834 struct hci_conn *conn;
2835
2836 BT_DBG("%s", hdev->name);
2837
2838 hci_dev_lock(hdev);
2839
2840 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedberg03b555e2011-01-04 15:40:05 +02002841 if (!conn)
2842 goto unlock;
Marcel Holtmann04936842008-07-14 20:13:48 +02002843
Johan Hedberg03b555e2011-01-04 15:40:05 +02002844 hci_conn_hold(conn);
2845
2846 if (!test_bit(HCI_MGMT, &hdev->flags))
2847 goto unlock;
2848
2849 if (test_bit(HCI_PAIRABLE, &hdev->flags) ||
2850 (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) {
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002851 struct hci_cp_io_capability_reply cp;
Brian Gixa68668b2011-08-11 15:49:36 -07002852 u8 io_cap = conn->io_capability;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002853
Brian Gixa68668b2011-08-11 15:49:36 -07002854 /* ACL-SSP does not support IO CAP 0x04 */
2855 cp.capability = (io_cap == 0x04) ? 0x01 : io_cap;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002856 bacpy(&cp.bdaddr, &ev->bdaddr);
Brian Gixa68668b2011-08-11 15:49:36 -07002857 if (conn->auth_initiator)
2858 cp.authentication = conn->auth_type;
2859 else
2860 cp.authentication = hci_get_auth_req(conn);
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002861
Szymon Jancce85ee12011-03-22 13:12:23 +01002862 if ((conn->out == 0x01 || conn->remote_oob == 0x01) &&
2863 hci_find_remote_oob_data(hdev, &conn->dst))
2864 cp.oob_data = 0x01;
2865 else
2866 cp.oob_data = 0x00;
2867
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002868 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
2869 sizeof(cp), &cp);
Johan Hedberg03b555e2011-01-04 15:40:05 +02002870 } else {
2871 struct hci_cp_io_capability_neg_reply cp;
2872
2873 bacpy(&cp.bdaddr, &ev->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002874 cp.reason = 0x16; /* Pairing not allowed */
Johan Hedberg03b555e2011-01-04 15:40:05 +02002875
2876 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
2877 sizeof(cp), &cp);
2878 }
2879
2880unlock:
2881 hci_dev_unlock(hdev);
2882}
2883
2884static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb)
2885{
2886 struct hci_ev_io_capa_reply *ev = (void *) skb->data;
2887 struct hci_conn *conn;
2888
2889 BT_DBG("%s", hdev->name);
2890
2891 hci_dev_lock(hdev);
2892
2893 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2894 if (!conn)
2895 goto unlock;
2896
Johan Hedberg03b555e2011-01-04 15:40:05 +02002897 conn->remote_cap = ev->capability;
2898 conn->remote_oob = ev->oob_data;
2899 conn->remote_auth = ev->authentication;
2900
2901unlock:
Marcel Holtmann04936842008-07-14 20:13:48 +02002902 hci_dev_unlock(hdev);
2903}
2904
Brian Gixa68668b2011-08-11 15:49:36 -07002905static inline void hci_user_ssp_confirmation_evt(struct hci_dev *hdev,
2906 u8 event, struct sk_buff *skb)
Johan Hedberga5c29682011-02-19 12:05:57 -03002907{
2908 struct hci_ev_user_confirm_req *ev = (void *) skb->data;
2909
2910 BT_DBG("%s", hdev->name);
2911
2912 hci_dev_lock(hdev);
2913
Brian Gixa68668b2011-08-11 15:49:36 -07002914 if (test_bit(HCI_MGMT, &hdev->flags)) {
2915 if (event == HCI_EV_USER_PASSKEY_REQUEST)
2916 mgmt_user_confirm_request(hdev->id, event,
2917 &ev->bdaddr, 0);
2918 else
2919 mgmt_user_confirm_request(hdev->id, event,
2920 &ev->bdaddr, ev->passkey);
2921 }
Johan Hedberga5c29682011-02-19 12:05:57 -03002922
2923 hci_dev_unlock(hdev);
2924}
2925
Marcel Holtmann04936842008-07-14 20:13:48 +02002926static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2927{
2928 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
2929 struct hci_conn *conn;
2930
2931 BT_DBG("%s", hdev->name);
2932
2933 hci_dev_lock(hdev);
2934
2935 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedberg2a611692011-02-19 12:06:00 -03002936 if (!conn)
2937 goto unlock;
Marcel Holtmann04936842008-07-14 20:13:48 +02002938
Johan Hedberg2a611692011-02-19 12:06:00 -03002939 /* To avoid duplicate auth_failed events to user space we check
2940 * the HCI_CONN_AUTH_PEND flag which will be set if we
2941 * initiated the authentication. A traditional auth_complete
2942 * event gets always produced as initiator and is also mapped to
2943 * the mgmt_auth_failed event */
2944 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->pend) && ev->status != 0)
2945 mgmt_auth_failed(hdev->id, &conn->dst, ev->status);
2946
2947 hci_conn_put(conn);
2948
2949unlock:
Marcel Holtmann04936842008-07-14 20:13:48 +02002950 hci_dev_unlock(hdev);
2951}
2952
Marcel Holtmann41a96212008-07-14 20:13:48 +02002953static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
2954{
2955 struct hci_ev_remote_host_features *ev = (void *) skb->data;
2956 struct inquiry_entry *ie;
2957
2958 BT_DBG("%s", hdev->name);
2959
2960 hci_dev_lock(hdev);
2961
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002962 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
2963 if (ie)
Marcel Holtmann41a96212008-07-14 20:13:48 +02002964 ie->data.ssp_mode = (ev->features[0] & 0x01);
2965
2966 hci_dev_unlock(hdev);
2967}
2968
Szymon Janc2763eda2011-03-22 13:12:22 +01002969static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
2970 struct sk_buff *skb)
2971{
2972 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
2973 struct oob_data *data;
2974
2975 BT_DBG("%s", hdev->name);
2976
2977 hci_dev_lock(hdev);
2978
Szymon Jance1ba1f12011-04-06 13:01:59 +02002979 if (!test_bit(HCI_MGMT, &hdev->flags))
2980 goto unlock;
2981
Szymon Janc2763eda2011-03-22 13:12:22 +01002982 data = hci_find_remote_oob_data(hdev, &ev->bdaddr);
2983 if (data) {
2984 struct hci_cp_remote_oob_data_reply cp;
2985
2986 bacpy(&cp.bdaddr, &ev->bdaddr);
2987 memcpy(cp.hash, data->hash, sizeof(cp.hash));
2988 memcpy(cp.randomizer, data->randomizer, sizeof(cp.randomizer));
2989
2990 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp),
2991 &cp);
2992 } else {
2993 struct hci_cp_remote_oob_data_neg_reply cp;
2994
2995 bacpy(&cp.bdaddr, &ev->bdaddr);
2996 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp),
2997 &cp);
2998 }
2999
Szymon Jance1ba1f12011-04-06 13:01:59 +02003000unlock:
Szymon Janc2763eda2011-03-22 13:12:22 +01003001 hci_dev_unlock(hdev);
3002}
3003
Ville Tervofcd89c02011-02-10 22:38:47 -03003004static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3005{
3006 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
3007 struct hci_conn *conn;
3008
3009 BT_DBG("%s status %d", hdev->name, ev->status);
3010
3011 hci_dev_lock(hdev);
3012
3013 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr);
Ville Tervob62f3282011-02-10 22:38:50 -03003014 if (!conn) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003015 conn = hci_le_conn_add(hdev, &ev->bdaddr, ev->bdaddr_type);
Ville Tervob62f3282011-02-10 22:38:50 -03003016 if (!conn) {
3017 BT_ERR("No memory for new connection");
3018 hci_dev_unlock(hdev);
3019 return;
3020 }
3021 }
Ville Tervofcd89c02011-02-10 22:38:47 -03003022
3023 if (ev->status) {
3024 hci_proto_connect_cfm(conn, ev->status);
3025 conn->state = BT_CLOSED;
3026 hci_conn_del(conn);
3027 goto unlock;
3028 }
3029
Vinicius Costa Gomes403d2c82011-06-09 18:50:50 -03003030 conn->sec_level = BT_SECURITY_LOW;
Ville Tervofcd89c02011-02-10 22:38:47 -03003031 conn->handle = __le16_to_cpu(ev->handle);
3032 conn->state = BT_CONNECTED;
Brian Gixa68668b2011-08-11 15:49:36 -07003033 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07003034 mgmt_connected(hdev->id, &ev->bdaddr, 1);
Ville Tervofcd89c02011-02-10 22:38:47 -03003035
Brian Gix6d5fb8a2011-09-09 14:53:04 -07003036 hci_conn_hold(conn);
Ville Tervofcd89c02011-02-10 22:38:47 -03003037 hci_conn_hold_device(conn);
3038 hci_conn_add_sysfs(conn);
3039
3040 hci_proto_connect_cfm(conn, ev->status);
3041
3042unlock:
3043 hci_dev_unlock(hdev);
3044}
3045
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003046static inline void hci_le_ltk_request_evt(struct hci_dev *hdev,
3047 struct sk_buff *skb)
3048{
3049 struct hci_ev_le_ltk_req *ev = (void *) skb->data;
3050 struct hci_cp_le_ltk_reply cp;
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003051 struct hci_cp_le_ltk_neg_reply neg;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003052 struct hci_conn *conn;
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003053 struct link_key *ltk;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003054
3055 BT_DBG("%s handle %d", hdev->name, cpu_to_le16(ev->handle));
3056
3057 hci_dev_lock(hdev);
3058
3059 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003060 if (conn == NULL)
3061 goto not_found;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003062
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003063 ltk = hci_find_ltk(hdev, ev->ediv, ev->random);
3064 if (ltk == NULL)
3065 goto not_found;
3066
3067 memcpy(cp.ltk, ltk->val, sizeof(ltk->val));
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003068 cp.handle = cpu_to_le16(conn->handle);
Vinicius Costa Gomes1fa2de32011-07-08 18:31:45 -03003069 conn->pin_length = ltk->pin_len;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003070
3071 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
3072
3073 hci_dev_unlock(hdev);
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003074
3075 return;
3076
3077not_found:
3078 neg.handle = ev->handle;
3079 hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg);
3080 hci_dev_unlock(hdev);
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003081}
3082
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003083static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
3084 struct sk_buff *skb)
3085{
3086 struct hci_ev_le_advertising_info *ev;
3087 u8 num_reports;
3088
3089 num_reports = skb->data[0];
3090 ev = (void *) &skb->data[1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003091
Brian Gix3dd70172011-09-16 21:38:54 -07003092 hci_dev_lock(hdev);
3093
Brian Gixa68668b2011-08-11 15:49:36 -07003094 while (num_reports--) {
3095 mgmt_device_found(hdev->id, &ev->bdaddr, ev->bdaddr_type,
3096 1, NULL, 0, ev->length, ev->data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003097 hci_add_adv_entry(hdev, ev);
Brian Gixa68668b2011-08-11 15:49:36 -07003098 ev = (void *) (ev->data + ev->length + 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003099 }
Brian Gix3dd70172011-09-16 21:38:54 -07003100
3101 hci_dev_unlock(hdev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003102}
3103
Ville Tervofcd89c02011-02-10 22:38:47 -03003104static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
3105{
3106 struct hci_ev_le_meta *le_ev = (void *) skb->data;
3107
3108 skb_pull(skb, sizeof(*le_ev));
3109
3110 switch (le_ev->subevent) {
3111 case HCI_EV_LE_CONN_COMPLETE:
3112 hci_le_conn_complete_evt(hdev, skb);
3113 break;
3114
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003115 case HCI_EV_LE_LTK_REQ:
3116 hci_le_ltk_request_evt(hdev, skb);
3117 break;
3118
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003119 case HCI_EV_LE_ADVERTISING_REPORT:
3120 hci_le_adv_report_evt(hdev, skb);
3121 break;
3122
Ville Tervofcd89c02011-02-10 22:38:47 -03003123 default:
3124 break;
3125 }
3126}
3127
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003128static inline void hci_phy_link_complete(struct hci_dev *hdev,
3129 struct sk_buff *skb)
3130{
3131 struct hci_ev_phys_link_complete *ev = (void *) skb->data;
3132 struct hci_conn *conn;
3133
3134 BT_DBG("%s handle %d status %d", hdev->name, ev->phy_handle,
3135 ev->status);
3136
3137 hci_dev_lock(hdev);
3138
3139 if (ev->status == 0) {
3140 conn = hci_conn_add(hdev, ACL_LINK, 0, BDADDR_ANY);
3141 if (conn) {
3142 conn->handle = ev->phy_handle;
3143 conn->state = BT_CONNECTED;
3144
3145 hci_conn_hold(conn);
3146 conn->disc_timeout = HCI_DISCONN_TIMEOUT/2;
3147 hci_conn_put(conn);
3148
3149 hci_conn_hold_device(conn);
3150 hci_conn_add_sysfs(conn);
3151 } else
3152 BT_ERR("No memory for new connection");
3153 }
3154
3155 hci_dev_unlock(hdev);
3156}
3157
3158static inline void hci_log_link_complete(struct hci_dev *hdev,
3159 struct sk_buff *skb)
3160{
3161 struct hci_ev_log_link_complete *ev = (void *) skb->data;
3162 struct hci_chan *chan;
3163
3164 BT_DBG("%s handle %d status %d", hdev->name,
3165 __le16_to_cpu(ev->log_handle), ev->status);
3166
3167 hci_dev_lock(hdev);
3168
3169 chan = hci_chan_list_lookup_id(hdev, ev->phy_handle);
3170
3171 if (ev->status == 0) {
3172 if (chan) {
3173 chan->ll_handle = __le16_to_cpu(ev->log_handle);
3174 chan->state = BT_CONNECTED;
3175 hci_proto_create_cfm(chan, ev->status);
3176 hci_chan_hold(chan);
3177 }
3178 } else {
3179 if (chan) {
3180 chan->state = BT_CLOSED;
3181 hci_proto_create_cfm(chan, ev->status);
3182 hci_chan_del(chan);
3183 }
3184 }
3185
3186 hci_dev_unlock(hdev);
3187}
3188
3189static inline void hci_flow_spec_modify_complete(struct hci_dev *hdev,
3190 struct sk_buff *skb)
3191{
3192 struct hci_ev_flow_spec_modify_complete *ev = (void *) skb->data;
3193 struct hci_chan *chan;
3194
3195 BT_DBG("%s handle %d status %d", hdev->name,
3196 __le16_to_cpu(ev->log_handle), ev->status);
3197
3198 hci_dev_lock(hdev);
3199
3200 chan = hci_chan_list_lookup_handle(hdev, ev->log_handle);
3201 if (chan)
3202 hci_proto_modify_cfm(chan, ev->status);
3203
3204 hci_dev_unlock(hdev);
3205}
3206
3207static inline void hci_disconn_log_link_complete_evt(struct hci_dev *hdev,
3208 struct sk_buff *skb)
3209{
3210 struct hci_ev_disconn_log_link_complete *ev = (void *) skb->data;
3211 struct hci_chan *chan;
3212
3213 BT_DBG("%s handle %d status %d", hdev->name,
3214 __le16_to_cpu(ev->log_handle), ev->status);
3215
3216 if (ev->status)
3217 return;
3218
3219 hci_dev_lock(hdev);
3220
3221 chan = hci_chan_list_lookup_handle(hdev, __le16_to_cpu(ev->log_handle));
3222 if (chan) {
3223 hci_proto_destroy_cfm(chan, ev->reason);
3224 hci_chan_del(chan);
3225 }
3226
3227 hci_dev_unlock(hdev);
3228}
3229
3230static inline void hci_disconn_phy_link_complete_evt(struct hci_dev *hdev,
3231 struct sk_buff *skb)
3232{
3233 struct hci_ev_disconn_phys_link_complete *ev = (void *) skb->data;
3234 struct hci_conn *conn;
3235
3236 BT_DBG("%s status %d", hdev->name, ev->status);
3237
3238 if (ev->status)
3239 return;
3240
3241 hci_dev_lock(hdev);
3242
3243 conn = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3244 if (conn) {
3245 conn->state = BT_CLOSED;
3246
3247 hci_proto_disconn_cfm(conn, ev->reason);
3248 hci_conn_del(conn);
3249 }
3250
3251 hci_dev_unlock(hdev);
3252}
3253
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
3255{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003256 struct hci_event_hdr *hdr = (void *) skb->data;
3257 __u8 event = hdr->evt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258
Brian Gixdfdd9362011-08-18 09:58:02 -07003259 BT_DBG("");
3260
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 skb_pull(skb, HCI_EVENT_HDR_SIZE);
3262
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003263 switch (event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 case HCI_EV_INQUIRY_COMPLETE:
3265 hci_inquiry_complete_evt(hdev, skb);
3266 break;
3267
3268 case HCI_EV_INQUIRY_RESULT:
3269 hci_inquiry_result_evt(hdev, skb);
3270 break;
3271
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003272 case HCI_EV_CONN_COMPLETE:
3273 hci_conn_complete_evt(hdev, skb);
Marcel Holtmann21d9e302005-09-13 01:32:25 +02003274 break;
3275
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 case HCI_EV_CONN_REQUEST:
3277 hci_conn_request_evt(hdev, skb);
3278 break;
3279
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280 case HCI_EV_DISCONN_COMPLETE:
3281 hci_disconn_complete_evt(hdev, skb);
3282 break;
3283
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 case HCI_EV_AUTH_COMPLETE:
3285 hci_auth_complete_evt(hdev, skb);
3286 break;
3287
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003288 case HCI_EV_REMOTE_NAME:
3289 hci_remote_name_evt(hdev, skb);
3290 break;
3291
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 case HCI_EV_ENCRYPT_CHANGE:
3293 hci_encrypt_change_evt(hdev, skb);
3294 break;
3295
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003296 case HCI_EV_CHANGE_LINK_KEY_COMPLETE:
3297 hci_change_link_key_complete_evt(hdev, skb);
3298 break;
3299
3300 case HCI_EV_REMOTE_FEATURES:
3301 hci_remote_features_evt(hdev, skb);
3302 break;
3303
3304 case HCI_EV_REMOTE_VERSION:
3305 hci_remote_version_evt(hdev, skb);
3306 break;
3307
3308 case HCI_EV_QOS_SETUP_COMPLETE:
3309 hci_qos_setup_complete_evt(hdev, skb);
3310 break;
3311
3312 case HCI_EV_CMD_COMPLETE:
3313 hci_cmd_complete_evt(hdev, skb);
3314 break;
3315
3316 case HCI_EV_CMD_STATUS:
3317 hci_cmd_status_evt(hdev, skb);
3318 break;
3319
3320 case HCI_EV_ROLE_CHANGE:
3321 hci_role_change_evt(hdev, skb);
3322 break;
3323
3324 case HCI_EV_NUM_COMP_PKTS:
3325 hci_num_comp_pkts_evt(hdev, skb);
3326 break;
3327
3328 case HCI_EV_MODE_CHANGE:
3329 hci_mode_change_evt(hdev, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 break;
3331
3332 case HCI_EV_PIN_CODE_REQ:
3333 hci_pin_code_request_evt(hdev, skb);
3334 break;
3335
3336 case HCI_EV_LINK_KEY_REQ:
3337 hci_link_key_request_evt(hdev, skb);
3338 break;
3339
3340 case HCI_EV_LINK_KEY_NOTIFY:
3341 hci_link_key_notify_evt(hdev, skb);
3342 break;
3343
3344 case HCI_EV_CLOCK_OFFSET:
3345 hci_clock_offset_evt(hdev, skb);
3346 break;
3347
Marcel Holtmanna8746412008-07-14 20:13:46 +02003348 case HCI_EV_PKT_TYPE_CHANGE:
3349 hci_pkt_type_change_evt(hdev, skb);
3350 break;
3351
Marcel Holtmann85a1e932005-08-09 20:28:02 -07003352 case HCI_EV_PSCAN_REP_MODE:
3353 hci_pscan_rep_mode_evt(hdev, skb);
3354 break;
3355
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003356 case HCI_EV_INQUIRY_RESULT_WITH_RSSI:
3357 hci_inquiry_result_with_rssi_evt(hdev, skb);
3358 break;
3359
3360 case HCI_EV_REMOTE_EXT_FEATURES:
3361 hci_remote_ext_features_evt(hdev, skb);
3362 break;
3363
3364 case HCI_EV_SYNC_CONN_COMPLETE:
3365 hci_sync_conn_complete_evt(hdev, skb);
3366 break;
3367
3368 case HCI_EV_SYNC_CONN_CHANGED:
3369 hci_sync_conn_changed_evt(hdev, skb);
3370 break;
3371
Marcel Holtmann04837f62006-07-03 10:02:33 +02003372 case HCI_EV_SNIFF_SUBRATE:
3373 hci_sniff_subrate_evt(hdev, skb);
3374 break;
3375
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003376 case HCI_EV_EXTENDED_INQUIRY_RESULT:
3377 hci_extended_inquiry_result_evt(hdev, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003378 break;
3379
Marcel Holtmann04936842008-07-14 20:13:48 +02003380 case HCI_EV_IO_CAPA_REQUEST:
3381 hci_io_capa_request_evt(hdev, skb);
3382 break;
3383
Johan Hedberg03b555e2011-01-04 15:40:05 +02003384 case HCI_EV_IO_CAPA_REPLY:
3385 hci_io_capa_reply_evt(hdev, skb);
3386 break;
3387
Brian Gixa68668b2011-08-11 15:49:36 -07003388 case HCI_EV_USER_PASSKEY_REQUEST:
3389 case HCI_EV_USER_PASSKEY_NOTIFICATION:
Johan Hedberga5c29682011-02-19 12:05:57 -03003390 case HCI_EV_USER_CONFIRM_REQUEST:
Brian Gixa68668b2011-08-11 15:49:36 -07003391 hci_user_ssp_confirmation_evt(hdev, event, skb);
Johan Hedberga5c29682011-02-19 12:05:57 -03003392 break;
3393
Marcel Holtmann04936842008-07-14 20:13:48 +02003394 case HCI_EV_SIMPLE_PAIR_COMPLETE:
3395 hci_simple_pair_complete_evt(hdev, skb);
3396 break;
3397
Marcel Holtmann41a96212008-07-14 20:13:48 +02003398 case HCI_EV_REMOTE_HOST_FEATURES:
3399 hci_remote_host_features_evt(hdev, skb);
3400 break;
3401
Ville Tervofcd89c02011-02-10 22:38:47 -03003402 case HCI_EV_LE_META:
3403 hci_le_meta_evt(hdev, skb);
3404 break;
3405
Szymon Janc2763eda2011-03-22 13:12:22 +01003406 case HCI_EV_REMOTE_OOB_DATA_REQUEST:
3407 hci_remote_oob_data_request_evt(hdev, skb);
3408 break;
3409
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003410 case HCI_EV_PHYS_LINK_COMPLETE:
3411 hci_phy_link_complete(hdev, skb);
3412 hci_amp_event_packet(hdev, event, skb);
3413 break;
3414
3415 case HCI_EV_LOG_LINK_COMPLETE:
3416 hci_log_link_complete(hdev, skb);
3417 break;
3418
3419 case HCI_EV_FLOW_SPEC_MODIFY_COMPLETE:
3420 hci_flow_spec_modify_complete(hdev, skb);
3421 break;
3422
3423 case HCI_EV_DISCONN_LOG_LINK_COMPLETE:
3424 hci_disconn_log_link_complete_evt(hdev, skb);
3425 break;
3426
3427 case HCI_EV_DISCONN_PHYS_LINK_COMPLETE:
3428 hci_disconn_phy_link_complete_evt(hdev, skb);
3429 hci_amp_event_packet(hdev, event, skb);
3430 break;
3431
3432 case HCI_EV_NUM_COMP_BLOCKS:
3433 hci_num_comp_blocks_evt(hdev, skb);
3434 break;
3435
3436 case HCI_EV_CHANNEL_SELECTED:
3437 hci_amp_event_packet(hdev, event, skb);
3438 break;
3439
3440 case HCI_EV_AMP_STATUS_CHANGE:
3441 hci_amp_event_packet(hdev, event, skb);
3442 break;
3443
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003444 default:
3445 BT_DBG("%s event 0x%x", hdev->name, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 break;
3447 }
3448
3449 kfree_skb(skb);
3450 hdev->stat.evt_rx++;
3451}
3452
3453/* Generate internal stack event */
3454void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data)
3455{
3456 struct hci_event_hdr *hdr;
3457 struct hci_ev_stack_internal *ev;
3458 struct sk_buff *skb;
3459
3460 skb = bt_skb_alloc(HCI_EVENT_HDR_SIZE + sizeof(*ev) + dlen, GFP_ATOMIC);
3461 if (!skb)
3462 return;
3463
3464 hdr = (void *) skb_put(skb, HCI_EVENT_HDR_SIZE);
3465 hdr->evt = HCI_EV_STACK_INTERNAL;
3466 hdr->plen = sizeof(*ev) + dlen;
3467
3468 ev = (void *) skb_put(skb, sizeof(*ev) + dlen);
3469 ev->type = type;
3470 memcpy(ev->data, data, dlen);
3471
Marcel Holtmann576c7d82005-08-06 12:36:54 +02003472 bt_cb(skb)->incoming = 1;
Patrick McHardya61bbcf2005-08-14 17:24:31 -07003473 __net_timestamp(skb);
Marcel Holtmann576c7d82005-08-06 12:36:54 +02003474
Marcel Holtmann0d48d932005-08-09 20:30:28 -07003475 bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 skb->dev = (void *) hdev;
Johan Hedbergeec8d2b2010-12-16 10:17:38 +02003477 hci_send_to_sock(hdev, skb, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 kfree_skb(skb);
3479}