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