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 #include "bta_api.h"
26 #include "bta_sys.h"
27 #include "bta_jv_api.h"
28 #include "bta_jv_int.h"
29 #include "gki.h"
30 #include <string.h>
31 #include "port_api.h"
32 #include "sdp_api.h"
33 #include "utl.h"
34 #include "gap_api.h"
35
36 /*****************************************************************************
37 ** Constants
38 *****************************************************************************/
39
40 static 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 *******************************************************************************/
BTA_JvEnable(tBTA_JV_DM_CBACK * p_cback)60 tBTA_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 int i;
65
66 APPL_TRACE_API( "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));
70 /* 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 }
75
76 /* register with BTA system manager */
77 bta_sys_register(BTA_ID_JV, &bta_jv_reg);
78
79 if (p_cback && (p_buf = (tBTA_JV_API_ENABLE *) GKI_getbuf(sizeof(tBTA_JV_API_ENABLE))) != NULL)
80 {
81 p_buf->hdr.event = BTA_JV_API_ENABLE_EVT;
82 p_buf->p_cback = p_cback;
83 bta_sys_sendmsg(p_buf);
84 status = BTA_JV_SUCCESS;
85 }
86 }
87 else
88 {
89 APPL_TRACE_ERROR("JVenable fails");
90 }
91 return(status);
92 }
93
94 /*******************************************************************************
95 **
96 ** Function BTA_JvDisable
97 **
98 ** Description Disable the Java I/F
99 **
100 ** Returns void
101 **
102 *******************************************************************************/
BTA_JvDisable(void)103 void BTA_JvDisable(void)
104 {
105 BT_HDR *p_buf;
106
107 APPL_TRACE_API( "BTA_JvDisable");
108 bta_sys_deregister(BTA_ID_JV);
109 if ((p_buf = (BT_HDR *) GKI_getbuf(sizeof(BT_HDR))) != NULL)
110 {
111 p_buf->event = BTA_JV_API_DISABLE_EVT;
112 bta_sys_sendmsg(p_buf);
113 }
114 }
115
116 /*******************************************************************************
117 **
118 ** Function BTA_JvIsEnable
119 **
120 ** Description Get the JV registration status.
121 **
122 ** Returns TRUE, if registered
123 **
124 *******************************************************************************/
BTA_JvIsEnable(void)125 BOOLEAN BTA_JvIsEnable(void)
126 {
127 return bta_sys_is_register(BTA_ID_JV);
128 }
129
130 /*******************************************************************************
131 **
132 ** Function BTA_JvIsEncrypted
133 **
134 ** Description This function checks if the link to peer device is encrypted
135 **
136 ** Returns TRUE if encrypted.
137 ** FALSE if not.
138 **
139 *******************************************************************************/
BTA_JvIsEncrypted(BD_ADDR bd_addr)140 BOOLEAN BTA_JvIsEncrypted(BD_ADDR bd_addr)
141 {
142 BOOLEAN is_encrypted = FALSE;
143 UINT8 sec_flags, le_flags;
144
145 if (BTM_GetSecurityFlags(bd_addr, &sec_flags) &&
146 BTM_GetSecurityFlagsByTransport(bd_addr, &le_flags, BT_TRANSPORT_LE))
147 {
148 if(sec_flags & BTM_SEC_FLAG_ENCRYPTED ||
149 le_flags & BTM_SEC_FLAG_ENCRYPTED)
150 is_encrypted = TRUE;
151 }
152 return is_encrypted;
153 }
154 /*******************************************************************************
155 **
156 ** Function BTA_JvGetChannelId
157 **
158 ** Description This function reserves a SCN (server channel number) for
159 ** applications running over RFCOMM, L2CAP of L2CAP_LE.
160 ** It is primarily called by server profiles/applications to
161 ** register their SCN into the SDP database. The SCN is reported
162 ** by the tBTA_JV_DM_CBACK callback with a BTA_JV_GET_SCN_EVT
163 ** for RFCOMM channels and BTA_JV_GET_PSM_EVT for L2CAP and LE.
164 ** If the SCN/PSM reported is 0, that means all resources are
165 ** exhausted.
166 ** Parameters
167 ** conn_type one of BTA_JV_CONN_TYPE_
168 ** user_data Any uservalue - will be returned in the resulting event.
169 ** channel Only used for RFCOMM - to try to allocate a specific RFCOMM
170 ** channel.
171 **
172 ** Returns BTA_JV_SUCCESS, if the request is being processed.
173 ** BTA_JV_FAILURE, otherwise.
174 **
175 *******************************************************************************/
BTA_JvGetChannelId(int conn_type,void * user_data,INT32 channel)176 tBTA_JV_STATUS BTA_JvGetChannelId(int conn_type, void* user_data, INT32 channel)
177 {
178 tBTA_JV_STATUS status = BTA_JV_FAILURE;
179 tBTA_JV_API_ALLOC_CHANNEL *p_msg;
180
181 APPL_TRACE_API( "%s", __func__);
182 if ((p_msg = (tBTA_JV_API_ALLOC_CHANNEL *)GKI_getbuf(sizeof(tBTA_JV_API_ALLOC_CHANNEL))) != NULL)
183 {
184 p_msg->hdr.event = BTA_JV_API_GET_CHANNEL_EVT;
185 p_msg->type = conn_type;
186 p_msg->channel = channel;
187 p_msg->user_data = user_data;
188 bta_sys_sendmsg(p_msg);
189 status = BTA_JV_SUCCESS;
190 }
191
192 return(status);
193 }
194
195 /*******************************************************************************
196 **
197 ** Function BTA_JvFreeChannel
198 **
199 ** Description This function frees a server channel number that was used
200 ** by an application running over RFCOMM.
201 ** Parameters
202 ** channel The channel to free
203 ** conn_type one of BTA_JV_CONN_TYPE_
204 **
205 ** Returns BTA_JV_SUCCESS, if the request is being processed.
206 ** BTA_JV_FAILURE, otherwise.
207 **
208 *******************************************************************************/
BTA_JvFreeChannel(UINT16 channel,int conn_type)209 tBTA_JV_STATUS BTA_JvFreeChannel(UINT16 channel, int conn_type)
210 {
211 tBTA_JV_STATUS status = BTA_JV_FAILURE;
212 tBTA_JV_API_FREE_CHANNEL *p_msg;
213
214 APPL_TRACE_API( "%s", __func__);
215 if ((p_msg = (tBTA_JV_API_FREE_CHANNEL *)GKI_getbuf(sizeof(tBTA_JV_API_FREE_CHANNEL))) != NULL)
216 {
217 p_msg->hdr.event = BTA_JV_API_FREE_SCN_EVT;
218 p_msg->scn = channel;
219 p_msg->type = conn_type;
220 bta_sys_sendmsg(p_msg);
221 status = BTA_JV_SUCCESS;
222 }
223
224 return(status);
225 }
226
227 /*******************************************************************************
228 **
229 ** Function BTA_JvStartDiscovery
230 **
231 ** Description This function performs service discovery for the services
232 ** provided by the given peer device. When the operation is
233 ** complete the tBTA_JV_DM_CBACK callback function will be
234 ** called with a BTA_JV_DISCOVERY_COMP_EVT.
235 **
236 ** Returns BTA_JV_SUCCESS, if the request is being processed.
237 ** BTA_JV_FAILURE, otherwise.
238 **
239 *******************************************************************************/
BTA_JvStartDiscovery(BD_ADDR bd_addr,UINT16 num_uuid,tSDP_UUID * p_uuid_list,void * user_data)240 tBTA_JV_STATUS BTA_JvStartDiscovery(BD_ADDR bd_addr, UINT16 num_uuid,
241 tSDP_UUID *p_uuid_list, void * user_data)
242 {
243 tBTA_JV_STATUS status = BTA_JV_FAILURE;
244 tBTA_JV_API_START_DISCOVERY *p_msg;
245
246 APPL_TRACE_API( "BTA_JvStartDiscovery");
247 if ((p_msg = (tBTA_JV_API_START_DISCOVERY *)GKI_getbuf(sizeof(tBTA_JV_API_START_DISCOVERY))) != NULL)
248 {
249 p_msg->hdr.event = BTA_JV_API_START_DISCOVERY_EVT;
250 bdcpy(p_msg->bd_addr, bd_addr);
251 p_msg->num_uuid = num_uuid;
252 memcpy(p_msg->uuid_list, p_uuid_list, num_uuid * sizeof(tSDP_UUID));
253 p_msg->num_attr = 0;
254 p_msg->user_data = user_data;
255 bta_sys_sendmsg(p_msg);
256 status = BTA_JV_SUCCESS;
257 }
258
259 return(status);
260 }
261
262 /*******************************************************************************
263 **
264 ** Function BTA_JvCreateRecord
265 **
266 ** Description Create a service record in the local SDP database.
267 ** When the operation is complete the tBTA_JV_DM_CBACK callback
268 ** function will be called with a BTA_JV_CREATE_RECORD_EVT.
269 **
270 ** Returns BTA_JV_SUCCESS, if the request is being processed.
271 ** BTA_JV_FAILURE, otherwise.
272 **
273 *******************************************************************************/
BTA_JvCreateRecordByUser(void * user_data)274 tBTA_JV_STATUS BTA_JvCreateRecordByUser(void *user_data)
275 {
276 tBTA_JV_STATUS status = BTA_JV_FAILURE;
277 tBTA_JV_API_CREATE_RECORD *p_msg;
278
279 APPL_TRACE_API( "BTA_JvCreateRecordByUser");
280 if ((p_msg = (tBTA_JV_API_CREATE_RECORD *)GKI_getbuf(sizeof(tBTA_JV_API_CREATE_RECORD))) != NULL)
281 {
282 p_msg->hdr.event = BTA_JV_API_CREATE_RECORD_EVT;
283 p_msg->user_data = user_data;
284 bta_sys_sendmsg(p_msg);
285 status = BTA_JV_SUCCESS;
286 }
287
288 return(status);
289 }
290
291 /*******************************************************************************
292 **
293 ** Function BTA_JvDeleteRecord
294 **
295 ** Description Delete a service record in the local SDP database.
296 **
297 ** Returns BTA_JV_SUCCESS, if the request is being processed.
298 ** BTA_JV_FAILURE, otherwise.
299 **
300 *******************************************************************************/
BTA_JvDeleteRecord(UINT32 handle)301 tBTA_JV_STATUS BTA_JvDeleteRecord(UINT32 handle)
302 {
303 tBTA_JV_STATUS status = BTA_JV_FAILURE;
304 tBTA_JV_API_ADD_ATTRIBUTE *p_msg;
305
306 APPL_TRACE_API( "BTA_JvDeleteRecord");
307 if ((p_msg = (tBTA_JV_API_ADD_ATTRIBUTE *)GKI_getbuf(sizeof(tBTA_JV_API_ADD_ATTRIBUTE))) != NULL)
308 {
309 p_msg->hdr.event = BTA_JV_API_DELETE_RECORD_EVT;
310 p_msg->handle = handle;
311 bta_sys_sendmsg(p_msg);
312 status = BTA_JV_SUCCESS;
313 }
314 return(status);
315 }
316
317 /*******************************************************************************
318 **
319 ** Function BTA_JvL2capConnectLE
320 **
321 ** Description Initiate an LE connection as a L2CAP client to the given BD
322 ** Address.
323 ** When the connection is initiated or failed to initiate,
324 ** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_CL_INIT_EVT
325 ** When the connection is established or failed,
326 ** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
327 **
328 ** Returns BTA_JV_SUCCESS, if the request is being processed.
329 ** BTA_JV_FAILURE, otherwise.
330 **
331 *******************************************************************************/
BTA_JvL2capConnectLE(tBTA_SEC sec_mask,tBTA_JV_ROLE role,const tL2CAP_ERTM_INFO * ertm_info,UINT16 remote_chan,UINT16 rx_mtu,tL2CAP_CFG_INFO * cfg,BD_ADDR peer_bd_addr,tBTA_JV_L2CAP_CBACK * p_cback,void * user_data)332 tBTA_JV_STATUS BTA_JvL2capConnectLE(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
333 const tL2CAP_ERTM_INFO *ertm_info, UINT16 remote_chan,
334 UINT16 rx_mtu, tL2CAP_CFG_INFO *cfg,
335 BD_ADDR peer_bd_addr, tBTA_JV_L2CAP_CBACK *p_cback, void *user_data)
336 {
337 tBTA_JV_STATUS status = BTA_JV_FAILURE;
338 tBTA_JV_API_L2CAP_CONNECT *p_msg;
339
340 APPL_TRACE_API( "%s", __func__);
341
342 if (p_cback &&
343 (p_msg =
344 (tBTA_JV_API_L2CAP_CONNECT *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_CONNECT))) != NULL)
345 {
346 p_msg->hdr.event = BTA_JV_API_L2CAP_CONNECT_LE_EVT;
347 p_msg->sec_mask = sec_mask;
348 p_msg->role = role;
349 p_msg->remote_chan = remote_chan;
350 p_msg->rx_mtu = rx_mtu;
351 if(cfg != NULL) {
352 p_msg->has_cfg = TRUE;
353 p_msg->cfg = *cfg;
354 } else {
355 p_msg->has_cfg = FALSE;
356 }
357 if(ertm_info != NULL) {
358 p_msg->has_ertm_info = TRUE;
359 p_msg->ertm_info = *ertm_info;
360 } else {
361 p_msg->has_ertm_info = FALSE;
362 }
363 memcpy(p_msg->peer_bd_addr, peer_bd_addr, sizeof(BD_ADDR));
364 p_msg->p_cback = p_cback;
365 p_msg->user_data = user_data;
366 bta_sys_sendmsg(p_msg);
367 status = BTA_JV_SUCCESS;
368 }
369
370 return(status);
371 }
372
373 /*******************************************************************************
374 **
375 ** Function BTA_JvL2capConnect
376 **
377 ** Description Initiate a connection as a L2CAP client to the given BD
378 ** Address.
379 ** When the connection is initiated or failed to initiate,
380 ** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_CL_INIT_EVT
381 ** When the connection is established or failed,
382 ** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
383 **
384 ** Returns BTA_JV_SUCCESS, if the request is being processed.
385 ** BTA_JV_FAILURE, otherwise.
386 **
387 *******************************************************************************/
BTA_JvL2capConnect(tBTA_SEC sec_mask,tBTA_JV_ROLE role,const tL2CAP_ERTM_INFO * ertm_info,UINT16 remote_psm,UINT16 rx_mtu,tL2CAP_CFG_INFO * cfg,BD_ADDR peer_bd_addr,tBTA_JV_L2CAP_CBACK * p_cback,void * user_data)388 tBTA_JV_STATUS BTA_JvL2capConnect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
389 const tL2CAP_ERTM_INFO *ertm_info, UINT16 remote_psm,
390 UINT16 rx_mtu, tL2CAP_CFG_INFO *cfg,
391 BD_ADDR peer_bd_addr, tBTA_JV_L2CAP_CBACK *p_cback, void *user_data)
392 {
393 tBTA_JV_STATUS status = BTA_JV_FAILURE;
394 tBTA_JV_API_L2CAP_CONNECT *p_msg;
395
396 APPL_TRACE_API( "%s", __func__);
397
398 if (p_cback &&
399 (p_msg = (tBTA_JV_API_L2CAP_CONNECT *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_CONNECT))) != NULL)
400 {
401 p_msg->hdr.event = BTA_JV_API_L2CAP_CONNECT_EVT;
402 p_msg->sec_mask = sec_mask;
403 p_msg->role = role;
404 p_msg->remote_psm = remote_psm;
405 p_msg->rx_mtu = rx_mtu;
406 if(cfg != NULL) {
407 p_msg->has_cfg = TRUE;
408 p_msg->cfg = *cfg;
409 } else {
410 p_msg->has_cfg = FALSE;
411 }
412 if(ertm_info != NULL) {
413 p_msg->has_ertm_info = TRUE;
414 p_msg->ertm_info = *ertm_info;
415 } else {
416 p_msg->has_ertm_info = FALSE;
417 }
418 memcpy(p_msg->peer_bd_addr, peer_bd_addr, sizeof(BD_ADDR));
419 p_msg->p_cback = p_cback;
420 p_msg->user_data = user_data;
421 bta_sys_sendmsg(p_msg);
422 status = BTA_JV_SUCCESS;
423 }
424
425 return(status);
426 }
427
428 /*******************************************************************************
429 **
430 ** Function BTA_JvL2capClose
431 **
432 ** Description This function closes an L2CAP client connection
433 **
434 ** Returns BTA_JV_SUCCESS, if the request is being processed.
435 ** BTA_JV_FAILURE, otherwise.
436 **
437 *******************************************************************************/
BTA_JvL2capClose(UINT32 handle)438 tBTA_JV_STATUS BTA_JvL2capClose(UINT32 handle)
439 {
440 tBTA_JV_STATUS status = BTA_JV_FAILURE;
441 tBTA_JV_API_L2CAP_CLOSE *p_msg;
442
443 APPL_TRACE_API( "%s", __func__);
444
445 if (handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback &&
446 (p_msg = (tBTA_JV_API_L2CAP_CLOSE *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_CLOSE))) != NULL)
447 {
448 p_msg->hdr.event = BTA_JV_API_L2CAP_CLOSE_EVT;
449 p_msg->handle = handle;
450 p_msg->p_cb = &bta_jv_cb.l2c_cb[handle];
451 bta_sys_sendmsg(p_msg);
452 status = BTA_JV_SUCCESS;
453 }
454
455 return(status);
456 }
457
458 /*******************************************************************************
459 **
460 ** Function BTA_JvL2capCloseLE
461 **
462 ** Description This function closes an L2CAP client connection for Fixed Channels
463 ** Function is idempotent and no callbacks are called!
464 **
465 ** Returns BTA_JV_SUCCESS, if the request is being processed.
466 ** BTA_JV_FAILURE, otherwise.
467 **
468 *******************************************************************************/
BTA_JvL2capCloseLE(UINT32 handle)469 tBTA_JV_STATUS BTA_JvL2capCloseLE(UINT32 handle)
470 {
471 tBTA_JV_STATUS status = BTA_JV_FAILURE;
472 tBTA_JV_API_L2CAP_CLOSE *p_msg;
473
474 APPL_TRACE_API( "%s", __func__);
475
476 if ((p_msg = (tBTA_JV_API_L2CAP_CLOSE *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_CLOSE))) != NULL)
477 {
478 p_msg->hdr.event = BTA_JV_API_L2CAP_CLOSE_FIXED_EVT;
479 p_msg->handle = handle;
480 bta_sys_sendmsg(p_msg);
481 status = BTA_JV_SUCCESS;
482 }
483
484 return(status);
485 }
486
487 /*******************************************************************************
488 **
489 ** Function BTA_JvL2capStartServer
490 **
491 ** Description This function starts an L2CAP server and listens for an L2CAP
492 ** connection from a remote Bluetooth device. When the server
493 ** is started successfully, tBTA_JV_L2CAP_CBACK is called with
494 ** BTA_JV_L2CAP_START_EVT. When the connection is established,
495 ** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT.
496 **
497 ** Returns BTA_JV_SUCCESS, if the request is being processed.
498 ** BTA_JV_FAILURE, otherwise.
499 **
500 *******************************************************************************/
BTA_JvL2capStartServer(tBTA_SEC sec_mask,tBTA_JV_ROLE role,const tL2CAP_ERTM_INFO * ertm_info,UINT16 local_psm,UINT16 rx_mtu,tL2CAP_CFG_INFO * cfg,tBTA_JV_L2CAP_CBACK * p_cback,void * user_data)501 tBTA_JV_STATUS BTA_JvL2capStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
502 const tL2CAP_ERTM_INFO *ertm_info,UINT16 local_psm, UINT16 rx_mtu, tL2CAP_CFG_INFO *cfg,
503 tBTA_JV_L2CAP_CBACK *p_cback, void *user_data)
504 {
505 tBTA_JV_STATUS status = BTA_JV_FAILURE;
506 tBTA_JV_API_L2CAP_SERVER *p_msg;
507
508 APPL_TRACE_API( "%s", __func__);
509
510 if (p_cback &&
511 (p_msg = (tBTA_JV_API_L2CAP_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_SERVER))) != NULL)
512 {
513 p_msg->hdr.event = BTA_JV_API_L2CAP_START_SERVER_EVT;
514 p_msg->sec_mask = sec_mask;
515 p_msg->role = role;
516 p_msg->local_psm = local_psm;
517 p_msg->rx_mtu = rx_mtu;
518 if(cfg != NULL) {
519 p_msg->has_cfg = TRUE;
520 p_msg->cfg = *cfg;
521 } else {
522 p_msg->has_cfg = FALSE;
523 }
524 if(ertm_info != NULL) {
525 p_msg->has_ertm_info = TRUE;
526 p_msg->ertm_info = *ertm_info;
527 } else {
528 p_msg->has_ertm_info = FALSE;
529 }
530 p_msg->p_cback = p_cback;
531 p_msg->user_data = user_data;
532 bta_sys_sendmsg(p_msg);
533 status = BTA_JV_SUCCESS;
534 }
535
536 return(status);
537 }
538
539 /*******************************************************************************
540 **
541 ** Function BTA_JvL2capStartServerLE
542 **
543 ** Description This function starts an LE L2CAP server and listens for an L2CAP
544 ** connection from a remote Bluetooth device. When the server
545 ** is started successfully, tBTA_JV_L2CAP_CBACK is called with
546 ** BTA_JV_L2CAP_START_EVT. When the connection is established,
547 ** tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT.
548 **
549 ** Returns BTA_JV_SUCCESS, if the request is being processed.
550 ** BTA_JV_FAILURE, otherwise.
551 **
552 *******************************************************************************/
BTA_JvL2capStartServerLE(tBTA_SEC sec_mask,tBTA_JV_ROLE role,const tL2CAP_ERTM_INFO * ertm_info,UINT16 local_chan,UINT16 rx_mtu,tL2CAP_CFG_INFO * cfg,tBTA_JV_L2CAP_CBACK * p_cback,void * user_data)553 tBTA_JV_STATUS BTA_JvL2capStartServerLE(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
554 const tL2CAP_ERTM_INFO *ertm_info,UINT16 local_chan, UINT16 rx_mtu, tL2CAP_CFG_INFO *cfg,
555 tBTA_JV_L2CAP_CBACK *p_cback, void *user_data)
556 {
557 tBTA_JV_STATUS status = BTA_JV_FAILURE;
558 tBTA_JV_API_L2CAP_SERVER *p_msg;
559
560 APPL_TRACE_API( "%s", __func__);
561
562 if (p_cback &&
563 (p_msg = (tBTA_JV_API_L2CAP_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_SERVER))) != NULL)
564 {
565 p_msg->hdr.event = BTA_JV_API_L2CAP_START_SERVER_LE_EVT;
566 p_msg->sec_mask = sec_mask;
567 p_msg->role = role;
568 p_msg->local_chan = local_chan;
569 p_msg->rx_mtu = rx_mtu;
570 if(cfg != NULL) {
571 p_msg->has_cfg = TRUE;
572 p_msg->cfg = *cfg;
573 } else {
574 p_msg->has_cfg = FALSE;
575 }
576 if(ertm_info != NULL) {
577 p_msg->has_ertm_info = TRUE;
578 p_msg->ertm_info = *ertm_info;
579 } else {
580 p_msg->has_ertm_info = FALSE;
581 }
582 p_msg->p_cback = p_cback;
583 p_msg->user_data = user_data;
584 bta_sys_sendmsg(p_msg);
585 status = BTA_JV_SUCCESS;
586 }
587
588 return(status);
589 }
590
591 /*******************************************************************************
592 **
593 ** Function BTA_JvL2capStopServer
594 **
595 ** Description This function stops the L2CAP server. If the server has an
596 ** active connection, it would be closed.
597 **
598 ** Returns BTA_JV_SUCCESS, if the request is being processed.
599 ** BTA_JV_FAILURE, otherwise.
600 **
601 *******************************************************************************/
BTA_JvL2capStopServer(UINT16 local_psm,void * user_data)602 tBTA_JV_STATUS BTA_JvL2capStopServer(UINT16 local_psm, void *user_data)
603 {
604 tBTA_JV_STATUS status = BTA_JV_FAILURE;
605 tBTA_JV_API_L2CAP_SERVER *p_msg;
606
607 APPL_TRACE_API( "%s", __func__);
608
609 if ((p_msg = (tBTA_JV_API_L2CAP_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_SERVER))) != NULL)
610 {
611 p_msg->hdr.event = BTA_JV_API_L2CAP_STOP_SERVER_EVT;
612 p_msg->local_psm = local_psm;
613 p_msg->user_data = user_data;
614 bta_sys_sendmsg(p_msg);
615 status = BTA_JV_SUCCESS;
616 }
617
618 return(status);
619 }
620
621 /*******************************************************************************
622 **
623 ** Function BTA_JvL2capStopServerLE
624 **
625 ** Description This function stops the LE L2CAP server. If the server has an
626 ** active connection, it would be closed.
627 **
628 ** Returns BTA_JV_SUCCESS, if the request is being processed.
629 ** BTA_JV_FAILURE, otherwise.
630 **
631 *******************************************************************************/
BTA_JvL2capStopServerLE(UINT16 local_chan,void * user_data)632 tBTA_JV_STATUS BTA_JvL2capStopServerLE(UINT16 local_chan, void *user_data)
633 {
634 tBTA_JV_STATUS status = BTA_JV_FAILURE;
635 tBTA_JV_API_L2CAP_SERVER *p_msg;
636
637 APPL_TRACE_API( "%s", __func__);
638
639 if ((p_msg = (tBTA_JV_API_L2CAP_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_SERVER))) != NULL)
640 {
641 p_msg->hdr.event = BTA_JV_API_L2CAP_STOP_SERVER_LE_EVT;
642 p_msg->local_chan = local_chan;
643 p_msg->user_data = user_data;
644 bta_sys_sendmsg(p_msg);
645 status = BTA_JV_SUCCESS;
646 }
647
648 return(status);
649 }
650
651 /*******************************************************************************
652 **
653 ** Function BTA_JvL2capRead
654 **
655 ** Description This function reads data from an L2CAP connecti;
656 tBTA_JV_RFC_CB *p_cb = rc->p_cb;
657 on
658 ** When the operation is complete, tBTA_JV_L2CAP_CBACK is
659 ** called with BTA_JV_L2CAP_READ_EVT.
660 **
661 ** Returns BTA_JV_SUCCESS, if the request is being processed.
662 ** BTA_JV_FAILURE, otherwise.
663 **
664 *******************************************************************************/
BTA_JvL2capRead(UINT32 handle,UINT32 req_id,UINT8 * p_data,UINT16 len)665 tBTA_JV_STATUS BTA_JvL2capRead(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len)
666 {
667 tBTA_JV_STATUS status = BTA_JV_FAILURE;
668 tBTA_JV_L2CAP_READ evt_data;
669
670 APPL_TRACE_API( "%s", __func__);
671
672
673 if (handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback)
674 {
675 status = BTA_JV_SUCCESS;
676 evt_data.status = BTA_JV_FAILURE;
677 evt_data.handle = handle;
678 evt_data.req_id = req_id;
679 evt_data.p_data = p_data;
680 evt_data.len = 0;
681
682 if (BT_PASS == GAP_ConnReadData((UINT16)handle, p_data, len, &evt_data.len))
683 {
684 evt_data.status = BTA_JV_SUCCESS;
685 }
686 bta_jv_cb.l2c_cb[handle].p_cback(
687 BTA_JV_L2CAP_READ_EVT, (tBTA_JV *)&evt_data, bta_jv_cb.l2c_cb[handle].user_data);
688 }
689
690 return(status);
691 }
692
693 /*******************************************************************************
694 **
695 ** Function BTA_JvL2capReceive
696 **
697 ** Description This function reads data from an L2CAP connection
698 ** When the operation is complete, tBTA_JV_L2CAP_CBACK is
699 ** called with BTA_JV_L2CAP_RECEIVE_EVT.
700 ** If there are more data queued in L2CAP than len, the extra data will be discarded.
701 **
702 ** Returns BTA_JV_SUCCESS, if the request is being processed.
703 ** BTA_JV_FAILURE, otherwise.
704 **
705 *******************************************************************************/
BTA_JvL2capReceive(UINT32 handle,UINT32 req_id,UINT8 * p_data,UINT16 len)706 tBTA_JV_STATUS BTA_JvL2capReceive(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len)
707 {
708 tBTA_JV_STATUS status = BTA_JV_FAILURE;
709 tBTA_JV_L2CAP_RECEIVE evt_data;
710 UINT32 left_over = 0;
711 UINT16 max_len, read_len;
712
713 APPL_TRACE_API( "%s", __func__);
714
715
716 if (handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback)
717 {
718 status = BTA_JV_SUCCESS;
719 evt_data.status = BTA_JV_FAILURE;
720 evt_data.handle = handle;
721 evt_data.req_id = req_id;
722 evt_data.p_data = p_data;
723 evt_data.len = 0;
724
725 if (BT_PASS == GAP_ConnReadData((UINT16)handle, p_data, len, &evt_data.len))
726 {
727 evt_data.status = BTA_JV_SUCCESS;
728 GAP_GetRxQueueCnt ((UINT16)handle, &left_over);
729 while (left_over)
730 {
731 max_len = (left_over > 0xFFFF)?0xFFFF:left_over;
732 GAP_ConnReadData ((UINT16)handle, NULL, max_len, &read_len);
733 left_over -= read_len;
734 }
735 }
736 bta_jv_cb.l2c_cb[handle].p_cback(
737 BTA_JV_L2CAP_RECEIVE_EVT, (tBTA_JV *)&evt_data, bta_jv_cb.l2c_cb[handle].user_data);
738 }
739
740 return(status);
741 }
742 /*******************************************************************************
743 **
744 ** Function BTA_JvL2capReady
745 **
746 ** Description This function determined if there is data to read from
747 ** an L2CAP connection
748 **
749 ** Returns BTA_JV_SUCCESS, if data queue size is in *p_data_size.
750 ** BTA_JV_FAILURE, if error.
751 **
752 *******************************************************************************/
BTA_JvL2capReady(UINT32 handle,UINT32 * p_data_size)753 tBTA_JV_STATUS BTA_JvL2capReady(UINT32 handle, UINT32 *p_data_size)
754 {
755 tBTA_JV_STATUS status = BTA_JV_FAILURE;
756
757 APPL_TRACE_API( "%s: %d", __func__, handle);
758 if (p_data_size && handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback)
759 {
760 *p_data_size = 0;
761 if(BT_PASS == GAP_GetRxQueueCnt((UINT16)handle, p_data_size) )
762 {
763 status = BTA_JV_SUCCESS;
764 }
765 }
766
767 return(status);
768 }
769
770
771 /*******************************************************************************
772 **
773 ** Function BTA_JvL2capWrite
774 **
775 ** Description This function writes data to an L2CAP connection
776 ** When the operation is complete, tBTA_JV_L2CAP_CBACK is
777 ** called with BTA_JV_L2CAP_WRITE_EVT. Works for
778 ** PSM-based connections
779 **
780 ** Returns BTA_JV_SUCCESS, if the request is being processed.
781 ** BTA_JV_FAILURE, otherwise.
782 **
783 *******************************************************************************/
BTA_JvL2capWrite(UINT32 handle,UINT32 req_id,UINT8 * p_data,UINT16 len,void * user_data)784 tBTA_JV_STATUS BTA_JvL2capWrite(UINT32 handle, UINT32 req_id, UINT8 *p_data,
785 UINT16 len, void *user_data)
786 {
787 tBTA_JV_STATUS status = BTA_JV_FAILURE;
788 tBTA_JV_API_L2CAP_WRITE *p_msg;
789
790 APPL_TRACE_API( "%s", __func__);
791
792 if (handle < BTA_JV_MAX_L2C_CONN && bta_jv_cb.l2c_cb[handle].p_cback &&
793 (p_msg = (tBTA_JV_API_L2CAP_WRITE *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_WRITE))) != NULL)
794 {
795 p_msg->hdr.event = BTA_JV_API_L2CAP_WRITE_EVT;
796 p_msg->handle = handle;
797 p_msg->req_id = req_id;
798 p_msg->p_data = p_data;
799 p_msg->p_cb = &bta_jv_cb.l2c_cb[handle];
800 p_msg->len = len;
801 p_msg->user_data = user_data;
802 bta_sys_sendmsg(p_msg);
803 status = BTA_JV_SUCCESS;
804 }
805
806 return(status);
807 }
808
809 /*******************************************************************************
810 **
811 ** Function BTA_JvL2capWriteFixed
812 **
813 ** Description This function writes data to an L2CAP connection
814 ** When the operation is complete, tBTA_JV_L2CAP_CBACK is
815 ** called with BTA_JV_L2CAP_WRITE_EVT. Works for
816 ** fixed-channel connections
817 **
818 ** Returns BTA_JV_SUCCESS, if the request is being processed.
819 ** BTA_JV_FAILURE, otherwise.
820 **
821 *******************************************************************************/
BTA_JvL2capWriteFixed(UINT16 channel,BD_ADDR * addr,UINT32 req_id,tBTA_JV_L2CAP_CBACK * p_cback,UINT8 * p_data,UINT16 len,void * user_data)822 tBTA_JV_STATUS BTA_JvL2capWriteFixed(UINT16 channel, BD_ADDR *addr, UINT32 req_id,
823 tBTA_JV_L2CAP_CBACK *p_cback, UINT8 *p_data, UINT16 len, void *user_data)
824 {
825 tBTA_JV_STATUS status = BTA_JV_FAILURE;
826 tBTA_JV_API_L2CAP_WRITE_FIXED *p_msg;
827
828 APPL_TRACE_API( "%s", __func__);
829
830 if ((p_msg =
831 (tBTA_JV_API_L2CAP_WRITE_FIXED *)GKI_getbuf(sizeof(tBTA_JV_API_L2CAP_WRITE_FIXED))) != NULL)
832 {
833 p_msg->hdr.event = BTA_JV_API_L2CAP_WRITE_FIXED_EVT;
834 p_msg->channel = channel;
835 memcpy(p_msg->addr, addr, sizeof(p_msg->addr));
836 p_msg->req_id = req_id;
837 p_msg->p_data = p_data;
838 p_msg->p_cback = p_cback;
839 p_msg->len = len;
840 p_msg->user_data = user_data;
841 bta_sys_sendmsg(p_msg);
842 status = BTA_JV_SUCCESS;
843 }
844
845 return(status);
846 }
847
848 /*******************************************************************************
849 **
850 ** Function BTA_JvRfcommConnect
851 **
852 ** Description This function makes an RFCOMM conection to a remote BD
853 ** Address.
854 ** When the connection is initiated or failed to initiate,
855 ** tBTA_JV_RFCOMM_CBACK is called with BTA_JV_RFCOMM_CL_INIT_EVT
856 ** When the connection is established or failed,
857 ** tBTA_JV_RFCOMM_CBACK is called with BTA_JV_RFCOMM_OPEN_EVT
858 **
859 ** Returns BTA_JV_SUCCESS, if the request is being processed.
860 ** BTA_JV_FAILURE, otherwise.
861 **
862 *******************************************************************************/
BTA_JvRfcommConnect(tBTA_SEC sec_mask,tBTA_JV_ROLE role,UINT8 remote_scn,BD_ADDR peer_bd_addr,tBTA_JV_RFCOMM_CBACK * p_cback,void * user_data)863 tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask,
864 tBTA_JV_ROLE role, UINT8 remote_scn, BD_ADDR peer_bd_addr,
865 tBTA_JV_RFCOMM_CBACK *p_cback, void* user_data)
866 {
867 tBTA_JV_STATUS status = BTA_JV_FAILURE;
868 tBTA_JV_API_RFCOMM_CONNECT *p_msg;
869
870 APPL_TRACE_API( "BTA_JvRfcommConnect");
871 if (p_cback &&
872 (p_msg = (tBTA_JV_API_RFCOMM_CONNECT *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_CONNECT))) != NULL)
873 {
874 p_msg->hdr.event = BTA_JV_API_RFCOMM_CONNECT_EVT;
875 p_msg->sec_mask = sec_mask;
876 p_msg->role = role;
877 p_msg->remote_scn = remote_scn;
878 memcpy(p_msg->peer_bd_addr, peer_bd_addr, sizeof(BD_ADDR));
879 p_msg->p_cback = p_cback;
880 p_msg->user_data = user_data;
881 bta_sys_sendmsg(p_msg);
882 status = BTA_JV_SUCCESS;
883 }
884
885 return(status);
886 }
887
888 /*******************************************************************************
889 **
890 ** Function BTA_JvRfcommClose
891 **
892 ** Description This function closes an RFCOMM connection
893 **
894 ** Returns BTA_JV_SUCCESS, if the request is being processed.
895 ** BTA_JV_FAILURE, otherwise.
896 **
897 *******************************************************************************/
BTA_JvRfcommClose(UINT32 handle,void * user_data)898 tBTA_JV_STATUS BTA_JvRfcommClose(UINT32 handle, void *user_data)
899 {
900 tBTA_JV_STATUS status = BTA_JV_FAILURE;
901 tBTA_JV_API_RFCOMM_CLOSE *p_msg;
902 UINT32 hi = ((handle & BTA_JV_RFC_HDL_MASK)&~BTA_JV_RFCOMM_MASK) - 1;
903 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle);
904
905 APPL_TRACE_API( "BTA_JvRfcommClose");
906 if (hi < BTA_JV_MAX_RFC_CONN && bta_jv_cb.rfc_cb[hi].p_cback &&
907 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si] &&
908 (p_msg = (tBTA_JV_API_RFCOMM_CLOSE *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_CLOSE))) != NULL)
909 {
910 p_msg->hdr.event = BTA_JV_API_RFCOMM_CLOSE_EVT;
911 p_msg->handle = handle;
912 p_msg->p_cb = &bta_jv_cb.rfc_cb[hi];
913 p_msg->p_pcb = &bta_jv_cb.port_cb[p_msg->p_cb->rfc_hdl[si] - 1];
914 p_msg->user_data = user_data;
915 bta_sys_sendmsg(p_msg);
916 status = BTA_JV_SUCCESS;
917 }
918
919 return(status);
920 }
921
922 /*******************************************************************************
923 **
924 ** Function BTA_JvRfcommStartServer
925 **
926 ** Description This function starts listening for an RFCOMM connection
927 ** request from a remote Bluetooth device. When the server is
928 ** started successfully, tBTA_JV_RFCOMM_CBACK is called
929 ** with BTA_JV_RFCOMM_START_EVT.
930 ** When the connection is established, tBTA_JV_RFCOMM_CBACK
931 ** is called with BTA_JV_RFCOMM_OPEN_EVT.
932 **
933 ** Returns BTA_JV_SUCCESS, if the request is being processed.
934 ** BTA_JV_FAILURE, otherwise.
935 **
936 *******************************************************************************/
BTA_JvRfcommStartServer(tBTA_SEC sec_mask,tBTA_JV_ROLE role,UINT8 local_scn,UINT8 max_session,tBTA_JV_RFCOMM_CBACK * p_cback,void * user_data)937 tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask,
938 tBTA_JV_ROLE role, UINT8 local_scn, UINT8 max_session,
939 tBTA_JV_RFCOMM_CBACK *p_cback, void* user_data)
940 {
941 tBTA_JV_STATUS status = BTA_JV_FAILURE;
942 tBTA_JV_API_RFCOMM_SERVER *p_msg;
943
944 APPL_TRACE_API( "BTA_JvRfcommStartServer");
945 if (p_cback &&
946 (p_msg = (tBTA_JV_API_RFCOMM_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_SERVER))) != NULL)
947 {
948 if (max_session == 0)
949 max_session = 1;
950 if (max_session > BTA_JV_MAX_RFC_SR_SESSION)
951 {
952 APPL_TRACE_DEBUG( "max_session is too big. use max (%d)", max_session, BTA_JV_MAX_RFC_SR_SESSION);
953 max_session = BTA_JV_MAX_RFC_SR_SESSION;
954 }
955 p_msg->hdr.event = BTA_JV_API_RFCOMM_START_SERVER_EVT;
956 p_msg->sec_mask = sec_mask;
957 p_msg->role = role;
958 p_msg->local_scn = local_scn;
959 p_msg->max_session = max_session;
960 p_msg->p_cback = p_cback;
961 p_msg->user_data = user_data; //caller's private data
962 bta_sys_sendmsg(p_msg);
963 status = BTA_JV_SUCCESS;
964 }
965
966 return(status);
967 }
968
969 /*******************************************************************************
970 **
971 ** Function BTA_JvRfcommStopServer
972 **
973 ** Description This function stops the RFCOMM server. If the server has an
974 ** active connection, it would be closed.
975 **
976 ** Returns BTA_JV_SUCCESS, if the request is being processed.
977 ** BTA_JV_FAILURE, otherwise.
978 **
979 *******************************************************************************/
BTA_JvRfcommStopServer(UINT32 handle,void * user_data)980 tBTA_JV_STATUS BTA_JvRfcommStopServer(UINT32 handle, void * user_data)
981 {
982 tBTA_JV_STATUS status = BTA_JV_FAILURE;
983 tBTA_JV_API_RFCOMM_SERVER *p_msg;
984 APPL_TRACE_API( "BTA_JvRfcommStopServer");
985 if ((p_msg = (tBTA_JV_API_RFCOMM_SERVER *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_SERVER))) != NULL)
986 {
987 p_msg->hdr.event = BTA_JV_API_RFCOMM_STOP_SERVER_EVT;
988 p_msg->handle = handle;
989 p_msg->user_data = user_data; //caller's private data
990 bta_sys_sendmsg(p_msg);
991 status = BTA_JV_SUCCESS;
992 }
993
994 return(status);
995 }
996
997 /*******************************************************************************
998 **
999 ** Function BTA_JvRfcommRead
1000 **
1001 ** Description This function reads data from an RFCOMM connection
1002 ** The actual size of data read is returned in p_len.
1003 **
1004 ** Returns BTA_JV_SUCCESS, if the request is being processed.
1005 ** BTA_JV_FAILURE, otherwise.
1006 **
1007 *******************************************************************************/
BTA_JvRfcommRead(UINT32 handle,UINT32 req_id,UINT8 * p_data,UINT16 len)1008 tBTA_JV_STATUS BTA_JvRfcommRead(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len)
1009 {
1010 tBTA_JV_STATUS status = BTA_JV_FAILURE;
1011 tBTA_JV_API_RFCOMM_READ *p_msg;
1012 UINT32 hi = ((handle & BTA_JV_RFC_HDL_MASK)&~BTA_JV_RFCOMM_MASK) - 1;
1013 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle);
1014
1015 APPL_TRACE_API( "BTA_JvRfcommRead");
1016 if (hi < BTA_JV_MAX_RFC_CONN && bta_jv_cb.rfc_cb[hi].p_cback &&
1017 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si] &&
1018 (p_msg = (tBTA_JV_API_RFCOMM_READ *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_READ))) != NULL)
1019 {
1020 p_msg->hdr.event = BTA_JV_API_RFCOMM_READ_EVT;
1021 p_msg->handle = handle;
1022 p_msg->req_id = req_id;
1023 p_msg->p_data = p_data;
1024 p_msg->len = len;
1025 p_msg->p_cb = &bta_jv_cb.rfc_cb[hi];
1026 p_msg->p_pcb = &bta_jv_cb.port_cb[p_msg->p_cb->rfc_hdl[si] - 1];
1027 bta_sys_sendmsg(p_msg);
1028 status = BTA_JV_SUCCESS;
1029 }
1030
1031 return(status);
1032 }
1033
1034 /*******************************************************************************
1035 **
1036 ** Function BTA_JvRfcommGetPortHdl
1037 **
1038 ** Description This function fetches the rfcomm port handle
1039 **
1040 ** Returns BTA_JV_SUCCESS, if the request is being processed.
1041 ** BTA_JV_FAILURE, otherwise.
1042 **
1043 *******************************************************************************/
BTA_JvRfcommGetPortHdl(UINT32 handle)1044 UINT16 BTA_JvRfcommGetPortHdl(UINT32 handle)
1045 {
1046 UINT32 hi = ((handle & BTA_JV_RFC_HDL_MASK) & ~BTA_JV_RFCOMM_MASK) - 1;
1047 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle);
1048
1049 if (hi < BTA_JV_MAX_RFC_CONN &&
1050 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si])
1051 return bta_jv_cb.port_cb[bta_jv_cb.rfc_cb[hi].rfc_hdl[si] - 1].port_handle;
1052 else
1053 return 0xffff;
1054 }
1055
1056
1057 /*******************************************************************************
1058 **
1059 ** Function BTA_JvRfcommReady
1060 **
1061 ** Description This function determined if there is data to read from
1062 ** an RFCOMM connection
1063 **
1064 ** Returns BTA_JV_SUCCESS, if data queue size is in *p_data_size.
1065 ** BTA_JV_FAILURE, if error.
1066 **
1067 *******************************************************************************/
BTA_JvRfcommReady(UINT32 handle,UINT32 * p_data_size)1068 tBTA_JV_STATUS BTA_JvRfcommReady(UINT32 handle, UINT32 *p_data_size)
1069 {
1070 tBTA_JV_STATUS status = BTA_JV_FAILURE;
1071 UINT16 size = 0;
1072 UINT32 hi = ((handle & BTA_JV_RFC_HDL_MASK)&~BTA_JV_RFCOMM_MASK) - 1;
1073 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle);
1074
1075 APPL_TRACE_API( "BTA_JvRfcommReady");
1076 if (hi < BTA_JV_MAX_RFC_CONN && bta_jv_cb.rfc_cb[hi].p_cback &&
1077 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si])
1078 {
1079 if(PORT_GetRxQueueCnt(bta_jv_cb.rfc_cb[hi].rfc_hdl[si], &size) == PORT_SUCCESS)
1080 {
1081 status = BTA_JV_SUCCESS;
1082 }
1083 }
1084 *p_data_size = size;
1085 return(status);
1086 }
1087
1088 /*******************************************************************************
1089 **
1090 ** Function BTA_JvRfcommWrite
1091 **
1092 ** Description This function writes data to an RFCOMM connection
1093 **
1094 ** Returns BTA_JV_SUCCESS, if the request is being processed.
1095 ** BTA_JV_FAILURE, otherwise.
1096 **
1097 *******************************************************************************/
BTA_JvRfcommWrite(UINT32 handle,UINT32 req_id)1098 tBTA_JV_STATUS BTA_JvRfcommWrite(UINT32 handle, UINT32 req_id)
1099 {
1100 tBTA_JV_STATUS status = BTA_JV_FAILURE;
1101 tBTA_JV_API_RFCOMM_WRITE *p_msg;
1102 UINT32 hi = ((handle & BTA_JV_RFC_HDL_MASK)&~BTA_JV_RFCOMM_MASK) - 1;
1103 UINT32 si = BTA_JV_RFC_HDL_TO_SIDX(handle);
1104
1105 APPL_TRACE_API( "BTA_JvRfcommWrite");
1106 APPL_TRACE_DEBUG( "handle:0x%x, hi:%d, si:%d", handle, hi, si);
1107 if (hi < BTA_JV_MAX_RFC_CONN && bta_jv_cb.rfc_cb[hi].p_cback &&
1108 si < BTA_JV_MAX_RFC_SR_SESSION && bta_jv_cb.rfc_cb[hi].rfc_hdl[si] &&
1109 (p_msg = (tBTA_JV_API_RFCOMM_WRITE *)GKI_getbuf(sizeof(tBTA_JV_API_RFCOMM_WRITE))) != NULL)
1110 {
1111 p_msg->hdr.event = BTA_JV_API_RFCOMM_WRITE_EVT;
1112 p_msg->handle = handle;
1113 p_msg->req_id = req_id;
1114 p_msg->p_cb = &bta_jv_cb.rfc_cb[hi];
1115 p_msg->p_pcb = &bta_jv_cb.port_cb[p_msg->p_cb->rfc_hdl[si] - 1];
1116 APPL_TRACE_API( "write ok");
1117 bta_sys_sendmsg(p_msg);
1118 status = BTA_JV_SUCCESS;
1119 }
1120
1121 return(status);
1122 }
1123
1124
1125 /*******************************************************************************
1126 **
1127 ** Function BTA_JVSetPmProfile
1128 **
1129 ** Description This function set or free power mode profile for different JV application
1130 **
1131 ** Parameters: handle, JV handle from RFCOMM or L2CAP
1132 ** app_id: app specific pm ID, can be BTA_JV_PM_ALL, see bta_dm_cfg.c for details
1133 ** BTA_JV_PM_ID_CLEAR: removes pm management on the handle. init_st is ignored and
1134 ** BTA_JV_CONN_CLOSE is called implicitely
1135 ** init_st: state after calling this API. typically it should be BTA_JV_CONN_OPEN
1136 **
1137 ** Returns BTA_JV_SUCCESS, if the request is being processed.
1138 ** BTA_JV_FAILURE, otherwise.
1139 **
1140 ** NOTE: BTA_JV_PM_ID_CLEAR: In general no need to be called as jv pm calls automatically
1141 ** BTA_JV_CONN_CLOSE to remove in case of connection close!
1142 **
1143 *******************************************************************************/
BTA_JvSetPmProfile(UINT32 handle,tBTA_JV_PM_ID app_id,tBTA_JV_CONN_STATE init_st)1144 tBTA_JV_STATUS BTA_JvSetPmProfile(UINT32 handle, tBTA_JV_PM_ID app_id, tBTA_JV_CONN_STATE init_st)
1145 {
1146 tBTA_JV_STATUS status = BTA_JV_FAILURE;
1147 tBTA_JV_API_SET_PM_PROFILE *p_msg;
1148
1149 APPL_TRACE_API("BTA_JVSetPmProfile handle:0x%x, app_id:%d", handle, app_id);
1150 if ((p_msg = (tBTA_JV_API_SET_PM_PROFILE *)GKI_getbuf(sizeof(tBTA_JV_API_SET_PM_PROFILE)))
1151 != NULL)
1152 {
1153 p_msg->hdr.event = BTA_JV_API_SET_PM_PROFILE_EVT;
1154 p_msg->handle = handle;
1155 p_msg->app_id = app_id;
1156 p_msg->init_st = init_st;
1157 bta_sys_sendmsg(p_msg);
1158 status = BTA_JV_SUCCESS;
1159 }
1160
1161 return (status);
1162 }
1163