1 /****************************************************************************** 2 * 3 * Copyright (C) 2009-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 #ifndef BTIF_HL_H 20 #define BTIF_HL_H 21 22 #include <hardware/bluetooth.h> 23 24 #include "bta_hl_api.h" 25 #include "bt_common.h" 26 #include "osi/include/alarm.h" 27 28 /******************************************************************************* 29 ** Constants & Macros 30 ********************************************************************************/ 31 32 #define BTIF_HL_DATA_TYPE_NONE 0x0000 33 #define BTIF_HL_DATA_TYPE_PULSE_OXIMETER 0x1004 /* from BT assigned number */ 34 #define BTIF_HL_DATA_TYPE_BLOOD_PRESSURE_MON 0x1007 35 #define BTIF_HL_DATA_TYPE_BODY_THERMOMETER 0x1008 36 #define BTIF_HL_DATA_TYPE_BODY_WEIGHT_SCALE 0x100F 37 #define BTIF_HL_DATA_TYPE_GLUCOSE_METER 0x1011 38 #define BTIF_HL_DATA_TYPE_STEP_COUNTER 0x1068 39 #define BTIF_HL_DATA_TYPE_BCA 0x1014 40 #define BTIF_HL_DATA_TYPE_PEAK_FLOW 0x1015 41 #define BTIF_HL_DATA_TYPE_CARDIO 0x1029 42 #define BTIF_HL_DATA_TYPE_ACTIVITY_HUB 0x1047 43 #define BTIF_HL_DATA_TYPE_AMM 0x1048 44 45 #define BTIF_HL_CCH_NUM_FILTER_ELEMS 3 46 #define BTIF_HL_APPLICATION_NAME_LEN 512 47 48 /******************************************************************************* 49 ** Type definitions and return values 50 ********************************************************************************/ 51 52 typedef enum 53 { 54 BTIF_HL_SOC_STATE_IDLE, 55 BTIF_HL_SOC_STATE_W4_ADD, 56 BTIF_HL_SOC_STATE_W4_CONN, 57 BTIF_HL_SOC_STATE_W4_READ, 58 BTIF_HL_SOC_STATE_W4_REL 59 } btif_hl_soc_state_t; 60 61 typedef enum 62 { 63 BTIF_HL_STATE_DISABLED, 64 BTIF_HL_STATE_DISABLING, 65 BTIF_HL_STATE_ENABLED, 66 BTIF_HL_STATE_ENABLING, 67 } btif_hl_state_t; 68 69 typedef enum 70 { 71 BTIF_HL_CCH_OP_NONE, 72 BTIF_HL_CCH_OP_MDEP_FILTERING, 73 BTIF_HL_CCH_OP_MATCHED_CTRL_PSM, 74 BTIF_HL_CCH_OP_DCH_OPEN, 75 BTIF_HL_CCH_OP_DCH_RECONNECT, 76 BTIF_HL_CCH_OP_DCH_ECHO_TEST 77 } btif_hl_cch_op_t; 78 79 typedef enum 80 { 81 BTIF_HL_PEND_DCH_OP_NONE, 82 BTIF_HL_PEND_DCH_OP_DELETE_MDL, 83 BTIF_HL_PEND_DCH_OP_OPEN, 84 BTIF_HL_PEND_DCH_OP_RECONNECT 85 } btif_hl_pend_dch_op_t; 86 87 typedef enum 88 { 89 BTIF_HL_DCH_OP_NONE, 90 BTIF_HL_DCH_OP_DISC 91 } btif_hl_dch_op_t; 92 93 typedef enum 94 { 95 BTIF_HL_CHAN_CB_STATE_NONE, 96 BTIF_HL_CHAN_CB_STATE_CONNECTING_PENDING, 97 BTIF_HL_CHAN_CB_STATE_CONNECTED_PENDING, 98 99 BTIF_HL_CHAN_CB_STATE_DISCONNECTING_PENDING, 100 BTIF_HL_CHAN_CB_STATE_DISCONNECTED_PENDING, 101 BTIF_HL_CHAN_CB_STATE_DESTROYED_PENDING, 102 } btif_hl_chan_cb_state_t; 103 104 enum 105 { 106 BTIF_HL_SEND_CONNECTED_CB, 107 BTIF_HL_SEND_DISCONNECTED_CB, 108 BTIF_HL_REG_APP, 109 BTIF_HL_UNREG_APP, 110 BTIF_HL_UPDATE_MDL, 111 }; 112 113 typedef struct 114 { 115 UINT8 mdep_cfg_idx; 116 int data_type; 117 tBTA_HL_MDEP_ID peer_mdep_id; 118 } btif_hl_extra_mdl_cfg_t; 119 120 typedef struct 121 { 122 tBTA_HL_MDL_CFG base; 123 btif_hl_extra_mdl_cfg_t extra; 124 } btif_hl_mdl_cfg_t; 125 126 typedef struct 127 { 128 BOOLEAN active; 129 UINT8 app_idx; 130 } btif_hl_app_data_t; 131 132 typedef struct 133 { 134 int channel_id; 135 BD_ADDR bd_addr; 136 UINT8 mdep_cfg_idx; 137 int max_s; 138 int socket_id[2]; 139 UINT8 app_idx; 140 UINT8 mcl_idx; 141 UINT8 mdl_idx; 142 btif_hl_soc_state_t state; 143 }btif_hl_soc_cb_t; 144 145 typedef struct 146 { 147 UINT16 data_type; 148 UINT16 max_tx_apdu_size; 149 UINT16 max_rx_apdu_size; 150 } btif_hl_data_type_cfg_t; 151 152 typedef struct 153 { 154 UINT16 data_type; 155 tBTA_HL_MDEP_ROLE peer_mdep_role; 156 } btif_hl_filter_elem_t; 157 158 typedef struct 159 { 160 UINT8 num_elems; 161 btif_hl_filter_elem_t elem[BTIF_HL_CCH_NUM_FILTER_ELEMS]; 162 } btif_hl_cch_filter_t; 163 164 typedef struct 165 { 166 BOOLEAN in_use; 167 UINT16 mdl_id; 168 tBTA_HL_MDL_HANDLE mdl_handle; 169 btif_hl_dch_op_t dch_oper; 170 tBTA_HL_MDEP_ID local_mdep_id; 171 UINT8 local_mdep_cfg_idx; 172 tBTA_HL_DCH_CFG local_cfg; 173 tBTA_HL_MDEP_ID peer_mdep_id; 174 UINT16 peer_data_type; 175 tBTA_HL_MDEP_ROLE peer_mdep_role; 176 tBTA_HL_DCH_MODE dch_mode; 177 tBTA_SEC sec_mask; 178 BOOLEAN is_the_first_reliable; 179 BOOLEAN delete_mdl; 180 UINT16 mtu; 181 tMCA_CHNL_CFG chnl_cfg; 182 UINT16 tx_size; 183 UINT8 *p_tx_pkt; 184 UINT8 *p_rx_pkt; 185 BOOLEAN cong; 186 btif_hl_soc_cb_t *p_scb; 187 int channel_id; 188 } btif_hl_mdl_cb_t; 189 190 typedef struct 191 { 192 int channel_id; 193 int mdep_cfg_idx; 194 BOOLEAN in_use; 195 btif_hl_chan_cb_state_t cb_state; 196 btif_hl_pend_dch_op_t op; 197 BD_ADDR bd_addr; 198 BOOLEAN abort_pending; 199 } btif_hl_pending_chan_cb_t; 200 201 typedef struct 202 { 203 btif_hl_mdl_cb_t mdl[BTA_HL_NUM_MDLS_PER_MCL]; 204 BOOLEAN in_use; 205 BOOLEAN is_connected; 206 UINT16 req_ctrl_psm; 207 UINT16 ctrl_psm; 208 UINT16 data_psm; 209 BD_ADDR bd_addr; 210 UINT16 cch_mtu; 211 tBTA_SEC sec_mask; 212 tBTA_HL_MCL_HANDLE mcl_handle; 213 btif_hl_pending_chan_cb_t pcb; 214 BOOLEAN valid_sdp_idx; 215 UINT8 sdp_idx; 216 tBTA_HL_SDP sdp; 217 btif_hl_cch_op_t cch_oper; 218 alarm_t *cch_timer; 219 } btif_hl_mcl_cb_t; 220 221 typedef struct 222 { 223 BOOLEAN active; 224 UINT16 mdl_id; 225 UINT8 mdep_cfg_idx; 226 BD_ADDR bd_addr; 227 int channel_id; 228 } btif_hl_delete_mdl_t; 229 230 typedef struct 231 { 232 btif_hl_mcl_cb_t mcb[BTA_HL_NUM_MCLS]; /* application Control Blocks */ 233 BOOLEAN in_use; /* this CB is in use*/ 234 BOOLEAN reg_pending; 235 UINT8 app_id; 236 237 tBTA_HL_SUP_FEATURE sup_feature; 238 tBTA_HL_DCH_CFG channel_type[BTA_HL_NUM_MDEPS]; 239 tBTA_HL_SDP_INFO_IND sdp_info_ind; 240 btif_hl_cch_filter_t filter; 241 242 btif_hl_mdl_cfg_t mdl_cfg[BTA_HL_NUM_MDL_CFGS]; 243 int mdl_cfg_channel_id[BTA_HL_NUM_MDL_CFGS]; 244 245 btif_hl_delete_mdl_t delete_mdl; 246 tBTA_HL_DEVICE_TYPE dev_type; 247 tBTA_HL_APP_HANDLE app_handle; 248 UINT16 sec_mask; /* Security mask for BTM_SetSecurityLevel() */ 249 char srv_name[BTA_SERVICE_NAME_LEN +1]; /* service name to be used in the SDP; null terminated*/ 250 char srv_desp[BTA_SERVICE_DESP_LEN +1]; /* service description to be used in the SDP; null terminated */ 251 char provider_name[BTA_PROVIDER_NAME_LEN +1]; /* provide name to be used in the SDP; null terminated */ 252 char application_name[BTIF_HL_APPLICATION_NAME_LEN +1]; /* applicaiton name */ 253 } btif_hl_app_cb_t; 254 255 typedef struct 256 { 257 BOOLEAN in_use; 258 UINT8 app_idx; 259 } btif_hl_pending_reg_cb_t; 260 261 /* BTIF-HL control block */ 262 typedef struct 263 { 264 btif_hl_app_cb_t acb[BTA_HL_NUM_APPS]; /* HL Control Blocks */ 265 tBTA_HL_CTRL_CBACK *p_ctrl_cback; /* pointer to control callback function */ 266 UINT8 next_app_id; 267 UINT16 next_channel_id; 268 btif_hl_state_t state; 269 } btif_hl_cb_t; 270 271 typedef UINT8 btif_hl_evt_t; 272 273 typedef struct 274 { 275 int app_id; 276 BD_ADDR bd_addr; 277 int mdep_cfg_index; 278 int channel_id; 279 btif_hl_chan_cb_state_t cb_state; 280 int fd; 281 } btif_hl_send_chan_state_cb_t; 282 283 typedef struct 284 { 285 UINT8 app_idx; 286 } btif_hl_reg_t; 287 288 typedef btif_hl_reg_t btif_hl_unreg_t; 289 typedef btif_hl_reg_t btif_hl_update_mdl_t; 290 291 typedef union 292 { 293 btif_hl_send_chan_state_cb_t chan_cb; 294 btif_hl_reg_t reg; 295 btif_hl_unreg_t unreg; 296 btif_hl_update_mdl_t update_mdl; 297 } btif_hl_evt_cb_t; 298 299 /******************************************************************************* 300 ** Functions 301 ********************************************************************************/ 302 303 #define BTIF_HL_GET_CB_PTR() &(btif_hl_cb) 304 #define BTIF_HL_GET_APP_CB_PTR(app_idx) &(btif_hl_cb.acb[(app_idx)]) 305 #define BTIF_HL_GET_MCL_CB_PTR(app_idx, mcl_idx) &(btif_hl_cb.acb[(app_idx)].mcb[(mcl_idx)]) 306 #define BTIF_HL_GET_MDL_CB_PTR(app_idx, mcl_idx, mdl_idx) &(btif_hl_cb.acb[(app_idx)].mcb[(mcl_idx)].mdl[mdl_idx]) 307 #define BTIF_HL_GET_PCB_PTR(app_idx, mcl_idx) &(btif_hl_cb.acb[app_idx].mcb[mcl_idx].pcb) 308 #define BTIF_HL_GET_MDL_CFG_PTR(app_idx, item_idx) &(btif_hl_cb.acb[(app_idx)].mdl_cfg[(item_idx)]) 309 #define BTIF_HL_GET_MDL_CFG_CHANNEL_ID_PTR(app_idx, item_idx) &(btif_hl_cb.acb[(app_idx)].mdl_cfg_channel_id[(item_idx)]) 310 311 extern btif_hl_cb_t btif_hl_cb; 312 extern btif_hl_cb_t *p_btif_hl_cb; 313 314 extern BOOLEAN btif_hl_find_mcl_idx(UINT8 app_idx, BD_ADDR p_bd_addr, UINT8 *p_mcl_idx); 315 extern BOOLEAN btif_hl_find_app_idx(UINT8 app_id, UINT8 *p_app_idx); 316 extern BOOLEAN btif_hl_find_avail_mcl_idx(UINT8 app_idx, UINT8 *p_mcl_idx); 317 extern BOOLEAN btif_hl_find_avail_mdl_idx(UINT8 app_idx, UINT8 mcl_idx, 318 UINT8 *p_mdl_idx); 319 extern BOOLEAN btif_hl_find_mcl_idx_using_handle( tBTA_HL_MCL_HANDLE mcl_handle, 320 UINT8 *p_app_idx, UINT8 *p_mcl_idx); 321 extern BOOLEAN btif_hl_save_mdl_cfg(UINT8 app_id, UINT8 item_idx, tBTA_HL_MDL_CFG *p_mdl_cfg); 322 extern BOOLEAN btif_hl_delete_mdl_cfg(UINT8 app_id, UINT8 item_idx); 323 extern BOOLEAN btif_hl_find_mdl_idx_using_handle(tBTA_HL_MDL_HANDLE mdl_handle, 324 UINT8 *p_app_idx,UINT8 *p_mcl_idx, 325 UINT8 *p_mdl_idx); 326 extern void btif_hl_abort_pending_chan_setup(UINT8 app_idx, UINT8 mcl_idx); 327 extern BOOLEAN btif_hl_proc_pending_op(UINT8 app_idx, UINT8 mcl_idx); 328 extern BOOLEAN btif_hl_load_mdl_config (UINT8 app_id, UINT8 buffer_size, 329 tBTA_HL_MDL_CFG *p_mdl_buf ); 330 #endif 331