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 #include <string>
30
31 #include "bta/include/bta_api.h"
32 #include "bta_sec_api.h"
33 #include "include/macros.h"
34 #include "internal_include/bt_target.h"
35 #include "stack/include/bt_hdr.h"
36 #include "stack/include/l2c_api.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 #define BTA_JV_MAX_L2C_CONN \
82 GAP_MAX_CONNECTIONS /* GAP handle is used as index, hence do not change this \
83 value */
84 #define BTA_JV_MAX_RFC_CONN MAX_RFC_PORTS
85
86 #ifndef BTA_JV_DEF_RFC_MTU
87 #define BTA_JV_DEF_RFC_MTU (3 * 330)
88 #endif
89
90 #ifndef BTA_JV_MAX_RFC_SR_SESSION
91 #define BTA_JV_MAX_RFC_SR_SESSION MAX_BD_CONNECTIONS
92 #endif
93
94 /* BTA_JV_MAX_RFC_SR_SESSION can not be bigger than MAX_BD_CONNECTIONS */
95 #if (BTA_JV_MAX_RFC_SR_SESSION > MAX_BD_CONNECTIONS)
96 #undef BTA_JV_MAX_RFC_SR_SESSION
97 #define BTA_JV_MAX_RFC_SR_SESSION MAX_BD_CONNECTIONS
98 #endif
99
100 #define BTA_JV_FIRST_SERVICE_ID BTA_FIRST_JV_SERVICE_ID
101 #define BTA_JV_LAST_SERVICE_ID BTA_LAST_JV_SERVICE_ID
102 #define BTA_JV_NUM_SERVICE_ID \
103 (BTA_LAST_JV_SERVICE_ID - BTA_FIRST_JV_SERVICE_ID + 1)
104
105 /* Discoverable modes */
106 enum { BTA_JV_DISC_NONE, BTA_JV_DISC_LIMITED, BTA_JV_DISC_GENERAL };
107 typedef uint16_t tBTA_JV_DISC;
108
109 /* JV ID type */
110 #define BTA_JV_PM_ID_1 1 /* PM example profile 1 */
111 #define BTA_JV_PM_ID_2 2 /* PM example profile 2 */
112 #define BTA_JV_PM_ID_CLEAR 0 /* Special JV ID used to clear PM profile */
113 #define BTA_JV_PM_ALL 0xFF /* Generic match all id, see bta_dm_cfg.c */
114 typedef uint8_t tBTA_JV_PM_ID;
115
116 #define BTA_JV_PM_HANDLE_CLEAR \
117 0xFF /* Special JV ID used to clear PM profile */
118
119 /* define maximum number of registered PM entities. should be in sync with bta
120 * pm! */
121 #ifndef BTA_JV_PM_MAX_NUM
122 #define BTA_JV_PM_MAX_NUM 12
123 #endif
124
125 /* JV pm connection states */
126 typedef enum : uint8_t {
127 BTA_JV_CONN_OPEN = 0, /* Connection opened state */
128 BTA_JV_CONN_CLOSE, /* Connection closed state */
129 BTA_JV_APP_OPEN, /* JV Application opened state */
130 BTA_JV_APP_CLOSE, /* JV Application closed state */
131 BTA_JV_SCO_OPEN, /* SCO connection opened state */
132 BTA_JV_SCO_CLOSE, /* SCO connection opened state */
133 BTA_JV_CONN_IDLE, /* Connection idle state */
134 BTA_JV_CONN_BUSY, /* Connection busy state */
135 BTA_JV_MAX_CONN_STATE /* Max number of connection state */
136 } tBTA_JV_CONN_STATE;
137
bta_jv_conn_state_text(const tBTA_JV_CONN_STATE & state)138 inline std::string bta_jv_conn_state_text(const tBTA_JV_CONN_STATE& state) {
139 switch (state) {
140 CASE_RETURN_STRING(BTA_JV_CONN_OPEN);
141 CASE_RETURN_STRING(BTA_JV_CONN_CLOSE);
142 CASE_RETURN_STRING(BTA_JV_APP_OPEN);
143 CASE_RETURN_STRING(BTA_JV_APP_CLOSE);
144 CASE_RETURN_STRING(BTA_JV_SCO_OPEN);
145 CASE_RETURN_STRING(BTA_JV_SCO_CLOSE);
146 CASE_RETURN_STRING(BTA_JV_CONN_IDLE);
147 CASE_RETURN_STRING(BTA_JV_CONN_BUSY);
148 CASE_RETURN_STRING(BTA_JV_MAX_CONN_STATE);
149 default:
150 RETURN_UNKNOWN_TYPE_STRING(tBTA_JV_CONN_STATE, state);
151 }
152 }
153
154 namespace fmt {
155 template <>
156 struct formatter<tBTA_JV_CONN_STATE> : enum_formatter<tBTA_JV_CONN_STATE> {};
157 } // namespace fmt
158
159 /* JV Connection types */
160 enum class tBTA_JV_CONN_TYPE {
161 UNKNOWN = -1,
162 RFCOMM = 0,
163 L2CAP = 1,
164 L2CAP_LE = 2,
165 };
166
167 inline std::string bta_jv_conn_type_text(const tBTA_JV_CONN_TYPE& type) {
168 switch (type) {
169 CASE_RETURN_STRING(tBTA_JV_CONN_TYPE::UNKNOWN);
170 CASE_RETURN_STRING(tBTA_JV_CONN_TYPE::RFCOMM);
171 CASE_RETURN_STRING(tBTA_JV_CONN_TYPE::L2CAP);
172 CASE_RETURN_STRING(tBTA_JV_CONN_TYPE::L2CAP_LE);
173 }
174 RETURN_UNKNOWN_TYPE_STRING(tBTA_JV_CONN_TYPE, type);
175 }
176
177 namespace fmt {
178 template <>
179 struct formatter<tBTA_JV_CONN_TYPE> : enum_formatter<tBTA_JV_CONN_TYPE> {};
180 } // namespace fmt
181
182 enum tBTA_JV_EVT : uint16_t {
183 /* Java I/F callback events */
184 /* events received by tBTA_JV_DM_CBACK */
185 BTA_JV_ENABLE_EVT = 0, // JV enabled
186 BTA_JV_GET_SCN_EVT = 6, // Reserved an SCN
187 BTA_JV_GET_PSM_EVT = 7, // Reserved a PSM
188 BTA_JV_DISCOVERY_COMP_EVT = 8, // SDP discovery complete
189 BTA_JV_CREATE_RECORD_EVT = 11, // the result for BTA_JvCreateRecord
190 /* events received by tBTA_JV_L2CAP_CBACK */
191 BTA_JV_L2CAP_OPEN_EVT = 16, // open status of L2CAP connection
192 BTA_JV_L2CAP_CLOSE_EVT = 17, // L2CAP connection closed
193 BTA_JV_L2CAP_START_EVT = 18, // L2CAP server started
194 BTA_JV_L2CAP_CL_INIT_EVT = 19, // L2CAP client initiated a connection
195 BTA_JV_L2CAP_DATA_IND_EVT = 20, // L2CAP connection received data
196 BTA_JV_L2CAP_CONG_EVT = 21, // L2CAP connection congestion status changed
197 BTA_JV_L2CAP_READ_EVT = 22, // the result for BTA_JvL2capRead
198 BTA_JV_L2CAP_WRITE_EVT = 24, // the result for BTA_JvL2capWrite
199
200 /* events received by tBTA_JV_RFCOMM_CBACK */
201 BTA_JV_RFCOMM_OPEN_EVT = 26, // open status of RFCOMM Client connection
202 BTA_JV_RFCOMM_CLOSE_EVT = 27, // RFCOMM connection closed
203 BTA_JV_RFCOMM_START_EVT = 28, // RFCOMM server started
204 BTA_JV_RFCOMM_CL_INIT_EVT = 29, // RFCOMM client initiated a connection
205 BTA_JV_RFCOMM_DATA_IND_EVT = 30, // RFCOMM connection received data
206 BTA_JV_RFCOMM_CONG_EVT = 31, // RFCOMM connection congestion status changed
207 BTA_JV_RFCOMM_WRITE_EVT = 33, // the result for BTA_JvRfcommWrite
208 BTA_JV_RFCOMM_SRV_OPEN_EVT = 34, // open status of Server RFCOMM connection
209 BTA_JV_MAX_EVT = 35, // max number of JV events
210 };
211
212 inline std::string bta_jv_event_text(const tBTA_JV_EVT& event) {
213 switch (event) {
214 CASE_RETURN_TEXT(BTA_JV_ENABLE_EVT);
215 CASE_RETURN_TEXT(BTA_JV_GET_SCN_EVT);
216 CASE_RETURN_TEXT(BTA_JV_GET_PSM_EVT);
217 CASE_RETURN_TEXT(BTA_JV_DISCOVERY_COMP_EVT);
218 CASE_RETURN_TEXT(BTA_JV_CREATE_RECORD_EVT);
219 CASE_RETURN_TEXT(BTA_JV_L2CAP_OPEN_EVT);
220 CASE_RETURN_TEXT(BTA_JV_L2CAP_CLOSE_EVT);
221 CASE_RETURN_TEXT(BTA_JV_L2CAP_START_EVT);
222 CASE_RETURN_TEXT(BTA_JV_L2CAP_CL_INIT_EVT);
223 CASE_RETURN_TEXT(BTA_JV_L2CAP_DATA_IND_EVT);
224 CASE_RETURN_TEXT(BTA_JV_L2CAP_CONG_EVT);
225 CASE_RETURN_TEXT(BTA_JV_L2CAP_READ_EVT);
226 CASE_RETURN_TEXT(BTA_JV_L2CAP_WRITE_EVT);
227 CASE_RETURN_TEXT(BTA_JV_RFCOMM_OPEN_EVT);
228 CASE_RETURN_TEXT(BTA_JV_RFCOMM_CLOSE_EVT);
229 CASE_RETURN_TEXT(BTA_JV_RFCOMM_START_EVT);
230 CASE_RETURN_TEXT(BTA_JV_RFCOMM_CL_INIT_EVT);
231 CASE_RETURN_TEXT(BTA_JV_RFCOMM_DATA_IND_EVT);
232 CASE_RETURN_TEXT(BTA_JV_RFCOMM_CONG_EVT);
233 CASE_RETURN_TEXT(BTA_JV_RFCOMM_WRITE_EVT);
234 CASE_RETURN_TEXT(BTA_JV_RFCOMM_SRV_OPEN_EVT);
235 CASE_RETURN_TEXT(BTA_JV_MAX_EVT);
236 default:
237 return base::StringPrintf("UNKNOWN[%hu]", event);
238 }
239 }
240
241 /* data associated with BTA_JV_SET_DISCOVER_EVT */
242 typedef struct {
243 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
244 tBTA_JV_DISC disc_mode; /* The current discoverable mode */
245 } tBTA_JV_SET_DISCOVER;
246
247 /* data associated with BTA_JV_DISCOVERY_COMP_EVT_ */
248 typedef struct {
249 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
250 int scn; /* channel # */
251 } tBTA_JV_DISCOVERY_COMP;
252
253 /* data associated with BTA_JV_CREATE_RECORD_EVT */
254 typedef struct {
255 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
256 } tBTA_JV_CREATE_RECORD;
257
258 /* data associated with BTA_JV_L2CAP_OPEN_EVT */
259 typedef struct {
260 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
261 uint32_t handle; /* The connection handle */
262 RawAddress rem_bda; /* The peer address */
263 int32_t tx_mtu; /* The transmit MTU */
264 uint16_t local_cid; /* The local CID */
265 uint16_t remote_cid; /* The remote CID */
266 } tBTA_JV_L2CAP_OPEN;
267
268 /* data associated with BTA_JV_L2CAP_OPEN_EVT for LE sockets */
269 typedef struct {
270 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
271 uint32_t handle; /* The connection handle */
272 RawAddress rem_bda; /* The peer address */
273 int32_t tx_mtu; /* The transmit MTU */
274 void** p_p_cback; /* set them for new socket */
275 void** p_user_data; /* set them for new socket */
276
277 } tBTA_JV_L2CAP_LE_OPEN;
278
279 /* data associated with BTA_JV_L2CAP_CLOSE_EVT */
280 typedef struct {
281 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
282 uint32_t handle; /* The connection handle */
283 bool async; /* false, if local initiates disconnect */
284 /* Reason that triggered the L2CAP connection close callback.
285 Used when L2CAP close callback was triggered due to a GAP error. */
286 tBTA_JV_L2CAP_REASON reason;
287 } tBTA_JV_L2CAP_CLOSE;
288
289 /* data associated with BTA_JV_L2CAP_START_EVT */
290 typedef struct {
291 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
292 uint32_t handle; /* The connection handle */
293 uint8_t sec_id; /* security ID used by this server */
294 } tBTA_JV_L2CAP_START;
295
296 /* data associated with BTA_JV_L2CAP_CL_INIT_EVT */
297 typedef struct {
298 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
299 uint32_t handle; /* The connection handle */
300 uint8_t sec_id; /* security ID used by this client */
301 } tBTA_JV_L2CAP_CL_INIT;
302
303 /* data associated with BTA_JV_L2CAP_CONG_EVT */
304 typedef struct {
305 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
306 uint32_t handle; /* The connection handle */
307 bool cong; /* true, congested. false, uncongested */
308 } tBTA_JV_L2CAP_CONG;
309
310 /* data associated with BTA_JV_L2CAP_READ_EVT */
311 typedef struct {
312 tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */
313 uint32_t handle; /* The connection handle */
314 uint32_t req_id; /* The req_id in the associated BTA_JvL2capRead() */
315 uint8_t* p_data; /* This points the same location as the p_data
316 * 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
429 BTA_JV_RFCOMM_DATA_IND_EVT */
430 tBTA_JV_LE_DATA_IND le_data_ind; /* BTA_JV_L2CAP_LE_DATA_IND_EVT */
431 tBTA_JV_L2CAP_LE_OPEN l2c_le_open; /* BTA_JV_L2CAP_OPEN_EVT */
432 } tBTA_JV;
433
434 /* JAVA DM Interface callback */
435 typedef void(tBTA_JV_DM_CBACK)(tBTA_JV_EVT event, tBTA_JV* p_data, uint32_t id);
436
437 /* JAVA RFCOMM interface callback */
438 typedef uint32_t(tBTA_JV_RFCOMM_CBACK)(tBTA_JV_EVT event, tBTA_JV* p_data,
439 uint32_t rfcomm_slot_id);
440
441 /* JAVA L2CAP interface callback */
442 typedef void(tBTA_JV_L2CAP_CBACK)(tBTA_JV_EVT event, tBTA_JV* p_data,
443 uint32_t l2cap_socket_id);
444
445 /*******************************************************************************
446 *
447 * Function BTA_JvEnable
448 *
449 * Description Enable the Java I/F service. When the enable
450 * operation is complete the callback function will be
451 * called with a BTA_JV_ENABLE_EVT. This function must
452 * be called before other functions in the JV API are
453 * called.
454 *
455 * Returns BTA_JV_SUCCESS if successful.
456 * BTA_JV_FAIL if internal failure.
457 *
458 ******************************************************************************/
459 tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK* p_cback);
460
461 /*******************************************************************************
462 *
463 * Function BTA_JvDisable
464 *
465 * Description Disable the Java I/F
466 *
467 * Returns void
468 *
469 ******************************************************************************/
470 void BTA_JvDisable(void);
471
472 /*******************************************************************************
473 *
474 * Function BTA_JvGetChannelId
475 *
476 * Description This function reserves a SCN/PSM for applications running
477 * over RFCOMM or L2CAP. It is primarily called by
478 * server profiles/applications to register their SCN/PSM into
479 * the SDP database. The SCN is reported by the
480 * tBTA_JV_DM_CBACK callback with a BTA_JV_GET_SCN_EVT.
481 * If the SCN/PSM reported is 0, that means all SCN resources
482 * are exhausted.
483 * The channel parameter can be used to request a specific
484 * channel. If the request on the specific channel fails, the
485 * SCN/PSM returned in the EVT will be 0 - no attempt to
486 * request a new channel will be made. set channel to <= 0 to
487 * automatically assign an channel ID.
488 *
489 * Returns void
490 *
491 ******************************************************************************/
492 void BTA_JvGetChannelId(tBTA_JV_CONN_TYPE conn_type, uint32_t id,
493 int32_t channel);
494
495 /*******************************************************************************
496 *
497 * Function BTA_JvFreeChannel
498 *
499 * Description This function frees a SCN/PSM that was used
500 * by an application running over RFCOMM or L2CAP.
501 *
502 * Returns BTA_JV_SUCCESS, if the request is being processed.
503 * BTA_JV_FAILURE, otherwise.
504 *
505 ******************************************************************************/
506 tBTA_JV_STATUS BTA_JvFreeChannel(uint16_t channel, tBTA_JV_CONN_TYPE conn_type);
507
508 /*******************************************************************************
509 *
510 * Function BTA_JvStartDiscovery
511 *
512 * Description This function performs service discovery for the services
513 * provided by the given peer device. When the operation is
514 * complete the tBTA_JV_DM_CBACK callback function will be
515 * called with a BTA_JV_DISCOVERY_COMP_EVT.
516 *
517 * Returns BTA_JV_SUCCESS, if the request is being processed.
518 * BTA_JV_FAILURE, otherwise.
519 *
520 ******************************************************************************/
521 tBTA_JV_STATUS BTA_JvStartDiscovery(const RawAddress& bd_addr,
522 uint16_t num_uuid,
523 const bluetooth::Uuid* p_uuid_list,
524 uint32_t rfcomm_slot_id);
525
526 /*******************************************************************************
527 *
528 * Function BTA_JvCreateRecordByUser
529 *
530 * Description Create a service record in the local SDP database by user in
531 * tBTA_JV_DM_CBACK callback with a BTA_JV_CREATE_RECORD_EVT.
532 *
533 * Returns BTA_JV_SUCCESS, if the request is being processed.
534 * BTA_JV_FAILURE, otherwise.
535 *
536 ******************************************************************************/
537 tBTA_JV_STATUS BTA_JvCreateRecordByUser(uint32_t rfcomm_slot_id);
538
539 /*******************************************************************************
540 *
541 * Function BTA_JvDeleteRecord
542 *
543 * Description Delete a service record in the local SDP database.
544 *
545 * Returns BTA_JV_SUCCESS, if the request is being processed.
546 * BTA_JV_FAILURE, otherwise.
547 *
548 ******************************************************************************/
549 tBTA_JV_STATUS BTA_JvDeleteRecord(uint32_t handle);
550
551 /*******************************************************************************
552 *
553 * Function BTA_JvL2capConnect
554 *
555 * Description Initiate a connection as a L2CAP client to the given BD
556 * Address.
557 * When the connection is initiated or failed to initiate,
558 * tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_CL_INIT_EVT
559 * When the connection is established or failed,
560 * tBTA_JV_L2CAP_CBACK is called with BTA_JV_L2CAP_OPEN_EVT
561 *
562 ******************************************************************************/
563 void BTA_JvL2capConnect(tBTA_JV_CONN_TYPE conn_type, tBTA_SEC sec_mask,
564 std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,
565 uint16_t remote_psm, uint16_t rx_mtu,
566 std::unique_ptr<tL2CAP_CFG_INFO> cfg,
567 const RawAddress& peer_bd_addr,
568 tBTA_JV_L2CAP_CBACK* p_cback, uint32_t l2cap_socket_id);
569
570 /*******************************************************************************
571 *
572 * Function BTA_JvL2capClose
573 *
574 * Description This function closes an L2CAP client connection
575 *
576 * Returns BTA_JV_SUCCESS, if the request is being processed.
577 * BTA_JV_FAILURE, otherwise.
578 *
579 ******************************************************************************/
580 tBTA_JV_STATUS BTA_JvL2capClose(uint32_t handle);
581
582 /*******************************************************************************
583 *
584 * Function BTA_JvL2capStartServer
585 *
586 * Description This function starts an L2CAP server and listens for an
587 * L2CAP connection from a remote Bluetooth device. When the
588 * server is started successfully, tBTA_JV_L2CAP_CBACK is
589 * called with BTA_JV_L2CAP_START_EVT. When the connection is
590 * established, tBTA_JV_L2CAP_CBACK is called with
591 * BTA_JV_L2CAP_OPEN_EVT.
592 *
593 * Returns void
594 *
595 ******************************************************************************/
596 void BTA_JvL2capStartServer(tBTA_JV_CONN_TYPE conn_type, tBTA_SEC sec_mask,
597 std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,
598 uint16_t local_psm, uint16_t rx_mtu,
599 std::unique_ptr<tL2CAP_CFG_INFO> cfg,
600 tBTA_JV_L2CAP_CBACK* p_cback,
601 uint32_t l2cap_socket_id);
602
603 /*******************************************************************************
604 *
605 * Function BTA_JvL2capStopServer
606 *
607 * Description This function stops the L2CAP server. If the server has
608 * an active connection, it would be closed.
609 *
610 * Returns BTA_JV_SUCCESS, if the request is being processed.
611 * BTA_JV_FAILURE, otherwise.
612 *
613 ******************************************************************************/
614 tBTA_JV_STATUS BTA_JvL2capStopServer(uint16_t local_psm,
615 uint32_t l2cap_socket_id);
616
617 /*******************************************************************************
618 *
619 * Function BTA_JvL2capRead
620 *
621 * Description This function reads data from an L2CAP connection
622 * When the operation is complete, tBTA_JV_L2CAP_CBACK is
623 * called with BTA_JV_L2CAP_READ_EVT.
624 *
625 * Returns BTA_JV_SUCCESS, if the request is being processed.
626 * BTA_JV_FAILURE, otherwise.
627 *
628 ******************************************************************************/
629 tBTA_JV_STATUS BTA_JvL2capRead(uint32_t handle, uint32_t req_id,
630 uint8_t* p_data, uint16_t len);
631
632 /*******************************************************************************
633 *
634 * Function BTA_JvL2capReady
635 *
636 * Description This function determined if there is data to read from
637 * an L2CAP connection
638 *
639 * Returns BTA_JV_SUCCESS, if data queue size is in *p_data_size.
640 * BTA_JV_FAILURE, if error.
641 *
642 ******************************************************************************/
643 tBTA_JV_STATUS BTA_JvL2capReady(uint32_t handle, uint32_t* p_data_size);
644
645 /*******************************************************************************
646 *
647 * Function BTA_JvL2capWrite
648 *
649 * Description This function writes data to an L2CAP connection
650 * When the operation is complete, tBTA_JV_L2CAP_CBACK is
651 * called with BTA_JV_L2CAP_WRITE_EVT. Works for
652 * PSM-based connections
653 *
654 * Returns BTA_JV_SUCCESS, if the request is being processed.
655 * BTA_JV_FAILURE, otherwise.
656 *
657 ******************************************************************************/
658 tBTA_JV_STATUS BTA_JvL2capWrite(uint32_t handle, uint32_t req_id, BT_HDR* msg,
659 uint32_t user_id);
660
661 /*******************************************************************************
662 *
663 * Function BTA_JvRfcommConnect
664 *
665 * Description This function makes an RFCOMM conection to a remote BD
666 * Address.
667 * When the connection is initiated or failed to initiate,
668 * tBTA_JV_RFCOMM_CBACK is called with
669 * BTA_JV_RFCOMM_CL_INIT_EVT
670 * When the connection is established or failed,
671 * tBTA_JV_RFCOMM_CBACK is called with BTA_JV_RFCOMM_OPEN_EVT
672 *
673 * Returns BTA_JV_SUCCESS, if the request is being processed.
674 * BTA_JV_FAILURE, otherwise.
675 *
676 ******************************************************************************/
677 tBTA_JV_STATUS BTA_JvRfcommConnect(tBTA_SEC sec_mask, uint8_t remote_scn,
678 const RawAddress& peer_bd_addr,
679 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,
710 uint8_t max_session,
711 tBTA_JV_RFCOMM_CBACK* p_cback,
712 uint32_t rfcomm_slot_id);
713
714 /*******************************************************************************
715 *
716 * Function BTA_JvRfcommStopServer
717 *
718 * Description This function stops the RFCOMM server. If the server has an
719 * active connection, it would be closed.
720 *
721 * Returns BTA_JV_SUCCESS, if the request is being processed.
722 * BTA_JV_FAILURE, otherwise.
723 *
724 ******************************************************************************/
725 tBTA_JV_STATUS BTA_JvRfcommStopServer(uint32_t handle, uint32_t rfcomm_slot_id);
726
727 /*******************************************************************************
728 *
729 * Function BTA_JvRfcommWrite
730 *
731 * Description This function writes data to an RFCOMM connection
732 * When the operation is complete, tBTA_JV_RFCOMM_CBACK is
733 * called with BTA_JV_RFCOMM_WRITE_EVT.
734 *
735 * Returns BTA_JV_SUCCESS, if the request is being processed.
736 * BTA_JV_FAILURE, otherwise.
737 *
738 ******************************************************************************/
739 tBTA_JV_STATUS BTA_JvRfcommWrite(uint32_t handle, uint32_t req_id);
740
741 /*******************************************************************************
742 *
743 * Function BTA_JVSetPmProfile
744 *
745 * Description This function set or free power mode profile for different JV
746 * application
747 *
748 * Parameters: handle, JV handle from RFCOMM or L2CAP
749 * app_id: app specific pm ID, can be BTA_JV_PM_ALL, see
750 * bta_dm_cfg.c for details
751 * BTA_JV_PM_ID_CLEAR: removes pm management on the handle. init_st
752 * is ignored and BTA_JV_CONN_CLOSE is called
753 * implicitly
754 * init_st: state after calling this API. typically it should be
755 * BTA_JV_CONN_OPEN
756 *
757 * Returns BTA_JV_SUCCESS, if the request is being processed.
758 * BTA_JV_FAILURE, otherwise.
759 *
760 * NOTE: BTA_JV_PM_ID_CLEAR: In general no need to be called as jv pm
761 * calls automatically
762 * BTA_JV_CONN_CLOSE to remove in case of connection close!
763 *
764 ******************************************************************************/
765 tBTA_JV_STATUS BTA_JvSetPmProfile(uint32_t handle, tBTA_JV_PM_ID app_id,
766 tBTA_JV_CONN_STATE init_st);
767
768 /*******************************************************************************
769 *
770 * Function BTA_JvRfcommGetPortHdl
771 *
772 * Description This function fetches the rfcomm port handle
773 *
774 * Returns BTA_JV_SUCCESS, if the request is being processed.
775 * BTA_JV_FAILURE, otherwise.
776 *
777 ******************************************************************************/
778 uint16_t BTA_JvRfcommGetPortHdl(uint32_t handle);
779
780 #endif /* BTA_JV_API_H */
781