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