blob: 53188890e135c94e3b5c66d2c101bc145f341b2c [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
Bhakthavatsala Raghavendra2738eec2013-02-12 19:44:47 +05303 Copyright (c) 2000-2001, 2010-2013 The Linux Foundation. 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;
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800226 hci_dev_lock(hdev);
Royston Rodriguesc58c0c22011-10-24 12:54:13 +0530227 if (!status)
228 memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
229
Johan Hedbergb312b1612011-03-16 14:29:37 +0200230 if (test_bit(HCI_MGMT, &hdev->flags))
231 mgmt_set_local_name_complete(hdev->id, sent, status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800232 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200233}
234
235static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
236{
237 struct hci_rp_read_local_name *rp = (void *) skb->data;
238
239 BT_DBG("%s status 0x%x", hdev->name, rp->status);
240
241 if (rp->status)
242 return;
243
Johan Hedberg1f6c6372011-03-16 14:29:35 +0200244 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200245}
246
247static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
248{
249 __u8 status = *((__u8 *) skb->data);
250 void *sent;
251
252 BT_DBG("%s status 0x%x", hdev->name, status);
253
254 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
255 if (!sent)
256 return;
257
258 if (!status) {
259 __u8 param = *((__u8 *) sent);
260
261 if (param == AUTH_ENABLED)
262 set_bit(HCI_AUTH, &hdev->flags);
263 else
264 clear_bit(HCI_AUTH, &hdev->flags);
265 }
266
Johan Hedberg23bb5762010-12-21 23:01:27 +0200267 hci_req_complete(hdev, HCI_OP_WRITE_AUTH_ENABLE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200268}
269
270static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
271{
272 __u8 status = *((__u8 *) skb->data);
273 void *sent;
274
275 BT_DBG("%s status 0x%x", hdev->name, status);
276
277 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
278 if (!sent)
279 return;
280
281 if (!status) {
282 __u8 param = *((__u8 *) sent);
283
284 if (param)
285 set_bit(HCI_ENCRYPT, &hdev->flags);
286 else
287 clear_bit(HCI_ENCRYPT, &hdev->flags);
288 }
289
Johan Hedberg23bb5762010-12-21 23:01:27 +0200290 hci_req_complete(hdev, HCI_OP_WRITE_ENCRYPT_MODE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200291}
292
293static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
294{
295 __u8 status = *((__u8 *) skb->data);
296 void *sent;
297
298 BT_DBG("%s status 0x%x", hdev->name, status);
299
300 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
301 if (!sent)
302 return;
303
304 if (!status) {
305 __u8 param = *((__u8 *) sent);
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200306 int old_pscan, old_iscan;
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800307 hci_dev_lock(hdev);
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);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800325 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200326 }
327
Johan Hedberg23bb5762010-12-21 23:01:27 +0200328 hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200329}
330
331static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
332{
333 struct hci_rp_read_class_of_dev *rp = (void *) skb->data;
334
335 BT_DBG("%s status 0x%x", hdev->name, rp->status);
336
337 if (rp->status)
338 return;
339
340 memcpy(hdev->dev_class, rp->dev_class, 3);
341
342 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
343 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
344}
345
346static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
347{
348 __u8 status = *((__u8 *) skb->data);
349 void *sent;
350
351 BT_DBG("%s status 0x%x", hdev->name, status);
352
Marcel Holtmannf383f272008-07-14 20:13:47 +0200353 if (status)
354 return;
355
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200356 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
357 if (!sent)
358 return;
359
Marcel Holtmannf383f272008-07-14 20:13:47 +0200360 memcpy(hdev->dev_class, sent, 3);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200361}
362
363static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
364{
365 struct hci_rp_read_voice_setting *rp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 __u16 setting;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200367
368 BT_DBG("%s status 0x%x", hdev->name, rp->status);
369
370 if (rp->status)
371 return;
372
373 setting = __le16_to_cpu(rp->voice_setting);
374
Marcel Holtmannf383f272008-07-14 20:13:47 +0200375 if (hdev->voice_setting == setting)
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200376 return;
377
378 hdev->voice_setting = setting;
379
380 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
381
382 if (hdev->notify) {
383 tasklet_disable(&hdev->tx_task);
384 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
385 tasklet_enable(&hdev->tx_task);
386 }
387}
388
389static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
390{
391 __u8 status = *((__u8 *) skb->data);
Marcel Holtmannf383f272008-07-14 20:13:47 +0200392 __u16 setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 void *sent;
394
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200395 BT_DBG("%s status 0x%x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Marcel Holtmannf383f272008-07-14 20:13:47 +0200397 if (status)
398 return;
399
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200400 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
401 if (!sent)
402 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Marcel Holtmannf383f272008-07-14 20:13:47 +0200404 setting = get_unaligned_le16(sent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Marcel Holtmannf383f272008-07-14 20:13:47 +0200406 if (hdev->voice_setting == setting)
407 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Marcel Holtmannf383f272008-07-14 20:13:47 +0200409 hdev->voice_setting = setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Marcel Holtmannf383f272008-07-14 20:13:47 +0200411 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
412
413 if (hdev->notify) {
414 tasklet_disable(&hdev->tx_task);
415 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
416 tasklet_enable(&hdev->tx_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 }
418}
419
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200420static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421{
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200422 __u8 status = *((__u8 *) skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200424 BT_DBG("%s status 0x%x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Johan Hedberg23bb5762010-12-21 23:01:27 +0200426 hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427}
428
Sunny Kapdi320598f2012-07-30 14:52:56 -0700429static void hci_cc_le_clear_white_list(struct hci_dev *hdev,
430 struct sk_buff *skb)
431{
432 __u8 status = *((__u8 *) skb->data);
433
434 BT_DBG("%s status 0x%x", hdev->name, status);
435
436 hci_req_complete(hdev, HCI_OP_LE_CLEAR_WHITE_LIST, status);
437}
438
Marcel Holtmann333140b2008-07-14 20:13:48 +0200439static void hci_cc_read_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
440{
441 struct hci_rp_read_ssp_mode *rp = (void *) skb->data;
442
443 BT_DBG("%s status 0x%x", hdev->name, rp->status);
444
445 if (rp->status)
446 return;
447
448 hdev->ssp_mode = rp->mode;
449}
450
451static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
452{
453 __u8 status = *((__u8 *) skb->data);
454 void *sent;
455
456 BT_DBG("%s status 0x%x", hdev->name, status);
457
458 if (status)
459 return;
460
461 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
462 if (!sent)
463 return;
464
465 hdev->ssp_mode = *((__u8 *) sent);
466}
467
Johan Hedbergd5859e22011-01-25 01:19:58 +0200468static u8 hci_get_inquiry_mode(struct hci_dev *hdev)
469{
470 if (hdev->features[6] & LMP_EXT_INQ)
471 return 2;
472
473 if (hdev->features[3] & LMP_RSSI_INQ)
474 return 1;
475
476 if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 &&
477 hdev->lmp_subver == 0x0757)
478 return 1;
479
480 if (hdev->manufacturer == 15) {
481 if (hdev->hci_rev == 0x03 && hdev->lmp_subver == 0x6963)
482 return 1;
483 if (hdev->hci_rev == 0x09 && hdev->lmp_subver == 0x6963)
484 return 1;
485 if (hdev->hci_rev == 0x00 && hdev->lmp_subver == 0x6965)
486 return 1;
487 }
488
489 if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 &&
490 hdev->lmp_subver == 0x1805)
491 return 1;
492
493 return 0;
494}
495
496static void hci_setup_inquiry_mode(struct hci_dev *hdev)
497{
498 u8 mode;
499
500 mode = hci_get_inquiry_mode(hdev);
501
502 hci_send_cmd(hdev, HCI_OP_WRITE_INQUIRY_MODE, 1, &mode);
503}
504
505static void hci_setup_event_mask(struct hci_dev *hdev)
506{
507 /* The second byte is 0xff instead of 0x9f (two reserved bits
508 * disabled) since a Broadcom 1.2 dongle doesn't respond to the
509 * command otherwise */
510 u8 events[8] = { 0xff, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x00 };
511
Brian Gixa68668b2011-08-11 15:49:36 -0700512 BT_DBG("");
513
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700514 /* Events for 1.2 and newer controllers */
515 if (hdev->lmp_ver > 1) {
516 events[4] |= 0x01; /* Flow Specification Complete */
517 events[4] |= 0x02; /* Inquiry Result with RSSI */
518 events[4] |= 0x04; /* Read Remote Extended Features Complete */
519 events[5] |= 0x08; /* Synchronous Connection Complete */
520 events[5] |= 0x10; /* Synchronous Connection Changed */
521 }
Johan Hedbergd5859e22011-01-25 01:19:58 +0200522
523 if (hdev->features[3] & LMP_RSSI_INQ)
524 events[4] |= 0x04; /* Inquiry Result with RSSI */
525
526 if (hdev->features[5] & LMP_SNIFF_SUBR)
527 events[5] |= 0x20; /* Sniff Subrating */
528
529 if (hdev->features[5] & LMP_PAUSE_ENC)
530 events[5] |= 0x80; /* Encryption Key Refresh Complete */
531
532 if (hdev->features[6] & LMP_EXT_INQ)
533 events[5] |= 0x40; /* Extended Inquiry Result */
534
535 if (hdev->features[6] & LMP_NO_FLUSH)
536 events[7] |= 0x01; /* Enhanced Flush Complete */
537
538 if (hdev->features[7] & LMP_LSTO)
539 events[6] |= 0x80; /* Link Supervision Timeout Changed */
540
541 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
542 events[6] |= 0x01; /* IO Capability Request */
543 events[6] |= 0x02; /* IO Capability Response */
544 events[6] |= 0x04; /* User Confirmation Request */
545 events[6] |= 0x08; /* User Passkey Request */
546 events[6] |= 0x10; /* Remote OOB Data Request */
547 events[6] |= 0x20; /* Simple Pairing Complete */
548 events[7] |= 0x04; /* User Passkey Notification */
549 events[7] |= 0x08; /* Keypress Notification */
550 events[7] |= 0x10; /* Remote Host Supported
551 * Features Notification */
552 }
553
554 if (hdev->features[4] & LMP_LE)
555 events[7] |= 0x20; /* LE Meta-Event */
556
557 hci_send_cmd(hdev, HCI_OP_SET_EVENT_MASK, sizeof(events), events);
558}
559
560static void hci_setup(struct hci_dev *hdev)
561{
Johan Hedbergd5859e22011-01-25 01:19:58 +0200562 if (hdev->lmp_ver > 1)
563 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL);
564
565 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
566 u8 mode = 0x01;
567 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, sizeof(mode), &mode);
568 }
569
570 if (hdev->features[3] & LMP_RSSI_INQ)
571 hci_setup_inquiry_mode(hdev);
572
573 if (hdev->features[7] & LMP_INQ_TX_PWR)
574 hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, 0, NULL);
575}
576
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200577static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
578{
579 struct hci_rp_read_local_version *rp = (void *) skb->data;
580
581 BT_DBG("%s status 0x%x", hdev->name, rp->status);
582
583 if (rp->status)
584 return;
585
586 hdev->hci_ver = rp->hci_ver;
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200587 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200588 hdev->lmp_ver = rp->lmp_ver;
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200589 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200590 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200591
592 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name,
593 hdev->manufacturer,
594 hdev->hci_ver, hdev->hci_rev);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200595
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700596 if (hdev->dev_type == HCI_BREDR && test_bit(HCI_INIT, &hdev->flags))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200597 hci_setup(hdev);
598}
599
600static void hci_setup_link_policy(struct hci_dev *hdev)
601{
602 u16 link_policy = 0;
603
604 if (hdev->features[0] & LMP_RSWITCH)
605 link_policy |= HCI_LP_RSWITCH;
606 if (hdev->features[0] & LMP_HOLD)
607 link_policy |= HCI_LP_HOLD;
608 if (hdev->features[0] & LMP_SNIFF)
609 link_policy |= HCI_LP_SNIFF;
610 if (hdev->features[1] & LMP_PARK)
611 link_policy |= HCI_LP_PARK;
612
613 link_policy = cpu_to_le16(link_policy);
614 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY,
615 sizeof(link_policy), &link_policy);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200616}
617
618static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb)
619{
620 struct hci_rp_read_local_commands *rp = (void *) skb->data;
621
622 BT_DBG("%s status 0x%x", hdev->name, rp->status);
623
624 if (rp->status)
Johan Hedbergd5859e22011-01-25 01:19:58 +0200625 goto done;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200626
627 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
Johan Hedbergd5859e22011-01-25 01:19:58 +0200628
629 if (test_bit(HCI_INIT, &hdev->flags) && (hdev->commands[5] & 0x10))
630 hci_setup_link_policy(hdev);
631
632done:
633 hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200634}
635
636static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb)
637{
638 struct hci_rp_read_local_features *rp = (void *) skb->data;
639
640 BT_DBG("%s status 0x%x", hdev->name, rp->status);
641
642 if (rp->status)
643 return;
644
645 memcpy(hdev->features, rp->features, 8);
646
Brian Gixa68668b2011-08-11 15:49:36 -0700647 if (hdev->dev_type == HCI_BREDR && test_bit(HCI_INIT, &hdev->flags)) {
648 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
649 u8 mode = 0x01;
650 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE,
651 sizeof(mode), &mode);
652 }
653
654 if (hdev->features[3] & LMP_RSSI_INQ)
655 hci_setup_inquiry_mode(hdev);
656
657 if (hdev->features[7] & LMP_INQ_TX_PWR)
658 hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER,
659 0, NULL);
660
661 hci_setup_event_mask(hdev);
662 }
663
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200664 /* Adjust default settings according to features
665 * supported by device. */
666
667 if (hdev->features[0] & LMP_3SLOT)
668 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
669
670 if (hdev->features[0] & LMP_5SLOT)
671 hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
672
673 if (hdev->features[1] & LMP_HV2) {
674 hdev->pkt_type |= (HCI_HV2);
675 hdev->esco_type |= (ESCO_HV2);
676 }
677
678 if (hdev->features[1] & LMP_HV3) {
679 hdev->pkt_type |= (HCI_HV3);
680 hdev->esco_type |= (ESCO_HV3);
681 }
682
683 if (hdev->features[3] & LMP_ESCO)
684 hdev->esco_type |= (ESCO_EV3);
685
686 if (hdev->features[4] & LMP_EV4)
687 hdev->esco_type |= (ESCO_EV4);
688
689 if (hdev->features[4] & LMP_EV5)
690 hdev->esco_type |= (ESCO_EV5);
691
Marcel Holtmannefc76882009-02-06 09:13:37 +0100692 if (hdev->features[5] & LMP_EDR_ESCO_2M)
693 hdev->esco_type |= (ESCO_2EV3);
694
695 if (hdev->features[5] & LMP_EDR_ESCO_3M)
696 hdev->esco_type |= (ESCO_3EV3);
697
698 if (hdev->features[5] & LMP_EDR_3S_ESCO)
699 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
700
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200701 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name,
702 hdev->features[0], hdev->features[1],
703 hdev->features[2], hdev->features[3],
704 hdev->features[4], hdev->features[5],
705 hdev->features[6], hdev->features[7]);
706}
707
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700708static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
709 struct sk_buff *skb)
Andre Guedesd5fa5132011-06-30 19:20:52 -0300710{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700711 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
Andre Guedesd5fa5132011-06-30 19:20:52 -0300712
713 BT_DBG("%s status 0x%x", hdev->name, rp->status);
714
715 if (rp->status)
716 return;
717
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700718 hdev->flow_ctl_mode = rp->mode;
Andre Guedesd5fa5132011-06-30 19:20:52 -0300719}
720
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200721static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
722{
723 struct hci_rp_read_buffer_size *rp = (void *) skb->data;
724
725 BT_DBG("%s status 0x%x", hdev->name, rp->status);
726
727 if (rp->status)
728 return;
729
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700730 if (hdev->flow_ctl_mode == HCI_PACKET_BASED_FLOW_CTL_MODE) {
731 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
732 hdev->sco_mtu = rp->sco_mtu;
733 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
734 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
735 hdev->acl_cnt = hdev->acl_pkts;
736 hdev->sco_cnt = hdev->sco_pkts;
737 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200738
739 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
740 hdev->sco_mtu = 64;
741 hdev->sco_pkts = 8;
742 }
743
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200744
745 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name,
746 hdev->acl_mtu, hdev->acl_pkts,
747 hdev->sco_mtu, hdev->sco_pkts);
748}
749
750static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
751{
752 struct hci_rp_read_bd_addr *rp = (void *) skb->data;
753
754 BT_DBG("%s status 0x%x", hdev->name, rp->status);
755
756 if (!rp->status)
757 bacpy(&hdev->bdaddr, &rp->bdaddr);
758
Johan Hedberg23bb5762010-12-21 23:01:27 +0200759 hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status);
760}
761
762static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb)
763{
764 __u8 status = *((__u8 *) skb->data);
765
766 BT_DBG("%s status 0x%x", hdev->name, status);
767
768 hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200769}
770
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700771static void hci_cc_read_data_block_size(struct hci_dev *hdev,
772 struct sk_buff *skb)
773{
774 struct hci_rp_read_data_block_size *rp = (void *) skb->data;
775
776 BT_DBG("%s status 0x%x", hdev->name, rp->status);
777
778 if (rp->status)
779 return;
780
781 if (hdev->flow_ctl_mode == HCI_BLOCK_BASED_FLOW_CTL_MODE) {
782 hdev->acl_mtu = __le16_to_cpu(rp->max_acl_len);
783 hdev->sco_mtu = 0;
784 hdev->data_block_len = __le16_to_cpu(rp->data_block_len);
785 /* acl_pkts indicates the number of blocks */
786 hdev->acl_pkts = __le16_to_cpu(rp->num_blocks);
787 hdev->sco_pkts = 0;
788 hdev->acl_cnt = hdev->acl_pkts;
789 hdev->sco_cnt = 0;
790 }
791
792 BT_DBG("%s acl mtu %d:%d, data block len %d", hdev->name,
793 hdev->acl_mtu, hdev->acl_cnt, hdev->data_block_len);
794}
795
796static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
797 struct sk_buff *skb)
798{
799 struct hci_rp_read_local_amp_info *rp = (void *) skb->data;
800
801 BT_DBG("%s status 0x%x", hdev->name, rp->status);
802
803 if (rp->status)
804 return;
805
806 hdev->amp_status = rp->amp_status;
807 hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
808 hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
809 hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
810 hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
811 hdev->amp_type = rp->amp_type;
812 hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
813 hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
814 hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
815 hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
816
817 hci_req_complete(hdev, HCI_OP_READ_LOCAL_AMP_INFO, rp->status);
818}
819
Johan Hedbergb0916ea2011-01-10 13:44:55 +0200820static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
821 struct sk_buff *skb)
822{
823 __u8 status = *((__u8 *) skb->data);
824
825 BT_DBG("%s status 0x%x", hdev->name, status);
826
827 hci_req_complete(hdev, HCI_OP_DELETE_STORED_LINK_KEY, status);
828}
829
Johan Hedbergd5859e22011-01-25 01:19:58 +0200830static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb)
831{
832 __u8 status = *((__u8 *) skb->data);
833
834 BT_DBG("%s status 0x%x", hdev->name, status);
835
836 hci_req_complete(hdev, HCI_OP_SET_EVENT_MASK, status);
837}
838
839static void hci_cc_write_inquiry_mode(struct hci_dev *hdev,
840 struct sk_buff *skb)
841{
842 __u8 status = *((__u8 *) skb->data);
843
844 BT_DBG("%s status 0x%x", hdev->name, status);
845
846 hci_req_complete(hdev, HCI_OP_WRITE_INQUIRY_MODE, status);
847}
848
849static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
850 struct sk_buff *skb)
851{
852 __u8 status = *((__u8 *) skb->data);
853
854 BT_DBG("%s status 0x%x", hdev->name, status);
855
856 hci_req_complete(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, status);
857}
858
859static void hci_cc_set_event_flt(struct hci_dev *hdev, struct sk_buff *skb)
860{
861 __u8 status = *((__u8 *) skb->data);
862
863 BT_DBG("%s status 0x%x", hdev->name, status);
864
865 hci_req_complete(hdev, HCI_OP_SET_EVENT_FLT, status);
866}
867
Johan Hedberg980e1a52011-01-22 06:10:07 +0200868static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb)
869{
870 struct hci_rp_pin_code_reply *rp = (void *) skb->data;
871 struct hci_cp_pin_code_reply *cp;
872 struct hci_conn *conn;
873
874 BT_DBG("%s status 0x%x", hdev->name, rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800875 hci_dev_lock(hdev);
Johan Hedberg980e1a52011-01-22 06:10:07 +0200876
877 if (test_bit(HCI_MGMT, &hdev->flags))
878 mgmt_pin_code_reply_complete(hdev->id, &rp->bdaddr, rp->status);
879
880 if (rp->status != 0)
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800881 goto unlock;
Johan Hedberg980e1a52011-01-22 06:10:07 +0200882
883 cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
884 if (!cp)
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800885 goto unlock;
Johan Hedberg980e1a52011-01-22 06:10:07 +0200886
887 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
888 if (conn)
889 conn->pin_length = cp->pin_len;
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800890unlock:
891 hci_dev_unlock(hdev);
Johan Hedberg980e1a52011-01-22 06:10:07 +0200892}
893
894static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
895{
896 struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data;
897
898 BT_DBG("%s status 0x%x", hdev->name, rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800899 hci_dev_lock(hdev);
Johan Hedberg980e1a52011-01-22 06:10:07 +0200900
901 if (test_bit(HCI_MGMT, &hdev->flags))
902 mgmt_pin_code_neg_reply_complete(hdev->id, &rp->bdaddr,
903 rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800904 hci_dev_unlock(hdev);
Johan Hedberg980e1a52011-01-22 06:10:07 +0200905}
Ville Tervo6ed58ec2011-02-10 22:38:48 -0300906static void hci_cc_le_read_buffer_size(struct hci_dev *hdev,
907 struct sk_buff *skb)
908{
909 struct hci_rp_le_read_buffer_size *rp = (void *) skb->data;
910
911 BT_DBG("%s status 0x%x", hdev->name, rp->status);
912
913 if (rp->status)
914 return;
915
916 hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
917 hdev->le_pkts = rp->le_max_pkt;
918
919 hdev->le_cnt = hdev->le_pkts;
920
921 BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
922
923 hci_req_complete(hdev, HCI_OP_LE_READ_BUFFER_SIZE, rp->status);
924}
Johan Hedberg980e1a52011-01-22 06:10:07 +0200925
Sunny Kapdi320598f2012-07-30 14:52:56 -0700926static void hci_cc_le_read_white_list_size(struct hci_dev *hdev,
927 struct sk_buff *skb)
928{
929 struct hci_rp_le_read_white_list_size *rp = (void *) skb->data;
930
931 BT_DBG("%s status 0x%x", hdev->name, rp->status);
932
933 if (rp->status)
934 return;
935
936 hdev->le_white_list_size = rp->size;
937
938 BT_DBG("%s le white list %d", hdev->name, hdev->le_white_list_size);
939
940 hci_req_complete(hdev, HCI_OP_LE_READ_WHITE_LIST_SIZE, rp->status);
941}
942
Johan Hedberga5c29682011-02-19 12:05:57 -0300943static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
944{
945 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
946
947 BT_DBG("%s status 0x%x", hdev->name, rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800948 hci_dev_lock(hdev);
Johan Hedberga5c29682011-02-19 12:05:57 -0300949
950 if (test_bit(HCI_MGMT, &hdev->flags))
951 mgmt_user_confirm_reply_complete(hdev->id, &rp->bdaddr,
952 rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800953 hci_dev_unlock(hdev);
Johan Hedberga5c29682011-02-19 12:05:57 -0300954}
955
956static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
957 struct sk_buff *skb)
958{
959 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
960
961 BT_DBG("%s status 0x%x", hdev->name, rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800962 hci_dev_lock(hdev);
Johan Hedberga5c29682011-02-19 12:05:57 -0300963
964 if (test_bit(HCI_MGMT, &hdev->flags))
965 mgmt_user_confirm_neg_reply_complete(hdev->id, &rp->bdaddr,
966 rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800967 hci_dev_unlock(hdev);
Johan Hedberga5c29682011-02-19 12:05:57 -0300968}
969
Archana Ramachandran26a752b2011-12-20 11:27:40 -0800970static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb)
971{
972 struct hci_conn *conn;
973 struct hci_rp_read_rssi *rp = (void *) skb->data;
974
975 BT_DBG("%s status 0x%x", hdev->name, rp->status);
976
977 BT_DBG("%s rssi : %d handle : %d", hdev->name, rp->rssi, rp->handle);
978
979 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
980 if (conn)
981 mgmt_read_rssi_complete(hdev->id, rp->rssi, &conn->dst,
982 __le16_to_cpu(rp->handle), rp->status);
983}
984
Szymon Jancc35938b2011-03-22 13:12:21 +0100985static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
986 struct sk_buff *skb)
987{
988 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
989
990 BT_DBG("%s status 0x%x", hdev->name, rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800991 hci_dev_lock(hdev);
Szymon Jancc35938b2011-03-22 13:12:21 +0100992
993 mgmt_read_local_oob_data_reply_complete(hdev->id, rp->hash,
994 rp->randomizer, rp->status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -0800995 hci_dev_unlock(hdev);
Szymon Jancc35938b2011-03-22 13:12:21 +0100996}
997
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -0300998static void hci_cc_le_ltk_reply(struct hci_dev *hdev, struct sk_buff *skb)
999{
1000 struct hci_rp_le_ltk_reply *rp = (void *) skb->data;
1001
1002 BT_DBG("%s status 0x%x", hdev->name, rp->status);
1003
1004 if (rp->status)
1005 return;
1006
1007 hci_req_complete(hdev, HCI_OP_LE_LTK_REPLY, rp->status);
1008}
1009
1010static void hci_cc_le_ltk_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
1011{
1012 struct hci_rp_le_ltk_neg_reply *rp = (void *) skb->data;
1013
1014 BT_DBG("%s status 0x%x", hdev->name, rp->status);
1015
1016 if (rp->status)
1017 return;
1018
1019 hci_req_complete(hdev, HCI_OP_LE_LTK_NEG_REPLY, rp->status);
1020}
1021
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001022static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
1023 struct sk_buff *skb)
Andre Guedese326af42011-06-30 19:20:53 -03001024{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001025 void *sent;
1026 __u8 param_scan_enable;
Andre Guedese326af42011-06-30 19:20:53 -03001027 __u8 status = *((__u8 *) skb->data);
1028
Andre Guedese326af42011-06-30 19:20:53 -03001029 if (status)
1030 return;
1031
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001032 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
1033 if (!sent)
1034 return;
1035
1036 param_scan_enable = *((__u8 *) sent);
1037 if (param_scan_enable == 0x01) {
1038 del_timer(&hdev->adv_timer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001039 } else if (param_scan_enable == 0x00) {
1040 mod_timer(&hdev->adv_timer, jiffies + ADV_CLEAR_TIMEOUT);
1041 }
Andre Guedese326af42011-06-30 19:20:53 -03001042}
1043
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001044static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
1045{
1046 BT_DBG("%s status 0x%x", hdev->name, status);
1047
1048 if (status) {
Johan Hedberg23bb5762010-12-21 23:01:27 +02001049 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
Johan Hedberg314b2382011-04-27 10:29:57 -04001050
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001051 hci_conn_check_pending(hdev);
Brian Gixa68668b2011-08-11 15:49:36 -07001052 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001053 set_bit(HCI_INQUIRY, &hdev->flags);
Subramanian Srinivasana727a492011-11-30 13:06:07 -08001054 hci_dev_lock(hdev);
Brian Gixa68668b2011-08-11 15:49:36 -07001055 if (test_bit(HCI_MGMT, &hdev->flags))
1056 mgmt_inquiry_started(hdev->id);
Subramanian Srinivasana727a492011-11-30 13:06:07 -08001057 hci_dev_unlock(hdev);
Brian Gixa68668b2011-08-11 15:49:36 -07001058 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001059}
1060
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
1062{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001063 struct hci_cp_create_conn *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001066 BT_DBG("%s status 0x%x", hdev->name, status);
1067
1068 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 if (!cp)
1070 return;
1071
1072 hci_dev_lock(hdev);
1073
1074 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1075
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001076 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->bdaddr), conn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077
1078 if (status) {
1079 if (conn && conn->state == BT_CONNECT) {
Marcel Holtmann4c67bc72006-10-15 17:30:56 +02001080 if (status != 0x0c || conn->attempt > 2) {
1081 conn->state = BT_CLOSED;
1082 hci_proto_connect_cfm(conn, status);
1083 hci_conn_del(conn);
1084 } else
1085 conn->state = BT_CONNECT2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 }
1087 } else {
1088 if (!conn) {
Nick Pellybbcda3b2010-02-11 11:54:28 -08001089 conn = hci_conn_add(hdev, ACL_LINK, 0, &cp->bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 if (conn) {
1091 conn->out = 1;
1092 conn->link_mode |= HCI_LM_MASTER;
1093 } else
Gustavo F. Padovan893ef972010-07-18 15:13:37 -03001094 BT_ERR("No memory for new connection");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 }
1096 }
1097
1098 hci_dev_unlock(hdev);
1099}
1100
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001101static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001103 struct hci_cp_add_sco *cp;
1104 struct hci_conn *acl, *sco;
1105 __u16 handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001107 BT_DBG("%s status 0x%x", hdev->name, status);
1108
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001109 if (!status)
1110 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001112 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
1113 if (!cp)
1114 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001116 handle = __le16_to_cpu(cp->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001118 BT_DBG("%s handle %d", hdev->name, handle);
Marcel Holtmann6bd57412006-11-18 22:14:22 +01001119
1120 hci_dev_lock(hdev);
1121
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001122 acl = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001123 if (acl) {
1124 sco = acl->link;
1125 if (sco) {
1126 sco->state = BT_CLOSED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001127
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001128 hci_proto_connect_cfm(sco, status);
1129 hci_conn_del(sco);
1130 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001131 }
Marcel Holtmann6bd57412006-11-18 22:14:22 +01001132
1133 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134}
1135
Marcel Holtmannf8558552008-07-14 20:13:49 +02001136static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
1137{
1138 struct hci_cp_auth_requested *cp;
1139 struct hci_conn *conn;
1140
1141 BT_DBG("%s status 0x%x", hdev->name, status);
1142
Marcel Holtmannf8558552008-07-14 20:13:49 +02001143 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
1144 if (!cp)
1145 return;
1146
1147 hci_dev_lock(hdev);
1148
1149 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1150 if (conn) {
Prabhakaran Mc7953ca72012-03-06 20:43:46 +05301151 if (status) {
1152 mgmt_auth_failed(hdev->id, &conn->dst, status);
1153 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
1154
1155 if (conn->state == BT_CONFIG) {
1156 conn->state = BT_CONNECTED;
1157 hci_proto_connect_cfm(conn, status);
1158 hci_conn_put(conn);
1159 } else {
1160 hci_auth_cfm(conn, status);
1161 hci_conn_hold(conn);
1162 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
1163 hci_conn_put(conn);
1164 }
1165
1166 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) {
1167 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
1168 hci_encrypt_cfm(conn, status, 0x00);
1169 }
Marcel Holtmannf8558552008-07-14 20:13:49 +02001170 }
Srinivas Krovvidi9ff51452011-09-27 19:25:02 +05301171 conn->auth_initiator = 1;
Marcel Holtmannf8558552008-07-14 20:13:49 +02001172 }
1173
1174 hci_dev_unlock(hdev);
1175}
1176
1177static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
1178{
1179 struct hci_cp_set_conn_encrypt *cp;
1180 struct hci_conn *conn;
1181
1182 BT_DBG("%s status 0x%x", hdev->name, status);
1183
1184 if (!status)
1185 return;
1186
1187 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
1188 if (!cp)
1189 return;
1190
1191 hci_dev_lock(hdev);
1192
1193 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1194 if (conn) {
1195 if (conn->state == BT_CONFIG) {
1196 hci_proto_connect_cfm(conn, status);
1197 hci_conn_put(conn);
1198 }
1199 }
1200
1201 hci_dev_unlock(hdev);
1202}
1203
Johan Hedberg127178d2010-11-18 22:22:29 +02001204static int hci_outgoing_auth_needed(struct hci_dev *hdev,
Szymon Janc138d22e2011-02-17 16:44:23 +01001205 struct hci_conn *conn)
Johan Hedberg392599b2010-11-18 22:22:28 +02001206{
Johan Hedberg392599b2010-11-18 22:22:28 +02001207 if (conn->state != BT_CONFIG || !conn->out)
1208 return 0;
1209
Johan Hedberg765c2a92011-01-19 12:06:52 +05301210 if (conn->pending_sec_level == BT_SECURITY_SDP)
Johan Hedberg392599b2010-11-18 22:22:28 +02001211 return 0;
1212
1213 /* Only request authentication for SSP connections or non-SSP
Prabhakaran Mc6001a712011-09-06 11:56:25 +05301214 * devices with sec_level >= BT_SECURITY_MEDIUM*/
1215 BT_DBG("Pending sec level is %d", conn->pending_sec_level);
Johan Hedberg392599b2010-11-18 22:22:28 +02001216 if (!(hdev->ssp_mode > 0 && conn->ssp_mode > 0) &&
Prabhakaran Mc6001a712011-09-06 11:56:25 +05301217 conn->pending_sec_level < BT_SECURITY_MEDIUM)
Johan Hedberg392599b2010-11-18 22:22:28 +02001218 return 0;
1219
Johan Hedberg392599b2010-11-18 22:22:28 +02001220 return 1;
1221}
1222
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001223static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
1224{
Johan Hedberg127178d2010-11-18 22:22:29 +02001225 struct hci_cp_remote_name_req *cp;
1226 struct hci_conn *conn;
1227
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001228 BT_DBG("%s status 0x%x", hdev->name, status);
Johan Hedberg127178d2010-11-18 22:22:29 +02001229
1230 /* If successful wait for the name req complete event before
1231 * checking for the need to do authentication */
1232 if (!status)
1233 return;
1234
1235 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
1236 if (!cp)
1237 return;
1238
1239 hci_dev_lock(hdev);
1240
1241 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001242 if (conn && hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02001243 struct hci_cp_auth_requested cp;
1244 cp.handle = __cpu_to_le16(conn->handle);
1245 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1246 }
1247
1248 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001249}
1250
Marcel Holtmann769be972008-07-14 20:13:49 +02001251static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
1252{
1253 struct hci_cp_read_remote_features *cp;
1254 struct hci_conn *conn;
1255
1256 BT_DBG("%s status 0x%x", hdev->name, status);
1257
1258 if (!status)
1259 return;
1260
1261 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
1262 if (!cp)
1263 return;
1264
1265 hci_dev_lock(hdev);
1266
1267 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1268 if (conn) {
1269 if (conn->state == BT_CONFIG) {
Marcel Holtmann769be972008-07-14 20:13:49 +02001270 hci_proto_connect_cfm(conn, status);
1271 hci_conn_put(conn);
1272 }
1273 }
1274
1275 hci_dev_unlock(hdev);
1276}
1277
1278static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
1279{
1280 struct hci_cp_read_remote_ext_features *cp;
1281 struct hci_conn *conn;
1282
1283 BT_DBG("%s status 0x%x", hdev->name, status);
1284
1285 if (!status)
1286 return;
1287
1288 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
1289 if (!cp)
1290 return;
1291
1292 hci_dev_lock(hdev);
1293
1294 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1295 if (conn) {
1296 if (conn->state == BT_CONFIG) {
Marcel Holtmann769be972008-07-14 20:13:49 +02001297 hci_proto_connect_cfm(conn, status);
1298 hci_conn_put(conn);
1299 }
1300 }
1301
1302 hci_dev_unlock(hdev);
1303}
1304
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001305static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
1306{
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001307 struct hci_cp_setup_sync_conn *cp;
1308 struct hci_conn *acl, *sco;
1309 __u16 handle;
1310
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001311 BT_DBG("%s status 0x%x", hdev->name, status);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001312
1313 if (!status)
1314 return;
1315
1316 cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
1317 if (!cp)
1318 return;
1319
1320 handle = __le16_to_cpu(cp->handle);
1321
1322 BT_DBG("%s handle %d", hdev->name, handle);
1323
1324 hci_dev_lock(hdev);
1325
1326 acl = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001327 if (acl) {
1328 sco = acl->link;
1329 if (sco) {
1330 sco->state = BT_CLOSED;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001331
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001332 hci_proto_connect_cfm(sco, status);
1333 hci_conn_del(sco);
1334 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001335 }
1336
1337 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001338}
1339
1340static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
1341{
1342 struct hci_cp_sniff_mode *cp;
1343 struct hci_conn *conn;
1344
1345 BT_DBG("%s status 0x%x", hdev->name, status);
1346
1347 if (!status)
1348 return;
1349
1350 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
1351 if (!cp)
1352 return;
1353
1354 hci_dev_lock(hdev);
1355
1356 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001357 if (conn) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001358 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
1359
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001360 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
1361 hci_sco_setup(conn, status);
1362 }
1363
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001364 hci_dev_unlock(hdev);
1365}
1366
1367static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
1368{
1369 struct hci_cp_exit_sniff_mode *cp;
1370 struct hci_conn *conn;
1371
1372 BT_DBG("%s status 0x%x", hdev->name, status);
1373
1374 if (!status)
1375 return;
1376
1377 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
1378 if (!cp)
1379 return;
1380
1381 hci_dev_lock(hdev);
1382
1383 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001384 if (conn) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001385 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
1386
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001387 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
1388 hci_sco_setup(conn, status);
1389 }
1390
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001391 hci_dev_unlock(hdev);
1392}
1393
Ville Tervofcd89c02011-02-10 22:38:47 -03001394static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
1395{
1396 struct hci_cp_le_create_conn *cp;
1397 struct hci_conn *conn;
Brian Gixa94b6122012-02-23 16:07:10 -08001398 unsigned long exp = msecs_to_jiffies(5000);
Ville Tervofcd89c02011-02-10 22:38:47 -03001399
1400 BT_DBG("%s status 0x%x", hdev->name, status);
1401
1402 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN);
1403 if (!cp)
1404 return;
1405
1406 hci_dev_lock(hdev);
1407
1408 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr);
1409
1410 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr),
1411 conn);
1412
1413 if (status) {
1414 if (conn && conn->state == BT_CONNECT) {
1415 conn->state = BT_CLOSED;
1416 hci_proto_connect_cfm(conn, status);
1417 hci_conn_del(conn);
1418 }
1419 } else {
1420 if (!conn) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001421 conn = hci_le_conn_add(hdev, &cp->peer_addr,
1422 cp->peer_addr_type);
1423 if (conn)
Ville Tervofcd89c02011-02-10 22:38:47 -03001424 conn->out = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001425 else
Ville Tervofcd89c02011-02-10 22:38:47 -03001426 BT_ERR("No memory for new connection");
Brian Gixa94b6122012-02-23 16:07:10 -08001427 } else
1428 exp = msecs_to_jiffies(conn->conn_timeout * 1000);
Brian Gix114f3a62011-09-27 14:02:20 -07001429
Brian Gixa94b6122012-02-23 16:07:10 -08001430 if (conn && exp)
1431 mod_timer(&conn->disc_timer, jiffies + exp);
Ville Tervofcd89c02011-02-10 22:38:47 -03001432 }
1433
1434 hci_dev_unlock(hdev);
1435}
1436
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001437static void hci_cs_accept_logical_link(struct hci_dev *hdev, __u8 status)
1438{
1439 struct hci_cp_create_logical_link *ap;
1440 struct hci_chan *chan;
1441
1442 BT_DBG("%s status 0x%x", hdev->name, status);
1443
1444 ap = hci_sent_cmd_data(hdev, HCI_OP_ACCEPT_LOGICAL_LINK);
1445 if (!ap)
1446 return;
1447
1448 hci_dev_lock(hdev);
1449
1450 chan = hci_chan_list_lookup_id(hdev, ap->phy_handle);
1451
1452 BT_DBG("%s chan %p", hdev->name, chan);
1453
1454 if (status) {
1455 if (chan && chan->state == BT_CONNECT) {
1456 chan->state = BT_CLOSED;
1457 hci_proto_create_cfm(chan, status);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001458 }
Mat Martineau9f8d4672011-12-14 12:10:46 -08001459 } else if (chan) {
1460 chan->state = BT_CONNECT2;
1461 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001462
1463 hci_dev_unlock(hdev);
1464}
1465
1466static void hci_cs_create_logical_link(struct hci_dev *hdev, __u8 status)
1467{
1468 struct hci_cp_create_logical_link *cp;
1469 struct hci_chan *chan;
1470
1471 BT_DBG("%s status 0x%x", hdev->name, status);
1472
1473 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_LOGICAL_LINK);
1474 if (!cp)
1475 return;
1476
1477 hci_dev_lock(hdev);
1478
1479 chan = hci_chan_list_lookup_id(hdev, cp->phy_handle);
1480
1481 BT_DBG("%s chan %p", hdev->name, chan);
1482
1483 if (status) {
1484 if (chan && chan->state == BT_CONNECT) {
1485 chan->state = BT_CLOSED;
1486 hci_proto_create_cfm(chan, status);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001487 }
1488 } else if (chan)
1489 chan->state = BT_CONNECT2;
1490
1491 hci_dev_unlock(hdev);
1492}
1493
1494static void hci_cs_flow_spec_modify(struct hci_dev *hdev, __u8 status)
1495{
1496 struct hci_cp_flow_spec_modify *cp;
1497 struct hci_chan *chan;
1498
1499 BT_DBG("%s status 0x%x", hdev->name, status);
1500
1501 cp = hci_sent_cmd_data(hdev, HCI_OP_FLOW_SPEC_MODIFY);
1502 if (!cp)
1503 return;
1504
1505 hci_dev_lock(hdev);
1506
1507 chan = hci_chan_list_lookup_handle(hdev, cp->log_handle);
1508 if (chan) {
1509 if (status)
1510 hci_proto_modify_cfm(chan, status);
1511 else {
1512 chan->tx_fs = cp->tx_fs;
1513 chan->rx_fs = cp->rx_fs;
1514 }
1515 }
1516
1517 hci_dev_unlock(hdev);
1518}
1519
1520static void hci_cs_disconn_logical_link(struct hci_dev *hdev, __u8 status)
1521{
1522 struct hci_cp_disconn_logical_link *cp;
1523 struct hci_chan *chan;
1524
1525 if (!status)
1526 return;
1527
1528 BT_DBG("%s status 0x%x", hdev->name, status);
1529
1530 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONN_LOGICAL_LINK);
1531 if (!cp)
1532 return;
1533
1534 hci_dev_lock(hdev);
1535
1536 chan = hci_chan_list_lookup_handle(hdev, cp->log_handle);
1537 if (chan)
1538 hci_chan_del(chan);
1539
1540 hci_dev_unlock(hdev);
1541}
1542
1543static void hci_cs_disconn_physical_link(struct hci_dev *hdev, __u8 status)
1544{
1545 struct hci_cp_disconn_phys_link *cp;
1546 struct hci_conn *conn;
1547
1548 if (!status)
1549 return;
1550
1551 BT_DBG("%s status 0x%x", hdev->name, status);
1552
1553 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONN_PHYS_LINK);
1554 if (!cp)
1555 return;
1556
1557 hci_dev_lock(hdev);
1558
1559 conn = hci_conn_hash_lookup_handle(hdev, cp->phy_handle);
1560 if (conn) {
1561 conn->state = BT_CLOSED;
1562 hci_conn_del(conn);
1563 }
1564
1565 hci_dev_unlock(hdev);
1566}
1567
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03001568static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
1569{
Archana Ramachandran1cb41162013-01-29 16:20:19 -08001570 struct hci_cp_le_start_enc *cp;
1571 struct hci_conn *conn;
1572
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03001573 BT_DBG("%s status 0x%x", hdev->name, status);
Archana Ramachandran1cb41162013-01-29 16:20:19 -08001574 if (!status) {
1575 return;
1576 }
1577
1578 BT_DBG("%s Le start enc failed 0x%x", hdev->name, status);
1579 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_START_ENC);
1580 if (!cp) {
1581 BT_DBG("CP is null");
1582 return;
1583 }
1584 hci_dev_lock(hdev);
1585
1586 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1587 if (conn) {
1588 BT_DBG("conn exists");
1589 hci_conn_put(conn);
1590 }
1591 hci_dev_unlock(hdev);
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03001592}
1593
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001594static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1595{
1596 __u8 status = *((__u8 *) skb->data);
1597
1598 BT_DBG("%s status %d", hdev->name, status);
1599
Royston Rodrigues1670f382012-02-28 21:39:10 +05301600 if (!hdev->disco_state)
Brian Gixa68668b2011-08-11 15:49:36 -07001601 clear_bit(HCI_INQUIRY, &hdev->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001602
Johan Hedberg23bb5762010-12-21 23:01:27 +02001603 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -08001604 hci_dev_lock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001605
Brian Gixa68668b2011-08-11 15:49:36 -07001606 if (test_bit(HCI_MGMT, &hdev->flags))
1607 mgmt_inquiry_complete_evt(hdev->id, status);
Subramanian Srinivasana727a492011-11-30 13:06:07 -08001608 hci_dev_unlock(hdev);
Brian Gixa68668b2011-08-11 15:49:36 -07001609
1610 if (!lmp_le_capable(hdev))
1611 hci_conn_check_pending(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001612}
1613
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
1615{
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001616 struct inquiry_data data;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001617 struct inquiry_info *info = (void *) (skb->data + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 int num_rsp = *((__u8 *) skb->data);
1619
1620 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
1621
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001622 if (!num_rsp)
1623 return;
1624
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 hci_dev_lock(hdev);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001626
Johan Hedberge17acd42011-03-30 23:57:16 +03001627 for (; num_rsp; num_rsp--, info++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 bacpy(&data.bdaddr, &info->bdaddr);
1629 data.pscan_rep_mode = info->pscan_rep_mode;
1630 data.pscan_period_mode = info->pscan_period_mode;
1631 data.pscan_mode = info->pscan_mode;
1632 memcpy(data.dev_class, info->dev_class, 3);
1633 data.clock_offset = info->clock_offset;
1634 data.rssi = 0x00;
Marcel Holtmann41a96212008-07-14 20:13:48 +02001635 data.ssp_mode = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07001637 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
1638 info->dev_class, 0, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001640
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 hci_dev_unlock(hdev);
1642}
1643
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001644static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001646 struct hci_ev_conn_complete *ev = (void *) skb->data;
1647 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001649 BT_DBG("%s", hdev->name);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001650
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 hci_dev_lock(hdev);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001652
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001653 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
Marcel Holtmann94992372009-04-19 19:30:03 +02001654 if (!conn) {
1655 if (ev->link_type != SCO_LINK)
1656 goto unlock;
1657
1658 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
1659 if (!conn)
1660 goto unlock;
1661
1662 conn->type = SCO_LINK;
1663 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001664
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001665 if (!ev->status) {
1666 conn->handle = __le16_to_cpu(ev->handle);
Marcel Holtmann769be972008-07-14 20:13:49 +02001667
1668 if (conn->type == ACL_LINK) {
1669 conn->state = BT_CONFIG;
1670 hci_conn_hold(conn);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001671 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07001672 mgmt_connected(hdev->id, &ev->bdaddr, 0);
Brian Gixa68668b2011-08-11 15:49:36 -07001673 } else if (conn->type == LE_LINK) {
1674 conn->state = BT_CONNECTED;
1675 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07001676 mgmt_connected(hdev->id, &ev->bdaddr, 1);
Marcel Holtmann769be972008-07-14 20:13:49 +02001677 } else
1678 conn->state = BT_CONNECTED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001679
Marcel Holtmann9eba32b2009-08-22 14:19:26 -07001680 hci_conn_hold_device(conn);
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02001681 hci_conn_add_sysfs(conn);
1682
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001683 if (test_bit(HCI_AUTH, &hdev->flags))
1684 conn->link_mode |= HCI_LM_AUTH;
1685
1686 if (test_bit(HCI_ENCRYPT, &hdev->flags))
1687 conn->link_mode |= HCI_LM_ENCRYPT;
1688
Srinivas Krovvidid352b262012-01-12 19:46:26 +05301689 /* Get remote version */
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001690 if (conn->type == ACL_LINK) {
Srinivas Krovvidid352b262012-01-12 19:46:26 +05301691 struct hci_cp_read_remote_version cp;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001692 cp.handle = ev->handle;
Mallikarjuna GB8e71da12012-11-21 17:01:05 +05301693 hci_send_cmd(hdev, HCI_OP_READ_CLOCK_OFFSET,
1694 sizeof(cp), &cp);
Srinivas Krovvidid352b262012-01-12 19:46:26 +05301695 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_VERSION,
1696 sizeof(cp), &cp);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001697 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001698
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001699 /* Set packet type for incoming connection */
Marcel Holtmanna8746412008-07-14 20:13:46 +02001700 if (!conn->out && hdev->hci_ver < 3) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001701 struct hci_cp_change_conn_ptype cp;
1702 cp.handle = ev->handle;
Marcel Holtmanna8746412008-07-14 20:13:46 +02001703 cp.pkt_type = cpu_to_le16(conn->pkt_type);
1704 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE,
1705 sizeof(cp), &cp);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001706 }
Johan Hedberg17d5c042011-01-22 06:09:08 +02001707 } else {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001708 conn->state = BT_CLOSED;
Brian Gixa68668b2011-08-11 15:49:36 -07001709 if (conn->type == ACL_LINK || conn->type == LE_LINK)
Johan Hedberg17d5c042011-01-22 06:09:08 +02001710 mgmt_connect_failed(hdev->id, &ev->bdaddr, ev->status);
1711 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001712
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001713 if (conn->type == ACL_LINK)
1714 hci_sco_setup(conn, ev->status);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001715
Marcel Holtmann769be972008-07-14 20:13:49 +02001716 if (ev->status) {
1717 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001718 hci_conn_del(conn);
Marcel Holtmannc89b6e62009-01-15 21:57:03 +01001719 } else if (ev->link_type != ACL_LINK)
1720 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001721
1722unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001724
1725 hci_conn_check_pending(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726}
1727
hyungseoung.yoodbb18fb2011-11-18 13:57:01 +09001728static inline bool is_sco_active(struct hci_dev *hdev)
1729{
1730 if (hci_conn_hash_lookup_state(hdev, SCO_LINK, BT_CONNECTED) ||
1731 (hci_conn_hash_lookup_state(hdev, ESCO_LINK,
1732 BT_CONNECTED)))
1733 return true;
1734 return false;
1735}
1736
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1738{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001739 struct hci_ev_conn_request *ev = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 int mask = hdev->link_mode;
1741
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001742 BT_DBG("%s bdaddr %s type 0x%x", hdev->name,
1743 batostr(&ev->bdaddr), ev->link_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
1745 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
1746
Szymon Janc138d22e2011-02-17 16:44:23 +01001747 if ((mask & HCI_LM_ACCEPT) &&
1748 !hci_blacklist_lookup(hdev, &ev->bdaddr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 /* Connection accepted */
Marcel Holtmannc7bdd502008-07-14 20:13:47 +02001750 struct inquiry_entry *ie;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 hci_dev_lock(hdev);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001754
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02001755 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
1756 if (ie)
Marcel Holtmannc7bdd502008-07-14 20:13:47 +02001757 memcpy(ie->data.dev_class, ev->dev_class, 3);
1758
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
1760 if (!conn) {
Nick Pellybbcda3b2010-02-11 11:54:28 -08001761 /* pkt_type not yet used for incoming connections */
1762 conn = hci_conn_add(hdev, ev->link_type, 0, &ev->bdaddr);
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02001763 if (!conn) {
Gustavo F. Padovan893ef972010-07-18 15:13:37 -03001764 BT_ERR("No memory for new connection");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 hci_dev_unlock(hdev);
1766 return;
1767 }
1768 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001769
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 memcpy(conn->dev_class, ev->dev_class, 3);
Srinivas Krovvidi0916aed2011-12-20 12:06:34 +05301771 /* For incoming connection update remote class to userspace */
1772 mgmt_remote_class(hdev->id, &ev->bdaddr, ev->dev_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 conn->state = BT_CONNECT;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001774
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 hci_dev_unlock(hdev);
1776
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001777 if (ev->link_type == ACL_LINK || !lmp_esco_capable(hdev)) {
1778 struct hci_cp_accept_conn_req cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001780 bacpy(&cp.bdaddr, &ev->bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
hyungseoung.yoodbb18fb2011-11-18 13:57:01 +09001782 if (lmp_rswitch_capable(hdev) && ((mask & HCI_LM_MASTER)
1783 || is_sco_active(hdev)))
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001784 cp.role = 0x00; /* Become master */
1785 else
1786 cp.role = 0x01; /* Remain slave */
1787
1788 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ,
1789 sizeof(cp), &cp);
1790 } else {
1791 struct hci_cp_accept_sync_conn_req cp;
1792
1793 bacpy(&cp.bdaddr, &ev->bdaddr);
Marcel Holtmanna8746412008-07-14 20:13:46 +02001794 cp.pkt_type = cpu_to_le16(conn->pkt_type);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001795
1796 cp.tx_bandwidth = cpu_to_le32(0x00001f40);
1797 cp.rx_bandwidth = cpu_to_le32(0x00001f40);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001798 cp.max_latency = cpu_to_le16(0x000A);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001799 cp.content_format = cpu_to_le16(hdev->voice_setting);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001800 cp.retrans_effort = 0x01;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001801
1802 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
1803 sizeof(cp), &cp);
1804 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 } else {
1806 /* Connection rejected */
1807 struct hci_cp_reject_conn_req cp;
1808
1809 bacpy(&cp.bdaddr, &ev->bdaddr);
1810 cp.reason = 0x0f;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001811 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 }
1813}
1814
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1816{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001817 struct hci_ev_disconn_complete *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02001818 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Archana Ramachandranb2f194d2012-08-14 12:03:01 -07001820 BT_DBG("%s status %d reason %d", hdev->name, ev->status, ev->reason);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
Johan Hedberg8962ee72011-01-20 12:40:27 +02001822 if (ev->status) {
Subramanian Srinivasana727a492011-11-30 13:06:07 -08001823 hci_dev_lock(hdev);
Johan Hedberg8962ee72011-01-20 12:40:27 +02001824 mgmt_disconnect_failed(hdev->id);
Subramanian Srinivasana727a492011-11-30 13:06:07 -08001825 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826 return;
Johan Hedberg8962ee72011-01-20 12:40:27 +02001827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 hci_dev_lock(hdev);
1830
Marcel Holtmann04837f62006-07-03 10:02:33 +02001831 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergf7520542011-01-20 12:34:39 +02001832 if (!conn)
1833 goto unlock;
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02001834
Johan Hedbergf7520542011-01-20 12:34:39 +02001835 conn->state = BT_CLOSED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Brian Gixa68668b2011-08-11 15:49:36 -07001837 if (conn->type == ACL_LINK || conn->type == LE_LINK)
Archana Ramachandranb2f194d2012-08-14 12:03:01 -07001838 mgmt_disconnected(hdev->id, &conn->dst, ev->reason);
Johan Hedbergf7520542011-01-20 12:34:39 +02001839
Brian Gixe9ceb522011-09-22 10:46:35 -07001840 if (conn->type == LE_LINK)
1841 del_timer(&conn->smp_timer);
1842
Mat Martineau3b9239a2012-02-16 11:54:30 -08001843 hci_proto_disconn_cfm(conn, ev->reason, 0);
Johan Hedbergf7520542011-01-20 12:34:39 +02001844 hci_conn_del(conn);
1845
1846unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 hci_dev_unlock(hdev);
1848}
1849
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001850static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1851{
1852 struct hci_ev_auth_complete *ev = (void *) skb->data;
1853 struct hci_conn *conn;
1854
1855 BT_DBG("%s status %d", hdev->name, ev->status);
1856
1857 hci_dev_lock(hdev);
1858
1859 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001860 if (conn) {
1861 if (ev->status == 0x06 && hdev->ssp_mode > 0 &&
1862 conn->ssp_mode > 0) {
1863 struct hci_cp_auth_requested cp;
Prabhakaran Mcb04401d2011-09-20 17:37:55 +05301864 hci_remove_link_key(hdev, &conn->dst);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001865 cp.handle = cpu_to_le16(conn->handle);
1866 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED,
1867 sizeof(cp), &cp);
1868 hci_dev_unlock(hdev);
1869 BT_INFO("Pin or key missing");
1870 return;
1871 }
Waldemar Rymarkiewicz54444292011-05-31 15:49:26 +02001872
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001873 if (!ev->status) {
Waldemar Rymarkiewicz54444292011-05-31 15:49:26 +02001874 conn->link_mode |= HCI_LM_AUTH;
1875 conn->sec_level = conn->pending_sec_level;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001876 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001877 mgmt_auth_failed(hdev->id, &conn->dst, ev->status);
1878 conn->sec_level = BT_SECURITY_LOW;
1879 }
1880
1881 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
1882
1883 if (conn->state == BT_CONFIG) {
1884 if (!ev->status && hdev->ssp_mode > 0 &&
1885 conn->ssp_mode > 0) {
1886 struct hci_cp_set_conn_encrypt cp;
1887 cp.handle = ev->handle;
1888 cp.encrypt = 0x01;
1889 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT,
1890 sizeof(cp), &cp);
1891 } else {
1892 conn->state = BT_CONNECTED;
1893 hci_proto_connect_cfm(conn, ev->status);
Sumit Bajpai97039062013-04-23 19:19:08 +05301894 if (ev->status)
1895 conn->disc_timeout = HCI_DISCONN_AUTH_FAILED_TIMEOUT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001896 hci_conn_put(conn);
1897 }
1898 } else {
1899 hci_auth_cfm(conn, ev->status);
1900
1901 hci_conn_hold(conn);
1902 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001903 hci_conn_put(conn);
1904 }
1905
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001906 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) {
1907 if (!ev->status) {
Prabhakaran Mc48584712012-04-20 15:47:58 +05301908 if (conn->link_mode & HCI_LM_ENCRYPT) {
1909 /* Encryption implies authentication */
1910 conn->link_mode |= HCI_LM_AUTH;
1911 conn->link_mode |= HCI_LM_ENCRYPT;
1912 conn->sec_level =
1913 conn->pending_sec_level;
1914 clear_bit(HCI_CONN_ENCRYPT_PEND,
1915 &conn->pend);
1916 hci_encrypt_cfm(conn, ev->status, 1);
1917
1918 if (test_bit(HCI_MGMT, &hdev->flags))
1919 mgmt_encrypt_change(hdev->id,
1920 &conn->dst,
1921 ev->status);
1922
1923 } else {
1924 struct hci_cp_set_conn_encrypt cp;
1925 cp.handle = ev->handle;
1926 cp.encrypt = 0x01;
1927 hci_send_cmd(hdev,
1928 HCI_OP_SET_CONN_ENCRYPT,
1929 sizeof(cp), &cp);
1930 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001931 } else {
1932 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
1933 hci_encrypt_cfm(conn, ev->status, 0x00);
1934 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001935 }
1936 }
1937
1938 hci_dev_unlock(hdev);
1939}
1940
1941static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
1942{
Johan Hedberg127178d2010-11-18 22:22:29 +02001943 struct hci_ev_remote_name *ev = (void *) skb->data;
1944 struct hci_conn *conn;
1945
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001946 BT_DBG("%s", hdev->name);
1947
1948 hci_conn_check_pending(hdev);
Johan Hedberg127178d2010-11-18 22:22:29 +02001949
1950 hci_dev_lock(hdev);
1951
Brian Gixa68668b2011-08-11 15:49:36 -07001952 if (test_bit(HCI_MGMT, &hdev->flags))
1953 mgmt_remote_name(hdev->id, &ev->bdaddr, ev->status, ev->name);
Johan Hedberga88a9652011-03-30 13:18:12 +03001954
Johan Hedberg127178d2010-11-18 22:22:29 +02001955 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001956 if (conn && hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02001957 struct hci_cp_auth_requested cp;
1958 cp.handle = __cpu_to_le16(conn->handle);
1959 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1960 }
1961
1962 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001963}
1964
1965static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
1966{
1967 struct hci_ev_encrypt_change *ev = (void *) skb->data;
1968 struct hci_conn *conn;
1969
1970 BT_DBG("%s status %d", hdev->name, ev->status);
1971
1972 hci_dev_lock(hdev);
1973
1974 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1975 if (conn) {
1976 if (!ev->status) {
Marcel Holtmannae293192008-07-14 20:13:45 +02001977 if (ev->encrypt) {
1978 /* Encryption implies authentication */
1979 conn->link_mode |= HCI_LM_AUTH;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001980 conn->link_mode |= HCI_LM_ENCRYPT;
Vinicius Costa Gomes64532ec2011-06-09 18:50:53 -03001981 conn->sec_level = conn->pending_sec_level;
Marcel Holtmannae293192008-07-14 20:13:45 +02001982 } else
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001983 conn->link_mode &= ~HCI_LM_ENCRYPT;
1984 }
1985
1986 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
1987
Marcel Holtmannf8558552008-07-14 20:13:49 +02001988 if (conn->state == BT_CONFIG) {
1989 if (!ev->status)
1990 conn->state = BT_CONNECTED;
1991
1992 hci_proto_connect_cfm(conn, ev->status);
1993 hci_conn_put(conn);
Prabhakaran Mcafface82012-04-10 11:38:35 +05301994 } else {
1995 /*
1996 * If the remote device does not support
1997 * Pause Encryption, usually during the
1998 * roleSwitch we see Encryption disable
1999 * for short duration. Allow remote device
2000 * to disable encryption
2001 * for short duration in this case.
2002 */
2003 if ((ev->encrypt == 0) && (ev->status == 0) &&
2004 ((conn->features[5] & LMP_PAUSE_ENC) == 0)) {
2005 mod_timer(&conn->encrypt_pause_timer,
2006 jiffies + msecs_to_jiffies(500));
2007 BT_INFO("enc pause timer, enc_pend_flag set");
2008 } else {
2009 del_timer(&conn->encrypt_pause_timer);
2010 hci_encrypt_cfm(conn, ev->status, ev->encrypt);
2011 }
2012 }
Prabhakaran Mc46230fa2011-11-30 18:11:21 +05302013
2014 if (test_bit(HCI_MGMT, &hdev->flags))
2015 mgmt_encrypt_change(hdev->id, &conn->dst, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002016 }
2017
2018 hci_dev_unlock(hdev);
2019}
2020
2021static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2022{
2023 struct hci_ev_change_link_key_complete *ev = (void *) skb->data;
2024 struct hci_conn *conn;
2025
2026 BT_DBG("%s status %d", hdev->name, ev->status);
2027
2028 hci_dev_lock(hdev);
2029
2030 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2031 if (conn) {
2032 if (!ev->status)
2033 conn->link_mode |= HCI_LM_SECURE;
2034
2035 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
2036
2037 hci_key_change_cfm(conn, ev->status);
2038 }
2039
2040 hci_dev_unlock(hdev);
2041}
2042
2043static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
2044{
2045 struct hci_ev_remote_features *ev = (void *) skb->data;
2046 struct hci_conn *conn;
2047
2048 BT_DBG("%s status %d", hdev->name, ev->status);
2049
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002050 hci_dev_lock(hdev);
2051
2052 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergccd556f2010-11-10 17:11:51 +02002053 if (!conn)
2054 goto unlock;
Marcel Holtmann769be972008-07-14 20:13:49 +02002055
Sunny Kapdif3caf882012-02-25 19:27:09 -08002056 if (!ev->status) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02002057 memcpy(conn->features, ev->features, 8);
Sunny Kapdif3caf882012-02-25 19:27:09 -08002058 mgmt_remote_features(hdev->id, &conn->dst, ev->features);
2059 }
Johan Hedbergccd556f2010-11-10 17:11:51 +02002060
2061 if (conn->state != BT_CONFIG)
2062 goto unlock;
2063
2064 if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) {
2065 struct hci_cp_read_remote_ext_features cp;
2066 cp.handle = ev->handle;
2067 cp.page = 0x01;
2068 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
Marcel Holtmann769be972008-07-14 20:13:49 +02002069 sizeof(cp), &cp);
Johan Hedberg392599b2010-11-18 22:22:28 +02002070 goto unlock;
Prabhakaran Mc9f08bfd2012-03-26 18:18:17 +05302071 } else if (!(lmp_ssp_capable(conn)) && conn->auth_initiator &&
Bhakthavatsala Raghavendra2738eec2013-02-12 19:44:47 +05302072 (conn->pending_sec_level == BT_SECURITY_VERY_HIGH)) {
Prabhakaran Mc9f08bfd2012-03-26 18:18:17 +05302073 conn->pending_sec_level = BT_SECURITY_MEDIUM;
Johan Hedberg392599b2010-11-18 22:22:28 +02002074 }
2075
Johan Hedberg127178d2010-11-18 22:22:29 +02002076 if (!ev->status) {
2077 struct hci_cp_remote_name_req cp;
2078 memset(&cp, 0, sizeof(cp));
2079 bacpy(&cp.bdaddr, &conn->dst);
2080 cp.pscan_rep_mode = 0x02;
2081 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2082 }
Johan Hedberg392599b2010-11-18 22:22:28 +02002083
Johan Hedberg127178d2010-11-18 22:22:29 +02002084 if (!hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02002085 conn->state = BT_CONNECTED;
2086 hci_proto_connect_cfm(conn, ev->status);
2087 hci_conn_put(conn);
Marcel Holtmann769be972008-07-14 20:13:49 +02002088 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002089
Johan Hedbergccd556f2010-11-10 17:11:51 +02002090unlock:
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002091 hci_dev_unlock(hdev);
2092}
2093
2094static inline void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb)
2095{
Srinivas Krovvidid352b262012-01-12 19:46:26 +05302096 struct hci_ev_remote_version *ev = (void *) skb->data;
2097 struct hci_cp_read_remote_features cp;
2098 struct hci_conn *conn;
2099 BT_DBG("%s status %d", hdev->name, ev->status);
2100
2101 hci_dev_lock(hdev);
2102 cp.handle = ev->handle;
2103 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES,
2104 sizeof(cp), &cp);
2105
2106 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2107 if (!conn)
2108 goto unlock;
2109 if (!ev->status)
2110 mgmt_remote_version(hdev->id, &conn->dst, ev->lmp_ver,
2111 ev->manufacturer, ev->lmp_subver);
2112unlock:
2113 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002114}
2115
2116static inline void hci_qos_setup_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2117{
2118 BT_DBG("%s", hdev->name);
2119}
2120
2121static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2122{
2123 struct hci_ev_cmd_complete *ev = (void *) skb->data;
2124 __u16 opcode;
2125
2126 skb_pull(skb, sizeof(*ev));
2127
2128 opcode = __le16_to_cpu(ev->opcode);
2129
Bhasker Neti6f4ceb12012-06-26 16:48:18 +05302130 if (test_bit(HCI_RESET, &hdev->flags) && (opcode != HCI_OP_RESET))
2131 return;
2132
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002133 switch (opcode) {
2134 case HCI_OP_INQUIRY_CANCEL:
2135 hci_cc_inquiry_cancel(hdev, skb);
2136 break;
2137
2138 case HCI_OP_EXIT_PERIODIC_INQ:
2139 hci_cc_exit_periodic_inq(hdev, skb);
2140 break;
2141
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002142 case HCI_OP_LINK_KEY_REPLY:
2143 hci_cc_link_key_reply(hdev, skb);
2144 break;
2145
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002146 case HCI_OP_REMOTE_NAME_REQ_CANCEL:
2147 hci_cc_remote_name_req_cancel(hdev, skb);
2148 break;
2149
2150 case HCI_OP_ROLE_DISCOVERY:
2151 hci_cc_role_discovery(hdev, skb);
2152 break;
2153
Marcel Holtmanne4e8e372008-07-14 20:13:47 +02002154 case HCI_OP_READ_LINK_POLICY:
2155 hci_cc_read_link_policy(hdev, skb);
2156 break;
2157
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002158 case HCI_OP_WRITE_LINK_POLICY:
2159 hci_cc_write_link_policy(hdev, skb);
2160 break;
2161
Marcel Holtmanne4e8e372008-07-14 20:13:47 +02002162 case HCI_OP_READ_DEF_LINK_POLICY:
2163 hci_cc_read_def_link_policy(hdev, skb);
2164 break;
2165
2166 case HCI_OP_WRITE_DEF_LINK_POLICY:
2167 hci_cc_write_def_link_policy(hdev, skb);
2168 break;
2169
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002170 case HCI_OP_RESET:
2171 hci_cc_reset(hdev, skb);
2172 break;
2173
2174 case HCI_OP_WRITE_LOCAL_NAME:
2175 hci_cc_write_local_name(hdev, skb);
2176 break;
2177
2178 case HCI_OP_READ_LOCAL_NAME:
2179 hci_cc_read_local_name(hdev, skb);
2180 break;
2181
2182 case HCI_OP_WRITE_AUTH_ENABLE:
2183 hci_cc_write_auth_enable(hdev, skb);
2184 break;
2185
2186 case HCI_OP_WRITE_ENCRYPT_MODE:
2187 hci_cc_write_encrypt_mode(hdev, skb);
2188 break;
2189
2190 case HCI_OP_WRITE_SCAN_ENABLE:
2191 hci_cc_write_scan_enable(hdev, skb);
2192 break;
2193
2194 case HCI_OP_READ_CLASS_OF_DEV:
2195 hci_cc_read_class_of_dev(hdev, skb);
2196 break;
2197
2198 case HCI_OP_WRITE_CLASS_OF_DEV:
2199 hci_cc_write_class_of_dev(hdev, skb);
2200 break;
2201
2202 case HCI_OP_READ_VOICE_SETTING:
2203 hci_cc_read_voice_setting(hdev, skb);
2204 break;
2205
2206 case HCI_OP_WRITE_VOICE_SETTING:
2207 hci_cc_write_voice_setting(hdev, skb);
2208 break;
2209
2210 case HCI_OP_HOST_BUFFER_SIZE:
2211 hci_cc_host_buffer_size(hdev, skb);
2212 break;
2213
Marcel Holtmann333140b2008-07-14 20:13:48 +02002214 case HCI_OP_READ_SSP_MODE:
2215 hci_cc_read_ssp_mode(hdev, skb);
2216 break;
2217
2218 case HCI_OP_WRITE_SSP_MODE:
2219 hci_cc_write_ssp_mode(hdev, skb);
2220 break;
2221
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002222 case HCI_OP_READ_LOCAL_VERSION:
2223 hci_cc_read_local_version(hdev, skb);
2224 break;
2225
2226 case HCI_OP_READ_LOCAL_COMMANDS:
2227 hci_cc_read_local_commands(hdev, skb);
2228 break;
2229
2230 case HCI_OP_READ_LOCAL_FEATURES:
2231 hci_cc_read_local_features(hdev, skb);
2232 break;
2233
2234 case HCI_OP_READ_BUFFER_SIZE:
2235 hci_cc_read_buffer_size(hdev, skb);
2236 break;
2237
2238 case HCI_OP_READ_BD_ADDR:
2239 hci_cc_read_bd_addr(hdev, skb);
2240 break;
2241
Johan Hedberg23bb5762010-12-21 23:01:27 +02002242 case HCI_OP_WRITE_CA_TIMEOUT:
2243 hci_cc_write_ca_timeout(hdev, skb);
2244 break;
2245
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002246 case HCI_OP_READ_FLOW_CONTROL_MODE:
2247 hci_cc_read_flow_control_mode(hdev, skb);
2248 break;
2249
2250 case HCI_OP_READ_DATA_BLOCK_SIZE:
2251 hci_cc_read_data_block_size(hdev, skb);
2252 break;
2253
2254 case HCI_OP_READ_LOCAL_AMP_INFO:
2255 hci_cc_read_local_amp_info(hdev, skb);
2256 break;
2257
2258 case HCI_OP_READ_LOCAL_AMP_ASSOC:
2259 case HCI_OP_WRITE_REMOTE_AMP_ASSOC:
2260 hci_amp_cmd_complete(hdev, opcode, skb);
2261 break;
2262
Johan Hedbergb0916ea2011-01-10 13:44:55 +02002263 case HCI_OP_DELETE_STORED_LINK_KEY:
2264 hci_cc_delete_stored_link_key(hdev, skb);
2265 break;
2266
Johan Hedbergd5859e22011-01-25 01:19:58 +02002267 case HCI_OP_SET_EVENT_MASK:
2268 hci_cc_set_event_mask(hdev, skb);
2269 break;
2270
2271 case HCI_OP_WRITE_INQUIRY_MODE:
2272 hci_cc_write_inquiry_mode(hdev, skb);
2273 break;
2274
2275 case HCI_OP_READ_INQ_RSP_TX_POWER:
2276 hci_cc_read_inq_rsp_tx_power(hdev, skb);
2277 break;
2278
2279 case HCI_OP_SET_EVENT_FLT:
2280 hci_cc_set_event_flt(hdev, skb);
2281 break;
2282
Johan Hedberg980e1a52011-01-22 06:10:07 +02002283 case HCI_OP_PIN_CODE_REPLY:
2284 hci_cc_pin_code_reply(hdev, skb);
2285 break;
2286
2287 case HCI_OP_PIN_CODE_NEG_REPLY:
2288 hci_cc_pin_code_neg_reply(hdev, skb);
2289 break;
2290
Szymon Jancc35938b2011-03-22 13:12:21 +01002291 case HCI_OP_READ_LOCAL_OOB_DATA:
2292 hci_cc_read_local_oob_data_reply(hdev, skb);
2293 break;
2294
Ville Tervo6ed58ec2011-02-10 22:38:48 -03002295 case HCI_OP_LE_READ_BUFFER_SIZE:
2296 hci_cc_le_read_buffer_size(hdev, skb);
2297 break;
2298
Sunny Kapdi320598f2012-07-30 14:52:56 -07002299 case HCI_OP_LE_READ_WHITE_LIST_SIZE:
2300 hci_cc_le_read_white_list_size(hdev, skb);
2301 break;
2302
2303 case HCI_OP_LE_CLEAR_WHITE_LIST:
2304 hci_cc_le_clear_white_list(hdev, skb);
2305 break;
2306
Archana Ramachandran26a752b2011-12-20 11:27:40 -08002307 case HCI_OP_READ_RSSI:
2308 hci_cc_read_rssi(hdev, skb);
2309 break;
2310
Johan Hedberga5c29682011-02-19 12:05:57 -03002311 case HCI_OP_USER_CONFIRM_REPLY:
2312 hci_cc_user_confirm_reply(hdev, skb);
2313 break;
2314
2315 case HCI_OP_USER_CONFIRM_NEG_REPLY:
2316 hci_cc_user_confirm_neg_reply(hdev, skb);
2317 break;
2318
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03002319 case HCI_OP_LE_LTK_REPLY:
2320 hci_cc_le_ltk_reply(hdev, skb);
2321 break;
2322
2323 case HCI_OP_LE_LTK_NEG_REPLY:
2324 hci_cc_le_ltk_neg_reply(hdev, skb);
2325 break;
2326
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002327 case HCI_OP_LE_SET_SCAN_ENABLE:
2328 hci_cc_le_set_scan_enable(hdev, skb);
Andre Guedese326af42011-06-30 19:20:53 -03002329 break;
2330
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002331 default:
2332 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
2333 break;
2334 }
2335
Ville Tervo6bd32322011-02-16 16:32:41 +02002336 if (ev->opcode != HCI_OP_NOP)
2337 del_timer(&hdev->cmd_timer);
2338
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002339 if (ev->ncmd) {
2340 atomic_set(&hdev->cmd_cnt, 1);
2341 if (!skb_queue_empty(&hdev->cmd_q))
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002342 tasklet_schedule(&hdev->cmd_task);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002343 }
2344}
2345
2346static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2347{
2348 struct hci_ev_cmd_status *ev = (void *) skb->data;
2349 __u16 opcode;
2350
2351 skb_pull(skb, sizeof(*ev));
2352
2353 opcode = __le16_to_cpu(ev->opcode);
2354
2355 switch (opcode) {
2356 case HCI_OP_INQUIRY:
2357 hci_cs_inquiry(hdev, ev->status);
2358 break;
2359
2360 case HCI_OP_CREATE_CONN:
2361 hci_cs_create_conn(hdev, ev->status);
2362 break;
2363
2364 case HCI_OP_ADD_SCO:
2365 hci_cs_add_sco(hdev, ev->status);
2366 break;
2367
Marcel Holtmannf8558552008-07-14 20:13:49 +02002368 case HCI_OP_AUTH_REQUESTED:
2369 hci_cs_auth_requested(hdev, ev->status);
2370 break;
2371
2372 case HCI_OP_SET_CONN_ENCRYPT:
2373 hci_cs_set_conn_encrypt(hdev, ev->status);
2374 break;
2375
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002376 case HCI_OP_REMOTE_NAME_REQ:
2377 hci_cs_remote_name_req(hdev, ev->status);
2378 break;
2379
Marcel Holtmann769be972008-07-14 20:13:49 +02002380 case HCI_OP_READ_REMOTE_FEATURES:
2381 hci_cs_read_remote_features(hdev, ev->status);
2382 break;
2383
2384 case HCI_OP_READ_REMOTE_EXT_FEATURES:
2385 hci_cs_read_remote_ext_features(hdev, ev->status);
2386 break;
2387
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002388 case HCI_OP_SETUP_SYNC_CONN:
2389 hci_cs_setup_sync_conn(hdev, ev->status);
2390 break;
2391
2392 case HCI_OP_SNIFF_MODE:
2393 hci_cs_sniff_mode(hdev, ev->status);
2394 break;
2395
2396 case HCI_OP_EXIT_SNIFF_MODE:
2397 hci_cs_exit_sniff_mode(hdev, ev->status);
2398 break;
2399
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002400 case HCI_OP_CREATE_LOGICAL_LINK:
2401 hci_cs_create_logical_link(hdev, ev->status);
2402 break;
2403
2404 case HCI_OP_ACCEPT_LOGICAL_LINK:
2405 hci_cs_accept_logical_link(hdev, ev->status);
2406 break;
2407
2408 case HCI_OP_DISCONN_LOGICAL_LINK:
2409 hci_cs_disconn_logical_link(hdev, ev->status);
2410 break;
2411
2412 case HCI_OP_FLOW_SPEC_MODIFY:
2413 hci_cs_flow_spec_modify(hdev, ev->status);
2414 break;
2415
2416 case HCI_OP_CREATE_PHYS_LINK:
2417 case HCI_OP_ACCEPT_PHYS_LINK:
2418 hci_amp_cmd_status(hdev, opcode, ev->status);
2419 break;
2420
2421 case HCI_OP_DISCONN_PHYS_LINK:
2422 hci_cs_disconn_physical_link(hdev, ev->status);
2423
Johan Hedberg8962ee72011-01-20 12:40:27 +02002424 case HCI_OP_DISCONNECT:
2425 if (ev->status != 0)
2426 mgmt_disconnect_failed(hdev->id);
2427 break;
2428
Ville Tervofcd89c02011-02-10 22:38:47 -03002429 case HCI_OP_LE_CREATE_CONN:
2430 hci_cs_le_create_conn(hdev, ev->status);
2431 break;
2432
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03002433 case HCI_OP_LE_START_ENC:
2434 hci_cs_le_start_enc(hdev, ev->status);
2435 break;
2436
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002437 default:
2438 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
2439 break;
2440 }
2441
Ville Tervo6bd32322011-02-16 16:32:41 +02002442 if (ev->opcode != HCI_OP_NOP)
2443 del_timer(&hdev->cmd_timer);
2444
Gustavo F. Padovan10572132011-03-16 15:36:29 -03002445 if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002446 atomic_set(&hdev->cmd_cnt, 1);
2447 if (!skb_queue_empty(&hdev->cmd_q))
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002448 tasklet_schedule(&hdev->cmd_task);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002449 }
2450}
2451
2452static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2453{
2454 struct hci_ev_role_change *ev = (void *) skb->data;
2455 struct hci_conn *conn;
2456
2457 BT_DBG("%s status %d", hdev->name, ev->status);
2458
2459 hci_dev_lock(hdev);
2460
2461 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2462 if (conn) {
2463 if (!ev->status) {
2464 if (ev->role)
2465 conn->link_mode &= ~HCI_LM_MASTER;
2466 else
2467 conn->link_mode |= HCI_LM_MASTER;
2468 }
2469
2470 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->pend);
2471
2472 hci_role_switch_cfm(conn, ev->status, ev->role);
2473 }
2474
2475 hci_dev_unlock(hdev);
2476}
2477
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
2479{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002480 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
Marcel Holtmann1ebb9252005-11-08 09:57:21 -08002481 __le16 *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 int i;
2483
2484 skb_pull(skb, sizeof(*ev));
2485
2486 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
2487
2488 if (skb->len < ev->num_hndl * 4) {
2489 BT_DBG("%s bad parameters", hdev->name);
2490 return;
2491 }
2492
2493 tasklet_disable(&hdev->tx_task);
2494
Marcel Holtmann1ebb9252005-11-08 09:57:21 -08002495 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002496 struct hci_conn *conn = NULL;
2497 struct hci_chan *chan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 __u16 handle, count;
2499
Harvey Harrison83985312008-05-02 16:25:46 -07002500 handle = get_unaligned_le16(ptr++);
2501 count = get_unaligned_le16(ptr++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002503 if (hdev->dev_type == HCI_BREDR)
2504 conn = hci_conn_hash_lookup_handle(hdev, handle);
2505 else {
2506 chan = hci_chan_list_lookup_handle(hdev, handle);
2507 if (chan)
2508 conn = chan->conn;
2509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 if (conn) {
2511 conn->sent -= count;
2512
Marcel Holtmann5b7f9902007-07-11 09:51:55 +02002513 if (conn->type == ACL_LINK) {
Andrei Emeltchenko70f230202010-12-01 16:58:25 +02002514 hdev->acl_cnt += count;
2515 if (hdev->acl_cnt > hdev->acl_pkts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 hdev->acl_cnt = hdev->acl_pkts;
Ville Tervo6ed58ec2011-02-10 22:38:48 -03002517 } else if (conn->type == LE_LINK) {
2518 if (hdev->le_pkts) {
2519 hdev->le_cnt += count;
2520 if (hdev->le_cnt > hdev->le_pkts)
2521 hdev->le_cnt = hdev->le_pkts;
2522 } else {
2523 hdev->acl_cnt += count;
2524 if (hdev->acl_cnt > hdev->acl_pkts)
2525 hdev->acl_cnt = hdev->acl_pkts;
2526 }
Marcel Holtmann5b7f9902007-07-11 09:51:55 +02002527 } else {
Andrei Emeltchenko70f230202010-12-01 16:58:25 +02002528 hdev->sco_cnt += count;
2529 if (hdev->sco_cnt > hdev->sco_pkts)
Marcel Holtmann5b7f9902007-07-11 09:51:55 +02002530 hdev->sco_cnt = hdev->sco_pkts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 }
2532 }
2533 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002534
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002535 tasklet_schedule(&hdev->tx_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537 tasklet_enable(&hdev->tx_task);
2538}
2539
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002540static inline void hci_num_comp_blocks_evt(struct hci_dev *hdev,
2541 struct sk_buff *skb)
2542{
2543 struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
2544 __le16 *ptr;
2545 int i;
2546
2547 skb_pull(skb, sizeof(*ev));
2548
2549 BT_DBG("%s total_num_blocks %d num_hndl %d",
2550 hdev->name, ev->total_num_blocks, ev->num_hndl);
2551
2552 if (skb->len < ev->num_hndl * 6) {
2553 BT_DBG("%s bad parameters", hdev->name);
2554 return;
2555 }
2556
2557 tasklet_disable(&hdev->tx_task);
2558
2559 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) {
2560 struct hci_conn *conn = NULL;
2561 struct hci_chan *chan;
2562 __u16 handle, block_count;
2563
2564 handle = get_unaligned_le16(ptr++);
2565
2566 /* Skip packet count */
2567 ptr++;
2568 block_count = get_unaligned_le16(ptr++);
2569
2570 BT_DBG("%s handle %d count %d", hdev->name, handle,
2571 block_count);
2572
2573 if (hdev->dev_type == HCI_BREDR)
2574 conn = hci_conn_hash_lookup_handle(hdev, handle);
2575 else {
2576 chan = hci_chan_list_lookup_handle(hdev, handle);
2577 if (chan)
2578 conn = chan->conn;
2579 }
2580 if (conn) {
2581 BT_DBG("%s conn %p sent %d", hdev->name,
2582 conn, conn->sent);
2583
2584 conn->sent -= block_count;
2585
2586 if (conn->type == ACL_LINK) {
2587 hdev->acl_cnt += block_count;
2588 if (hdev->acl_cnt > hdev->acl_pkts)
2589 hdev->acl_cnt = hdev->acl_pkts;
2590 } else {
2591 /* We should not find ourselves here */
2592 BT_DBG("Unexpected event for SCO connection");
2593 }
2594 }
2595 }
2596
2597 tasklet_schedule(&hdev->tx_task);
2598
2599 tasklet_enable(&hdev->tx_task);
2600}
2601
Marcel Holtmann04837f62006-07-03 10:02:33 +02002602static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002604 struct hci_ev_mode_change *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002605 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606
2607 BT_DBG("%s status %d", hdev->name, ev->status);
2608
2609 hci_dev_lock(hdev);
2610
Marcel Holtmann04837f62006-07-03 10:02:33 +02002611 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2612 if (conn) {
2613 conn->mode = ev->mode;
2614 conn->interval = __le16_to_cpu(ev->interval);
2615
2616 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) {
2617 if (conn->mode == HCI_CM_ACTIVE)
2618 conn->power_save = 1;
2619 else
2620 conn->power_save = 0;
2621 }
Rahul Kashyapb44f9e22012-05-03 16:45:17 +05302622 if (conn->mode == HCI_CM_SNIFF)
2623 if (wake_lock_active(&conn->idle_lock))
2624 wake_unlock(&conn->idle_lock);
Marcel Holtmanne73439d2010-07-26 10:06:00 -04002625
2626 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
2627 hci_sco_setup(conn, ev->status);
Marcel Holtmann04837f62006-07-03 10:02:33 +02002628 }
2629
2630 hci_dev_unlock(hdev);
2631}
2632
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2634{
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002635 struct hci_ev_pin_code_req *ev = (void *) skb->data;
2636 struct hci_conn *conn;
2637
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002638 BT_DBG("%s", hdev->name);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002639
2640 hci_dev_lock(hdev);
2641
2642 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Marcel Holtmann3d7a9d12009-05-09 12:09:21 -07002643 if (conn && conn->state == BT_CONNECTED) {
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002644 hci_conn_hold(conn);
2645 conn->disc_timeout = HCI_PAIRING_TIMEOUT;
2646 hci_conn_put(conn);
Srinivas Krovvidi32ba9352012-01-26 10:48:08 +05302647 hci_conn_enter_active_mode(conn, 0);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002648 }
2649
Johan Hedberg03b555e2011-01-04 15:40:05 +02002650 if (!test_bit(HCI_PAIRABLE, &hdev->flags))
2651 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY,
2652 sizeof(ev->bdaddr), &ev->bdaddr);
Waldemar Rymarkiewicza770bb52011-04-28 12:07:59 +02002653
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002654 if (test_bit(HCI_MGMT, &hdev->flags))
2655 mgmt_pin_code_request(hdev->id, &ev->bdaddr);
Johan Hedberg980e1a52011-01-22 06:10:07 +02002656
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002657 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658}
2659
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2661{
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002662 struct hci_ev_link_key_req *ev = (void *) skb->data;
2663 struct hci_cp_link_key_reply cp;
2664 struct hci_conn *conn;
2665 struct link_key *key;
2666
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002667 BT_DBG("%s", hdev->name);
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002668
2669 if (!test_bit(HCI_LINK_KEYS, &hdev->flags))
2670 return;
2671
2672 hci_dev_lock(hdev);
2673
2674 key = hci_find_link_key(hdev, &ev->bdaddr);
2675 if (!key) {
2676 BT_DBG("%s link key not found for %s", hdev->name,
2677 batostr(&ev->bdaddr));
2678 goto not_found;
2679 }
2680
Brian Gixcf956772011-10-20 15:18:51 -07002681 BT_DBG("%s found key type %u for %s", hdev->name, key->key_type,
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002682 batostr(&ev->bdaddr));
2683
Brian Gixcf956772011-10-20 15:18:51 -07002684 if (!test_bit(HCI_DEBUG_KEYS, &hdev->flags) && key->key_type == 0x03) {
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002685 BT_DBG("%s ignoring debug key", hdev->name);
2686 goto not_found;
2687 }
2688
2689 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2690
Prabhakaran Mc6001a712011-09-06 11:56:25 +05302691 if (conn) {
2692 BT_DBG("Conn pending sec level is %d, ssp is %d, key len is %d",
2693 conn->pending_sec_level, conn->ssp_mode, key->pin_len);
2694 }
Bhakthavatsala Raghavendraf212b6e2013-02-13 13:27:45 +05302695 if (conn && (conn->ssp_mode == 0) &&
2696 (conn->pending_sec_level == BT_SECURITY_VERY_HIGH) &&
2697 (key->pin_len != 16)) {
2698 BT_DBG("Security is high ignoring this key");
2699 goto not_found;
2700 }
Prabhakaran Mc6001a712011-09-06 11:56:25 +05302701
Brian Gixcf956772011-10-20 15:18:51 -07002702 if (key->key_type == 0x04 && conn && conn->auth_type != 0xff &&
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002703 (conn->auth_type & 0x01)) {
2704 BT_DBG("%s ignoring unauthenticated key", hdev->name);
2705 goto not_found;
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002706 }
2707
2708 bacpy(&cp.bdaddr, &ev->bdaddr);
2709 memcpy(cp.link_key, key->val, 16);
2710
2711 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp);
2712
2713 hci_dev_unlock(hdev);
2714
2715 return;
2716
2717not_found:
2718 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr);
2719 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720}
2721
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
2723{
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002724 struct hci_ev_link_key_notify *ev = (void *) skb->data;
2725 struct hci_conn *conn;
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002726 u8 pin_len = 0;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002727
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002728 BT_DBG("%s type %d", hdev->name, ev->key_type);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002729
2730 hci_dev_lock(hdev);
2731
2732 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2733 if (conn) {
2734 hci_conn_hold(conn);
2735 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002736
2737 memcpy(conn->link_key, ev->link_key, 16);
2738 conn->key_type = ev->key_type;
2739 hci_disconnect_amp(conn, 0x06);
2740
Prabhakaran Mc48584712012-04-20 15:47:58 +05302741 conn->link_mode &= ~HCI_LM_ENCRYPT;
Johan Hedberg980e1a52011-01-22 06:10:07 +02002742 pin_len = conn->pin_length;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002743 hci_conn_put(conn);
Srinivas Krovvidi32ba9352012-01-26 10:48:08 +05302744 hci_conn_enter_active_mode(conn, 0);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002745 }
2746
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002747 if (test_bit(HCI_LINK_KEYS, &hdev->flags))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002748 hci_add_link_key(hdev, 1, &ev->bdaddr, ev->link_key,
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002749 ev->key_type, pin_len);
2750
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002751 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752}
2753
Marcel Holtmann04837f62006-07-03 10:02:33 +02002754static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb)
2755{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002756 struct hci_ev_clock_offset *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002757 struct hci_conn *conn;
2758
2759 BT_DBG("%s status %d", hdev->name, ev->status);
2760
2761 hci_dev_lock(hdev);
2762
2763 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 if (conn && !ev->status) {
2765 struct inquiry_entry *ie;
2766
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002767 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
2768 if (ie) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 ie->data.clock_offset = ev->clock_offset;
2770 ie->timestamp = jiffies;
2771 }
2772 }
2773
2774 hci_dev_unlock(hdev);
2775}
2776
Marcel Holtmanna8746412008-07-14 20:13:46 +02002777static inline void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2778{
2779 struct hci_ev_pkt_type_change *ev = (void *) skb->data;
2780 struct hci_conn *conn;
2781
2782 BT_DBG("%s status %d", hdev->name, ev->status);
2783
2784 hci_dev_lock(hdev);
2785
2786 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2787 if (conn && !ev->status)
2788 conn->pkt_type = __le16_to_cpu(ev->pkt_type);
2789
2790 hci_dev_unlock(hdev);
2791}
2792
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002793static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
2794{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002795 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002796 struct inquiry_entry *ie;
2797
2798 BT_DBG("%s", hdev->name);
2799
2800 hci_dev_lock(hdev);
2801
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002802 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
2803 if (ie) {
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002804 ie->data.pscan_rep_mode = ev->pscan_rep_mode;
2805 ie->timestamp = jiffies;
2806 }
2807
2808 hci_dev_unlock(hdev);
2809}
2810
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002811static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct sk_buff *skb)
2812{
2813 struct inquiry_data data;
2814 int num_rsp = *((__u8 *) skb->data);
2815
2816 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
2817
2818 if (!num_rsp)
2819 return;
2820
2821 hci_dev_lock(hdev);
2822
2823 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {
Szymon Janc138d22e2011-02-17 16:44:23 +01002824 struct inquiry_info_with_rssi_and_pscan_mode *info;
2825 info = (void *) (skb->data + 1);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002826
Johan Hedberge17acd42011-03-30 23:57:16 +03002827 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002828 bacpy(&data.bdaddr, &info->bdaddr);
2829 data.pscan_rep_mode = info->pscan_rep_mode;
2830 data.pscan_period_mode = info->pscan_period_mode;
2831 data.pscan_mode = info->pscan_mode;
2832 memcpy(data.dev_class, info->dev_class, 3);
2833 data.clock_offset = info->clock_offset;
2834 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002835 data.ssp_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002836 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07002837 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
Johan Hedberge17acd42011-03-30 23:57:16 +03002838 info->dev_class, info->rssi,
Brian Gixa68668b2011-08-11 15:49:36 -07002839 0, NULL);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002840 }
2841 } else {
2842 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
2843
Johan Hedberge17acd42011-03-30 23:57:16 +03002844 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002845 bacpy(&data.bdaddr, &info->bdaddr);
2846 data.pscan_rep_mode = info->pscan_rep_mode;
2847 data.pscan_period_mode = info->pscan_period_mode;
2848 data.pscan_mode = 0x00;
2849 memcpy(data.dev_class, info->dev_class, 3);
2850 data.clock_offset = info->clock_offset;
2851 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002852 data.ssp_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002853 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07002854 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
Johan Hedberge17acd42011-03-30 23:57:16 +03002855 info->dev_class, info->rssi,
Brian Gixa68668b2011-08-11 15:49:36 -07002856 0, NULL);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002857 }
2858 }
2859
2860 hci_dev_unlock(hdev);
2861}
2862
2863static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
2864{
Marcel Holtmann41a96212008-07-14 20:13:48 +02002865 struct hci_ev_remote_ext_features *ev = (void *) skb->data;
2866 struct hci_conn *conn;
2867
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002868 BT_DBG("%s", hdev->name);
Marcel Holtmann41a96212008-07-14 20:13:48 +02002869
Marcel Holtmann41a96212008-07-14 20:13:48 +02002870 hci_dev_lock(hdev);
2871
2872 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergccd556f2010-11-10 17:11:51 +02002873 if (!conn)
2874 goto unlock;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002875
Johan Hedbergccd556f2010-11-10 17:11:51 +02002876 if (!ev->status && ev->page == 0x01) {
2877 struct inquiry_entry *ie;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002878
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002879 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
2880 if (ie)
Johan Hedbergccd556f2010-11-10 17:11:51 +02002881 ie->data.ssp_mode = (ev->features[0] & 0x01);
Marcel Holtmann769be972008-07-14 20:13:49 +02002882
Johan Hedbergccd556f2010-11-10 17:11:51 +02002883 conn->ssp_mode = (ev->features[0] & 0x01);
Bhakthavatsala Raghavendra6edb4f12011-11-04 16:07:41 +05302884 /*In case if remote device ssp supported/2.0 device
Bhakthavatsala Raghavendra2738eec2013-02-12 19:44:47 +05302885 reduce the security level to MEDIUM if it is VERY HIGH*/
Prabhakaran Mc453651c2012-03-02 11:55:59 +05302886 if (!conn->ssp_mode && conn->auth_initiator &&
Bhakthavatsala Raghavendra2738eec2013-02-12 19:44:47 +05302887 (conn->pending_sec_level == BT_SECURITY_VERY_HIGH))
Bhakthavatsala Raghavendra6edb4f12011-11-04 16:07:41 +05302888 conn->pending_sec_level = BT_SECURITY_MEDIUM;
Prabhakaran Mc76a83552012-04-09 14:43:18 +05302889
2890 if (conn->ssp_mode && conn->auth_initiator &&
2891 conn->io_capability != 0x03) {
Bhakthavatsala Raghavendra2738eec2013-02-12 19:44:47 +05302892 conn->pending_sec_level = BT_SECURITY_VERY_HIGH;
Prabhakaran Mc76a83552012-04-09 14:43:18 +05302893 conn->auth_type = HCI_AT_DEDICATED_BONDING_MITM;
2894 }
Marcel Holtmann41a96212008-07-14 20:13:48 +02002895 }
2896
Johan Hedbergccd556f2010-11-10 17:11:51 +02002897 if (conn->state != BT_CONFIG)
2898 goto unlock;
2899
Johan Hedberg127178d2010-11-18 22:22:29 +02002900 if (!ev->status) {
2901 struct hci_cp_remote_name_req cp;
2902 memset(&cp, 0, sizeof(cp));
2903 bacpy(&cp.bdaddr, &conn->dst);
2904 cp.pscan_rep_mode = 0x02;
2905 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2906 }
Johan Hedberg392599b2010-11-18 22:22:28 +02002907
Johan Hedberg127178d2010-11-18 22:22:29 +02002908 if (!hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02002909 conn->state = BT_CONNECTED;
2910 hci_proto_connect_cfm(conn, ev->status);
2911 hci_conn_put(conn);
2912 }
2913
2914unlock:
Marcel Holtmann41a96212008-07-14 20:13:48 +02002915 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002916}
2917
2918static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2919{
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002920 struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
2921 struct hci_conn *conn;
2922
2923 BT_DBG("%s status %d", hdev->name, ev->status);
2924
2925 hci_dev_lock(hdev);
2926
2927 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
Marcel Holtmann9dc0a3a2008-07-14 20:13:46 +02002928 if (!conn) {
2929 if (ev->link_type == ESCO_LINK)
2930 goto unlock;
2931
2932 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
2933 if (!conn)
2934 goto unlock;
2935
2936 conn->type = SCO_LINK;
2937 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002938
Marcel Holtmann732547f2009-04-19 19:14:14 +02002939 switch (ev->status) {
2940 case 0x00:
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002941 conn->handle = __le16_to_cpu(ev->handle);
2942 conn->state = BT_CONNECTED;
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02002943
Marcel Holtmann9eba32b2009-08-22 14:19:26 -07002944 hci_conn_hold_device(conn);
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02002945 hci_conn_add_sysfs(conn);
Marcel Holtmann732547f2009-04-19 19:14:14 +02002946 break;
2947
Stephen Coe705e5712010-02-16 11:29:44 -05002948 case 0x11: /* Unsupported Feature or Parameter Value */
Marcel Holtmann732547f2009-04-19 19:14:14 +02002949 case 0x1c: /* SCO interval rejected */
Nick Pelly1038a002010-02-03 11:42:26 -08002950 case 0x1a: /* Unsupported Remote Feature */
Marcel Holtmann732547f2009-04-19 19:14:14 +02002951 case 0x1f: /* Unspecified error */
2952 if (conn->out && conn->attempt < 2) {
Nitin Srivastava1dd7a242013-03-04 15:02:08 +05302953 if (!conn->hdev->is_wbs) {
Kun Han Kim15b911f2011-07-08 09:30:28 -07002954 conn->pkt_type =
2955 (hdev->esco_type & SCO_ESCO_MASK) |
Marcel Holtmann732547f2009-04-19 19:14:14 +02002956 (hdev->esco_type & EDR_ESCO_MASK);
Nitin Srivastava1dd7a242013-03-04 15:02:08 +05302957 hci_setup_sync(conn, conn->link->handle);
2958 goto unlock;
2959 }
Marcel Holtmann732547f2009-04-19 19:14:14 +02002960 }
2961 /* fall through */
2962
2963 default:
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002964 conn->state = BT_CLOSED;
Marcel Holtmann732547f2009-04-19 19:14:14 +02002965 break;
2966 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002967
2968 hci_proto_connect_cfm(conn, ev->status);
2969 if (ev->status)
2970 hci_conn_del(conn);
2971
2972unlock:
2973 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002974}
2975
2976static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb)
2977{
2978 BT_DBG("%s", hdev->name);
2979}
2980
Marcel Holtmann04837f62006-07-03 10:02:33 +02002981static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb)
2982{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002983 struct hci_ev_sniff_subrate *ev = (void *) skb->data;
Srinivas Krovvidia7c3d7e2012-08-06 15:31:55 +05302984 struct hci_conn *conn =
2985 hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Marcel Holtmann04837f62006-07-03 10:02:33 +02002986
2987 BT_DBG("%s status %d", hdev->name, ev->status);
Srinivas Krovvidia7c3d7e2012-08-06 15:31:55 +05302988 if (conn && (ev->max_rx_latency > hdev->sniff_max_interval)) {
2989 BT_ERR("value of rx_latency:%d", ev->max_rx_latency);
2990 hci_dev_lock(hdev);
2991 hci_conn_enter_active_mode(conn, 1);
2992 hci_dev_unlock(hdev);
2993 }
Marcel Holtmann04837f62006-07-03 10:02:33 +02002994}
2995
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002996static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
2997{
2998 struct inquiry_data data;
2999 struct extended_inquiry_info *info = (void *) (skb->data + 1);
3000 int num_rsp = *((__u8 *) skb->data);
3001
3002 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
3003
3004 if (!num_rsp)
3005 return;
3006
3007 hci_dev_lock(hdev);
3008
Johan Hedberge17acd42011-03-30 23:57:16 +03003009 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003010 bacpy(&data.bdaddr, &info->bdaddr);
Szymon Janc138d22e2011-02-17 16:44:23 +01003011 data.pscan_rep_mode = info->pscan_rep_mode;
3012 data.pscan_period_mode = info->pscan_period_mode;
3013 data.pscan_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003014 memcpy(data.dev_class, info->dev_class, 3);
Szymon Janc138d22e2011-02-17 16:44:23 +01003015 data.clock_offset = info->clock_offset;
3016 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02003017 data.ssp_mode = 0x01;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003018 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07003019 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
3020 info->dev_class, info->rssi,
3021 HCI_MAX_EIR_LENGTH, info->data);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003022 }
3023
3024 hci_dev_unlock(hdev);
3025}
3026
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003027static inline u8 hci_get_auth_req(struct hci_conn *conn)
3028{
Brian Gixa68668b2011-08-11 15:49:36 -07003029 BT_DBG("%p", conn);
3030
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003031 /* If remote requests dedicated bonding follow that lead */
3032 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) {
3033 /* If both remote and local IO capabilities allow MITM
3034 * protection then require it, otherwise don't */
Brian Gixa68668b2011-08-11 15:49:36 -07003035 if (conn->remote_cap == 0x03 || conn->io_capability == 0x03) {
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003036 return 0x02;
Brian Gixa68668b2011-08-11 15:49:36 -07003037 } else {
3038 conn->auth_type |= 0x01;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003039 return 0x03;
Brian Gixa68668b2011-08-11 15:49:36 -07003040 }
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003041 }
3042
3043 /* If remote requests no-bonding follow that lead */
Brian Gixa68668b2011-08-11 15:49:36 -07003044 if (conn->remote_auth <= 0x01)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003045 return 0x00;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003046
3047 return conn->auth_type;
3048}
3049
Marcel Holtmann04936842008-07-14 20:13:48 +02003050static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
3051{
3052 struct hci_ev_io_capa_request *ev = (void *) skb->data;
3053 struct hci_conn *conn;
3054
3055 BT_DBG("%s", hdev->name);
3056
3057 hci_dev_lock(hdev);
3058
3059 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedberg03b555e2011-01-04 15:40:05 +02003060 if (!conn)
3061 goto unlock;
Marcel Holtmann04936842008-07-14 20:13:48 +02003062
Johan Hedberg03b555e2011-01-04 15:40:05 +02003063 hci_conn_hold(conn);
3064
3065 if (!test_bit(HCI_MGMT, &hdev->flags))
3066 goto unlock;
3067
3068 if (test_bit(HCI_PAIRABLE, &hdev->flags) ||
3069 (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) {
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003070 struct hci_cp_io_capability_reply cp;
Brian Gixa68668b2011-08-11 15:49:36 -07003071 u8 io_cap = conn->io_capability;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003072
Brian Gixa68668b2011-08-11 15:49:36 -07003073 /* ACL-SSP does not support IO CAP 0x04 */
3074 cp.capability = (io_cap == 0x04) ? 0x01 : io_cap;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003075 bacpy(&cp.bdaddr, &ev->bdaddr);
Brian Gixa68668b2011-08-11 15:49:36 -07003076 if (conn->auth_initiator)
3077 cp.authentication = conn->auth_type;
3078 else
3079 cp.authentication = hci_get_auth_req(conn);
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003080
Szymon Jancce85ee12011-03-22 13:12:23 +01003081 if ((conn->out == 0x01 || conn->remote_oob == 0x01) &&
3082 hci_find_remote_oob_data(hdev, &conn->dst))
3083 cp.oob_data = 0x01;
3084 else
3085 cp.oob_data = 0x00;
3086
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003087 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
3088 sizeof(cp), &cp);
Johan Hedberg03b555e2011-01-04 15:40:05 +02003089 } else {
3090 struct hci_cp_io_capability_neg_reply cp;
3091
3092 bacpy(&cp.bdaddr, &ev->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003093 cp.reason = 0x16; /* Pairing not allowed */
Johan Hedberg03b555e2011-01-04 15:40:05 +02003094
3095 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
3096 sizeof(cp), &cp);
3097 }
3098
3099unlock:
3100 hci_dev_unlock(hdev);
3101}
3102
3103static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb)
3104{
3105 struct hci_ev_io_capa_reply *ev = (void *) skb->data;
3106 struct hci_conn *conn;
3107
3108 BT_DBG("%s", hdev->name);
3109
3110 hci_dev_lock(hdev);
3111
3112 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3113 if (!conn)
3114 goto unlock;
3115
Johan Hedberg03b555e2011-01-04 15:40:05 +02003116 conn->remote_cap = ev->capability;
3117 conn->remote_oob = ev->oob_data;
3118 conn->remote_auth = ev->authentication;
3119
3120unlock:
Marcel Holtmann04936842008-07-14 20:13:48 +02003121 hci_dev_unlock(hdev);
3122}
3123
Brian Gixa68668b2011-08-11 15:49:36 -07003124static inline void hci_user_ssp_confirmation_evt(struct hci_dev *hdev,
3125 u8 event, struct sk_buff *skb)
Johan Hedberga5c29682011-02-19 12:05:57 -03003126{
3127 struct hci_ev_user_confirm_req *ev = (void *) skb->data;
3128
3129 BT_DBG("%s", hdev->name);
3130
3131 hci_dev_lock(hdev);
3132
Brian Gixa68668b2011-08-11 15:49:36 -07003133 if (test_bit(HCI_MGMT, &hdev->flags)) {
3134 if (event == HCI_EV_USER_PASSKEY_REQUEST)
3135 mgmt_user_confirm_request(hdev->id, event,
3136 &ev->bdaddr, 0);
3137 else
3138 mgmt_user_confirm_request(hdev->id, event,
3139 &ev->bdaddr, ev->passkey);
3140 }
Johan Hedberga5c29682011-02-19 12:05:57 -03003141
3142 hci_dev_unlock(hdev);
3143}
3144
Marcel Holtmann04936842008-07-14 20:13:48 +02003145static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3146{
3147 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
3148 struct hci_conn *conn;
3149
3150 BT_DBG("%s", hdev->name);
3151
3152 hci_dev_lock(hdev);
3153
3154 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedberg2a611692011-02-19 12:06:00 -03003155 if (!conn)
3156 goto unlock;
Marcel Holtmann04936842008-07-14 20:13:48 +02003157
Johan Hedberg2a611692011-02-19 12:06:00 -03003158 /* To avoid duplicate auth_failed events to user space we check
3159 * the HCI_CONN_AUTH_PEND flag which will be set if we
3160 * initiated the authentication. A traditional auth_complete
3161 * event gets always produced as initiator and is also mapped to
3162 * the mgmt_auth_failed event */
3163 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->pend) && ev->status != 0)
3164 mgmt_auth_failed(hdev->id, &conn->dst, ev->status);
3165
3166 hci_conn_put(conn);
3167
3168unlock:
Marcel Holtmann04936842008-07-14 20:13:48 +02003169 hci_dev_unlock(hdev);
3170}
3171
Marcel Holtmann41a96212008-07-14 20:13:48 +02003172static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
3173{
3174 struct hci_ev_remote_host_features *ev = (void *) skb->data;
3175 struct inquiry_entry *ie;
3176
3177 BT_DBG("%s", hdev->name);
3178
3179 hci_dev_lock(hdev);
3180
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02003181 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
3182 if (ie)
Marcel Holtmann41a96212008-07-14 20:13:48 +02003183 ie->data.ssp_mode = (ev->features[0] & 0x01);
3184
3185 hci_dev_unlock(hdev);
3186}
3187
Szymon Janc2763eda2011-03-22 13:12:22 +01003188static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
3189 struct sk_buff *skb)
3190{
3191 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
3192 struct oob_data *data;
3193
3194 BT_DBG("%s", hdev->name);
3195
3196 hci_dev_lock(hdev);
3197
Szymon Jance1ba1f12011-04-06 13:01:59 +02003198 if (!test_bit(HCI_MGMT, &hdev->flags))
3199 goto unlock;
3200
Szymon Janc2763eda2011-03-22 13:12:22 +01003201 data = hci_find_remote_oob_data(hdev, &ev->bdaddr);
3202 if (data) {
3203 struct hci_cp_remote_oob_data_reply cp;
3204
3205 bacpy(&cp.bdaddr, &ev->bdaddr);
3206 memcpy(cp.hash, data->hash, sizeof(cp.hash));
3207 memcpy(cp.randomizer, data->randomizer, sizeof(cp.randomizer));
3208
3209 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp),
3210 &cp);
3211 } else {
3212 struct hci_cp_remote_oob_data_neg_reply cp;
3213
3214 bacpy(&cp.bdaddr, &ev->bdaddr);
3215 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp),
3216 &cp);
3217 }
3218
Szymon Jance1ba1f12011-04-06 13:01:59 +02003219unlock:
Szymon Janc2763eda2011-03-22 13:12:22 +01003220 hci_dev_unlock(hdev);
3221}
3222
Ville Tervofcd89c02011-02-10 22:38:47 -03003223static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3224{
3225 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
3226 struct hci_conn *conn;
Sunny Kapdi320598f2012-07-30 14:52:56 -07003227 u8 white_list;
Ville Tervofcd89c02011-02-10 22:38:47 -03003228
3229 BT_DBG("%s status %d", hdev->name, ev->status);
3230
3231 hci_dev_lock(hdev);
3232
Sunny Kapdi320598f2012-07-30 14:52:56 -07003233 /* Ignore event for LE cancel create conn whitelist */
3234 if (ev->status && !bacmp(&ev->bdaddr, BDADDR_ANY))
3235 goto unlock;
3236
3237 if (hci_conn_hash_lookup_ba(hdev, LE_LINK, BDADDR_ANY))
3238 white_list = 1;
3239 else
3240 white_list = 0;
3241
3242 BT_DBG("w_list %d", white_list);
3243
Ville Tervofcd89c02011-02-10 22:38:47 -03003244 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr);
Ville Tervob62f3282011-02-10 22:38:50 -03003245 if (!conn) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003246 conn = hci_le_conn_add(hdev, &ev->bdaddr, ev->bdaddr_type);
Ville Tervob62f3282011-02-10 22:38:50 -03003247 if (!conn) {
3248 BT_ERR("No memory for new connection");
3249 hci_dev_unlock(hdev);
3250 return;
3251 }
3252 }
Ville Tervofcd89c02011-02-10 22:38:47 -03003253
3254 if (ev->status) {
3255 hci_proto_connect_cfm(conn, ev->status);
3256 conn->state = BT_CLOSED;
3257 hci_conn_del(conn);
3258 goto unlock;
3259 }
3260
Vinicius Costa Gomes403d2c82011-06-09 18:50:50 -03003261 conn->sec_level = BT_SECURITY_LOW;
Ville Tervofcd89c02011-02-10 22:38:47 -03003262 conn->handle = __le16_to_cpu(ev->handle);
3263 conn->state = BT_CONNECTED;
Brian Gixa68668b2011-08-11 15:49:36 -07003264 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07003265 mgmt_connected(hdev->id, &ev->bdaddr, 1);
Sunny Kapdia42b5022012-07-05 22:48:31 -07003266 mgmt_le_conn_params(hdev->id, &ev->bdaddr,
3267 __le16_to_cpu(ev->interval),
3268 __le16_to_cpu(ev->latency),
3269 __le16_to_cpu(ev->supervision_timeout));
Ville Tervofcd89c02011-02-10 22:38:47 -03003270
Brian Gix6d5fb8a2011-09-09 14:53:04 -07003271 hci_conn_hold(conn);
Ville Tervofcd89c02011-02-10 22:38:47 -03003272 hci_conn_hold_device(conn);
3273 hci_conn_add_sysfs(conn);
3274
Sunny Kapdi320598f2012-07-30 14:52:56 -07003275 if (!white_list)
3276 hci_proto_connect_cfm(conn, ev->status);
Ville Tervofcd89c02011-02-10 22:38:47 -03003277
3278unlock:
3279 hci_dev_unlock(hdev);
3280}
3281
Sunny Kapdia42b5022012-07-05 22:48:31 -07003282static inline void hci_le_conn_update_complete_evt(struct hci_dev *hdev,
3283 struct sk_buff *skb)
3284{
3285 struct hci_ev_le_conn_update_complete *ev = (void *) skb->data;
3286 struct hci_conn *conn;
3287
3288 BT_DBG("%s status %d", hdev->name, ev->status);
3289
3290 hci_dev_lock(hdev);
3291
3292 conn = hci_conn_hash_lookup_handle(hdev,
3293 __le16_to_cpu(ev->handle));
3294 if (conn == NULL) {
3295 BT_ERR("Unknown connection update");
3296 goto unlock;
3297 }
3298
3299 if (ev->status) {
3300 BT_ERR("Connection update unsuccessful");
3301 goto unlock;
3302 }
3303
3304 mgmt_le_conn_params(hdev->id, &conn->dst,
3305 __le16_to_cpu(ev->interval),
3306 __le16_to_cpu(ev->latency),
3307 __le16_to_cpu(ev->supervision_timeout));
3308
3309unlock:
3310 hci_dev_unlock(hdev);
3311}
3312
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003313static inline void hci_le_ltk_request_evt(struct hci_dev *hdev,
3314 struct sk_buff *skb)
3315{
3316 struct hci_ev_le_ltk_req *ev = (void *) skb->data;
3317 struct hci_cp_le_ltk_reply cp;
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003318 struct hci_cp_le_ltk_neg_reply neg;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003319 struct hci_conn *conn;
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003320 struct link_key *ltk;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003321
3322 BT_DBG("%s handle %d", hdev->name, cpu_to_le16(ev->handle));
3323
3324 hci_dev_lock(hdev);
3325
3326 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003327 if (conn == NULL)
3328 goto not_found;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003329
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003330 ltk = hci_find_ltk(hdev, ev->ediv, ev->random);
3331 if (ltk == NULL)
3332 goto not_found;
3333
3334 memcpy(cp.ltk, ltk->val, sizeof(ltk->val));
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003335 cp.handle = cpu_to_le16(conn->handle);
Vinicius Costa Gomes1fa2de32011-07-08 18:31:45 -03003336 conn->pin_length = ltk->pin_len;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003337
3338 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
3339
3340 hci_dev_unlock(hdev);
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003341
3342 return;
3343
3344not_found:
3345 neg.handle = ev->handle;
3346 hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg);
3347 hci_dev_unlock(hdev);
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003348}
3349
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003350static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
3351 struct sk_buff *skb)
3352{
3353 struct hci_ev_le_advertising_info *ev;
3354 u8 num_reports;
3355
3356 num_reports = skb->data[0];
3357 ev = (void *) &skb->data[1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003358
Brian Gix3dd70172011-09-16 21:38:54 -07003359 hci_dev_lock(hdev);
3360
Brian Gixa68668b2011-08-11 15:49:36 -07003361 while (num_reports--) {
3362 mgmt_device_found(hdev->id, &ev->bdaddr, ev->bdaddr_type,
3363 1, NULL, 0, ev->length, ev->data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003364 hci_add_adv_entry(hdev, ev);
Brian Gixa68668b2011-08-11 15:49:36 -07003365 ev = (void *) (ev->data + ev->length + 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003366 }
Brian Gix3dd70172011-09-16 21:38:54 -07003367
3368 hci_dev_unlock(hdev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003369}
3370
Ville Tervofcd89c02011-02-10 22:38:47 -03003371static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
3372{
3373 struct hci_ev_le_meta *le_ev = (void *) skb->data;
3374
3375 skb_pull(skb, sizeof(*le_ev));
3376
3377 switch (le_ev->subevent) {
3378 case HCI_EV_LE_CONN_COMPLETE:
3379 hci_le_conn_complete_evt(hdev, skb);
3380 break;
3381
Sunny Kapdia42b5022012-07-05 22:48:31 -07003382 case HCI_EV_LE_CONN_UPDATE_COMPLETE:
3383 hci_le_conn_update_complete_evt(hdev, skb);
3384 break;
3385
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003386 case HCI_EV_LE_LTK_REQ:
3387 hci_le_ltk_request_evt(hdev, skb);
3388 break;
3389
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003390 case HCI_EV_LE_ADVERTISING_REPORT:
3391 hci_le_adv_report_evt(hdev, skb);
3392 break;
3393
Ville Tervofcd89c02011-02-10 22:38:47 -03003394 default:
3395 break;
3396 }
3397}
3398
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003399static inline void hci_phy_link_complete(struct hci_dev *hdev,
3400 struct sk_buff *skb)
3401{
3402 struct hci_ev_phys_link_complete *ev = (void *) skb->data;
3403 struct hci_conn *conn;
3404
3405 BT_DBG("%s handle %d status %d", hdev->name, ev->phy_handle,
3406 ev->status);
3407
3408 hci_dev_lock(hdev);
3409
3410 if (ev->status == 0) {
3411 conn = hci_conn_add(hdev, ACL_LINK, 0, BDADDR_ANY);
3412 if (conn) {
3413 conn->handle = ev->phy_handle;
3414 conn->state = BT_CONNECTED;
3415
3416 hci_conn_hold(conn);
3417 conn->disc_timeout = HCI_DISCONN_TIMEOUT/2;
3418 hci_conn_put(conn);
3419
3420 hci_conn_hold_device(conn);
3421 hci_conn_add_sysfs(conn);
3422 } else
3423 BT_ERR("No memory for new connection");
3424 }
3425
3426 hci_dev_unlock(hdev);
3427}
3428
3429static inline void hci_log_link_complete(struct hci_dev *hdev,
3430 struct sk_buff *skb)
3431{
3432 struct hci_ev_log_link_complete *ev = (void *) skb->data;
3433 struct hci_chan *chan;
3434
3435 BT_DBG("%s handle %d status %d", hdev->name,
3436 __le16_to_cpu(ev->log_handle), ev->status);
3437
3438 hci_dev_lock(hdev);
3439
3440 chan = hci_chan_list_lookup_id(hdev, ev->phy_handle);
3441
Mat Martineau9f8d4672011-12-14 12:10:46 -08003442 if (chan) {
3443 if (ev->status == 0) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003444 chan->ll_handle = __le16_to_cpu(ev->log_handle);
3445 chan->state = BT_CONNECTED;
Mat Martineau9f8d4672011-12-14 12:10:46 -08003446 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003447 chan->state = BT_CLOSED;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003448 }
Mat Martineau9f8d4672011-12-14 12:10:46 -08003449
3450 hci_proto_create_cfm(chan, ev->status);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003451 }
3452
3453 hci_dev_unlock(hdev);
3454}
3455
3456static inline void hci_flow_spec_modify_complete(struct hci_dev *hdev,
3457 struct sk_buff *skb)
3458{
3459 struct hci_ev_flow_spec_modify_complete *ev = (void *) skb->data;
3460 struct hci_chan *chan;
3461
3462 BT_DBG("%s handle %d status %d", hdev->name,
3463 __le16_to_cpu(ev->log_handle), ev->status);
3464
3465 hci_dev_lock(hdev);
3466
3467 chan = hci_chan_list_lookup_handle(hdev, ev->log_handle);
3468 if (chan)
3469 hci_proto_modify_cfm(chan, ev->status);
3470
3471 hci_dev_unlock(hdev);
3472}
3473
3474static inline void hci_disconn_log_link_complete_evt(struct hci_dev *hdev,
3475 struct sk_buff *skb)
3476{
3477 struct hci_ev_disconn_log_link_complete *ev = (void *) skb->data;
3478 struct hci_chan *chan;
3479
3480 BT_DBG("%s handle %d status %d", hdev->name,
3481 __le16_to_cpu(ev->log_handle), ev->status);
3482
3483 if (ev->status)
3484 return;
3485
3486 hci_dev_lock(hdev);
3487
3488 chan = hci_chan_list_lookup_handle(hdev, __le16_to_cpu(ev->log_handle));
Mat Martineau9f8d4672011-12-14 12:10:46 -08003489 if (chan)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003490 hci_proto_destroy_cfm(chan, ev->reason);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003491
3492 hci_dev_unlock(hdev);
3493}
3494
3495static inline void hci_disconn_phy_link_complete_evt(struct hci_dev *hdev,
3496 struct sk_buff *skb)
3497{
3498 struct hci_ev_disconn_phys_link_complete *ev = (void *) skb->data;
3499 struct hci_conn *conn;
3500
3501 BT_DBG("%s status %d", hdev->name, ev->status);
3502
3503 if (ev->status)
3504 return;
3505
3506 hci_dev_lock(hdev);
3507
3508 conn = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3509 if (conn) {
3510 conn->state = BT_CLOSED;
3511
Mat Martineau3b9239a2012-02-16 11:54:30 -08003512 hci_proto_disconn_cfm(conn, ev->reason, 0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003513 hci_conn_del(conn);
3514 }
3515
3516 hci_dev_unlock(hdev);
3517}
3518
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
3520{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003521 struct hci_event_hdr *hdr = (void *) skb->data;
3522 __u8 event = hdr->evt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
Brian Gixdfdd9362011-08-18 09:58:02 -07003524 BT_DBG("");
3525
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 skb_pull(skb, HCI_EVENT_HDR_SIZE);
3527
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003528 switch (event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 case HCI_EV_INQUIRY_COMPLETE:
3530 hci_inquiry_complete_evt(hdev, skb);
3531 break;
3532
3533 case HCI_EV_INQUIRY_RESULT:
3534 hci_inquiry_result_evt(hdev, skb);
3535 break;
3536
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003537 case HCI_EV_CONN_COMPLETE:
3538 hci_conn_complete_evt(hdev, skb);
Marcel Holtmann21d9e302005-09-13 01:32:25 +02003539 break;
3540
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 case HCI_EV_CONN_REQUEST:
3542 hci_conn_request_evt(hdev, skb);
3543 break;
3544
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 case HCI_EV_DISCONN_COMPLETE:
3546 hci_disconn_complete_evt(hdev, skb);
3547 break;
3548
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 case HCI_EV_AUTH_COMPLETE:
3550 hci_auth_complete_evt(hdev, skb);
3551 break;
3552
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003553 case HCI_EV_REMOTE_NAME:
3554 hci_remote_name_evt(hdev, skb);
3555 break;
3556
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557 case HCI_EV_ENCRYPT_CHANGE:
3558 hci_encrypt_change_evt(hdev, skb);
3559 break;
3560
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003561 case HCI_EV_CHANGE_LINK_KEY_COMPLETE:
3562 hci_change_link_key_complete_evt(hdev, skb);
3563 break;
3564
3565 case HCI_EV_REMOTE_FEATURES:
3566 hci_remote_features_evt(hdev, skb);
3567 break;
3568
3569 case HCI_EV_REMOTE_VERSION:
3570 hci_remote_version_evt(hdev, skb);
3571 break;
3572
3573 case HCI_EV_QOS_SETUP_COMPLETE:
3574 hci_qos_setup_complete_evt(hdev, skb);
3575 break;
3576
3577 case HCI_EV_CMD_COMPLETE:
3578 hci_cmd_complete_evt(hdev, skb);
3579 break;
3580
3581 case HCI_EV_CMD_STATUS:
3582 hci_cmd_status_evt(hdev, skb);
3583 break;
3584
3585 case HCI_EV_ROLE_CHANGE:
3586 hci_role_change_evt(hdev, skb);
3587 break;
3588
3589 case HCI_EV_NUM_COMP_PKTS:
3590 hci_num_comp_pkts_evt(hdev, skb);
3591 break;
3592
3593 case HCI_EV_MODE_CHANGE:
3594 hci_mode_change_evt(hdev, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 break;
3596
3597 case HCI_EV_PIN_CODE_REQ:
3598 hci_pin_code_request_evt(hdev, skb);
3599 break;
3600
3601 case HCI_EV_LINK_KEY_REQ:
3602 hci_link_key_request_evt(hdev, skb);
3603 break;
3604
3605 case HCI_EV_LINK_KEY_NOTIFY:
3606 hci_link_key_notify_evt(hdev, skb);
3607 break;
3608
3609 case HCI_EV_CLOCK_OFFSET:
3610 hci_clock_offset_evt(hdev, skb);
3611 break;
3612
Marcel Holtmanna8746412008-07-14 20:13:46 +02003613 case HCI_EV_PKT_TYPE_CHANGE:
3614 hci_pkt_type_change_evt(hdev, skb);
3615 break;
3616
Marcel Holtmann85a1e932005-08-09 20:28:02 -07003617 case HCI_EV_PSCAN_REP_MODE:
3618 hci_pscan_rep_mode_evt(hdev, skb);
3619 break;
3620
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003621 case HCI_EV_INQUIRY_RESULT_WITH_RSSI:
3622 hci_inquiry_result_with_rssi_evt(hdev, skb);
3623 break;
3624
3625 case HCI_EV_REMOTE_EXT_FEATURES:
3626 hci_remote_ext_features_evt(hdev, skb);
3627 break;
3628
3629 case HCI_EV_SYNC_CONN_COMPLETE:
3630 hci_sync_conn_complete_evt(hdev, skb);
3631 break;
3632
3633 case HCI_EV_SYNC_CONN_CHANGED:
3634 hci_sync_conn_changed_evt(hdev, skb);
3635 break;
3636
Marcel Holtmann04837f62006-07-03 10:02:33 +02003637 case HCI_EV_SNIFF_SUBRATE:
3638 hci_sniff_subrate_evt(hdev, skb);
3639 break;
3640
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003641 case HCI_EV_EXTENDED_INQUIRY_RESULT:
3642 hci_extended_inquiry_result_evt(hdev, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 break;
3644
Marcel Holtmann04936842008-07-14 20:13:48 +02003645 case HCI_EV_IO_CAPA_REQUEST:
3646 hci_io_capa_request_evt(hdev, skb);
3647 break;
3648
Johan Hedberg03b555e2011-01-04 15:40:05 +02003649 case HCI_EV_IO_CAPA_REPLY:
3650 hci_io_capa_reply_evt(hdev, skb);
3651 break;
3652
Brian Gixa68668b2011-08-11 15:49:36 -07003653 case HCI_EV_USER_PASSKEY_REQUEST:
3654 case HCI_EV_USER_PASSKEY_NOTIFICATION:
Johan Hedberga5c29682011-02-19 12:05:57 -03003655 case HCI_EV_USER_CONFIRM_REQUEST:
Brian Gixa68668b2011-08-11 15:49:36 -07003656 hci_user_ssp_confirmation_evt(hdev, event, skb);
Johan Hedberga5c29682011-02-19 12:05:57 -03003657 break;
3658
Marcel Holtmann04936842008-07-14 20:13:48 +02003659 case HCI_EV_SIMPLE_PAIR_COMPLETE:
3660 hci_simple_pair_complete_evt(hdev, skb);
3661 break;
3662
Marcel Holtmann41a96212008-07-14 20:13:48 +02003663 case HCI_EV_REMOTE_HOST_FEATURES:
3664 hci_remote_host_features_evt(hdev, skb);
3665 break;
3666
Ville Tervofcd89c02011-02-10 22:38:47 -03003667 case HCI_EV_LE_META:
3668 hci_le_meta_evt(hdev, skb);
3669 break;
3670
Szymon Janc2763eda2011-03-22 13:12:22 +01003671 case HCI_EV_REMOTE_OOB_DATA_REQUEST:
3672 hci_remote_oob_data_request_evt(hdev, skb);
3673 break;
3674
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003675 case HCI_EV_PHYS_LINK_COMPLETE:
3676 hci_phy_link_complete(hdev, skb);
3677 hci_amp_event_packet(hdev, event, skb);
3678 break;
3679
3680 case HCI_EV_LOG_LINK_COMPLETE:
3681 hci_log_link_complete(hdev, skb);
3682 break;
3683
3684 case HCI_EV_FLOW_SPEC_MODIFY_COMPLETE:
3685 hci_flow_spec_modify_complete(hdev, skb);
3686 break;
3687
3688 case HCI_EV_DISCONN_LOG_LINK_COMPLETE:
3689 hci_disconn_log_link_complete_evt(hdev, skb);
3690 break;
3691
3692 case HCI_EV_DISCONN_PHYS_LINK_COMPLETE:
3693 hci_disconn_phy_link_complete_evt(hdev, skb);
3694 hci_amp_event_packet(hdev, event, skb);
3695 break;
3696
3697 case HCI_EV_NUM_COMP_BLOCKS:
3698 hci_num_comp_blocks_evt(hdev, skb);
3699 break;
3700
3701 case HCI_EV_CHANNEL_SELECTED:
3702 hci_amp_event_packet(hdev, event, skb);
3703 break;
3704
3705 case HCI_EV_AMP_STATUS_CHANGE:
3706 hci_amp_event_packet(hdev, event, skb);
3707 break;
3708
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003709 default:
3710 BT_DBG("%s event 0x%x", hdev->name, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003711 break;
3712 }
3713
3714 kfree_skb(skb);
3715 hdev->stat.evt_rx++;
3716}
3717
3718/* Generate internal stack event */
3719void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data)
3720{
3721 struct hci_event_hdr *hdr;
3722 struct hci_ev_stack_internal *ev;
3723 struct sk_buff *skb;
3724
3725 skb = bt_skb_alloc(HCI_EVENT_HDR_SIZE + sizeof(*ev) + dlen, GFP_ATOMIC);
3726 if (!skb)
3727 return;
3728
3729 hdr = (void *) skb_put(skb, HCI_EVENT_HDR_SIZE);
3730 hdr->evt = HCI_EV_STACK_INTERNAL;
3731 hdr->plen = sizeof(*ev) + dlen;
3732
3733 ev = (void *) skb_put(skb, sizeof(*ev) + dlen);
3734 ev->type = type;
3735 memcpy(ev->data, data, dlen);
3736
Marcel Holtmann576c7d82005-08-06 12:36:54 +02003737 bt_cb(skb)->incoming = 1;
Patrick McHardya61bbcf2005-08-14 17:24:31 -07003738 __net_timestamp(skb);
Marcel Holtmann576c7d82005-08-06 12:36:54 +02003739
Marcel Holtmann0d48d932005-08-09 20:30:28 -07003740 bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003741 skb->dev = (void *) hdev;
Johan Hedbergeec8d2b2010-12-16 10:17:38 +02003742 hci_send_to_sock(hdev, skb, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003743 kfree_skb(skb);
3744}