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