blob: bca71a8b1272d72e0d81c09948bd79b4f0da14e9 [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
Ron Shaffer2d0a0342010-05-28 11:53:46 -04003 Copyright (c) 2000-2001, 2010, 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 <asm/unaligned.h>
28
29#include <net/bluetooth/bluetooth.h>
30#include <net/bluetooth/hci_core.h>
Mikel Astizf0d6a0e2012-08-09 09:52:30 +020031#include <net/bluetooth/mgmt.h>
Andrei Emeltchenko8e2a0d92012-09-27 17:26:08 +030032#include <net/bluetooth/a2mp.h>
Andrei Emeltchenko903e4542012-09-27 17:26:09 +030033#include <net/bluetooth/amp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Linus Torvalds1da177e2005-04-16 15:20:36 -070035/* Handle HCI Event packets */
36
Marcel Holtmanna9de9242007-10-20 13:33:56 +020037static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070038{
Marcel Holtmanna9de9242007-10-20 13:33:56 +020039 __u8 status = *((__u8 *) skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +030041 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Andre Guedese6d465c2011-11-09 17:14:26 -030043 if (status) {
44 hci_dev_lock(hdev);
45 mgmt_stop_discovery_failed(hdev, status);
46 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +020047 return;
Andre Guedese6d465c2011-11-09 17:14:26 -030048 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Andre Guedes89352e72011-11-04 14:16:53 -030050 clear_bit(HCI_INQUIRY, &hdev->flags);
51
Johan Hedberg56e5cb82011-11-08 20:40:16 +020052 hci_dev_lock(hdev);
Johan Hedbergff9ef572012-01-04 14:23:45 +020053 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
Johan Hedberg56e5cb82011-11-08 20:40:16 +020054 hci_dev_unlock(hdev);
Marcel Holtmann6bd57412006-11-18 22:14:22 +010055
Johan Hedberg23bb5762010-12-21 23:01:27 +020056 hci_req_complete(hdev, HCI_OP_INQUIRY_CANCEL, status);
Marcel Holtmann6bd57412006-11-18 22:14:22 +010057
Marcel Holtmanna9de9242007-10-20 13:33:56 +020058 hci_conn_check_pending(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059}
60
Andre Guedes4d934832012-03-21 00:03:35 -030061static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
62{
63 __u8 status = *((__u8 *) skb->data);
64
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +030065 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Andre Guedesae854a72012-03-21 00:03:36 -030066
67 if (status)
68 return;
69
70 set_bit(HCI_PERIODIC_INQ, &hdev->dev_flags);
Andre Guedes4d934832012-03-21 00:03:35 -030071}
72
Marcel Holtmanna9de9242007-10-20 13:33:56 +020073static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Marcel Holtmanna9de9242007-10-20 13:33:56 +020075 __u8 status = *((__u8 *) skb->data);
76
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +030077 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +020078
79 if (status)
80 return;
81
Andre Guedesae854a72012-03-21 00:03:36 -030082 clear_bit(HCI_PERIODIC_INQ, &hdev->dev_flags);
83
Marcel Holtmanna9de9242007-10-20 13:33:56 +020084 hci_conn_check_pending(hdev);
85}
86
Gustavo Padovan807deac2012-05-17 00:36:24 -030087static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev,
88 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +020089{
90 BT_DBG("%s", hdev->name);
91}
92
93static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
94{
95 struct hci_rp_role_discovery *rp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +030098 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200100 if (rp->status)
101 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200103 hci_dev_lock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200105 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
106 if (conn) {
107 if (rp->role)
108 conn->link_mode &= ~HCI_LM_MASTER;
109 else
110 conn->link_mode |= HCI_LM_MASTER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200112
113 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200116static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
117{
118 struct hci_rp_read_link_policy *rp = (void *) skb->data;
119 struct hci_conn *conn;
120
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300121 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200122
123 if (rp->status)
124 return;
125
126 hci_dev_lock(hdev);
127
128 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
129 if (conn)
130 conn->link_policy = __le16_to_cpu(rp->policy);
131
132 hci_dev_unlock(hdev);
133}
134
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200135static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200137 struct hci_rp_write_link_policy *rp = (void *) skb->data;
138 struct hci_conn *conn;
139 void *sent;
140
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300141 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200142
143 if (rp->status)
144 return;
145
146 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
147 if (!sent)
148 return;
149
150 hci_dev_lock(hdev);
151
152 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200153 if (conn)
Harvey Harrison83985312008-05-02 16:25:46 -0700154 conn->link_policy = get_unaligned_le16(sent + 2);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200155
156 hci_dev_unlock(hdev);
157}
158
Gustavo Padovan807deac2012-05-17 00:36:24 -0300159static void hci_cc_read_def_link_policy(struct hci_dev *hdev,
160 struct sk_buff *skb)
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200161{
162 struct hci_rp_read_def_link_policy *rp = (void *) skb->data;
163
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300164 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200165
166 if (rp->status)
167 return;
168
169 hdev->link_policy = __le16_to_cpu(rp->policy);
170}
171
Gustavo Padovan807deac2012-05-17 00:36:24 -0300172static void hci_cc_write_def_link_policy(struct hci_dev *hdev,
173 struct sk_buff *skb)
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200174{
175 __u8 status = *((__u8 *) skb->data);
176 void *sent;
177
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300178 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200179
180 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
181 if (!sent)
182 return;
183
184 if (!status)
185 hdev->link_policy = get_unaligned_le16(sent);
186
Johan Hedberg23bb5762010-12-21 23:01:27 +0200187 hci_req_complete(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, status);
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200188}
189
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200190static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
191{
192 __u8 status = *((__u8 *) skb->data);
193
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300194 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200195
Gustavo F. Padovan10572132011-03-16 15:36:29 -0300196 clear_bit(HCI_RESET, &hdev->flags);
197
Johan Hedberg23bb5762010-12-21 23:01:27 +0200198 hci_req_complete(hdev, HCI_OP_RESET, status);
Andre Guedesd23264a2011-11-25 20:53:38 -0300199
Johan Hedberga297e972012-02-21 17:55:47 +0200200 /* Reset all non-persistent flags */
Andre Guedesae854a72012-03-21 00:03:36 -0300201 hdev->dev_flags &= ~(BIT(HCI_LE_SCAN) | BIT(HCI_PENDING_CLASS) |
202 BIT(HCI_PERIODIC_INQ));
Andre Guedes69775ff2012-02-23 16:50:05 +0200203
204 hdev->discovery.state = DISCOVERY_STOPPED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200205}
206
207static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
208{
209 __u8 status = *((__u8 *) skb->data);
210 void *sent;
211
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300212 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200213
214 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
215 if (!sent)
216 return;
217
Johan Hedberg56e5cb82011-11-08 20:40:16 +0200218 hci_dev_lock(hdev);
219
Johan Hedbergf51d5b22012-02-22 18:17:32 +0200220 if (test_bit(HCI_MGMT, &hdev->dev_flags))
221 mgmt_set_local_name_complete(hdev, sent, status);
Johan Hedberg28cc7bd2012-02-22 21:06:55 +0200222 else if (!status)
223 memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
Johan Hedbergf51d5b22012-02-22 18:17:32 +0200224
Johan Hedberg56e5cb82011-11-08 20:40:16 +0200225 hci_dev_unlock(hdev);
Johan Hedberg3159d382012-02-24 13:47:56 +0200226
227 hci_req_complete(hdev, HCI_OP_WRITE_LOCAL_NAME, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200228}
229
230static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
231{
232 struct hci_rp_read_local_name *rp = (void *) skb->data;
233
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300234 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200235
236 if (rp->status)
237 return;
238
Johan Hedbergdb99b5f2012-02-22 20:14:22 +0200239 if (test_bit(HCI_SETUP, &hdev->dev_flags))
240 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200241}
242
243static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
244{
245 __u8 status = *((__u8 *) skb->data);
246 void *sent;
247
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300248 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200249
250 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
251 if (!sent)
252 return;
253
254 if (!status) {
255 __u8 param = *((__u8 *) sent);
256
257 if (param == AUTH_ENABLED)
258 set_bit(HCI_AUTH, &hdev->flags);
259 else
260 clear_bit(HCI_AUTH, &hdev->flags);
261 }
262
Johan Hedberg33ef95e2012-02-16 23:56:27 +0200263 if (test_bit(HCI_MGMT, &hdev->dev_flags))
264 mgmt_auth_enable_complete(hdev, status);
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
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300274 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200275
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{
Johan Hedberg36f7fc72011-11-04 00:17:45 +0200294 __u8 param, status = *((__u8 *) skb->data);
295 int old_pscan, old_iscan;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200296 void *sent;
297
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300298 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200299
300 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
301 if (!sent)
302 return;
303
Johan Hedberg36f7fc72011-11-04 00:17:45 +0200304 param = *((__u8 *) sent);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200305
Johan Hedberg56e5cb82011-11-08 20:40:16 +0200306 hci_dev_lock(hdev);
307
Mikel Astizfa1bd912012-08-09 09:52:29 +0200308 if (status) {
Johan Hedberg744cf192011-11-08 20:40:14 +0200309 mgmt_write_scan_failed(hdev, param, status);
Johan Hedberg2d7cee52011-11-07 22:16:03 +0200310 hdev->discov_timeout = 0;
311 goto done;
312 }
313
Johan Hedberg36f7fc72011-11-04 00:17:45 +0200314 old_pscan = test_and_clear_bit(HCI_PSCAN, &hdev->flags);
315 old_iscan = test_and_clear_bit(HCI_ISCAN, &hdev->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200316
Johan Hedberg36f7fc72011-11-04 00:17:45 +0200317 if (param & SCAN_INQUIRY) {
318 set_bit(HCI_ISCAN, &hdev->flags);
319 if (!old_iscan)
Johan Hedberg744cf192011-11-08 20:40:14 +0200320 mgmt_discoverable(hdev, 1);
Johan Hedberg16ab91a2011-11-07 22:16:02 +0200321 if (hdev->discov_timeout > 0) {
322 int to = msecs_to_jiffies(hdev->discov_timeout * 1000);
323 queue_delayed_work(hdev->workqueue, &hdev->discov_off,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300324 to);
Johan Hedberg16ab91a2011-11-07 22:16:02 +0200325 }
Johan Hedberg36f7fc72011-11-04 00:17:45 +0200326 } else if (old_iscan)
Johan Hedberg744cf192011-11-08 20:40:14 +0200327 mgmt_discoverable(hdev, 0);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200328
Johan Hedberg36f7fc72011-11-04 00:17:45 +0200329 if (param & SCAN_PAGE) {
330 set_bit(HCI_PSCAN, &hdev->flags);
331 if (!old_pscan)
Johan Hedberg744cf192011-11-08 20:40:14 +0200332 mgmt_connectable(hdev, 1);
Johan Hedberg36f7fc72011-11-04 00:17:45 +0200333 } else if (old_pscan)
Johan Hedberg744cf192011-11-08 20:40:14 +0200334 mgmt_connectable(hdev, 0);
Johan Hedberg36f7fc72011-11-04 00:17:45 +0200335
336done:
Johan Hedberg56e5cb82011-11-08 20:40:16 +0200337 hci_dev_unlock(hdev);
Johan Hedberg23bb5762010-12-21 23:01:27 +0200338 hci_req_complete(hdev, HCI_OP_WRITE_SCAN_ENABLE, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200339}
340
341static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
342{
343 struct hci_rp_read_class_of_dev *rp = (void *) skb->data;
344
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300345 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200346
347 if (rp->status)
348 return;
349
350 memcpy(hdev->dev_class, rp->dev_class, 3);
351
352 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300353 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200354}
355
356static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
357{
358 __u8 status = *((__u8 *) skb->data);
359 void *sent;
360
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300361 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200362
363 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
364 if (!sent)
365 return;
366
Marcel Holtmann7f9a9032012-02-22 18:38:01 +0100367 hci_dev_lock(hdev);
368
369 if (status == 0)
370 memcpy(hdev->dev_class, sent, 3);
371
372 if (test_bit(HCI_MGMT, &hdev->dev_flags))
373 mgmt_set_class_of_dev_complete(hdev, sent, status);
374
375 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200376}
377
378static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
379{
380 struct hci_rp_read_voice_setting *rp = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 __u16 setting;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200382
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300383 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200384
385 if (rp->status)
386 return;
387
388 setting = __le16_to_cpu(rp->voice_setting);
389
Marcel Holtmannf383f272008-07-14 20:13:47 +0200390 if (hdev->voice_setting == setting)
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200391 return;
392
393 hdev->voice_setting = setting;
394
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300395 BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200396
Gustavo F. Padovan3c547112011-12-14 22:58:44 -0200397 if (hdev->notify)
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200398 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200399}
400
Gustavo Padovan8fc9ced2012-05-23 04:04:21 -0300401static void hci_cc_write_voice_setting(struct hci_dev *hdev,
402 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200403{
404 __u8 status = *((__u8 *) skb->data);
Marcel Holtmannf383f272008-07-14 20:13:47 +0200405 __u16 setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 void *sent;
407
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300408 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409
Marcel Holtmannf383f272008-07-14 20:13:47 +0200410 if (status)
411 return;
412
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200413 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
414 if (!sent)
415 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Marcel Holtmannf383f272008-07-14 20:13:47 +0200417 setting = get_unaligned_le16(sent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Marcel Holtmannf383f272008-07-14 20:13:47 +0200419 if (hdev->voice_setting == setting)
420 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Marcel Holtmannf383f272008-07-14 20:13:47 +0200422 hdev->voice_setting = setting;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300424 BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting);
Marcel Holtmannf383f272008-07-14 20:13:47 +0200425
Gustavo F. Padovan3c547112011-12-14 22:58:44 -0200426 if (hdev->notify)
Marcel Holtmannf383f272008-07-14 20:13:47 +0200427 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428}
429
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200430static void hci_cc_host_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200432 __u8 status = *((__u8 *) skb->data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300434 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Johan Hedberg23bb5762010-12-21 23:01:27 +0200436 hci_req_complete(hdev, HCI_OP_HOST_BUFFER_SIZE, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
Marcel Holtmann333140b2008-07-14 20:13:48 +0200439static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
440{
441 __u8 status = *((__u8 *) skb->data);
Johan Hedberg5ed8eb22012-10-25 00:09:51 +0300442 struct hci_cp_write_ssp_mode *sent;
Marcel Holtmann333140b2008-07-14 20:13:48 +0200443
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300444 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmann333140b2008-07-14 20:13:48 +0200445
Marcel Holtmann333140b2008-07-14 20:13:48 +0200446 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
447 if (!sent)
448 return;
449
Johan Hedberg5ed8eb22012-10-25 00:09:51 +0300450 if (!status) {
451 if (sent->mode)
452 hdev->host_features[0] |= LMP_HOST_SSP;
453 else
454 hdev->host_features[0] &= ~LMP_HOST_SSP;
455 }
456
Johan Hedberged2c4ee2012-02-17 00:56:28 +0200457 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg5ed8eb22012-10-25 00:09:51 +0300458 mgmt_ssp_enable_complete(hdev, sent->mode, status);
Johan Hedbergc0ecddc2012-02-22 12:38:31 +0200459 else if (!status) {
Johan Hedberg5ed8eb22012-10-25 00:09:51 +0300460 if (sent->mode)
Johan Hedbergc0ecddc2012-02-22 12:38:31 +0200461 set_bit(HCI_SSP_ENABLED, &hdev->dev_flags);
462 else
463 clear_bit(HCI_SSP_ENABLED, &hdev->dev_flags);
464 }
Marcel Holtmann333140b2008-07-14 20:13:48 +0200465}
466
Johan Hedbergd5859e22011-01-25 01:19:58 +0200467static u8 hci_get_inquiry_mode(struct hci_dev *hdev)
468{
Johan Hedberg976eb202012-10-24 21:12:01 +0300469 if (lmp_ext_inq_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200470 return 2;
471
Johan Hedberg976eb202012-10-24 21:12:01 +0300472 if (lmp_inq_rssi_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200473 return 1;
474
475 if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 &&
Gustavo Padovan807deac2012-05-17 00:36:24 -0300476 hdev->lmp_subver == 0x0757)
Johan Hedbergd5859e22011-01-25 01:19:58 +0200477 return 1;
478
479 if (hdev->manufacturer == 15) {
480 if (hdev->hci_rev == 0x03 && hdev->lmp_subver == 0x6963)
481 return 1;
482 if (hdev->hci_rev == 0x09 && hdev->lmp_subver == 0x6963)
483 return 1;
484 if (hdev->hci_rev == 0x00 && hdev->lmp_subver == 0x6965)
485 return 1;
486 }
487
488 if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 &&
Gustavo Padovan807deac2012-05-17 00:36:24 -0300489 hdev->lmp_subver == 0x1805)
Johan Hedbergd5859e22011-01-25 01:19:58 +0200490 return 1;
491
492 return 0;
493}
494
495static void hci_setup_inquiry_mode(struct hci_dev *hdev)
496{
497 u8 mode;
498
499 mode = hci_get_inquiry_mode(hdev);
500
501 hci_send_cmd(hdev, HCI_OP_WRITE_INQUIRY_MODE, 1, &mode);
502}
503
504static void hci_setup_event_mask(struct hci_dev *hdev)
505{
506 /* The second byte is 0xff instead of 0x9f (two reserved bits
507 * disabled) since a Broadcom 1.2 dongle doesn't respond to the
508 * command otherwise */
509 u8 events[8] = { 0xff, 0xff, 0xfb, 0xff, 0x00, 0x00, 0x00, 0x00 };
510
Ville Tervo6de6c182011-05-27 11:16:21 +0300511 /* CSR 1.1 dongles does not accept any bitfield so don't try to set
512 * any event mask for pre 1.2 devices */
Andrei Emeltchenko5a13b092011-12-01 14:33:28 +0200513 if (hdev->hci_ver < BLUETOOTH_VER_1_2)
Ville Tervo6de6c182011-05-27 11:16:21 +0300514 return;
515
Johan Hedberge1171e82012-10-19 20:57:45 +0300516 if (lmp_bredr_capable(hdev)) {
517 events[4] |= 0x01; /* Flow Specification Complete */
518 events[4] |= 0x02; /* Inquiry Result with RSSI */
519 events[4] |= 0x04; /* Read Remote Extended Features Complete */
520 events[5] |= 0x08; /* Synchronous Connection Complete */
521 events[5] |= 0x10; /* Synchronous Connection Changed */
522 }
Johan Hedbergd5859e22011-01-25 01:19:58 +0200523
Johan Hedberg976eb202012-10-24 21:12:01 +0300524 if (lmp_inq_rssi_capable(hdev))
Johan Hedberga24299e2012-04-26 09:47:46 +0300525 events[4] |= 0x02; /* Inquiry Result with RSSI */
Johan Hedbergd5859e22011-01-25 01:19:58 +0200526
Andre Guedes999dcd12012-07-24 15:03:52 -0300527 if (lmp_sniffsubr_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200528 events[5] |= 0x20; /* Sniff Subrating */
529
Johan Hedberg976eb202012-10-24 21:12:01 +0300530 if (lmp_pause_enc_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200531 events[5] |= 0x80; /* Encryption Key Refresh Complete */
532
Johan Hedberg976eb202012-10-24 21:12:01 +0300533 if (lmp_ext_inq_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200534 events[5] |= 0x40; /* Extended Inquiry Result */
535
Andre Guedesc58e8102012-07-24 15:03:53 -0300536 if (lmp_no_flush_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200537 events[7] |= 0x01; /* Enhanced Flush Complete */
538
Johan Hedberg976eb202012-10-24 21:12:01 +0300539 if (lmp_lsto_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200540 events[6] |= 0x80; /* Link Supervision Timeout Changed */
541
Andre Guedes9a1a1992012-07-24 15:03:48 -0300542 if (lmp_ssp_capable(hdev)) {
Johan Hedbergd5859e22011-01-25 01:19:58 +0200543 events[6] |= 0x01; /* IO Capability Request */
544 events[6] |= 0x02; /* IO Capability Response */
545 events[6] |= 0x04; /* User Confirmation Request */
546 events[6] |= 0x08; /* User Passkey Request */
547 events[6] |= 0x10; /* Remote OOB Data Request */
548 events[6] |= 0x20; /* Simple Pairing Complete */
549 events[7] |= 0x04; /* User Passkey Notification */
550 events[7] |= 0x08; /* Keypress Notification */
551 events[7] |= 0x10; /* Remote Host Supported
552 * Features Notification */
553 }
554
Andre Guedesc383ddc2012-07-24 15:03:47 -0300555 if (lmp_le_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200556 events[7] |= 0x20; /* LE Meta-Event */
557
558 hci_send_cmd(hdev, HCI_OP_SET_EVENT_MASK, sizeof(events), events);
Johan Hedberge36b04c2012-10-19 20:57:47 +0300559
560 if (lmp_le_capable(hdev)) {
561 memset(events, 0, sizeof(events));
562 events[0] = 0x1f;
563 hci_send_cmd(hdev, HCI_OP_LE_SET_EVENT_MASK,
564 sizeof(events), events);
565 }
Johan Hedbergd5859e22011-01-25 01:19:58 +0200566}
567
Gustavo Padovan4611dfa2012-10-24 11:18:41 -0200568static void bredr_setup(struct hci_dev *hdev)
Johan Hedberge1171e82012-10-19 20:57:45 +0300569{
570 struct hci_cp_delete_stored_link_key cp;
571 __le16 param;
572 __u8 flt_type;
573
574 /* Read Buffer Size (ACL mtu, max pkt, etc.) */
575 hci_send_cmd(hdev, HCI_OP_READ_BUFFER_SIZE, 0, NULL);
576
577 /* Read Class of Device */
578 hci_send_cmd(hdev, HCI_OP_READ_CLASS_OF_DEV, 0, NULL);
579
580 /* Read Local Name */
581 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_NAME, 0, NULL);
582
583 /* Read Voice Setting */
584 hci_send_cmd(hdev, HCI_OP_READ_VOICE_SETTING, 0, NULL);
585
586 /* Clear Event Filters */
587 flt_type = HCI_FLT_CLEAR_ALL;
588 hci_send_cmd(hdev, HCI_OP_SET_EVENT_FLT, 1, &flt_type);
589
590 /* Connection accept timeout ~20 secs */
591 param = __constant_cpu_to_le16(0x7d00);
592 hci_send_cmd(hdev, HCI_OP_WRITE_CA_TIMEOUT, 2, &param);
593
594 bacpy(&cp.bdaddr, BDADDR_ANY);
595 cp.delete_all = 1;
596 hci_send_cmd(hdev, HCI_OP_DELETE_STORED_LINK_KEY, sizeof(cp), &cp);
597}
598
Gustavo Padovan4611dfa2012-10-24 11:18:41 -0200599static void le_setup(struct hci_dev *hdev)
Johan Hedberge1171e82012-10-19 20:57:45 +0300600{
601 /* Read LE Buffer Size */
602 hci_send_cmd(hdev, HCI_OP_LE_READ_BUFFER_SIZE, 0, NULL);
Johan Hedberg8fa19092012-10-19 20:57:49 +0300603
604 /* Read LE Advertising Channel TX Power */
605 hci_send_cmd(hdev, HCI_OP_LE_READ_ADV_TX_POWER, 0, NULL);
Johan Hedberge1171e82012-10-19 20:57:45 +0300606}
607
Johan Hedbergd5859e22011-01-25 01:19:58 +0200608static void hci_setup(struct hci_dev *hdev)
609{
Andrei Emeltchenkoe61ef4992011-12-19 16:31:27 +0200610 if (hdev->dev_type != HCI_BREDR)
611 return;
612
Johan Hedberge1171e82012-10-19 20:57:45 +0300613 /* Read BD Address */
614 hci_send_cmd(hdev, HCI_OP_READ_BD_ADDR, 0, NULL);
615
616 if (lmp_bredr_capable(hdev))
Gustavo Padovan4611dfa2012-10-24 11:18:41 -0200617 bredr_setup(hdev);
Johan Hedberge1171e82012-10-19 20:57:45 +0300618
619 if (lmp_le_capable(hdev))
Gustavo Padovan4611dfa2012-10-24 11:18:41 -0200620 le_setup(hdev);
Johan Hedberge1171e82012-10-19 20:57:45 +0300621
Johan Hedbergd5859e22011-01-25 01:19:58 +0200622 hci_setup_event_mask(hdev);
623
Andrei Emeltchenkod095c1e2011-12-01 14:33:27 +0200624 if (hdev->hci_ver > BLUETOOTH_VER_1_1)
Johan Hedbergd5859e22011-01-25 01:19:58 +0200625 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL);
626
Gustavo Padovan6d3c7302012-05-24 03:36:37 -0300627 if (lmp_ssp_capable(hdev)) {
Johan Hedberg54d04db2012-02-22 15:47:48 +0200628 if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) {
629 u8 mode = 0x01;
630 hci_send_cmd(hdev, HCI_OP_WRITE_SSP_MODE,
Gustavo F. Padovan04124682012-03-08 01:25:00 -0300631 sizeof(mode), &mode);
Johan Hedberg54d04db2012-02-22 15:47:48 +0200632 } else {
633 struct hci_cp_write_eir cp;
634
635 memset(hdev->eir, 0, sizeof(hdev->eir));
636 memset(&cp, 0, sizeof(cp));
637
638 hci_send_cmd(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp);
639 }
Johan Hedbergd5859e22011-01-25 01:19:58 +0200640 }
641
Johan Hedberg976eb202012-10-24 21:12:01 +0300642 if (lmp_inq_rssi_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200643 hci_setup_inquiry_mode(hdev);
644
Johan Hedberg976eb202012-10-24 21:12:01 +0300645 if (lmp_inq_tx_pwr_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200646 hci_send_cmd(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, 0, NULL);
Andre Guedes971e3a42011-06-30 19:20:52 -0300647
Johan Hedberg976eb202012-10-24 21:12:01 +0300648 if (lmp_ext_feat_capable(hdev)) {
Andre Guedes971e3a42011-06-30 19:20:52 -0300649 struct hci_cp_read_local_ext_features cp;
650
651 cp.page = 0x01;
Gustavo F. Padovan04124682012-03-08 01:25:00 -0300652 hci_send_cmd(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, sizeof(cp),
653 &cp);
Andre Guedes971e3a42011-06-30 19:20:52 -0300654 }
Andre Guedese6100a22011-06-30 19:20:54 -0300655
Johan Hedberg47990ea2012-02-22 11:58:37 +0200656 if (test_bit(HCI_LINK_SECURITY, &hdev->dev_flags)) {
657 u8 enable = 1;
Gustavo F. Padovan04124682012-03-08 01:25:00 -0300658 hci_send_cmd(hdev, HCI_OP_WRITE_AUTH_ENABLE, sizeof(enable),
659 &enable);
Johan Hedberg47990ea2012-02-22 11:58:37 +0200660 }
Johan Hedbergd5859e22011-01-25 01:19:58 +0200661}
662
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200663static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
664{
665 struct hci_rp_read_local_version *rp = (void *) skb->data;
666
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300667 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200668
669 if (rp->status)
Andrei Emeltchenko28b8df72012-02-24 12:45:44 +0200670 goto done;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200671
672 hdev->hci_ver = rp->hci_ver;
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200673 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200674 hdev->lmp_ver = rp->lmp_ver;
Marcel Holtmanne4e8e372008-07-14 20:13:47 +0200675 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200676 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200677
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300678 BT_DBG("%s manufacturer 0x%4.4x hci ver %d:%d", hdev->name,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300679 hdev->manufacturer, hdev->hci_ver, hdev->hci_rev);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200680
681 if (test_bit(HCI_INIT, &hdev->flags))
682 hci_setup(hdev);
Andrei Emeltchenko28b8df72012-02-24 12:45:44 +0200683
684done:
685 hci_req_complete(hdev, HCI_OP_READ_LOCAL_VERSION, rp->status);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200686}
687
688static void hci_setup_link_policy(struct hci_dev *hdev)
689{
Andrei Emeltchenko035100c2012-03-12 15:59:32 +0200690 struct hci_cp_write_def_link_policy cp;
Johan Hedbergd5859e22011-01-25 01:19:58 +0200691 u16 link_policy = 0;
692
Andre Guedes9f92ebf2012-07-24 15:03:50 -0300693 if (lmp_rswitch_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200694 link_policy |= HCI_LP_RSWITCH;
Johan Hedberg976eb202012-10-24 21:12:01 +0300695 if (lmp_hold_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200696 link_policy |= HCI_LP_HOLD;
Andre Guedes6eded102012-07-24 15:03:51 -0300697 if (lmp_sniff_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200698 link_policy |= HCI_LP_SNIFF;
Johan Hedberg976eb202012-10-24 21:12:01 +0300699 if (lmp_park_capable(hdev))
Johan Hedbergd5859e22011-01-25 01:19:58 +0200700 link_policy |= HCI_LP_PARK;
701
Andrei Emeltchenko035100c2012-03-12 15:59:32 +0200702 cp.policy = cpu_to_le16(link_policy);
703 hci_send_cmd(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, sizeof(cp), &cp);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200704}
705
Gustavo Padovan8fc9ced2012-05-23 04:04:21 -0300706static void hci_cc_read_local_commands(struct hci_dev *hdev,
707 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200708{
709 struct hci_rp_read_local_commands *rp = (void *) skb->data;
710
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300711 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200712
713 if (rp->status)
Johan Hedbergd5859e22011-01-25 01:19:58 +0200714 goto done;
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200715
716 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
Johan Hedbergd5859e22011-01-25 01:19:58 +0200717
718 if (test_bit(HCI_INIT, &hdev->flags) && (hdev->commands[5] & 0x10))
719 hci_setup_link_policy(hdev);
720
721done:
722 hci_req_complete(hdev, HCI_OP_READ_LOCAL_COMMANDS, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200723}
724
Gustavo Padovan8fc9ced2012-05-23 04:04:21 -0300725static void hci_cc_read_local_features(struct hci_dev *hdev,
726 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200727{
728 struct hci_rp_read_local_features *rp = (void *) skb->data;
729
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300730 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200731
732 if (rp->status)
733 return;
734
735 memcpy(hdev->features, rp->features, 8);
736
737 /* Adjust default settings according to features
738 * supported by device. */
739
740 if (hdev->features[0] & LMP_3SLOT)
741 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
742
743 if (hdev->features[0] & LMP_5SLOT)
744 hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
745
746 if (hdev->features[1] & LMP_HV2) {
747 hdev->pkt_type |= (HCI_HV2);
748 hdev->esco_type |= (ESCO_HV2);
749 }
750
751 if (hdev->features[1] & LMP_HV3) {
752 hdev->pkt_type |= (HCI_HV3);
753 hdev->esco_type |= (ESCO_HV3);
754 }
755
Andre Guedes45db810f2012-07-24 15:03:49 -0300756 if (lmp_esco_capable(hdev))
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200757 hdev->esco_type |= (ESCO_EV3);
758
759 if (hdev->features[4] & LMP_EV4)
760 hdev->esco_type |= (ESCO_EV4);
761
762 if (hdev->features[4] & LMP_EV5)
763 hdev->esco_type |= (ESCO_EV5);
764
Marcel Holtmannefc76882009-02-06 09:13:37 +0100765 if (hdev->features[5] & LMP_EDR_ESCO_2M)
766 hdev->esco_type |= (ESCO_2EV3);
767
768 if (hdev->features[5] & LMP_EDR_ESCO_3M)
769 hdev->esco_type |= (ESCO_3EV3);
770
771 if (hdev->features[5] & LMP_EDR_3S_ESCO)
772 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
773
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200774 BT_DBG("%s features 0x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x", hdev->name,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300775 hdev->features[0], hdev->features[1],
776 hdev->features[2], hdev->features[3],
777 hdev->features[4], hdev->features[5],
778 hdev->features[6], hdev->features[7]);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200779}
780
Johan Hedberg8f984df2012-02-28 01:07:22 +0200781static void hci_set_le_support(struct hci_dev *hdev)
782{
783 struct hci_cp_write_le_host_supported cp;
784
785 memset(&cp, 0, sizeof(cp));
786
Marcel Holtmann9d428202012-05-03 07:12:31 +0200787 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) {
Johan Hedberg8f984df2012-02-28 01:07:22 +0200788 cp.le = 1;
Johan Hedberg976eb202012-10-24 21:12:01 +0300789 cp.simul = !!lmp_le_br_capable(hdev);
Johan Hedberg8f984df2012-02-28 01:07:22 +0200790 }
791
Johan Hedberg976eb202012-10-24 21:12:01 +0300792 if (cp.le != !!lmp_host_le_capable(hdev))
Gustavo F. Padovan04124682012-03-08 01:25:00 -0300793 hci_send_cmd(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, sizeof(cp),
794 &cp);
Johan Hedberg8f984df2012-02-28 01:07:22 +0200795}
796
Andre Guedes971e3a42011-06-30 19:20:52 -0300797static void hci_cc_read_local_ext_features(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300798 struct sk_buff *skb)
Andre Guedes971e3a42011-06-30 19:20:52 -0300799{
800 struct hci_rp_read_local_ext_features *rp = (void *) skb->data;
801
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300802 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Andre Guedes971e3a42011-06-30 19:20:52 -0300803
804 if (rp->status)
Johan Hedberg8f984df2012-02-28 01:07:22 +0200805 goto done;
Andre Guedes971e3a42011-06-30 19:20:52 -0300806
Andre Guedesb5b32b62011-12-30 10:34:04 -0300807 switch (rp->page) {
808 case 0:
809 memcpy(hdev->features, rp->features, 8);
810 break;
811 case 1:
812 memcpy(hdev->host_features, rp->features, 8);
813 break;
814 }
Andre Guedes971e3a42011-06-30 19:20:52 -0300815
Andre Guedesc383ddc2012-07-24 15:03:47 -0300816 if (test_bit(HCI_INIT, &hdev->flags) && lmp_le_capable(hdev))
Johan Hedberg8f984df2012-02-28 01:07:22 +0200817 hci_set_le_support(hdev);
818
819done:
Andre Guedes971e3a42011-06-30 19:20:52 -0300820 hci_req_complete(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, rp->status);
821}
822
Andrei Emeltchenko1e89cff2011-11-24 14:52:02 +0200823static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300824 struct sk_buff *skb)
Andrei Emeltchenko1e89cff2011-11-24 14:52:02 +0200825{
826 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
827
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300828 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Andrei Emeltchenko1e89cff2011-11-24 14:52:02 +0200829
830 if (rp->status)
831 return;
832
833 hdev->flow_ctl_mode = rp->mode;
834
835 hci_req_complete(hdev, HCI_OP_READ_FLOW_CONTROL_MODE, rp->status);
836}
837
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200838static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
839{
840 struct hci_rp_read_buffer_size *rp = (void *) skb->data;
841
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300842 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200843
844 if (rp->status)
845 return;
846
847 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
848 hdev->sco_mtu = rp->sco_mtu;
849 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
850 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
851
852 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
853 hdev->sco_mtu = 64;
854 hdev->sco_pkts = 8;
855 }
856
857 hdev->acl_cnt = hdev->acl_pkts;
858 hdev->sco_cnt = hdev->sco_pkts;
859
Gustavo Padovan807deac2012-05-17 00:36:24 -0300860 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu,
861 hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200862}
863
864static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
865{
866 struct hci_rp_read_bd_addr *rp = (void *) skb->data;
867
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300868 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200869
870 if (!rp->status)
871 bacpy(&hdev->bdaddr, &rp->bdaddr);
872
Johan Hedberg23bb5762010-12-21 23:01:27 +0200873 hci_req_complete(hdev, HCI_OP_READ_BD_ADDR, rp->status);
874}
875
Andrei Emeltchenko350ee4c2011-12-07 15:56:51 +0200876static void hci_cc_read_data_block_size(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300877 struct sk_buff *skb)
Andrei Emeltchenko350ee4c2011-12-07 15:56:51 +0200878{
879 struct hci_rp_read_data_block_size *rp = (void *) skb->data;
880
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300881 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Andrei Emeltchenko350ee4c2011-12-07 15:56:51 +0200882
883 if (rp->status)
884 return;
885
886 hdev->block_mtu = __le16_to_cpu(rp->max_acl_len);
887 hdev->block_len = __le16_to_cpu(rp->block_len);
888 hdev->num_blocks = __le16_to_cpu(rp->num_blocks);
889
890 hdev->block_cnt = hdev->num_blocks;
891
892 BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300893 hdev->block_cnt, hdev->block_len);
Andrei Emeltchenko350ee4c2011-12-07 15:56:51 +0200894
895 hci_req_complete(hdev, HCI_OP_READ_DATA_BLOCK_SIZE, rp->status);
896}
897
Johan Hedberg23bb5762010-12-21 23:01:27 +0200898static void hci_cc_write_ca_timeout(struct hci_dev *hdev, struct sk_buff *skb)
899{
900 __u8 status = *((__u8 *) skb->data);
901
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300902 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Johan Hedberg23bb5762010-12-21 23:01:27 +0200903
904 hci_req_complete(hdev, HCI_OP_WRITE_CA_TIMEOUT, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +0200905}
906
Andrei Emeltchenko928abaa2011-10-12 10:53:57 +0300907static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300908 struct sk_buff *skb)
Andrei Emeltchenko928abaa2011-10-12 10:53:57 +0300909{
910 struct hci_rp_read_local_amp_info *rp = (void *) skb->data;
911
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300912 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Andrei Emeltchenko928abaa2011-10-12 10:53:57 +0300913
914 if (rp->status)
Andrei Emeltchenko8e2a0d92012-09-27 17:26:08 +0300915 goto a2mp_rsp;
Andrei Emeltchenko928abaa2011-10-12 10:53:57 +0300916
917 hdev->amp_status = rp->amp_status;
918 hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
919 hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
920 hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
921 hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
922 hdev->amp_type = rp->amp_type;
923 hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
924 hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
925 hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
926 hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
927
928 hci_req_complete(hdev, HCI_OP_READ_LOCAL_AMP_INFO, rp->status);
Andrei Emeltchenko8e2a0d92012-09-27 17:26:08 +0300929
930a2mp_rsp:
931 a2mp_send_getinfo_rsp(hdev);
Andrei Emeltchenko928abaa2011-10-12 10:53:57 +0300932}
933
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300934static void hci_cc_read_local_amp_assoc(struct hci_dev *hdev,
935 struct sk_buff *skb)
936{
937 struct hci_rp_read_local_amp_assoc *rp = (void *) skb->data;
938 struct amp_assoc *assoc = &hdev->loc_assoc;
939 size_t rem_len, frag_len;
940
941 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
942
943 if (rp->status)
944 goto a2mp_rsp;
945
946 frag_len = skb->len - sizeof(*rp);
947 rem_len = __le16_to_cpu(rp->rem_len);
948
949 if (rem_len > frag_len) {
Andrei Emeltchenko2e430be32012-09-28 14:44:23 +0300950 BT_DBG("frag_len %zu rem_len %zu", frag_len, rem_len);
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300951
952 memcpy(assoc->data + assoc->offset, rp->frag, frag_len);
953 assoc->offset += frag_len;
954
955 /* Read other fragments */
956 amp_read_loc_assoc_frag(hdev, rp->phy_handle);
957
958 return;
959 }
960
961 memcpy(assoc->data + assoc->offset, rp->frag, rem_len);
962 assoc->len = assoc->offset + rem_len;
963 assoc->offset = 0;
964
965a2mp_rsp:
966 /* Send A2MP Rsp when all fragments are received */
967 a2mp_send_getampassoc_rsp(hdev, rp->status);
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +0300968 a2mp_send_create_phy_link_req(hdev, rp->status);
Andrei Emeltchenko903e4542012-09-27 17:26:09 +0300969}
970
Johan Hedbergb0916ea2011-01-10 13:44:55 +0200971static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300972 struct sk_buff *skb)
Johan Hedbergb0916ea2011-01-10 13:44:55 +0200973{
974 __u8 status = *((__u8 *) skb->data);
975
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300976 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Johan Hedbergb0916ea2011-01-10 13:44:55 +0200977
978 hci_req_complete(hdev, HCI_OP_DELETE_STORED_LINK_KEY, status);
979}
980
Johan Hedbergd5859e22011-01-25 01:19:58 +0200981static void hci_cc_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb)
982{
983 __u8 status = *((__u8 *) skb->data);
984
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300985 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200986
987 hci_req_complete(hdev, HCI_OP_SET_EVENT_MASK, status);
988}
989
990static void hci_cc_write_inquiry_mode(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -0300991 struct sk_buff *skb)
Johan Hedbergd5859e22011-01-25 01:19:58 +0200992{
993 __u8 status = *((__u8 *) skb->data);
994
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +0300995 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Johan Hedbergd5859e22011-01-25 01:19:58 +0200996
997 hci_req_complete(hdev, HCI_OP_WRITE_INQUIRY_MODE, status);
998}
999
1000static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -03001001 struct sk_buff *skb)
Johan Hedbergd5859e22011-01-25 01:19:58 +02001002{
Marcel Holtmann91c4e9b2012-03-11 19:27:21 -07001003 struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data;
Johan Hedbergd5859e22011-01-25 01:19:58 +02001004
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001005 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Johan Hedbergd5859e22011-01-25 01:19:58 +02001006
Marcel Holtmann91c4e9b2012-03-11 19:27:21 -07001007 if (!rp->status)
1008 hdev->inq_tx_power = rp->tx_power;
1009
1010 hci_req_complete(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, rp->status);
Johan Hedbergd5859e22011-01-25 01:19:58 +02001011}
1012
1013static void hci_cc_set_event_flt(struct hci_dev *hdev, struct sk_buff *skb)
1014{
1015 __u8 status = *((__u8 *) skb->data);
1016
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001017 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Johan Hedbergd5859e22011-01-25 01:19:58 +02001018
1019 hci_req_complete(hdev, HCI_OP_SET_EVENT_FLT, status);
1020}
1021
Johan Hedberg980e1a52011-01-22 06:10:07 +02001022static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb)
1023{
1024 struct hci_rp_pin_code_reply *rp = (void *) skb->data;
1025 struct hci_cp_pin_code_reply *cp;
1026 struct hci_conn *conn;
1027
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001028 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Johan Hedberg980e1a52011-01-22 06:10:07 +02001029
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001030 hci_dev_lock(hdev);
1031
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02001032 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg744cf192011-11-08 20:40:14 +02001033 mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status);
Johan Hedberg980e1a52011-01-22 06:10:07 +02001034
Mikel Astizfa1bd912012-08-09 09:52:29 +02001035 if (rp->status)
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001036 goto unlock;
Johan Hedberg980e1a52011-01-22 06:10:07 +02001037
1038 cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
1039 if (!cp)
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001040 goto unlock;
Johan Hedberg980e1a52011-01-22 06:10:07 +02001041
1042 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1043 if (conn)
1044 conn->pin_length = cp->pin_len;
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001045
1046unlock:
1047 hci_dev_unlock(hdev);
Johan Hedberg980e1a52011-01-22 06:10:07 +02001048}
1049
1050static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
1051{
1052 struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data;
1053
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001054 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Johan Hedberg980e1a52011-01-22 06:10:07 +02001055
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001056 hci_dev_lock(hdev);
1057
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02001058 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg744cf192011-11-08 20:40:14 +02001059 mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr,
Gustavo Padovan807deac2012-05-17 00:36:24 -03001060 rp->status);
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001061
1062 hci_dev_unlock(hdev);
Johan Hedberg980e1a52011-01-22 06:10:07 +02001063}
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001064
Ville Tervo6ed58ec2011-02-10 22:38:48 -03001065static void hci_cc_le_read_buffer_size(struct hci_dev *hdev,
1066 struct sk_buff *skb)
1067{
1068 struct hci_rp_le_read_buffer_size *rp = (void *) skb->data;
1069
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001070 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Ville Tervo6ed58ec2011-02-10 22:38:48 -03001071
1072 if (rp->status)
1073 return;
1074
1075 hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
1076 hdev->le_pkts = rp->le_max_pkt;
1077
1078 hdev->le_cnt = hdev->le_pkts;
1079
1080 BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
1081
1082 hci_req_complete(hdev, HCI_OP_LE_READ_BUFFER_SIZE, rp->status);
1083}
Johan Hedberg980e1a52011-01-22 06:10:07 +02001084
Johan Hedberg8fa19092012-10-19 20:57:49 +03001085static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
1086 struct sk_buff *skb)
1087{
1088 struct hci_rp_le_read_adv_tx_power *rp = (void *) skb->data;
1089
1090 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1091
1092 if (!rp->status)
1093 hdev->adv_tx_power = rp->tx_power;
1094
1095 hci_req_complete(hdev, HCI_OP_LE_READ_ADV_TX_POWER, rp->status);
1096}
1097
Johan Hedberge36b04c2012-10-19 20:57:47 +03001098static void hci_cc_le_set_event_mask(struct hci_dev *hdev, struct sk_buff *skb)
1099{
1100 __u8 status = *((__u8 *) skb->data);
1101
1102 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1103
1104 hci_req_complete(hdev, HCI_OP_LE_SET_EVENT_MASK, status);
1105}
1106
Johan Hedberga5c29682011-02-19 12:05:57 -03001107static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
1108{
1109 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1110
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001111 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Johan Hedberga5c29682011-02-19 12:05:57 -03001112
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001113 hci_dev_lock(hdev);
1114
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02001115 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001116 mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0,
1117 rp->status);
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001118
1119 hci_dev_unlock(hdev);
Johan Hedberga5c29682011-02-19 12:05:57 -03001120}
1121
1122static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -03001123 struct sk_buff *skb)
Johan Hedberga5c29682011-02-19 12:05:57 -03001124{
1125 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1126
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001127 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Johan Hedberga5c29682011-02-19 12:05:57 -03001128
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001129 hci_dev_lock(hdev);
1130
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02001131 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg744cf192011-11-08 20:40:14 +02001132 mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001133 ACL_LINK, 0, rp->status);
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001134
1135 hci_dev_unlock(hdev);
Johan Hedberga5c29682011-02-19 12:05:57 -03001136}
1137
Brian Gix1143d452011-11-23 08:28:34 -08001138static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb)
1139{
1140 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1141
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001142 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Brian Gix1143d452011-11-23 08:28:34 -08001143
1144 hci_dev_lock(hdev);
1145
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02001146 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg272d90d2012-02-09 15:26:12 +02001147 mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001148 0, rp->status);
Brian Gix1143d452011-11-23 08:28:34 -08001149
1150 hci_dev_unlock(hdev);
1151}
1152
1153static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -03001154 struct sk_buff *skb)
Brian Gix1143d452011-11-23 08:28:34 -08001155{
1156 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1157
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001158 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Brian Gix1143d452011-11-23 08:28:34 -08001159
1160 hci_dev_lock(hdev);
1161
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02001162 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Brian Gix1143d452011-11-23 08:28:34 -08001163 mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001164 ACL_LINK, 0, rp->status);
Brian Gix1143d452011-11-23 08:28:34 -08001165
1166 hci_dev_unlock(hdev);
1167}
1168
Szymon Jancc35938b2011-03-22 13:12:21 +01001169static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -03001170 struct sk_buff *skb)
Szymon Jancc35938b2011-03-22 13:12:21 +01001171{
1172 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
1173
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001174 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Szymon Jancc35938b2011-03-22 13:12:21 +01001175
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001176 hci_dev_lock(hdev);
Johan Hedberg744cf192011-11-08 20:40:14 +02001177 mgmt_read_local_oob_data_reply_complete(hdev, rp->hash,
Szymon Jancc35938b2011-03-22 13:12:21 +01001178 rp->randomizer, rp->status);
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001179 hci_dev_unlock(hdev);
Szymon Jancc35938b2011-03-22 13:12:21 +01001180}
1181
Andre Guedes07f7fa52011-12-02 21:13:31 +09001182static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
1183{
1184 __u8 status = *((__u8 *) skb->data);
1185
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001186 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Andre Guedes7ba8b4b2012-02-03 17:47:59 -03001187
1188 hci_req_complete(hdev, HCI_OP_LE_SET_SCAN_PARAM, status);
Andre Guedes3fd24152012-02-03 17:48:01 -03001189
1190 if (status) {
1191 hci_dev_lock(hdev);
1192 mgmt_start_discovery_failed(hdev, status);
1193 hci_dev_unlock(hdev);
1194 return;
1195 }
Andre Guedes07f7fa52011-12-02 21:13:31 +09001196}
1197
Andre Guedeseb9d91f2011-05-26 16:23:52 -03001198static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -03001199 struct sk_buff *skb)
Andre Guedeseb9d91f2011-05-26 16:23:52 -03001200{
1201 struct hci_cp_le_set_scan_enable *cp;
1202 __u8 status = *((__u8 *) skb->data);
1203
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001204 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Andre Guedeseb9d91f2011-05-26 16:23:52 -03001205
Andre Guedeseb9d91f2011-05-26 16:23:52 -03001206 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
1207 if (!cp)
1208 return;
1209
Andrei Emeltchenko68a8aea2011-12-19 16:14:18 +02001210 switch (cp->enable) {
1211 case LE_SCANNING_ENABLED:
Andre Guedes7ba8b4b2012-02-03 17:47:59 -03001212 hci_req_complete(hdev, HCI_OP_LE_SET_SCAN_ENABLE, status);
1213
Andre Guedes3fd24152012-02-03 17:48:01 -03001214 if (status) {
1215 hci_dev_lock(hdev);
1216 mgmt_start_discovery_failed(hdev, status);
1217 hci_dev_unlock(hdev);
Andre Guedes7ba8b4b2012-02-03 17:47:59 -03001218 return;
Andre Guedes3fd24152012-02-03 17:48:01 -03001219 }
Andre Guedes7ba8b4b2012-02-03 17:47:59 -03001220
Andre Guedesd23264a2011-11-25 20:53:38 -03001221 set_bit(HCI_LE_SCAN, &hdev->dev_flags);
1222
Andre Guedesa8f13c82011-09-09 18:56:24 -03001223 hci_dev_lock(hdev);
Andre Guedes343f9352012-02-17 20:39:37 -03001224 hci_discovery_set_state(hdev, DISCOVERY_FINDING);
Andre Guedesa8f13c82011-09-09 18:56:24 -03001225 hci_dev_unlock(hdev);
Andrei Emeltchenko68a8aea2011-12-19 16:14:18 +02001226 break;
1227
1228 case LE_SCANNING_DISABLED:
Andre Guedesc9ecc482012-03-15 16:52:08 -03001229 if (status) {
1230 hci_dev_lock(hdev);
1231 mgmt_stop_discovery_failed(hdev, status);
1232 hci_dev_unlock(hdev);
Andre Guedes7ba8b4b2012-02-03 17:47:59 -03001233 return;
Andre Guedesc9ecc482012-03-15 16:52:08 -03001234 }
Andre Guedes7ba8b4b2012-02-03 17:47:59 -03001235
Andre Guedesd23264a2011-11-25 20:53:38 -03001236 clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
1237
Andre Guedesbc3dd332012-03-06 19:37:06 -03001238 if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED &&
1239 hdev->discovery.state == DISCOVERY_FINDING) {
Andre Guedes5e0452c2012-02-17 20:39:38 -03001240 mgmt_interleaved_discovery(hdev);
1241 } else {
1242 hci_dev_lock(hdev);
1243 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1244 hci_dev_unlock(hdev);
1245 }
1246
Andrei Emeltchenko68a8aea2011-12-19 16:14:18 +02001247 break;
1248
1249 default:
1250 BT_ERR("Used reserved LE_Scan_Enable param %d", cp->enable);
1251 break;
Andre Guedes35815082011-05-26 16:23:53 -03001252 }
Andre Guedeseb9d91f2011-05-26 16:23:52 -03001253}
1254
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03001255static void hci_cc_le_ltk_reply(struct hci_dev *hdev, struct sk_buff *skb)
1256{
1257 struct hci_rp_le_ltk_reply *rp = (void *) skb->data;
1258
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001259 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03001260
1261 if (rp->status)
1262 return;
1263
1264 hci_req_complete(hdev, HCI_OP_LE_LTK_REPLY, rp->status);
1265}
1266
1267static void hci_cc_le_ltk_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
1268{
1269 struct hci_rp_le_ltk_neg_reply *rp = (void *) skb->data;
1270
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001271 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03001272
1273 if (rp->status)
1274 return;
1275
1276 hci_req_complete(hdev, HCI_OP_LE_LTK_NEG_REPLY, rp->status);
1277}
1278
Gustavo Padovan6039aa732012-05-23 04:04:18 -03001279static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
1280 struct sk_buff *skb)
Andre Guedesf9b49302011-06-30 19:20:53 -03001281{
Johan Hedberg06199cf2012-02-22 16:37:11 +02001282 struct hci_cp_write_le_host_supported *sent;
Andre Guedesf9b49302011-06-30 19:20:53 -03001283 __u8 status = *((__u8 *) skb->data);
1284
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001285 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Andre Guedesf9b49302011-06-30 19:20:53 -03001286
Johan Hedberg06199cf2012-02-22 16:37:11 +02001287 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED);
Johan Hedberg8f984df2012-02-28 01:07:22 +02001288 if (!sent)
Andre Guedesf9b49302011-06-30 19:20:53 -03001289 return;
1290
Johan Hedberg8f984df2012-02-28 01:07:22 +02001291 if (!status) {
1292 if (sent->le)
1293 hdev->host_features[0] |= LMP_HOST_LE;
1294 else
1295 hdev->host_features[0] &= ~LMP_HOST_LE;
Johan Hedberg53b2caa2012-10-24 21:11:59 +03001296
1297 if (sent->simul)
1298 hdev->host_features[0] |= LMP_HOST_LE_BREDR;
1299 else
1300 hdev->host_features[0] &= ~LMP_HOST_LE_BREDR;
Johan Hedberg8f984df2012-02-28 01:07:22 +02001301 }
1302
1303 if (test_bit(HCI_MGMT, &hdev->dev_flags) &&
Gustavo Padovan807deac2012-05-17 00:36:24 -03001304 !test_bit(HCI_INIT, &hdev->flags))
Johan Hedberg8f984df2012-02-28 01:07:22 +02001305 mgmt_le_enable_complete(hdev, sent->le, status);
1306
1307 hci_req_complete(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, status);
Andre Guedesf9b49302011-06-30 19:20:53 -03001308}
1309
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +03001310static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
1311 struct sk_buff *skb)
1312{
1313 struct hci_rp_write_remote_amp_assoc *rp = (void *) skb->data;
1314
1315 BT_DBG("%s status 0x%2.2x phy_handle 0x%2.2x",
1316 hdev->name, rp->status, rp->phy_handle);
1317
1318 if (rp->status)
1319 return;
1320
1321 amp_write_rem_assoc_continue(hdev, rp->phy_handle);
1322}
1323
Gustavo Padovan6039aa732012-05-23 04:04:18 -03001324static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001325{
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001326 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001327
1328 if (status) {
Johan Hedberg23bb5762010-12-21 23:01:27 +02001329 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001330 hci_conn_check_pending(hdev);
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001331 hci_dev_lock(hdev);
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02001332 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Andre Guedes7a135102011-11-09 17:14:25 -03001333 mgmt_start_discovery_failed(hdev, status);
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001334 hci_dev_unlock(hdev);
Johan Hedberg314b2382011-04-27 10:29:57 -04001335 return;
1336 }
1337
Andre Guedes89352e72011-11-04 14:16:53 -03001338 set_bit(HCI_INQUIRY, &hdev->flags);
1339
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001340 hci_dev_lock(hdev);
Andre Guedes343f9352012-02-17 20:39:37 -03001341 hci_discovery_set_state(hdev, DISCOVERY_FINDING);
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001342 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001343}
1344
Gustavo Padovan6039aa732012-05-23 04:04:18 -03001345static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001347 struct hci_cp_create_conn *cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001350 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001351
1352 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 if (!cp)
1354 return;
1355
1356 hci_dev_lock(hdev);
1357
1358 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1359
Andrei Emeltchenko6ed93dc2012-09-25 12:49:43 +03001360 BT_DBG("%s bdaddr %pMR hcon %p", hdev->name, &cp->bdaddr, conn);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362 if (status) {
1363 if (conn && conn->state == BT_CONNECT) {
Marcel Holtmann4c67bc72006-10-15 17:30:56 +02001364 if (status != 0x0c || conn->attempt > 2) {
1365 conn->state = BT_CLOSED;
1366 hci_proto_connect_cfm(conn, status);
1367 hci_conn_del(conn);
1368 } else
1369 conn->state = BT_CONNECT2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 }
1371 } else {
1372 if (!conn) {
1373 conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr);
1374 if (conn) {
Johan Hedberga0c808b2012-01-16 09:49:58 +02001375 conn->out = true;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 conn->link_mode |= HCI_LM_MASTER;
1377 } else
Gustavo F. Padovan893ef972010-07-18 15:13:37 -03001378 BT_ERR("No memory for new connection");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
1380 }
1381
1382 hci_dev_unlock(hdev);
1383}
1384
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001385static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001387 struct hci_cp_add_sco *cp;
1388 struct hci_conn *acl, *sco;
1389 __u16 handle;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001391 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001392
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001393 if (!status)
1394 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001396 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
1397 if (!cp)
1398 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001400 handle = __le16_to_cpu(cp->handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001402 BT_DBG("%s handle 0x%4.4x", hdev->name, handle);
Marcel Holtmann6bd57412006-11-18 22:14:22 +01001403
1404 hci_dev_lock(hdev);
1405
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001406 acl = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001407 if (acl) {
1408 sco = acl->link;
1409 if (sco) {
1410 sco->state = BT_CLOSED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001411
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001412 hci_proto_connect_cfm(sco, status);
1413 hci_conn_del(sco);
1414 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001415 }
Marcel Holtmann6bd57412006-11-18 22:14:22 +01001416
1417 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418}
1419
Marcel Holtmannf8558552008-07-14 20:13:49 +02001420static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
1421{
1422 struct hci_cp_auth_requested *cp;
1423 struct hci_conn *conn;
1424
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001425 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmannf8558552008-07-14 20:13:49 +02001426
1427 if (!status)
1428 return;
1429
1430 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
1431 if (!cp)
1432 return;
1433
1434 hci_dev_lock(hdev);
1435
1436 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1437 if (conn) {
1438 if (conn->state == BT_CONFIG) {
1439 hci_proto_connect_cfm(conn, status);
1440 hci_conn_put(conn);
1441 }
1442 }
1443
1444 hci_dev_unlock(hdev);
1445}
1446
1447static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
1448{
1449 struct hci_cp_set_conn_encrypt *cp;
1450 struct hci_conn *conn;
1451
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001452 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmannf8558552008-07-14 20:13:49 +02001453
1454 if (!status)
1455 return;
1456
1457 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
1458 if (!cp)
1459 return;
1460
1461 hci_dev_lock(hdev);
1462
1463 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1464 if (conn) {
1465 if (conn->state == BT_CONFIG) {
1466 hci_proto_connect_cfm(conn, status);
1467 hci_conn_put(conn);
1468 }
1469 }
1470
1471 hci_dev_unlock(hdev);
1472}
1473
Johan Hedberg127178d2010-11-18 22:22:29 +02001474static int hci_outgoing_auth_needed(struct hci_dev *hdev,
Gustavo Padovan807deac2012-05-17 00:36:24 -03001475 struct hci_conn *conn)
Johan Hedberg392599b2010-11-18 22:22:28 +02001476{
Johan Hedberg392599b2010-11-18 22:22:28 +02001477 if (conn->state != BT_CONFIG || !conn->out)
1478 return 0;
1479
Johan Hedberg765c2a92011-01-19 12:06:52 +05301480 if (conn->pending_sec_level == BT_SECURITY_SDP)
Johan Hedberg392599b2010-11-18 22:22:28 +02001481 return 0;
1482
1483 /* Only request authentication for SSP connections or non-SSP
Vinicius Costa Gomese9bf2bf2011-09-02 14:51:20 -03001484 * devices with sec_level HIGH or if MITM protection is requested */
Gustavo Padovan807deac2012-05-17 00:36:24 -03001485 if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) &&
1486 conn->pending_sec_level != BT_SECURITY_HIGH)
Johan Hedberg392599b2010-11-18 22:22:28 +02001487 return 0;
1488
Johan Hedberg392599b2010-11-18 22:22:28 +02001489 return 1;
1490}
1491
Gustavo Padovan6039aa732012-05-23 04:04:18 -03001492static int hci_resolve_name(struct hci_dev *hdev,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001493 struct inquiry_entry *e)
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001494{
1495 struct hci_cp_remote_name_req cp;
1496
1497 memset(&cp, 0, sizeof(cp));
1498
1499 bacpy(&cp.bdaddr, &e->data.bdaddr);
1500 cp.pscan_rep_mode = e->data.pscan_rep_mode;
1501 cp.pscan_mode = e->data.pscan_mode;
1502 cp.clock_offset = e->data.clock_offset;
1503
1504 return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
1505}
1506
Johan Hedbergb644ba32012-01-17 21:48:47 +02001507static bool hci_resolve_next_name(struct hci_dev *hdev)
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001508{
1509 struct discovery_state *discov = &hdev->discovery;
1510 struct inquiry_entry *e;
1511
Johan Hedbergb644ba32012-01-17 21:48:47 +02001512 if (list_empty(&discov->resolve))
1513 return false;
1514
1515 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
Ram Malovanyc8100892012-07-19 10:26:09 +03001516 if (!e)
1517 return false;
1518
Johan Hedbergb644ba32012-01-17 21:48:47 +02001519 if (hci_resolve_name(hdev, e) == 0) {
1520 e->name_state = NAME_PENDING;
1521 return true;
1522 }
1523
1524 return false;
1525}
1526
1527static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001528 bdaddr_t *bdaddr, u8 *name, u8 name_len)
Johan Hedbergb644ba32012-01-17 21:48:47 +02001529{
1530 struct discovery_state *discov = &hdev->discovery;
1531 struct inquiry_entry *e;
1532
1533 if (conn && !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001534 mgmt_device_connected(hdev, bdaddr, ACL_LINK, 0x00, 0, name,
1535 name_len, conn->dev_class);
Johan Hedbergb644ba32012-01-17 21:48:47 +02001536
1537 if (discov->state == DISCOVERY_STOPPED)
1538 return;
1539
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001540 if (discov->state == DISCOVERY_STOPPING)
1541 goto discov_complete;
1542
1543 if (discov->state != DISCOVERY_RESOLVING)
1544 return;
1545
1546 e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING);
Ram Malovany7cc83802012-07-19 10:26:10 +03001547 /* If the device was not found in a list of found devices names of which
1548 * are pending. there is no need to continue resolving a next name as it
1549 * will be done upon receiving another Remote Name Request Complete
1550 * Event */
1551 if (!e)
1552 return;
1553
1554 list_del(&e->list);
1555 if (name) {
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001556 e->name_state = NAME_KNOWN;
Ram Malovany7cc83802012-07-19 10:26:10 +03001557 mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00,
1558 e->data.rssi, name, name_len);
Ram Malovanyc3e7c0d2012-07-19 10:26:11 +03001559 } else {
1560 e->name_state = NAME_NOT_KNOWN;
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001561 }
1562
Johan Hedbergb644ba32012-01-17 21:48:47 +02001563 if (hci_resolve_next_name(hdev))
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001564 return;
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001565
1566discov_complete:
1567 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1568}
1569
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001570static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
1571{
Johan Hedberg127178d2010-11-18 22:22:29 +02001572 struct hci_cp_remote_name_req *cp;
1573 struct hci_conn *conn;
1574
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001575 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Johan Hedberg127178d2010-11-18 22:22:29 +02001576
1577 /* If successful wait for the name req complete event before
1578 * checking for the need to do authentication */
1579 if (!status)
1580 return;
1581
1582 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
1583 if (!cp)
1584 return;
1585
1586 hci_dev_lock(hdev);
1587
1588 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
Johan Hedbergb644ba32012-01-17 21:48:47 +02001589
1590 if (test_bit(HCI_MGMT, &hdev->dev_flags))
1591 hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0);
1592
Johan Hedberg79c6c702011-04-28 11:28:55 -07001593 if (!conn)
1594 goto unlock;
1595
1596 if (!hci_outgoing_auth_needed(hdev, conn))
1597 goto unlock;
1598
Johan Hedberg51a8efd2012-01-16 06:10:31 +02001599 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02001600 struct hci_cp_auth_requested cp;
1601 cp.handle = __cpu_to_le16(conn->handle);
1602 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
1603 }
1604
Johan Hedberg79c6c702011-04-28 11:28:55 -07001605unlock:
Johan Hedberg127178d2010-11-18 22:22:29 +02001606 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001607}
1608
Marcel Holtmann769be972008-07-14 20:13:49 +02001609static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
1610{
1611 struct hci_cp_read_remote_features *cp;
1612 struct hci_conn *conn;
1613
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001614 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmann769be972008-07-14 20:13:49 +02001615
1616 if (!status)
1617 return;
1618
1619 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
1620 if (!cp)
1621 return;
1622
1623 hci_dev_lock(hdev);
1624
1625 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1626 if (conn) {
1627 if (conn->state == BT_CONFIG) {
Marcel Holtmann769be972008-07-14 20:13:49 +02001628 hci_proto_connect_cfm(conn, status);
1629 hci_conn_put(conn);
1630 }
1631 }
1632
1633 hci_dev_unlock(hdev);
1634}
1635
1636static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
1637{
1638 struct hci_cp_read_remote_ext_features *cp;
1639 struct hci_conn *conn;
1640
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001641 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmann769be972008-07-14 20:13:49 +02001642
1643 if (!status)
1644 return;
1645
1646 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
1647 if (!cp)
1648 return;
1649
1650 hci_dev_lock(hdev);
1651
1652 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1653 if (conn) {
1654 if (conn->state == BT_CONFIG) {
Marcel Holtmann769be972008-07-14 20:13:49 +02001655 hci_proto_connect_cfm(conn, status);
1656 hci_conn_put(conn);
1657 }
1658 }
1659
1660 hci_dev_unlock(hdev);
1661}
1662
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001663static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
1664{
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001665 struct hci_cp_setup_sync_conn *cp;
1666 struct hci_conn *acl, *sco;
1667 __u16 handle;
1668
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001669 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001670
1671 if (!status)
1672 return;
1673
1674 cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
1675 if (!cp)
1676 return;
1677
1678 handle = __le16_to_cpu(cp->handle);
1679
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001680 BT_DBG("%s handle 0x%4.4x", hdev->name, handle);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001681
1682 hci_dev_lock(hdev);
1683
1684 acl = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001685 if (acl) {
1686 sco = acl->link;
1687 if (sco) {
1688 sco->state = BT_CLOSED;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001689
Andrei Emeltchenko5a08ecc2011-01-11 17:20:20 +02001690 hci_proto_connect_cfm(sco, status);
1691 hci_conn_del(sco);
1692 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02001693 }
1694
1695 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001696}
1697
1698static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
1699{
1700 struct hci_cp_sniff_mode *cp;
1701 struct hci_conn *conn;
1702
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001703 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001704
1705 if (!status)
1706 return;
1707
1708 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
1709 if (!cp)
1710 return;
1711
1712 hci_dev_lock(hdev);
1713
1714 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001715 if (conn) {
Johan Hedberg51a8efd2012-01-16 06:10:31 +02001716 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001717
Johan Hedberg51a8efd2012-01-16 06:10:31 +02001718 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001719 hci_sco_setup(conn, status);
1720 }
1721
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001722 hci_dev_unlock(hdev);
1723}
1724
1725static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
1726{
1727 struct hci_cp_exit_sniff_mode *cp;
1728 struct hci_conn *conn;
1729
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001730 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001731
1732 if (!status)
1733 return;
1734
1735 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
1736 if (!cp)
1737 return;
1738
1739 hci_dev_lock(hdev);
1740
1741 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001742 if (conn) {
Johan Hedberg51a8efd2012-01-16 06:10:31 +02001743 clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001744
Johan Hedberg51a8efd2012-01-16 06:10:31 +02001745 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001746 hci_sco_setup(conn, status);
1747 }
1748
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001749 hci_dev_unlock(hdev);
1750}
1751
Johan Hedberg88c3df12012-02-09 14:27:38 +02001752static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
1753{
1754 struct hci_cp_disconnect *cp;
1755 struct hci_conn *conn;
1756
1757 if (!status)
1758 return;
1759
1760 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT);
1761 if (!cp)
1762 return;
1763
1764 hci_dev_lock(hdev);
1765
1766 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
1767 if (conn)
1768 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001769 conn->dst_type, status);
Johan Hedberg88c3df12012-02-09 14:27:38 +02001770
1771 hci_dev_unlock(hdev);
1772}
1773
Ville Tervofcd89c02011-02-10 22:38:47 -03001774static void hci_cs_le_create_conn(struct hci_dev *hdev, __u8 status)
1775{
Ville Tervofcd89c02011-02-10 22:38:47 -03001776 struct hci_conn *conn;
1777
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001778 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Ville Tervofcd89c02011-02-10 22:38:47 -03001779
Ville Tervofcd89c02011-02-10 22:38:47 -03001780 if (status) {
Andre Guedesf00a06a2012-07-27 15:10:13 -03001781 hci_dev_lock(hdev);
Ville Tervofcd89c02011-02-10 22:38:47 -03001782
Andre Guedes0c95ab72012-07-27 15:10:14 -03001783 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
Andre Guedesf00a06a2012-07-27 15:10:13 -03001784 if (!conn) {
1785 hci_dev_unlock(hdev);
1786 return;
1787 }
1788
Andrei Emeltchenko6ed93dc2012-09-25 12:49:43 +03001789 BT_DBG("%s bdaddr %pMR conn %p", hdev->name, &conn->dst, conn);
Andre Guedesf00a06a2012-07-27 15:10:13 -03001790
1791 conn->state = BT_CLOSED;
Andre Guedes0c95ab72012-07-27 15:10:14 -03001792 mgmt_connect_failed(hdev, &conn->dst, conn->type,
Andre Guedesf00a06a2012-07-27 15:10:13 -03001793 conn->dst_type, status);
1794 hci_proto_connect_cfm(conn, status);
1795 hci_conn_del(conn);
1796
1797 hci_dev_unlock(hdev);
1798 }
Ville Tervofcd89c02011-02-10 22:38:47 -03001799}
1800
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03001801static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
1802{
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001803 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03001804}
1805
Andrei Emeltchenkoa02226d2012-09-27 17:26:19 +03001806static void hci_cs_create_phylink(struct hci_dev *hdev, u8 status)
1807{
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +03001808 struct hci_cp_create_phy_link *cp;
1809
Andrei Emeltchenkoa02226d2012-09-27 17:26:19 +03001810 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +03001811
1812 if (status)
1813 return;
1814
1815 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_PHY_LINK);
1816 if (!cp)
1817 return;
1818
1819 amp_write_remote_assoc(hdev, cp->phy_handle);
Andrei Emeltchenkoa02226d2012-09-27 17:26:19 +03001820}
1821
Andrei Emeltchenko0b26ab92012-09-27 17:26:24 +03001822static void hci_cs_accept_phylink(struct hci_dev *hdev, u8 status)
1823{
1824 struct hci_cp_accept_phy_link *cp;
1825
1826 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1827
1828 if (status)
1829 return;
1830
1831 cp = hci_sent_cmd_data(hdev, HCI_OP_ACCEPT_PHY_LINK);
1832 if (!cp)
1833 return;
1834
1835 amp_write_remote_assoc(hdev, cp->phy_handle);
1836}
1837
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +02001838static void hci_cs_create_logical_link(struct hci_dev *hdev, u8 status)
1839{
1840 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1841}
1842
Gustavo Padovan6039aa732012-05-23 04:04:18 -03001843static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001844{
1845 __u8 status = *((__u8 *) skb->data);
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001846 struct discovery_state *discov = &hdev->discovery;
1847 struct inquiry_entry *e;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001848
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03001849 BT_DBG("%s status 0x%2.2x", hdev->name, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001850
Johan Hedberg23bb5762010-12-21 23:01:27 +02001851 hci_req_complete(hdev, HCI_OP_INQUIRY, status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001852
1853 hci_conn_check_pending(hdev);
Andre Guedes89352e72011-11-04 14:16:53 -03001854
1855 if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags))
1856 return;
1857
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02001858 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001859 return;
1860
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001861 hci_dev_lock(hdev);
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001862
Andre Guedes343f9352012-02-17 20:39:37 -03001863 if (discov->state != DISCOVERY_FINDING)
Johan Hedberg30dc78e2012-01-04 15:44:20 +02001864 goto unlock;
1865
1866 if (list_empty(&discov->resolve)) {
1867 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1868 goto unlock;
1869 }
1870
1871 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
1872 if (e && hci_resolve_name(hdev, e) == 0) {
1873 e->name_state = NAME_PENDING;
1874 hci_discovery_set_state(hdev, DISCOVERY_RESOLVING);
1875 } else {
1876 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1877 }
1878
1879unlock:
Johan Hedberg56e5cb82011-11-08 20:40:16 +02001880 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001881}
1882
Gustavo Padovan6039aa732012-05-23 04:04:18 -03001883static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884{
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001885 struct inquiry_data data;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001886 struct inquiry_info *info = (void *) (skb->data + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 int num_rsp = *((__u8 *) skb->data);
1888
1889 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
1890
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001891 if (!num_rsp)
1892 return;
1893
Andre Guedes1519cc12012-03-21 00:03:38 -03001894 if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags))
1895 return;
1896
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 hci_dev_lock(hdev);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001898
Johan Hedberge17acd42011-03-30 23:57:16 +03001899 for (; num_rsp; num_rsp--, info++) {
Johan Hedberg388fc8f2012-02-23 00:38:59 +02001900 bool name_known, ssp;
Johan Hedberg31754052012-01-04 13:39:52 +02001901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 bacpy(&data.bdaddr, &info->bdaddr);
1903 data.pscan_rep_mode = info->pscan_rep_mode;
1904 data.pscan_period_mode = info->pscan_period_mode;
1905 data.pscan_mode = info->pscan_mode;
1906 memcpy(data.dev_class, info->dev_class, 3);
1907 data.clock_offset = info->clock_offset;
1908 data.rssi = 0x00;
Marcel Holtmann41a96212008-07-14 20:13:48 +02001909 data.ssp_mode = 0x00;
Johan Hedberg31754052012-01-04 13:39:52 +02001910
Johan Hedberg388fc8f2012-02-23 00:38:59 +02001911 name_known = hci_inquiry_cache_update(hdev, &data, false, &ssp);
Johan Hedberg48264f02011-11-09 13:58:58 +02001912 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001913 info->dev_class, 0, !name_known, ssp, NULL,
1914 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917 hci_dev_unlock(hdev);
1918}
1919
Gustavo Padovan6039aa732012-05-23 04:04:18 -03001920static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001922 struct hci_ev_conn_complete *ev = (void *) skb->data;
1923 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001925 BT_DBG("%s", hdev->name);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 hci_dev_lock(hdev);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001928
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001929 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
Marcel Holtmann94992372009-04-19 19:30:03 +02001930 if (!conn) {
1931 if (ev->link_type != SCO_LINK)
1932 goto unlock;
1933
1934 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
1935 if (!conn)
1936 goto unlock;
1937
1938 conn->type = SCO_LINK;
1939 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001940
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001941 if (!ev->status) {
1942 conn->handle = __le16_to_cpu(ev->handle);
Marcel Holtmann769be972008-07-14 20:13:49 +02001943
1944 if (conn->type == ACL_LINK) {
1945 conn->state = BT_CONFIG;
1946 hci_conn_hold(conn);
Szymon Janca9ea3ed2012-07-19 14:46:08 +02001947
1948 if (!conn->out && !hci_conn_ssp_enabled(conn) &&
1949 !hci_find_link_key(hdev, &ev->bdaddr))
1950 conn->disc_timeout = HCI_PAIRING_TIMEOUT;
1951 else
1952 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Marcel Holtmann769be972008-07-14 20:13:49 +02001953 } else
1954 conn->state = BT_CONNECTED;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001955
Marcel Holtmann9eba32b2009-08-22 14:19:26 -07001956 hci_conn_hold_device(conn);
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02001957 hci_conn_add_sysfs(conn);
1958
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001959 if (test_bit(HCI_AUTH, &hdev->flags))
1960 conn->link_mode |= HCI_LM_AUTH;
1961
1962 if (test_bit(HCI_ENCRYPT, &hdev->flags))
1963 conn->link_mode |= HCI_LM_ENCRYPT;
1964
1965 /* Get remote features */
1966 if (conn->type == ACL_LINK) {
1967 struct hci_cp_read_remote_features cp;
1968 cp.handle = ev->handle;
Marcel Holtmann769be972008-07-14 20:13:49 +02001969 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_FEATURES,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001970 sizeof(cp), &cp);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001971 }
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001972
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001973 /* Set packet type for incoming connection */
Andrei Emeltchenkod095c1e2011-12-01 14:33:27 +02001974 if (!conn->out && hdev->hci_ver < BLUETOOTH_VER_2_0) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001975 struct hci_cp_change_conn_ptype cp;
1976 cp.handle = ev->handle;
Marcel Holtmanna8746412008-07-14 20:13:46 +02001977 cp.pkt_type = cpu_to_le16(conn->pkt_type);
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001978 hci_send_cmd(hdev, HCI_OP_CHANGE_CONN_PTYPE, sizeof(cp),
1979 &cp);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001980 }
Johan Hedberg17d5c042011-01-22 06:09:08 +02001981 } else {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001982 conn->state = BT_CLOSED;
Johan Hedberg17d5c042011-01-22 06:09:08 +02001983 if (conn->type == ACL_LINK)
Johan Hedberg744cf192011-11-08 20:40:14 +02001984 mgmt_connect_failed(hdev, &ev->bdaddr, conn->type,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03001985 conn->dst_type, ev->status);
Johan Hedberg17d5c042011-01-22 06:09:08 +02001986 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001987
Marcel Holtmanne73439d2010-07-26 10:06:00 -04001988 if (conn->type == ACL_LINK)
1989 hci_sco_setup(conn, ev->status);
Marcel Holtmann45bb4bf2005-08-09 20:27:49 -07001990
Marcel Holtmann769be972008-07-14 20:13:49 +02001991 if (ev->status) {
1992 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001993 hci_conn_del(conn);
Marcel Holtmannc89b6e62009-01-15 21:57:03 +01001994 } else if (ev->link_type != ACL_LINK)
1995 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001996
1997unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001998 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02001999
2000 hci_conn_check_pending(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001}
2002
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002003static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002005 struct hci_ev_conn_request *ev = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 int mask = hdev->link_mode;
2007
Andrei Emeltchenko6ed93dc2012-09-25 12:49:43 +03002008 BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr,
Gustavo Padovan807deac2012-05-17 00:36:24 -03002009 ev->link_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
2011 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type);
2012
Szymon Janc138d22e2011-02-17 16:44:23 +01002013 if ((mask & HCI_LM_ACCEPT) &&
Gustavo Padovan807deac2012-05-17 00:36:24 -03002014 !hci_blacklist_lookup(hdev, &ev->bdaddr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 /* Connection accepted */
Marcel Holtmannc7bdd502008-07-14 20:13:47 +02002016 struct inquiry_entry *ie;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
2019 hci_dev_lock(hdev);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002020
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002021 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
2022 if (ie)
Marcel Holtmannc7bdd502008-07-14 20:13:47 +02002023 memcpy(ie->data.dev_class, ev->dev_class, 3);
2024
Gustavo Padovan8fc9ced2012-05-23 04:04:21 -03002025 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type,
2026 &ev->bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 if (!conn) {
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02002028 conn = hci_conn_add(hdev, ev->link_type, &ev->bdaddr);
2029 if (!conn) {
Gustavo F. Padovan893ef972010-07-18 15:13:37 -03002030 BT_ERR("No memory for new connection");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 hci_dev_unlock(hdev);
2032 return;
2033 }
2034 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002035
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 memcpy(conn->dev_class, ev->dev_class, 3);
2037 conn->state = BT_CONNECT;
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 hci_dev_unlock(hdev);
2040
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002041 if (ev->link_type == ACL_LINK || !lmp_esco_capable(hdev)) {
2042 struct hci_cp_accept_conn_req cp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002044 bacpy(&cp.bdaddr, &ev->bdaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002046 if (lmp_rswitch_capable(hdev) && (mask & HCI_LM_MASTER))
2047 cp.role = 0x00; /* Become master */
2048 else
2049 cp.role = 0x01; /* Remain slave */
2050
Gustavo F. Padovan04124682012-03-08 01:25:00 -03002051 hci_send_cmd(hdev, HCI_OP_ACCEPT_CONN_REQ, sizeof(cp),
2052 &cp);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002053 } else {
2054 struct hci_cp_accept_sync_conn_req cp;
2055
2056 bacpy(&cp.bdaddr, &ev->bdaddr);
Marcel Holtmanna8746412008-07-14 20:13:46 +02002057 cp.pkt_type = cpu_to_le16(conn->pkt_type);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002058
Andrei Emeltchenko82781e62012-05-25 11:38:27 +03002059 cp.tx_bandwidth = __constant_cpu_to_le32(0x00001f40);
2060 cp.rx_bandwidth = __constant_cpu_to_le32(0x00001f40);
2061 cp.max_latency = __constant_cpu_to_le16(0xffff);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002062 cp.content_format = cpu_to_le16(hdev->voice_setting);
2063 cp.retrans_effort = 0xff;
2064
2065 hci_send_cmd(hdev, HCI_OP_ACCEPT_SYNC_CONN_REQ,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03002066 sizeof(cp), &cp);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02002067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 } else {
2069 /* Connection rejected */
2070 struct hci_cp_reject_conn_req cp;
2071
2072 bacpy(&cp.bdaddr, &ev->bdaddr);
Andrei Emeltchenko9f5a0d72011-11-07 14:20:25 +02002073 cp.reason = HCI_ERROR_REJ_BAD_ADDR;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002074 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 }
2076}
2077
Mikel Astizf0d6a0e2012-08-09 09:52:30 +02002078static u8 hci_to_mgmt_reason(u8 err)
2079{
2080 switch (err) {
2081 case HCI_ERROR_CONNECTION_TIMEOUT:
2082 return MGMT_DEV_DISCONN_TIMEOUT;
2083 case HCI_ERROR_REMOTE_USER_TERM:
2084 case HCI_ERROR_REMOTE_LOW_RESOURCES:
2085 case HCI_ERROR_REMOTE_POWER_OFF:
2086 return MGMT_DEV_DISCONN_REMOTE;
2087 case HCI_ERROR_LOCAL_HOST_TERM:
2088 return MGMT_DEV_DISCONN_LOCAL_HOST;
2089 default:
2090 return MGMT_DEV_DISCONN_UNKNOWN;
2091 }
2092}
2093
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002094static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002096 struct hci_ev_disconn_complete *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002097 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002099 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 hci_dev_lock(hdev);
2102
Marcel Holtmann04837f62006-07-03 10:02:33 +02002103 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergf7520542011-01-20 12:34:39 +02002104 if (!conn)
2105 goto unlock;
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02002106
Johan Hedberg37d9ef72011-11-10 15:54:39 +02002107 if (ev->status == 0)
2108 conn->state = BT_CLOSED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109
Johan Hedbergb644ba32012-01-17 21:48:47 +02002110 if (test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags) &&
Gustavo Padovan807deac2012-05-17 00:36:24 -03002111 (conn->type == ACL_LINK || conn->type == LE_LINK)) {
Mikel Astizf0d6a0e2012-08-09 09:52:30 +02002112 if (ev->status) {
Johan Hedberg88c3df12012-02-09 14:27:38 +02002113 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
Gustavo Padovan807deac2012-05-17 00:36:24 -03002114 conn->dst_type, ev->status);
Mikel Astizf0d6a0e2012-08-09 09:52:30 +02002115 } else {
2116 u8 reason = hci_to_mgmt_reason(ev->reason);
2117
Johan Hedbergafc747a2012-01-15 18:11:07 +02002118 mgmt_device_disconnected(hdev, &conn->dst, conn->type,
Mikel Astizf0d6a0e2012-08-09 09:52:30 +02002119 conn->dst_type, reason);
2120 }
Johan Hedberg37d9ef72011-11-10 15:54:39 +02002121 }
Johan Hedbergf7520542011-01-20 12:34:39 +02002122
Johan Hedberg37d9ef72011-11-10 15:54:39 +02002123 if (ev->status == 0) {
Vishal Agarwal6ec5bca2012-04-16 14:44:44 +05302124 if (conn->type == ACL_LINK && conn->flush_key)
2125 hci_remove_link_key(hdev, &conn->dst);
Johan Hedberg37d9ef72011-11-10 15:54:39 +02002126 hci_proto_disconn_cfm(conn, ev->reason);
2127 hci_conn_del(conn);
2128 }
Johan Hedbergf7520542011-01-20 12:34:39 +02002129
2130unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 hci_dev_unlock(hdev);
2132}
2133
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002134static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002135{
2136 struct hci_ev_auth_complete *ev = (void *) skb->data;
2137 struct hci_conn *conn;
2138
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002139 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002140
2141 hci_dev_lock(hdev);
2142
2143 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002144 if (!conn)
2145 goto unlock;
2146
2147 if (!ev->status) {
Johan Hedbergaa64a8b2012-01-18 21:33:12 +02002148 if (!hci_conn_ssp_enabled(conn) &&
Gustavo Padovan807deac2012-05-17 00:36:24 -03002149 test_bit(HCI_CONN_REAUTH_PEND, &conn->flags)) {
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002150 BT_INFO("re-auth of legacy device is not possible.");
Johan Hedberg2a611692011-02-19 12:06:00 -03002151 } else {
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002152 conn->link_mode |= HCI_LM_AUTH;
2153 conn->sec_level = conn->pending_sec_level;
Johan Hedberg2a611692011-02-19 12:06:00 -03002154 }
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002155 } else {
Johan Hedbergbab73cb2012-02-09 16:07:29 +02002156 mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03002157 ev->status);
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002158 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002159
Johan Hedberg51a8efd2012-01-16 06:10:31 +02002160 clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
2161 clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002162
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002163 if (conn->state == BT_CONFIG) {
Johan Hedbergaa64a8b2012-01-18 21:33:12 +02002164 if (!ev->status && hci_conn_ssp_enabled(conn)) {
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002165 struct hci_cp_set_conn_encrypt cp;
2166 cp.handle = ev->handle;
2167 cp.encrypt = 0x01;
2168 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
Gustavo Padovan807deac2012-05-17 00:36:24 -03002169 &cp);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002170 } else {
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002171 conn->state = BT_CONNECTED;
2172 hci_proto_connect_cfm(conn, ev->status);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002173 hci_conn_put(conn);
2174 }
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002175 } else {
2176 hci_auth_cfm(conn, ev->status);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002177
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002178 hci_conn_hold(conn);
2179 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
2180 hci_conn_put(conn);
2181 }
2182
Johan Hedberg51a8efd2012-01-16 06:10:31 +02002183 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) {
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002184 if (!ev->status) {
2185 struct hci_cp_set_conn_encrypt cp;
2186 cp.handle = ev->handle;
2187 cp.encrypt = 0x01;
2188 hci_send_cmd(hdev, HCI_OP_SET_CONN_ENCRYPT, sizeof(cp),
Gustavo Padovan807deac2012-05-17 00:36:24 -03002189 &cp);
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002190 } else {
Johan Hedberg51a8efd2012-01-16 06:10:31 +02002191 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002192 hci_encrypt_cfm(conn, ev->status, 0x00);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002193 }
2194 }
2195
Waldemar Rymarkiewiczd7556e22011-05-31 15:49:26 +02002196unlock:
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002197 hci_dev_unlock(hdev);
2198}
2199
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002200static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002201{
Johan Hedberg127178d2010-11-18 22:22:29 +02002202 struct hci_ev_remote_name *ev = (void *) skb->data;
2203 struct hci_conn *conn;
2204
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002205 BT_DBG("%s", hdev->name);
2206
2207 hci_conn_check_pending(hdev);
Johan Hedberg127178d2010-11-18 22:22:29 +02002208
2209 hci_dev_lock(hdev);
2210
2211 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedbergb644ba32012-01-17 21:48:47 +02002212
2213 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
2214 goto check_auth;
2215
2216 if (ev->status == 0)
2217 hci_check_pending_name(hdev, conn, &ev->bdaddr, ev->name,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03002218 strnlen(ev->name, HCI_MAX_NAME_LENGTH));
Johan Hedbergb644ba32012-01-17 21:48:47 +02002219 else
2220 hci_check_pending_name(hdev, conn, &ev->bdaddr, NULL, 0);
2221
2222check_auth:
Johan Hedberg79c6c702011-04-28 11:28:55 -07002223 if (!conn)
2224 goto unlock;
2225
2226 if (!hci_outgoing_auth_needed(hdev, conn))
2227 goto unlock;
2228
Johan Hedberg51a8efd2012-01-16 06:10:31 +02002229 if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02002230 struct hci_cp_auth_requested cp;
2231 cp.handle = __cpu_to_le16(conn->handle);
2232 hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED, sizeof(cp), &cp);
2233 }
2234
Johan Hedberg79c6c702011-04-28 11:28:55 -07002235unlock:
Johan Hedberg127178d2010-11-18 22:22:29 +02002236 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002237}
2238
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002239static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002240{
2241 struct hci_ev_encrypt_change *ev = (void *) skb->data;
2242 struct hci_conn *conn;
2243
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002244 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002245
2246 hci_dev_lock(hdev);
2247
2248 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2249 if (conn) {
2250 if (!ev->status) {
Marcel Holtmannae293192008-07-14 20:13:45 +02002251 if (ev->encrypt) {
2252 /* Encryption implies authentication */
2253 conn->link_mode |= HCI_LM_AUTH;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002254 conn->link_mode |= HCI_LM_ENCRYPT;
Vinicius Costa Gomesda85e5e2011-06-09 18:50:53 -03002255 conn->sec_level = conn->pending_sec_level;
Marcel Holtmannae293192008-07-14 20:13:45 +02002256 } else
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002257 conn->link_mode &= ~HCI_LM_ENCRYPT;
2258 }
2259
Johan Hedberg51a8efd2012-01-16 06:10:31 +02002260 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002261
Gustavo Padovana7d77232012-05-13 03:20:07 -03002262 if (ev->status && conn->state == BT_CONNECTED) {
Gustavo Padovand839c812012-05-16 12:17:12 -03002263 hci_acl_disconn(conn, HCI_ERROR_AUTH_FAILURE);
Gustavo Padovana7d77232012-05-13 03:20:07 -03002264 hci_conn_put(conn);
2265 goto unlock;
2266 }
2267
Marcel Holtmannf8558552008-07-14 20:13:49 +02002268 if (conn->state == BT_CONFIG) {
2269 if (!ev->status)
2270 conn->state = BT_CONNECTED;
2271
2272 hci_proto_connect_cfm(conn, ev->status);
2273 hci_conn_put(conn);
2274 } else
2275 hci_encrypt_cfm(conn, ev->status, ev->encrypt);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002276 }
2277
Gustavo Padovana7d77232012-05-13 03:20:07 -03002278unlock:
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002279 hci_dev_unlock(hdev);
2280}
2281
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002282static void hci_change_link_key_complete_evt(struct hci_dev *hdev,
2283 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002284{
2285 struct hci_ev_change_link_key_complete *ev = (void *) skb->data;
2286 struct hci_conn *conn;
2287
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002288 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002289
2290 hci_dev_lock(hdev);
2291
2292 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2293 if (conn) {
2294 if (!ev->status)
2295 conn->link_mode |= HCI_LM_SECURE;
2296
Johan Hedberg51a8efd2012-01-16 06:10:31 +02002297 clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002298
2299 hci_key_change_cfm(conn, ev->status);
2300 }
2301
2302 hci_dev_unlock(hdev);
2303}
2304
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002305static void hci_remote_features_evt(struct hci_dev *hdev,
2306 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002307{
2308 struct hci_ev_remote_features *ev = (void *) skb->data;
2309 struct hci_conn *conn;
2310
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002311 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002312
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002313 hci_dev_lock(hdev);
2314
2315 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergccd556f2010-11-10 17:11:51 +02002316 if (!conn)
2317 goto unlock;
Marcel Holtmann769be972008-07-14 20:13:49 +02002318
Johan Hedbergccd556f2010-11-10 17:11:51 +02002319 if (!ev->status)
2320 memcpy(conn->features, ev->features, 8);
2321
2322 if (conn->state != BT_CONFIG)
2323 goto unlock;
2324
2325 if (!ev->status && lmp_ssp_capable(hdev) && lmp_ssp_capable(conn)) {
2326 struct hci_cp_read_remote_ext_features cp;
2327 cp.handle = ev->handle;
2328 cp.page = 0x01;
2329 hci_send_cmd(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES,
Gustavo Padovan807deac2012-05-17 00:36:24 -03002330 sizeof(cp), &cp);
Johan Hedberg392599b2010-11-18 22:22:28 +02002331 goto unlock;
2332 }
2333
Johan Hedberg671267b2012-05-12 16:11:50 -03002334 if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02002335 struct hci_cp_remote_name_req cp;
2336 memset(&cp, 0, sizeof(cp));
2337 bacpy(&cp.bdaddr, &conn->dst);
2338 cp.pscan_rep_mode = 0x02;
2339 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
Johan Hedbergb644ba32012-01-17 21:48:47 +02002340 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
2341 mgmt_device_connected(hdev, &conn->dst, conn->type,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03002342 conn->dst_type, 0, NULL, 0,
2343 conn->dev_class);
Johan Hedberg392599b2010-11-18 22:22:28 +02002344
Johan Hedberg127178d2010-11-18 22:22:29 +02002345 if (!hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02002346 conn->state = BT_CONNECTED;
2347 hci_proto_connect_cfm(conn, ev->status);
2348 hci_conn_put(conn);
Marcel Holtmann769be972008-07-14 20:13:49 +02002349 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002350
Johan Hedbergccd556f2010-11-10 17:11:51 +02002351unlock:
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002352 hci_dev_unlock(hdev);
2353}
2354
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002355static void hci_remote_version_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002356{
2357 BT_DBG("%s", hdev->name);
2358}
2359
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002360static void hci_qos_setup_complete_evt(struct hci_dev *hdev,
2361 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002362{
2363 BT_DBG("%s", hdev->name);
2364}
2365
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002366static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002367{
2368 struct hci_ev_cmd_complete *ev = (void *) skb->data;
2369 __u16 opcode;
2370
2371 skb_pull(skb, sizeof(*ev));
2372
2373 opcode = __le16_to_cpu(ev->opcode);
2374
2375 switch (opcode) {
2376 case HCI_OP_INQUIRY_CANCEL:
2377 hci_cc_inquiry_cancel(hdev, skb);
2378 break;
2379
Andre Guedes4d934832012-03-21 00:03:35 -03002380 case HCI_OP_PERIODIC_INQ:
2381 hci_cc_periodic_inq(hdev, skb);
2382 break;
2383
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002384 case HCI_OP_EXIT_PERIODIC_INQ:
2385 hci_cc_exit_periodic_inq(hdev, skb);
2386 break;
2387
2388 case HCI_OP_REMOTE_NAME_REQ_CANCEL:
2389 hci_cc_remote_name_req_cancel(hdev, skb);
2390 break;
2391
2392 case HCI_OP_ROLE_DISCOVERY:
2393 hci_cc_role_discovery(hdev, skb);
2394 break;
2395
Marcel Holtmanne4e8e372008-07-14 20:13:47 +02002396 case HCI_OP_READ_LINK_POLICY:
2397 hci_cc_read_link_policy(hdev, skb);
2398 break;
2399
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002400 case HCI_OP_WRITE_LINK_POLICY:
2401 hci_cc_write_link_policy(hdev, skb);
2402 break;
2403
Marcel Holtmanne4e8e372008-07-14 20:13:47 +02002404 case HCI_OP_READ_DEF_LINK_POLICY:
2405 hci_cc_read_def_link_policy(hdev, skb);
2406 break;
2407
2408 case HCI_OP_WRITE_DEF_LINK_POLICY:
2409 hci_cc_write_def_link_policy(hdev, skb);
2410 break;
2411
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002412 case HCI_OP_RESET:
2413 hci_cc_reset(hdev, skb);
2414 break;
2415
2416 case HCI_OP_WRITE_LOCAL_NAME:
2417 hci_cc_write_local_name(hdev, skb);
2418 break;
2419
2420 case HCI_OP_READ_LOCAL_NAME:
2421 hci_cc_read_local_name(hdev, skb);
2422 break;
2423
2424 case HCI_OP_WRITE_AUTH_ENABLE:
2425 hci_cc_write_auth_enable(hdev, skb);
2426 break;
2427
2428 case HCI_OP_WRITE_ENCRYPT_MODE:
2429 hci_cc_write_encrypt_mode(hdev, skb);
2430 break;
2431
2432 case HCI_OP_WRITE_SCAN_ENABLE:
2433 hci_cc_write_scan_enable(hdev, skb);
2434 break;
2435
2436 case HCI_OP_READ_CLASS_OF_DEV:
2437 hci_cc_read_class_of_dev(hdev, skb);
2438 break;
2439
2440 case HCI_OP_WRITE_CLASS_OF_DEV:
2441 hci_cc_write_class_of_dev(hdev, skb);
2442 break;
2443
2444 case HCI_OP_READ_VOICE_SETTING:
2445 hci_cc_read_voice_setting(hdev, skb);
2446 break;
2447
2448 case HCI_OP_WRITE_VOICE_SETTING:
2449 hci_cc_write_voice_setting(hdev, skb);
2450 break;
2451
2452 case HCI_OP_HOST_BUFFER_SIZE:
2453 hci_cc_host_buffer_size(hdev, skb);
2454 break;
2455
Marcel Holtmann333140b2008-07-14 20:13:48 +02002456 case HCI_OP_WRITE_SSP_MODE:
2457 hci_cc_write_ssp_mode(hdev, skb);
2458 break;
2459
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002460 case HCI_OP_READ_LOCAL_VERSION:
2461 hci_cc_read_local_version(hdev, skb);
2462 break;
2463
2464 case HCI_OP_READ_LOCAL_COMMANDS:
2465 hci_cc_read_local_commands(hdev, skb);
2466 break;
2467
2468 case HCI_OP_READ_LOCAL_FEATURES:
2469 hci_cc_read_local_features(hdev, skb);
2470 break;
2471
Andre Guedes971e3a42011-06-30 19:20:52 -03002472 case HCI_OP_READ_LOCAL_EXT_FEATURES:
2473 hci_cc_read_local_ext_features(hdev, skb);
2474 break;
2475
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002476 case HCI_OP_READ_BUFFER_SIZE:
2477 hci_cc_read_buffer_size(hdev, skb);
2478 break;
2479
2480 case HCI_OP_READ_BD_ADDR:
2481 hci_cc_read_bd_addr(hdev, skb);
2482 break;
2483
Andrei Emeltchenko350ee4c2011-12-07 15:56:51 +02002484 case HCI_OP_READ_DATA_BLOCK_SIZE:
2485 hci_cc_read_data_block_size(hdev, skb);
2486 break;
2487
Johan Hedberg23bb5762010-12-21 23:01:27 +02002488 case HCI_OP_WRITE_CA_TIMEOUT:
2489 hci_cc_write_ca_timeout(hdev, skb);
2490 break;
2491
Andrei Emeltchenko1e89cff2011-11-24 14:52:02 +02002492 case HCI_OP_READ_FLOW_CONTROL_MODE:
2493 hci_cc_read_flow_control_mode(hdev, skb);
2494 break;
2495
Andrei Emeltchenko928abaa2011-10-12 10:53:57 +03002496 case HCI_OP_READ_LOCAL_AMP_INFO:
2497 hci_cc_read_local_amp_info(hdev, skb);
2498 break;
2499
Andrei Emeltchenko903e4542012-09-27 17:26:09 +03002500 case HCI_OP_READ_LOCAL_AMP_ASSOC:
2501 hci_cc_read_local_amp_assoc(hdev, skb);
2502 break;
2503
Johan Hedbergb0916ea2011-01-10 13:44:55 +02002504 case HCI_OP_DELETE_STORED_LINK_KEY:
2505 hci_cc_delete_stored_link_key(hdev, skb);
2506 break;
2507
Johan Hedbergd5859e22011-01-25 01:19:58 +02002508 case HCI_OP_SET_EVENT_MASK:
2509 hci_cc_set_event_mask(hdev, skb);
2510 break;
2511
2512 case HCI_OP_WRITE_INQUIRY_MODE:
2513 hci_cc_write_inquiry_mode(hdev, skb);
2514 break;
2515
2516 case HCI_OP_READ_INQ_RSP_TX_POWER:
2517 hci_cc_read_inq_rsp_tx_power(hdev, skb);
2518 break;
2519
2520 case HCI_OP_SET_EVENT_FLT:
2521 hci_cc_set_event_flt(hdev, skb);
2522 break;
2523
Johan Hedberg980e1a52011-01-22 06:10:07 +02002524 case HCI_OP_PIN_CODE_REPLY:
2525 hci_cc_pin_code_reply(hdev, skb);
2526 break;
2527
2528 case HCI_OP_PIN_CODE_NEG_REPLY:
2529 hci_cc_pin_code_neg_reply(hdev, skb);
2530 break;
2531
Szymon Jancc35938b2011-03-22 13:12:21 +01002532 case HCI_OP_READ_LOCAL_OOB_DATA:
2533 hci_cc_read_local_oob_data_reply(hdev, skb);
2534 break;
2535
Ville Tervo6ed58ec2011-02-10 22:38:48 -03002536 case HCI_OP_LE_READ_BUFFER_SIZE:
2537 hci_cc_le_read_buffer_size(hdev, skb);
2538 break;
2539
Johan Hedberg8fa19092012-10-19 20:57:49 +03002540 case HCI_OP_LE_READ_ADV_TX_POWER:
2541 hci_cc_le_read_adv_tx_power(hdev, skb);
2542 break;
2543
Johan Hedberge36b04c2012-10-19 20:57:47 +03002544 case HCI_OP_LE_SET_EVENT_MASK:
2545 hci_cc_le_set_event_mask(hdev, skb);
2546 break;
2547
Johan Hedberga5c29682011-02-19 12:05:57 -03002548 case HCI_OP_USER_CONFIRM_REPLY:
2549 hci_cc_user_confirm_reply(hdev, skb);
2550 break;
2551
2552 case HCI_OP_USER_CONFIRM_NEG_REPLY:
2553 hci_cc_user_confirm_neg_reply(hdev, skb);
2554 break;
2555
Brian Gix1143d452011-11-23 08:28:34 -08002556 case HCI_OP_USER_PASSKEY_REPLY:
2557 hci_cc_user_passkey_reply(hdev, skb);
2558 break;
2559
2560 case HCI_OP_USER_PASSKEY_NEG_REPLY:
2561 hci_cc_user_passkey_neg_reply(hdev, skb);
Szymon Janc16cde992012-04-13 12:32:42 +02002562 break;
Andre Guedes07f7fa52011-12-02 21:13:31 +09002563
2564 case HCI_OP_LE_SET_SCAN_PARAM:
2565 hci_cc_le_set_scan_param(hdev, skb);
Brian Gix1143d452011-11-23 08:28:34 -08002566 break;
2567
Andre Guedeseb9d91f2011-05-26 16:23:52 -03002568 case HCI_OP_LE_SET_SCAN_ENABLE:
2569 hci_cc_le_set_scan_enable(hdev, skb);
2570 break;
2571
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03002572 case HCI_OP_LE_LTK_REPLY:
2573 hci_cc_le_ltk_reply(hdev, skb);
2574 break;
2575
2576 case HCI_OP_LE_LTK_NEG_REPLY:
2577 hci_cc_le_ltk_neg_reply(hdev, skb);
2578 break;
2579
Andre Guedesf9b49302011-06-30 19:20:53 -03002580 case HCI_OP_WRITE_LE_HOST_SUPPORTED:
2581 hci_cc_write_le_host_supported(hdev, skb);
2582 break;
2583
Andrei Emeltchenko93c284e2012-09-27 17:26:20 +03002584 case HCI_OP_WRITE_REMOTE_AMP_ASSOC:
2585 hci_cc_write_remote_amp_assoc(hdev, skb);
2586 break;
2587
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002588 default:
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002589 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002590 break;
2591 }
2592
Ville Tervo6bd32322011-02-16 16:32:41 +02002593 if (ev->opcode != HCI_OP_NOP)
2594 del_timer(&hdev->cmd_timer);
2595
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002596 if (ev->ncmd) {
2597 atomic_set(&hdev->cmd_cnt, 1);
2598 if (!skb_queue_empty(&hdev->cmd_q))
Gustavo F. Padovanc347b762011-12-14 23:53:47 -02002599 queue_work(hdev->workqueue, &hdev->cmd_work);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002600 }
2601}
2602
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002603static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002604{
2605 struct hci_ev_cmd_status *ev = (void *) skb->data;
2606 __u16 opcode;
2607
2608 skb_pull(skb, sizeof(*ev));
2609
2610 opcode = __le16_to_cpu(ev->opcode);
2611
2612 switch (opcode) {
2613 case HCI_OP_INQUIRY:
2614 hci_cs_inquiry(hdev, ev->status);
2615 break;
2616
2617 case HCI_OP_CREATE_CONN:
2618 hci_cs_create_conn(hdev, ev->status);
2619 break;
2620
2621 case HCI_OP_ADD_SCO:
2622 hci_cs_add_sco(hdev, ev->status);
2623 break;
2624
Marcel Holtmannf8558552008-07-14 20:13:49 +02002625 case HCI_OP_AUTH_REQUESTED:
2626 hci_cs_auth_requested(hdev, ev->status);
2627 break;
2628
2629 case HCI_OP_SET_CONN_ENCRYPT:
2630 hci_cs_set_conn_encrypt(hdev, ev->status);
2631 break;
2632
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002633 case HCI_OP_REMOTE_NAME_REQ:
2634 hci_cs_remote_name_req(hdev, ev->status);
2635 break;
2636
Marcel Holtmann769be972008-07-14 20:13:49 +02002637 case HCI_OP_READ_REMOTE_FEATURES:
2638 hci_cs_read_remote_features(hdev, ev->status);
2639 break;
2640
2641 case HCI_OP_READ_REMOTE_EXT_FEATURES:
2642 hci_cs_read_remote_ext_features(hdev, ev->status);
2643 break;
2644
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002645 case HCI_OP_SETUP_SYNC_CONN:
2646 hci_cs_setup_sync_conn(hdev, ev->status);
2647 break;
2648
2649 case HCI_OP_SNIFF_MODE:
2650 hci_cs_sniff_mode(hdev, ev->status);
2651 break;
2652
2653 case HCI_OP_EXIT_SNIFF_MODE:
2654 hci_cs_exit_sniff_mode(hdev, ev->status);
2655 break;
2656
Johan Hedberg8962ee72011-01-20 12:40:27 +02002657 case HCI_OP_DISCONNECT:
Johan Hedberg88c3df12012-02-09 14:27:38 +02002658 hci_cs_disconnect(hdev, ev->status);
Johan Hedberg8962ee72011-01-20 12:40:27 +02002659 break;
2660
Ville Tervofcd89c02011-02-10 22:38:47 -03002661 case HCI_OP_LE_CREATE_CONN:
2662 hci_cs_le_create_conn(hdev, ev->status);
2663 break;
2664
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03002665 case HCI_OP_LE_START_ENC:
2666 hci_cs_le_start_enc(hdev, ev->status);
2667 break;
2668
Andrei Emeltchenkoa02226d2012-09-27 17:26:19 +03002669 case HCI_OP_CREATE_PHY_LINK:
2670 hci_cs_create_phylink(hdev, ev->status);
2671 break;
2672
Andrei Emeltchenko0b26ab92012-09-27 17:26:24 +03002673 case HCI_OP_ACCEPT_PHY_LINK:
2674 hci_cs_accept_phylink(hdev, ev->status);
2675 break;
2676
Andrei Emeltchenko5ce66b52012-10-31 15:46:30 +02002677 case HCI_OP_CREATE_LOGICAL_LINK:
2678 hci_cs_create_logical_link(hdev, ev->status);
2679 break;
2680
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002681 default:
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002682 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002683 break;
2684 }
2685
Ville Tervo6bd32322011-02-16 16:32:41 +02002686 if (ev->opcode != HCI_OP_NOP)
2687 del_timer(&hdev->cmd_timer);
2688
Gustavo F. Padovan10572132011-03-16 15:36:29 -03002689 if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002690 atomic_set(&hdev->cmd_cnt, 1);
2691 if (!skb_queue_empty(&hdev->cmd_q))
Gustavo F. Padovanc347b762011-12-14 23:53:47 -02002692 queue_work(hdev->workqueue, &hdev->cmd_work);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002693 }
2694}
2695
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002696static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002697{
2698 struct hci_ev_role_change *ev = (void *) skb->data;
2699 struct hci_conn *conn;
2700
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002701 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002702
2703 hci_dev_lock(hdev);
2704
2705 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2706 if (conn) {
2707 if (!ev->status) {
2708 if (ev->role)
2709 conn->link_mode &= ~HCI_LM_MASTER;
2710 else
2711 conn->link_mode |= HCI_LM_MASTER;
2712 }
2713
Johan Hedberg51a8efd2012-01-16 06:10:31 +02002714 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002715
2716 hci_role_switch_cfm(conn, ev->status, ev->role);
2717 }
2718
2719 hci_dev_unlock(hdev);
2720}
2721
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002722static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002724 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 int i;
2726
Andrei Emeltchenko32ac5b92011-12-19 16:31:29 +02002727 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) {
2728 BT_ERR("Wrong event for mode %d", hdev->flow_ctl_mode);
2729 return;
2730 }
2731
Andrei Emeltchenkoc5993de2011-12-30 12:07:47 +02002732 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) +
Gustavo Padovan807deac2012-05-17 00:36:24 -03002733 ev->num_hndl * sizeof(struct hci_comp_pkts_info)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 BT_DBG("%s bad parameters", hdev->name);
2735 return;
2736 }
2737
Andrei Emeltchenkoc5993de2011-12-30 12:07:47 +02002738 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
2739
Andrei Emeltchenko613a1c02011-12-19 16:31:30 +02002740 for (i = 0; i < ev->num_hndl; i++) {
2741 struct hci_comp_pkts_info *info = &ev->handles[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 struct hci_conn *conn;
2743 __u16 handle, count;
2744
Andrei Emeltchenko613a1c02011-12-19 16:31:30 +02002745 handle = __le16_to_cpu(info->handle);
2746 count = __le16_to_cpu(info->count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
2748 conn = hci_conn_hash_lookup_handle(hdev, handle);
Andrei Emeltchenkof4280912011-12-07 15:56:52 +02002749 if (!conn)
2750 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751
Andrei Emeltchenkof4280912011-12-07 15:56:52 +02002752 conn->sent -= count;
2753
2754 switch (conn->type) {
2755 case ACL_LINK:
2756 hdev->acl_cnt += count;
2757 if (hdev->acl_cnt > hdev->acl_pkts)
2758 hdev->acl_cnt = hdev->acl_pkts;
2759 break;
2760
2761 case LE_LINK:
2762 if (hdev->le_pkts) {
2763 hdev->le_cnt += count;
2764 if (hdev->le_cnt > hdev->le_pkts)
2765 hdev->le_cnt = hdev->le_pkts;
2766 } else {
Andrei Emeltchenko70f230202010-12-01 16:58:25 +02002767 hdev->acl_cnt += count;
2768 if (hdev->acl_cnt > hdev->acl_pkts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 hdev->acl_cnt = hdev->acl_pkts;
2770 }
Andrei Emeltchenkof4280912011-12-07 15:56:52 +02002771 break;
2772
2773 case SCO_LINK:
2774 hdev->sco_cnt += count;
2775 if (hdev->sco_cnt > hdev->sco_pkts)
2776 hdev->sco_cnt = hdev->sco_pkts;
2777 break;
2778
2779 default:
2780 BT_ERR("Unknown type %d conn %p", conn->type, conn);
2781 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 }
2783 }
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002784
Gustavo F. Padovan3eff45e2011-12-15 00:50:02 -02002785 queue_work(hdev->workqueue, &hdev->tx_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786}
2787
Andrei Emeltchenko76ef7cf2012-10-10 17:38:29 +03002788static struct hci_conn *__hci_conn_lookup_handle(struct hci_dev *hdev,
2789 __u16 handle)
2790{
2791 struct hci_chan *chan;
2792
2793 switch (hdev->dev_type) {
2794 case HCI_BREDR:
2795 return hci_conn_hash_lookup_handle(hdev, handle);
2796 case HCI_AMP:
2797 chan = hci_chan_lookup_handle(hdev, handle);
2798 if (chan)
2799 return chan->conn;
2800 break;
2801 default:
2802 BT_ERR("%s unknown dev_type %d", hdev->name, hdev->dev_type);
2803 break;
2804 }
2805
2806 return NULL;
2807}
2808
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002809static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)
Andrei Emeltchenko25e89e92012-01-04 12:41:58 +02002810{
2811 struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
2812 int i;
2813
2814 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) {
2815 BT_ERR("Wrong event for mode %d", hdev->flow_ctl_mode);
2816 return;
2817 }
2818
2819 if (skb->len < sizeof(*ev) || skb->len < sizeof(*ev) +
Gustavo Padovan807deac2012-05-17 00:36:24 -03002820 ev->num_hndl * sizeof(struct hci_comp_blocks_info)) {
Andrei Emeltchenko25e89e92012-01-04 12:41:58 +02002821 BT_DBG("%s bad parameters", hdev->name);
2822 return;
2823 }
2824
2825 BT_DBG("%s num_blocks %d num_hndl %d", hdev->name, ev->num_blocks,
Gustavo Padovan807deac2012-05-17 00:36:24 -03002826 ev->num_hndl);
Andrei Emeltchenko25e89e92012-01-04 12:41:58 +02002827
2828 for (i = 0; i < ev->num_hndl; i++) {
2829 struct hci_comp_blocks_info *info = &ev->handles[i];
Andrei Emeltchenko76ef7cf2012-10-10 17:38:29 +03002830 struct hci_conn *conn = NULL;
Andrei Emeltchenko25e89e92012-01-04 12:41:58 +02002831 __u16 handle, block_count;
2832
2833 handle = __le16_to_cpu(info->handle);
2834 block_count = __le16_to_cpu(info->blocks);
2835
Andrei Emeltchenko76ef7cf2012-10-10 17:38:29 +03002836 conn = __hci_conn_lookup_handle(hdev, handle);
Andrei Emeltchenko25e89e92012-01-04 12:41:58 +02002837 if (!conn)
2838 continue;
2839
2840 conn->sent -= block_count;
2841
2842 switch (conn->type) {
2843 case ACL_LINK:
Andrei Emeltchenkobd1eb662012-10-10 17:38:30 +03002844 case AMP_LINK:
Andrei Emeltchenko25e89e92012-01-04 12:41:58 +02002845 hdev->block_cnt += block_count;
2846 if (hdev->block_cnt > hdev->num_blocks)
2847 hdev->block_cnt = hdev->num_blocks;
2848 break;
2849
2850 default:
2851 BT_ERR("Unknown type %d conn %p", conn->type, conn);
2852 break;
2853 }
2854 }
2855
2856 queue_work(hdev->workqueue, &hdev->tx_work);
2857}
2858
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002859static void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002861 struct hci_ev_mode_change *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02002862 struct hci_conn *conn;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03002864 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865
2866 hci_dev_lock(hdev);
2867
Marcel Holtmann04837f62006-07-03 10:02:33 +02002868 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2869 if (conn) {
2870 conn->mode = ev->mode;
2871 conn->interval = __le16_to_cpu(ev->interval);
2872
Gustavo Padovan8fc9ced2012-05-23 04:04:21 -03002873 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND,
2874 &conn->flags)) {
Marcel Holtmann04837f62006-07-03 10:02:33 +02002875 if (conn->mode == HCI_CM_ACTIVE)
Johan Hedberg58a681e2012-01-16 06:47:28 +02002876 set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
Marcel Holtmann04837f62006-07-03 10:02:33 +02002877 else
Johan Hedberg58a681e2012-01-16 06:47:28 +02002878 clear_bit(HCI_CONN_POWER_SAVE, &conn->flags);
Marcel Holtmann04837f62006-07-03 10:02:33 +02002879 }
Marcel Holtmanne73439d2010-07-26 10:06:00 -04002880
Johan Hedberg51a8efd2012-01-16 06:10:31 +02002881 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
Marcel Holtmanne73439d2010-07-26 10:06:00 -04002882 hci_sco_setup(conn, ev->status);
Marcel Holtmann04837f62006-07-03 10:02:33 +02002883 }
2884
2885 hci_dev_unlock(hdev);
2886}
2887
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002888static void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889{
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002890 struct hci_ev_pin_code_req *ev = (void *) skb->data;
2891 struct hci_conn *conn;
2892
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002893 BT_DBG("%s", hdev->name);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002894
2895 hci_dev_lock(hdev);
2896
2897 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Waldemar Rymarkiewiczb6f98042011-09-23 10:01:30 +02002898 if (!conn)
2899 goto unlock;
2900
2901 if (conn->state == BT_CONNECTED) {
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002902 hci_conn_hold(conn);
2903 conn->disc_timeout = HCI_PAIRING_TIMEOUT;
2904 hci_conn_put(conn);
2905 }
2906
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02002907 if (!test_bit(HCI_PAIRABLE, &hdev->dev_flags))
Johan Hedberg03b555e2011-01-04 15:40:05 +02002908 hci_send_cmd(hdev, HCI_OP_PIN_CODE_NEG_REPLY,
Gustavo Padovan807deac2012-05-17 00:36:24 -03002909 sizeof(ev->bdaddr), &ev->bdaddr);
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02002910 else if (test_bit(HCI_MGMT, &hdev->dev_flags)) {
Waldemar Rymarkiewicza770bb52011-04-28 12:07:59 +02002911 u8 secure;
2912
2913 if (conn->pending_sec_level == BT_SECURITY_HIGH)
2914 secure = 1;
2915 else
2916 secure = 0;
2917
Johan Hedberg744cf192011-11-08 20:40:14 +02002918 mgmt_pin_code_request(hdev, &ev->bdaddr, secure);
Waldemar Rymarkiewicza770bb52011-04-28 12:07:59 +02002919 }
Johan Hedberg980e1a52011-01-22 06:10:07 +02002920
Waldemar Rymarkiewiczb6f98042011-09-23 10:01:30 +02002921unlock:
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002922 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923}
2924
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002925static void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926{
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002927 struct hci_ev_link_key_req *ev = (void *) skb->data;
2928 struct hci_cp_link_key_reply cp;
2929 struct hci_conn *conn;
2930 struct link_key *key;
2931
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002932 BT_DBG("%s", hdev->name);
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002933
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02002934 if (!test_bit(HCI_LINK_KEYS, &hdev->dev_flags))
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002935 return;
2936
2937 hci_dev_lock(hdev);
2938
2939 key = hci_find_link_key(hdev, &ev->bdaddr);
2940 if (!key) {
Andrei Emeltchenko6ed93dc2012-09-25 12:49:43 +03002941 BT_DBG("%s link key not found for %pMR", hdev->name,
2942 &ev->bdaddr);
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002943 goto not_found;
2944 }
2945
Andrei Emeltchenko6ed93dc2012-09-25 12:49:43 +03002946 BT_DBG("%s found key type %u for %pMR", hdev->name, key->type,
2947 &ev->bdaddr);
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002948
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02002949 if (!test_bit(HCI_DEBUG_KEYS, &hdev->dev_flags) &&
Gustavo Padovan807deac2012-05-17 00:36:24 -03002950 key->type == HCI_LK_DEBUG_COMBINATION) {
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002951 BT_DBG("%s ignoring debug key", hdev->name);
2952 goto not_found;
2953 }
2954
2955 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Waldemar Rymarkiewicz60b83f52011-04-28 12:07:56 +02002956 if (conn) {
2957 if (key->type == HCI_LK_UNAUTH_COMBINATION &&
Gustavo Padovan807deac2012-05-17 00:36:24 -03002958 conn->auth_type != 0xff && (conn->auth_type & 0x01)) {
Waldemar Rymarkiewicz60b83f52011-04-28 12:07:56 +02002959 BT_DBG("%s ignoring unauthenticated key", hdev->name);
2960 goto not_found;
2961 }
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002962
Waldemar Rymarkiewicz60b83f52011-04-28 12:07:56 +02002963 if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 &&
Gustavo Padovan807deac2012-05-17 00:36:24 -03002964 conn->pending_sec_level == BT_SECURITY_HIGH) {
Gustavo Padovan8fc9ced2012-05-23 04:04:21 -03002965 BT_DBG("%s ignoring key unauthenticated for high security",
2966 hdev->name);
Waldemar Rymarkiewicz60b83f52011-04-28 12:07:56 +02002967 goto not_found;
2968 }
2969
2970 conn->key_type = key->type;
2971 conn->pin_length = key->pin_len;
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002972 }
2973
2974 bacpy(&cp.bdaddr, &ev->bdaddr);
Andrei Emeltchenko9b3b4462012-05-23 11:31:20 +03002975 memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE);
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002976
2977 hci_send_cmd(hdev, HCI_OP_LINK_KEY_REPLY, sizeof(cp), &cp);
2978
2979 hci_dev_unlock(hdev);
2980
2981 return;
2982
2983not_found:
2984 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr);
2985 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986}
2987
Gustavo Padovan6039aa732012-05-23 04:04:18 -03002988static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989{
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002990 struct hci_ev_link_key_notify *ev = (void *) skb->data;
2991 struct hci_conn *conn;
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02002992 u8 pin_len = 0;
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002993
Marcel Holtmanna9de9242007-10-20 13:33:56 +02002994 BT_DBG("%s", hdev->name);
Marcel Holtmann052b30b2009-04-26 20:01:22 +02002995
2996 hci_dev_lock(hdev);
2997
2998 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
2999 if (conn) {
3000 hci_conn_hold(conn);
3001 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
Johan Hedberg980e1a52011-01-22 06:10:07 +02003002 pin_len = conn->pin_length;
Waldemar Rymarkiewicz13d39312011-04-28 12:07:55 +02003003
3004 if (ev->key_type != HCI_LK_CHANGED_COMBINATION)
3005 conn->key_type = ev->key_type;
3006
Marcel Holtmann052b30b2009-04-26 20:01:22 +02003007 hci_conn_put(conn);
3008 }
3009
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02003010 if (test_bit(HCI_LINK_KEYS, &hdev->dev_flags))
Johan Hedbergd25e28a2011-04-28 11:28:59 -07003011 hci_add_link_key(hdev, conn, 1, &ev->bdaddr, ev->link_key,
Gustavo Padovan807deac2012-05-17 00:36:24 -03003012 ev->key_type, pin_len);
Johan Hedberg55ed8ca12011-01-17 14:41:05 +02003013
Marcel Holtmann052b30b2009-04-26 20:01:22 +02003014 hci_dev_unlock(hdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015}
3016
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003017static void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmann04837f62006-07-03 10:02:33 +02003018{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003019 struct hci_ev_clock_offset *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02003020 struct hci_conn *conn;
3021
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03003022 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmann04837f62006-07-03 10:02:33 +02003023
3024 hci_dev_lock(hdev);
3025
3026 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 if (conn && !ev->status) {
3028 struct inquiry_entry *ie;
3029
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02003030 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
3031 if (ie) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 ie->data.clock_offset = ev->clock_offset;
3033 ie->timestamp = jiffies;
3034 }
3035 }
3036
3037 hci_dev_unlock(hdev);
3038}
3039
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003040static void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna8746412008-07-14 20:13:46 +02003041{
3042 struct hci_ev_pkt_type_change *ev = (void *) skb->data;
3043 struct hci_conn *conn;
3044
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03003045 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmanna8746412008-07-14 20:13:46 +02003046
3047 hci_dev_lock(hdev);
3048
3049 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3050 if (conn && !ev->status)
3051 conn->pkt_type = __le16_to_cpu(ev->pkt_type);
3052
3053 hci_dev_unlock(hdev);
3054}
3055
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003056static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmann85a1e932005-08-09 20:28:02 -07003057{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003058 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
Marcel Holtmann85a1e932005-08-09 20:28:02 -07003059 struct inquiry_entry *ie;
3060
3061 BT_DBG("%s", hdev->name);
3062
3063 hci_dev_lock(hdev);
3064
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02003065 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
3066 if (ie) {
Marcel Holtmann85a1e932005-08-09 20:28:02 -07003067 ie->data.pscan_rep_mode = ev->pscan_rep_mode;
3068 ie->timestamp = jiffies;
3069 }
3070
3071 hci_dev_unlock(hdev);
3072}
3073
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003074static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev,
3075 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003076{
3077 struct inquiry_data data;
3078 int num_rsp = *((__u8 *) skb->data);
Johan Hedberg388fc8f2012-02-23 00:38:59 +02003079 bool name_known, ssp;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003080
3081 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
3082
3083 if (!num_rsp)
3084 return;
3085
Andre Guedes1519cc12012-03-21 00:03:38 -03003086 if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags))
3087 return;
3088
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003089 hci_dev_lock(hdev);
3090
3091 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {
Szymon Janc138d22e2011-02-17 16:44:23 +01003092 struct inquiry_info_with_rssi_and_pscan_mode *info;
3093 info = (void *) (skb->data + 1);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003094
Johan Hedberge17acd42011-03-30 23:57:16 +03003095 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003096 bacpy(&data.bdaddr, &info->bdaddr);
3097 data.pscan_rep_mode = info->pscan_rep_mode;
3098 data.pscan_period_mode = info->pscan_period_mode;
3099 data.pscan_mode = info->pscan_mode;
3100 memcpy(data.dev_class, info->dev_class, 3);
3101 data.clock_offset = info->clock_offset;
3102 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02003103 data.ssp_mode = 0x00;
Johan Hedberg31754052012-01-04 13:39:52 +02003104
3105 name_known = hci_inquiry_cache_update(hdev, &data,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003106 false, &ssp);
Johan Hedberg48264f02011-11-09 13:58:58 +02003107 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003108 info->dev_class, info->rssi,
3109 !name_known, ssp, NULL, 0);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003110 }
3111 } else {
3112 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
3113
Johan Hedberge17acd42011-03-30 23:57:16 +03003114 for (; num_rsp; num_rsp--, info++) {
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003115 bacpy(&data.bdaddr, &info->bdaddr);
3116 data.pscan_rep_mode = info->pscan_rep_mode;
3117 data.pscan_period_mode = info->pscan_period_mode;
3118 data.pscan_mode = 0x00;
3119 memcpy(data.dev_class, info->dev_class, 3);
3120 data.clock_offset = info->clock_offset;
3121 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02003122 data.ssp_mode = 0x00;
Johan Hedberg31754052012-01-04 13:39:52 +02003123 name_known = hci_inquiry_cache_update(hdev, &data,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003124 false, &ssp);
Johan Hedberg48264f02011-11-09 13:58:58 +02003125 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003126 info->dev_class, info->rssi,
3127 !name_known, ssp, NULL, 0);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003128 }
3129 }
3130
3131 hci_dev_unlock(hdev);
3132}
3133
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003134static void hci_remote_ext_features_evt(struct hci_dev *hdev,
3135 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003136{
Marcel Holtmann41a96212008-07-14 20:13:48 +02003137 struct hci_ev_remote_ext_features *ev = (void *) skb->data;
3138 struct hci_conn *conn;
3139
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003140 BT_DBG("%s", hdev->name);
Marcel Holtmann41a96212008-07-14 20:13:48 +02003141
Marcel Holtmann41a96212008-07-14 20:13:48 +02003142 hci_dev_lock(hdev);
3143
3144 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Johan Hedbergccd556f2010-11-10 17:11:51 +02003145 if (!conn)
3146 goto unlock;
Marcel Holtmann41a96212008-07-14 20:13:48 +02003147
Johan Hedbergccd556f2010-11-10 17:11:51 +02003148 if (!ev->status && ev->page == 0x01) {
3149 struct inquiry_entry *ie;
Marcel Holtmann41a96212008-07-14 20:13:48 +02003150
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02003151 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
3152 if (ie)
Johan Hedberg02b7cc62012-02-28 02:28:43 +02003153 ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP);
Marcel Holtmann769be972008-07-14 20:13:49 +02003154
Johan Hedberg02b7cc62012-02-28 02:28:43 +02003155 if (ev->features[0] & LMP_HOST_SSP)
Johan Hedberg58a681e2012-01-16 06:47:28 +02003156 set_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
Marcel Holtmann41a96212008-07-14 20:13:48 +02003157 }
3158
Johan Hedbergccd556f2010-11-10 17:11:51 +02003159 if (conn->state != BT_CONFIG)
3160 goto unlock;
3161
Johan Hedberg671267b2012-05-12 16:11:50 -03003162 if (!ev->status && !test_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags)) {
Johan Hedberg127178d2010-11-18 22:22:29 +02003163 struct hci_cp_remote_name_req cp;
3164 memset(&cp, 0, sizeof(cp));
3165 bacpy(&cp.bdaddr, &conn->dst);
3166 cp.pscan_rep_mode = 0x02;
3167 hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
Johan Hedbergb644ba32012-01-17 21:48:47 +02003168 } else if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
3169 mgmt_device_connected(hdev, &conn->dst, conn->type,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003170 conn->dst_type, 0, NULL, 0,
3171 conn->dev_class);
Johan Hedberg392599b2010-11-18 22:22:28 +02003172
Johan Hedberg127178d2010-11-18 22:22:29 +02003173 if (!hci_outgoing_auth_needed(hdev, conn)) {
Johan Hedbergccd556f2010-11-10 17:11:51 +02003174 conn->state = BT_CONNECTED;
3175 hci_proto_connect_cfm(conn, ev->status);
3176 hci_conn_put(conn);
3177 }
3178
3179unlock:
Marcel Holtmann41a96212008-07-14 20:13:48 +02003180 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003181}
3182
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003183static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
3184 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003185{
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02003186 struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
3187 struct hci_conn *conn;
3188
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03003189 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02003190
3191 hci_dev_lock(hdev);
3192
3193 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
Marcel Holtmann9dc0a3a2008-07-14 20:13:46 +02003194 if (!conn) {
3195 if (ev->link_type == ESCO_LINK)
3196 goto unlock;
3197
3198 conn = hci_conn_hash_lookup_ba(hdev, ESCO_LINK, &ev->bdaddr);
3199 if (!conn)
3200 goto unlock;
3201
3202 conn->type = SCO_LINK;
3203 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02003204
Marcel Holtmann732547f2009-04-19 19:14:14 +02003205 switch (ev->status) {
3206 case 0x00:
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02003207 conn->handle = __le16_to_cpu(ev->handle);
3208 conn->state = BT_CONNECTED;
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02003209
Marcel Holtmann9eba32b2009-08-22 14:19:26 -07003210 hci_conn_hold_device(conn);
Marcel Holtmann7d0db0a2008-07-14 20:13:51 +02003211 hci_conn_add_sysfs(conn);
Marcel Holtmann732547f2009-04-19 19:14:14 +02003212 break;
3213
Stephen Coe705e5712010-02-16 11:29:44 -05003214 case 0x11: /* Unsupported Feature or Parameter Value */
Marcel Holtmann732547f2009-04-19 19:14:14 +02003215 case 0x1c: /* SCO interval rejected */
Nick Pelly1038a002010-02-03 11:42:26 -08003216 case 0x1a: /* Unsupported Remote Feature */
Marcel Holtmann732547f2009-04-19 19:14:14 +02003217 case 0x1f: /* Unspecified error */
3218 if (conn->out && conn->attempt < 2) {
3219 conn->pkt_type = (hdev->esco_type & SCO_ESCO_MASK) |
3220 (hdev->esco_type & EDR_ESCO_MASK);
3221 hci_setup_sync(conn, conn->link->handle);
3222 goto unlock;
3223 }
3224 /* fall through */
3225
3226 default:
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02003227 conn->state = BT_CLOSED;
Marcel Holtmann732547f2009-04-19 19:14:14 +02003228 break;
3229 }
Marcel Holtmannb6a0dc82007-10-20 14:55:10 +02003230
3231 hci_proto_connect_cfm(conn, ev->status);
3232 if (ev->status)
3233 hci_conn_del(conn);
3234
3235unlock:
3236 hci_dev_unlock(hdev);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003237}
3238
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003239static void hci_sync_conn_changed_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003240{
3241 BT_DBG("%s", hdev->name);
3242}
3243
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003244static void hci_sniff_subrate_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmann04837f62006-07-03 10:02:33 +02003245{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003246 struct hci_ev_sniff_subrate *ev = (void *) skb->data;
Marcel Holtmann04837f62006-07-03 10:02:33 +02003247
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03003248 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Marcel Holtmann04837f62006-07-03 10:02:33 +02003249}
3250
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003251static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,
3252 struct sk_buff *skb)
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003253{
3254 struct inquiry_data data;
3255 struct extended_inquiry_info *info = (void *) (skb->data + 1);
3256 int num_rsp = *((__u8 *) skb->data);
Vishal Agarwal9d939d92012-04-26 19:19:56 +05303257 size_t eir_len;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003258
3259 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
3260
3261 if (!num_rsp)
3262 return;
3263
Andre Guedes1519cc12012-03-21 00:03:38 -03003264 if (test_bit(HCI_PERIODIC_INQ, &hdev->dev_flags))
3265 return;
3266
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003267 hci_dev_lock(hdev);
3268
Johan Hedberge17acd42011-03-30 23:57:16 +03003269 for (; num_rsp; num_rsp--, info++) {
Johan Hedberg388fc8f2012-02-23 00:38:59 +02003270 bool name_known, ssp;
Johan Hedberg561aafb2012-01-04 13:31:59 +02003271
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003272 bacpy(&data.bdaddr, &info->bdaddr);
Szymon Janc138d22e2011-02-17 16:44:23 +01003273 data.pscan_rep_mode = info->pscan_rep_mode;
3274 data.pscan_period_mode = info->pscan_period_mode;
3275 data.pscan_mode = 0x00;
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003276 memcpy(data.dev_class, info->dev_class, 3);
Szymon Janc138d22e2011-02-17 16:44:23 +01003277 data.clock_offset = info->clock_offset;
3278 data.rssi = info->rssi;
Marcel Holtmann41a96212008-07-14 20:13:48 +02003279 data.ssp_mode = 0x01;
Johan Hedberg561aafb2012-01-04 13:31:59 +02003280
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02003281 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg4ddb1932012-01-15 20:04:43 +02003282 name_known = eir_has_data_type(info->data,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003283 sizeof(info->data),
3284 EIR_NAME_COMPLETE);
Johan Hedberg561aafb2012-01-04 13:31:59 +02003285 else
3286 name_known = true;
3287
Johan Hedberg388fc8f2012-02-23 00:38:59 +02003288 name_known = hci_inquiry_cache_update(hdev, &data, name_known,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003289 &ssp);
Vishal Agarwal9d939d92012-04-26 19:19:56 +05303290 eir_len = eir_get_length(info->data, sizeof(info->data));
Johan Hedberg48264f02011-11-09 13:58:58 +02003291 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003292 info->dev_class, info->rssi, !name_known,
Vishal Agarwal9d939d92012-04-26 19:19:56 +05303293 ssp, info->data, eir_len);
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003294 }
3295
3296 hci_dev_unlock(hdev);
3297}
3298
Johan Hedberg1c2e0042012-06-08 23:31:13 +08003299static void hci_key_refresh_complete_evt(struct hci_dev *hdev,
3300 struct sk_buff *skb)
3301{
3302 struct hci_ev_key_refresh_complete *ev = (void *) skb->data;
3303 struct hci_conn *conn;
3304
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03003305 BT_DBG("%s status 0x%2.2x handle 0x%4.4x", hdev->name, ev->status,
Johan Hedberg1c2e0042012-06-08 23:31:13 +08003306 __le16_to_cpu(ev->handle));
3307
3308 hci_dev_lock(hdev);
3309
3310 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3311 if (!conn)
3312 goto unlock;
3313
3314 if (!ev->status)
3315 conn->sec_level = conn->pending_sec_level;
3316
3317 clear_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags);
3318
3319 if (ev->status && conn->state == BT_CONNECTED) {
3320 hci_acl_disconn(conn, HCI_ERROR_AUTH_FAILURE);
3321 hci_conn_put(conn);
3322 goto unlock;
3323 }
3324
3325 if (conn->state == BT_CONFIG) {
3326 if (!ev->status)
3327 conn->state = BT_CONNECTED;
3328
3329 hci_proto_connect_cfm(conn, ev->status);
3330 hci_conn_put(conn);
3331 } else {
3332 hci_auth_cfm(conn, ev->status);
3333
3334 hci_conn_hold(conn);
3335 conn->disc_timeout = HCI_DISCONN_TIMEOUT;
3336 hci_conn_put(conn);
3337 }
3338
3339unlock:
3340 hci_dev_unlock(hdev);
3341}
3342
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003343static u8 hci_get_auth_req(struct hci_conn *conn)
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003344{
3345 /* If remote requests dedicated bonding follow that lead */
3346 if (conn->remote_auth == 0x02 || conn->remote_auth == 0x03) {
3347 /* If both remote and local IO capabilities allow MITM
3348 * protection then require it, otherwise don't */
3349 if (conn->remote_cap == 0x03 || conn->io_capability == 0x03)
3350 return 0x02;
3351 else
3352 return 0x03;
3353 }
3354
3355 /* If remote requests no-bonding follow that lead */
3356 if (conn->remote_auth == 0x00 || conn->remote_auth == 0x01)
Waldemar Rymarkiewicz58797bf2011-04-28 12:07:58 +02003357 return conn->remote_auth | (conn->auth_type & 0x01);
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003358
3359 return conn->auth_type;
3360}
3361
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003362static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
Marcel Holtmann04936842008-07-14 20:13:48 +02003363{
3364 struct hci_ev_io_capa_request *ev = (void *) skb->data;
3365 struct hci_conn *conn;
3366
3367 BT_DBG("%s", hdev->name);
3368
3369 hci_dev_lock(hdev);
3370
3371 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedberg03b555e2011-01-04 15:40:05 +02003372 if (!conn)
3373 goto unlock;
Marcel Holtmann04936842008-07-14 20:13:48 +02003374
Johan Hedberg03b555e2011-01-04 15:40:05 +02003375 hci_conn_hold(conn);
3376
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02003377 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg03b555e2011-01-04 15:40:05 +02003378 goto unlock;
3379
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02003380 if (test_bit(HCI_PAIRABLE, &hdev->dev_flags) ||
Gustavo Padovan807deac2012-05-17 00:36:24 -03003381 (conn->remote_auth & ~0x01) == HCI_AT_NO_BONDING) {
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003382 struct hci_cp_io_capability_reply cp;
3383
3384 bacpy(&cp.bdaddr, &ev->bdaddr);
Hemant Gupta7a7f1e72012-01-16 13:34:29 +05303385 /* Change the IO capability from KeyboardDisplay
3386 * to DisplayYesNo as it is not supported by BT spec. */
3387 cp.capability = (conn->io_capability == 0x04) ?
3388 0x01 : conn->io_capability;
Johan Hedberg7cbc9bd2011-04-28 11:29:04 -07003389 conn->auth_type = hci_get_auth_req(conn);
3390 cp.authentication = conn->auth_type;
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003391
Gustavo Padovan8fc9ced2012-05-23 04:04:21 -03003392 if (hci_find_remote_oob_data(hdev, &conn->dst) &&
3393 (conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags)))
Szymon Jancce85ee12011-03-22 13:12:23 +01003394 cp.oob_data = 0x01;
3395 else
3396 cp.oob_data = 0x00;
3397
Johan Hedberg17fa4b92011-01-25 13:28:33 +02003398 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_REPLY,
Gustavo Padovan807deac2012-05-17 00:36:24 -03003399 sizeof(cp), &cp);
Johan Hedberg03b555e2011-01-04 15:40:05 +02003400 } else {
3401 struct hci_cp_io_capability_neg_reply cp;
3402
3403 bacpy(&cp.bdaddr, &ev->bdaddr);
Andrei Emeltchenko9f5a0d72011-11-07 14:20:25 +02003404 cp.reason = HCI_ERROR_PAIRING_NOT_ALLOWED;
Johan Hedberg03b555e2011-01-04 15:40:05 +02003405
3406 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
Gustavo Padovan807deac2012-05-17 00:36:24 -03003407 sizeof(cp), &cp);
Johan Hedberg03b555e2011-01-04 15:40:05 +02003408 }
3409
3410unlock:
3411 hci_dev_unlock(hdev);
3412}
3413
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003414static void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb)
Johan Hedberg03b555e2011-01-04 15:40:05 +02003415{
3416 struct hci_ev_io_capa_reply *ev = (void *) skb->data;
3417 struct hci_conn *conn;
3418
3419 BT_DBG("%s", hdev->name);
3420
3421 hci_dev_lock(hdev);
3422
3423 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3424 if (!conn)
3425 goto unlock;
3426
Johan Hedberg03b555e2011-01-04 15:40:05 +02003427 conn->remote_cap = ev->capability;
Johan Hedberg03b555e2011-01-04 15:40:05 +02003428 conn->remote_auth = ev->authentication;
Johan Hedberg58a681e2012-01-16 06:47:28 +02003429 if (ev->oob_data)
3430 set_bit(HCI_CONN_REMOTE_OOB, &conn->flags);
Johan Hedberg03b555e2011-01-04 15:40:05 +02003431
3432unlock:
Marcel Holtmann04936842008-07-14 20:13:48 +02003433 hci_dev_unlock(hdev);
3434}
3435
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003436static void hci_user_confirm_request_evt(struct hci_dev *hdev,
3437 struct sk_buff *skb)
Johan Hedberga5c29682011-02-19 12:05:57 -03003438{
3439 struct hci_ev_user_confirm_req *ev = (void *) skb->data;
Johan Hedberg55bc1a32011-04-28 11:28:56 -07003440 int loc_mitm, rem_mitm, confirm_hint = 0;
Johan Hedberg7a828902011-04-28 11:28:53 -07003441 struct hci_conn *conn;
Johan Hedberga5c29682011-02-19 12:05:57 -03003442
3443 BT_DBG("%s", hdev->name);
3444
3445 hci_dev_lock(hdev);
3446
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02003447 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg7a828902011-04-28 11:28:53 -07003448 goto unlock;
Johan Hedberga5c29682011-02-19 12:05:57 -03003449
Johan Hedberg7a828902011-04-28 11:28:53 -07003450 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3451 if (!conn)
3452 goto unlock;
3453
3454 loc_mitm = (conn->auth_type & 0x01);
3455 rem_mitm = (conn->remote_auth & 0x01);
3456
3457 /* If we require MITM but the remote device can't provide that
3458 * (it has NoInputNoOutput) then reject the confirmation
3459 * request. The only exception is when we're dedicated bonding
3460 * initiators (connect_cfm_cb set) since then we always have the MITM
3461 * bit set. */
3462 if (!conn->connect_cfm_cb && loc_mitm && conn->remote_cap == 0x03) {
3463 BT_DBG("Rejecting request: remote device can't provide MITM");
3464 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY,
Gustavo Padovan807deac2012-05-17 00:36:24 -03003465 sizeof(ev->bdaddr), &ev->bdaddr);
Johan Hedberg7a828902011-04-28 11:28:53 -07003466 goto unlock;
3467 }
3468
3469 /* If no side requires MITM protection; auto-accept */
3470 if ((!loc_mitm || conn->remote_cap == 0x03) &&
Gustavo Padovan807deac2012-05-17 00:36:24 -03003471 (!rem_mitm || conn->io_capability == 0x03)) {
Johan Hedberg55bc1a32011-04-28 11:28:56 -07003472
3473 /* If we're not the initiators request authorization to
3474 * proceed from user space (mgmt_user_confirm with
3475 * confirm_hint set to 1). */
Johan Hedberg51a8efd2012-01-16 06:10:31 +02003476 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
Johan Hedberg55bc1a32011-04-28 11:28:56 -07003477 BT_DBG("Confirming auto-accept as acceptor");
3478 confirm_hint = 1;
3479 goto confirm;
3480 }
3481
Johan Hedberg9f616562011-04-28 11:28:54 -07003482 BT_DBG("Auto-accept of user confirmation with %ums delay",
Gustavo Padovan807deac2012-05-17 00:36:24 -03003483 hdev->auto_accept_delay);
Johan Hedberg9f616562011-04-28 11:28:54 -07003484
3485 if (hdev->auto_accept_delay > 0) {
3486 int delay = msecs_to_jiffies(hdev->auto_accept_delay);
3487 mod_timer(&conn->auto_accept_timer, jiffies + delay);
3488 goto unlock;
3489 }
3490
Johan Hedberg7a828902011-04-28 11:28:53 -07003491 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_REPLY,
Gustavo Padovan807deac2012-05-17 00:36:24 -03003492 sizeof(ev->bdaddr), &ev->bdaddr);
Johan Hedberg7a828902011-04-28 11:28:53 -07003493 goto unlock;
3494 }
3495
Johan Hedberg55bc1a32011-04-28 11:28:56 -07003496confirm:
Johan Hedberg272d90d2012-02-09 15:26:12 +02003497 mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0, ev->passkey,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003498 confirm_hint);
Johan Hedberg7a828902011-04-28 11:28:53 -07003499
3500unlock:
Johan Hedberga5c29682011-02-19 12:05:57 -03003501 hci_dev_unlock(hdev);
3502}
3503
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003504static void hci_user_passkey_request_evt(struct hci_dev *hdev,
3505 struct sk_buff *skb)
Brian Gix1143d452011-11-23 08:28:34 -08003506{
3507 struct hci_ev_user_passkey_req *ev = (void *) skb->data;
3508
3509 BT_DBG("%s", hdev->name);
3510
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02003511 if (test_bit(HCI_MGMT, &hdev->dev_flags))
Johan Hedberg272d90d2012-02-09 15:26:12 +02003512 mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0);
Brian Gix1143d452011-11-23 08:28:34 -08003513}
3514
Johan Hedberg92a25252012-09-06 18:39:26 +03003515static void hci_user_passkey_notify_evt(struct hci_dev *hdev,
3516 struct sk_buff *skb)
3517{
3518 struct hci_ev_user_passkey_notify *ev = (void *) skb->data;
3519 struct hci_conn *conn;
3520
3521 BT_DBG("%s", hdev->name);
3522
3523 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3524 if (!conn)
3525 return;
3526
3527 conn->passkey_notify = __le32_to_cpu(ev->passkey);
3528 conn->passkey_entered = 0;
3529
3530 if (test_bit(HCI_MGMT, &hdev->dev_flags))
3531 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
3532 conn->dst_type, conn->passkey_notify,
3533 conn->passkey_entered);
3534}
3535
3536static void hci_keypress_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
3537{
3538 struct hci_ev_keypress_notify *ev = (void *) skb->data;
3539 struct hci_conn *conn;
3540
3541 BT_DBG("%s", hdev->name);
3542
3543 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3544 if (!conn)
3545 return;
3546
3547 switch (ev->type) {
3548 case HCI_KEYPRESS_STARTED:
3549 conn->passkey_entered = 0;
3550 return;
3551
3552 case HCI_KEYPRESS_ENTERED:
3553 conn->passkey_entered++;
3554 break;
3555
3556 case HCI_KEYPRESS_ERASED:
3557 conn->passkey_entered--;
3558 break;
3559
3560 case HCI_KEYPRESS_CLEARED:
3561 conn->passkey_entered = 0;
3562 break;
3563
3564 case HCI_KEYPRESS_COMPLETED:
3565 return;
3566 }
3567
3568 if (test_bit(HCI_MGMT, &hdev->dev_flags))
3569 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
3570 conn->dst_type, conn->passkey_notify,
3571 conn->passkey_entered);
3572}
3573
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003574static void hci_simple_pair_complete_evt(struct hci_dev *hdev,
3575 struct sk_buff *skb)
Marcel Holtmann04936842008-07-14 20:13:48 +02003576{
3577 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
3578 struct hci_conn *conn;
3579
3580 BT_DBG("%s", hdev->name);
3581
3582 hci_dev_lock(hdev);
3583
3584 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
Johan Hedberg2a611692011-02-19 12:06:00 -03003585 if (!conn)
3586 goto unlock;
Marcel Holtmann04936842008-07-14 20:13:48 +02003587
Johan Hedberg2a611692011-02-19 12:06:00 -03003588 /* To avoid duplicate auth_failed events to user space we check
3589 * the HCI_CONN_AUTH_PEND flag which will be set if we
3590 * initiated the authentication. A traditional auth_complete
3591 * event gets always produced as initiator and is also mapped to
3592 * the mgmt_auth_failed event */
Mikel Astizfa1bd912012-08-09 09:52:29 +02003593 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) && ev->status)
Johan Hedbergbab73cb2012-02-09 16:07:29 +02003594 mgmt_auth_failed(hdev, &conn->dst, conn->type, conn->dst_type,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003595 ev->status);
Johan Hedberg2a611692011-02-19 12:06:00 -03003596
3597 hci_conn_put(conn);
3598
3599unlock:
Marcel Holtmann04936842008-07-14 20:13:48 +02003600 hci_dev_unlock(hdev);
3601}
3602
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003603static void hci_remote_host_features_evt(struct hci_dev *hdev,
3604 struct sk_buff *skb)
Marcel Holtmann41a96212008-07-14 20:13:48 +02003605{
3606 struct hci_ev_remote_host_features *ev = (void *) skb->data;
3607 struct inquiry_entry *ie;
3608
3609 BT_DBG("%s", hdev->name);
3610
3611 hci_dev_lock(hdev);
3612
Andrei Emeltchenkocc11b9c2010-11-22 13:21:37 +02003613 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
3614 if (ie)
Johan Hedberg02b7cc62012-02-28 02:28:43 +02003615 ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP);
Marcel Holtmann41a96212008-07-14 20:13:48 +02003616
3617 hci_dev_unlock(hdev);
3618}
3619
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003620static void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
3621 struct sk_buff *skb)
Szymon Janc2763eda2011-03-22 13:12:22 +01003622{
3623 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
3624 struct oob_data *data;
3625
3626 BT_DBG("%s", hdev->name);
3627
3628 hci_dev_lock(hdev);
3629
Johan Hedberga8b2d5c2012-01-08 23:11:15 +02003630 if (!test_bit(HCI_MGMT, &hdev->dev_flags))
Szymon Jance1ba1f12011-04-06 13:01:59 +02003631 goto unlock;
3632
Szymon Janc2763eda2011-03-22 13:12:22 +01003633 data = hci_find_remote_oob_data(hdev, &ev->bdaddr);
3634 if (data) {
3635 struct hci_cp_remote_oob_data_reply cp;
3636
3637 bacpy(&cp.bdaddr, &ev->bdaddr);
3638 memcpy(cp.hash, data->hash, sizeof(cp.hash));
3639 memcpy(cp.randomizer, data->randomizer, sizeof(cp.randomizer));
3640
3641 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_REPLY, sizeof(cp),
Gustavo Padovan807deac2012-05-17 00:36:24 -03003642 &cp);
Szymon Janc2763eda2011-03-22 13:12:22 +01003643 } else {
3644 struct hci_cp_remote_oob_data_neg_reply cp;
3645
3646 bacpy(&cp.bdaddr, &ev->bdaddr);
3647 hci_send_cmd(hdev, HCI_OP_REMOTE_OOB_DATA_NEG_REPLY, sizeof(cp),
Gustavo Padovan807deac2012-05-17 00:36:24 -03003648 &cp);
Szymon Janc2763eda2011-03-22 13:12:22 +01003649 }
3650
Szymon Jance1ba1f12011-04-06 13:01:59 +02003651unlock:
Szymon Janc2763eda2011-03-22 13:12:22 +01003652 hci_dev_unlock(hdev);
3653}
3654
Andrei Emeltchenkod5e91192012-10-25 15:20:44 +03003655static void hci_phy_link_complete_evt(struct hci_dev *hdev,
3656 struct sk_buff *skb)
3657{
3658 struct hci_ev_phy_link_complete *ev = (void *) skb->data;
3659 struct hci_conn *hcon, *bredr_hcon;
3660
3661 BT_DBG("%s handle 0x%2.2x status 0x%2.2x", hdev->name, ev->phy_handle,
3662 ev->status);
3663
3664 hci_dev_lock(hdev);
3665
3666 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3667 if (!hcon) {
3668 hci_dev_unlock(hdev);
3669 return;
3670 }
3671
3672 if (ev->status) {
3673 hci_conn_del(hcon);
3674 hci_dev_unlock(hdev);
3675 return;
3676 }
3677
3678 bredr_hcon = hcon->amp_mgr->l2cap_conn->hcon;
3679
3680 hcon->state = BT_CONNECTED;
3681 bacpy(&hcon->dst, &bredr_hcon->dst);
3682
3683 hci_conn_hold(hcon);
3684 hcon->disc_timeout = HCI_DISCONN_TIMEOUT;
3685 hci_conn_put(hcon);
3686
3687 hci_conn_hold_device(hcon);
3688 hci_conn_add_sysfs(hcon);
3689
3690 hci_dev_unlock(hdev);
3691
3692 if (hcon->out) {
3693 struct hci_dev *bredr_hdev = hci_dev_hold(bredr_hcon->hdev);
3694
3695 if (!bredr_hdev)
3696 return;
3697
3698 /* Placeholder - create chan req
3699 l2cap_chan_create_cfm(bredr_hcon, hcon->remote_id);
3700 */
3701
3702 hci_dev_put(bredr_hdev);
3703 }
3704}
3705
Andrei Emeltchenko27695fb2012-10-25 15:20:45 +03003706static void hci_loglink_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3707{
3708 struct hci_ev_logical_link_complete *ev = (void *) skb->data;
3709 struct hci_conn *hcon;
3710 struct hci_chan *hchan;
3711 struct amp_mgr *mgr;
3712
3713 BT_DBG("%s log_handle 0x%4.4x phy_handle 0x%2.2x status 0x%2.2x",
3714 hdev->name, le16_to_cpu(ev->handle), ev->phy_handle,
3715 ev->status);
3716
3717 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3718 if (!hcon)
3719 return;
3720
3721 /* Create AMP hchan */
3722 hchan = hci_chan_create(hcon);
3723 if (!hchan)
3724 return;
3725
3726 hchan->handle = le16_to_cpu(ev->handle);
3727
3728 BT_DBG("hcon %p mgr %p hchan %p", hcon, hcon->amp_mgr, hchan);
3729
3730 mgr = hcon->amp_mgr;
3731 if (mgr && mgr->bredr_chan) {
3732 struct l2cap_chan *bredr_chan = mgr->bredr_chan;
3733
3734 l2cap_chan_lock(bredr_chan);
3735
3736 bredr_chan->conn->mtu = hdev->block_mtu;
3737 l2cap_logical_cfm(bredr_chan, hchan, 0);
3738 hci_conn_hold(hcon);
3739
3740 l2cap_chan_unlock(bredr_chan);
3741 }
3742}
3743
Andrei Emeltchenko606e2a12012-10-31 15:46:31 +02003744static void hci_disconn_loglink_complete_evt(struct hci_dev *hdev,
3745 struct sk_buff *skb)
3746{
3747 struct hci_ev_disconn_logical_link_complete *ev = (void *) skb->data;
3748 struct hci_chan *hchan;
3749
3750 BT_DBG("%s log handle 0x%4.4x status 0x%2.2x", hdev->name,
3751 le16_to_cpu(ev->handle), ev->status);
3752
3753 if (ev->status)
3754 return;
3755
3756 hci_dev_lock(hdev);
3757
3758 hchan = hci_chan_lookup_handle(hdev, le16_to_cpu(ev->handle));
3759 if (!hchan)
3760 goto unlock;
3761
3762 amp_destroy_logical_link(hchan, ev->reason);
3763
3764unlock:
3765 hci_dev_unlock(hdev);
3766}
3767
Andrei Emeltchenko9eef6b32012-10-31 15:46:32 +02003768static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev,
3769 struct sk_buff *skb)
3770{
3771 struct hci_ev_disconn_phy_link_complete *ev = (void *) skb->data;
3772 struct hci_conn *hcon;
3773
3774 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3775
3776 if (ev->status)
3777 return;
3778
3779 hci_dev_lock(hdev);
3780
3781 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3782 if (hcon) {
3783 hcon->state = BT_CLOSED;
3784 hci_conn_del(hcon);
3785 }
3786
3787 hci_dev_unlock(hdev);
3788}
3789
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003790static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
Ville Tervofcd89c02011-02-10 22:38:47 -03003791{
3792 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
3793 struct hci_conn *conn;
3794
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03003795 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
Ville Tervofcd89c02011-02-10 22:38:47 -03003796
3797 hci_dev_lock(hdev);
3798
Andre Guedesb47a09b2012-07-27 15:10:15 -03003799 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
Ville Tervob62f3282011-02-10 22:38:50 -03003800 if (!conn) {
3801 conn = hci_conn_add(hdev, LE_LINK, &ev->bdaddr);
3802 if (!conn) {
3803 BT_ERR("No memory for new connection");
Andre Guedes230fd162012-07-27 15:10:10 -03003804 goto unlock;
Ville Tervob62f3282011-02-10 22:38:50 -03003805 }
Andre Guedes29b79882011-05-31 14:20:54 -03003806
3807 conn->dst_type = ev->bdaddr_type;
Andre Guedesb9b343d2012-07-27 15:10:11 -03003808
3809 if (ev->role == LE_CONN_ROLE_MASTER) {
3810 conn->out = true;
3811 conn->link_mode |= HCI_LM_MASTER;
3812 }
Ville Tervob62f3282011-02-10 22:38:50 -03003813 }
Ville Tervofcd89c02011-02-10 22:38:47 -03003814
Andre Guedescd17dec2012-07-27 15:10:16 -03003815 if (ev->status) {
3816 mgmt_connect_failed(hdev, &conn->dst, conn->type,
3817 conn->dst_type, ev->status);
3818 hci_proto_connect_cfm(conn, ev->status);
3819 conn->state = BT_CLOSED;
3820 hci_conn_del(conn);
3821 goto unlock;
3822 }
3823
Johan Hedbergb644ba32012-01-17 21:48:47 +02003824 if (!test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
3825 mgmt_device_connected(hdev, &ev->bdaddr, conn->type,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003826 conn->dst_type, 0, NULL, 0, NULL);
Vinicius Costa Gomes83bc71b2011-05-06 18:41:43 -03003827
Vinicius Costa Gomes7b5c0d52011-06-09 18:50:50 -03003828 conn->sec_level = BT_SECURITY_LOW;
Ville Tervofcd89c02011-02-10 22:38:47 -03003829 conn->handle = __le16_to_cpu(ev->handle);
3830 conn->state = BT_CONNECTED;
3831
3832 hci_conn_hold_device(conn);
3833 hci_conn_add_sysfs(conn);
3834
3835 hci_proto_connect_cfm(conn, ev->status);
3836
3837unlock:
3838 hci_dev_unlock(hdev);
3839}
3840
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003841static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
Andre Guedes9aa04c92011-05-26 16:23:51 -03003842{
Andre Guedese95beb42011-09-26 20:48:35 -03003843 u8 num_reports = skb->data[0];
3844 void *ptr = &skb->data[1];
Andre Guedes3c9e9192012-01-10 18:20:50 -03003845 s8 rssi;
Andre Guedes9aa04c92011-05-26 16:23:51 -03003846
3847 hci_dev_lock(hdev);
3848
Andre Guedese95beb42011-09-26 20:48:35 -03003849 while (num_reports--) {
3850 struct hci_ev_le_advertising_info *ev = ptr;
Andre Guedes9aa04c92011-05-26 16:23:51 -03003851
Andre Guedes3c9e9192012-01-10 18:20:50 -03003852 rssi = ev->data[ev->length];
3853 mgmt_device_found(hdev, &ev->bdaddr, LE_LINK, ev->bdaddr_type,
Gustavo F. Padovan04124682012-03-08 01:25:00 -03003854 NULL, rssi, 0, 1, ev->data, ev->length);
Andre Guedes3c9e9192012-01-10 18:20:50 -03003855
Andre Guedese95beb42011-09-26 20:48:35 -03003856 ptr += sizeof(*ev) + ev->length + 1;
Andre Guedes9aa04c92011-05-26 16:23:51 -03003857 }
3858
3859 hci_dev_unlock(hdev);
3860}
3861
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003862static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003863{
3864 struct hci_ev_le_ltk_req *ev = (void *) skb->data;
3865 struct hci_cp_le_ltk_reply cp;
Vinicius Costa Gomesbea710f2011-07-07 18:59:37 -03003866 struct hci_cp_le_ltk_neg_reply neg;
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003867 struct hci_conn *conn;
Vinicius Costa Gomesc9839a12012-02-02 21:08:01 -03003868 struct smp_ltk *ltk;
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003869
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03003870 BT_DBG("%s handle 0x%4.4x", hdev->name, __le16_to_cpu(ev->handle));
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003871
3872 hci_dev_lock(hdev);
3873
3874 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
Vinicius Costa Gomesbea710f2011-07-07 18:59:37 -03003875 if (conn == NULL)
3876 goto not_found;
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003877
Vinicius Costa Gomesbea710f2011-07-07 18:59:37 -03003878 ltk = hci_find_ltk(hdev, ev->ediv, ev->random);
3879 if (ltk == NULL)
3880 goto not_found;
3881
3882 memcpy(cp.ltk, ltk->val, sizeof(ltk->val));
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003883 cp.handle = cpu_to_le16(conn->handle);
Vinicius Costa Gomesc9839a12012-02-02 21:08:01 -03003884
3885 if (ltk->authenticated)
3886 conn->sec_level = BT_SECURITY_HIGH;
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003887
3888 hci_send_cmd(hdev, HCI_OP_LE_LTK_REPLY, sizeof(cp), &cp);
3889
Vinicius Costa Gomesc9839a12012-02-02 21:08:01 -03003890 if (ltk->type & HCI_SMP_STK) {
3891 list_del(&ltk->list);
3892 kfree(ltk);
3893 }
3894
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003895 hci_dev_unlock(hdev);
Vinicius Costa Gomesbea710f2011-07-07 18:59:37 -03003896
3897 return;
3898
3899not_found:
3900 neg.handle = ev->handle;
3901 hci_send_cmd(hdev, HCI_OP_LE_LTK_NEG_REPLY, sizeof(neg), &neg);
3902 hci_dev_unlock(hdev);
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003903}
3904
Gustavo Padovan6039aa732012-05-23 04:04:18 -03003905static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
Ville Tervofcd89c02011-02-10 22:38:47 -03003906{
3907 struct hci_ev_le_meta *le_ev = (void *) skb->data;
3908
3909 skb_pull(skb, sizeof(*le_ev));
3910
3911 switch (le_ev->subevent) {
3912 case HCI_EV_LE_CONN_COMPLETE:
3913 hci_le_conn_complete_evt(hdev, skb);
3914 break;
3915
Andre Guedes9aa04c92011-05-26 16:23:51 -03003916 case HCI_EV_LE_ADVERTISING_REPORT:
3917 hci_le_adv_report_evt(hdev, skb);
3918 break;
3919
Vinicius Costa Gomesa7a595f2011-06-09 18:50:47 -03003920 case HCI_EV_LE_LTK_REQ:
3921 hci_le_ltk_request_evt(hdev, skb);
3922 break;
3923
Ville Tervofcd89c02011-02-10 22:38:47 -03003924 default:
3925 break;
3926 }
3927}
3928
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +03003929static void hci_chan_selected_evt(struct hci_dev *hdev, struct sk_buff *skb)
3930{
3931 struct hci_ev_channel_selected *ev = (void *) skb->data;
3932 struct hci_conn *hcon;
3933
3934 BT_DBG("%s handle 0x%2.2x", hdev->name, ev->phy_handle);
3935
3936 skb_pull(skb, sizeof(*ev));
3937
3938 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
3939 if (!hcon)
3940 return;
3941
3942 amp_read_loc_assoc_final_data(hdev, hcon);
3943}
3944
Linus Torvalds1da177e2005-04-16 15:20:36 -07003945void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
3946{
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003947 struct hci_event_hdr *hdr = (void *) skb->data;
3948 __u8 event = hdr->evt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003949
3950 skb_pull(skb, HCI_EVENT_HDR_SIZE);
3951
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003952 switch (event) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003953 case HCI_EV_INQUIRY_COMPLETE:
3954 hci_inquiry_complete_evt(hdev, skb);
3955 break;
3956
3957 case HCI_EV_INQUIRY_RESULT:
3958 hci_inquiry_result_evt(hdev, skb);
3959 break;
3960
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003961 case HCI_EV_CONN_COMPLETE:
3962 hci_conn_complete_evt(hdev, skb);
Marcel Holtmann21d9e302005-09-13 01:32:25 +02003963 break;
3964
Linus Torvalds1da177e2005-04-16 15:20:36 -07003965 case HCI_EV_CONN_REQUEST:
3966 hci_conn_request_evt(hdev, skb);
3967 break;
3968
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 case HCI_EV_DISCONN_COMPLETE:
3970 hci_disconn_complete_evt(hdev, skb);
3971 break;
3972
Linus Torvalds1da177e2005-04-16 15:20:36 -07003973 case HCI_EV_AUTH_COMPLETE:
3974 hci_auth_complete_evt(hdev, skb);
3975 break;
3976
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003977 case HCI_EV_REMOTE_NAME:
3978 hci_remote_name_evt(hdev, skb);
3979 break;
3980
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 case HCI_EV_ENCRYPT_CHANGE:
3982 hci_encrypt_change_evt(hdev, skb);
3983 break;
3984
Marcel Holtmanna9de9242007-10-20 13:33:56 +02003985 case HCI_EV_CHANGE_LINK_KEY_COMPLETE:
3986 hci_change_link_key_complete_evt(hdev, skb);
3987 break;
3988
3989 case HCI_EV_REMOTE_FEATURES:
3990 hci_remote_features_evt(hdev, skb);
3991 break;
3992
3993 case HCI_EV_REMOTE_VERSION:
3994 hci_remote_version_evt(hdev, skb);
3995 break;
3996
3997 case HCI_EV_QOS_SETUP_COMPLETE:
3998 hci_qos_setup_complete_evt(hdev, skb);
3999 break;
4000
4001 case HCI_EV_CMD_COMPLETE:
4002 hci_cmd_complete_evt(hdev, skb);
4003 break;
4004
4005 case HCI_EV_CMD_STATUS:
4006 hci_cmd_status_evt(hdev, skb);
4007 break;
4008
4009 case HCI_EV_ROLE_CHANGE:
4010 hci_role_change_evt(hdev, skb);
4011 break;
4012
4013 case HCI_EV_NUM_COMP_PKTS:
4014 hci_num_comp_pkts_evt(hdev, skb);
4015 break;
4016
4017 case HCI_EV_MODE_CHANGE:
4018 hci_mode_change_evt(hdev, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004019 break;
4020
4021 case HCI_EV_PIN_CODE_REQ:
4022 hci_pin_code_request_evt(hdev, skb);
4023 break;
4024
4025 case HCI_EV_LINK_KEY_REQ:
4026 hci_link_key_request_evt(hdev, skb);
4027 break;
4028
4029 case HCI_EV_LINK_KEY_NOTIFY:
4030 hci_link_key_notify_evt(hdev, skb);
4031 break;
4032
4033 case HCI_EV_CLOCK_OFFSET:
4034 hci_clock_offset_evt(hdev, skb);
4035 break;
4036
Marcel Holtmanna8746412008-07-14 20:13:46 +02004037 case HCI_EV_PKT_TYPE_CHANGE:
4038 hci_pkt_type_change_evt(hdev, skb);
4039 break;
4040
Marcel Holtmann85a1e932005-08-09 20:28:02 -07004041 case HCI_EV_PSCAN_REP_MODE:
4042 hci_pscan_rep_mode_evt(hdev, skb);
4043 break;
4044
Marcel Holtmanna9de9242007-10-20 13:33:56 +02004045 case HCI_EV_INQUIRY_RESULT_WITH_RSSI:
4046 hci_inquiry_result_with_rssi_evt(hdev, skb);
4047 break;
4048
4049 case HCI_EV_REMOTE_EXT_FEATURES:
4050 hci_remote_ext_features_evt(hdev, skb);
4051 break;
4052
4053 case HCI_EV_SYNC_CONN_COMPLETE:
4054 hci_sync_conn_complete_evt(hdev, skb);
4055 break;
4056
4057 case HCI_EV_SYNC_CONN_CHANGED:
4058 hci_sync_conn_changed_evt(hdev, skb);
4059 break;
4060
Marcel Holtmann04837f62006-07-03 10:02:33 +02004061 case HCI_EV_SNIFF_SUBRATE:
4062 hci_sniff_subrate_evt(hdev, skb);
4063 break;
4064
Marcel Holtmanna9de9242007-10-20 13:33:56 +02004065 case HCI_EV_EXTENDED_INQUIRY_RESULT:
4066 hci_extended_inquiry_result_evt(hdev, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 break;
4068
Johan Hedberg1c2e0042012-06-08 23:31:13 +08004069 case HCI_EV_KEY_REFRESH_COMPLETE:
4070 hci_key_refresh_complete_evt(hdev, skb);
4071 break;
4072
Marcel Holtmann04936842008-07-14 20:13:48 +02004073 case HCI_EV_IO_CAPA_REQUEST:
4074 hci_io_capa_request_evt(hdev, skb);
4075 break;
4076
Johan Hedberg03b555e2011-01-04 15:40:05 +02004077 case HCI_EV_IO_CAPA_REPLY:
4078 hci_io_capa_reply_evt(hdev, skb);
4079 break;
4080
Johan Hedberga5c29682011-02-19 12:05:57 -03004081 case HCI_EV_USER_CONFIRM_REQUEST:
4082 hci_user_confirm_request_evt(hdev, skb);
4083 break;
4084
Brian Gix1143d452011-11-23 08:28:34 -08004085 case HCI_EV_USER_PASSKEY_REQUEST:
4086 hci_user_passkey_request_evt(hdev, skb);
4087 break;
4088
Johan Hedberg92a25252012-09-06 18:39:26 +03004089 case HCI_EV_USER_PASSKEY_NOTIFY:
4090 hci_user_passkey_notify_evt(hdev, skb);
4091 break;
4092
4093 case HCI_EV_KEYPRESS_NOTIFY:
4094 hci_keypress_notify_evt(hdev, skb);
4095 break;
4096
Marcel Holtmann04936842008-07-14 20:13:48 +02004097 case HCI_EV_SIMPLE_PAIR_COMPLETE:
4098 hci_simple_pair_complete_evt(hdev, skb);
4099 break;
4100
Marcel Holtmann41a96212008-07-14 20:13:48 +02004101 case HCI_EV_REMOTE_HOST_FEATURES:
4102 hci_remote_host_features_evt(hdev, skb);
4103 break;
4104
Ville Tervofcd89c02011-02-10 22:38:47 -03004105 case HCI_EV_LE_META:
4106 hci_le_meta_evt(hdev, skb);
4107 break;
4108
Andrei Emeltchenko9495b2e2012-09-27 17:26:22 +03004109 case HCI_EV_CHANNEL_SELECTED:
4110 hci_chan_selected_evt(hdev, skb);
4111 break;
4112
Szymon Janc2763eda2011-03-22 13:12:22 +01004113 case HCI_EV_REMOTE_OOB_DATA_REQUEST:
4114 hci_remote_oob_data_request_evt(hdev, skb);
4115 break;
4116
Andrei Emeltchenkod5e91192012-10-25 15:20:44 +03004117 case HCI_EV_PHY_LINK_COMPLETE:
4118 hci_phy_link_complete_evt(hdev, skb);
4119 break;
4120
Andrei Emeltchenko27695fb2012-10-25 15:20:45 +03004121 case HCI_EV_LOGICAL_LINK_COMPLETE:
4122 hci_loglink_complete_evt(hdev, skb);
4123 break;
4124
Andrei Emeltchenko606e2a12012-10-31 15:46:31 +02004125 case HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE:
4126 hci_disconn_loglink_complete_evt(hdev, skb);
4127 break;
4128
Andrei Emeltchenko9eef6b32012-10-31 15:46:32 +02004129 case HCI_EV_DISCONN_PHY_LINK_COMPLETE:
4130 hci_disconn_phylink_complete_evt(hdev, skb);
4131 break;
4132
Andrei Emeltchenko25e89e92012-01-04 12:41:58 +02004133 case HCI_EV_NUM_COMP_BLOCKS:
4134 hci_num_comp_blocks_evt(hdev, skb);
4135 break;
4136
Marcel Holtmanna9de9242007-10-20 13:33:56 +02004137 default:
Andrei Emeltchenko9f1db002012-07-11 14:32:43 +03004138 BT_DBG("%s event 0x%2.2x", hdev->name, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 break;
4140 }
4141
4142 kfree_skb(skb);
4143 hdev->stat.evt_rx++;
4144}