1 /******************************************************************************
2 *
3 * Copyright (C) 1999-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 /******************************************************************************
20 *
21 * This file contains functions that interface with the HCI transport. On
22 * the receive side, it routes events to the appropriate handler, e.g.
23 * L2CAP, ScoMgr. On the transmit side, it manages the command
24 * transmission.
25 *
26 ******************************************************************************/
27
28 //#define LOG_TAG "bt_btu_hcif"
29
30 //#include <stdlib.h>
31 #include <string.h>
32
33 #include "stack/bt_types.h"
34 #include "stack/hcimsgs.h"
35 #include "stack/btu.h"
36 #include "l2c_int.h"
37 #include "stack/btm_api.h"
38 #include "btm_int.h"
39 //#include "bt_utils.h"
40 #include "device/controller.h"
41 #include "osi/osi.h"
42 #include "hci/hci_layer.h"
43 #include "common/bt_trace.h"
44
45 #include "osi/thread.h"
46 //#include "osi/mutex.h"
47 // TODO(zachoverflow): remove this horrible hack
48 #include "stack/btu.h"
49
50 extern void btm_process_cancel_complete(UINT8 status, UINT8 mode);
51 extern void btm_ble_test_command_complete(UINT8 *p);
52
53 /********************************************************************************/
54 /* L O C A L F U N C T I O N P R O T O T Y P E S */
55 /********************************************************************************/
56 static void btu_hcif_inquiry_comp_evt (UINT8 *p);
57 static void btu_hcif_inquiry_result_evt (UINT8 *p);
58 static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p);
59 static void btu_hcif_extended_inquiry_result_evt (UINT8 *p);
60
61 static void btu_hcif_connection_comp_evt (UINT8 *p);
62 static void btu_hcif_connection_request_evt (UINT8 *p);
63 static void btu_hcif_disconnection_comp_evt (UINT8 *p);
64 #if (SMP_INCLUDED == 1)
65 static void btu_hcif_authentication_comp_evt (UINT8 *p);
66 #endif ///SMP_INCLUDED == 1
67 static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len);
68 #if (SMP_INCLUDED == 1)
69 static void btu_hcif_encryption_change_evt (UINT8 *p);
70 #endif ///SMP_INCLUDED == 1
71 static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p);
72 static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p);
73 static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p);
74 static void btu_hcif_qos_setup_comp_evt (UINT8 *p);
75 static void btu_hcif_command_complete_evt (BT_HDR *response, void *context);
76 static void btu_hcif_command_status_evt (uint8_t status, BT_HDR *command, void *context);
77 static void btu_hcif_hardware_error_evt (UINT8 *p);
78 static void btu_hcif_flush_occured_evt (void);
79 static void btu_hcif_role_change_evt (UINT8 *p);
80 static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p);
81 static void btu_hcif_mode_change_evt (UINT8 *p);
82 #if (SMP_INCLUDED == 1)
83 static void btu_hcif_pin_code_request_evt (UINT8 *p);
84 static void btu_hcif_link_key_request_evt (UINT8 *p);
85 static void btu_hcif_link_key_notification_evt (UINT8 *p);
86 #endif ///SMP_INCLUDED == 1
87 static void btu_hcif_loopback_command_evt (void);
88 static void btu_hcif_data_buf_overflow_evt (void);
89 static void btu_hcif_max_slots_changed_evt (void);
90 static void btu_hcif_read_clock_off_comp_evt (UINT8 *p);
91 static void btu_hcif_conn_pkt_type_change_evt (void);
92 static void btu_hcif_qos_violation_evt (UINT8 *p);
93 static void btu_hcif_page_scan_mode_change_evt (void);
94 static void btu_hcif_page_scan_rep_mode_chng_evt (void);
95 static void btu_hcif_esco_connection_comp_evt(UINT8 *p);
96 static void btu_hcif_esco_connection_chg_evt(UINT8 *p);
97
98 /* Simple Pairing Events */
99 static void btu_hcif_host_support_evt (UINT8 *p);
100 #if (SMP_INCLUDED == 1)
101 static void btu_hcif_io_cap_request_evt (UINT8 *p);
102 static void btu_hcif_io_cap_response_evt (UINT8 *p);
103 static void btu_hcif_user_conf_request_evt (UINT8 *p);
104 static void btu_hcif_user_passkey_request_evt (UINT8 *p);
105 static void btu_hcif_user_passkey_notif_evt (UINT8 *p);
106 static void btu_hcif_keypress_notif_evt (UINT8 *p);
107 #endif ///SMP_INCLUDED == 1
108 #if BTM_OOB_INCLUDED == 1 && SMP_INCLUDED == 1
109 static void btu_hcif_rem_oob_request_evt (UINT8 *p);
110 #endif
111 #if (SMP_INCLUDED == 1)
112 static void btu_hcif_simple_pair_complete_evt (UINT8 *p);
113 #endif ///SMP_INCLUDED == 1
114 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == 1
115 static void btu_hcif_enhanced_flush_complete_evt (void);
116 #endif
117
118 #if (BTM_SSR_INCLUDED == 1)
119 static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len);
120 #endif /* BTM_SSR_INCLUDED == 1 */
121
122 #if BLE_INCLUDED == 1
123 static void btu_ble_ll_conn_complete_evt (UINT8 *p, UINT16 evt_len);
124 static void btu_ble_process_adv_pkt (UINT8 *p);
125 static void btu_ble_process_adv_dis(UINT8 *p);
126 static void btu_ble_read_remote_feat_evt (UINT8 *p);
127 static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len);
128 static void btu_ble_ll_get_conn_param_format_err_from_contoller (UINT8 status, UINT16 handle);
129 #if (SMP_INCLUDED == 1)
130 static void btu_ble_proc_ltk_req (UINT8 *p);
131 static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p);
132 #endif ///SMP_INCLUDED == 1
133 static void btu_ble_data_length_change_evt (UINT8 *p, UINT16 evt_len);
134 #if (BLE_LLT_INCLUDED == 1)
135 static void btu_ble_rc_param_req_evt(UINT8 *p);
136 #endif
137 //#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == 1)
138 static void btu_ble_proc_enhanced_conn_cmpl (UINT8 *p, UINT16 evt_len);
139 //#endif
140 #if (BLE_50_FEATURE_SUPPORT == 1)
141 static void btu_ble_phy_update_complete_evt(UINT8 *p);
142 static void btu_ble_ext_adv_report_evt(UINT8 *p, UINT16 evt_len);
143 static void btu_ble_periodic_adv_sync_establish_evt(UINT8 *p);
144 static void btu_ble_periodic_adv_report_evt(UINT8 *p, UINT8 evt_len);
145 static void btu_ble_periodic_adv_sync_lost_evt(UINT8 *p);
146 static void btu_ble_scan_timeout_evt(UINT8 *p);
147 static void btu_ble_adv_set_terminate_evt(UINT8 *p);
148 static void btu_ble_scan_req_received_evt(UINT8 *p);
149
150 #endif // #if (BLE_50_FEATURE_SUPPORT == 1)
151
152 extern osi_sem_t adv_enable_sem;
153 extern osi_sem_t adv_data_sem;
154 extern osi_sem_t adv_param_sem;
155 extern osi_sem_t scan_enable_sem;
156 extern osi_sem_t scan_param_sem;
157 extern uint8_t adv_enable_status;
158 extern uint8_t adv_data_status;
159 extern uint8_t adv_param_status;
160 extern uint8_t scan_enable_status;
161 extern uint8_t scan_param_status;
162
163 #endif
164
165 /*******************************************************************************
166 **
167 ** Function btu_hcif_process_event
168 **
169 ** Description This function is called when an event is received from
170 ** the Host Controller.
171 **
172 ** Returns void
173 **
174 *******************************************************************************/
btu_hcif_process_event(UNUSED_ATTR UINT8 controller_id,BT_HDR * p_msg)175 void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg)
176 {
177 UINT8 *p = (UINT8 *)(p_msg + 1) + p_msg->offset;
178 UINT8 hci_evt_code, hci_evt_len;
179 #if BLE_INCLUDED == 1
180 UINT8 ble_sub_code;
181 #endif
182 STREAM_TO_UINT8 (hci_evt_code, p);
183 STREAM_TO_UINT8 (hci_evt_len, p);
184
185 switch (hci_evt_code) {
186 case HCI_INQUIRY_COMP_EVT:
187 btu_hcif_inquiry_comp_evt (p);
188 break;
189 case HCI_INQUIRY_RESULT_EVT:
190 btu_hcif_inquiry_result_evt (p);
191 break;
192 case HCI_INQUIRY_RSSI_RESULT_EVT:
193 btu_hcif_inquiry_rssi_result_evt (p);
194 break;
195 case HCI_EXTENDED_INQUIRY_RESULT_EVT:
196 btu_hcif_extended_inquiry_result_evt (p);
197 break;
198 case HCI_CONNECTION_COMP_EVT:
199 btu_hcif_connection_comp_evt (p);
200 break;
201 case HCI_CONNECTION_REQUEST_EVT:
202 btu_hcif_connection_request_evt (p);
203 break;
204 case HCI_DISCONNECTION_COMP_EVT:
205 btu_hcif_disconnection_comp_evt (p);
206 break;
207 case HCI_AUTHENTICATION_COMP_EVT:
208 #if (SMP_INCLUDED == 1)
209 btu_hcif_authentication_comp_evt (p);
210 #endif ///SMP_INCLUDED == 1
211 break;
212 case HCI_RMT_NAME_REQUEST_COMP_EVT:
213 btu_hcif_rmt_name_request_comp_evt (p, hci_evt_len);
214 break;
215 case HCI_ENCRYPTION_CHANGE_EVT:
216 #if (SMP_INCLUDED == 1)
217 btu_hcif_encryption_change_evt (p);
218 #endif ///SMP_INCLUDED == 1
219 break;
220 #if BLE_INCLUDED == 1
221 case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT:
222 #if (SMP_INCLUDED == 1)
223 btu_hcif_encryption_key_refresh_cmpl_evt(p);
224 #endif ///SMP_INCLUDED == 1
225 break;
226 #endif
227 case HCI_READ_RMT_FEATURES_COMP_EVT:
228 btu_hcif_read_rmt_features_comp_evt (p);
229 break;
230 case HCI_READ_RMT_EXT_FEATURES_COMP_EVT:
231 btu_hcif_read_rmt_ext_features_comp_evt (p);
232 break;
233 case HCI_READ_RMT_VERSION_COMP_EVT:
234 btu_hcif_read_rmt_version_comp_evt (p);
235 break;
236 case HCI_QOS_SETUP_COMP_EVT:
237 btu_hcif_qos_setup_comp_evt (p);
238 break;
239 case HCI_COMMAND_COMPLETE_EVT:
240 //HCI_TRACE_ERROR("%s should not have received a command complete event. "
241 // "Someone didn't go through the hci transmit_command function.", __func__);
242 break;
243 case HCI_COMMAND_STATUS_EVT:
244 //HCI_TRACE_ERROR("%s should not have received a command status event. "
245 // "Someone didn't go through the hci transmit_command function.", __func__);
246 break;
247 case HCI_HARDWARE_ERROR_EVT:
248 btu_hcif_hardware_error_evt (p);
249 break;
250 case HCI_FLUSH_OCCURED_EVT:
251 btu_hcif_flush_occured_evt ();
252 break;
253 case HCI_ROLE_CHANGE_EVT:
254 btu_hcif_role_change_evt (p);
255 break;
256 case HCI_NUM_COMPL_DATA_PKTS_EVT:
257 btu_hcif_num_compl_data_pkts_evt (p);
258 break;
259 case HCI_MODE_CHANGE_EVT:
260 btu_hcif_mode_change_evt (p);
261 break;
262 #if (SMP_INCLUDED == 1)
263 case HCI_PIN_CODE_REQUEST_EVT:
264 btu_hcif_pin_code_request_evt (p);
265 break;
266 case HCI_LINK_KEY_REQUEST_EVT:
267 btu_hcif_link_key_request_evt (p);
268 break;
269 case HCI_LINK_KEY_NOTIFICATION_EVT:
270 btu_hcif_link_key_notification_evt (p);
271 break;
272 #endif ///SMP_INCLUDED == 1
273 case HCI_LOOPBACK_COMMAND_EVT:
274 btu_hcif_loopback_command_evt ();
275 break;
276 case HCI_DATA_BUF_OVERFLOW_EVT:
277 btu_hcif_data_buf_overflow_evt ();
278 break;
279 case HCI_MAX_SLOTS_CHANGED_EVT:
280 btu_hcif_max_slots_changed_evt ();
281 break;
282 case HCI_READ_CLOCK_OFF_COMP_EVT:
283 btu_hcif_read_clock_off_comp_evt (p);
284 break;
285 case HCI_CONN_PKT_TYPE_CHANGE_EVT:
286 btu_hcif_conn_pkt_type_change_evt ();
287 break;
288 case HCI_QOS_VIOLATION_EVT:
289 btu_hcif_qos_violation_evt (p);
290 break;
291 case HCI_PAGE_SCAN_MODE_CHANGE_EVT:
292 btu_hcif_page_scan_mode_change_evt ();
293 break;
294 case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT:
295 btu_hcif_page_scan_rep_mode_chng_evt ();
296 break;
297 case HCI_ESCO_CONNECTION_COMP_EVT:
298 btu_hcif_esco_connection_comp_evt (p);
299 break;
300 case HCI_ESCO_CONNECTION_CHANGED_EVT:
301 btu_hcif_esco_connection_chg_evt (p);
302 break;
303 #if (BTM_SSR_INCLUDED == 1)
304 case HCI_SNIFF_SUB_RATE_EVT:
305 btu_hcif_ssr_evt (p, hci_evt_len);
306 break;
307 #endif /* BTM_SSR_INCLUDED == 1 */
308 case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT:
309 btu_hcif_host_support_evt (p);
310 break;
311 #if (SMP_INCLUDED == 1)
312 case HCI_IO_CAPABILITY_REQUEST_EVT:
313 btu_hcif_io_cap_request_evt (p);
314 break;
315 case HCI_IO_CAPABILITY_RESPONSE_EVT:
316 btu_hcif_io_cap_response_evt (p);
317 break;
318 case HCI_USER_CONFIRMATION_REQUEST_EVT:
319 btu_hcif_user_conf_request_evt (p);
320 break;
321 case HCI_USER_PASSKEY_REQUEST_EVT:
322 btu_hcif_user_passkey_request_evt (p);
323 break;
324 #endif ///SMP_INCLUDED == 1
325 #if BTM_OOB_INCLUDED == 1 && SMP_INCLUDED == 1
326 case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
327 btu_hcif_rem_oob_request_evt (p);
328 break;
329 #endif
330 #if (SMP_INCLUDED == 1)
331 case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
332 btu_hcif_simple_pair_complete_evt (p);
333 break;
334 case HCI_USER_PASSKEY_NOTIFY_EVT:
335 btu_hcif_user_passkey_notif_evt (p);
336 break;
337 case HCI_KEYPRESS_NOTIFY_EVT:
338 btu_hcif_keypress_notif_evt (p);
339 break;
340 #endif ///SMP_INCLUDED == 1
341 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == 1
342 case HCI_ENHANCED_FLUSH_COMPLETE_EVT:
343 btu_hcif_enhanced_flush_complete_evt ();
344 break;
345 #endif
346
347 #if (BLE_INCLUDED == 1)
348 case HCI_BLE_EVENT:
349 STREAM_TO_UINT8 (ble_sub_code, p);
350
351 HCI_TRACE_DEBUG("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code, ble_sub_code);
352
353 switch (ble_sub_code) {
354 case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */
355 btu_ble_process_adv_pkt(p);
356 break;
357 case HCI_BLE_ADV_DISCARD_REPORT_EVT:
358 btu_ble_process_adv_dis(p);
359 break;
360 case HCI_BLE_CONN_COMPLETE_EVT:
361 btu_ble_ll_conn_complete_evt(p, hci_evt_len);
362 break;
363 case HCI_BLE_LL_CONN_PARAM_UPD_EVT:
364 btu_ble_ll_conn_param_upd_evt(p, hci_evt_len);
365 break;
366 case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT:
367 btu_ble_read_remote_feat_evt(p);
368 break;
369 case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */
370 #if (SMP_INCLUDED == 1)
371 btu_ble_proc_ltk_req(p);
372 #endif ///SMP_INCLUDED == 1
373 break;
374 //#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == 1)
375 case HCI_BLE_ENHANCED_CONN_COMPLETE_EVT:
376 btu_ble_proc_enhanced_conn_cmpl(p, hci_evt_len);
377 break;
378 //#endif
379 #if (BLE_LLT_INCLUDED == 1)
380 case HCI_BLE_RC_PARAM_REQ_EVT:
381 btu_ble_rc_param_req_evt(p);
382 break;
383 #endif
384 case HCI_BLE_DATA_LENGTH_CHANGE_EVT:
385 btu_ble_data_length_change_evt(p, hci_evt_len);
386 break;
387 #if (BLE_50_FEATURE_SUPPORT == 1)
388 case HCI_BLE_PHY_UPDATE_COMPLETE_EVT:
389 btu_ble_phy_update_complete_evt(p);
390 break;
391 case HCI_BLE_EXT_ADV_REPORT_EVT:
392 //HCI_TRACE_ERROR("%s, HCI_BLE_EXT_ADV_REPORT_EVT.", __func__);
393 btu_ble_ext_adv_report_evt(p, hci_evt_len);
394 break;
395 case HCI_BLE_PERIOD_ADV_SYNC_ESTAB_EVT:
396 btu_ble_periodic_adv_sync_establish_evt(p);
397 break;
398 case HCI_BLE_PERIOD_ADV_REPORT_EVT:
399 btu_ble_periodic_adv_report_evt(p, hci_evt_len);
400 break;
401 case HCI_BLE_PERIOD_ADV_SYNC_LOST_EVT:
402 btu_ble_periodic_adv_sync_lost_evt(p);
403 break;
404 case HCI_BLE_SCAN_TIMEOUT_EVT:
405 btu_ble_scan_timeout_evt(p);
406 break;
407 case HCI_BLE_ADV_SET_TERMINATED_EVT:
408 btu_ble_adv_set_terminate_evt(p);
409 break;
410 case HCI_BLE_SCAN_REQ_RECEIVED_EVT:
411 btu_ble_scan_req_received_evt(p);
412 break;
413 case HCI_BLE_CHANNEL_SELECT_ALG:
414 break;
415 #endif // #if (BLE_50_FEATURE_SUPPORT == 1)
416 }
417 break;
418 #endif /* BLE_INCLUDED */
419 case HCI_VENDOR_SPECIFIC_EVT:
420 btm_vendor_specific_evt (p, hci_evt_len);
421 break;
422 }
423 }
424
425
426 /*******************************************************************************
427 **
428 ** Function btu_hcif_send_cmd
429 **
430 ** Description This function is called to send commands to the Host Controller.
431 **
432 ** Returns void
433 **
434 *******************************************************************************/
btu_hcif_send_cmd(UNUSED_ATTR UINT8 controller_id,BT_HDR * p_buf)435 void btu_hcif_send_cmd (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_buf)
436 {
437 if (!p_buf) {
438 HCI_TRACE_ERROR("%s p_buf is NULL", __func__);
439 return;
440 }
441
442 uint16_t opcode;
443 uint8_t *stream = p_buf->data + p_buf->offset;
444 void *vsc_callback = NULL;
445
446 STREAM_TO_UINT16(opcode, stream);
447
448 // Eww...horrible hackery here
449 /* If command was a VSC, then extract command_complete callback */
450 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC
451 #if BLE_INCLUDED == 1
452 || (opcode == HCI_BLE_RAND)
453 || (opcode == HCI_BLE_ENCRYPT)
454 #endif
455 ) {
456 vsc_callback = *((void **)(p_buf + 1));
457 }
458
459 hci_layer_get_interface()->transmit_command(
460 p_buf,
461 btu_hcif_command_complete_evt,
462 btu_hcif_command_status_evt,
463 vsc_callback);
464
465 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == 1)
466 btu_check_bt_sleep ();
467 #endif
468 }
469 #if (BLE_50_FEATURE_SUPPORT == 1)
btu_hcif_send_cmd_sync(UINT8 controller_id,BT_HDR * p_buf)470 UINT8 btu_hcif_send_cmd_sync (UINT8 controller_id, BT_HDR *p_buf)
471 {
472 if (!p_buf) {
473 HCI_TRACE_ERROR("%s p_buf is NULL", __func__);
474 return HCI_ERR_ILLEGAL_PARAMETER_FMT;
475 }
476 BlE_SYNC *sync_info = btsnd_hcic_ble_get_sync_info();
477 if((sync_info == NULL) || (sync_info->sync_sem == NULL)) {
478 HCI_TRACE_ERROR("%s sync_info error", __func__);
479 return HCI_ERR_ILLEGAL_PARAMETER_FMT;
480 }
481 uint16_t opcode;
482 uint8_t *stream = p_buf->data + p_buf->offset;
483 void *vsc_callback = NULL;
484
485 STREAM_TO_UINT16(opcode, stream);
486
487 sync_info->opcode = opcode;
488
489 // Eww...horrible hackery here
490 /* If command was a VSC, then extract command_complete callback */
491 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC
492 #if BLE_INCLUDED == 1
493 || (opcode == HCI_BLE_RAND)
494 || (opcode == HCI_BLE_ENCRYPT)
495 #endif
496 ) {
497 vsc_callback = *((void **)(p_buf + 1));
498 }
499
500 hci_layer_get_interface()->transmit_command(
501 p_buf,
502 btu_hcif_command_complete_evt,
503 btu_hcif_command_status_evt,
504 vsc_callback);
505
506 osi_sem_take(&sync_info->sync_sem, OSI_SEM_MAX_TIMEOUT);
507
508 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == 1)
509 btu_check_bt_sleep ();
510 #endif
511 return btsnd_hcic_ble_get_status();
512 }
513 #endif // #if (BLE_50_FEATURE_SUPPORT == 1)
514
515
516 /*******************************************************************************
517 **
518 ** Function btu_hcif_send_host_rdy_for_data
519 **
520 ** Description This function is called to check if it can send commands
521 ** to the Host Controller. It may be passed the address of
522 ** a packet to send.
523 **
524 ** Returns void
525 **
526 *******************************************************************************/
btu_hcif_send_host_rdy_for_data(void)527 void btu_hcif_send_host_rdy_for_data(void)
528 {
529 UINT16 num_pkts[MAX_L2CAP_LINKS + 4]; /* 3 SCO connections */
530 UINT16 handles[MAX_L2CAP_LINKS + 4];
531 UINT8 num_ents;
532
533 /* Get the L2CAP numbers */
534 num_ents = l2c_link_pkts_rcvd (num_pkts, handles);
535
536 /* Get the SCO numbers */
537 /* No SCO for now ?? */
538
539 if (num_ents) {
540 btsnd_hcic_host_num_xmitted_pkts (num_ents, handles, num_pkts);
541 }
542 }
543
544 /*******************************************************************************
545 **
546 ** Function btu_hcif_inquiry_comp_evt
547 **
548 ** Description Process event HCI_INQUIRY_COMP_EVT
549 **
550 ** Returns void
551 **
552 *******************************************************************************/
btu_hcif_inquiry_comp_evt(UINT8 * p)553 static void btu_hcif_inquiry_comp_evt (UINT8 *p)
554 {
555 UINT8 status;
556
557 STREAM_TO_UINT8 (status, p);
558
559 /* Tell inquiry processing that we are done */
560 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
561 }
562
563
564 /*******************************************************************************
565 **
566 ** Function btu_hcif_inquiry_result_evt
567 **
568 ** Description Process event HCI_INQUIRY_RESULT_EVT
569 **
570 ** Returns void
571 **
572 *******************************************************************************/
btu_hcif_inquiry_result_evt(UINT8 * p)573 static void btu_hcif_inquiry_result_evt (UINT8 *p)
574 {
575 /* Store results in the cache */
576 btm_process_inq_results (p, BTM_INQ_RESULT_STANDARD);
577 }
578
579 /*******************************************************************************
580 **
581 ** Function btu_hcif_inquiry_rssi_result_evt
582 **
583 ** Description Process event HCI_INQUIRY_RSSI_RESULT_EVT
584 **
585 ** Returns void
586 **
587 *******************************************************************************/
btu_hcif_inquiry_rssi_result_evt(UINT8 * p)588 static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p)
589 {
590 /* Store results in the cache */
591 btm_process_inq_results (p, BTM_INQ_RESULT_WITH_RSSI);
592 }
593
594 /*******************************************************************************
595 **
596 ** Function btu_hcif_extended_inquiry_result_evt
597 **
598 ** Description Process event HCI_EXTENDED_INQUIRY_RESULT_EVT
599 **
600 ** Returns void
601 **
602 *******************************************************************************/
btu_hcif_extended_inquiry_result_evt(UINT8 * p)603 static void btu_hcif_extended_inquiry_result_evt (UINT8 *p)
604 {
605 /* Store results in the cache */
606 btm_process_inq_results (p, BTM_INQ_RESULT_EXTENDED);
607 }
608
609 /*******************************************************************************
610 **
611 ** Function btu_hcif_connection_comp_evt
612 **
613 ** Description Process event HCI_CONNECTION_COMP_EVT
614 **
615 ** Returns void
616 **
617 *******************************************************************************/
btu_hcif_connection_comp_evt(UINT8 * p)618 static void btu_hcif_connection_comp_evt (UINT8 *p)
619 {
620 UINT8 status;
621 UINT16 handle;
622 BD_ADDR bda;
623 UINT8 link_type;
624 #if SMP_INCLUDED == 1
625 UINT8 enc_mode;
626 #endif ///SMP_INCLUDED == 1
627 #if BTM_SCO_INCLUDED == 1
628 tBTM_ESCO_DATA esco_data;
629 #endif
630
631 STREAM_TO_UINT8 (status, p);
632 STREAM_TO_UINT16 (handle, p);
633 STREAM_TO_BDADDR (bda, p);
634 STREAM_TO_UINT8 (link_type, p);
635 #if (SMP_INCLUDED == 1)
636 STREAM_TO_UINT8 (enc_mode, p);
637 #endif ///SMP_INCLUDED == 1
638 handle = HCID_GET_HANDLE (handle);
639
640 if (link_type == HCI_LINK_TYPE_ACL) {
641 #if (SMP_INCLUDED == 1)
642 btm_sec_connected (bda, handle, status, enc_mode);
643 #endif ///SMP_INCLUDED == 1
644 l2c_link_hci_conn_comp (status, handle, bda);
645 }
646 #if BTM_SCO_INCLUDED == 1
647 else {
648 memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA));
649 /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */
650 memcpy (esco_data.bd_addr, bda, BD_ADDR_LEN);
651 btm_sco_connected (status, bda, handle, &esco_data);
652 }
653 #endif /* BTM_SCO_INCLUDED */
654 }
655
656
657 /*******************************************************************************
658 **
659 ** Function btu_hcif_connection_request_evt
660 **
661 ** Description Process event HCI_CONNECTION_REQUEST_EVT
662 **
663 ** Returns void
664 **
665 *******************************************************************************/
btu_hcif_connection_request_evt(UINT8 * p)666 static void btu_hcif_connection_request_evt (UINT8 *p)
667 {
668 BD_ADDR bda;
669 DEV_CLASS dc;
670 UINT8 link_type;
671
672 STREAM_TO_BDADDR (bda, p);
673 STREAM_TO_DEVCLASS (dc, p);
674 STREAM_TO_UINT8 (link_type, p);
675 /* Pass request to security manager to check connect filters before */
676 /* passing request to l2cap */
677 if (link_type == HCI_LINK_TYPE_ACL) {
678 #if (SMP_INCLUDED == 1)
679 btm_sec_conn_req (bda, dc);
680 #endif ///SMP_INCLUDED == 1
681 }
682 #if BTM_SCO_INCLUDED == 1
683 else {
684 btm_sco_conn_req (bda, dc, link_type);
685 }
686 #endif /* BTM_SCO_INCLUDED */
687 }
688
689
690 /*******************************************************************************
691 **
692 ** Function btu_hcif_disconnection_comp_evt
693 **
694 ** Description Process event HCI_DISCONNECTION_COMP_EVT
695 **
696 ** Returns void
697 **
698 *******************************************************************************/
btu_hcif_disconnection_comp_evt(UINT8 * p)699 static void btu_hcif_disconnection_comp_evt (UINT8 *p)
700 {
701 UINT16 handle;
702 UINT8 reason;
703
704 ++p;
705 STREAM_TO_UINT16 (handle, p);
706 STREAM_TO_UINT8 (reason, p);
707
708 handle = HCID_GET_HANDLE (handle);
709
710 if (reason != HCI_ERR_PEER_USER && reason != HCI_ERR_CONN_CAUSE_LOCAL_HOST) {
711 HCI_TRACE_WARNING("DiscCmpl evt: hdl=%d, rsn=0x%x", handle, reason);
712 }
713
714 #if BTM_SCO_INCLUDED == 1
715 /* If L2CAP doesn't know about it, send it to SCO */
716 if (!l2c_link_hci_disc_comp (handle, reason)) {
717 btm_sco_removed (handle, reason);
718 }
719 #else
720 l2c_link_hci_disc_comp (handle, reason);
721 #endif /* BTM_SCO_INCLUDED */
722 #if (SMP_INCLUDED == 1)
723 /* Notify security manager */
724 btm_sec_disconnected (handle, reason);
725 #endif ///SMP_INCLUDED == 1
726 }
727
728 /*******************************************************************************
729 **
730 ** Function btu_hcif_authentication_comp_evt
731 **
732 ** Description Process event HCI_AUTHENTICATION_COMP_EVT
733 **
734 ** Returns void
735 **
736 *******************************************************************************/
737 #if (SMP_INCLUDED == 1)
btu_hcif_authentication_comp_evt(UINT8 * p)738 static void btu_hcif_authentication_comp_evt (UINT8 *p)
739 {
740 UINT8 status;
741 UINT16 handle;
742
743 STREAM_TO_UINT8 (status, p);
744 STREAM_TO_UINT16 (handle, p);
745
746 btm_sec_auth_complete (handle, status);
747 }
748 #endif ///SMP_INCLUDED == 1
749
750 /*******************************************************************************
751 **
752 ** Function btu_hcif_rmt_name_request_comp_evt
753 **
754 ** Description Process event HCI_RMT_NAME_REQUEST_COMP_EVT
755 **
756 ** Returns void
757 **
758 *******************************************************************************/
btu_hcif_rmt_name_request_comp_evt(UINT8 * p,UINT16 evt_len)759 static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len)
760 {
761 UINT8 status;
762 BD_ADDR bd_addr;
763
764 STREAM_TO_UINT8 (status, p);
765 STREAM_TO_BDADDR (bd_addr, p);
766
767 evt_len -= (1 + BD_ADDR_LEN);
768
769 btm_process_remote_name (bd_addr, p, evt_len, status);
770 #if (SMP_INCLUDED == 1)
771 btm_sec_rmt_name_request_complete (bd_addr, p, status);
772 #endif ///SMP_INCLUDED == 1
773 }
774
775
776 /*******************************************************************************
777 **
778 ** Function btu_hcif_encryption_change_evt
779 **
780 ** Description Process event HCI_ENCRYPTION_CHANGE_EVT
781 **
782 ** Returns void
783 **
784 *******************************************************************************/
785 #if (SMP_INCLUDED == 1)
btu_hcif_encryption_change_evt(UINT8 * p)786 static void btu_hcif_encryption_change_evt (UINT8 *p)
787 {
788 UINT8 status;
789 UINT16 handle;
790 UINT8 encr_enable;
791
792 STREAM_TO_UINT8 (status, p);
793 STREAM_TO_UINT16 (handle, p);
794 STREAM_TO_UINT8 (encr_enable, p);
795
796 btm_acl_encrypt_change (handle, status, encr_enable);
797 btm_sec_encrypt_change (handle, status, encr_enable);
798 }
799 #endif ///SMP_INCLUDED == 1
800
801 /*******************************************************************************
802 **
803 ** Function btu_hcif_read_rmt_features_comp_evt
804 **
805 ** Description Process event HCI_READ_RMT_FEATURES_COMP_EVT
806 **
807 ** Returns void
808 **
809 *******************************************************************************/
btu_hcif_read_rmt_features_comp_evt(UINT8 * p)810 static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p)
811 {
812 btm_read_remote_features_complete(p);
813 }
814
815 /*******************************************************************************
816 **
817 ** Function btu_hcif_read_rmt_ext_features_comp_evt
818 **
819 ** Description Process event HCI_READ_RMT_EXT_FEATURES_COMP_EVT
820 **
821 ** Returns void
822 **
823 *******************************************************************************/
btu_hcif_read_rmt_ext_features_comp_evt(UINT8 * p)824 static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p)
825 {
826 UINT8 *p_cur = p;
827 UINT8 status;
828 UINT16 handle;
829
830 STREAM_TO_UINT8 (status, p_cur);
831
832 if (status == HCI_SUCCESS) {
833 btm_read_remote_ext_features_complete(p);
834 } else {
835 STREAM_TO_UINT16 (handle, p_cur);
836 btm_read_remote_ext_features_failed(status, handle);
837 }
838 }
839
840 /*******************************************************************************
841 **
842 ** Function btu_hcif_read_rmt_version_comp_evt
843 **
844 ** Description Process event HCI_READ_RMT_VERSION_COMP_EVT
845 **
846 ** Returns void
847 **
848 *******************************************************************************/
btu_hcif_read_rmt_version_comp_evt(UINT8 * p)849 static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p)
850 {
851 btm_read_remote_version_complete (p);
852 }
853
854
855 /*******************************************************************************
856 **
857 ** Function btu_hcif_qos_setup_comp_evt
858 **
859 ** Description Process event HCI_QOS_SETUP_COMP_EVT
860 **
861 ** Returns void
862 **
863 *******************************************************************************/
btu_hcif_qos_setup_comp_evt(UINT8 * p)864 static void btu_hcif_qos_setup_comp_evt (UINT8 *p)
865 {
866 UINT8 status;
867 UINT16 handle;
868 FLOW_SPEC flow;
869
870 STREAM_TO_UINT8 (status, p);
871 STREAM_TO_UINT16 (handle, p);
872 STREAM_TO_UINT8 (flow.qos_flags, p);
873 STREAM_TO_UINT8 (flow.service_type, p);
874 STREAM_TO_UINT32 (flow.token_rate, p);
875 STREAM_TO_UINT32 (flow.peak_bandwidth, p);
876 STREAM_TO_UINT32 (flow.latency, p);
877 STREAM_TO_UINT32 (flow.delay_variation, p);
878
879 btm_qos_setup_complete(status, handle, &flow);
880 }
881
882
883 /*******************************************************************************
884 **
885 ** Function btu_hcif_esco_connection_comp_evt
886 **
887 ** Description Process event HCI_ESCO_CONNECTION_COMP_EVT
888 **
889 ** Returns void
890 **
891 *******************************************************************************/
btu_hcif_esco_connection_comp_evt(UINT8 * p)892 static void btu_hcif_esco_connection_comp_evt (UINT8 *p)
893 {
894 #if BTM_SCO_INCLUDED == 1
895 tBTM_ESCO_DATA data;
896 UINT16 handle;
897 BD_ADDR bda;
898 UINT8 status;
899
900 STREAM_TO_UINT8 (status, p);
901 STREAM_TO_UINT16 (handle, p);
902 STREAM_TO_BDADDR (bda, p);
903
904 STREAM_TO_UINT8 (data.link_type, p);
905 STREAM_TO_UINT8 (data.tx_interval, p);
906 STREAM_TO_UINT8 (data.retrans_window, p);
907 STREAM_TO_UINT16 (data.rx_pkt_len, p);
908 STREAM_TO_UINT16 (data.tx_pkt_len, p);
909 STREAM_TO_UINT8 (data.air_mode, p);
910
911 memcpy (data.bd_addr, bda, BD_ADDR_LEN);
912 btm_sco_connected (status, bda, handle, &data);
913 #endif
914 }
915
916
917 /*******************************************************************************
918 **
919 ** Function btu_hcif_esco_connection_chg_evt
920 **
921 ** Description Process event HCI_ESCO_CONNECTION_CHANGED_EVT
922 **
923 ** Returns void
924 **
925 *******************************************************************************/
btu_hcif_esco_connection_chg_evt(UINT8 * p)926 static void btu_hcif_esco_connection_chg_evt (UINT8 *p)
927 {
928 #if BTM_SCO_INCLUDED == 1
929 UINT16 handle;
930 UINT16 tx_pkt_len;
931 UINT16 rx_pkt_len;
932 UINT8 status;
933 UINT8 tx_interval;
934 UINT8 retrans_window;
935
936 STREAM_TO_UINT8 (status, p);
937 STREAM_TO_UINT16 (handle, p);
938
939 STREAM_TO_UINT8 (tx_interval, p);
940 STREAM_TO_UINT8 (retrans_window, p);
941 STREAM_TO_UINT16 (rx_pkt_len, p);
942 STREAM_TO_UINT16 (tx_pkt_len, p);
943
944 btm_esco_proc_conn_chg (status, handle, tx_interval, retrans_window,
945 rx_pkt_len, tx_pkt_len);
946 #endif
947 }
948
949 /*******************************************************************************
950 **
951 ** Function btu_hcif_hdl_command_complete
952 **
953 ** Description Handle command complete event
954 **
955 ** Returns void
956 **
957 *******************************************************************************/
btu_hcif_hdl_command_complete(UINT16 opcode,UINT8 * p,UINT16 evt_len,void * p_cplt_cback)958 static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_len,
959 void *p_cplt_cback)
960 {
961 switch (opcode) {
962 case HCI_INQUIRY_CANCEL:
963 /* Tell inquiry processing that we are done */
964 btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK);
965 break;
966 case HCI_SET_EVENT_FILTER:
967 btm_event_filter_complete (p);
968 break;
969
970 case HCI_DELETE_STORED_LINK_KEY:
971 btm_delete_stored_link_key_complete (p);
972 break;
973
974 case HCI_READ_LOCAL_NAME:
975 btm_read_local_name_complete (p, evt_len);
976 break;
977
978 case HCI_GET_LINK_QUALITY:
979 btm_read_link_quality_complete (p);
980 break;
981
982 case HCI_READ_RSSI:
983 btm_read_rssi_complete (p);
984 break;
985
986 case HCI_READ_TRANSMIT_POWER_LEVEL:
987 btm_read_tx_power_complete(p, 0);
988 break;
989
990 case HCI_CREATE_CONNECTION_CANCEL:
991 btm_create_conn_cancel_complete(p);
992 break;
993
994 case HCI_READ_LOCAL_OOB_DATA:
995 #if BTM_OOB_INCLUDED == 1 && SMP_INCLUDED == 1
996 btm_read_local_oob_complete(p);
997 #endif
998 break;
999
1000
1001 case HCI_READ_INQ_TX_POWER_LEVEL:
1002 btm_read_linq_tx_power_complete (p);
1003 break;
1004 #if (CLASSIC_BT_INCLUDED == 1)
1005 case HCI_SET_AFH_CHANNELS:
1006 btm_set_afh_channels_complete(p);
1007 break;
1008 #endif
1009
1010 #if (BLE_INCLUDED == 1)
1011 /* BLE Commands Complete*/
1012 case HCI_BLE_SET_HOST_CHNL_CLASS:
1013 btm_ble_set_channels_complete(p);
1014 break;
1015 case HCI_BLE_ADD_WHITE_LIST:
1016 btm_ble_add_2_white_list_complete(*p);
1017 break;
1018
1019 case HCI_BLE_CLEAR_WHITE_LIST:
1020 btm_ble_clear_white_list_complete(p, evt_len);
1021 break;
1022 case HCI_BLE_WRITE_ADV_PARAMS: {
1023 uint8_t status;
1024 STREAM_TO_UINT8 (status, p);
1025 if(status != HCI_SUCCESS) {
1026 HCI_TRACE_ERROR("hci write adv params error 0x%x", status);
1027 }
1028 break;
1029 }
1030 case HCI_BLE_RC_PARAM_REQ_REPLY: {
1031 uint8_t status;
1032 STREAM_TO_UINT8 (status, p);
1033 if(status != HCI_SUCCESS) {
1034 HCI_TRACE_ERROR("hci connection params reply command error 0x%x", status);
1035 }
1036 break;
1037 }
1038 case HCI_BLE_RC_PARAM_REQ_NEG_REPLY: {
1039 uint8_t status;
1040 STREAM_TO_UINT8 (status, p);
1041 if(status != HCI_SUCCESS) {
1042 HCI_TRACE_ERROR("hci connection params neg reply command error %x", status);
1043 }
1044 break;
1045 }
1046 case HCI_BLE_REMOVE_WHITE_LIST:
1047 btm_ble_remove_from_white_list_complete(p, evt_len);
1048 break;
1049
1050 case HCI_BLE_RAND:
1051 case HCI_BLE_ENCRYPT:
1052 #if (SMP_INCLUDED == 1)
1053 btm_ble_rand_enc_complete (p, opcode, (tBTM_RAND_ENC_CB *)p_cplt_cback);
1054 #endif ///SMP_INCLUDED == 1
1055 break;
1056
1057 case HCI_BLE_READ_ADV_CHNL_TX_POWER:
1058 btm_read_tx_power_complete(p, 1);
1059 break;
1060
1061 case HCI_BLE_WRITE_ADV_ENABLE:
1062 btm_ble_write_adv_enable_complete(p);
1063 break;
1064
1065 case HCI_BLE_CREATE_LL_CONN:
1066 btm_ble_create_ll_conn_complete(*p);
1067 break;
1068
1069 case HCI_BLE_TRANSMITTER_TEST:
1070 case HCI_BLE_RECEIVER_TEST:
1071 case HCI_BLE_TEST_END:
1072 btm_ble_test_command_complete(p);
1073 break;
1074 case HCI_BLE_CREATE_CONN_CANCEL:
1075 btm_ble_create_conn_cancel_complete(p);
1076 break;
1077
1078 #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == 1)
1079 case HCI_BLE_ADD_DEV_RESOLVING_LIST:
1080 btm_ble_add_resolving_list_entry_complete(p, evt_len);
1081 break;
1082
1083 case HCI_BLE_RM_DEV_RESOLVING_LIST:
1084 btm_ble_remove_resolving_list_entry_complete(p, evt_len);
1085 break;
1086
1087 case HCI_BLE_CLEAR_RESOLVING_LIST:
1088 btm_ble_clear_resolving_list_complete(p, evt_len);
1089 break;
1090
1091 case HCI_BLE_READ_RESOLVABLE_ADDR_PEER:
1092 btm_ble_read_resolving_list_entry_complete(p, evt_len);
1093 break;
1094
1095 case HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL:
1096 case HCI_BLE_SET_ADDR_RESOLUTION_ENABLE:
1097 case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT:
1098 break;
1099 #if (BLE_50_FEATURE_SUPPORT == 1)
1100 case HCI_BLE_SET_EXT_ADV_PARAM:
1101 case HCI_BLE_SET_EXT_ADV_DATA:
1102 case HCI_BLE_SET_EXT_SCAN_RSP_DATA:
1103 case HCI_BLE_SET_EXT_ADV_ENABLE: {
1104 uint8_t status;
1105 STREAM_TO_UINT8 (status, p);
1106 HCI_TRACE_EVENT("%s opcode 0x%x status 0x%x", __func__, opcode, status);
1107 break;
1108 }
1109 case HCI_BLE_READ_PHY: {
1110 uint8_t status;
1111 uint16_t conn_handle;
1112 uint8_t tx_phy;
1113 uint8_t rx_phy;
1114 STREAM_TO_UINT8(status, p);
1115 STREAM_TO_UINT16(conn_handle, p);
1116 STREAM_TO_UINT8(tx_phy, p);
1117 STREAM_TO_UINT8(rx_phy, p);
1118 btm_read_phy_callback(status, conn_handle, tx_phy, rx_phy);
1119 break;
1120 }
1121 case HCI_BLE_ENH_RX_TEST:
1122 case HCI_BLE_ENH_TX_TEST:
1123 btm_ble_test_command_complete(p);
1124 break;
1125 #endif // #if (BLE_50_FEATURE_SUPPORT == 1)
1126 #endif
1127 #endif /* (BLE_INCLUDED == 1) */
1128
1129 default: {
1130 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) {
1131 btm_vsc_complete (p, opcode, evt_len, (tBTM_CMPL_CB *)p_cplt_cback);
1132 }
1133 uint8_t status;
1134 STREAM_TO_UINT8 (status, p);
1135 if(status != HCI_SUCCESS) {
1136 HCI_TRACE_ERROR("CC evt: op=0x%x, status=0x%x", opcode, status);
1137 }
1138 break;
1139 }
1140 }
1141 }
1142
1143 /*******************************************************************************
1144 **
1145 ** Function btu_hcif_command_complete_evt
1146 **
1147 ** Description Process event HCI_COMMAND_COMPLETE_EVT
1148 **
1149 ** Returns void
1150 **
1151 *******************************************************************************/
btu_hcif_command_complete_evt_on_task(BT_HDR * event)1152 static void btu_hcif_command_complete_evt_on_task(BT_HDR *event)
1153 {
1154 command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0];
1155
1156 command_opcode_t opcode;
1157 uint8_t *stream = hack->response->data + hack->response->offset + 3; // 2 to skip the event headers, 1 to skip the command credits
1158 STREAM_TO_UINT16(opcode, stream);
1159
1160 btu_hcif_hdl_command_complete(
1161 opcode,
1162 stream,
1163 hack->response->len - 5, // 3 for the command complete headers, 2 for the event headers
1164 hack->context);
1165
1166 osi_free(hack->response);
1167 osi_free(event);
1168 }
1169
btu_hcif_command_complete_evt(BT_HDR * response,void * context)1170 static void btu_hcif_command_complete_evt(BT_HDR *response, void *context)
1171 {
1172 #if (BLE_INCLUDED == 1)
1173 command_opcode_t opcode;
1174 uint8_t *stream = response->data + response->offset + 3;
1175 STREAM_TO_UINT16(opcode, stream);
1176 switch (opcode) {
1177 case HCI_BLE_WRITE_ADV_DATA:
1178 adv_data_status = *stream;
1179 osi_sem_give(&adv_data_sem);
1180 break;
1181 case HCI_BLE_WRITE_SCAN_RSP_DATA:
1182 adv_data_status = *stream;
1183 osi_sem_give(&adv_data_sem);
1184 break;
1185 case HCI_BLE_WRITE_ADV_ENABLE: {
1186 adv_enable_status = *stream;
1187 osi_sem_give(&adv_enable_sem);
1188 break;
1189 }
1190 case HCI_BLE_WRITE_ADV_PARAMS:
1191 adv_param_status = *stream;
1192 osi_sem_give(&adv_param_sem);
1193 break;
1194 case HCI_BLE_WRITE_SCAN_PARAMS:
1195 scan_param_status = *stream;
1196 osi_sem_give(&scan_param_sem);
1197 break;
1198 case HCI_BLE_WRITE_SCAN_ENABLE:
1199 scan_enable_status = *stream;
1200 osi_sem_give(&scan_enable_sem);
1201 break;
1202 default:
1203 break;
1204 }
1205 #endif
1206 BT_HDR *event = osi_calloc(sizeof(BT_HDR) + sizeof(command_complete_hack_t));
1207 command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0];
1208 #if (BLE_50_FEATURE_SUPPORT == 1)
1209 UINT8 status = 0;
1210 stream = response->data + response->offset + 3 + 2; // 2 to skip the event headers, 1 to skip the command credits, 2 to opcode.
1211 STREAM_TO_UINT8(status, stream);
1212 btsnd_hci_ble_set_status(status);
1213 #endif // #if (BLE_50_FEATURE_SUPPORT == 1)
1214 HCI_TRACE_DEBUG("btu_hcif_command_complete_evt\n");
1215
1216 hack->callback = btu_hcif_command_complete_evt_on_task;
1217 hack->response = response;
1218 hack->context = context;
1219
1220 event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK;
1221
1222 btu_task_post(SIG_BTU_HCI_MSG, event, OSI_THREAD_MAX_TIMEOUT);
1223 }
1224
1225
1226 /*******************************************************************************
1227 **
1228 ** Function btu_hcif_hdl_command_status
1229 **
1230 ** Description Handle a command status event
1231 **
1232 ** Returns void
1233 **
1234 *******************************************************************************/
btu_hcif_hdl_command_status(UINT16 opcode,UINT8 status,UINT8 * p_cmd,void * p_vsc_status_cback)1235 static void btu_hcif_hdl_command_status (UINT16 opcode, UINT8 status, UINT8 *p_cmd,
1236 void *p_vsc_status_cback)
1237 {
1238 BD_ADDR bd_addr;
1239 UINT16 handle;
1240 #if BTM_SCO_INCLUDED == 1
1241 tBTM_ESCO_DATA esco_data;
1242 #endif
1243
1244 switch (opcode) {
1245 case HCI_EXIT_SNIFF_MODE:
1246 case HCI_EXIT_PARK_MODE:
1247 #if BTM_SCO_WAKE_PARKED_LINK == 1
1248 if (status != HCI_SUCCESS) {
1249 /* Allow SCO initiation to continue if waiting for change mode event */
1250 if (p_cmd != NULL) {
1251 p_cmd++; /* bypass length field */
1252 STREAM_TO_UINT16 (handle, p_cmd);
1253 btm_sco_chk_pend_unpark (status, handle);
1254 }
1255 }
1256 #endif
1257 /* Case Falls Through */
1258
1259 case HCI_HOLD_MODE:
1260 case HCI_SNIFF_MODE:
1261 case HCI_PARK_MODE:
1262 btm_pm_proc_cmd_status(status);
1263 break;
1264 #if (BLE_50_FEATURE_SUPPORT == 1)
1265 case HCI_BLE_PERIOD_ADV_CREATE_SYNC:
1266 {
1267 uint8_t btm_status = BTM_SUCCESS;
1268 if(status != HCI_SUCCESS) {
1269 HCI_TRACE_ERROR("CS evt: LE PA CreateSync status=0x%x", status);
1270 btm_status = BTM_ILLEGAL_VALUE;
1271 }
1272 btm_create_sync_callback(btm_status);
1273 break;
1274 }
1275 case HCI_BLE_SET_PHY:
1276 {
1277 uint8_t btm_status = BTM_SUCCESS;
1278 if(status != HCI_SUCCESS) {
1279 HCI_TRACE_ERROR("CS evt: LE SetPhy status=0x%x", status);
1280 btm_status = BTM_ILLEGAL_VALUE;
1281 }
1282 btm_set_phy_callback(btm_status);
1283 break;
1284 }
1285 #endif // #if (BLE_50_FEATURE_SUPPORT == 1)
1286 default:
1287 /* If command failed to start, we may need to tell BTM */
1288 if (status != HCI_SUCCESS) {
1289 switch (opcode) {
1290 case HCI_INQUIRY:
1291 /* Tell inquiry processing that we are done */
1292 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
1293 break;
1294
1295 case HCI_RMT_NAME_REQUEST:
1296 /* Tell inquiry processing that we are done */
1297 btm_process_remote_name (NULL, NULL, 0, status);
1298 #if (SMP_INCLUDED == 1)
1299 btm_sec_rmt_name_request_complete (NULL, NULL, status);
1300 #endif ///SMP_INCLUDED == 1
1301 break;
1302
1303 case HCI_QOS_SETUP_COMP_EVT:
1304 /* Tell qos setup that we are done */
1305 btm_qos_setup_complete(status, 0, NULL);
1306 break;
1307
1308 case HCI_SWITCH_ROLE:
1309 /* Tell BTM that the command failed */
1310 /* read bd addr out of stored command */
1311 if (p_cmd != NULL) {
1312 p_cmd++;
1313 STREAM_TO_BDADDR (bd_addr, p_cmd);
1314 btm_acl_role_changed(status, bd_addr, BTM_ROLE_UNDEFINED);
1315 } else {
1316 btm_acl_role_changed(status, NULL, BTM_ROLE_UNDEFINED);
1317 }
1318 l2c_link_role_changed (NULL, BTM_ROLE_UNDEFINED, HCI_ERR_COMMAND_DISALLOWED);
1319 break;
1320
1321 case HCI_CREATE_CONNECTION:
1322 /* read bd addr out of stored command */
1323 if (p_cmd != NULL) {
1324 p_cmd++;
1325 STREAM_TO_BDADDR (bd_addr, p_cmd);
1326 #if (SMP_INCLUDED == 1)
1327 btm_sec_connected (bd_addr, HCI_INVALID_HANDLE, status, 0);
1328 #endif ///SMP_INCLUDED == 1
1329 l2c_link_hci_conn_comp (status, HCI_INVALID_HANDLE, bd_addr);
1330 }
1331 break;
1332
1333 case HCI_READ_RMT_EXT_FEATURES:
1334 if (p_cmd != NULL) {
1335 p_cmd++; /* skip command length */
1336 STREAM_TO_UINT16 (handle, p_cmd);
1337 } else {
1338 handle = HCI_INVALID_HANDLE;
1339 }
1340
1341 btm_read_remote_ext_features_failed(status, handle);
1342 break;
1343
1344 case HCI_AUTHENTICATION_REQUESTED:
1345 #if (SMP_INCLUDED == 1)
1346 /* Device refused to start authentication. That should be treated as authentication failure. */
1347 btm_sec_auth_complete (BTM_INVALID_HCI_HANDLE, status);
1348 #endif ///SMP_INCLUDED == 1
1349 break;
1350
1351 case HCI_SET_CONN_ENCRYPTION:
1352 #if (SMP_INCLUDED == 1)
1353 /* Device refused to start encryption. That should be treated as encryption failure. */
1354 btm_sec_encrypt_change (BTM_INVALID_HCI_HANDLE, status, 0);
1355 #endif ///SMP_INCLUDED == 1
1356 break;
1357
1358 #if BLE_INCLUDED == 1
1359 case HCI_BLE_CREATE_LL_CONN:
1360 btm_ble_create_ll_conn_complete(status);
1361 break;
1362 case HCI_BLE_UPD_LL_CONN_PARAMS:
1363 if (p_cmd != NULL){
1364 p_cmd++;
1365 STREAM_TO_UINT16 (handle, p_cmd);
1366 btu_ble_ll_get_conn_param_format_err_from_contoller(status, handle);
1367 }
1368 break;
1369 #endif
1370
1371 #if BTM_SCO_INCLUDED == 1
1372 case HCI_SETUP_ESCO_CONNECTION:
1373 /* read handle out of stored command */
1374 if (p_cmd != NULL) {
1375 p_cmd++;
1376 STREAM_TO_UINT16 (handle, p_cmd);
1377
1378 /* Determine if initial connection failed or is a change of setup */
1379 if (btm_is_sco_active(handle)) {
1380 btm_esco_proc_conn_chg (status, handle, 0, 0, 0, 0);
1381 } else {
1382 btm_sco_connected (status, NULL, handle, &esco_data);
1383 }
1384 }
1385 break;
1386 #endif
1387
1388 /* This is commented out until an upper layer cares about returning event
1389 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == 1
1390 case HCI_ENHANCED_FLUSH:
1391 break;
1392 #endif
1393 */
1394 default:
1395 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) {
1396 btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback);
1397 }
1398 break;
1399 }
1400
1401 } else {
1402 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) {
1403 btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback);
1404 }
1405 }
1406 }
1407 }
1408
1409 /*******************************************************************************
1410 **
1411 ** Function btu_hcif_command_status_evt
1412 **
1413 ** Description Process event HCI_COMMAND_STATUS_EVT
1414 **
1415 ** Returns void
1416 **
1417 *******************************************************************************/
btu_hcif_command_status_evt_on_task(BT_HDR * event)1418 static void btu_hcif_command_status_evt_on_task(BT_HDR *event)
1419 {
1420 command_status_hack_t *hack = (command_status_hack_t *)&event->data[0];
1421
1422 command_opcode_t opcode;
1423 uint8_t *stream = hack->command->data + hack->command->offset;
1424 STREAM_TO_UINT16(opcode, stream);
1425
1426 btu_hcif_hdl_command_status(
1427 opcode,
1428 hack->status,
1429 stream,
1430 hack->context);
1431
1432 osi_free(hack->command);
1433 osi_free(event);
1434 }
1435
btu_hcif_command_status_evt(uint8_t status,BT_HDR * command,void * context)1436 static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *context)
1437 {
1438 BT_HDR *event = osi_calloc(sizeof(BT_HDR) + sizeof(command_status_hack_t));
1439 command_status_hack_t *hack = (command_status_hack_t *)&event->data[0];
1440
1441 hack->callback = btu_hcif_command_status_evt_on_task;
1442 hack->status = status;
1443 hack->command = command;
1444 hack->context = context;
1445
1446 event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK;
1447
1448 btu_task_post(SIG_BTU_HCI_MSG, event, OSI_THREAD_MAX_TIMEOUT);
1449 }
1450
1451 /*******************************************************************************
1452 **
1453 ** Function btu_hcif_hardware_error_evt
1454 **
1455 ** Description Process event HCI_HARDWARE_ERROR_EVT
1456 **
1457 ** Returns void
1458 **
1459 *******************************************************************************/
btu_hcif_hardware_error_evt(UINT8 * p)1460 static void btu_hcif_hardware_error_evt (UINT8 *p)
1461 {
1462 HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x\n", *p);
1463
1464 /* If anyone wants device status notifications, give him one. */
1465 btm_report_device_status (BTM_DEV_STATUS_DOWN);
1466
1467 /* Reset the controller */
1468 if (BTM_IsDeviceUp()) {
1469 BTM_DeviceReset (NULL);
1470 }
1471 }
1472
1473
1474 /*******************************************************************************
1475 **
1476 ** Function btu_hcif_flush_occured_evt
1477 **
1478 ** Description Process event HCI_FLUSH_OCCURED_EVT
1479 **
1480 ** Returns void
1481 **
1482 *******************************************************************************/
btu_hcif_flush_occured_evt(void)1483 static void btu_hcif_flush_occured_evt (void)
1484 {
1485 }
1486
1487
1488 /*******************************************************************************
1489 **
1490 ** Function btu_hcif_role_change_evt
1491 **
1492 ** Description Process event HCI_ROLE_CHANGE_EVT
1493 **
1494 ** Returns void
1495 **
1496 *******************************************************************************/
btu_hcif_role_change_evt(UINT8 * p)1497 static void btu_hcif_role_change_evt (UINT8 *p)
1498 {
1499 UINT8 status;
1500 BD_ADDR bda;
1501 UINT8 role;
1502
1503 STREAM_TO_UINT8 (status, p);
1504 STREAM_TO_BDADDR (bda, p);
1505 STREAM_TO_UINT8 (role, p);
1506
1507 l2c_link_role_changed (bda, role, status);
1508 btm_acl_role_changed(status, bda, role);
1509 }
1510
1511
1512 /*******************************************************************************
1513 **
1514 ** Function btu_hcif_num_compl_data_pkts_evt
1515 **
1516 ** Description Process event HCI_NUM_COMPL_DATA_PKTS_EVT
1517 **
1518 ** Returns void
1519 **
1520 *******************************************************************************/
btu_hcif_num_compl_data_pkts_evt(UINT8 * p)1521 static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p)
1522 {
1523 /* Process for L2CAP and SCO */
1524 l2c_link_process_num_completed_pkts (p);
1525
1526 /* Send on to SCO */
1527 #if (BTM_SCO_HCI_INCLUDED == 1) && (BTM_SCO_INCLUDED == 1)
1528 btm_sco_process_num_completed_pkts (p);
1529 #endif
1530 }
1531
1532 /*******************************************************************************
1533 **
1534 ** Function btu_hcif_mode_change_evt
1535 **
1536 ** Description Process event HCI_MODE_CHANGE_EVT
1537 **
1538 ** Returns void
1539 **
1540 *******************************************************************************/
btu_hcif_mode_change_evt(UINT8 * p)1541 static void btu_hcif_mode_change_evt (UINT8 *p)
1542 {
1543 UINT8 status;
1544 UINT16 handle;
1545 UINT8 current_mode;
1546 UINT16 interval;
1547
1548 STREAM_TO_UINT8 (status, p);
1549
1550 STREAM_TO_UINT16 (handle, p);
1551 STREAM_TO_UINT8 (current_mode, p);
1552 STREAM_TO_UINT16 (interval, p);
1553 #if BTM_SCO_WAKE_PARKED_LINK == 1
1554 btm_sco_chk_pend_unpark (status, handle);
1555 #endif
1556 btm_pm_proc_mode_change (status, handle, current_mode, interval);
1557
1558 /*
1559 #if (HID_DEV_INCLUDED == 1) && (HID_DEV_PM_INCLUDED == 1)
1560 hidd_pm_proc_mode_change( status, current_mode, interval ) ;
1561 #endif
1562 */
1563 }
1564
1565 /*******************************************************************************
1566 **
1567 ** Function btu_hcif_ssr_evt
1568 **
1569 ** Description Process event HCI_SNIFF_SUB_RATE_EVT
1570 **
1571 ** Returns void
1572 **
1573 *******************************************************************************/
1574 #if (BTM_SSR_INCLUDED == 1)
btu_hcif_ssr_evt(UINT8 * p,UINT16 evt_len)1575 static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len)
1576 {
1577 btm_pm_proc_ssr_evt(p, evt_len);
1578 }
1579 #endif
1580
1581 /*******************************************************************************
1582 **
1583 ** Function btu_hcif_pin_code_request_evt
1584 **
1585 ** Description Process event HCI_PIN_CODE_REQUEST_EVT
1586 **
1587 ** Returns void
1588 **
1589 *******************************************************************************/
1590 #if (SMP_INCLUDED == 1)
btu_hcif_pin_code_request_evt(UINT8 * p)1591 static void btu_hcif_pin_code_request_evt (UINT8 *p)
1592 {
1593 #if (CLASSIC_BT_INCLUDED == 1)
1594 BD_ADDR bda;
1595
1596 STREAM_TO_BDADDR (bda, p);
1597
1598 /* Tell L2CAP that there was a PIN code request, */
1599 /* it may need to stretch timeouts */
1600 l2c_pin_code_request (bda);
1601
1602 btm_sec_pin_code_request (bda);
1603 #endif ///CLASSIC_BT_INCLUDED == 1
1604 }
1605
1606
1607 /*******************************************************************************
1608 **
1609 ** Function btu_hcif_link_key_request_evt
1610 **
1611 ** Description Process event HCI_LINK_KEY_REQUEST_EVT
1612 **
1613 ** Returns void
1614 **
1615 *******************************************************************************/
btu_hcif_link_key_request_evt(UINT8 * p)1616 static void btu_hcif_link_key_request_evt (UINT8 *p)
1617 {
1618 BD_ADDR bda;
1619
1620 STREAM_TO_BDADDR (bda, p);
1621 btm_sec_link_key_request (bda);
1622 }
1623
1624 /*******************************************************************************
1625 **
1626 ** Function btu_hcif_link_key_notification_evt
1627 **
1628 ** Description Process event HCI_LINK_KEY_NOTIFICATION_EVT
1629 **
1630 ** Returns void
1631 **
1632 *******************************************************************************/
btu_hcif_link_key_notification_evt(UINT8 * p)1633 static void btu_hcif_link_key_notification_evt (UINT8 *p)
1634 {
1635 BD_ADDR bda;
1636 LINK_KEY key;
1637 UINT8 key_type;
1638
1639 STREAM_TO_BDADDR (bda, p);
1640 STREAM_TO_ARRAY16 (key, p);
1641 STREAM_TO_UINT8 (key_type, p);
1642
1643 btm_sec_link_key_notification (bda, key, key_type);
1644 }
1645 #endif ///SMP_INCLUDED == 1
1646
1647
1648 /*******************************************************************************
1649 **
1650 ** Function btu_hcif_loopback_command_evt
1651 **
1652 ** Description Process event HCI_LOOPBACK_COMMAND_EVT
1653 **
1654 ** Returns void
1655 **
1656 *******************************************************************************/
btu_hcif_loopback_command_evt(void)1657 static void btu_hcif_loopback_command_evt (void)
1658 {
1659 }
1660
1661
1662 /*******************************************************************************
1663 **
1664 ** Function btu_hcif_data_buf_overflow_evt
1665 **
1666 ** Description Process event HCI_DATA_BUF_OVERFLOW_EVT
1667 **
1668 ** Returns void
1669 **
1670 *******************************************************************************/
btu_hcif_data_buf_overflow_evt(void)1671 static void btu_hcif_data_buf_overflow_evt (void)
1672 {
1673 }
1674
1675
1676 /*******************************************************************************
1677 **
1678 ** Function btu_hcif_max_slots_changed_evt
1679 **
1680 ** Description Process event HCI_MAX_SLOTS_CHANGED_EVT
1681 **
1682 ** Returns void
1683 **
1684 *******************************************************************************/
btu_hcif_max_slots_changed_evt(void)1685 static void btu_hcif_max_slots_changed_evt (void)
1686 {
1687 }
1688
1689
1690 /*******************************************************************************
1691 **
1692 ** Function btu_hcif_read_clock_off_comp_evt
1693 **
1694 ** Description Process event HCI_READ_CLOCK_OFF_COMP_EVT
1695 **
1696 ** Returns void
1697 **
1698 *******************************************************************************/
btu_hcif_read_clock_off_comp_evt(UINT8 * p)1699 static void btu_hcif_read_clock_off_comp_evt (UINT8 *p)
1700 {
1701 UINT8 status;
1702 UINT16 handle;
1703 UINT16 clock_offset;
1704
1705 STREAM_TO_UINT8 (status, p);
1706
1707 /* If failed to get clock offset just drop the result */
1708 if (status != HCI_SUCCESS) {
1709 return;
1710 }
1711
1712 STREAM_TO_UINT16 (handle, p);
1713 STREAM_TO_UINT16 (clock_offset, p);
1714
1715 handle = HCID_GET_HANDLE (handle);
1716
1717 btm_process_clk_off_comp_evt (handle, clock_offset);
1718 btm_sec_update_clock_offset (handle, clock_offset);
1719 }
1720
1721
1722 /*******************************************************************************
1723 **
1724 ** Function btu_hcif_conn_pkt_type_change_evt
1725 **
1726 ** Description Process event HCI_CONN_PKT_TYPE_CHANGE_EVT
1727 **
1728 ** Returns void
1729 **
1730 *******************************************************************************/
btu_hcif_conn_pkt_type_change_evt(void)1731 static void btu_hcif_conn_pkt_type_change_evt (void)
1732 {
1733 }
1734
1735
1736 /*******************************************************************************
1737 **
1738 ** Function btu_hcif_qos_violation_evt
1739 **
1740 ** Description Process event HCI_QOS_VIOLATION_EVT
1741 **
1742 ** Returns void
1743 **
1744 *******************************************************************************/
btu_hcif_qos_violation_evt(UINT8 * p)1745 static void btu_hcif_qos_violation_evt (UINT8 *p)
1746 {
1747 UINT16 handle;
1748
1749 STREAM_TO_UINT16 (handle, p);
1750
1751 handle = HCID_GET_HANDLE (handle);
1752
1753
1754 l2c_link_hci_qos_violation (handle);
1755 }
1756
1757
1758 /*******************************************************************************
1759 **
1760 ** Function btu_hcif_page_scan_mode_change_evt
1761 **
1762 ** Description Process event HCI_PAGE_SCAN_MODE_CHANGE_EVT
1763 **
1764 ** Returns void
1765 **
1766 *******************************************************************************/
btu_hcif_page_scan_mode_change_evt(void)1767 static void btu_hcif_page_scan_mode_change_evt (void)
1768 {
1769 }
1770
1771
1772 /*******************************************************************************
1773 **
1774 ** Function btu_hcif_page_scan_rep_mode_chng_evt
1775 **
1776 ** Description Process event HCI_PAGE_SCAN_REP_MODE_CHNG_EVT
1777 **
1778 ** Returns void
1779 **
1780 *******************************************************************************/
btu_hcif_page_scan_rep_mode_chng_evt(void)1781 static void btu_hcif_page_scan_rep_mode_chng_evt (void)
1782 {
1783 }
1784
1785 /**********************************************
1786 ** Simple Pairing Events
1787 ***********************************************/
1788
1789 /*******************************************************************************
1790 **
1791 ** Function btu_hcif_host_support_evt
1792 **
1793 ** Description Process event HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT
1794 **
1795 ** Returns void
1796 **
1797 *******************************************************************************/
btu_hcif_host_support_evt(UINT8 * p)1798 static void btu_hcif_host_support_evt (UINT8 *p)
1799 {
1800 btm_sec_rmt_host_support_feat_evt(p);
1801 }
1802
1803 /*******************************************************************************
1804 **
1805 ** Function btu_hcif_io_cap_request_evt
1806 **
1807 ** Description Process event HCI_IO_CAPABILITY_REQUEST_EVT
1808 **
1809 ** Returns void
1810 **
1811 *******************************************************************************/
1812 #if (SMP_INCLUDED == 1)
btu_hcif_io_cap_request_evt(UINT8 * p)1813 static void btu_hcif_io_cap_request_evt (UINT8 *p)
1814 {
1815 btm_io_capabilities_req(p);
1816 }
1817
1818
1819 /*******************************************************************************
1820 **
1821 ** Function btu_hcif_io_cap_response_evt
1822 **
1823 ** Description Process event HCI_IO_CAPABILITY_RESPONSE_EVT
1824 **
1825 ** Returns void
1826 **
1827 *******************************************************************************/
btu_hcif_io_cap_response_evt(UINT8 * p)1828 static void btu_hcif_io_cap_response_evt (UINT8 *p)
1829 {
1830 btm_io_capabilities_rsp(p);
1831 }
1832
1833
1834 /*******************************************************************************
1835 **
1836 ** Function btu_hcif_user_conf_request_evt
1837 **
1838 ** Description Process event HCI_USER_CONFIRMATION_REQUEST_EVT
1839 **
1840 ** Returns void
1841 **
1842 *******************************************************************************/
btu_hcif_user_conf_request_evt(UINT8 * p)1843 static void btu_hcif_user_conf_request_evt (UINT8 *p)
1844 {
1845 btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p);
1846 }
1847
1848 /*******************************************************************************
1849 **
1850 ** Function btu_hcif_user_passkey_request_evt
1851 **
1852 ** Description Process event HCI_USER_PASSKEY_REQUEST_EVT
1853 **
1854 ** Returns void
1855 **
1856 *******************************************************************************/
btu_hcif_user_passkey_request_evt(UINT8 * p)1857 static void btu_hcif_user_passkey_request_evt (UINT8 *p)
1858 {
1859 btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p);
1860 }
1861
1862 /*******************************************************************************
1863 **
1864 ** Function btu_hcif_user_passkey_notif_evt
1865 **
1866 ** Description Process event HCI_USER_PASSKEY_NOTIFY_EVT
1867 **
1868 ** Returns void
1869 **
1870 *******************************************************************************/
btu_hcif_user_passkey_notif_evt(UINT8 * p)1871 static void btu_hcif_user_passkey_notif_evt (UINT8 *p)
1872 {
1873 btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p);
1874 }
1875
1876 /*******************************************************************************
1877 **
1878 ** Function btu_hcif_keypress_notif_evt
1879 **
1880 ** Description Process event HCI_KEYPRESS_NOTIFY_EVT
1881 **
1882 ** Returns void
1883 **
1884 *******************************************************************************/
btu_hcif_keypress_notif_evt(UINT8 * p)1885 static void btu_hcif_keypress_notif_evt (UINT8 *p)
1886 {
1887 btm_keypress_notif_evt(p);
1888 }
1889 #endif ///SMP_INCLUDED == 1
1890
1891
1892 /*******************************************************************************
1893 **
1894 ** Function btu_hcif_rem_oob_request_evt
1895 **
1896 ** Description Process event HCI_REMOTE_OOB_DATA_REQUEST_EVT
1897 **
1898 ** Returns void
1899 **
1900 *******************************************************************************/
1901 #if BTM_OOB_INCLUDED == 1 && SMP_INCLUDED == 1
btu_hcif_rem_oob_request_evt(UINT8 * p)1902 static void btu_hcif_rem_oob_request_evt (UINT8 *p)
1903 {
1904 btm_rem_oob_req(p);
1905 }
1906 #endif
1907
1908 /*******************************************************************************
1909 **
1910 ** Function btu_hcif_simple_pair_complete_evt
1911 **
1912 ** Description Process event HCI_SIMPLE_PAIRING_COMPLETE_EVT
1913 **
1914 ** Returns void
1915 **
1916 *******************************************************************************/
1917 #if (SMP_INCLUDED == 1)
btu_hcif_simple_pair_complete_evt(UINT8 * p)1918 static void btu_hcif_simple_pair_complete_evt (UINT8 *p)
1919 {
1920 btm_simple_pair_complete(p);
1921 }
1922 #endif ///SMP_INCLUDED == 1
1923 /*******************************************************************************
1924 **
1925 ** Function btu_hcif_enhanced_flush_complete_evt
1926 **
1927 ** Description Process event HCI_ENHANCED_FLUSH_COMPLETE_EVT
1928 **
1929 ** Returns void
1930 **
1931 *******************************************************************************/
1932 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == 1
btu_hcif_enhanced_flush_complete_evt(void)1933 static void btu_hcif_enhanced_flush_complete_evt (void)
1934 {
1935 /* This is empty until an upper layer cares about returning event */
1936 }
1937 #endif
1938 /**********************************************
1939 ** End of Simple Pairing Events
1940 ***********************************************/
1941
1942
1943 /**********************************************
1944 ** BLE Events
1945 ***********************************************/
1946 #if (defined BLE_INCLUDED) && (BLE_INCLUDED == 1)
1947 #if (SMP_INCLUDED == 1)
btu_hcif_encryption_key_refresh_cmpl_evt(UINT8 * p)1948 static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p)
1949 {
1950 UINT8 status;
1951 UINT8 enc_enable = 0;
1952 UINT16 handle;
1953
1954 STREAM_TO_UINT8 (status, p);
1955 STREAM_TO_UINT16 (handle, p);
1956
1957 if (status == HCI_SUCCESS) {
1958 enc_enable = 1;
1959 }
1960
1961 btm_sec_encrypt_change (handle, status, enc_enable);
1962 }
1963 #endif ///SMP_INCLUDED == 1
1964
btu_ble_process_adv_pkt(UINT8 * p)1965 static void btu_ble_process_adv_pkt (UINT8 *p)
1966 {
1967 HCI_TRACE_DEBUG("btu_ble_process_adv_pkt\n");
1968
1969 btm_ble_process_adv_pkt(p);
1970 }
1971
btu_ble_process_adv_dis(UINT8 * p)1972 static void btu_ble_process_adv_dis(UINT8 *p)
1973 {
1974 btm_ble_process_adv_discard_evt(p);
1975 }
1976
btu_ble_ll_conn_complete_evt(UINT8 * p,UINT16 evt_len)1977 static void btu_ble_ll_conn_complete_evt ( UINT8 *p, UINT16 evt_len)
1978 {
1979 btm_ble_conn_complete(p, evt_len, 0);
1980 }
1981 //#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == 1)
btu_ble_proc_enhanced_conn_cmpl(UINT8 * p,UINT16 evt_len)1982 static void btu_ble_proc_enhanced_conn_cmpl( UINT8 *p, UINT16 evt_len)
1983 {
1984 btm_ble_conn_complete(p, evt_len, 1);
1985 }
1986 //#endif
btu_ble_ll_conn_param_upd_evt(UINT8 * p,UINT16 evt_len)1987 static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len)
1988 {
1989 /* LE connection update has completed successfully as a master. */
1990 /* We can enable the update request if the result is a success. */
1991 /* extract the HCI handle first */
1992 UINT8 status;
1993 UINT16 handle, conn_interval, conn_latency, conn_timeout;
1994 STREAM_TO_UINT8 (status, p);
1995 STREAM_TO_UINT16 (handle, p);
1996 STREAM_TO_UINT16 (conn_interval, p);
1997 STREAM_TO_UINT16 (conn_latency, p);
1998 STREAM_TO_UINT16 (conn_timeout, p);
1999
2000 l2cble_process_conn_update_evt(handle, status, conn_interval,
2001 conn_latency, conn_timeout);
2002 }
2003
btu_ble_ll_get_conn_param_format_err_from_contoller(UINT8 status,UINT16 handle)2004 static void btu_ble_ll_get_conn_param_format_err_from_contoller (UINT8 status, UINT16 handle)
2005 {
2006 /* host send illegal connection parameters format, controller would send
2007 back HCI_ERR_ILLEGAL_PARAMETER_FMT */
2008 l2cble_get_conn_param_format_err_from_contoller(status, handle);
2009
2010 }
2011
btu_ble_read_remote_feat_evt(UINT8 * p)2012 static void btu_ble_read_remote_feat_evt (UINT8 *p)
2013 {
2014 btm_ble_read_remote_features_complete(p);
2015 }
2016
2017 #if BLE_INCLUDED == 1 && SMP_INCLUDED == 1
btu_ble_proc_ltk_req(UINT8 * p)2018 static void btu_ble_proc_ltk_req (UINT8 *p)
2019 {
2020
2021 UINT16 ediv, handle;
2022 UINT8 *pp;
2023
2024 STREAM_TO_UINT16(handle, p);
2025 pp = p + 8;
2026 STREAM_TO_UINT16(ediv, pp);
2027
2028 btm_ble_ltk_request(handle, p, ediv);
2029 /* This is empty until an upper layer cares about returning event */
2030 }
2031 #endif ///BLE_INCLUDED == 1 && SMP_INCLUDED == 1
2032
2033
btu_ble_data_length_change_evt(UINT8 * p,UINT16 evt_len)2034 static void btu_ble_data_length_change_evt(UINT8 *p, UINT16 evt_len)
2035 {
2036 UINT16 handle;
2037 UINT16 tx_data_len;
2038 UINT16 rx_data_len;
2039
2040 if (!controller_get_interface()->supports_ble_packet_extension()) {
2041 HCI_TRACE_WARNING("%s, request not supported", __FUNCTION__);
2042 return;
2043 }
2044
2045 STREAM_TO_UINT16(handle, p);
2046 STREAM_TO_UINT16(tx_data_len, p);
2047 p += 2; /* Skip the TxTimer */
2048 STREAM_TO_UINT16(rx_data_len, p);
2049
2050 l2cble_process_data_length_change_event(handle, tx_data_len, rx_data_len);
2051 }
2052 #if (BLE_50_FEATURE_SUPPORT == 1)
btu_ble_phy_update_complete_evt(UINT8 * p)2053 static void btu_ble_phy_update_complete_evt(UINT8 *p)
2054 {
2055 if (!p) {
2056 HCI_TRACE_ERROR("%s, Invalid params.", __func__);
2057 return;
2058 }
2059 tBTM_BLE_UPDATE_PHY update_phy = {0};
2060 STREAM_TO_UINT8(update_phy.status, p);
2061 STREAM_TO_UINT16(update_phy.conn_idx, p);
2062 STREAM_TO_UINT8(update_phy.tx_phy, p);
2063 STREAM_TO_UINT8(update_phy.rx_phy, p);
2064
2065 btm_ble_update_phy_evt(&update_phy);
2066 }
2067
btu_ble_ext_adv_report_evt(UINT8 * p,UINT16 evt_len)2068 static void btu_ble_ext_adv_report_evt(UINT8 *p, UINT16 evt_len)
2069 {
2070 tBTM_BLE_EXT_ADV_REPORT ext_adv_report = {0};
2071 UINT8 num_reports = {0};
2072 //UINT8 legacy_event_type = 0;
2073 UINT16 evt_type = 0;
2074 uint8_t addr_type;
2075 BD_ADDR bda;
2076
2077 if (!p) {
2078 HCI_TRACE_ERROR("%s, Invalid params.", __func__);
2079 return;
2080 }
2081
2082 STREAM_TO_UINT8(num_reports, p);
2083
2084 if (num_reports == 0) {
2085 HCI_TRACE_ERROR("%s, Invalid number reports is 0", __func__);
2086 }
2087
2088 while (num_reports--) {
2089 STREAM_TO_UINT16(evt_type, p);
2090 ext_adv_report.event_type = evt_type & 0x1F;
2091 if(ext_adv_report.event_type & BTM_BLE_ADV_LEGACY_MASK) {
2092 ext_adv_report.data_status = BTM_BLE_EXT_ADV_DATA_COMPLETE;
2093 } else {
2094 switch(evt_type & BTM_BLE_ADV_DATA_STATUS_MASK) {
2095 case BTM_BLE_ADV_DATA_COMPLETE_MASK:
2096 ext_adv_report.data_status = BTM_BLE_EXT_ADV_DATA_COMPLETE;
2097 break;
2098 case BTM_BLE_ADV_DATA_INCOMPLETE_MASK:
2099 ext_adv_report.data_status = BTM_BLE_EXT_ADV_DATA_INCOMPLETE;
2100 break;
2101 case BTM_BLE_ADV_DATA_TRUNCATED_MASK:
2102 ext_adv_report.data_status = BTM_BLE_EXT_ADV_DATA_TRUNCATED;
2103 break;
2104 }
2105 }
2106
2107 STREAM_TO_UINT8(addr_type, p);
2108 STREAM_TO_BDADDR(bda, p);
2109 // If it is an anonymous adv, skip address resolution
2110 if(addr_type != 0xFF) {
2111 #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == 1)
2112 btm_identity_addr_to_random_pseudo(bda, &addr_type, 0);
2113 #endif
2114 }
2115 ext_adv_report.addr_type = addr_type;
2116 memcpy(ext_adv_report.addr, bda, 6);
2117 STREAM_TO_UINT8(ext_adv_report.primary_phy, p);
2118 STREAM_TO_UINT8(ext_adv_report.secondry_phy, p);
2119 STREAM_TO_UINT8(ext_adv_report.sid, p);
2120 STREAM_TO_UINT8(ext_adv_report.tx_power, p);
2121 STREAM_TO_UINT8(ext_adv_report.rssi, p);
2122 STREAM_TO_UINT16(ext_adv_report.per_adv_interval, p);
2123 STREAM_TO_UINT8(ext_adv_report.dir_addr_type, p);
2124 STREAM_TO_BDADDR(ext_adv_report.dir_addr, p);
2125 STREAM_TO_UINT8(ext_adv_report.adv_data_len, p);
2126 ext_adv_report.adv_data = p;
2127 btm_ble_ext_adv_report_evt(&ext_adv_report);
2128 p += ext_adv_report.adv_data_len;
2129 }
2130
2131 }
2132
btu_ble_periodic_adv_sync_establish_evt(UINT8 * p)2133 static void btu_ble_periodic_adv_sync_establish_evt(UINT8 *p)
2134 {
2135 tBTM_BLE_PERIOD_ADV_SYNC_ESTAB sync_estab = {0};
2136
2137 if (!p) {
2138 HCI_TRACE_ERROR("%s, Invalid params.", __func__);
2139 return;
2140 }
2141
2142 STREAM_TO_UINT8(sync_estab.status, p);
2143 STREAM_TO_UINT16(sync_estab.sync_handle, p);
2144 STREAM_TO_UINT8(sync_estab.sid, p);
2145 STREAM_TO_UINT8(sync_estab.adv_addr_type, p);
2146 STREAM_TO_BDADDR(sync_estab.adv_addr, p);
2147 STREAM_TO_UINT8(sync_estab.adv_phy, p);
2148 STREAM_TO_UINT16(sync_estab.period_adv_interval, p);
2149 STREAM_TO_UINT8(sync_estab.adv_clk_accuracy, p);
2150
2151 btm_ble_periodic_adv_sync_establish_evt(&sync_estab);
2152 }
2153
btu_ble_periodic_adv_report_evt(UINT8 * p,UINT8 evt_len)2154 static void btu_ble_periodic_adv_report_evt(UINT8 *p, UINT8 evt_len)
2155 {
2156 tBTM_PERIOD_ADV_REPORT adv_report = {0};
2157 /* This parameter is intended to be used in a future feature. */
2158 UINT8 unused = 0;
2159
2160 if (!p) {
2161 HCI_TRACE_ERROR("%s, Invalid params.", __func__);
2162 return;
2163 }
2164
2165 if (evt_len < sizeof(tBTM_PERIOD_ADV_REPORT)) {
2166 HCI_TRACE_ERROR("%s, Invalid params, the adv len is to short.", __func__);
2167 return;
2168 }
2169
2170 STREAM_TO_UINT16(adv_report.sync_handle, p);
2171 STREAM_TO_UINT8(adv_report.tx_power, p);
2172 STREAM_TO_UINT8(adv_report.rssi, p);
2173 STREAM_TO_UINT8(unused, p);
2174 STREAM_TO_UINT8(adv_report.data_status, p);
2175 STREAM_TO_UINT8(adv_report.data_length, p);
2176
2177 if (evt_len <= adv_report.data_length) {
2178 HCI_TRACE_ERROR("%s, Invalid ev_len = %d is less than adv len = %d", __func__, evt_len, adv_report.data_length);
2179 return;
2180 }
2181
2182 adv_report.data = p;
2183
2184 btm_ble_periodic_adv_report_evt(&adv_report);
2185
2186 UNUSED(unused);
2187 }
2188
btu_ble_periodic_adv_sync_lost_evt(UINT8 * p)2189 static void btu_ble_periodic_adv_sync_lost_evt(UINT8 *p)
2190 {
2191 tBTM_BLE_PERIOD_ADV_SYNC_LOST sync_lost = {0};
2192 if (!p) {
2193 HCI_TRACE_ERROR("%s, Invalid params.", __func__);
2194 return;
2195 }
2196
2197 STREAM_TO_UINT16(sync_lost.sync_handle, p);
2198
2199 btm_ble_periodic_adv_sync_lost_evt(&sync_lost);
2200 }
2201
btu_ble_scan_timeout_evt(UINT8 * p)2202 static void btu_ble_scan_timeout_evt(UINT8 *p)
2203 {
2204 UNUSED(p);
2205
2206 btm_ble_scan_timeout_evt();
2207 }
2208
btu_ble_adv_set_terminate_evt(UINT8 * p)2209 static void btu_ble_adv_set_terminate_evt(UINT8 *p)
2210 {
2211 tBTM_BLE_ADV_TERMINAT adv_term = {0};
2212
2213 if (!p) {
2214 HCI_TRACE_ERROR("%s, Invalid params.", __func__);
2215 return;
2216 }
2217
2218 STREAM_TO_UINT8(adv_term.status, p);
2219 STREAM_TO_UINT8(adv_term.adv_handle, p);
2220 STREAM_TO_UINT16(adv_term.conn_handle, p);
2221 STREAM_TO_UINT8(adv_term.completed_event, p);
2222
2223 btm_ble_adv_set_terminated_evt(&adv_term);
2224 }
2225
btu_ble_scan_req_received_evt(UINT8 * p)2226 static void btu_ble_scan_req_received_evt(UINT8 *p)
2227 {
2228 tBTM_BLE_SCAN_REQ_RECEIVED req_received = {0};
2229
2230 if (!p) {
2231 HCI_TRACE_ERROR("%s, Invalid params.", __func__);
2232 return;
2233 }
2234
2235 STREAM_TO_UINT8(req_received.adv_handle, p);
2236 STREAM_TO_UINT8(req_received.scan_addr_type, p);
2237 STREAM_TO_BDADDR(req_received.scan_addr, p);
2238
2239 btm_ble_scan_req_received_evt(&req_received);
2240 }
2241 #endif // #if (BLE_50_FEATURE_SUPPORT == 1)
2242 /**********************************************
2243 ** End of BLE Events Handler
2244 ***********************************************/
2245 #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == 1)
btu_ble_rc_param_req_evt(UINT8 * p)2246 static void btu_ble_rc_param_req_evt(UINT8 *p)
2247 {
2248 UINT16 handle;
2249 UINT16 int_min, int_max, latency, timeout;
2250
2251 STREAM_TO_UINT16(handle, p);
2252 STREAM_TO_UINT16(int_min, p);
2253 STREAM_TO_UINT16(int_max, p);
2254 STREAM_TO_UINT16(latency, p);
2255 STREAM_TO_UINT16(timeout, p);
2256
2257 l2cble_process_rc_param_request_evt(handle, int_min, int_max, latency, timeout);
2258 }
2259 #endif /* BLE_LLT_INCLUDED */
2260 #endif /* BLE_INCLUDED */
2261