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/internal/btm_api.h"
23 #include "stack/btm/neighbor_inquiry.h"
24 #include "stack/btm/power_mode.h"
25 #include "stack/include/acl_client_callbacks.h"
26 #include "stack/include/bt_hdr.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     void (*ACL_RegisterClient)(struct acl_client_callback_s* callbacks);
39     void (*ACL_UnregisterClient)(struct acl_client_callback_s* callbacks);
40     void (*btm_init)();
41     void (*btm_free)();
42     void (*btm_ble_init)();
43     void (*btm_ble_free)();
44     void (*BTM_reset_complete)();
45   } lifecycle;
46 
47   // Acl peer and lifecycle
48   struct {
49     [[nodiscard]] bool (*BTM_IsAclConnectionUp)(const RawAddress& bd_addr, tBT_TRANSPORT transport);
50     [[nodiscard]] bool (*BTM_ReadConnectedTransportAddress)(RawAddress* bd_addr,
51                                                             tBT_TRANSPORT transport);
52     [[nodiscard]] uint8_t* (*BTM_ReadRemoteFeatures)(const RawAddress&);
53     void (*BTM_ReadDevInfo)(const RawAddress& bd_addr, tBT_DEVICE_TYPE* p_dev_type,
54                             tBLE_ADDR_TYPE* p_addr_type);
55     [[nodiscard]] uint16_t (*BTM_GetMaxPacketSize)(const RawAddress& bd_addr);
56     [[nodiscard]] bool (*BTM_ReadRemoteVersion)(const RawAddress& addr, uint8_t* lmp_version,
57                                                 uint16_t* manufacturer, uint16_t* lmp_sub_version);
58     [[nodiscard]] tBT_DEVICE_TYPE (*BTM_GetPeerDeviceTypeFromFeatures)(const RawAddress& bd_addr);
59     void (*BTM_RequestPeerSCA)(const RawAddress& remote_bda, tBT_TRANSPORT transport);
60     [[nodiscard]] uint8_t (*BTM_GetPeerSCA)(const RawAddress& remote_bda, tBT_TRANSPORT transport);
61     [[nodiscard]] bool (*BTM_IsPhy2mSupported)(const RawAddress& remote_bda,
62                                                tBT_TRANSPORT transport);
63     [[nodiscard]] uint16_t (*BTM_GetHCIConnHandle)(const RawAddress& bd_addr,
64                                                    tBT_TRANSPORT transport);
65     [[nodiscard]] bool (*BTM_IsAclConnectionUpAndHandleValid)(const RawAddress& remote_bda,
66                                                               tBT_TRANSPORT transport);
67   } peer;
68 
69   struct {
70     [[nodiscard]] tBTM_STATUS (*BTM_GetRole)(const RawAddress& remote_bd_addr, tHCI_ROLE* p_role);
71     [[nodiscard]] tBTM_STATUS (*BTM_SetPowerMode)(uint8_t pm_id, const RawAddress& bd_addr,
72                                                   const tBTM_PM_PWR_MD* p_mode);
73     [[nodiscard]] tBTM_STATUS (*BTM_SetSsrParams)(const RawAddress& bd_addr, uint16_t max_lat,
74                                                   uint16_t min_rmt_to, uint16_t min_loc_to);
75     [[nodiscard]] tBTM_STATUS (*BTM_SwitchRoleToCentral)(const RawAddress& remote_bd_addr);
76     void (*BTM_block_role_switch_for)(const RawAddress& peer_addr);
77     void (*BTM_block_sniff_mode_for)(const RawAddress& peer_addr);
78     void (*BTM_default_unblock_role_switch)();
79     void (*BTM_unblock_role_switch_for)(const RawAddress& peer_addr);
80     void (*BTM_unblock_sniff_mode_for)(const RawAddress& peer_addr);
81     void (*BTM_WritePageTimeout)(uint16_t timeout);
82   } link_policy;
83 
84   struct {
85     [[nodiscard]] tBTM_STATUS (*BTM_GetLinkSuperTout)(const RawAddress& bd_addr,
86                                                       uint16_t* p_timeout);
87     [[nodiscard]] tBTM_STATUS (*BTM_ReadRSSI)(const RawAddress& bd_addr, tBTM_CMPL_CB* p_cb);
88   } link_controller;
89 
90   SecurityClientInterface security;
91   struct {
92     [[nodiscard]] tBTM_STATUS (*BTM_BleGetEnergyInfo)(tBTM_BLE_ENERGY_INFO_CBACK* callback);
93     [[nodiscard]] tBTM_STATUS (*BTM_BleObserve)(bool start, uint8_t duration,
94                                                 tBTM_INQ_RESULTS_CB* p_results_cb,
95                                                 tBTM_CMPL_CB* p_cmpl_cb);
96     [[nodiscard]] tBTM_STATUS (*BTM_SetBleDataLength)(const RawAddress& bd_addr,
97                                                       uint16_t tx_pdu_length);
98     void (*BTM_BleReadControllerFeatures)(tBTM_BLE_CTRL_FEATURES_CBACK* p_vsc_cback);
99     void (*BTM_BleSetPhy)(const RawAddress& bd_addr, uint8_t tx_phys, uint8_t rx_phys,
100                           uint16_t phy_options);
101     void (*BTM_BleSetPrefConnParams)(const RawAddress& bd_addr, uint16_t min_conn_int,
102                                      uint16_t max_conn_int, uint16_t peripheral_latency,
103                                      uint16_t supervision_tout);
104     [[nodiscard]] bool (*BTM_UseLeLink)(const RawAddress& bd_addr);
105     [[nodiscard]] bool (*BTM_IsRemoteVersionReceived)(const RawAddress& remote_bda);
106     void (*BTM_SetConsolidationCallback)(BTM_CONSOLIDATION_CB* cb);
107   } ble;
108 
109   struct {
110     [[nodiscard]] tBTM_STATUS (*BTM_CreateSco)(const RawAddress* bd_addr, bool is_orig,
111                                                uint16_t pkt_types, uint16_t* p_sco_inx,
112                                                tBTM_SCO_CB* p_conn_cb, tBTM_SCO_CB* p_disc_cb);
113     [[nodiscard]] tBTM_STATUS (*BTM_RegForEScoEvts)(uint16_t sco_inx,
114                                                     tBTM_ESCO_CBACK* p_esco_cback);
115     [[nodiscard]] tBTM_STATUS (*BTM_RemoveSco)(uint16_t sco_inx);
116     void (*BTM_RemoveScoByBdaddr)(const RawAddress& bda);
117     void (*BTM_WriteVoiceSettings)(uint16_t settings);
118     void (*BTM_EScoConnRsp)(uint16_t sco_inx, tHCI_STATUS hci_status, enh_esco_params_t* p_parms);
119     [[nodiscard]] uint8_t (*BTM_GetNumScoLinks)();
120     [[nodiscard]] tBTM_STATUS (*BTM_SetEScoMode)(enh_esco_params_t* p_parms);
121     [[nodiscard]] tBTM_SCO_DEBUG_DUMP (*BTM_GetScoDebugDump)(void);
122     [[nodiscard]] bool (*BTM_IsScoActiveByBdaddr)(const RawAddress& remote_bda);
123   } sco;
124 
125   struct {
126     [[nodiscard]] tBTM_STATUS (*BTM_ReadLocalDeviceName)(const char** p_name);
127     [[nodiscard]] tBTM_STATUS (*BTM_SetLocalDeviceName)(const char* p_name);
128     [[nodiscard]] tBTM_STATUS (*BTM_SetDeviceClass)(DEV_CLASS dev_class);
129     [[nodiscard]] bool (*BTM_IsDeviceUp)();
130     [[nodiscard]] DEV_CLASS (*BTM_ReadDeviceClass)();
131   } local;
132 
133   struct {
134     [[nodiscard]] tBTM_STATUS (*BTM_WriteEIR)(BT_HDR* p_buff);
135     [[nodiscard]] uint8_t (*BTM_GetEirSupportedServices)(uint32_t* p_eir_uuid, uint8_t** p,
136                                                          uint8_t max_num_uuid16,
137                                                          uint8_t* p_num_uuid16);
138     [[nodiscard]] uint8_t (*BTM_GetEirUuidList)(const uint8_t* p_eir, size_t eir_len,
139                                                 uint8_t uuid_size, uint8_t* p_num_uuid,
140                                                 uint8_t* p_uuid_list, uint8_t max_num_uuid);
141     void (*BTM_AddEirService)(uint32_t* p_eir_uuid, uint16_t uuid16);
142     void (*BTM_RemoveEirService)(uint32_t* p_eir_uuid, uint16_t uuid16);
143   } eir;
144 
145   struct {
146     [[nodiscard]] tBTM_INQ_INFO* (*BTM_InqDbRead)(const RawAddress& p_bda);
147     [[nodiscard]] tBTM_INQ_INFO* (*BTM_InqDbFirst)();
148     [[nodiscard]] tBTM_INQ_INFO* (*BTM_InqDbNext)(tBTM_INQ_INFO* p_cur);
149     [[nodiscard]] tBTM_STATUS (*BTM_ClearInqDb)(const RawAddress* p_bda);
150   } db;
151 
152   struct {
153     void (*BTM_VendorSpecificCommand)(uint16_t opcode, uint8_t param_len, uint8_t* p_param_buf,
154                                       tBTM_VSC_CMPL_CB* p_cb);
155   } vendor;
156 };
157 
158 struct btm_client_interface_t& get_btm_client_interface();
159 
160 void DumpsysBtm(int fd);
161