1 /****************************************************************************** 2 * 3 * Copyright 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 #ifndef HCIMSGS_H 20 #define HCIMSGS_H 21 22 #include <base/functional/callback_forward.h> 23 24 #include <cstdint> 25 #include <vector> 26 27 #include "device/include/esco_parameters.h" 28 #include "stack/include/bt_lap.h" 29 #include "stack/include/bt_name.h" 30 #include "stack/include/bt_octets.h" 31 #include "stack/include/btm_api_types.h" 32 #include "types/ble_address_with_type.h" 33 #include "types/raw_address.h" 34 35 /* Message by message.... */ 36 37 enum hci_data_direction_t { 38 HOST_TO_CONTROLLER = 0, 39 CONTROLLER_TO_HOST = 1, 40 }; 41 42 /* Disconnect */ 43 namespace bluetooth::legacy::hci { 44 class Interface { 45 public: 46 virtual void Disconnect(uint16_t handle, uint8_t reason) const = 0; 47 virtual void ChangeConnectionPacketType(uint16_t handle, 48 uint16_t packet_types) const = 0; 49 virtual void StartRoleSwitch(const RawAddress& bd_addr, 50 uint8_t role) const = 0; 51 virtual void ConfigureDataPath(hci_data_direction_t data_path_direction, 52 uint8_t data_path_id, 53 std::vector<uint8_t> vendor_config) const = 0; 54 virtual ~Interface() = default; 55 }; 56 57 const Interface& GetInterface(); 58 } // namespace bluetooth::legacy::hci 59 60 /* Add SCO Connection */ 61 void btsnd_hcic_add_SCO_conn(uint16_t handle, uint16_t packet_types); 62 63 /* Create Connection Cancel */ 64 void btsnd_hcic_create_conn_cancel(const RawAddress& dest); 65 66 /* Reject Connection Request */ 67 void btsnd_hcic_reject_conn(const RawAddress& bd_addr, uint8_t reason); 68 69 /* Link Key Request Reply */ 70 void btsnd_hcic_link_key_req_reply(const RawAddress& bd_addr, 71 const LinkKey& link_key); 72 73 /* Link Key Request Neg Reply */ 74 void btsnd_hcic_link_key_neg_reply(const RawAddress& bd_addr); 75 76 /* PIN Code Request Reply */ 77 void btsnd_hcic_pin_code_req_reply(const RawAddress& bd_addr, 78 uint8_t pin_code_len, PIN_CODE pin_code); 79 80 /* Link Key Request Neg Reply */ 81 void btsnd_hcic_pin_code_neg_reply(const RawAddress& bd_addr); 82 83 /* Change Connection Type */ 84 void btsnd_hcic_change_conn_type(uint16_t handle, uint16_t packet_types); 85 86 /* Change Connection Type */ 87 void btsnd_hcic_auth_request(uint16_t handle); /* Authentication Request */ 88 89 /* Set Connection Encryption */ 90 void btsnd_hcic_set_conn_encrypt(uint16_t handle, bool enable); 91 92 /* Remote Extended Features */ 93 void btsnd_hcic_rmt_ext_features(uint16_t handle, uint8_t page_num); 94 95 void btsnd_hcic_rmt_ver_req(uint16_t handle); /* Remote Version Info Request */ 96 void btsnd_hcic_read_rmt_clk_offset(uint16_t handle); /* Remote Clock Offset */ 97 void btsnd_hcic_setup_esco_conn(uint16_t handle, uint32_t transmit_bandwidth, 98 uint32_t receive_bandwidth, 99 uint16_t max_latency, uint16_t voice, 100 uint8_t retrans_effort, uint16_t packet_types); 101 void btsnd_hcic_accept_esco_conn(const RawAddress& bd_addr, 102 uint32_t transmit_bandwidth, 103 uint32_t receive_bandwidth, 104 uint16_t max_latency, uint16_t content_fmt, 105 uint8_t retrans_effort, uint16_t packet_types); 106 107 void btsnd_hcic_reject_esco_conn(const RawAddress& bd_addr, uint8_t reason); 108 /* Hold Mode */ 109 void btsnd_hcic_hold_mode(uint16_t handle, uint16_t max_hold_period, 110 uint16_t min_hold_period); 111 112 /* Hold Mode */ 113 114 /* Sniff Mode */ 115 void btsnd_hcic_sniff_mode(uint16_t handle, uint16_t max_sniff_period, 116 uint16_t min_sniff_period, uint16_t sniff_attempt, 117 uint16_t sniff_timeout); 118 119 /* Exit Sniff Mode */ 120 void btsnd_hcic_exit_sniff_mode(uint16_t handle); 121 122 /* Park Mode */ 123 void btsnd_hcic_park_mode(uint16_t handle, uint16_t beacon_max_interval, 124 uint16_t beacon_min_interval); 125 126 /* Exit Park Mode */ 127 void btsnd_hcic_exit_park_mode(uint16_t handle); 128 129 /* Write Policy Settings */ 130 void btsnd_hcic_write_policy_set(uint16_t handle, uint16_t settings); 131 132 /* Write Default Policy Settings */ 133 void btsnd_hcic_write_def_policy_set(uint16_t settings); 134 135 /****************************************** 136 * Lisbon Features 137 ******************************************/ 138 /* Sniff Subrating */ 139 void btsnd_hcic_sniff_sub_rate(uint16_t handle, uint16_t max_lat, 140 uint16_t min_remote_lat, uint16_t min_local_lat); 141 /* Sniff Subrating */ 142 143 /* Extended Inquiry Response */ 144 void btsnd_hcic_write_ext_inquiry_response(void* buffer, uint8_t fec_req); 145 /* IO Capabilities Response */ 146 void btsnd_hcic_io_cap_req_reply(const RawAddress& bd_addr, uint8_t capability, 147 uint8_t oob_present, uint8_t auth_req); 148 /* IO Capabilities Req Neg Reply */ 149 void btsnd_hcic_io_cap_req_neg_reply(const RawAddress& bd_addr, 150 uint8_t err_code); 151 /* Read Local OOB Data */ 152 void btsnd_hcic_read_local_oob_data(void); 153 154 /* Read Local OOB Extended Data */ 155 void btsnd_hcic_read_local_oob_extended_data(void); 156 157 void btsnd_hcic_user_conf_reply(const RawAddress& bd_addr, bool is_yes); 158 159 void btsnd_hcic_user_passkey_reply(const RawAddress& bd_addr, uint32_t value); 160 161 void btsnd_hcic_user_passkey_neg_reply(const RawAddress& bd_addr); 162 163 /* Remote OOB Data Request Reply */ 164 void btsnd_hcic_rem_oob_reply(const RawAddress& bd_addr, const Octet16& c, 165 const Octet16& r); 166 167 /* Remote OOB Data Request Negative Reply */ 168 void btsnd_hcic_rem_oob_neg_reply(const RawAddress& bd_addr); 169 170 /* Read Default Erroneous Data Reporting */ 171 void btsnd_hcic_read_default_erroneous_data_rpt(void); 172 173 /**** end of Simple Pairing Commands ****/ 174 175 extern void btsnd_hcic_set_event_filter(uint8_t filt_type, 176 uint8_t filt_cond_type, 177 uint8_t* filt_cond, 178 uint8_t filt_cond_len); 179 /* Set Event Filter */ 180 181 /* Delete Stored Key */ 182 void btsnd_hcic_delete_stored_key(const RawAddress& bd_addr, 183 bool delete_all_flag); 184 /* Delete Stored Key */ 185 186 /* Change Local Name */ 187 void btsnd_hcic_change_name(BD_NAME name); 188 189 #define HCIC_PARAM_SIZE_READ_CMD 0 190 191 #define HCIC_PARAM_SIZE_WRITE_PARAM1 1 192 193 #define HCIC_PARAM_SIZE_WRITE_PARAM3 3 194 195 void btsnd_hcic_write_pin_type(uint8_t type); /* Write PIN Type */ 196 void btsnd_hcic_write_auto_accept(uint8_t flag); /* Write Auto Accept */ 197 void btsnd_hcic_read_name(void); /* Read Local Name */ 198 void btsnd_hcic_write_page_tout(uint16_t timeout); /* Write Page Timout */ 199 void btsnd_hcic_write_scan_enable(uint8_t flag); /* Write Scan Enable */ 200 void btsnd_hcic_write_pagescan_cfg( 201 uint16_t interval, uint16_t window); /* Write Page Scan Activity */ 202 /* Write Page Scan Activity */ 203 204 /* Write Inquiry Scan Activity */ 205 void btsnd_hcic_write_inqscan_cfg(uint16_t interval, uint16_t window); 206 /* Write Inquiry Scan Activity */ 207 208 void btsnd_hcic_write_auth_enable( 209 uint8_t flag); /* Write Authentication Enable */ 210 void btsnd_hcic_write_dev_class(DEV_CLASS dev); /* Write Class of Device */ 211 void btsnd_hcic_write_voice_settings(uint16_t flags); /* Write Voice Settings */ 212 213 void btsnd_hcic_write_auto_flush_tout( 214 uint16_t handle, uint16_t timeout); /* Write Retransmit Timout */ 215 216 void btsnd_hcic_read_tx_power(uint16_t handle, 217 uint8_t type); /* Read Tx Power */ 218 219 /* Write Link Supervision Timeout */ 220 void btsnd_hcic_write_link_super_tout(uint16_t handle, uint16_t timeout); 221 /* Write Link Supervision Timeout */ 222 223 void btsnd_hcic_write_cur_iac_lap( 224 uint8_t num_cur_iac, LAP* const iac_lap); /* Write Current IAC LAP */ 225 /* Write Current IAC LAP */ 226 227 void btsnd_hcic_read_rssi(uint16_t handle); /* Read RSSI */ 228 using ReadEncKeySizeCb = base::OnceCallback<void(uint8_t, uint16_t, uint8_t)>; 229 void btsnd_hcic_read_encryption_key_size(uint16_t handle, ReadEncKeySizeCb cb); 230 void btsnd_hcic_read_failed_contact_counter(uint16_t handle); 231 void btsnd_hcic_enable_test_mode(void); /* Enable Device Under Test Mode */ 232 void btsnd_hcic_write_pagescan_type(uint8_t type); /* Write Page Scan Type */ 233 void btsnd_hcic_write_inqscan_type(uint8_t type); /* Write Inquiry Scan Type */ 234 void btsnd_hcic_write_inquiry_mode(uint8_t type); /* Write Inquiry Mode */ 235 236 /* Enhanced setup SCO connection (CSA2) */ 237 void btsnd_hcic_enhanced_set_up_synchronous_connection( 238 uint16_t conn_handle, enh_esco_params_t* p_parms); 239 240 /* Enhanced accept SCO connection request (CSA2) */ 241 void btsnd_hcic_enhanced_accept_synchronous_connection( 242 const RawAddress& bd_addr, enh_esco_params_t* p_parms); 243 244 #define HCI_DATA_HANDLE_MASK 0x0FFF 245 #define HCI_DATA_PKT_STATUS_MASK 0x3000 246 247 #define HCID_GET_HANDLE_EVENT(p) \ 248 (uint16_t)((*((uint8_t*)((p) + 1) + (p)->offset) + \ 249 (*((uint8_t*)((p) + 1) + (p)->offset + 1) << 8))) 250 251 #define HCID_GET_HANDLE(u16) (uint16_t)((u16)&HCI_DATA_HANDLE_MASK) 252 #define HCID_GET_PKT_STATUS(u16) \ 253 (uint16_t)(((u16)&HCI_DATA_PKT_STATUS_MASK) >> 12) 254 255 #define HCI_DATA_EVENT_MASK 3 256 #define HCI_DATA_EVENT_OFFSET 12 257 #define HCID_GET_EVENT(u16) \ 258 (uint8_t)(((u16) >> HCI_DATA_EVENT_OFFSET) & HCI_DATA_EVENT_MASK) 259 260 void btsnd_hcic_vendor_spec_cmd(uint16_t opcode, uint8_t len, uint8_t* p_data, 261 tBTM_VSC_CMPL_CB* p_cmd_cplt_cback); 262 263 /******************************************************************************* 264 * BLE Commands 265 * Note: "local_controller_id" is for transport, not counted in HCI 266 * message size 267 ******************************************************************************/ 268 #define HCIC_BLE_RAND_DI_SIZE 8 269 270 #define HCIC_BLE_CHNL_MAP_SIZE 5 271 #define HCIC_PARAM_SIZE_BLE_READ_PHY 2 272 #define HCIC_PARAM_SIZE_BLE_SET_PHY 7 273 274 /* ULP HCI command */ 275 void btsnd_hcic_ble_set_local_used_feat(uint8_t feat_set[8]); 276 277 void btsnd_hcic_ble_write_adv_params(uint16_t adv_int_min, uint16_t adv_int_max, 278 uint8_t adv_type, 279 tBLE_ADDR_TYPE addr_type_own, 280 tBLE_ADDR_TYPE addr_type_dir, 281 const RawAddress& direct_bda, 282 uint8_t channel_map, 283 uint8_t adv_filter_policy); 284 285 void btsnd_hcic_ble_read_adv_chnl_tx_power(void); 286 287 void btsnd_hcic_ble_set_adv_data(uint8_t data_len, uint8_t* p_data); 288 289 void btsnd_hcic_ble_set_adv_enable(uint8_t adv_enable); 290 291 void btsnd_hcic_ble_set_scan_params(uint8_t scan_type, uint16_t scan_int, 292 uint16_t scan_win, uint8_t addr_type, 293 uint8_t scan_filter_policy); 294 295 void btsnd_hcic_ble_set_scan_enable(uint8_t scan_enable, uint8_t duplicate); 296 297 void btsnd_hcic_ble_read_acceptlist_size(void); 298 299 void btsnd_hcic_ble_read_remote_feat(uint16_t handle); 300 301 void btsnd_hcic_ble_rand(base::Callback<void(BT_OCTET8)> cb); 302 303 void btsnd_hcic_ble_start_enc(uint16_t handle, 304 uint8_t rand[HCIC_BLE_RAND_DI_SIZE], 305 uint16_t ediv, const Octet16& ltk); 306 307 void btsnd_hcic_ble_ltk_req_reply(uint16_t handle, const Octet16& ltk); 308 309 void btsnd_hcic_ble_ltk_req_neg_reply(uint16_t handle); 310 311 void btsnd_hcic_ble_read_supported_states(void); 312 313 void btsnd_hcic_ble_receiver_test(uint8_t rx_freq); 314 315 void btsnd_hcic_ble_transmitter_test(uint8_t tx_freq, uint8_t test_data_len, 316 uint8_t payload); 317 void btsnd_hcic_ble_test_end(void); 318 319 void btsnd_hcic_ble_set_data_length(uint16_t conn_handle, uint16_t tx_octets, 320 uint16_t tx_time); 321 322 struct scanning_phy_cfg { 323 uint8_t scan_type; 324 uint16_t scan_int; 325 uint16_t scan_win; 326 }; 327 328 void btsnd_hcic_ble_set_extended_scan_params(uint8_t own_address_type, 329 uint8_t scanning_filter_policy, 330 uint8_t scanning_phys, 331 scanning_phy_cfg* phy_cfg); 332 333 void btsnd_hcic_ble_set_extended_scan_enable(uint8_t enable, 334 uint8_t filter_duplicates, 335 uint16_t duration, 336 uint16_t period); 337 338 struct EXT_CONN_PHY_CFG { 339 uint16_t scan_int; 340 uint16_t scan_win; 341 uint16_t conn_int_min; 342 uint16_t conn_int_max; 343 uint16_t conn_latency; 344 uint16_t sup_timeout; 345 uint16_t min_ce_len; 346 uint16_t max_ce_len; 347 }; 348 349 void btsnd_hcic_ble_read_resolvable_addr_peer(uint8_t addr_type_peer, 350 const RawAddress& bda_peer); 351 352 void btsnd_hcic_ble_set_rand_priv_addr_timeout(uint16_t rpa_timout); 353 354 void btsnd_hcic_read_authenticated_payload_tout(uint16_t handle); 355 356 void btsnd_hcic_write_authenticated_payload_tout(uint16_t handle, 357 uint16_t timeout); 358 359 struct EXT_CIS_CFG { 360 uint8_t cis_id; 361 uint16_t max_sdu_size_mtos; 362 uint16_t max_sdu_size_stom; 363 uint8_t phy_mtos; 364 uint8_t phy_stom; 365 uint8_t rtn_mtos; 366 uint8_t rtn_stom; 367 }; 368 369 void btsnd_hcic_set_cig_params(uint8_t cig_id, uint32_t sdu_itv_mtos, 370 uint32_t sdu_itv_stom, uint8_t sca, 371 uint8_t packing, uint8_t framing, 372 uint16_t max_trans_lat_stom, 373 uint16_t max_trans_lat_mtos, uint8_t cis_cnt, 374 const EXT_CIS_CFG* cis_cfg, 375 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 376 377 struct EXT_CIS_TEST_CFG { 378 uint8_t cis_id; 379 uint8_t nse; 380 uint16_t max_sdu_size_mtos; 381 uint16_t max_sdu_size_stom; 382 uint8_t max_pdu_mtos; 383 uint8_t max_pdu_stom; 384 uint8_t phy_mtos; 385 uint8_t phy_stom; 386 uint8_t bn_mtos; 387 uint8_t bn_stom; 388 }; 389 390 struct EXT_CIS_CREATE_CFG { 391 uint16_t cis_conn_handle; 392 uint16_t acl_conn_handle; 393 }; 394 395 void btsnd_hcic_create_cis(uint8_t num_cis, 396 const EXT_CIS_CREATE_CFG* cis_create_cfg, 397 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 398 399 void btsnd_hcic_remove_cig(uint8_t cig_id, 400 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 401 402 void btsnd_hcic_req_peer_sca(uint16_t conn_handle); 403 404 void btsnd_hcic_create_big(uint8_t big_handle, uint8_t adv_handle, 405 uint8_t num_bis, uint32_t sdu_itv, 406 uint16_t max_sdu_size, uint16_t max_trans_lat, 407 uint8_t rtn, uint8_t phy, uint8_t packing, 408 uint8_t framing, uint8_t enc, 409 std::array<uint8_t, 16> bcst_code); 410 411 void btsnd_hcic_term_big(uint8_t big_handle, uint8_t reason); 412 413 void btsnd_hcic_setup_iso_data_path( 414 uint16_t iso_handle, uint8_t data_path_dir, uint8_t data_path_id, 415 uint8_t codec_id_format, uint16_t codec_id_company, 416 uint16_t codec_id_vendor, uint32_t controller_delay, 417 std::vector<uint8_t> codec_conf, 418 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 419 420 void btsnd_hcic_remove_iso_data_path( 421 uint16_t iso_handle, uint8_t data_path_dir, 422 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 423 424 void btsnd_hcic_read_iso_link_quality( 425 uint16_t iso_handle, base::OnceCallback<void(uint8_t*, uint16_t)> cb); 426 427 void btsnd_hcic_ble_periodic_advertising_create_sync( 428 uint8_t options, uint8_t adv_sid, uint8_t adv_addr_type, 429 const RawAddress& adv_addr, uint16_t skip_num, uint16_t sync_timeout, 430 uint8_t sync_cte_type); 431 432 void btsnd_hcic_ble_periodic_advertising_create_sync_cancel( 433 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 434 435 void btsnd_hcic_ble_periodic_advertising_terminate_sync( 436 uint16_t sync_handle, base::OnceCallback<void(uint8_t*, uint16_t)> cb); 437 438 void btsnd_hci_ble_add_device_to_periodic_advertiser_list( 439 uint8_t adv_addr_type, const RawAddress& adv_addr, uint8_t adv_sid, 440 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 441 442 void btsnd_hci_ble_remove_device_from_periodic_advertiser_list( 443 uint8_t adv_addr_type, const RawAddress& adv_addr, uint8_t adv_sid, 444 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 445 446 void btsnd_hci_ble_clear_periodic_advertiser_list( 447 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 448 449 void btsnd_hcic_ble_set_periodic_advertising_receive_enable( 450 uint16_t sync_handle, bool enable, 451 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 452 453 void btsnd_hcic_ble_periodic_advertising_sync_transfer( 454 uint16_t conn_handle, uint16_t service_data, uint16_t sync_handle, 455 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 456 457 void btsnd_hcic_ble_periodic_advertising_set_info_transfer( 458 uint16_t conn_handle, uint16_t service_data, uint8_t adv_handle, 459 base::OnceCallback<void(uint8_t*, uint16_t)> cb); 460 461 void btsnd_hcic_ble_set_periodic_advertising_sync_transfer_params( 462 uint16_t conn_handle, uint8_t mode, uint16_t skip, uint16_t sync_timeout, 463 uint8_t cte_type, base::OnceCallback<void(uint8_t*, uint16_t)> cb); 464 465 void btsnd_hcic_ble_set_default_periodic_advertising_sync_transfer_params( 466 uint16_t conn_handle, uint8_t mode, uint16_t skip, uint16_t sync_timeout, 467 uint8_t cte_type, base::OnceCallback<void(uint8_t*, uint16_t)> cb); 468 469 void btsnd_hcic_configure_data_path(hci_data_direction_t data_path_direction, 470 uint8_t data_path_id, 471 std::vector<uint8_t> vendor_config); 472 473 #endif 474