hci_event.c (f81483aaeb59da530b286fe5d081e1705eb5c886) hci_event.c (72279d17df54d5e4e7910b39c61a3f3464e36633)
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as

--- 31 unchanged lines hidden (view full) ---

40
41#define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \
42 "\x00\x00\x00\x00\x00\x00\x00\x00"
43
44#define secs_to_jiffies(_secs) msecs_to_jiffies((_secs) * 1000)
45
46/* Handle HCI Event packets */
47
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
4
5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as

--- 31 unchanged lines hidden (view full) ---

40
41#define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \
42 "\x00\x00\x00\x00\x00\x00\x00\x00"
43
44#define secs_to_jiffies(_secs) msecs_to_jiffies((_secs) * 1000)
45
46/* Handle HCI Event packets */
47
48static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb,
49 u8 *new_status)
48static void *hci_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb,
49 u8 ev, size_t len)
50{
50{
51 __u8 status = *((__u8 *) skb->data);
51 void *data;
52
52
53 BT_DBG("%s status 0x%2.2x", hdev->name, status);
53 data = skb_pull_data(skb, len);
54 if (!data)
55 bt_dev_err(hdev, "Malformed Event: 0x%2.2x", ev);
54
56
57 return data;
58}
59
60static void *hci_cc_skb_pull(struct hci_dev *hdev, struct sk_buff *skb,
61 u16 op, size_t len)
62{
63 void *data;
64
65 data = skb_pull_data(skb, len);
66 if (!data)
67 bt_dev_err(hdev, "Malformed Command Complete: 0x%4.4x", op);
68
69 return data;
70}
71
72static void *hci_le_ev_skb_pull(struct hci_dev *hdev, struct sk_buff *skb,
73 u8 ev, size_t len)
74{
75 void *data;
76
77 data = skb_pull_data(skb, len);
78 if (!data)
79 bt_dev_err(hdev, "Malformed LE Event: 0x%2.2x", ev);
80
81 return data;
82}
83
84static u8 hci_cc_inquiry_cancel(struct hci_dev *hdev, void *data,
85 struct sk_buff *skb)
86{
87 struct hci_ev_status *rp = data;
88
89 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
90
55 /* It is possible that we receive Inquiry Complete event right
56 * before we receive Inquiry Cancel Command Complete event, in
57 * which case the latter event should have status of Command
58 * Disallowed (0x0c). This should not be treated as error, since
59 * we actually achieve what Inquiry Cancel wants to achieve,
60 * which is to end the last Inquiry session.
61 */
91 /* It is possible that we receive Inquiry Complete event right
92 * before we receive Inquiry Cancel Command Complete event, in
93 * which case the latter event should have status of Command
94 * Disallowed (0x0c). This should not be treated as error, since
95 * we actually achieve what Inquiry Cancel wants to achieve,
96 * which is to end the last Inquiry session.
97 */
62 if (status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) {
98 if (rp->status == 0x0c && !test_bit(HCI_INQUIRY, &hdev->flags)) {
63 bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command");
99 bt_dev_warn(hdev, "Ignoring error of Inquiry Cancel command");
64 status = 0x00;
100 rp->status = 0x00;
65 }
66
101 }
102
67 *new_status = status;
103 if (rp->status)
104 return rp->status;
68
105
69 if (status)
70 return;
71
72 clear_bit(HCI_INQUIRY, &hdev->flags);
73 smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */
74 wake_up_bit(&hdev->flags, HCI_INQUIRY);
75
76 hci_dev_lock(hdev);
77 /* Set discovery state to stopped if we're not doing LE active
78 * scanning.
79 */
80 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
81 hdev->le_scan_type != LE_SCAN_ACTIVE)
82 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
83 hci_dev_unlock(hdev);
84
85 hci_conn_check_pending(hdev);
106 clear_bit(HCI_INQUIRY, &hdev->flags);
107 smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */
108 wake_up_bit(&hdev->flags, HCI_INQUIRY);
109
110 hci_dev_lock(hdev);
111 /* Set discovery state to stopped if we're not doing LE active
112 * scanning.
113 */
114 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
115 hdev->le_scan_type != LE_SCAN_ACTIVE)
116 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
117 hci_dev_unlock(hdev);
118
119 hci_conn_check_pending(hdev);
120
121 return rp->status;
86}
87
122}
123
88static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
124static u8 hci_cc_periodic_inq(struct hci_dev *hdev, void *data,
125 struct sk_buff *skb)
89{
126{
90 __u8 status = *((__u8 *) skb->data);
127 struct hci_ev_status *rp = data;
91
128
92 BT_DBG("%s status 0x%2.2x", hdev->name, status);
129 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
93
130
94 if (status)
95 return;
131 if (rp->status)
132 return rp->status;
96
97 hci_dev_set_flag(hdev, HCI_PERIODIC_INQ);
133
134 hci_dev_set_flag(hdev, HCI_PERIODIC_INQ);
135
136 return rp->status;
98}
99
137}
138
100static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
139static u8 hci_cc_exit_periodic_inq(struct hci_dev *hdev, void *data,
140 struct sk_buff *skb)
101{
141{
102 __u8 status = *((__u8 *) skb->data);
142 struct hci_ev_status *rp = data;
103
143
104 BT_DBG("%s status 0x%2.2x", hdev->name, status);
144 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
105
145
106 if (status)
107 return;
146 if (rp->status)
147 return rp->status;
108
109 hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ);
110
111 hci_conn_check_pending(hdev);
148
149 hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ);
150
151 hci_conn_check_pending(hdev);
152
153 return rp->status;
112}
113
154}
155
114static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev,
115 struct sk_buff *skb)
156static u8 hci_cc_remote_name_req_cancel(struct hci_dev *hdev, void *data,
157 struct sk_buff *skb)
116{
158{
117 BT_DBG("%s", hdev->name);
159 struct hci_ev_status *rp = data;
160
161 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
162
163 return rp->status;
118}
119
164}
165
120static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
166static u8 hci_cc_role_discovery(struct hci_dev *hdev, void *data,
167 struct sk_buff *skb)
121{
168{
122 struct hci_rp_role_discovery *rp = (void *) skb->data;
169 struct hci_rp_role_discovery *rp = data;
123 struct hci_conn *conn;
124
170 struct hci_conn *conn;
171
125 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
172 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
126
127 if (rp->status)
173
174 if (rp->status)
128 return;
175 return rp->status;
129
130 hci_dev_lock(hdev);
131
132 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
133 if (conn)
134 conn->role = rp->role;
135
136 hci_dev_unlock(hdev);
176
177 hci_dev_lock(hdev);
178
179 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
180 if (conn)
181 conn->role = rp->role;
182
183 hci_dev_unlock(hdev);
184
185 return rp->status;
137}
138
186}
187
139static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
188static u8 hci_cc_read_link_policy(struct hci_dev *hdev, void *data,
189 struct sk_buff *skb)
140{
190{
141 struct hci_rp_read_link_policy *rp = (void *) skb->data;
191 struct hci_rp_read_link_policy *rp = data;
142 struct hci_conn *conn;
143
192 struct hci_conn *conn;
193
144 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
194 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
145
146 if (rp->status)
195
196 if (rp->status)
147 return;
197 return rp->status;
148
149 hci_dev_lock(hdev);
150
151 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
152 if (conn)
153 conn->link_policy = __le16_to_cpu(rp->policy);
154
155 hci_dev_unlock(hdev);
198
199 hci_dev_lock(hdev);
200
201 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
202 if (conn)
203 conn->link_policy = __le16_to_cpu(rp->policy);
204
205 hci_dev_unlock(hdev);
206
207 return rp->status;
156}
157
208}
209
158static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
210static u8 hci_cc_write_link_policy(struct hci_dev *hdev, void *data,
211 struct sk_buff *skb)
159{
212{
160 struct hci_rp_write_link_policy *rp = (void *) skb->data;
213 struct hci_rp_write_link_policy *rp = data;
161 struct hci_conn *conn;
162 void *sent;
163
214 struct hci_conn *conn;
215 void *sent;
216
164 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
217 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
165
166 if (rp->status)
218
219 if (rp->status)
167 return;
220 return rp->status;
168
169 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
170 if (!sent)
221
222 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
223 if (!sent)
171 return;
224 return rp->status;
172
173 hci_dev_lock(hdev);
174
175 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
176 if (conn)
177 conn->link_policy = get_unaligned_le16(sent + 2);
178
179 hci_dev_unlock(hdev);
225
226 hci_dev_lock(hdev);
227
228 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
229 if (conn)
230 conn->link_policy = get_unaligned_le16(sent + 2);
231
232 hci_dev_unlock(hdev);
233
234 return rp->status;
180}
181
235}
236
182static void hci_cc_read_def_link_policy(struct hci_dev *hdev,
183 struct sk_buff *skb)
237static u8 hci_cc_read_def_link_policy(struct hci_dev *hdev, void *data,
238 struct sk_buff *skb)
184{
239{
185 struct hci_rp_read_def_link_policy *rp = (void *) skb->data;
240 struct hci_rp_read_def_link_policy *rp = data;
186
241
187 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
242 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
188
189 if (rp->status)
243
244 if (rp->status)
190 return;
245 return rp->status;
191
192 hdev->link_policy = __le16_to_cpu(rp->policy);
246
247 hdev->link_policy = __le16_to_cpu(rp->policy);
248
249 return rp->status;
193}
194
250}
251
195static void hci_cc_write_def_link_policy(struct hci_dev *hdev,
196 struct sk_buff *skb)
252static u8 hci_cc_write_def_link_policy(struct hci_dev *hdev, void *data,
253 struct sk_buff *skb)
197{
254{
198 __u8 status = *((__u8 *) skb->data);
255 struct hci_ev_status *rp = data;
199 void *sent;
200
256 void *sent;
257
201 BT_DBG("%s status 0x%2.2x", hdev->name, status);
258 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
202
259
203 if (status)
204 return;
260 if (rp->status)
261 return rp->status;
205
206 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
207 if (!sent)
262
263 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
264 if (!sent)
208 return;
265 return rp->status;
209
210 hdev->link_policy = get_unaligned_le16(sent);
266
267 hdev->link_policy = get_unaligned_le16(sent);
268
269 return rp->status;
211}
212
270}
271
213static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
272static u8 hci_cc_reset(struct hci_dev *hdev, void *data, struct sk_buff *skb)
214{
273{
215 __u8 status = *((__u8 *) skb->data);
274 struct hci_ev_status *rp = data;
216
275
217 BT_DBG("%s status 0x%2.2x", hdev->name, status);
276 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
218
219 clear_bit(HCI_RESET, &hdev->flags);
220
277
278 clear_bit(HCI_RESET, &hdev->flags);
279
221 if (status)
222 return;
280 if (rp->status)
281 return rp->status;
223
224 /* Reset all non-persistent flags */
225 hci_dev_clear_volatile_flags(hdev);
226
227 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
228
229 hdev->inq_tx_power = HCI_TX_POWER_INVALID;
230 hdev->adv_tx_power = HCI_TX_POWER_INVALID;

--- 5 unchanged lines hidden (view full) ---

236 hdev->scan_rsp_data_len = 0;
237
238 hdev->le_scan_type = LE_SCAN_PASSIVE;
239
240 hdev->ssp_debug_mode = 0;
241
242 hci_bdaddr_list_clear(&hdev->le_accept_list);
243 hci_bdaddr_list_clear(&hdev->le_resolv_list);
282
283 /* Reset all non-persistent flags */
284 hci_dev_clear_volatile_flags(hdev);
285
286 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
287
288 hdev->inq_tx_power = HCI_TX_POWER_INVALID;
289 hdev->adv_tx_power = HCI_TX_POWER_INVALID;

--- 5 unchanged lines hidden (view full) ---

295 hdev->scan_rsp_data_len = 0;
296
297 hdev->le_scan_type = LE_SCAN_PASSIVE;
298
299 hdev->ssp_debug_mode = 0;
300
301 hci_bdaddr_list_clear(&hdev->le_accept_list);
302 hci_bdaddr_list_clear(&hdev->le_resolv_list);
303
304 return rp->status;
244}
245
305}
306
246static void hci_cc_read_stored_link_key(struct hci_dev *hdev,
247 struct sk_buff *skb)
307static u8 hci_cc_read_stored_link_key(struct hci_dev *hdev, void *data,
308 struct sk_buff *skb)
248{
309{
249 struct hci_rp_read_stored_link_key *rp = (void *)skb->data;
310 struct hci_rp_read_stored_link_key *rp = data;
250 struct hci_cp_read_stored_link_key *sent;
251
311 struct hci_cp_read_stored_link_key *sent;
312
252 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
313 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
253
254 sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY);
255 if (!sent)
314
315 sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY);
316 if (!sent)
256 return;
317 return rp->status;
257
258 if (!rp->status && sent->read_all == 0x01) {
318
319 if (!rp->status && sent->read_all == 0x01) {
259 hdev->stored_max_keys = rp->max_keys;
260 hdev->stored_num_keys = rp->num_keys;
320 hdev->stored_max_keys = le16_to_cpu(rp->max_keys);
321 hdev->stored_num_keys = le16_to_cpu(rp->num_keys);
261 }
322 }
323
324 return rp->status;
262}
263
325}
326
264static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
265 struct sk_buff *skb)
327static u8 hci_cc_delete_stored_link_key(struct hci_dev *hdev, void *data,
328 struct sk_buff *skb)
266{
329{
267 struct hci_rp_delete_stored_link_key *rp = (void *)skb->data;
330 struct hci_rp_delete_stored_link_key *rp = data;
268
331
269 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
332 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
270
271 if (rp->status)
333
334 if (rp->status)
272 return;
335 return rp->status;
273
274 if (rp->num_keys <= hdev->stored_num_keys)
336
337 if (rp->num_keys <= hdev->stored_num_keys)
275 hdev->stored_num_keys -= rp->num_keys;
338 hdev->stored_num_keys -= le16_to_cpu(rp->num_keys);
276 else
277 hdev->stored_num_keys = 0;
339 else
340 hdev->stored_num_keys = 0;
341
342 return rp->status;
278}
279
343}
344
280static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
345static u8 hci_cc_write_local_name(struct hci_dev *hdev, void *data,
346 struct sk_buff *skb)
281{
347{
282 __u8 status = *((__u8 *) skb->data);
348 struct hci_ev_status *rp = data;
283 void *sent;
284
349 void *sent;
350
285 BT_DBG("%s status 0x%2.2x", hdev->name, status);
351 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
286
287 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
288 if (!sent)
352
353 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
354 if (!sent)
289 return;
355 return rp->status;
290
291 hci_dev_lock(hdev);
292
293 if (hci_dev_test_flag(hdev, HCI_MGMT))
356
357 hci_dev_lock(hdev);
358
359 if (hci_dev_test_flag(hdev, HCI_MGMT))
294 mgmt_set_local_name_complete(hdev, sent, status);
295 else if (!status)
360 mgmt_set_local_name_complete(hdev, sent, rp->status);
361 else if (!rp->status)
296 memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
297
298 hci_dev_unlock(hdev);
362 memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
363
364 hci_dev_unlock(hdev);
365
366 return rp->status;
299}
300
367}
368
301static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
369static u8 hci_cc_read_local_name(struct hci_dev *hdev, void *data,
370 struct sk_buff *skb)
302{
371{
303 struct hci_rp_read_local_name *rp = (void *) skb->data;
372 struct hci_rp_read_local_name *rp = data;
304
373
305 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
374 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
306
307 if (rp->status)
375
376 if (rp->status)
308 return;
377 return rp->status;
309
310 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
311 hci_dev_test_flag(hdev, HCI_CONFIG))
312 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
378
379 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
380 hci_dev_test_flag(hdev, HCI_CONFIG))
381 memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
382
383 return rp->status;
313}
314
384}
385
315static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
386static u8 hci_cc_write_auth_enable(struct hci_dev *hdev, void *data,
387 struct sk_buff *skb)
316{
388{
317 __u8 status = *((__u8 *) skb->data);
389 struct hci_ev_status *rp = data;
318 void *sent;
319
390 void *sent;
391
320 BT_DBG("%s status 0x%2.2x", hdev->name, status);
392 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
321
322 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
323 if (!sent)
393
394 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
395 if (!sent)
324 return;
396 return rp->status;
325
326 hci_dev_lock(hdev);
327
397
398 hci_dev_lock(hdev);
399
328 if (!status) {
400 if (!rp->status) {
329 __u8 param = *((__u8 *) sent);
330
331 if (param == AUTH_ENABLED)
332 set_bit(HCI_AUTH, &hdev->flags);
333 else
334 clear_bit(HCI_AUTH, &hdev->flags);
335 }
336
337 if (hci_dev_test_flag(hdev, HCI_MGMT))
401 __u8 param = *((__u8 *) sent);
402
403 if (param == AUTH_ENABLED)
404 set_bit(HCI_AUTH, &hdev->flags);
405 else
406 clear_bit(HCI_AUTH, &hdev->flags);
407 }
408
409 if (hci_dev_test_flag(hdev, HCI_MGMT))
338 mgmt_auth_enable_complete(hdev, status);
410 mgmt_auth_enable_complete(hdev, rp->status);
339
340 hci_dev_unlock(hdev);
411
412 hci_dev_unlock(hdev);
413
414 return rp->status;
341}
342
415}
416
343static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
417static u8 hci_cc_write_encrypt_mode(struct hci_dev *hdev, void *data,
418 struct sk_buff *skb)
344{
419{
345 __u8 status = *((__u8 *) skb->data);
420 struct hci_ev_status *rp = data;
346 __u8 param;
347 void *sent;
348
421 __u8 param;
422 void *sent;
423
349 BT_DBG("%s status 0x%2.2x", hdev->name, status);
424 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
350
425
351 if (status)
352 return;
426 if (rp->status)
427 return rp->status;
353
354 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
355 if (!sent)
428
429 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
430 if (!sent)
356 return;
431 return rp->status;
357
358 param = *((__u8 *) sent);
359
360 if (param)
361 set_bit(HCI_ENCRYPT, &hdev->flags);
362 else
363 clear_bit(HCI_ENCRYPT, &hdev->flags);
432
433 param = *((__u8 *) sent);
434
435 if (param)
436 set_bit(HCI_ENCRYPT, &hdev->flags);
437 else
438 clear_bit(HCI_ENCRYPT, &hdev->flags);
439
440 return rp->status;
364}
365
441}
442
366static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
443static u8 hci_cc_write_scan_enable(struct hci_dev *hdev, void *data,
444 struct sk_buff *skb)
367{
445{
368 __u8 status = *((__u8 *) skb->data);
446 struct hci_ev_status *rp = data;
369 __u8 param;
370 void *sent;
371
447 __u8 param;
448 void *sent;
449
372 BT_DBG("%s status 0x%2.2x", hdev->name, status);
450 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
373
374 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
375 if (!sent)
451
452 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
453 if (!sent)
376 return;
454 return rp->status;
377
378 param = *((__u8 *) sent);
379
380 hci_dev_lock(hdev);
381
455
456 param = *((__u8 *) sent);
457
458 hci_dev_lock(hdev);
459
382 if (status) {
460 if (rp->status) {
383 hdev->discov_timeout = 0;
384 goto done;
385 }
386
387 if (param & SCAN_INQUIRY)
388 set_bit(HCI_ISCAN, &hdev->flags);
389 else
390 clear_bit(HCI_ISCAN, &hdev->flags);
391
392 if (param & SCAN_PAGE)
393 set_bit(HCI_PSCAN, &hdev->flags);
394 else
395 clear_bit(HCI_PSCAN, &hdev->flags);
396
397done:
398 hci_dev_unlock(hdev);
461 hdev->discov_timeout = 0;
462 goto done;
463 }
464
465 if (param & SCAN_INQUIRY)
466 set_bit(HCI_ISCAN, &hdev->flags);
467 else
468 clear_bit(HCI_ISCAN, &hdev->flags);
469
470 if (param & SCAN_PAGE)
471 set_bit(HCI_PSCAN, &hdev->flags);
472 else
473 clear_bit(HCI_PSCAN, &hdev->flags);
474
475done:
476 hci_dev_unlock(hdev);
477
478 return rp->status;
399}
400
479}
480
401static void hci_cc_set_event_filter(struct hci_dev *hdev, struct sk_buff *skb)
481static u8 hci_cc_set_event_filter(struct hci_dev *hdev, void *data,
482 struct sk_buff *skb)
402{
483{
403 __u8 status = *((__u8 *)skb->data);
484 struct hci_ev_status *rp = data;
404 struct hci_cp_set_event_filter *cp;
405 void *sent;
406
485 struct hci_cp_set_event_filter *cp;
486 void *sent;
487
407 BT_DBG("%s status 0x%2.2x", hdev->name, status);
488 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
408
489
409 if (status)
410 return;
490 if (rp->status)
491 return rp->status;
411
412 sent = hci_sent_cmd_data(hdev, HCI_OP_SET_EVENT_FLT);
413 if (!sent)
492
493 sent = hci_sent_cmd_data(hdev, HCI_OP_SET_EVENT_FLT);
494 if (!sent)
414 return;
495 return rp->status;
415
416 cp = (struct hci_cp_set_event_filter *)sent;
417
418 if (cp->flt_type == HCI_FLT_CLEAR_ALL)
419 hci_dev_clear_flag(hdev, HCI_EVENT_FILTER_CONFIGURED);
420 else
421 hci_dev_set_flag(hdev, HCI_EVENT_FILTER_CONFIGURED);
496
497 cp = (struct hci_cp_set_event_filter *)sent;
498
499 if (cp->flt_type == HCI_FLT_CLEAR_ALL)
500 hci_dev_clear_flag(hdev, HCI_EVENT_FILTER_CONFIGURED);
501 else
502 hci_dev_set_flag(hdev, HCI_EVENT_FILTER_CONFIGURED);
503
504 return rp->status;
422}
423
505}
506
424static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
507static u8 hci_cc_read_class_of_dev(struct hci_dev *hdev, void *data,
508 struct sk_buff *skb)
425{
509{
426 struct hci_rp_read_class_of_dev *rp = (void *) skb->data;
510 struct hci_rp_read_class_of_dev *rp = data;
427
511
428 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
512 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
429
430 if (rp->status)
513
514 if (rp->status)
431 return;
515 return rp->status;
432
433 memcpy(hdev->dev_class, rp->dev_class, 3);
434
516
517 memcpy(hdev->dev_class, rp->dev_class, 3);
518
435 BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
436 hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
519 bt_dev_dbg(hdev, "class 0x%.2x%.2x%.2x", hdev->dev_class[2],
520 hdev->dev_class[1], hdev->dev_class[0]);
521
522 return rp->status;
437}
438
523}
524
439static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
525static u8 hci_cc_write_class_of_dev(struct hci_dev *hdev, void *data,
526 struct sk_buff *skb)
440{
527{
441 __u8 status = *((__u8 *) skb->data);
528 struct hci_ev_status *rp = data;
442 void *sent;
443
529 void *sent;
530
444 BT_DBG("%s status 0x%2.2x", hdev->name, status);
531 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
445
446 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
447 if (!sent)
532
533 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
534 if (!sent)
448 return;
535 return rp->status;
449
450 hci_dev_lock(hdev);
451
536
537 hci_dev_lock(hdev);
538
452 if (status == 0)
539 if (!rp->status)
453 memcpy(hdev->dev_class, sent, 3);
454
455 if (hci_dev_test_flag(hdev, HCI_MGMT))
540 memcpy(hdev->dev_class, sent, 3);
541
542 if (hci_dev_test_flag(hdev, HCI_MGMT))
456 mgmt_set_class_of_dev_complete(hdev, sent, status);
543 mgmt_set_class_of_dev_complete(hdev, sent, rp->status);
457
458 hci_dev_unlock(hdev);
544
545 hci_dev_unlock(hdev);
546
547 return rp->status;
459}
460
548}
549
461static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
550static u8 hci_cc_read_voice_setting(struct hci_dev *hdev, void *data,
551 struct sk_buff *skb)
462{
552{
463 struct hci_rp_read_voice_setting *rp = (void *) skb->data;
553 struct hci_rp_read_voice_setting *rp = data;
464 __u16 setting;
465
554 __u16 setting;
555
466 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
556 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
467
468 if (rp->status)
557
558 if (rp->status)
469 return;
559 return rp->status;
470
471 setting = __le16_to_cpu(rp->voice_setting);
472
473 if (hdev->voice_setting == setting)
560
561 setting = __le16_to_cpu(rp->voice_setting);
562
563 if (hdev->voice_setting == setting)
474 return;
564 return rp->status;
475
476 hdev->voice_setting = setting;
477
565
566 hdev->voice_setting = setting;
567
478 BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting);
568 bt_dev_dbg(hdev, "voice setting 0x%4.4x", setting);
479
480 if (hdev->notify)
481 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
569
570 if (hdev->notify)
571 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
572
573 return rp->status;
482}
483
574}
575
484static void hci_cc_write_voice_setting(struct hci_dev *hdev,
485 struct sk_buff *skb)
576static u8 hci_cc_write_voice_setting(struct hci_dev *hdev, void *data,
577 struct sk_buff *skb)
486{
578{
487 __u8 status = *((__u8 *) skb->data);
579 struct hci_ev_status *rp = data;
488 __u16 setting;
489 void *sent;
490
580 __u16 setting;
581 void *sent;
582
491 BT_DBG("%s status 0x%2.2x", hdev->name, status);
583 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
492
584
493 if (status)
494 return;
585 if (rp->status)
586 return rp->status;
495
496 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
497 if (!sent)
587
588 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
589 if (!sent)
498 return;
590 return rp->status;
499
500 setting = get_unaligned_le16(sent);
501
502 if (hdev->voice_setting == setting)
591
592 setting = get_unaligned_le16(sent);
593
594 if (hdev->voice_setting == setting)
503 return;
595 return rp->status;
504
505 hdev->voice_setting = setting;
506
596
597 hdev->voice_setting = setting;
598
507 BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting);
599 bt_dev_dbg(hdev, "voice setting 0x%4.4x", setting);
508
509 if (hdev->notify)
510 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
600
601 if (hdev->notify)
602 hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
603
604 return rp->status;
511}
512
605}
606
513static void hci_cc_read_num_supported_iac(struct hci_dev *hdev,
514 struct sk_buff *skb)
607static u8 hci_cc_read_num_supported_iac(struct hci_dev *hdev, void *data,
608 struct sk_buff *skb)
515{
609{
516 struct hci_rp_read_num_supported_iac *rp = (void *) skb->data;
610 struct hci_rp_read_num_supported_iac *rp = data;
517
611
518 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
612 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
519
520 if (rp->status)
613
614 if (rp->status)
521 return;
615 return rp->status;
522
523 hdev->num_iac = rp->num_iac;
524
616
617 hdev->num_iac = rp->num_iac;
618
525 BT_DBG("%s num iac %d", hdev->name, hdev->num_iac);
619 bt_dev_dbg(hdev, "num iac %d", hdev->num_iac);
620
621 return rp->status;
526}
527
622}
623
528static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
624static u8 hci_cc_write_ssp_mode(struct hci_dev *hdev, void *data,
625 struct sk_buff *skb)
529{
626{
530 __u8 status = *((__u8 *) skb->data);
627 struct hci_ev_status *rp = data;
531 struct hci_cp_write_ssp_mode *sent;
532
628 struct hci_cp_write_ssp_mode *sent;
629
533 BT_DBG("%s status 0x%2.2x", hdev->name, status);
630 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
534
535 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
536 if (!sent)
631
632 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
633 if (!sent)
537 return;
634 return rp->status;
538
539 hci_dev_lock(hdev);
540
635
636 hci_dev_lock(hdev);
637
541 if (!status) {
638 if (!rp->status) {
542 if (sent->mode)
543 hdev->features[1][0] |= LMP_HOST_SSP;
544 else
545 hdev->features[1][0] &= ~LMP_HOST_SSP;
546 }
547
639 if (sent->mode)
640 hdev->features[1][0] |= LMP_HOST_SSP;
641 else
642 hdev->features[1][0] &= ~LMP_HOST_SSP;
643 }
644
548 if (hci_dev_test_flag(hdev, HCI_MGMT))
549 mgmt_ssp_enable_complete(hdev, sent->mode, status);
550 else if (!status) {
645 if (!rp->status) {
551 if (sent->mode)
552 hci_dev_set_flag(hdev, HCI_SSP_ENABLED);
553 else
554 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED);
555 }
556
557 hci_dev_unlock(hdev);
646 if (sent->mode)
647 hci_dev_set_flag(hdev, HCI_SSP_ENABLED);
648 else
649 hci_dev_clear_flag(hdev, HCI_SSP_ENABLED);
650 }
651
652 hci_dev_unlock(hdev);
653
654 return rp->status;
558}
559
655}
656
560static void hci_cc_write_sc_support(struct hci_dev *hdev, struct sk_buff *skb)
657static u8 hci_cc_write_sc_support(struct hci_dev *hdev, void *data,
658 struct sk_buff *skb)
561{
659{
562 u8 status = *((u8 *) skb->data);
660 struct hci_ev_status *rp = data;
563 struct hci_cp_write_sc_support *sent;
564
661 struct hci_cp_write_sc_support *sent;
662
565 BT_DBG("%s status 0x%2.2x", hdev->name, status);
663 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
566
567 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SC_SUPPORT);
568 if (!sent)
664
665 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SC_SUPPORT);
666 if (!sent)
569 return;
667 return rp->status;
570
571 hci_dev_lock(hdev);
572
668
669 hci_dev_lock(hdev);
670
573 if (!status) {
671 if (!rp->status) {
574 if (sent->support)
575 hdev->features[1][0] |= LMP_HOST_SC;
576 else
577 hdev->features[1][0] &= ~LMP_HOST_SC;
578 }
579
672 if (sent->support)
673 hdev->features[1][0] |= LMP_HOST_SC;
674 else
675 hdev->features[1][0] &= ~LMP_HOST_SC;
676 }
677
580 if (!hci_dev_test_flag(hdev, HCI_MGMT) && !status) {
678 if (!hci_dev_test_flag(hdev, HCI_MGMT) && !rp->status) {
581 if (sent->support)
582 hci_dev_set_flag(hdev, HCI_SC_ENABLED);
583 else
584 hci_dev_clear_flag(hdev, HCI_SC_ENABLED);
585 }
586
587 hci_dev_unlock(hdev);
679 if (sent->support)
680 hci_dev_set_flag(hdev, HCI_SC_ENABLED);
681 else
682 hci_dev_clear_flag(hdev, HCI_SC_ENABLED);
683 }
684
685 hci_dev_unlock(hdev);
686
687 return rp->status;
588}
589
688}
689
590static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
690static u8 hci_cc_read_local_version(struct hci_dev *hdev, void *data,
691 struct sk_buff *skb)
591{
692{
592 struct hci_rp_read_local_version *rp = (void *) skb->data;
693 struct hci_rp_read_local_version *rp = data;
593
694
594 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
695 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
595
596 if (rp->status)
696
697 if (rp->status)
597 return;
698 return rp->status;
598
599 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
600 hci_dev_test_flag(hdev, HCI_CONFIG)) {
601 hdev->hci_ver = rp->hci_ver;
602 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
603 hdev->lmp_ver = rp->lmp_ver;
604 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
605 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
606 }
699
700 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
701 hci_dev_test_flag(hdev, HCI_CONFIG)) {
702 hdev->hci_ver = rp->hci_ver;
703 hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
704 hdev->lmp_ver = rp->lmp_ver;
705 hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
706 hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
707 }
708
709 return rp->status;
607}
608
710}
711
609static void hci_cc_read_local_commands(struct hci_dev *hdev,
610 struct sk_buff *skb)
712static u8 hci_cc_read_local_commands(struct hci_dev *hdev, void *data,
713 struct sk_buff *skb)
611{
714{
612 struct hci_rp_read_local_commands *rp = (void *) skb->data;
715 struct hci_rp_read_local_commands *rp = data;
613
716
614 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
717 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
615
616 if (rp->status)
718
719 if (rp->status)
617 return;
720 return rp->status;
618
619 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
620 hci_dev_test_flag(hdev, HCI_CONFIG))
621 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
721
722 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
723 hci_dev_test_flag(hdev, HCI_CONFIG))
724 memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
725
726 return rp->status;
622}
623
727}
728
624static void hci_cc_read_auth_payload_timeout(struct hci_dev *hdev,
625 struct sk_buff *skb)
729static u8 hci_cc_read_auth_payload_timeout(struct hci_dev *hdev, void *data,
730 struct sk_buff *skb)
626{
731{
627 struct hci_rp_read_auth_payload_to *rp = (void *)skb->data;
732 struct hci_rp_read_auth_payload_to *rp = data;
628 struct hci_conn *conn;
629
733 struct hci_conn *conn;
734
630 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
735 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
631
632 if (rp->status)
736
737 if (rp->status)
633 return;
738 return rp->status;
634
635 hci_dev_lock(hdev);
636
637 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
638 if (conn)
639 conn->auth_payload_timeout = __le16_to_cpu(rp->timeout);
640
641 hci_dev_unlock(hdev);
739
740 hci_dev_lock(hdev);
741
742 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
743 if (conn)
744 conn->auth_payload_timeout = __le16_to_cpu(rp->timeout);
745
746 hci_dev_unlock(hdev);
747
748 return rp->status;
642}
643
749}
750
644static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev,
645 struct sk_buff *skb)
751static u8 hci_cc_write_auth_payload_timeout(struct hci_dev *hdev, void *data,
752 struct sk_buff *skb)
646{
753{
647 struct hci_rp_write_auth_payload_to *rp = (void *)skb->data;
754 struct hci_rp_write_auth_payload_to *rp = data;
648 struct hci_conn *conn;
649 void *sent;
650
755 struct hci_conn *conn;
756 void *sent;
757
651 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
758 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
652
653 if (rp->status)
759
760 if (rp->status)
654 return;
761 return rp->status;
655
656 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO);
657 if (!sent)
762
763 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO);
764 if (!sent)
658 return;
765 return rp->status;
659
660 hci_dev_lock(hdev);
661
662 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
663 if (conn)
664 conn->auth_payload_timeout = get_unaligned_le16(sent + 2);
665
666 hci_dev_unlock(hdev);
766
767 hci_dev_lock(hdev);
768
769 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
770 if (conn)
771 conn->auth_payload_timeout = get_unaligned_le16(sent + 2);
772
773 hci_dev_unlock(hdev);
774
775 return rp->status;
667}
668
776}
777
669static void hci_cc_read_local_features(struct hci_dev *hdev,
670 struct sk_buff *skb)
778static u8 hci_cc_read_local_features(struct hci_dev *hdev, void *data,
779 struct sk_buff *skb)
671{
780{
672 struct hci_rp_read_local_features *rp = (void *) skb->data;
781 struct hci_rp_read_local_features *rp = data;
673
782
674 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
783 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
675
676 if (rp->status)
784
785 if (rp->status)
677 return;
786 return rp->status;
678
679 memcpy(hdev->features, rp->features, 8);
680
681 /* Adjust default settings according to features
682 * supported by device. */
683
684 if (hdev->features[0][0] & LMP_3SLOT)
685 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);

--- 23 unchanged lines hidden (view full) ---

709 if (hdev->features[0][5] & LMP_EDR_ESCO_2M)
710 hdev->esco_type |= (ESCO_2EV3);
711
712 if (hdev->features[0][5] & LMP_EDR_ESCO_3M)
713 hdev->esco_type |= (ESCO_3EV3);
714
715 if (hdev->features[0][5] & LMP_EDR_3S_ESCO)
716 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
787
788 memcpy(hdev->features, rp->features, 8);
789
790 /* Adjust default settings according to features
791 * supported by device. */
792
793 if (hdev->features[0][0] & LMP_3SLOT)
794 hdev->pkt_type |= (HCI_DM3 | HCI_DH3);

--- 23 unchanged lines hidden (view full) ---

818 if (hdev->features[0][5] & LMP_EDR_ESCO_2M)
819 hdev->esco_type |= (ESCO_2EV3);
820
821 if (hdev->features[0][5] & LMP_EDR_ESCO_3M)
822 hdev->esco_type |= (ESCO_3EV3);
823
824 if (hdev->features[0][5] & LMP_EDR_3S_ESCO)
825 hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
826
827 return rp->status;
717}
718
828}
829
719static void hci_cc_read_local_ext_features(struct hci_dev *hdev,
720 struct sk_buff *skb)
830static u8 hci_cc_read_local_ext_features(struct hci_dev *hdev, void *data,
831 struct sk_buff *skb)
721{
832{
722 struct hci_rp_read_local_ext_features *rp = (void *) skb->data;
833 struct hci_rp_read_local_ext_features *rp = data;
723
834
724 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
835 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
725
726 if (rp->status)
836
837 if (rp->status)
727 return;
838 return rp->status;
728
729 if (hdev->max_page < rp->max_page)
730 hdev->max_page = rp->max_page;
731
732 if (rp->page < HCI_MAX_PAGES)
733 memcpy(hdev->features[rp->page], rp->features, 8);
839
840 if (hdev->max_page < rp->max_page)
841 hdev->max_page = rp->max_page;
842
843 if (rp->page < HCI_MAX_PAGES)
844 memcpy(hdev->features[rp->page], rp->features, 8);
845
846 return rp->status;
734}
735
847}
848
736static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
737 struct sk_buff *skb)
849static u8 hci_cc_read_flow_control_mode(struct hci_dev *hdev, void *data,
850 struct sk_buff *skb)
738{
851{
739 struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
852 struct hci_rp_read_flow_control_mode *rp = data;
740
853
741 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
854 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
742
743 if (rp->status)
855
856 if (rp->status)
744 return;
857 return rp->status;
745
746 hdev->flow_ctl_mode = rp->mode;
858
859 hdev->flow_ctl_mode = rp->mode;
860
861 return rp->status;
747}
748
862}
863
749static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
864static u8 hci_cc_read_buffer_size(struct hci_dev *hdev, void *data,
865 struct sk_buff *skb)
750{
866{
751 struct hci_rp_read_buffer_size *rp = (void *) skb->data;
867 struct hci_rp_read_buffer_size *rp = data;
752
868
753 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
869 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
754
755 if (rp->status)
870
871 if (rp->status)
756 return;
872 return rp->status;
757
758 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
759 hdev->sco_mtu = rp->sco_mtu;
760 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
761 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
762
763 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
764 hdev->sco_mtu = 64;
765 hdev->sco_pkts = 8;
766 }
767
768 hdev->acl_cnt = hdev->acl_pkts;
769 hdev->sco_cnt = hdev->sco_pkts;
770
771 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu,
772 hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts);
873
874 hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
875 hdev->sco_mtu = rp->sco_mtu;
876 hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
877 hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
878
879 if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
880 hdev->sco_mtu = 64;
881 hdev->sco_pkts = 8;
882 }
883
884 hdev->acl_cnt = hdev->acl_pkts;
885 hdev->sco_cnt = hdev->sco_pkts;
886
887 BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu,
888 hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts);
889
890 return rp->status;
773}
774
891}
892
775static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
893static u8 hci_cc_read_bd_addr(struct hci_dev *hdev, void *data,
894 struct sk_buff *skb)
776{
895{
777 struct hci_rp_read_bd_addr *rp = (void *) skb->data;
896 struct hci_rp_read_bd_addr *rp = data;
778
897
779 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
898 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
780
781 if (rp->status)
899
900 if (rp->status)
782 return;
901 return rp->status;
783
784 if (test_bit(HCI_INIT, &hdev->flags))
785 bacpy(&hdev->bdaddr, &rp->bdaddr);
786
787 if (hci_dev_test_flag(hdev, HCI_SETUP))
788 bacpy(&hdev->setup_addr, &rp->bdaddr);
902
903 if (test_bit(HCI_INIT, &hdev->flags))
904 bacpy(&hdev->bdaddr, &rp->bdaddr);
905
906 if (hci_dev_test_flag(hdev, HCI_SETUP))
907 bacpy(&hdev->setup_addr, &rp->bdaddr);
908
909 return rp->status;
789}
790
910}
911
791static void hci_cc_read_local_pairing_opts(struct hci_dev *hdev,
792 struct sk_buff *skb)
912static u8 hci_cc_read_local_pairing_opts(struct hci_dev *hdev, void *data,
913 struct sk_buff *skb)
793{
914{
794 struct hci_rp_read_local_pairing_opts *rp = (void *) skb->data;
915 struct hci_rp_read_local_pairing_opts *rp = data;
795
916
796 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
917 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
797
798 if (rp->status)
918
919 if (rp->status)
799 return;
920 return rp->status;
800
801 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
802 hci_dev_test_flag(hdev, HCI_CONFIG)) {
803 hdev->pairing_opts = rp->pairing_opts;
804 hdev->max_enc_key_size = rp->max_key_size;
805 }
921
922 if (hci_dev_test_flag(hdev, HCI_SETUP) ||
923 hci_dev_test_flag(hdev, HCI_CONFIG)) {
924 hdev->pairing_opts = rp->pairing_opts;
925 hdev->max_enc_key_size = rp->max_key_size;
926 }
927
928 return rp->status;
806}
807
929}
930
808static void hci_cc_read_page_scan_activity(struct hci_dev *hdev,
809 struct sk_buff *skb)
931static u8 hci_cc_read_page_scan_activity(struct hci_dev *hdev, void *data,
932 struct sk_buff *skb)
810{
933{
811 struct hci_rp_read_page_scan_activity *rp = (void *) skb->data;
934 struct hci_rp_read_page_scan_activity *rp = data;
812
935
813 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
936 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
814
815 if (rp->status)
937
938 if (rp->status)
816 return;
939 return rp->status;
817
818 if (test_bit(HCI_INIT, &hdev->flags)) {
819 hdev->page_scan_interval = __le16_to_cpu(rp->interval);
820 hdev->page_scan_window = __le16_to_cpu(rp->window);
821 }
940
941 if (test_bit(HCI_INIT, &hdev->flags)) {
942 hdev->page_scan_interval = __le16_to_cpu(rp->interval);
943 hdev->page_scan_window = __le16_to_cpu(rp->window);
944 }
945
946 return rp->status;
822}
823
947}
948
824static void hci_cc_write_page_scan_activity(struct hci_dev *hdev,
825 struct sk_buff *skb)
949static u8 hci_cc_write_page_scan_activity(struct hci_dev *hdev, void *data,
950 struct sk_buff *skb)
826{
951{
827 u8 status = *((u8 *) skb->data);
952 struct hci_ev_status *rp = data;
828 struct hci_cp_write_page_scan_activity *sent;
829
953 struct hci_cp_write_page_scan_activity *sent;
954
830 BT_DBG("%s status 0x%2.2x", hdev->name, status);
955 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
831
956
832 if (status)
833 return;
957 if (rp->status)
958 return rp->status;
834
835 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY);
836 if (!sent)
959
960 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY);
961 if (!sent)
837 return;
962 return rp->status;
838
839 hdev->page_scan_interval = __le16_to_cpu(sent->interval);
840 hdev->page_scan_window = __le16_to_cpu(sent->window);
963
964 hdev->page_scan_interval = __le16_to_cpu(sent->interval);
965 hdev->page_scan_window = __le16_to_cpu(sent->window);
966
967 return rp->status;
841}
842
968}
969
843static void hci_cc_read_page_scan_type(struct hci_dev *hdev,
844 struct sk_buff *skb)
970static u8 hci_cc_read_page_scan_type(struct hci_dev *hdev, void *data,
971 struct sk_buff *skb)
845{
972{
846 struct hci_rp_read_page_scan_type *rp = (void *) skb->data;
973 struct hci_rp_read_page_scan_type *rp = data;
847
974
848 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
975 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
849
850 if (rp->status)
976
977 if (rp->status)
851 return;
978 return rp->status;
852
853 if (test_bit(HCI_INIT, &hdev->flags))
854 hdev->page_scan_type = rp->type;
979
980 if (test_bit(HCI_INIT, &hdev->flags))
981 hdev->page_scan_type = rp->type;
982
983 return rp->status;
855}
856
984}
985
857static void hci_cc_write_page_scan_type(struct hci_dev *hdev,
858 struct sk_buff *skb)
986static u8 hci_cc_write_page_scan_type(struct hci_dev *hdev, void *data,
987 struct sk_buff *skb)
859{
988{
860 u8 status = *((u8 *) skb->data);
989 struct hci_ev_status *rp = data;
861 u8 *type;
862
990 u8 *type;
991
863 BT_DBG("%s status 0x%2.2x", hdev->name, status);
992 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
864
993
865 if (status)
866 return;
994 if (rp->status)
995 return rp->status;
867
868 type = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE);
869 if (type)
870 hdev->page_scan_type = *type;
996
997 type = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE);
998 if (type)
999 hdev->page_scan_type = *type;
1000
1001 return rp->status;
871}
872
1002}
1003
873static void hci_cc_read_data_block_size(struct hci_dev *hdev,
874 struct sk_buff *skb)
1004static u8 hci_cc_read_data_block_size(struct hci_dev *hdev, void *data,
1005 struct sk_buff *skb)
875{
1006{
876 struct hci_rp_read_data_block_size *rp = (void *) skb->data;
1007 struct hci_rp_read_data_block_size *rp = data;
877
1008
878 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1009 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
879
880 if (rp->status)
1010
1011 if (rp->status)
881 return;
1012 return rp->status;
882
883 hdev->block_mtu = __le16_to_cpu(rp->max_acl_len);
884 hdev->block_len = __le16_to_cpu(rp->block_len);
885 hdev->num_blocks = __le16_to_cpu(rp->num_blocks);
886
887 hdev->block_cnt = hdev->num_blocks;
888
889 BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu,
890 hdev->block_cnt, hdev->block_len);
1013
1014 hdev->block_mtu = __le16_to_cpu(rp->max_acl_len);
1015 hdev->block_len = __le16_to_cpu(rp->block_len);
1016 hdev->num_blocks = __le16_to_cpu(rp->num_blocks);
1017
1018 hdev->block_cnt = hdev->num_blocks;
1019
1020 BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu,
1021 hdev->block_cnt, hdev->block_len);
1022
1023 return rp->status;
891}
892
1024}
1025
893static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb)
1026static u8 hci_cc_read_clock(struct hci_dev *hdev, void *data,
1027 struct sk_buff *skb)
894{
1028{
895 struct hci_rp_read_clock *rp = (void *) skb->data;
1029 struct hci_rp_read_clock *rp = data;
896 struct hci_cp_read_clock *cp;
897 struct hci_conn *conn;
898
1030 struct hci_cp_read_clock *cp;
1031 struct hci_conn *conn;
1032
899 BT_DBG("%s", hdev->name);
1033 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
900
1034
901 if (skb->len < sizeof(*rp))
902 return;
903
904 if (rp->status)
1035 if (rp->status)
905 return;
1036 return rp->status;
906
907 hci_dev_lock(hdev);
908
909 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK);
910 if (!cp)
911 goto unlock;
912
913 if (cp->which == 0x00) {

--- 4 unchanged lines hidden (view full) ---

918 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
919 if (conn) {
920 conn->clock = le32_to_cpu(rp->clock);
921 conn->clock_accuracy = le16_to_cpu(rp->accuracy);
922 }
923
924unlock:
925 hci_dev_unlock(hdev);
1037
1038 hci_dev_lock(hdev);
1039
1040 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK);
1041 if (!cp)
1042 goto unlock;
1043
1044 if (cp->which == 0x00) {

--- 4 unchanged lines hidden (view full) ---

1049 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
1050 if (conn) {
1051 conn->clock = le32_to_cpu(rp->clock);
1052 conn->clock_accuracy = le16_to_cpu(rp->accuracy);
1053 }
1054
1055unlock:
1056 hci_dev_unlock(hdev);
1057 return rp->status;
926}
927
1058}
1059
928static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
929 struct sk_buff *skb)
1060static u8 hci_cc_read_local_amp_info(struct hci_dev *hdev, void *data,
1061 struct sk_buff *skb)
930{
1062{
931 struct hci_rp_read_local_amp_info *rp = (void *) skb->data;
1063 struct hci_rp_read_local_amp_info *rp = data;
932
1064
933 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1065 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
934
935 if (rp->status)
1066
1067 if (rp->status)
936 return;
1068 return rp->status;
937
938 hdev->amp_status = rp->amp_status;
939 hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
940 hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
941 hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
942 hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
943 hdev->amp_type = rp->amp_type;
944 hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
945 hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
946 hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
947 hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
1069
1070 hdev->amp_status = rp->amp_status;
1071 hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
1072 hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
1073 hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
1074 hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
1075 hdev->amp_type = rp->amp_type;
1076 hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
1077 hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
1078 hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
1079 hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
1080
1081 return rp->status;
948}
949
1082}
1083
950static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
951 struct sk_buff *skb)
1084static u8 hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev, void *data,
1085 struct sk_buff *skb)
952{
1086{
953 struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data;
1087 struct hci_rp_read_inq_rsp_tx_power *rp = data;
954
1088
955 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1089 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
956
957 if (rp->status)
1090
1091 if (rp->status)
958 return;
1092 return rp->status;
959
960 hdev->inq_tx_power = rp->tx_power;
1093
1094 hdev->inq_tx_power = rp->tx_power;
1095
1096 return rp->status;
961}
962
1097}
1098
963static void hci_cc_read_def_err_data_reporting(struct hci_dev *hdev,
964 struct sk_buff *skb)
1099static u8 hci_cc_read_def_err_data_reporting(struct hci_dev *hdev, void *data,
1100 struct sk_buff *skb)
965{
1101{
966 struct hci_rp_read_def_err_data_reporting *rp = (void *)skb->data;
1102 struct hci_rp_read_def_err_data_reporting *rp = data;
967
1103
968 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1104 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
969
970 if (rp->status)
1105
1106 if (rp->status)
971 return;
1107 return rp->status;
972
973 hdev->err_data_reporting = rp->err_data_reporting;
1108
1109 hdev->err_data_reporting = rp->err_data_reporting;
1110
1111 return rp->status;
974}
975
1112}
1113
976static void hci_cc_write_def_err_data_reporting(struct hci_dev *hdev,
977 struct sk_buff *skb)
1114static u8 hci_cc_write_def_err_data_reporting(struct hci_dev *hdev, void *data,
1115 struct sk_buff *skb)
978{
1116{
979 __u8 status = *((__u8 *)skb->data);
1117 struct hci_ev_status *rp = data;
980 struct hci_cp_write_def_err_data_reporting *cp;
981
1118 struct hci_cp_write_def_err_data_reporting *cp;
1119
982 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1120 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
983
1121
984 if (status)
985 return;
1122 if (rp->status)
1123 return rp->status;
986
987 cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING);
988 if (!cp)
1124
1125 cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING);
1126 if (!cp)
989 return;
1127 return rp->status;
990
991 hdev->err_data_reporting = cp->err_data_reporting;
1128
1129 hdev->err_data_reporting = cp->err_data_reporting;
1130
1131 return rp->status;
992}
993
1132}
1133
994static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb)
1134static u8 hci_cc_pin_code_reply(struct hci_dev *hdev, void *data,
1135 struct sk_buff *skb)
995{
1136{
996 struct hci_rp_pin_code_reply *rp = (void *) skb->data;
1137 struct hci_rp_pin_code_reply *rp = data;
997 struct hci_cp_pin_code_reply *cp;
998 struct hci_conn *conn;
999
1138 struct hci_cp_pin_code_reply *cp;
1139 struct hci_conn *conn;
1140
1000 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1141 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1001
1002 hci_dev_lock(hdev);
1003
1004 if (hci_dev_test_flag(hdev, HCI_MGMT))
1005 mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status);
1006
1007 if (rp->status)
1008 goto unlock;
1009
1010 cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
1011 if (!cp)
1012 goto unlock;
1013
1014 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1015 if (conn)
1016 conn->pin_length = cp->pin_len;
1017
1018unlock:
1019 hci_dev_unlock(hdev);
1142
1143 hci_dev_lock(hdev);
1144
1145 if (hci_dev_test_flag(hdev, HCI_MGMT))
1146 mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status);
1147
1148 if (rp->status)
1149 goto unlock;
1150
1151 cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
1152 if (!cp)
1153 goto unlock;
1154
1155 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1156 if (conn)
1157 conn->pin_length = cp->pin_len;
1158
1159unlock:
1160 hci_dev_unlock(hdev);
1161 return rp->status;
1020}
1021
1162}
1163
1022static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
1164static u8 hci_cc_pin_code_neg_reply(struct hci_dev *hdev, void *data,
1165 struct sk_buff *skb)
1023{
1166{
1024 struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data;
1167 struct hci_rp_pin_code_neg_reply *rp = data;
1025
1168
1026 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1169 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1027
1028 hci_dev_lock(hdev);
1029
1030 if (hci_dev_test_flag(hdev, HCI_MGMT))
1031 mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr,
1032 rp->status);
1033
1034 hci_dev_unlock(hdev);
1170
1171 hci_dev_lock(hdev);
1172
1173 if (hci_dev_test_flag(hdev, HCI_MGMT))
1174 mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr,
1175 rp->status);
1176
1177 hci_dev_unlock(hdev);
1178
1179 return rp->status;
1035}
1036
1180}
1181
1037static void hci_cc_le_read_buffer_size(struct hci_dev *hdev,
1038 struct sk_buff *skb)
1182static u8 hci_cc_le_read_buffer_size(struct hci_dev *hdev, void *data,
1183 struct sk_buff *skb)
1039{
1184{
1040 struct hci_rp_le_read_buffer_size *rp = (void *) skb->data;
1185 struct hci_rp_le_read_buffer_size *rp = data;
1041
1186
1042 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1187 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1043
1044 if (rp->status)
1188
1189 if (rp->status)
1045 return;
1190 return rp->status;
1046
1047 hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
1048 hdev->le_pkts = rp->le_max_pkt;
1049
1050 hdev->le_cnt = hdev->le_pkts;
1051
1052 BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
1191
1192 hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
1193 hdev->le_pkts = rp->le_max_pkt;
1194
1195 hdev->le_cnt = hdev->le_pkts;
1196
1197 BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
1198
1199 return rp->status;
1053}
1054
1200}
1201
1055static void hci_cc_le_read_local_features(struct hci_dev *hdev,
1056 struct sk_buff *skb)
1202static u8 hci_cc_le_read_local_features(struct hci_dev *hdev, void *data,
1203 struct sk_buff *skb)
1057{
1204{
1058 struct hci_rp_le_read_local_features *rp = (void *) skb->data;
1205 struct hci_rp_le_read_local_features *rp = data;
1059
1060 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1061
1062 if (rp->status)
1206
1207 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1208
1209 if (rp->status)
1063 return;
1210 return rp->status;
1064
1065 memcpy(hdev->le_features, rp->features, 8);
1211
1212 memcpy(hdev->le_features, rp->features, 8);
1213
1214 return rp->status;
1066}
1067
1215}
1216
1068static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
1069 struct sk_buff *skb)
1217static u8 hci_cc_le_read_adv_tx_power(struct hci_dev *hdev, void *data,
1218 struct sk_buff *skb)
1070{
1219{
1071 struct hci_rp_le_read_adv_tx_power *rp = (void *) skb->data;
1220 struct hci_rp_le_read_adv_tx_power *rp = data;
1072
1221
1073 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1222 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1074
1075 if (rp->status)
1223
1224 if (rp->status)
1076 return;
1225 return rp->status;
1077
1078 hdev->adv_tx_power = rp->tx_power;
1226
1227 hdev->adv_tx_power = rp->tx_power;
1228
1229 return rp->status;
1079}
1080
1230}
1231
1081static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
1232static u8 hci_cc_user_confirm_reply(struct hci_dev *hdev, void *data,
1233 struct sk_buff *skb)
1082{
1234{
1083 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1235 struct hci_rp_user_confirm_reply *rp = data;
1084
1236
1085 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1237 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1086
1087 hci_dev_lock(hdev);
1088
1089 if (hci_dev_test_flag(hdev, HCI_MGMT))
1090 mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0,
1091 rp->status);
1092
1093 hci_dev_unlock(hdev);
1238
1239 hci_dev_lock(hdev);
1240
1241 if (hci_dev_test_flag(hdev, HCI_MGMT))
1242 mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0,
1243 rp->status);
1244
1245 hci_dev_unlock(hdev);
1246
1247 return rp->status;
1094}
1095
1248}
1249
1096static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
1097 struct sk_buff *skb)
1250static u8 hci_cc_user_confirm_neg_reply(struct hci_dev *hdev, void *data,
1251 struct sk_buff *skb)
1098{
1252{
1099 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1253 struct hci_rp_user_confirm_reply *rp = data;
1100
1254
1101 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1255 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1102
1103 hci_dev_lock(hdev);
1104
1105 if (hci_dev_test_flag(hdev, HCI_MGMT))
1106 mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr,
1107 ACL_LINK, 0, rp->status);
1108
1109 hci_dev_unlock(hdev);
1256
1257 hci_dev_lock(hdev);
1258
1259 if (hci_dev_test_flag(hdev, HCI_MGMT))
1260 mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr,
1261 ACL_LINK, 0, rp->status);
1262
1263 hci_dev_unlock(hdev);
1264
1265 return rp->status;
1110}
1111
1266}
1267
1112static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb)
1268static u8 hci_cc_user_passkey_reply(struct hci_dev *hdev, void *data,
1269 struct sk_buff *skb)
1113{
1270{
1114 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1271 struct hci_rp_user_confirm_reply *rp = data;
1115
1272
1116 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1273 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1117
1118 hci_dev_lock(hdev);
1119
1120 if (hci_dev_test_flag(hdev, HCI_MGMT))
1121 mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK,
1122 0, rp->status);
1123
1124 hci_dev_unlock(hdev);
1274
1275 hci_dev_lock(hdev);
1276
1277 if (hci_dev_test_flag(hdev, HCI_MGMT))
1278 mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK,
1279 0, rp->status);
1280
1281 hci_dev_unlock(hdev);
1282
1283 return rp->status;
1125}
1126
1284}
1285
1127static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
1128 struct sk_buff *skb)
1286static u8 hci_cc_user_passkey_neg_reply(struct hci_dev *hdev, void *data,
1287 struct sk_buff *skb)
1129{
1288{
1130 struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
1289 struct hci_rp_user_confirm_reply *rp = data;
1131
1290
1132 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1291 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1133
1134 hci_dev_lock(hdev);
1135
1136 if (hci_dev_test_flag(hdev, HCI_MGMT))
1137 mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
1138 ACL_LINK, 0, rp->status);
1139
1140 hci_dev_unlock(hdev);
1292
1293 hci_dev_lock(hdev);
1294
1295 if (hci_dev_test_flag(hdev, HCI_MGMT))
1296 mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
1297 ACL_LINK, 0, rp->status);
1298
1299 hci_dev_unlock(hdev);
1300
1301 return rp->status;
1141}
1142
1302}
1303
1143static void hci_cc_read_local_oob_data(struct hci_dev *hdev,
1144 struct sk_buff *skb)
1304static u8 hci_cc_read_local_oob_data(struct hci_dev *hdev, void *data,
1305 struct sk_buff *skb)
1145{
1306{
1146 struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
1307 struct hci_rp_read_local_oob_data *rp = data;
1147
1308
1148 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1309 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1310
1311 return rp->status;
1149}
1150
1312}
1313
1151static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev,
1152 struct sk_buff *skb)
1314static u8 hci_cc_read_local_oob_ext_data(struct hci_dev *hdev, void *data,
1315 struct sk_buff *skb)
1153{
1316{
1154 struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data;
1317 struct hci_rp_read_local_oob_ext_data *rp = data;
1155
1318
1156 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1319 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1320
1321 return rp->status;
1157}
1158
1322}
1323
1159static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb)
1324static u8 hci_cc_le_set_random_addr(struct hci_dev *hdev, void *data,
1325 struct sk_buff *skb)
1160{
1326{
1161 __u8 status = *((__u8 *) skb->data);
1327 struct hci_ev_status *rp = data;
1162 bdaddr_t *sent;
1163
1328 bdaddr_t *sent;
1329
1164 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1330 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1165
1331
1166 if (status)
1167 return;
1332 if (rp->status)
1333 return rp->status;
1168
1169 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR);
1170 if (!sent)
1334
1335 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR);
1336 if (!sent)
1171 return;
1337 return rp->status;
1172
1173 hci_dev_lock(hdev);
1174
1175 bacpy(&hdev->random_addr, sent);
1176
1177 if (!bacmp(&hdev->rpa, sent)) {
1178 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED);
1179 queue_delayed_work(hdev->workqueue, &hdev->rpa_expired,
1180 secs_to_jiffies(hdev->rpa_timeout));
1181 }
1182
1183 hci_dev_unlock(hdev);
1338
1339 hci_dev_lock(hdev);
1340
1341 bacpy(&hdev->random_addr, sent);
1342
1343 if (!bacmp(&hdev->rpa, sent)) {
1344 hci_dev_clear_flag(hdev, HCI_RPA_EXPIRED);
1345 queue_delayed_work(hdev->workqueue, &hdev->rpa_expired,
1346 secs_to_jiffies(hdev->rpa_timeout));
1347 }
1348
1349 hci_dev_unlock(hdev);
1350
1351 return rp->status;
1184}
1185
1352}
1353
1186static void hci_cc_le_set_default_phy(struct hci_dev *hdev, struct sk_buff *skb)
1354static u8 hci_cc_le_set_default_phy(struct hci_dev *hdev, void *data,
1355 struct sk_buff *skb)
1187{
1356{
1188 __u8 status = *((__u8 *) skb->data);
1357 struct hci_ev_status *rp = data;
1189 struct hci_cp_le_set_default_phy *cp;
1190
1358 struct hci_cp_le_set_default_phy *cp;
1359
1191 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1360 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1192
1361
1193 if (status)
1194 return;
1362 if (rp->status)
1363 return rp->status;
1195
1196 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_DEFAULT_PHY);
1197 if (!cp)
1364
1365 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_DEFAULT_PHY);
1366 if (!cp)
1198 return;
1367 return rp->status;
1199
1200 hci_dev_lock(hdev);
1201
1202 hdev->le_tx_def_phys = cp->tx_phys;
1203 hdev->le_rx_def_phys = cp->rx_phys;
1204
1205 hci_dev_unlock(hdev);
1368
1369 hci_dev_lock(hdev);
1370
1371 hdev->le_tx_def_phys = cp->tx_phys;
1372 hdev->le_rx_def_phys = cp->rx_phys;
1373
1374 hci_dev_unlock(hdev);
1375
1376 return rp->status;
1206}
1207
1377}
1378
1208static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev,
1209 struct sk_buff *skb)
1379static u8 hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev, void *data,
1380 struct sk_buff *skb)
1210{
1381{
1211 __u8 status = *((__u8 *) skb->data);
1382 struct hci_ev_status *rp = data;
1212 struct hci_cp_le_set_adv_set_rand_addr *cp;
1213 struct adv_info *adv;
1214
1383 struct hci_cp_le_set_adv_set_rand_addr *cp;
1384 struct adv_info *adv;
1385
1215 if (status)
1216 return;
1386 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1217
1387
1388 if (rp->status)
1389 return rp->status;
1390
1218 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR);
1219 /* Update only in case the adv instance since handle 0x00 shall be using
1220 * HCI_OP_LE_SET_RANDOM_ADDR since that allows both extended and
1221 * non-extended adverting.
1222 */
1223 if (!cp || !cp->handle)
1391 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR);
1392 /* Update only in case the adv instance since handle 0x00 shall be using
1393 * HCI_OP_LE_SET_RANDOM_ADDR since that allows both extended and
1394 * non-extended adverting.
1395 */
1396 if (!cp || !cp->handle)
1224 return;
1397 return rp->status;
1225
1226 hci_dev_lock(hdev);
1227
1228 adv = hci_find_adv_instance(hdev, cp->handle);
1229 if (adv) {
1230 bacpy(&adv->random_addr, &cp->bdaddr);
1231 if (!bacmp(&hdev->rpa, &cp->bdaddr)) {
1232 adv->rpa_expired = false;
1233 queue_delayed_work(hdev->workqueue,
1234 &adv->rpa_expired_cb,
1235 secs_to_jiffies(hdev->rpa_timeout));
1236 }
1237 }
1238
1239 hci_dev_unlock(hdev);
1398
1399 hci_dev_lock(hdev);
1400
1401 adv = hci_find_adv_instance(hdev, cp->handle);
1402 if (adv) {
1403 bacpy(&adv->random_addr, &cp->bdaddr);
1404 if (!bacmp(&hdev->rpa, &cp->bdaddr)) {
1405 adv->rpa_expired = false;
1406 queue_delayed_work(hdev->workqueue,
1407 &adv->rpa_expired_cb,
1408 secs_to_jiffies(hdev->rpa_timeout));
1409 }
1410 }
1411
1412 hci_dev_unlock(hdev);
1413
1414 return rp->status;
1240}
1241
1415}
1416
1242static void hci_cc_le_read_transmit_power(struct hci_dev *hdev,
1243 struct sk_buff *skb)
1417static u8 hci_cc_le_remove_adv_set(struct hci_dev *hdev, void *data,
1418 struct sk_buff *skb)
1244{
1419{
1245 struct hci_rp_le_read_transmit_power *rp = (void *)skb->data;
1420 struct hci_ev_status *rp = data;
1421 u8 *instance;
1422 int err;
1246
1423
1247 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1424 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1248
1249 if (rp->status)
1425
1426 if (rp->status)
1250 return;
1427 return rp->status;
1251
1428
1429 instance = hci_sent_cmd_data(hdev, HCI_OP_LE_REMOVE_ADV_SET);
1430 if (!instance)
1431 return rp->status;
1432
1433 hci_dev_lock(hdev);
1434
1435 err = hci_remove_adv_instance(hdev, *instance);
1436 if (!err)
1437 mgmt_advertising_removed(hci_skb_sk(hdev->sent_cmd), hdev,
1438 *instance);
1439
1440 hci_dev_unlock(hdev);
1441
1442 return rp->status;
1443}
1444
1445static u8 hci_cc_le_clear_adv_sets(struct hci_dev *hdev, void *data,
1446 struct sk_buff *skb)
1447{
1448 struct hci_ev_status *rp = data;
1449 struct adv_info *adv, *n;
1450 int err;
1451
1452 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1453
1454 if (rp->status)
1455 return rp->status;
1456
1457 if (!hci_sent_cmd_data(hdev, HCI_OP_LE_CLEAR_ADV_SETS))
1458 return rp->status;
1459
1460 hci_dev_lock(hdev);
1461
1462 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) {
1463 u8 instance = adv->instance;
1464
1465 err = hci_remove_adv_instance(hdev, instance);
1466 if (!err)
1467 mgmt_advertising_removed(hci_skb_sk(hdev->sent_cmd),
1468 hdev, instance);
1469 }
1470
1471 hci_dev_unlock(hdev);
1472
1473 return rp->status;
1474}
1475
1476static u8 hci_cc_le_read_transmit_power(struct hci_dev *hdev, void *data,
1477 struct sk_buff *skb)
1478{
1479 struct hci_rp_le_read_transmit_power *rp = data;
1480
1481 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1482
1483 if (rp->status)
1484 return rp->status;
1485
1252 hdev->min_le_tx_power = rp->min_le_tx_power;
1253 hdev->max_le_tx_power = rp->max_le_tx_power;
1486 hdev->min_le_tx_power = rp->min_le_tx_power;
1487 hdev->max_le_tx_power = rp->max_le_tx_power;
1488
1489 return rp->status;
1254}
1255
1490}
1491
1256static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
1492static u8 hci_cc_le_set_privacy_mode(struct hci_dev *hdev, void *data,
1493 struct sk_buff *skb)
1257{
1494{
1258 __u8 *sent, status = *((__u8 *) skb->data);
1495 struct hci_ev_status *rp = data;
1496 struct hci_cp_le_set_privacy_mode *cp;
1497 struct hci_conn_params *params;
1259
1498
1260 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1499 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1261
1500
1262 if (status)
1263 return;
1501 if (rp->status)
1502 return rp->status;
1264
1503
1504 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_PRIVACY_MODE);
1505 if (!cp)
1506 return rp->status;
1507
1508 hci_dev_lock(hdev);
1509
1510 params = hci_conn_params_lookup(hdev, &cp->bdaddr, cp->bdaddr_type);
1511 if (params)
1512 params->privacy_mode = cp->mode;
1513
1514 hci_dev_unlock(hdev);
1515
1516 return rp->status;
1517}
1518
1519static u8 hci_cc_le_set_adv_enable(struct hci_dev *hdev, void *data,
1520 struct sk_buff *skb)
1521{
1522 struct hci_ev_status *rp = data;
1523 __u8 *sent;
1524
1525 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1526
1527 if (rp->status)
1528 return rp->status;
1529
1265 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE);
1266 if (!sent)
1530 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE);
1531 if (!sent)
1267 return;
1532 return rp->status;
1268
1269 hci_dev_lock(hdev);
1270
1271 /* If we're doing connection initiation as peripheral. Set a
1272 * timeout in case something goes wrong.
1273 */
1274 if (*sent) {
1275 struct hci_conn *conn;

--- 5 unchanged lines hidden (view full) ---

1281 queue_delayed_work(hdev->workqueue,
1282 &conn->le_conn_timeout,
1283 conn->conn_timeout);
1284 } else {
1285 hci_dev_clear_flag(hdev, HCI_LE_ADV);
1286 }
1287
1288 hci_dev_unlock(hdev);
1533
1534 hci_dev_lock(hdev);
1535
1536 /* If we're doing connection initiation as peripheral. Set a
1537 * timeout in case something goes wrong.
1538 */
1539 if (*sent) {
1540 struct hci_conn *conn;

--- 5 unchanged lines hidden (view full) ---

1546 queue_delayed_work(hdev->workqueue,
1547 &conn->le_conn_timeout,
1548 conn->conn_timeout);
1549 } else {
1550 hci_dev_clear_flag(hdev, HCI_LE_ADV);
1551 }
1552
1553 hci_dev_unlock(hdev);
1554
1555 return rp->status;
1289}
1290
1556}
1557
1291static void hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev,
1292 struct sk_buff *skb)
1558static u8 hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev, void *data,
1559 struct sk_buff *skb)
1293{
1294 struct hci_cp_le_set_ext_adv_enable *cp;
1295 struct hci_cp_ext_adv_set *set;
1560{
1561 struct hci_cp_le_set_ext_adv_enable *cp;
1562 struct hci_cp_ext_adv_set *set;
1296 __u8 status = *((__u8 *) skb->data);
1297 struct adv_info *adv = NULL, *n;
1563 struct adv_info *adv = NULL, *n;
1564 struct hci_ev_status *rp = data;
1298
1565
1299 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1566 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1300
1567
1301 if (status)
1302 return;
1568 if (rp->status)
1569 return rp->status;
1303
1304 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE);
1305 if (!cp)
1570
1571 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE);
1572 if (!cp)
1306 return;
1573 return rp->status;
1307
1308 set = (void *)cp->data;
1309
1310 hci_dev_lock(hdev);
1311
1312 if (cp->num_of_sets)
1313 adv = hci_find_adv_instance(hdev, set->handle);
1314

--- 6 unchanged lines hidden (view full) ---

1321 adv->enabled = true;
1322
1323 conn = hci_lookup_le_connect(hdev);
1324 if (conn)
1325 queue_delayed_work(hdev->workqueue,
1326 &conn->le_conn_timeout,
1327 conn->conn_timeout);
1328 } else {
1574
1575 set = (void *)cp->data;
1576
1577 hci_dev_lock(hdev);
1578
1579 if (cp->num_of_sets)
1580 adv = hci_find_adv_instance(hdev, set->handle);
1581

--- 6 unchanged lines hidden (view full) ---

1588 adv->enabled = true;
1589
1590 conn = hci_lookup_le_connect(hdev);
1591 if (conn)
1592 queue_delayed_work(hdev->workqueue,
1593 &conn->le_conn_timeout,
1594 conn->conn_timeout);
1595 } else {
1329 if (adv) {
1330 adv->enabled = false;
1596 if (cp->num_of_sets) {
1597 if (adv)
1598 adv->enabled = false;
1599
1331 /* If just one instance was disabled check if there are
1332 * any other instance enabled before clearing HCI_LE_ADV
1333 */
1334 list_for_each_entry_safe(adv, n, &hdev->adv_instances,
1335 list) {
1336 if (adv->enabled)
1337 goto unlock;
1338 }

--- 4 unchanged lines hidden (view full) ---

1343 adv->enabled = false;
1344 }
1345
1346 hci_dev_clear_flag(hdev, HCI_LE_ADV);
1347 }
1348
1349unlock:
1350 hci_dev_unlock(hdev);
1600 /* If just one instance was disabled check if there are
1601 * any other instance enabled before clearing HCI_LE_ADV
1602 */
1603 list_for_each_entry_safe(adv, n, &hdev->adv_instances,
1604 list) {
1605 if (adv->enabled)
1606 goto unlock;
1607 }

--- 4 unchanged lines hidden (view full) ---

1612 adv->enabled = false;
1613 }
1614
1615 hci_dev_clear_flag(hdev, HCI_LE_ADV);
1616 }
1617
1618unlock:
1619 hci_dev_unlock(hdev);
1620 return rp->status;
1351}
1352
1621}
1622
1353static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
1623static u8 hci_cc_le_set_scan_param(struct hci_dev *hdev, void *data,
1624 struct sk_buff *skb)
1354{
1355 struct hci_cp_le_set_scan_param *cp;
1625{
1626 struct hci_cp_le_set_scan_param *cp;
1356 __u8 status = *((__u8 *) skb->data);
1627 struct hci_ev_status *rp = data;
1357
1628
1358 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1629 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1359
1630
1360 if (status)
1361 return;
1631 if (rp->status)
1632 return rp->status;
1362
1363 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM);
1364 if (!cp)
1633
1634 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM);
1635 if (!cp)
1365 return;
1636 return rp->status;
1366
1367 hci_dev_lock(hdev);
1368
1369 hdev->le_scan_type = cp->type;
1370
1371 hci_dev_unlock(hdev);
1637
1638 hci_dev_lock(hdev);
1639
1640 hdev->le_scan_type = cp->type;
1641
1642 hci_dev_unlock(hdev);
1643
1644 return rp->status;
1372}
1373
1645}
1646
1374static void hci_cc_le_set_ext_scan_param(struct hci_dev *hdev,
1375 struct sk_buff *skb)
1647static u8 hci_cc_le_set_ext_scan_param(struct hci_dev *hdev, void *data,
1648 struct sk_buff *skb)
1376{
1377 struct hci_cp_le_set_ext_scan_params *cp;
1649{
1650 struct hci_cp_le_set_ext_scan_params *cp;
1378 __u8 status = *((__u8 *) skb->data);
1651 struct hci_ev_status *rp = data;
1379 struct hci_cp_le_scan_phy_params *phy_param;
1380
1652 struct hci_cp_le_scan_phy_params *phy_param;
1653
1381 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1654 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1382
1655
1383 if (status)
1384 return;
1656 if (rp->status)
1657 return rp->status;
1385
1386 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS);
1387 if (!cp)
1658
1659 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS);
1660 if (!cp)
1388 return;
1661 return rp->status;
1389
1390 phy_param = (void *)cp->data;
1391
1392 hci_dev_lock(hdev);
1393
1394 hdev->le_scan_type = phy_param->type;
1395
1396 hci_dev_unlock(hdev);
1662
1663 phy_param = (void *)cp->data;
1664
1665 hci_dev_lock(hdev);
1666
1667 hdev->le_scan_type = phy_param->type;
1668
1669 hci_dev_unlock(hdev);
1670
1671 return rp->status;
1397}
1398
1399static bool has_pending_adv_report(struct hci_dev *hdev)
1400{
1401 struct discovery_state *d = &hdev->discovery;
1402
1403 return bacmp(&d->last_adv_addr, BDADDR_ANY);
1404}

--- 53 unchanged lines hidden (view full) ---

1458 * when it's already disabled.
1459 */
1460 cancel_delayed_work(&hdev->le_scan_disable);
1461
1462 hci_dev_clear_flag(hdev, HCI_LE_SCAN);
1463
1464 /* The HCI_LE_SCAN_INTERRUPTED flag indicates that we
1465 * interrupted scanning due to a connect request. Mark
1672}
1673
1674static bool has_pending_adv_report(struct hci_dev *hdev)
1675{
1676 struct discovery_state *d = &hdev->discovery;
1677
1678 return bacmp(&d->last_adv_addr, BDADDR_ANY);
1679}

--- 53 unchanged lines hidden (view full) ---

1733 * when it's already disabled.
1734 */
1735 cancel_delayed_work(&hdev->le_scan_disable);
1736
1737 hci_dev_clear_flag(hdev, HCI_LE_SCAN);
1738
1739 /* The HCI_LE_SCAN_INTERRUPTED flag indicates that we
1740 * interrupted scanning due to a connect request. Mark
1466 * therefore discovery as stopped. If this was not
1467 * because of a connect request advertising might have
1468 * been disabled because of active scanning, so
1469 * re-enable it again if necessary.
1741 * therefore discovery as stopped.
1470 */
1471 if (hci_dev_test_and_clear_flag(hdev, HCI_LE_SCAN_INTERRUPTED))
1472 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1742 */
1743 if (hci_dev_test_and_clear_flag(hdev, HCI_LE_SCAN_INTERRUPTED))
1744 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
1473 else if (!hci_dev_test_flag(hdev, HCI_LE_ADV) &&
1474 hdev->discovery.state == DISCOVERY_FINDING)
1475 hci_req_reenable_advertising(hdev);
1476
1477 break;
1478
1479 default:
1480 bt_dev_err(hdev, "use of reserved LE_Scan_Enable param %d",
1481 enable);
1482 break;
1483 }
1484
1485 hci_dev_unlock(hdev);
1486}
1487
1745
1746 break;
1747
1748 default:
1749 bt_dev_err(hdev, "use of reserved LE_Scan_Enable param %d",
1750 enable);
1751 break;
1752 }
1753
1754 hci_dev_unlock(hdev);
1755}
1756
1488static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
1489 struct sk_buff *skb)
1757static u8 hci_cc_le_set_scan_enable(struct hci_dev *hdev, void *data,
1758 struct sk_buff *skb)
1490{
1491 struct hci_cp_le_set_scan_enable *cp;
1759{
1760 struct hci_cp_le_set_scan_enable *cp;
1492 __u8 status = *((__u8 *) skb->data);
1761 struct hci_ev_status *rp = data;
1493
1762
1494 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1763 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1495
1764
1496 if (status)
1497 return;
1765 if (rp->status)
1766 return rp->status;
1498
1499 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
1500 if (!cp)
1767
1768 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
1769 if (!cp)
1501 return;
1770 return rp->status;
1502
1503 le_set_scan_enable_complete(hdev, cp->enable);
1771
1772 le_set_scan_enable_complete(hdev, cp->enable);
1773
1774 return rp->status;
1504}
1505
1775}
1776
1506static void hci_cc_le_set_ext_scan_enable(struct hci_dev *hdev,
1507 struct sk_buff *skb)
1777static u8 hci_cc_le_set_ext_scan_enable(struct hci_dev *hdev, void *data,
1778 struct sk_buff *skb)
1508{
1509 struct hci_cp_le_set_ext_scan_enable *cp;
1779{
1780 struct hci_cp_le_set_ext_scan_enable *cp;
1510 __u8 status = *((__u8 *) skb->data);
1781 struct hci_ev_status *rp = data;
1511
1782
1512 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1783 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1513
1784
1514 if (status)
1515 return;
1785 if (rp->status)
1786 return rp->status;
1516
1517 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE);
1518 if (!cp)
1787
1788 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE);
1789 if (!cp)
1519 return;
1790 return rp->status;
1520
1521 le_set_scan_enable_complete(hdev, cp->enable);
1791
1792 le_set_scan_enable_complete(hdev, cp->enable);
1793
1794 return rp->status;
1522}
1523
1795}
1796
1524static void hci_cc_le_read_num_adv_sets(struct hci_dev *hdev,
1797static u8 hci_cc_le_read_num_adv_sets(struct hci_dev *hdev, void *data,
1525 struct sk_buff *skb)
1526{
1798 struct sk_buff *skb)
1799{
1527 struct hci_rp_le_read_num_supported_adv_sets *rp = (void *) skb->data;
1800 struct hci_rp_le_read_num_supported_adv_sets *rp = data;
1528
1801
1529 BT_DBG("%s status 0x%2.2x No of Adv sets %u", hdev->name, rp->status,
1530 rp->num_of_sets);
1802 bt_dev_dbg(hdev, "status 0x%2.2x No of Adv sets %u", rp->status,
1803 rp->num_of_sets);
1531
1532 if (rp->status)
1804
1805 if (rp->status)
1533 return;
1806 return rp->status;
1534
1535 hdev->le_num_of_adv_sets = rp->num_of_sets;
1807
1808 hdev->le_num_of_adv_sets = rp->num_of_sets;
1809
1810 return rp->status;
1536}
1537
1811}
1812
1538static void hci_cc_le_read_accept_list_size(struct hci_dev *hdev,
1539 struct sk_buff *skb)
1813static u8 hci_cc_le_read_accept_list_size(struct hci_dev *hdev, void *data,
1814 struct sk_buff *skb)
1540{
1815{
1541 struct hci_rp_le_read_accept_list_size *rp = (void *)skb->data;
1816 struct hci_rp_le_read_accept_list_size *rp = data;
1542
1817
1543 BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size);
1818 bt_dev_dbg(hdev, "status 0x%2.2x size %u", rp->status, rp->size);
1544
1545 if (rp->status)
1819
1820 if (rp->status)
1546 return;
1821 return rp->status;
1547
1548 hdev->le_accept_list_size = rp->size;
1822
1823 hdev->le_accept_list_size = rp->size;
1824
1825 return rp->status;
1549}
1550
1826}
1827
1551static void hci_cc_le_clear_accept_list(struct hci_dev *hdev,
1552 struct sk_buff *skb)
1828static u8 hci_cc_le_clear_accept_list(struct hci_dev *hdev, void *data,
1829 struct sk_buff *skb)
1553{
1830{
1554 __u8 status = *((__u8 *) skb->data);
1831 struct hci_ev_status *rp = data;
1555
1832
1556 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1833 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1557
1834
1558 if (status)
1559 return;
1835 if (rp->status)
1836 return rp->status;
1560
1561 hci_bdaddr_list_clear(&hdev->le_accept_list);
1837
1838 hci_bdaddr_list_clear(&hdev->le_accept_list);
1839
1840 return rp->status;
1562}
1563
1841}
1842
1564static void hci_cc_le_add_to_accept_list(struct hci_dev *hdev,
1565 struct sk_buff *skb)
1843static u8 hci_cc_le_add_to_accept_list(struct hci_dev *hdev, void *data,
1844 struct sk_buff *skb)
1566{
1567 struct hci_cp_le_add_to_accept_list *sent;
1845{
1846 struct hci_cp_le_add_to_accept_list *sent;
1568 __u8 status = *((__u8 *) skb->data);
1847 struct hci_ev_status *rp = data;
1569
1848
1570 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1849 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1571
1850
1572 if (status)
1573 return;
1851 if (rp->status)
1852 return rp->status;
1574
1575 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST);
1576 if (!sent)
1853
1854 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST);
1855 if (!sent)
1577 return;
1856 return rp->status;
1578
1579 hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr,
1580 sent->bdaddr_type);
1857
1858 hci_bdaddr_list_add(&hdev->le_accept_list, &sent->bdaddr,
1859 sent->bdaddr_type);
1860
1861 return rp->status;
1581}
1582
1862}
1863
1583static void hci_cc_le_del_from_accept_list(struct hci_dev *hdev,
1584 struct sk_buff *skb)
1864static u8 hci_cc_le_del_from_accept_list(struct hci_dev *hdev, void *data,
1865 struct sk_buff *skb)
1585{
1586 struct hci_cp_le_del_from_accept_list *sent;
1866{
1867 struct hci_cp_le_del_from_accept_list *sent;
1587 __u8 status = *((__u8 *) skb->data);
1868 struct hci_ev_status *rp = data;
1588
1869
1589 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1870 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1590
1871
1591 if (status)
1592 return;
1872 if (rp->status)
1873 return rp->status;
1593
1594 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST);
1595 if (!sent)
1874
1875 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST);
1876 if (!sent)
1596 return;
1877 return rp->status;
1597
1598 hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr,
1599 sent->bdaddr_type);
1878
1879 hci_bdaddr_list_del(&hdev->le_accept_list, &sent->bdaddr,
1880 sent->bdaddr_type);
1881
1882 return rp->status;
1600}
1601
1883}
1884
1602static void hci_cc_le_read_supported_states(struct hci_dev *hdev,
1603 struct sk_buff *skb)
1885static u8 hci_cc_le_read_supported_states(struct hci_dev *hdev, void *data,
1886 struct sk_buff *skb)
1604{
1887{
1605 struct hci_rp_le_read_supported_states *rp = (void *) skb->data;
1888 struct hci_rp_le_read_supported_states *rp = data;
1606
1889
1607 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1890 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1608
1609 if (rp->status)
1891
1892 if (rp->status)
1610 return;
1893 return rp->status;
1611
1612 memcpy(hdev->le_states, rp->le_states, 8);
1894
1895 memcpy(hdev->le_states, rp->le_states, 8);
1896
1897 return rp->status;
1613}
1614
1898}
1899
1615static void hci_cc_le_read_def_data_len(struct hci_dev *hdev,
1616 struct sk_buff *skb)
1900static u8 hci_cc_le_read_def_data_len(struct hci_dev *hdev, void *data,
1901 struct sk_buff *skb)
1617{
1902{
1618 struct hci_rp_le_read_def_data_len *rp = (void *) skb->data;
1903 struct hci_rp_le_read_def_data_len *rp = data;
1619
1904
1620 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
1905 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1621
1622 if (rp->status)
1906
1907 if (rp->status)
1623 return;
1908 return rp->status;
1624
1625 hdev->le_def_tx_len = le16_to_cpu(rp->tx_len);
1626 hdev->le_def_tx_time = le16_to_cpu(rp->tx_time);
1909
1910 hdev->le_def_tx_len = le16_to_cpu(rp->tx_len);
1911 hdev->le_def_tx_time = le16_to_cpu(rp->tx_time);
1912
1913 return rp->status;
1627}
1628
1914}
1915
1629static void hci_cc_le_write_def_data_len(struct hci_dev *hdev,
1630 struct sk_buff *skb)
1916static u8 hci_cc_le_write_def_data_len(struct hci_dev *hdev, void *data,
1917 struct sk_buff *skb)
1631{
1632 struct hci_cp_le_write_def_data_len *sent;
1918{
1919 struct hci_cp_le_write_def_data_len *sent;
1633 __u8 status = *((__u8 *) skb->data);
1920 struct hci_ev_status *rp = data;
1634
1921
1635 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1922 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1636
1923
1637 if (status)
1638 return;
1924 if (rp->status)
1925 return rp->status;
1639
1640 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN);
1641 if (!sent)
1926
1927 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN);
1928 if (!sent)
1642 return;
1929 return rp->status;
1643
1644 hdev->le_def_tx_len = le16_to_cpu(sent->tx_len);
1645 hdev->le_def_tx_time = le16_to_cpu(sent->tx_time);
1930
1931 hdev->le_def_tx_len = le16_to_cpu(sent->tx_len);
1932 hdev->le_def_tx_time = le16_to_cpu(sent->tx_time);
1933
1934 return rp->status;
1646}
1647
1935}
1936
1648static void hci_cc_le_add_to_resolv_list(struct hci_dev *hdev,
1649 struct sk_buff *skb)
1937static u8 hci_cc_le_add_to_resolv_list(struct hci_dev *hdev, void *data,
1938 struct sk_buff *skb)
1650{
1651 struct hci_cp_le_add_to_resolv_list *sent;
1939{
1940 struct hci_cp_le_add_to_resolv_list *sent;
1652 __u8 status = *((__u8 *) skb->data);
1941 struct hci_ev_status *rp = data;
1653
1942
1654 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1943 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1655
1944
1656 if (status)
1657 return;
1945 if (rp->status)
1946 return rp->status;
1658
1659 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST);
1660 if (!sent)
1947
1948 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST);
1949 if (!sent)
1661 return;
1950 return rp->status;
1662
1663 hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
1664 sent->bdaddr_type, sent->peer_irk,
1665 sent->local_irk);
1951
1952 hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
1953 sent->bdaddr_type, sent->peer_irk,
1954 sent->local_irk);
1955
1956 return rp->status;
1666}
1667
1957}
1958
1668static void hci_cc_le_del_from_resolv_list(struct hci_dev *hdev,
1669 struct sk_buff *skb)
1959static u8 hci_cc_le_del_from_resolv_list(struct hci_dev *hdev, void *data,
1960 struct sk_buff *skb)
1670{
1671 struct hci_cp_le_del_from_resolv_list *sent;
1961{
1962 struct hci_cp_le_del_from_resolv_list *sent;
1672 __u8 status = *((__u8 *) skb->data);
1963 struct hci_ev_status *rp = data;
1673
1964
1674 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1965 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1675
1966
1676 if (status)
1677 return;
1967 if (rp->status)
1968 return rp->status;
1678
1679 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST);
1680 if (!sent)
1969
1970 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST);
1971 if (!sent)
1681 return;
1972 return rp->status;
1682
1683 hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
1684 sent->bdaddr_type);
1973
1974 hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
1975 sent->bdaddr_type);
1976
1977 return rp->status;
1685}
1686
1978}
1979
1687static void hci_cc_le_clear_resolv_list(struct hci_dev *hdev,
1688 struct sk_buff *skb)
1980static u8 hci_cc_le_clear_resolv_list(struct hci_dev *hdev, void *data,
1981 struct sk_buff *skb)
1689{
1982{
1690 __u8 status = *((__u8 *) skb->data);
1983 struct hci_ev_status *rp = data;
1691
1984
1692 BT_DBG("%s status 0x%2.2x", hdev->name, status);
1985 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1693
1986
1694 if (status)
1695 return;
1987 if (rp->status)
1988 return rp->status;
1696
1697 hci_bdaddr_list_clear(&hdev->le_resolv_list);
1989
1990 hci_bdaddr_list_clear(&hdev->le_resolv_list);
1991
1992 return rp->status;
1698}
1699
1993}
1994
1700static void hci_cc_le_read_resolv_list_size(struct hci_dev *hdev,
1701 struct sk_buff *skb)
1995static u8 hci_cc_le_read_resolv_list_size(struct hci_dev *hdev, void *data,
1996 struct sk_buff *skb)
1702{
1997{
1703 struct hci_rp_le_read_resolv_list_size *rp = (void *) skb->data;
1998 struct hci_rp_le_read_resolv_list_size *rp = data;
1704
1999
1705 BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size);
2000 bt_dev_dbg(hdev, "status 0x%2.2x size %u", rp->status, rp->size);
1706
1707 if (rp->status)
2001
2002 if (rp->status)
1708 return;
2003 return rp->status;
1709
1710 hdev->le_resolv_list_size = rp->size;
2004
2005 hdev->le_resolv_list_size = rp->size;
2006
2007 return rp->status;
1711}
1712
2008}
2009
1713static void hci_cc_le_set_addr_resolution_enable(struct hci_dev *hdev,
1714 struct sk_buff *skb)
2010static u8 hci_cc_le_set_addr_resolution_enable(struct hci_dev *hdev, void *data,
2011 struct sk_buff *skb)
1715{
2012{
1716 __u8 *sent, status = *((__u8 *) skb->data);
2013 struct hci_ev_status *rp = data;
2014 __u8 *sent;
1717
2015
1718 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2016 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1719
2017
1720 if (status)
1721 return;
2018 if (rp->status)
2019 return rp->status;
1722
1723 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE);
1724 if (!sent)
2020
2021 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE);
2022 if (!sent)
1725 return;
2023 return rp->status;
1726
1727 hci_dev_lock(hdev);
1728
1729 if (*sent)
1730 hci_dev_set_flag(hdev, HCI_LL_RPA_RESOLUTION);
1731 else
1732 hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);
1733
1734 hci_dev_unlock(hdev);
2024
2025 hci_dev_lock(hdev);
2026
2027 if (*sent)
2028 hci_dev_set_flag(hdev, HCI_LL_RPA_RESOLUTION);
2029 else
2030 hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);
2031
2032 hci_dev_unlock(hdev);
2033
2034 return rp->status;
1735}
1736
2035}
2036
1737static void hci_cc_le_read_max_data_len(struct hci_dev *hdev,
1738 struct sk_buff *skb)
2037static u8 hci_cc_le_read_max_data_len(struct hci_dev *hdev, void *data,
2038 struct sk_buff *skb)
1739{
2039{
1740 struct hci_rp_le_read_max_data_len *rp = (void *) skb->data;
2040 struct hci_rp_le_read_max_data_len *rp = data;
1741
2041
1742 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
2042 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1743
1744 if (rp->status)
2043
2044 if (rp->status)
1745 return;
2045 return rp->status;
1746
1747 hdev->le_max_tx_len = le16_to_cpu(rp->tx_len);
1748 hdev->le_max_tx_time = le16_to_cpu(rp->tx_time);
1749 hdev->le_max_rx_len = le16_to_cpu(rp->rx_len);
1750 hdev->le_max_rx_time = le16_to_cpu(rp->rx_time);
2046
2047 hdev->le_max_tx_len = le16_to_cpu(rp->tx_len);
2048 hdev->le_max_tx_time = le16_to_cpu(rp->tx_time);
2049 hdev->le_max_rx_len = le16_to_cpu(rp->rx_len);
2050 hdev->le_max_rx_time = le16_to_cpu(rp->rx_time);
2051
2052 return rp->status;
1751}
1752
2053}
2054
1753static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
1754 struct sk_buff *skb)
2055static u8 hci_cc_write_le_host_supported(struct hci_dev *hdev, void *data,
2056 struct sk_buff *skb)
1755{
1756 struct hci_cp_write_le_host_supported *sent;
2057{
2058 struct hci_cp_write_le_host_supported *sent;
1757 __u8 status = *((__u8 *) skb->data);
2059 struct hci_ev_status *rp = data;
1758
2060
1759 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2061 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1760
2062
1761 if (status)
1762 return;
2063 if (rp->status)
2064 return rp->status;
1763
1764 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED);
1765 if (!sent)
2065
2066 sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED);
2067 if (!sent)
1766 return;
2068 return rp->status;
1767
1768 hci_dev_lock(hdev);
1769
1770 if (sent->le) {
1771 hdev->features[1][0] |= LMP_HOST_LE;
1772 hci_dev_set_flag(hdev, HCI_LE_ENABLED);
1773 } else {
1774 hdev->features[1][0] &= ~LMP_HOST_LE;
1775 hci_dev_clear_flag(hdev, HCI_LE_ENABLED);
1776 hci_dev_clear_flag(hdev, HCI_ADVERTISING);
1777 }
1778
1779 if (sent->simul)
1780 hdev->features[1][0] |= LMP_HOST_LE_BREDR;
1781 else
1782 hdev->features[1][0] &= ~LMP_HOST_LE_BREDR;
1783
1784 hci_dev_unlock(hdev);
2069
2070 hci_dev_lock(hdev);
2071
2072 if (sent->le) {
2073 hdev->features[1][0] |= LMP_HOST_LE;
2074 hci_dev_set_flag(hdev, HCI_LE_ENABLED);
2075 } else {
2076 hdev->features[1][0] &= ~LMP_HOST_LE;
2077 hci_dev_clear_flag(hdev, HCI_LE_ENABLED);
2078 hci_dev_clear_flag(hdev, HCI_ADVERTISING);
2079 }
2080
2081 if (sent->simul)
2082 hdev->features[1][0] |= LMP_HOST_LE_BREDR;
2083 else
2084 hdev->features[1][0] &= ~LMP_HOST_LE_BREDR;
2085
2086 hci_dev_unlock(hdev);
2087
2088 return rp->status;
1785}
1786
2089}
2090
1787static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
2091static u8 hci_cc_set_adv_param(struct hci_dev *hdev, void *data,
2092 struct sk_buff *skb)
1788{
1789 struct hci_cp_le_set_adv_param *cp;
2093{
2094 struct hci_cp_le_set_adv_param *cp;
1790 u8 status = *((u8 *) skb->data);
2095 struct hci_ev_status *rp = data;
1791
2096
1792 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2097 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1793
2098
1794 if (status)
1795 return;
2099 if (rp->status)
2100 return rp->status;
1796
1797 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM);
1798 if (!cp)
2101
2102 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM);
2103 if (!cp)
1799 return;
2104 return rp->status;
1800
1801 hci_dev_lock(hdev);
1802 hdev->adv_addr_type = cp->own_address_type;
1803 hci_dev_unlock(hdev);
2105
2106 hci_dev_lock(hdev);
2107 hdev->adv_addr_type = cp->own_address_type;
2108 hci_dev_unlock(hdev);
2109
2110 return rp->status;
1804}
1805
2111}
2112
1806static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
2113static u8 hci_cc_set_ext_adv_param(struct hci_dev *hdev, void *data,
2114 struct sk_buff *skb)
1807{
2115{
1808 struct hci_rp_le_set_ext_adv_params *rp = (void *) skb->data;
2116 struct hci_rp_le_set_ext_adv_params *rp = data;
1809 struct hci_cp_le_set_ext_adv_params *cp;
1810 struct adv_info *adv_instance;
1811
2117 struct hci_cp_le_set_ext_adv_params *cp;
2118 struct adv_info *adv_instance;
2119
1812 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
2120 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1813
1814 if (rp->status)
2121
2122 if (rp->status)
1815 return;
2123 return rp->status;
1816
1817 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS);
1818 if (!cp)
2124
2125 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS);
2126 if (!cp)
1819 return;
2127 return rp->status;
1820
1821 hci_dev_lock(hdev);
1822 hdev->adv_addr_type = cp->own_addr_type;
1823 if (!cp->handle) {
1824 /* Store in hdev for instance 0 */
1825 hdev->adv_tx_power = rp->tx_power;
1826 } else {
1827 adv_instance = hci_find_adv_instance(hdev, cp->handle);
1828 if (adv_instance)
1829 adv_instance->tx_power = rp->tx_power;
1830 }
1831 /* Update adv data as tx power is known now */
1832 hci_req_update_adv_data(hdev, cp->handle);
1833
1834 hci_dev_unlock(hdev);
2128
2129 hci_dev_lock(hdev);
2130 hdev->adv_addr_type = cp->own_addr_type;
2131 if (!cp->handle) {
2132 /* Store in hdev for instance 0 */
2133 hdev->adv_tx_power = rp->tx_power;
2134 } else {
2135 adv_instance = hci_find_adv_instance(hdev, cp->handle);
2136 if (adv_instance)
2137 adv_instance->tx_power = rp->tx_power;
2138 }
2139 /* Update adv data as tx power is known now */
2140 hci_req_update_adv_data(hdev, cp->handle);
2141
2142 hci_dev_unlock(hdev);
2143
2144 return rp->status;
1835}
1836
2145}
2146
1837static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb)
2147static u8 hci_cc_read_rssi(struct hci_dev *hdev, void *data,
2148 struct sk_buff *skb)
1838{
2149{
1839 struct hci_rp_read_rssi *rp = (void *) skb->data;
2150 struct hci_rp_read_rssi *rp = data;
1840 struct hci_conn *conn;
1841
2151 struct hci_conn *conn;
2152
1842 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
2153 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1843
1844 if (rp->status)
2154
2155 if (rp->status)
1845 return;
2156 return rp->status;
1846
1847 hci_dev_lock(hdev);
1848
1849 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
1850 if (conn)
1851 conn->rssi = rp->rssi;
1852
1853 hci_dev_unlock(hdev);
2157
2158 hci_dev_lock(hdev);
2159
2160 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
2161 if (conn)
2162 conn->rssi = rp->rssi;
2163
2164 hci_dev_unlock(hdev);
2165
2166 return rp->status;
1854}
1855
2167}
2168
1856static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb)
2169static u8 hci_cc_read_tx_power(struct hci_dev *hdev, void *data,
2170 struct sk_buff *skb)
1857{
1858 struct hci_cp_read_tx_power *sent;
2171{
2172 struct hci_cp_read_tx_power *sent;
1859 struct hci_rp_read_tx_power *rp = (void *) skb->data;
2173 struct hci_rp_read_tx_power *rp = data;
1860 struct hci_conn *conn;
1861
2174 struct hci_conn *conn;
2175
1862 BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
2176 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1863
1864 if (rp->status)
2177
2178 if (rp->status)
1865 return;
2179 return rp->status;
1866
1867 sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER);
1868 if (!sent)
2180
2181 sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER);
2182 if (!sent)
1869 return;
2183 return rp->status;
1870
1871 hci_dev_lock(hdev);
1872
1873 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
1874 if (!conn)
1875 goto unlock;
1876
1877 switch (sent->type) {
1878 case 0x00:
1879 conn->tx_power = rp->tx_power;
1880 break;
1881 case 0x01:
1882 conn->max_tx_power = rp->tx_power;
1883 break;
1884 }
1885
1886unlock:
1887 hci_dev_unlock(hdev);
2184
2185 hci_dev_lock(hdev);
2186
2187 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
2188 if (!conn)
2189 goto unlock;
2190
2191 switch (sent->type) {
2192 case 0x00:
2193 conn->tx_power = rp->tx_power;
2194 break;
2195 case 0x01:
2196 conn->max_tx_power = rp->tx_power;
2197 break;
2198 }
2199
2200unlock:
2201 hci_dev_unlock(hdev);
2202 return rp->status;
1888}
1889
2203}
2204
1890static void hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, struct sk_buff *skb)
2205static u8 hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, void *data,
2206 struct sk_buff *skb)
1891{
2207{
1892 u8 status = *((u8 *) skb->data);
2208 struct hci_ev_status *rp = data;
1893 u8 *mode;
1894
2209 u8 *mode;
2210
1895 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2211 bt_dev_dbg(hdev, "status 0x%2.2x", rp->status);
1896
2212
1897 if (status)
1898 return;
2213 if (rp->status)
2214 return rp->status;
1899
1900 mode = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE);
1901 if (mode)
1902 hdev->ssp_debug_mode = *mode;
2215
2216 mode = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE);
2217 if (mode)
2218 hdev->ssp_debug_mode = *mode;
2219
2220 return rp->status;
1903}
1904
1905static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
1906{
2221}
2222
2223static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
2224{
1907 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2225 bt_dev_dbg(hdev, "status 0x%2.2x", status);
1908
1909 if (status) {
1910 hci_conn_check_pending(hdev);
1911 return;
1912 }
1913
1914 set_bit(HCI_INQUIRY, &hdev->flags);
1915}
1916
1917static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
1918{
1919 struct hci_cp_create_conn *cp;
1920 struct hci_conn *conn;
1921
2226
2227 if (status) {
2228 hci_conn_check_pending(hdev);
2229 return;
2230 }
2231
2232 set_bit(HCI_INQUIRY, &hdev->flags);
2233}
2234
2235static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
2236{
2237 struct hci_cp_create_conn *cp;
2238 struct hci_conn *conn;
2239
1922 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2240 bt_dev_dbg(hdev, "status 0x%2.2x", status);
1923
1924 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
1925 if (!cp)
1926 return;
1927
1928 hci_dev_lock(hdev);
1929
1930 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
1931
2241
2242 cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
2243 if (!cp)
2244 return;
2245
2246 hci_dev_lock(hdev);
2247
2248 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
2249
1932 BT_DBG("%s bdaddr %pMR hcon %p", hdev->name, &cp->bdaddr, conn);
2250 bt_dev_dbg(hdev, "bdaddr %pMR hcon %p", &cp->bdaddr, conn);
1933
1934 if (status) {
1935 if (conn && conn->state == BT_CONNECT) {
1936 if (status != 0x0c || conn->attempt > 2) {
1937 conn->state = BT_CLOSED;
1938 hci_connect_cfm(conn, status);
1939 hci_conn_del(conn);
1940 } else

--- 12 unchanged lines hidden (view full) ---

1953}
1954
1955static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
1956{
1957 struct hci_cp_add_sco *cp;
1958 struct hci_conn *acl, *sco;
1959 __u16 handle;
1960
2251
2252 if (status) {
2253 if (conn && conn->state == BT_CONNECT) {
2254 if (status != 0x0c || conn->attempt > 2) {
2255 conn->state = BT_CLOSED;
2256 hci_connect_cfm(conn, status);
2257 hci_conn_del(conn);
2258 } else

--- 12 unchanged lines hidden (view full) ---

2271}
2272
2273static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
2274{
2275 struct hci_cp_add_sco *cp;
2276 struct hci_conn *acl, *sco;
2277 __u16 handle;
2278
1961 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2279 bt_dev_dbg(hdev, "status 0x%2.2x", status);
1962
1963 if (!status)
1964 return;
1965
1966 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
1967 if (!cp)
1968 return;
1969
1970 handle = __le16_to_cpu(cp->handle);
1971
2280
2281 if (!status)
2282 return;
2283
2284 cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
2285 if (!cp)
2286 return;
2287
2288 handle = __le16_to_cpu(cp->handle);
2289
1972 BT_DBG("%s handle 0x%4.4x", hdev->name, handle);
2290 bt_dev_dbg(hdev, "handle 0x%4.4x", handle);
1973
1974 hci_dev_lock(hdev);
1975
1976 acl = hci_conn_hash_lookup_handle(hdev, handle);
1977 if (acl) {
1978 sco = acl->link;
1979 if (sco) {
1980 sco->state = BT_CLOSED;

--- 6 unchanged lines hidden (view full) ---

1987 hci_dev_unlock(hdev);
1988}
1989
1990static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
1991{
1992 struct hci_cp_auth_requested *cp;
1993 struct hci_conn *conn;
1994
2291
2292 hci_dev_lock(hdev);
2293
2294 acl = hci_conn_hash_lookup_handle(hdev, handle);
2295 if (acl) {
2296 sco = acl->link;
2297 if (sco) {
2298 sco->state = BT_CLOSED;

--- 6 unchanged lines hidden (view full) ---

2305 hci_dev_unlock(hdev);
2306}
2307
2308static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
2309{
2310 struct hci_cp_auth_requested *cp;
2311 struct hci_conn *conn;
2312
1995 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2313 bt_dev_dbg(hdev, "status 0x%2.2x", status);
1996
1997 if (!status)
1998 return;
1999
2000 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
2001 if (!cp)
2002 return;
2003

--- 10 unchanged lines hidden (view full) ---

2014 hci_dev_unlock(hdev);
2015}
2016
2017static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
2018{
2019 struct hci_cp_set_conn_encrypt *cp;
2020 struct hci_conn *conn;
2021
2314
2315 if (!status)
2316 return;
2317
2318 cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
2319 if (!cp)
2320 return;
2321

--- 10 unchanged lines hidden (view full) ---

2332 hci_dev_unlock(hdev);
2333}
2334
2335static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
2336{
2337 struct hci_cp_set_conn_encrypt *cp;
2338 struct hci_conn *conn;
2339
2022 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2340 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2023
2024 if (!status)
2025 return;
2026
2027 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
2028 if (!cp)
2029 return;
2030

--- 50 unchanged lines hidden (view full) ---

2081static bool hci_resolve_next_name(struct hci_dev *hdev)
2082{
2083 struct discovery_state *discov = &hdev->discovery;
2084 struct inquiry_entry *e;
2085
2086 if (list_empty(&discov->resolve))
2087 return false;
2088
2341
2342 if (!status)
2343 return;
2344
2345 cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
2346 if (!cp)
2347 return;
2348

--- 50 unchanged lines hidden (view full) ---

2399static bool hci_resolve_next_name(struct hci_dev *hdev)
2400{
2401 struct discovery_state *discov = &hdev->discovery;
2402 struct inquiry_entry *e;
2403
2404 if (list_empty(&discov->resolve))
2405 return false;
2406
2407 /* We should stop if we already spent too much time resolving names. */
2408 if (time_after(jiffies, discov->name_resolve_timeout)) {
2409 bt_dev_warn_ratelimited(hdev, "Name resolve takes too long.");
2410 return false;
2411 }
2412
2089 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
2090 if (!e)
2091 return false;
2092
2093 if (hci_resolve_name(hdev, e) == 0) {
2094 e->name_state = NAME_PENDING;
2095 return true;
2096 }

--- 30 unchanged lines hidden (view full) ---

2127 /* If the device was not found in a list of found devices names of which
2128 * are pending. there is no need to continue resolving a next name as it
2129 * will be done upon receiving another Remote Name Request Complete
2130 * Event */
2131 if (!e)
2132 return;
2133
2134 list_del(&e->list);
2413 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
2414 if (!e)
2415 return false;
2416
2417 if (hci_resolve_name(hdev, e) == 0) {
2418 e->name_state = NAME_PENDING;
2419 return true;
2420 }

--- 30 unchanged lines hidden (view full) ---

2451 /* If the device was not found in a list of found devices names of which
2452 * are pending. there is no need to continue resolving a next name as it
2453 * will be done upon receiving another Remote Name Request Complete
2454 * Event */
2455 if (!e)
2456 return;
2457
2458 list_del(&e->list);
2135 if (name) {
2136 e->name_state = NAME_KNOWN;
2137 mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00,
2138 e->data.rssi, name, name_len);
2139 } else {
2140 e->name_state = NAME_NOT_KNOWN;
2141 }
2142
2459
2460 e->name_state = name ? NAME_KNOWN : NAME_NOT_KNOWN;
2461 mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00, e->data.rssi,
2462 name, name_len);
2463
2143 if (hci_resolve_next_name(hdev))
2144 return;
2145
2146discov_complete:
2147 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
2148}
2149
2150static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
2151{
2152 struct hci_cp_remote_name_req *cp;
2153 struct hci_conn *conn;
2154
2464 if (hci_resolve_next_name(hdev))
2465 return;
2466
2467discov_complete:
2468 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
2469}
2470
2471static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
2472{
2473 struct hci_cp_remote_name_req *cp;
2474 struct hci_conn *conn;
2475
2155 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2476 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2156
2157 /* If successful wait for the name req complete event before
2158 * checking for the need to do authentication */
2159 if (!status)
2160 return;
2161
2162 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
2163 if (!cp)

--- 26 unchanged lines hidden (view full) ---

2190 hci_dev_unlock(hdev);
2191}
2192
2193static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
2194{
2195 struct hci_cp_read_remote_features *cp;
2196 struct hci_conn *conn;
2197
2477
2478 /* If successful wait for the name req complete event before
2479 * checking for the need to do authentication */
2480 if (!status)
2481 return;
2482
2483 cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
2484 if (!cp)

--- 26 unchanged lines hidden (view full) ---

2511 hci_dev_unlock(hdev);
2512}
2513
2514static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
2515{
2516 struct hci_cp_read_remote_features *cp;
2517 struct hci_conn *conn;
2518
2198 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2519 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2199
2200 if (!status)
2201 return;
2202
2203 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
2204 if (!cp)
2205 return;
2206

--- 10 unchanged lines hidden (view full) ---

2217 hci_dev_unlock(hdev);
2218}
2219
2220static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
2221{
2222 struct hci_cp_read_remote_ext_features *cp;
2223 struct hci_conn *conn;
2224
2520
2521 if (!status)
2522 return;
2523
2524 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
2525 if (!cp)
2526 return;
2527

--- 10 unchanged lines hidden (view full) ---

2538 hci_dev_unlock(hdev);
2539}
2540
2541static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
2542{
2543 struct hci_cp_read_remote_ext_features *cp;
2544 struct hci_conn *conn;
2545
2225 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2546 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2226
2227 if (!status)
2228 return;
2229
2230 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
2231 if (!cp)
2232 return;
2233

--- 11 unchanged lines hidden (view full) ---

2245}
2246
2247static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
2248{
2249 struct hci_cp_setup_sync_conn *cp;
2250 struct hci_conn *acl, *sco;
2251 __u16 handle;
2252
2547
2548 if (!status)
2549 return;
2550
2551 cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
2552 if (!cp)
2553 return;
2554

--- 11 unchanged lines hidden (view full) ---

2566}
2567
2568static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
2569{
2570 struct hci_cp_setup_sync_conn *cp;
2571 struct hci_conn *acl, *sco;
2572 __u16 handle;
2573
2253 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2574 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2254
2255 if (!status)
2256 return;
2257
2258 cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
2259 if (!cp)
2260 return;
2261
2262 handle = __le16_to_cpu(cp->handle);
2263
2575
2576 if (!status)
2577 return;
2578
2579 cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
2580 if (!cp)
2581 return;
2582
2583 handle = __le16_to_cpu(cp->handle);
2584
2264 BT_DBG("%s handle 0x%4.4x", hdev->name, handle);
2585 bt_dev_dbg(hdev, "handle 0x%4.4x", handle);
2265
2266 hci_dev_lock(hdev);
2267
2268 acl = hci_conn_hash_lookup_handle(hdev, handle);
2269 if (acl) {
2270 sco = acl->link;
2271 if (sco) {
2272 sco->state = BT_CLOSED;

--- 41 unchanged lines hidden (view full) ---

2314 hci_dev_unlock(hdev);
2315}
2316
2317static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
2318{
2319 struct hci_cp_sniff_mode *cp;
2320 struct hci_conn *conn;
2321
2586
2587 hci_dev_lock(hdev);
2588
2589 acl = hci_conn_hash_lookup_handle(hdev, handle);
2590 if (acl) {
2591 sco = acl->link;
2592 if (sco) {
2593 sco->state = BT_CLOSED;

--- 41 unchanged lines hidden (view full) ---

2635 hci_dev_unlock(hdev);
2636}
2637
2638static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
2639{
2640 struct hci_cp_sniff_mode *cp;
2641 struct hci_conn *conn;
2642
2322 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2643 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2323
2324 if (!status)
2325 return;
2326
2327 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
2328 if (!cp)
2329 return;
2330

--- 10 unchanged lines hidden (view full) ---

2341 hci_dev_unlock(hdev);
2342}
2343
2344static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
2345{
2346 struct hci_cp_exit_sniff_mode *cp;
2347 struct hci_conn *conn;
2348
2644
2645 if (!status)
2646 return;
2647
2648 cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
2649 if (!cp)
2650 return;
2651

--- 10 unchanged lines hidden (view full) ---

2662 hci_dev_unlock(hdev);
2663}
2664
2665static void hci_cs_exit_sniff_mode(struct hci_dev *hdev, __u8 status)
2666{
2667 struct hci_cp_exit_sniff_mode *cp;
2668 struct hci_conn *conn;
2669
2349 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2670 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2350
2351 if (!status)
2352 return;
2353
2354 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
2355 if (!cp)
2356 return;
2357

--- 8 unchanged lines hidden (view full) ---

2366 }
2367
2368 hci_dev_unlock(hdev);
2369}
2370
2371static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
2372{
2373 struct hci_cp_disconnect *cp;
2671
2672 if (!status)
2673 return;
2674
2675 cp = hci_sent_cmd_data(hdev, HCI_OP_EXIT_SNIFF_MODE);
2676 if (!cp)
2677 return;
2678

--- 8 unchanged lines hidden (view full) ---

2687 }
2688
2689 hci_dev_unlock(hdev);
2690}
2691
2692static void hci_cs_disconnect(struct hci_dev *hdev, u8 status)
2693{
2694 struct hci_cp_disconnect *cp;
2695 struct hci_conn_params *params;
2374 struct hci_conn *conn;
2696 struct hci_conn *conn;
2697 bool mgmt_conn;
2375
2698
2376 if (!status)
2699 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2700
2701 /* Wait for HCI_EV_DISCONN_COMPLETE if status 0x00 and not suspended
2702 * otherwise cleanup the connection immediately.
2703 */
2704 if (!status && !hdev->suspended)
2377 return;
2378
2379 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT);
2380 if (!cp)
2381 return;
2382
2383 hci_dev_lock(hdev);
2384
2385 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2705 return;
2706
2707 cp = hci_sent_cmd_data(hdev, HCI_OP_DISCONNECT);
2708 if (!cp)
2709 return;
2710
2711 hci_dev_lock(hdev);
2712
2713 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
2386 if (conn) {
2714 if (!conn)
2715 goto unlock;
2716
2717 if (status) {
2387 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
2388 conn->dst_type, status);
2389
2390 if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) {
2391 hdev->cur_adv_instance = conn->adv_instance;
2718 mgmt_disconnect_failed(hdev, &conn->dst, conn->type,
2719 conn->dst_type, status);
2720
2721 if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) {
2722 hdev->cur_adv_instance = conn->adv_instance;
2392 hci_req_reenable_advertising(hdev);
2723 hci_enable_advertising(hdev);
2393 }
2394
2724 }
2725
2395 /* If the disconnection failed for any reason, the upper layer
2396 * does not retry to disconnect in current implementation.
2397 * Hence, we need to do some basic cleanup here and re-enable
2398 * advertising if necessary.
2399 */
2400 hci_conn_del(conn);
2726 goto done;
2401 }
2402
2727 }
2728
2729 mgmt_conn = test_and_clear_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags);
2730
2731 if (conn->type == ACL_LINK) {
2732 if (test_bit(HCI_CONN_FLUSH_KEY, &conn->flags))
2733 hci_remove_link_key(hdev, &conn->dst);
2734 }
2735
2736 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type);
2737 if (params) {
2738 switch (params->auto_connect) {
2739 case HCI_AUTO_CONN_LINK_LOSS:
2740 if (cp->reason != HCI_ERROR_CONNECTION_TIMEOUT)
2741 break;
2742 fallthrough;
2743
2744 case HCI_AUTO_CONN_DIRECT:
2745 case HCI_AUTO_CONN_ALWAYS:
2746 list_del_init(&params->action);
2747 list_add(&params->action, &hdev->pend_le_conns);
2748 break;
2749
2750 default:
2751 break;
2752 }
2753 }
2754
2755 mgmt_device_disconnected(hdev, &conn->dst, conn->type, conn->dst_type,
2756 cp->reason, mgmt_conn);
2757
2758 hci_disconn_cfm(conn, cp->reason);
2759
2760done:
2761 /* If the disconnection failed for any reason, the upper layer
2762 * does not retry to disconnect in current implementation.
2763 * Hence, we need to do some basic cleanup here and re-enable
2764 * advertising if necessary.
2765 */
2766 hci_conn_del(conn);
2767unlock:
2403 hci_dev_unlock(hdev);
2404}
2405
2406static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type, bool *resolved)
2407{
2408 /* When using controller based address resolution, then the new
2409 * address types 0x02 and 0x03 are used. These types need to be
2410 * converted back into either public address or random address type

--- 50 unchanged lines hidden (view full) ---

2461 &conn->le_conn_timeout,
2462 conn->conn_timeout);
2463}
2464
2465static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
2466{
2467 struct hci_cp_le_create_conn *cp;
2468
2768 hci_dev_unlock(hdev);
2769}
2770
2771static u8 ev_bdaddr_type(struct hci_dev *hdev, u8 type, bool *resolved)
2772{
2773 /* When using controller based address resolution, then the new
2774 * address types 0x02 and 0x03 are used. These types need to be
2775 * converted back into either public address or random address type

--- 50 unchanged lines hidden (view full) ---

2826 &conn->le_conn_timeout,
2827 conn->conn_timeout);
2828}
2829
2830static void hci_cs_le_create_conn(struct hci_dev *hdev, u8 status)
2831{
2832 struct hci_cp_le_create_conn *cp;
2833
2469 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2834 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2470
2471 /* All connection failure handling is taken care of by the
2472 * hci_le_conn_failed function which is triggered by the HCI
2473 * request completion callbacks used for connecting.
2474 */
2475 if (status)
2476 return;
2477

--- 8 unchanged lines hidden (view full) ---

2486
2487 hci_dev_unlock(hdev);
2488}
2489
2490static void hci_cs_le_ext_create_conn(struct hci_dev *hdev, u8 status)
2491{
2492 struct hci_cp_le_ext_create_conn *cp;
2493
2835
2836 /* All connection failure handling is taken care of by the
2837 * hci_le_conn_failed function which is triggered by the HCI
2838 * request completion callbacks used for connecting.
2839 */
2840 if (status)
2841 return;
2842

--- 8 unchanged lines hidden (view full) ---

2851
2852 hci_dev_unlock(hdev);
2853}
2854
2855static void hci_cs_le_ext_create_conn(struct hci_dev *hdev, u8 status)
2856{
2857 struct hci_cp_le_ext_create_conn *cp;
2858
2494 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2859 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2495
2496 /* All connection failure handling is taken care of by the
2497 * hci_le_conn_failed function which is triggered by the HCI
2498 * request completion callbacks used for connecting.
2499 */
2500 if (status)
2501 return;
2502

--- 9 unchanged lines hidden (view full) ---

2512 hci_dev_unlock(hdev);
2513}
2514
2515static void hci_cs_le_read_remote_features(struct hci_dev *hdev, u8 status)
2516{
2517 struct hci_cp_le_read_remote_features *cp;
2518 struct hci_conn *conn;
2519
2860
2861 /* All connection failure handling is taken care of by the
2862 * hci_le_conn_failed function which is triggered by the HCI
2863 * request completion callbacks used for connecting.
2864 */
2865 if (status)
2866 return;
2867

--- 9 unchanged lines hidden (view full) ---

2877 hci_dev_unlock(hdev);
2878}
2879
2880static void hci_cs_le_read_remote_features(struct hci_dev *hdev, u8 status)
2881{
2882 struct hci_cp_le_read_remote_features *cp;
2883 struct hci_conn *conn;
2884
2520 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2885 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2521
2522 if (!status)
2523 return;
2524
2525 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_READ_REMOTE_FEATURES);
2526 if (!cp)
2527 return;
2528

--- 10 unchanged lines hidden (view full) ---

2539 hci_dev_unlock(hdev);
2540}
2541
2542static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
2543{
2544 struct hci_cp_le_start_enc *cp;
2545 struct hci_conn *conn;
2546
2886
2887 if (!status)
2888 return;
2889
2890 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_READ_REMOTE_FEATURES);
2891 if (!cp)
2892 return;
2893

--- 10 unchanged lines hidden (view full) ---

2904 hci_dev_unlock(hdev);
2905}
2906
2907static void hci_cs_le_start_enc(struct hci_dev *hdev, u8 status)
2908{
2909 struct hci_cp_le_start_enc *cp;
2910 struct hci_conn *conn;
2911
2547 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2912 bt_dev_dbg(hdev, "status 0x%2.2x", status);
2548
2549 if (!status)
2550 return;
2551
2552 hci_dev_lock(hdev);
2553
2554 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_START_ENC);
2555 if (!cp)

--- 31 unchanged lines hidden (view full) ---

2587
2588 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
2589 if (conn)
2590 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
2591
2592 hci_dev_unlock(hdev);
2593}
2594
2913
2914 if (!status)
2915 return;
2916
2917 hci_dev_lock(hdev);
2918
2919 cp = hci_sent_cmd_data(hdev, HCI_OP_LE_START_ENC);
2920 if (!cp)

--- 31 unchanged lines hidden (view full) ---

2952
2953 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
2954 if (conn)
2955 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
2956
2957 hci_dev_unlock(hdev);
2958}
2959
2595static void hci_inquiry_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
2960static void hci_inquiry_complete_evt(struct hci_dev *hdev, void *data,
2961 struct sk_buff *skb)
2596{
2962{
2597 __u8 status = *((__u8 *) skb->data);
2963 struct hci_ev_status *ev = data;
2598 struct discovery_state *discov = &hdev->discovery;
2599 struct inquiry_entry *e;
2600
2964 struct discovery_state *discov = &hdev->discovery;
2965 struct inquiry_entry *e;
2966
2601 BT_DBG("%s status 0x%2.2x", hdev->name, status);
2967 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
2602
2603 hci_conn_check_pending(hdev);
2604
2605 if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags))
2606 return;
2607
2608 smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */
2609 wake_up_bit(&hdev->flags, HCI_INQUIRY);

--- 19 unchanged lines hidden (view full) ---

2629 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
2630 goto unlock;
2631 }
2632
2633 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
2634 if (e && hci_resolve_name(hdev, e) == 0) {
2635 e->name_state = NAME_PENDING;
2636 hci_discovery_set_state(hdev, DISCOVERY_RESOLVING);
2968
2969 hci_conn_check_pending(hdev);
2970
2971 if (!test_and_clear_bit(HCI_INQUIRY, &hdev->flags))
2972 return;
2973
2974 smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */
2975 wake_up_bit(&hdev->flags, HCI_INQUIRY);

--- 19 unchanged lines hidden (view full) ---

2995 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
2996 goto unlock;
2997 }
2998
2999 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
3000 if (e && hci_resolve_name(hdev, e) == 0) {
3001 e->name_state = NAME_PENDING;
3002 hci_discovery_set_state(hdev, DISCOVERY_RESOLVING);
3003 discov->name_resolve_timeout = jiffies + NAME_RESOLVE_DURATION;
2637 } else {
2638 /* When BR/EDR inquiry is active and no LE scanning is in
2639 * progress, then change discovery state to indicate completion.
2640 *
2641 * When running LE scanning and BR/EDR inquiry simultaneously
2642 * and the LE scan already finished, then change the discovery
2643 * state to indicate completion.
2644 */
2645 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
2646 !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks))
2647 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
2648 }
2649
2650unlock:
2651 hci_dev_unlock(hdev);
2652}
2653
3004 } else {
3005 /* When BR/EDR inquiry is active and no LE scanning is in
3006 * progress, then change discovery state to indicate completion.
3007 *
3008 * When running LE scanning and BR/EDR inquiry simultaneously
3009 * and the LE scan already finished, then change the discovery
3010 * state to indicate completion.
3011 */
3012 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
3013 !test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks))
3014 hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
3015 }
3016
3017unlock:
3018 hci_dev_unlock(hdev);
3019}
3020
2654static void hci_inquiry_result_evt(struct hci_dev *hdev, struct sk_buff *skb)
3021static void hci_inquiry_result_evt(struct hci_dev *hdev, void *edata,
3022 struct sk_buff *skb)
2655{
3023{
3024 struct hci_ev_inquiry_result *ev = edata;
2656 struct inquiry_data data;
3025 struct inquiry_data data;
2657 struct inquiry_info *info = (void *) (skb->data + 1);
2658 int num_rsp = *((__u8 *) skb->data);
3026 int i;
2659
3027
2660 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
3028 if (!hci_ev_skb_pull(hdev, skb, HCI_EV_INQUIRY_RESULT,
3029 flex_array_size(ev, info, ev->num)))
3030 return;
2661
3031
2662 if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1)
3032 bt_dev_dbg(hdev, "num %d", ev->num);
3033
3034 if (!ev->num)
2663 return;
2664
2665 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
2666 return;
2667
2668 hci_dev_lock(hdev);
2669
3035 return;
3036
3037 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
3038 return;
3039
3040 hci_dev_lock(hdev);
3041
2670 for (; num_rsp; num_rsp--, info++) {
3042 for (i = 0; i < ev->num; i++) {
3043 struct inquiry_info *info = &ev->info[i];
2671 u32 flags;
2672
2673 bacpy(&data.bdaddr, &info->bdaddr);
2674 data.pscan_rep_mode = info->pscan_rep_mode;
2675 data.pscan_period_mode = info->pscan_period_mode;
2676 data.pscan_mode = info->pscan_mode;
2677 memcpy(data.dev_class, info->dev_class, 3);
2678 data.clock_offset = info->clock_offset;

--- 5 unchanged lines hidden (view full) ---

2684 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
2685 info->dev_class, HCI_RSSI_INVALID,
2686 flags, NULL, 0, NULL, 0);
2687 }
2688
2689 hci_dev_unlock(hdev);
2690}
2691
3044 u32 flags;
3045
3046 bacpy(&data.bdaddr, &info->bdaddr);
3047 data.pscan_rep_mode = info->pscan_rep_mode;
3048 data.pscan_period_mode = info->pscan_period_mode;
3049 data.pscan_mode = info->pscan_mode;
3050 memcpy(data.dev_class, info->dev_class, 3);
3051 data.clock_offset = info->clock_offset;

--- 5 unchanged lines hidden (view full) ---

3057 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
3058 info->dev_class, HCI_RSSI_INVALID,
3059 flags, NULL, 0, NULL, 0);
3060 }
3061
3062 hci_dev_unlock(hdev);
3063}
3064
2692static void hci_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3065static void hci_conn_complete_evt(struct hci_dev *hdev, void *data,
3066 struct sk_buff *skb)
2693{
3067{
2694 struct hci_ev_conn_complete *ev = (void *) skb->data;
3068 struct hci_ev_conn_complete *ev = data;
2695 struct hci_conn *conn;
2696
3069 struct hci_conn *conn;
3070
2697 BT_DBG("%s", hdev->name);
3071 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
2698
2699 hci_dev_lock(hdev);
2700
2701 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
2702 if (!conn) {
2703 /* Connection may not exist if auto-connected. Check the bredr
2704 * allowlist to see if this device is allowed to auto connect.
2705 * If link is an ACL type, create a connection class

--- 102 unchanged lines hidden (view full) ---

2808{
2809 struct hci_cp_reject_conn_req cp;
2810
2811 bacpy(&cp.bdaddr, bdaddr);
2812 cp.reason = HCI_ERROR_REJ_BAD_ADDR;
2813 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
2814}
2815
3072
3073 hci_dev_lock(hdev);
3074
3075 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
3076 if (!conn) {
3077 /* Connection may not exist if auto-connected. Check the bredr
3078 * allowlist to see if this device is allowed to auto connect.
3079 * If link is an ACL type, create a connection class

--- 102 unchanged lines hidden (view full) ---

3182{
3183 struct hci_cp_reject_conn_req cp;
3184
3185 bacpy(&cp.bdaddr, bdaddr);
3186 cp.reason = HCI_ERROR_REJ_BAD_ADDR;
3187 hci_send_cmd(hdev, HCI_OP_REJECT_CONN_REQ, sizeof(cp), &cp);
3188}
3189
2816static void hci_conn_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
3190static void hci_conn_request_evt(struct hci_dev *hdev, void *data,
3191 struct sk_buff *skb)
2817{
3192{
2818 struct hci_ev_conn_request *ev = (void *) skb->data;
3193 struct hci_ev_conn_request *ev = data;
2819 int mask = hdev->link_mode;
2820 struct inquiry_entry *ie;
2821 struct hci_conn *conn;
2822 __u8 flags = 0;
2823
3194 int mask = hdev->link_mode;
3195 struct inquiry_entry *ie;
3196 struct hci_conn *conn;
3197 __u8 flags = 0;
3198
2824 BT_DBG("%s bdaddr %pMR type 0x%x", hdev->name, &ev->bdaddr,
2825 ev->link_type);
3199 bt_dev_dbg(hdev, "bdaddr %pMR type 0x%x", &ev->bdaddr, ev->link_type);
2826
2827 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type,
2828 &flags);
2829
2830 if (!(mask & HCI_LM_ACCEPT)) {
2831 hci_reject_conn(hdev, &ev->bdaddr);
2832 return;
2833 }

--- 85 unchanged lines hidden (view full) ---

2919 return MGMT_DEV_DISCONN_REMOTE;
2920 case HCI_ERROR_LOCAL_HOST_TERM:
2921 return MGMT_DEV_DISCONN_LOCAL_HOST;
2922 default:
2923 return MGMT_DEV_DISCONN_UNKNOWN;
2924 }
2925}
2926
3200
3201 mask |= hci_proto_connect_ind(hdev, &ev->bdaddr, ev->link_type,
3202 &flags);
3203
3204 if (!(mask & HCI_LM_ACCEPT)) {
3205 hci_reject_conn(hdev, &ev->bdaddr);
3206 return;
3207 }

--- 85 unchanged lines hidden (view full) ---

3293 return MGMT_DEV_DISCONN_REMOTE;
3294 case HCI_ERROR_LOCAL_HOST_TERM:
3295 return MGMT_DEV_DISCONN_LOCAL_HOST;
3296 default:
3297 return MGMT_DEV_DISCONN_UNKNOWN;
3298 }
3299}
3300
2927static void hci_disconn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3301static void hci_disconn_complete_evt(struct hci_dev *hdev, void *data,
3302 struct sk_buff *skb)
2928{
3303{
2929 struct hci_ev_disconn_complete *ev = (void *) skb->data;
3304 struct hci_ev_disconn_complete *ev = data;
2930 u8 reason;
2931 struct hci_conn_params *params;
2932 struct hci_conn *conn;
2933 bool mgmt_connected;
2934
3305 u8 reason;
3306 struct hci_conn_params *params;
3307 struct hci_conn *conn;
3308 bool mgmt_connected;
3309
2935 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3310 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
2936
2937 hci_dev_lock(hdev);
2938
2939 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
2940 if (!conn)
2941 goto unlock;
2942
2943 if (ev->status) {

--- 28 unchanged lines hidden (view full) ---

2972 if (ev->reason != HCI_ERROR_CONNECTION_TIMEOUT)
2973 break;
2974 fallthrough;
2975
2976 case HCI_AUTO_CONN_DIRECT:
2977 case HCI_AUTO_CONN_ALWAYS:
2978 list_del_init(&params->action);
2979 list_add(&params->action, &hdev->pend_le_conns);
3311
3312 hci_dev_lock(hdev);
3313
3314 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3315 if (!conn)
3316 goto unlock;
3317
3318 if (ev->status) {

--- 28 unchanged lines hidden (view full) ---

3347 if (ev->reason != HCI_ERROR_CONNECTION_TIMEOUT)
3348 break;
3349 fallthrough;
3350
3351 case HCI_AUTO_CONN_DIRECT:
3352 case HCI_AUTO_CONN_ALWAYS:
3353 list_del_init(&params->action);
3354 list_add(&params->action, &hdev->pend_le_conns);
2980 hci_update_background_scan(hdev);
3355 hci_update_passive_scan(hdev);
2981 break;
2982
2983 default:
2984 break;
2985 }
2986 }
2987
2988 hci_disconn_cfm(conn, ev->reason);
2989
3356 break;
3357
3358 default:
3359 break;
3360 }
3361 }
3362
3363 hci_disconn_cfm(conn, ev->reason);
3364
2990 /* The suspend notifier is waiting for all devices to disconnect so
2991 * clear the bit from pending tasks and inform the wait queue.
2992 */
2993 if (list_empty(&hdev->conn_hash.list) &&
2994 test_and_clear_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks)) {
2995 wake_up(&hdev->suspend_wait_q);
2996 }
2997
2998 /* Re-enable advertising if necessary, since it might
2999 * have been disabled by the connection. From the
3000 * HCI_LE_Set_Advertise_Enable command description in
3001 * the core specification (v4.0):
3002 * "The Controller shall continue advertising until the Host
3003 * issues an LE_Set_Advertise_Enable command with
3004 * Advertising_Enable set to 0x00 (Advertising is disabled)
3005 * or until a connection is created or until the Advertising
3006 * is timed out due to Directed Advertising."
3007 */
3008 if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) {
3009 hdev->cur_adv_instance = conn->adv_instance;
3365 /* Re-enable advertising if necessary, since it might
3366 * have been disabled by the connection. From the
3367 * HCI_LE_Set_Advertise_Enable command description in
3368 * the core specification (v4.0):
3369 * "The Controller shall continue advertising until the Host
3370 * issues an LE_Set_Advertise_Enable command with
3371 * Advertising_Enable set to 0x00 (Advertising is disabled)
3372 * or until a connection is created or until the Advertising
3373 * is timed out due to Directed Advertising."
3374 */
3375 if (conn->type == LE_LINK && conn->role == HCI_ROLE_SLAVE) {
3376 hdev->cur_adv_instance = conn->adv_instance;
3010 hci_req_reenable_advertising(hdev);
3377 hci_enable_advertising(hdev);
3011 }
3012
3013 hci_conn_del(conn);
3014
3015unlock:
3016 hci_dev_unlock(hdev);
3017}
3018
3378 }
3379
3380 hci_conn_del(conn);
3381
3382unlock:
3383 hci_dev_unlock(hdev);
3384}
3385
3019static void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
3386static void hci_auth_complete_evt(struct hci_dev *hdev, void *data,
3387 struct sk_buff *skb)
3020{
3388{
3021 struct hci_ev_auth_complete *ev = (void *) skb->data;
3389 struct hci_ev_auth_complete *ev = data;
3022 struct hci_conn *conn;
3023
3390 struct hci_conn *conn;
3391
3024 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3392 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3025
3026 hci_dev_lock(hdev);
3027
3028 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3029 if (!conn)
3030 goto unlock;
3031
3032 if (!ev->status) {

--- 48 unchanged lines hidden (view full) ---

3081 hci_encrypt_cfm(conn, ev->status);
3082 }
3083 }
3084
3085unlock:
3086 hci_dev_unlock(hdev);
3087}
3088
3393
3394 hci_dev_lock(hdev);
3395
3396 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3397 if (!conn)
3398 goto unlock;
3399
3400 if (!ev->status) {

--- 48 unchanged lines hidden (view full) ---

3449 hci_encrypt_cfm(conn, ev->status);
3450 }
3451 }
3452
3453unlock:
3454 hci_dev_unlock(hdev);
3455}
3456
3089static void hci_remote_name_evt(struct hci_dev *hdev, struct sk_buff *skb)
3457static void hci_remote_name_evt(struct hci_dev *hdev, void *data,
3458 struct sk_buff *skb)
3090{
3459{
3091 struct hci_ev_remote_name *ev = (void *) skb->data;
3460 struct hci_ev_remote_name *ev = data;
3092 struct hci_conn *conn;
3093
3461 struct hci_conn *conn;
3462
3094 BT_DBG("%s", hdev->name);
3463 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3095
3096 hci_conn_check_pending(hdev);
3097
3098 hci_dev_lock(hdev);
3099
3100 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3101
3102 if (!hci_dev_test_flag(hdev, HCI_MGMT))

--- 61 unchanged lines hidden (view full) ---

3164 }
3165
3166 hci_encrypt_cfm(conn, 0);
3167
3168unlock:
3169 hci_dev_unlock(hdev);
3170}
3171
3464
3465 hci_conn_check_pending(hdev);
3466
3467 hci_dev_lock(hdev);
3468
3469 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3470
3471 if (!hci_dev_test_flag(hdev, HCI_MGMT))

--- 61 unchanged lines hidden (view full) ---

3533 }
3534
3535 hci_encrypt_cfm(conn, 0);
3536
3537unlock:
3538 hci_dev_unlock(hdev);
3539}
3540
3172static void hci_encrypt_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
3541static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data,
3542 struct sk_buff *skb)
3173{
3543{
3174 struct hci_ev_encrypt_change *ev = (void *) skb->data;
3544 struct hci_ev_encrypt_change *ev = data;
3175 struct hci_conn *conn;
3176
3545 struct hci_conn *conn;
3546
3177 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3547 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3178
3179 hci_dev_lock(hdev);
3180
3181 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3182 if (!conn)
3183 goto unlock;
3184
3185 if (!ev->status) {

--- 92 unchanged lines hidden (view full) ---

3278
3279notify:
3280 hci_encrypt_cfm(conn, ev->status);
3281
3282unlock:
3283 hci_dev_unlock(hdev);
3284}
3285
3548
3549 hci_dev_lock(hdev);
3550
3551 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3552 if (!conn)
3553 goto unlock;
3554
3555 if (!ev->status) {

--- 92 unchanged lines hidden (view full) ---

3648
3649notify:
3650 hci_encrypt_cfm(conn, ev->status);
3651
3652unlock:
3653 hci_dev_unlock(hdev);
3654}
3655
3286static void hci_change_link_key_complete_evt(struct hci_dev *hdev,
3656static void hci_change_link_key_complete_evt(struct hci_dev *hdev, void *data,
3287 struct sk_buff *skb)
3288{
3657 struct sk_buff *skb)
3658{
3289 struct hci_ev_change_link_key_complete *ev = (void *) skb->data;
3659 struct hci_ev_change_link_key_complete *ev = data;
3290 struct hci_conn *conn;
3291
3660 struct hci_conn *conn;
3661
3292 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3662 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3293
3294 hci_dev_lock(hdev);
3295
3296 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3297 if (conn) {
3298 if (!ev->status)
3299 set_bit(HCI_CONN_SECURE, &conn->flags);
3300
3301 clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
3302
3303 hci_key_change_cfm(conn, ev->status);
3304 }
3305
3306 hci_dev_unlock(hdev);
3307}
3308
3663
3664 hci_dev_lock(hdev);
3665
3666 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3667 if (conn) {
3668 if (!ev->status)
3669 set_bit(HCI_CONN_SECURE, &conn->flags);
3670
3671 clear_bit(HCI_CONN_AUTH_PEND, &conn->flags);
3672
3673 hci_key_change_cfm(conn, ev->status);
3674 }
3675
3676 hci_dev_unlock(hdev);
3677}
3678
3309static void hci_remote_features_evt(struct hci_dev *hdev,
3679static void hci_remote_features_evt(struct hci_dev *hdev, void *data,
3310 struct sk_buff *skb)
3311{
3680 struct sk_buff *skb)
3681{
3312 struct hci_ev_remote_features *ev = (void *) skb->data;
3682 struct hci_ev_remote_features *ev = data;
3313 struct hci_conn *conn;
3314
3683 struct hci_conn *conn;
3684
3315 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
3685 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3316
3317 hci_dev_lock(hdev);
3318
3319 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3320 if (!conn)
3321 goto unlock;
3322
3323 if (!ev->status)

--- 41 unchanged lines hidden (view full) ---

3365 atomic_set(&hdev->cmd_cnt, 1);
3366 } else {
3367 schedule_delayed_work(&hdev->ncmd_timer,
3368 HCI_NCMD_TIMEOUT);
3369 }
3370 }
3371}
3372
3686
3687 hci_dev_lock(hdev);
3688
3689 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
3690 if (!conn)
3691 goto unlock;
3692
3693 if (!ev->status)

--- 41 unchanged lines hidden (view full) ---

3735 atomic_set(&hdev->cmd_cnt, 1);
3736 } else {
3737 schedule_delayed_work(&hdev->ncmd_timer,
3738 HCI_NCMD_TIMEOUT);
3739 }
3740 }
3741}
3742
3373static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
3374 u16 *opcode, u8 *status,
3375 hci_req_complete_t *req_complete,
3376 hci_req_complete_skb_t *req_complete_skb)
3377{
3378 struct hci_ev_cmd_complete *ev = (void *) skb->data;
3743#define HCI_CC_VL(_op, _func, _min, _max) \
3744{ \
3745 .op = _op, \
3746 .func = _func, \
3747 .min_len = _min, \
3748 .max_len = _max, \
3749}
3379
3750
3380 *opcode = __le16_to_cpu(ev->opcode);
3381 *status = skb->data[sizeof(*ev)];
3751#define HCI_CC(_op, _func, _len) \
3752 HCI_CC_VL(_op, _func, _len, _len)
3382
3753
3383 skb_pull(skb, sizeof(*ev));
3754#define HCI_CC_STATUS(_op, _func) \
3755 HCI_CC(_op, _func, sizeof(struct hci_ev_status))
3384
3756
3385 switch (*opcode) {
3386 case HCI_OP_INQUIRY_CANCEL:
3387 hci_cc_inquiry_cancel(hdev, skb, status);
3388 break;
3757static const struct hci_cc {
3758 u16 op;
3759 u8 (*func)(struct hci_dev *hdev, void *data, struct sk_buff *skb);
3760 u16 min_len;
3761 u16 max_len;
3762} hci_cc_table[] = {
3763 HCI_CC_STATUS(HCI_OP_INQUIRY_CANCEL, hci_cc_inquiry_cancel),
3764 HCI_CC_STATUS(HCI_OP_PERIODIC_INQ, hci_cc_periodic_inq),
3765 HCI_CC_STATUS(HCI_OP_EXIT_PERIODIC_INQ, hci_cc_exit_periodic_inq),
3766 HCI_CC_STATUS(HCI_OP_REMOTE_NAME_REQ_CANCEL,
3767 hci_cc_remote_name_req_cancel),
3768 HCI_CC(HCI_OP_ROLE_DISCOVERY, hci_cc_role_discovery,
3769 sizeof(struct hci_rp_role_discovery)),
3770 HCI_CC(HCI_OP_READ_LINK_POLICY, hci_cc_read_link_policy,
3771 sizeof(struct hci_rp_read_link_policy)),
3772 HCI_CC(HCI_OP_WRITE_LINK_POLICY, hci_cc_write_link_policy,
3773 sizeof(struct hci_rp_write_link_policy)),
3774 HCI_CC(HCI_OP_READ_DEF_LINK_POLICY, hci_cc_read_def_link_policy,
3775 sizeof(struct hci_rp_read_def_link_policy)),
3776 HCI_CC_STATUS(HCI_OP_WRITE_DEF_LINK_POLICY,
3777 hci_cc_write_def_link_policy),
3778 HCI_CC_STATUS(HCI_OP_RESET, hci_cc_reset),
3779 HCI_CC(HCI_OP_READ_STORED_LINK_KEY, hci_cc_read_stored_link_key,
3780 sizeof(struct hci_rp_read_stored_link_key)),
3781 HCI_CC(HCI_OP_DELETE_STORED_LINK_KEY, hci_cc_delete_stored_link_key,
3782 sizeof(struct hci_rp_delete_stored_link_key)),
3783 HCI_CC_STATUS(HCI_OP_WRITE_LOCAL_NAME, hci_cc_write_local_name),
3784 HCI_CC(HCI_OP_READ_LOCAL_NAME, hci_cc_read_local_name,
3785 sizeof(struct hci_rp_read_local_name)),
3786 HCI_CC_STATUS(HCI_OP_WRITE_AUTH_ENABLE, hci_cc_write_auth_enable),
3787 HCI_CC_STATUS(HCI_OP_WRITE_ENCRYPT_MODE, hci_cc_write_encrypt_mode),
3788 HCI_CC_STATUS(HCI_OP_WRITE_SCAN_ENABLE, hci_cc_write_scan_enable),
3789 HCI_CC_STATUS(HCI_OP_SET_EVENT_FLT, hci_cc_set_event_filter),
3790 HCI_CC(HCI_OP_READ_CLASS_OF_DEV, hci_cc_read_class_of_dev,
3791 sizeof(struct hci_rp_read_class_of_dev)),
3792 HCI_CC_STATUS(HCI_OP_WRITE_CLASS_OF_DEV, hci_cc_write_class_of_dev),
3793 HCI_CC(HCI_OP_READ_VOICE_SETTING, hci_cc_read_voice_setting,
3794 sizeof(struct hci_rp_read_voice_setting)),
3795 HCI_CC_STATUS(HCI_OP_WRITE_VOICE_SETTING, hci_cc_write_voice_setting),
3796 HCI_CC(HCI_OP_READ_NUM_SUPPORTED_IAC, hci_cc_read_num_supported_iac,
3797 sizeof(struct hci_rp_read_num_supported_iac)),
3798 HCI_CC_STATUS(HCI_OP_WRITE_SSP_MODE, hci_cc_write_ssp_mode),
3799 HCI_CC_STATUS(HCI_OP_WRITE_SC_SUPPORT, hci_cc_write_sc_support),
3800 HCI_CC(HCI_OP_READ_AUTH_PAYLOAD_TO, hci_cc_read_auth_payload_timeout,
3801 sizeof(struct hci_rp_read_auth_payload_to)),
3802 HCI_CC(HCI_OP_WRITE_AUTH_PAYLOAD_TO, hci_cc_write_auth_payload_timeout,
3803 sizeof(struct hci_rp_write_auth_payload_to)),
3804 HCI_CC(HCI_OP_READ_LOCAL_VERSION, hci_cc_read_local_version,
3805 sizeof(struct hci_rp_read_local_version)),
3806 HCI_CC(HCI_OP_READ_LOCAL_COMMANDS, hci_cc_read_local_commands,
3807 sizeof(struct hci_rp_read_local_commands)),
3808 HCI_CC(HCI_OP_READ_LOCAL_FEATURES, hci_cc_read_local_features,
3809 sizeof(struct hci_rp_read_local_features)),
3810 HCI_CC(HCI_OP_READ_LOCAL_EXT_FEATURES, hci_cc_read_local_ext_features,
3811 sizeof(struct hci_rp_read_local_ext_features)),
3812 HCI_CC(HCI_OP_READ_BUFFER_SIZE, hci_cc_read_buffer_size,
3813 sizeof(struct hci_rp_read_buffer_size)),
3814 HCI_CC(HCI_OP_READ_BD_ADDR, hci_cc_read_bd_addr,
3815 sizeof(struct hci_rp_read_bd_addr)),
3816 HCI_CC(HCI_OP_READ_LOCAL_PAIRING_OPTS, hci_cc_read_local_pairing_opts,
3817 sizeof(struct hci_rp_read_local_pairing_opts)),
3818 HCI_CC(HCI_OP_READ_PAGE_SCAN_ACTIVITY, hci_cc_read_page_scan_activity,
3819 sizeof(struct hci_rp_read_page_scan_activity)),
3820 HCI_CC_STATUS(HCI_OP_WRITE_PAGE_SCAN_ACTIVITY,
3821 hci_cc_write_page_scan_activity),
3822 HCI_CC(HCI_OP_READ_PAGE_SCAN_TYPE, hci_cc_read_page_scan_type,
3823 sizeof(struct hci_rp_read_page_scan_type)),
3824 HCI_CC_STATUS(HCI_OP_WRITE_PAGE_SCAN_TYPE, hci_cc_write_page_scan_type),
3825 HCI_CC(HCI_OP_READ_DATA_BLOCK_SIZE, hci_cc_read_data_block_size,
3826 sizeof(struct hci_rp_read_data_block_size)),
3827 HCI_CC(HCI_OP_READ_FLOW_CONTROL_MODE, hci_cc_read_flow_control_mode,
3828 sizeof(struct hci_rp_read_flow_control_mode)),
3829 HCI_CC(HCI_OP_READ_LOCAL_AMP_INFO, hci_cc_read_local_amp_info,
3830 sizeof(struct hci_rp_read_local_amp_info)),
3831 HCI_CC(HCI_OP_READ_CLOCK, hci_cc_read_clock,
3832 sizeof(struct hci_rp_read_clock)),
3833 HCI_CC(HCI_OP_READ_INQ_RSP_TX_POWER, hci_cc_read_inq_rsp_tx_power,
3834 sizeof(struct hci_rp_read_inq_rsp_tx_power)),
3835 HCI_CC(HCI_OP_READ_DEF_ERR_DATA_REPORTING,
3836 hci_cc_read_def_err_data_reporting,
3837 sizeof(struct hci_rp_read_def_err_data_reporting)),
3838 HCI_CC_STATUS(HCI_OP_WRITE_DEF_ERR_DATA_REPORTING,
3839 hci_cc_write_def_err_data_reporting),
3840 HCI_CC(HCI_OP_PIN_CODE_REPLY, hci_cc_pin_code_reply,
3841 sizeof(struct hci_rp_pin_code_reply)),
3842 HCI_CC(HCI_OP_PIN_CODE_NEG_REPLY, hci_cc_pin_code_neg_reply,
3843 sizeof(struct hci_rp_pin_code_neg_reply)),
3844 HCI_CC(HCI_OP_READ_LOCAL_OOB_DATA, hci_cc_read_local_oob_data,
3845 sizeof(struct hci_rp_read_local_oob_data)),
3846 HCI_CC(HCI_OP_READ_LOCAL_OOB_EXT_DATA, hci_cc_read_local_oob_ext_data,
3847 sizeof(struct hci_rp_read_local_oob_ext_data)),
3848 HCI_CC(HCI_OP_LE_READ_BUFFER_SIZE, hci_cc_le_read_buffer_size,
3849 sizeof(struct hci_rp_le_read_buffer_size)),
3850 HCI_CC(HCI_OP_LE_READ_LOCAL_FEATURES, hci_cc_le_read_local_features,
3851 sizeof(struct hci_rp_le_read_local_features)),
3852 HCI_CC(HCI_OP_LE_READ_ADV_TX_POWER, hci_cc_le_read_adv_tx_power,
3853 sizeof(struct hci_rp_le_read_adv_tx_power)),
3854 HCI_CC(HCI_OP_USER_CONFIRM_REPLY, hci_cc_user_confirm_reply,
3855 sizeof(struct hci_rp_user_confirm_reply)),
3856 HCI_CC(HCI_OP_USER_CONFIRM_NEG_REPLY, hci_cc_user_confirm_neg_reply,
3857 sizeof(struct hci_rp_user_confirm_reply)),
3858 HCI_CC(HCI_OP_USER_PASSKEY_REPLY, hci_cc_user_passkey_reply,
3859 sizeof(struct hci_rp_user_confirm_reply)),
3860 HCI_CC(HCI_OP_USER_PASSKEY_NEG_REPLY, hci_cc_user_passkey_neg_reply,
3861 sizeof(struct hci_rp_user_confirm_reply)),
3862 HCI_CC_STATUS(HCI_OP_LE_SET_RANDOM_ADDR, hci_cc_le_set_random_addr),
3863 HCI_CC_STATUS(HCI_OP_LE_SET_ADV_ENABLE, hci_cc_le_set_adv_enable),
3864 HCI_CC_STATUS(HCI_OP_LE_SET_SCAN_PARAM, hci_cc_le_set_scan_param),
3865 HCI_CC_STATUS(HCI_OP_LE_SET_SCAN_ENABLE, hci_cc_le_set_scan_enable),
3866 HCI_CC(HCI_OP_LE_READ_ACCEPT_LIST_SIZE,
3867 hci_cc_le_read_accept_list_size,
3868 sizeof(struct hci_rp_le_read_accept_list_size)),
3869 HCI_CC_STATUS(HCI_OP_LE_CLEAR_ACCEPT_LIST, hci_cc_le_clear_accept_list),
3870 HCI_CC_STATUS(HCI_OP_LE_ADD_TO_ACCEPT_LIST,
3871 hci_cc_le_add_to_accept_list),
3872 HCI_CC_STATUS(HCI_OP_LE_DEL_FROM_ACCEPT_LIST,
3873 hci_cc_le_del_from_accept_list),
3874 HCI_CC(HCI_OP_LE_READ_SUPPORTED_STATES, hci_cc_le_read_supported_states,
3875 sizeof(struct hci_rp_le_read_supported_states)),
3876 HCI_CC(HCI_OP_LE_READ_DEF_DATA_LEN, hci_cc_le_read_def_data_len,
3877 sizeof(struct hci_rp_le_read_def_data_len)),
3878 HCI_CC_STATUS(HCI_OP_LE_WRITE_DEF_DATA_LEN,
3879 hci_cc_le_write_def_data_len),
3880 HCI_CC_STATUS(HCI_OP_LE_ADD_TO_RESOLV_LIST,
3881 hci_cc_le_add_to_resolv_list),
3882 HCI_CC_STATUS(HCI_OP_LE_DEL_FROM_RESOLV_LIST,
3883 hci_cc_le_del_from_resolv_list),
3884 HCI_CC_STATUS(HCI_OP_LE_CLEAR_RESOLV_LIST,
3885 hci_cc_le_clear_resolv_list),
3886 HCI_CC(HCI_OP_LE_READ_RESOLV_LIST_SIZE, hci_cc_le_read_resolv_list_size,
3887 sizeof(struct hci_rp_le_read_resolv_list_size)),
3888 HCI_CC_STATUS(HCI_OP_LE_SET_ADDR_RESOLV_ENABLE,
3889 hci_cc_le_set_addr_resolution_enable),
3890 HCI_CC(HCI_OP_LE_READ_MAX_DATA_LEN, hci_cc_le_read_max_data_len,
3891 sizeof(struct hci_rp_le_read_max_data_len)),
3892 HCI_CC_STATUS(HCI_OP_WRITE_LE_HOST_SUPPORTED,
3893 hci_cc_write_le_host_supported),
3894 HCI_CC_STATUS(HCI_OP_LE_SET_ADV_PARAM, hci_cc_set_adv_param),
3895 HCI_CC(HCI_OP_READ_RSSI, hci_cc_read_rssi,
3896 sizeof(struct hci_rp_read_rssi)),
3897 HCI_CC(HCI_OP_READ_TX_POWER, hci_cc_read_tx_power,
3898 sizeof(struct hci_rp_read_tx_power)),
3899 HCI_CC_STATUS(HCI_OP_WRITE_SSP_DEBUG_MODE, hci_cc_write_ssp_debug_mode),
3900 HCI_CC_STATUS(HCI_OP_LE_SET_EXT_SCAN_PARAMS,
3901 hci_cc_le_set_ext_scan_param),
3902 HCI_CC_STATUS(HCI_OP_LE_SET_EXT_SCAN_ENABLE,
3903 hci_cc_le_set_ext_scan_enable),
3904 HCI_CC_STATUS(HCI_OP_LE_SET_DEFAULT_PHY, hci_cc_le_set_default_phy),
3905 HCI_CC(HCI_OP_LE_READ_NUM_SUPPORTED_ADV_SETS,
3906 hci_cc_le_read_num_adv_sets,
3907 sizeof(struct hci_rp_le_read_num_supported_adv_sets)),
3908 HCI_CC(HCI_OP_LE_SET_EXT_ADV_PARAMS, hci_cc_set_ext_adv_param,
3909 sizeof(struct hci_rp_le_set_ext_adv_params)),
3910 HCI_CC_STATUS(HCI_OP_LE_SET_EXT_ADV_ENABLE,
3911 hci_cc_le_set_ext_adv_enable),
3912 HCI_CC_STATUS(HCI_OP_LE_SET_ADV_SET_RAND_ADDR,
3913 hci_cc_le_set_adv_set_random_addr),
3914 HCI_CC_STATUS(HCI_OP_LE_REMOVE_ADV_SET, hci_cc_le_remove_adv_set),
3915 HCI_CC_STATUS(HCI_OP_LE_CLEAR_ADV_SETS, hci_cc_le_clear_adv_sets),
3916 HCI_CC(HCI_OP_LE_READ_TRANSMIT_POWER, hci_cc_le_read_transmit_power,
3917 sizeof(struct hci_rp_le_read_transmit_power)),
3918 HCI_CC_STATUS(HCI_OP_LE_SET_PRIVACY_MODE, hci_cc_le_set_privacy_mode)
3919};
3389
3920
3390 case HCI_OP_PERIODIC_INQ:
3391 hci_cc_periodic_inq(hdev, skb);
3392 break;
3921static u8 hci_cc_func(struct hci_dev *hdev, const struct hci_cc *cc,
3922 struct sk_buff *skb)
3923{
3924 void *data;
3393
3925
3394 case HCI_OP_EXIT_PERIODIC_INQ:
3395 hci_cc_exit_periodic_inq(hdev, skb);
3396 break;
3926 if (skb->len < cc->min_len) {
3927 bt_dev_err(hdev, "unexpected cc 0x%4.4x length: %u < %u",
3928 cc->op, skb->len, cc->min_len);
3929 return HCI_ERROR_UNSPECIFIED;
3930 }
3397
3931
3398 case HCI_OP_REMOTE_NAME_REQ_CANCEL:
3399 hci_cc_remote_name_req_cancel(hdev, skb);
3400 break;
3932 /* Just warn if the length is over max_len size it still be possible to
3933 * partially parse the cc so leave to callback to decide if that is
3934 * acceptable.
3935 */
3936 if (skb->len > cc->max_len)
3937 bt_dev_warn(hdev, "unexpected cc 0x%4.4x length: %u > %u",
3938 cc->op, skb->len, cc->max_len);
3401
3939
3402 case HCI_OP_ROLE_DISCOVERY:
3403 hci_cc_role_discovery(hdev, skb);
3404 break;
3940 data = hci_cc_skb_pull(hdev, skb, cc->op, cc->min_len);
3941 if (!data)
3942 return HCI_ERROR_UNSPECIFIED;
3405
3943
3406 case HCI_OP_READ_LINK_POLICY:
3407 hci_cc_read_link_policy(hdev, skb);
3408 break;
3944 return cc->func(hdev, data, skb);
3945}
3409
3946
3410 case HCI_OP_WRITE_LINK_POLICY:
3411 hci_cc_write_link_policy(hdev, skb);
3412 break;
3947static void hci_cmd_complete_evt(struct hci_dev *hdev, void *data,
3948 struct sk_buff *skb, u16 *opcode, u8 *status,
3949 hci_req_complete_t *req_complete,
3950 hci_req_complete_skb_t *req_complete_skb)
3951{
3952 struct hci_ev_cmd_complete *ev = data;
3953 int i;
3413
3954
3414 case HCI_OP_READ_DEF_LINK_POLICY:
3415 hci_cc_read_def_link_policy(hdev, skb);
3416 break;
3955 *opcode = __le16_to_cpu(ev->opcode);
3417
3956
3418 case HCI_OP_WRITE_DEF_LINK_POLICY:
3419 hci_cc_write_def_link_policy(hdev, skb);
3420 break;
3957 bt_dev_dbg(hdev, "opcode 0x%4.4x", *opcode);
3421
3958
3422 case HCI_OP_RESET:
3423 hci_cc_reset(hdev, skb);
3424 break;
3425
3426 case HCI_OP_READ_STORED_LINK_KEY:
3427 hci_cc_read_stored_link_key(hdev, skb);
3428 break;
3429
3430 case HCI_OP_DELETE_STORED_LINK_KEY:
3431 hci_cc_delete_stored_link_key(hdev, skb);
3432 break;
3433
3434 case HCI_OP_WRITE_LOCAL_NAME:
3435 hci_cc_write_local_name(hdev, skb);
3436 break;
3437
3438 case HCI_OP_READ_LOCAL_NAME:
3439 hci_cc_read_local_name(hdev, skb);
3440 break;
3441
3442 case HCI_OP_WRITE_AUTH_ENABLE:
3443 hci_cc_write_auth_enable(hdev, skb);
3444 break;
3445
3446 case HCI_OP_WRITE_ENCRYPT_MODE:
3447 hci_cc_write_encrypt_mode(hdev, skb);
3448 break;
3449
3450 case HCI_OP_WRITE_SCAN_ENABLE:
3451 hci_cc_write_scan_enable(hdev, skb);
3452 break;
3453
3454 case HCI_OP_SET_EVENT_FLT:
3455 hci_cc_set_event_filter(hdev, skb);
3456 break;
3457
3458 case HCI_OP_READ_CLASS_OF_DEV:
3459 hci_cc_read_class_of_dev(hdev, skb);
3460 break;
3461
3462 case HCI_OP_WRITE_CLASS_OF_DEV:
3463 hci_cc_write_class_of_dev(hdev, skb);
3464 break;
3465
3466 case HCI_OP_READ_VOICE_SETTING:
3467 hci_cc_read_voice_setting(hdev, skb);
3468 break;
3469
3470 case HCI_OP_WRITE_VOICE_SETTING:
3471 hci_cc_write_voice_setting(hdev, skb);
3472 break;
3473
3474 case HCI_OP_READ_NUM_SUPPORTED_IAC:
3475 hci_cc_read_num_supported_iac(hdev, skb);
3476 break;
3477
3478 case HCI_OP_WRITE_SSP_MODE:
3479 hci_cc_write_ssp_mode(hdev, skb);
3480 break;
3481
3482 case HCI_OP_WRITE_SC_SUPPORT:
3483 hci_cc_write_sc_support(hdev, skb);
3484 break;
3485
3486 case HCI_OP_READ_AUTH_PAYLOAD_TO:
3487 hci_cc_read_auth_payload_timeout(hdev, skb);
3488 break;
3489
3490 case HCI_OP_WRITE_AUTH_PAYLOAD_TO:
3491 hci_cc_write_auth_payload_timeout(hdev, skb);
3492 break;
3493
3494 case HCI_OP_READ_LOCAL_VERSION:
3495 hci_cc_read_local_version(hdev, skb);
3496 break;
3497
3498 case HCI_OP_READ_LOCAL_COMMANDS:
3499 hci_cc_read_local_commands(hdev, skb);
3500 break;
3501
3502 case HCI_OP_READ_LOCAL_FEATURES:
3503 hci_cc_read_local_features(hdev, skb);
3504 break;
3505
3506 case HCI_OP_READ_LOCAL_EXT_FEATURES:
3507 hci_cc_read_local_ext_features(hdev, skb);
3508 break;
3509
3510 case HCI_OP_READ_BUFFER_SIZE:
3511 hci_cc_read_buffer_size(hdev, skb);
3512 break;
3513
3514 case HCI_OP_READ_BD_ADDR:
3515 hci_cc_read_bd_addr(hdev, skb);
3516 break;
3517
3518 case HCI_OP_READ_LOCAL_PAIRING_OPTS:
3519 hci_cc_read_local_pairing_opts(hdev, skb);
3520 break;
3521
3522 case HCI_OP_READ_PAGE_SCAN_ACTIVITY:
3523 hci_cc_read_page_scan_activity(hdev, skb);
3524 break;
3525
3526 case HCI_OP_WRITE_PAGE_SCAN_ACTIVITY:
3527 hci_cc_write_page_scan_activity(hdev, skb);
3528 break;
3529
3530 case HCI_OP_READ_PAGE_SCAN_TYPE:
3531 hci_cc_read_page_scan_type(hdev, skb);
3532 break;
3533
3534 case HCI_OP_WRITE_PAGE_SCAN_TYPE:
3535 hci_cc_write_page_scan_type(hdev, skb);
3536 break;
3537
3538 case HCI_OP_READ_DATA_BLOCK_SIZE:
3539 hci_cc_read_data_block_size(hdev, skb);
3540 break;
3541
3542 case HCI_OP_READ_FLOW_CONTROL_MODE:
3543 hci_cc_read_flow_control_mode(hdev, skb);
3544 break;
3545
3546 case HCI_OP_READ_LOCAL_AMP_INFO:
3547 hci_cc_read_local_amp_info(hdev, skb);
3548 break;
3549
3550 case HCI_OP_READ_CLOCK:
3551 hci_cc_read_clock(hdev, skb);
3552 break;
3553
3554 case HCI_OP_READ_INQ_RSP_TX_POWER:
3555 hci_cc_read_inq_rsp_tx_power(hdev, skb);
3556 break;
3557
3558 case HCI_OP_READ_DEF_ERR_DATA_REPORTING:
3559 hci_cc_read_def_err_data_reporting(hdev, skb);
3560 break;
3561
3562 case HCI_OP_WRITE_DEF_ERR_DATA_REPORTING:
3563 hci_cc_write_def_err_data_reporting(hdev, skb);
3564 break;
3565
3566 case HCI_OP_PIN_CODE_REPLY:
3567 hci_cc_pin_code_reply(hdev, skb);
3568 break;
3569
3570 case HCI_OP_PIN_CODE_NEG_REPLY:
3571 hci_cc_pin_code_neg_reply(hdev, skb);
3572 break;
3573
3574 case HCI_OP_READ_LOCAL_OOB_DATA:
3575 hci_cc_read_local_oob_data(hdev, skb);
3576 break;
3577
3578 case HCI_OP_READ_LOCAL_OOB_EXT_DATA:
3579 hci_cc_read_local_oob_ext_data(hdev, skb);
3580 break;
3581
3582 case HCI_OP_LE_READ_BUFFER_SIZE:
3583 hci_cc_le_read_buffer_size(hdev, skb);
3584 break;
3585
3586 case HCI_OP_LE_READ_LOCAL_FEATURES:
3587 hci_cc_le_read_local_features(hdev, skb);
3588 break;
3589
3590 case HCI_OP_LE_READ_ADV_TX_POWER:
3591 hci_cc_le_read_adv_tx_power(hdev, skb);
3592 break;
3593
3594 case HCI_OP_USER_CONFIRM_REPLY:
3595 hci_cc_user_confirm_reply(hdev, skb);
3596 break;
3597
3598 case HCI_OP_USER_CONFIRM_NEG_REPLY:
3599 hci_cc_user_confirm_neg_reply(hdev, skb);
3600 break;
3601
3602 case HCI_OP_USER_PASSKEY_REPLY:
3603 hci_cc_user_passkey_reply(hdev, skb);
3604 break;
3605
3606 case HCI_OP_USER_PASSKEY_NEG_REPLY:
3607 hci_cc_user_passkey_neg_reply(hdev, skb);
3608 break;
3609
3610 case HCI_OP_LE_SET_RANDOM_ADDR:
3611 hci_cc_le_set_random_addr(hdev, skb);
3612 break;
3613
3614 case HCI_OP_LE_SET_ADV_ENABLE:
3615 hci_cc_le_set_adv_enable(hdev, skb);
3616 break;
3617
3618 case HCI_OP_LE_SET_SCAN_PARAM:
3619 hci_cc_le_set_scan_param(hdev, skb);
3620 break;
3621
3622 case HCI_OP_LE_SET_SCAN_ENABLE:
3623 hci_cc_le_set_scan_enable(hdev, skb);
3624 break;
3625
3626 case HCI_OP_LE_READ_ACCEPT_LIST_SIZE:
3627 hci_cc_le_read_accept_list_size(hdev, skb);
3628 break;
3629
3630 case HCI_OP_LE_CLEAR_ACCEPT_LIST:
3631 hci_cc_le_clear_accept_list(hdev, skb);
3632 break;
3633
3634 case HCI_OP_LE_ADD_TO_ACCEPT_LIST:
3635 hci_cc_le_add_to_accept_list(hdev, skb);
3636 break;
3637
3638 case HCI_OP_LE_DEL_FROM_ACCEPT_LIST:
3639 hci_cc_le_del_from_accept_list(hdev, skb);
3640 break;
3641
3642 case HCI_OP_LE_READ_SUPPORTED_STATES:
3643 hci_cc_le_read_supported_states(hdev, skb);
3644 break;
3645
3646 case HCI_OP_LE_READ_DEF_DATA_LEN:
3647 hci_cc_le_read_def_data_len(hdev, skb);
3648 break;
3649
3650 case HCI_OP_LE_WRITE_DEF_DATA_LEN:
3651 hci_cc_le_write_def_data_len(hdev, skb);
3652 break;
3653
3654 case HCI_OP_LE_ADD_TO_RESOLV_LIST:
3655 hci_cc_le_add_to_resolv_list(hdev, skb);
3656 break;
3657
3658 case HCI_OP_LE_DEL_FROM_RESOLV_LIST:
3659 hci_cc_le_del_from_resolv_list(hdev, skb);
3660 break;
3661
3662 case HCI_OP_LE_CLEAR_RESOLV_LIST:
3663 hci_cc_le_clear_resolv_list(hdev, skb);
3664 break;
3665
3666 case HCI_OP_LE_READ_RESOLV_LIST_SIZE:
3667 hci_cc_le_read_resolv_list_size(hdev, skb);
3668 break;
3669
3670 case HCI_OP_LE_SET_ADDR_RESOLV_ENABLE:
3671 hci_cc_le_set_addr_resolution_enable(hdev, skb);
3672 break;
3673
3674 case HCI_OP_LE_READ_MAX_DATA_LEN:
3675 hci_cc_le_read_max_data_len(hdev, skb);
3676 break;
3677
3678 case HCI_OP_WRITE_LE_HOST_SUPPORTED:
3679 hci_cc_write_le_host_supported(hdev, skb);
3680 break;
3681
3682 case HCI_OP_LE_SET_ADV_PARAM:
3683 hci_cc_set_adv_param(hdev, skb);
3684 break;
3685
3686 case HCI_OP_READ_RSSI:
3687 hci_cc_read_rssi(hdev, skb);
3688 break;
3689
3690 case HCI_OP_READ_TX_POWER:
3691 hci_cc_read_tx_power(hdev, skb);
3692 break;
3693
3694 case HCI_OP_WRITE_SSP_DEBUG_MODE:
3695 hci_cc_write_ssp_debug_mode(hdev, skb);
3696 break;
3697
3698 case HCI_OP_LE_SET_EXT_SCAN_PARAMS:
3699 hci_cc_le_set_ext_scan_param(hdev, skb);
3700 break;
3701
3702 case HCI_OP_LE_SET_EXT_SCAN_ENABLE:
3703 hci_cc_le_set_ext_scan_enable(hdev, skb);
3704 break;
3705
3706 case HCI_OP_LE_SET_DEFAULT_PHY:
3707 hci_cc_le_set_default_phy(hdev, skb);
3708 break;
3709
3710 case HCI_OP_LE_READ_NUM_SUPPORTED_ADV_SETS:
3711 hci_cc_le_read_num_adv_sets(hdev, skb);
3712 break;
3713
3714 case HCI_OP_LE_SET_EXT_ADV_PARAMS:
3715 hci_cc_set_ext_adv_param(hdev, skb);
3716 break;
3717
3718 case HCI_OP_LE_SET_EXT_ADV_ENABLE:
3719 hci_cc_le_set_ext_adv_enable(hdev, skb);
3720 break;
3721
3722 case HCI_OP_LE_SET_ADV_SET_RAND_ADDR:
3723 hci_cc_le_set_adv_set_random_addr(hdev, skb);
3724 break;
3725
3726 case HCI_OP_LE_READ_TRANSMIT_POWER:
3727 hci_cc_le_read_transmit_power(hdev, skb);
3728 break;
3729
3730 default:
3731 BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode);
3732 break;
3959 for (i = 0; i < ARRAY_SIZE(hci_cc_table); i++) {
3960 if (hci_cc_table[i].op == *opcode) {
3961 *status = hci_cc_func(hdev, &hci_cc_table[i], skb);
3962 break;
3963 }
3733 }
3734
3735 handle_cmd_cnt_and_timer(hdev, ev->ncmd);
3736
3737 hci_req_cmd_complete(hdev, *opcode, *status, req_complete,
3738 req_complete_skb);
3739
3740 if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) {
3741 bt_dev_err(hdev,
3742 "unexpected event for opcode 0x%4.4x", *opcode);
3743 return;
3744 }
3745
3746 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q))
3747 queue_work(hdev->workqueue, &hdev->cmd_work);
3748}
3749
3964 }
3965
3966 handle_cmd_cnt_and_timer(hdev, ev->ncmd);
3967
3968 hci_req_cmd_complete(hdev, *opcode, *status, req_complete,
3969 req_complete_skb);
3970
3971 if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) {
3972 bt_dev_err(hdev,
3973 "unexpected event for opcode 0x%4.4x", *opcode);
3974 return;
3975 }
3976
3977 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q))
3978 queue_work(hdev->workqueue, &hdev->cmd_work);
3979}
3980
3750static void hci_cmd_status_evt(struct hci_dev *hdev, struct sk_buff *skb,
3751 u16 *opcode, u8 *status,
3981#define HCI_CS(_op, _func) \
3982{ \
3983 .op = _op, \
3984 .func = _func, \
3985}
3986
3987static const struct hci_cs {
3988 u16 op;
3989 void (*func)(struct hci_dev *hdev, __u8 status);
3990} hci_cs_table[] = {
3991 HCI_CS(HCI_OP_INQUIRY, hci_cs_inquiry),
3992 HCI_CS(HCI_OP_CREATE_CONN, hci_cs_create_conn),
3993 HCI_CS(HCI_OP_DISCONNECT, hci_cs_disconnect),
3994 HCI_CS(HCI_OP_ADD_SCO, hci_cs_add_sco),
3995 HCI_CS(HCI_OP_AUTH_REQUESTED, hci_cs_auth_requested),
3996 HCI_CS(HCI_OP_SET_CONN_ENCRYPT, hci_cs_set_conn_encrypt),
3997 HCI_CS(HCI_OP_REMOTE_NAME_REQ, hci_cs_remote_name_req),
3998 HCI_CS(HCI_OP_READ_REMOTE_FEATURES, hci_cs_read_remote_features),
3999 HCI_CS(HCI_OP_READ_REMOTE_EXT_FEATURES,
4000 hci_cs_read_remote_ext_features),
4001 HCI_CS(HCI_OP_SETUP_SYNC_CONN, hci_cs_setup_sync_conn),
4002 HCI_CS(HCI_OP_ENHANCED_SETUP_SYNC_CONN,
4003 hci_cs_enhanced_setup_sync_conn),
4004 HCI_CS(HCI_OP_SNIFF_MODE, hci_cs_sniff_mode),
4005 HCI_CS(HCI_OP_EXIT_SNIFF_MODE, hci_cs_exit_sniff_mode),
4006 HCI_CS(HCI_OP_SWITCH_ROLE, hci_cs_switch_role),
4007 HCI_CS(HCI_OP_LE_CREATE_CONN, hci_cs_le_create_conn),
4008 HCI_CS(HCI_OP_LE_READ_REMOTE_FEATURES, hci_cs_le_read_remote_features),
4009 HCI_CS(HCI_OP_LE_START_ENC, hci_cs_le_start_enc),
4010 HCI_CS(HCI_OP_LE_EXT_CREATE_CONN, hci_cs_le_ext_create_conn)
4011};
4012
4013static void hci_cmd_status_evt(struct hci_dev *hdev, void *data,
4014 struct sk_buff *skb, u16 *opcode, u8 *status,
3752 hci_req_complete_t *req_complete,
3753 hci_req_complete_skb_t *req_complete_skb)
3754{
4015 hci_req_complete_t *req_complete,
4016 hci_req_complete_skb_t *req_complete_skb)
4017{
3755 struct hci_ev_cmd_status *ev = (void *) skb->data;
4018 struct hci_ev_cmd_status *ev = data;
4019 int i;
3756
4020
3757 skb_pull(skb, sizeof(*ev));
3758
3759 *opcode = __le16_to_cpu(ev->opcode);
3760 *status = ev->status;
3761
4021 *opcode = __le16_to_cpu(ev->opcode);
4022 *status = ev->status;
4023
3762 switch (*opcode) {
3763 case HCI_OP_INQUIRY:
3764 hci_cs_inquiry(hdev, ev->status);
3765 break;
4024 bt_dev_dbg(hdev, "opcode 0x%4.4x", *opcode);
3766
4025
3767 case HCI_OP_CREATE_CONN:
3768 hci_cs_create_conn(hdev, ev->status);
3769 break;
3770
3771 case HCI_OP_DISCONNECT:
3772 hci_cs_disconnect(hdev, ev->status);
3773 break;
3774
3775 case HCI_OP_ADD_SCO:
3776 hci_cs_add_sco(hdev, ev->status);
3777 break;
3778
3779 case HCI_OP_AUTH_REQUESTED:
3780 hci_cs_auth_requested(hdev, ev->status);
3781 break;
3782
3783 case HCI_OP_SET_CONN_ENCRYPT:
3784 hci_cs_set_conn_encrypt(hdev, ev->status);
3785 break;
3786
3787 case HCI_OP_REMOTE_NAME_REQ:
3788 hci_cs_remote_name_req(hdev, ev->status);
3789 break;
3790
3791 case HCI_OP_READ_REMOTE_FEATURES:
3792 hci_cs_read_remote_features(hdev, ev->status);
3793 break;
3794
3795 case HCI_OP_READ_REMOTE_EXT_FEATURES:
3796 hci_cs_read_remote_ext_features(hdev, ev->status);
3797 break;
3798
3799 case HCI_OP_SETUP_SYNC_CONN:
3800 hci_cs_setup_sync_conn(hdev, ev->status);
3801 break;
3802
3803 case HCI_OP_ENHANCED_SETUP_SYNC_CONN:
3804 hci_cs_enhanced_setup_sync_conn(hdev, ev->status);
3805 break;
3806
3807 case HCI_OP_SNIFF_MODE:
3808 hci_cs_sniff_mode(hdev, ev->status);
3809 break;
3810
3811 case HCI_OP_EXIT_SNIFF_MODE:
3812 hci_cs_exit_sniff_mode(hdev, ev->status);
3813 break;
3814
3815 case HCI_OP_SWITCH_ROLE:
3816 hci_cs_switch_role(hdev, ev->status);
3817 break;
3818
3819 case HCI_OP_LE_CREATE_CONN:
3820 hci_cs_le_create_conn(hdev, ev->status);
3821 break;
3822
3823 case HCI_OP_LE_READ_REMOTE_FEATURES:
3824 hci_cs_le_read_remote_features(hdev, ev->status);
3825 break;
3826
3827 case HCI_OP_LE_START_ENC:
3828 hci_cs_le_start_enc(hdev, ev->status);
3829 break;
3830
3831 case HCI_OP_LE_EXT_CREATE_CONN:
3832 hci_cs_le_ext_create_conn(hdev, ev->status);
3833 break;
3834
3835 default:
3836 BT_DBG("%s opcode 0x%4.4x", hdev->name, *opcode);
3837 break;
4026 for (i = 0; i < ARRAY_SIZE(hci_cs_table); i++) {
4027 if (hci_cs_table[i].op == *opcode) {
4028 hci_cs_table[i].func(hdev, ev->status);
4029 break;
4030 }
3838 }
3839
3840 handle_cmd_cnt_and_timer(hdev, ev->ncmd);
3841
3842 /* Indicate request completion if the command failed. Also, if
3843 * we're not waiting for a special event and we get a success
3844 * command status we should try to flag the request as completed
3845 * (since for this kind of commands there will not be a command
3846 * complete event).
3847 */
4031 }
4032
4033 handle_cmd_cnt_and_timer(hdev, ev->ncmd);
4034
4035 /* Indicate request completion if the command failed. Also, if
4036 * we're not waiting for a special event and we get a success
4037 * command status we should try to flag the request as completed
4038 * (since for this kind of commands there will not be a command
4039 * complete event).
4040 */
3848 if (ev->status ||
3849 (hdev->sent_cmd && !bt_cb(hdev->sent_cmd)->hci.req_event))
4041 if (ev->status || (hdev->sent_cmd && !hci_skb_event(hdev->sent_cmd))) {
3850 hci_req_cmd_complete(hdev, *opcode, ev->status, req_complete,
3851 req_complete_skb);
4042 hci_req_cmd_complete(hdev, *opcode, ev->status, req_complete,
4043 req_complete_skb);
3852
3853 if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) {
3854 bt_dev_err(hdev,
3855 "unexpected event for opcode 0x%4.4x", *opcode);
3856 return;
4044 if (hci_dev_test_flag(hdev, HCI_CMD_PENDING)) {
4045 bt_dev_err(hdev, "unexpected event for opcode 0x%4.4x",
4046 *opcode);
4047 return;
4048 }
3857 }
3858
3859 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q))
3860 queue_work(hdev->workqueue, &hdev->cmd_work);
3861}
3862
4049 }
4050
4051 if (atomic_read(&hdev->cmd_cnt) && !skb_queue_empty(&hdev->cmd_q))
4052 queue_work(hdev->workqueue, &hdev->cmd_work);
4053}
4054
3863static void hci_hardware_error_evt(struct hci_dev *hdev, struct sk_buff *skb)
4055static void hci_hardware_error_evt(struct hci_dev *hdev, void *data,
4056 struct sk_buff *skb)
3864{
4057{
3865 struct hci_ev_hardware_error *ev = (void *) skb->data;
4058 struct hci_ev_hardware_error *ev = data;
3866
4059
4060 bt_dev_dbg(hdev, "code 0x%2.2x", ev->code);
4061
3867 hdev->hw_error_code = ev->code;
3868
3869 queue_work(hdev->req_workqueue, &hdev->error_reset);
3870}
3871
4062 hdev->hw_error_code = ev->code;
4063
4064 queue_work(hdev->req_workqueue, &hdev->error_reset);
4065}
4066
3872static void hci_role_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
4067static void hci_role_change_evt(struct hci_dev *hdev, void *data,
4068 struct sk_buff *skb)
3873{
4069{
3874 struct hci_ev_role_change *ev = (void *) skb->data;
4070 struct hci_ev_role_change *ev = data;
3875 struct hci_conn *conn;
3876
4071 struct hci_conn *conn;
4072
3877 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
4073 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
3878
3879 hci_dev_lock(hdev);
3880
3881 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
3882 if (conn) {
3883 if (!ev->status)
3884 conn->role = ev->role;
3885
3886 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
3887
3888 hci_role_switch_cfm(conn, ev->status, ev->role);
3889 }
3890
3891 hci_dev_unlock(hdev);
3892}
3893
4074
4075 hci_dev_lock(hdev);
4076
4077 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4078 if (conn) {
4079 if (!ev->status)
4080 conn->role = ev->role;
4081
4082 clear_bit(HCI_CONN_RSWITCH_PEND, &conn->flags);
4083
4084 hci_role_switch_cfm(conn, ev->status, ev->role);
4085 }
4086
4087 hci_dev_unlock(hdev);
4088}
4089
3894static void hci_num_comp_pkts_evt(struct hci_dev *hdev, struct sk_buff *skb)
4090static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data,
4091 struct sk_buff *skb)
3895{
4092{
3896 struct hci_ev_num_comp_pkts *ev = (void *) skb->data;
4093 struct hci_ev_num_comp_pkts *ev = data;
3897 int i;
3898
4094 int i;
4095
4096 if (!hci_ev_skb_pull(hdev, skb, HCI_EV_NUM_COMP_PKTS,
4097 flex_array_size(ev, handles, ev->num)))
4098 return;
4099
3899 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) {
3900 bt_dev_err(hdev, "wrong event for mode %d", hdev->flow_ctl_mode);
3901 return;
3902 }
3903
4100 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_PACKET_BASED) {
4101 bt_dev_err(hdev, "wrong event for mode %d", hdev->flow_ctl_mode);
4102 return;
4103 }
4104
3904 if (skb->len < sizeof(*ev) ||
3905 skb->len < struct_size(ev, handles, ev->num_hndl)) {
3906 BT_DBG("%s bad parameters", hdev->name);
3907 return;
3908 }
4105 bt_dev_dbg(hdev, "num %d", ev->num);
3909
4106
3910 BT_DBG("%s num_hndl %d", hdev->name, ev->num_hndl);
3911
3912 for (i = 0; i < ev->num_hndl; i++) {
4107 for (i = 0; i < ev->num; i++) {
3913 struct hci_comp_pkts_info *info = &ev->handles[i];
3914 struct hci_conn *conn;
3915 __u16 handle, count;
3916
3917 handle = __le16_to_cpu(info->handle);
3918 count = __le16_to_cpu(info->count);
3919
3920 conn = hci_conn_hash_lookup_handle(hdev, handle);

--- 53 unchanged lines hidden (view full) ---

3974 default:
3975 bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type);
3976 break;
3977 }
3978
3979 return NULL;
3980}
3981
4108 struct hci_comp_pkts_info *info = &ev->handles[i];
4109 struct hci_conn *conn;
4110 __u16 handle, count;
4111
4112 handle = __le16_to_cpu(info->handle);
4113 count = __le16_to_cpu(info->count);
4114
4115 conn = hci_conn_hash_lookup_handle(hdev, handle);

--- 53 unchanged lines hidden (view full) ---

4169 default:
4170 bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type);
4171 break;
4172 }
4173
4174 return NULL;
4175}
4176
3982static void hci_num_comp_blocks_evt(struct hci_dev *hdev, struct sk_buff *skb)
4177static void hci_num_comp_blocks_evt(struct hci_dev *hdev, void *data,
4178 struct sk_buff *skb)
3983{
4179{
3984 struct hci_ev_num_comp_blocks *ev = (void *) skb->data;
4180 struct hci_ev_num_comp_blocks *ev = data;
3985 int i;
3986
4181 int i;
4182
3987 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) {
3988 bt_dev_err(hdev, "wrong event for mode %d", hdev->flow_ctl_mode);
4183 if (!hci_ev_skb_pull(hdev, skb, HCI_EV_NUM_COMP_BLOCKS,
4184 flex_array_size(ev, handles, ev->num_hndl)))
3989 return;
4185 return;
3990 }
3991
4186
3992 if (skb->len < sizeof(*ev) ||
3993 skb->len < struct_size(ev, handles, ev->num_hndl)) {
3994 BT_DBG("%s bad parameters", hdev->name);
4187 if (hdev->flow_ctl_mode != HCI_FLOW_CTL_MODE_BLOCK_BASED) {
4188 bt_dev_err(hdev, "wrong event for mode %d",
4189 hdev->flow_ctl_mode);
3995 return;
3996 }
3997
4190 return;
4191 }
4192
3998 BT_DBG("%s num_blocks %d num_hndl %d", hdev->name, ev->num_blocks,
3999 ev->num_hndl);
4193 bt_dev_dbg(hdev, "num_blocks %d num_hndl %d", ev->num_blocks,
4194 ev->num_hndl);
4000
4001 for (i = 0; i < ev->num_hndl; i++) {
4002 struct hci_comp_blocks_info *info = &ev->handles[i];
4003 struct hci_conn *conn = NULL;
4004 __u16 handle, block_count;
4005
4006 handle = __le16_to_cpu(info->handle);
4007 block_count = __le16_to_cpu(info->blocks);

--- 17 unchanged lines hidden (view full) ---

4025 conn->type, conn);
4026 break;
4027 }
4028 }
4029
4030 queue_work(hdev->workqueue, &hdev->tx_work);
4031}
4032
4195
4196 for (i = 0; i < ev->num_hndl; i++) {
4197 struct hci_comp_blocks_info *info = &ev->handles[i];
4198 struct hci_conn *conn = NULL;
4199 __u16 handle, block_count;
4200
4201 handle = __le16_to_cpu(info->handle);
4202 block_count = __le16_to_cpu(info->blocks);

--- 17 unchanged lines hidden (view full) ---

4220 conn->type, conn);
4221 break;
4222 }
4223 }
4224
4225 queue_work(hdev->workqueue, &hdev->tx_work);
4226}
4227
4033static void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
4228static void hci_mode_change_evt(struct hci_dev *hdev, void *data,
4229 struct sk_buff *skb)
4034{
4230{
4035 struct hci_ev_mode_change *ev = (void *) skb->data;
4231 struct hci_ev_mode_change *ev = data;
4036 struct hci_conn *conn;
4037
4232 struct hci_conn *conn;
4233
4038 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
4234 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4039
4040 hci_dev_lock(hdev);
4041
4042 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4043 if (conn) {
4044 conn->mode = ev->mode;
4045
4046 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND,

--- 6 unchanged lines hidden (view full) ---

4053
4054 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
4055 hci_sco_setup(conn, ev->status);
4056 }
4057
4058 hci_dev_unlock(hdev);
4059}
4060
4235
4236 hci_dev_lock(hdev);
4237
4238 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4239 if (conn) {
4240 conn->mode = ev->mode;
4241
4242 if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND,

--- 6 unchanged lines hidden (view full) ---

4249
4250 if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
4251 hci_sco_setup(conn, ev->status);
4252 }
4253
4254 hci_dev_unlock(hdev);
4255}
4256
4061static void hci_pin_code_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
4257static void hci_pin_code_request_evt(struct hci_dev *hdev, void *data,
4258 struct sk_buff *skb)
4062{
4259{
4063 struct hci_ev_pin_code_req *ev = (void *) skb->data;
4260 struct hci_ev_pin_code_req *ev = data;
4064 struct hci_conn *conn;
4065
4261 struct hci_conn *conn;
4262
4066 BT_DBG("%s", hdev->name);
4263 bt_dev_dbg(hdev, "");
4067
4068 hci_dev_lock(hdev);
4069
4070 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4071 if (!conn)
4072 goto unlock;
4073
4074 if (conn->state == BT_CONNECTED) {

--- 48 unchanged lines hidden (view full) ---

4123 conn->pending_sec_level = BT_SECURITY_HIGH;
4124 break;
4125 case HCI_LK_AUTH_COMBINATION_P256:
4126 conn->pending_sec_level = BT_SECURITY_FIPS;
4127 break;
4128 }
4129}
4130
4264
4265 hci_dev_lock(hdev);
4266
4267 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4268 if (!conn)
4269 goto unlock;
4270
4271 if (conn->state == BT_CONNECTED) {

--- 48 unchanged lines hidden (view full) ---

4320 conn->pending_sec_level = BT_SECURITY_HIGH;
4321 break;
4322 case HCI_LK_AUTH_COMBINATION_P256:
4323 conn->pending_sec_level = BT_SECURITY_FIPS;
4324 break;
4325 }
4326}
4327
4131static void hci_link_key_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
4328static void hci_link_key_request_evt(struct hci_dev *hdev, void *data,
4329 struct sk_buff *skb)
4132{
4330{
4133 struct hci_ev_link_key_req *ev = (void *) skb->data;
4331 struct hci_ev_link_key_req *ev = data;
4134 struct hci_cp_link_key_reply cp;
4135 struct hci_conn *conn;
4136 struct link_key *key;
4137
4332 struct hci_cp_link_key_reply cp;
4333 struct hci_conn *conn;
4334 struct link_key *key;
4335
4138 BT_DBG("%s", hdev->name);
4336 bt_dev_dbg(hdev, "");
4139
4140 if (!hci_dev_test_flag(hdev, HCI_MGMT))
4141 return;
4142
4143 hci_dev_lock(hdev);
4144
4145 key = hci_find_link_key(hdev, &ev->bdaddr);
4146 if (!key) {
4337
4338 if (!hci_dev_test_flag(hdev, HCI_MGMT))
4339 return;
4340
4341 hci_dev_lock(hdev);
4342
4343 key = hci_find_link_key(hdev, &ev->bdaddr);
4344 if (!key) {
4147 BT_DBG("%s link key not found for %pMR", hdev->name,
4148 &ev->bdaddr);
4345 bt_dev_dbg(hdev, "link key not found for %pMR", &ev->bdaddr);
4149 goto not_found;
4150 }
4151
4346 goto not_found;
4347 }
4348
4152 BT_DBG("%s found key type %u for %pMR", hdev->name, key->type,
4153 &ev->bdaddr);
4349 bt_dev_dbg(hdev, "found key type %u for %pMR", key->type, &ev->bdaddr);
4154
4155 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4156 if (conn) {
4157 clear_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags);
4158
4159 if ((key->type == HCI_LK_UNAUTH_COMBINATION_P192 ||
4160 key->type == HCI_LK_UNAUTH_COMBINATION_P256) &&
4161 conn->auth_type != 0xff && (conn->auth_type & 0x01)) {
4350
4351 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4352 if (conn) {
4353 clear_bit(HCI_CONN_NEW_LINK_KEY, &conn->flags);
4354
4355 if ((key->type == HCI_LK_UNAUTH_COMBINATION_P192 ||
4356 key->type == HCI_LK_UNAUTH_COMBINATION_P256) &&
4357 conn->auth_type != 0xff && (conn->auth_type & 0x01)) {
4162 BT_DBG("%s ignoring unauthenticated key", hdev->name);
4358 bt_dev_dbg(hdev, "ignoring unauthenticated key");
4163 goto not_found;
4164 }
4165
4166 if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 &&
4167 (conn->pending_sec_level == BT_SECURITY_HIGH ||
4168 conn->pending_sec_level == BT_SECURITY_FIPS)) {
4359 goto not_found;
4360 }
4361
4362 if (key->type == HCI_LK_COMBINATION && key->pin_len < 16 &&
4363 (conn->pending_sec_level == BT_SECURITY_HIGH ||
4364 conn->pending_sec_level == BT_SECURITY_FIPS)) {
4169 BT_DBG("%s ignoring key unauthenticated for high security",
4170 hdev->name);
4365 bt_dev_dbg(hdev, "ignoring key unauthenticated for high security");
4171 goto not_found;
4172 }
4173
4174 conn_set_key(conn, key->type, key->pin_len);
4175 }
4176
4177 bacpy(&cp.bdaddr, &ev->bdaddr);
4178 memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE);

--- 4 unchanged lines hidden (view full) ---

4183
4184 return;
4185
4186not_found:
4187 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr);
4188 hci_dev_unlock(hdev);
4189}
4190
4366 goto not_found;
4367 }
4368
4369 conn_set_key(conn, key->type, key->pin_len);
4370 }
4371
4372 bacpy(&cp.bdaddr, &ev->bdaddr);
4373 memcpy(cp.link_key, key->val, HCI_LINK_KEY_SIZE);

--- 4 unchanged lines hidden (view full) ---

4378
4379 return;
4380
4381not_found:
4382 hci_send_cmd(hdev, HCI_OP_LINK_KEY_NEG_REPLY, 6, &ev->bdaddr);
4383 hci_dev_unlock(hdev);
4384}
4385
4191static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
4386static void hci_link_key_notify_evt(struct hci_dev *hdev, void *data,
4387 struct sk_buff *skb)
4192{
4388{
4193 struct hci_ev_link_key_notify *ev = (void *) skb->data;
4389 struct hci_ev_link_key_notify *ev = data;
4194 struct hci_conn *conn;
4195 struct link_key *key;
4196 bool persistent;
4197 u8 pin_len = 0;
4198
4390 struct hci_conn *conn;
4391 struct link_key *key;
4392 bool persistent;
4393 u8 pin_len = 0;
4394
4199 BT_DBG("%s", hdev->name);
4395 bt_dev_dbg(hdev, "");
4200
4201 hci_dev_lock(hdev);
4202
4203 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4204 if (!conn)
4205 goto unlock;
4206
4207 hci_conn_hold(conn);

--- 35 unchanged lines hidden (view full) ---

4243 clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags);
4244 else
4245 set_bit(HCI_CONN_FLUSH_KEY, &conn->flags);
4246
4247unlock:
4248 hci_dev_unlock(hdev);
4249}
4250
4396
4397 hci_dev_lock(hdev);
4398
4399 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4400 if (!conn)
4401 goto unlock;
4402
4403 hci_conn_hold(conn);

--- 35 unchanged lines hidden (view full) ---

4439 clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags);
4440 else
4441 set_bit(HCI_CONN_FLUSH_KEY, &conn->flags);
4442
4443unlock:
4444 hci_dev_unlock(hdev);
4445}
4446
4251static void hci_clock_offset_evt(struct hci_dev *hdev, struct sk_buff *skb)
4447static void hci_clock_offset_evt(struct hci_dev *hdev, void *data,
4448 struct sk_buff *skb)
4252{
4449{
4253 struct hci_ev_clock_offset *ev = (void *) skb->data;
4450 struct hci_ev_clock_offset *ev = data;
4254 struct hci_conn *conn;
4255
4451 struct hci_conn *conn;
4452
4256 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
4453 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4257
4258 hci_dev_lock(hdev);
4259
4260 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4261 if (conn && !ev->status) {
4262 struct inquiry_entry *ie;
4263
4264 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
4265 if (ie) {
4266 ie->data.clock_offset = ev->clock_offset;
4267 ie->timestamp = jiffies;
4268 }
4269 }
4270
4271 hci_dev_unlock(hdev);
4272}
4273
4454
4455 hci_dev_lock(hdev);
4456
4457 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4458 if (conn && !ev->status) {
4459 struct inquiry_entry *ie;
4460
4461 ie = hci_inquiry_cache_lookup(hdev, &conn->dst);
4462 if (ie) {
4463 ie->data.clock_offset = ev->clock_offset;
4464 ie->timestamp = jiffies;
4465 }
4466 }
4467
4468 hci_dev_unlock(hdev);
4469}
4470
4274static void hci_pkt_type_change_evt(struct hci_dev *hdev, struct sk_buff *skb)
4471static void hci_pkt_type_change_evt(struct hci_dev *hdev, void *data,
4472 struct sk_buff *skb)
4275{
4473{
4276 struct hci_ev_pkt_type_change *ev = (void *) skb->data;
4474 struct hci_ev_pkt_type_change *ev = data;
4277 struct hci_conn *conn;
4278
4475 struct hci_conn *conn;
4476
4279 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
4477 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4280
4281 hci_dev_lock(hdev);
4282
4283 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4284 if (conn && !ev->status)
4285 conn->pkt_type = __le16_to_cpu(ev->pkt_type);
4286
4287 hci_dev_unlock(hdev);
4288}
4289
4478
4479 hci_dev_lock(hdev);
4480
4481 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4482 if (conn && !ev->status)
4483 conn->pkt_type = __le16_to_cpu(ev->pkt_type);
4484
4485 hci_dev_unlock(hdev);
4486}
4487
4290static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, struct sk_buff *skb)
4488static void hci_pscan_rep_mode_evt(struct hci_dev *hdev, void *data,
4489 struct sk_buff *skb)
4291{
4490{
4292 struct hci_ev_pscan_rep_mode *ev = (void *) skb->data;
4491 struct hci_ev_pscan_rep_mode *ev = data;
4293 struct inquiry_entry *ie;
4294
4492 struct inquiry_entry *ie;
4493
4295 BT_DBG("%s", hdev->name);
4494 bt_dev_dbg(hdev, "");
4296
4297 hci_dev_lock(hdev);
4298
4299 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
4300 if (ie) {
4301 ie->data.pscan_rep_mode = ev->pscan_rep_mode;
4302 ie->timestamp = jiffies;
4303 }
4304
4305 hci_dev_unlock(hdev);
4306}
4307
4495
4496 hci_dev_lock(hdev);
4497
4498 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
4499 if (ie) {
4500 ie->data.pscan_rep_mode = ev->pscan_rep_mode;
4501 ie->timestamp = jiffies;
4502 }
4503
4504 hci_dev_unlock(hdev);
4505}
4506
4308static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev,
4507static void hci_inquiry_result_with_rssi_evt(struct hci_dev *hdev, void *edata,
4309 struct sk_buff *skb)
4310{
4508 struct sk_buff *skb)
4509{
4510 struct hci_ev_inquiry_result_rssi *ev = edata;
4311 struct inquiry_data data;
4511 struct inquiry_data data;
4312 int num_rsp = *((__u8 *) skb->data);
4512 int i;
4313
4513
4314 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
4514 bt_dev_dbg(hdev, "num_rsp %d", ev->num);
4315
4515
4316 if (!num_rsp)
4516 if (!ev->num)
4317 return;
4318
4319 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
4320 return;
4321
4322 hci_dev_lock(hdev);
4323
4517 return;
4518
4519 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
4520 return;
4521
4522 hci_dev_lock(hdev);
4523
4324 if ((skb->len - 1) / num_rsp != sizeof(struct inquiry_info_with_rssi)) {
4325 struct inquiry_info_with_rssi_and_pscan_mode *info;
4326 info = (void *) (skb->data + 1);
4524 if (skb->len == array_size(ev->num,
4525 sizeof(struct inquiry_info_rssi_pscan))) {
4526 struct inquiry_info_rssi_pscan *info;
4327
4527
4328 if (skb->len < num_rsp * sizeof(*info) + 1)
4329 goto unlock;
4330
4331 for (; num_rsp; num_rsp--, info++) {
4528 for (i = 0; i < ev->num; i++) {
4332 u32 flags;
4333
4529 u32 flags;
4530
4531 info = hci_ev_skb_pull(hdev, skb,
4532 HCI_EV_INQUIRY_RESULT_WITH_RSSI,
4533 sizeof(*info));
4534 if (!info) {
4535 bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x",
4536 HCI_EV_INQUIRY_RESULT_WITH_RSSI);
4537 return;
4538 }
4539
4334 bacpy(&data.bdaddr, &info->bdaddr);
4335 data.pscan_rep_mode = info->pscan_rep_mode;
4336 data.pscan_period_mode = info->pscan_period_mode;
4337 data.pscan_mode = info->pscan_mode;
4338 memcpy(data.dev_class, info->dev_class, 3);
4339 data.clock_offset = info->clock_offset;
4340 data.rssi = info->rssi;
4341 data.ssp_mode = 0x00;
4342
4343 flags = hci_inquiry_cache_update(hdev, &data, false);
4344
4345 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
4346 info->dev_class, info->rssi,
4347 flags, NULL, 0, NULL, 0);
4348 }
4540 bacpy(&data.bdaddr, &info->bdaddr);
4541 data.pscan_rep_mode = info->pscan_rep_mode;
4542 data.pscan_period_mode = info->pscan_period_mode;
4543 data.pscan_mode = info->pscan_mode;
4544 memcpy(data.dev_class, info->dev_class, 3);
4545 data.clock_offset = info->clock_offset;
4546 data.rssi = info->rssi;
4547 data.ssp_mode = 0x00;
4548
4549 flags = hci_inquiry_cache_update(hdev, &data, false);
4550
4551 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
4552 info->dev_class, info->rssi,
4553 flags, NULL, 0, NULL, 0);
4554 }
4349 } else {
4350 struct inquiry_info_with_rssi *info = (void *) (skb->data + 1);
4555 } else if (skb->len == array_size(ev->num,
4556 sizeof(struct inquiry_info_rssi))) {
4557 struct inquiry_info_rssi *info;
4351
4558
4352 if (skb->len < num_rsp * sizeof(*info) + 1)
4353 goto unlock;
4354
4355 for (; num_rsp; num_rsp--, info++) {
4559 for (i = 0; i < ev->num; i++) {
4356 u32 flags;
4357
4560 u32 flags;
4561
4562 info = hci_ev_skb_pull(hdev, skb,
4563 HCI_EV_INQUIRY_RESULT_WITH_RSSI,
4564 sizeof(*info));
4565 if (!info) {
4566 bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x",
4567 HCI_EV_INQUIRY_RESULT_WITH_RSSI);
4568 return;
4569 }
4570
4358 bacpy(&data.bdaddr, &info->bdaddr);
4359 data.pscan_rep_mode = info->pscan_rep_mode;
4360 data.pscan_period_mode = info->pscan_period_mode;
4361 data.pscan_mode = 0x00;
4362 memcpy(data.dev_class, info->dev_class, 3);
4363 data.clock_offset = info->clock_offset;
4364 data.rssi = info->rssi;
4365 data.ssp_mode = 0x00;
4366
4367 flags = hci_inquiry_cache_update(hdev, &data, false);
4368
4369 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
4370 info->dev_class, info->rssi,
4371 flags, NULL, 0, NULL, 0);
4372 }
4571 bacpy(&data.bdaddr, &info->bdaddr);
4572 data.pscan_rep_mode = info->pscan_rep_mode;
4573 data.pscan_period_mode = info->pscan_period_mode;
4574 data.pscan_mode = 0x00;
4575 memcpy(data.dev_class, info->dev_class, 3);
4576 data.clock_offset = info->clock_offset;
4577 data.rssi = info->rssi;
4578 data.ssp_mode = 0x00;
4579
4580 flags = hci_inquiry_cache_update(hdev, &data, false);
4581
4582 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
4583 info->dev_class, info->rssi,
4584 flags, NULL, 0, NULL, 0);
4585 }
4586 } else {
4587 bt_dev_err(hdev, "Malformed HCI Event: 0x%2.2x",
4588 HCI_EV_INQUIRY_RESULT_WITH_RSSI);
4373 }
4374
4589 }
4590
4375unlock:
4376 hci_dev_unlock(hdev);
4377}
4378
4591 hci_dev_unlock(hdev);
4592}
4593
4379static void hci_remote_ext_features_evt(struct hci_dev *hdev,
4594static void hci_remote_ext_features_evt(struct hci_dev *hdev, void *data,
4380 struct sk_buff *skb)
4381{
4595 struct sk_buff *skb)
4596{
4382 struct hci_ev_remote_ext_features *ev = (void *) skb->data;
4597 struct hci_ev_remote_ext_features *ev = data;
4383 struct hci_conn *conn;
4384
4598 struct hci_conn *conn;
4599
4385 BT_DBG("%s", hdev->name);
4600 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4386
4387 hci_dev_lock(hdev);
4388
4389 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4390 if (!conn)
4391 goto unlock;
4392
4393 if (ev->page < HCI_MAX_PAGES)

--- 41 unchanged lines hidden (view full) ---

4435 hci_connect_cfm(conn, ev->status);
4436 hci_conn_drop(conn);
4437 }
4438
4439unlock:
4440 hci_dev_unlock(hdev);
4441}
4442
4601
4602 hci_dev_lock(hdev);
4603
4604 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4605 if (!conn)
4606 goto unlock;
4607
4608 if (ev->page < HCI_MAX_PAGES)

--- 41 unchanged lines hidden (view full) ---

4650 hci_connect_cfm(conn, ev->status);
4651 hci_conn_drop(conn);
4652 }
4653
4654unlock:
4655 hci_dev_unlock(hdev);
4656}
4657
4443static void hci_sync_conn_complete_evt(struct hci_dev *hdev,
4658static void hci_sync_conn_complete_evt(struct hci_dev *hdev, void *data,
4444 struct sk_buff *skb)
4445{
4659 struct sk_buff *skb)
4660{
4446 struct hci_ev_sync_conn_complete *ev = (void *) skb->data;
4661 struct hci_ev_sync_conn_complete *ev = data;
4447 struct hci_conn *conn;
4662 struct hci_conn *conn;
4448 unsigned int notify_evt;
4449
4663
4450 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
4664 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
4451
4452 hci_dev_lock(hdev);
4453
4454 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
4455 if (!conn) {
4456 if (ev->link_type == ESCO_LINK)
4457 goto unlock;
4458

--- 53 unchanged lines hidden (view full) ---

4512 fallthrough;
4513
4514 default:
4515 conn->state = BT_CLOSED;
4516 break;
4517 }
4518
4519 bt_dev_dbg(hdev, "SCO connected with air mode: %02x", ev->air_mode);
4665
4666 hci_dev_lock(hdev);
4667
4668 conn = hci_conn_hash_lookup_ba(hdev, ev->link_type, &ev->bdaddr);
4669 if (!conn) {
4670 if (ev->link_type == ESCO_LINK)
4671 goto unlock;
4672

--- 53 unchanged lines hidden (view full) ---

4726 fallthrough;
4727
4728 default:
4729 conn->state = BT_CLOSED;
4730 break;
4731 }
4732
4733 bt_dev_dbg(hdev, "SCO connected with air mode: %02x", ev->air_mode);
4520
4521 switch (ev->air_mode) {
4522 case 0x02:
4523 notify_evt = HCI_NOTIFY_ENABLE_SCO_CVSD;
4524 break;
4525 case 0x03:
4526 notify_evt = HCI_NOTIFY_ENABLE_SCO_TRANSP;
4527 break;
4528 }
4529
4530 /* Notify only in case of SCO over HCI transport data path which
4531 * is zero and non-zero value shall be non-HCI transport data path
4532 */
4734 /* Notify only in case of SCO over HCI transport data path which
4735 * is zero and non-zero value shall be non-HCI transport data path
4736 */
4533 if (conn->codec.data_path == 0) {
4534 if (hdev->notify)
4535 hdev->notify(hdev, notify_evt);
4737 if (conn->codec.data_path == 0 && hdev->notify) {
4738 switch (ev->air_mode) {
4739 case 0x02:
4740 hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_CVSD);
4741 break;
4742 case 0x03:
4743 hdev->notify(hdev, HCI_NOTIFY_ENABLE_SCO_TRANSP);
4744 break;
4745 }
4536 }
4537
4538 hci_connect_cfm(conn, ev->status);
4539 if (ev->status)
4540 hci_conn_del(conn);
4541
4542unlock:
4543 hci_dev_unlock(hdev);

--- 11 unchanged lines hidden (view full) ---

4555
4556 parsed += field_len + 1;
4557 eir += field_len + 1;
4558 }
4559
4560 return eir_len;
4561}
4562
4746 }
4747
4748 hci_connect_cfm(conn, ev->status);
4749 if (ev->status)
4750 hci_conn_del(conn);
4751
4752unlock:
4753 hci_dev_unlock(hdev);

--- 11 unchanged lines hidden (view full) ---

4765
4766 parsed += field_len + 1;
4767 eir += field_len + 1;
4768 }
4769
4770 return eir_len;
4771}
4772
4563static void hci_extended_inquiry_result_evt(struct hci_dev *hdev,
4773static void hci_extended_inquiry_result_evt(struct hci_dev *hdev, void *edata,
4564 struct sk_buff *skb)
4565{
4774 struct sk_buff *skb)
4775{
4776 struct hci_ev_ext_inquiry_result *ev = edata;
4566 struct inquiry_data data;
4777 struct inquiry_data data;
4567 struct extended_inquiry_info *info = (void *) (skb->data + 1);
4568 int num_rsp = *((__u8 *) skb->data);
4569 size_t eir_len;
4778 size_t eir_len;
4779 int i;
4570
4780
4571 BT_DBG("%s num_rsp %d", hdev->name, num_rsp);
4781 if (!hci_ev_skb_pull(hdev, skb, HCI_EV_EXTENDED_INQUIRY_RESULT,
4782 flex_array_size(ev, info, ev->num)))
4783 return;
4572
4784
4573 if (!num_rsp || skb->len < num_rsp * sizeof(*info) + 1)
4785 bt_dev_dbg(hdev, "num %d", ev->num);
4786
4787 if (!ev->num)
4574 return;
4575
4576 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
4577 return;
4578
4579 hci_dev_lock(hdev);
4580
4788 return;
4789
4790 if (hci_dev_test_flag(hdev, HCI_PERIODIC_INQ))
4791 return;
4792
4793 hci_dev_lock(hdev);
4794
4581 for (; num_rsp; num_rsp--, info++) {
4795 for (i = 0; i < ev->num; i++) {
4796 struct extended_inquiry_info *info = &ev->info[i];
4582 u32 flags;
4583 bool name_known;
4584
4585 bacpy(&data.bdaddr, &info->bdaddr);
4586 data.pscan_rep_mode = info->pscan_rep_mode;
4587 data.pscan_period_mode = info->pscan_period_mode;
4588 data.pscan_mode = 0x00;
4589 memcpy(data.dev_class, info->dev_class, 3);

--- 15 unchanged lines hidden (view full) ---

4605 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
4606 info->dev_class, info->rssi,
4607 flags, info->data, eir_len, NULL, 0);
4608 }
4609
4610 hci_dev_unlock(hdev);
4611}
4612
4797 u32 flags;
4798 bool name_known;
4799
4800 bacpy(&data.bdaddr, &info->bdaddr);
4801 data.pscan_rep_mode = info->pscan_rep_mode;
4802 data.pscan_period_mode = info->pscan_period_mode;
4803 data.pscan_mode = 0x00;
4804 memcpy(data.dev_class, info->dev_class, 3);

--- 15 unchanged lines hidden (view full) ---

4820 mgmt_device_found(hdev, &info->bdaddr, ACL_LINK, 0x00,
4821 info->dev_class, info->rssi,
4822 flags, info->data, eir_len, NULL, 0);
4823 }
4824
4825 hci_dev_unlock(hdev);
4826}
4827
4613static void hci_key_refresh_complete_evt(struct hci_dev *hdev,
4828static void hci_key_refresh_complete_evt(struct hci_dev *hdev, void *data,
4614 struct sk_buff *skb)
4615{
4829 struct sk_buff *skb)
4830{
4616 struct hci_ev_key_refresh_complete *ev = (void *) skb->data;
4831 struct hci_ev_key_refresh_complete *ev = data;
4617 struct hci_conn *conn;
4618
4832 struct hci_conn *conn;
4833
4619 BT_DBG("%s status 0x%2.2x handle 0x%4.4x", hdev->name, ev->status,
4620 __le16_to_cpu(ev->handle));
4834 bt_dev_dbg(hdev, "status 0x%2.2x handle 0x%4.4x", ev->status,
4835 __le16_to_cpu(ev->handle));
4621
4622 hci_dev_lock(hdev);
4623
4624 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4625 if (!conn)
4626 goto unlock;
4627
4628 /* For BR/EDR the necessary steps are taken through the

--- 86 unchanged lines hidden (view full) ---

4715 */
4716 if (!memcmp(data->rand192, ZERO_KEY, 16) ||
4717 !memcmp(data->hash192, ZERO_KEY, 16))
4718 return 0x00;
4719
4720 return 0x01;
4721}
4722
4836
4837 hci_dev_lock(hdev);
4838
4839 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
4840 if (!conn)
4841 goto unlock;
4842
4843 /* For BR/EDR the necessary steps are taken through the

--- 86 unchanged lines hidden (view full) ---

4930 */
4931 if (!memcmp(data->rand192, ZERO_KEY, 16) ||
4932 !memcmp(data->hash192, ZERO_KEY, 16))
4933 return 0x00;
4934
4935 return 0x01;
4936}
4937
4723static void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
4938static void hci_io_capa_request_evt(struct hci_dev *hdev, void *data,
4939 struct sk_buff *skb)
4724{
4940{
4725 struct hci_ev_io_capa_request *ev = (void *) skb->data;
4941 struct hci_ev_io_capa_request *ev = data;
4726 struct hci_conn *conn;
4727
4942 struct hci_conn *conn;
4943
4728 BT_DBG("%s", hdev->name);
4944 bt_dev_dbg(hdev, "");
4729
4730 hci_dev_lock(hdev);
4731
4732 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4733 if (!conn)
4734 goto unlock;
4735
4736 hci_conn_hold(conn);

--- 47 unchanged lines hidden (view full) ---

4784 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
4785 sizeof(cp), &cp);
4786 }
4787
4788unlock:
4789 hci_dev_unlock(hdev);
4790}
4791
4945
4946 hci_dev_lock(hdev);
4947
4948 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4949 if (!conn)
4950 goto unlock;
4951
4952 hci_conn_hold(conn);

--- 47 unchanged lines hidden (view full) ---

5000 hci_send_cmd(hdev, HCI_OP_IO_CAPABILITY_NEG_REPLY,
5001 sizeof(cp), &cp);
5002 }
5003
5004unlock:
5005 hci_dev_unlock(hdev);
5006}
5007
4792static void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *skb)
5008static void hci_io_capa_reply_evt(struct hci_dev *hdev, void *data,
5009 struct sk_buff *skb)
4793{
5010{
4794 struct hci_ev_io_capa_reply *ev = (void *) skb->data;
5011 struct hci_ev_io_capa_reply *ev = data;
4795 struct hci_conn *conn;
4796
5012 struct hci_conn *conn;
5013
4797 BT_DBG("%s", hdev->name);
5014 bt_dev_dbg(hdev, "");
4798
4799 hci_dev_lock(hdev);
4800
4801 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4802 if (!conn)
4803 goto unlock;
4804
4805 conn->remote_cap = ev->capability;
4806 conn->remote_auth = ev->authentication;
4807
4808unlock:
4809 hci_dev_unlock(hdev);
4810}
4811
5015
5016 hci_dev_lock(hdev);
5017
5018 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5019 if (!conn)
5020 goto unlock;
5021
5022 conn->remote_cap = ev->capability;
5023 conn->remote_auth = ev->authentication;
5024
5025unlock:
5026 hci_dev_unlock(hdev);
5027}
5028
4812static void hci_user_confirm_request_evt(struct hci_dev *hdev,
5029static void hci_user_confirm_request_evt(struct hci_dev *hdev, void *data,
4813 struct sk_buff *skb)
4814{
5030 struct sk_buff *skb)
5031{
4815 struct hci_ev_user_confirm_req *ev = (void *) skb->data;
5032 struct hci_ev_user_confirm_req *ev = data;
4816 int loc_mitm, rem_mitm, confirm_hint = 0;
4817 struct hci_conn *conn;
4818
5033 int loc_mitm, rem_mitm, confirm_hint = 0;
5034 struct hci_conn *conn;
5035
4819 BT_DBG("%s", hdev->name);
5036 bt_dev_dbg(hdev, "");
4820
4821 hci_dev_lock(hdev);
4822
4823 if (!hci_dev_test_flag(hdev, HCI_MGMT))
4824 goto unlock;
4825
4826 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4827 if (!conn)

--- 4 unchanged lines hidden (view full) ---

4832
4833 /* If we require MITM but the remote device can't provide that
4834 * (it has NoInputNoOutput) then reject the confirmation
4835 * request. We check the security level here since it doesn't
4836 * necessarily match conn->auth_type.
4837 */
4838 if (conn->pending_sec_level > BT_SECURITY_MEDIUM &&
4839 conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) {
5037
5038 hci_dev_lock(hdev);
5039
5040 if (!hci_dev_test_flag(hdev, HCI_MGMT))
5041 goto unlock;
5042
5043 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5044 if (!conn)

--- 4 unchanged lines hidden (view full) ---

5049
5050 /* If we require MITM but the remote device can't provide that
5051 * (it has NoInputNoOutput) then reject the confirmation
5052 * request. We check the security level here since it doesn't
5053 * necessarily match conn->auth_type.
5054 */
5055 if (conn->pending_sec_level > BT_SECURITY_MEDIUM &&
5056 conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) {
4840 BT_DBG("Rejecting request: remote device can't provide MITM");
5057 bt_dev_dbg(hdev, "Rejecting request: remote device can't provide MITM");
4841 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY,
4842 sizeof(ev->bdaddr), &ev->bdaddr);
4843 goto unlock;
4844 }
4845
4846 /* If no side requires MITM protection; auto-accept */
4847 if ((!loc_mitm || conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) &&
4848 (!rem_mitm || conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)) {
4849
4850 /* If we're not the initiators request authorization to
4851 * proceed from user space (mgmt_user_confirm with
4852 * confirm_hint set to 1). The exception is if neither
4853 * side had MITM or if the local IO capability is
4854 * NoInputNoOutput, in which case we do auto-accept
4855 */
4856 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) &&
4857 conn->io_capability != HCI_IO_NO_INPUT_OUTPUT &&
4858 (loc_mitm || rem_mitm)) {
5058 hci_send_cmd(hdev, HCI_OP_USER_CONFIRM_NEG_REPLY,
5059 sizeof(ev->bdaddr), &ev->bdaddr);
5060 goto unlock;
5061 }
5062
5063 /* If no side requires MITM protection; auto-accept */
5064 if ((!loc_mitm || conn->remote_cap == HCI_IO_NO_INPUT_OUTPUT) &&
5065 (!rem_mitm || conn->io_capability == HCI_IO_NO_INPUT_OUTPUT)) {
5066
5067 /* If we're not the initiators request authorization to
5068 * proceed from user space (mgmt_user_confirm with
5069 * confirm_hint set to 1). The exception is if neither
5070 * side had MITM or if the local IO capability is
5071 * NoInputNoOutput, in which case we do auto-accept
5072 */
5073 if (!test_bit(HCI_CONN_AUTH_PEND, &conn->flags) &&
5074 conn->io_capability != HCI_IO_NO_INPUT_OUTPUT &&
5075 (loc_mitm || rem_mitm)) {
4859 BT_DBG("Confirming auto-accept as acceptor");
5076 bt_dev_dbg(hdev, "Confirming auto-accept as acceptor");
4860 confirm_hint = 1;
4861 goto confirm;
4862 }
4863
4864 /* If there already exists link key in local host, leave the
4865 * decision to user space since the remote device could be
4866 * legitimate or malicious.
4867 */

--- 21 unchanged lines hidden (view full) ---

4889confirm:
4890 mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0,
4891 le32_to_cpu(ev->passkey), confirm_hint);
4892
4893unlock:
4894 hci_dev_unlock(hdev);
4895}
4896
5077 confirm_hint = 1;
5078 goto confirm;
5079 }
5080
5081 /* If there already exists link key in local host, leave the
5082 * decision to user space since the remote device could be
5083 * legitimate or malicious.
5084 */

--- 21 unchanged lines hidden (view full) ---

5106confirm:
5107 mgmt_user_confirm_request(hdev, &ev->bdaddr, ACL_LINK, 0,
5108 le32_to_cpu(ev->passkey), confirm_hint);
5109
5110unlock:
5111 hci_dev_unlock(hdev);
5112}
5113
4897static void hci_user_passkey_request_evt(struct hci_dev *hdev,
5114static void hci_user_passkey_request_evt(struct hci_dev *hdev, void *data,
4898 struct sk_buff *skb)
4899{
5115 struct sk_buff *skb)
5116{
4900 struct hci_ev_user_passkey_req *ev = (void *) skb->data;
5117 struct hci_ev_user_passkey_req *ev = data;
4901
5118
4902 BT_DBG("%s", hdev->name);
5119 bt_dev_dbg(hdev, "");
4903
4904 if (hci_dev_test_flag(hdev, HCI_MGMT))
4905 mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0);
4906}
4907
5120
5121 if (hci_dev_test_flag(hdev, HCI_MGMT))
5122 mgmt_user_passkey_request(hdev, &ev->bdaddr, ACL_LINK, 0);
5123}
5124
4908static void hci_user_passkey_notify_evt(struct hci_dev *hdev,
5125static void hci_user_passkey_notify_evt(struct hci_dev *hdev, void *data,
4909 struct sk_buff *skb)
4910{
5126 struct sk_buff *skb)
5127{
4911 struct hci_ev_user_passkey_notify *ev = (void *) skb->data;
5128 struct hci_ev_user_passkey_notify *ev = data;
4912 struct hci_conn *conn;
4913
5129 struct hci_conn *conn;
5130
4914 BT_DBG("%s", hdev->name);
5131 bt_dev_dbg(hdev, "");
4915
4916 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4917 if (!conn)
4918 return;
4919
4920 conn->passkey_notify = __le32_to_cpu(ev->passkey);
4921 conn->passkey_entered = 0;
4922
4923 if (hci_dev_test_flag(hdev, HCI_MGMT))
4924 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
4925 conn->dst_type, conn->passkey_notify,
4926 conn->passkey_entered);
4927}
4928
5132
5133 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5134 if (!conn)
5135 return;
5136
5137 conn->passkey_notify = __le32_to_cpu(ev->passkey);
5138 conn->passkey_entered = 0;
5139
5140 if (hci_dev_test_flag(hdev, HCI_MGMT))
5141 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
5142 conn->dst_type, conn->passkey_notify,
5143 conn->passkey_entered);
5144}
5145
4929static void hci_keypress_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
5146static void hci_keypress_notify_evt(struct hci_dev *hdev, void *data,
5147 struct sk_buff *skb)
4930{
5148{
4931 struct hci_ev_keypress_notify *ev = (void *) skb->data;
5149 struct hci_ev_keypress_notify *ev = data;
4932 struct hci_conn *conn;
4933
5150 struct hci_conn *conn;
5151
4934 BT_DBG("%s", hdev->name);
5152 bt_dev_dbg(hdev, "");
4935
4936 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4937 if (!conn)
4938 return;
4939
4940 switch (ev->type) {
4941 case HCI_KEYPRESS_STARTED:
4942 conn->passkey_entered = 0;

--- 16 unchanged lines hidden (view full) ---

4959 }
4960
4961 if (hci_dev_test_flag(hdev, HCI_MGMT))
4962 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
4963 conn->dst_type, conn->passkey_notify,
4964 conn->passkey_entered);
4965}
4966
5153
5154 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5155 if (!conn)
5156 return;
5157
5158 switch (ev->type) {
5159 case HCI_KEYPRESS_STARTED:
5160 conn->passkey_entered = 0;

--- 16 unchanged lines hidden (view full) ---

5177 }
5178
5179 if (hci_dev_test_flag(hdev, HCI_MGMT))
5180 mgmt_user_passkey_notify(hdev, &conn->dst, conn->type,
5181 conn->dst_type, conn->passkey_notify,
5182 conn->passkey_entered);
5183}
5184
4967static void hci_simple_pair_complete_evt(struct hci_dev *hdev,
5185static void hci_simple_pair_complete_evt(struct hci_dev *hdev, void *data,
4968 struct sk_buff *skb)
4969{
5186 struct sk_buff *skb)
5187{
4970 struct hci_ev_simple_pair_complete *ev = (void *) skb->data;
5188 struct hci_ev_simple_pair_complete *ev = data;
4971 struct hci_conn *conn;
4972
5189 struct hci_conn *conn;
5190
4973 BT_DBG("%s", hdev->name);
5191 bt_dev_dbg(hdev, "");
4974
4975 hci_dev_lock(hdev);
4976
4977 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
4978 if (!conn)
4979 goto unlock;
4980
4981 /* Reset the authentication requirement to unknown */

--- 8 unchanged lines hidden (view full) ---

4990 mgmt_auth_failed(conn, ev->status);
4991
4992 hci_conn_drop(conn);
4993
4994unlock:
4995 hci_dev_unlock(hdev);
4996}
4997
5192
5193 hci_dev_lock(hdev);
5194
5195 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5196 if (!conn)
5197 goto unlock;
5198
5199 /* Reset the authentication requirement to unknown */

--- 8 unchanged lines hidden (view full) ---

5208 mgmt_auth_failed(conn, ev->status);
5209
5210 hci_conn_drop(conn);
5211
5212unlock:
5213 hci_dev_unlock(hdev);
5214}
5215
4998static void hci_remote_host_features_evt(struct hci_dev *hdev,
5216static void hci_remote_host_features_evt(struct hci_dev *hdev, void *data,
4999 struct sk_buff *skb)
5000{
5217 struct sk_buff *skb)
5218{
5001 struct hci_ev_remote_host_features *ev = (void *) skb->data;
5219 struct hci_ev_remote_host_features *ev = data;
5002 struct inquiry_entry *ie;
5003 struct hci_conn *conn;
5004
5220 struct inquiry_entry *ie;
5221 struct hci_conn *conn;
5222
5005 BT_DBG("%s", hdev->name);
5223 bt_dev_dbg(hdev, "");
5006
5007 hci_dev_lock(hdev);
5008
5009 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5010 if (conn)
5011 memcpy(conn->features[1], ev->features, 8);
5012
5013 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
5014 if (ie)
5015 ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP);
5016
5017 hci_dev_unlock(hdev);
5018}
5019
5224
5225 hci_dev_lock(hdev);
5226
5227 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &ev->bdaddr);
5228 if (conn)
5229 memcpy(conn->features[1], ev->features, 8);
5230
5231 ie = hci_inquiry_cache_lookup(hdev, &ev->bdaddr);
5232 if (ie)
5233 ie->data.ssp_mode = (ev->features[0] & LMP_HOST_SSP);
5234
5235 hci_dev_unlock(hdev);
5236}
5237
5020static void hci_remote_oob_data_request_evt(struct hci_dev *hdev,
5238static void hci_remote_oob_data_request_evt(struct hci_dev *hdev, void *edata,
5021 struct sk_buff *skb)
5022{
5239 struct sk_buff *skb)
5240{
5023 struct hci_ev_remote_oob_data_request *ev = (void *) skb->data;
5241 struct hci_ev_remote_oob_data_request *ev = edata;
5024 struct oob_data *data;
5025
5242 struct oob_data *data;
5243
5026 BT_DBG("%s", hdev->name);
5244 bt_dev_dbg(hdev, "");
5027
5028 hci_dev_lock(hdev);
5029
5030 if (!hci_dev_test_flag(hdev, HCI_MGMT))
5031 goto unlock;
5032
5033 data = hci_find_remote_oob_data(hdev, &ev->bdaddr, BDADDR_BREDR);
5034 if (!data) {

--- 32 unchanged lines hidden (view full) ---

5067 sizeof(cp), &cp);
5068 }
5069
5070unlock:
5071 hci_dev_unlock(hdev);
5072}
5073
5074#if IS_ENABLED(CONFIG_BT_HS)
5245
5246 hci_dev_lock(hdev);
5247
5248 if (!hci_dev_test_flag(hdev, HCI_MGMT))
5249 goto unlock;
5250
5251 data = hci_find_remote_oob_data(hdev, &ev->bdaddr, BDADDR_BREDR);
5252 if (!data) {

--- 32 unchanged lines hidden (view full) ---

5285 sizeof(cp), &cp);
5286 }
5287
5288unlock:
5289 hci_dev_unlock(hdev);
5290}
5291
5292#if IS_ENABLED(CONFIG_BT_HS)
5075static void hci_chan_selected_evt(struct hci_dev *hdev, struct sk_buff *skb)
5293static void hci_chan_selected_evt(struct hci_dev *hdev, void *data,
5294 struct sk_buff *skb)
5076{
5295{
5077 struct hci_ev_channel_selected *ev = (void *)skb->data;
5296 struct hci_ev_channel_selected *ev = data;
5078 struct hci_conn *hcon;
5079
5297 struct hci_conn *hcon;
5298
5080 BT_DBG("%s handle 0x%2.2x", hdev->name, ev->phy_handle);
5299 bt_dev_dbg(hdev, "handle 0x%2.2x", ev->phy_handle);
5081
5300
5082 skb_pull(skb, sizeof(*ev));
5083
5084 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5085 if (!hcon)
5086 return;
5087
5088 amp_read_loc_assoc_final_data(hdev, hcon);
5089}
5090
5301 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5302 if (!hcon)
5303 return;
5304
5305 amp_read_loc_assoc_final_data(hdev, hcon);
5306}
5307
5091static void hci_phy_link_complete_evt(struct hci_dev *hdev,
5308static void hci_phy_link_complete_evt(struct hci_dev *hdev, void *data,
5092 struct sk_buff *skb)
5093{
5309 struct sk_buff *skb)
5310{
5094 struct hci_ev_phy_link_complete *ev = (void *) skb->data;
5311 struct hci_ev_phy_link_complete *ev = data;
5095 struct hci_conn *hcon, *bredr_hcon;
5096
5312 struct hci_conn *hcon, *bredr_hcon;
5313
5097 BT_DBG("%s handle 0x%2.2x status 0x%2.2x", hdev->name, ev->phy_handle,
5098 ev->status);
5314 bt_dev_dbg(hdev, "handle 0x%2.2x status 0x%2.2x", ev->phy_handle,
5315 ev->status);
5099
5100 hci_dev_lock(hdev);
5101
5102 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5103 if (!hcon)
5104 goto unlock;
5105
5106 if (!hcon->amp_mgr)

--- 17 unchanged lines hidden (view full) ---

5124 hci_conn_add_sysfs(hcon);
5125
5126 amp_physical_cfm(bredr_hcon, hcon);
5127
5128unlock:
5129 hci_dev_unlock(hdev);
5130}
5131
5316
5317 hci_dev_lock(hdev);
5318
5319 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5320 if (!hcon)
5321 goto unlock;
5322
5323 if (!hcon->amp_mgr)

--- 17 unchanged lines hidden (view full) ---

5341 hci_conn_add_sysfs(hcon);
5342
5343 amp_physical_cfm(bredr_hcon, hcon);
5344
5345unlock:
5346 hci_dev_unlock(hdev);
5347}
5348
5132static void hci_loglink_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
5349static void hci_loglink_complete_evt(struct hci_dev *hdev, void *data,
5350 struct sk_buff *skb)
5133{
5351{
5134 struct hci_ev_logical_link_complete *ev = (void *) skb->data;
5352 struct hci_ev_logical_link_complete *ev = data;
5135 struct hci_conn *hcon;
5136 struct hci_chan *hchan;
5137 struct amp_mgr *mgr;
5138
5353 struct hci_conn *hcon;
5354 struct hci_chan *hchan;
5355 struct amp_mgr *mgr;
5356
5139 BT_DBG("%s log_handle 0x%4.4x phy_handle 0x%2.2x status 0x%2.2x",
5140 hdev->name, le16_to_cpu(ev->handle), ev->phy_handle,
5141 ev->status);
5357 bt_dev_dbg(hdev, "log_handle 0x%4.4x phy_handle 0x%2.2x status 0x%2.2x",
5358 le16_to_cpu(ev->handle), ev->phy_handle, ev->status);
5142
5143 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5144 if (!hcon)
5145 return;
5146
5147 /* Create AMP hchan */
5148 hchan = hci_chan_create(hcon);
5149 if (!hchan)

--- 13 unchanged lines hidden (view full) ---

5163 bredr_chan->conn->mtu = hdev->block_mtu;
5164 l2cap_logical_cfm(bredr_chan, hchan, 0);
5165 hci_conn_hold(hcon);
5166
5167 l2cap_chan_unlock(bredr_chan);
5168 }
5169}
5170
5359
5360 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5361 if (!hcon)
5362 return;
5363
5364 /* Create AMP hchan */
5365 hchan = hci_chan_create(hcon);
5366 if (!hchan)

--- 13 unchanged lines hidden (view full) ---

5380 bredr_chan->conn->mtu = hdev->block_mtu;
5381 l2cap_logical_cfm(bredr_chan, hchan, 0);
5382 hci_conn_hold(hcon);
5383
5384 l2cap_chan_unlock(bredr_chan);
5385 }
5386}
5387
5171static void hci_disconn_loglink_complete_evt(struct hci_dev *hdev,
5388static void hci_disconn_loglink_complete_evt(struct hci_dev *hdev, void *data,
5172 struct sk_buff *skb)
5173{
5389 struct sk_buff *skb)
5390{
5174 struct hci_ev_disconn_logical_link_complete *ev = (void *) skb->data;
5391 struct hci_ev_disconn_logical_link_complete *ev = data;
5175 struct hci_chan *hchan;
5176
5392 struct hci_chan *hchan;
5393
5177 BT_DBG("%s log handle 0x%4.4x status 0x%2.2x", hdev->name,
5178 le16_to_cpu(ev->handle), ev->status);
5394 bt_dev_dbg(hdev, "handle 0x%4.4x status 0x%2.2x",
5395 le16_to_cpu(ev->handle), ev->status);
5179
5180 if (ev->status)
5181 return;
5182
5183 hci_dev_lock(hdev);
5184
5185 hchan = hci_chan_lookup_handle(hdev, le16_to_cpu(ev->handle));
5186 if (!hchan || !hchan->amp)
5187 goto unlock;
5188
5189 amp_destroy_logical_link(hchan, ev->reason);
5190
5191unlock:
5192 hci_dev_unlock(hdev);
5193}
5194
5396
5397 if (ev->status)
5398 return;
5399
5400 hci_dev_lock(hdev);
5401
5402 hchan = hci_chan_lookup_handle(hdev, le16_to_cpu(ev->handle));
5403 if (!hchan || !hchan->amp)
5404 goto unlock;
5405
5406 amp_destroy_logical_link(hchan, ev->reason);
5407
5408unlock:
5409 hci_dev_unlock(hdev);
5410}
5411
5195static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev,
5412static void hci_disconn_phylink_complete_evt(struct hci_dev *hdev, void *data,
5196 struct sk_buff *skb)
5197{
5413 struct sk_buff *skb)
5414{
5198 struct hci_ev_disconn_phy_link_complete *ev = (void *) skb->data;
5415 struct hci_ev_disconn_phy_link_complete *ev = data;
5199 struct hci_conn *hcon;
5200
5416 struct hci_conn *hcon;
5417
5201 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
5418 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
5202
5203 if (ev->status)
5204 return;
5205
5206 hci_dev_lock(hdev);
5207
5208 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5209 if (hcon) {

--- 197 unchanged lines hidden (view full) ---

5407 if (params->conn) {
5408 hci_conn_drop(params->conn);
5409 hci_conn_put(params->conn);
5410 params->conn = NULL;
5411 }
5412 }
5413
5414unlock:
5419
5420 if (ev->status)
5421 return;
5422
5423 hci_dev_lock(hdev);
5424
5425 hcon = hci_conn_hash_lookup_handle(hdev, ev->phy_handle);
5426 if (hcon) {

--- 197 unchanged lines hidden (view full) ---

5624 if (params->conn) {
5625 hci_conn_drop(params->conn);
5626 hci_conn_put(params->conn);
5627 params->conn = NULL;
5628 }
5629 }
5630
5631unlock:
5415 hci_update_background_scan(hdev);
5632 hci_update_passive_scan(hdev);
5416 hci_dev_unlock(hdev);
5417}
5418
5633 hci_dev_unlock(hdev);
5634}
5635
5419static void hci_le_conn_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
5636static void hci_le_conn_complete_evt(struct hci_dev *hdev, void *data,
5637 struct sk_buff *skb)
5420{
5638{
5421 struct hci_ev_le_conn_complete *ev = (void *) skb->data;
5639 struct hci_ev_le_conn_complete *ev = data;
5422
5640
5423 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
5641 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
5424
5425 le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
5426 NULL, ev->role, le16_to_cpu(ev->handle),
5427 le16_to_cpu(ev->interval),
5428 le16_to_cpu(ev->latency),
5429 le16_to_cpu(ev->supervision_timeout));
5430}
5431
5642
5643 le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
5644 NULL, ev->role, le16_to_cpu(ev->handle),
5645 le16_to_cpu(ev->interval),
5646 le16_to_cpu(ev->latency),
5647 le16_to_cpu(ev->supervision_timeout));
5648}
5649
5432static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
5650static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev, void *data,
5433 struct sk_buff *skb)
5434{
5651 struct sk_buff *skb)
5652{
5435 struct hci_ev_le_enh_conn_complete *ev = (void *) skb->data;
5653 struct hci_ev_le_enh_conn_complete *ev = data;
5436
5654
5437 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
5655 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
5438
5439 le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
5440 &ev->local_rpa, ev->role, le16_to_cpu(ev->handle),
5441 le16_to_cpu(ev->interval),
5442 le16_to_cpu(ev->latency),
5443 le16_to_cpu(ev->supervision_timeout));
5656
5657 le_conn_complete_evt(hdev, ev->status, &ev->bdaddr, ev->bdaddr_type,
5658 &ev->local_rpa, ev->role, le16_to_cpu(ev->handle),
5659 le16_to_cpu(ev->interval),
5660 le16_to_cpu(ev->latency),
5661 le16_to_cpu(ev->supervision_timeout));
5444
5445 if (use_ll_privacy(hdev) &&
5446 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
5447 hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION))
5448 hci_req_disable_address_resolution(hdev);
5449}
5450
5662}
5663
5451static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb)
5664static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, void *data,
5665 struct sk_buff *skb)
5452{
5666{
5453 struct hci_evt_le_ext_adv_set_term *ev = (void *) skb->data;
5667 struct hci_evt_le_ext_adv_set_term *ev = data;
5454 struct hci_conn *conn;
5668 struct hci_conn *conn;
5455 struct adv_info *adv;
5669 struct adv_info *adv, *n;
5456
5670
5457 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
5671 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
5458
5459 adv = hci_find_adv_instance(hdev, ev->handle);
5460
5672
5673 adv = hci_find_adv_instance(hdev, ev->handle);
5674
5675 /* The Bluetooth Core 5.3 specification clearly states that this event
5676 * shall not be sent when the Host disables the advertising set. So in
5677 * case of HCI_ERROR_CANCELLED_BY_HOST, just ignore the event.
5678 *
5679 * When the Host disables an advertising set, all cleanup is done via
5680 * its command callback and not needed to be duplicated here.
5681 */
5682 if (ev->status == HCI_ERROR_CANCELLED_BY_HOST) {
5683 bt_dev_warn_ratelimited(hdev, "Unexpected advertising set terminated event");
5684 return;
5685 }
5686
5461 if (ev->status) {
5462 if (!adv)
5463 return;
5464
5465 /* Remove advertising as it has been terminated */
5466 hci_remove_adv_instance(hdev, ev->handle);
5467 mgmt_advertising_removed(NULL, hdev, ev->handle);
5468
5687 if (ev->status) {
5688 if (!adv)
5689 return;
5690
5691 /* Remove advertising as it has been terminated */
5692 hci_remove_adv_instance(hdev, ev->handle);
5693 mgmt_advertising_removed(NULL, hdev, ev->handle);
5694
5695 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) {
5696 if (adv->enabled)
5697 return;
5698 }
5699
5700 /* We are no longer advertising, clear HCI_LE_ADV */
5701 hci_dev_clear_flag(hdev, HCI_LE_ADV);
5469 return;
5470 }
5471
5472 if (adv)
5473 adv->enabled = false;
5474
5475 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle));
5476 if (conn) {

--- 11 unchanged lines hidden (view full) ---

5488 return;
5489 }
5490
5491 if (adv)
5492 bacpy(&conn->resp_addr, &adv->random_addr);
5493 }
5494}
5495
5702 return;
5703 }
5704
5705 if (adv)
5706 adv->enabled = false;
5707
5708 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->conn_handle));
5709 if (conn) {

--- 11 unchanged lines hidden (view full) ---

5721 return;
5722 }
5723
5724 if (adv)
5725 bacpy(&conn->resp_addr, &adv->random_addr);
5726 }
5727}
5728
5496static void hci_le_conn_update_complete_evt(struct hci_dev *hdev,
5729static void hci_le_conn_update_complete_evt(struct hci_dev *hdev, void *data,
5497 struct sk_buff *skb)
5498{
5730 struct sk_buff *skb)
5731{
5499 struct hci_ev_le_conn_update_complete *ev = (void *) skb->data;
5732 struct hci_ev_le_conn_update_complete *ev = data;
5500 struct hci_conn *conn;
5501
5733 struct hci_conn *conn;
5734
5502 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
5735 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
5503
5504 if (ev->status)
5505 return;
5506
5507 hci_dev_lock(hdev);
5508
5509 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
5510 if (conn) {

--- 4 unchanged lines hidden (view full) ---

5515
5516 hci_dev_unlock(hdev);
5517}
5518
5519/* This function requires the caller holds hdev->lock */
5520static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
5521 bdaddr_t *addr,
5522 u8 addr_type, bool addr_resolved,
5736
5737 if (ev->status)
5738 return;
5739
5740 hci_dev_lock(hdev);
5741
5742 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
5743 if (conn) {

--- 4 unchanged lines hidden (view full) ---

5748
5749 hci_dev_unlock(hdev);
5750}
5751
5752/* This function requires the caller holds hdev->lock */
5753static struct hci_conn *check_pending_le_conn(struct hci_dev *hdev,
5754 bdaddr_t *addr,
5755 u8 addr_type, bool addr_resolved,
5523 u8 adv_type, bdaddr_t *direct_rpa)
5756 u8 adv_type)
5524{
5525 struct hci_conn *conn;
5526 struct hci_conn_params *params;
5527
5528 /* If the event is not connectable don't proceed further */
5529 if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND)
5530 return NULL;
5531
5757{
5758 struct hci_conn *conn;
5759 struct hci_conn_params *params;
5760
5761 /* If the event is not connectable don't proceed further */
5762 if (adv_type != LE_ADV_IND && adv_type != LE_ADV_DIRECT_IND)
5763 return NULL;
5764
5532 /* Ignore if the device is blocked */
5533 if (hci_bdaddr_list_lookup(&hdev->reject_list, addr, addr_type))
5765 /* Ignore if the device is blocked or hdev is suspended */
5766 if (hci_bdaddr_list_lookup(&hdev->reject_list, addr, addr_type) ||
5767 hdev->suspended)
5534 return NULL;
5535
5536 /* Most controller will fail if we try to create new connections
5537 * while we have an existing one in peripheral role.
5538 */
5539 if (hdev->conn_hash.le_num_peripheral > 0 &&
5540 (!test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) ||
5541 !(hdev->le_states[3] & 0x10)))

--- 27 unchanged lines hidden (view full) ---

5569 break;
5570 default:
5571 return NULL;
5572 }
5573 }
5574
5575 conn = hci_connect_le(hdev, addr, addr_type, addr_resolved,
5576 BT_SECURITY_LOW, hdev->def_le_autoconnect_timeout,
5768 return NULL;
5769
5770 /* Most controller will fail if we try to create new connections
5771 * while we have an existing one in peripheral role.
5772 */
5773 if (hdev->conn_hash.le_num_peripheral > 0 &&
5774 (!test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) ||
5775 !(hdev->le_states[3] & 0x10)))

--- 27 unchanged lines hidden (view full) ---

5803 break;
5804 default:
5805 return NULL;
5806 }
5807 }
5808
5809 conn = hci_connect_le(hdev, addr, addr_type, addr_resolved,
5810 BT_SECURITY_LOW, hdev->def_le_autoconnect_timeout,
5577 HCI_ROLE_MASTER, direct_rpa);
5811 HCI_ROLE_MASTER);
5578 if (!IS_ERR(conn)) {
5579 /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned
5580 * by higher layer that tried to connect, if no then
5581 * store the pointer since we don't really have any
5582 * other owner of the object besides the params that
5583 * triggered it. This way we can abort the connection if
5584 * the parameters get removed and keep the reference
5585 * count consistent once the connection is established.

--- 106 unchanged lines hidden (view full) ---

5692 bdaddr_type = ev_bdaddr_type(hdev, bdaddr_type, &bdaddr_resolved);
5693
5694 /* Check if we have been requested to connect to this device.
5695 *
5696 * direct_addr is set only for directed advertising reports (it is NULL
5697 * for advertising reports) and is already verified to be RPA above.
5698 */
5699 conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, bdaddr_resolved,
5812 if (!IS_ERR(conn)) {
5813 /* If HCI_AUTO_CONN_EXPLICIT is set, conn is already owned
5814 * by higher layer that tried to connect, if no then
5815 * store the pointer since we don't really have any
5816 * other owner of the object besides the params that
5817 * triggered it. This way we can abort the connection if
5818 * the parameters get removed and keep the reference
5819 * count consistent once the connection is established.

--- 106 unchanged lines hidden (view full) ---

5926 bdaddr_type = ev_bdaddr_type(hdev, bdaddr_type, &bdaddr_resolved);
5927
5928 /* Check if we have been requested to connect to this device.
5929 *
5930 * direct_addr is set only for directed advertising reports (it is NULL
5931 * for advertising reports) and is already verified to be RPA above.
5932 */
5933 conn = check_pending_le_conn(hdev, bdaddr, bdaddr_type, bdaddr_resolved,
5700 type, direct_addr);
5934 type);
5701 if (!ext_adv && conn && type == LE_ADV_IND && len <= HCI_MAX_AD_LENGTH) {
5702 /* Store report for later inclusion by
5703 * mgmt_device_connected
5704 */
5705 memcpy(conn->le_adv_data, data, len);
5706 conn->le_adv_data_len = len;
5707 }
5708

--- 100 unchanged lines hidden (view full) ---

5809 * sending a merged device found event.
5810 */
5811 mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK,
5812 d->last_adv_addr_type, NULL, rssi, d->last_adv_flags,
5813 d->last_adv_data, d->last_adv_data_len, data, len);
5814 clear_pending_adv_report(hdev);
5815}
5816
5935 if (!ext_adv && conn && type == LE_ADV_IND && len <= HCI_MAX_AD_LENGTH) {
5936 /* Store report for later inclusion by
5937 * mgmt_device_connected
5938 */
5939 memcpy(conn->le_adv_data, data, len);
5940 conn->le_adv_data_len = len;
5941 }
5942

--- 100 unchanged lines hidden (view full) ---

6043 * sending a merged device found event.
6044 */
6045 mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK,
6046 d->last_adv_addr_type, NULL, rssi, d->last_adv_flags,
6047 d->last_adv_data, d->last_adv_data_len, data, len);
6048 clear_pending_adv_report(hdev);
6049}
6050
5817static void hci_le_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
6051static void hci_le_adv_report_evt(struct hci_dev *hdev, void *data,
6052 struct sk_buff *skb)
5818{
6053{
5819 u8 num_reports = skb->data[0];
5820 void *ptr = &skb->data[1];
6054 struct hci_ev_le_advertising_report *ev = data;
5821
6055
6056 if (!ev->num)
6057 return;
6058
5822 hci_dev_lock(hdev);
5823
6059 hci_dev_lock(hdev);
6060
5824 while (num_reports--) {
5825 struct hci_ev_le_advertising_info *ev = ptr;
6061 while (ev->num--) {
6062 struct hci_ev_le_advertising_info *info;
5826 s8 rssi;
5827
6063 s8 rssi;
6064
5828 if (ev->length <= HCI_MAX_AD_LENGTH) {
5829 rssi = ev->data[ev->length];
5830 process_adv_report(hdev, ev->evt_type, &ev->bdaddr,
5831 ev->bdaddr_type, NULL, 0, rssi,
5832 ev->data, ev->length, false);
6065 info = hci_le_ev_skb_pull(hdev, skb,
6066 HCI_EV_LE_ADVERTISING_REPORT,
6067 sizeof(*info));
6068 if (!info)
6069 break;
6070
6071 if (!hci_le_ev_skb_pull(hdev, skb, HCI_EV_LE_ADVERTISING_REPORT,
6072 info->length + 1))
6073 break;
6074
6075 if (info->length <= HCI_MAX_AD_LENGTH) {
6076 rssi = info->data[info->length];
6077 process_adv_report(hdev, info->type, &info->bdaddr,
6078 info->bdaddr_type, NULL, 0, rssi,
6079 info->data, info->length, false);
5833 } else {
5834 bt_dev_err(hdev, "Dropping invalid advertising data");
5835 }
6080 } else {
6081 bt_dev_err(hdev, "Dropping invalid advertising data");
6082 }
5836
5837 ptr += sizeof(*ev) + ev->length + 1;
5838 }
5839
5840 hci_dev_unlock(hdev);
5841}
5842
5843static u8 ext_evt_type_to_legacy(struct hci_dev *hdev, u16 evt_type)
5844{
5845 if (evt_type & LE_EXT_ADV_LEGACY_PDU) {

--- 33 unchanged lines hidden (view full) ---

5879
5880invalid:
5881 bt_dev_err_ratelimited(hdev, "Unknown advertising packet type: 0x%02x",
5882 evt_type);
5883
5884 return LE_ADV_INVALID;
5885}
5886
6083 }
6084
6085 hci_dev_unlock(hdev);
6086}
6087
6088static u8 ext_evt_type_to_legacy(struct hci_dev *hdev, u16 evt_type)
6089{
6090 if (evt_type & LE_EXT_ADV_LEGACY_PDU) {

--- 33 unchanged lines hidden (view full) ---

6124
6125invalid:
6126 bt_dev_err_ratelimited(hdev, "Unknown advertising packet type: 0x%02x",
6127 evt_type);
6128
6129 return LE_ADV_INVALID;
6130}
6131
5887static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, struct sk_buff *skb)
6132static void hci_le_ext_adv_report_evt(struct hci_dev *hdev, void *data,
6133 struct sk_buff *skb)
5888{
6134{
5889 u8 num_reports = skb->data[0];
5890 void *ptr = &skb->data[1];
6135 struct hci_ev_le_ext_adv_report *ev = data;
5891
6136
6137 if (!ev->num)
6138 return;
6139
5892 hci_dev_lock(hdev);
5893
6140 hci_dev_lock(hdev);
6141
5894 while (num_reports--) {
5895 struct hci_ev_le_ext_adv_report *ev = ptr;
6142 while (ev->num--) {
6143 struct hci_ev_le_ext_adv_info *info;
5896 u8 legacy_evt_type;
5897 u16 evt_type;
5898
6144 u8 legacy_evt_type;
6145 u16 evt_type;
6146
5899 evt_type = __le16_to_cpu(ev->evt_type);
6147 info = hci_le_ev_skb_pull(hdev, skb, HCI_EV_LE_EXT_ADV_REPORT,
6148 sizeof(*info));
6149 if (!info)
6150 break;
6151
6152 if (!hci_le_ev_skb_pull(hdev, skb, HCI_EV_LE_EXT_ADV_REPORT,
6153 info->length))
6154 break;
6155
6156 evt_type = __le16_to_cpu(info->type);
5900 legacy_evt_type = ext_evt_type_to_legacy(hdev, evt_type);
5901 if (legacy_evt_type != LE_ADV_INVALID) {
6157 legacy_evt_type = ext_evt_type_to_legacy(hdev, evt_type);
6158 if (legacy_evt_type != LE_ADV_INVALID) {
5902 process_adv_report(hdev, legacy_evt_type, &ev->bdaddr,
5903 ev->bdaddr_type, NULL, 0, ev->rssi,
5904 ev->data, ev->length,
6159 process_adv_report(hdev, legacy_evt_type, &info->bdaddr,
6160 info->bdaddr_type, NULL, 0,
6161 info->rssi, info->data, info->length,
5905 !(evt_type & LE_EXT_ADV_LEGACY_PDU));
5906 }
6162 !(evt_type & LE_EXT_ADV_LEGACY_PDU));
6163 }
5907
5908 ptr += sizeof(*ev) + ev->length;
5909 }
5910
5911 hci_dev_unlock(hdev);
5912}
5913
6164 }
6165
6166 hci_dev_unlock(hdev);
6167}
6168
5914static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev,
6169static void hci_le_remote_feat_complete_evt(struct hci_dev *hdev, void *data,
5915 struct sk_buff *skb)
5916{
6170 struct sk_buff *skb)
6171{
5917 struct hci_ev_le_remote_feat_complete *ev = (void *)skb->data;
6172 struct hci_ev_le_remote_feat_complete *ev = data;
5918 struct hci_conn *conn;
5919
6173 struct hci_conn *conn;
6174
5920 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
6175 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
5921
5922 hci_dev_lock(hdev);
5923
5924 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
5925 if (conn) {
5926 if (!ev->status)
5927 memcpy(conn->features[0], ev->features, 8);
5928

--- 19 unchanged lines hidden (view full) ---

5948 hci_connect_cfm(conn, status);
5949 hci_conn_drop(conn);
5950 }
5951 }
5952
5953 hci_dev_unlock(hdev);
5954}
5955
6176
6177 hci_dev_lock(hdev);
6178
6179 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
6180 if (conn) {
6181 if (!ev->status)
6182 memcpy(conn->features[0], ev->features, 8);
6183

--- 19 unchanged lines hidden (view full) ---

6203 hci_connect_cfm(conn, status);
6204 hci_conn_drop(conn);
6205 }
6206 }
6207
6208 hci_dev_unlock(hdev);
6209}
6210
5956static void hci_le_ltk_request_evt(struct hci_dev *hdev, struct sk_buff *skb)
6211static void hci_le_ltk_request_evt(struct hci_dev *hdev, void *data,
6212 struct sk_buff *skb)
5957{
6213{
5958 struct hci_ev_le_ltk_req *ev = (void *) skb->data;
6214 struct hci_ev_le_ltk_req *ev = data;
5959 struct hci_cp_le_ltk_reply cp;
5960 struct hci_cp_le_ltk_neg_reply neg;
5961 struct hci_conn *conn;
5962 struct smp_ltk *ltk;
5963
6215 struct hci_cp_le_ltk_reply cp;
6216 struct hci_cp_le_ltk_neg_reply neg;
6217 struct hci_conn *conn;
6218 struct smp_ltk *ltk;
6219
5964 BT_DBG("%s handle 0x%4.4x", hdev->name, __le16_to_cpu(ev->handle));
6220 bt_dev_dbg(hdev, "handle 0x%4.4x", __le16_to_cpu(ev->handle));
5965
5966 hci_dev_lock(hdev);
5967
5968 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
5969 if (conn == NULL)
5970 goto not_found;
5971
5972 ltk = hci_find_ltk(hdev, &conn->dst, conn->dst_type, conn->role);

--- 51 unchanged lines hidden (view full) ---

6024
6025 cp.handle = cpu_to_le16(handle);
6026 cp.reason = reason;
6027
6028 hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY, sizeof(cp),
6029 &cp);
6030}
6031
6221
6222 hci_dev_lock(hdev);
6223
6224 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
6225 if (conn == NULL)
6226 goto not_found;
6227
6228 ltk = hci_find_ltk(hdev, &conn->dst, conn->dst_type, conn->role);

--- 51 unchanged lines hidden (view full) ---

6280
6281 cp.handle = cpu_to_le16(handle);
6282 cp.reason = reason;
6283
6284 hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_NEG_REPLY, sizeof(cp),
6285 &cp);
6286}
6287
6032static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev,
6288static void hci_le_remote_conn_param_req_evt(struct hci_dev *hdev, void *data,
6033 struct sk_buff *skb)
6034{
6289 struct sk_buff *skb)
6290{
6035 struct hci_ev_le_remote_conn_param_req *ev = (void *) skb->data;
6291 struct hci_ev_le_remote_conn_param_req *ev = data;
6036 struct hci_cp_le_conn_param_req_reply cp;
6037 struct hci_conn *hcon;
6038 u16 handle, min, max, latency, timeout;
6039
6292 struct hci_cp_le_conn_param_req_reply cp;
6293 struct hci_conn *hcon;
6294 u16 handle, min, max, latency, timeout;
6295
6296 bt_dev_dbg(hdev, "handle 0x%4.4x", __le16_to_cpu(ev->handle));
6297
6040 handle = le16_to_cpu(ev->handle);
6041 min = le16_to_cpu(ev->interval_min);
6042 max = le16_to_cpu(ev->interval_max);
6043 latency = le16_to_cpu(ev->latency);
6044 timeout = le16_to_cpu(ev->timeout);
6045
6046 hcon = hci_conn_hash_lookup_handle(hdev, handle);
6047 if (!hcon || hcon->state != BT_CONNECTED)

--- 34 unchanged lines hidden (view full) ---

6082 cp.latency = ev->latency;
6083 cp.timeout = ev->timeout;
6084 cp.min_ce_len = 0;
6085 cp.max_ce_len = 0;
6086
6087 hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp);
6088}
6089
6298 handle = le16_to_cpu(ev->handle);
6299 min = le16_to_cpu(ev->interval_min);
6300 max = le16_to_cpu(ev->interval_max);
6301 latency = le16_to_cpu(ev->latency);
6302 timeout = le16_to_cpu(ev->timeout);
6303
6304 hcon = hci_conn_hash_lookup_handle(hdev, handle);
6305 if (!hcon || hcon->state != BT_CONNECTED)

--- 34 unchanged lines hidden (view full) ---

6340 cp.latency = ev->latency;
6341 cp.timeout = ev->timeout;
6342 cp.min_ce_len = 0;
6343 cp.max_ce_len = 0;
6344
6345 hci_send_cmd(hdev, HCI_OP_LE_CONN_PARAM_REQ_REPLY, sizeof(cp), &cp);
6346}
6347
6090static void hci_le_direct_adv_report_evt(struct hci_dev *hdev,
6348static void hci_le_direct_adv_report_evt(struct hci_dev *hdev, void *data,
6091 struct sk_buff *skb)
6092{
6349 struct sk_buff *skb)
6350{
6093 u8 num_reports = skb->data[0];
6094 struct hci_ev_le_direct_adv_info *ev = (void *)&skb->data[1];
6351 struct hci_ev_le_direct_adv_report *ev = data;
6352 int i;
6095
6353
6096 if (!num_reports || skb->len < num_reports * sizeof(*ev) + 1)
6354 if (!hci_le_ev_skb_pull(hdev, skb, HCI_EV_LE_DIRECT_ADV_REPORT,
6355 flex_array_size(ev, info, ev->num)))
6097 return;
6098
6356 return;
6357
6358 if (!ev->num)
6359 return;
6360
6099 hci_dev_lock(hdev);
6100
6361 hci_dev_lock(hdev);
6362
6101 for (; num_reports; num_reports--, ev++)
6102 process_adv_report(hdev, ev->evt_type, &ev->bdaddr,
6103 ev->bdaddr_type, &ev->direct_addr,
6104 ev->direct_addr_type, ev->rssi, NULL, 0,
6363 for (i = 0; i < ev->num; i++) {
6364 struct hci_ev_le_direct_adv_info *info = &ev->info[i];
6365
6366 process_adv_report(hdev, info->type, &info->bdaddr,
6367 info->bdaddr_type, &info->direct_addr,
6368 info->direct_addr_type, info->rssi, NULL, 0,
6105 false);
6369 false);
6370 }
6106
6107 hci_dev_unlock(hdev);
6108}
6109
6371
6372 hci_dev_unlock(hdev);
6373}
6374
6110static void hci_le_phy_update_evt(struct hci_dev *hdev, struct sk_buff *skb)
6375static void hci_le_phy_update_evt(struct hci_dev *hdev, void *data,
6376 struct sk_buff *skb)
6111{
6377{
6112 struct hci_ev_le_phy_update_complete *ev = (void *) skb->data;
6378 struct hci_ev_le_phy_update_complete *ev = data;
6113 struct hci_conn *conn;
6114
6379 struct hci_conn *conn;
6380
6115 BT_DBG("%s status 0x%2.2x", hdev->name, ev->status);
6381 bt_dev_dbg(hdev, "status 0x%2.2x", ev->status);
6116
6117 if (ev->status)
6118 return;
6119
6120 hci_dev_lock(hdev);
6121
6122 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
6123 if (!conn)
6124 goto unlock;
6125
6126 conn->le_tx_phy = ev->tx_phy;
6127 conn->le_rx_phy = ev->rx_phy;
6128
6129unlock:
6130 hci_dev_unlock(hdev);
6131}
6132
6382
6383 if (ev->status)
6384 return;
6385
6386 hci_dev_lock(hdev);
6387
6388 conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(ev->handle));
6389 if (!conn)
6390 goto unlock;
6391
6392 conn->le_tx_phy = ev->tx_phy;
6393 conn->le_rx_phy = ev->rx_phy;
6394
6395unlock:
6396 hci_dev_unlock(hdev);
6397}
6398
6133static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
6134{
6135 struct hci_ev_le_meta *le_ev = (void *) skb->data;
6399#define HCI_LE_EV_VL(_op, _func, _min_len, _max_len) \
6400[_op] = { \
6401 .func = _func, \
6402 .min_len = _min_len, \
6403 .max_len = _max_len, \
6404}
6136
6405
6137 skb_pull(skb, sizeof(*le_ev));
6406#define HCI_LE_EV(_op, _func, _len) \
6407 HCI_LE_EV_VL(_op, _func, _len, _len)
6138
6408
6139 switch (le_ev->subevent) {
6140 case HCI_EV_LE_CONN_COMPLETE:
6141 hci_le_conn_complete_evt(hdev, skb);
6142 break;
6409#define HCI_LE_EV_STATUS(_op, _func) \
6410 HCI_LE_EV(_op, _func, sizeof(struct hci_ev_status))
6143
6411
6144 case HCI_EV_LE_CONN_UPDATE_COMPLETE:
6145 hci_le_conn_update_complete_evt(hdev, skb);
6146 break;
6412/* Entries in this table shall have their position according to the subevent
6413 * opcode they handle so the use of the macros above is recommend since it does
6414 * attempt to initialize at its proper index using Designated Initializers that
6415 * way events without a callback function can be ommited.
6416 */
6417static const struct hci_le_ev {
6418 void (*func)(struct hci_dev *hdev, void *data, struct sk_buff *skb);
6419 u16 min_len;
6420 u16 max_len;
6421} hci_le_ev_table[U8_MAX + 1] = {
6422 /* [0x01 = HCI_EV_LE_CONN_COMPLETE] */
6423 HCI_LE_EV(HCI_EV_LE_CONN_COMPLETE, hci_le_conn_complete_evt,
6424 sizeof(struct hci_ev_le_conn_complete)),
6425 /* [0x02 = HCI_EV_LE_ADVERTISING_REPORT] */
6426 HCI_LE_EV_VL(HCI_EV_LE_ADVERTISING_REPORT, hci_le_adv_report_evt,
6427 sizeof(struct hci_ev_le_advertising_report),
6428 HCI_MAX_EVENT_SIZE),
6429 /* [0x03 = HCI_EV_LE_CONN_UPDATE_COMPLETE] */
6430 HCI_LE_EV(HCI_EV_LE_CONN_UPDATE_COMPLETE,
6431 hci_le_conn_update_complete_evt,
6432 sizeof(struct hci_ev_le_conn_update_complete)),
6433 /* [0x04 = HCI_EV_LE_REMOTE_FEAT_COMPLETE] */
6434 HCI_LE_EV(HCI_EV_LE_REMOTE_FEAT_COMPLETE,
6435 hci_le_remote_feat_complete_evt,
6436 sizeof(struct hci_ev_le_remote_feat_complete)),
6437 /* [0x05 = HCI_EV_LE_LTK_REQ] */
6438 HCI_LE_EV(HCI_EV_LE_LTK_REQ, hci_le_ltk_request_evt,
6439 sizeof(struct hci_ev_le_ltk_req)),
6440 /* [0x06 = HCI_EV_LE_REMOTE_CONN_PARAM_REQ] */
6441 HCI_LE_EV(HCI_EV_LE_REMOTE_CONN_PARAM_REQ,
6442 hci_le_remote_conn_param_req_evt,
6443 sizeof(struct hci_ev_le_remote_conn_param_req)),
6444 /* [0x0a = HCI_EV_LE_ENHANCED_CONN_COMPLETE] */
6445 HCI_LE_EV(HCI_EV_LE_ENHANCED_CONN_COMPLETE,
6446 hci_le_enh_conn_complete_evt,
6447 sizeof(struct hci_ev_le_enh_conn_complete)),
6448 /* [0x0b = HCI_EV_LE_DIRECT_ADV_REPORT] */
6449 HCI_LE_EV_VL(HCI_EV_LE_DIRECT_ADV_REPORT, hci_le_direct_adv_report_evt,
6450 sizeof(struct hci_ev_le_direct_adv_report),
6451 HCI_MAX_EVENT_SIZE),
6452 /* [0x0c = HCI_EV_LE_PHY_UPDATE_COMPLETE] */
6453 HCI_LE_EV(HCI_EV_LE_PHY_UPDATE_COMPLETE, hci_le_phy_update_evt,
6454 sizeof(struct hci_ev_le_phy_update_complete)),
6455 /* [0x0d = HCI_EV_LE_EXT_ADV_REPORT] */
6456 HCI_LE_EV_VL(HCI_EV_LE_EXT_ADV_REPORT, hci_le_ext_adv_report_evt,
6457 sizeof(struct hci_ev_le_ext_adv_report),
6458 HCI_MAX_EVENT_SIZE),
6459 /* [0x12 = HCI_EV_LE_EXT_ADV_SET_TERM] */
6460 HCI_LE_EV(HCI_EV_LE_EXT_ADV_SET_TERM, hci_le_ext_adv_term_evt,
6461 sizeof(struct hci_evt_le_ext_adv_set_term)),
6462};
6147
6463
6148 case HCI_EV_LE_ADVERTISING_REPORT:
6149 hci_le_adv_report_evt(hdev, skb);
6150 break;
6464static void hci_le_meta_evt(struct hci_dev *hdev, void *data,
6465 struct sk_buff *skb, u16 *opcode, u8 *status,
6466 hci_req_complete_t *req_complete,
6467 hci_req_complete_skb_t *req_complete_skb)
6468{
6469 struct hci_ev_le_meta *ev = data;
6470 const struct hci_le_ev *subev;
6151
6471
6152 case HCI_EV_LE_REMOTE_FEAT_COMPLETE:
6153 hci_le_remote_feat_complete_evt(hdev, skb);
6154 break;
6472 bt_dev_dbg(hdev, "subevent 0x%2.2x", ev->subevent);
6155
6473
6156 case HCI_EV_LE_LTK_REQ:
6157 hci_le_ltk_request_evt(hdev, skb);
6158 break;
6474 /* Only match event if command OGF is for LE */
6475 if (hdev->sent_cmd &&
6476 hci_opcode_ogf(hci_skb_opcode(hdev->sent_cmd)) == 0x08 &&
6477 hci_skb_event(hdev->sent_cmd) == ev->subevent) {
6478 *opcode = hci_skb_opcode(hdev->sent_cmd);
6479 hci_req_cmd_complete(hdev, *opcode, 0x00, req_complete,
6480 req_complete_skb);
6481 }
6159
6482
6160 case HCI_EV_LE_REMOTE_CONN_PARAM_REQ:
6161 hci_le_remote_conn_param_req_evt(hdev, skb);
6162 break;
6483 subev = &hci_le_ev_table[ev->subevent];
6484 if (!subev->func)
6485 return;
6163
6486
6164 case HCI_EV_LE_DIRECT_ADV_REPORT:
6165 hci_le_direct_adv_report_evt(hdev, skb);
6166 break;
6487 if (skb->len < subev->min_len) {
6488 bt_dev_err(hdev, "unexpected subevent 0x%2.2x length: %u < %u",
6489 ev->subevent, skb->len, subev->min_len);
6490 return;
6491 }
6167
6492
6168 case HCI_EV_LE_PHY_UPDATE_COMPLETE:
6169 hci_le_phy_update_evt(hdev, skb);
6170 break;
6493 /* Just warn if the length is over max_len size it still be
6494 * possible to partially parse the event so leave to callback to
6495 * decide if that is acceptable.
6496 */
6497 if (skb->len > subev->max_len)
6498 bt_dev_warn(hdev, "unexpected subevent 0x%2.2x length: %u > %u",
6499 ev->subevent, skb->len, subev->max_len);
6171
6500
6172 case HCI_EV_LE_EXT_ADV_REPORT:
6173 hci_le_ext_adv_report_evt(hdev, skb);
6174 break;
6501 data = hci_le_ev_skb_pull(hdev, skb, ev->subevent, subev->min_len);
6502 if (!data)
6503 return;
6175
6504
6176 case HCI_EV_LE_ENHANCED_CONN_COMPLETE:
6177 hci_le_enh_conn_complete_evt(hdev, skb);
6178 break;
6179
6180 case HCI_EV_LE_EXT_ADV_SET_TERM:
6181 hci_le_ext_adv_term_evt(hdev, skb);
6182 break;
6183
6184 default:
6185 break;
6186 }
6505 subev->func(hdev, data, skb);
6187}
6188
6189static bool hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode,
6190 u8 event, struct sk_buff *skb)
6191{
6192 struct hci_ev_cmd_complete *ev;
6193 struct hci_event_hdr *hdr;
6194
6195 if (!skb)
6196 return false;
6197
6506}
6507
6508static bool hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode,
6509 u8 event, struct sk_buff *skb)
6510{
6511 struct hci_ev_cmd_complete *ev;
6512 struct hci_event_hdr *hdr;
6513
6514 if (!skb)
6515 return false;
6516
6198 if (skb->len < sizeof(*hdr)) {
6199 bt_dev_err(hdev, "too short HCI event");
6517 hdr = hci_ev_skb_pull(hdev, skb, event, sizeof(*hdr));
6518 if (!hdr)
6200 return false;
6519 return false;
6201 }
6202
6520
6203 hdr = (void *) skb->data;
6204 skb_pull(skb, HCI_EVENT_HDR_SIZE);
6205
6206 if (event) {
6207 if (hdr->evt != event)
6208 return false;
6209 return true;
6210 }
6211
6212 /* Check if request ended in Command Status - no way to retrieve
6213 * any extra parameters in this case.
6214 */
6215 if (hdr->evt == HCI_EV_CMD_STATUS)
6216 return false;
6217
6218 if (hdr->evt != HCI_EV_CMD_COMPLETE) {
6219 bt_dev_err(hdev, "last event is not cmd complete (0x%2.2x)",
6220 hdr->evt);
6221 return false;
6222 }
6223
6521 if (event) {
6522 if (hdr->evt != event)
6523 return false;
6524 return true;
6525 }
6526
6527 /* Check if request ended in Command Status - no way to retrieve
6528 * any extra parameters in this case.
6529 */
6530 if (hdr->evt == HCI_EV_CMD_STATUS)
6531 return false;
6532
6533 if (hdr->evt != HCI_EV_CMD_COMPLETE) {
6534 bt_dev_err(hdev, "last event is not cmd complete (0x%2.2x)",
6535 hdr->evt);
6536 return false;
6537 }
6538
6224 if (skb->len < sizeof(*ev)) {
6225 bt_dev_err(hdev, "too short cmd_complete event");
6539 ev = hci_cc_skb_pull(hdev, skb, opcode, sizeof(*ev));
6540 if (!ev)
6226 return false;
6541 return false;
6227 }
6228
6542
6229 ev = (void *) skb->data;
6230 skb_pull(skb, sizeof(*ev));
6231
6232 if (opcode != __le16_to_cpu(ev->opcode)) {
6233 BT_DBG("opcode doesn't match (0x%2.2x != 0x%2.2x)", opcode,
6234 __le16_to_cpu(ev->opcode));
6235 return false;
6236 }
6237
6238 return true;
6239}
6240
6241static void hci_store_wake_reason(struct hci_dev *hdev, u8 event,
6242 struct sk_buff *skb)
6243{
6244 struct hci_ev_le_advertising_info *adv;
6245 struct hci_ev_le_direct_adv_info *direct_adv;
6543 if (opcode != __le16_to_cpu(ev->opcode)) {
6544 BT_DBG("opcode doesn't match (0x%2.2x != 0x%2.2x)", opcode,
6545 __le16_to_cpu(ev->opcode));
6546 return false;
6547 }
6548
6549 return true;
6550}
6551
6552static void hci_store_wake_reason(struct hci_dev *hdev, u8 event,
6553 struct sk_buff *skb)
6554{
6555 struct hci_ev_le_advertising_info *adv;
6556 struct hci_ev_le_direct_adv_info *direct_adv;
6246 struct hci_ev_le_ext_adv_report *ext_adv;
6557 struct hci_ev_le_ext_adv_info *ext_adv;
6247 const struct hci_ev_conn_complete *conn_complete = (void *)skb->data;
6248 const struct hci_ev_conn_request *conn_request = (void *)skb->data;
6249
6250 hci_dev_lock(hdev);
6251
6252 /* If we are currently suspended and this is the first BT event seen,
6253 * save the wake reason associated with the event.
6254 */

--- 47 unchanged lines hidden (view full) ---

6302 } else {
6303 hdev->wake_reason = MGMT_WAKE_REASON_UNEXPECTED;
6304 }
6305
6306unlock:
6307 hci_dev_unlock(hdev);
6308}
6309
6558 const struct hci_ev_conn_complete *conn_complete = (void *)skb->data;
6559 const struct hci_ev_conn_request *conn_request = (void *)skb->data;
6560
6561 hci_dev_lock(hdev);
6562
6563 /* If we are currently suspended and this is the first BT event seen,
6564 * save the wake reason associated with the event.
6565 */

--- 47 unchanged lines hidden (view full) ---

6613 } else {
6614 hdev->wake_reason = MGMT_WAKE_REASON_UNEXPECTED;
6615 }
6616
6617unlock:
6618 hci_dev_unlock(hdev);
6619}
6620
6621#define HCI_EV_VL(_op, _func, _min_len, _max_len) \
6622[_op] = { \
6623 .req = false, \
6624 .func = _func, \
6625 .min_len = _min_len, \
6626 .max_len = _max_len, \
6627}
6628
6629#define HCI_EV(_op, _func, _len) \
6630 HCI_EV_VL(_op, _func, _len, _len)
6631
6632#define HCI_EV_STATUS(_op, _func) \
6633 HCI_EV(_op, _func, sizeof(struct hci_ev_status))
6634
6635#define HCI_EV_REQ_VL(_op, _func, _min_len, _max_len) \
6636[_op] = { \
6637 .req = true, \
6638 .func_req = _func, \
6639 .min_len = _min_len, \
6640 .max_len = _max_len, \
6641}
6642
6643#define HCI_EV_REQ(_op, _func, _len) \
6644 HCI_EV_REQ_VL(_op, _func, _len, _len)
6645
6646/* Entries in this table shall have their position according to the event opcode
6647 * they handle so the use of the macros above is recommend since it does attempt
6648 * to initialize at its proper index using Designated Initializers that way
6649 * events without a callback function don't have entered.
6650 */
6651static const struct hci_ev {
6652 bool req;
6653 union {
6654 void (*func)(struct hci_dev *hdev, void *data,
6655 struct sk_buff *skb);
6656 void (*func_req)(struct hci_dev *hdev, void *data,
6657 struct sk_buff *skb, u16 *opcode, u8 *status,
6658 hci_req_complete_t *req_complete,
6659 hci_req_complete_skb_t *req_complete_skb);
6660 };
6661 u16 min_len;
6662 u16 max_len;
6663} hci_ev_table[U8_MAX + 1] = {
6664 /* [0x01 = HCI_EV_INQUIRY_COMPLETE] */
6665 HCI_EV_STATUS(HCI_EV_INQUIRY_COMPLETE, hci_inquiry_complete_evt),
6666 /* [0x02 = HCI_EV_INQUIRY_RESULT] */
6667 HCI_EV_VL(HCI_EV_INQUIRY_RESULT, hci_inquiry_result_evt,
6668 sizeof(struct hci_ev_inquiry_result), HCI_MAX_EVENT_SIZE),
6669 /* [0x03 = HCI_EV_CONN_COMPLETE] */
6670 HCI_EV(HCI_EV_CONN_COMPLETE, hci_conn_complete_evt,
6671 sizeof(struct hci_ev_conn_complete)),
6672 /* [0x04 = HCI_EV_CONN_REQUEST] */
6673 HCI_EV(HCI_EV_CONN_REQUEST, hci_conn_request_evt,
6674 sizeof(struct hci_ev_conn_request)),
6675 /* [0x05 = HCI_EV_DISCONN_COMPLETE] */
6676 HCI_EV(HCI_EV_DISCONN_COMPLETE, hci_disconn_complete_evt,
6677 sizeof(struct hci_ev_disconn_complete)),
6678 /* [0x06 = HCI_EV_AUTH_COMPLETE] */
6679 HCI_EV(HCI_EV_AUTH_COMPLETE, hci_auth_complete_evt,
6680 sizeof(struct hci_ev_auth_complete)),
6681 /* [0x07 = HCI_EV_REMOTE_NAME] */
6682 HCI_EV(HCI_EV_REMOTE_NAME, hci_remote_name_evt,
6683 sizeof(struct hci_ev_remote_name)),
6684 /* [0x08 = HCI_EV_ENCRYPT_CHANGE] */
6685 HCI_EV(HCI_EV_ENCRYPT_CHANGE, hci_encrypt_change_evt,
6686 sizeof(struct hci_ev_encrypt_change)),
6687 /* [0x09 = HCI_EV_CHANGE_LINK_KEY_COMPLETE] */
6688 HCI_EV(HCI_EV_CHANGE_LINK_KEY_COMPLETE,
6689 hci_change_link_key_complete_evt,
6690 sizeof(struct hci_ev_change_link_key_complete)),
6691 /* [0x0b = HCI_EV_REMOTE_FEATURES] */
6692 HCI_EV(HCI_EV_REMOTE_FEATURES, hci_remote_features_evt,
6693 sizeof(struct hci_ev_remote_features)),
6694 /* [0x0e = HCI_EV_CMD_COMPLETE] */
6695 HCI_EV_REQ_VL(HCI_EV_CMD_COMPLETE, hci_cmd_complete_evt,
6696 sizeof(struct hci_ev_cmd_complete), HCI_MAX_EVENT_SIZE),
6697 /* [0x0f = HCI_EV_CMD_STATUS] */
6698 HCI_EV_REQ(HCI_EV_CMD_STATUS, hci_cmd_status_evt,
6699 sizeof(struct hci_ev_cmd_status)),
6700 /* [0x10 = HCI_EV_CMD_STATUS] */
6701 HCI_EV(HCI_EV_HARDWARE_ERROR, hci_hardware_error_evt,
6702 sizeof(struct hci_ev_hardware_error)),
6703 /* [0x12 = HCI_EV_ROLE_CHANGE] */
6704 HCI_EV(HCI_EV_ROLE_CHANGE, hci_role_change_evt,
6705 sizeof(struct hci_ev_role_change)),
6706 /* [0x13 = HCI_EV_NUM_COMP_PKTS] */
6707 HCI_EV_VL(HCI_EV_NUM_COMP_PKTS, hci_num_comp_pkts_evt,
6708 sizeof(struct hci_ev_num_comp_pkts), HCI_MAX_EVENT_SIZE),
6709 /* [0x14 = HCI_EV_MODE_CHANGE] */
6710 HCI_EV(HCI_EV_MODE_CHANGE, hci_mode_change_evt,
6711 sizeof(struct hci_ev_mode_change)),
6712 /* [0x16 = HCI_EV_PIN_CODE_REQ] */
6713 HCI_EV(HCI_EV_PIN_CODE_REQ, hci_pin_code_request_evt,
6714 sizeof(struct hci_ev_pin_code_req)),
6715 /* [0x17 = HCI_EV_LINK_KEY_REQ] */
6716 HCI_EV(HCI_EV_LINK_KEY_REQ, hci_link_key_request_evt,
6717 sizeof(struct hci_ev_link_key_req)),
6718 /* [0x18 = HCI_EV_LINK_KEY_NOTIFY] */
6719 HCI_EV(HCI_EV_LINK_KEY_NOTIFY, hci_link_key_notify_evt,
6720 sizeof(struct hci_ev_link_key_notify)),
6721 /* [0x1c = HCI_EV_CLOCK_OFFSET] */
6722 HCI_EV(HCI_EV_CLOCK_OFFSET, hci_clock_offset_evt,
6723 sizeof(struct hci_ev_clock_offset)),
6724 /* [0x1d = HCI_EV_PKT_TYPE_CHANGE] */
6725 HCI_EV(HCI_EV_PKT_TYPE_CHANGE, hci_pkt_type_change_evt,
6726 sizeof(struct hci_ev_pkt_type_change)),
6727 /* [0x20 = HCI_EV_PSCAN_REP_MODE] */
6728 HCI_EV(HCI_EV_PSCAN_REP_MODE, hci_pscan_rep_mode_evt,
6729 sizeof(struct hci_ev_pscan_rep_mode)),
6730 /* [0x22 = HCI_EV_INQUIRY_RESULT_WITH_RSSI] */
6731 HCI_EV_VL(HCI_EV_INQUIRY_RESULT_WITH_RSSI,
6732 hci_inquiry_result_with_rssi_evt,
6733 sizeof(struct hci_ev_inquiry_result_rssi),
6734 HCI_MAX_EVENT_SIZE),
6735 /* [0x23 = HCI_EV_REMOTE_EXT_FEATURES] */
6736 HCI_EV(HCI_EV_REMOTE_EXT_FEATURES, hci_remote_ext_features_evt,
6737 sizeof(struct hci_ev_remote_ext_features)),
6738 /* [0x2c = HCI_EV_SYNC_CONN_COMPLETE] */
6739 HCI_EV(HCI_EV_SYNC_CONN_COMPLETE, hci_sync_conn_complete_evt,
6740 sizeof(struct hci_ev_sync_conn_complete)),
6741 /* [0x2d = HCI_EV_EXTENDED_INQUIRY_RESULT] */
6742 HCI_EV_VL(HCI_EV_EXTENDED_INQUIRY_RESULT,
6743 hci_extended_inquiry_result_evt,
6744 sizeof(struct hci_ev_ext_inquiry_result), HCI_MAX_EVENT_SIZE),
6745 /* [0x30 = HCI_EV_KEY_REFRESH_COMPLETE] */
6746 HCI_EV(HCI_EV_KEY_REFRESH_COMPLETE, hci_key_refresh_complete_evt,
6747 sizeof(struct hci_ev_key_refresh_complete)),
6748 /* [0x31 = HCI_EV_IO_CAPA_REQUEST] */
6749 HCI_EV(HCI_EV_IO_CAPA_REQUEST, hci_io_capa_request_evt,
6750 sizeof(struct hci_ev_io_capa_request)),
6751 /* [0x32 = HCI_EV_IO_CAPA_REPLY] */
6752 HCI_EV(HCI_EV_IO_CAPA_REPLY, hci_io_capa_reply_evt,
6753 sizeof(struct hci_ev_io_capa_reply)),
6754 /* [0x33 = HCI_EV_USER_CONFIRM_REQUEST] */
6755 HCI_EV(HCI_EV_USER_CONFIRM_REQUEST, hci_user_confirm_request_evt,
6756 sizeof(struct hci_ev_user_confirm_req)),
6757 /* [0x34 = HCI_EV_USER_PASSKEY_REQUEST] */
6758 HCI_EV(HCI_EV_USER_PASSKEY_REQUEST, hci_user_passkey_request_evt,
6759 sizeof(struct hci_ev_user_passkey_req)),
6760 /* [0x35 = HCI_EV_REMOTE_OOB_DATA_REQUEST] */
6761 HCI_EV(HCI_EV_REMOTE_OOB_DATA_REQUEST, hci_remote_oob_data_request_evt,
6762 sizeof(struct hci_ev_remote_oob_data_request)),
6763 /* [0x36 = HCI_EV_SIMPLE_PAIR_COMPLETE] */
6764 HCI_EV(HCI_EV_SIMPLE_PAIR_COMPLETE, hci_simple_pair_complete_evt,
6765 sizeof(struct hci_ev_simple_pair_complete)),
6766 /* [0x3b = HCI_EV_USER_PASSKEY_NOTIFY] */
6767 HCI_EV(HCI_EV_USER_PASSKEY_NOTIFY, hci_user_passkey_notify_evt,
6768 sizeof(struct hci_ev_user_passkey_notify)),
6769 /* [0x3c = HCI_EV_KEYPRESS_NOTIFY] */
6770 HCI_EV(HCI_EV_KEYPRESS_NOTIFY, hci_keypress_notify_evt,
6771 sizeof(struct hci_ev_keypress_notify)),
6772 /* [0x3d = HCI_EV_REMOTE_HOST_FEATURES] */
6773 HCI_EV(HCI_EV_REMOTE_HOST_FEATURES, hci_remote_host_features_evt,
6774 sizeof(struct hci_ev_remote_host_features)),
6775 /* [0x3e = HCI_EV_LE_META] */
6776 HCI_EV_REQ_VL(HCI_EV_LE_META, hci_le_meta_evt,
6777 sizeof(struct hci_ev_le_meta), HCI_MAX_EVENT_SIZE),
6778#if IS_ENABLED(CONFIG_BT_HS)
6779 /* [0x40 = HCI_EV_PHY_LINK_COMPLETE] */
6780 HCI_EV(HCI_EV_PHY_LINK_COMPLETE, hci_phy_link_complete_evt,
6781 sizeof(struct hci_ev_phy_link_complete)),
6782 /* [0x41 = HCI_EV_CHANNEL_SELECTED] */
6783 HCI_EV(HCI_EV_CHANNEL_SELECTED, hci_chan_selected_evt,
6784 sizeof(struct hci_ev_channel_selected)),
6785 /* [0x42 = HCI_EV_DISCONN_PHY_LINK_COMPLETE] */
6786 HCI_EV(HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE,
6787 hci_disconn_loglink_complete_evt,
6788 sizeof(struct hci_ev_disconn_logical_link_complete)),
6789 /* [0x45 = HCI_EV_LOGICAL_LINK_COMPLETE] */
6790 HCI_EV(HCI_EV_LOGICAL_LINK_COMPLETE, hci_loglink_complete_evt,
6791 sizeof(struct hci_ev_logical_link_complete)),
6792 /* [0x46 = HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE] */
6793 HCI_EV(HCI_EV_DISCONN_PHY_LINK_COMPLETE,
6794 hci_disconn_phylink_complete_evt,
6795 sizeof(struct hci_ev_disconn_phy_link_complete)),
6796#endif
6797 /* [0x48 = HCI_EV_NUM_COMP_BLOCKS] */
6798 HCI_EV(HCI_EV_NUM_COMP_BLOCKS, hci_num_comp_blocks_evt,
6799 sizeof(struct hci_ev_num_comp_blocks)),
6800 /* [0xff = HCI_EV_VENDOR] */
6801 HCI_EV(HCI_EV_VENDOR, msft_vendor_evt, 0),
6802};
6803
6804static void hci_event_func(struct hci_dev *hdev, u8 event, struct sk_buff *skb,
6805 u16 *opcode, u8 *status,
6806 hci_req_complete_t *req_complete,
6807 hci_req_complete_skb_t *req_complete_skb)
6808{
6809 const struct hci_ev *ev = &hci_ev_table[event];
6810 void *data;
6811
6812 if (!ev->func)
6813 return;
6814
6815 if (skb->len < ev->min_len) {
6816 bt_dev_err(hdev, "unexpected event 0x%2.2x length: %u < %u",
6817 event, skb->len, ev->min_len);
6818 return;
6819 }
6820
6821 /* Just warn if the length is over max_len size it still be
6822 * possible to partially parse the event so leave to callback to
6823 * decide if that is acceptable.
6824 */
6825 if (skb->len > ev->max_len)
6826 bt_dev_warn(hdev, "unexpected event 0x%2.2x length: %u > %u",
6827 event, skb->len, ev->max_len);
6828
6829 data = hci_ev_skb_pull(hdev, skb, event, ev->min_len);
6830 if (!data)
6831 return;
6832
6833 if (ev->req)
6834 ev->func_req(hdev, data, skb, opcode, status, req_complete,
6835 req_complete_skb);
6836 else
6837 ev->func(hdev, data, skb);
6838}
6839
6310void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
6311{
6312 struct hci_event_hdr *hdr = (void *) skb->data;
6313 hci_req_complete_t req_complete = NULL;
6314 hci_req_complete_skb_t req_complete_skb = NULL;
6315 struct sk_buff *orig_skb = NULL;
6840void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb)
6841{
6842 struct hci_event_hdr *hdr = (void *) skb->data;
6843 hci_req_complete_t req_complete = NULL;
6844 hci_req_complete_skb_t req_complete_skb = NULL;
6845 struct sk_buff *orig_skb = NULL;
6316 u8 status = 0, event = hdr->evt, req_evt = 0;
6846 u8 status = 0, event, req_evt = 0;
6317 u16 opcode = HCI_OP_NOP;
6318
6847 u16 opcode = HCI_OP_NOP;
6848
6849 if (skb->len < sizeof(*hdr)) {
6850 bt_dev_err(hdev, "Malformed HCI Event");
6851 goto done;
6852 }
6853
6854 event = hdr->evt;
6319 if (!event) {
6855 if (!event) {
6320 bt_dev_warn(hdev, "Received unexpected HCI Event 00000000");
6856 bt_dev_warn(hdev, "Received unexpected HCI Event 0x%2.2x",
6857 event);
6321 goto done;
6322 }
6323
6858 goto done;
6859 }
6860
6324 if (hdev->sent_cmd && bt_cb(hdev->sent_cmd)->hci.req_event == event) {
6325 struct hci_command_hdr *cmd_hdr = (void *) hdev->sent_cmd->data;
6326 opcode = __le16_to_cpu(cmd_hdr->opcode);
6327 hci_req_cmd_complete(hdev, opcode, status, &req_complete,
6328 &req_complete_skb);
6861 /* Only match event if command OGF is not for LE */
6862 if (hdev->sent_cmd &&
6863 hci_opcode_ogf(hci_skb_opcode(hdev->sent_cmd)) != 0x08 &&
6864 hci_skb_event(hdev->sent_cmd) == event) {
6865 hci_req_cmd_complete(hdev, hci_skb_opcode(hdev->sent_cmd),
6866 status, &req_complete, &req_complete_skb);
6329 req_evt = event;
6330 }
6331
6332 /* If it looks like we might end up having to call
6333 * req_complete_skb, store a pristine copy of the skb since the
6334 * various handlers may modify the original one through
6335 * skb_pull() calls, etc.
6336 */
6337 if (req_complete_skb || event == HCI_EV_CMD_STATUS ||
6338 event == HCI_EV_CMD_COMPLETE)
6339 orig_skb = skb_clone(skb, GFP_KERNEL);
6340
6341 skb_pull(skb, HCI_EVENT_HDR_SIZE);
6342
6343 /* Store wake reason if we're suspended */
6344 hci_store_wake_reason(hdev, event, skb);
6345
6867 req_evt = event;
6868 }
6869
6870 /* If it looks like we might end up having to call
6871 * req_complete_skb, store a pristine copy of the skb since the
6872 * various handlers may modify the original one through
6873 * skb_pull() calls, etc.
6874 */
6875 if (req_complete_skb || event == HCI_EV_CMD_STATUS ||
6876 event == HCI_EV_CMD_COMPLETE)
6877 orig_skb = skb_clone(skb, GFP_KERNEL);
6878
6879 skb_pull(skb, HCI_EVENT_HDR_SIZE);
6880
6881 /* Store wake reason if we're suspended */
6882 hci_store_wake_reason(hdev, event, skb);
6883
6346 switch (event) {
6347 case HCI_EV_INQUIRY_COMPLETE:
6348 hci_inquiry_complete_evt(hdev, skb);
6349 break;
6884 bt_dev_dbg(hdev, "event 0x%2.2x", event);
6350
6885
6351 case HCI_EV_INQUIRY_RESULT:
6352 hci_inquiry_result_evt(hdev, skb);
6353 break;
6886 hci_event_func(hdev, event, skb, &opcode, &status, &req_complete,
6887 &req_complete_skb);
6354
6888
6355 case HCI_EV_CONN_COMPLETE:
6356 hci_conn_complete_evt(hdev, skb);
6357 break;
6358
6359 case HCI_EV_CONN_REQUEST:
6360 hci_conn_request_evt(hdev, skb);
6361 break;
6362
6363 case HCI_EV_DISCONN_COMPLETE:
6364 hci_disconn_complete_evt(hdev, skb);
6365 break;
6366
6367 case HCI_EV_AUTH_COMPLETE:
6368 hci_auth_complete_evt(hdev, skb);
6369 break;
6370
6371 case HCI_EV_REMOTE_NAME:
6372 hci_remote_name_evt(hdev, skb);
6373 break;
6374
6375 case HCI_EV_ENCRYPT_CHANGE:
6376 hci_encrypt_change_evt(hdev, skb);
6377 break;
6378
6379 case HCI_EV_CHANGE_LINK_KEY_COMPLETE:
6380 hci_change_link_key_complete_evt(hdev, skb);
6381 break;
6382
6383 case HCI_EV_REMOTE_FEATURES:
6384 hci_remote_features_evt(hdev, skb);
6385 break;
6386
6387 case HCI_EV_CMD_COMPLETE:
6388 hci_cmd_complete_evt(hdev, skb, &opcode, &status,
6389 &req_complete, &req_complete_skb);
6390 break;
6391
6392 case HCI_EV_CMD_STATUS:
6393 hci_cmd_status_evt(hdev, skb, &opcode, &status, &req_complete,
6394 &req_complete_skb);
6395 break;
6396
6397 case HCI_EV_HARDWARE_ERROR:
6398 hci_hardware_error_evt(hdev, skb);
6399 break;
6400
6401 case HCI_EV_ROLE_CHANGE:
6402 hci_role_change_evt(hdev, skb);
6403 break;
6404
6405 case HCI_EV_NUM_COMP_PKTS:
6406 hci_num_comp_pkts_evt(hdev, skb);
6407 break;
6408
6409 case HCI_EV_MODE_CHANGE:
6410 hci_mode_change_evt(hdev, skb);
6411 break;
6412
6413 case HCI_EV_PIN_CODE_REQ:
6414 hci_pin_code_request_evt(hdev, skb);
6415 break;
6416
6417 case HCI_EV_LINK_KEY_REQ:
6418 hci_link_key_request_evt(hdev, skb);
6419 break;
6420
6421 case HCI_EV_LINK_KEY_NOTIFY:
6422 hci_link_key_notify_evt(hdev, skb);
6423 break;
6424
6425 case HCI_EV_CLOCK_OFFSET:
6426 hci_clock_offset_evt(hdev, skb);
6427 break;
6428
6429 case HCI_EV_PKT_TYPE_CHANGE:
6430 hci_pkt_type_change_evt(hdev, skb);
6431 break;
6432
6433 case HCI_EV_PSCAN_REP_MODE:
6434 hci_pscan_rep_mode_evt(hdev, skb);
6435 break;
6436
6437 case HCI_EV_INQUIRY_RESULT_WITH_RSSI:
6438 hci_inquiry_result_with_rssi_evt(hdev, skb);
6439 break;
6440
6441 case HCI_EV_REMOTE_EXT_FEATURES:
6442 hci_remote_ext_features_evt(hdev, skb);
6443 break;
6444
6445 case HCI_EV_SYNC_CONN_COMPLETE:
6446 hci_sync_conn_complete_evt(hdev, skb);
6447 break;
6448
6449 case HCI_EV_EXTENDED_INQUIRY_RESULT:
6450 hci_extended_inquiry_result_evt(hdev, skb);
6451 break;
6452
6453 case HCI_EV_KEY_REFRESH_COMPLETE:
6454 hci_key_refresh_complete_evt(hdev, skb);
6455 break;
6456
6457 case HCI_EV_IO_CAPA_REQUEST:
6458 hci_io_capa_request_evt(hdev, skb);
6459 break;
6460
6461 case HCI_EV_IO_CAPA_REPLY:
6462 hci_io_capa_reply_evt(hdev, skb);
6463 break;
6464
6465 case HCI_EV_USER_CONFIRM_REQUEST:
6466 hci_user_confirm_request_evt(hdev, skb);
6467 break;
6468
6469 case HCI_EV_USER_PASSKEY_REQUEST:
6470 hci_user_passkey_request_evt(hdev, skb);
6471 break;
6472
6473 case HCI_EV_USER_PASSKEY_NOTIFY:
6474 hci_user_passkey_notify_evt(hdev, skb);
6475 break;
6476
6477 case HCI_EV_KEYPRESS_NOTIFY:
6478 hci_keypress_notify_evt(hdev, skb);
6479 break;
6480
6481 case HCI_EV_SIMPLE_PAIR_COMPLETE:
6482 hci_simple_pair_complete_evt(hdev, skb);
6483 break;
6484
6485 case HCI_EV_REMOTE_HOST_FEATURES:
6486 hci_remote_host_features_evt(hdev, skb);
6487 break;
6488
6489 case HCI_EV_LE_META:
6490 hci_le_meta_evt(hdev, skb);
6491 break;
6492
6493 case HCI_EV_REMOTE_OOB_DATA_REQUEST:
6494 hci_remote_oob_data_request_evt(hdev, skb);
6495 break;
6496
6497#if IS_ENABLED(CONFIG_BT_HS)
6498 case HCI_EV_CHANNEL_SELECTED:
6499 hci_chan_selected_evt(hdev, skb);
6500 break;
6501
6502 case HCI_EV_PHY_LINK_COMPLETE:
6503 hci_phy_link_complete_evt(hdev, skb);
6504 break;
6505
6506 case HCI_EV_LOGICAL_LINK_COMPLETE:
6507 hci_loglink_complete_evt(hdev, skb);
6508 break;
6509
6510 case HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE:
6511 hci_disconn_loglink_complete_evt(hdev, skb);
6512 break;
6513
6514 case HCI_EV_DISCONN_PHY_LINK_COMPLETE:
6515 hci_disconn_phylink_complete_evt(hdev, skb);
6516 break;
6517#endif
6518
6519 case HCI_EV_NUM_COMP_BLOCKS:
6520 hci_num_comp_blocks_evt(hdev, skb);
6521 break;
6522
6523 case HCI_EV_VENDOR:
6524 msft_vendor_evt(hdev, skb);
6525 break;
6526
6527 default:
6528 BT_DBG("%s event 0x%2.2x", hdev->name, event);
6529 break;
6530 }
6531
6532 if (req_complete) {
6533 req_complete(hdev, status, opcode);
6534 } else if (req_complete_skb) {
6535 if (!hci_get_cmd_complete(hdev, opcode, req_evt, orig_skb)) {
6536 kfree_skb(orig_skb);
6537 orig_skb = NULL;
6538 }
6539 req_complete_skb(hdev, status, opcode, orig_skb);
6540 }
6541
6542done:
6543 kfree_skb(orig_skb);
6544 kfree_skb(skb);
6545 hdev->stat.evt_rx++;
6546}
6889 if (req_complete) {
6890 req_complete(hdev, status, opcode);
6891 } else if (req_complete_skb) {
6892 if (!hci_get_cmd_complete(hdev, opcode, req_evt, orig_skb)) {
6893 kfree_skb(orig_skb);
6894 orig_skb = NULL;
6895 }
6896 req_complete_skb(hdev, status, opcode, orig_skb);
6897 }
6898
6899done:
6900 kfree_skb(orig_skb);
6901 kfree_skb(skb);
6902 hdev->stat.evt_rx++;
6903}