bta_jv_api.c revision 9ac641d0a674333af57b85b367e64cf94dfae291
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 implementation of the JAVA API for Bluetooth Wireless 22 * Technology (JABWT) as specified by the JSR82 specificiation 23 * 24 ******************************************************************************/ 25 26#include "bta_api.h" 27#include "bd.h" 28#include "bta_sys.h" 29#include "bta_jv_api.h" 30#include "bta_jv_int.h" 31#include "gki.h" 32#include <string.h> 33#include "port_api.h" 34#include "sdp_api.h" 35 36/***************************************************************************** 37** Constants 38*****************************************************************************/ 39 40static const tBTA_SYS_REG bta_jv_reg = 41{ 42 bta_jv_sm_execute, 43 NULL 44}; 45 46/******************************************************************************* 47** 48** Function BTA_JvEnable 49** 50** Description Enable the Java I/F service. When the enable 51** operation is complete the callback function will be 52** called with a BTA_JV_ENABLE_EVT. This function must 53** be called before other function in the JV API are 54** called. 55** 56** Returns BTA_JV_SUCCESS if successful. 57** BTA_JV_FAIL if internal failure. 58** 59*******************************************************************************/ 60tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK *p_cback) 61{ 62 tBTA_JV_STATUS status = BTA_JV_FAILURE; 63 tBTA_JV_API_ENABLE *p_buf; 64 65 APPL_TRACE_API0( "BTA_JvEnable"); 66 if(p_cback && FALSE == bta_sys_is_register(BTA_ID_JV)) 67 { 68 memset(&bta_jv_cb, 0, sizeof(tBTA_JV_CB)); 69 70 /* register with BTA system manager */ 71 GKI_sched_lock(); 72 bta_sys_register(BTA_ID_JV, &bta_jv_reg); 73 GKI_sched_unlock(); 74 75 if (p_cback && (p_buf = (tBTA_JV_API_ENABLE *) GKI_getbuf(sizeof(tBTA_JV_API_ENABLE))) != NULL) 76 { 77 p_buf->hdr.event = BTA_JV_API_ENABLE_EVT; 78 p_buf->p_cback = p_cback; 79 bta_sys_sendmsg(p_buf); 80 status = BTA_JV_SUCCESS; 81 } 82 } 83 return(status); 84} 85 86/******************************************************************************* 87** 88** Function BTA_JvDisable 89** 90** Description Disable the Java I/F 91** 92** Returns void 93** 94*******************************************************************************/ 95void BTA_JvDisable(void) 96{ 97 BT_HDR *p_buf; 98 99 APPL_TRACE_API0( "BTA_JvDisable"); 100 bta_sys_deregister(BTA_ID_JV); 101 if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL) 102 { 103 p_buf->event = BTA_JV_API_DISABLE_EVT; 104 bta_sys_sendmsg(p_buf); 105 } 106} 107 108/******************************************************************************* 109** 110** Function BTA_JvIsEnable 111** 112** Description Get the JV registration status. 113** 114** Returns TRUE, if registered 115** 116*******************************************************************************/ 117BOOLEAN BTA_JvIsEnable(void) 118{ 119 return bta_sys_is_register(BTA_ID_JV); 120} 121 122/******************************************************************************* 123** 124** Function BTA_JvSetDiscoverability 125** 126** Description This function sets the Bluetooth discoverable modes 127** of the local device. This controls whether other 128** Bluetooth devices can find the local device. 129** 130** When the operation is complete the tBTA_JV_DM_CBACK callback 131** function will be called with a BTA_JV_SET_DISCOVER_EVT. 132** 133** Returns BTA_JV_SUCCESS if successful. 134** BTA_JV_FAIL if internal failure. 135** 136*******************************************************************************/ 137tBTA_JV_STATUS BTA_JvSetDiscoverability(tBTA_JV_DISC disc_mode) 138{ 139 tBTA_JV_STATUS status = BTA_JV_FAILURE; 140 tBTA_JV_API_SET_DISCOVERABILITY *p_msg; 141 142 APPL_TRACE_API0( "BTA_JvSetDiscoverability"); 143 if ((p_msg = (tBTA_JV_API_SET_DISCOVERABILITY *)GKI_getbuf(sizeof(tBTA_JV_MSG))) != NULL) 144 { 145 p_msg->hdr.event = BTA_JV_API_SET_DISCOVERABILITY_EVT; 146 p_msg->disc_mode = disc_mode; 147 bta_sys_sendmsg(p_msg); 148 status = BTA_JV_SUCCESS; 149 } 150 151 return(status); 152} 153 154/******************************************************************************* 155** 156** Function BTA_JvGetDiscoverability 157** 158** Description This function gets the Bluetooth 159** discoverable modes of local device 160** 161** Returns The current Bluetooth discoverable mode. 162** 163*******************************************************************************/ 164tBTA_JV_DISC BTA_JvGetDiscoverability(void) 165{ 166 APPL_TRACE_API0( "BTA_JvGetDiscoverability"); 167 return BTM_ReadDiscoverability(0, 0); 168} 169 170/******************************************************************************* 171** 172** Function BTA_JvGetLocalDeviceAddr 173** 174** Description This function obtains the local Bluetooth device address. 175** The local Bluetooth device address is reported by the 176** tBTA_JV_DM_CBACK callback with a BTA_JV_LOCAL_ADDR_EVT. 177** 178** Returns BTA_JV_SUCCESS if successful. 179** BTA_JV_FAIL if internal failure. 180** 181*******************************************************************************/ 182tBTA_JV_STATUS BTA_JvGetLocalDeviceAddr(void) 183{ 184 tBTA_JV_STATUS ret = BTA_JV_FAILURE; 185 BT_HDR *p_msg; 186 187 APPL_TRACE_API0( "BTA_JvGetLocalDeviceAddr"); 188 if ((p_msg = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL) 189 { 190 p_msg->event = BTA_JV_API_GET_LOCAL_DEVICE_ADDR_EVT; 191 bta_sys_sendmsg(p_msg); 192 ret = BTA_JV_SUCCESS; 193 } 194 195 return(ret); 196} 197 198/******************************************************************************* 199** 200** Function BTA_JvGetLocalDeviceName 201** 202** Description This function obtains the name of the local device 203** The local Bluetooth device name is reported by the 204** tBTA_JV_DM_CBACK callback with a BTA_JV_LOCAL_NAME_EVT. 205** 206** Returns BTA_JV_SUCCESS if successful. 207** BTA_JV_FAIL if internal failure. 208** 209*******************************************************************************/ 210tBTA_JV_STATUS BTA_JvGetLocalDeviceName(void) 211{ 212 tBTA_JV_STATUS ret = BTA_JV_FAILURE; 213 BT_HDR *p_msg; 214 215 APPL_TRACE_API0( "BTA_JvGetLocalDeviceName"); 216 if ((p_msg = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL) 217 { 218 p_msg->event = BTA_JV_API_GET_LOCAL_DEVICE_NAME_EVT; 219 bta_sys_sendmsg(p_msg); 220 ret = BTA_JV_SUCCESS; 221 } 222 223 return(ret); 224} 225 226/******************************************************************************* 227** 228** Function BTA_JvGetRemoteDeviceName 229** 230** Description This function obtains the name of the specified device. 231** The Bluetooth device name is reported by the 232** tBTA_JV_DM_CBACK callback with a BTA_JV_REMOTE_NAME_EVT. 233** 234** Returns BTA_JV_SUCCESS if successful. 235** BTA_JV_FAIL if internal failure. 236** 237*******************************************************************************/ 238tBTA_JV_STATUS BTA_JvGetRemoteDeviceName(BD_ADDR bd_addr) 239{ 240 tBTA_JV_STATUS ret = BTA_JV_FAILURE; 241 tBTA_JV_API_GET_REMOTE_NAME *p_msg; 242 243 APPL_TRACE_API0( "BTA_JvGetRemoteDeviceName"); 244 if ((p_msg = (tBTA_JV_API_GET_REMOTE_NAME *)GKI_getbuf(sizeof(tBTA_JV_API_GET_REMOTE_NAME))) != NULL) 245 { 246 p_msg->hdr.event = BTA_JV_API_GET_REMOTE_DEVICE_NAME_EVT; 247 bdcpy(p_msg->bd_addr, bd_addr); 248 bta_sys_sendmsg(p_msg); 249 ret = BTA_JV_SUCCESS; 250 } 251 252 return(ret); 253} 254 255/******************************************************************************* 256** 257** Function BTA_JvGetPreknownDevice 258** 259** Description This function obtains the Bluetooth address in the inquiry 260** database collected via the previous call to BTA_DmSearch(). 261** 262** Returns The number of preknown devices if p_bd_addr is NULL 263** BTA_JV_SUCCESS if successful. 264** BTA_JV_INTERNAL_ERR(-1) if internal failure. 265** 266*******************************************************************************/ 267INT32 BTA_JvGetPreknownDevice(UINT8 * p_bd_addr, UINT32 index) 268{ 269 tBTA_JV_STATUS status = BTA_JV_FAILURE; 270 tBTM_INQ_INFO *p_info; 271 UINT32 count = 0; 272 INT32 ret = BTA_JV_INTERNAL_ERR; 273 274 APPL_TRACE_API0( "BTA_JvGetPreknownDevice"); 275 p_info = BTM_InqFirstResult(); 276 if(p_info) 277 { 278 status = BTA_JV_SUCCESS; 279 /* the database is valid */ 280 if(NULL == p_bd_addr) 281 { 282 /* p_bd_addr is NULL: count the number of preknown devices */ 283 /* set the index to an invalid size (too big) */ 284 index = BTM_INQ_DB_SIZE; 285 } 286 else if(index >= BTM_INQ_DB_SIZE) 287 { 288 /* invalid index - error */ 289 status = (tBTA_JV_STATUS)BTA_JV_INTERNAL_ERR; 290 } 291 292 if(BTA_JV_SUCCESS == status) 293 { 294 while(p_info && index > count) 295 { 296 count++; 297 p_info = BTM_InqNextResult(p_info); 298 } 299 300 if(p_bd_addr) 301 { 302 if(index == count && p_info) 303 { 304 count = BTA_JV_SUCCESS; 305 bdcpy(p_bd_addr, p_info->results.remote_bd_addr); 306 } 307 else 308 status = (tBTA_JV_STATUS)BTA_JV_INTERNAL_ERR; 309 } 310 /* 311 else report the count 312 */ 313 } 314 /* 315 else error had happened. 316 */ 317 } 318 319 if(BTA_JV_SUCCESS == status) 320 { 321 ret = count; 322 } 323 return ret; 324} 325 326 327/******************************************************************************* 328** 329** Function BTA_JvGetDeviceClass 330** 331** Description This function obtains the local Class of Device. This 332** function executes in place. The result is returned right away. 333** 334** Returns DEV_CLASS, A three-byte array of UINT8 that contains the 335** Class of Device information. The definitions are in the 336** "Bluetooth Assigned Numbers". 337** 338*******************************************************************************/ 339UINT8 * BTA_JvGetDeviceClass(void) 340{ 341 APPL_TRACE_API0( "BTA_JvGetDeviceClass"); 342 return BTM_ReadDeviceClass(); 343} 344 345/******************************************************************************* 346** 347** Function BTA_JvSetServiceClass 348** 349** Description This function sets the service class of local Class of Device 350** 351** Returns BTA_JV_SUCCESS if successful. 352** BTA_JV_FAIL if internal failure. 353** 354*******************************************************************************/ 355tBTA_JV_STATUS BTA_JvSetServiceClass(UINT32 service) 356{ 357 tBTA_JV_STATUS status = BTA_JV_FAILURE; 358 tBTA_JV_API_SET_SERVICE_CLASS *p_msg; 359 360 APPL_TRACE_API0( "BTA_JvSetServiceClass"); 361 if ((p_msg = (tBTA_JV_API_SET_SERVICE_CLASS *)GKI_getbuf(sizeof(tBTA_JV_API_SET_SERVICE_CLASS))) != NULL) 362 { 363 p_msg->hdr.event = BTA_JV_API_SET_SERVICE_CLASS_EVT; 364 p_msg->service = service; 365 bta_sys_sendmsg(p_msg); 366 status = BTA_JV_SUCCESS; 367 } 368 369 return(status); 370} 371 372/******************************************************************************* 373** 374** Function BTA_JvSetEncryption 375** 376** Description This function ensures that the connection to the given device 377** is encrypted. 378** When the operation is complete the tBTA_JV_DM_CBACK callback 379** function will be called with a BTA_JV_SET_ENCRYPTION_EVT. 380** 381** Returns BTA_JV_SUCCESS, if the request is being processed. 382** BTA_JV_FAILURE, otherwise. 383** 384*******************************************************************************/ 385tBTA_JV_STATUS BTA_JvSetEncryption(BD_ADDR bd_addr) 386{ 387 tBTA_JV_STATUS ret = BTA_JV_FAILURE; 388 tBTA_JV_API_SET_ENCRYPTION *p_msg; 389 390 APPL_TRACE_API0( "BTA_JvSetEncryption"); 391 if ((p_msg = (tBTA_JV_API_SET_ENCRYPTION *)GKI_getbuf(sizeof(tBTA_JV_API_SET_ENCRYPTION))) != NULL) 392 { 393 p_msg->hdr.event = BTA_JV_API_SET_ENCRYPTION_EVT; 394 bdcpy(p_msg->bd_addr, bd_addr); 395 bta_sys_sendmsg(p_msg); 396 ret = BTA_JV_SUCCESS; 397 } 398 399 return(ret); 400} 401 402/******************************************************************************* 403** 404** Function BTA_JvIsAuthenticated 405** 406** Description This function checks if the peer device is authenticated 407** 408** Returns TRUE if authenticated. 409** FALSE if not. 410** 411*******************************************************************************/ 412BOOLEAN BTA_JvIsAuthenticated(BD_ADDR bd_addr) 413{ 414 BOOLEAN is_authenticated = FALSE; 415 UINT8 sec_flags; 416 417 if(BTM_GetSecurityFlags(bd_addr, &sec_flags)) 418 { 419 if(sec_flags&BTM_SEC_FLAG_AUTHENTICATED) 420 is_authenticated = TRUE; 421 } 422 return is_authenticated; 423} 424 425/******************************************************************************* 426** 427** Function BTA_JvIsTrusted 428** 429** Description This function checks if the peer device is trusted 430** (previously paired) 431** 432** Returns TRUE if trusted. 433** FALSE if not. 434** 435*******************************************************************************/ 436BOOLEAN BTA_JvIsTrusted(BD_ADDR bd_addr) 437{ 438 BOOLEAN is_trusted = FALSE; 439 UINT8 sec_flags; 440 441 if(BTM_GetSecurityFlags(bd_addr, &sec_flags)) 442 { 443 if ((sec_flags&BTM_SEC_FLAG_AUTHENTICATED) || 444 (sec_flags&BTM_SEC_FLAG_LKEY_KNOWN)) 445 { 446 is_trusted = TRUE; 447 } 448 } 449 return is_trusted; 450} 451 452/******************************************************************************* 453** 454** Function BTA_JvIsAuthorized 455** 456** Description This function checks if the peer device is authorized 457** 458** Returns TRUE if authorized. 459** FALSE if not. 460** 461*******************************************************************************/ 462BOOLEAN BTA_JvIsAuthorized(BD_ADDR bd_addr) 463{ 464 BOOLEAN is_authorized = FALSE; 465 UINT8 sec_flags; 466 467 if(BTM_GetSecurityFlags(bd_addr, &sec_flags)) 468 { 469 if(sec_flags&BTM_SEC_FLAG_AUTHORIZED) 470 is_authorized = TRUE; 471 } 472 return is_authorized; 473} 474 475/******************************************************************************* 476** 477** Function BTA_JvIsEncrypted 478** 479** Description This function checks if the link to peer device is encrypted 480** 481** Returns TRUE if encrypted. 482** FALSE if not. 483** 484*******************************************************************************/ 485BOOLEAN BTA_JvIsEncrypted(BD_ADDR bd_addr) 486{ 487 BOOLEAN is_encrypted = FALSE; 488 UINT8 sec_flags; 489 490 if(BTM_GetSecurityFlags(bd_addr, &sec_flags)) 491 { 492 if(sec_flags&BTM_SEC_FLAG_ENCRYPTED) 493 is_encrypted = TRUE; 494 } 495 return is_encrypted; 496} 497 498/******************************************************************************* 499** 500** Function BTA_JvGetSecurityMode 501** 502** Description This function returns the current Bluetooth security mode 503** of the local device 504** 505** Returns The current Bluetooth security mode. 506** 507*******************************************************************************/ 508tBTA_JV_SEC_MODE BTA_JvGetSecurityMode(void) 509{ 510 return BTM_GetSecurityMode(); 511} 512 513/******************************************************************************* 514** 515** Function BTA_JvGetSCN 516** 517** Description This function reserves a SCN (server channel number) for 518** applications running over RFCOMM. It is primarily called by 519** server profiles/applications to register their SCN into the 520** SDP database. The SCN is reported by the tBTA_JV_DM_CBACK 521** callback with a BTA_JV_GET_SCN_EVT. 522** If the SCN reported is 0, that means all SCN resources are 523** exhausted. 524** 525** Returns BTA_JV_SUCCESS, if the request is being processed. 526** BTA_JV_FAILURE, otherwise. 527** 528*******************************************************************************/ 529tBTA_JV_STATUS BTA_JvGetSCN(void) 530{ 531 tBTA_JV_STATUS status = BTA_JV_FAILURE; 532 BT_HDR *p_msg; 533 534 APPL_TRACE_API0( "BTA_JvGetSCN"); 535 if ((p_msg = (BT_HDR *)GKI_getbuf(sizeof(BT_HDR))) != NULL) 536 { 537 p_msg->event = BTA_JV_API_GET_SCN_EVT; 538 bta_sys_sendmsg(p_msg); 539 status = BTA_JV_SUCCESS; 540 } 541 542 return(status); 543} 544 545/******************************************************************************* 546** 547** Function BTA_JvFreeSCN 548** 549** Description This function frees a server channel number that was used 550** by an application running over RFCOMM. 551** 552** Returns BTA_JV_SUCCESS, if the request is being processed. 553** BTA_JV_FAILURE, otherwise. 554** 555*******************************************************************************/ 556tBTA_JV_STATUS BTA_JvFreeSCN(UINT8 scn) 557{ 558 tBTA_JV_STATUS status = BTA_JV_FAILURE; 559 tBTA_JV_API_FREE_SCN *p_msg; 560 561 APPL_TRACE_API0( "BTA_JvFreeSCN"); 562 if ((p_msg = (tBTA_JV_API_FREE_SCN *)GKI_getbuf(sizeof(tBTA_JV_API_FREE_SCN))) != NULL) 563 { 564 p_msg->hdr.event = BTA_JV_API_FREE_SCN_EVT; 565 p_msg->scn = scn; 566 bta_sys_sendmsg(p_msg); 567 status = BTA_JV_SUCCESS; 568 } 569 570 return(status); 571} 572 573/******************************************************************************* 574** 575** Function BTA_JvGetPSM 576** 577** Description This function reserves a PSM (Protocol Service Multiplexer) 578** applications running over L2CAP. It is primarily called by 579** server profiles/applications to register their PSM into the 580** SDP database. 581** 582** Returns The next free PSM 583** 584*******************************************************************************/ 585UINT16 BTA_JvGetPSM(void) 586{ 587#if 0 588 APPL_TRACE_API0( "BTA_JvGetPSM"); 589 590 return (L2CA_AllocatePSM()); 591#endif 592 return 0; 593} 594 595 596/******************************************************************************* 597** 598** Function BTA_JvStartDiscovery 599** 600** Description This function performs service discovery for the services 601** provided by the given peer device. When the operation is 602** complete the tBTA_JV_DM_CBACK callback function will be 603** called with a BTA_JV_DISCOVERY_COMP_EVT. 604** 605** Returns BTA_JV_SUCCESS, if the request is being processed. 606** BTA_JV_FAILURE, otherwise. 607** 608*******************************************************************************/ 609tBTA_JV_STATUS BTA_JvStartDiscovery(BD_ADDR bd_addr, UINT16 num_uuid, 610 tSDP_UUID *p_uuid_list, void * user_data) 611{ 612 tBTA_JV_STATUS status = BTA_JV_FAILURE; 613 tBTA_JV_API_START_DISCOVERY *p_msg; 614 615 APPL_TRACE_API0( "BTA_JvStartDiscovery"); 616 if ((p_msg = (tBTA_JV_API_START_DISCOVERY *)GKI_getbuf(sizeof(tBTA_JV_API_START_DISCOVERY))) != NULL) 617 { 618 p_msg->hdr.event = BTA_JV_API_START_DISCOVERY_EVT; 619 bdcpy(p_msg->bd_addr, bd_addr); 620 p_msg->num_uuid = num_uuid; 621 memcpy(p_msg->uuid_list, p_uuid_list, num_uuid * sizeof(tSDP_UUID)); 622 p_msg->num_attr = 0; 623 p_msg->user_data = user_data; 624 bta_sys_sendmsg(p_msg); 625 status = BTA_JV_SUCCESS; 626 } 627 628 return(status); 629} 630 631/******************************************************************************* 632** 633** Function BTA_JvCancelDiscovery 634** 635** Description This function cancels an active service discovery. 636** When the operation is 637** complete the tBTA_JV_DM_CBACK callback function will be 638** called with a BTA_JV_CANCEL_DISCVRY_EVT. 639** 640** Returns BTA_JV_SUCCESS, if the request is being processed. 641** BTA_JV_FAILURE, otherwise. 642** 643*******************************************************************************/ 644tBTA_JV_STATUS BTA_JvCancelDiscovery(void * user_data) 645{ 646 tBTA_JV_STATUS status = BTA_JV_FAILURE; 647 tBTA_JV_API_CANCEL_DISCOVERY *p_msg; 648 649 APPL_TRACE_API0( "BTA_JvCancelDiscovery"); 650 if ((p_msg = (tBTA_JV_API_CANCEL_DISCOVERY *)GKI_getbuf(sizeof(tBTA_JV_API_CANCEL_DISCOVERY))) != NULL) 651 { 652 p_msg->hdr.event = BTA_JV_API_CANCEL_DISCOVERY_EVT; 653 p_msg->user_data = user_data; 654 bta_sys_sendmsg(p_msg); 655 status = BTA_JV_SUCCESS; 656 } 657 658 return(status); 659} 660 661/******************************************************************************* 662** 663** Function BTA_JvGetServicesLength 664** 665** Description This function obtains the number of services and the length 666** of each service found in the SDP database (result of last 667** BTA_JvStartDiscovery().When the operation is complete the 668** tBTA_JV_DM_CBACK callback function will be called with a 669** BTA_JV_SERVICES_LEN_EVT. 670** 671** Returns BTA_JV_SUCCESS, if the request is being processed. 672** BTA_JV_FAILURE, otherwise. 673** 674*******************************************************************************/ 675tBTA_JV_STATUS BTA_JvGetServicesLength(BOOLEAN inc_hdr, UINT16 *p_services_len) 676{ 677 tBTA_JV_STATUS status = BTA_JV_FAILURE; 678 tBTA_JV_API_GET_SERVICES_LENGTH *p_msg; 679 680 APPL_TRACE_API0( "BTA_JvGetServicesLength"); 681 if ((p_msg = (tBTA_JV_API_GET_SERVICES_LENGTH *)GKI_getbuf(sizeof(tBTA_JV_API_GET_SERVICES_LENGTH))) != NULL) 682 { 683 p_msg->hdr.event = BTA_JV_API_GET_SERVICES_LENGTH_EVT; 684 p_msg->p_services_len = p_services_len; 685 p_msg->inc_hdr = inc_hdr; 686 bta_sys_sendmsg(p_msg); 687 status = BTA_JV_SUCCESS; 688 } 689 690 return(status); 691} 692/******************************************************************************* 693** 694** Function BTA_JvGetServicesResult 695** 696** Description This function returns a number of service records found 697** during current service search, equals to the number returned 698** by previous call to BTA_JvGetServicesLength. 699** The contents of each SDP record will be returned under a 700** TLV (type, len, value) representation in the data buffer 701** provided by the caller. 702** 703** Returns -1, if error. Otherwise, the number of services 704** 705*******************************************************************************/ 706INT32 BTA_JvGetServicesResult(BOOLEAN inc_hdr, UINT8 **TLVs) 707{ 708#if 0 709 INT32 num_services = -1; 710 UINT8 *p, *np, *op, type; 711 UINT32 raw_used, raw_cur; 712 UINT32 len; 713 UINT32 hdr_len; 714 715 APPL_TRACE_API0( "BTA_JvGetServicesResult"); 716 if(p_bta_jv_cfg->p_sdp_db->p_first_rec) 717 { 718 /* the database is valid */ 719 num_services = 0; 720 p = p_bta_jv_cfg->p_sdp_db->raw_data; 721 raw_used = p_bta_jv_cfg->p_sdp_db->raw_used; 722 while(raw_used && p) 723 { 724 op = p; 725 type = *p++; 726 np = sdpu_get_len_from_type(p, type, &len); 727 p = np + len; 728 raw_cur = p - op; 729 if(raw_used >= raw_cur) 730 { 731 raw_used -= raw_cur; 732 } 733 else 734 { 735 /* error. can not continue */ 736 break; 737 } 738 if(inc_hdr) 739 { 740 hdr_len = np - op; 741 memcpy(TLVs[num_services++], op, len+hdr_len); 742 } 743 else 744 { 745 memcpy(TLVs[num_services++], np, len); 746 } 747 } /* end of while */ 748 } 749 return(num_services); 750#endif 751 return 0; 752} 753/******************************************************************************* 754** 755** Function BTA_JvServiceSelect 756** 757** Description This function checks if the SDP database contains the given 758** service UUID. When the operation is complete the 759** tBTA_JV_DM_CBACK callback function will be called with a 760** BTA_JV_SERVICE_SEL_EVT with the length of the service record. 761** If the service is not found or error, -1 is reported. 762** 763** Returns BTA_JV_SUCCESS, if the request is being processed. 764** BTA_JV_FAILURE, otherwise. 765** 766*******************************************************************************/ 767tBTA_JV_STATUS BTA_JvServiceSelect(UINT16 uuid) 768{ 769 tBTA_JV_STATUS status = BTA_JV_FAILURE; 770 tBTA_JV_API_SERVICE_SELECT *p_msg; 771 772 APPL_TRACE_API0( "BTA_JvServiceSelect"); 773 if ((p_msg = (tBTA_JV_API_SERVICE_SELECT *)GKI_getbuf(sizeof(tBTA_JV_API_SERVICE_SELECT))) != NULL) 774 { 775 p_msg->hdr.event = BTA_JV_API_SERVICE_SELECT_EVT; 776 p_msg->uuid = uuid; 777 bta_sys_sendmsg(p_msg); 778 status = BTA_JV_SUCCESS; 779 } 780 return(status); 781} 782 783/******************************************************************************* 784** 785** Function BTA_JvServiceResult 786** 787** Description This function returns the contents of the SDP record from 788** last BTA_JvServiceSelect. The contents will be returned under 789** a TLV (type, len, value) representation in the data buffer 790** provided by the caller. 791** 792** Returns -1, if error. Otherwise, the length of service record. 793** 794*******************************************************************************/ 795INT32 BTA_JvServiceResult(UINT8 *TLV) 796{ 797 INT32 serv_sel = -1; 798 799 APPL_TRACE_API0( "BTA_JvServiceResult"); 800 if(bta_jv_cb.p_sel_raw_data) 801 { 802 serv_sel = bta_jv_cb.sel_len; 803 memcpy(TLV, bta_jv_cb.p_sel_raw_data, serv_sel); 804 } 805 806 return serv_sel; 807} 808 809 810/******************************************************************************* 811** 812** Function BTA_JvCreateRecord 813** 814** Description Create a service record in the local SDP database. 815** When the operation is complete the tBTA_JV_DM_CBACK callback 816** function will be called with a BTA_JV_CREATE_RECORD_EVT. 817** 818** Returns BTA_JV_SUCCESS, if the request is being processed. 819** BTA_JV_FAILURE, otherwise. 820** 821*******************************************************************************/ 822tBTA_JV_STATUS BTA_JvCreateRecordByUser(void *user_data) 823{ 824 tBTA_JV_STATUS status = BTA_JV_FAILURE; 825 tBTA_JV_API_CREATE_RECORD *p_msg; 826 827 APPL_TRACE_API0( "BTA_JvCreateRecordByUser"); 828 if ((p_msg = (tBTA_JV_API_CREATE_RECORD *)GKI_getbuf(sizeof(tBTA_JV_API_CREATE_RECORD))) != NULL) 829 { 830 p_msg->hdr.event = BTA_JV_API_CREATE_RECORD_EVT; 831 p_msg->user_data = user_data; 832 bta_sys_sendmsg(p_msg); 833 status = BTA_JV_SUCCESS; 834 } 835 836 return(status); 837} 838 839/******************************************************************************* 840** 841** Function BTA_JvUpdateRecord 842** 843** Description Update a service record in the local SDP database. 844** When the operation is complete the tBTA_JV_DM_CBACK callback 845** function will be called with a BTA_JV_UPDATE_RECORD_EVT. 846** 847** Returns BTA_JV_SUCCESS, if the request is being processed. 848** BTA_JV_FAILURE, otherwise. 849** 850*******************************************************************************/ 851tBTA_JV_STATUS BTA_JvUpdateRecord(UINT32 handle, UINT16 *p_ids, 852 UINT8 **p_values, INT32 *p_value_sizes, INT32 array_len) 853{ 854#if 0 855 tBTA_JV_STATUS status = BTA_JV_FAILURE; 856 tBTA_JV_API_UPDATE_RECORD *p_msg; 857 858 APPL_TRACE_API0( "BTA_JvUpdateRecord"); 859 if ((p_msg = (tBTA_JV_API_UPDATE_RECORD *)GKI_getbuf(sizeof(tBTA_JV_API_UPDATE_RECORD))) != NULL) 860 { 861 p_msg->hdr.event = BTA_JV_API_UPDATE_RECORD_EVT; 862 p_msg->handle = handle; 863 p_msg->p_ids = p_ids; 864 p_msg->p_values = p_values; 865 p_msg->p_value_sizes = p_value_sizes; 866 p_msg->array_len = array_len; 867 bta_sys_sendmsg(p_msg); 868 status = BTA_JV_SUCCESS; 869 } 870 return(status); 871#endif 872 return -1; 873} 874 875/******************************************************************************* 876** 877** Function BTA_JvAddAttribute 878** 879** Description Add an attribute to a service record in the local SDP database. 880** When the operation is complete the tBTA_JV_DM_CBACK callback 881** function will be called with a BTA_JV_ADD_ATTR_EVT. 882** 883** Returns BTA_JV_SUCCESS, if the request is being processed. 884** BTA_JV_FAILURE, otherwise. 885** 886*******************************************************************************/ 887tBTA_JV_STATUS BTA_JvAddAttribute(UINT32 handle, UINT16 attr_id, 888 UINT8 *p_value, INT32 value_size) 889{ 890 tBTA_JV_STATUS status = BTA_JV_FAILURE; 891 tBTA_JV_API_ADD_ATTRIBUTE *p_msg; 892 893 APPL_TRACE_API0( "BTA_JvAddAttribute"); 894 if ((p_msg = (tBTA_JV_API_ADD_ATTRIBUTE *)GKI_getbuf(sizeof(tBTA_JV_API_ADD_ATTRIBUTE))) != NULL) 895 { 896 p_msg->hdr.event = BTA_JV_API_ADD_ATTRIBUTE_EVT; 897 p_msg->handle = handle; 898 p_msg->attr_id = attr_id; 899 p_msg->p_value = p_value; 900 p_msg->value_size = value_size; 901 bta_sys_sendmsg(p_msg); 902 status = BTA_JV_SUCCESS; 903 } 904 return(status); 905} 906 907/******************************************************************************* 908** 909** Function BTA_JvDeleteAttribute 910** 911** Description Delete an attribute from a service record in the local SDP database. 912** When the operation is complete the tBTA_JV_DM_CBACK callback 913** function will be called with a BTA_JV_DELETE_ATTR_EVT. 914** 915** Returns BTA_JV_SUCCESS, if the request is being processed. 916** BTA_JV_FAILURE, otherwise. 917** 918*******************************************************************************/ 919tBTA_JV_STATUS BTA_JvDeleteAttribute(UINT32 handle, UINT16 attr_id) 920{ 921 tBTA_JV_STATUS status = BTA_JV_FAILURE; 922 tBTA_JV_API_ADD_ATTRIBUTE *p_msg; 923 924 APPL_TRACE_API0( "BTA_JvDeleteAttribute"); 925 if ((p_msg = (tBTA_JV_API_ADD_ATTRIBUTE *)GKI_getbuf(sizeof(tBTA_JV_API_ADD_ATTRIBUTE))) != NULL) 926 { 927 p_msg->hdr.event = BTA_JV_API_DELETE_ATTRIBUTE_EVT; 928 p_msg->handle = handle; 929 p_msg->attr_id = attr_id; 930 bta_sys_sendmsg(p_msg); 931 status = BTA_JV_SUCCESS; 932 } 933 return(status); 934} 935 936/******************************************************************************* 937** 938** Function BTA_JvDeleteRecord 939** 940** Description Delete a service record in the local SDP database. 941** 942** Returns BTA_JV_SUCCESS, if the request is being processed. 943** BTA_JV_FAILURE, otherwise. 944** 945*******************************************************************************/ 946tBTA_JV_STATUS BTA_JvDeleteRecord(UINT32 handle) 947{ 948 tBTA_JV_STATUS status = BTA_JV_FAILURE; 949 tBTA_JV_API_ADD_ATTRIBUTE *p_msg; 950 951 APPL_TRACE_API0( "BTA_JvDeleteRecord"); 952 if ((p_msg = (tBTA_JV_API_ADD_ATTRIBUTE *)GKI_getbuf(sizeof(tBTA_JV_API_ADD_ATTRIBUTE))) != NULL) 953 { 954 p_msg->hdr.event = BTA_JV_API_DELETE_RECORD_EVT; 955 p_msg->handle = handle; 956 bta_sys_sendmsg(p_msg); 957 status = BTA_JV_SUCCESS; 958 } 959 return(status); 960} 961 962/******************************************************************************* 963** 964** Function BTA_JvReadRecord 965** 966** Description Read a service record in the local SDP database. 967** 968** Returns -1, if the record is not found. 969** Otherwise, the offset (0 or 1) to start of data in p_data. 970** 971** The size of data copied into p_data is in *p_data_len. 972** 973*******************************************************************************/ 974INT32 BTA_JvReadRecord(UINT32 handle, UINT8 *p_data, INT32 *p_data_len) 975{ 976 UINT32 sdp_handle; 977 978 sdp_handle = bta_jv_get_sdp_handle(handle); 979 980 if(sdp_handle) 981 { 982 return SDP_ReadRecord(sdp_handle, p_data, p_data_len); 983 } 984 985 return -1; 986} 987 988/******************************************************************************* 989** 990** Function BTA_JvL2capConnect 991** 992** Description Initiate a connection as a L2CAP client to the given BD 993** Address. 994** When the connection is initiated or failed to initiate, 995** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_CL_INIT_EVT 996** When the connection is established or failed, 997** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT 998** 999** Returns BTA_JV_SUCCESS, if the request is being processed. 1000** BTA_JV_FAILURE, otherwise. 1001** 1002*******************************************************************************/ 1003tBTA_JV_STATUS BTA_JvL2capConnect(tBTA_SEC sec_mask, 1004 tBTA_JV_ROLE role, UINT16 remote_psm, UINT16 rx_mtu, 1005 BD_ADDR peer_bd_addr, tBTA_JV_L2CAP_CBACK *p_cback) 1006{ 1007 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1008 tBTA_JV_API_L2CAP_CONNECT *p_msg; 1009 1010 APPL_TRACE_API0( "BTA_JvL2capConnect"); 1011 if (p_cback && 1012 (p_msg = (tBTA_JV_API_L2CAP_CONNECT *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_CONNECT))) != NULL) 1013 { 1014 p_msg->hdr.event = BTA_JV_API_L2CAP_CONNECT_EVT; 1015 p_msg->sec_mask = sec_mask; 1016 p_msg->role = role; 1017 p_msg->remote_psm = remote_psm; 1018 p_msg->rx_mtu = rx_mtu; 1019 memcpy(p_msg->peer_bd_addr, peer_bd_addr, sizeof(BD_ADDR)); 1020 p_msg->p_cback = p_cback; 1021 bta_sys_sendmsg(p_msg); 1022 status = BTA_JV_SUCCESS; 1023 } 1024 1025 return(status); 1026} 1027 1028/******************************************************************************* 1029** 1030** Function BTA_JvL2capClose 1031** 1032** Description This function closes an L2CAP client connection 1033** 1034** Returns BTA_JV_SUCCESS, if the request is being processed. 1035** BTA_JV_FAILURE, otherwise. 1036** 1037*******************************************************************************/ 1038tBTA_JV_STATUS BTA_JvL2capClose(UINT32 handle) 1039{ 1040 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1041 tBTA_JV_API_L2CAP_CLOSE *p_msg; 1042 1043 APPL_TRACE_API0( "BTA_JvL2capClose"); 1044 if (handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback && 1045 (p_msg = (tBTA_JV_API_L2CAP_CLOSE *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_CLOSE))) != NULL) 1046 { 1047 p_msg->hdr.event = BTA_JV_API_L2CAP_CLOSE_EVT; 1048 p_msg->handle = handle; 1049 p_msg->p_cb = &bta_jv_cb.l2c_cb[handle]; 1050 bta_sys_sendmsg(p_msg); 1051 status = BTA_JV_SUCCESS; 1052 } 1053 1054 return(status); 1055} 1056 1057/******************************************************************************* 1058** 1059** Function BTA_JvL2capStartServer 1060** 1061** Description This function starts an L2CAP server and listens for an L2CAP 1062** connection from a remote Bluetooth device. When the server 1063** is started successfully, tBTA_JV_L2CAP_CBACK is called with 1064** BTA_JV_L2CAP_START_EVT. When the connection is established, 1065** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT. 1066** 1067** Returns BTA_JV_SUCCESS, if the request is being processed. 1068** BTA_JV_FAILURE, otherwise. 1069** 1070*******************************************************************************/ 1071tBTA_JV_STATUS BTA_JvL2capStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role, 1072 UINT16 local_psm, UINT16 rx_mtu, 1073 tBTA_JV_L2CAP_CBACK *p_cback) 1074{ 1075 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1076 tBTA_JV_API_L2CAP_SERVER *p_msg; 1077 1078 APPL_TRACE_API0( "BTA_JvL2capStartServer"); 1079 if (p_cback && 1080 (p_msg = (tBTA_JV_API_L2CAP_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_SERVER))) != NULL) 1081 { 1082 p_msg->hdr.event = BTA_JV_API_L2CAP_START_SERVER_EVT; 1083 p_msg->sec_mask = sec_mask; 1084 p_msg->role = role; 1085 p_msg->local_psm = local_psm; 1086 p_msg->rx_mtu = rx_mtu; 1087 p_msg->p_cback = p_cback; 1088 bta_sys_sendmsg(p_msg); 1089 status = BTA_JV_SUCCESS; 1090 } 1091 1092 return(status); 1093} 1094 1095/******************************************************************************* 1096** 1097** Function BTA_JvL2capStopServer 1098** 1099** Description This function stops the L2CAP server. If the server has an 1100** active connection, it would be closed. 1101** 1102** Returns BTA_JV_SUCCESS, if the request is being processed. 1103** BTA_JV_FAILURE, otherwise. 1104** 1105*******************************************************************************/ 1106tBTA_JV_STATUS BTA_JvL2capStopServer(UINT16 local_psm) 1107{ 1108 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1109 tBTA_JV_API_L2CAP_SERVER *p_msg; 1110 1111 APPL_TRACE_API0( "BTA_JvL2capStopServer"); 1112 if ((p_msg = (tBTA_JV_API_L2CAP_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_SERVER))) != NULL) 1113 { 1114 p_msg->hdr.event = BTA_JV_API_L2CAP_STOP_SERVER_EVT; 1115 p_msg->local_psm = local_psm; 1116 bta_sys_sendmsg(p_msg); 1117 status = BTA_JV_SUCCESS; 1118 } 1119 1120 return(status); 1121} 1122 1123/******************************************************************************* 1124** 1125** Function BTA_JvL2capRead 1126** 1127** Description This function reads data from an L2CAP connecti; 1128 tBTA_JV_RFC_CB *p_cb = rc->p_cb; 1129on 1130** When the operation is complete, tBTA_JV_L2CAP_CBACK is 1131** called with BTA_JV_L2CAP_READ_EVT. 1132** 1133** Returns BTA_JV_SUCCESS, if the request is being processed. 1134** BTA_JV_FAILURE, otherwise. 1135** 1136*******************************************************************************/ 1137tBTA_JV_STATUS BTA_JvL2capRead(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len) 1138{ 1139#if 0 1140 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1141#if SDP_FOR_JV_INCLUDED == TRUE 1142 tBTA_JV_API_L2CAP_READ *p_msg; 1143#endif 1144 tBTA_JV_L2CAP_READ evt_data; 1145 1146 APPL_TRACE_API0( "BTA_JvL2capRead"); 1147 1148#if SDP_FOR_JV_INCLUDED == TRUE 1149 if(BTA_JV_L2C_FOR_SDP_HDL == handle) 1150 { 1151 if (bta_jv_cb.l2c_cb[handle].p_cback && 1152 (p_msg = (tBTA_JV_API_L2CAP_READ *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_READ))) != NULL) 1153 { 1154 p_msg->hdr.event = BTA_JV_API_L2CAP_READ_EVT; 1155 p_msg->handle = handle; 1156 p_msg->req_id = req_id; 1157 p_msg->p_data = p_data; 1158 p_msg->len = len; 1159 p_msg->p_cback = bta_jv_cb.l2c_cb[handle].p_cback; 1160 bta_sys_sendmsg(p_msg); 1161 status = BTA_JV_SUCCESS; 1162 } 1163 } 1164 else 1165#endif 1166 if (handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback) 1167 { 1168 status = BTA_JV_SUCCESS; 1169 evt_data.status = BTA_JV_FAILURE; 1170 evt_data.handle = handle; 1171 evt_data.req_id = req_id; 1172 evt_data.p_data = p_data; 1173 evt_data.len = 0; 1174 1175 if (BT_PASS == GAP_ConnReadData((UINT16)handle, p_data, len, &evt_data.len)) 1176 { 1177 evt_data.status = BTA_JV_SUCCESS; 1178 } 1179 bta_jv_cb.l2c_cb[handle].p_cback(BTA_JV_L2CAP_READ_EVT, (tBTA_JV *)&evt_data); 1180 } 1181 1182 return(status); 1183#endif 1184 return -1; 1185} 1186 1187/******************************************************************************* 1188** 1189** Function BTA_JvL2capReceive 1190** 1191** Description This function reads data from an L2CAP connection 1192** When the operation is complete, tBTA_JV_L2CAP_CBACK is 1193** called with BTA_JV_L2CAP_RECEIVE_EVT. 1194** If there are more data queued in L2CAP than len, the extra data will be discarded. 1195** 1196** Returns BTA_JV_SUCCESS, if the request is being processed. 1197** BTA_JV_FAILURE, otherwise. 1198** 1199*******************************************************************************/ 1200tBTA_JV_STATUS BTA_JvL2capReceive(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len) 1201{ 1202#if 0 1203 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1204 tBTA_JV_L2CAP_RECEIVE evt_data; 1205 UINT32 left_over = 0; 1206 UINT16 max_len, read_len; 1207 1208 APPL_TRACE_API0( "BTA_JvL2capReceive"); 1209 1210 if (handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback) 1211 { 1212 status = BTA_JV_SUCCESS; 1213 evt_data.status = BTA_JV_FAILURE; 1214 evt_data.handle = handle; 1215 evt_data.req_id = req_id; 1216 evt_data.p_data = p_data; 1217 evt_data.len = 0; 1218 1219 if (BT_PASS == GAP_ConnReadData((UINT16)handle, p_data, len, &evt_data.len)) 1220 { 1221 evt_data.status = BTA_JV_SUCCESS; 1222 GAP_GetRxQueueCnt ((UINT16)handle, &left_over); 1223 while (left_over) 1224 { 1225 max_len = (left_over > 0xFFFF)?0xFFFF:left_over; 1226 GAP_ConnReadData ((UINT16)handle, NULL, max_len, &read_len); 1227 left_over -= read_len; 1228 } 1229 } 1230 bta_jv_cb.l2c_cb[handle].p_cback(BTA_JV_L2CAP_RECEIVE_EVT, (tBTA_JV *)&evt_data); 1231 } 1232 1233 return(status); 1234#endif 1235 return -1; 1236} 1237/******************************************************************************* 1238** 1239** Function BTA_JvL2capReady 1240** 1241** Description This function determined if there is data to read from 1242** an L2CAP connection 1243** 1244** Returns BTA_JV_SUCCESS, if data queue size is in *p_data_size. 1245** BTA_JV_FAILURE, if error. 1246** 1247*******************************************************************************/ 1248tBTA_JV_STATUS BTA_JvL2capReady(UINT32 handle, UINT32 *p_data_size) 1249{ 1250#if 0 1251 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1252 1253 APPL_TRACE_API1( "BTA_JvL2capReady: %d", handle); 1254 if (p_data_size && handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback) 1255 { 1256 *p_data_size = 0; 1257#if SDP_FOR_JV_INCLUDED == TRUE 1258 if(BTA_JV_L2C_FOR_SDP_HDL == handle) 1259 { 1260 *p_data_size = bta_jv_cb.sdp_data_size; 1261 status = BTA_JV_SUCCESS; 1262 } 1263 else 1264#endif 1265 if(BT_PASS == GAP_GetRxQueueCnt((UINT16)handle, p_data_size) ) 1266 { 1267 status = BTA_JV_SUCCESS; 1268 } 1269 } 1270 1271 return(status); 1272#endif 1273 return -1; 1274} 1275 1276 1277/******************************************************************************* 1278** 1279** Function BTA_JvL2capWrite 1280** 1281** Description This function writes data to an L2CAP connection 1282** When the operation is complete, tBTA_JV_L2CAP_CBACK is 1283** called with BTA_JV_L2CAP_WRITE_EVT. 1284** 1285** Returns BTA_JV_SUCCESS, if the request is being processed. 1286** BTA_JV_FAILURE, otherwise. 1287** 1288*******************************************************************************/ 1289tBTA_JV_STATUS BTA_JvL2capWrite(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len) 1290{ 1291 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1292 tBTA_JV_API_L2CAP_WRITE *p_msg; 1293 1294 APPL_TRACE_API0( "BTA_JvL2capWrite"); 1295 if (handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback && 1296 (p_msg = (tBTA_JV_API_L2CAP_WRITE *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_WRITE))) != NULL) 1297 { 1298 p_msg->hdr.event = BTA_JV_API_L2CAP_WRITE_EVT; 1299 p_msg->handle = handle; 1300 p_msg->req_id = req_id; 1301 p_msg->p_data = p_data; 1302 p_msg->p_cb = &bta_jv_cb.l2c_cb[handle]; 1303 p_msg->len = len; 1304 bta_sys_sendmsg(p_msg); 1305 status = BTA_JV_SUCCESS; 1306 } 1307 1308 return(status); 1309} 1310 1311/******************************************************************************* 1312** 1313** Function BTA_JvRfcommConnect 1314** 1315** Description This function makes an RFCOMM conection to a remote BD 1316** Address. 1317** When the connection is initiated or failed to initiate, 1318** tBTA_JV_RFCOMM_CBACK is called with BTA_JV_RFCOMM_CL_INIT_EVT 1319** When the connection is established or failed, 1320** tBTA_JV_RFCOMM_CBACK is called with BTA_JV_RFCOMM_OPEN_EVT 1321** 1322** Returns BTA_JV_SUCCESS, if the request is being processed. 1323** BTA_JV_FAILURE, otherwise. 1324** 1325*******************************************************************************/ 1326tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, 1327 tBTA_JV_ROLE role, UINT8 remote_scn, BD_ADDR peer_bd_addr, 1328 tBTA_JV_RFCOMM_CBACK *p_cback, void* user_data) 1329{ 1330 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1331 tBTA_JV_API_RFCOMM_CONNECT *p_msg; 1332 1333 APPL_TRACE_API0( "BTA_JvRfcommConnect"); 1334 if (p_cback && 1335 (p_msg = (tBTA_JV_API_RFCOMM_CONNECT *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_CONNECT))) != NULL) 1336 { 1337 p_msg->hdr.event = BTA_JV_API_RFCOMM_CONNECT_EVT; 1338 p_msg->sec_mask = sec_mask; 1339 p_msg->role = role; 1340 p_msg->remote_scn = remote_scn; 1341 memcpy(p_msg->peer_bd_addr, peer_bd_addr, sizeof(BD_ADDR)); 1342 p_msg->p_cback = p_cback; 1343 p_msg->user_data = user_data; 1344 bta_sys_sendmsg(p_msg); 1345 status = BTA_JV_SUCCESS; 1346 } 1347 1348 return(status); 1349} 1350 1351/******************************************************************************* 1352** 1353** Function BTA_JvRfcommClose 1354** 1355** Description This function closes an RFCOMM connection 1356** 1357** Returns BTA_JV_SUCCESS, if the request is being processed. 1358** BTA_JV_FAILURE, otherwise. 1359** 1360*******************************************************************************/ 1361tBTA_JV_STATUS BTA_JvRfcommClose(UINT32 handle, void *user_data) 1362{ 1363 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1364 tBTA_JV_API_RFCOMM_CLOSE *p_msg; 1365 UINT32 hi = (handle & BTA_JV_RFC_HDL_MASK) - 1; 1366 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle); 1367 1368 APPL_TRACE_API0( "BTA_JvRfcommClose"); 1369 if (hi < BTA_JV_MAX_RFC_CONN && bta_jv_cb.rfc_cb[hi].p_cback && 1370 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si] && 1371 (p_msg = (tBTA_JV_API_RFCOMM_CLOSE *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_CLOSE))) != NULL) 1372 { 1373 p_msg->hdr.event = BTA_JV_API_RFCOMM_CLOSE_EVT; 1374 p_msg->handle = handle; 1375 p_msg->p_cb = &bta_jv_cb.rfc_cb[hi]; 1376 p_msg->p_pcb = &bta_jv_cb.port_cb[p_msg->p_cb->rfc_hdl[si] - 1]; 1377 p_msg->user_data = user_data; 1378 bta_sys_sendmsg(p_msg); 1379 status = BTA_JV_SUCCESS; 1380 } 1381 1382 return(status); 1383} 1384 1385/******************************************************************************* 1386** 1387** Function BTA_JvRfcommStartServer 1388** 1389** Description This function starts listening for an RFCOMM connection 1390** request from a remote Bluetooth device. When the server is 1391** started successfully, tBTA_JV_RFCOMM_CBACK is called 1392** with BTA_JV_RFCOMM_START_EVT. 1393** When the connection is established, tBTA_JV_RFCOMM_CBACK 1394** is called with BTA_JV_RFCOMM_OPEN_EVT. 1395** 1396** Returns BTA_JV_SUCCESS, if the request is being processed. 1397** BTA_JV_FAILURE, otherwise. 1398** 1399*******************************************************************************/ 1400tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, 1401 tBTA_JV_ROLE role, UINT8 local_scn, UINT8 max_session, 1402 tBTA_JV_RFCOMM_CBACK *p_cback, void* user_data) 1403{ 1404 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1405 tBTA_JV_API_RFCOMM_SERVER *p_msg; 1406 1407 APPL_TRACE_API0( "BTA_JvRfcommStartServer"); 1408 if (p_cback && 1409 (p_msg = (tBTA_JV_API_RFCOMM_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_SERVER))) != NULL) 1410 { 1411 if (max_session == 0) 1412 max_session = 1; 1413 if (max_session > BTA_JV_MAX_RFC_SR_SESSION) 1414 { 1415 APPL_TRACE_DEBUG2( "max_session is too big. use max (%d)", max_session, BTA_JV_MAX_RFC_SR_SESSION); 1416 max_session = BTA_JV_MAX_RFC_SR_SESSION; 1417 } 1418 p_msg->hdr.event = BTA_JV_API_RFCOMM_START_SERVER_EVT; 1419 p_msg->sec_mask = sec_mask; 1420 p_msg->role = role; 1421 p_msg->local_scn = local_scn; 1422 p_msg->max_session = max_session; 1423 p_msg->p_cback = p_cback; 1424 p_msg->user_data = user_data; //caller's private data 1425 bta_sys_sendmsg(p_msg); 1426 status = BTA_JV_SUCCESS; 1427 } 1428 1429 return(status); 1430} 1431 1432/******************************************************************************* 1433** 1434** Function BTA_JvRfcommStopServer 1435** 1436** Description This function stops the RFCOMM server. If the server has an 1437** active connection, it would be closed. 1438** 1439** Returns BTA_JV_SUCCESS, if the request is being processed. 1440** BTA_JV_FAILURE, otherwise. 1441** 1442*******************************************************************************/ 1443tBTA_JV_STATUS BTA_JvRfcommStopServer(UINT32 handle, void * user_data) 1444{ 1445 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1446 tBTA_JV_API_RFCOMM_SERVER *p_msg; 1447 APPL_TRACE_API0( "BTA_JvRfcommStopServer"); 1448 if ((p_msg = (tBTA_JV_API_RFCOMM_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_SERVER))) != NULL) 1449 { 1450 p_msg->hdr.event = BTA_JV_API_RFCOMM_STOP_SERVER_EVT; 1451 p_msg->rfc_handle = handle; 1452 p_msg->user_data = user_data; //caller's private data 1453 bta_sys_sendmsg(p_msg); 1454 status = BTA_JV_SUCCESS; 1455 } 1456 1457 return(status); 1458} 1459 1460/******************************************************************************* 1461** 1462** Function BTA_JvRfcommRead 1463** 1464** Description This function reads data from an RFCOMM connection 1465** The actual size of data read is returned in p_len. 1466** 1467** Returns BTA_JV_SUCCESS, if the request is being processed. 1468** BTA_JV_FAILURE, otherwise. 1469** 1470*******************************************************************************/ 1471tBTA_JV_STATUS BTA_JvRfcommRead(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len) 1472{ 1473 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1474 tBTA_JV_API_RFCOMM_READ *p_msg; 1475 UINT32 hi = (handle & BTA_JV_RFC_HDL_MASK) - 1; 1476 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle); 1477 1478 APPL_TRACE_API0( "BTA_JvRfcommRead"); 1479 if (hi < BTA_JV_MAX_RFC_CONN && bta_jv_cb.rfc_cb[hi].p_cback && 1480 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si] && 1481 (p_msg = (tBTA_JV_API_RFCOMM_READ *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_READ))) != NULL) 1482 { 1483 p_msg->hdr.event = BTA_JV_API_RFCOMM_READ_EVT; 1484 p_msg->handle = handle; 1485 p_msg->req_id = req_id; 1486 p_msg->p_data = p_data; 1487 p_msg->len = len; 1488 p_msg->p_cb = &bta_jv_cb.rfc_cb[hi]; 1489 p_msg->p_pcb = &bta_jv_cb.port_cb[p_msg->p_cb->rfc_hdl[si] - 1]; 1490 bta_sys_sendmsg(p_msg); 1491 status = BTA_JV_SUCCESS; 1492 } 1493 1494 return(status); 1495} 1496 1497/******************************************************************************* 1498** 1499** Function BTA_JvRfcommGetPortHdl 1500** 1501** Description This function fetches the rfcomm port handle 1502** 1503** Returns BTA_JV_SUCCESS, if the request is being processed. 1504** BTA_JV_FAILURE, otherwise. 1505** 1506*******************************************************************************/ 1507UINT16 BTA_JvRfcommGetPortHdl(UINT32 handle) 1508{ 1509 UINT32 hi = (handle & BTA_JV_RFC_HDL_MASK) - 1; 1510 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle); 1511 1512 if (hi < BTA_JV_MAX_RFC_CONN && 1513 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si]) 1514 return bta_jv_cb.port_cb[bta_jv_cb.rfc_cb[hi].rfc_hdl[si] - 1].port_handle; 1515 else 1516 return 0xffff; 1517} 1518 1519 1520/******************************************************************************* 1521** 1522** Function BTA_JvRfcommReady 1523** 1524** Description This function determined if there is data to read from 1525** an RFCOMM connection 1526** 1527** Returns BTA_JV_SUCCESS, if data queue size is in *p_data_size. 1528** BTA_JV_FAILURE, if error. 1529** 1530*******************************************************************************/ 1531tBTA_JV_STATUS BTA_JvRfcommReady(UINT32 handle, UINT32 *p_data_size) 1532{ 1533 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1534 UINT16 size = 0; 1535 UINT32 hi = (handle & BTA_JV_RFC_HDL_MASK) - 1; 1536 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle); 1537 1538 APPL_TRACE_API0( "BTA_JvRfcommReady"); 1539 if (hi < BTA_JV_MAX_RFC_CONN && bta_jv_cb.rfc_cb[hi].p_cback && 1540 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si]) 1541 { 1542 if(PORT_GetRxQueueCnt(bta_jv_cb.rfc_cb[hi].rfc_hdl[si], &size) == PORT_SUCCESS) 1543 { 1544 status = BTA_JV_SUCCESS; 1545 } 1546 } 1547 *p_data_size = size; 1548 return(status); 1549} 1550 1551/******************************************************************************* 1552** 1553** Function BTA_JvRfcommWrite 1554** 1555** Description This function writes data to an RFCOMM connection 1556** 1557** Returns BTA_JV_SUCCESS, if the request is being processed. 1558** BTA_JV_FAILURE, otherwise. 1559** 1560*******************************************************************************/ 1561tBTA_JV_STATUS BTA_JvRfcommWrite(UINT32 handle, UINT32 req_id) 1562{ 1563 tBTA_JV_STATUS status = BTA_JV_FAILURE; 1564 tBTA_JV_API_RFCOMM_WRITE *p_msg; 1565 UINT32 hi = (handle & BTA_JV_RFC_HDL_MASK) - 1; 1566 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle); 1567 1568 APPL_TRACE_API0( "BTA_JvRfcommWrite"); 1569 APPL_TRACE_DEBUG3( "handle:0x%x, hi:%d, si:%d", handle, hi, si); 1570 if (hi < BTA_JV_MAX_RFC_CONN && bta_jv_cb.rfc_cb[hi].p_cback && 1571 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si] && 1572 (p_msg = (tBTA_JV_API_RFCOMM_WRITE *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_WRITE))) != NULL) 1573 { 1574 p_msg->hdr.event = BTA_JV_API_RFCOMM_WRITE_EVT; 1575 p_msg->handle = handle; 1576 p_msg->req_id = req_id; 1577 p_msg->p_cb = &bta_jv_cb.rfc_cb[hi]; 1578 p_msg->p_pcb = &bta_jv_cb.port_cb[p_msg->p_cb->rfc_hdl[si] - 1]; 1579 APPL_TRACE_API0( "write ok"); 1580 bta_sys_sendmsg(p_msg); 1581 status = BTA_JV_SUCCESS; 1582 } 1583 1584 return(status); 1585} 1586 1587