]> granicus.if.org Git - esp-idf/blob - components/bt/bluedroid/bta/include/bta_sys.h
component/bt: free timer resources after using them
[esp-idf] / components / bt / bluedroid / bta / include / bta_sys.h
1 /******************************************************************************
2  *
3  *  Copyright (C) 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 "bt_target.h"
28 #include "bt_defs.h"
29
30 /*****************************************************************************
31 **  Constants and data types
32 *****************************************************************************/
33
34 /* vendor specific event handler function type */
35 typedef BOOLEAN (tBTA_SYS_VS_EVT_HDLR)(UINT16 evt, void *p);
36
37 /* event handler function type */
38 typedef BOOLEAN (tBTA_SYS_EVT_HDLR)(BT_HDR *p_msg);
39
40 /* disable function type */
41 typedef void (tBTA_SYS_DISABLE)(void);
42
43
44 /* HW modules */
45 enum {
46     BTA_SYS_HW_BLUETOOTH,
47     BTA_SYS_HW_RT,
48
49     BTA_SYS_MAX_HW_MODULES
50 };
51
52 typedef UINT16 tBTA_SYS_HW_MODULE;
53
54 #ifndef BTA_DM_NUM_JV_ID
55 #define BTA_DM_NUM_JV_ID    2
56 #endif
57
58 /* SW sub-systems */
59 #define BTA_ID_SYS          0            /* system manager */
60 /* BLUETOOTH PART - from 0 to BTA_ID_BLUETOOTH_MAX */
61 #define BTA_ID_DM           1            /* device manager */
62 #define BTA_ID_DM_SEARCH    2            /* device manager search */
63 #define BTA_ID_DM_SEC       3            /* device manager security */
64 #define BTA_ID_DG           4            /* data gateway */
65 #define BTA_ID_AG           5            /* audio gateway */
66 #define BTA_ID_OPC          6            /* object push client */
67 #define BTA_ID_OPS          7            /* object push server */
68 #define BTA_ID_FTS          8            /* file transfer server */
69 #define BTA_ID_CT           9            /* cordless telephony terminal */
70 #define BTA_ID_FTC          10           /* file transfer client */
71 #define BTA_ID_SS           11           /* synchronization server */
72 #define BTA_ID_PR           12           /* Printer client */
73 #define BTA_ID_BIC          13           /* Basic Imaging Client */
74 #define BTA_ID_PAN          14           /* Personal Area Networking */
75 #define BTA_ID_BIS          15           /* Basic Imaging Server */
76 #define BTA_ID_ACC          16           /* Advanced Camera Client */
77 #define BTA_ID_SC           17           /* SIM Card Access server */
78 #define BTA_ID_AV           18           /* Advanced audio/video */
79 #define BTA_ID_AVK          19           /* Audio/video sink */
80 #define BTA_ID_HD           20           /* HID Device */
81 #define BTA_ID_CG           21           /* Cordless Gateway */
82 #define BTA_ID_BP           22           /* Basic Printing Client */
83 #define BTA_ID_HH           23           /* Human Interface Device Host */
84 #define BTA_ID_PBS          24           /* Phone Book Access Server */
85 #define BTA_ID_PBC          25           /* Phone Book Access Client */
86 #define BTA_ID_JV           26           /* Java */
87 #define BTA_ID_HS           27           /* Headset */
88 #define BTA_ID_MSE          28           /* Message Server Equipment */
89 #define BTA_ID_MCE          29           /* Message Client Equipment */
90 #define BTA_ID_HL           30           /* Health Device Profile*/
91 #define BTA_ID_GATTC        31           /* GATT Client */
92 #define BTA_ID_GATTS        32           /* GATT Client */
93 #define BTA_ID_SDP          33           /* SDP Client */
94 #define BTA_ID_BLUETOOTH_MAX   34        /* last BT profile */
95
96 /* GENERIC */
97 #define BTA_ID_PRM          38
98 #define BTA_ID_SYSTEM       39           /* platform-specific */
99 #define BTA_ID_SWRAP        40           /* Insight script wrapper */
100 #define BTA_ID_MIP          41           /* Multicase Individual Polling */
101 #define BTA_ID_RT           42           /* Audio Routing module: This module is always on. */
102
103
104 /* JV */
105 #define BTA_ID_JV1          44           /* JV1 */
106 #define BTA_ID_JV2          45           /* JV2 */
107
108 #define BTA_ID_MAX          (44 + BTA_DM_NUM_JV_ID)
109
110 typedef UINT8 tBTA_SYS_ID;
111
112
113 #define BTA_SYS_CONN_OPEN           0x00
114 #define BTA_SYS_CONN_CLOSE          0x01
115 #define BTA_SYS_APP_OPEN            0x02
116 #define BTA_SYS_APP_CLOSE           0x03
117 #define BTA_SYS_SCO_OPEN            0x04
118 #define BTA_SYS_SCO_CLOSE           0x05
119 #define BTA_SYS_CONN_IDLE           0x06
120 #define BTA_SYS_CONN_BUSY           0x07
121
122 /* for link policy */
123 #define BTA_SYS_PLCY_SET            0x10 /* set the link policy to the given addr */
124 #define BTA_SYS_PLCY_CLR            0x11 /* clear the link policy to the given addr */
125 #define BTA_SYS_PLCY_DEF_SET        0x12 /* set the default link policy */
126 #define BTA_SYS_PLCY_DEF_CLR        0x13 /* clear the default link policy */
127 #define BTA_SYS_ROLE_CHANGE         0x14 /* role change */
128
129 typedef UINT8 tBTA_SYS_CONN_STATUS;
130
131 /* Bitmask of sys features */
132 #define BTA_SYS_FEAT_PCM2           0x0001
133 #define BTA_SYS_FEAT_PCM2_MASTER    0x0002
134
135 /* tBTA_PREF_ROLES */
136 typedef UINT8 tBTA_SYS_PREF_ROLES;
137
138 /* conn callback for role / low power manager*/
139 typedef void (tBTA_SYS_CONN_CBACK)(tBTA_SYS_CONN_STATUS status, UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
140
141 /* conn callback for role / low power manager*/
142 typedef void (tBTA_SYS_SSR_CFG_CBACK)(UINT8 id, UINT8 app_id, UINT16 latency, UINT16 tout);
143
144 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
145 /* eir callback for adding/removeing UUID */
146 typedef void (tBTA_SYS_EIR_CBACK)(UINT16 uuid16, BOOLEAN adding);
147 #endif
148
149 /* registration structure */
150 typedef struct {
151     tBTA_SYS_EVT_HDLR   *evt_hdlr;
152     tBTA_SYS_DISABLE    *disable;
153 } tBTA_SYS_REG;
154
155 /* data type to send events to BTA SYS HW manager */
156 typedef struct {
157     BT_HDR                hdr;
158     tBTA_SYS_HW_MODULE   hw_module;
159 } tBTA_SYS_HW_MSG;
160
161 /*****************************************************************************
162 **  Global data
163 *****************************************************************************/
164
165 /* trace level */
166 extern UINT8 appl_trace_level;
167
168 /*****************************************************************************
169 **  Macros
170 *****************************************************************************/
171
172 /* Calculate start of event enumeration; id is top 8 bits of event */
173 #define BTA_SYS_EVT_START(id)       ((id) << 8)
174
175 /*****************************************************************************
176 **  events for BTA SYS HW manager
177 *****************************************************************************/
178
179 /* events sent to SYS HW manager - must be kept synchronized with tables in bta_sys_main.c */
180 enum {
181     /* device manager local device API events */
182     BTA_SYS_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_SYS),
183     BTA_SYS_EVT_ENABLED_EVT,
184     BTA_SYS_EVT_STACK_ENABLED_EVT,
185     BTA_SYS_API_DISABLE_EVT,
186     BTA_SYS_EVT_DISABLED_EVT,
187     BTA_SYS_ERROR_EVT,
188
189     BTA_SYS_MAX_EVT
190 };
191
192
193
194 /* SYS HW status events - returned by SYS HW manager to other modules. */
195 enum {
196     BTA_SYS_HW_OFF_EVT,
197     BTA_SYS_HW_ON_EVT,
198     BTA_SYS_HW_STARTING_EVT,
199     BTA_SYS_HW_STOPPING_EVT,
200     BTA_SYS_HW_ERROR_EVT
201
202 };
203 typedef UINT8 tBTA_SYS_HW_EVT;
204
205 /* HW enable callback type */
206 typedef void (tBTA_SYS_HW_CBACK)(tBTA_SYS_HW_EVT status);
207
208 /*****************************************************************************
209 **  Function declarations
210 *****************************************************************************/
211
212 #ifdef __cplusplus
213 extern "C" {
214 #endif
215
216 extern void bta_sys_init(void);
217 extern void bta_sys_free(void);
218 extern void bta_sys_event(BT_HDR *p_msg);
219 extern void bta_sys_set_trace_level(UINT8 level);
220 extern void bta_sys_register(UINT8 id, const tBTA_SYS_REG *p_reg);
221 extern void bta_sys_deregister(UINT8 id);
222 extern BOOLEAN bta_sys_is_register(UINT8 id);
223 extern UINT16 bta_sys_get_sys_features(void);
224 extern void bta_sys_sendmsg(void *p_msg);
225 extern void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms);
226 extern void bta_sys_stop_timer(TIMER_LIST_ENT *p_tle);
227 extern void bta_sys_free_timer(TIMER_LIST_ENT *p_tle);
228 extern void bta_sys_disable(tBTA_SYS_HW_MODULE module);
229 extern UINT32 bta_sys_get_remaining_ticks(TIMER_LIST_ENT *p_target_tle);
230
231 extern void bta_sys_hw_register( tBTA_SYS_HW_MODULE module, tBTA_SYS_HW_CBACK *cback);
232 extern void bta_sys_hw_unregister( tBTA_SYS_HW_MODULE module );
233
234
235 extern void bta_sys_rm_register(tBTA_SYS_CONN_CBACK *p_cback);
236 extern void bta_sys_pm_register(tBTA_SYS_CONN_CBACK *p_cback);
237
238 extern void bta_sys_policy_register(tBTA_SYS_CONN_CBACK *p_cback);
239 extern void bta_sys_sco_register(tBTA_SYS_CONN_CBACK *p_cback);
240
241
242 extern void bta_sys_conn_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
243 extern void bta_sys_conn_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
244 extern void bta_sys_app_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
245 extern void bta_sys_app_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
246 extern void bta_sys_sco_open(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
247 extern void bta_sys_sco_close(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
248 extern void bta_sys_sco_use(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
249 extern void bta_sys_sco_unuse(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
250 extern void bta_sys_idle(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
251 extern void bta_sys_busy(UINT8 id, UINT8 app_id, BD_ADDR peer_addr);
252
253 #if (BTM_SSR_INCLUDED == TRUE)
254 extern void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK *p_cback);
255 extern void bta_sys_chg_ssr_config (UINT8 id, UINT8 app_id, UINT16 max_latency, UINT16 min_tout);
256 #endif
257
258 extern void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK *p_cback);
259 extern void bta_sys_notify_role_chg(BD_ADDR_PTR p_bda, UINT8 new_role, UINT8 hci_status);
260 extern void bta_sys_collision_register(UINT8 bta_id, tBTA_SYS_CONN_CBACK *p_cback);
261 extern void bta_sys_notify_collision (BD_ADDR_PTR p_bda);
262
263 #if (BTA_EIR_CANNED_UUID_LIST != TRUE)
264 extern void bta_sys_eir_register(tBTA_SYS_EIR_CBACK *p_cback);
265 extern void bta_sys_add_uuid(UINT16 uuid16);
266 extern void bta_sys_remove_uuid(UINT16 uuid16);
267 #else
268 #define bta_sys_eir_register(ut)
269 #define bta_sys_add_uuid(ut)
270 #define bta_sys_remove_uuid(ut)
271 #endif
272
273 extern void bta_sys_set_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr);
274 extern void bta_sys_clear_policy (UINT8 id, UINT8 policy, BD_ADDR peer_addr);
275 extern void bta_sys_set_default_policy (UINT8 id, UINT8 policy);
276 extern void bta_sys_clear_default_policy (UINT8 id, UINT8 policy);
277 extern BOOLEAN bta_sys_vs_hdl(UINT16 evt, void *p);
278
279 #ifdef __cplusplus
280 }
281 #endif
282
283 #endif /* BTA_SYS_H */