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