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