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