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