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