1 /******************************************************************************
3 * Copyright (C) 1999-2012 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
19 /******************************************************************************
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
26 ******************************************************************************/
28 #define LOG_TAG "bt_btu_hcif"
40 #include "device/include/controller.h"
42 #include "hci_layer.h"
46 #include "osi/include/log.h"
48 // TODO(zachoverflow): remove this horrible hack
50 extern fixed_queue_t *btu_hci_msg_queue;
52 extern void btm_process_cancel_complete(UINT8 status, UINT8 mode);
53 extern void btm_ble_test_command_complete(UINT8 *p);
55 /********************************************************************************/
56 /* L O C A L F U N C T I O N P R O T O T Y P E S */
57 /********************************************************************************/
58 static void btu_hcif_inquiry_comp_evt (UINT8 *p);
59 static void btu_hcif_inquiry_result_evt (UINT8 *p);
60 static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p);
61 static void btu_hcif_extended_inquiry_result_evt (UINT8 *p);
63 static void btu_hcif_connection_comp_evt (UINT8 *p);
64 static void btu_hcif_connection_request_evt (UINT8 *p);
65 static void btu_hcif_disconnection_comp_evt (UINT8 *p);
66 static void btu_hcif_authentication_comp_evt (UINT8 *p);
67 static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len);
68 static void btu_hcif_encryption_change_evt (UINT8 *p);
69 static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p);
70 static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p);
71 static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p);
72 static void btu_hcif_qos_setup_comp_evt (UINT8 *p);
73 static void btu_hcif_command_complete_evt (BT_HDR *response, void *context);
74 static void btu_hcif_command_status_evt (uint8_t status, BT_HDR *command, void *context);
75 static void btu_hcif_hardware_error_evt (UINT8 *p);
76 static void btu_hcif_flush_occured_evt (void);
77 static void btu_hcif_role_change_evt (UINT8 *p);
78 static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p);
79 static void btu_hcif_mode_change_evt (UINT8 *p);
80 static void btu_hcif_pin_code_request_evt (UINT8 *p);
81 static void btu_hcif_link_key_request_evt (UINT8 *p);
82 static void btu_hcif_link_key_notification_evt (UINT8 *p);
83 static void btu_hcif_loopback_command_evt (void);
84 static void btu_hcif_data_buf_overflow_evt (void);
85 static void btu_hcif_max_slots_changed_evt (void);
86 static void btu_hcif_read_clock_off_comp_evt (UINT8 *p);
87 static void btu_hcif_conn_pkt_type_change_evt (void);
88 static void btu_hcif_qos_violation_evt (UINT8 *p);
89 static void btu_hcif_page_scan_mode_change_evt (void);
90 static void btu_hcif_page_scan_rep_mode_chng_evt (void);
91 static void btu_hcif_esco_connection_comp_evt(UINT8 *p);
92 static void btu_hcif_esco_connection_chg_evt(UINT8 *p);
94 /* Simple Pairing Events */
95 static void btu_hcif_host_support_evt (UINT8 *p);
96 static void btu_hcif_io_cap_request_evt (UINT8 *p);
97 static void btu_hcif_io_cap_response_evt (UINT8 *p);
98 static void btu_hcif_user_conf_request_evt (UINT8 *p);
99 static void btu_hcif_user_passkey_request_evt (UINT8 *p);
100 static void btu_hcif_user_passkey_notif_evt (UINT8 *p);
101 static void btu_hcif_keypress_notif_evt (UINT8 *p);
103 #if BTM_OOB_INCLUDED == TRUE
104 static void btu_hcif_rem_oob_request_evt (UINT8 *p);
107 static void btu_hcif_simple_pair_complete_evt (UINT8 *p);
108 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
109 static void btu_hcif_enhanced_flush_complete_evt (void);
112 #if (BTM_SSR_INCLUDED == TRUE)
113 static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len);
114 #endif /* BTM_SSR_INCLUDED == TRUE */
116 #if BLE_INCLUDED == TRUE
117 static void btu_ble_ll_conn_complete_evt (UINT8 *p, UINT16 evt_len);
118 static void btu_ble_process_adv_pkt (UINT8 *p);
119 static void btu_ble_read_remote_feat_evt (UINT8 *p);
120 static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len);
121 static void btu_ble_proc_ltk_req (UINT8 *p);
122 static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p);
123 static void btu_ble_data_length_change_evt (UINT8 *p, UINT16 evt_len);
124 #if (BLE_LLT_INCLUDED == TRUE)
125 static void btu_ble_rc_param_req_evt(UINT8 *p);
127 #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
128 static void btu_ble_proc_enhanced_conn_cmpl (UINT8 *p, UINT16 evt_len);
133 /*******************************************************************************
135 ** Function btu_hcif_process_event
137 ** Description This function is called when an event is received from
138 ** the Host Controller.
142 *******************************************************************************/
143 void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg)
145 UINT8 *p = (UINT8 *)(p_msg + 1) + p_msg->offset;
146 UINT8 hci_evt_code, hci_evt_len;
147 #if BLE_INCLUDED == TRUE
150 STREAM_TO_UINT8 (hci_evt_code, p);
151 STREAM_TO_UINT8 (hci_evt_len, p);
153 switch (hci_evt_code)
155 case HCI_INQUIRY_COMP_EVT:
156 btu_hcif_inquiry_comp_evt (p);
158 case HCI_INQUIRY_RESULT_EVT:
159 btu_hcif_inquiry_result_evt (p);
161 case HCI_INQUIRY_RSSI_RESULT_EVT:
162 btu_hcif_inquiry_rssi_result_evt (p);
164 case HCI_EXTENDED_INQUIRY_RESULT_EVT:
165 btu_hcif_extended_inquiry_result_evt (p);
167 case HCI_CONNECTION_COMP_EVT:
168 btu_hcif_connection_comp_evt (p);
170 case HCI_CONNECTION_REQUEST_EVT:
171 btu_hcif_connection_request_evt (p);
173 case HCI_DISCONNECTION_COMP_EVT:
174 btu_hcif_disconnection_comp_evt (p);
176 case HCI_AUTHENTICATION_COMP_EVT:
177 btu_hcif_authentication_comp_evt (p);
179 case HCI_RMT_NAME_REQUEST_COMP_EVT:
180 btu_hcif_rmt_name_request_comp_evt (p, hci_evt_len);
182 case HCI_ENCRYPTION_CHANGE_EVT:
183 btu_hcif_encryption_change_evt (p);
185 #if BLE_INCLUDED == TRUE
186 case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT:
187 btu_hcif_encryption_key_refresh_cmpl_evt(p);
190 case HCI_READ_RMT_FEATURES_COMP_EVT:
191 btu_hcif_read_rmt_features_comp_evt (p);
193 case HCI_READ_RMT_EXT_FEATURES_COMP_EVT:
194 btu_hcif_read_rmt_ext_features_comp_evt (p);
196 case HCI_READ_RMT_VERSION_COMP_EVT:
197 btu_hcif_read_rmt_version_comp_evt (p);
199 case HCI_QOS_SETUP_COMP_EVT:
200 btu_hcif_qos_setup_comp_evt (p);
202 case HCI_COMMAND_COMPLETE_EVT:
203 LOG_ERROR(LOG_TAG, "%s should not have received a command complete event. "
204 "Someone didn't go through the hci transmit_command function.", __func__);
206 case HCI_COMMAND_STATUS_EVT:
207 LOG_ERROR(LOG_TAG, "%s should not have received a command status event. "
208 "Someone didn't go through the hci transmit_command function.", __func__);
210 case HCI_HARDWARE_ERROR_EVT:
211 btu_hcif_hardware_error_evt (p);
213 case HCI_FLUSH_OCCURED_EVT:
214 btu_hcif_flush_occured_evt ();
216 case HCI_ROLE_CHANGE_EVT:
217 btu_hcif_role_change_evt (p);
219 case HCI_NUM_COMPL_DATA_PKTS_EVT:
220 btu_hcif_num_compl_data_pkts_evt (p);
222 case HCI_MODE_CHANGE_EVT:
223 btu_hcif_mode_change_evt (p);
225 case HCI_PIN_CODE_REQUEST_EVT:
226 btu_hcif_pin_code_request_evt (p);
228 case HCI_LINK_KEY_REQUEST_EVT:
229 btu_hcif_link_key_request_evt (p);
231 case HCI_LINK_KEY_NOTIFICATION_EVT:
232 btu_hcif_link_key_notification_evt (p);
234 case HCI_LOOPBACK_COMMAND_EVT:
235 btu_hcif_loopback_command_evt ();
237 case HCI_DATA_BUF_OVERFLOW_EVT:
238 btu_hcif_data_buf_overflow_evt ();
240 case HCI_MAX_SLOTS_CHANGED_EVT:
241 btu_hcif_max_slots_changed_evt ();
243 case HCI_READ_CLOCK_OFF_COMP_EVT:
244 btu_hcif_read_clock_off_comp_evt (p);
246 case HCI_CONN_PKT_TYPE_CHANGE_EVT:
247 btu_hcif_conn_pkt_type_change_evt ();
249 case HCI_QOS_VIOLATION_EVT:
250 btu_hcif_qos_violation_evt (p);
252 case HCI_PAGE_SCAN_MODE_CHANGE_EVT:
253 btu_hcif_page_scan_mode_change_evt ();
255 case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT:
256 btu_hcif_page_scan_rep_mode_chng_evt ();
258 case HCI_ESCO_CONNECTION_COMP_EVT:
259 btu_hcif_esco_connection_comp_evt (p);
261 case HCI_ESCO_CONNECTION_CHANGED_EVT:
262 btu_hcif_esco_connection_chg_evt (p);
264 #if (BTM_SSR_INCLUDED == TRUE)
265 case HCI_SNIFF_SUB_RATE_EVT:
266 btu_hcif_ssr_evt (p, hci_evt_len);
268 #endif /* BTM_SSR_INCLUDED == TRUE */
269 case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT:
270 btu_hcif_host_support_evt (p);
272 case HCI_IO_CAPABILITY_REQUEST_EVT:
273 btu_hcif_io_cap_request_evt (p);
275 case HCI_IO_CAPABILITY_RESPONSE_EVT:
276 btu_hcif_io_cap_response_evt (p);
278 case HCI_USER_CONFIRMATION_REQUEST_EVT:
279 btu_hcif_user_conf_request_evt (p);
281 case HCI_USER_PASSKEY_REQUEST_EVT:
282 btu_hcif_user_passkey_request_evt (p);
284 #if BTM_OOB_INCLUDED == TRUE
285 case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
286 btu_hcif_rem_oob_request_evt (p);
289 case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
290 btu_hcif_simple_pair_complete_evt (p);
292 case HCI_USER_PASSKEY_NOTIFY_EVT:
293 btu_hcif_user_passkey_notif_evt (p);
295 case HCI_KEYPRESS_NOTIFY_EVT:
296 btu_hcif_keypress_notif_evt (p);
298 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
299 case HCI_ENHANCED_FLUSH_COMPLETE_EVT:
300 btu_hcif_enhanced_flush_complete_evt ();
304 #if (BLE_INCLUDED == TRUE)
306 STREAM_TO_UINT8 (ble_sub_code, p);
308 HCI_TRACE_EVENT("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code, ble_sub_code);
310 switch (ble_sub_code)
312 case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */
313 btu_ble_process_adv_pkt(p);
315 case HCI_BLE_CONN_COMPLETE_EVT:
316 btu_ble_ll_conn_complete_evt(p, hci_evt_len);
318 case HCI_BLE_LL_CONN_PARAM_UPD_EVT:
319 btu_ble_ll_conn_param_upd_evt(p, hci_evt_len);
321 case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT:
322 btu_ble_read_remote_feat_evt(p);
324 case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */
325 btu_ble_proc_ltk_req(p);
327 #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
328 case HCI_BLE_ENHANCED_CONN_COMPLETE_EVT:
329 btu_ble_proc_enhanced_conn_cmpl(p, hci_evt_len);
332 #if (BLE_LLT_INCLUDED == TRUE)
333 case HCI_BLE_RC_PARAM_REQ_EVT:
334 btu_ble_rc_param_req_evt(p);
337 case HCI_BLE_DATA_LENGTH_CHANGE_EVT:
338 btu_ble_data_length_change_evt(p, hci_evt_len);
342 #endif /* BLE_INCLUDED */
343 case HCI_VENDOR_SPECIFIC_EVT:
344 btm_vendor_specific_evt (p, hci_evt_len);
349 /*******************************************************************************
351 ** Function btu_hcif_send_cmd
353 ** Description This function is called to send commands to the Host Controller.
357 *******************************************************************************/
358 void btu_hcif_send_cmd (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_buf)
364 uint8_t *stream = p_buf->data + p_buf->offset;
365 void * vsc_callback = NULL;
367 STREAM_TO_UINT16(opcode, stream);
369 // Eww...horrible hackery here
370 /* If command was a VSC, then extract command_complete callback */
371 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC
372 #if BLE_INCLUDED == TRUE
373 || (opcode == HCI_BLE_RAND)
374 || (opcode == HCI_BLE_ENCRYPT)
377 vsc_callback = *((void **)(p_buf + 1));
380 hci_layer_get_interface()->transmit_command(
382 btu_hcif_command_complete_evt,
383 btu_hcif_command_status_evt,
386 #if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
387 btu_check_bt_sleep ();
391 /*******************************************************************************
393 ** Function btu_hcif_send_host_rdy_for_data
395 ** Description This function is called to check if it can send commands
396 ** to the Host Controller. It may be passed the address of
401 *******************************************************************************/
402 void btu_hcif_send_host_rdy_for_data(void)
404 UINT16 num_pkts[MAX_L2CAP_LINKS + 4]; /* 3 SCO connections */
405 UINT16 handles[MAX_L2CAP_LINKS + 4];
408 /* Get the L2CAP numbers */
409 num_ents = l2c_link_pkts_rcvd (num_pkts, handles);
411 /* Get the SCO numbers */
412 /* No SCO for now ?? */
416 btsnd_hcic_host_num_xmitted_pkts (num_ents, handles, num_pkts);
420 /*******************************************************************************
422 ** Function btu_hcif_inquiry_comp_evt
424 ** Description Process event HCI_INQUIRY_COMP_EVT
428 *******************************************************************************/
429 static void btu_hcif_inquiry_comp_evt (UINT8 *p)
433 STREAM_TO_UINT8 (status, p);
435 /* Tell inquiry processing that we are done */
436 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
439 /*******************************************************************************
441 ** Function btu_hcif_inquiry_result_evt
443 ** Description Process event HCI_INQUIRY_RESULT_EVT
447 *******************************************************************************/
448 static void btu_hcif_inquiry_result_evt (UINT8 *p)
450 /* Store results in the cache */
451 btm_process_inq_results (p, BTM_INQ_RESULT_STANDARD);
454 /*******************************************************************************
456 ** Function btu_hcif_inquiry_rssi_result_evt
458 ** Description Process event HCI_INQUIRY_RSSI_RESULT_EVT
462 *******************************************************************************/
463 static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p)
465 /* Store results in the cache */
466 btm_process_inq_results (p, BTM_INQ_RESULT_WITH_RSSI);
469 /*******************************************************************************
471 ** Function btu_hcif_extended_inquiry_result_evt
473 ** Description Process event HCI_EXTENDED_INQUIRY_RESULT_EVT
477 *******************************************************************************/
478 static void btu_hcif_extended_inquiry_result_evt (UINT8 *p)
480 /* Store results in the cache */
481 btm_process_inq_results (p, BTM_INQ_RESULT_EXTENDED);
484 /*******************************************************************************
486 ** Function btu_hcif_connection_comp_evt
488 ** Description Process event HCI_CONNECTION_COMP_EVT
492 *******************************************************************************/
493 static void btu_hcif_connection_comp_evt (UINT8 *p)
500 #if BTM_SCO_INCLUDED == TRUE
501 tBTM_ESCO_DATA esco_data;
504 STREAM_TO_UINT8 (status, p);
505 STREAM_TO_UINT16 (handle, p);
506 STREAM_TO_BDADDR (bda, p);
507 STREAM_TO_UINT8 (link_type, p);
508 STREAM_TO_UINT8 (enc_mode, p);
510 handle = HCID_GET_HANDLE (handle);
512 if (link_type == HCI_LINK_TYPE_ACL)
514 btm_sec_connected (bda, handle, status, enc_mode);
516 l2c_link_hci_conn_comp (status, handle, bda);
518 #if BTM_SCO_INCLUDED == TRUE
521 memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA));
522 /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */
523 memcpy (esco_data.bd_addr, bda, BD_ADDR_LEN);
524 btm_sco_connected (status, bda, handle, &esco_data);
526 #endif /* BTM_SCO_INCLUDED */
529 /*******************************************************************************
531 ** Function btu_hcif_connection_request_evt
533 ** Description Process event HCI_CONNECTION_REQUEST_EVT
537 *******************************************************************************/
538 static void btu_hcif_connection_request_evt (UINT8 *p)
544 STREAM_TO_BDADDR (bda, p);
545 STREAM_TO_DEVCLASS (dc, p);
546 STREAM_TO_UINT8 (link_type, p);
548 /* Pass request to security manager to check connect filters before */
549 /* passing request to l2cap */
550 if (link_type == HCI_LINK_TYPE_ACL)
552 btm_sec_conn_req (bda, dc);
554 #if BTM_SCO_INCLUDED == TRUE
557 btm_sco_conn_req (bda, dc, link_type);
559 #endif /* BTM_SCO_INCLUDED */
562 /*******************************************************************************
564 ** Function btu_hcif_disconnection_comp_evt
566 ** Description Process event HCI_DISCONNECTION_COMP_EVT
570 *******************************************************************************/
571 static void btu_hcif_disconnection_comp_evt (UINT8 *p)
577 STREAM_TO_UINT16 (handle, p);
578 STREAM_TO_UINT8 (reason, p);
580 handle = HCID_GET_HANDLE (handle);
582 #if BTM_SCO_INCLUDED == TRUE
583 /* If L2CAP doesn't know about it, send it to SCO */
584 if (!l2c_link_hci_disc_comp (handle, reason))
585 btm_sco_removed (handle, reason);
587 l2c_link_hci_disc_comp (handle, reason);
588 #endif /* BTM_SCO_INCLUDED */
590 /* Notify security manager */
591 btm_sec_disconnected (handle, reason);
594 /*******************************************************************************
596 ** Function btu_hcif_authentication_comp_evt
598 ** Description Process event HCI_AUTHENTICATION_COMP_EVT
602 *******************************************************************************/
603 static void btu_hcif_authentication_comp_evt (UINT8 *p)
608 STREAM_TO_UINT8 (status, p);
609 STREAM_TO_UINT16 (handle, p);
611 btm_sec_auth_complete (handle, status);
614 /*******************************************************************************
616 ** Function btu_hcif_rmt_name_request_comp_evt
618 ** Description Process event HCI_RMT_NAME_REQUEST_COMP_EVT
622 *******************************************************************************/
623 static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len)
628 STREAM_TO_UINT8 (status, p);
629 STREAM_TO_BDADDR (bd_addr, p);
631 evt_len -= (1 + BD_ADDR_LEN);
633 btm_process_remote_name (bd_addr, p, evt_len, status);
635 btm_sec_rmt_name_request_complete (bd_addr, p, status);
638 /*******************************************************************************
640 ** Function btu_hcif_encryption_change_evt
642 ** Description Process event HCI_ENCRYPTION_CHANGE_EVT
646 *******************************************************************************/
647 static void btu_hcif_encryption_change_evt (UINT8 *p)
653 STREAM_TO_UINT8 (status, p);
654 STREAM_TO_UINT16 (handle, p);
655 STREAM_TO_UINT8 (encr_enable, p);
657 btm_acl_encrypt_change (handle, status, encr_enable);
658 btm_sec_encrypt_change (handle, status, encr_enable);
661 /*******************************************************************************
663 ** Function btu_hcif_read_rmt_features_comp_evt
665 ** Description Process event HCI_READ_RMT_FEATURES_COMP_EVT
669 *******************************************************************************/
670 static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p)
672 btm_read_remote_features_complete(p);
675 /*******************************************************************************
677 ** Function btu_hcif_read_rmt_ext_features_comp_evt
679 ** Description Process event HCI_READ_RMT_EXT_FEATURES_COMP_EVT
683 *******************************************************************************/
684 static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p)
690 STREAM_TO_UINT8 (status, p_cur);
692 if (status == HCI_SUCCESS)
693 btm_read_remote_ext_features_complete(p);
696 STREAM_TO_UINT16 (handle, p_cur);
697 btm_read_remote_ext_features_failed(status, handle);
701 /*******************************************************************************
703 ** Function btu_hcif_read_rmt_version_comp_evt
705 ** Description Process event HCI_READ_RMT_VERSION_COMP_EVT
709 *******************************************************************************/
710 static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p)
712 btm_read_remote_version_complete (p);
715 /*******************************************************************************
717 ** Function btu_hcif_qos_setup_comp_evt
719 ** Description Process event HCI_QOS_SETUP_COMP_EVT
723 *******************************************************************************/
724 static void btu_hcif_qos_setup_comp_evt (UINT8 *p)
730 STREAM_TO_UINT8 (status, p);
731 STREAM_TO_UINT16 (handle, p);
732 STREAM_TO_UINT8 (flow.qos_flags, p);
733 STREAM_TO_UINT8 (flow.service_type, p);
734 STREAM_TO_UINT32 (flow.token_rate, p);
735 STREAM_TO_UINT32 (flow.peak_bandwidth, p);
736 STREAM_TO_UINT32 (flow.latency, p);
737 STREAM_TO_UINT32 (flow.delay_variation, p);
739 btm_qos_setup_complete(status, handle, &flow);
742 /*******************************************************************************
744 ** Function btu_hcif_esco_connection_comp_evt
746 ** Description Process event HCI_ESCO_CONNECTION_COMP_EVT
750 *******************************************************************************/
751 static void btu_hcif_esco_connection_comp_evt (UINT8 *p)
753 #if BTM_SCO_INCLUDED == TRUE
759 STREAM_TO_UINT8 (status, p);
760 STREAM_TO_UINT16 (handle, p);
761 STREAM_TO_BDADDR (bda, p);
763 STREAM_TO_UINT8 (data.link_type, p);
764 STREAM_TO_UINT8 (data.tx_interval, p);
765 STREAM_TO_UINT8 (data.retrans_window, p);
766 STREAM_TO_UINT16 (data.rx_pkt_len, p);
767 STREAM_TO_UINT16 (data.tx_pkt_len, p);
768 STREAM_TO_UINT8 (data.air_mode, p);
770 memcpy (data.bd_addr, bda, BD_ADDR_LEN);
771 btm_sco_connected (status, bda, handle, &data);
775 /*******************************************************************************
777 ** Function btu_hcif_esco_connection_chg_evt
779 ** Description Process event HCI_ESCO_CONNECTION_CHANGED_EVT
783 *******************************************************************************/
784 static void btu_hcif_esco_connection_chg_evt (UINT8 *p)
786 #if BTM_SCO_INCLUDED == TRUE
792 UINT8 retrans_window;
794 STREAM_TO_UINT8 (status, p);
795 STREAM_TO_UINT16 (handle, p);
797 STREAM_TO_UINT8 (tx_interval, p);
798 STREAM_TO_UINT8 (retrans_window, p);
799 STREAM_TO_UINT16 (rx_pkt_len, p);
800 STREAM_TO_UINT16 (tx_pkt_len, p);
802 btm_esco_proc_conn_chg (status, handle, tx_interval, retrans_window,
803 rx_pkt_len, tx_pkt_len);
807 /*******************************************************************************
809 ** Function btu_hcif_hdl_command_complete
811 ** Description Handle command complete event
815 *******************************************************************************/
816 static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_len,
821 case HCI_INQUIRY_CANCEL:
822 /* Tell inquiry processing that we are done */
823 btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK);
825 case HCI_SET_EVENT_FILTER:
826 btm_event_filter_complete (p);
829 case HCI_DELETE_STORED_LINK_KEY:
830 btm_delete_stored_link_key_complete (p);
833 case HCI_READ_LOCAL_NAME:
834 btm_read_local_name_complete (p, evt_len);
837 case HCI_GET_LINK_QUALITY:
838 btm_read_link_quality_complete (p);
842 btm_read_rssi_complete (p);
845 case HCI_READ_TRANSMIT_POWER_LEVEL:
846 btm_read_tx_power_complete(p, FALSE);
849 case HCI_CREATE_CONNECTION_CANCEL:
850 btm_create_conn_cancel_complete(p);
853 case HCI_READ_LOCAL_OOB_DATA:
854 #if BTM_OOB_INCLUDED == TRUE
855 btm_read_local_oob_complete(p);
859 case HCI_READ_INQ_TX_POWER_LEVEL:
860 btm_read_linq_tx_power_complete (p);
863 #if (BLE_INCLUDED == TRUE)
864 /* BLE Commands sComplete*/
865 case HCI_BLE_ADD_WHITE_LIST:
866 btm_ble_add_2_white_list_complete(*p);
869 case HCI_BLE_CLEAR_WHITE_LIST:
870 btm_ble_clear_white_list_complete(p, evt_len);
873 case HCI_BLE_REMOVE_WHITE_LIST:
874 btm_ble_remove_from_white_list_complete(p, evt_len);
878 case HCI_BLE_ENCRYPT:
879 btm_ble_rand_enc_complete (p, opcode, (tBTM_RAND_ENC_CB *)p_cplt_cback);
882 case HCI_BLE_READ_ADV_CHNL_TX_POWER:
883 btm_read_tx_power_complete(p, TRUE);
886 case HCI_BLE_WRITE_ADV_ENABLE:
887 btm_ble_write_adv_enable_complete(p);
890 case HCI_BLE_CREATE_LL_CONN:
891 btm_ble_create_ll_conn_complete(*p);
894 case HCI_BLE_TRANSMITTER_TEST:
895 case HCI_BLE_RECEIVER_TEST:
896 case HCI_BLE_TEST_END:
897 btm_ble_test_command_complete(p);
900 #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
901 case HCI_BLE_ADD_DEV_RESOLVING_LIST:
902 btm_ble_add_resolving_list_entry_complete(p, evt_len);
905 case HCI_BLE_RM_DEV_RESOLVING_LIST:
906 btm_ble_remove_resolving_list_entry_complete(p, evt_len);
909 case HCI_BLE_CLEAR_RESOLVING_LIST:
910 btm_ble_clear_resolving_list_complete(p, evt_len);
913 case HCI_BLE_READ_RESOLVABLE_ADDR_PEER:
914 btm_ble_read_resolving_list_entry_complete(p, evt_len);
917 case HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL:
918 case HCI_BLE_SET_ADDR_RESOLUTION_ENABLE:
919 case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT:
922 #endif /* (BLE_INCLUDED == TRUE) */
925 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
926 btm_vsc_complete (p, opcode, evt_len, (tBTM_CMPL_CB *)p_cplt_cback);
931 /*******************************************************************************
933 ** Function btu_hcif_command_complete_evt
935 ** Description Process event HCI_COMMAND_COMPLETE_EVT
939 *******************************************************************************/
940 static void btu_hcif_command_complete_evt_on_task(BT_HDR *event)
942 command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0];
944 command_opcode_t opcode;
945 uint8_t *stream = hack->response->data + hack->response->offset + 3; // 2 to skip the event headers, 1 to skip the command credits
946 STREAM_TO_UINT16(opcode, stream);
948 btu_hcif_hdl_command_complete(
951 hack->response->len - 5, // 3 for the command complete headers, 2 for the event headers
954 GKI_freebuf(hack->response);
958 static void btu_hcif_command_complete_evt(BT_HDR *response, void *context)
960 BT_HDR *event = osi_calloc(sizeof(BT_HDR) + sizeof(command_complete_hack_t));
961 command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0];
963 hack->callback = btu_hcif_command_complete_evt_on_task;
964 hack->response = response;
965 hack->context = context;
967 event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK;
969 fixed_queue_enqueue(btu_hci_msg_queue, event);
972 /*******************************************************************************
974 ** Function btu_hcif_hdl_command_status
976 ** Description Handle a command status event
980 *******************************************************************************/
981 static void btu_hcif_hdl_command_status (UINT16 opcode, UINT8 status, UINT8 *p_cmd,
982 void *p_vsc_status_cback)
986 #if BTM_SCO_INCLUDED == TRUE
987 tBTM_ESCO_DATA esco_data;
992 case HCI_EXIT_SNIFF_MODE:
993 case HCI_EXIT_PARK_MODE:
994 #if BTM_SCO_WAKE_PARKED_LINK == TRUE
995 if (status != HCI_SUCCESS)
997 /* Allow SCO initiation to continue if waiting for change mode event */
1000 p_cmd++; /* bypass length field */
1001 STREAM_TO_UINT16 (handle, p_cmd);
1002 btm_sco_chk_pend_unpark (status, handle);
1006 /* Case Falls Through */
1009 case HCI_SNIFF_MODE:
1011 btm_pm_proc_cmd_status(status);
1015 /* If command failed to start, we may need to tell BTM */
1016 if (status != HCI_SUCCESS)
1021 /* Tell inquiry processing that we are done */
1022 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
1025 case HCI_RMT_NAME_REQUEST:
1026 /* Tell inquiry processing that we are done */
1027 btm_process_remote_name (NULL, NULL, 0, status);
1029 btm_sec_rmt_name_request_complete (NULL, NULL, status);
1032 case HCI_QOS_SETUP_COMP_EVT:
1033 /* Tell qos setup that we are done */
1034 btm_qos_setup_complete(status,0,NULL);
1037 case HCI_SWITCH_ROLE:
1038 /* Tell BTM that the command failed */
1039 /* read bd addr out of stored command */
1043 STREAM_TO_BDADDR (bd_addr, p_cmd);
1044 btm_acl_role_changed(status, bd_addr, BTM_ROLE_UNDEFINED);
1047 btm_acl_role_changed(status, NULL, BTM_ROLE_UNDEFINED);
1048 l2c_link_role_changed (NULL, BTM_ROLE_UNDEFINED, HCI_ERR_COMMAND_DISALLOWED);
1051 case HCI_CREATE_CONNECTION:
1052 /* read bd addr out of stored command */
1056 STREAM_TO_BDADDR (bd_addr, p_cmd);
1057 btm_sec_connected (bd_addr, HCI_INVALID_HANDLE, status, 0);
1058 l2c_link_hci_conn_comp (status, HCI_INVALID_HANDLE, bd_addr);
1062 case HCI_READ_RMT_EXT_FEATURES:
1065 p_cmd++; /* skip command length */
1066 STREAM_TO_UINT16 (handle, p_cmd);
1069 handle = HCI_INVALID_HANDLE;
1071 btm_read_remote_ext_features_failed(status, handle);
1074 case HCI_AUTHENTICATION_REQUESTED:
1075 /* Device refused to start authentication. That should be treated as authentication failure. */
1076 btm_sec_auth_complete (BTM_INVALID_HCI_HANDLE, status);
1079 case HCI_SET_CONN_ENCRYPTION:
1080 /* Device refused to start encryption. That should be treated as encryption failure. */
1081 btm_sec_encrypt_change (BTM_INVALID_HCI_HANDLE, status, FALSE);
1084 #if BLE_INCLUDED == TRUE
1085 case HCI_BLE_CREATE_LL_CONN:
1086 btm_ble_create_ll_conn_complete(status);
1090 #if BTM_SCO_INCLUDED == TRUE
1091 case HCI_SETUP_ESCO_CONNECTION:
1092 /* read handle out of stored command */
1096 STREAM_TO_UINT16 (handle, p_cmd);
1098 /* Determine if initial connection failed or is a change of setup */
1099 if (btm_is_sco_active(handle))
1100 btm_esco_proc_conn_chg (status, handle, 0, 0, 0, 0);
1102 btm_sco_connected (status, NULL, handle, &esco_data);
1107 /* This is commented out until an upper layer cares about returning event
1108 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
1109 case HCI_ENHANCED_FLUSH:
1114 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1115 btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback);
1122 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1123 btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback);
1128 /*******************************************************************************
1130 ** Function btu_hcif_command_status_evt
1132 ** Description Process event HCI_COMMAND_STATUS_EVT
1136 *******************************************************************************/
1137 static void btu_hcif_command_status_evt_on_task(BT_HDR *event)
1139 command_status_hack_t *hack = (command_status_hack_t *)&event->data[0];
1141 command_opcode_t opcode;
1142 uint8_t *stream = hack->command->data + hack->command->offset;
1143 STREAM_TO_UINT16(opcode, stream);
1145 btu_hcif_hdl_command_status(
1151 GKI_freebuf(hack->command);
1155 static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *context)
1157 BT_HDR *event = osi_calloc(sizeof(BT_HDR) + sizeof(command_status_hack_t));
1158 command_status_hack_t *hack = (command_status_hack_t *)&event->data[0];
1160 hack->callback = btu_hcif_command_status_evt_on_task;
1161 hack->status = status;
1162 hack->command = command;
1163 hack->context = context;
1165 event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK;
1167 fixed_queue_enqueue(btu_hci_msg_queue, event);
1170 /*******************************************************************************
1172 ** Function btu_hcif_hardware_error_evt
1174 ** Description Process event HCI_HARDWARE_ERROR_EVT
1178 *******************************************************************************/
1179 static void btu_hcif_hardware_error_evt (UINT8 *p)
1181 HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p);
1183 /* If anyone wants device status notifications, give him one. */
1184 btm_report_device_status (BTM_DEV_STATUS_DOWN);
1186 /* Reset the controller */
1187 if (BTM_IsDeviceUp())
1188 BTM_DeviceReset (NULL);
1191 /*******************************************************************************
1193 ** Function btu_hcif_flush_occured_evt
1195 ** Description Process event HCI_FLUSH_OCCURED_EVT
1199 *******************************************************************************/
1200 static void btu_hcif_flush_occured_evt (void)
1204 /*******************************************************************************
1206 ** Function btu_hcif_role_change_evt
1208 ** Description Process event HCI_ROLE_CHANGE_EVT
1212 *******************************************************************************/
1213 static void btu_hcif_role_change_evt (UINT8 *p)
1219 STREAM_TO_UINT8 (status, p);
1220 STREAM_TO_BDADDR (bda, p);
1221 STREAM_TO_UINT8 (role, p);
1223 l2c_link_role_changed (bda, role, status);
1224 btm_acl_role_changed(status, bda, role);
1227 /*******************************************************************************
1229 ** Function btu_hcif_num_compl_data_pkts_evt
1231 ** Description Process event HCI_NUM_COMPL_DATA_PKTS_EVT
1235 *******************************************************************************/
1236 static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p)
1238 /* Process for L2CAP and SCO */
1239 l2c_link_process_num_completed_pkts (p);
1241 /* Send on to SCO */
1242 /*?? No SCO for now */
1245 /*******************************************************************************
1247 ** Function btu_hcif_mode_change_evt
1249 ** Description Process event HCI_MODE_CHANGE_EVT
1253 *******************************************************************************/
1254 static void btu_hcif_mode_change_evt (UINT8 *p)
1261 STREAM_TO_UINT8 (status, p);
1263 STREAM_TO_UINT16 (handle, p);
1264 STREAM_TO_UINT8 (current_mode, p);
1265 STREAM_TO_UINT16 (interval, p);
1266 #if BTM_SCO_WAKE_PARKED_LINK == TRUE
1267 btm_sco_chk_pend_unpark (status, handle);
1269 btm_pm_proc_mode_change (status, handle, current_mode, interval);
1271 #if (HID_DEV_INCLUDED == TRUE) && (HID_DEV_PM_INCLUDED == TRUE)
1272 hidd_pm_proc_mode_change( status, current_mode, interval ) ;
1276 /*******************************************************************************
1278 ** Function btu_hcif_ssr_evt
1280 ** Description Process event HCI_SNIFF_SUB_RATE_EVT
1284 *******************************************************************************/
1285 #if (BTM_SSR_INCLUDED == TRUE)
1286 static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len)
1288 btm_pm_proc_ssr_evt(p, evt_len);
1292 /*******************************************************************************
1294 ** Function btu_hcif_pin_code_request_evt
1296 ** Description Process event HCI_PIN_CODE_REQUEST_EVT
1300 *******************************************************************************/
1301 static void btu_hcif_pin_code_request_evt (UINT8 *p)
1305 STREAM_TO_BDADDR (bda, p);
1307 /* Tell L2CAP that there was a PIN code request, */
1308 /* it may need to stretch timeouts */
1309 l2c_pin_code_request (bda);
1311 btm_sec_pin_code_request (bda);
1314 /*******************************************************************************
1316 ** Function btu_hcif_link_key_request_evt
1318 ** Description Process event HCI_LINK_KEY_REQUEST_EVT
1322 *******************************************************************************/
1323 static void btu_hcif_link_key_request_evt (UINT8 *p)
1327 STREAM_TO_BDADDR (bda, p);
1328 btm_sec_link_key_request (bda);
1331 /*******************************************************************************
1333 ** Function btu_hcif_link_key_notification_evt
1335 ** Description Process event HCI_LINK_KEY_NOTIFICATION_EVT
1339 *******************************************************************************/
1340 static void btu_hcif_link_key_notification_evt (UINT8 *p)
1346 STREAM_TO_BDADDR (bda, p);
1347 STREAM_TO_ARRAY16 (key, p);
1348 STREAM_TO_UINT8 (key_type, p);
1350 btm_sec_link_key_notification (bda, key, key_type);
1353 /*******************************************************************************
1355 ** Function btu_hcif_loopback_command_evt
1357 ** Description Process event HCI_LOOPBACK_COMMAND_EVT
1361 *******************************************************************************/
1362 static void btu_hcif_loopback_command_evt (void)
1366 /*******************************************************************************
1368 ** Function btu_hcif_data_buf_overflow_evt
1370 ** Description Process event HCI_DATA_BUF_OVERFLOW_EVT
1374 *******************************************************************************/
1375 static void btu_hcif_data_buf_overflow_evt (void)
1379 /*******************************************************************************
1381 ** Function btu_hcif_max_slots_changed_evt
1383 ** Description Process event HCI_MAX_SLOTS_CHANGED_EVT
1387 *******************************************************************************/
1388 static void btu_hcif_max_slots_changed_evt (void)
1392 /*******************************************************************************
1394 ** Function btu_hcif_read_clock_off_comp_evt
1396 ** Description Process event HCI_READ_CLOCK_OFF_COMP_EVT
1400 *******************************************************************************/
1401 static void btu_hcif_read_clock_off_comp_evt (UINT8 *p)
1405 UINT16 clock_offset;
1407 STREAM_TO_UINT8 (status, p);
1409 /* If failed to get clock offset just drop the result */
1410 if (status != HCI_SUCCESS)
1413 STREAM_TO_UINT16 (handle, p);
1414 STREAM_TO_UINT16 (clock_offset, p);
1416 handle = HCID_GET_HANDLE (handle);
1418 btm_process_clk_off_comp_evt (handle, clock_offset);
1419 btm_sec_update_clock_offset (handle, clock_offset);
1422 /*******************************************************************************
1424 ** Function btu_hcif_conn_pkt_type_change_evt
1426 ** Description Process event HCI_CONN_PKT_TYPE_CHANGE_EVT
1430 *******************************************************************************/
1431 static void btu_hcif_conn_pkt_type_change_evt (void)
1435 /*******************************************************************************
1437 ** Function btu_hcif_qos_violation_evt
1439 ** Description Process event HCI_QOS_VIOLATION_EVT
1443 *******************************************************************************/
1444 static void btu_hcif_qos_violation_evt (UINT8 *p)
1448 STREAM_TO_UINT16 (handle, p);
1450 handle = HCID_GET_HANDLE (handle);
1452 l2c_link_hci_qos_violation (handle);
1455 /*******************************************************************************
1457 ** Function btu_hcif_page_scan_mode_change_evt
1459 ** Description Process event HCI_PAGE_SCAN_MODE_CHANGE_EVT
1463 *******************************************************************************/
1464 static void btu_hcif_page_scan_mode_change_evt (void)
1468 /*******************************************************************************
1470 ** Function btu_hcif_page_scan_rep_mode_chng_evt
1472 ** Description Process event HCI_PAGE_SCAN_REP_MODE_CHNG_EVT
1476 *******************************************************************************/
1477 static void btu_hcif_page_scan_rep_mode_chng_evt (void)
1481 /**********************************************
1482 ** Simple Pairing Events
1483 ***********************************************/
1485 /*******************************************************************************
1487 ** Function btu_hcif_host_support_evt
1489 ** Description Process event HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT
1493 *******************************************************************************/
1494 static void btu_hcif_host_support_evt (UINT8 *p)
1496 btm_sec_rmt_host_support_feat_evt(p);
1499 /*******************************************************************************
1501 ** Function btu_hcif_io_cap_request_evt
1503 ** Description Process event HCI_IO_CAPABILITY_REQUEST_EVT
1507 *******************************************************************************/
1508 static void btu_hcif_io_cap_request_evt (UINT8 *p)
1510 btm_io_capabilities_req(p);
1513 /*******************************************************************************
1515 ** Function btu_hcif_io_cap_response_evt
1517 ** Description Process event HCI_IO_CAPABILITY_RESPONSE_EVT
1521 *******************************************************************************/
1522 static void btu_hcif_io_cap_response_evt (UINT8 *p)
1524 btm_io_capabilities_rsp(p);
1527 /*******************************************************************************
1529 ** Function btu_hcif_user_conf_request_evt
1531 ** Description Process event HCI_USER_CONFIRMATION_REQUEST_EVT
1535 *******************************************************************************/
1536 static void btu_hcif_user_conf_request_evt (UINT8 *p)
1538 btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p);
1541 /*******************************************************************************
1543 ** Function btu_hcif_user_passkey_request_evt
1545 ** Description Process event HCI_USER_PASSKEY_REQUEST_EVT
1549 *******************************************************************************/
1550 static void btu_hcif_user_passkey_request_evt (UINT8 *p)
1552 btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p);
1555 /*******************************************************************************
1557 ** Function btu_hcif_user_passkey_notif_evt
1559 ** Description Process event HCI_USER_PASSKEY_NOTIFY_EVT
1563 *******************************************************************************/
1564 static void btu_hcif_user_passkey_notif_evt (UINT8 *p)
1566 btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p);
1569 /*******************************************************************************
1571 ** Function btu_hcif_keypress_notif_evt
1573 ** Description Process event HCI_KEYPRESS_NOTIFY_EVT
1577 *******************************************************************************/
1578 static void btu_hcif_keypress_notif_evt (UINT8 *p)
1580 btm_keypress_notif_evt(p);
1583 /*******************************************************************************
1585 ** Function btu_hcif_rem_oob_request_evt
1587 ** Description Process event HCI_REMOTE_OOB_DATA_REQUEST_EVT
1591 *******************************************************************************/
1592 #if BTM_OOB_INCLUDED == TRUE
1593 static void btu_hcif_rem_oob_request_evt (UINT8 *p)
1599 /*******************************************************************************
1601 ** Function btu_hcif_simple_pair_complete_evt
1603 ** Description Process event HCI_SIMPLE_PAIRING_COMPLETE_EVT
1607 *******************************************************************************/
1608 static void btu_hcif_simple_pair_complete_evt (UINT8 *p)
1610 btm_simple_pair_complete(p);
1613 /*******************************************************************************
1615 ** Function btu_hcif_enhanced_flush_complete_evt
1617 ** Description Process event HCI_ENHANCED_FLUSH_COMPLETE_EVT
1621 *******************************************************************************/
1622 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
1623 static void btu_hcif_enhanced_flush_complete_evt (void)
1625 /* This is empty until an upper layer cares about returning event */
1628 /**********************************************
1629 ** End of Simple Pairing Events
1630 ***********************************************/
1632 /**********************************************
1634 ***********************************************/
1635 #if (defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)
1636 static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p)
1639 UINT8 enc_enable = 0;
1642 STREAM_TO_UINT8 (status, p);
1643 STREAM_TO_UINT16 (handle, p);
1645 if (status == HCI_SUCCESS) enc_enable = 1;
1647 btm_sec_encrypt_change (handle, status, enc_enable);
1650 static void btu_ble_process_adv_pkt (UINT8 *p)
1652 HCI_TRACE_EVENT("btu_ble_process_adv_pkt");
1654 btm_ble_process_adv_pkt(p);
1657 static void btu_ble_ll_conn_complete_evt ( UINT8 *p, UINT16 evt_len)
1659 btm_ble_conn_complete(p, evt_len, FALSE);
1661 #if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE)
1662 static void btu_ble_proc_enhanced_conn_cmpl( UINT8 *p, UINT16 evt_len)
1664 btm_ble_conn_complete(p, evt_len, TRUE);
1667 static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len)
1669 /* LE connection update has completed successfully as a master. */
1670 /* We can enable the update request if the result is a success. */
1671 /* extract the HCI handle first */
1675 STREAM_TO_UINT8 (status, p);
1676 STREAM_TO_UINT16 (handle, p);
1677 l2cble_process_conn_update_evt(handle, status);
1680 static void btu_ble_read_remote_feat_evt (UINT8 *p)
1682 btm_ble_read_remote_features_complete(p);
1685 static void btu_ble_proc_ltk_req (UINT8 *p)
1687 UINT16 ediv, handle;
1690 STREAM_TO_UINT16(handle, p);
1692 STREAM_TO_UINT16(ediv, pp);
1693 #if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
1694 btm_ble_ltk_request(handle, p, ediv);
1696 /* This is empty until an upper layer cares about returning event */
1699 static void btu_ble_data_length_change_evt(UINT8 *p, UINT16 evt_len)
1705 if (!controller_get_interface()->supports_ble_packet_extension())
1707 HCI_TRACE_WARNING("%s, request not supported", __FUNCTION__);
1711 STREAM_TO_UINT16(handle, p);
1712 STREAM_TO_UINT16(tx_data_len, p);
1713 p += 2; /* Skip the TxTimer */
1714 STREAM_TO_UINT16(rx_data_len, p);
1716 l2cble_process_data_length_change_event(handle, tx_data_len, rx_data_len);
1719 /**********************************************
1720 ** End of BLE Events Handler
1721 ***********************************************/
1722 #if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
1723 static void btu_ble_rc_param_req_evt(UINT8 *p)
1726 UINT16 int_min, int_max, latency, timeout;
1728 STREAM_TO_UINT16(handle, p);
1729 STREAM_TO_UINT16(int_min, p);
1730 STREAM_TO_UINT16(int_max, p);
1731 STREAM_TO_UINT16(latency, p);
1732 STREAM_TO_UINT16(timeout, p);
1734 l2cble_process_rc_param_request_evt(handle, int_min, int_max, latency, timeout);
1736 #endif /* BLE_LLT_INCLUDED */
1738 #endif /* BLE_INCLUDED */