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