blob: 13ec4cd8432c60c48a0aae66ad85cb993567a507 [file] [log] [blame]
The Android Open Source Project5738f832012-12-12 16:00:35 -08001/******************************************************************************
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#include <stdlib.h>
29#include <string.h>
30#include <stdio.h>
31
32#include "gki.h"
33#include "bt_types.h"
34#include "hcimsgs.h"
35#include "btu.h"
36#include "l2c_int.h"
37#include "btm_api.h"
38#include "btm_int.h"
39
Kévin PETIT22c6e502014-02-12 17:24:01 +000040extern void btm_process_cancel_complete(UINT8 status, UINT8 mode);
41extern void btm_ble_test_command_complete(UINT8 *p);
42
Bhakthavatsala Raghavendra016380f2013-11-27 13:03:42 -080043#include "bt_target.h"
The Android Open Source Project5738f832012-12-12 16:00:35 -080044// btla-specific ++
45#define LOG_TAG "BTLD"
46#if (defined(ANDROID_APP_INCLUDED) && (ANDROID_APP_INCLUDED == TRUE) && (!defined(LINUX_NATIVE)) )
47#include <cutils/log.h>
48#else
49#define LOGV(format, ...) fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__)
50#define LOGE(format, ...) fprintf (stderr, LOG_TAG format"\n", ## __VA_ARGS__)
51#define LOGI(format, ...) fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__)
52#endif
53
54// btla-specific ++
55/* BTE application task */
56#if APPL_INCLUDED == TRUE
57#include "bte_appl.h"
58#endif
59// btla-specific --
60
The Android Open Source Project689d66b2012-12-12 17:18:15 -080061//Counter to track number of HCI command timeout
62static int num_hci_cmds_timed_out;
63
The Android Open Source Project5738f832012-12-12 16:00:35 -080064/********************************************************************************/
65/* L O C A L F U N C T I O N P R O T O T Y P E S */
66/********************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -080067static void btu_hcif_inquiry_comp_evt (UINT8 *p);
68static void btu_hcif_inquiry_result_evt (UINT8 *p);
69static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -080070#if (BTM_EIR_CLIENT_INCLUDED == TRUE)
Mike J. Chen92c997f2014-01-31 18:07:48 -080071static void btu_hcif_extended_inquiry_result_evt (UINT8 *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -080072#endif
73
Mike J. Chen92c997f2014-01-31 18:07:48 -080074static void btu_hcif_connection_comp_evt (UINT8 *p);
75static void btu_hcif_connection_request_evt (UINT8 *p);
76static void btu_hcif_disconnection_comp_evt (UINT8 *p);
77static void btu_hcif_authentication_comp_evt (UINT8 *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -080078static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len);
Mike J. Chen92c997f2014-01-31 18:07:48 -080079static void btu_hcif_encryption_change_evt (UINT8 *p);
80static void btu_hcif_change_conn_link_key_evt (UINT8 *p);
81static void btu_hcif_master_link_key_comp_evt (UINT8 *p);
82static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p);
83static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p);
84static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p);
85static void btu_hcif_qos_setup_comp_evt (UINT8 *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -080086static void btu_hcif_command_complete_evt (UINT8 controller_id, UINT8 *p, UINT16 evt_len);
Mike J. Chen92c997f2014-01-31 18:07:48 -080087static void btu_hcif_command_status_evt (UINT8 controller_id, UINT8 *p);
88static void btu_hcif_hardware_error_evt (UINT8 *p);
89static void btu_hcif_flush_occured_evt (void);
90static void btu_hcif_role_change_evt (UINT8 *p);
91static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p);
92static void btu_hcif_mode_change_evt (UINT8 *p);
93static void btu_hcif_return_link_keys_evt (UINT8 *p);
94static void btu_hcif_pin_code_request_evt (UINT8 *p);
95static void btu_hcif_link_key_request_evt (UINT8 *p);
96static void btu_hcif_link_key_notification_evt (UINT8 *p);
97static void btu_hcif_loopback_command_evt (void);
98static void btu_hcif_data_buf_overflow_evt (void);
99static void btu_hcif_max_slots_changed_evt (void);
100static void btu_hcif_read_clock_off_comp_evt (UINT8 *p);
101static void btu_hcif_conn_pkt_type_change_evt (void);
102static void btu_hcif_qos_violation_evt (UINT8 *p);
103static void btu_hcif_page_scan_mode_change_evt (void);
104static void btu_hcif_page_scan_rep_mode_chng_evt (void);
105static void btu_hcif_esco_connection_comp_evt(UINT8 *p);
106static void btu_hcif_esco_connection_chg_evt(UINT8 *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800107
108/* Simple Pairing Events */
Mike J. Chen92c997f2014-01-31 18:07:48 -0800109static void btu_hcif_host_support_evt (UINT8 *p);
110static void btu_hcif_io_cap_request_evt (UINT8 *p);
111static void btu_hcif_io_cap_response_evt (UINT8 *p);
112static void btu_hcif_user_conf_request_evt (UINT8 *p);
113static void btu_hcif_user_passkey_request_evt (UINT8 *p);
114static void btu_hcif_user_passkey_notif_evt (UINT8 *p);
115static void btu_hcif_keypress_notif_evt (UINT8 *p);
116static void btu_hcif_link_super_tout_evt (UINT8 *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800117
118 #if BTM_OOB_INCLUDED == TRUE
Mike J. Chen92c997f2014-01-31 18:07:48 -0800119static void btu_hcif_rem_oob_request_evt (UINT8 *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800120 #endif
121
Mike J. Chen92c997f2014-01-31 18:07:48 -0800122static void btu_hcif_simple_pair_complete_evt (UINT8 *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800123 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
Mike J. Chen92c997f2014-01-31 18:07:48 -0800124static void btu_hcif_enhanced_flush_complete_evt (void);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800125 #endif
126
127 #if (BTM_SSR_INCLUDED == TRUE)
128static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len);
129 #endif /* BTM_SSR_INCLUDED == TRUE */
130
131 #if (HID_DEV_INCLUDED == TRUE) && (HID_DEV_PM_INCLUDED == TRUE)
132extern void hidd_pm_proc_mode_change( UINT8 hci_status, UINT8 mode, UINT16 interval );
133 #endif
134
135
136 #if BLE_INCLUDED == TRUE
137static void btu_ble_ll_conn_complete_evt (UINT8 *p, UINT16 evt_len);
Mike J. Chen92c997f2014-01-31 18:07:48 -0800138static void btu_ble_process_adv_pkt (UINT8 *p);
139static void btu_ble_read_remote_feat_evt (UINT8 *p);
Chaojing Sun97e75b72014-10-07 17:07:05 -0700140static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len);
Mike J. Chen92c997f2014-01-31 18:07:48 -0800141static void btu_ble_proc_ltk_req (UINT8 *p);
142static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p);
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700143#if (BLE_LLT_INCLUDED == TRUE)
144static void btu_ble_rc_param_req_evt(UINT8 *p);
145#endif
The Android Open Source Project5738f832012-12-12 16:00:35 -0800146 #endif
147/*******************************************************************************
148**
149** Function btu_hcif_store_cmd
150**
151** Description This function stores a copy of an outgoing command and
152** and sets a timer waiting for a event in response to the
153** command.
154**
155** Returns void
156**
157*******************************************************************************/
158static void btu_hcif_store_cmd (UINT8 controller_id, BT_HDR *p_buf)
159{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800160 tHCI_CMD_CB *p_hci_cmd_cb;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800161 UINT16 opcode;
162 BT_HDR *p_cmd;
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -0800163 UINT8 *p;
164
165 /* Validate controller ID */
166 if (controller_id >= BTU_MAX_LOCAL_CTRLS)
167 return;
168
169 p_hci_cmd_cb = &(btu_cb.hci_cmd_cb[controller_id]);
170 p = (UINT8 *)(p_buf + 1) + p_buf->offset;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800171
172 /* get command opcode */
173 STREAM_TO_UINT16 (opcode, p);
174
175 /* don't do anything for certain commands */
176 if ((opcode == HCI_RESET) || (opcode == HCI_HOST_NUM_PACKETS_DONE))
177 {
178 return;
179 }
180
181 /* allocate buffer (HCI_GET_CMD_BUF will either get a buffer from HCI_CMD_POOL or from 'best-fit' pool) */
182 if ((p_cmd = HCI_GET_CMD_BUF(p_buf->len + p_buf->offset - HCIC_PREAMBLE_SIZE)) == NULL)
183 {
184 return;
185 }
186
187 /* copy buffer */
188 memcpy (p_cmd, p_buf, sizeof(BT_HDR));
189
190 /* If vendor specific save the callback function */
191 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC
192#if BLE_INCLUDED == TRUE
193 || (opcode == HCI_BLE_RAND )
194 || (opcode == HCI_BLE_ENCRYPT)
195#endif
196 )
197 {
The Android Open Source Project5738f832012-12-12 16:00:35 -0800198 memcpy ((UINT8 *)(p_cmd + 1), (UINT8 *)(p_buf + 1), sizeof(void *));
199 }
200
201 memcpy ((UINT8 *)(p_cmd + 1) + p_cmd->offset,
202 (UINT8 *)(p_buf + 1) + p_buf->offset, p_buf->len);
203
204 /* queue copy of cmd */
205 GKI_enqueue(&(p_hci_cmd_cb->cmd_cmpl_q), p_cmd);
206
207 /* start timer */
208 if (BTU_CMD_CMPL_TIMEOUT > 0)
209 {
210#if (defined(BTU_CMD_CMPL_TOUT_DOUBLE_CHECK) && BTU_CMD_CMPL_TOUT_DOUBLE_CHECK == TRUE)
211 p_hci_cmd_cb->checked_hcisu = FALSE;
212#endif
213 btu_start_timer (&(p_hci_cmd_cb->cmd_cmpl_timer),
214 (UINT16)(BTU_TTYPE_BTU_CMD_CMPL + controller_id),
215 BTU_CMD_CMPL_TIMEOUT);
216 }
217}
218
219/*******************************************************************************
220**
221** Function btu_hcif_process_event
222**
223** Description This function is called when an event is received from
224** the Host Controller.
225**
226** Returns void
227**
228*******************************************************************************/
229void btu_hcif_process_event (UINT8 controller_id, BT_HDR *p_msg)
230{
231 UINT8 *p = (UINT8 *)(p_msg + 1) + p_msg->offset;
232 UINT8 hci_evt_code, hci_evt_len;
233#if BLE_INCLUDED == TRUE
234 UINT8 ble_sub_code;
235#endif
236 STREAM_TO_UINT8 (hci_evt_code, p);
237 STREAM_TO_UINT8 (hci_evt_len, p);
238
239 switch (hci_evt_code)
240 {
241 case HCI_INQUIRY_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800242 btu_hcif_inquiry_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800243 break;
244 case HCI_INQUIRY_RESULT_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800245 btu_hcif_inquiry_result_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800246 break;
247 case HCI_INQUIRY_RSSI_RESULT_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800248 btu_hcif_inquiry_rssi_result_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800249 break;
250#if (BTM_EIR_CLIENT_INCLUDED == TRUE)
251 case HCI_EXTENDED_INQUIRY_RESULT_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800252 btu_hcif_extended_inquiry_result_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800253 break;
254#endif
255 case HCI_CONNECTION_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800256 btu_hcif_connection_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800257 break;
258 case HCI_CONNECTION_REQUEST_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800259 btu_hcif_connection_request_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800260 break;
261 case HCI_DISCONNECTION_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800262 btu_hcif_disconnection_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800263 break;
264 case HCI_AUTHENTICATION_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800265 btu_hcif_authentication_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800266 break;
267 case HCI_RMT_NAME_REQUEST_COMP_EVT:
268 btu_hcif_rmt_name_request_comp_evt (p, hci_evt_len);
269 break;
270 case HCI_ENCRYPTION_CHANGE_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800271 btu_hcif_encryption_change_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800272 break;
273#if BLE_INCLUDED == TRUE
274 case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800275 btu_hcif_encryption_key_refresh_cmpl_evt(p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800276 break;
277#endif
278 case HCI_CHANGE_CONN_LINK_KEY_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800279 btu_hcif_change_conn_link_key_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800280 break;
281 case HCI_MASTER_LINK_KEY_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800282 btu_hcif_master_link_key_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800283 break;
284 case HCI_READ_RMT_FEATURES_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800285 btu_hcif_read_rmt_features_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800286 break;
287 case HCI_READ_RMT_EXT_FEATURES_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800288 btu_hcif_read_rmt_ext_features_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800289 break;
290 case HCI_READ_RMT_VERSION_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800291 btu_hcif_read_rmt_version_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800292 break;
293 case HCI_QOS_SETUP_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800294 btu_hcif_qos_setup_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800295 break;
296 case HCI_COMMAND_COMPLETE_EVT:
297 btu_hcif_command_complete_evt (controller_id, p, hci_evt_len);
298 break;
299 case HCI_COMMAND_STATUS_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800300 btu_hcif_command_status_evt (controller_id, p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800301 break;
302 case HCI_HARDWARE_ERROR_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800303 btu_hcif_hardware_error_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800304 break;
305 case HCI_FLUSH_OCCURED_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800306 btu_hcif_flush_occured_evt ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800307 break;
308 case HCI_ROLE_CHANGE_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800309 btu_hcif_role_change_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800310 break;
311 case HCI_NUM_COMPL_DATA_PKTS_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800312 btu_hcif_num_compl_data_pkts_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800313 break;
314 case HCI_MODE_CHANGE_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800315 btu_hcif_mode_change_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800316 break;
317 case HCI_RETURN_LINK_KEYS_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800318 btu_hcif_return_link_keys_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800319 break;
320 case HCI_PIN_CODE_REQUEST_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800321 btu_hcif_pin_code_request_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800322 break;
323 case HCI_LINK_KEY_REQUEST_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800324 btu_hcif_link_key_request_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800325 break;
326 case HCI_LINK_KEY_NOTIFICATION_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800327 btu_hcif_link_key_notification_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800328 break;
329 case HCI_LOOPBACK_COMMAND_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800330 btu_hcif_loopback_command_evt ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800331 break;
332 case HCI_DATA_BUF_OVERFLOW_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800333 btu_hcif_data_buf_overflow_evt ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800334 break;
335 case HCI_MAX_SLOTS_CHANGED_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800336 btu_hcif_max_slots_changed_evt ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800337 break;
338 case HCI_READ_CLOCK_OFF_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800339 btu_hcif_read_clock_off_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800340 break;
341 case HCI_CONN_PKT_TYPE_CHANGE_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800342 btu_hcif_conn_pkt_type_change_evt ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800343 break;
344 case HCI_QOS_VIOLATION_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800345 btu_hcif_qos_violation_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800346 break;
347 case HCI_PAGE_SCAN_MODE_CHANGE_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800348 btu_hcif_page_scan_mode_change_evt ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800349 break;
350 case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800351 btu_hcif_page_scan_rep_mode_chng_evt ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800352 break;
353 case HCI_ESCO_CONNECTION_COMP_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800354 btu_hcif_esco_connection_comp_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800355 break;
356 case HCI_ESCO_CONNECTION_CHANGED_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800357 btu_hcif_esco_connection_chg_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800358 break;
359#if (BTM_SSR_INCLUDED == TRUE)
360 case HCI_SNIFF_SUB_RATE_EVT:
361 btu_hcif_ssr_evt (p, hci_evt_len);
362 break;
363#endif /* BTM_SSR_INCLUDED == TRUE */
364 case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800365 btu_hcif_host_support_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800366 break;
367 case HCI_IO_CAPABILITY_REQUEST_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800368 btu_hcif_io_cap_request_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800369 break;
370 case HCI_IO_CAPABILITY_RESPONSE_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800371 btu_hcif_io_cap_response_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800372 break;
373 case HCI_USER_CONFIRMATION_REQUEST_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800374 btu_hcif_user_conf_request_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800375 break;
376 case HCI_USER_PASSKEY_REQUEST_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800377 btu_hcif_user_passkey_request_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800378 break;
379#if BTM_OOB_INCLUDED == TRUE
380 case HCI_REMOTE_OOB_DATA_REQUEST_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800381 btu_hcif_rem_oob_request_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800382 break;
383#endif
384 case HCI_SIMPLE_PAIRING_COMPLETE_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800385 btu_hcif_simple_pair_complete_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800386 break;
387 case HCI_USER_PASSKEY_NOTIFY_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800388 btu_hcif_user_passkey_notif_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800389 break;
390 case HCI_KEYPRESS_NOTIFY_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800391 btu_hcif_keypress_notif_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800392 break;
393 case HCI_LINK_SUPER_TOUT_CHANGED_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800394 btu_hcif_link_super_tout_evt (p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800395 break;
396#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
397 case HCI_ENHANCED_FLUSH_COMPLETE_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800398 btu_hcif_enhanced_flush_complete_evt ();
The Android Open Source Project5738f832012-12-12 16:00:35 -0800399 break;
400#endif
401
402#if (BLE_INCLUDED == TRUE)
403 case HCI_BLE_EVENT:
404 STREAM_TO_UINT8 (ble_sub_code, p);
405
Mike J. Chend65b00f2014-06-25 18:12:22 -0700406 HCI_TRACE_EVENT("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code, ble_sub_code);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800407
408 switch (ble_sub_code)
409 {
410 case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */
Mike J. Chen92c997f2014-01-31 18:07:48 -0800411 btu_ble_process_adv_pkt(p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800412 break;
413 case HCI_BLE_CONN_COMPLETE_EVT:
414 btu_ble_ll_conn_complete_evt(p, hci_evt_len);
415 break;
416 case HCI_BLE_LL_CONN_PARAM_UPD_EVT:
Chaojing Sun97e75b72014-10-07 17:07:05 -0700417 btu_ble_ll_conn_param_upd_evt(p, hci_evt_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800418 break;
419 case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT:
Mike J. Chen92c997f2014-01-31 18:07:48 -0800420 btu_ble_read_remote_feat_evt(p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800421 break;
422 case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */
Mike J. Chen92c997f2014-01-31 18:07:48 -0800423 btu_ble_proc_ltk_req(p);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800424 break;
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -0700425#if (BLE_LLT_INCLUDED == TRUE)
426 case HCI_BLE_RC_PARAM_REQ_EVT:
427 btu_ble_rc_param_req_evt(p);
428 break;
429#endif
430
The Android Open Source Project5738f832012-12-12 16:00:35 -0800431 }
432 break;
433#endif /* BLE_INCLUDED */
434 case HCI_VENDOR_SPECIFIC_EVT:
435 btm_vendor_specific_evt (p, hci_evt_len);
436 break;
437 }
The Android Open Source Project689d66b2012-12-12 17:18:15 -0800438 // reset the num_hci_cmds_timed_out upon receving any event from controller.
439 num_hci_cmds_timed_out = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -0800440}
441
442
443/*******************************************************************************
444**
445** Function btu_hcif_send_cmd
446**
447** Description This function is called to check if it can send commands
448** to the Host Controller. It may be passed the address of
449** a packet to send.
450**
451** Returns void
452**
453*******************************************************************************/
454void btu_hcif_send_cmd (UINT8 controller_id, BT_HDR *p_buf)
455{
456 tHCI_CMD_CB * p_hci_cmd_cb = &(btu_cb.hci_cmd_cb[controller_id]);
457
458#if ((L2CAP_HOST_FLOW_CTRL == TRUE)||defined(HCI_TESTER))
459 UINT8 *pp;
460 UINT16 code;
461#endif
462
463 /* If there are already commands in the queue, then enqueue this command */
464 if ((p_buf) && (p_hci_cmd_cb->cmd_xmit_q.count))
465 {
466 GKI_enqueue (&(p_hci_cmd_cb->cmd_xmit_q), p_buf);
467 p_buf = NULL;
468 }
469
470 /* Allow for startup case, where no acks may be received */
471 if ( ((controller_id == LOCAL_BR_EDR_CONTROLLER_ID)
472 && (p_hci_cmd_cb->cmd_window == 0)
473 && (btm_cb.devcb.state == BTM_DEV_STATE_WAIT_RESET_CMPLT)) )
474 {
475 p_hci_cmd_cb->cmd_window = p_hci_cmd_cb->cmd_xmit_q.count + 1;
476 }
477
478 /* See if we can send anything */
479 while (p_hci_cmd_cb->cmd_window != 0)
480 {
481 if (!p_buf)
482 p_buf = (BT_HDR *)GKI_dequeue (&(p_hci_cmd_cb->cmd_xmit_q));
483
484 if (p_buf)
485 {
486 btu_hcif_store_cmd(controller_id, p_buf);
487
488#if ((L2CAP_HOST_FLOW_CTRL == TRUE)||defined(HCI_TESTER))
489 pp = (UINT8 *)(p_buf + 1) + p_buf->offset;
490
491 STREAM_TO_UINT16 (code, pp);
492
493 /*
494 * We do not need to decrease window for host flow control,
495 * host flow control does not receive an event back from controller
496 */
497 if (code != HCI_HOST_NUM_PACKETS_DONE)
498#endif
499 p_hci_cmd_cb->cmd_window--;
500
501 if (controller_id == LOCAL_BR_EDR_CONTROLLER_ID)
502 {
503 HCI_CMD_TO_LOWER(p_buf);
504 }
505 else
506 {
507 /* Unknown controller */
Mike J. Chend65b00f2014-06-25 18:12:22 -0700508 HCI_TRACE_WARNING("BTU HCI(ctrl id=%d) controller ID not recognized", controller_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -0800509 GKI_freebuf(p_buf);;
510 }
511
512 p_buf = NULL;
513 }
514 else
515 break;
516 }
517
518 if (p_buf)
519 GKI_enqueue (&(p_hci_cmd_cb->cmd_xmit_q), p_buf);
520
521#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE)
522 if (controller_id == LOCAL_BR_EDR_CONTROLLER_ID)
523 {
524 /* check if controller can go to sleep */
525 btu_check_bt_sleep ();
526 }
527#endif
528
529}
530
531
532/*******************************************************************************
533**
534** Function btu_hcif_send_host_rdy_for_data
535**
536** Description This function is called to check if it can send commands
537** to the Host Controller. It may be passed the address of
538** a packet to send.
539**
540** Returns void
541**
542*******************************************************************************/
543void btu_hcif_send_host_rdy_for_data(void)
544{
545 UINT16 num_pkts[MAX_L2CAP_LINKS + 4]; /* 3 SCO connections */
546 UINT16 handles[MAX_L2CAP_LINKS + 4];
547 UINT8 num_ents;
548
549 /* Get the L2CAP numbers */
550 num_ents = l2c_link_pkts_rcvd (num_pkts, handles);
551
552 /* Get the SCO numbers */
553 /* No SCO for now ?? */
554
555 if (num_ents)
556 {
557 btsnd_hcic_host_num_xmitted_pkts (num_ents, handles, num_pkts);
558 }
559}
560
561/*******************************************************************************
562**
563** Function btu_hcif_inquiry_comp_evt
564**
565** Description Process event HCI_INQUIRY_COMP_EVT
566**
567** Returns void
568**
569*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800570static void btu_hcif_inquiry_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800571{
572 UINT8 status;
573
574 STREAM_TO_UINT8 (status, p);
575
576 /* Tell inquiry processing that we are done */
577 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
578}
579
580
581/*******************************************************************************
582**
583** Function btu_hcif_inquiry_result_evt
584**
585** Description Process event HCI_INQUIRY_RESULT_EVT
586**
587** Returns void
588**
589*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800590static void btu_hcif_inquiry_result_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800591{
592 /* Store results in the cache */
593 btm_process_inq_results (p, BTM_INQ_RESULT_STANDARD);
594}
595
596/*******************************************************************************
597**
598** Function btu_hcif_inquiry_rssi_result_evt
599**
600** Description Process event HCI_INQUIRY_RSSI_RESULT_EVT
601**
602** Returns void
603**
604*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800605static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800606{
607 /* Store results in the cache */
608 btm_process_inq_results (p, BTM_INQ_RESULT_WITH_RSSI);
609}
610
611/*******************************************************************************
612**
613** Function btu_hcif_extended_inquiry_result_evt
614**
615** Description Process event HCI_EXTENDED_INQUIRY_RESULT_EVT
616**
617** Returns void
618**
619*******************************************************************************/
620#if (BTM_EIR_CLIENT_INCLUDED == TRUE)
Mike J. Chen92c997f2014-01-31 18:07:48 -0800621static void btu_hcif_extended_inquiry_result_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800622{
623 /* Store results in the cache */
624 btm_process_inq_results (p, BTM_INQ_RESULT_EXTENDED);
625}
626#endif
627
628/*******************************************************************************
629**
630** Function btu_hcif_connection_comp_evt
631**
632** Description Process event HCI_CONNECTION_COMP_EVT
633**
634** Returns void
635**
636*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800637static void btu_hcif_connection_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800638{
639 UINT8 status;
640 UINT16 handle;
641 BD_ADDR bda;
642 UINT8 link_type;
643 UINT8 enc_mode;
644#if BTM_SCO_INCLUDED == TRUE
645 tBTM_ESCO_DATA esco_data;
646#endif
647
648 STREAM_TO_UINT8 (status, p);
649 STREAM_TO_UINT16 (handle, p);
650 STREAM_TO_BDADDR (bda, p);
651 STREAM_TO_UINT8 (link_type, p);
652 STREAM_TO_UINT8 (enc_mode, p);
653
654 handle = HCID_GET_HANDLE (handle);
655
656 if (link_type == HCI_LINK_TYPE_ACL)
657 {
658 btm_sec_connected (bda, handle, status, enc_mode);
659
660 l2c_link_hci_conn_comp (status, handle, bda);
661 }
662#if BTM_SCO_INCLUDED == TRUE
663 else
664 {
665 memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA));
666 /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */
667 memcpy (esco_data.bd_addr, bda, BD_ADDR_LEN);
668 btm_sco_connected (status, bda, handle, &esco_data);
669 }
670#endif /* BTM_SCO_INCLUDED */
671}
672
673
674/*******************************************************************************
675**
676** Function btu_hcif_connection_request_evt
677**
678** Description Process event HCI_CONNECTION_REQUEST_EVT
679**
680** Returns void
681**
682*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800683static void btu_hcif_connection_request_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800684{
685 BD_ADDR bda;
686 DEV_CLASS dc;
687 UINT8 link_type;
688
689 STREAM_TO_BDADDR (bda, p);
690 STREAM_TO_DEVCLASS (dc, p);
691 STREAM_TO_UINT8 (link_type, p);
692
693 /* Pass request to security manager to check connect filters before */
694 /* passing request to l2cap */
695 if (link_type == HCI_LINK_TYPE_ACL)
696 {
697 btm_sec_conn_req (bda, dc);
698 }
699#if BTM_SCO_INCLUDED == TRUE
700 else
701 {
702 btm_sco_conn_req (bda, dc, link_type);
703 }
704#endif /* BTM_SCO_INCLUDED */
705}
706
707
708/*******************************************************************************
709**
710** Function btu_hcif_disconnection_comp_evt
711**
712** Description Process event HCI_DISCONNECTION_COMP_EVT
713**
714** Returns void
715**
716*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800717static void btu_hcif_disconnection_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800718{
719 UINT8 status;
720 UINT16 handle;
721 UINT8 reason;
722
723 STREAM_TO_UINT8 (status, p);
724 STREAM_TO_UINT16 (handle, p);
725 STREAM_TO_UINT8 (reason, p);
726
727 handle = HCID_GET_HANDLE (handle);
728
729#if BTM_SCO_INCLUDED == TRUE
730 /* If L2CAP doesn't know about it, send it to SCO */
731 if (!l2c_link_hci_disc_comp (handle, reason))
732 btm_sco_removed (handle, reason);
733#else
734 l2c_link_hci_disc_comp (handle, reason);
735#endif /* BTM_SCO_INCLUDED */
736
737 /* Notify security manager */
738 btm_sec_disconnected (handle, reason);
739}
740
741/*******************************************************************************
742**
743** Function btu_hcif_authentication_comp_evt
744**
745** Description Process event HCI_AUTHENTICATION_COMP_EVT
746**
747** Returns void
748**
749*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800750static void btu_hcif_authentication_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800751{
752 UINT8 status;
753 UINT16 handle;
754
755 STREAM_TO_UINT8 (status, p);
756 STREAM_TO_UINT16 (handle, p);
757
758 btm_sec_auth_complete (handle, status);
759}
760
761
762/*******************************************************************************
763**
764** Function btu_hcif_rmt_name_request_comp_evt
765**
766** Description Process event HCI_RMT_NAME_REQUEST_COMP_EVT
767**
768** Returns void
769**
770*******************************************************************************/
771static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len)
772{
773 UINT8 status;
774 BD_ADDR bd_addr;
775
776 STREAM_TO_UINT8 (status, p);
777 STREAM_TO_BDADDR (bd_addr, p);
778
779 evt_len -= (1 + BD_ADDR_LEN);
780
781 btm_process_remote_name (bd_addr, p, evt_len, status);
782
783 btm_sec_rmt_name_request_complete (bd_addr, p, status);
784}
785
786
787/*******************************************************************************
788**
789** Function btu_hcif_encryption_change_evt
790**
791** Description Process event HCI_ENCRYPTION_CHANGE_EVT
792**
793** Returns void
794**
795*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800796static void btu_hcif_encryption_change_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800797{
798 UINT8 status;
799 UINT16 handle;
800 UINT8 encr_enable;
801
802 STREAM_TO_UINT8 (status, p);
803 STREAM_TO_UINT16 (handle, p);
804 STREAM_TO_UINT8 (encr_enable, p);
805
806 btm_acl_encrypt_change (handle, status, encr_enable);
807 btm_sec_encrypt_change (handle, status, encr_enable);
808}
809
810
811/*******************************************************************************
812**
813** Function btu_hcif_change_conn_link_key_evt
814**
815** Description Process event HCI_CHANGE_CONN_LINK_KEY_EVT
816**
817** Returns void
818**
819*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800820static void btu_hcif_change_conn_link_key_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800821{
822 UINT8 status;
823 UINT16 handle;
824
825 STREAM_TO_UINT8 (status, p);
826 STREAM_TO_UINT16 (handle, p);
827
828 btm_acl_link_key_change (handle, status);
829}
830
831
832/*******************************************************************************
833**
834** Function btu_hcif_master_link_key_comp_evt
835**
836** Description Process event HCI_MASTER_LINK_KEY_COMP_EVT
837**
838** Returns void
839**
840*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800841static void btu_hcif_master_link_key_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800842{
843 UINT8 status;
844 UINT16 handle;
845 UINT8 key_flg;
846
847 STREAM_TO_UINT8 (status, p);
848 STREAM_TO_UINT16 (handle, p);
849 STREAM_TO_UINT8 (key_flg, p);
850
851 btm_sec_mkey_comp_event (handle, status, key_flg);
852}
853
854
855/*******************************************************************************
856**
857** Function btu_hcif_read_rmt_features_comp_evt
858**
859** Description Process event HCI_READ_RMT_FEATURES_COMP_EVT
860**
861** Returns void
862**
863*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800864static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800865{
866 btm_read_remote_features_complete(p);
867}
868
869/*******************************************************************************
870**
871** Function btu_hcif_read_rmt_ext_features_comp_evt
872**
873** Description Process event HCI_READ_RMT_EXT_FEATURES_COMP_EVT
874**
875** Returns void
876**
877*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800878static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800879{
Ganesh Ganapathi Batta9d140a92013-04-11 16:13:14 -0700880 UINT8 *p_cur = p;
881 UINT8 status;
882 UINT16 handle;
883
884 STREAM_TO_UINT8 (status, p_cur);
885
886 if (status == HCI_SUCCESS)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800887 btm_read_remote_ext_features_complete(p);
888 else
Ganesh Ganapathi Batta9d140a92013-04-11 16:13:14 -0700889 {
890 STREAM_TO_UINT16 (handle, p_cur);
891 btm_read_remote_ext_features_failed(status, handle);
892 }
The Android Open Source Project5738f832012-12-12 16:00:35 -0800893}
894
895/*******************************************************************************
896**
897** Function btu_hcif_read_rmt_version_comp_evt
898**
899** Description Process event HCI_READ_RMT_VERSION_COMP_EVT
900**
901** Returns void
902**
903*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800904static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800905{
906 btm_read_remote_version_complete (p);
907}
908
909
910/*******************************************************************************
911**
912** Function btu_hcif_qos_setup_comp_evt
913**
914** Description Process event HCI_QOS_SETUP_COMP_EVT
915**
916** Returns void
917**
918*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800919static void btu_hcif_qos_setup_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800920{
921 UINT8 status;
922 UINT16 handle;
923 FLOW_SPEC flow;
924
925 STREAM_TO_UINT8 (status, p);
926 STREAM_TO_UINT16 (handle, p);
927 STREAM_TO_UINT8 (flow.qos_flags, p);
928 STREAM_TO_UINT8 (flow.service_type, p);
929 STREAM_TO_UINT32 (flow.token_rate, p);
930 STREAM_TO_UINT32 (flow.peak_bandwidth, p);
931 STREAM_TO_UINT32 (flow.latency, p);
932 STREAM_TO_UINT32 (flow.delay_variation, p);
933
934 btm_qos_setup_complete(status, handle, &flow);
935}
936
937
938/*******************************************************************************
939**
940** Function btu_hcif_esco_connection_comp_evt
941**
942** Description Process event HCI_ESCO_CONNECTION_COMP_EVT
943**
944** Returns void
945**
946*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800947static void btu_hcif_esco_connection_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800948{
949#if BTM_SCO_INCLUDED == TRUE
950 tBTM_ESCO_DATA data;
951 UINT16 handle;
952 BD_ADDR bda;
953 UINT8 status;
954
955 STREAM_TO_UINT8 (status, p);
956 STREAM_TO_UINT16 (handle, p);
957 STREAM_TO_BDADDR (bda, p);
958
959 STREAM_TO_UINT8 (data.link_type, p);
960 STREAM_TO_UINT8 (data.tx_interval, p);
961 STREAM_TO_UINT8 (data.retrans_window, p);
962 STREAM_TO_UINT16 (data.rx_pkt_len, p);
963 STREAM_TO_UINT16 (data.tx_pkt_len, p);
964 STREAM_TO_UINT8 (data.air_mode, p);
965
966 memcpy (data.bd_addr, bda, BD_ADDR_LEN);
967 btm_sco_connected (status, bda, handle, &data);
968#endif
969}
970
971
972/*******************************************************************************
973**
974** Function btu_hcif_esco_connection_chg_evt
975**
976** Description Process event HCI_ESCO_CONNECTION_CHANGED_EVT
977**
978** Returns void
979**
980*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -0800981static void btu_hcif_esco_connection_chg_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -0800982{
983#if BTM_SCO_INCLUDED == TRUE
984 UINT16 handle;
985 UINT16 tx_pkt_len;
986 UINT16 rx_pkt_len;
987 UINT8 status;
988 UINT8 tx_interval;
989 UINT8 retrans_window;
990
991 STREAM_TO_UINT8 (status, p);
992 STREAM_TO_UINT16 (handle, p);
993
994 STREAM_TO_UINT8 (tx_interval, p);
995 STREAM_TO_UINT8 (retrans_window, p);
996 STREAM_TO_UINT16 (rx_pkt_len, p);
997 STREAM_TO_UINT16 (tx_pkt_len, p);
998
999 btm_esco_proc_conn_chg (status, handle, tx_interval, retrans_window,
1000 rx_pkt_len, tx_pkt_len);
1001#endif
1002}
1003
1004/*******************************************************************************
1005**
1006** Function btu_hcif_hdl_command_complete
1007**
1008** Description Handle command complete event
1009**
1010** Returns void
1011**
1012*******************************************************************************/
1013static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_len,
Mike J. Chen92c997f2014-01-31 18:07:48 -08001014 void *p_cplt_cback)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001015{
1016 switch (opcode)
1017 {
1018 case HCI_RESET:
1019 btm_reset_complete (); /* BR/EDR */
1020 break;
1021
1022 case HCI_INQUIRY_CANCEL:
1023 /* Tell inquiry processing that we are done */
1024 btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK);
1025 break;
1026 case HCI_SET_EVENT_FILTER:
1027 btm_event_filter_complete (p);
1028 break;
1029
1030 case HCI_READ_STORED_LINK_KEY:
1031 btm_read_stored_link_key_complete (p);
1032 break;
1033
1034 case HCI_WRITE_STORED_LINK_KEY:
1035 btm_write_stored_link_key_complete (p);
1036 break;
1037
1038 case HCI_DELETE_STORED_LINK_KEY:
1039 btm_delete_stored_link_key_complete (p);
1040 break;
1041
1042 case HCI_READ_LOCAL_VERSION_INFO:
1043 btm_read_local_version_complete (p, evt_len);
1044 break;
1045
1046 case HCI_READ_POLICY_SETTINGS:
1047 btm_read_link_policy_complete (p);
1048 break;
1049
1050 case HCI_READ_BUFFER_SIZE:
1051 btm_read_hci_buf_size_complete (p, evt_len);
1052 break;
1053
Ganesh Ganapathi Batta9d140a92013-04-11 16:13:14 -07001054 case HCI_READ_LOCAL_SUPPORTED_CMDS:
1055 btm_read_local_supported_cmds_complete (p);
1056 break;
1057
The Android Open Source Project5738f832012-12-12 16:00:35 -08001058 case HCI_READ_LOCAL_FEATURES:
1059 btm_read_local_features_complete (p, evt_len);
1060 break;
1061
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001062 case HCI_READ_LOCAL_EXT_FEATURES:
1063 btm_read_local_ext_features_complete (p, evt_len);
1064 break;
1065
The Android Open Source Project5738f832012-12-12 16:00:35 -08001066 case HCI_READ_LOCAL_NAME:
1067 btm_read_local_name_complete (p, evt_len);
1068 break;
1069
1070 case HCI_READ_BD_ADDR:
1071 btm_read_local_addr_complete (p, evt_len);
1072 break;
1073
1074 case HCI_GET_LINK_QUALITY:
1075 btm_read_link_quality_complete (p);
1076 break;
1077
1078 case HCI_READ_RSSI:
1079 btm_read_rssi_complete (p);
1080 break;
1081
1082 case HCI_READ_TRANSMIT_POWER_LEVEL:
1083 btm_read_tx_power_complete(p, FALSE);
1084 break;
1085
1086 case HCI_CREATE_CONNECTION_CANCEL:
1087 btm_create_conn_cancel_complete(p);
1088 break;
1089
1090 case HCI_READ_LOCAL_OOB_DATA:
1091#if BTM_OOB_INCLUDED == TRUE
1092 btm_read_local_oob_complete(p);
1093#endif
1094 break;
1095
1096
1097 case HCI_READ_INQ_TX_POWER_LEVEL:
1098 btm_read_linq_tx_power_complete (p);
1099 break;
1100
Andre Eisenbach3aa60542013-03-22 18:00:51 -07001101 case HCI_WRITE_SIMPLE_PAIRING_MODE:
1102 btm_write_simple_paring_mode_complete (p);
1103 break;
1104
1105 case HCI_WRITE_LE_HOST_SUPPORTED:
1106 btm_write_le_host_supported_complete (p);
1107 break;
1108
Srinu Jellac8372bb2014-06-30 16:52:48 +05301109#if (defined(BTM_SECURE_CONN_HOST_INCLUDED) && BTM_SECURE_CONN_HOST_INCLUDED == TRUE)
1110 case HCI_WRITE_SECURE_CONN_HOST_SUPPORT:
1111 btm_write_secure_conn_host_support_complete (p);
1112 break;
1113
1114 case HCI_READ_SECURE_CONN_HOST_SUPPORT:
1115 break;
1116
1117 case HCI_WRITE_SEC_CONN_TEST_MODE:
1118 break;
1119
1120 case HCI_WRITE_AUTH_PAYLOAD_TOUT:
1121 break;
1122
1123 case HCI_READ_AUTH_PAYLOAD_TOUT:
1124 break;
1125
1126 case HCI_READ_LOCAL_OOB_EXTENDED_DATA:
1127#if BTM_OOB_INCLUDED == TRUE
1128 btm_read_local_oob_extended_complete(p);
1129 break;
1130#endif
1131 case HCI_REM_OOB_EXTENDED_DATA_REQ_REPLY:
1132 break;
1133#endif
1134
The Android Open Source Project5738f832012-12-12 16:00:35 -08001135#if (BLE_INCLUDED == TRUE)
Priti Aghera24adb372014-09-10 11:42:10 -07001136/* BLE Commands sComplete*/
The Android Open Source Project5738f832012-12-12 16:00:35 -08001137 case HCI_BLE_READ_WHITE_LIST_SIZE :
1138 btm_read_white_list_size_complete(p, evt_len);
1139 break;
1140
1141 case HCI_BLE_ADD_WHITE_LIST:
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001142 btm_ble_add_2_white_list_complete(*p);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001143 break;
1144
1145 case HCI_BLE_CLEAR_WHITE_LIST:
1146 btm_ble_clear_white_list_complete(p, evt_len);
1147 break;
1148
1149 case HCI_BLE_REMOVE_WHITE_LIST:
1150 btm_ble_remove_from_white_list_complete(p, evt_len);
1151 break;
1152
1153 case HCI_BLE_RAND:
1154 case HCI_BLE_ENCRYPT:
The Android Open Source Project5738f832012-12-12 16:00:35 -08001155 btm_ble_rand_enc_complete (p, opcode, (tBTM_RAND_ENC_CB *)p_cplt_cback);
1156 break;
Prerepa Viswanadham16fe0822014-08-07 11:38:06 -07001157
The Android Open Source Project5738f832012-12-12 16:00:35 -08001158 case HCI_BLE_READ_BUFFER_SIZE:
1159 btm_read_ble_buf_size_complete(p, evt_len);
1160 break;
1161
Andre Eisenbach3aa60542013-03-22 18:00:51 -07001162 case HCI_BLE_READ_LOCAL_SPT_FEAT:
1163 btm_read_ble_local_supported_features_complete(p, evt_len);
1164 break;
1165
The Android Open Source Project5738f832012-12-12 16:00:35 -08001166 case HCI_BLE_READ_ADV_CHNL_TX_POWER:
1167 btm_read_tx_power_complete(p, TRUE);
1168 break;
1169
1170 case HCI_BLE_WRITE_ADV_ENABLE:
1171 btm_ble_write_adv_enable_complete(p);
1172 break;
1173
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07001174 case HCI_BLE_READ_SUPPORTED_STATES:
1175 btm_read_ble_local_supported_states_complete(p, evt_len);
1176 break;
1177
Priti Aghera24adb372014-09-10 11:42:10 -07001178 case HCI_BLE_CREATE_LL_CONN:
1179 btm_ble_create_ll_conn_complete(*p);
1180 break;
1181
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08001182 case HCI_BLE_TRANSMITTER_TEST:
1183 case HCI_BLE_RECEIVER_TEST:
1184 case HCI_BLE_TEST_END:
1185 btm_ble_test_command_complete(p);
1186 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001187#endif /* (BLE_INCLUDED == TRUE) */
1188
1189 default:
1190 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1191 btm_vsc_complete (p, opcode, evt_len, (tBTM_CMPL_CB *)p_cplt_cback);
1192 break;
1193 }
1194}
1195
1196/*******************************************************************************
1197**
1198** Function btu_hcif_command_complete_evt
1199**
1200** Description Process event HCI_COMMAND_COMPLETE_EVT
1201**
1202** Returns void
1203**
1204*******************************************************************************/
1205static void btu_hcif_command_complete_evt (UINT8 controller_id, UINT8 *p, UINT16 evt_len)
1206{
1207 tHCI_CMD_CB *p_hci_cmd_cb = &(btu_cb.hci_cmd_cb[controller_id]);
1208 UINT16 cc_opcode;
1209 BT_HDR *p_cmd;
1210 void *p_cplt_cback = NULL;
1211
1212 STREAM_TO_UINT8 (p_hci_cmd_cb->cmd_window, p);
1213
1214#if (defined(HCI_MAX_SIMUL_CMDS) && (HCI_MAX_SIMUL_CMDS > 0))
1215 if (p_hci_cmd_cb->cmd_window > HCI_MAX_SIMUL_CMDS)
1216 p_hci_cmd_cb->cmd_window = HCI_MAX_SIMUL_CMDS;
1217#endif
1218
1219 STREAM_TO_UINT16 (cc_opcode, p);
1220
1221 evt_len -= 3;
1222
1223 /* only do this for certain commands */
1224 if ((cc_opcode != HCI_RESET) && (cc_opcode != HCI_HOST_NUM_PACKETS_DONE) &&
1225 (cc_opcode != HCI_COMMAND_NONE))
1226 {
1227 /* dequeue and free stored command */
1228
1229/* always use cmd code check, when one cmd timeout waiting for cmd_cmpl,
1230 it'll cause the rest of the command goes in wrong order */
1231 p_cmd = (BT_HDR *) GKI_getfirst (&p_hci_cmd_cb->cmd_cmpl_q);
1232
1233 while (p_cmd)
1234 {
1235 UINT16 opcode_dequeued;
1236 UINT8 *p_dequeued;
1237
1238 /* Make sure dequeued command is for the command_cplt received */
1239 p_dequeued = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
1240 STREAM_TO_UINT16 (opcode_dequeued, p_dequeued);
1241
Srinu Jella2426af32014-07-28 14:25:10 +05301242 /* extract the callback for vendor specific commands for which
1243 controller has responded with 0xffff*/
1244 if ( (opcode_dequeued != cc_opcode)
1245#if (defined(BTM_READ_CTLR_CAP_INCLUDED) && BTM_READ_CTLR_CAP_INCLUDED == TRUE)
1246 && !((opcode_dequeued == HCI_BLE_VENDOR_CAP_OCF) &&
1247 ((opcode_dequeued & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) &&
1248 ((cc_opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC))
1249#endif
1250 )
The Android Open Source Project5738f832012-12-12 16:00:35 -08001251 {
1252 /* opcode does not match, check next command in the queue */
1253 p_cmd = (BT_HDR *) GKI_getnext(p_cmd);
1254 continue;
1255 }
1256 GKI_remove_from_queue(&p_hci_cmd_cb->cmd_cmpl_q, p_cmd);
1257
1258 /* If command was a VSC, then extract command_complete callback */
1259 if ((cc_opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC
1260#if BLE_INCLUDED == TRUE
1261 || (cc_opcode == HCI_BLE_RAND )
1262 || (cc_opcode == HCI_BLE_ENCRYPT)
1263#endif
1264 )
1265 {
1266 p_cplt_cback = *((void **)(p_cmd + 1));
1267 }
1268
1269 GKI_freebuf (p_cmd);
1270
1271 break;
1272 }
1273
1274 /* if more commands in queue restart timer */
1275 if (BTU_CMD_CMPL_TIMEOUT > 0)
1276 {
1277 if (!GKI_queue_is_empty (&(p_hci_cmd_cb->cmd_cmpl_q)))
1278 {
1279#if (defined(BTU_CMD_CMPL_TOUT_DOUBLE_CHECK) && BTU_CMD_CMPL_TOUT_DOUBLE_CHECK == TRUE)
1280 p_hci_cmd_cb->checked_hcisu = FALSE;
1281#endif
1282 btu_start_timer (&(p_hci_cmd_cb->cmd_cmpl_timer),
1283 (UINT16)(BTU_TTYPE_BTU_CMD_CMPL + controller_id),
1284 BTU_CMD_CMPL_TIMEOUT);
1285 }
1286 else
1287 {
1288 btu_stop_timer (&(p_hci_cmd_cb->cmd_cmpl_timer));
1289 }
1290 }
1291 }
1292
1293 /* handle event */
Mike J. Chen92c997f2014-01-31 18:07:48 -08001294 btu_hcif_hdl_command_complete (cc_opcode, p, evt_len, p_cplt_cback);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001295
1296 /* see if we can send more commands */
1297 btu_hcif_send_cmd (controller_id, NULL);
1298}
1299
1300
1301/*******************************************************************************
1302**
1303** Function btu_hcif_hdl_command_status
1304**
1305** Description Handle a command status event
1306**
1307** Returns void
1308**
1309*******************************************************************************/
1310static void btu_hcif_hdl_command_status (UINT16 opcode, UINT8 status, UINT8 *p_cmd,
Mike J. Chen92c997f2014-01-31 18:07:48 -08001311 void *p_vsc_status_cback)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001312{
1313 BD_ADDR bd_addr;
1314 UINT16 handle;
1315#if BTM_SCO_INCLUDED == TRUE
1316 tBTM_ESCO_DATA esco_data;
1317#endif
1318
1319#if BTM_PWR_MGR_INCLUDED == TRUE
1320 switch (opcode)
1321 {
1322 case HCI_EXIT_SNIFF_MODE:
1323 case HCI_EXIT_PARK_MODE:
1324#if BTM_SCO_WAKE_PARKED_LINK == TRUE
1325 if (status != HCI_SUCCESS)
1326 {
1327 /* Allow SCO initiation to continue if waiting for change mode event */
1328 if (p_cmd != NULL)
1329 {
1330 p_cmd++; /* bypass length field */
1331 STREAM_TO_UINT16 (handle, p_cmd);
1332 btm_sco_chk_pend_unpark (status, handle);
1333 }
1334 }
1335#endif
1336 /* Case Falls Through */
1337
1338 case HCI_HOLD_MODE:
1339 case HCI_SNIFF_MODE:
1340 case HCI_PARK_MODE:
1341 btm_pm_proc_cmd_status(status);
1342 break;
1343
1344 default:
1345#endif /* BTM_PWR_MGR_INCLUDED */
1346 /* If command failed to start, we may need to tell BTM */
1347 if (status != HCI_SUCCESS)
1348 {
1349 switch (opcode)
1350 {
1351 case HCI_INQUIRY:
1352 /* Tell inquiry processing that we are done */
1353 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
1354 break;
1355
1356 case HCI_RMT_NAME_REQUEST:
1357 /* Tell inquiry processing that we are done */
1358 btm_process_remote_name (NULL, NULL, 0, status);
1359
1360 btm_sec_rmt_name_request_complete (NULL, NULL, status);
1361 break;
1362
1363 case HCI_CHANGE_CONN_LINK_KEY:
1364 /* Let host know we're done with error */
1365 /* read handle out of stored command */
1366 if (p_cmd != NULL)
1367 {
1368 p_cmd++;
1369 STREAM_TO_UINT16 (handle, p_cmd);
1370
1371 btm_acl_link_key_change (handle, status);
1372 }
1373 break;
1374
1375 case HCI_QOS_SETUP_COMP_EVT:
1376 /* Tell qos setup that we are done */
1377 btm_qos_setup_complete(status,0,NULL);
1378 break;
1379
1380 case HCI_SWITCH_ROLE:
1381 /* Tell BTM that the command failed */
1382 /* read bd addr out of stored command */
1383 if (p_cmd != NULL)
1384 {
1385 p_cmd++;
1386 STREAM_TO_BDADDR (bd_addr, p_cmd);
1387 btm_acl_role_changed(status, bd_addr, BTM_ROLE_UNDEFINED);
1388 }
1389 else
1390 btm_acl_role_changed(status, NULL, BTM_ROLE_UNDEFINED);
1391 l2c_link_role_changed (NULL, BTM_ROLE_UNDEFINED, HCI_ERR_COMMAND_DISALLOWED);
1392 break;
1393
1394 case HCI_CREATE_CONNECTION:
1395 /* read bd addr out of stored command */
1396 if (p_cmd != NULL)
1397 {
1398 p_cmd++;
1399 STREAM_TO_BDADDR (bd_addr, p_cmd);
1400 btm_sec_connected (bd_addr, HCI_INVALID_HANDLE, status, 0);
1401 l2c_link_hci_conn_comp (status, HCI_INVALID_HANDLE, bd_addr);
1402 }
1403 break;
1404
Ganesh Ganapathi Batta9d140a92013-04-11 16:13:14 -07001405 case HCI_READ_RMT_EXT_FEATURES:
1406 if (p_cmd != NULL)
1407 {
1408 p_cmd++; /* skip command length */
1409 STREAM_TO_UINT16 (handle, p_cmd);
1410 }
1411 else
1412 handle = HCI_INVALID_HANDLE;
1413
1414 btm_read_remote_ext_features_failed(status, handle);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001415 break;
1416
1417 case HCI_AUTHENTICATION_REQUESTED:
1418 /* Device refused to start authentication. That should be treated as authentication failure. */
1419 btm_sec_auth_complete (BTM_INVALID_HCI_HANDLE, status);
1420 break;
1421
1422 case HCI_SET_CONN_ENCRYPTION:
1423 /* Device refused to start encryption. That should be treated as encryption failure. */
1424 btm_sec_encrypt_change (BTM_INVALID_HCI_HANDLE, status, FALSE);
1425 break;
1426
Priti Aghera24adb372014-09-10 11:42:10 -07001427#if BLE_INCLUDED == TRUE
1428 case HCI_BLE_CREATE_LL_CONN:
1429 btm_ble_create_ll_conn_complete(status);
1430 break;
1431#endif
1432
The Android Open Source Project5738f832012-12-12 16:00:35 -08001433#if BTM_SCO_INCLUDED == TRUE
1434 case HCI_SETUP_ESCO_CONNECTION:
1435 /* read handle out of stored command */
1436 if (p_cmd != NULL)
1437 {
1438 p_cmd++;
1439 STREAM_TO_UINT16 (handle, p_cmd);
1440
1441 /* Determine if initial connection failed or is a change of setup */
1442 if (btm_is_sco_active(handle))
1443 btm_esco_proc_conn_chg (status, handle, 0, 0, 0, 0);
1444 else
1445 btm_sco_connected (status, NULL, handle, &esco_data);
1446 }
1447 break;
1448#endif
1449
1450/* This is commented out until an upper layer cares about returning event
1451#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
1452 case HCI_ENHANCED_FLUSH:
1453 break;
1454#endif
1455*/
1456 default:
1457 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1458 btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback);
1459 break;
1460 }
1461
1462 }
1463 else
1464 {
1465 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1466 btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback);
1467 }
1468#if BTM_PWR_MGR_INCLUDED == TRUE
1469 }
1470#endif
1471}
1472
1473/*******************************************************************************
1474**
1475** Function btu_hcif_command_status_evt
1476**
1477** Description Process event HCI_COMMAND_STATUS_EVT
1478**
1479** Returns void
1480**
1481*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001482static void btu_hcif_command_status_evt (UINT8 controller_id, UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001483{
1484 tHCI_CMD_CB * p_hci_cmd_cb = &(btu_cb.hci_cmd_cb[controller_id]);
1485 UINT8 status;
1486 UINT16 opcode;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001487 UINT16 cmd_opcode;
Ganesh Ganapathi Batta7ffe8962013-04-05 13:42:42 -07001488 BT_HDR *p_cmd = NULL;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001489 UINT8 *p_data = NULL;
1490 void *p_vsc_status_cback = NULL;
1491
1492 STREAM_TO_UINT8 (status, p);
1493 STREAM_TO_UINT8 (p_hci_cmd_cb->cmd_window, p);
1494
1495#if (defined(HCI_MAX_SIMUL_CMDS) && (HCI_MAX_SIMUL_CMDS > 0))
1496 if (p_hci_cmd_cb->cmd_window > HCI_MAX_SIMUL_CMDS)
1497 p_hci_cmd_cb->cmd_window = HCI_MAX_SIMUL_CMDS;
1498#endif
1499
1500 STREAM_TO_UINT16 (opcode, p);
1501
1502 /* only do this for certain commands */
1503 if ((opcode != HCI_RESET) && (opcode != HCI_HOST_NUM_PACKETS_DONE) &&
1504 (opcode != HCI_COMMAND_NONE))
1505 {
Ganesh Ganapathi Batta7ffe8962013-04-05 13:42:42 -07001506 /*look for corresponding command in cmd_queue*/
1507 p_cmd = (BT_HDR *) GKI_getfirst(&(p_hci_cmd_cb->cmd_cmpl_q));
1508 while (p_cmd)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001509 {
The Android Open Source Project5738f832012-12-12 16:00:35 -08001510 p_data = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
1511 STREAM_TO_UINT16 (cmd_opcode, p_data);
1512
Ganesh Ganapathi Batta7ffe8962013-04-05 13:42:42 -07001513 /* Make sure this command is for the command_status received */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001514 if (cmd_opcode != opcode)
1515 {
Ganesh Ganapathi Batta7ffe8962013-04-05 13:42:42 -07001516 /* opcode does not match, check next command in the queue */
1517 p_cmd = (BT_HDR *) GKI_getnext(p_cmd);
1518 continue;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001519 }
Ganesh Ganapathi Batta7ffe8962013-04-05 13:42:42 -07001520 else
The Android Open Source Project5738f832012-12-12 16:00:35 -08001521 {
Ganesh Ganapathi Batta7ffe8962013-04-05 13:42:42 -07001522 GKI_remove_from_queue(&p_hci_cmd_cb->cmd_cmpl_q, p_cmd);
1523
1524 /* If command was a VSC, then extract command_status callback */
1525 if ((cmd_opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC)
1526 {
1527 p_vsc_status_cback = *((void **)(p_cmd + 1));
1528 }
1529 break;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001530 }
1531 }
1532
1533 /* if more commands in queue restart timer */
1534 if (BTU_CMD_CMPL_TIMEOUT > 0)
1535 {
1536 if (!GKI_queue_is_empty (&(p_hci_cmd_cb->cmd_cmpl_q)))
1537 {
1538#if (defined(BTU_CMD_CMPL_TOUT_DOUBLE_CHECK) && BTU_CMD_CMPL_TOUT_DOUBLE_CHECK == TRUE)
1539 p_hci_cmd_cb->checked_hcisu = FALSE;
1540#endif
1541 btu_start_timer (&(p_hci_cmd_cb->cmd_cmpl_timer),
1542 (UINT16)(BTU_TTYPE_BTU_CMD_CMPL + controller_id),
1543 BTU_CMD_CMPL_TIMEOUT);
1544 }
1545 else
1546 {
1547 btu_stop_timer (&(p_hci_cmd_cb->cmd_cmpl_timer));
1548 }
1549 }
1550 }
1551
1552 /* handle command */
Mike J. Chen92c997f2014-01-31 18:07:48 -08001553 btu_hcif_hdl_command_status (opcode, status, p_data, p_vsc_status_cback);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001554
1555 /* free stored command */
1556 if (p_cmd != NULL)
1557 {
1558 GKI_freebuf (p_cmd);
1559 }
Ganesh Ganapathi Batta7ffe8962013-04-05 13:42:42 -07001560 else
1561 {
Mike J. Chend65b00f2014-06-25 18:12:22 -07001562 HCI_TRACE_WARNING("No command in queue matching opcode %d", opcode);
Ganesh Ganapathi Batta7ffe8962013-04-05 13:42:42 -07001563 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001564
1565 /* See if we can forward any more commands */
1566 btu_hcif_send_cmd (controller_id, NULL);
1567}
1568
1569/*******************************************************************************
1570**
1571** Function btu_hcif_cmd_timeout
1572**
1573** Description Handle a command timeout
1574**
1575** Returns void
1576**
1577*******************************************************************************/
1578void btu_hcif_cmd_timeout (UINT8 controller_id)
1579{
1580 tHCI_CMD_CB * p_hci_cmd_cb = &(btu_cb.hci_cmd_cb[controller_id]);
1581 BT_HDR *p_cmd;
1582 UINT8 *p;
1583 void *p_cplt_cback = NULL;
1584 UINT16 opcode;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001585 UINT16 event;
The Android Open Source Project5738f832012-12-12 16:00:35 -08001586
1587#if (defined(BTU_CMD_CMPL_TOUT_DOUBLE_CHECK) && BTU_CMD_CMPL_TOUT_DOUBLE_CHECK == TRUE)
1588 if (!(p_hci_cmd_cb->checked_hcisu))
1589 {
Mike J. Chend65b00f2014-06-25 18:12:22 -07001590 HCI_TRACE_WARNING("BTU HCI(id=%d) command timeout - double check HCISU", controller_id);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001591
1592 /* trigger HCISU to read any pending data in transport buffer */
1593 GKI_send_event(HCISU_TASK, HCISU_EVT_MASK);
1594
1595 btu_start_timer (&(p_hci_cmd_cb->cmd_cmpl_timer),
1596 (UINT16)(BTU_TTYPE_BTU_CMD_CMPL + controller_id),
1597 2); /* start short timer, if timer is set to 1 then it could expire before HCISU checks. */
1598
1599 p_hci_cmd_cb->checked_hcisu = TRUE;
1600
1601 return;
1602 }
1603#endif
1604
1605 /* set the controller cmd window to 1, as if we received a response, so
1606 ** the flow of commands from the stack doesn't hang */
1607 p_hci_cmd_cb->cmd_window = 1;
1608
1609 /* get queued command */
1610 if ((p_cmd = (BT_HDR *) GKI_dequeue (&(p_hci_cmd_cb->cmd_cmpl_q))) == NULL)
1611 {
Mike J. Chend65b00f2014-06-25 18:12:22 -07001612 HCI_TRACE_WARNING("Cmd timeout; no cmd in queue");
The Android Open Source Project5738f832012-12-12 16:00:35 -08001613 return;
1614 }
1615
1616 /* if more commands in queue restart timer */
1617 if (BTU_CMD_CMPL_TIMEOUT > 0)
1618 {
1619 if (!GKI_queue_is_empty (&(p_hci_cmd_cb->cmd_cmpl_q)))
1620 {
1621#if (defined(BTU_CMD_CMPL_TOUT_DOUBLE_CHECK) && BTU_CMD_CMPL_TOUT_DOUBLE_CHECK == TRUE)
1622 p_hci_cmd_cb->checked_hcisu = FALSE;
1623#endif
1624 btu_start_timer (&(p_hci_cmd_cb->cmd_cmpl_timer),
1625 (UINT16)(BTU_TTYPE_BTU_CMD_CMPL + controller_id),
1626 BTU_CMD_CMPL_TIMEOUT);
1627 }
1628 }
1629
1630 p = (UINT8 *)(p_cmd + 1) + p_cmd->offset;
1631#if (NFC_INCLUDED == TRUE)
1632 if (controller_id == NFC_CONTROLLER_ID)
1633 {
1634 //TODO call nfc_ncif_cmd_timeout
Mike J. Chend65b00f2014-06-25 18:12:22 -07001635 HCI_TRACE_WARNING("BTU NCI command timeout - header 0x%02x%02x", p[0], p[1]);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001636 return;
1637 }
1638#endif
1639
1640 /* get opcode from stored command */
1641 STREAM_TO_UINT16 (opcode, p);
1642
1643// btla-specific ++
1644#if (defined(ANDROID_APP_INCLUDED) && (ANDROID_APP_INCLUDED == TRUE))
1645 ALOGE("######################################################################");
1646 ALOGE("#");
1647 ALOGE("# WARNING : BTU HCI(id=%d) command timeout. opcode=0x%x", controller_id, opcode);
1648 ALOGE("#");
1649 ALOGE("######################################################################");
1650#else
Mike J. Chend65b00f2014-06-25 18:12:22 -07001651 HCI_TRACE_WARNING("BTU HCI(id=%d) command timeout. opcode=0x%x", controller_id, opcode);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001652#endif
1653// btla-specific ++
1654
1655 /* send stack a fake command complete or command status, but first determine
1656 ** which to send
1657 */
1658 switch (opcode)
1659 {
1660 case HCI_HOLD_MODE:
1661 case HCI_SNIFF_MODE:
1662 case HCI_EXIT_SNIFF_MODE:
1663 case HCI_PARK_MODE:
1664 case HCI_EXIT_PARK_MODE:
1665 case HCI_INQUIRY:
1666 case HCI_RMT_NAME_REQUEST:
1667 case HCI_QOS_SETUP_COMP_EVT:
1668 case HCI_CREATE_CONNECTION:
1669 case HCI_CHANGE_CONN_LINK_KEY:
1670 case HCI_SWITCH_ROLE:
Ganesh Ganapathi Batta9d140a92013-04-11 16:13:14 -07001671 case HCI_READ_RMT_EXT_FEATURES:
The Android Open Source Project5738f832012-12-12 16:00:35 -08001672 case HCI_AUTHENTICATION_REQUESTED:
1673 case HCI_SET_CONN_ENCRYPTION:
1674#if BTM_SCO_INCLUDED == TRUE
1675 case HCI_SETUP_ESCO_CONNECTION:
1676#endif
1677 /* fake a command status */
Mike J. Chen92c997f2014-01-31 18:07:48 -08001678 btu_hcif_hdl_command_status (opcode, HCI_ERR_UNSPECIFIED, p, NULL);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001679 break;
1680
1681 default:
1682 /* If vendor specific restore the callback function */
1683 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC
1684#if BLE_INCLUDED == TRUE
1685 || (opcode == HCI_BLE_RAND ) ||
1686 (opcode == HCI_BLE_ENCRYPT)
1687#endif
1688 )
1689 {
1690 p_cplt_cback = *((void **)(p_cmd + 1));
The Android Open Source Project5738f832012-12-12 16:00:35 -08001691 }
1692
1693 /* fake a command complete; first create a fake event */
The Android Open Source Project5738f832012-12-12 16:00:35 -08001694 event = HCI_ERR_UNSPECIFIED;
Mike J. Chen92c997f2014-01-31 18:07:48 -08001695 btu_hcif_hdl_command_complete (opcode, (UINT8 *)&event, 1, p_cplt_cback);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001696 break;
1697 }
1698
1699 /* free stored command */
1700 GKI_freebuf(p_cmd);
1701
The Android Open Source Project689d66b2012-12-12 17:18:15 -08001702 num_hci_cmds_timed_out++;
1703 /* When we receive consecutive HCI cmd timeouts for >=BTM_MAX_HCI_CMD_TOUT_BEFORE_RESTART
1704 times, Bluetooth process will be killed and restarted */
1705 if (num_hci_cmds_timed_out >= BTM_MAX_HCI_CMD_TOUT_BEFORE_RESTART)
1706 {
Mike J. Chend65b00f2014-06-25 18:12:22 -07001707 HCI_TRACE_ERROR("Num consecutive HCI Cmd tout =%d Restarting BT process",num_hci_cmds_timed_out);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001708
Bhakthavatsala Raghavendra016380f2013-11-27 13:03:42 -08001709 bte_ssr_cleanup();
Sharvil Nanavati405b5c92016-06-17 14:15:46 -07001710 TEMP_FAILURE_RETRY(usleep(10000)); /* 10 milliseconds */
The Android Open Source Project689d66b2012-12-12 17:18:15 -08001711 /* Killing the process to force a restart as part of fault tolerance */
1712 kill(getpid(), SIGKILL);
1713 }
1714 else
1715 {
Mike J. Chend65b00f2014-06-25 18:12:22 -07001716 HCI_TRACE_WARNING("HCI Cmd timeout counter %d", num_hci_cmds_timed_out);
The Android Open Source Project689d66b2012-12-12 17:18:15 -08001717
1718 /* If anyone wants device status notifications, give him one */
1719 btm_report_device_status (BTM_DEV_STATUS_CMD_TOUT);
1720 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001721 /* See if we can forward any more commands */
1722 btu_hcif_send_cmd (controller_id, NULL);
1723}
1724
1725/*******************************************************************************
1726**
1727** Function btu_hcif_hardware_error_evt
1728**
1729** Description Process event HCI_HARDWARE_ERROR_EVT
1730**
1731** Returns void
1732**
1733*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001734static void btu_hcif_hardware_error_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001735{
Mike J. Chend65b00f2014-06-25 18:12:22 -07001736 HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p);
The Android Open Source Project5738f832012-12-12 16:00:35 -08001737
1738 /* If anyone wants device status notifications, give him one. */
1739 btm_report_device_status (BTM_DEV_STATUS_DOWN);
1740
1741 /* Reset the controller */
1742 if (BTM_IsDeviceUp())
1743 BTM_DeviceReset (NULL);
Bhakthavatsala Raghavendra016380f2013-11-27 13:03:42 -08001744 if(*p == 0x0f)
1745 {
1746 HCI_TRACE_ERROR("Ctlr H/w error event - code:Tigger SSR");
1747 bte_ssr_cleanup();
1748 usleep(20000); /* 20 milliseconds */
1749 /* Killing the process to force a restart as part of fault tolerance */
1750 kill(getpid(), SIGKILL);
1751 }
The Android Open Source Project5738f832012-12-12 16:00:35 -08001752}
1753
1754
1755/*******************************************************************************
1756**
1757** Function btu_hcif_flush_occured_evt
1758**
1759** Description Process event HCI_FLUSH_OCCURED_EVT
1760**
1761** Returns void
1762**
1763*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001764static void btu_hcif_flush_occured_evt (void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001765{
1766}
1767
1768
1769/*******************************************************************************
1770**
1771** Function btu_hcif_role_change_evt
1772**
1773** Description Process event HCI_ROLE_CHANGE_EVT
1774**
1775** Returns void
1776**
1777*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001778static void btu_hcif_role_change_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001779{
1780 UINT8 status;
1781 BD_ADDR bda;
1782 UINT8 role;
1783
1784 STREAM_TO_UINT8 (status, p);
1785 STREAM_TO_BDADDR (bda, p);
1786 STREAM_TO_UINT8 (role, p);
1787
1788 l2c_link_role_changed (bda, role, status);
1789 btm_acl_role_changed(status, bda, role);
1790}
1791
1792
1793/*******************************************************************************
1794**
1795** Function btu_hcif_num_compl_data_pkts_evt
1796**
1797** Description Process event HCI_NUM_COMPL_DATA_PKTS_EVT
1798**
1799** Returns void
1800**
1801*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001802static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001803{
1804 /* Process for L2CAP and SCO */
1805 l2c_link_process_num_completed_pkts (p);
1806
1807 /* Send on to SCO */
1808 /*?? No SCO for now */
1809}
1810
1811/*******************************************************************************
1812**
1813** Function btu_hcif_mode_change_evt
1814**
1815** Description Process event HCI_MODE_CHANGE_EVT
1816**
1817** Returns void
1818**
1819*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001820static void btu_hcif_mode_change_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001821{
1822 UINT8 status;
1823 UINT16 handle;
1824 UINT8 current_mode;
1825 UINT16 interval;
1826
1827 STREAM_TO_UINT8 (status, p);
1828
1829 STREAM_TO_UINT16 (handle, p);
1830 STREAM_TO_UINT8 (current_mode, p);
1831 STREAM_TO_UINT16 (interval, p);
1832#if BTM_PWR_MGR_INCLUDED == TRUE
1833#if BTM_SCO_WAKE_PARKED_LINK == TRUE
1834 btm_sco_chk_pend_unpark (status, handle);
1835#endif
1836 btm_pm_proc_mode_change (status, handle, current_mode, interval);
1837#else
1838 btm_process_mode_change (status, handle, current_mode, interval);
1839#endif /* BTM_PWR_MGR_INCLUDED == TRUE */
1840
1841#if (HID_DEV_INCLUDED == TRUE) && (HID_DEV_PM_INCLUDED == TRUE)
1842 hidd_pm_proc_mode_change( status, current_mode, interval ) ;
1843#endif
1844}
1845
1846/*******************************************************************************
1847**
1848** Function btu_hcif_ssr_evt
1849**
1850** Description Process event HCI_SNIFF_SUB_RATE_EVT
1851**
1852** Returns void
1853**
1854*******************************************************************************/
1855 #if (BTM_SSR_INCLUDED == TRUE)
1856static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len)
1857{
1858#if (BTM_PWR_MGR_INCLUDED == TRUE)
1859 btm_pm_proc_ssr_evt(p, evt_len);
1860#endif
1861}
1862 #endif
1863
1864
1865/*******************************************************************************
1866**
1867** Function btu_hcif_return_link_keys_evt
1868**
1869** Description Process event HCI_RETURN_LINK_KEYS_EVT
1870**
1871** Returns void
1872**
1873*******************************************************************************/
1874
Mike J. Chen92c997f2014-01-31 18:07:48 -08001875static void btu_hcif_return_link_keys_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001876{
1877 UINT8 num_keys;
1878 tBTM_RETURN_LINK_KEYS_EVT *result;
1879
1880 /* get the number of link keys */
1881 num_keys = *p;
1882
1883 /* If there are no link keys don't call the call back */
1884 if (!num_keys)
1885 return;
1886
1887 /* Take one extra byte at the beginning to specify event */
1888 result = (tBTM_RETURN_LINK_KEYS_EVT *)(--p);
1889 result->event = BTM_CB_EVT_RETURN_LINK_KEYS;
1890
1891 /* Call the BTM function to pass the link keys to application */
1892 btm_return_link_keys_evt (result);
1893}
1894
1895
1896/*******************************************************************************
1897**
1898** Function btu_hcif_pin_code_request_evt
1899**
1900** Description Process event HCI_PIN_CODE_REQUEST_EVT
1901**
1902** Returns void
1903**
1904*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001905static void btu_hcif_pin_code_request_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001906{
1907 BD_ADDR bda;
1908
1909 STREAM_TO_BDADDR (bda, p);
1910
1911 /* Tell L2CAP that there was a PIN code request, */
1912 /* it may need to stretch timeouts */
1913 l2c_pin_code_request (bda);
1914
1915 btm_sec_pin_code_request (bda);
1916}
1917
1918
1919/*******************************************************************************
1920**
1921** Function btu_hcif_link_key_request_evt
1922**
1923** Description Process event HCI_LINK_KEY_REQUEST_EVT
1924**
1925** Returns void
1926**
1927*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001928static void btu_hcif_link_key_request_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001929{
1930 BD_ADDR bda;
1931
1932 STREAM_TO_BDADDR (bda, p);
1933 btm_sec_link_key_request (bda);
1934}
1935
1936
1937/*******************************************************************************
1938**
1939** Function btu_hcif_link_key_notification_evt
1940**
1941** Description Process event HCI_LINK_KEY_NOTIFICATION_EVT
1942**
1943** Returns void
1944**
1945*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001946static void btu_hcif_link_key_notification_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001947{
1948 BD_ADDR bda;
1949 LINK_KEY key;
1950 UINT8 key_type;
1951
1952 STREAM_TO_BDADDR (bda, p);
1953 STREAM_TO_ARRAY16 (key, p);
1954 STREAM_TO_UINT8 (key_type, p);
1955
1956 btm_sec_link_key_notification (bda, key, key_type);
1957}
1958
1959
1960/*******************************************************************************
1961**
1962** Function btu_hcif_loopback_command_evt
1963**
1964** Description Process event HCI_LOOPBACK_COMMAND_EVT
1965**
1966** Returns void
1967**
1968*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001969static void btu_hcif_loopback_command_evt (void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001970{
1971}
1972
1973
1974/*******************************************************************************
1975**
1976** Function btu_hcif_data_buf_overflow_evt
1977**
1978** Description Process event HCI_DATA_BUF_OVERFLOW_EVT
1979**
1980** Returns void
1981**
1982*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001983static void btu_hcif_data_buf_overflow_evt (void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001984{
1985}
1986
1987
1988/*******************************************************************************
1989**
1990** Function btu_hcif_max_slots_changed_evt
1991**
1992** Description Process event HCI_MAX_SLOTS_CHANGED_EVT
1993**
1994** Returns void
1995**
1996*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08001997static void btu_hcif_max_slots_changed_evt (void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08001998{
1999}
2000
2001
2002/*******************************************************************************
2003**
2004** Function btu_hcif_read_clock_off_comp_evt
2005**
2006** Description Process event HCI_READ_CLOCK_OFF_COMP_EVT
2007**
2008** Returns void
2009**
2010*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002011static void btu_hcif_read_clock_off_comp_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002012{
2013 UINT8 status;
2014 UINT16 handle;
2015 UINT16 clock_offset;
2016
2017 STREAM_TO_UINT8 (status, p);
2018
2019 /* If failed to get clock offset just drop the result */
2020 if (status != HCI_SUCCESS)
2021 return;
2022
2023 STREAM_TO_UINT16 (handle, p);
2024 STREAM_TO_UINT16 (clock_offset, p);
2025
2026 handle = HCID_GET_HANDLE (handle);
2027
2028 btm_process_clk_off_comp_evt (handle, clock_offset);
2029 btm_sec_update_clock_offset (handle, clock_offset);
2030}
2031
2032
2033/*******************************************************************************
2034**
2035** Function btu_hcif_conn_pkt_type_change_evt
2036**
2037** Description Process event HCI_CONN_PKT_TYPE_CHANGE_EVT
2038**
2039** Returns void
2040**
2041*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002042static void btu_hcif_conn_pkt_type_change_evt (void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002043{
2044}
2045
2046
2047/*******************************************************************************
2048**
2049** Function btu_hcif_qos_violation_evt
2050**
2051** Description Process event HCI_QOS_VIOLATION_EVT
2052**
2053** Returns void
2054**
2055*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002056static void btu_hcif_qos_violation_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002057{
2058 UINT16 handle;
2059
2060 STREAM_TO_UINT16 (handle, p);
2061
2062 handle = HCID_GET_HANDLE (handle);
2063
2064
2065 l2c_link_hci_qos_violation (handle);
2066}
2067
2068
2069/*******************************************************************************
2070**
2071** Function btu_hcif_page_scan_mode_change_evt
2072**
2073** Description Process event HCI_PAGE_SCAN_MODE_CHANGE_EVT
2074**
2075** Returns void
2076**
2077*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002078static void btu_hcif_page_scan_mode_change_evt (void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002079{
2080}
2081
2082
2083/*******************************************************************************
2084**
2085** Function btu_hcif_page_scan_rep_mode_chng_evt
2086**
2087** Description Process event HCI_PAGE_SCAN_REP_MODE_CHNG_EVT
2088**
2089** Returns void
2090**
2091*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002092static void btu_hcif_page_scan_rep_mode_chng_evt (void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002093{
2094}
2095
2096/**********************************************
2097** Simple Pairing Events
2098***********************************************/
2099
2100/*******************************************************************************
2101**
2102** Function btu_hcif_host_support_evt
2103**
2104** Description Process event HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT
2105**
2106** Returns void
2107**
2108*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002109static void btu_hcif_host_support_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002110{
2111 btm_sec_rmt_host_support_feat_evt(p);
2112}
2113
2114/*******************************************************************************
2115**
2116** Function btu_hcif_io_cap_request_evt
2117**
2118** Description Process event HCI_IO_CAPABILITY_REQUEST_EVT
2119**
2120** Returns void
2121**
2122*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002123static void btu_hcif_io_cap_request_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002124{
2125 btm_io_capabilities_req(p);
2126}
2127
2128
2129/*******************************************************************************
2130**
2131** Function btu_hcif_io_cap_response_evt
2132**
2133** Description Process event HCI_IO_CAPABILITY_RESPONSE_EVT
2134**
2135** Returns void
2136**
2137*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002138static void btu_hcif_io_cap_response_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002139{
2140 btm_io_capabilities_rsp(p);
2141}
2142
2143
2144/*******************************************************************************
2145**
2146** Function btu_hcif_user_conf_request_evt
2147**
2148** Description Process event HCI_USER_CONFIRMATION_REQUEST_EVT
2149**
2150** Returns void
2151**
2152*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002153static void btu_hcif_user_conf_request_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002154{
2155 btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p);
2156}
2157
2158
2159/*******************************************************************************
2160**
2161** Function btu_hcif_user_passkey_request_evt
2162**
2163** Description Process event HCI_USER_PASSKEY_REQUEST_EVT
2164**
2165** Returns void
2166**
2167*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002168static void btu_hcif_user_passkey_request_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002169{
2170 btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p);
2171}
2172
2173/*******************************************************************************
2174**
2175** Function btu_hcif_user_passkey_notif_evt
2176**
2177** Description Process event HCI_USER_PASSKEY_NOTIFY_EVT
2178**
2179** Returns void
2180**
2181*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002182static void btu_hcif_user_passkey_notif_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002183{
2184 btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p);
2185}
2186
2187/*******************************************************************************
2188**
2189** Function btu_hcif_keypress_notif_evt
2190**
2191** Description Process event HCI_KEYPRESS_NOTIFY_EVT
2192**
2193** Returns void
2194**
2195*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002196static void btu_hcif_keypress_notif_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002197{
2198 btm_keypress_notif_evt(p);
2199}
2200
2201/*******************************************************************************
2202**
2203** Function btu_hcif_link_super_tout_evt
2204**
2205** Description Process event HCI_LINK_SUPER_TOUT_CHANGED_EVT
2206**
2207** Returns void
2208**
2209*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002210static void btu_hcif_link_super_tout_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002211{
2212 UINT16 handle, timeout;
2213 STREAM_TO_UINT16 (handle, p);
2214 STREAM_TO_UINT16 (timeout, p);
2215
2216 btm_proc_lsto_evt(handle, timeout);
2217}
2218
2219/*******************************************************************************
2220**
2221** Function btu_hcif_rem_oob_request_evt
2222**
2223** Description Process event HCI_REMOTE_OOB_DATA_REQUEST_EVT
2224**
2225** Returns void
2226**
2227*******************************************************************************/
2228 #if BTM_OOB_INCLUDED == TRUE
Mike J. Chen92c997f2014-01-31 18:07:48 -08002229static void btu_hcif_rem_oob_request_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002230{
2231 btm_rem_oob_req(p);
2232}
2233 #endif
2234
2235/*******************************************************************************
2236**
2237** Function btu_hcif_simple_pair_complete_evt
2238**
2239** Description Process event HCI_SIMPLE_PAIRING_COMPLETE_EVT
2240**
2241** Returns void
2242**
2243*******************************************************************************/
Mike J. Chen92c997f2014-01-31 18:07:48 -08002244static void btu_hcif_simple_pair_complete_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002245{
2246 btm_simple_pair_complete(p);
2247}
2248/*******************************************************************************
2249**
2250** Function btu_hcif_flush_cmd_queue
2251**
2252** Description Flush the HCI command complete queue and transmit queue when
2253** needed.
2254**
2255** Returns void
2256**
2257*******************************************************************************/
2258void btu_hcif_flush_cmd_queue(void)
2259{
2260 BT_HDR *p_cmd;
2261
2262 btu_cb.hci_cmd_cb[0].cmd_window = 0;
2263 while ((p_cmd = (BT_HDR *) GKI_dequeue (&btu_cb.hci_cmd_cb[0].cmd_cmpl_q)) != NULL)
2264 {
2265 GKI_freebuf (p_cmd);
2266 }
2267 while ((p_cmd = (BT_HDR *) GKI_dequeue (&btu_cb.hci_cmd_cb[0].cmd_xmit_q)) != NULL)
2268 {
2269 GKI_freebuf (p_cmd);
2270 }
2271}
2272
2273/*******************************************************************************
2274**
2275** Function btu_hcif_enhanced_flush_complete_evt
2276**
2277** Description Process event HCI_ENHANCED_FLUSH_COMPLETE_EVT
2278**
2279** Returns void
2280**
2281*******************************************************************************/
2282#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
Mike J. Chen92c997f2014-01-31 18:07:48 -08002283static void btu_hcif_enhanced_flush_complete_evt (void)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002284{
2285/* This is empty until an upper layer cares about returning event */
2286}
2287#endif
2288/**********************************************
2289** End of Simple Pairing Events
2290***********************************************/
2291
2292
2293/**********************************************
2294** BLE Events
2295***********************************************/
2296#if (defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE)
Mike J. Chen92c997f2014-01-31 18:07:48 -08002297static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002298{
2299 UINT8 status;
Andre Eisenbachad839862013-06-24 13:19:13 -07002300 UINT8 enc_enable = 0;
The Android Open Source Project5738f832012-12-12 16:00:35 -08002301 UINT16 handle;
2302
2303 STREAM_TO_UINT8 (status, p);
2304 STREAM_TO_UINT16 (handle, p);
2305
Andre Eisenbachad839862013-06-24 13:19:13 -07002306 if (status == HCI_SUCCESS) enc_enable = 1;
2307
2308 btm_sec_encrypt_change (handle, status, enc_enable);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002309}
2310
Mike J. Chen92c997f2014-01-31 18:07:48 -08002311static void btu_ble_process_adv_pkt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002312{
Mike J. Chend65b00f2014-06-25 18:12:22 -07002313 HCI_TRACE_EVENT("btu_ble_process_adv_pkt");
The Android Open Source Project5738f832012-12-12 16:00:35 -08002314
2315 btm_ble_process_adv_pkt(p);
2316}
2317
The Android Open Source Project5738f832012-12-12 16:00:35 -08002318static void btu_ble_ll_conn_complete_evt ( UINT8 *p, UINT16 evt_len)
2319{
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002320 btm_ble_conn_complete(p, evt_len);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002321}
2322
Chaojing Sun97e75b72014-10-07 17:07:05 -07002323static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002324{
Chaojing Sun97e75b72014-10-07 17:07:05 -07002325 /* LE connection update has completed successfully as a master. */
2326 /* We can enable the update request if the result is a success. */
2327 /* extract the HCI handle first */
2328 UINT8 status;
2329 UINT16 handle;
2330
2331 STREAM_TO_UINT8 (status, p);
2332 STREAM_TO_UINT16 (handle, p);
2333 l2cble_process_conn_update_evt(handle, status);
The Android Open Source Project5738f832012-12-12 16:00:35 -08002334}
2335
Mike J. Chen92c997f2014-01-31 18:07:48 -08002336static void btu_ble_read_remote_feat_evt (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002337{
2338 btm_ble_read_remote_features_complete(p);
2339}
2340
Mike J. Chen92c997f2014-01-31 18:07:48 -08002341static void btu_ble_proc_ltk_req (UINT8 *p)
The Android Open Source Project5738f832012-12-12 16:00:35 -08002342{
2343 UINT16 ediv, handle;
2344 UINT8 *pp;
2345
2346 STREAM_TO_UINT16(handle, p);
2347 pp = p + 8;
2348 STREAM_TO_UINT16(ediv, pp);
Ganesh Ganapathi Battaead3cde2013-02-05 15:22:31 -08002349#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE
The Android Open Source Project5738f832012-12-12 16:00:35 -08002350 btm_ble_ltk_request(handle, p, ediv);
2351#endif
2352 /* This is empty until an upper layer cares about returning event */
2353}
2354/**********************************************
2355** End of BLE Events Handler
2356***********************************************/
Ganesh Ganapathi Batta7fa4fba2014-04-16 16:50:09 -07002357#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE)
2358static void btu_ble_rc_param_req_evt(UINT8 *p)
2359{
2360 UINT16 handle;
2361 UINT16 int_min, int_max, latency, timeout;
2362
2363 STREAM_TO_UINT16(handle, p);
2364 STREAM_TO_UINT16(int_min, p);
2365 STREAM_TO_UINT16(int_max, p);
2366 STREAM_TO_UINT16(latency, p);
2367 STREAM_TO_UINT16(timeout, p);
2368
2369 l2cble_process_rc_param_request_evt(handle, int_min, int_max, latency, timeout);
2370}
2371#endif /* BLE_LLT_INCLUDED */
2372
The Android Open Source Project5738f832012-12-12 16:00:35 -08002373#endif /* BLE_INCLUDED */