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 <assert.h> 31#include <stdio.h> 32#include <stdlib.h> 33#include <string.h> 34 35#include "device/include/controller.h" 36#include "osi/include/log.h" 37#include "osi/include/osi.h" 38#include "bt_types.h" 39#include "bt_utils.h" 40#include "btm_api.h" 41#include "btm_int.h" 42#include "btu.h" 43#include "bt_common.h" 44#include "hci_layer.h" 45#include "hcimsgs.h" 46#include "l2c_int.h" 47 48// TODO(zachoverflow): remove this horrible hack 49#include "btu.h" 50extern fixed_queue_t *btu_hci_msg_queue; 51 52extern void btm_process_cancel_complete(UINT8 status, UINT8 mode); 53extern 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/********************************************************************************/ 58static void btu_hcif_inquiry_comp_evt (UINT8 *p); 59static void btu_hcif_inquiry_result_evt (UINT8 *p); 60static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p); 61static void btu_hcif_extended_inquiry_result_evt (UINT8 *p); 62 63static void btu_hcif_connection_comp_evt (UINT8 *p); 64static void btu_hcif_connection_request_evt (UINT8 *p); 65static void btu_hcif_disconnection_comp_evt (UINT8 *p); 66static void btu_hcif_authentication_comp_evt (UINT8 *p); 67static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len); 68static void btu_hcif_encryption_change_evt (UINT8 *p); 69static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p); 70static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p); 71static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p); 72static void btu_hcif_qos_setup_comp_evt (UINT8 *p); 73static void btu_hcif_command_complete_evt (BT_HDR *response, void *context); 74static void btu_hcif_command_status_evt (uint8_t status, BT_HDR *command, void *context); 75static void btu_hcif_hardware_error_evt (UINT8 *p); 76static void btu_hcif_flush_occured_evt (void); 77static void btu_hcif_role_change_evt (UINT8 *p); 78static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p); 79static void btu_hcif_mode_change_evt (UINT8 *p); 80static void btu_hcif_pin_code_request_evt (UINT8 *p); 81static void btu_hcif_link_key_request_evt (UINT8 *p); 82static void btu_hcif_link_key_notification_evt (UINT8 *p); 83static void btu_hcif_loopback_command_evt (void); 84static void btu_hcif_data_buf_overflow_evt (void); 85static void btu_hcif_max_slots_changed_evt (void); 86static void btu_hcif_read_clock_off_comp_evt (UINT8 *p); 87static void btu_hcif_conn_pkt_type_change_evt (void); 88static void btu_hcif_qos_violation_evt (UINT8 *p); 89static void btu_hcif_page_scan_mode_change_evt (void); 90static void btu_hcif_page_scan_rep_mode_chng_evt (void); 91static void btu_hcif_esco_connection_comp_evt(UINT8 *p); 92static void btu_hcif_esco_connection_chg_evt(UINT8 *p); 93 94/* Simple Pairing Events */ 95static void btu_hcif_host_support_evt (UINT8 *p); 96static void btu_hcif_io_cap_request_evt (UINT8 *p); 97static void btu_hcif_io_cap_response_evt (UINT8 *p); 98static void btu_hcif_user_conf_request_evt (UINT8 *p); 99static void btu_hcif_user_passkey_request_evt (UINT8 *p); 100static void btu_hcif_user_passkey_notif_evt (UINT8 *p); 101static void btu_hcif_keypress_notif_evt (UINT8 *p); 102static void btu_hcif_rem_oob_request_evt (UINT8 *p); 103 104static void btu_hcif_simple_pair_complete_evt (UINT8 *p); 105 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE 106static void btu_hcif_enhanced_flush_complete_evt (void); 107 #endif 108 109 #if (BTM_SSR_INCLUDED == TRUE) 110static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len); 111 #endif /* BTM_SSR_INCLUDED == TRUE */ 112 113 #if BLE_INCLUDED == TRUE 114static void btu_ble_ll_conn_complete_evt (UINT8 *p, UINT16 evt_len); 115static void btu_ble_process_adv_pkt (UINT8 *p); 116static void btu_ble_read_remote_feat_evt (UINT8 *p); 117static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len); 118static void btu_ble_proc_ltk_req (UINT8 *p); 119static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p); 120static void btu_ble_data_length_change_evt (UINT8 *p, UINT16 evt_len); 121#if (BLE_LLT_INCLUDED == TRUE) 122static void btu_ble_rc_param_req_evt(UINT8 *p); 123#endif 124#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) 125static void btu_ble_proc_enhanced_conn_cmpl (UINT8 *p, UINT16 evt_len); 126#endif 127 128 #endif 129 130/******************************************************************************* 131** 132** Function btu_hcif_process_event 133** 134** Description This function is called when an event is received from 135** the Host Controller. 136** 137** Returns void 138** 139*******************************************************************************/ 140void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg) 141{ 142 UINT8 *p = (UINT8 *)(p_msg + 1) + p_msg->offset; 143 UINT8 hci_evt_code, hci_evt_len; 144#if BLE_INCLUDED == TRUE 145 UINT8 ble_sub_code; 146#endif 147 STREAM_TO_UINT8 (hci_evt_code, p); 148 STREAM_TO_UINT8 (hci_evt_len, p); 149 150 switch (hci_evt_code) 151 { 152 case HCI_INQUIRY_COMP_EVT: 153 btu_hcif_inquiry_comp_evt (p); 154 break; 155 case HCI_INQUIRY_RESULT_EVT: 156 btu_hcif_inquiry_result_evt (p); 157 break; 158 case HCI_INQUIRY_RSSI_RESULT_EVT: 159 btu_hcif_inquiry_rssi_result_evt (p); 160 break; 161 case HCI_EXTENDED_INQUIRY_RESULT_EVT: 162 btu_hcif_extended_inquiry_result_evt (p); 163 break; 164 case HCI_CONNECTION_COMP_EVT: 165 btu_hcif_connection_comp_evt (p); 166 break; 167 case HCI_CONNECTION_REQUEST_EVT: 168 btu_hcif_connection_request_evt (p); 169 break; 170 case HCI_DISCONNECTION_COMP_EVT: 171 btu_hcif_disconnection_comp_evt (p); 172 break; 173 case HCI_AUTHENTICATION_COMP_EVT: 174 btu_hcif_authentication_comp_evt (p); 175 break; 176 case HCI_RMT_NAME_REQUEST_COMP_EVT: 177 btu_hcif_rmt_name_request_comp_evt (p, hci_evt_len); 178 break; 179 case HCI_ENCRYPTION_CHANGE_EVT: 180 btu_hcif_encryption_change_evt (p); 181 break; 182#if BLE_INCLUDED == TRUE 183 case HCI_ENCRYPTION_KEY_REFRESH_COMP_EVT: 184 btu_hcif_encryption_key_refresh_cmpl_evt(p); 185 break; 186#endif 187 case HCI_READ_RMT_FEATURES_COMP_EVT: 188 btu_hcif_read_rmt_features_comp_evt (p); 189 break; 190 case HCI_READ_RMT_EXT_FEATURES_COMP_EVT: 191 btu_hcif_read_rmt_ext_features_comp_evt (p); 192 break; 193 case HCI_READ_RMT_VERSION_COMP_EVT: 194 btu_hcif_read_rmt_version_comp_evt (p); 195 break; 196 case HCI_QOS_SETUP_COMP_EVT: 197 btu_hcif_qos_setup_comp_evt (p); 198 break; 199 case HCI_COMMAND_COMPLETE_EVT: 200 LOG_ERROR(LOG_TAG, "%s should not have received a command complete event. " 201 "Someone didn't go through the hci transmit_command function.", __func__); 202 break; 203 case HCI_COMMAND_STATUS_EVT: 204 LOG_ERROR(LOG_TAG, "%s should not have received a command status event. " 205 "Someone didn't go through the hci transmit_command function.", __func__); 206 break; 207 case HCI_HARDWARE_ERROR_EVT: 208 btu_hcif_hardware_error_evt (p); 209 break; 210 case HCI_FLUSH_OCCURED_EVT: 211 btu_hcif_flush_occured_evt (); 212 break; 213 case HCI_ROLE_CHANGE_EVT: 214 btu_hcif_role_change_evt (p); 215 break; 216 case HCI_NUM_COMPL_DATA_PKTS_EVT: 217 btu_hcif_num_compl_data_pkts_evt (p); 218 break; 219 case HCI_MODE_CHANGE_EVT: 220 btu_hcif_mode_change_evt (p); 221 break; 222 case HCI_PIN_CODE_REQUEST_EVT: 223 btu_hcif_pin_code_request_evt (p); 224 break; 225 case HCI_LINK_KEY_REQUEST_EVT: 226 btu_hcif_link_key_request_evt (p); 227 break; 228 case HCI_LINK_KEY_NOTIFICATION_EVT: 229 btu_hcif_link_key_notification_evt (p); 230 break; 231 case HCI_LOOPBACK_COMMAND_EVT: 232 btu_hcif_loopback_command_evt (); 233 break; 234 case HCI_DATA_BUF_OVERFLOW_EVT: 235 btu_hcif_data_buf_overflow_evt (); 236 break; 237 case HCI_MAX_SLOTS_CHANGED_EVT: 238 btu_hcif_max_slots_changed_evt (); 239 break; 240 case HCI_READ_CLOCK_OFF_COMP_EVT: 241 btu_hcif_read_clock_off_comp_evt (p); 242 break; 243 case HCI_CONN_PKT_TYPE_CHANGE_EVT: 244 btu_hcif_conn_pkt_type_change_evt (); 245 break; 246 case HCI_QOS_VIOLATION_EVT: 247 btu_hcif_qos_violation_evt (p); 248 break; 249 case HCI_PAGE_SCAN_MODE_CHANGE_EVT: 250 btu_hcif_page_scan_mode_change_evt (); 251 break; 252 case HCI_PAGE_SCAN_REP_MODE_CHNG_EVT: 253 btu_hcif_page_scan_rep_mode_chng_evt (); 254 break; 255 case HCI_ESCO_CONNECTION_COMP_EVT: 256 btu_hcif_esco_connection_comp_evt (p); 257 break; 258 case HCI_ESCO_CONNECTION_CHANGED_EVT: 259 btu_hcif_esco_connection_chg_evt (p); 260 break; 261#if (BTM_SSR_INCLUDED == TRUE) 262 case HCI_SNIFF_SUB_RATE_EVT: 263 btu_hcif_ssr_evt (p, hci_evt_len); 264 break; 265#endif /* BTM_SSR_INCLUDED == TRUE */ 266 case HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT: 267 btu_hcif_host_support_evt (p); 268 break; 269 case HCI_IO_CAPABILITY_REQUEST_EVT: 270 btu_hcif_io_cap_request_evt (p); 271 break; 272 case HCI_IO_CAPABILITY_RESPONSE_EVT: 273 btu_hcif_io_cap_response_evt (p); 274 break; 275 case HCI_USER_CONFIRMATION_REQUEST_EVT: 276 btu_hcif_user_conf_request_evt (p); 277 break; 278 case HCI_USER_PASSKEY_REQUEST_EVT: 279 btu_hcif_user_passkey_request_evt (p); 280 break; 281 case HCI_REMOTE_OOB_DATA_REQUEST_EVT: 282 btu_hcif_rem_oob_request_evt (p); 283 break; 284 case HCI_SIMPLE_PAIRING_COMPLETE_EVT: 285 btu_hcif_simple_pair_complete_evt (p); 286 break; 287 case HCI_USER_PASSKEY_NOTIFY_EVT: 288 btu_hcif_user_passkey_notif_evt (p); 289 break; 290 case HCI_KEYPRESS_NOTIFY_EVT: 291 btu_hcif_keypress_notif_evt (p); 292 break; 293#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE 294 case HCI_ENHANCED_FLUSH_COMPLETE_EVT: 295 btu_hcif_enhanced_flush_complete_evt (); 296 break; 297#endif 298 299#if (BLE_INCLUDED == TRUE) 300 case HCI_BLE_EVENT: 301 STREAM_TO_UINT8 (ble_sub_code, p); 302 303 HCI_TRACE_EVENT("BLE HCI(id=%d) event = 0x%02x)", hci_evt_code, ble_sub_code); 304 305 switch (ble_sub_code) 306 { 307 case HCI_BLE_ADV_PKT_RPT_EVT: /* result of inquiry */ 308 btu_ble_process_adv_pkt(p); 309 break; 310 case HCI_BLE_CONN_COMPLETE_EVT: 311 btu_ble_ll_conn_complete_evt(p, hci_evt_len); 312 break; 313 case HCI_BLE_LL_CONN_PARAM_UPD_EVT: 314 btu_ble_ll_conn_param_upd_evt(p, hci_evt_len); 315 break; 316 case HCI_BLE_READ_REMOTE_FEAT_CMPL_EVT: 317 btu_ble_read_remote_feat_evt(p); 318 break; 319 case HCI_BLE_LTK_REQ_EVT: /* received only at slave device */ 320 btu_ble_proc_ltk_req(p); 321 break; 322#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) 323 case HCI_BLE_ENHANCED_CONN_COMPLETE_EVT: 324 btu_ble_proc_enhanced_conn_cmpl(p, hci_evt_len); 325 break; 326#endif 327#if (BLE_LLT_INCLUDED == TRUE) 328 case HCI_BLE_RC_PARAM_REQ_EVT: 329 btu_ble_rc_param_req_evt(p); 330 break; 331#endif 332 case HCI_BLE_DATA_LENGTH_CHANGE_EVT: 333 btu_ble_data_length_change_evt(p, hci_evt_len); 334 break; 335 } 336 break; 337#endif /* BLE_INCLUDED */ 338 case HCI_VENDOR_SPECIFIC_EVT: 339 btm_vendor_specific_evt (p, hci_evt_len); 340 break; 341 } 342} 343 344/******************************************************************************* 345** 346** Function btu_hcif_send_cmd 347** 348** Description This function is called to send commands to the Host Controller. 349** 350** Returns void 351** 352*******************************************************************************/ 353void btu_hcif_send_cmd (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_buf) 354{ 355 if (!p_buf) 356 return; 357 358 uint16_t opcode; 359 uint8_t *stream = p_buf->data + p_buf->offset; 360 void * vsc_callback = NULL; 361 362 STREAM_TO_UINT16(opcode, stream); 363 364 // Eww...horrible hackery here 365 /* If command was a VSC, then extract command_complete callback */ 366 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC 367#if BLE_INCLUDED == TRUE 368 || (opcode == HCI_BLE_RAND) 369 || (opcode == HCI_BLE_ENCRYPT) 370#endif 371 ) { 372 vsc_callback = *((void **)(p_buf + 1)); 373 } 374 375 hci_layer_get_interface()->transmit_command( 376 p_buf, 377 btu_hcif_command_complete_evt, 378 btu_hcif_command_status_evt, 379 vsc_callback); 380 381#if (defined(HCILP_INCLUDED) && HCILP_INCLUDED == TRUE) 382 btu_check_bt_sleep (); 383#endif 384} 385 386/******************************************************************************* 387** 388** Function btu_hcif_inquiry_comp_evt 389** 390** Description Process event HCI_INQUIRY_COMP_EVT 391** 392** Returns void 393** 394*******************************************************************************/ 395static void btu_hcif_inquiry_comp_evt (UINT8 *p) 396{ 397 UINT8 status; 398 399 STREAM_TO_UINT8 (status, p); 400 401 /* Tell inquiry processing that we are done */ 402 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK); 403} 404 405/******************************************************************************* 406** 407** Function btu_hcif_inquiry_result_evt 408** 409** Description Process event HCI_INQUIRY_RESULT_EVT 410** 411** Returns void 412** 413*******************************************************************************/ 414static void btu_hcif_inquiry_result_evt (UINT8 *p) 415{ 416 /* Store results in the cache */ 417 btm_process_inq_results (p, BTM_INQ_RESULT_STANDARD); 418} 419 420/******************************************************************************* 421** 422** Function btu_hcif_inquiry_rssi_result_evt 423** 424** Description Process event HCI_INQUIRY_RSSI_RESULT_EVT 425** 426** Returns void 427** 428*******************************************************************************/ 429static void btu_hcif_inquiry_rssi_result_evt (UINT8 *p) 430{ 431 /* Store results in the cache */ 432 btm_process_inq_results (p, BTM_INQ_RESULT_WITH_RSSI); 433} 434 435/******************************************************************************* 436** 437** Function btu_hcif_extended_inquiry_result_evt 438** 439** Description Process event HCI_EXTENDED_INQUIRY_RESULT_EVT 440** 441** Returns void 442** 443*******************************************************************************/ 444static void btu_hcif_extended_inquiry_result_evt (UINT8 *p) 445{ 446 /* Store results in the cache */ 447 btm_process_inq_results (p, BTM_INQ_RESULT_EXTENDED); 448} 449 450/******************************************************************************* 451** 452** Function btu_hcif_connection_comp_evt 453** 454** Description Process event HCI_CONNECTION_COMP_EVT 455** 456** Returns void 457** 458*******************************************************************************/ 459static void btu_hcif_connection_comp_evt (UINT8 *p) 460{ 461 UINT8 status; 462 UINT16 handle; 463 BD_ADDR bda; 464 UINT8 link_type; 465 UINT8 enc_mode; 466#if BTM_SCO_INCLUDED == TRUE 467 tBTM_ESCO_DATA esco_data; 468#endif 469 470 STREAM_TO_UINT8 (status, p); 471 STREAM_TO_UINT16 (handle, p); 472 STREAM_TO_BDADDR (bda, p); 473 STREAM_TO_UINT8 (link_type, p); 474 STREAM_TO_UINT8 (enc_mode, p); 475 476 handle = HCID_GET_HANDLE (handle); 477 478 if (link_type == HCI_LINK_TYPE_ACL) 479 { 480 btm_sec_connected (bda, handle, status, enc_mode); 481 482 l2c_link_hci_conn_comp (status, handle, bda); 483 } 484#if BTM_SCO_INCLUDED == TRUE 485 else 486 { 487 memset(&esco_data, 0, sizeof(tBTM_ESCO_DATA)); 488 /* esco_data.link_type = HCI_LINK_TYPE_SCO; already zero */ 489 memcpy (esco_data.bd_addr, bda, BD_ADDR_LEN); 490 btm_sco_connected (status, bda, handle, &esco_data); 491 } 492#endif /* BTM_SCO_INCLUDED */ 493} 494 495/******************************************************************************* 496** 497** Function btu_hcif_connection_request_evt 498** 499** Description Process event HCI_CONNECTION_REQUEST_EVT 500** 501** Returns void 502** 503*******************************************************************************/ 504static void btu_hcif_connection_request_evt (UINT8 *p) 505{ 506 BD_ADDR bda; 507 DEV_CLASS dc; 508 UINT8 link_type; 509 510 STREAM_TO_BDADDR (bda, p); 511 STREAM_TO_DEVCLASS (dc, p); 512 STREAM_TO_UINT8 (link_type, p); 513 514 /* Pass request to security manager to check connect filters before */ 515 /* passing request to l2cap */ 516 if (link_type == HCI_LINK_TYPE_ACL) 517 { 518 btm_sec_conn_req (bda, dc); 519 } 520#if BTM_SCO_INCLUDED == TRUE 521 else 522 { 523 btm_sco_conn_req (bda, dc, link_type); 524 } 525#endif /* BTM_SCO_INCLUDED */ 526} 527 528/******************************************************************************* 529** 530** Function btu_hcif_disconnection_comp_evt 531** 532** Description Process event HCI_DISCONNECTION_COMP_EVT 533** 534** Returns void 535** 536*******************************************************************************/ 537static void btu_hcif_disconnection_comp_evt (UINT8 *p) 538{ 539 UINT16 handle; 540 UINT8 reason; 541 542 ++p; 543 STREAM_TO_UINT16 (handle, p); 544 STREAM_TO_UINT8 (reason, p); 545 546 handle = HCID_GET_HANDLE (handle); 547 548#if BTM_SCO_INCLUDED == TRUE 549 /* If L2CAP doesn't know about it, send it to SCO */ 550 if (!l2c_link_hci_disc_comp (handle, reason)) 551 btm_sco_removed (handle, reason); 552#else 553 l2c_link_hci_disc_comp (handle, reason); 554#endif /* BTM_SCO_INCLUDED */ 555 556 /* Notify security manager */ 557 btm_sec_disconnected (handle, reason); 558} 559 560/******************************************************************************* 561** 562** Function btu_hcif_authentication_comp_evt 563** 564** Description Process event HCI_AUTHENTICATION_COMP_EVT 565** 566** Returns void 567** 568*******************************************************************************/ 569static void btu_hcif_authentication_comp_evt (UINT8 *p) 570{ 571 UINT8 status; 572 UINT16 handle; 573 574 STREAM_TO_UINT8 (status, p); 575 STREAM_TO_UINT16 (handle, p); 576 577 btm_sec_auth_complete (handle, status); 578} 579 580/******************************************************************************* 581** 582** Function btu_hcif_rmt_name_request_comp_evt 583** 584** Description Process event HCI_RMT_NAME_REQUEST_COMP_EVT 585** 586** Returns void 587** 588*******************************************************************************/ 589static void btu_hcif_rmt_name_request_comp_evt (UINT8 *p, UINT16 evt_len) 590{ 591 UINT8 status; 592 BD_ADDR bd_addr; 593 594 STREAM_TO_UINT8 (status, p); 595 STREAM_TO_BDADDR (bd_addr, p); 596 597 evt_len -= (1 + BD_ADDR_LEN); 598 599 btm_process_remote_name (bd_addr, p, evt_len, status); 600 601 btm_sec_rmt_name_request_complete (bd_addr, p, status); 602} 603 604/******************************************************************************* 605** 606** Function btu_hcif_encryption_change_evt 607** 608** Description Process event HCI_ENCRYPTION_CHANGE_EVT 609** 610** Returns void 611** 612*******************************************************************************/ 613static void btu_hcif_encryption_change_evt (UINT8 *p) 614{ 615 UINT8 status; 616 UINT16 handle; 617 UINT8 encr_enable; 618 619 STREAM_TO_UINT8 (status, p); 620 STREAM_TO_UINT16 (handle, p); 621 STREAM_TO_UINT8 (encr_enable, p); 622 623 btm_acl_encrypt_change (handle, status, encr_enable); 624 btm_sec_encrypt_change (handle, status, encr_enable); 625} 626 627/******************************************************************************* 628** 629** Function btu_hcif_read_rmt_features_comp_evt 630** 631** Description Process event HCI_READ_RMT_FEATURES_COMP_EVT 632** 633** Returns void 634** 635*******************************************************************************/ 636static void btu_hcif_read_rmt_features_comp_evt (UINT8 *p) 637{ 638 btm_read_remote_features_complete(p); 639} 640 641/******************************************************************************* 642** 643** Function btu_hcif_read_rmt_ext_features_comp_evt 644** 645** Description Process event HCI_READ_RMT_EXT_FEATURES_COMP_EVT 646** 647** Returns void 648** 649*******************************************************************************/ 650static void btu_hcif_read_rmt_ext_features_comp_evt (UINT8 *p) 651{ 652 UINT8 *p_cur = p; 653 UINT8 status; 654 UINT16 handle; 655 656 STREAM_TO_UINT8 (status, p_cur); 657 658 if (status == HCI_SUCCESS) 659 btm_read_remote_ext_features_complete(p); 660 else 661 { 662 STREAM_TO_UINT16 (handle, p_cur); 663 btm_read_remote_ext_features_failed(status, handle); 664 } 665} 666 667/******************************************************************************* 668** 669** Function btu_hcif_read_rmt_version_comp_evt 670** 671** Description Process event HCI_READ_RMT_VERSION_COMP_EVT 672** 673** Returns void 674** 675*******************************************************************************/ 676static void btu_hcif_read_rmt_version_comp_evt (UINT8 *p) 677{ 678 btm_read_remote_version_complete (p); 679} 680 681/******************************************************************************* 682** 683** Function btu_hcif_qos_setup_comp_evt 684** 685** Description Process event HCI_QOS_SETUP_COMP_EVT 686** 687** Returns void 688** 689*******************************************************************************/ 690static void btu_hcif_qos_setup_comp_evt (UINT8 *p) 691{ 692 UINT8 status; 693 UINT16 handle; 694 FLOW_SPEC flow; 695 696 STREAM_TO_UINT8 (status, p); 697 STREAM_TO_UINT16 (handle, p); 698 STREAM_TO_UINT8 (flow.qos_flags, p); 699 STREAM_TO_UINT8 (flow.service_type, p); 700 STREAM_TO_UINT32 (flow.token_rate, p); 701 STREAM_TO_UINT32 (flow.peak_bandwidth, p); 702 STREAM_TO_UINT32 (flow.latency, p); 703 STREAM_TO_UINT32 (flow.delay_variation, p); 704 705 btm_qos_setup_complete(status, handle, &flow); 706} 707 708/******************************************************************************* 709** 710** Function btu_hcif_esco_connection_comp_evt 711** 712** Description Process event HCI_ESCO_CONNECTION_COMP_EVT 713** 714** Returns void 715** 716*******************************************************************************/ 717static void btu_hcif_esco_connection_comp_evt (UINT8 *p) 718{ 719#if BTM_SCO_INCLUDED == TRUE 720 tBTM_ESCO_DATA data; 721 UINT16 handle; 722 BD_ADDR bda; 723 UINT8 status; 724 725 STREAM_TO_UINT8 (status, p); 726 STREAM_TO_UINT16 (handle, p); 727 STREAM_TO_BDADDR (bda, p); 728 729 STREAM_TO_UINT8 (data.link_type, p); 730 STREAM_TO_UINT8 (data.tx_interval, p); 731 STREAM_TO_UINT8 (data.retrans_window, p); 732 STREAM_TO_UINT16 (data.rx_pkt_len, p); 733 STREAM_TO_UINT16 (data.tx_pkt_len, p); 734 STREAM_TO_UINT8 (data.air_mode, p); 735 736 memcpy (data.bd_addr, bda, BD_ADDR_LEN); 737 btm_sco_connected (status, bda, handle, &data); 738#endif 739} 740 741/******************************************************************************* 742** 743** Function btu_hcif_esco_connection_chg_evt 744** 745** Description Process event HCI_ESCO_CONNECTION_CHANGED_EVT 746** 747** Returns void 748** 749*******************************************************************************/ 750static void btu_hcif_esco_connection_chg_evt (UINT8 *p) 751{ 752#if BTM_SCO_INCLUDED == TRUE 753 UINT16 handle; 754 UINT16 tx_pkt_len; 755 UINT16 rx_pkt_len; 756 UINT8 status; 757 UINT8 tx_interval; 758 UINT8 retrans_window; 759 760 STREAM_TO_UINT8 (status, p); 761 STREAM_TO_UINT16 (handle, p); 762 763 STREAM_TO_UINT8 (tx_interval, p); 764 STREAM_TO_UINT8 (retrans_window, p); 765 STREAM_TO_UINT16 (rx_pkt_len, p); 766 STREAM_TO_UINT16 (tx_pkt_len, p); 767 768 btm_esco_proc_conn_chg (status, handle, tx_interval, retrans_window, 769 rx_pkt_len, tx_pkt_len); 770#endif 771} 772 773/******************************************************************************* 774** 775** Function btu_hcif_hdl_command_complete 776** 777** Description Handle command complete event 778** 779** Returns void 780** 781*******************************************************************************/ 782static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_len, 783 void *p_cplt_cback) 784{ 785 switch (opcode) 786 { 787 case HCI_INQUIRY_CANCEL: 788 /* Tell inquiry processing that we are done */ 789 btm_process_cancel_complete(HCI_SUCCESS, BTM_BR_INQUIRY_MASK); 790 break; 791 case HCI_SET_EVENT_FILTER: 792 btm_event_filter_complete (p); 793 break; 794 795 case HCI_DELETE_STORED_LINK_KEY: 796 btm_delete_stored_link_key_complete (p); 797 break; 798 799 case HCI_READ_LOCAL_NAME: 800 btm_read_local_name_complete (p, evt_len); 801 break; 802 803 case HCI_GET_LINK_QUALITY: 804 btm_read_link_quality_complete (p); 805 break; 806 807 case HCI_READ_RSSI: 808 btm_read_rssi_complete (p); 809 break; 810 811 case HCI_READ_TRANSMIT_POWER_LEVEL: 812 btm_read_tx_power_complete(p, FALSE); 813 break; 814 815 case HCI_CREATE_CONNECTION_CANCEL: 816 btm_create_conn_cancel_complete(p); 817 break; 818 819 case HCI_READ_LOCAL_OOB_DATA: 820 btm_read_local_oob_complete(p); 821 break; 822 823 case HCI_READ_INQ_TX_POWER_LEVEL: 824 btm_read_inq_tx_power_complete(p); 825 break; 826 827#if (BLE_INCLUDED == TRUE) 828/* BLE Commands sComplete*/ 829 case HCI_BLE_ADD_WHITE_LIST: 830 btm_ble_add_2_white_list_complete(*p); 831 break; 832 833 case HCI_BLE_CLEAR_WHITE_LIST: 834 btm_ble_clear_white_list_complete(p, evt_len); 835 break; 836 837 case HCI_BLE_REMOVE_WHITE_LIST: 838 btm_ble_remove_from_white_list_complete(p, evt_len); 839 break; 840 841 case HCI_BLE_RAND: 842 case HCI_BLE_ENCRYPT: 843 btm_ble_rand_enc_complete (p, opcode, (tBTM_RAND_ENC_CB *)p_cplt_cback); 844 break; 845 846 case HCI_BLE_READ_ADV_CHNL_TX_POWER: 847 btm_read_tx_power_complete(p, TRUE); 848 break; 849 850 case HCI_BLE_WRITE_ADV_ENABLE: 851 btm_ble_write_adv_enable_complete(p); 852 break; 853 854 case HCI_BLE_CREATE_LL_CONN: 855 btm_ble_create_ll_conn_complete(*p); 856 break; 857 858 case HCI_BLE_TRANSMITTER_TEST: 859 case HCI_BLE_RECEIVER_TEST: 860 case HCI_BLE_TEST_END: 861 btm_ble_test_command_complete(p); 862 break; 863 864#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) 865 case HCI_BLE_ADD_DEV_RESOLVING_LIST: 866 btm_ble_add_resolving_list_entry_complete(p, evt_len); 867 break; 868 869 case HCI_BLE_RM_DEV_RESOLVING_LIST: 870 btm_ble_remove_resolving_list_entry_complete(p, evt_len); 871 break; 872 873 case HCI_BLE_CLEAR_RESOLVING_LIST: 874 btm_ble_clear_resolving_list_complete(p, evt_len); 875 break; 876 877 case HCI_BLE_READ_RESOLVABLE_ADDR_PEER: 878 btm_ble_read_resolving_list_entry_complete(p, evt_len); 879 break; 880 881 case HCI_BLE_READ_RESOLVABLE_ADDR_LOCAL: 882 case HCI_BLE_SET_ADDR_RESOLUTION_ENABLE: 883 case HCI_BLE_SET_RAND_PRIV_ADDR_TIMOUT: 884 break; 885#endif 886#endif /* (BLE_INCLUDED == TRUE) */ 887 888 default: 889 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) 890 btm_vsc_complete (p, opcode, evt_len, (tBTM_CMPL_CB *)p_cplt_cback); 891 break; 892 } 893} 894 895/******************************************************************************* 896** 897** Function btu_hcif_command_complete_evt 898** 899** Description Process event HCI_COMMAND_COMPLETE_EVT 900** 901** Returns void 902** 903*******************************************************************************/ 904static void btu_hcif_command_complete_evt_on_task(BT_HDR *event) 905{ 906 command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0]; 907 908 command_opcode_t opcode; 909 uint8_t *stream = hack->response->data + hack->response->offset + 3; // 2 to skip the event headers, 1 to skip the command credits 910 STREAM_TO_UINT16(opcode, stream); 911 912 btu_hcif_hdl_command_complete( 913 opcode, 914 stream, 915 hack->response->len - 5, // 3 for the command complete headers, 2 for the event headers 916 hack->context); 917 918 osi_free(hack->response); 919 osi_free(event); 920} 921 922static void btu_hcif_command_complete_evt(BT_HDR *response, void *context) 923{ 924 BT_HDR *event = osi_calloc(sizeof(BT_HDR) + sizeof(command_complete_hack_t)); 925 command_complete_hack_t *hack = (command_complete_hack_t *)&event->data[0]; 926 927 hack->callback = btu_hcif_command_complete_evt_on_task; 928 hack->response = response; 929 hack->context = context; 930 931 event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; 932 933 fixed_queue_enqueue(btu_hci_msg_queue, event); 934} 935 936/******************************************************************************* 937** 938** Function btu_hcif_hdl_command_status 939** 940** Description Handle a command status event 941** 942** Returns void 943** 944*******************************************************************************/ 945static void btu_hcif_hdl_command_status (UINT16 opcode, UINT8 status, UINT8 *p_cmd, 946 void *p_vsc_status_cback) 947{ 948 BD_ADDR bd_addr; 949 UINT16 handle; 950#if BTM_SCO_INCLUDED == TRUE 951 tBTM_ESCO_DATA esco_data; 952#endif 953 954 switch (opcode) 955 { 956 case HCI_EXIT_SNIFF_MODE: 957 case HCI_EXIT_PARK_MODE: 958#if BTM_SCO_WAKE_PARKED_LINK == TRUE 959 if (status != HCI_SUCCESS) 960 { 961 /* Allow SCO initiation to continue if waiting for change mode event */ 962 if (p_cmd != NULL) 963 { 964 p_cmd++; /* bypass length field */ 965 STREAM_TO_UINT16 (handle, p_cmd); 966 btm_sco_chk_pend_unpark (status, handle); 967 } 968 } 969#endif 970 /* Case Falls Through */ 971 972 case HCI_HOLD_MODE: 973 case HCI_SNIFF_MODE: 974 case HCI_PARK_MODE: 975 btm_pm_proc_cmd_status(status); 976 break; 977 978 default: 979 /* If command failed to start, we may need to tell BTM */ 980 if (status != HCI_SUCCESS) 981 { 982 switch (opcode) 983 { 984 case HCI_INQUIRY: 985 /* Tell inquiry processing that we are done */ 986 btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK); 987 break; 988 989 case HCI_RMT_NAME_REQUEST: 990 /* Tell inquiry processing that we are done */ 991 btm_process_remote_name (NULL, NULL, 0, status); 992 993 btm_sec_rmt_name_request_complete (NULL, NULL, status); 994 break; 995 996 case HCI_QOS_SETUP_COMP_EVT: 997 /* Tell qos setup that we are done */ 998 btm_qos_setup_complete(status,0,NULL); 999 break; 1000 1001 case HCI_SWITCH_ROLE: 1002 /* Tell BTM that the command failed */ 1003 /* read bd addr out of stored command */ 1004 if (p_cmd != NULL) 1005 { 1006 p_cmd++; 1007 STREAM_TO_BDADDR (bd_addr, p_cmd); 1008 btm_acl_role_changed(status, bd_addr, BTM_ROLE_UNDEFINED); 1009 } 1010 else 1011 btm_acl_role_changed(status, NULL, BTM_ROLE_UNDEFINED); 1012 l2c_link_role_changed (NULL, BTM_ROLE_UNDEFINED, HCI_ERR_COMMAND_DISALLOWED); 1013 break; 1014 1015 case HCI_CREATE_CONNECTION: 1016 /* read bd addr out of stored command */ 1017 if (p_cmd != NULL) 1018 { 1019 p_cmd++; 1020 STREAM_TO_BDADDR (bd_addr, p_cmd); 1021 btm_sec_connected (bd_addr, HCI_INVALID_HANDLE, status, 0); 1022 l2c_link_hci_conn_comp (status, HCI_INVALID_HANDLE, bd_addr); 1023 } 1024 break; 1025 1026 case HCI_READ_RMT_EXT_FEATURES: 1027 if (p_cmd != NULL) 1028 { 1029 p_cmd++; /* skip command length */ 1030 STREAM_TO_UINT16 (handle, p_cmd); 1031 } 1032 else 1033 handle = HCI_INVALID_HANDLE; 1034 1035 btm_read_remote_ext_features_failed(status, handle); 1036 break; 1037 1038 case HCI_AUTHENTICATION_REQUESTED: 1039 /* Device refused to start authentication. That should be treated as authentication failure. */ 1040 btm_sec_auth_complete (BTM_INVALID_HCI_HANDLE, status); 1041 break; 1042 1043 case HCI_SET_CONN_ENCRYPTION: 1044 /* Device refused to start encryption. That should be treated as encryption failure. */ 1045 btm_sec_encrypt_change (BTM_INVALID_HCI_HANDLE, status, FALSE); 1046 break; 1047 1048#if BLE_INCLUDED == TRUE 1049 case HCI_BLE_CREATE_LL_CONN: 1050 btm_ble_create_ll_conn_complete(status); 1051 break; 1052#endif 1053 1054#if BTM_SCO_INCLUDED == TRUE 1055 case HCI_SETUP_ESCO_CONNECTION: 1056 /* read handle out of stored command */ 1057 if (p_cmd != NULL) 1058 { 1059 p_cmd++; 1060 STREAM_TO_UINT16 (handle, p_cmd); 1061 1062 /* Determine if initial connection failed or is a change of setup */ 1063 if (btm_is_sco_active(handle)) 1064 btm_esco_proc_conn_chg (status, handle, 0, 0, 0, 0); 1065 else 1066 btm_sco_connected (status, NULL, handle, &esco_data); 1067 } 1068 break; 1069#endif 1070 1071/* This is commented out until an upper layer cares about returning event 1072#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE 1073 case HCI_ENHANCED_FLUSH: 1074 break; 1075#endif 1076*/ 1077 default: 1078 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) 1079 btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback); 1080 break; 1081 } 1082 1083 } 1084 else 1085 { 1086 if ((opcode & HCI_GRP_VENDOR_SPECIFIC) == HCI_GRP_VENDOR_SPECIFIC) 1087 btm_vsc_complete (&status, opcode, 1, (tBTM_CMPL_CB *)p_vsc_status_cback); 1088 } 1089 } 1090} 1091 1092/******************************************************************************* 1093** 1094** Function btu_hcif_command_status_evt 1095** 1096** Description Process event HCI_COMMAND_STATUS_EVT 1097** 1098** Returns void 1099** 1100*******************************************************************************/ 1101static void btu_hcif_command_status_evt_on_task(BT_HDR *event) 1102{ 1103 command_status_hack_t *hack = (command_status_hack_t *)&event->data[0]; 1104 1105 command_opcode_t opcode; 1106 uint8_t *stream = hack->command->data + hack->command->offset; 1107 STREAM_TO_UINT16(opcode, stream); 1108 1109 btu_hcif_hdl_command_status( 1110 opcode, 1111 hack->status, 1112 stream, 1113 hack->context); 1114 1115 osi_free(hack->command); 1116 osi_free(event); 1117} 1118 1119static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *context) 1120{ 1121 BT_HDR *event = osi_calloc(sizeof(BT_HDR) + sizeof(command_status_hack_t)); 1122 command_status_hack_t *hack = (command_status_hack_t *)&event->data[0]; 1123 1124 hack->callback = btu_hcif_command_status_evt_on_task; 1125 hack->status = status; 1126 hack->command = command; 1127 hack->context = context; 1128 1129 event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK; 1130 1131 fixed_queue_enqueue(btu_hci_msg_queue, event); 1132} 1133 1134/******************************************************************************* 1135** 1136** Function btu_hcif_hardware_error_evt 1137** 1138** Description Process event HCI_HARDWARE_ERROR_EVT 1139** 1140** Returns void 1141** 1142*******************************************************************************/ 1143static void btu_hcif_hardware_error_evt (UINT8 *p) 1144{ 1145 HCI_TRACE_ERROR("Ctlr H/w error event - code:0x%x", *p); 1146 1147 /* If anyone wants device status notifications, give him one. */ 1148 btm_report_device_status (BTM_DEV_STATUS_DOWN); 1149 1150 /* Reset the controller */ 1151 if (BTM_IsDeviceUp()) 1152 BTM_DeviceReset (NULL); 1153} 1154 1155/******************************************************************************* 1156** 1157** Function btu_hcif_flush_occured_evt 1158** 1159** Description Process event HCI_FLUSH_OCCURED_EVT 1160** 1161** Returns void 1162** 1163*******************************************************************************/ 1164static void btu_hcif_flush_occured_evt (void) 1165{ 1166} 1167 1168/******************************************************************************* 1169** 1170** Function btu_hcif_role_change_evt 1171** 1172** Description Process event HCI_ROLE_CHANGE_EVT 1173** 1174** Returns void 1175** 1176*******************************************************************************/ 1177static void btu_hcif_role_change_evt (UINT8 *p) 1178{ 1179 UINT8 status; 1180 BD_ADDR bda; 1181 UINT8 role; 1182 1183 STREAM_TO_UINT8 (status, p); 1184 STREAM_TO_BDADDR (bda, p); 1185 STREAM_TO_UINT8 (role, p); 1186 1187 l2c_link_role_changed (bda, role, status); 1188 btm_acl_role_changed(status, bda, role); 1189} 1190 1191/******************************************************************************* 1192** 1193** Function btu_hcif_num_compl_data_pkts_evt 1194** 1195** Description Process event HCI_NUM_COMPL_DATA_PKTS_EVT 1196** 1197** Returns void 1198** 1199*******************************************************************************/ 1200static void btu_hcif_num_compl_data_pkts_evt (UINT8 *p) 1201{ 1202 /* Process for L2CAP and SCO */ 1203 l2c_link_process_num_completed_pkts (p); 1204 1205 /* Send on to SCO */ 1206 /*?? No SCO for now */ 1207} 1208 1209/******************************************************************************* 1210** 1211** Function btu_hcif_mode_change_evt 1212** 1213** Description Process event HCI_MODE_CHANGE_EVT 1214** 1215** Returns void 1216** 1217*******************************************************************************/ 1218static void btu_hcif_mode_change_evt (UINT8 *p) 1219{ 1220 UINT8 status; 1221 UINT16 handle; 1222 UINT8 current_mode; 1223 UINT16 interval; 1224 1225 STREAM_TO_UINT8 (status, p); 1226 1227 STREAM_TO_UINT16 (handle, p); 1228 STREAM_TO_UINT8 (current_mode, p); 1229 STREAM_TO_UINT16 (interval, p); 1230#if BTM_SCO_WAKE_PARKED_LINK == TRUE 1231 btm_sco_chk_pend_unpark (status, handle); 1232#endif 1233 btm_pm_proc_mode_change (status, handle, current_mode, interval); 1234 1235#if (HID_DEV_INCLUDED == TRUE) && (HID_DEV_PM_INCLUDED == TRUE) 1236 hidd_pm_proc_mode_change( status, current_mode, interval ) ; 1237#endif 1238} 1239 1240/******************************************************************************* 1241** 1242** Function btu_hcif_ssr_evt 1243** 1244** Description Process event HCI_SNIFF_SUB_RATE_EVT 1245** 1246** Returns void 1247** 1248*******************************************************************************/ 1249 #if (BTM_SSR_INCLUDED == TRUE) 1250static void btu_hcif_ssr_evt (UINT8 *p, UINT16 evt_len) 1251{ 1252 btm_pm_proc_ssr_evt(p, evt_len); 1253} 1254 #endif 1255 1256/******************************************************************************* 1257** 1258** Function btu_hcif_pin_code_request_evt 1259** 1260** Description Process event HCI_PIN_CODE_REQUEST_EVT 1261** 1262** Returns void 1263** 1264*******************************************************************************/ 1265static void btu_hcif_pin_code_request_evt (UINT8 *p) 1266{ 1267 BD_ADDR bda; 1268 1269 STREAM_TO_BDADDR (bda, p); 1270 1271 /* Tell L2CAP that there was a PIN code request, */ 1272 /* it may need to stretch timeouts */ 1273 l2c_pin_code_request (bda); 1274 1275 btm_sec_pin_code_request (bda); 1276} 1277 1278/******************************************************************************* 1279** 1280** Function btu_hcif_link_key_request_evt 1281** 1282** Description Process event HCI_LINK_KEY_REQUEST_EVT 1283** 1284** Returns void 1285** 1286*******************************************************************************/ 1287static void btu_hcif_link_key_request_evt (UINT8 *p) 1288{ 1289 BD_ADDR bda; 1290 1291 STREAM_TO_BDADDR (bda, p); 1292 btm_sec_link_key_request (bda); 1293} 1294 1295/******************************************************************************* 1296** 1297** Function btu_hcif_link_key_notification_evt 1298** 1299** Description Process event HCI_LINK_KEY_NOTIFICATION_EVT 1300** 1301** Returns void 1302** 1303*******************************************************************************/ 1304static void btu_hcif_link_key_notification_evt (UINT8 *p) 1305{ 1306 BD_ADDR bda; 1307 LINK_KEY key; 1308 UINT8 key_type; 1309 1310 STREAM_TO_BDADDR (bda, p); 1311 STREAM_TO_ARRAY16 (key, p); 1312 STREAM_TO_UINT8 (key_type, p); 1313 1314 btm_sec_link_key_notification (bda, key, key_type); 1315} 1316 1317/******************************************************************************* 1318** 1319** Function btu_hcif_loopback_command_evt 1320** 1321** Description Process event HCI_LOOPBACK_COMMAND_EVT 1322** 1323** Returns void 1324** 1325*******************************************************************************/ 1326static void btu_hcif_loopback_command_evt (void) 1327{ 1328} 1329 1330/******************************************************************************* 1331** 1332** Function btu_hcif_data_buf_overflow_evt 1333** 1334** Description Process event HCI_DATA_BUF_OVERFLOW_EVT 1335** 1336** Returns void 1337** 1338*******************************************************************************/ 1339static void btu_hcif_data_buf_overflow_evt (void) 1340{ 1341} 1342 1343/******************************************************************************* 1344** 1345** Function btu_hcif_max_slots_changed_evt 1346** 1347** Description Process event HCI_MAX_SLOTS_CHANGED_EVT 1348** 1349** Returns void 1350** 1351*******************************************************************************/ 1352static void btu_hcif_max_slots_changed_evt (void) 1353{ 1354} 1355 1356/******************************************************************************* 1357** 1358** Function btu_hcif_read_clock_off_comp_evt 1359** 1360** Description Process event HCI_READ_CLOCK_OFF_COMP_EVT 1361** 1362** Returns void 1363** 1364*******************************************************************************/ 1365static void btu_hcif_read_clock_off_comp_evt (UINT8 *p) 1366{ 1367 UINT8 status; 1368 UINT16 handle; 1369 UINT16 clock_offset; 1370 1371 STREAM_TO_UINT8 (status, p); 1372 1373 /* If failed to get clock offset just drop the result */ 1374 if (status != HCI_SUCCESS) 1375 return; 1376 1377 STREAM_TO_UINT16 (handle, p); 1378 STREAM_TO_UINT16 (clock_offset, p); 1379 1380 handle = HCID_GET_HANDLE (handle); 1381 1382 btm_process_clk_off_comp_evt (handle, clock_offset); 1383 btm_sec_update_clock_offset (handle, clock_offset); 1384} 1385 1386/******************************************************************************* 1387** 1388** Function btu_hcif_conn_pkt_type_change_evt 1389** 1390** Description Process event HCI_CONN_PKT_TYPE_CHANGE_EVT 1391** 1392** Returns void 1393** 1394*******************************************************************************/ 1395static void btu_hcif_conn_pkt_type_change_evt (void) 1396{ 1397} 1398 1399/******************************************************************************* 1400** 1401** Function btu_hcif_qos_violation_evt 1402** 1403** Description Process event HCI_QOS_VIOLATION_EVT 1404** 1405** Returns void 1406** 1407*******************************************************************************/ 1408static void btu_hcif_qos_violation_evt (UINT8 *p) 1409{ 1410 UINT16 handle; 1411 1412 STREAM_TO_UINT16 (handle, p); 1413 1414 handle = HCID_GET_HANDLE (handle); 1415 1416 l2c_link_hci_qos_violation (handle); 1417} 1418 1419/******************************************************************************* 1420** 1421** Function btu_hcif_page_scan_mode_change_evt 1422** 1423** Description Process event HCI_PAGE_SCAN_MODE_CHANGE_EVT 1424** 1425** Returns void 1426** 1427*******************************************************************************/ 1428static void btu_hcif_page_scan_mode_change_evt (void) 1429{ 1430} 1431 1432/******************************************************************************* 1433** 1434** Function btu_hcif_page_scan_rep_mode_chng_evt 1435** 1436** Description Process event HCI_PAGE_SCAN_REP_MODE_CHNG_EVT 1437** 1438** Returns void 1439** 1440*******************************************************************************/ 1441static void btu_hcif_page_scan_rep_mode_chng_evt (void) 1442{ 1443} 1444 1445/********************************************** 1446** Simple Pairing Events 1447***********************************************/ 1448 1449/******************************************************************************* 1450** 1451** Function btu_hcif_host_support_evt 1452** 1453** Description Process event HCI_RMT_HOST_SUP_FEAT_NOTIFY_EVT 1454** 1455** Returns void 1456** 1457*******************************************************************************/ 1458static void btu_hcif_host_support_evt (UINT8 *p) 1459{ 1460 btm_sec_rmt_host_support_feat_evt(p); 1461} 1462 1463/******************************************************************************* 1464** 1465** Function btu_hcif_io_cap_request_evt 1466** 1467** Description Process event HCI_IO_CAPABILITY_REQUEST_EVT 1468** 1469** Returns void 1470** 1471*******************************************************************************/ 1472static void btu_hcif_io_cap_request_evt (UINT8 *p) 1473{ 1474 btm_io_capabilities_req(p); 1475} 1476 1477/******************************************************************************* 1478** 1479** Function btu_hcif_io_cap_response_evt 1480** 1481** Description Process event HCI_IO_CAPABILITY_RESPONSE_EVT 1482** 1483** Returns void 1484** 1485*******************************************************************************/ 1486static void btu_hcif_io_cap_response_evt (UINT8 *p) 1487{ 1488 btm_io_capabilities_rsp(p); 1489} 1490 1491/******************************************************************************* 1492** 1493** Function btu_hcif_user_conf_request_evt 1494** 1495** Description Process event HCI_USER_CONFIRMATION_REQUEST_EVT 1496** 1497** Returns void 1498** 1499*******************************************************************************/ 1500static void btu_hcif_user_conf_request_evt (UINT8 *p) 1501{ 1502 btm_proc_sp_req_evt(BTM_SP_CFM_REQ_EVT, p); 1503} 1504 1505/******************************************************************************* 1506** 1507** Function btu_hcif_user_passkey_request_evt 1508** 1509** Description Process event HCI_USER_PASSKEY_REQUEST_EVT 1510** 1511** Returns void 1512** 1513*******************************************************************************/ 1514static void btu_hcif_user_passkey_request_evt (UINT8 *p) 1515{ 1516 btm_proc_sp_req_evt(BTM_SP_KEY_REQ_EVT, p); 1517} 1518 1519/******************************************************************************* 1520** 1521** Function btu_hcif_user_passkey_notif_evt 1522** 1523** Description Process event HCI_USER_PASSKEY_NOTIFY_EVT 1524** 1525** Returns void 1526** 1527*******************************************************************************/ 1528static void btu_hcif_user_passkey_notif_evt (UINT8 *p) 1529{ 1530 btm_proc_sp_req_evt(BTM_SP_KEY_NOTIF_EVT, p); 1531} 1532 1533/******************************************************************************* 1534** 1535** Function btu_hcif_keypress_notif_evt 1536** 1537** Description Process event HCI_KEYPRESS_NOTIFY_EVT 1538** 1539** Returns void 1540** 1541*******************************************************************************/ 1542static void btu_hcif_keypress_notif_evt (UINT8 *p) 1543{ 1544 btm_keypress_notif_evt(p); 1545} 1546 1547/******************************************************************************* 1548** 1549** Function btu_hcif_rem_oob_request_evt 1550** 1551** Description Process event HCI_REMOTE_OOB_DATA_REQUEST_EVT 1552** 1553** Returns void 1554** 1555*******************************************************************************/ 1556static void btu_hcif_rem_oob_request_evt (UINT8 *p) 1557{ 1558 btm_rem_oob_req(p); 1559} 1560 1561/******************************************************************************* 1562** 1563** Function btu_hcif_simple_pair_complete_evt 1564** 1565** Description Process event HCI_SIMPLE_PAIRING_COMPLETE_EVT 1566** 1567** Returns void 1568** 1569*******************************************************************************/ 1570static void btu_hcif_simple_pair_complete_evt (UINT8 *p) 1571{ 1572 btm_simple_pair_complete(p); 1573} 1574 1575/******************************************************************************* 1576** 1577** Function btu_hcif_enhanced_flush_complete_evt 1578** 1579** Description Process event HCI_ENHANCED_FLUSH_COMPLETE_EVT 1580** 1581** Returns void 1582** 1583*******************************************************************************/ 1584#if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE 1585static void btu_hcif_enhanced_flush_complete_evt (void) 1586{ 1587/* This is empty until an upper layer cares about returning event */ 1588} 1589#endif 1590/********************************************** 1591** End of Simple Pairing Events 1592***********************************************/ 1593 1594/********************************************** 1595** BLE Events 1596***********************************************/ 1597#if (defined BLE_INCLUDED) && (BLE_INCLUDED == TRUE) 1598static void btu_hcif_encryption_key_refresh_cmpl_evt (UINT8 *p) 1599{ 1600 UINT8 status; 1601 UINT8 enc_enable = 0; 1602 UINT16 handle; 1603 1604 STREAM_TO_UINT8 (status, p); 1605 STREAM_TO_UINT16 (handle, p); 1606 1607 if (status == HCI_SUCCESS) enc_enable = 1; 1608 1609 btm_sec_encrypt_change (handle, status, enc_enable); 1610} 1611 1612static void btu_ble_process_adv_pkt (UINT8 *p) 1613{ 1614 HCI_TRACE_EVENT("btu_ble_process_adv_pkt"); 1615 1616 btm_ble_process_adv_pkt(p); 1617} 1618 1619static void btu_ble_ll_conn_complete_evt ( UINT8 *p, UINT16 evt_len) 1620{ 1621 btm_ble_conn_complete(p, evt_len, FALSE); 1622} 1623#if (defined BLE_PRIVACY_SPT && BLE_PRIVACY_SPT == TRUE) 1624static void btu_ble_proc_enhanced_conn_cmpl( UINT8 *p, UINT16 evt_len) 1625{ 1626 btm_ble_conn_complete(p, evt_len, TRUE); 1627} 1628#endif 1629static void btu_ble_ll_conn_param_upd_evt (UINT8 *p, UINT16 evt_len) 1630{ 1631 /* LE connection update has completed successfully as a master. */ 1632 /* We can enable the update request if the result is a success. */ 1633 /* extract the HCI handle first */ 1634 UINT8 status; 1635 UINT16 handle; 1636 UINT16 interval; 1637 UINT16 latency; 1638 UINT16 timeout; 1639 1640 STREAM_TO_UINT8(status, p); 1641 STREAM_TO_UINT16(handle, p); 1642 STREAM_TO_UINT16(interval, p); 1643 STREAM_TO_UINT16(latency, p); 1644 STREAM_TO_UINT16(timeout, p); 1645 1646 l2cble_process_conn_update_evt(handle, status, interval, latency, timeout); 1647} 1648 1649static void btu_ble_read_remote_feat_evt (UINT8 *p) 1650{ 1651 btm_ble_read_remote_features_complete(p); 1652} 1653 1654static void btu_ble_proc_ltk_req (UINT8 *p) 1655{ 1656 UINT16 ediv, handle; 1657 UINT8 *pp; 1658 1659 STREAM_TO_UINT16(handle, p); 1660 pp = p + 8; 1661 STREAM_TO_UINT16(ediv, pp); 1662#if BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE 1663 btm_ble_ltk_request(handle, p, ediv); 1664#endif 1665 /* This is empty until an upper layer cares about returning event */ 1666} 1667 1668static void btu_ble_data_length_change_evt(UINT8 *p, UINT16 evt_len) 1669{ 1670 UINT16 handle; 1671 UINT16 tx_data_len; 1672 UINT16 rx_data_len; 1673 1674 if (!controller_get_interface()->supports_ble_packet_extension()) 1675 { 1676 HCI_TRACE_WARNING("%s, request not supported", __FUNCTION__); 1677 return; 1678 } 1679 1680 STREAM_TO_UINT16(handle, p); 1681 STREAM_TO_UINT16(tx_data_len, p); 1682 p += 2; /* Skip the TxTimer */ 1683 STREAM_TO_UINT16(rx_data_len, p); 1684 1685 l2cble_process_data_length_change_event(handle, tx_data_len, rx_data_len); 1686} 1687 1688/********************************************** 1689** End of BLE Events Handler 1690***********************************************/ 1691#if (defined BLE_LLT_INCLUDED) && (BLE_LLT_INCLUDED == TRUE) 1692static void btu_ble_rc_param_req_evt(UINT8 *p) 1693{ 1694 UINT16 handle; 1695 UINT16 int_min, int_max, latency, timeout; 1696 1697 STREAM_TO_UINT16(handle, p); 1698 STREAM_TO_UINT16(int_min, p); 1699 STREAM_TO_UINT16(int_max, p); 1700 STREAM_TO_UINT16(latency, p); 1701 STREAM_TO_UINT16(timeout, p); 1702 1703 l2cble_process_rc_param_request_evt(handle, int_min, int_max, latency, timeout); 1704} 1705#endif /* BLE_LLT_INCLUDED */ 1706 1707#endif /* BLE_INCLUDED */ 1708 1709