1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <cstdint> 20 21 #include "device/include/esco_parameters.h" 22 #include "stack/btm/neighbor_inquiry.h" 23 #include "stack/btm/power_mode.h" 24 #include "stack/include/acl_client_callbacks.h" 25 #include "stack/include/bt_hdr.h" 26 #include "stack/include/btm_api.h" 27 #include "stack/include/btm_api_types.h" 28 #include "stack/include/btm_ble_api_types.h" 29 #include "stack/include/btm_status.h" 30 #include "stack/include/security_client_callbacks.h" 31 #include "types/bt_transport.h" 32 #include "types/raw_address.h" 33 34 struct btm_client_interface_t { 35 struct { 36 [[nodiscard]] tBTM_STATUS (*BTM_PmRegister)(uint8_t mask, uint8_t* p_pm_id, 37 tBTM_PM_STATUS_CBACK* p_cback); 38 [[nodiscard]] uint16_t (*BTM_GetHCIConnHandle)(const RawAddress& bd_addr, 39 tBT_TRANSPORT transport); 40 void (*BTM_VendorSpecificCommand)(uint16_t opcode, uint8_t param_len, 41 uint8_t* p_param_buf, 42 tBTM_VSC_CMPL_CB* p_cb); 43 void (*ACL_RegisterClient)(struct acl_client_callback_s* callbacks); 44 void (*ACL_UnregisterClient)(struct acl_client_callback_s* callbacks); 45 void (*btm_init)(); 46 void (*btm_free)(); 47 void (*btm_ble_init)(); 48 void (*btm_ble_free)(); 49 void (*BTM_reset_complete)(); 50 } lifecycle; 51 52 // Acl peer and lifecycle 53 struct { 54 [[nodiscard]] bool (*BTM_IsAclConnectionUp)(const RawAddress& bd_addr, 55 tBT_TRANSPORT transport); 56 [[nodiscard]] bool (*BTM_ReadConnectedTransportAddress)( 57 RawAddress* bd_addr, tBT_TRANSPORT transport); 58 [[nodiscard]] tBTM_STATUS (*BTM_CancelRemoteDeviceName)(void); 59 [[nodiscard]] tBTM_STATUS (*BTM_ReadRemoteDeviceName)( 60 const RawAddress& bd_addr, tBTM_NAME_CMPL_CB* p_cb, 61 tBT_TRANSPORT transport); 62 [[nodiscard]] uint8_t* (*BTM_ReadRemoteFeatures)(const RawAddress&); 63 void (*BTM_ReadDevInfo)(const RawAddress& bd_addr, 64 tBT_DEVICE_TYPE* p_dev_type, 65 tBLE_ADDR_TYPE* p_addr_type); 66 [[nodiscard]] uint16_t (*BTM_GetMaxPacketSize)(const RawAddress& bd_addr); 67 [[nodiscard]] bool (*BTM_ReadRemoteVersion)(const RawAddress& addr, 68 uint8_t* lmp_version, 69 uint16_t* manufacturer, 70 uint16_t* lmp_sub_version); 71 [[nodiscard]] tBT_DEVICE_TYPE (*BTM_GetPeerDeviceTypeFromFeatures)( 72 const RawAddress& bd_addr); 73 void (*BTM_RequestPeerSCA)(const RawAddress& remote_bda, 74 tBT_TRANSPORT transport); 75 [[nodiscard]] uint8_t (*BTM_GetPeerSCA)(const RawAddress& remote_bda, 76 tBT_TRANSPORT transport); 77 [[nodiscard]] bool (*BTM_IsPhy2mSupported)(const RawAddress& remote_bda, 78 tBT_TRANSPORT transport); 79 } peer; 80 81 struct { 82 [[nodiscard]] tBTM_STATUS (*BTM_GetRole)(const RawAddress& remote_bd_addr, 83 tHCI_ROLE* p_role); 84 [[nodiscard]] tBTM_STATUS (*BTM_SetPowerMode)(uint8_t pm_id, 85 const RawAddress& bd_addr, 86 const tBTM_PM_PWR_MD* p_mode); 87 [[nodiscard]] tBTM_STATUS (*BTM_SetSsrParams)(const RawAddress& bd_addr, 88 uint16_t max_lat, 89 uint16_t min_rmt_to, 90 uint16_t min_loc_to); 91 [[nodiscard]] tBTM_STATUS (*BTM_SwitchRoleToCentral)( 92 const RawAddress& remote_bd_addr); 93 void (*BTM_block_role_switch_for)(const RawAddress& peer_addr); 94 void (*BTM_block_sniff_mode_for)(const RawAddress& peer_addr); 95 void (*BTM_default_unblock_role_switch)(); 96 void (*BTM_unblock_role_switch_for)(const RawAddress& peer_addr); 97 void (*BTM_unblock_sniff_mode_for)(const RawAddress& peer_addr); 98 void (*BTM_WritePageTimeout)(uint16_t timeout); 99 } link_policy; 100 101 struct { 102 [[nodiscard]] tBTM_STATUS (*BTM_GetLinkSuperTout)(const RawAddress& bd_addr, 103 uint16_t* p_timeout); 104 [[nodiscard]] tBTM_STATUS (*BTM_ReadRSSI)(const RawAddress& bd_addr, 105 tBTM_CMPL_CB* p_cb); 106 } link_controller; 107 108 SecurityClientInterface security; 109 struct { 110 [[nodiscard]] tBTM_STATUS (*BTM_BleGetEnergyInfo)( 111 tBTM_BLE_ENERGY_INFO_CBACK* callback); 112 [[nodiscard]] tBTM_STATUS (*BTM_BleObserve)( 113 bool start, uint8_t duration, tBTM_INQ_RESULTS_CB* p_results_cb, 114 tBTM_CMPL_CB* p_cmpl_cb, bool low_latency_scan); 115 [[nodiscard]] tBTM_STATUS (*BTM_SetBleDataLength)(const RawAddress& bd_addr, 116 uint16_t tx_pdu_length); 117 void (*BTM_BleReadControllerFeatures)( 118 tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback); 119 void (*BTM_BleSetPhy)(const RawAddress& bd_addr, uint8_t tx_phys, 120 uint8_t rx_phys, uint16_t phy_options); 121 void (*BTM_BleSetPrefConnParams)(const RawAddress& bd_addr, 122 uint16_t min_conn_int, 123 uint16_t max_conn_int, 124 uint16_t peripheral_latency, 125 uint16_t supervision_tout); 126 [[nodiscard]] bool (*BTM_UseLeLink)(const RawAddress& bd_addr); 127 [[nodiscard]] bool (*BTM_IsRemoteVersionReceived)( 128 const RawAddress& remote_bda); 129 void (*BTM_SetConsolidationCallback)(BTM_CONSOLIDATION_CB* cb); 130 } ble; 131 132 struct { 133 [[nodiscard]] tBTM_STATUS (*BTM_CreateSco)(const RawAddress* bd_addr, 134 bool is_orig, uint16_t pkt_types, 135 uint16_t* p_sco_inx, 136 tBTM_SCO_CB* p_conn_cb, 137 tBTM_SCO_CB* p_disc_cb); 138 [[nodiscard]] tBTM_STATUS (*BTM_RegForEScoEvts)( 139 uint16_t sco_inx, tBTM_ESCO_CBACK* p_esco_cback); 140 [[nodiscard]] tBTM_STATUS (*BTM_RemoveSco)(uint16_t sco_inx); 141 void (*BTM_WriteVoiceSettings)(uint16_t settings); 142 void (*BTM_EScoConnRsp)(uint16_t sco_inx, tHCI_STATUS hci_status, 143 enh_esco_params_t* p_parms); 144 [[nodiscard]] uint8_t (*BTM_GetNumScoLinks)(); 145 [[nodiscard]] tBTM_STATUS (*BTM_SetEScoMode)(enh_esco_params_t* p_parms); 146 [[nodiscard]] tBTM_SCO_DEBUG_DUMP (*BTM_GetScoDebugDump)(void); 147 [[nodiscard]] bool (*BTM_IsScoActiveByBdaddr)(const RawAddress& remote_bda); 148 } sco; 149 150 struct { 151 [[nodiscard]] tBTM_STATUS (*BTM_ReadLocalDeviceName)(const char** p_name); 152 [[nodiscard]] tBTM_STATUS (*BTM_ReadLocalDeviceNameFromController)( 153 tBTM_CMPL_CB* p_rln_cmpl_cback); 154 [[nodiscard]] tBTM_STATUS (*BTM_SetLocalDeviceName)(const char* p_name); 155 [[nodiscard]] tBTM_STATUS (*BTM_SetDeviceClass)(DEV_CLASS dev_class); 156 [[nodiscard]] bool (*BTM_IsDeviceUp)(); 157 [[nodiscard]] DEV_CLASS (*BTM_ReadDeviceClass)(); 158 } local; 159 160 struct { 161 [[nodiscard]] tBTM_STATUS (*BTM_WriteEIR)(BT_HDR* p_buff); 162 [[nodiscard]] uint8_t (*BTM_GetEirSupportedServices)(uint32_t* p_eir_uuid, 163 uint8_t** p, 164 uint8_t max_num_uuid16, 165 uint8_t* p_num_uuid16); 166 [[nodiscard]] uint8_t (*BTM_GetEirUuidList)( 167 const uint8_t* p_eir, size_t eir_len, uint8_t uuid_size, 168 uint8_t* p_num_uuid, uint8_t* p_uuid_list, uint8_t max_num_uuid); 169 void (*BTM_AddEirService)(uint32_t* p_eir_uuid, uint16_t uuid16); 170 void (*BTM_RemoveEirService)(uint32_t* p_eir_uuid, uint16_t uuid16); 171 } eir; 172 173 struct { 174 [[nodiscard]] tBTM_INQ_INFO* (*BTM_InqDbRead)(const RawAddress& p_bda); 175 [[nodiscard]] tBTM_INQ_INFO* (*BTM_InqDbFirst)(); 176 [[nodiscard]] tBTM_INQ_INFO* (*BTM_InqDbNext)(tBTM_INQ_INFO* p_cur); 177 [[nodiscard]] tBTM_STATUS (*BTM_ClearInqDb)(const RawAddress* p_bda); 178 } db; 179 }; 180 181 struct btm_client_interface_t& get_btm_client_interface(); 182