1 /******************************************************************************
2 *
3 * Copyright 2006-2012 Broadcom Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 ******************************************************************************/
18
19 /******************************************************************************
20 *
21 * This is the implementation of the JAVA API for Bluetooth Wireless
22 * Technology (JABWT) as specified by the JSR82 specificiation
23 *
24 ******************************************************************************/
25
26 #include <base/functional/bind.h>
27 #include <base/location.h>
28 #include <base/logging.h>
29
30 #include <cstdint>
31 #include <memory>
32
33 #include "bt_target.h" // Must be first to define build configuration
34 #include "bta/jv/bta_jv_int.h"
35 #include "osi/include/allocator.h"
36 #include "stack/include/bt_hdr.h"
37 #include "stack/include/btu.h" // do_in_main_thread
38 #include "stack/include/gap_api.h"
39 #include "types/bluetooth/uuid.h"
40 #include "types/raw_address.h"
41
42 using base::Bind;
43 using bluetooth::Uuid;
44
45 namespace {
46 bool bta_jv_enabled = false;
47 }
48
49 /*******************************************************************************
50 *
51 * Function BTA_JvEnable
52 *
53 * Description Enable the Java I/F service. When the enable
54 * operation is complete the callback function will be
55 * called with a BTA_JV_ENABLE_EVT. This function must
56 * be called before other function in the JV API are
57 * called.
58 *
59 * Returns BTA_JV_SUCCESS if successful.
60 * BTA_JV_FAIL if internal failure.
61 *
62 ******************************************************************************/
BTA_JvEnable(tBTA_JV_DM_CBACK * p_cback)63 tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback) {
64 if (!p_cback || bta_jv_enabled) {
65 LOG(ERROR) << __func__ << ": failure";
66 return BTA_JV_FAILURE;
67 }
68
69 VLOG(2) << __func__;
70
71 memset(&bta_jv_cb, 0, sizeof(tBTA_JV_CB));
72 /* set handle to invalid value by default */
73 for (int i = 0; i < BTA_JV_PM_MAX_NUM; i++) {
74 bta_jv_cb.pm_cb[i].handle = BTA_JV_PM_HANDLE_CLEAR;
75 }
76 bta_jv_cb.dyn_psm = 0xfff;
77 used_l2cap_classic_dynamic_psm = {};
78
79 bta_jv_enabled = true;
80
81 do_in_main_thread(FROM_HERE, Bind(&bta_jv_enable, p_cback));
82 return BTA_JV_SUCCESS;
83 }
84
85 /** Disable the Java I/F */
BTA_JvDisable(void)86 void BTA_JvDisable(void) {
87 VLOG(2) << __func__;
88
89 bta_jv_enabled = false;
90
91 do_in_main_thread(FROM_HERE, Bind(&bta_jv_disable));
92 }
93
94 /*******************************************************************************
95 *
96 * Function BTA_JvGetChannelId
97 *
98 * Description This function reserves a SCN (server channel number) for
99 * applications running over RFCOMM, L2CAP of L2CAP_LE.
100 * It is primarily called by server profiles/applications to
101 * register their SCN into the SDP database. The SCN is
102 * reported by the tBTA_JV_DM_CBACK callback with a
103 * BTA_JV_GET_SCN_EVT for RFCOMM channels and
104 * BTA_JV_GET_PSM_EVT for L2CAP and LE.
105 * If the SCN/PSM reported is 0, that means all resources are
106 * exhausted.
107 * Parameters
108 * conn_type one of BTA_JV_CONN_TYPE_
109 * user_data Any uservalue - will be returned in the resulting event.
110 * channel Only used for RFCOMM - to try to allocate a specific RFCOMM
111 * channel.
112 *
113 * Returns void
114 *
115 ******************************************************************************/
BTA_JvGetChannelId(int conn_type,uint32_t id,int32_t channel)116 void BTA_JvGetChannelId(int conn_type, uint32_t id, int32_t channel) {
117 VLOG(2) << __func__ << ": conn_type=" << conn_type;
118
119 if (conn_type != BTA_JV_CONN_TYPE_RFCOMM &&
120 conn_type != BTA_JV_CONN_TYPE_L2CAP &&
121 conn_type != BTA_JV_CONN_TYPE_L2CAP_LE) {
122 CHECK(false) << "Invalid conn_type=" << conn_type;
123 }
124
125 do_in_main_thread(FROM_HERE,
126 Bind(&bta_jv_get_channel_id, conn_type, channel, id, id));
127 }
128
129 /*******************************************************************************
130 *
131 * Function BTA_JvFreeChannel
132 *
133 * Description This function frees a server channel number that was used
134 * by an application running over RFCOMM.
135 * Parameters
136 * channel The channel to free
137 * conn_type one of BTA_JV_CONN_TYPE_
138 *
139 * Returns BTA_JV_SUCCESS, if the request is being processed.
140 * BTA_JV_FAILURE, otherwise.
141 *
142 ******************************************************************************/
BTA_JvFreeChannel(uint16_t channel,int conn_type)143 tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, int conn_type) {
144 VLOG(2) << __func__;
145
146 do_in_main_thread(FROM_HERE, Bind(&bta_jv_free_scn, conn_type, channel));
147 return BTA_JV_SUCCESS;
148 }
149
150 /*******************************************************************************
151 *
152 * Function BTA_JvStartDiscovery
153 *
154 * Description This function performs service discovery for the services
155 * provided by the given peer device. When the operation is
156 * complete the tBTA_JV_DM_CBACK callback function will be
157 * called with a BTA_JV_DISCOVERY_COMP_EVT.
158 *
159 * Returns BTA_JV_SUCCESS, if the request is being processed.
160 * BTA_JV_FAILURE, otherwise.
161 *
162 ******************************************************************************/
BTA_JvStartDiscovery(const RawAddress & bd_addr,uint16_t num_uuid,const Uuid * p_uuid_list,uint32_t rfcomm_slot_id)163 tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr,
164 uint16_t num_uuid, const Uuid* p_uuid_list,
165 uint32_t rfcomm_slot_id) {
166 VLOG(2) << __func__;
167
168 Uuid* uuid_list_copy = new Uuid[num_uuid];
169 memcpy(uuid_list_copy, p_uuid_list, num_uuid * sizeof(Uuid));
170
171 do_in_main_thread(FROM_HERE,
172 Bind(&bta_jv_start_discovery, bd_addr, num_uuid,
173 base::Owned(uuid_list_copy), rfcomm_slot_id));
174 return BTA_JV_SUCCESS;
175 }
176
177 /*******************************************************************************
178 *
179 * Function BTA_JvCreateRecord
180 *
181 * Description Create a service record in the local SDP database.
182 * When the operation is complete the tBTA_JV_DM_CBACK callback
183 * function will be called with a BTA_JV_CREATE_RECORD_EVT.
184 *
185 * Returns BTA_JV_SUCCESS, if the request is being processed.
186 * BTA_JV_FAILURE, otherwise.
187 *
188 ******************************************************************************/
BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id)189 tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id) {
190 VLOG(2) << __func__;
191
192 do_in_main_thread(FROM_HERE, Bind(&bta_jv_create_record, rfcomm_slot_id));
193 return BTA_JV_SUCCESS;
194 }
195
196 /*******************************************************************************
197 *
198 * Function BTA_JvDeleteRecord
199 *
200 * Description Delete a service record in the local SDP database.
201 *
202 * Returns BTA_JV_SUCCESS, if the request is being processed.
203 * BTA_JV_FAILURE, otherwise.
204 *
205 ******************************************************************************/
BTA_JvDeleteRecord(uint32_t handle)206 tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle) {
207 VLOG(2) << __func__;
208
209 do_in_main_thread(FROM_HERE, Bind(&bta_jv_delete_record, handle));
210 return BTA_JV_SUCCESS;
211 }
212
213 /*******************************************************************************
214 *
215 * Function BTA_JvL2capConnect
216 *
217 * Description Initiate a connection as a L2CAP client to the given BD
218 * Address.
219 * When the connection is initiated or failed to initiate,
220 * tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_CL_INIT_EVT
221 * When the connection is established or failed,
222 * tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
223 *
224 ******************************************************************************/
BTA_JvL2capConnect(int conn_type,tBTA_SEC sec_mask,tBTA_JV_ROLE role,std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,uint16_t remote_psm,uint16_t rx_mtu,std::unique_ptr<tL2CAP_CFG_INFO> cfg,const RawAddress & peer_bd_addr,tBTA_JV_L2CAP_CBACK * p_cback,uint32_t l2cap_socket_id)225 void BTA_JvL2capConnect(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
226 std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,
227 uint16_t remote_psm, uint16_t rx_mtu,
228 std::unique_ptr<tL2CAP_CFG_INFO> cfg,
229 const RawAddress& peer_bd_addr,
230 tBTA_JV_L2CAP_CBACK* p_cback,
231 uint32_t l2cap_socket_id) {
232 VLOG(2) << __func__;
233 CHECK(p_cback);
234
235 do_in_main_thread(FROM_HERE,
236 Bind(&bta_jv_l2cap_connect, conn_type, sec_mask, role,
237 remote_psm, rx_mtu, peer_bd_addr, base::Passed(&cfg),
238 base::Passed(&ertm_info), p_cback, l2cap_socket_id));
239 }
240
241 /*******************************************************************************
242 *
243 * Function BTA_JvL2capClose
244 *
245 * Description This function closes an L2CAP client connection
246 *
247 * Returns BTA_JV_SUCCESS, if the request is being processed.
248 * BTA_JV_FAILURE, otherwise.
249 *
250 ******************************************************************************/
BTA_JvL2capClose(uint32_t handle)251 tBTA_JV_STATUS BTA_JvL2capClose(uint32_t handle) {
252 VLOG(2) << __func__;
253
254 if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback)
255 return BTA_JV_FAILURE;
256
257 do_in_main_thread(
258 FROM_HERE, Bind(&bta_jv_l2cap_close, handle, &bta_jv_cb.l2c_cb[handle]));
259 return BTA_JV_SUCCESS;
260 }
261
262 /*******************************************************************************
263 *
264 * Function BTA_JvL2capStartServer
265 *
266 * Description This function starts an L2CAP server and listens for an
267 * L2CAP connection from a remote Bluetooth device. When the
268 * server is started successfully, tBTA_JV_L2CAP_CBACK is
269 * called with BTA_JV_L2CAP_START_EVT. When the connection is
270 * established tBTA_JV_L2CAP_CBACK is called with
271 * BTA_JV_L2CAP_OPEN_EVT.
272 *
273 * Returns void
274 *
275 ******************************************************************************/
BTA_JvL2capStartServer(int conn_type,tBTA_SEC sec_mask,tBTA_JV_ROLE role,std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,uint16_t local_psm,uint16_t rx_mtu,std::unique_ptr<tL2CAP_CFG_INFO> cfg,tBTA_JV_L2CAP_CBACK * p_cback,uint32_t l2cap_socket_id)276 void BTA_JvL2capStartServer(int conn_type, tBTA_SEC sec_mask, tBTA_JV_ROLE role,
277 std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,
278 uint16_t local_psm, uint16_t rx_mtu,
279 std::unique_ptr<tL2CAP_CFG_INFO> cfg,
280 tBTA_JV_L2CAP_CBACK* p_cback,
281 uint32_t l2cap_socket_id) {
282 VLOG(2) << __func__;
283 CHECK(p_cback);
284
285 do_in_main_thread(FROM_HERE,
286 Bind(&bta_jv_l2cap_start_server, conn_type, sec_mask, role,
287 local_psm, rx_mtu, base::Passed(&cfg),
288 base::Passed(&ertm_info), p_cback, l2cap_socket_id));
289 }
290
291 /*******************************************************************************
292 *
293 * Function BTA_JvL2capStopServer
294 *
295 * Description This function stops the L2CAP server. If the server has an
296 * active connection, it would be closed.
297 *
298 * Returns BTA_JV_SUCCESS, if the request is being processed.
299 * BTA_JV_FAILURE, otherwise.
300 *
301 ******************************************************************************/
BTA_JvL2capStopServer(uint16_t local_psm,uint32_t l2cap_socket_id)302 tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm,
303 uint32_t l2cap_socket_id) {
304 VLOG(2) << __func__;
305
306 do_in_main_thread(
307 FROM_HERE, Bind(&bta_jv_l2cap_stop_server, local_psm, l2cap_socket_id));
308 return BTA_JV_SUCCESS;
309 }
310
311 /*******************************************************************************
312 *
313 * Function BTA_JvL2capRead
314 *
315 * Description This function reads data from an L2CAP connection
316 * When the operation is complete, tBTA_JV_L2CAP_CBACK is
317 * called with BTA_JV_L2CAP_READ_EVT.
318 *
319 * Returns BTA_JV_SUCCESS, if the request is being processed.
320 * BTA_JV_FAILURE, otherwise.
321 *
322 ******************************************************************************/
BTA_JvL2capRead(uint32_t handle,uint32_t req_id,uint8_t * p_data,uint16_t len)323 tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
324 uint8_t* p_data, uint16_t len) {
325 VLOG(2) << __func__;
326
327 if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback)
328 return BTA_JV_FAILURE;
329
330 tBTA_JV_L2CAP_READ evt_data;
331 evt_data.status = BTA_JV_FAILURE;
332 evt_data.handle = handle;
333 evt_data.req_id = req_id;
334 evt_data.p_data = p_data;
335 evt_data.len = 0;
336
337 if (BT_PASS ==
338 GAP_ConnReadData((uint16_t)handle, p_data, len, &evt_data.len)) {
339 evt_data.status = BTA_JV_SUCCESS;
340 }
341 bta_jv_cb.l2c_cb[handle].p_cback(BTA_JV_L2CAP_READ_EVT, (tBTA_JV*)&evt_data,
342 bta_jv_cb.l2c_cb[handle].l2cap_socket_id);
343 return BTA_JV_SUCCESS;
344 }
345
346 /*******************************************************************************
347 *
348 * Function BTA_JvL2capReady
349 *
350 * Description This function determined if there is data to read from
351 * an L2CAP connection
352 *
353 * Returns BTA_JV_SUCCESS, if data queue size is in *p_data_size.
354 * BTA_JV_FAILURE, if error.
355 *
356 ******************************************************************************/
BTA_JvL2capReady(uint32_t handle,uint32_t * p_data_size)357 tBTA_JV_STATUS BTA_JvL2capReady(uint32_t handle, uint32_t* p_data_size) {
358 tBTA_JV_STATUS status = BTA_JV_FAILURE;
359
360 VLOG(2) << __func__ << ": handle=" << handle;
361 if (p_data_size && handle < BTA_JV_MAX_L2C_CONN &&
362 bta_jv_cb.l2c_cb[handle].p_cback) {
363 *p_data_size = 0;
364 if (BT_PASS == GAP_GetRxQueueCnt((uint16_t)handle, p_data_size)) {
365 status = BTA_JV_SUCCESS;
366 }
367 }
368
369 return (status);
370 }
371
372 /*******************************************************************************
373 *
374 * Function BTA_JvL2capWrite
375 *
376 * Description This function writes data to an L2CAP connection
377 * When the operation is complete, tBTA_JV_L2CAP_CBACK is
378 * called with BTA_JV_L2CAP_WRITE_EVT. Works for
379 * PSM-based connections. This function takes ownership of
380 * p_data, and will osi_free it. Data length must be smaller
381 * than remote maximum SDU size.
382 *
383 * Returns BTA_JV_SUCCESS, if the request is being processed.
384 * BTA_JV_FAILURE, otherwise.
385 *
386 ******************************************************************************/
BTA_JvL2capWrite(uint32_t handle,uint32_t req_id,BT_HDR * msg,uint32_t user_id)387 tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg,
388 uint32_t user_id) {
389 VLOG(2) << __func__;
390
391 if (handle >= BTA_JV_MAX_L2C_CONN || !bta_jv_cb.l2c_cb[handle].p_cback) {
392 osi_free(msg);
393 return BTA_JV_FAILURE;
394 }
395
396 do_in_main_thread(FROM_HERE, Bind(&bta_jv_l2cap_write, handle, req_id, msg,
397 user_id, &bta_jv_cb.l2c_cb[handle]));
398 return BTA_JV_SUCCESS;
399 }
400
401 /*******************************************************************************
402 *
403 * Function BTA_JvRfcommConnect
404 *
405 * Description This function makes an RFCOMM conection to a remote BD
406 * Address.
407 * When the connection is initiated or failed to initiate,
408 * tBTA_JV_RFCOMM_CBACK is called with
409 * BTA_JV_RFCOMM_CL_INIT_EVT
410 * When the connection is established or failed,
411 * tBTA_JV_RFCOMM_CBACK is called with BTA_JV_RFCOMM_OPEN_EVT
412 *
413 * Returns BTA_JV_SUCCESS, if the request is being processed.
414 * BTA_JV_FAILURE, otherwise.
415 *
416 ******************************************************************************/
BTA_JvRfcommConnect(tBTA_SEC sec_mask,tBTA_JV_ROLE role,uint8_t remote_scn,const RawAddress & peer_bd_addr,tBTA_JV_RFCOMM_CBACK * p_cback,uint32_t rfcomm_slot_id)417 tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
418 uint8_t remote_scn,
419 const RawAddress& peer_bd_addr,
420 tBTA_JV_RFCOMM_CBACK* p_cback,
421 uint32_t rfcomm_slot_id) {
422 VLOG(2) << __func__;
423
424 if (!p_cback) return BTA_JV_FAILURE; /* Nothing to do */
425
426 do_in_main_thread(FROM_HERE,
427 Bind(&bta_jv_rfcomm_connect, sec_mask, remote_scn,
428 peer_bd_addr, p_cback, rfcomm_slot_id));
429 return BTA_JV_SUCCESS;
430 }
431
432 /*******************************************************************************
433 *
434 * Function BTA_JvRfcommClose
435 *
436 * Description This function closes an RFCOMM connection
437 *
438 * Returns BTA_JV_SUCCESS, if the request is being processed.
439 * BTA_JV_FAILURE, otherwise.
440 *
441 ******************************************************************************/
BTA_JvRfcommClose(uint32_t handle,uint32_t rfcomm_slot_id)442 tBTA_JV_STATUS BTA_JvRfcommClose(uint32_t handle, uint32_t rfcomm_slot_id) {
443 uint32_t hi = ((handle & BTA_JV_RFC_HDL_MASK) & ~BTA_JV_RFCOMM_MASK) - 1;
444 uint32_t si = BTA_JV_RFC_HDL_TO_SIDX(handle);
445
446 VLOG(2) << __func__;
447
448 if (hi >= BTA_JV_MAX_RFC_CONN || !bta_jv_cb.rfc_cb[hi].p_cback ||
449 si >= BTA_JV_MAX_RFC_SR_SESSION || !bta_jv_cb.rfc_cb[hi].rfc_hdl[si])
450 return BTA_JV_FAILURE;
451
452 do_in_main_thread(FROM_HERE,
453 Bind(&bta_jv_rfcomm_close, handle, rfcomm_slot_id));
454 return BTA_JV_SUCCESS;
455 }
456
457 /*******************************************************************************
458 *
459 * Function BTA_JvRfcommStartServer
460 *
461 * Description This function starts listening for an RFCOMM connection
462 * request from a remote Bluetooth device. When the server is
463 * started successfully, tBTA_JV_RFCOMM_CBACK is called
464 * with BTA_JV_RFCOMM_START_EVT.
465 * When the connection is established, tBTA_JV_RFCOMM_CBACK
466 * is called with BTA_JV_RFCOMM_OPEN_EVT.
467 *
468 * Returns BTA_JV_SUCCESS, if the request is being processed.
469 * BTA_JV_FAILURE, otherwise.
470 *
471 ******************************************************************************/
BTA_JvRfcommStartServer(tBTA_SEC sec_mask,tBTA_JV_ROLE role,uint8_t local_scn,uint8_t max_session,tBTA_JV_RFCOMM_CBACK * p_cback,uint32_t rfcomm_slot_id)472 tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
473 uint8_t local_scn, uint8_t max_session,
474 tBTA_JV_RFCOMM_CBACK* p_cback,
475 uint32_t rfcomm_slot_id) {
476 VLOG(2) << __func__;
477
478 if (p_cback == NULL) return BTA_JV_FAILURE; /* Nothing to do */
479
480 if (max_session == 0) max_session = 1;
481 if (max_session > BTA_JV_MAX_RFC_SR_SESSION) {
482 LOG(INFO) << __func__ << "max_session is too big. use max "
483 << BTA_JV_MAX_RFC_SR_SESSION;
484 max_session = BTA_JV_MAX_RFC_SR_SESSION;
485 }
486
487 do_in_main_thread(FROM_HERE,
488 Bind(&bta_jv_rfcomm_start_server, sec_mask, local_scn,
489 max_session, p_cback, rfcomm_slot_id));
490 return BTA_JV_SUCCESS;
491 }
492
493 /*******************************************************************************
494 *
495 * Function BTA_JvRfcommStopServer
496 *
497 * Description This function stops the RFCOMM server. If the server has an
498 * active connection, it would be closed.
499 *
500 * Returns BTA_JV_SUCCESS, if the request is being processed.
501 * BTA_JV_FAILURE, otherwise.
502 *
503 ******************************************************************************/
BTA_JvRfcommStopServer(uint32_t handle,uint32_t rfcomm_slot_id)504 tBTA_JV_STATUS BTA_JvRfcommStopServer(uint32_t handle,
505 uint32_t rfcomm_slot_id) {
506 VLOG(2) << __func__;
507
508 do_in_main_thread(FROM_HERE,
509 Bind(&bta_jv_rfcomm_stop_server, handle, rfcomm_slot_id));
510 return BTA_JV_SUCCESS;
511 }
512
513 /*******************************************************************************
514 *
515 * Function BTA_JvRfcommGetPortHdl
516 *
517 * Description This function fetches the rfcomm port handle
518 *
519 * Returns BTA_JV_SUCCESS, if the request is being processed.
520 * BTA_JV_FAILURE, otherwise.
521 *
522 ******************************************************************************/
BTA_JvRfcommGetPortHdl(uint32_t handle)523 uint16_t BTA_JvRfcommGetPortHdl(uint32_t handle) {
524 uint32_t hi = ((handle & BTA_JV_RFC_HDL_MASK) & ~BTA_JV_RFCOMM_MASK) - 1;
525 uint32_t si = BTA_JV_RFC_HDL_TO_SIDX(handle);
526
527 if (hi < BTA_JV_MAX_RFC_CONN && si < BTA_JV_MAX_RFC_SR_SESSION &&
528 bta_jv_cb.rfc_cb[hi].rfc_hdl[si])
529 return bta_jv_cb.port_cb[bta_jv_cb.rfc_cb[hi].rfc_hdl[si] - 1].port_handle;
530 else
531 return 0xffff;
532 }
533
534 /*******************************************************************************
535 *
536 * Function BTA_JvRfcommWrite
537 *
538 * Description This function writes data to an RFCOMM connection
539 *
540 * Returns BTA_JV_SUCCESS, if the request is being processed.
541 * BTA_JV_FAILURE, otherwise.
542 *
543 ******************************************************************************/
BTA_JvRfcommWrite(uint32_t handle,uint32_t req_id)544 tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id) {
545 uint32_t hi = ((handle & BTA_JV_RFC_HDL_MASK) & ~BTA_JV_RFCOMM_MASK) - 1;
546 uint32_t si = BTA_JV_RFC_HDL_TO_SIDX(handle);
547
548 VLOG(2) << __func__;
549
550 VLOG(2) << __func__ << "handle=" << loghex(handle) << ", hi=" << hi
551 << ", si=" << si;
552 if (hi >= BTA_JV_MAX_RFC_CONN || !bta_jv_cb.rfc_cb[hi].p_cback ||
553 si >= BTA_JV_MAX_RFC_SR_SESSION || !bta_jv_cb.rfc_cb[hi].rfc_hdl[si]) {
554 return BTA_JV_FAILURE;
555 }
556
557 VLOG(2) << "write ok";
558
559 tBTA_JV_RFC_CB* p_cb = &bta_jv_cb.rfc_cb[hi];
560 do_in_main_thread(FROM_HERE, Bind(&bta_jv_rfcomm_write, handle, req_id, p_cb,
561 &bta_jv_cb.port_cb[p_cb->rfc_hdl[si] - 1]));
562 return BTA_JV_SUCCESS;
563 }
564
565 /*******************************************************************************
566 *
567 * Function BTA_JVSetPmProfile
568 *
569 * Description: This function set or free power mode profile for different JV
570 * application.
571 *
572 * Parameters: handle, JV handle from RFCOMM or L2CAP
573 * app_id: app specific pm ID, can be BTA_JV_PM_ALL, see
574 * bta_dm_cfg.c for details
575 * BTA_JV_PM_ID_CLEAR: removes pm management on the handle. init_st
576 * is ignored and BTA_JV_CONN_CLOSE is called implicitly
577 * init_st: state after calling this API. typically it should be
578 * BTA_JV_CONN_OPEN
579 *
580 * Returns BTA_JV_SUCCESS, if the request is being processed.
581 * BTA_JV_FAILURE, otherwise.
582 *
583 * NOTE: BTA_JV_PM_ID_CLEAR: In general no need to be called as jv pm
584 * calls automatically
585 * BTA_JV_CONN_CLOSE to remove in case of connection close!
586 *
587 ******************************************************************************/
BTA_JvSetPmProfile(uint32_t handle,tBTA_JV_PM_ID app_id,tBTA_JV_CONN_STATE init_st)588 tBTA_JV_STATUS BTA_JvSetPmProfile(uint32_t handle, tBTA_JV_PM_ID app_id,
589 tBTA_JV_CONN_STATE init_st) {
590 VLOG(2) << __func__ << " handle=" << loghex(handle) << ", app_id:" << app_id;
591
592 do_in_main_thread(FROM_HERE,
593 Bind(&bta_jv_set_pm_profile, handle, app_id, init_st));
594 return BTA_JV_SUCCESS;
595 }
596