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