Home | History | Annotate | Download | only in jv
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2006-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 private interface file for the BTA Java I/F
     22  *
     23  ******************************************************************************/
     24 #ifndef BTA_JV_INT_H
     25 #define BTA_JV_INT_H
     26 
     27 #include "bta_sys.h"
     28 #include "bta_api.h"
     29 #include "bta_jv_api.h"
     30 #include "rfcdefs.h"
     31 #include "port_api.h"
     32 
     33 /*****************************************************************************
     34 **  Constants
     35 *****************************************************************************/
     36 
     37 enum
     38 {
     39     /* these events are handled by the state machine */
     40     BTA_JV_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_JV),
     41     BTA_JV_API_DISABLE_EVT,
     42     BTA_JV_API_GET_CHANNEL_EVT,
     43     BTA_JV_API_FREE_SCN_EVT,
     44     BTA_JV_API_START_DISCOVERY_EVT,
     45     BTA_JV_API_CREATE_RECORD_EVT,
     46     BTA_JV_API_DELETE_RECORD_EVT,
     47     BTA_JV_API_L2CAP_CONNECT_EVT,
     48     BTA_JV_API_L2CAP_CLOSE_EVT,
     49     BTA_JV_API_L2CAP_START_SERVER_EVT,
     50     BTA_JV_API_L2CAP_STOP_SERVER_EVT,
     51     BTA_JV_API_L2CAP_READ_EVT,
     52     BTA_JV_API_L2CAP_WRITE_EVT,
     53     BTA_JV_API_RFCOMM_CONNECT_EVT,
     54     BTA_JV_API_RFCOMM_CLOSE_EVT,
     55     BTA_JV_API_RFCOMM_START_SERVER_EVT,
     56     BTA_JV_API_RFCOMM_STOP_SERVER_EVT,
     57     BTA_JV_API_RFCOMM_READ_EVT,
     58     BTA_JV_API_RFCOMM_WRITE_EVT,
     59     BTA_JV_API_SET_PM_PROFILE_EVT,
     60     BTA_JV_API_PM_STATE_CHANGE_EVT,
     61     BTA_JV_API_L2CAP_CONNECT_LE_EVT,
     62     BTA_JV_API_L2CAP_START_SERVER_LE_EVT,
     63     BTA_JV_API_L2CAP_STOP_SERVER_LE_EVT,
     64     BTA_JV_API_L2CAP_WRITE_FIXED_EVT,
     65     BTA_JV_API_L2CAP_CLOSE_FIXED_EVT,
     66     BTA_JV_MAX_INT_EVT
     67 };
     68 
     69 #ifndef BTA_JV_RFC_EV_MASK
     70 #define BTA_JV_RFC_EV_MASK (PORT_EV_RXCHAR | PORT_EV_TXEMPTY | PORT_EV_FC | PORT_EV_FCS)
     71 #endif
     72 
     73 /* data type for BTA_JV_API_ENABLE_EVT */
     74 typedef struct
     75 {
     76     BT_HDR          hdr;
     77     tBTA_JV_DM_CBACK   *p_cback;
     78 } tBTA_JV_API_ENABLE;
     79 
     80 /* data type for BTA_JV_API_START_DISCOVERY_EVT */
     81 typedef struct
     82 {
     83     BT_HDR      hdr;
     84     BD_ADDR bd_addr;
     85     UINT16 num_uuid;
     86     tSDP_UUID uuid_list[BTA_JV_MAX_UUIDS];
     87     UINT16 num_attr;
     88     UINT16 attr_list[BTA_JV_MAX_ATTRS];
     89     void            *user_data;      /* piggyback caller's private data*/
     90 } tBTA_JV_API_START_DISCOVERY;
     91 
     92 enum
     93 {
     94     BTA_JV_PM_FREE_ST = 0, /* empty PM slot */
     95     BTA_JV_PM_IDLE_ST,
     96     BTA_JV_PM_BUSY_ST
     97 };
     98 
     99 /* BTA JV PM control block */
    100 typedef struct
    101 {
    102     UINT32          handle;     /* The connection handle */
    103     UINT8           state;      /* state: see above enum */
    104     tBTA_JV_PM_ID   app_id;     /* JV app specific id indicating power table to use */
    105     BD_ADDR         peer_bd_addr;    /* Peer BD address */
    106 } tBTA_JV_PM_CB;
    107 
    108 enum
    109 {
    110     BTA_JV_ST_NONE = 0,
    111     BTA_JV_ST_CL_OPENING,
    112     BTA_JV_ST_CL_OPEN,
    113     BTA_JV_ST_CL_CLOSING,
    114     BTA_JV_ST_SR_LISTEN,
    115     BTA_JV_ST_SR_OPEN,
    116     BTA_JV_ST_SR_CLOSING
    117 } ;
    118 typedef UINT8  tBTA_JV_STATE;
    119 #define BTA_JV_ST_CL_MAX    BTA_JV_ST_CL_CLOSING
    120 /* JV L2CAP control block */
    121 typedef struct
    122 {
    123     tBTA_JV_L2CAP_CBACK *p_cback;   /* the callback function */
    124     UINT16              psm;        /* the psm used for this server connection */
    125     tBTA_JV_STATE       state;      /* the state of this control block */
    126     tBTA_SERVICE_ID     sec_id;     /* service id */
    127     UINT32              handle;     /* the handle reported to java app (same as gap handle) */
    128     BOOLEAN             cong;       /* TRUE, if congested */
    129     tBTA_JV_PM_CB      *p_pm_cb;    /* ptr to pm control block, NULL: unused */
    130     void                *user_data; /* user data for callback from higher layers */
    131 } tBTA_JV_L2C_CB;
    132 
    133 #define BTA_JV_RFC_HDL_MASK         0xFF
    134 #define BTA_JV_RFCOMM_MASK          0x80
    135 #define BTA_JV_ALL_APP_ID           0xFF
    136 #define BTA_JV_RFC_HDL_TO_SIDX(r)   (((r)&0xFF00) >> 8)
    137 #define BTA_JV_RFC_H_S_TO_HDL(h, s) ((h)|(s<<8))
    138 
    139 /* port control block */
    140 typedef struct
    141 {
    142     UINT32              handle;     /* the rfcomm session handle at jv */
    143     UINT16              port_handle;/* port handle */
    144     tBTA_JV_STATE       state;      /* the state of this control block */
    145     UINT8               max_sess;   /* max sessions */
    146     void                *user_data; /* piggyback caller's private data*/
    147     BOOLEAN             cong;       /* TRUE, if congested */
    148     tBTA_JV_PM_CB       *p_pm_cb;   /* ptr to pm control block, NULL: unused */
    149 } tBTA_JV_PCB;
    150 
    151 /* JV RFCOMM control block */
    152 typedef struct
    153 {
    154     tBTA_JV_RFCOMM_CBACK *p_cback;  /* the callback function */
    155     UINT16              rfc_hdl[BTA_JV_MAX_RFC_SR_SESSION];
    156     tBTA_SERVICE_ID     sec_id;     /* service id */
    157     UINT8               handle;     /* index: the handle reported to java app */
    158     UINT8               scn;        /* the scn of the server */
    159     UINT8               max_sess;   /* max sessions */
    160     int                 curr_sess;   /* current sessions count*/
    161 } tBTA_JV_RFC_CB;
    162 
    163 /* data type for BTA_JV_API_L2CAP_CONNECT_EVT & BTA_JV_API_L2CAP_CONNECT_LE_EVT */
    164 typedef struct
    165 {
    166     BT_HDR              hdr;
    167     tBTA_SEC            sec_mask;
    168     tBTA_JV_ROLE        role;
    169     union {
    170         UINT16          remote_psm;
    171         UINT16          remote_chan;
    172     };
    173     UINT16              rx_mtu;
    174     BD_ADDR             peer_bd_addr;
    175     INT32               has_cfg;
    176     tL2CAP_CFG_INFO     cfg;
    177     INT32               has_ertm_info;
    178     tL2CAP_ERTM_INFO    ertm_info;
    179     tBTA_JV_L2CAP_CBACK *p_cback;
    180     void                *user_data;
    181 } tBTA_JV_API_L2CAP_CONNECT;
    182 
    183 /* data type for BTA_JV_API_L2CAP_SERVER_EVT */
    184 typedef struct
    185 {
    186     BT_HDR              hdr;
    187     tBTA_SEC            sec_mask;
    188     tBTA_JV_ROLE        role;
    189     union {
    190         UINT16          local_psm;
    191         UINT16          local_chan;
    192     };
    193     UINT16              rx_mtu;
    194     INT32               has_cfg;
    195     tL2CAP_CFG_INFO     cfg;
    196     INT32               has_ertm_info;
    197     tL2CAP_ERTM_INFO    ertm_info;
    198     tBTA_JV_L2CAP_CBACK *p_cback;
    199     void                *user_data;
    200 } tBTA_JV_API_L2CAP_SERVER;
    201 
    202 /* data type for BTA_JV_API_L2CAP_CLOSE_EVT */
    203 typedef struct
    204 {
    205     BT_HDR          hdr;
    206     UINT32          handle;
    207     tBTA_JV_L2C_CB  *p_cb;
    208 } tBTA_JV_API_L2CAP_CLOSE;
    209 
    210 /* data type for BTA_JV_API_L2CAP_READ_EVT */
    211 typedef struct
    212 {
    213     BT_HDR              hdr;
    214     UINT32              handle;
    215     UINT32              req_id;
    216     tBTA_JV_L2CAP_CBACK *p_cback;
    217     UINT8*              p_data;
    218     UINT16              len;
    219     void                *user_data;
    220 } tBTA_JV_API_L2CAP_READ;
    221 
    222 /* data type for BTA_JV_API_L2CAP_WRITE_EVT */
    223 typedef struct
    224 {
    225     BT_HDR              hdr;
    226     UINT32              handle;
    227     UINT32              req_id;
    228     tBTA_JV_L2C_CB      *p_cb;
    229     UINT8               *p_data;
    230     UINT16              len;
    231     void                *user_data;
    232 } tBTA_JV_API_L2CAP_WRITE;
    233 
    234 /* data type for BTA_JV_API_L2CAP_WRITE_FIXED_EVT */
    235 typedef struct
    236 {
    237     BT_HDR              hdr;
    238     UINT16              channel;
    239     BD_ADDR             addr;
    240     UINT32              req_id;
    241     tBTA_JV_L2CAP_CBACK *p_cback;
    242     UINT8               *p_data;
    243     UINT16              len;
    244     void                *user_data;
    245 } tBTA_JV_API_L2CAP_WRITE_FIXED;
    246 
    247 /* data type for BTA_JV_API_RFCOMM_CONNECT_EVT */
    248 typedef struct
    249 {
    250     BT_HDR          hdr;
    251     tBTA_SEC        sec_mask;
    252     tBTA_JV_ROLE    role;
    253     UINT8           remote_scn;
    254     BD_ADDR         peer_bd_addr;
    255     tBTA_JV_RFCOMM_CBACK *p_cback;
    256     void            *user_data;
    257 } tBTA_JV_API_RFCOMM_CONNECT;
    258 
    259 /* data type for BTA_JV_API_RFCOMM_SERVER_EVT */
    260 typedef struct
    261 {
    262     BT_HDR          hdr;
    263     tBTA_SEC        sec_mask;
    264     tBTA_JV_ROLE    role;
    265     UINT8           local_scn;
    266     UINT8           max_session;
    267     UINT32          handle;
    268     tBTA_JV_RFCOMM_CBACK *p_cback;
    269     void            *user_data;
    270 } tBTA_JV_API_RFCOMM_SERVER;
    271 
    272 /* data type for BTA_JV_API_RFCOMM_READ_EVT */
    273 typedef struct
    274 {
    275     BT_HDR          hdr;
    276     UINT32          handle;
    277     UINT32          req_id;
    278     UINT8           *p_data;
    279     UINT16          len;
    280     tBTA_JV_RFC_CB  *p_cb;
    281     tBTA_JV_PCB     *p_pcb;
    282 } tBTA_JV_API_RFCOMM_READ;
    283 
    284 /* data type for BTA_JV_API_SET_PM_PROFILE_EVT */
    285 typedef struct
    286 {
    287     BT_HDR              hdr;
    288     UINT32              handle;
    289     tBTA_JV_PM_ID       app_id;
    290     tBTA_JV_CONN_STATE  init_st;
    291 } tBTA_JV_API_SET_PM_PROFILE;
    292 
    293 /* data type for BTA_JV_API_PM_STATE_CHANGE_EVT */
    294 typedef struct
    295 {
    296     BT_HDR              hdr;
    297     tBTA_JV_PM_CB       *p_cb;
    298     tBTA_JV_CONN_STATE  state;
    299 } tBTA_JV_API_PM_STATE_CHANGE;
    300 
    301 /* data type for BTA_JV_API_RFCOMM_WRITE_EVT */
    302 typedef struct
    303 {
    304     BT_HDR          hdr;
    305     UINT32          handle;
    306     UINT32          req_id;
    307     UINT8           *p_data;
    308     int             len;
    309     tBTA_JV_RFC_CB  *p_cb;
    310     tBTA_JV_PCB     *p_pcb;
    311 } tBTA_JV_API_RFCOMM_WRITE;
    312 
    313 /* data type for BTA_JV_API_RFCOMM_CLOSE_EVT */
    314 typedef struct
    315 {
    316     BT_HDR          hdr;
    317     UINT32          handle;
    318     tBTA_JV_RFC_CB  *p_cb;
    319     tBTA_JV_PCB     *p_pcb;
    320     void            *user_data;
    321 } tBTA_JV_API_RFCOMM_CLOSE;
    322 
    323 /* data type for BTA_JV_API_CREATE_RECORD_EVT */
    324 typedef struct
    325 {
    326     BT_HDR      hdr;
    327     void        *user_data;
    328 } tBTA_JV_API_CREATE_RECORD;
    329 
    330 /* data type for BTA_JV_API_ADD_ATTRIBUTE_EVT */
    331 typedef struct
    332 {
    333     BT_HDR      hdr;
    334     UINT32      handle;
    335     UINT16      attr_id;
    336     UINT8       *p_value;
    337     INT32       value_size;
    338 } tBTA_JV_API_ADD_ATTRIBUTE;
    339 
    340 /* data type for BTA_JV_API_FREE_SCN_EVT */
    341 typedef struct
    342 {
    343     BT_HDR      hdr;
    344     INT32       type;       /* One of BTA_JV_CONN_TYPE_ */
    345     UINT16      scn;
    346 } tBTA_JV_API_FREE_CHANNEL;
    347 
    348 /* data type for BTA_JV_API_ALLOC_CHANNEL_EVT */
    349 typedef struct
    350 {
    351     BT_HDR      hdr;
    352     INT32       type;       /* One of BTA_JV_CONN_TYPE_ */
    353     INT32       channel;    /* optionally request a specific channel */
    354     void        *user_data;
    355 } tBTA_JV_API_ALLOC_CHANNEL;
    356 /* union of all data types */
    357 typedef union
    358 {
    359     /* GKI event buffer header */
    360     BT_HDR                          hdr;
    361     tBTA_JV_API_ENABLE              enable;
    362     tBTA_JV_API_START_DISCOVERY     start_discovery;
    363     tBTA_JV_API_ALLOC_CHANNEL       alloc_channel;
    364     tBTA_JV_API_FREE_CHANNEL        free_channel;
    365     tBTA_JV_API_CREATE_RECORD       create_record;
    366     tBTA_JV_API_ADD_ATTRIBUTE       add_attr;
    367     tBTA_JV_API_L2CAP_CONNECT       l2cap_connect;
    368     tBTA_JV_API_L2CAP_READ          l2cap_read;
    369     tBTA_JV_API_L2CAP_WRITE         l2cap_write;
    370     tBTA_JV_API_L2CAP_CLOSE         l2cap_close;
    371     tBTA_JV_API_L2CAP_SERVER        l2cap_server;
    372     tBTA_JV_API_RFCOMM_CONNECT      rfcomm_connect;
    373     tBTA_JV_API_RFCOMM_READ         rfcomm_read;
    374     tBTA_JV_API_RFCOMM_WRITE        rfcomm_write;
    375     tBTA_JV_API_SET_PM_PROFILE      set_pm;
    376     tBTA_JV_API_PM_STATE_CHANGE     change_pm_state;
    377     tBTA_JV_API_RFCOMM_CLOSE        rfcomm_close;
    378     tBTA_JV_API_RFCOMM_SERVER       rfcomm_server;
    379     tBTA_JV_API_L2CAP_WRITE_FIXED   l2cap_write_fixed;
    380 } tBTA_JV_MSG;
    381 
    382 /* JV control block */
    383 typedef struct
    384 {
    385     /* the SDP handle reported to JV user is the (index + 1) to sdp_handle[].
    386      * if sdp_handle[i]==0, it's not used.
    387      * otherwise sdp_handle[i] is the stack SDP handle. */
    388     UINT32                  sdp_handle[BTA_JV_MAX_SDP_REC]; /* SDP records created */
    389     UINT8                   *p_sel_raw_data;/* the raw data of last service select */
    390     tBTA_JV_DM_CBACK        *p_dm_cback;
    391     tBTA_JV_L2C_CB          l2c_cb[BTA_JV_MAX_L2C_CONN];    /* index is GAP handle (index) */
    392     tBTA_JV_RFC_CB          rfc_cb[BTA_JV_MAX_RFC_CONN];
    393     tBTA_JV_PCB             port_cb[MAX_RFC_PORTS];         /* index of this array is
    394                                                                the port_handle, */
    395     UINT8                   sec_id[BTA_JV_NUM_SERVICE_ID];  /* service ID */
    396     BOOLEAN                 scn[BTA_JV_MAX_SCN];            /* SCN allocated by java */
    397     UINT16                  free_psm_list[BTA_JV_MAX_L2C_CONN];  /* PSMs freed by java
    398                                                                     (can be reused) */
    399     UINT8                   sdp_active;                     /* see BTA_JV_SDP_ACT_* */
    400     tSDP_UUID               uuid;                           /* current uuid of sdp discovery*/
    401     tBTA_JV_PM_CB           pm_cb[BTA_JV_PM_MAX_NUM];       /* PM on a per JV handle bases */
    402 } tBTA_JV_CB;
    403 
    404 enum
    405 {
    406     BTA_JV_SDP_ACT_NONE = 0,
    407     BTA_JV_SDP_ACT_YES,     /* waiting for SDP result */
    408     BTA_JV_SDP_ACT_CANCEL   /* waiting for cancel complete */
    409 };
    410 
    411 /* JV control block */
    412 #if BTA_DYNAMIC_MEMORY == FALSE
    413 extern tBTA_JV_CB bta_jv_cb;
    414 #else
    415 extern tBTA_JV_CB *bta_jv_cb_ptr;
    416 #define bta_jv_cb (*bta_jv_cb_ptr)
    417 #endif
    418 
    419 /* config struct */
    420 extern tBTA_JV_CFG *p_bta_jv_cfg;
    421 
    422 extern BOOLEAN bta_jv_sm_execute(BT_HDR *p_msg);
    423 
    424 extern void bta_jv_enable (tBTA_JV_MSG *p_data);
    425 extern void bta_jv_disable (tBTA_JV_MSG *p_data);
    426 extern void bta_jv_get_channel_id (tBTA_JV_MSG *p_data);
    427 extern void bta_jv_free_scn (tBTA_JV_MSG *p_data);
    428 extern void bta_jv_start_discovery (tBTA_JV_MSG *p_data);
    429 extern void bta_jv_create_record (tBTA_JV_MSG *p_data);
    430 extern void bta_jv_delete_record (tBTA_JV_MSG *p_data);
    431 extern void bta_jv_l2cap_connect (tBTA_JV_MSG *p_data);
    432 extern void bta_jv_l2cap_close (tBTA_JV_MSG *p_data);
    433 extern void bta_jv_l2cap_start_server (tBTA_JV_MSG *p_data);
    434 extern void bta_jv_l2cap_stop_server (tBTA_JV_MSG *p_data);
    435 extern void bta_jv_l2cap_read (tBTA_JV_MSG *p_data);
    436 extern void bta_jv_l2cap_write (tBTA_JV_MSG *p_data);
    437 extern void bta_jv_rfcomm_connect (tBTA_JV_MSG *p_data);
    438 extern void bta_jv_rfcomm_close (tBTA_JV_MSG *p_data);
    439 extern void bta_jv_rfcomm_start_server (tBTA_JV_MSG *p_data);
    440 extern void bta_jv_rfcomm_stop_server (tBTA_JV_MSG *p_data);
    441 extern void bta_jv_rfcomm_read (tBTA_JV_MSG *p_data);
    442 extern void bta_jv_rfcomm_write (tBTA_JV_MSG *p_data);
    443 extern void bta_jv_set_pm_profile (tBTA_JV_MSG *p_data);
    444 extern void bta_jv_change_pm_state(tBTA_JV_MSG *p_data);
    445 extern void bta_jv_l2cap_connect_le (tBTA_JV_MSG *p_data);
    446 extern void bta_jv_l2cap_start_server_le (tBTA_JV_MSG *p_data);
    447 extern void bta_jv_l2cap_stop_server_le (tBTA_JV_MSG *p_data);
    448 extern void bta_jv_l2cap_write_fixed (tBTA_JV_MSG *p_data);
    449 extern void bta_jv_l2cap_close_fixed (tBTA_JV_MSG *p_data);
    450 
    451 #endif /* BTA_JV_INT_H */
    452