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