• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 public interface file the BTA Java I/F
22  *
23  ******************************************************************************/
24 #pragma once
25 
26 #include <cstdint>
27 #include <memory>
28 #include <string>
29 
30 #include "bta/include/bta_api.h"
31 #include "bta/include/bta_sec_api.h"
32 #include "include/macros.h"
33 #include "internal_include/bt_target.h"
34 #include "stack/include/bt_hdr.h"
35 #include "stack/include/l2cap_types.h"
36 #include "stack/include/port_api.h"
37 #include "stack/include/rfcdefs.h"
38 #include "types/bluetooth/uuid.h"
39 #include "types/raw_address.h"
40 
41 /*****************************************************************************
42  *  Constants and data types
43  ****************************************************************************/
44 enum class tBTA_JV_STATUS {
45   SUCCESS = 0, /* Successful operation. */
46   FAILURE = 1, /* Generic failure. */
47   BUSY = 2,    /* Temporarily can not handle this request. */
48 };
49 
bta_jv_status_text(const tBTA_JV_STATUS & status)50 inline std::string bta_jv_status_text(const tBTA_JV_STATUS& status) {
51   switch (status) {
52     CASE_RETURN_TEXT(tBTA_JV_STATUS::SUCCESS);
53     CASE_RETURN_TEXT(tBTA_JV_STATUS::FAILURE);
54     CASE_RETURN_TEXT(tBTA_JV_STATUS::BUSY);
55   }
56 }
57 
58 #define BTA_JV_INTERNAL_ERR (-1) /* internal error. */
59 
60 /* L2CAP errors from underlying layers propagated via callbacks. */
61 #define BTA_JV_L2CAP_REASON_EMPTY 0
62 #define BTA_JV_L2CAP_REASON_UNKNOWN 1
63 #define BTA_JV_L2CAP_REASON_ACL_FAILURE 2
64 #define BTA_JV_L2CAP_REASON_CL_SEC_FAILURE 3
65 #define BTA_JV_L2CAP_REASON_INSUFFICIENT_AUTHENTICATION 4
66 #define BTA_JV_L2CAP_REASON_INSUFFICIENT_AUTHORIZATION 5
67 #define BTA_JV_L2CAP_REASON_INSUFFICIENT_ENCRYP_KEY_SIZE 6
68 #define BTA_JV_L2CAP_REASON_INSUFFICIENT_ENCRYP 7
69 #define BTA_JV_L2CAP_REASON_INVALID_SOURCE_CID 8
70 #define BTA_JV_L2CAP_REASON_SOURCE_CID_ALREADY_ALLOCATED 9
71 #define BTA_JV_L2CAP_REASON_UNACCEPTABLE_PARAMETERS 10
72 #define BTA_JV_L2CAP_REASON_INVALID_PARAMETERS 11
73 #define BTA_JV_L2CAP_REASON_NO_RESOURCES 12
74 #define BTA_JV_L2CAP_REASON_NO_PSM 13
75 #define BTA_JV_L2CAP_REASON_TIMEOUT 14
76 
77 typedef uint8_t tBTA_JV_L2CAP_REASON;
78 
79 #define BTA_JV_MAX_UUIDS SDP_MAX_UUID_FILTERS
80 #define BTA_JV_MAX_ATTRS SDP_MAX_ATTR_FILTERS
81 #define BTA_JV_MAX_SDP_REC SDP_MAX_RECORDS
82 /* GAP handle is used as index, hence do not change this value */
83 #define BTA_JV_MAX_L2C_CONN GAP_MAX_CONNECTIONS
84 #define BTA_JV_MAX_RFC_CONN MAX_RFC_PORTS
85 
86 #ifndef BTA_JV_DEF_RFC_MTU
87 #define BTA_JV_DEF_RFC_MTU (3 * 330)
88 #endif
89 
90 #ifndef BTA_JV_MAX_RFC_SR_SESSION
91 #define BTA_JV_MAX_RFC_SR_SESSION MAX_BD_CONNECTIONS
92 #endif
93 
94 /* BTA_JV_MAX_RFC_SR_SESSION can not be bigger than MAX_BD_CONNECTIONS */
95 #if (BTA_JV_MAX_RFC_SR_SESSION > MAX_BD_CONNECTIONS)
96 #undef BTA_JV_MAX_RFC_SR_SESSION
97 #define BTA_JV_MAX_RFC_SR_SESSION MAX_BD_CONNECTIONS
98 #endif
99 
100 #define BTA_JV_FIRST_SERVICE_ID BTA_FIRST_JV_SERVICE_ID
101 #define BTA_JV_LAST_SERVICE_ID BTA_LAST_JV_SERVICE_ID
102 #define BTA_JV_NUM_SERVICE_ID (BTA_LAST_JV_SERVICE_ID - BTA_FIRST_JV_SERVICE_ID + 1)
103 
104 /* Discoverable modes */
105 enum { BTA_JV_DISC_NONE, BTA_JV_DISC_LIMITED, BTA_JV_DISC_GENERAL };
106 typedef uint16_t tBTA_JV_DISC;
107 
108 /* JV ID type */
109 #define BTA_JV_PM_ID_1 1     /* PM example profile 1 */
110 #define BTA_JV_PM_ID_2 2     /* PM example profile 2 */
111 #define BTA_JV_PM_ID_CLEAR 0 /* Special JV ID used to clear PM profile */
112 #define BTA_JV_PM_ALL 0xFF   /* Generic match all id, see bta_dm_cfg.c */
113 typedef uint8_t tBTA_JV_PM_ID;
114 
115 #define BTA_JV_PM_HANDLE_CLEAR 0xFF /* Special JV ID used to clear PM profile  */
116 
117 /* define maximum number of registered PM entities. should be in sync with bta
118  * pm! */
119 #ifndef BTA_JV_PM_MAX_NUM
120 #define BTA_JV_PM_MAX_NUM 12
121 #endif
122 
123 /* JV pm connection states */
124 typedef enum : uint8_t {
125   BTA_JV_CONN_OPEN = 0, /* Connection opened state */
126   BTA_JV_CONN_CLOSE,    /* Connection closed state */
127   BTA_JV_APP_OPEN,      /* JV Application opened state */
128   BTA_JV_APP_CLOSE,     /* JV Application closed state */
129   BTA_JV_SCO_OPEN,      /* SCO connection opened state */
130   BTA_JV_SCO_CLOSE,     /* SCO connection opened state */
131   BTA_JV_CONN_IDLE,     /* Connection idle state */
132   BTA_JV_CONN_BUSY,     /* Connection busy state */
133   BTA_JV_MAX_CONN_STATE /* Max number of connection state */
134 } tBTA_JV_CONN_STATE;
135 
bta_jv_conn_state_text(const tBTA_JV_CONN_STATE & state)136 inline std::string bta_jv_conn_state_text(const tBTA_JV_CONN_STATE& state) {
137   switch (state) {
138     CASE_RETURN_STRING(BTA_JV_CONN_OPEN);
139     CASE_RETURN_STRING(BTA_JV_CONN_CLOSE);
140     CASE_RETURN_STRING(BTA_JV_APP_OPEN);
141     CASE_RETURN_STRING(BTA_JV_APP_CLOSE);
142     CASE_RETURN_STRING(BTA_JV_SCO_OPEN);
143     CASE_RETURN_STRING(BTA_JV_SCO_CLOSE);
144     CASE_RETURN_STRING(BTA_JV_CONN_IDLE);
145     CASE_RETURN_STRING(BTA_JV_CONN_BUSY);
146     CASE_RETURN_STRING(BTA_JV_MAX_CONN_STATE);
147     default:
148       RETURN_UNKNOWN_TYPE_STRING(tBTA_JV_CONN_STATE, state);
149   }
150 }
151 
152 namespace std {
153 template <>
154 struct formatter<tBTA_JV_CONN_STATE> : enum_formatter<tBTA_JV_CONN_STATE> {};
155 }  // namespace std
156 
157 /* JV Connection types */
158 enum class tBTA_JV_CONN_TYPE {
159   UNKNOWN = -1,
160   RFCOMM = 0,
161   L2CAP = 1,
162   L2CAP_LE = 2,
163 };
164 
165 inline std::string bta_jv_conn_type_text(const tBTA_JV_CONN_TYPE& type) {
166   switch (type) {
167     CASE_RETURN_STRING(tBTA_JV_CONN_TYPE::UNKNOWN);
168     CASE_RETURN_STRING(tBTA_JV_CONN_TYPE::RFCOMM);
169     CASE_RETURN_STRING(tBTA_JV_CONN_TYPE::L2CAP);
170     CASE_RETURN_STRING(tBTA_JV_CONN_TYPE::L2CAP_LE);
171   }
172   RETURN_UNKNOWN_TYPE_STRING(tBTA_JV_CONN_TYPE, type);
173 }
174 
175 namespace std {
176 template <>
177 struct formatter<tBTA_JV_CONN_TYPE> : enum_formatter<tBTA_JV_CONN_TYPE> {};
178 }  // namespace std
179 
180 enum tBTA_JV_EVT : uint16_t {
181   /* Java I/F callback events */
182   /* events received by tBTA_JV_DM_CBACK */
183   BTA_JV_ENABLE_EVT = 0,          // JV enabled
184   BTA_JV_GET_SCN_EVT = 6,         // Reserved an SCN
185   BTA_JV_GET_PSM_EVT = 7,         // Reserved a PSM
186   BTA_JV_DISCOVERY_COMP_EVT = 8,  // SDP discovery complete
187   BTA_JV_CREATE_RECORD_EVT = 11,  // the result for BTA_JvCreateRecord
188   /* events received by tBTA_JV_L2CAP_CBACK */
189   BTA_JV_L2CAP_OPEN_EVT = 16,      // open status of L2CAP connection
190   BTA_JV_L2CAP_CLOSE_EVT = 17,     // L2CAP connection closed
191   BTA_JV_L2CAP_START_EVT = 18,     // L2CAP server started
192   BTA_JV_L2CAP_CL_INIT_EVT = 19,   // L2CAP client initiated a connection
193   BTA_JV_L2CAP_DATA_IND_EVT = 20,  // L2CAP connection received data
194   BTA_JV_L2CAP_CONG_EVT = 21,      // L2CAP connection congestion status changed
195   BTA_JV_L2CAP_READ_EVT = 22,      // the result for BTA_JvL2capRead
196   BTA_JV_L2CAP_WRITE_EVT = 24,     // the result for BTA_JvL2capWrite
197 
198   /* events received by tBTA_JV_RFCOMM_CBACK */
199   BTA_JV_RFCOMM_OPEN_EVT = 26,      // open status of RFCOMM Client connection
200   BTA_JV_RFCOMM_CLOSE_EVT = 27,     // RFCOMM connection closed
201   BTA_JV_RFCOMM_START_EVT = 28,     // RFCOMM server started
202   BTA_JV_RFCOMM_CL_INIT_EVT = 29,   // RFCOMM client initiated a connection
203   BTA_JV_RFCOMM_DATA_IND_EVT = 30,  // RFCOMM connection received data
204   BTA_JV_RFCOMM_CONG_EVT = 31,      // RFCOMM connection congestion status changed
205   BTA_JV_RFCOMM_WRITE_EVT = 33,     // the result for BTA_JvRfcommWrite
206   BTA_JV_RFCOMM_SRV_OPEN_EVT = 34,  // open status of Server RFCOMM connection
207   BTA_JV_MAX_EVT = 35,              // max number of JV events
208 };
209 
210 inline std::string bta_jv_event_text(const tBTA_JV_EVT& event) {
211   switch (event) {
212     CASE_RETURN_TEXT(BTA_JV_ENABLE_EVT);
213     CASE_RETURN_TEXT(BTA_JV_GET_SCN_EVT);
214     CASE_RETURN_TEXT(BTA_JV_GET_PSM_EVT);
215     CASE_RETURN_TEXT(BTA_JV_DISCOVERY_COMP_EVT);
216     CASE_RETURN_TEXT(BTA_JV_CREATE_RECORD_EVT);
217     CASE_RETURN_TEXT(BTA_JV_L2CAP_OPEN_EVT);
218     CASE_RETURN_TEXT(BTA_JV_L2CAP_CLOSE_EVT);
219     CASE_RETURN_TEXT(BTA_JV_L2CAP_START_EVT);
220     CASE_RETURN_TEXT(BTA_JV_L2CAP_CL_INIT_EVT);
221     CASE_RETURN_TEXT(BTA_JV_L2CAP_DATA_IND_EVT);
222     CASE_RETURN_TEXT(BTA_JV_L2CAP_CONG_EVT);
223     CASE_RETURN_TEXT(BTA_JV_L2CAP_READ_EVT);
224     CASE_RETURN_TEXT(BTA_JV_L2CAP_WRITE_EVT);
225     CASE_RETURN_TEXT(BTA_JV_RFCOMM_OPEN_EVT);
226     CASE_RETURN_TEXT(BTA_JV_RFCOMM_CLOSE_EVT);
227     CASE_RETURN_TEXT(BTA_JV_RFCOMM_START_EVT);
228     CASE_RETURN_TEXT(BTA_JV_RFCOMM_CL_INIT_EVT);
229     CASE_RETURN_TEXT(BTA_JV_RFCOMM_DATA_IND_EVT);
230     CASE_RETURN_TEXT(BTA_JV_RFCOMM_CONG_EVT);
231     CASE_RETURN_TEXT(BTA_JV_RFCOMM_WRITE_EVT);
232     CASE_RETURN_TEXT(BTA_JV_RFCOMM_SRV_OPEN_EVT);
233     CASE_RETURN_TEXT(BTA_JV_MAX_EVT);
234     default:
235       return std::format("UNKNOWN[{}]", static_cast<uint16_t>(event));
236   }
237 }
238 
239 /* data associated with BTA_JV_SET_DISCOVER_EVT */
240 typedef struct {
241   tBTA_JV_STATUS status;  /* Whether the operation succeeded or failed. */
242   tBTA_JV_DISC disc_mode; /* The current discoverable mode */
243 } tBTA_JV_SET_DISCOVER;
244 
245 /* data associated with BTA_JV_DISCOVERY_COMP_EVT_ */
246 typedef struct {
247   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
248   int scn;               /* channel # */
249 } tBTA_JV_DISCOVERY_COMP;
250 
251 /* data associated with BTA_JV_CREATE_RECORD_EVT */
252 typedef struct {
253   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
254 } tBTA_JV_CREATE_RECORD;
255 
256 /* data associated with BTA_JV_L2CAP_OPEN_EVT */
257 typedef struct {
258   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
259   uint32_t handle;       /* The connection handle */
260   RawAddress rem_bda;    /* The peer address */
261   int32_t tx_mtu;        /* The transmit MTU */
262   uint16_t local_cid;    /* The local CID */
263   uint16_t remote_cid;   /* The remote CID */
264   uint16_t local_coc_mps;     /* The local COC MPS */
265   uint16_t remote_coc_mps;    /* The remote COC MPS */
266   uint16_t local_coc_credit;  /* The local COC credit */
267   uint16_t remote_coc_credit; /* The remote COC credit */
268   uint16_t acl_handle;        /* The ACL handle */
269 } tBTA_JV_L2CAP_OPEN;
270 
271 /* data associated with BTA_JV_L2CAP_OPEN_EVT for LE sockets */
272 typedef struct {
273   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
274   uint32_t handle;       /* The connection handle */
275   RawAddress rem_bda;    /* The peer address */
276   int32_t tx_mtu;        /* The transmit MTU */
277   void** p_p_cback;      /* set them for new socket */
278   void** p_user_data;    /* set them for new socket */
279 } tBTA_JV_L2CAP_LE_OPEN;
280 
281 /* data associated with BTA_JV_L2CAP_CLOSE_EVT */
282 typedef struct {
283   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
284   uint32_t handle;       /* The connection handle */
285   bool async;            /* false, if local initiates disconnect */
286   /* Reason that triggered the L2CAP connection close callback.
287   Used when L2CAP close callback was triggered due to a GAP error. */
288   tBTA_JV_L2CAP_REASON reason;
289 } tBTA_JV_L2CAP_CLOSE;
290 
291 /* data associated with BTA_JV_L2CAP_START_EVT */
292 typedef struct {
293   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
294   uint32_t handle;       /* The connection handle */
295   uint8_t sec_id;        /* security ID used by this server */
296 } tBTA_JV_L2CAP_START;
297 
298 /* data associated with BTA_JV_L2CAP_CL_INIT_EVT */
299 typedef struct {
300   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
301   uint32_t handle;       /* The connection handle */
302   uint8_t sec_id;        /* security ID used by this client */
303 } tBTA_JV_L2CAP_CL_INIT;
304 
305 /* data associated with BTA_JV_L2CAP_CONG_EVT */
306 typedef struct {
307   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
308   uint32_t handle;       /* The connection handle */
309   bool cong;             /* true, congested. false, uncongested */
310 } tBTA_JV_L2CAP_CONG;
311 
312 /* data associated with BTA_JV_L2CAP_READ_EVT */
313 typedef struct {
314   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
315   uint32_t handle;       /* The connection handle */
316   uint32_t req_id;       /* The req_id in the associated BTA_JvL2capRead() */
317   uint8_t* p_data;       /* Points to the same location as p_data parameter in BTA_JvL2capRead() */
318   uint16_t len;          /* The length of the data read. */
319 } tBTA_JV_L2CAP_READ;
320 
321 /* data associated with BTA_JV_L2CAP_WRITE_EVT */
322 typedef struct {
323   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
324   uint32_t handle;       /* The connection handle */
325   uint32_t req_id;       /* The req_id in the associated BTA_JvL2capWrite() */
326   uint16_t len;          /* The length of the data written. */
327   bool cong;             /* congestion status */
328 } tBTA_JV_L2CAP_WRITE;
329 
330 /* data associated with BTA_JV_RFCOMM_OPEN_EVT */
331 typedef struct {
332   tBTA_JV_STATUS status;   /* Whether the operation succeeded or failed. */
333   uint32_t handle;         /* The connection handle */
334   RawAddress rem_bda;      /* The peer address */
335   uint16_t rx_mtu;         /* The receive (local) L2CAP MTU */
336   uint16_t tx_mtu;         /* The transmit (remote) L2CAP MTU */
337   uint16_t local_credit;   /* The local RFCOMM credit */
338   uint16_t remote_credit;  /* The remote RFCOMM credit */
339   uint16_t local_cid;      /* The local L2CAP CID */
340   uint16_t remote_cid;     /* The remote L2CAP CID */
341   uint16_t dlci;           /* DLCI */
342   uint16_t max_frame_size; /* The max frame size for RFCOMM */
343   uint16_t acl_handle;     /* The ACL handle */
344   bool mux_initiator;      /* Is the initiator of the RFCOMM multiplexer control channel */
345 } tBTA_JV_RFCOMM_OPEN;
346 /* data associated with BTA_JV_RFCOMM_SRV_OPEN_EVT */
347 typedef struct {
348   tBTA_JV_STATUS status;      /* Whether the operation succeeded or failed. */
349   uint32_t handle;            /* The connection handle */
350   uint32_t new_listen_handle; /* The new listen handle */
351   RawAddress rem_bda;         /* The peer address */
352   uint16_t rx_mtu;            /* The receive (local) L2CAP MTU */
353   uint16_t tx_mtu;            /* The transmit (remote) L2CAP MTU */
354   uint16_t local_credit;      /* The local RFCOMM credit */
355   uint16_t remote_credit;     /* The remote RFCOMM credit */
356   uint16_t local_cid;         /* The local L2CAP CID */
357   uint16_t remote_cid;        /* The remote L2CAP CID */
358   uint16_t dlci;              /* DLCI */
359   uint16_t max_frame_size;    /* The max frame size for RFCOMM */
360   uint16_t acl_handle;        /* The ACL handle */
361   bool mux_initiator;         /* Is the initiator of the RFCOMM multiplexer control channel */
362 } tBTA_JV_RFCOMM_SRV_OPEN;
363 
364 /* data associated with BTA_JV_RFCOMM_CLOSE_EVT */
365 typedef struct {
366   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
367   uint32_t port_status;  /* PORT status */
368   uint32_t handle;       /* The connection handle */
369   bool async;            /* false, if local initiates disconnect */
370 } tBTA_JV_RFCOMM_CLOSE;
371 
372 /* data associated with BTA_JV_RFCOMM_START_EVT */
373 typedef struct {
374   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
375   uint32_t handle;       /* The connection handle */
376   uint8_t sec_id;        /* security ID used by this server */
377   bool use_co;           /* true to use co_rfc_data */
378 } tBTA_JV_RFCOMM_START;
379 
380 /* data associated with BTA_JV_RFCOMM_CL_INIT_EVT */
381 typedef struct {
382   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
383   uint32_t handle;       /* The connection handle */
384   uint8_t sec_id;        /* security ID used by this client */
385   bool use_co;           /* true to use co_rfc_data */
386 } tBTA_JV_RFCOMM_CL_INIT;
387 /*data associated with BTA_JV_L2CAP_DATA_IND_EVT & BTA_JV_RFCOMM_DATA_IND_EVT */
388 typedef struct {
389   uint32_t handle; /* The connection handle */
390 } tBTA_JV_DATA_IND;
391 
392 /*data associated with BTA_JV_L2CAP_DATA_IND_EVT if used for LE */
393 typedef struct {
394   uint32_t handle; /* The connection handle */
395   BT_HDR* p_buf;   /* The incoming data */
396 } tBTA_JV_LE_DATA_IND;
397 
398 /* data associated with BTA_JV_RFCOMM_CONG_EVT */
399 typedef struct {
400   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
401   uint32_t handle;       /* The connection handle */
402   bool cong;             /* true, congested. false, uncongested */
403 } tBTA_JV_RFCOMM_CONG;
404 
405 /* data associated with BTA_JV_RFCOMM_WRITE_EVT */
406 typedef struct {
407   tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
408   uint32_t handle;       /* The connection handle */
409   uint32_t req_id;       /* The req_id in the associated BTA_JvRfcommWrite() */
410   int len;               /* The length of the data written. */
411   bool cong;             /* congestion status */
412 } tBTA_JV_RFCOMM_WRITE;
413 
414 /* data associated with BTA_JV_API_SET_PM_PROFILE_EVT */
415 typedef struct {
416   tBTA_JV_STATUS status; /* Status of the operation */
417   uint32_t handle;       /* Connection handle */
418   tBTA_JV_PM_ID app_id;  /* JV app ID */
419 } tBTA_JV_SET_PM_PROFILE;
420 
421 /* data associated with BTA_JV_API_NOTIFY_PM_STATE_CHANGE_EVT */
422 typedef struct {
423   uint32_t handle;          /* Connection handle */
424   tBTA_JV_CONN_STATE state; /* JV connection stata */
425 } tBTA_JV_NOTIFY_PM_STATE_CHANGE;
426 
427 /* union of data associated with JV callback */
428 typedef union {
429   tBTA_JV_STATUS status;                /* BTA_JV_ENABLE_EVT */
430   tBTA_JV_DISCOVERY_COMP disc_comp;     /* BTA_JV_DISCOVERY_COMP_EVT */
431   tBTA_JV_SET_DISCOVER set_discover;    /* BTA_JV_SET_DISCOVER_EVT */
432   uint8_t scn;                          /* BTA_JV_GET_SCN_EVT */
433   uint16_t psm;                         /* BTA_JV_GET_PSM_EVT */
434   tBTA_JV_CREATE_RECORD create_rec;     /* BTA_JV_CREATE_RECORD_EVT */
435   tBTA_JV_L2CAP_OPEN l2c_open;          /* BTA_JV_L2CAP_OPEN_EVT */
436   tBTA_JV_L2CAP_CLOSE l2c_close;        /* BTA_JV_L2CAP_CLOSE_EVT */
437   tBTA_JV_L2CAP_START l2c_start;        /* BTA_JV_L2CAP_START_EVT */
438   tBTA_JV_L2CAP_CL_INIT l2c_cl_init;    /* BTA_JV_L2CAP_CL_INIT_EVT */
439   tBTA_JV_L2CAP_CONG l2c_cong;          /* BTA_JV_L2CAP_CONG_EVT */
440   tBTA_JV_L2CAP_READ l2c_read;          /* BTA_JV_L2CAP_READ_EVT */
441   tBTA_JV_L2CAP_WRITE l2c_write;        /* BTA_JV_L2CAP_WRITE_EVT */
442   tBTA_JV_RFCOMM_OPEN rfc_open;         /* BTA_JV_RFCOMM_OPEN_EVT */
443   tBTA_JV_RFCOMM_SRV_OPEN rfc_srv_open; /* BTA_JV_RFCOMM_SRV_OPEN_EVT */
444   tBTA_JV_RFCOMM_CLOSE rfc_close;       /* BTA_JV_RFCOMM_CLOSE_EVT */
445   tBTA_JV_RFCOMM_START rfc_start;       /* BTA_JV_RFCOMM_START_EVT */
446   tBTA_JV_RFCOMM_CL_INIT rfc_cl_init;   /* BTA_JV_RFCOMM_CL_INIT_EVT */
447   tBTA_JV_RFCOMM_CONG rfc_cong;         /* BTA_JV_RFCOMM_CONG_EVT */
448   tBTA_JV_RFCOMM_WRITE rfc_write;       /* BTA_JV_RFCOMM_WRITE_EVT */
449   tBTA_JV_DATA_IND data_ind;            /* BTA_JV_L2CAP_DATA_IND_EVT, BTA_JV_RFCOMM_DATA_IND_EVT */
450   tBTA_JV_LE_DATA_IND le_data_ind;      /* BTA_JV_L2CAP_LE_DATA_IND_EVT */
451   tBTA_JV_L2CAP_LE_OPEN l2c_le_open;    /* BTA_JV_L2CAP_OPEN_EVT */
452 } tBTA_JV;
453 
454 /* JAVA DM Interface callback */
455 typedef void(tBTA_JV_DM_CBACK)(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id);
456 
457 /* JAVA RFCOMM interface callback */
458 typedef uint32_t(tBTA_JV_RFCOMM_CBACK)(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t rfcomm_slot_id);
459 
460 /* JAVA L2CAP interface callback */
461 typedef void(tBTA_JV_L2CAP_CBACK)(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t l2cap_socket_id);
462 
463 /*******************************************************************************
464  *
465  * Function         BTA_JvEnable
466  *
467  * Description      Enable the Java I/F service. When the enable
468  *                  operation is complete the callback function will be
469  *                  called with a BTA_JV_ENABLE_EVT. This function must
470  *                  be called before other functions in the JV API are
471  *                  called.
472  *
473  * Returns          BTA_JV_SUCCESS if successful.
474  *                  BTA_JV_FAIL if internal failure.
475  *
476  ******************************************************************************/
477 tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback);
478 
479 /*******************************************************************************
480  *
481  * Function         BTA_JvDisable
482  *
483  * Description      Disable the Java I/F
484  *
485  * Returns          void
486  *
487  ******************************************************************************/
488 void BTA_JvDisable(void);
489 
490 /*******************************************************************************
491  *
492  * Function         BTA_JvGetChannelId
493  *
494  * Description      This function reserves a SCN/PSM for applications running
495  *                  over RFCOMM or L2CAP. It is primarily called by
496  *                  server profiles/applications to register their SCN/PSM into
497  *                  the SDP database. The SCN is reported by the
498  *                  tBTA_JV_DM_CBACK callback with a BTA_JV_GET_SCN_EVT.
499  *                  If the SCN/PSM reported is 0, that means all SCN resources
500  *                  are exhausted.
501  *                  The channel parameter can be used to request a specific
502  *                  channel. If the request on the specific channel fails, the
503  *                  SCN/PSM returned in the EVT will be 0 - no attempt to
504  *                  request a new channel will be made. set channel to <= 0 to
505  *                  automatically assign an channel ID.
506  *
507  * Returns          void
508  *
509  ******************************************************************************/
510 void BTA_JvGetChannelId(tBTA_JV_CONN_TYPE conn_type, uint32_t id, int32_t channel);
511 
512 /*******************************************************************************
513  *
514  * Function         BTA_JvFreeChannel
515  *
516  * Description      This function frees a SCN/PSM that was used
517  *                  by an application running over RFCOMM or L2CAP.
518  *
519  * Returns          BTA_JV_SUCCESS, if the request is being processed.
520  *                  BTA_JV_FAILURE, otherwise.
521  *
522  ******************************************************************************/
523 tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, tBTA_JV_CONN_TYPE conn_type);
524 
525 /*******************************************************************************
526  *
527  * Function         BTA_JvStartDiscovery
528  *
529  * Description      This function performs service discovery for the services
530  *                  provided by the given peer device. When the operation is
531  *                  complete the tBTA_JV_DM_CBACK callback function will be
532  *                  called with a BTA_JV_DISCOVERY_COMP_EVT.
533  *
534  * Returns          BTA_JV_SUCCESS, if the request is being processed.
535  *                  BTA_JV_FAILURE, otherwise.
536  *
537  ******************************************************************************/
538 tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr, uint16_t num_uuid,
539                                     const bluetooth::Uuid* p_uuid_list, uint32_t rfcomm_slot_id);
540 
541 /*******************************************************************************
542  *
543  * Function         BTA_JvCancelDiscovery
544  *
545  * Description      This function cancels the ongoing service discovery and make
546  *                  sure the tBTA_JV_DM_CBACK callback function will be called
547  *                  with a BTA_JV_DISCOVERY_COMP_EVT.
548  *
549  * Returns          void
550  *
551  ******************************************************************************/
552 void BTA_JvCancelDiscovery(uint32_t rfcomm_slot_id);
553 
554 /*******************************************************************************
555  *
556  * Function         BTA_JvCreateRecordByUser
557  *
558  * Description      Create a service record in the local SDP database by user in
559  *                  tBTA_JV_DM_CBACK callback with a BTA_JV_CREATE_RECORD_EVT.
560  *
561  * Returns          BTA_JV_SUCCESS, if the request is being processed.
562  *                  BTA_JV_FAILURE, otherwise.
563  *
564  ******************************************************************************/
565 tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id);
566 
567 /*******************************************************************************
568  *
569  * Function         BTA_JvDeleteRecord
570  *
571  * Description      Delete a service record in the local SDP database.
572  *
573  * Returns          BTA_JV_SUCCESS, if the request is being processed.
574  *                  BTA_JV_FAILURE, otherwise.
575  *
576  ******************************************************************************/
577 tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle);
578 
579 /*******************************************************************************
580  *
581  * Function         BTA_JvL2capConnect
582  *
583  * Description      Initiate a connection as a L2CAP client to the given BD
584  *                  Address.
585  *                  When the connection is initiated or failed to initiate,
586  *                  tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_CL_INIT_EVT
587  *                  When the connection is established or failed,
588  *                  tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
589  *
590  ******************************************************************************/
591 void BTA_JvL2capConnect(tBTA_JV_CONN_TYPE conn_type, tBTA_SEC sec_mask,
592                         std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info, uint16_t remote_psm,
593                         uint16_t rx_mtu, std::unique_ptr<tL2CAP_CFG_INFO> cfg,
594                         const RawAddress& peer_bd_addr, tBTA_JV_L2CAP_CBACK* p_cback,
595                         uint32_t l2cap_socket_id);
596 
597 /*******************************************************************************
598  *
599  * Function         BTA_JvL2capClose
600  *
601  * Description      This function closes an L2CAP client connection
602  *
603  * Returns          BTA_JV_SUCCESS, if the request is being processed.
604  *                  BTA_JV_FAILURE, otherwise.
605  *
606  ******************************************************************************/
607 tBTA_JV_STATUS BTA_JvL2capClose(uint32_t handle);
608 
609 /*******************************************************************************
610  *
611  * Function         BTA_JvL2capStartServer
612  *
613  * Description      This function starts an L2CAP server and listens for an
614  *                  L2CAP connection from a remote Bluetooth device.  When the
615  *                  server is started successfully, tBTA_JV_L2CAP_CBACK is
616  *                  called with BTA_JV_L2CAP_START_EVT.  When the connection is
617  *                  established, tBTA_JV_L2CAP_CBACK is called with
618  *                  BTA_JV_L2CAP_OPEN_EVT.
619  *
620  * Returns          void
621  *
622  ******************************************************************************/
623 void BTA_JvL2capStartServer(tBTA_JV_CONN_TYPE conn_type, tBTA_SEC sec_mask,
624                             std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info, uint16_t local_psm,
625                             uint16_t rx_mtu, std::unique_ptr<tL2CAP_CFG_INFO> cfg,
626                             tBTA_JV_L2CAP_CBACK* p_cback, uint32_t l2cap_socket_id);
627 
628 /*******************************************************************************
629  *
630  * Function         BTA_JvL2capStopServer
631  *
632  * Description      This function stops the L2CAP server. If the server has
633  *                  an active connection, it would be closed.
634  *
635  * Returns          BTA_JV_SUCCESS, if the request is being processed.
636  *                  BTA_JV_FAILURE, otherwise.
637  *
638  ******************************************************************************/
639 tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm, uint32_t l2cap_socket_id);
640 
641 /*******************************************************************************
642  *
643  * Function         BTA_JvL2capRead
644  *
645  * Description      This function reads data from an L2CAP connection
646  *                  When the operation is complete, tBTA_JV_L2CAP_CBACK is
647  *                  called with BTA_JV_L2CAP_READ_EVT.
648  *
649  * Returns          BTA_JV_SUCCESS, if the request is being processed.
650  *                  BTA_JV_FAILURE, otherwise.
651  *
652  ******************************************************************************/
653 tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id, uint8_t* p_data, uint16_t len);
654 
655 /*******************************************************************************
656  *
657  * Function         BTA_JvL2capReady
658  *
659  * Description      This function determined if there is data to read from
660  *                  an L2CAP connection
661  *
662  * Returns          BTA_JV_SUCCESS, if data queue size is in *p_data_size.
663  *                  BTA_JV_FAILURE, if error.
664  *
665  ******************************************************************************/
666 tBTA_JV_STATUS BTA_JvL2capReady(uint32_t handle, uint32_t* p_data_size);
667 
668 /*******************************************************************************
669  *
670  * Function         BTA_JvL2capWrite
671  *
672  * Description      This function writes data to an L2CAP connection
673  *                  When the operation is complete, tBTA_JV_L2CAP_CBACK is
674  *                  called with BTA_JV_L2CAP_WRITE_EVT. Works for
675  *                  PSM-based connections
676  *
677  * Returns          BTA_JV_SUCCESS, if the request is being processed.
678  *                  BTA_JV_FAILURE, otherwise.
679  *
680  ******************************************************************************/
681 tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg, uint32_t user_id);
682 
683 /*******************************************************************************
684  *
685  * Function         BTA_JvRfcommConnect
686  *
687  * Description      This function makes an RFCOMM conection to a remote BD
688  *                  Address.
689  *                  When the connection is initiated or failed to initiate,
690  *                  tBTA_JV_RFCOMM_CBACK is called with
691  *                  BTA_JV_RFCOMM_CL_INIT_EVT
692  *                  When the connection is established or failed,
693  *                  tBTA_JV_RFCOMM_CBACK is called with BTA_JV_RFCOMM_OPEN_EVT
694  *
695  * Returns          BTA_JV_SUCCESS, if the request is being processed.
696  *                  BTA_JV_FAILURE, otherwise.
697  *
698  ******************************************************************************/
699 tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, uint8_t remote_scn,
700                                    const RawAddress& peer_bd_addr, tBTA_JV_RFCOMM_CBACK* p_cback,
701                                    uint32_t rfcomm_slot_id, RfcommCfgInfo cfg, uint32_t app_uid,
702                                    uint64_t sdp_duration_ms);
703 
704 /*******************************************************************************
705  *
706  * Function         BTA_JvRfcommClose
707  *
708  * Description      This function closes an RFCOMM connection
709  *
710  * Returns          BTA_JV_SUCCESS, if the request is being processed.
711  *                  BTA_JV_FAILURE, otherwise.
712  *
713  ******************************************************************************/
714 tBTA_JV_STATUS BTA_JvRfcommClose(uint32_t handle, uint32_t rfcomm_slot_id);
715 
716 /*******************************************************************************
717  *
718  * Function         BTA_JvRfcommStartServer
719  *
720  * Description      This function starts listening for an RFCOMM connection
721  *                  request from a remote Bluetooth device.  When the server is
722  *                  started successfully, tBTA_JV_RFCOMM_CBACK is called
723  *                  with BTA_JV_RFCOMM_START_EVT.
724  *                  When the connection is established, tBTA_JV_RFCOMM_CBACK
725  *                  is called with BTA_JV_RFCOMM_OPEN_EVT.
726  *
727  * Returns          BTA_JV_SUCCESS, if the request is being processed.
728  *                  BTA_JV_FAILURE, otherwise.
729  *
730  ******************************************************************************/
731 tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, uint8_t local_scn, uint8_t max_session,
732                                        tBTA_JV_RFCOMM_CBACK* p_cback, uint32_t rfcomm_slot_id,
733                                        RfcommCfgInfo cfg, uint32_t app_uid);
734 
735 /*******************************************************************************
736  *
737  * Function         BTA_JvRfcommStopServer
738  *
739  * Description      This function stops the RFCOMM server. If the server has an
740  *                  active connection, it would be closed.
741  *
742  * Returns          BTA_JV_SUCCESS, if the request is being processed.
743  *                  BTA_JV_FAILURE, otherwise.
744  *
745  ******************************************************************************/
746 tBTA_JV_STATUS BTA_JvRfcommStopServer(uint32_t handle, uint32_t rfcomm_slot_id);
747 
748 /*******************************************************************************
749  *
750  * Function         BTA_JvRfcommWrite
751  *
752  * Description      This function writes data to an RFCOMM connection
753  *                  When the operation is complete, tBTA_JV_RFCOMM_CBACK is
754  *                  called with BTA_JV_RFCOMM_WRITE_EVT.
755  *
756  * Returns          BTA_JV_SUCCESS, if the request is being processed.
757  *                  BTA_JV_FAILURE, otherwise.
758  *
759  ******************************************************************************/
760 tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id);
761 
762 /*******************************************************************************
763  *
764  * Function    BTA_JVSetPmProfile
765  *
766  * Description This function set or free power mode profile for different JV
767  *             application
768  *
769  * Parameters:  handle,  JV handle from RFCOMM or L2CAP
770  *              app_id:  app specific pm ID, can be BTA_JV_PM_ALL, see
771  *                       bta_dm_cfg.c for details
772  *              BTA_JV_PM_ID_CLEAR: removes pm management on the handle. init_st
773  *                                  is ignored and BTA_JV_CONN_CLOSE is called
774  *                                  implicitly
775  *              init_st: state after calling this API. typically it should be
776  *                       BTA_JV_CONN_OPEN
777  *
778  * Returns      BTA_JV_SUCCESS, if the request is being processed.
779  *              BTA_JV_FAILURE, otherwise.
780  *
781  * NOTE:        BTA_JV_PM_ID_CLEAR: In general no need to be called as jv pm
782  *                                  calls automatically
783  *              BTA_JV_CONN_CLOSE to remove in case of connection close!
784  *
785  ******************************************************************************/
786 tBTA_JV_STATUS BTA_JvSetPmProfile(uint32_t handle, tBTA_JV_PM_ID app_id,
787                                   tBTA_JV_CONN_STATE init_st);
788 
789 /*******************************************************************************
790  *
791  * Function         BTA_JvRfcommGetPortHdl
792  *
793  * Description    This function fetches the rfcomm port handle
794  *
795  * Returns          BTA_JV_SUCCESS, if the request is being processed.
796  *                  BTA_JV_FAILURE, otherwise.
797  *
798  ******************************************************************************/
799 uint16_t BTA_JvRfcommGetPortHdl(uint32_t handle);
800