1 /******************************************************************************
2 *
3 * Copyright 2003-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 /******************************************************************************
20 *
21 * This is the public interface file for the BTA system manager.
22 *
23 ******************************************************************************/
24 #ifndef BTA_SYS_H
25 #define BTA_SYS_H
26
27 #include <base/time/time.h>
28
29 #include <cstdint>
30
31 #include "bt_target.h" // Must be first to define build configuration
32 #include "osi/include/alarm.h"
33 #include "stack/include/bt_hdr.h"
34 #include "stack/include/hci_error_code.h"
35 #include "types/bluetooth/uuid.h"
36 #include "types/hci_role.h"
37 #include "types/raw_address.h"
38
39 /*****************************************************************************
40 * Constants and data types
41 ****************************************************************************/
42
43 /* vendor specific event handler function type */
44 typedef bool(tBTA_SYS_VS_EVT_HDLR)(uint16_t evt, void* p);
45
46 /* event handler function type */
47 typedef bool(tBTA_SYS_EVT_HDLR)(BT_HDR_RIGID* p_msg);
48 static_assert(
49 sizeof(BT_HDR) == sizeof(BT_HDR_RIGID),
50 "Rigid replacement should be same size struct with flexible member");
51
52 /* disable function type */
53 typedef void(tBTA_SYS_DISABLE)(void);
54
55 template <typename T, typename U>
Specialize(U * u)56 inline const T* Specialize(U* u) {
57 return const_cast<const T*>(reinterpret_cast<T*>(u));
58 }
59
60 #ifndef BTA_DM_NUM_JV_ID
61 #define BTA_DM_NUM_JV_ID 2
62 #endif
63
64 /* SW sub-systems */
65 #define BTA_ID_SYS 0 /* system manager */
66 /* BLUETOOTH PART - from 0 to BTA_ID_BLUETOOTH_MAX */
67 #define BTA_ID_DM_SEARCH 2 /* device manager search */
68 #define BTA_ID_DM_SEC 3 /* device manager security */
69 #define BTA_ID_DG 4 /* data gateway */
70 #define BTA_ID_AG 5 /* audio gateway */
71 #define BTA_ID_OPC 6 /* object push client */
72 #define BTA_ID_OPS 7 /* object push server */
73 #define BTA_ID_FTS 8 /* file transfer server */
74 #define BTA_ID_CT 9 /* cordless telephony terminal */
75 #define BTA_ID_FTC 10 /* file transfer client */
76 #define BTA_ID_SS 11 /* synchronization server */
77 #define BTA_ID_PR 12 /* Printer client */
78 #define BTA_ID_BIC 13 /* Basic Imaging Client */
79 #define BTA_ID_PAN 14 /* Personal Area Networking */
80 #define BTA_ID_BIS 15 /* Basic Imaging Server */
81 #define BTA_ID_ACC 16 /* Advanced Camera Client */
82 #define BTA_ID_SC 17 /* SIM Card Access server */
83 #define BTA_ID_AV 18 /* Advanced audio/video */
84 #define BTA_ID_HD 20 /* HID Device */
85 #define BTA_ID_CG 21 /* Cordless Gateway */
86 #define BTA_ID_BP 22 /* Basic Printing Client */
87 #define BTA_ID_HH 23 /* Human Interface Device Host */
88 #define BTA_ID_PBS 24 /* Phone Book Access Server */
89 #define BTA_ID_PBC 25 /* Phone Book Access Client */
90 #define BTA_ID_JV 26 /* Java */
91 #define BTA_ID_HS 27 /* Headset */
92 #define BTA_ID_MSE 28 /* Message Server Equipment */
93 #define BTA_ID_MCE 29 /* Message Client Equipment */
94 #define BTA_ID_HL 30 /* Health Device Profile*/
95 #define BTA_ID_GATTC 31 /* GATT Client */
96 #define BTA_ID_GATTS 32 /* GATT Client */
97 #define BTA_ID_SDP 33 /* SDP Client */
98 #define BTA_ID_BLUETOOTH_MAX 34 /* last BT profile */
99
100 #define BTA_ID_MAX (44 + BTA_DM_NUM_JV_ID)
101
102 typedef uint8_t tBTA_SYS_ID;
103
BtaIdSysText(tBTA_SYS_ID sys_id)104 inline std::string BtaIdSysText(tBTA_SYS_ID sys_id) {
105 switch (sys_id) {
106 case BTA_ID_DM_SEARCH: // 2
107 return std::string("Scanner");
108 case BTA_ID_AG: // 5
109 return std::string("Audio gateway");
110 case BTA_ID_PAN: // 14
111 return std::string("PAN Personal area network");
112 case BTA_ID_AV: // 18
113 return std::string("Advanced audio/video");
114 case BTA_ID_HD: // 20
115 return std::string("HID Human interface device");
116 case BTA_ID_HH: // 23
117 return std::string("HID Human interface host");
118 case BTA_ID_GATTC: // 31
119 return std::string("GATT client");
120 case BTA_ID_GATTS: // 32
121 return std::string("GATT server");
122 default:
123 return std::string("Unknown");
124 }
125 }
126
127 typedef enum : uint8_t {
128 BTA_SYS_CONN_OPEN = 0x00,
129 BTA_SYS_CONN_CLOSE = 0x01,
130 BTA_SYS_APP_OPEN = 0x02,
131 BTA_SYS_APP_CLOSE = 0x03,
132 BTA_SYS_SCO_OPEN = 0x04,
133 BTA_SYS_SCO_CLOSE = 0x05,
134 BTA_SYS_CONN_IDLE = 0x06,
135 BTA_SYS_CONN_BUSY = 0x07,
136 BTA_SYS_ROLE_CHANGE = 0x14, /* role change */
137 } tBTA_SYS_CONN_STATUS;
138
bta_sys_conn_status_text(tBTA_SYS_CONN_STATUS status)139 inline std::string bta_sys_conn_status_text(tBTA_SYS_CONN_STATUS status) {
140 switch (status) {
141 case BTA_SYS_CONN_OPEN:
142 return std::string("BTA_SYS_CONN_OPEN");
143 case BTA_SYS_CONN_CLOSE:
144 return std::string("BTA_SYS_CONN_CLOSE");
145 case BTA_SYS_APP_OPEN:
146 return std::string("BTA_SYS_APP_OPEN");
147 case BTA_SYS_APP_CLOSE:
148 return std::string("BTA_SYS_APP_CLOSE");
149 case BTA_SYS_SCO_OPEN:
150 return std::string("BTA_SYS_SCO_OPEN");
151 case BTA_SYS_SCO_CLOSE:
152 return std::string("BTA_SYS_SCO_CLOSE");
153 case BTA_SYS_CONN_IDLE:
154 return std::string("BTA_SYS_CONN_IDLE");
155 case BTA_SYS_CONN_BUSY:
156 return std::string("BTA_SYS_CONN_BUSY");
157 case BTA_SYS_ROLE_CHANGE:
158 return std::string("BTA_SYS_ROLE_CHANGE");
159 default:
160 return std::string("UNKNOWN");
161 }
162 }
163
164 /* conn callback for role / low power manager*/
165 typedef void(tBTA_SYS_CONN_CBACK)(tBTA_SYS_CONN_STATUS status, uint8_t id,
166 uint8_t app_id, const RawAddress& peer_addr);
167
168 /* conn callback for role / low power manager*/
169 typedef void(tBTA_SYS_SSR_CFG_CBACK)(uint8_t id, uint8_t app_id,
170 uint16_t latency, uint16_t tout);
171
172 typedef struct {
173 bluetooth::Uuid custom_uuid;
174 uint32_t handle;
175 } tBTA_CUSTOM_UUID;
176
177 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
178 /* eir callback for adding/removeing UUID */
179 typedef void(tBTA_SYS_EIR_CBACK)(uint16_t uuid16, bool adding);
180 typedef void(tBTA_SYS_CUST_EIR_CBACK)(const tBTA_CUSTOM_UUID &curr, bool adding);
181 #endif
182
183 /* registration structure */
184 typedef struct {
185 tBTA_SYS_EVT_HDLR* evt_hdlr;
186 tBTA_SYS_DISABLE* disable;
187 } tBTA_SYS_REG;
188
189 /*****************************************************************************
190 * Global data
191 ****************************************************************************/
192
193 /* trace level */
194 extern uint8_t appl_trace_level;
195
196 /*****************************************************************************
197 * Macros
198 ****************************************************************************/
199 /* Calculate start of event enumeration; id is top 8 bits of event */
200 #define BTA_SYS_EVT_START(id) ((id) << 8)
201
202 /*****************************************************************************
203 * Function declarations
204 ****************************************************************************/
205 void bta_set_forward_hw_failures(bool value);
206 void BTA_sys_signal_hw_error();
207
208 void bta_sys_init(void);
209 void bta_sys_register(uint8_t id, const tBTA_SYS_REG* p_reg);
210 void bta_sys_deregister(uint8_t id);
211 bool bta_sys_is_register(uint8_t id);
212 void bta_sys_sendmsg(void* p_msg);
213 void bta_sys_sendmsg_delayed(void* p_msg, const base::TimeDelta& delay);
214 void bta_sys_start_timer(alarm_t* alarm, uint64_t interval_ms, uint16_t event,
215 uint16_t layer_specific);
216 void bta_sys_disable();
217
218 void bta_sys_rm_register(tBTA_SYS_CONN_CBACK* p_cback);
219 void bta_sys_pm_register(tBTA_SYS_CONN_CBACK* p_cback);
220
221 void bta_sys_sco_register(tBTA_SYS_CONN_CBACK* p_cback);
222
223 void bta_sys_conn_open(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
224 void bta_sys_conn_close(uint8_t id, uint8_t app_id,
225 const RawAddress& peer_addr);
226 void bta_sys_app_open(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
227 void bta_sys_app_close(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
228 void bta_sys_sco_open(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
229 void bta_sys_sco_close(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
230 void bta_sys_sco_use(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
231 void bta_sys_sco_unuse(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
232 void bta_sys_idle(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
233 void bta_sys_busy(uint8_t id, uint8_t app_id, const RawAddress& peer_addr);
234
235 void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK* p_cback);
236 void bta_sys_chg_ssr_config(uint8_t id, uint8_t app_id, uint16_t max_latency,
237 uint16_t min_tout);
238
239 void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK* p_cback);
240 void bta_sys_notify_role_chg(const RawAddress& peer_addr, tHCI_ROLE new_role,
241 tHCI_STATUS hci_status);
242 void bta_sys_collision_register(uint8_t bta_id, tBTA_SYS_CONN_CBACK* p_cback);
243 void bta_sys_notify_collision(const RawAddress& peer_addr);
244
245 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
246 void bta_sys_eir_register(tBTA_SYS_EIR_CBACK* p_cback);
247 void bta_sys_eir_unregister();
248 void bta_sys_add_uuid(uint16_t uuid16);
249 void bta_sys_remove_uuid(uint16_t uuid16);
250 void bta_sys_cust_eir_register(tBTA_SYS_CUST_EIR_CBACK* p_cback);
251 void bta_sys_add_cust_uuid(const tBTA_CUSTOM_UUID& curr);
252 void bta_sys_remove_cust_uuid(const tBTA_CUSTOM_UUID& curr);
253 #else
254 #define bta_sys_eir_register(ut)
255 #define bta_sys_eir_unregister()
256 #define bta_sys_add_uuid(ut)
257 #define bta_sys_remove_uuid(ut)
258 #define bta_sys_cust_eir_register(ut)
259 #define bta_sys_add_cust_uuid(ut)
260 #define bta_sys_remove_cust_uuid(ut)
261 #endif
262
263 #endif /* BTA_SYS_H */
264