blob: 6fdc7c73fd055437db5038cd5dbd4e0218b4a23c [file] [log] [blame]
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +09001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 BlueZ - Bluetooth protocol stack for Linux
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003 Copyright (c) 2000-2001, 2010-2011, Code Aurora Forum. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation;
10
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +090015 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
YOSHIFUJI Hideaki8e87d142007-02-09 23:24:33 +090020 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 SOFTWARE IS DISCLAIMED.
23*/
24
25/* Bluetooth HCI event handling. */
26
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/module.h>
28
29#include <linux/types.h>
30#include <linux/errno.h>
31#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <linux/slab.h>
33#include <linux/poll.h>
34#include <linux/fcntl.h>
35#include <linux/init.h>
36#include <linux/skbuff.h>
37#include <linux/interrupt.h>
38#include <linux/notifier.h>
39#include <net/sock.h>
40
41#include <asm/system.h>
Andrei Emeltchenko70f230202010-12-01 16:58:25 +020042#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#include <asm/unaligned.h>
44
45#include <net/bluetooth/bluetooth.h>
46#include <net/bluetooth/hci_core.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/* Handle HCI Event packets */
49
Marcel Holtmanna9de9242007-10-20 13:33:56 +020050static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Marcel Holtmanna9de9242007-10-20 13:33:56 +020052 __u8 status = *((__u8 *) skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Marcel Holtmanna9de9242007-10-20 13:33:56 +020054 BT_DBG("%s status 0x%x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Marcel Holtmanna9de9242007-10-20 13:33:56 +020056 if (status)
57 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059 clear_bit(HCI_INQUIRY, &hdev->flags);
Marcel Holtmann6bd57412006-11-18 22:14:22 +010060
Johan Hedberg23bb5762010-12-21 23:01:27 +020061 hci_req_complete(hdev, HCI_OP_INQUIRY_CANCEL, status);
Marcel Holtmann6bd57412006-11-18 22:14:22 +010062
Marcel Holtmanna9de9242007-10-20 13:33:56 +020063 hci_conn_check_pending(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064}
65
Marcel Holtmanna9de9242007-10-20 13:33:56 +020066static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
Marcel Holtmanna9de9242007-10-20 13:33:56 +020068 __u8 status = *((__u8 *) skb->data);
69
70 BT_DBG("%s status 0x%x", hdev->name, status);
71
72 if (status)
73 return;
74
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070075 clear_bit(HCI_INQUIRY, &hdev->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +020076
77 hci_conn_check_pending(hdev);
78}
79
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070080static void hci_cc_link_key_reply(struct hci_dev *hdev, struct sk_buff *skb)
81{
82 struct hci_rp_link_key_reply *rp = (void *) skb->data;
83 struct hci_conn *conn;
84 struct hci_cp_link_key_reply *cp;
85
86 BT_DBG("%s status 0x%x", hdev->name, rp->status);
87 if (rp->status)
88 return;
89
90 cp = hci_sent_cmd_data(hdev, HCI_OP_LINK_KEY_REPLY);
91 if (!cp)
92 return;
93
94 hci_dev_lock(hdev);
95 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
96 if (conn) {
97 hci_conn_hold(conn);
98 memcpy(conn->link_key, cp->link_key, sizeof(conn->link_key));
99 conn->key_type = 5;
100 hci_conn_put(conn);
101 }
102 hci_dev_unlock(hdev);
103}
104
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200105static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev, struct sk_buff *skb)
106{
107 BT_DBG("%s", hdev->name);
108}
109
110static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
111{
112 struct hci_rp_role_discovery *rp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200115 BT_DBG("%s status 0x%x", hdev->name, rp->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200117 if (rp->status)
118 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200120 hci_dev_lock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200122 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
123 if (conn) {
124 if (rp->role)
125 conn->link_mode &= ~HCI_LM_MASTER;
126 else
127 conn->link_mode |= HCI_LM_MASTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200129
130 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131}
132
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200133static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
134{
135 struct hci_rp_read_link_policy *rp = (void *) skb->data;
136 struct hci_conn *conn;
137
138 BT_DBG("%s status 0x%x", hdev->name, rp->status);
139
140 if (rp->status)
141 return;
142
143 hci_dev_lock(hdev);
144
145 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
146 if (conn)
147 conn->link_policy = __le16_to_cpu(rp->policy);
148
149 hci_dev_unlock(hdev);
150}
151
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200152static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200154 struct hci_rp_write_link_policy *rp = (void *) skb->data;
155 struct hci_conn *conn;
156 void *sent;
157
158 BT_DBG("%s status 0x%x", hdev->name, rp->status);
159
160 if (rp->status)
161 return;
162
163 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
164 if (!sent)
165 return;
166
167 hci_dev_lock(hdev);
168
169 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200170 if (conn)
Harvey Harrison83985312008-05-02 16:25:46 -0700171 conn->link_policy = get_unaligned_le16(sent + 2);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200172
173 hci_dev_unlock(hdev);
174}
175
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200176static void hci_cc_read_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
177{
178 struct hci_rp_read_def_link_policy *rp = (void *) skb->data;
179
180 BT_DBG("%s status 0x%x", hdev->name, rp->status);
181
182 if (rp->status)
183 return;
184
185 hdev->link_policy = __le16_to_cpu(rp->policy);
186}
187
188static void hci_cc_write_def_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
189{
190 __u8 status = *((__u8 *) skb->data);
191 void *sent;
192
193 BT_DBG("%s status 0x%x", hdev->name, status);
194
195 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
196 if (!sent)
197 return;
198
199 if (!status)
200 hdev->link_policy = get_unaligned_le16(sent);
201
Johan Hedberg23bb5762010-12-21 23:01:27 +0200202 hci_req_complete(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, status);
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200203}
204
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200205static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
206{
207 __u8 status = *((__u8 *) skb->data);
208
209 BT_DBG("%s status 0x%x", hdev->name, status);
210
Gustavo F. Padovan10572132011-03-16 15:36:29 -0300211 clear_bit(HCI_RESET, &hdev->flags);
212
Johan Hedberg23bb5762010-12-21 23:01:27 +0200213 hci_req_complete(hdev, HCI_OP_RESET, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200214}
215
216static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
217{
218 __u8 status = *((__u8 *) skb->data);
219 void *sent;
220
221 BT_DBG("%s status 0x%x", hdev->name, status);
222
223 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
224 if (!sent)
225 return;
226
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);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200232}
233
234static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
235{
236 struct hci_rp_read_local_name *rp = (void *) skb->data;
237
238 BT_DBG("%s status 0x%x", hdev->name, rp->status);
239
240 if (rp->status)
241 return;
242
Johan Hedberg1f6c6372011-03-16 14:29:35 +0200243 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200244}
245
246static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
247{
248 __u8 status = *((__u8 *) skb->data);
249 void *sent;
250
251 BT_DBG("%s status 0x%x", hdev->name, status);
252
253 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
254 if (!sent)
255 return;
256
257 if (!status) {
258 __u8 param = *((__u8 *) sent);
259
260 if (param == AUTH_ENABLED)
261 set_bit(HCI_AUTH, &hdev->flags);
262 else
263 clear_bit(HCI_AUTH, &hdev->flags);
264 }
265
Johan Hedberg23bb5762010-12-21 23:01:27 +0200266 hci_req_complete(hdev, HCI_OP_WRITE_AUTH_ENABLE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200267}
268
269static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
270{
271 __u8 status = *((__u8 *) skb->data);
272 void *sent;
273
274 BT_DBG("%s status 0x%x", hdev->name, status);
275
276 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
277 if (!sent)
278 return;
279
280 if (!status) {
281 __u8 param = *((__u8 *) sent);
282
283 if (param)
284 set_bit(HCI_ENCRYPT, &hdev->flags);
285 else
286 clear_bit(HCI_ENCRYPT, &hdev->flags);
287 }
288
Johan Hedberg23bb5762010-12-21 23:01:27 +0200289 hci_req_complete(hdev, HCI_OP_WRITE_ENCRYPT_MODE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200290}
291
292static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
293{
294 __u8 status = *((__u8 *) skb->data);
295 void *sent;
296
297 BT_DBG("%s status 0x%x", hdev->name, status);
298
299 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
300 if (!sent)
301 return;
302
303 if (!status) {
304 __u8 param = *((__u8 *) sent);
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200305 int old_pscan, old_iscan;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200306
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200307 old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags);
308 old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200309
Johan Hedberg73f22f62010-12-29 16:00:25 +0200310 if (param & SCAN_INQUIRY) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200311 set_bit(HCI_ISCAN, &hdev->flags);
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200312 if (!old_iscan)
313 mgmt_discoverable(hdev->id, 1);
314 } else if (old_iscan)
Johan Hedberg73f22f62010-12-29 16:00:25 +0200315 mgmt_discoverable(hdev->id, 0);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200316
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200317 if (param & SCAN_PAGE) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200318 set_bit(HCI_PSCAN, &hdev->flags);
Johan Hedberg9fbcbb42010-12-30 00:18:33 +0200319 if (!old_pscan)
320 mgmt_connectable(hdev->id, 1);
321 } else if (old_pscan)
322 mgmt_connectable(hdev->id, 0);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200323 }
324
Johan Hedberg23bb5762010-12-21 23:01:27 +0200325 hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200326}
327
328static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
329{
330 struct hci_rp_read_class_of_dev *rp = (void *) skb->data;
331
332 BT_DBG("%s status 0x%x", hdev->name, rp->status);
333
334 if (rp->status)
335 return;
336
337 memcpy(hdev->dev_class, rp->dev_class, 3);
338
339 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
340 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
341}
342
343static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
344{
345 __u8 status = *((__u8 *) skb->data);
346 void *sent;
347
348 BT_DBG("%s status 0x%x", hdev->name, status);
349
Marcel Holtmannf383f272008-07-14 20:13:47 +0200350 if (status)
351 return;
352
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200353 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
354 if (!sent)
355 return;
356
Marcel Holtmannf383f272008-07-14 20:13:47 +0200357 memcpy(hdev->dev_class, sent, 3);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200358}
359
360static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
361{
362 struct hci_rp_read_voice_setting *rp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 __u16 setting;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200364
365 BT_DBG("%s status 0x%x", hdev->name, rp->status);
366
367 if (rp->status)
368 return;
369
370 setting = __le16_to_cpu(rp->voice_setting);
371
Marcel Holtmannf383f272008-07-14 20:13:47 +0200372 if (hdev->voice_setting == setting)
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200373 return;
374
375 hdev->voice_setting = setting;
376
377 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
378
379 if (hdev->notify) {
380 tasklet_disable(&hdev->tx_task);
381 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
382 tasklet_enable(&hdev->tx_task);
383 }
384}
385
386static void hci_cc_write_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
387{
388 __u8 status = *((__u8 *) skb->data);
Marcel Holtmannf383f272008-07-14 20:13:47 +0200389 __u16 setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 void *sent;
391
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200392 BT_DBG("%s status 0x%x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Marcel Holtmannf383f272008-07-14 20:13:47 +0200394 if (status)
395 return;
396
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200397 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
398 if (!sent)
399 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Marcel Holtmannf383f272008-07-14 20:13:47 +0200401 setting = get_unaligned_le16(sent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Marcel Holtmannf383f272008-07-14 20:13:47 +0200403 if (hdev->voice_setting == setting)
404 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
Marcel Holtmannf383f272008-07-14 20:13:47 +0200406 hdev->voice_setting = setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Marcel Holtmannf383f272008-07-14 20:13:47 +0200408 BT_DBG("%s voice setting 0x%04x", hdev->name, setting);
409
410 if (hdev->notify) {
411 tasklet_disable(&hdev->tx_task);
412 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
413 tasklet_enable(&hdev->tx_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
415}
416
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200417static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418{
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200419 __u8 status = *((__u8 *) skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200421 BT_DBG("%s status 0x%x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Johan Hedberg23bb5762010-12-21 23:01:27 +0200423 hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424}
425
Marcel Holtmann333140b2008-07-14 20:13:48 +0200426static void hci_cc_read_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
427{
428 struct hci_rp_read_ssp_mode *rp = (void *) skb->data;
429
430 BT_DBG("%s status 0x%x", hdev->name, rp->status);
431
432 if (rp->status)
433 return;
434
435 hdev->ssp_mode = rp->mode;
436}
437
438static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
439{
440 __u8 status = *((__u8 *) skb->data);
441 void *sent;
442
443 BT_DBG("%s status 0x%x", hdev->name, status);
444
445 if (status)
446 return;
447
448 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
449 if (!sent)
450 return;
451
452 hdev->ssp_mode = *((__u8 *) sent);
453}
454
Johan Hedbergd5859e22011-01-25 01:19:58 +0200455static u8 hci_get_inquiry_mode(struct hci_dev *hdev)
456{
457 if (hdev->features[6] & LMP_EXT_INQ)
458 return 2;
459
460 if (hdev->features[3] & LMP_RSSI_INQ)
461 return 1;
462
463 if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 &&
464 hdev->lmp_subver == 0x0757)
465 return 1;
466
467 if (hdev->manufacturer == 15) {
468 if (hdev->hci_rev == 0x03 && hdev->lmp_subver == 0x6963)
469 return 1;
470 if (hdev->hci_rev == 0x09 && hdev->lmp_subver == 0x6963)
471 return 1;
472 if (hdev->hci_rev == 0x00 && hdev->lmp_subver == 0x6965)
473 return 1;
474 }
475
476 if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 &&
477 hdev->lmp_subver == 0x1805)
478 return 1;
479
480 return 0;
481}
482
483static void hci_setup_inquiry_mode(struct hci_dev *hdev)
484{
485 u8 mode;
486
487 mode = hci_get_inquiry_mode(hdev);
488
489 hci_send_cmd(hdev, HCI_OP_WRITE_INQUIRY_MODE, 1, &mode);
490}
491
492static void hci_setup_event_mask(struct hci_dev *hdev)
493{
494 /* The second byte is 0xff instead of 0x9f (two reserved bits
495 * disabled) since a Broadcom 1.2 dongle doesn't respond to the
496 * command otherwise */
497 u8 events[8] = { 0xff, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x00 };
498
Brian Gixa68668b2011-08-11 15:49:36 -0700499 BT_DBG("");
500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700501 /* Events for 1.2 and newer controllers */
502 if (hdev->lmp_ver > 1) {
503 events[4] |= 0x01; /* Flow Specification Complete */
504 events[4] |= 0x02; /* Inquiry Result with RSSI */
505 events[4] |= 0x04; /* Read Remote Extended Features Complete */
506 events[5] |= 0x08; /* Synchronous Connection Complete */
507 events[5] |= 0x10; /* Synchronous Connection Changed */
508 }
Johan Hedbergd5859e22011-01-25 01:19:58 +0200509
510 if (hdev->features[3] & LMP_RSSI_INQ)
511 events[4] |= 0x04; /* Inquiry Result with RSSI */
512
513 if (hdev->features[5] & LMP_SNIFF_SUBR)
514 events[5] |= 0x20; /* Sniff Subrating */
515
516 if (hdev->features[5] & LMP_PAUSE_ENC)
517 events[5] |= 0x80; /* Encryption Key Refresh Complete */
518
519 if (hdev->features[6] & LMP_EXT_INQ)
520 events[5] |= 0x40; /* Extended Inquiry Result */
521
522 if (hdev->features[6] & LMP_NO_FLUSH)
523 events[7] |= 0x01; /* Enhanced Flush Complete */
524
525 if (hdev->features[7] & LMP_LSTO)
526 events[6] |= 0x80; /* Link Supervision Timeout Changed */
527
528 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
529 events[6] |= 0x01; /* IO Capability Request */
530 events[6] |= 0x02; /* IO Capability Response */
531 events[6] |= 0x04; /* User Confirmation Request */
532 events[6] |= 0x08; /* User Passkey Request */
533 events[6] |= 0x10; /* Remote OOB Data Request */
534 events[6] |= 0x20; /* Simple Pairing Complete */
535 events[7] |= 0x04; /* User Passkey Notification */
536 events[7] |= 0x08; /* Keypress Notification */
537 events[7] |= 0x10; /* Remote Host Supported
538 * Features Notification */
539 }
540
541 if (hdev->features[4] & LMP_LE)
542 events[7] |= 0x20; /* LE Meta-Event */
543
544 hci_send_cmd(hdev, HCI_OP_SET_EVENT_MASK, sizeof(events), events);
545}
546
547static void hci_setup(struct hci_dev *hdev)
548{
Johan Hedbergd5859e22011-01-25 01:19:58 +0200549 if (hdev->lmp_ver > 1)
550 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL);
551
552 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
553 u8 mode = 0x01;
554 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE, sizeof(mode), &mode);
555 }
556
557 if (hdev->features[3] & LMP_RSSI_INQ)
558 hci_setup_inquiry_mode(hdev);
559
560 if (hdev->features[7] & LMP_INQ_TX_PWR)
561 hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, 0, NULL);
562}
563
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200564static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
565{
566 struct hci_rp_read_local_version *rp = (void *) skb->data;
567
568 BT_DBG("%s status 0x%x", hdev->name, rp->status);
569
570 if (rp->status)
571 return;
572
573 hdev->hci_ver = rp->hci_ver;
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200574 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200575 hdev->lmp_ver = rp->lmp_ver;
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200576 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200577 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200578
579 BT_DBG("%s manufacturer %d hci ver %d:%d", hdev->name,
580 hdev->manufacturer,
581 hdev->hci_ver, hdev->hci_rev);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200582
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583 if (hdev->dev_type == HCI_BREDR && test_bit(HCI_INIT, &hdev->flags))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200584 hci_setup(hdev);
585}
586
587static void hci_setup_link_policy(struct hci_dev *hdev)
588{
589 u16 link_policy = 0;
590
591 if (hdev->features[0] & LMP_RSWITCH)
592 link_policy |= HCI_LP_RSWITCH;
593 if (hdev->features[0] & LMP_HOLD)
594 link_policy |= HCI_LP_HOLD;
595 if (hdev->features[0] & LMP_SNIFF)
596 link_policy |= HCI_LP_SNIFF;
597 if (hdev->features[1] & LMP_PARK)
598 link_policy |= HCI_LP_PARK;
599
600 link_policy = cpu_to_le16(link_policy);
601 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY,
602 sizeof(link_policy), &link_policy);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200603}
604
605static void hci_cc_read_local_commands(struct hci_dev *hdev, struct sk_buff *skb)
606{
607 struct hci_rp_read_local_commands *rp = (void *) skb->data;
608
609 BT_DBG("%s status 0x%x", hdev->name, rp->status);
610
611 if (rp->status)
Johan Hedbergd5859e22011-01-25 01:19:58 +0200612 goto done;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200613
614 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
Johan Hedbergd5859e22011-01-25 01:19:58 +0200615
616 if (test_bit(HCI_INIT, &hdev->flags) && (hdev->commands[5] & 0x10))
617 hci_setup_link_policy(hdev);
618
619done:
620 hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200621}
622
623static void hci_cc_read_local_features(struct hci_dev *hdev, struct sk_buff *skb)
624{
625 struct hci_rp_read_local_features *rp = (void *) skb->data;
626
627 BT_DBG("%s status 0x%x", hdev->name, rp->status);
628
629 if (rp->status)
630 return;
631
632 memcpy(hdev->features, rp->features, 8);
633
Brian Gixa68668b2011-08-11 15:49:36 -0700634 if (hdev->dev_type == HCI_BREDR && test_bit(HCI_INIT, &hdev->flags)) {
635 if (hdev->features[6] & LMP_SIMPLE_PAIR) {
636 u8 mode = 0x01;
637 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE,
638 sizeof(mode), &mode);
639 }
640
641 if (hdev->features[3] & LMP_RSSI_INQ)
642 hci_setup_inquiry_mode(hdev);
643
644 if (hdev->features[7] & LMP_INQ_TX_PWR)
645 hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER,
646 0, NULL);
647
648 hci_setup_event_mask(hdev);
649 }
650
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200651 /* Adjust default settings according to features
652 * supported by device. */
653
654 if (hdev->features[0] & LMP_3SLOT)
655 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
656
657 if (hdev->features[0] & LMP_5SLOT)
658 hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
659
660 if (hdev->features[1] & LMP_HV2) {
661 hdev->pkt_type |= (HCI_HV2);
662 hdev->esco_type |= (ESCO_HV2);
663 }
664
665 if (hdev->features[1] & LMP_HV3) {
666 hdev->pkt_type |= (HCI_HV3);
667 hdev->esco_type |= (ESCO_HV3);
668 }
669
670 if (hdev->features[3] & LMP_ESCO)
671 hdev->esco_type |= (ESCO_EV3);
672
673 if (hdev->features[4] & LMP_EV4)
674 hdev->esco_type |= (ESCO_EV4);
675
676 if (hdev->features[4] & LMP_EV5)
677 hdev->esco_type |= (ESCO_EV5);
678
Marcel Holtmannefc76882009-02-06 09:13:37 +0100679 if (hdev->features[5] & LMP_EDR_ESCO_2M)
680 hdev->esco_type |= (ESCO_2EV3);
681
682 if (hdev->features[5] & LMP_EDR_ESCO_3M)
683 hdev->esco_type |= (ESCO_3EV3);
684
685 if (hdev->features[5] & LMP_EDR_3S_ESCO)
686 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
687
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200688 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name,
689 hdev->features[0], hdev->features[1],
690 hdev->features[2], hdev->features[3],
691 hdev->features[4], hdev->features[5],
692 hdev->features[6], hdev->features[7]);
693}
694
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700695static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
696 struct sk_buff *skb)
Andre Guedesd5fa5132011-06-30 19:20:52 -0300697{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700698 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
Andre Guedesd5fa5132011-06-30 19:20:52 -0300699
700 BT_DBG("%s status 0x%x", hdev->name, rp->status);
701
702 if (rp->status)
703 return;
704
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700705 hdev->flow_ctl_mode = rp->mode;
Andre Guedesd5fa5132011-06-30 19:20:52 -0300706}
707
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200708static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
709{
710 struct hci_rp_read_buffer_size *rp = (void *) skb->data;
711
712 BT_DBG("%s status 0x%x", hdev->name, rp->status);
713
714 if (rp->status)
715 return;
716
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700717 if (hdev->flow_ctl_mode == HCI_PACKET_BASED_FLOW_CTL_MODE) {
718 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
719 hdev->sco_mtu = rp->sco_mtu;
720 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
721 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
722 hdev->acl_cnt = hdev->acl_pkts;
723 hdev->sco_cnt = hdev->sco_pkts;
724 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200725
726 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
727 hdev->sco_mtu = 64;
728 hdev->sco_pkts = 8;
729 }
730
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200731
732 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name,
733 hdev->acl_mtu, hdev->acl_pkts,
734 hdev->sco_mtu, hdev->sco_pkts);
735}
736
737static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
738{
739 struct hci_rp_read_bd_addr *rp = (void *) skb->data;
740
741 BT_DBG("%s status 0x%x", hdev->name, rp->status);
742
743 if (!rp->status)
744 bacpy(&hdev->bdaddr, &rp->bdaddr);
745
Johan Hedberg23bb5762010-12-21 23:01:27 +0200746 hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status);
747}
748
749static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb)
750{
751 __u8 status = *((__u8 *) skb->data);
752
753 BT_DBG("%s status 0x%x", hdev->name, status);
754
755 hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200756}
757
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700758static void hci_cc_read_data_block_size(struct hci_dev *hdev,
759 struct sk_buff *skb)
760{
761 struct hci_rp_read_data_block_size *rp = (void *) skb->data;
762
763 BT_DBG("%s status 0x%x", hdev->name, rp->status);
764
765 if (rp->status)
766 return;
767
768 if (hdev->flow_ctl_mode == HCI_BLOCK_BASED_FLOW_CTL_MODE) {
769 hdev->acl_mtu = __le16_to_cpu(rp->max_acl_len);
770 hdev->sco_mtu = 0;
771 hdev->data_block_len = __le16_to_cpu(rp->data_block_len);
772 /* acl_pkts indicates the number of blocks */
773 hdev->acl_pkts = __le16_to_cpu(rp->num_blocks);
774 hdev->sco_pkts = 0;
775 hdev->acl_cnt = hdev->acl_pkts;
776 hdev->sco_cnt = 0;
777 }
778
779 BT_DBG("%s acl mtu %d:%d, data block len %d", hdev->name,
780 hdev->acl_mtu, hdev->acl_cnt, hdev->data_block_len);
781}
782
783static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
784 struct sk_buff *skb)
785{
786 struct hci_rp_read_local_amp_info *rp = (void *) skb->data;
787
788 BT_DBG("%s status 0x%x", hdev->name, rp->status);
789
790 if (rp->status)
791 return;
792
793 hdev->amp_status = rp->amp_status;
794 hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
795 hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
796 hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
797 hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
798 hdev->amp_type = rp->amp_type;
799 hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
800 hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
801 hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
802 hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
803
804 hci_req_complete(hdev, HCI_OP_READ_LOCAL_AMP_INFO, rp->status);
805}
806
Johan Hedbergb0916ea2011-01-10 13:44:55 +0200807static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
808 struct sk_buff *skb)
809{
810 __u8 status = *((__u8 *) skb->data);
811
812 BT_DBG("%s status 0x%x", hdev->name, status);
813
814 hci_req_complete(hdev, HCI_OP_DELETE_STORED_LINK_KEY, status);
815}
816
Johan Hedbergd5859e22011-01-25 01:19:58 +0200817static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb)
818{
819 __u8 status = *((__u8 *) skb->data);
820
821 BT_DBG("%s status 0x%x", hdev->name, status);
822
823 hci_req_complete(hdev, HCI_OP_SET_EVENT_MASK, status);
824}
825
826static void hci_cc_write_inquiry_mode(struct hci_dev *hdev,
827 struct sk_buff *skb)
828{
829 __u8 status = *((__u8 *) skb->data);
830
831 BT_DBG("%s status 0x%x", hdev->name, status);
832
833 hci_req_complete(hdev, HCI_OP_WRITE_INQUIRY_MODE, status);
834}
835
836static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
837 struct sk_buff *skb)
838{
839 __u8 status = *((__u8 *) skb->data);
840
841 BT_DBG("%s status 0x%x", hdev->name, status);
842
843 hci_req_complete(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, status);
844}
845
846static void hci_cc_set_event_flt(struct hci_dev *hdev, struct sk_buff *skb)
847{
848 __u8 status = *((__u8 *) skb->data);
849
850 BT_DBG("%s status 0x%x", hdev->name, status);
851
852 hci_req_complete(hdev, HCI_OP_SET_EVENT_FLT, status);
853}
854
Johan Hedberg980e1a52011-01-22 06:10:07 +0200855static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb)
856{
857 struct hci_rp_pin_code_reply *rp = (void *) skb->data;
858 struct hci_cp_pin_code_reply *cp;
859 struct hci_conn *conn;
860
861 BT_DBG("%s status 0x%x", hdev->name, rp->status);
862
863 if (test_bit(HCI_MGMT, &hdev->flags))
864 mgmt_pin_code_reply_complete(hdev->id, &rp->bdaddr, rp->status);
865
866 if (rp->status != 0)
867 return;
868
869 cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
870 if (!cp)
871 return;
872
873 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
874 if (conn)
875 conn->pin_length = cp->pin_len;
876}
877
878static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
879{
880 struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data;
881
882 BT_DBG("%s status 0x%x", hdev->name, rp->status);
883
884 if (test_bit(HCI_MGMT, &hdev->flags))
885 mgmt_pin_code_neg_reply_complete(hdev->id, &rp->bdaddr,
886 rp->status);
887}
Ville Tervo6ed58ec2011-02-10 22:38:48 -0300888static void hci_cc_le_read_buffer_size(struct hci_dev *hdev,
889 struct sk_buff *skb)
890{
891 struct hci_rp_le_read_buffer_size *rp = (void *) skb->data;
892
893 BT_DBG("%s status 0x%x", hdev->name, rp->status);
894
895 if (rp->status)
896 return;
897
898 hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
899 hdev->le_pkts = rp->le_max_pkt;
900
901 hdev->le_cnt = hdev->le_pkts;
902
903 BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
904
905 hci_req_complete(hdev, HCI_OP_LE_READ_BUFFER_SIZE, rp->status);
906}
Johan Hedberg980e1a52011-01-22 06:10:07 +0200907
Johan Hedberga5c29682011-02-19 12:05:57 -0300908static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
909{
910 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
911
912 BT_DBG("%s status 0x%x", hdev->name, rp->status);
913
914 if (test_bit(HCI_MGMT, &hdev->flags))
915 mgmt_user_confirm_reply_complete(hdev->id, &rp->bdaddr,
916 rp->status);
917}
918
919static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
920 struct sk_buff *skb)
921{
922 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
923
924 BT_DBG("%s status 0x%x", hdev->name, rp->status);
925
926 if (test_bit(HCI_MGMT, &hdev->flags))
927 mgmt_user_confirm_neg_reply_complete(hdev->id, &rp->bdaddr,
928 rp->status);
929}
930
Szymon Jancc35938b2011-03-22 13:12:21 +0100931static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
932 struct sk_buff *skb)
933{
934 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
935
936 BT_DBG("%s status 0x%x", hdev->name, rp->status);
937
938 mgmt_read_local_oob_data_reply_complete(hdev->id, rp->hash,
939 rp->randomizer, rp->status);
940}
941
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -0300942static void hci_cc_le_ltk_reply(struct hci_dev *hdev, struct sk_buff *skb)
943{
944 struct hci_rp_le_ltk_reply *rp = (void *) skb->data;
945
946 BT_DBG("%s status 0x%x", hdev->name, rp->status);
947
948 if (rp->status)
949 return;
950
951 hci_req_complete(hdev, HCI_OP_LE_LTK_REPLY, rp->status);
952}
953
954static void hci_cc_le_ltk_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
955{
956 struct hci_rp_le_ltk_neg_reply *rp = (void *) skb->data;
957
958 BT_DBG("%s status 0x%x", hdev->name, rp->status);
959
960 if (rp->status)
961 return;
962
963 hci_req_complete(hdev, HCI_OP_LE_LTK_NEG_REPLY, rp->status);
964}
965
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700966static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
967 struct sk_buff *skb)
Andre Guedese326af42011-06-30 19:20:53 -0300968{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700969 void *sent;
970 __u8 param_scan_enable;
Andre Guedese326af42011-06-30 19:20:53 -0300971 __u8 status = *((__u8 *) skb->data);
972
Andre Guedese326af42011-06-30 19:20:53 -0300973 if (status)
974 return;
975
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700976 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
977 if (!sent)
978 return;
979
980 param_scan_enable = *((__u8 *) sent);
981 if (param_scan_enable == 0x01) {
982 del_timer(&hdev->adv_timer);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700983 } else if (param_scan_enable == 0x00) {
984 mod_timer(&hdev->adv_timer, jiffies + ADV_CLEAR_TIMEOUT);
985 }
Andre Guedese326af42011-06-30 19:20:53 -0300986}
987
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200988static inline void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
989{
990 BT_DBG("%s status 0x%x", hdev->name, status);
991
992 if (status) {
Johan Hedberg23bb5762010-12-21 23:01:27 +0200993 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
Johan Hedberg314b2382011-04-27 10:29:57 -0400994
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700995 hci_conn_check_pending(hdev);
Brian Gixa68668b2011-08-11 15:49:36 -0700996 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700997 set_bit(HCI_INQUIRY, &hdev->flags);
Brian Gixa68668b2011-08-11 15:49:36 -0700998 if (test_bit(HCI_MGMT, &hdev->flags))
999 mgmt_inquiry_started(hdev->id);
1000 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001001}
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003static inline void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
1004{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001005 struct hci_cp_create_conn *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001008 BT_DBG("%s status 0x%x", hdev->name, status);
1009
1010 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 if (!cp)
1012 return;
1013
1014 hci_dev_lock(hdev);
1015
1016 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1017
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001018 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->bdaddr), conn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
1020 if (status) {
1021 if (conn && conn->state == BT_CONNECT) {
Marcel Holtmann4c67bc72006-10-15 17:30:56 +02001022 if (status != 0x0c || conn->attempt > 2) {
1023 conn->state = BT_CLOSED;
1024 hci_proto_connect_cfm(conn, status);
1025 hci_conn_del(conn);
1026 } else
1027 conn->state = BT_CONNECT2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
1029 } else {
1030 if (!conn) {
Nick Pellybbcda3b2010-02-11 11:54:28 -08001031 conn = hci_conn_add(hdev, ACL_LINK, 0, &cp->bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 if (conn) {
1033 conn->out = 1;
1034 conn->link_mode |= HCI_LM_MASTER;
1035 } else
Gustavo F. Padovan893ef972010-07-18 15:13:37 -03001036 BT_ERR("No memory for new connection");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038 }
1039
1040 hci_dev_unlock(hdev);
1041}
1042
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001043static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001045 struct hci_cp_add_sco *cp;
1046 struct hci_conn *acl, *sco;
1047 __u16 handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001049 BT_DBG("%s status 0x%x", hdev->name, status);
1050
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001051 if (!status)
1052 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001054 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
1055 if (!cp)
1056 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001058 handle = __le16_to_cpu(cp->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001060 BT_DBG("%s handle %d", hdev->name, handle);
Marcel Holtmann6bd57412006-11-18 22:14:22 +01001061
1062 hci_dev_lock(hdev);
1063
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001064 acl = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001065 if (acl) {
1066 sco = acl->link;
1067 if (sco) {
1068 sco->state = BT_CLOSED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001069
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001070 hci_proto_connect_cfm(sco, status);
1071 hci_conn_del(sco);
1072 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001073 }
Marcel Holtmann6bd57412006-11-18 22:14:22 +01001074
1075 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
Marcel Holtmannf8558552008-07-14 20:13:49 +02001078static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
1079{
1080 struct hci_cp_auth_requested *cp;
1081 struct hci_conn *conn;
1082
1083 BT_DBG("%s status 0x%x", hdev->name, status);
1084
Marcel Holtmannf8558552008-07-14 20:13:49 +02001085 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
1086 if (!cp)
1087 return;
1088
1089 hci_dev_lock(hdev);
1090
1091 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1092 if (conn) {
Srinivas Krovvidi9ff51452011-09-27 19:25:02 +05301093 if (status && conn->state == BT_CONFIG) {
Marcel Holtmannf8558552008-07-14 20:13:49 +02001094 hci_proto_connect_cfm(conn, status);
1095 hci_conn_put(conn);
1096 }
Srinivas Krovvidi9ff51452011-09-27 19:25:02 +05301097 conn->auth_initiator = 1;
Marcel Holtmannf8558552008-07-14 20:13:49 +02001098 }
1099
1100 hci_dev_unlock(hdev);
1101}
1102
1103static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
1104{
1105 struct hci_cp_set_conn_encrypt *cp;
1106 struct hci_conn *conn;
1107
1108 BT_DBG("%s status 0x%x", hdev->name, status);
1109
1110 if (!status)
1111 return;
1112
1113 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
1114 if (!cp)
1115 return;
1116
1117 hci_dev_lock(hdev);
1118
1119 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1120 if (conn) {
1121 if (conn->state == BT_CONFIG) {
1122 hci_proto_connect_cfm(conn, status);
1123 hci_conn_put(conn);
1124 }
1125 }
1126
1127 hci_dev_unlock(hdev);
1128}
1129
Johan Hedberg127178d2010-11-18 22:22:29 +02001130static int hci_outgoing_auth_needed(struct hci_dev *hdev,
Szymon Janc138d22e2011-02-17 16:44:23 +01001131 struct hci_conn *conn)
Johan Hedberg392599b2010-11-18 22:22:28 +02001132{
Johan Hedberg392599b2010-11-18 22:22:28 +02001133 if (conn->state != BT_CONFIG || !conn->out)
1134 return 0;
1135
Johan Hedberg765c2a92011-01-19 12:06:52 +05301136 if (conn->pending_sec_level == BT_SECURITY_SDP)
Johan Hedberg392599b2010-11-18 22:22:28 +02001137 return 0;
1138
1139 /* Only request authentication for SSP connections or non-SSP
Prabhakaran Mc6001a712011-09-06 11:56:25 +05301140 * devices with sec_level >= BT_SECURITY_MEDIUM*/
1141 BT_DBG("Pending sec level is %d", conn->pending_sec_level);
Johan Hedberg392599b2010-11-18 22:22:28 +02001142 if (!(hdev->ssp_mode > 0 && conn->ssp_mode > 0) &&
Prabhakaran Mc6001a712011-09-06 11:56:25 +05301143 conn->pending_sec_level < BT_SECURITY_MEDIUM)
Johan Hedberg392599b2010-11-18 22:22:28 +02001144 return 0;
1145
Johan Hedberg392599b2010-11-18 22:22:28 +02001146 return 1;
1147}
1148
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001149static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
1150{
Johan Hedberg127178d2010-11-18 22:22:29 +02001151 struct hci_cp_remote_name_req *cp;
1152 struct hci_conn *conn;
1153
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001154 BT_DBG("%s status 0x%x", hdev->name, status);
Johan Hedberg127178d2010-11-18 22:22:29 +02001155
1156 /* If successful wait for the name req complete event before
1157 * checking for the need to do authentication */
1158 if (!status)
1159 return;
1160
1161 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
1162 if (!cp)
1163 return;
1164
1165 hci_dev_lock(hdev);
1166
1167 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001168 if (conn && hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02001169 struct hci_cp_auth_requested cp;
1170 cp.handle = __cpu_to_le16(conn->handle);
1171 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1172 }
1173
1174 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001175}
1176
Marcel Holtmann769be972008-07-14 20:13:49 +02001177static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
1178{
1179 struct hci_cp_read_remote_features *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_READ_REMOTE_FEATURES);
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) {
Marcel Holtmann769be972008-07-14 20:13:49 +02001196 hci_proto_connect_cfm(conn, status);
1197 hci_conn_put(conn);
1198 }
1199 }
1200
1201 hci_dev_unlock(hdev);
1202}
1203
1204static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
1205{
1206 struct hci_cp_read_remote_ext_features *cp;
1207 struct hci_conn *conn;
1208
1209 BT_DBG("%s status 0x%x", hdev->name, status);
1210
1211 if (!status)
1212 return;
1213
1214 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
1215 if (!cp)
1216 return;
1217
1218 hci_dev_lock(hdev);
1219
1220 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1221 if (conn) {
1222 if (conn->state == BT_CONFIG) {
Marcel Holtmann769be972008-07-14 20:13:49 +02001223 hci_proto_connect_cfm(conn, status);
1224 hci_conn_put(conn);
1225 }
1226 }
1227
1228 hci_dev_unlock(hdev);
1229}
1230
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001231static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
1232{
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001233 struct hci_cp_setup_sync_conn *cp;
1234 struct hci_conn *acl, *sco;
1235 __u16 handle;
1236
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001237 BT_DBG("%s status 0x%x", hdev->name, status);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001238
1239 if (!status)
1240 return;
1241
1242 cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
1243 if (!cp)
1244 return;
1245
1246 handle = __le16_to_cpu(cp->handle);
1247
1248 BT_DBG("%s handle %d", hdev->name, handle);
1249
1250 hci_dev_lock(hdev);
1251
1252 acl = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001253 if (acl) {
1254 sco = acl->link;
1255 if (sco) {
1256 sco->state = BT_CLOSED;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001257
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001258 hci_proto_connect_cfm(sco, status);
1259 hci_conn_del(sco);
1260 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001261 }
1262
1263 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001264}
1265
1266static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
1267{
1268 struct hci_cp_sniff_mode *cp;
1269 struct hci_conn *conn;
1270
1271 BT_DBG("%s status 0x%x", hdev->name, status);
1272
1273 if (!status)
1274 return;
1275
1276 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
1277 if (!cp)
1278 return;
1279
1280 hci_dev_lock(hdev);
1281
1282 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001283 if (conn) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001284 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
1285
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001286 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
1287 hci_sco_setup(conn, status);
1288 }
1289
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001290 hci_dev_unlock(hdev);
1291}
1292
1293static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
1294{
1295 struct hci_cp_exit_sniff_mode *cp;
1296 struct hci_conn *conn;
1297
1298 BT_DBG("%s status 0x%x", hdev->name, status);
1299
1300 if (!status)
1301 return;
1302
1303 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
1304 if (!cp)
1305 return;
1306
1307 hci_dev_lock(hdev);
1308
1309 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001310 if (conn) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001311 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend);
1312
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001313 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
1314 hci_sco_setup(conn, status);
1315 }
1316
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001317 hci_dev_unlock(hdev);
1318}
1319
Ville Tervofcd89c02011-02-10 22:38:47 -03001320static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
1321{
1322 struct hci_cp_le_create_conn *cp;
1323 struct hci_conn *conn;
1324
1325 BT_DBG("%s status 0x%x", hdev->name, status);
1326
1327 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_CREATE_CONN);
1328 if (!cp)
1329 return;
1330
1331 hci_dev_lock(hdev);
1332
1333 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &cp->peer_addr);
1334
1335 BT_DBG("%s bdaddr %s conn %p", hdev->name, batostr(&cp->peer_addr),
1336 conn);
1337
1338 if (status) {
1339 if (conn && conn->state == BT_CONNECT) {
1340 conn->state = BT_CLOSED;
1341 hci_proto_connect_cfm(conn, status);
1342 hci_conn_del(conn);
1343 }
1344 } else {
1345 if (!conn) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001346 conn = hci_le_conn_add(hdev, &cp->peer_addr,
1347 cp->peer_addr_type);
1348 if (conn)
Ville Tervofcd89c02011-02-10 22:38:47 -03001349 conn->out = 1;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001350 else
Ville Tervofcd89c02011-02-10 22:38:47 -03001351 BT_ERR("No memory for new connection");
1352 }
Brian Gix114f3a62011-09-27 14:02:20 -07001353
1354 if (conn)
1355 mod_timer(&conn->disc_timer,
1356 jiffies + msecs_to_jiffies(5000));
Ville Tervofcd89c02011-02-10 22:38:47 -03001357 }
1358
1359 hci_dev_unlock(hdev);
1360}
1361
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001362static void hci_cs_accept_logical_link(struct hci_dev *hdev, __u8 status)
1363{
1364 struct hci_cp_create_logical_link *ap;
1365 struct hci_chan *chan;
1366
1367 BT_DBG("%s status 0x%x", hdev->name, status);
1368
1369 ap = hci_sent_cmd_data(hdev, HCI_OP_ACCEPT_LOGICAL_LINK);
1370 if (!ap)
1371 return;
1372
1373 hci_dev_lock(hdev);
1374
1375 chan = hci_chan_list_lookup_id(hdev, ap->phy_handle);
1376
1377 BT_DBG("%s chan %p", hdev->name, chan);
1378
1379 if (status) {
1380 if (chan && chan->state == BT_CONNECT) {
1381 chan->state = BT_CLOSED;
1382 hci_proto_create_cfm(chan, status);
1383 hci_chan_del(chan);
1384 }
1385 } else if (chan)
1386 chan->state = BT_CONNECT2;
1387
1388 hci_dev_unlock(hdev);
1389}
1390
1391static void hci_cs_create_logical_link(struct hci_dev *hdev, __u8 status)
1392{
1393 struct hci_cp_create_logical_link *cp;
1394 struct hci_chan *chan;
1395
1396 BT_DBG("%s status 0x%x", hdev->name, status);
1397
1398 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_LOGICAL_LINK);
1399 if (!cp)
1400 return;
1401
1402 hci_dev_lock(hdev);
1403
1404 chan = hci_chan_list_lookup_id(hdev, cp->phy_handle);
1405
1406 BT_DBG("%s chan %p", hdev->name, chan);
1407
1408 if (status) {
1409 if (chan && chan->state == BT_CONNECT) {
1410 chan->state = BT_CLOSED;
1411 hci_proto_create_cfm(chan, status);
1412 hci_chan_del(chan);
1413 }
1414 } else if (chan)
1415 chan->state = BT_CONNECT2;
1416
1417 hci_dev_unlock(hdev);
1418}
1419
1420static void hci_cs_flow_spec_modify(struct hci_dev *hdev, __u8 status)
1421{
1422 struct hci_cp_flow_spec_modify *cp;
1423 struct hci_chan *chan;
1424
1425 BT_DBG("%s status 0x%x", hdev->name, status);
1426
1427 cp = hci_sent_cmd_data(hdev, HCI_OP_FLOW_SPEC_MODIFY);
1428 if (!cp)
1429 return;
1430
1431 hci_dev_lock(hdev);
1432
1433 chan = hci_chan_list_lookup_handle(hdev, cp->log_handle);
1434 if (chan) {
1435 if (status)
1436 hci_proto_modify_cfm(chan, status);
1437 else {
1438 chan->tx_fs = cp->tx_fs;
1439 chan->rx_fs = cp->rx_fs;
1440 }
1441 }
1442
1443 hci_dev_unlock(hdev);
1444}
1445
1446static void hci_cs_disconn_logical_link(struct hci_dev *hdev, __u8 status)
1447{
1448 struct hci_cp_disconn_logical_link *cp;
1449 struct hci_chan *chan;
1450
1451 if (!status)
1452 return;
1453
1454 BT_DBG("%s status 0x%x", hdev->name, status);
1455
1456 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONN_LOGICAL_LINK);
1457 if (!cp)
1458 return;
1459
1460 hci_dev_lock(hdev);
1461
1462 chan = hci_chan_list_lookup_handle(hdev, cp->log_handle);
1463 if (chan)
1464 hci_chan_del(chan);
1465
1466 hci_dev_unlock(hdev);
1467}
1468
1469static void hci_cs_disconn_physical_link(struct hci_dev *hdev, __u8 status)
1470{
1471 struct hci_cp_disconn_phys_link *cp;
1472 struct hci_conn *conn;
1473
1474 if (!status)
1475 return;
1476
1477 BT_DBG("%s status 0x%x", hdev->name, status);
1478
1479 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONN_PHYS_LINK);
1480 if (!cp)
1481 return;
1482
1483 hci_dev_lock(hdev);
1484
1485 conn = hci_conn_hash_lookup_handle(hdev, cp->phy_handle);
1486 if (conn) {
1487 conn->state = BT_CLOSED;
1488 hci_conn_del(conn);
1489 }
1490
1491 hci_dev_unlock(hdev);
1492}
1493
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03001494static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
1495{
1496 BT_DBG("%s status 0x%x", hdev->name, status);
1497}
1498
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001499static inline void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1500{
1501 __u8 status = *((__u8 *) skb->data);
1502
1503 BT_DBG("%s status %d", hdev->name, status);
1504
Brian Gixa68668b2011-08-11 15:49:36 -07001505 if (!lmp_le_capable(hdev))
1506 clear_bit(HCI_INQUIRY, &hdev->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001507
Johan Hedberg23bb5762010-12-21 23:01:27 +02001508 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001509
Brian Gixa68668b2011-08-11 15:49:36 -07001510 if (test_bit(HCI_MGMT, &hdev->flags))
1511 mgmt_inquiry_complete_evt(hdev->id, status);
1512
1513 if (!lmp_le_capable(hdev))
1514 hci_conn_check_pending(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001515}
1516
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517static inline void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
1518{
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001519 struct inquiry_data data;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001520 struct inquiry_info *info = (void *) (skb->data + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 int num_rsp = *((__u8 *) skb->data);
1522
1523 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
1524
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001525 if (!num_rsp)
1526 return;
1527
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 hci_dev_lock(hdev);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001529
Johan Hedberge17acd42011-03-30 23:57:16 +03001530 for (; num_rsp; num_rsp--, info++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 bacpy(&data.bdaddr, &info->bdaddr);
1532 data.pscan_rep_mode = info->pscan_rep_mode;
1533 data.pscan_period_mode = info->pscan_period_mode;
1534 data.pscan_mode = info->pscan_mode;
1535 memcpy(data.dev_class, info->dev_class, 3);
1536 data.clock_offset = info->clock_offset;
1537 data.rssi = 0x00;
Marcel Holtmann41a96212008-07-14 20:13:48 +02001538 data.ssp_mode = 0x00;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07001540 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
1541 info->dev_class, 0, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001543
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 hci_dev_unlock(hdev);
1545}
1546
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001547static inline void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001549 struct hci_ev_conn_complete *ev = (void *) skb->data;
1550 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001552 BT_DBG("%s", hdev->name);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001553
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 hci_dev_lock(hdev);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001555
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001556 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
Marcel Holtmann94992372009-04-19 19:30:03 +02001557 if (!conn) {
1558 if (ev->link_type != SCO_LINK)
1559 goto unlock;
1560
1561 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
1562 if (!conn)
1563 goto unlock;
1564
1565 conn->type = SCO_LINK;
1566 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001567
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001568 if (!ev->status) {
1569 conn->handle = __le16_to_cpu(ev->handle);
Marcel Holtmann769be972008-07-14 20:13:49 +02001570
1571 if (conn->type == ACL_LINK) {
1572 conn->state = BT_CONFIG;
1573 hci_conn_hold(conn);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001574 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07001575 mgmt_connected(hdev->id, &ev->bdaddr, 0);
Brian Gixa68668b2011-08-11 15:49:36 -07001576 } else if (conn->type == LE_LINK) {
1577 conn->state = BT_CONNECTED;
1578 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07001579 mgmt_connected(hdev->id, &ev->bdaddr, 1);
Marcel Holtmann769be972008-07-14 20:13:49 +02001580 } else
1581 conn->state = BT_CONNECTED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001582
Marcel Holtmann9eba32b2009-08-22 14:19:26 -07001583 hci_conn_hold_device(conn);
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02001584 hci_conn_add_sysfs(conn);
1585
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001586 if (test_bit(HCI_AUTH, &hdev->flags))
1587 conn->link_mode |= HCI_LM_AUTH;
1588
1589 if (test_bit(HCI_ENCRYPT, &hdev->flags))
1590 conn->link_mode |= HCI_LM_ENCRYPT;
1591
1592 /* Get remote features */
1593 if (conn->type == ACL_LINK) {
1594 struct hci_cp_read_remote_features cp;
1595 cp.handle = ev->handle;
Marcel Holtmann769be972008-07-14 20:13:49 +02001596 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES,
1597 sizeof(cp), &cp);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001598 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001599
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001600 /* Set packet type for incoming connection */
Marcel Holtmanna8746412008-07-14 20:13:46 +02001601 if (!conn->out && hdev->hci_ver < 3) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001602 struct hci_cp_change_conn_ptype cp;
1603 cp.handle = ev->handle;
Marcel Holtmanna8746412008-07-14 20:13:46 +02001604 cp.pkt_type = cpu_to_le16(conn->pkt_type);
1605 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE,
1606 sizeof(cp), &cp);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001607 }
Johan Hedberg17d5c042011-01-22 06:09:08 +02001608 } else {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001609 conn->state = BT_CLOSED;
Brian Gixa68668b2011-08-11 15:49:36 -07001610 if (conn->type == ACL_LINK || conn->type == LE_LINK)
Johan Hedberg17d5c042011-01-22 06:09:08 +02001611 mgmt_connect_failed(hdev->id, &ev->bdaddr, ev->status);
1612 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001613
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001614 if (conn->type == ACL_LINK)
1615 hci_sco_setup(conn, ev->status);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001616
Marcel Holtmann769be972008-07-14 20:13:49 +02001617 if (ev->status) {
1618 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001619 hci_conn_del(conn);
Marcel Holtmannc89b6e62009-01-15 21:57:03 +01001620 } else if (ev->link_type != ACL_LINK)
1621 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001622
1623unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001625
1626 hci_conn_check_pending(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627}
1628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629static inline void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
1630{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001631 struct hci_ev_conn_request *ev = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 int mask = hdev->link_mode;
1633
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001634 BT_DBG("%s bdaddr %s type 0x%x", hdev->name,
1635 batostr(&ev->bdaddr), ev->link_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
1637 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
1638
Szymon Janc138d22e2011-02-17 16:44:23 +01001639 if ((mask & HCI_LM_ACCEPT) &&
1640 !hci_blacklist_lookup(hdev, &ev->bdaddr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 /* Connection accepted */
Marcel Holtmannc7bdd502008-07-14 20:13:47 +02001642 struct inquiry_entry *ie;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
1645 hci_dev_lock(hdev);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001646
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02001647 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
1648 if (ie)
Marcel Holtmannc7bdd502008-07-14 20:13:47 +02001649 memcpy(ie->data.dev_class, ev->dev_class, 3);
1650
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
1652 if (!conn) {
Nick Pellybbcda3b2010-02-11 11:54:28 -08001653 /* pkt_type not yet used for incoming connections */
1654 conn = hci_conn_add(hdev, ev->link_type, 0, &ev->bdaddr);
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02001655 if (!conn) {
Gustavo F. Padovan893ef972010-07-18 15:13:37 -03001656 BT_ERR("No memory for new connection");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 hci_dev_unlock(hdev);
1658 return;
1659 }
1660 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001661
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 memcpy(conn->dev_class, ev->dev_class, 3);
1663 conn->state = BT_CONNECT;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001664
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 hci_dev_unlock(hdev);
1666
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001667 if (ev->link_type == ACL_LINK || !lmp_esco_capable(hdev)) {
1668 struct hci_cp_accept_conn_req cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001670 bacpy(&cp.bdaddr, &ev->bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001672 if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
1673 cp.role = 0x00; /* Become master */
1674 else
1675 cp.role = 0x01; /* Remain slave */
1676
1677 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ,
1678 sizeof(cp), &cp);
1679 } else {
1680 struct hci_cp_accept_sync_conn_req cp;
1681
1682 bacpy(&cp.bdaddr, &ev->bdaddr);
Marcel Holtmanna8746412008-07-14 20:13:46 +02001683 cp.pkt_type = cpu_to_le16(conn->pkt_type);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001684
1685 cp.tx_bandwidth = cpu_to_le32(0x00001f40);
1686 cp.rx_bandwidth = cpu_to_le32(0x00001f40);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001687 cp.max_latency = cpu_to_le16(0x000A);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001688 cp.content_format = cpu_to_le16(hdev->voice_setting);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001689 cp.retrans_effort = 0x01;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001690
1691 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
1692 sizeof(cp), &cp);
1693 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 } else {
1695 /* Connection rejected */
1696 struct hci_cp_reject_conn_req cp;
1697
1698 bacpy(&cp.bdaddr, &ev->bdaddr);
1699 cp.reason = 0x0f;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001700 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 }
1702}
1703
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704static inline void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1705{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001706 struct hci_ev_disconn_complete *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02001707 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
1709 BT_DBG("%s status %d", hdev->name, ev->status);
1710
Johan Hedberg8962ee72011-01-20 12:40:27 +02001711 if (ev->status) {
1712 mgmt_disconnect_failed(hdev->id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 return;
Johan Hedberg8962ee72011-01-20 12:40:27 +02001714 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
1716 hci_dev_lock(hdev);
1717
Marcel Holtmann04837f62006-07-03 10:02:33 +02001718 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergf7520542011-01-20 12:34:39 +02001719 if (!conn)
1720 goto unlock;
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02001721
Johan Hedbergf7520542011-01-20 12:34:39 +02001722 conn->state = BT_CLOSED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723
Brian Gixa68668b2011-08-11 15:49:36 -07001724 if (conn->type == ACL_LINK || conn->type == LE_LINK)
Johan Hedbergf7520542011-01-20 12:34:39 +02001725 mgmt_disconnected(hdev->id, &conn->dst);
1726
Brian Gixe9ceb522011-09-22 10:46:35 -07001727 if (conn->type == LE_LINK)
1728 del_timer(&conn->smp_timer);
1729
Johan Hedbergf7520542011-01-20 12:34:39 +02001730 hci_proto_disconn_cfm(conn, ev->reason);
1731 hci_conn_del(conn);
1732
1733unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 hci_dev_unlock(hdev);
1735}
1736
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001737static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1738{
1739 struct hci_ev_auth_complete *ev = (void *) skb->data;
1740 struct hci_conn *conn;
1741
1742 BT_DBG("%s status %d", hdev->name, ev->status);
1743
1744 hci_dev_lock(hdev);
1745
1746 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001747 if (conn) {
1748 if (ev->status == 0x06 && hdev->ssp_mode > 0 &&
1749 conn->ssp_mode > 0) {
1750 struct hci_cp_auth_requested cp;
Prabhakaran Mcb04401d2011-09-20 17:37:55 +05301751 hci_remove_link_key(hdev, &conn->dst);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001752 cp.handle = cpu_to_le16(conn->handle);
1753 hci_send_cmd(conn->hdev, HCI_OP_AUTH_REQUESTED,
1754 sizeof(cp), &cp);
1755 hci_dev_unlock(hdev);
1756 BT_INFO("Pin or key missing");
1757 return;
1758 }
Waldemar Rymarkiewicz54444292011-05-31 15:49:26 +02001759
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001760 if (!ev->status) {
Waldemar Rymarkiewicz54444292011-05-31 15:49:26 +02001761 conn->link_mode |= HCI_LM_AUTH;
1762 conn->sec_level = conn->pending_sec_level;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001763 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001764 mgmt_auth_failed(hdev->id, &conn->dst, ev->status);
1765 conn->sec_level = BT_SECURITY_LOW;
1766 }
1767
1768 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
1769
1770 if (conn->state == BT_CONFIG) {
1771 if (!ev->status && hdev->ssp_mode > 0 &&
1772 conn->ssp_mode > 0) {
1773 struct hci_cp_set_conn_encrypt cp;
1774 cp.handle = ev->handle;
1775 cp.encrypt = 0x01;
1776 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT,
1777 sizeof(cp), &cp);
1778 } else {
1779 conn->state = BT_CONNECTED;
1780 hci_proto_connect_cfm(conn, ev->status);
1781 hci_conn_put(conn);
1782 }
1783 } else {
1784 hci_auth_cfm(conn, ev->status);
1785
1786 hci_conn_hold(conn);
1787 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02001788 hci_conn_put(conn);
1789 }
1790
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001791 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend)) {
1792 if (!ev->status) {
1793 struct hci_cp_set_conn_encrypt cp;
1794 cp.handle = ev->handle;
1795 cp.encrypt = 0x01;
1796 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT,
1797 sizeof(cp), &cp);
1798 } else {
1799 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
1800 hci_encrypt_cfm(conn, ev->status, 0x00);
1801 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001802 }
1803 }
1804
1805 hci_dev_unlock(hdev);
1806}
1807
1808static inline void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
1809{
Johan Hedberg127178d2010-11-18 22:22:29 +02001810 struct hci_ev_remote_name *ev = (void *) skb->data;
1811 struct hci_conn *conn;
1812
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001813 BT_DBG("%s", hdev->name);
1814
1815 hci_conn_check_pending(hdev);
Johan Hedberg127178d2010-11-18 22:22:29 +02001816
1817 hci_dev_lock(hdev);
1818
Brian Gixa68668b2011-08-11 15:49:36 -07001819 if (test_bit(HCI_MGMT, &hdev->flags))
1820 mgmt_remote_name(hdev->id, &ev->bdaddr, ev->status, ev->name);
Johan Hedberga88a9652011-03-30 13:18:12 +03001821
Johan Hedberg127178d2010-11-18 22:22:29 +02001822 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001823 if (conn && hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02001824 struct hci_cp_auth_requested cp;
1825 cp.handle = __cpu_to_le16(conn->handle);
1826 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1827 }
1828
1829 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001830}
1831
1832static inline void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
1833{
1834 struct hci_ev_encrypt_change *ev = (void *) skb->data;
1835 struct hci_conn *conn;
1836
1837 BT_DBG("%s status %d", hdev->name, ev->status);
1838
1839 hci_dev_lock(hdev);
1840
1841 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1842 if (conn) {
1843 if (!ev->status) {
Marcel Holtmannae293192008-07-14 20:13:45 +02001844 if (ev->encrypt) {
1845 /* Encryption implies authentication */
1846 conn->link_mode |= HCI_LM_AUTH;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001847 conn->link_mode |= HCI_LM_ENCRYPT;
Vinicius Costa Gomes64532ec2011-06-09 18:50:53 -03001848 conn->sec_level = conn->pending_sec_level;
Marcel Holtmannae293192008-07-14 20:13:45 +02001849 } else
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001850 conn->link_mode &= ~HCI_LM_ENCRYPT;
1851 }
1852
1853 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->pend);
1854
Marcel Holtmannf8558552008-07-14 20:13:49 +02001855 if (conn->state == BT_CONFIG) {
1856 if (!ev->status)
1857 conn->state = BT_CONNECTED;
1858
1859 hci_proto_connect_cfm(conn, ev->status);
1860 hci_conn_put(conn);
1861 } else
1862 hci_encrypt_cfm(conn, ev->status, ev->encrypt);
Prabhakaran Mc46230fa2011-11-30 18:11:21 +05301863
1864 if (test_bit(HCI_MGMT, &hdev->flags))
1865 mgmt_encrypt_change(hdev->id, &conn->dst, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001866 }
1867
1868 hci_dev_unlock(hdev);
1869}
1870
1871static inline void hci_change_link_key_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1872{
1873 struct hci_ev_change_link_key_complete *ev = (void *) skb->data;
1874 struct hci_conn *conn;
1875
1876 BT_DBG("%s status %d", hdev->name, ev->status);
1877
1878 hci_dev_lock(hdev);
1879
1880 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
1881 if (conn) {
1882 if (!ev->status)
1883 conn->link_mode |= HCI_LM_SECURE;
1884
1885 clear_bit(HCI_CONN_AUTH_PEND, &conn->pend);
1886
1887 hci_key_change_cfm(conn, ev->status);
1888 }
1889
1890 hci_dev_unlock(hdev);
1891}
1892
1893static inline void hci_remote_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
1894{
1895 struct hci_ev_remote_features *ev = (void *) skb->data;
1896 struct hci_conn *conn;
1897
1898 BT_DBG("%s status %d", hdev->name, ev->status);
1899
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001900 hci_dev_lock(hdev);
1901
1902 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergccd556f2010-11-10 17:11:51 +02001903 if (!conn)
1904 goto unlock;
Marcel Holtmann769be972008-07-14 20:13:49 +02001905
Johan Hedbergccd556f2010-11-10 17:11:51 +02001906 if (!ev->status)
1907 memcpy(conn->features, ev->features, 8);
1908
1909 if (conn->state != BT_CONFIG)
1910 goto unlock;
1911
1912 if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) {
1913 struct hci_cp_read_remote_ext_features cp;
1914 cp.handle = ev->handle;
1915 cp.page = 0x01;
1916 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
Marcel Holtmann769be972008-07-14 20:13:49 +02001917 sizeof(cp), &cp);
Johan Hedberg392599b2010-11-18 22:22:28 +02001918 goto unlock;
1919 }
1920
Johan Hedberg127178d2010-11-18 22:22:29 +02001921 if (!ev->status) {
1922 struct hci_cp_remote_name_req cp;
1923 memset(&cp, 0, sizeof(cp));
1924 bacpy(&cp.bdaddr, &conn->dst);
1925 cp.pscan_rep_mode = 0x02;
1926 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
1927 }
Johan Hedberg392599b2010-11-18 22:22:28 +02001928
Johan Hedberg127178d2010-11-18 22:22:29 +02001929 if (!hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02001930 conn->state = BT_CONNECTED;
1931 hci_proto_connect_cfm(conn, ev->status);
1932 hci_conn_put(conn);
Marcel Holtmann769be972008-07-14 20:13:49 +02001933 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001934
Johan Hedbergccd556f2010-11-10 17:11:51 +02001935unlock:
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001936 hci_dev_unlock(hdev);
1937}
1938
1939static inline void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb)
1940{
1941 BT_DBG("%s", hdev->name);
1942}
1943
1944static inline void hci_qos_setup_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1945{
1946 BT_DBG("%s", hdev->name);
1947}
1948
1949static inline void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
1950{
1951 struct hci_ev_cmd_complete *ev = (void *) skb->data;
1952 __u16 opcode;
1953
1954 skb_pull(skb, sizeof(*ev));
1955
1956 opcode = __le16_to_cpu(ev->opcode);
1957
1958 switch (opcode) {
1959 case HCI_OP_INQUIRY_CANCEL:
1960 hci_cc_inquiry_cancel(hdev, skb);
1961 break;
1962
1963 case HCI_OP_EXIT_PERIODIC_INQ:
1964 hci_cc_exit_periodic_inq(hdev, skb);
1965 break;
1966
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001967 case HCI_OP_LINK_KEY_REPLY:
1968 hci_cc_link_key_reply(hdev, skb);
1969 break;
1970
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001971 case HCI_OP_REMOTE_NAME_REQ_CANCEL:
1972 hci_cc_remote_name_req_cancel(hdev, skb);
1973 break;
1974
1975 case HCI_OP_ROLE_DISCOVERY:
1976 hci_cc_role_discovery(hdev, skb);
1977 break;
1978
Marcel Holtmanne4e8e372008-07-14 20:13:47 +02001979 case HCI_OP_READ_LINK_POLICY:
1980 hci_cc_read_link_policy(hdev, skb);
1981 break;
1982
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001983 case HCI_OP_WRITE_LINK_POLICY:
1984 hci_cc_write_link_policy(hdev, skb);
1985 break;
1986
Marcel Holtmanne4e8e372008-07-14 20:13:47 +02001987 case HCI_OP_READ_DEF_LINK_POLICY:
1988 hci_cc_read_def_link_policy(hdev, skb);
1989 break;
1990
1991 case HCI_OP_WRITE_DEF_LINK_POLICY:
1992 hci_cc_write_def_link_policy(hdev, skb);
1993 break;
1994
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001995 case HCI_OP_RESET:
1996 hci_cc_reset(hdev, skb);
1997 break;
1998
1999 case HCI_OP_WRITE_LOCAL_NAME:
2000 hci_cc_write_local_name(hdev, skb);
2001 break;
2002
2003 case HCI_OP_READ_LOCAL_NAME:
2004 hci_cc_read_local_name(hdev, skb);
2005 break;
2006
2007 case HCI_OP_WRITE_AUTH_ENABLE:
2008 hci_cc_write_auth_enable(hdev, skb);
2009 break;
2010
2011 case HCI_OP_WRITE_ENCRYPT_MODE:
2012 hci_cc_write_encrypt_mode(hdev, skb);
2013 break;
2014
2015 case HCI_OP_WRITE_SCAN_ENABLE:
2016 hci_cc_write_scan_enable(hdev, skb);
2017 break;
2018
2019 case HCI_OP_READ_CLASS_OF_DEV:
2020 hci_cc_read_class_of_dev(hdev, skb);
2021 break;
2022
2023 case HCI_OP_WRITE_CLASS_OF_DEV:
2024 hci_cc_write_class_of_dev(hdev, skb);
2025 break;
2026
2027 case HCI_OP_READ_VOICE_SETTING:
2028 hci_cc_read_voice_setting(hdev, skb);
2029 break;
2030
2031 case HCI_OP_WRITE_VOICE_SETTING:
2032 hci_cc_write_voice_setting(hdev, skb);
2033 break;
2034
2035 case HCI_OP_HOST_BUFFER_SIZE:
2036 hci_cc_host_buffer_size(hdev, skb);
2037 break;
2038
Marcel Holtmann333140b2008-07-14 20:13:48 +02002039 case HCI_OP_READ_SSP_MODE:
2040 hci_cc_read_ssp_mode(hdev, skb);
2041 break;
2042
2043 case HCI_OP_WRITE_SSP_MODE:
2044 hci_cc_write_ssp_mode(hdev, skb);
2045 break;
2046
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002047 case HCI_OP_READ_LOCAL_VERSION:
2048 hci_cc_read_local_version(hdev, skb);
2049 break;
2050
2051 case HCI_OP_READ_LOCAL_COMMANDS:
2052 hci_cc_read_local_commands(hdev, skb);
2053 break;
2054
2055 case HCI_OP_READ_LOCAL_FEATURES:
2056 hci_cc_read_local_features(hdev, skb);
2057 break;
2058
2059 case HCI_OP_READ_BUFFER_SIZE:
2060 hci_cc_read_buffer_size(hdev, skb);
2061 break;
2062
2063 case HCI_OP_READ_BD_ADDR:
2064 hci_cc_read_bd_addr(hdev, skb);
2065 break;
2066
Johan Hedberg23bb5762010-12-21 23:01:27 +02002067 case HCI_OP_WRITE_CA_TIMEOUT:
2068 hci_cc_write_ca_timeout(hdev, skb);
2069 break;
2070
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002071 case HCI_OP_READ_FLOW_CONTROL_MODE:
2072 hci_cc_read_flow_control_mode(hdev, skb);
2073 break;
2074
2075 case HCI_OP_READ_DATA_BLOCK_SIZE:
2076 hci_cc_read_data_block_size(hdev, skb);
2077 break;
2078
2079 case HCI_OP_READ_LOCAL_AMP_INFO:
2080 hci_cc_read_local_amp_info(hdev, skb);
2081 break;
2082
2083 case HCI_OP_READ_LOCAL_AMP_ASSOC:
2084 case HCI_OP_WRITE_REMOTE_AMP_ASSOC:
2085 hci_amp_cmd_complete(hdev, opcode, skb);
2086 break;
2087
Johan Hedbergb0916ea2011-01-10 13:44:55 +02002088 case HCI_OP_DELETE_STORED_LINK_KEY:
2089 hci_cc_delete_stored_link_key(hdev, skb);
2090 break;
2091
Johan Hedbergd5859e22011-01-25 01:19:58 +02002092 case HCI_OP_SET_EVENT_MASK:
2093 hci_cc_set_event_mask(hdev, skb);
2094 break;
2095
2096 case HCI_OP_WRITE_INQUIRY_MODE:
2097 hci_cc_write_inquiry_mode(hdev, skb);
2098 break;
2099
2100 case HCI_OP_READ_INQ_RSP_TX_POWER:
2101 hci_cc_read_inq_rsp_tx_power(hdev, skb);
2102 break;
2103
2104 case HCI_OP_SET_EVENT_FLT:
2105 hci_cc_set_event_flt(hdev, skb);
2106 break;
2107
Johan Hedberg980e1a52011-01-22 06:10:07 +02002108 case HCI_OP_PIN_CODE_REPLY:
2109 hci_cc_pin_code_reply(hdev, skb);
2110 break;
2111
2112 case HCI_OP_PIN_CODE_NEG_REPLY:
2113 hci_cc_pin_code_neg_reply(hdev, skb);
2114 break;
2115
Szymon Jancc35938b2011-03-22 13:12:21 +01002116 case HCI_OP_READ_LOCAL_OOB_DATA:
2117 hci_cc_read_local_oob_data_reply(hdev, skb);
2118 break;
2119
Ville Tervo6ed58ec2011-02-10 22:38:48 -03002120 case HCI_OP_LE_READ_BUFFER_SIZE:
2121 hci_cc_le_read_buffer_size(hdev, skb);
2122 break;
2123
Johan Hedberga5c29682011-02-19 12:05:57 -03002124 case HCI_OP_USER_CONFIRM_REPLY:
2125 hci_cc_user_confirm_reply(hdev, skb);
2126 break;
2127
2128 case HCI_OP_USER_CONFIRM_NEG_REPLY:
2129 hci_cc_user_confirm_neg_reply(hdev, skb);
2130 break;
2131
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03002132 case HCI_OP_LE_LTK_REPLY:
2133 hci_cc_le_ltk_reply(hdev, skb);
2134 break;
2135
2136 case HCI_OP_LE_LTK_NEG_REPLY:
2137 hci_cc_le_ltk_neg_reply(hdev, skb);
2138 break;
2139
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002140 case HCI_OP_LE_SET_SCAN_ENABLE:
2141 hci_cc_le_set_scan_enable(hdev, skb);
Andre Guedese326af42011-06-30 19:20:53 -03002142 break;
2143
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002144 default:
2145 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
2146 break;
2147 }
2148
Ville Tervo6bd32322011-02-16 16:32:41 +02002149 if (ev->opcode != HCI_OP_NOP)
2150 del_timer(&hdev->cmd_timer);
2151
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002152 if (ev->ncmd) {
2153 atomic_set(&hdev->cmd_cnt, 1);
2154 if (!skb_queue_empty(&hdev->cmd_q))
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002155 tasklet_schedule(&hdev->cmd_task);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002156 }
2157}
2158
2159static inline void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
2160{
2161 struct hci_ev_cmd_status *ev = (void *) skb->data;
2162 __u16 opcode;
2163
2164 skb_pull(skb, sizeof(*ev));
2165
2166 opcode = __le16_to_cpu(ev->opcode);
2167
2168 switch (opcode) {
2169 case HCI_OP_INQUIRY:
2170 hci_cs_inquiry(hdev, ev->status);
2171 break;
2172
2173 case HCI_OP_CREATE_CONN:
2174 hci_cs_create_conn(hdev, ev->status);
2175 break;
2176
2177 case HCI_OP_ADD_SCO:
2178 hci_cs_add_sco(hdev, ev->status);
2179 break;
2180
Marcel Holtmannf8558552008-07-14 20:13:49 +02002181 case HCI_OP_AUTH_REQUESTED:
2182 hci_cs_auth_requested(hdev, ev->status);
2183 break;
2184
2185 case HCI_OP_SET_CONN_ENCRYPT:
2186 hci_cs_set_conn_encrypt(hdev, ev->status);
2187 break;
2188
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002189 case HCI_OP_REMOTE_NAME_REQ:
2190 hci_cs_remote_name_req(hdev, ev->status);
2191 break;
2192
Marcel Holtmann769be972008-07-14 20:13:49 +02002193 case HCI_OP_READ_REMOTE_FEATURES:
2194 hci_cs_read_remote_features(hdev, ev->status);
2195 break;
2196
2197 case HCI_OP_READ_REMOTE_EXT_FEATURES:
2198 hci_cs_read_remote_ext_features(hdev, ev->status);
2199 break;
2200
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002201 case HCI_OP_SETUP_SYNC_CONN:
2202 hci_cs_setup_sync_conn(hdev, ev->status);
2203 break;
2204
2205 case HCI_OP_SNIFF_MODE:
2206 hci_cs_sniff_mode(hdev, ev->status);
2207 break;
2208
2209 case HCI_OP_EXIT_SNIFF_MODE:
2210 hci_cs_exit_sniff_mode(hdev, ev->status);
2211 break;
2212
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002213 case HCI_OP_CREATE_LOGICAL_LINK:
2214 hci_cs_create_logical_link(hdev, ev->status);
2215 break;
2216
2217 case HCI_OP_ACCEPT_LOGICAL_LINK:
2218 hci_cs_accept_logical_link(hdev, ev->status);
2219 break;
2220
2221 case HCI_OP_DISCONN_LOGICAL_LINK:
2222 hci_cs_disconn_logical_link(hdev, ev->status);
2223 break;
2224
2225 case HCI_OP_FLOW_SPEC_MODIFY:
2226 hci_cs_flow_spec_modify(hdev, ev->status);
2227 break;
2228
2229 case HCI_OP_CREATE_PHYS_LINK:
2230 case HCI_OP_ACCEPT_PHYS_LINK:
2231 hci_amp_cmd_status(hdev, opcode, ev->status);
2232 break;
2233
2234 case HCI_OP_DISCONN_PHYS_LINK:
2235 hci_cs_disconn_physical_link(hdev, ev->status);
2236
Johan Hedberg8962ee72011-01-20 12:40:27 +02002237 case HCI_OP_DISCONNECT:
2238 if (ev->status != 0)
2239 mgmt_disconnect_failed(hdev->id);
2240 break;
2241
Ville Tervofcd89c02011-02-10 22:38:47 -03002242 case HCI_OP_LE_CREATE_CONN:
2243 hci_cs_le_create_conn(hdev, ev->status);
2244 break;
2245
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03002246 case HCI_OP_LE_START_ENC:
2247 hci_cs_le_start_enc(hdev, ev->status);
2248 break;
2249
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002250 default:
2251 BT_DBG("%s opcode 0x%x", hdev->name, opcode);
2252 break;
2253 }
2254
Ville Tervo6bd32322011-02-16 16:32:41 +02002255 if (ev->opcode != HCI_OP_NOP)
2256 del_timer(&hdev->cmd_timer);
2257
Gustavo F. Padovan10572132011-03-16 15:36:29 -03002258 if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002259 atomic_set(&hdev->cmd_cnt, 1);
2260 if (!skb_queue_empty(&hdev->cmd_q))
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002261 tasklet_schedule(&hdev->cmd_task);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002262 }
2263}
2264
2265static inline void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2266{
2267 struct hci_ev_role_change *ev = (void *) skb->data;
2268 struct hci_conn *conn;
2269
2270 BT_DBG("%s status %d", hdev->name, ev->status);
2271
2272 hci_dev_lock(hdev);
2273
2274 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2275 if (conn) {
2276 if (!ev->status) {
2277 if (ev->role)
2278 conn->link_mode &= ~HCI_LM_MASTER;
2279 else
2280 conn->link_mode |= HCI_LM_MASTER;
2281 }
2282
2283 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->pend);
2284
2285 hci_role_switch_cfm(conn, ev->status, ev->role);
2286 }
2287
2288 hci_dev_unlock(hdev);
2289}
2290
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291static inline void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
2292{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002293 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
Marcel Holtmann1ebb9252005-11-08 09:57:21 -08002294 __le16 *ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 int i;
2296
2297 skb_pull(skb, sizeof(*ev));
2298
2299 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
2300
2301 if (skb->len < ev->num_hndl * 4) {
2302 BT_DBG("%s bad parameters", hdev->name);
2303 return;
2304 }
2305
2306 tasklet_disable(&hdev->tx_task);
2307
Marcel Holtmann1ebb9252005-11-08 09:57:21 -08002308 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002309 struct hci_conn *conn = NULL;
2310 struct hci_chan *chan;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 __u16 handle, count;
2312
Harvey Harrison83985312008-05-02 16:25:46 -07002313 handle = get_unaligned_le16(ptr++);
2314 count = get_unaligned_le16(ptr++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002316 if (hdev->dev_type == HCI_BREDR)
2317 conn = hci_conn_hash_lookup_handle(hdev, handle);
2318 else {
2319 chan = hci_chan_list_lookup_handle(hdev, handle);
2320 if (chan)
2321 conn = chan->conn;
2322 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 if (conn) {
2324 conn->sent -= count;
2325
Marcel Holtmann5b7f99092007-07-11 09:51:55 +02002326 if (conn->type == ACL_LINK) {
Andrei Emeltchenko70f230202010-12-01 16:58:25 +02002327 hdev->acl_cnt += count;
2328 if (hdev->acl_cnt > hdev->acl_pkts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 hdev->acl_cnt = hdev->acl_pkts;
Ville Tervo6ed58ec2011-02-10 22:38:48 -03002330 } else if (conn->type == LE_LINK) {
2331 if (hdev->le_pkts) {
2332 hdev->le_cnt += count;
2333 if (hdev->le_cnt > hdev->le_pkts)
2334 hdev->le_cnt = hdev->le_pkts;
2335 } else {
2336 hdev->acl_cnt += count;
2337 if (hdev->acl_cnt > hdev->acl_pkts)
2338 hdev->acl_cnt = hdev->acl_pkts;
2339 }
Marcel Holtmann5b7f99092007-07-11 09:51:55 +02002340 } else {
Andrei Emeltchenko70f230202010-12-01 16:58:25 +02002341 hdev->sco_cnt += count;
2342 if (hdev->sco_cnt > hdev->sco_pkts)
Marcel Holtmann5b7f99092007-07-11 09:51:55 +02002343 hdev->sco_cnt = hdev->sco_pkts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 }
2345 }
2346 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002347
Marcel Holtmannc78ae282009-11-18 01:02:54 +01002348 tasklet_schedule(&hdev->tx_task);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
2350 tasklet_enable(&hdev->tx_task);
2351}
2352
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002353static inline void hci_num_comp_blocks_evt(struct hci_dev *hdev,
2354 struct sk_buff *skb)
2355{
2356 struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
2357 __le16 *ptr;
2358 int i;
2359
2360 skb_pull(skb, sizeof(*ev));
2361
2362 BT_DBG("%s total_num_blocks %d num_hndl %d",
2363 hdev->name, ev->total_num_blocks, ev->num_hndl);
2364
2365 if (skb->len < ev->num_hndl * 6) {
2366 BT_DBG("%s bad parameters", hdev->name);
2367 return;
2368 }
2369
2370 tasklet_disable(&hdev->tx_task);
2371
2372 for (i = 0, ptr = (__le16 *) skb->data; i < ev->num_hndl; i++) {
2373 struct hci_conn *conn = NULL;
2374 struct hci_chan *chan;
2375 __u16 handle, block_count;
2376
2377 handle = get_unaligned_le16(ptr++);
2378
2379 /* Skip packet count */
2380 ptr++;
2381 block_count = get_unaligned_le16(ptr++);
2382
2383 BT_DBG("%s handle %d count %d", hdev->name, handle,
2384 block_count);
2385
2386 if (hdev->dev_type == HCI_BREDR)
2387 conn = hci_conn_hash_lookup_handle(hdev, handle);
2388 else {
2389 chan = hci_chan_list_lookup_handle(hdev, handle);
2390 if (chan)
2391 conn = chan->conn;
2392 }
2393 if (conn) {
2394 BT_DBG("%s conn %p sent %d", hdev->name,
2395 conn, conn->sent);
2396
2397 conn->sent -= block_count;
2398
2399 if (conn->type == ACL_LINK) {
2400 hdev->acl_cnt += block_count;
2401 if (hdev->acl_cnt > hdev->acl_pkts)
2402 hdev->acl_cnt = hdev->acl_pkts;
2403 } else {
2404 /* We should not find ourselves here */
2405 BT_DBG("Unexpected event for SCO connection");
2406 }
2407 }
2408 }
2409
2410 tasklet_schedule(&hdev->tx_task);
2411
2412 tasklet_enable(&hdev->tx_task);
2413}
2414
Marcel Holtmann04837f62006-07-03 10:02:33 +02002415static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002417 struct hci_ev_mode_change *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002418 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
2420 BT_DBG("%s status %d", hdev->name, ev->status);
2421
2422 hci_dev_lock(hdev);
2423
Marcel Holtmann04837f62006-07-03 10:02:33 +02002424 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2425 if (conn) {
2426 conn->mode = ev->mode;
2427 conn->interval = __le16_to_cpu(ev->interval);
2428
2429 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->pend)) {
2430 if (conn->mode == HCI_CM_ACTIVE)
2431 conn->power_save = 1;
2432 else
2433 conn->power_save = 0;
2434 }
Marcel Holtmanne73439d2010-07-26 10:06:00 -04002435
2436 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->pend))
2437 hci_sco_setup(conn, ev->status);
Marcel Holtmann04837f62006-07-03 10:02:33 +02002438 }
2439
2440 hci_dev_unlock(hdev);
2441}
2442
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443static inline void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2444{
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002445 struct hci_ev_pin_code_req *ev = (void *) skb->data;
2446 struct hci_conn *conn;
2447
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002448 BT_DBG("%s", hdev->name);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002449
2450 hci_dev_lock(hdev);
2451
2452 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Marcel Holtmann3d7a9d12009-05-09 12:09:21 -07002453 if (conn && conn->state == BT_CONNECTED) {
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002454 hci_conn_hold(conn);
2455 conn->disc_timeout = HCI_PAIRING_TIMEOUT;
2456 hci_conn_put(conn);
2457 }
2458
Johan Hedberg03b555e2011-01-04 15:40:05 +02002459 if (!test_bit(HCI_PAIRABLE, &hdev->flags))
2460 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY,
2461 sizeof(ev->bdaddr), &ev->bdaddr);
Waldemar Rymarkiewicza770bb52011-04-28 12:07:59 +02002462
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002463 if (test_bit(HCI_MGMT, &hdev->flags))
2464 mgmt_pin_code_request(hdev->id, &ev->bdaddr);
Johan Hedberg980e1a52011-01-22 06:10:07 +02002465
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002466 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467}
2468
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469static inline void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2470{
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002471 struct hci_ev_link_key_req *ev = (void *) skb->data;
2472 struct hci_cp_link_key_reply cp;
2473 struct hci_conn *conn;
2474 struct link_key *key;
2475
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002476 BT_DBG("%s", hdev->name);
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002477
2478 if (!test_bit(HCI_LINK_KEYS, &hdev->flags))
2479 return;
2480
2481 hci_dev_lock(hdev);
2482
2483 key = hci_find_link_key(hdev, &ev->bdaddr);
2484 if (!key) {
2485 BT_DBG("%s link key not found for %s", hdev->name,
2486 batostr(&ev->bdaddr));
2487 goto not_found;
2488 }
2489
Brian Gixcf956772011-10-20 15:18:51 -07002490 BT_DBG("%s found key type %u for %s", hdev->name, key->key_type,
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002491 batostr(&ev->bdaddr));
2492
Brian Gixcf956772011-10-20 15:18:51 -07002493 if (!test_bit(HCI_DEBUG_KEYS, &hdev->flags) && key->key_type == 0x03) {
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002494 BT_DBG("%s ignoring debug key", hdev->name);
2495 goto not_found;
2496 }
2497
2498 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2499
Prabhakaran Mc6001a712011-09-06 11:56:25 +05302500 if (conn) {
2501 BT_DBG("Conn pending sec level is %d, ssp is %d, key len is %d",
2502 conn->pending_sec_level, conn->ssp_mode, key->pin_len);
2503 }
2504 if (conn && (conn->ssp_mode == 0) &&
2505 (conn->pending_sec_level == BT_SECURITY_HIGH) &&
2506 (key->pin_len != 16)) {
2507 BT_DBG("Security is high ignoring this key");
2508 goto not_found;
2509 }
2510
Brian Gixcf956772011-10-20 15:18:51 -07002511 if (key->key_type == 0x04 && conn && conn->auth_type != 0xff &&
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002512 (conn->auth_type & 0x01)) {
2513 BT_DBG("%s ignoring unauthenticated key", hdev->name);
2514 goto not_found;
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002515 }
2516
2517 bacpy(&cp.bdaddr, &ev->bdaddr);
2518 memcpy(cp.link_key, key->val, 16);
2519
2520 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp);
2521
2522 hci_dev_unlock(hdev);
2523
2524 return;
2525
2526not_found:
2527 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr);
2528 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529}
2530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531static inline void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
2532{
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002533 struct hci_ev_link_key_notify *ev = (void *) skb->data;
2534 struct hci_conn *conn;
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002535 u8 pin_len = 0;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002536
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002537 BT_DBG("%s type %d", hdev->name, ev->key_type);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002538
2539 hci_dev_lock(hdev);
2540
2541 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2542 if (conn) {
2543 hci_conn_hold(conn);
2544 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002545
2546 memcpy(conn->link_key, ev->link_key, 16);
2547 conn->key_type = ev->key_type;
2548 hci_disconnect_amp(conn, 0x06);
2549
Johan Hedberg980e1a52011-01-22 06:10:07 +02002550 pin_len = conn->pin_length;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002551 hci_conn_put(conn);
2552 }
2553
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002554 if (test_bit(HCI_LINK_KEYS, &hdev->flags))
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002555 hci_add_link_key(hdev, 1, &ev->bdaddr, ev->link_key,
Johan Hedberg55ed8ca2011-01-17 14:41:05 +02002556 ev->key_type, pin_len);
2557
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002558 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559}
2560
Marcel Holtmann04837f62006-07-03 10:02:33 +02002561static inline void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb)
2562{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002563 struct hci_ev_clock_offset *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002564 struct hci_conn *conn;
2565
2566 BT_DBG("%s status %d", hdev->name, ev->status);
2567
2568 hci_dev_lock(hdev);
2569
2570 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 if (conn && !ev->status) {
2572 struct inquiry_entry *ie;
2573
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002574 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
2575 if (ie) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 ie->data.clock_offset = ev->clock_offset;
2577 ie->timestamp = jiffies;
2578 }
2579 }
2580
2581 hci_dev_unlock(hdev);
2582}
2583
Marcel Holtmanna8746412008-07-14 20:13:46 +02002584static inline void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
2585{
2586 struct hci_ev_pkt_type_change *ev = (void *) skb->data;
2587 struct hci_conn *conn;
2588
2589 BT_DBG("%s status %d", hdev->name, ev->status);
2590
2591 hci_dev_lock(hdev);
2592
2593 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2594 if (conn && !ev->status)
2595 conn->pkt_type = __le16_to_cpu(ev->pkt_type);
2596
2597 hci_dev_unlock(hdev);
2598}
2599
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002600static inline void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
2601{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002602 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002603 struct inquiry_entry *ie;
2604
2605 BT_DBG("%s", hdev->name);
2606
2607 hci_dev_lock(hdev);
2608
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002609 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
2610 if (ie) {
Marcel Holtmann85a1e932005-08-09 20:28:02 -07002611 ie->data.pscan_rep_mode = ev->pscan_rep_mode;
2612 ie->timestamp = jiffies;
2613 }
2614
2615 hci_dev_unlock(hdev);
2616}
2617
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002618static inline void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, struct sk_buff *skb)
2619{
2620 struct inquiry_data data;
2621 int num_rsp = *((__u8 *) skb->data);
2622
2623 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
2624
2625 if (!num_rsp)
2626 return;
2627
2628 hci_dev_lock(hdev);
2629
2630 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {
Szymon Janc138d22e2011-02-17 16:44:23 +01002631 struct inquiry_info_with_rssi_and_pscan_mode *info;
2632 info = (void *) (skb->data + 1);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002633
Johan Hedberge17acd42011-03-30 23:57:16 +03002634 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002635 bacpy(&data.bdaddr, &info->bdaddr);
2636 data.pscan_rep_mode = info->pscan_rep_mode;
2637 data.pscan_period_mode = info->pscan_period_mode;
2638 data.pscan_mode = info->pscan_mode;
2639 memcpy(data.dev_class, info->dev_class, 3);
2640 data.clock_offset = info->clock_offset;
2641 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002642 data.ssp_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002643 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07002644 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
Johan Hedberge17acd42011-03-30 23:57:16 +03002645 info->dev_class, info->rssi,
Brian Gixa68668b2011-08-11 15:49:36 -07002646 0, NULL);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002647 }
2648 } else {
2649 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
2650
Johan Hedberge17acd42011-03-30 23:57:16 +03002651 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002652 bacpy(&data.bdaddr, &info->bdaddr);
2653 data.pscan_rep_mode = info->pscan_rep_mode;
2654 data.pscan_period_mode = info->pscan_period_mode;
2655 data.pscan_mode = 0x00;
2656 memcpy(data.dev_class, info->dev_class, 3);
2657 data.clock_offset = info->clock_offset;
2658 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002659 data.ssp_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002660 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07002661 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
Johan Hedberge17acd42011-03-30 23:57:16 +03002662 info->dev_class, info->rssi,
Brian Gixa68668b2011-08-11 15:49:36 -07002663 0, NULL);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002664 }
2665 }
2666
2667 hci_dev_unlock(hdev);
2668}
2669
2670static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
2671{
Marcel Holtmann41a96212008-07-14 20:13:48 +02002672 struct hci_ev_remote_ext_features *ev = (void *) skb->data;
2673 struct hci_conn *conn;
2674
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002675 BT_DBG("%s", hdev->name);
Marcel Holtmann41a96212008-07-14 20:13:48 +02002676
Marcel Holtmann41a96212008-07-14 20:13:48 +02002677 hci_dev_lock(hdev);
2678
2679 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergccd556f2010-11-10 17:11:51 +02002680 if (!conn)
2681 goto unlock;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002682
Johan Hedbergccd556f2010-11-10 17:11:51 +02002683 if (!ev->status && ev->page == 0x01) {
2684 struct inquiry_entry *ie;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002685
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002686 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
2687 if (ie)
Johan Hedbergccd556f2010-11-10 17:11:51 +02002688 ie->data.ssp_mode = (ev->features[0] & 0x01);
Marcel Holtmann769be972008-07-14 20:13:49 +02002689
Johan Hedbergccd556f2010-11-10 17:11:51 +02002690 conn->ssp_mode = (ev->features[0] & 0x01);
Marcel Holtmann41a96212008-07-14 20:13:48 +02002691 }
2692
Johan Hedbergccd556f2010-11-10 17:11:51 +02002693 if (conn->state != BT_CONFIG)
2694 goto unlock;
2695
Johan Hedberg127178d2010-11-18 22:22:29 +02002696 if (!ev->status) {
2697 struct hci_cp_remote_name_req cp;
2698 memset(&cp, 0, sizeof(cp));
2699 bacpy(&cp.bdaddr, &conn->dst);
2700 cp.pscan_rep_mode = 0x02;
2701 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
2702 }
Johan Hedberg392599b2010-11-18 22:22:28 +02002703
Johan Hedberg127178d2010-11-18 22:22:29 +02002704 if (!hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02002705 conn->state = BT_CONNECTED;
2706 hci_proto_connect_cfm(conn, ev->status);
2707 hci_conn_put(conn);
2708 }
2709
2710unlock:
Marcel Holtmann41a96212008-07-14 20:13:48 +02002711 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002712}
2713
2714static inline void hci_sync_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2715{
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002716 struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
2717 struct hci_conn *conn;
2718
2719 BT_DBG("%s status %d", hdev->name, ev->status);
2720
2721 hci_dev_lock(hdev);
2722
2723 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
Marcel Holtmann9dc0a3a2008-07-14 20:13:46 +02002724 if (!conn) {
2725 if (ev->link_type == ESCO_LINK)
2726 goto unlock;
2727
2728 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
2729 if (!conn)
2730 goto unlock;
2731
2732 conn->type = SCO_LINK;
2733 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002734
Marcel Holtmann732547f2009-04-19 19:14:14 +02002735 switch (ev->status) {
2736 case 0x00:
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002737 conn->handle = __le16_to_cpu(ev->handle);
2738 conn->state = BT_CONNECTED;
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02002739
Marcel Holtmann9eba32b2009-08-22 14:19:26 -07002740 hci_conn_hold_device(conn);
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02002741 hci_conn_add_sysfs(conn);
Marcel Holtmann732547f2009-04-19 19:14:14 +02002742 break;
2743
Stephen Coe705e5712010-02-16 11:29:44 -05002744 case 0x11: /* Unsupported Feature or Parameter Value */
Marcel Holtmann732547f2009-04-19 19:14:14 +02002745 case 0x1c: /* SCO interval rejected */
Nick Pelly1038a002010-02-03 11:42:26 -08002746 case 0x1a: /* Unsupported Remote Feature */
Marcel Holtmann732547f2009-04-19 19:14:14 +02002747 case 0x1f: /* Unspecified error */
2748 if (conn->out && conn->attempt < 2) {
Kun Han Kim15b911f2011-07-08 09:30:28 -07002749 if (!conn->hdev->is_wbs)
2750 conn->pkt_type =
2751 (hdev->esco_type & SCO_ESCO_MASK) |
Marcel Holtmann732547f2009-04-19 19:14:14 +02002752 (hdev->esco_type & EDR_ESCO_MASK);
2753 hci_setup_sync(conn, conn->link->handle);
2754 goto unlock;
2755 }
2756 /* fall through */
2757
2758 default:
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002759 conn->state = BT_CLOSED;
Marcel Holtmann732547f2009-04-19 19:14:14 +02002760 break;
2761 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002762
2763 hci_proto_connect_cfm(conn, ev->status);
2764 if (ev->status)
2765 hci_conn_del(conn);
2766
2767unlock:
2768 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002769}
2770
2771static inline void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb)
2772{
2773 BT_DBG("%s", hdev->name);
2774}
2775
Marcel Holtmann04837f62006-07-03 10:02:33 +02002776static inline void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb)
2777{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002778 struct hci_ev_sniff_subrate *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002779
2780 BT_DBG("%s status %d", hdev->name, ev->status);
Marcel Holtmann04837f62006-07-03 10:02:33 +02002781}
2782
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002783static inline void hci_extended_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
2784{
2785 struct inquiry_data data;
2786 struct extended_inquiry_info *info = (void *) (skb->data + 1);
2787 int num_rsp = *((__u8 *) skb->data);
2788
2789 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
2790
2791 if (!num_rsp)
2792 return;
2793
2794 hci_dev_lock(hdev);
2795
Johan Hedberge17acd42011-03-30 23:57:16 +03002796 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002797 bacpy(&data.bdaddr, &info->bdaddr);
Szymon Janc138d22e2011-02-17 16:44:23 +01002798 data.pscan_rep_mode = info->pscan_rep_mode;
2799 data.pscan_period_mode = info->pscan_period_mode;
2800 data.pscan_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002801 memcpy(data.dev_class, info->dev_class, 3);
Szymon Janc138d22e2011-02-17 16:44:23 +01002802 data.clock_offset = info->clock_offset;
2803 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02002804 data.ssp_mode = 0x01;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002805 hci_inquiry_cache_update(hdev, &data);
Brian Gixa68668b2011-08-11 15:49:36 -07002806 mgmt_device_found(hdev->id, &info->bdaddr, 0, 0,
2807 info->dev_class, info->rssi,
2808 HCI_MAX_EIR_LENGTH, info->data);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002809 }
2810
2811 hci_dev_unlock(hdev);
2812}
2813
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002814static inline u8 hci_get_auth_req(struct hci_conn *conn)
2815{
Brian Gixa68668b2011-08-11 15:49:36 -07002816 BT_DBG("%p", conn);
2817
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002818 /* If remote requests dedicated bonding follow that lead */
2819 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) {
2820 /* If both remote and local IO capabilities allow MITM
2821 * protection then require it, otherwise don't */
Brian Gixa68668b2011-08-11 15:49:36 -07002822 if (conn->remote_cap == 0x03 || conn->io_capability == 0x03) {
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002823 return 0x02;
Brian Gixa68668b2011-08-11 15:49:36 -07002824 } else {
2825 conn->auth_type |= 0x01;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002826 return 0x03;
Brian Gixa68668b2011-08-11 15:49:36 -07002827 }
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002828 }
2829
2830 /* If remote requests no-bonding follow that lead */
Brian Gixa68668b2011-08-11 15:49:36 -07002831 if (conn->remote_auth <= 0x01)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002832 return 0x00;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002833
2834 return conn->auth_type;
2835}
2836
Marcel Holtmann04936842008-07-14 20:13:48 +02002837static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
2838{
2839 struct hci_ev_io_capa_request *ev = (void *) skb->data;
2840 struct hci_conn *conn;
2841
2842 BT_DBG("%s", hdev->name);
2843
2844 hci_dev_lock(hdev);
2845
2846 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedberg03b555e2011-01-04 15:40:05 +02002847 if (!conn)
2848 goto unlock;
Marcel Holtmann04936842008-07-14 20:13:48 +02002849
Johan Hedberg03b555e2011-01-04 15:40:05 +02002850 hci_conn_hold(conn);
2851
2852 if (!test_bit(HCI_MGMT, &hdev->flags))
2853 goto unlock;
2854
2855 if (test_bit(HCI_PAIRABLE, &hdev->flags) ||
2856 (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) {
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002857 struct hci_cp_io_capability_reply cp;
Brian Gixa68668b2011-08-11 15:49:36 -07002858 u8 io_cap = conn->io_capability;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002859
Brian Gixa68668b2011-08-11 15:49:36 -07002860 /* ACL-SSP does not support IO CAP 0x04 */
2861 cp.capability = (io_cap == 0x04) ? 0x01 : io_cap;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002862 bacpy(&cp.bdaddr, &ev->bdaddr);
Brian Gixa68668b2011-08-11 15:49:36 -07002863 if (conn->auth_initiator)
2864 cp.authentication = conn->auth_type;
2865 else
2866 cp.authentication = hci_get_auth_req(conn);
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002867
Szymon Jancce85ee12011-03-22 13:12:23 +01002868 if ((conn->out == 0x01 || conn->remote_oob == 0x01) &&
2869 hci_find_remote_oob_data(hdev, &conn->dst))
2870 cp.oob_data = 0x01;
2871 else
2872 cp.oob_data = 0x00;
2873
Johan Hedberg17fa4b92011-01-25 13:28:33 +02002874 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
2875 sizeof(cp), &cp);
Johan Hedberg03b555e2011-01-04 15:40:05 +02002876 } else {
2877 struct hci_cp_io_capability_neg_reply cp;
2878
2879 bacpy(&cp.bdaddr, &ev->bdaddr);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002880 cp.reason = 0x16; /* Pairing not allowed */
Johan Hedberg03b555e2011-01-04 15:40:05 +02002881
2882 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
2883 sizeof(cp), &cp);
2884 }
2885
2886unlock:
2887 hci_dev_unlock(hdev);
2888}
2889
2890static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb)
2891{
2892 struct hci_ev_io_capa_reply *ev = (void *) skb->data;
2893 struct hci_conn *conn;
2894
2895 BT_DBG("%s", hdev->name);
2896
2897 hci_dev_lock(hdev);
2898
2899 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2900 if (!conn)
2901 goto unlock;
2902
Johan Hedberg03b555e2011-01-04 15:40:05 +02002903 conn->remote_cap = ev->capability;
2904 conn->remote_oob = ev->oob_data;
2905 conn->remote_auth = ev->authentication;
2906
2907unlock:
Marcel Holtmann04936842008-07-14 20:13:48 +02002908 hci_dev_unlock(hdev);
2909}
2910
Brian Gixa68668b2011-08-11 15:49:36 -07002911static inline void hci_user_ssp_confirmation_evt(struct hci_dev *hdev,
2912 u8 event, struct sk_buff *skb)
Johan Hedberga5c29682011-02-19 12:05:57 -03002913{
2914 struct hci_ev_user_confirm_req *ev = (void *) skb->data;
2915
2916 BT_DBG("%s", hdev->name);
2917
2918 hci_dev_lock(hdev);
2919
Brian Gixa68668b2011-08-11 15:49:36 -07002920 if (test_bit(HCI_MGMT, &hdev->flags)) {
2921 if (event == HCI_EV_USER_PASSKEY_REQUEST)
2922 mgmt_user_confirm_request(hdev->id, event,
2923 &ev->bdaddr, 0);
2924 else
2925 mgmt_user_confirm_request(hdev->id, event,
2926 &ev->bdaddr, ev->passkey);
2927 }
Johan Hedberga5c29682011-02-19 12:05:57 -03002928
2929 hci_dev_unlock(hdev);
2930}
2931
Marcel Holtmann04936842008-07-14 20:13:48 +02002932static inline void hci_simple_pair_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2933{
2934 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
2935 struct hci_conn *conn;
2936
2937 BT_DBG("%s", hdev->name);
2938
2939 hci_dev_lock(hdev);
2940
2941 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedberg2a611692011-02-19 12:06:00 -03002942 if (!conn)
2943 goto unlock;
Marcel Holtmann04936842008-07-14 20:13:48 +02002944
Johan Hedberg2a611692011-02-19 12:06:00 -03002945 /* To avoid duplicate auth_failed events to user space we check
2946 * the HCI_CONN_AUTH_PEND flag which will be set if we
2947 * initiated the authentication. A traditional auth_complete
2948 * event gets always produced as initiator and is also mapped to
2949 * the mgmt_auth_failed event */
2950 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->pend) && ev->status != 0)
2951 mgmt_auth_failed(hdev->id, &conn->dst, ev->status);
2952
2953 hci_conn_put(conn);
2954
2955unlock:
Marcel Holtmann04936842008-07-14 20:13:48 +02002956 hci_dev_unlock(hdev);
2957}
2958
Marcel Holtmann41a96212008-07-14 20:13:48 +02002959static inline void hci_remote_host_features_evt(struct hci_dev *hdev, struct sk_buff *skb)
2960{
2961 struct hci_ev_remote_host_features *ev = (void *) skb->data;
2962 struct inquiry_entry *ie;
2963
2964 BT_DBG("%s", hdev->name);
2965
2966 hci_dev_lock(hdev);
2967
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002968 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
2969 if (ie)
Marcel Holtmann41a96212008-07-14 20:13:48 +02002970 ie->data.ssp_mode = (ev->features[0] & 0x01);
2971
2972 hci_dev_unlock(hdev);
2973}
2974
Szymon Janc2763eda2011-03-22 13:12:22 +01002975static inline void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
2976 struct sk_buff *skb)
2977{
2978 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
2979 struct oob_data *data;
2980
2981 BT_DBG("%s", hdev->name);
2982
2983 hci_dev_lock(hdev);
2984
Szymon Jance1ba1f12011-04-06 13:01:59 +02002985 if (!test_bit(HCI_MGMT, &hdev->flags))
2986 goto unlock;
2987
Szymon Janc2763eda2011-03-22 13:12:22 +01002988 data = hci_find_remote_oob_data(hdev, &ev->bdaddr);
2989 if (data) {
2990 struct hci_cp_remote_oob_data_reply cp;
2991
2992 bacpy(&cp.bdaddr, &ev->bdaddr);
2993 memcpy(cp.hash, data->hash, sizeof(cp.hash));
2994 memcpy(cp.randomizer, data->randomizer, sizeof(cp.randomizer));
2995
2996 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp),
2997 &cp);
2998 } else {
2999 struct hci_cp_remote_oob_data_neg_reply cp;
3000
3001 bacpy(&cp.bdaddr, &ev->bdaddr);
3002 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp),
3003 &cp);
3004 }
3005
Szymon Jance1ba1f12011-04-06 13:01:59 +02003006unlock:
Szymon Janc2763eda2011-03-22 13:12:22 +01003007 hci_dev_unlock(hdev);
3008}
3009
Ville Tervofcd89c02011-02-10 22:38:47 -03003010static inline void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3011{
3012 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
3013 struct hci_conn *conn;
3014
3015 BT_DBG("%s status %d", hdev->name, ev->status);
3016
3017 hci_dev_lock(hdev);
3018
3019 conn = hci_conn_hash_lookup_ba(hdev, LE_LINK, &ev->bdaddr);
Ville Tervob62f3282011-02-10 22:38:50 -03003020 if (!conn) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003021 conn = hci_le_conn_add(hdev, &ev->bdaddr, ev->bdaddr_type);
Ville Tervob62f3282011-02-10 22:38:50 -03003022 if (!conn) {
3023 BT_ERR("No memory for new connection");
3024 hci_dev_unlock(hdev);
3025 return;
3026 }
3027 }
Ville Tervofcd89c02011-02-10 22:38:47 -03003028
3029 if (ev->status) {
3030 hci_proto_connect_cfm(conn, ev->status);
3031 conn->state = BT_CLOSED;
3032 hci_conn_del(conn);
3033 goto unlock;
3034 }
3035
Vinicius Costa Gomes403d2c82011-06-09 18:50:50 -03003036 conn->sec_level = BT_SECURITY_LOW;
Ville Tervofcd89c02011-02-10 22:38:47 -03003037 conn->handle = __le16_to_cpu(ev->handle);
3038 conn->state = BT_CONNECTED;
Brian Gixa68668b2011-08-11 15:49:36 -07003039 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Brian Gix2e2f50d2011-09-13 12:36:04 -07003040 mgmt_connected(hdev->id, &ev->bdaddr, 1);
Ville Tervofcd89c02011-02-10 22:38:47 -03003041
Brian Gix6d5fb8a2011-09-09 14:53:04 -07003042 hci_conn_hold(conn);
Ville Tervofcd89c02011-02-10 22:38:47 -03003043 hci_conn_hold_device(conn);
3044 hci_conn_add_sysfs(conn);
3045
3046 hci_proto_connect_cfm(conn, ev->status);
3047
3048unlock:
3049 hci_dev_unlock(hdev);
3050}
3051
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003052static inline void hci_le_ltk_request_evt(struct hci_dev *hdev,
3053 struct sk_buff *skb)
3054{
3055 struct hci_ev_le_ltk_req *ev = (void *) skb->data;
3056 struct hci_cp_le_ltk_reply cp;
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003057 struct hci_cp_le_ltk_neg_reply neg;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003058 struct hci_conn *conn;
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003059 struct link_key *ltk;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003060
3061 BT_DBG("%s handle %d", hdev->name, cpu_to_le16(ev->handle));
3062
3063 hci_dev_lock(hdev);
3064
3065 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003066 if (conn == NULL)
3067 goto not_found;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003068
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003069 ltk = hci_find_ltk(hdev, ev->ediv, ev->random);
3070 if (ltk == NULL)
3071 goto not_found;
3072
3073 memcpy(cp.ltk, ltk->val, sizeof(ltk->val));
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003074 cp.handle = cpu_to_le16(conn->handle);
Vinicius Costa Gomes1fa2de32011-07-08 18:31:45 -03003075 conn->pin_length = ltk->pin_len;
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003076
3077 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
3078
3079 hci_dev_unlock(hdev);
Vinicius Costa Gomes60e56472011-07-07 18:59:37 -03003080
3081 return;
3082
3083not_found:
3084 neg.handle = ev->handle;
3085 hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg);
3086 hci_dev_unlock(hdev);
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003087}
3088
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003089static inline void hci_le_adv_report_evt(struct hci_dev *hdev,
3090 struct sk_buff *skb)
3091{
3092 struct hci_ev_le_advertising_info *ev;
3093 u8 num_reports;
3094
3095 num_reports = skb->data[0];
3096 ev = (void *) &skb->data[1];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003097
Brian Gix3dd70172011-09-16 21:38:54 -07003098 hci_dev_lock(hdev);
3099
Brian Gixa68668b2011-08-11 15:49:36 -07003100 while (num_reports--) {
3101 mgmt_device_found(hdev->id, &ev->bdaddr, ev->bdaddr_type,
3102 1, NULL, 0, ev->length, ev->data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003103 hci_add_adv_entry(hdev, ev);
Brian Gixa68668b2011-08-11 15:49:36 -07003104 ev = (void *) (ev->data + ev->length + 1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003105 }
Brian Gix3dd70172011-09-16 21:38:54 -07003106
3107 hci_dev_unlock(hdev);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003108}
3109
Ville Tervofcd89c02011-02-10 22:38:47 -03003110static inline void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
3111{
3112 struct hci_ev_le_meta *le_ev = (void *) skb->data;
3113
3114 skb_pull(skb, sizeof(*le_ev));
3115
3116 switch (le_ev->subevent) {
3117 case HCI_EV_LE_CONN_COMPLETE:
3118 hci_le_conn_complete_evt(hdev, skb);
3119 break;
3120
Vinicius Costa Gomes735038c2011-06-09 18:50:47 -03003121 case HCI_EV_LE_LTK_REQ:
3122 hci_le_ltk_request_evt(hdev, skb);
3123 break;
3124
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003125 case HCI_EV_LE_ADVERTISING_REPORT:
3126 hci_le_adv_report_evt(hdev, skb);
3127 break;
3128
Ville Tervofcd89c02011-02-10 22:38:47 -03003129 default:
3130 break;
3131 }
3132}
3133
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003134static inline void hci_phy_link_complete(struct hci_dev *hdev,
3135 struct sk_buff *skb)
3136{
3137 struct hci_ev_phys_link_complete *ev = (void *) skb->data;
3138 struct hci_conn *conn;
3139
3140 BT_DBG("%s handle %d status %d", hdev->name, ev->phy_handle,
3141 ev->status);
3142
3143 hci_dev_lock(hdev);
3144
3145 if (ev->status == 0) {
3146 conn = hci_conn_add(hdev, ACL_LINK, 0, BDADDR_ANY);
3147 if (conn) {
3148 conn->handle = ev->phy_handle;
3149 conn->state = BT_CONNECTED;
3150
3151 hci_conn_hold(conn);
3152 conn->disc_timeout = HCI_DISCONN_TIMEOUT/2;
3153 hci_conn_put(conn);
3154
3155 hci_conn_hold_device(conn);
3156 hci_conn_add_sysfs(conn);
3157 } else
3158 BT_ERR("No memory for new connection");
3159 }
3160
3161 hci_dev_unlock(hdev);
3162}
3163
3164static inline void hci_log_link_complete(struct hci_dev *hdev,
3165 struct sk_buff *skb)
3166{
3167 struct hci_ev_log_link_complete *ev = (void *) skb->data;
3168 struct hci_chan *chan;
3169
3170 BT_DBG("%s handle %d status %d", hdev->name,
3171 __le16_to_cpu(ev->log_handle), ev->status);
3172
3173 hci_dev_lock(hdev);
3174
3175 chan = hci_chan_list_lookup_id(hdev, ev->phy_handle);
3176
3177 if (ev->status == 0) {
3178 if (chan) {
3179 chan->ll_handle = __le16_to_cpu(ev->log_handle);
3180 chan->state = BT_CONNECTED;
3181 hci_proto_create_cfm(chan, ev->status);
3182 hci_chan_hold(chan);
3183 }
3184 } else {
3185 if (chan) {
3186 chan->state = BT_CLOSED;
3187 hci_proto_create_cfm(chan, ev->status);
3188 hci_chan_del(chan);
3189 }
3190 }
3191
3192 hci_dev_unlock(hdev);
3193}
3194
3195static inline void hci_flow_spec_modify_complete(struct hci_dev *hdev,
3196 struct sk_buff *skb)
3197{
3198 struct hci_ev_flow_spec_modify_complete *ev = (void *) skb->data;
3199 struct hci_chan *chan;
3200
3201 BT_DBG("%s handle %d status %d", hdev->name,
3202 __le16_to_cpu(ev->log_handle), ev->status);
3203
3204 hci_dev_lock(hdev);
3205
3206 chan = hci_chan_list_lookup_handle(hdev, ev->log_handle);
3207 if (chan)
3208 hci_proto_modify_cfm(chan, ev->status);
3209
3210 hci_dev_unlock(hdev);
3211}
3212
3213static inline void hci_disconn_log_link_complete_evt(struct hci_dev *hdev,
3214 struct sk_buff *skb)
3215{
3216 struct hci_ev_disconn_log_link_complete *ev = (void *) skb->data;
3217 struct hci_chan *chan;
3218
3219 BT_DBG("%s handle %d status %d", hdev->name,
3220 __le16_to_cpu(ev->log_handle), ev->status);
3221
3222 if (ev->status)
3223 return;
3224
3225 hci_dev_lock(hdev);
3226
3227 chan = hci_chan_list_lookup_handle(hdev, __le16_to_cpu(ev->log_handle));
3228 if (chan) {
3229 hci_proto_destroy_cfm(chan, ev->reason);
3230 hci_chan_del(chan);
3231 }
3232
3233 hci_dev_unlock(hdev);
3234}
3235
3236static inline void hci_disconn_phy_link_complete_evt(struct hci_dev *hdev,
3237 struct sk_buff *skb)
3238{
3239 struct hci_ev_disconn_phys_link_complete *ev = (void *) skb->data;
3240 struct hci_conn *conn;
3241
3242 BT_DBG("%s status %d", hdev->name, ev->status);
3243
3244 if (ev->status)
3245 return;
3246
3247 hci_dev_lock(hdev);
3248
3249 conn = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3250 if (conn) {
3251 conn->state = BT_CLOSED;
3252
3253 hci_proto_disconn_cfm(conn, ev->reason);
3254 hci_conn_del(conn);
3255 }
3256
3257 hci_dev_unlock(hdev);
3258}
3259
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
3261{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003262 struct hci_event_hdr *hdr = (void *) skb->data;
3263 __u8 event = hdr->evt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264
Brian Gixdfdd9362011-08-18 09:58:02 -07003265 BT_DBG("");
3266
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 skb_pull(skb, HCI_EVENT_HDR_SIZE);
3268
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003269 switch (event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 case HCI_EV_INQUIRY_COMPLETE:
3271 hci_inquiry_complete_evt(hdev, skb);
3272 break;
3273
3274 case HCI_EV_INQUIRY_RESULT:
3275 hci_inquiry_result_evt(hdev, skb);
3276 break;
3277
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003278 case HCI_EV_CONN_COMPLETE:
3279 hci_conn_complete_evt(hdev, skb);
Marcel Holtmann21d9e302005-09-13 01:32:25 +02003280 break;
3281
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 case HCI_EV_CONN_REQUEST:
3283 hci_conn_request_evt(hdev, skb);
3284 break;
3285
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 case HCI_EV_DISCONN_COMPLETE:
3287 hci_disconn_complete_evt(hdev, skb);
3288 break;
3289
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 case HCI_EV_AUTH_COMPLETE:
3291 hci_auth_complete_evt(hdev, skb);
3292 break;
3293
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003294 case HCI_EV_REMOTE_NAME:
3295 hci_remote_name_evt(hdev, skb);
3296 break;
3297
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 case HCI_EV_ENCRYPT_CHANGE:
3299 hci_encrypt_change_evt(hdev, skb);
3300 break;
3301
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003302 case HCI_EV_CHANGE_LINK_KEY_COMPLETE:
3303 hci_change_link_key_complete_evt(hdev, skb);
3304 break;
3305
3306 case HCI_EV_REMOTE_FEATURES:
3307 hci_remote_features_evt(hdev, skb);
3308 break;
3309
3310 case HCI_EV_REMOTE_VERSION:
3311 hci_remote_version_evt(hdev, skb);
3312 break;
3313
3314 case HCI_EV_QOS_SETUP_COMPLETE:
3315 hci_qos_setup_complete_evt(hdev, skb);
3316 break;
3317
3318 case HCI_EV_CMD_COMPLETE:
3319 hci_cmd_complete_evt(hdev, skb);
3320 break;
3321
3322 case HCI_EV_CMD_STATUS:
3323 hci_cmd_status_evt(hdev, skb);
3324 break;
3325
3326 case HCI_EV_ROLE_CHANGE:
3327 hci_role_change_evt(hdev, skb);
3328 break;
3329
3330 case HCI_EV_NUM_COMP_PKTS:
3331 hci_num_comp_pkts_evt(hdev, skb);
3332 break;
3333
3334 case HCI_EV_MODE_CHANGE:
3335 hci_mode_change_evt(hdev, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336 break;
3337
3338 case HCI_EV_PIN_CODE_REQ:
3339 hci_pin_code_request_evt(hdev, skb);
3340 break;
3341
3342 case HCI_EV_LINK_KEY_REQ:
3343 hci_link_key_request_evt(hdev, skb);
3344 break;
3345
3346 case HCI_EV_LINK_KEY_NOTIFY:
3347 hci_link_key_notify_evt(hdev, skb);
3348 break;
3349
3350 case HCI_EV_CLOCK_OFFSET:
3351 hci_clock_offset_evt(hdev, skb);
3352 break;
3353
Marcel Holtmanna8746412008-07-14 20:13:46 +02003354 case HCI_EV_PKT_TYPE_CHANGE:
3355 hci_pkt_type_change_evt(hdev, skb);
3356 break;
3357
Marcel Holtmann85a1e932005-08-09 20:28:02 -07003358 case HCI_EV_PSCAN_REP_MODE:
3359 hci_pscan_rep_mode_evt(hdev, skb);
3360 break;
3361
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003362 case HCI_EV_INQUIRY_RESULT_WITH_RSSI:
3363 hci_inquiry_result_with_rssi_evt(hdev, skb);
3364 break;
3365
3366 case HCI_EV_REMOTE_EXT_FEATURES:
3367 hci_remote_ext_features_evt(hdev, skb);
3368 break;
3369
3370 case HCI_EV_SYNC_CONN_COMPLETE:
3371 hci_sync_conn_complete_evt(hdev, skb);
3372 break;
3373
3374 case HCI_EV_SYNC_CONN_CHANGED:
3375 hci_sync_conn_changed_evt(hdev, skb);
3376 break;
3377
Marcel Holtmann04837f62006-07-03 10:02:33 +02003378 case HCI_EV_SNIFF_SUBRATE:
3379 hci_sniff_subrate_evt(hdev, skb);
3380 break;
3381
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003382 case HCI_EV_EXTENDED_INQUIRY_RESULT:
3383 hci_extended_inquiry_result_evt(hdev, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 break;
3385
Marcel Holtmann04936842008-07-14 20:13:48 +02003386 case HCI_EV_IO_CAPA_REQUEST:
3387 hci_io_capa_request_evt(hdev, skb);
3388 break;
3389
Johan Hedberg03b555e2011-01-04 15:40:05 +02003390 case HCI_EV_IO_CAPA_REPLY:
3391 hci_io_capa_reply_evt(hdev, skb);
3392 break;
3393
Brian Gixa68668b2011-08-11 15:49:36 -07003394 case HCI_EV_USER_PASSKEY_REQUEST:
3395 case HCI_EV_USER_PASSKEY_NOTIFICATION:
Johan Hedberga5c29682011-02-19 12:05:57 -03003396 case HCI_EV_USER_CONFIRM_REQUEST:
Brian Gixa68668b2011-08-11 15:49:36 -07003397 hci_user_ssp_confirmation_evt(hdev, event, skb);
Johan Hedberga5c29682011-02-19 12:05:57 -03003398 break;
3399
Marcel Holtmann04936842008-07-14 20:13:48 +02003400 case HCI_EV_SIMPLE_PAIR_COMPLETE:
3401 hci_simple_pair_complete_evt(hdev, skb);
3402 break;
3403
Marcel Holtmann41a96212008-07-14 20:13:48 +02003404 case HCI_EV_REMOTE_HOST_FEATURES:
3405 hci_remote_host_features_evt(hdev, skb);
3406 break;
3407
Ville Tervofcd89c02011-02-10 22:38:47 -03003408 case HCI_EV_LE_META:
3409 hci_le_meta_evt(hdev, skb);
3410 break;
3411
Szymon Janc2763eda2011-03-22 13:12:22 +01003412 case HCI_EV_REMOTE_OOB_DATA_REQUEST:
3413 hci_remote_oob_data_request_evt(hdev, skb);
3414 break;
3415
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003416 case HCI_EV_PHYS_LINK_COMPLETE:
3417 hci_phy_link_complete(hdev, skb);
3418 hci_amp_event_packet(hdev, event, skb);
3419 break;
3420
3421 case HCI_EV_LOG_LINK_COMPLETE:
3422 hci_log_link_complete(hdev, skb);
3423 break;
3424
3425 case HCI_EV_FLOW_SPEC_MODIFY_COMPLETE:
3426 hci_flow_spec_modify_complete(hdev, skb);
3427 break;
3428
3429 case HCI_EV_DISCONN_LOG_LINK_COMPLETE:
3430 hci_disconn_log_link_complete_evt(hdev, skb);
3431 break;
3432
3433 case HCI_EV_DISCONN_PHYS_LINK_COMPLETE:
3434 hci_disconn_phy_link_complete_evt(hdev, skb);
3435 hci_amp_event_packet(hdev, event, skb);
3436 break;
3437
3438 case HCI_EV_NUM_COMP_BLOCKS:
3439 hci_num_comp_blocks_evt(hdev, skb);
3440 break;
3441
3442 case HCI_EV_CHANNEL_SELECTED:
3443 hci_amp_event_packet(hdev, event, skb);
3444 break;
3445
3446 case HCI_EV_AMP_STATUS_CHANGE:
3447 hci_amp_event_packet(hdev, event, skb);
3448 break;
3449
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003450 default:
3451 BT_DBG("%s event 0x%x", hdev->name, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 break;
3453 }
3454
3455 kfree_skb(skb);
3456 hdev->stat.evt_rx++;
3457}
3458
3459/* Generate internal stack event */
3460void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data)
3461{
3462 struct hci_event_hdr *hdr;
3463 struct hci_ev_stack_internal *ev;
3464 struct sk_buff *skb;
3465
3466 skb = bt_skb_alloc(HCI_EVENT_HDR_SIZE + sizeof(*ev) + dlen, GFP_ATOMIC);
3467 if (!skb)
3468 return;
3469
3470 hdr = (void *) skb_put(skb, HCI_EVENT_HDR_SIZE);
3471 hdr->evt = HCI_EV_STACK_INTERNAL;
3472 hdr->plen = sizeof(*ev) + dlen;
3473
3474 ev = (void *) skb_put(skb, sizeof(*ev) + dlen);
3475 ev->type = type;
3476 memcpy(ev->data, data, dlen);
3477
Marcel Holtmann576c7d82005-08-06 12:36:54 +02003478 bt_cb(skb)->incoming = 1;
Patrick McHardya61bbcf2005-08-14 17:24:31 -07003479 __net_timestamp(skb);
Marcel Holtmann576c7d82005-08-06 12:36:54 +02003480
Marcel Holtmann0d48d932005-08-09 20:30:28 -07003481 bt_cb(skb)->pkt_type = HCI_EVENT_PKT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 skb->dev = (void *) hdev;
Johan Hedbergeec8d2b2010-12-16 10:17:38 +02003483 hci_send_to_sock(hdev, skb, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 kfree_skb(skb);
3485}