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 "bt_common.h" 28 #include "bt_target.h" 29 #include "osi/include/alarm.h" 30 31 #include <base/logging.h> 32 #include <base/threading/thread.h> 33 34 #include "bta/include/bta_closure_api.h" 35 36 /***************************************************************************** 37 * Constants and data types 38 ****************************************************************************/ 39 40 /* vendor specific event handler function type */ 41 typedef bool(tBTA_SYS_VS_EVT_HDLR)(uint16_t evt, void* p); 42 43 /* event handler function type */ 44 typedef bool(tBTA_SYS_EVT_HDLR)(BT_HDR* p_msg); 45 46 /* disable function type */ 47 typedef void(tBTA_SYS_DISABLE)(void); 48 49 /* HW modules */ 50 enum { 51 BTA_SYS_HW_BLUETOOTH, 52 BTA_SYS_HW_RT, 53 54 BTA_SYS_MAX_HW_MODULES 55 }; 56 57 typedef uint16_t tBTA_SYS_HW_MODULE; 58 59 #ifndef BTA_DM_NUM_JV_ID 60 #define BTA_DM_NUM_JV_ID 2 61 #endif 62 63 /* SW sub-systems */ 64 #define BTA_ID_SYS 0 /* system manager */ 65 /* BLUETOOTH PART - from 0 to BTA_ID_BLUETOOTH_MAX */ 66 #define BTA_ID_DM_SEARCH 2 /* device manager search */ 67 #define BTA_ID_DM_SEC 3 /* device manager security */ 68 #define BTA_ID_DG 4 /* data gateway */ 69 #define BTA_ID_AG 5 /* audio gateway */ 70 #define BTA_ID_OPC 6 /* object push client */ 71 #define BTA_ID_OPS 7 /* object push server */ 72 #define BTA_ID_FTS 8 /* file transfer server */ 73 #define BTA_ID_CT 9 /* cordless telephony terminal */ 74 #define BTA_ID_FTC 10 /* file transfer client */ 75 #define BTA_ID_SS 11 /* synchronization server */ 76 #define BTA_ID_PR 12 /* Printer client */ 77 #define BTA_ID_BIC 13 /* Basic Imaging Client */ 78 #define BTA_ID_PAN 14 /* Personal Area Networking */ 79 #define BTA_ID_BIS 15 /* Basic Imaging Server */ 80 #define BTA_ID_ACC 16 /* Advanced Camera Client */ 81 #define BTA_ID_SC 17 /* SIM Card Access server */ 82 #define BTA_ID_AV 18 /* Advanced audio/video */ 83 #define BTA_ID_AVK 19 /* Audio/video sink */ 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 /* GENERIC */ 101 #define BTA_ID_PRM 38 102 #define BTA_ID_SYSTEM 39 /* platform-specific */ 103 #define BTA_ID_SWRAP 40 /* Insight script wrapper */ 104 #define BTA_ID_MIP 41 /* Multicase Individual Polling */ 105 #define BTA_ID_RT 42 /* Audio Routing module: This module is always on. */ 106 #define BTA_ID_CLOSURE 43 /* Generic C++ closure */ 107 108 /* JV */ 109 #define BTA_ID_JV1 44 /* JV1 */ 110 #define BTA_ID_JV2 45 /* JV2 */ 111 112 #define BTA_ID_MAX (44 + BTA_DM_NUM_JV_ID) 113 114 typedef uint8_t tBTA_SYS_ID; 115 116 #define BTA_SYS_CONN_OPEN 0x00 117 #define BTA_SYS_CONN_CLOSE 0x01 118 #define BTA_SYS_APP_OPEN 0x02 119 #define BTA_SYS_APP_CLOSE 0x03 120 #define BTA_SYS_SCO_OPEN 0x04 121 #define BTA_SYS_SCO_CLOSE 0x05 122 #define BTA_SYS_CONN_IDLE 0x06 123 #define BTA_SYS_CONN_BUSY 0x07 124 125 /* for link policy */ 126 #define BTA_SYS_PLCY_SET 0x10 /* set the link policy to the given addr */ 127 #define BTA_SYS_PLCY_CLR 0x11 /* clear the link policy to the given addr */ 128 #define BTA_SYS_PLCY_DEF_SET 0x12 /* set the default link policy */ 129 #define BTA_SYS_PLCY_DEF_CLR 0x13 /* clear the default link policy */ 130 #define BTA_SYS_ROLE_CHANGE 0x14 /* role change */ 131 132 typedef uint8_t tBTA_SYS_CONN_STATUS; 133 134 /* Bitmask of sys features */ 135 #define BTA_SYS_FEAT_PCM2 0x0001 136 #define BTA_SYS_FEAT_PCM2_MASTER 0x0002 137 138 /* tBTA_PREF_ROLES */ 139 typedef uint8_t tBTA_SYS_PREF_ROLES; 140 141 /* conn callback for role / low power manager*/ 142 typedef void(tBTA_SYS_CONN_CBACK)(tBTA_SYS_CONN_STATUS status, uint8_t id, 143 uint8_t app_id, const RawAddress& peer_addr); 144 145 /* conn callback for role / low power manager*/ 146 typedef void(tBTA_SYS_SSR_CFG_CBACK)(uint8_t id, uint8_t app_id, 147 uint16_t latency, uint16_t tout); 148 149 #if (BTA_EIR_CANNED_UUID_LIST != TRUE) 150 /* eir callback for adding/removeing UUID */ 151 typedef void(tBTA_SYS_EIR_CBACK)(uint16_t uuid16, bool adding); 152 #endif 153 154 /* registration structure */ 155 typedef struct { 156 tBTA_SYS_EVT_HDLR* evt_hdlr; 157 tBTA_SYS_DISABLE* disable; 158 } tBTA_SYS_REG; 159 160 /* data type to send events to BTA SYS HW manager */ 161 typedef struct { 162 BT_HDR hdr; 163 tBTA_SYS_HW_MODULE hw_module; 164 } tBTA_SYS_HW_MSG; 165 166 typedef void (*tBTA_SYS_REGISTER)(uint8_t id, const tBTA_SYS_REG* p_reg); 167 168 /***************************************************************************** 169 * Global data 170 ****************************************************************************/ 171 172 /* trace level */ 173 extern uint8_t appl_trace_level; 174 175 /***************************************************************************** 176 * Macros 177 ****************************************************************************/ 178 179 /* Calculate start of event enumeration; id is top 8 bits of event */ 180 #define BTA_SYS_EVT_START(id) ((id) << 8) 181 182 /***************************************************************************** 183 * events for BTA SYS HW manager 184 ****************************************************************************/ 185 186 /* events sent to SYS HW manager - must be kept synchronized with tables in 187 * bta_sys_main.cc */ 188 enum { 189 /* device manager local device API events */ 190 BTA_SYS_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_SYS), 191 BTA_SYS_EVT_ENABLED_EVT, 192 BTA_SYS_EVT_STACK_ENABLED_EVT, 193 BTA_SYS_API_DISABLE_EVT, 194 BTA_SYS_EVT_DISABLED_EVT, 195 BTA_SYS_ERROR_EVT, 196 197 BTA_SYS_MAX_EVT 198 }; 199 200 /* SYS HW status events - returned by SYS HW manager to other modules. */ 201 enum { 202 BTA_SYS_HW_OFF_EVT, 203 BTA_SYS_HW_ON_EVT, 204 BTA_SYS_HW_STARTING_EVT, 205 BTA_SYS_HW_STOPPING_EVT, 206 BTA_SYS_HW_ERROR_EVT 207 208 }; 209 typedef uint8_t tBTA_SYS_HW_EVT; 210 211 /* HW enable callback type */ 212 typedef void(tBTA_SYS_HW_CBACK)(tBTA_SYS_HW_EVT status); 213 214 /***************************************************************************** 215 * Function declarations 216 ****************************************************************************/ 217 218 extern void bta_sys_init(void); 219 extern void bta_sys_free(void); 220 extern void bta_sys_event(BT_HDR* p_msg); 221 extern void bta_sys_set_trace_level(uint8_t level); 222 extern void bta_sys_register(uint8_t id, const tBTA_SYS_REG* p_reg); 223 extern void bta_sys_deregister(uint8_t id); 224 extern bool bta_sys_is_register(uint8_t id); 225 extern uint16_t bta_sys_get_sys_features(void); 226 extern void bta_sys_sendmsg(void* p_msg); 227 extern void bta_sys_start_timer(alarm_t* alarm, period_ms_t interval, 228 uint16_t event, uint16_t layer_specific); 229 extern void bta_sys_disable(tBTA_SYS_HW_MODULE module); 230 231 extern void bta_sys_hw_register(tBTA_SYS_HW_MODULE module, 232 tBTA_SYS_HW_CBACK* cback); 233 extern void bta_sys_hw_unregister(tBTA_SYS_HW_MODULE module); 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 extern void bta_sys_conn_open(uint8_t id, uint8_t app_id, 242 const RawAddress& peer_addr); 243 extern void bta_sys_conn_close(uint8_t id, uint8_t app_id, 244 const RawAddress& peer_addr); 245 extern void bta_sys_app_open(uint8_t id, uint8_t app_id, 246 const RawAddress& peer_addr); 247 extern void bta_sys_app_close(uint8_t id, uint8_t app_id, 248 const RawAddress& peer_addr); 249 extern void bta_sys_sco_open(uint8_t id, uint8_t app_id, 250 const RawAddress& peer_addr); 251 extern void bta_sys_sco_close(uint8_t id, uint8_t app_id, 252 const RawAddress& peer_addr); 253 extern void bta_sys_sco_use(uint8_t id, uint8_t app_id, 254 const RawAddress& peer_addr); 255 extern void bta_sys_sco_unuse(uint8_t id, uint8_t app_id, 256 const RawAddress& peer_addr); 257 extern void bta_sys_idle(uint8_t id, uint8_t app_id, 258 const RawAddress& peer_addr); 259 extern void bta_sys_busy(uint8_t id, uint8_t app_id, 260 const RawAddress& peer_addr); 261 262 #if (BTM_SSR_INCLUDED == TRUE) 263 extern void bta_sys_ssr_cfg_register(tBTA_SYS_SSR_CFG_CBACK* p_cback); 264 extern void bta_sys_chg_ssr_config(uint8_t id, uint8_t app_id, 265 uint16_t max_latency, uint16_t min_tout); 266 #endif 267 268 extern void bta_sys_role_chg_register(tBTA_SYS_CONN_CBACK* p_cback); 269 extern void bta_sys_notify_role_chg(const RawAddress& peer_addr, 270 uint8_t new_role, uint8_t hci_status); 271 extern void bta_sys_collision_register(uint8_t bta_id, 272 tBTA_SYS_CONN_CBACK* p_cback); 273 extern void bta_sys_notify_collision(const RawAddress& peer_addr); 274 275 #if (BTA_EIR_CANNED_UUID_LIST != TRUE) 276 extern void bta_sys_eir_register(tBTA_SYS_EIR_CBACK* p_cback); 277 extern void bta_sys_add_uuid(uint16_t uuid16); 278 extern void bta_sys_remove_uuid(uint16_t uuid16); 279 #else 280 #define bta_sys_eir_register(ut) 281 #define bta_sys_add_uuid(ut) 282 #define bta_sys_remove_uuid(ut) 283 #endif 284 285 extern void bta_sys_set_policy(uint8_t id, uint8_t policy, 286 const RawAddress& peer_addr); 287 extern void bta_sys_clear_policy(uint8_t id, uint8_t policy, 288 const RawAddress& peer_addr); 289 extern void bta_sys_set_default_policy(uint8_t id, uint8_t policy); 290 extern void bta_sys_clear_default_policy(uint8_t id, uint8_t policy); 291 292 #endif /* BTA_SYS_H */ 293