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