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 #include "stack/btm/neighbor_inquiry.h" 21 #include "stack/include/acl_client_callbacks.h" 22 #include "stack/include/btm_api_types.h" 23 #include "stack/include/btm_ble_api_types.h" 24 #include "stack/include/btm_status.h" 25 #include "stack/include/hci_error_code.h" 26 #include "stack/include/hcidefs.h" 27 #include "stack/include/security_client_callbacks.h" 28 #include "types/bt_transport.h" 29 #include "types/raw_address.h" 30 31 struct btm_client_interface_s { 32 struct { 33 tBTM_STATUS (*BTM_PmRegister)(uint8_t mask, uint8_t* p_pm_id, 34 tBTM_PM_STATUS_CBACK* p_cback); 35 uint16_t (*BTM_GetHCIConnHandle)(const RawAddress& bd_addr, 36 tBT_TRANSPORT transport); 37 void (*BTM_VendorSpecificCommand)(uint16_t opcode, uint8_t param_len, 38 uint8_t* p_param_buf, 39 tBTM_VSC_CMPL_CB* p_cb); 40 void (*ACL_RegisterClient)(struct acl_client_callback_s* callbacks); 41 void (*ACL_UnregisterClient)(struct acl_client_callback_s* callbacks); 42 void (*btm_init)(); 43 void (*btm_free)(); 44 void (*btm_ble_init)(); 45 void (*btm_ble_free)(); 46 void (*BTM_reset_complete)(); 47 } lifecycle; 48 49 struct { 50 // Server channel number 51 uint8_t (*BTM_AllocateSCN)(void); 52 bool (*BTM_TryAllocateSCN)(uint8_t scn); 53 bool (*BTM_FreeSCN)(uint8_t scn); 54 } scn; 55 56 // Neighbor 57 struct { 58 void (*BTM_CancelInquiry)(); 59 tBTM_INQ_INFO* (*BTM_InqDbNext)(tBTM_INQ_INFO* p_cur); 60 tBTM_STATUS (*BTM_ClearInqDb)(const RawAddress* p_bda); 61 tBTM_STATUS (*BTM_SetDiscoverability)(uint16_t inq_mode); 62 tBTM_STATUS (*BTM_SetConnectability)(uint16_t page_mode); 63 tBTM_STATUS (*BTM_StartInquiry)(tBTM_INQ_RESULTS_CB* p_results_cb, 64 tBTM_CMPL_CB* p_cmpl_cb); 65 uint16_t (*BTM_IsInquiryActive)(void); 66 tBTM_STATUS (*BTM_SetInquiryMode)(uint8_t mode); 67 void (*BTM_EnableInterlacedInquiryScan)(); 68 void (*BTM_EnableInterlacedPageScan)(); 69 } neighbor; 70 71 // Acl peer and lifecycle 72 struct { 73 struct { 74 bool (*SupportTransparentSynchronousData)(const RawAddress& bd_addr); 75 } features; 76 77 bool (*BTM_IsAclConnectionUp)(const RawAddress& bd_addr, 78 tBT_TRANSPORT transport); 79 bool (*BTM_ReadConnectedTransportAddress)(RawAddress* bd_addr, 80 tBT_TRANSPORT transport); 81 tBTM_STATUS (*BTM_CancelRemoteDeviceName)(void); 82 tBTM_STATUS (*BTM_ReadRemoteDeviceName)(const RawAddress& bd_addr, 83 tBTM_CMPL_CB* p_cb, 84 tBT_TRANSPORT transport); 85 uint8_t* (*BTM_ReadRemoteFeatures)(const RawAddress&); 86 void (*BTM_ReadDevInfo)(const RawAddress& bd_addr, 87 tBT_DEVICE_TYPE* p_dev_type, 88 tBLE_ADDR_TYPE* p_addr_type); 89 uint16_t (*BTM_GetMaxPacketSize)(const RawAddress& bd_addr); 90 bool (*BTM_ReadRemoteVersion)(const RawAddress& addr, uint8_t* lmp_version, 91 uint16_t* manufacturer, 92 uint16_t* lmp_sub_version); 93 } peer; 94 95 struct { 96 tBTM_STATUS (*BTM_GetRole)(const RawAddress& remote_bd_addr, 97 tHCI_ROLE* p_role); 98 tBTM_STATUS (*BTM_SetPowerMode)(uint8_t pm_id, const RawAddress& bd_addr, 99 const tBTM_PM_PWR_MD* p_mode); 100 tBTM_STATUS (*BTM_SetSsrParams)(const RawAddress& bd_addr, uint16_t max_lat, 101 uint16_t min_rmt_to, uint16_t min_loc_to); 102 tBTM_STATUS (*BTM_SwitchRoleToCentral)(const RawAddress& remote_bd_addr); 103 void (*BTM_block_role_switch_for)(const RawAddress& peer_addr); 104 void (*BTM_block_sniff_mode_for)(const RawAddress& peer_addr); 105 void (*BTM_default_unblock_role_switch)(); 106 void (*BTM_unblock_role_switch_for)(const RawAddress& peer_addr); 107 void (*BTM_unblock_sniff_mode_for)(const RawAddress& peer_addr); 108 void (*BTM_WritePageTimeout)(uint16_t timeout); 109 } link_policy; 110 111 struct { 112 tBTM_STATUS (*BTM_GetLinkSuperTout)(const RawAddress& bd_addr, 113 uint16_t* p_timeout); 114 tBTM_STATUS (*BTM_ReadRSSI)(const RawAddress& bd_addr, tBTM_CMPL_CB* p_cb); 115 } link_controller; 116 117 struct { 118 bool (*BTM_SecAddDevice)(const RawAddress& bd_addr, DEV_CLASS dev_class, 119 BD_NAME bd_name, uint8_t* features, 120 LinkKey* link_key, uint8_t key_type, 121 uint8_t pin_length); 122 bool (*BTM_SecAddRmtNameNotifyCallback)(tBTM_RMT_NAME_CALLBACK* p_callback); 123 bool (*BTM_SecDeleteDevice)(const RawAddress& bd_addr); 124 bool (*BTM_SecDeleteRmtNameNotifyCallbac)( 125 tBTM_RMT_NAME_CALLBACK* p_callback); 126 bool (*BTM_SecRegister)(const tBTM_APPL_INFO* p_cb_info); 127 char* (*BTM_SecReadDevName)(const RawAddress& bd_addr); 128 tBTM_STATUS (*BTM_SecBond)(const RawAddress& bd_addr, 129 tBLE_ADDR_TYPE addr_type, 130 tBT_TRANSPORT transport, int device_type, 131 uint8_t pin_len, uint8_t* p_pin); 132 tBTM_STATUS (*BTM_SecBondCancel)(const RawAddress& bd_addr); 133 void (*BTM_SecAddBleKey)(const RawAddress& bd_addr, 134 tBTM_LE_KEY_VALUE* p_le_key, 135 tBTM_LE_KEY_TYPE key_type); 136 void (*BTM_SecAddBleDevice)(const RawAddress& bd_addr, 137 tBT_DEVICE_TYPE dev_type, 138 tBLE_ADDR_TYPE addr_type); 139 void (*BTM_SecClearSecurityFlags)(const RawAddress& bd_addr); 140 uint8_t (*BTM_SecClrService)(uint8_t service_id); 141 uint8_t (*BTM_SecClrServiceByPsm)(uint16_t psm); 142 void (*BTM_RemoteOobDataReply)(tBTM_STATUS res, const RawAddress& bd_addr, 143 const Octet16& c, const Octet16& r); 144 void (*BTM_PINCodeReply)(const RawAddress& bd_addr, uint8_t res, 145 uint8_t pin_len, uint8_t* p_pin); 146 void (*BTM_ConfirmReqReply)(tBTM_STATUS res, const RawAddress& bd_addr); 147 bool (*BTM_SecDeleteRmtNameNotifyCallback)( 148 tBTM_RMT_NAME_CALLBACK* p_callback); 149 tBTM_STATUS (*BTM_SetEncryption)(const RawAddress& bd_addr, 150 tBT_TRANSPORT transport, 151 tBTM_SEC_CALLBACK* p_callback, 152 void* p_ref_data, 153 tBTM_BLE_SEC_ACT sec_act); 154 bool (*BTM_IsEncrypted)(const RawAddress& bd_addr, tBT_TRANSPORT transport); 155 bool (*BTM_SecIsSecurityPending)(const RawAddress& bd_addr); 156 bool (*BTM_IsLinkKeyKnown)(const RawAddress& bd_addr, 157 tBT_TRANSPORT transport); 158 } security; 159 160 struct { 161 tBTM_STATUS (*BTM_BleGetEnergyInfo)(tBTM_BLE_ENERGY_INFO_CBACK* callback); 162 tBTM_STATUS (*BTM_BleObserve)(bool start, uint8_t duration, 163 tBTM_INQ_RESULTS_CB* p_results_cb, 164 tBTM_CMPL_CB* p_cmpl_cb); 165 tBTM_STATUS (*BTM_SetBleDataLength)(const RawAddress& bd_addr, 166 uint16_t tx_pdu_length); 167 void (*BTM_BleConfirmReply)(const RawAddress& bd_addr, uint8_t res); 168 void (*BTM_BleLoadLocalKeys)(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key); 169 void (*BTM_BlePasskeyReply)(const RawAddress& bd_addr, uint8_t res, 170 uint32_t passkey); 171 void (*BTM_BleReadControllerFeatures)( 172 tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback); 173 void (*BTM_BleSetConnScanParams)(uint32_t scan_interval, 174 uint32_t scan_window); 175 void (*BTM_BleSetPhy)(const RawAddress& bd_addr, uint8_t tx_phys, 176 uint8_t rx_phys, uint16_t phy_options); 177 void (*BTM_BleSetPrefConnParams)(const RawAddress& bd_addr, 178 uint16_t min_conn_int, 179 uint16_t max_conn_int, 180 uint16_t peripheral_latency, 181 uint16_t supervision_tout); 182 bool (*BTM_UseLeLink)(const RawAddress& bd_addr); 183 } ble; 184 185 struct { 186 tBTM_STATUS (*BTM_CreateSco)(const RawAddress* bd_addr, bool is_orig, 187 uint16_t pkt_types, uint16_t* p_sco_inx, 188 tBTM_SCO_CB* p_conn_cb, 189 tBTM_SCO_CB* p_disc_cb); 190 tBTM_STATUS (*BTM_RegForEScoEvts)(uint16_t sco_inx, 191 tBTM_ESCO_CBACK* p_esco_cback); 192 tBTM_STATUS (*BTM_RemoveSco)(uint16_t sco_inx); 193 void (*BTM_WriteVoiceSettings)(uint16_t settings); 194 void (*BTM_EScoConnRsp)(uint16_t sco_inx, uint8_t hci_status, 195 enh_esco_params_t* p_parms); 196 uint8_t (*BTM_GetNumScoLinks)(); 197 tBTM_STATUS (*BTM_SetEScoMode)(enh_esco_params_t* p_parms); 198 } sco; 199 200 struct { 201 tBTM_STATUS (*BTM_ReadLocalDeviceNameFromController)( 202 tBTM_CMPL_CB* p_rln_cmpl_cback); 203 tBTM_STATUS (*BTM_SetLocalDeviceName)(char* p_name); 204 tBTM_STATUS (*BTM_SetDeviceClass)(DEV_CLASS dev_class); 205 bool (*BTM_IsDeviceUp)(); 206 uint8_t* (*BTM_ReadDeviceClass)(); 207 } local; 208 209 struct { 210 tBTM_STATUS (*BTM_WriteEIR)(BT_HDR* p_buff); 211 uint8_t (*BTM_GetEirSupportedServices)(uint32_t* p_eir_uuid, uint8_t** p, 212 uint8_t max_num_uuid16, 213 uint8_t* p_num_uuid16); 214 uint8_t (*BTM_GetEirUuidList)(uint8_t* p_eir, size_t eir_len, 215 uint8_t uuid_size, uint8_t* p_num_uuid, 216 uint8_t* p_uuid_list, uint8_t max_num_uuid); 217 void (*BTM_RemoveEirService)(uint32_t* p_eir_uuid, uint16_t uuid16); 218 } eir; 219 220 struct { 221 tBTM_INQ_INFO* (*BTM_InqDbRead)(const RawAddress& p_bda); 222 tBTM_INQ_INFO* (*BTM_InqDbFirst)(); 223 tBTM_INQ_INFO* (*BTM_InqDbNext)(tBTM_INQ_INFO* p_cur); 224 tBTM_STATUS (*BTM_ClearInqDb)(const RawAddress* p_bda); 225 } db; 226 }; 227 228 struct btm_client_interface_s& get_btm_client_interface(); 229