OSDN Git Service

07396d019361829ee839e22c2e5949469ccd3f85
[android-x86/system-bt.git] / bta / jv / bta_jv_int.h
1 /******************************************************************************
2  *
3  *  Copyright (C) 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 private interface file for the BTA Java I/F
22  *
23  ******************************************************************************/
24 #ifndef BTA_JV_INT_H
25 #define BTA_JV_INT_H
26
27 #include "bta_sys.h"
28 #include "bta_api.h"
29 #include "bta_jv_api.h"
30 #include "rfcdefs.h"
31 #include "port_api.h"
32
33 /*****************************************************************************
34 **  Constants
35 *****************************************************************************/
36
37 enum
38 {
39     /* these events are handled by the state machine */
40     BTA_JV_API_ENABLE_EVT = BTA_SYS_EVT_START(BTA_ID_JV),
41     BTA_JV_API_DISABLE_EVT,
42     BTA_JV_API_GET_CHANNEL_EVT,
43     BTA_JV_API_FREE_SCN_EVT,
44     BTA_JV_API_START_DISCOVERY_EVT,
45     BTA_JV_API_CREATE_RECORD_EVT,
46     BTA_JV_API_DELETE_RECORD_EVT,
47     BTA_JV_API_L2CAP_CONNECT_EVT,
48     BTA_JV_API_L2CAP_CLOSE_EVT,
49     BTA_JV_API_L2CAP_START_SERVER_EVT,
50     BTA_JV_API_L2CAP_STOP_SERVER_EVT,
51     BTA_JV_API_L2CAP_READ_EVT,
52     BTA_JV_API_L2CAP_WRITE_EVT,
53     BTA_JV_API_RFCOMM_CONNECT_EVT,
54     BTA_JV_API_RFCOMM_CLOSE_EVT,
55     BTA_JV_API_RFCOMM_START_SERVER_EVT,
56     BTA_JV_API_RFCOMM_STOP_SERVER_EVT,
57     BTA_JV_API_RFCOMM_READ_EVT,
58     BTA_JV_API_RFCOMM_WRITE_EVT,
59     BTA_JV_API_SET_PM_PROFILE_EVT,
60     BTA_JV_API_PM_STATE_CHANGE_EVT,
61     BTA_JV_API_L2CAP_CONNECT_LE_EVT,
62     BTA_JV_API_L2CAP_START_SERVER_LE_EVT,
63     BTA_JV_API_L2CAP_STOP_SERVER_LE_EVT,
64     BTA_JV_API_L2CAP_WRITE_FIXED_EVT,
65     BTA_JV_API_L2CAP_CLOSE_FIXED_EVT,
66     BTA_JV_MAX_INT_EVT
67 };
68
69 #ifndef BTA_JV_RFC_EV_MASK
70 #define BTA_JV_RFC_EV_MASK (PORT_EV_RXCHAR | PORT_EV_TXEMPTY | PORT_EV_FC | PORT_EV_FCS)
71 #endif
72
73 /* data type for BTA_JV_API_ENABLE_EVT */
74 typedef struct
75 {
76     BT_HDR          hdr;
77     tBTA_JV_DM_CBACK   *p_cback;
78 } tBTA_JV_API_ENABLE;
79
80 /* data type for BTA_JV_API_START_DISCOVERY_EVT */
81 typedef struct
82 {
83     BT_HDR      hdr;
84     BD_ADDR bd_addr;
85     UINT16 num_uuid;
86     tSDP_UUID uuid_list[BTA_JV_MAX_UUIDS];
87     UINT16 num_attr;
88     UINT16 attr_list[BTA_JV_MAX_ATTRS];
89     void            *user_data;      /* piggyback caller's private data*/
90 } tBTA_JV_API_START_DISCOVERY;
91
92 enum
93 {
94     BTA_JV_PM_FREE_ST = 0, /* empty PM slot */
95     BTA_JV_PM_IDLE_ST,
96     BTA_JV_PM_BUSY_ST
97 };
98
99 /* BTA JV PM control block */
100 typedef struct
101 {
102     UINT32          handle;     /* The connection handle */
103     UINT8           state;      /* state: see above enum */
104     tBTA_JV_PM_ID   app_id;     /* JV app specific id indicating power table to use */
105     BD_ADDR         peer_bd_addr;    /* Peer BD address */
106 } tBTA_JV_PM_CB;
107
108 enum
109 {
110     BTA_JV_ST_NONE = 0,
111     BTA_JV_ST_CL_OPENING,
112     BTA_JV_ST_CL_OPEN,
113     BTA_JV_ST_CL_CLOSING,
114     BTA_JV_ST_SR_LISTEN,
115     BTA_JV_ST_SR_OPEN,
116     BTA_JV_ST_SR_CLOSING
117 } ;
118 typedef UINT8  tBTA_JV_STATE;
119 #define BTA_JV_ST_CL_MAX    BTA_JV_ST_CL_CLOSING
120 /* JV L2CAP control block */
121 typedef struct
122 {
123     tBTA_JV_L2CAP_CBACK *p_cback;   /* the callback function */
124     UINT16              psm;        /* the psm used for this server connection */
125     tBTA_JV_STATE       state;      /* the state of this control block */
126     tBTA_SERVICE_ID     sec_id;     /* service id */
127     UINT32              handle;     /* the handle reported to java app (same as gap handle) */
128     BOOLEAN             cong;       /* TRUE, if congested */
129     tBTA_JV_PM_CB      *p_pm_cb;    /* ptr to pm control block, NULL: unused */
130     void                *user_data; /* user data for callback from higher layers */
131 } tBTA_JV_L2C_CB;
132
133 #define BTA_JV_RFC_HDL_MASK         0xFF
134 #define BTA_JV_RFCOMM_MASK          0x80
135 #define BTA_JV_ALL_APP_ID           0xFF
136 #define BTA_JV_RFC_HDL_TO_SIDX(r)   (((r)&0xFF00) >> 8)
137 #define BTA_JV_RFC_H_S_TO_HDL(h, s) ((h)|(s<<8))
138
139 /* port control block */
140 typedef struct
141 {
142     UINT32              handle;     /* the rfcomm session handle at jv */
143     UINT16              port_handle;/* port handle */
144     tBTA_JV_STATE       state;      /* the state of this control block */
145     UINT8               max_sess;   /* max sessions */
146     void                *user_data; /* piggyback caller's private data*/
147     BOOLEAN             cong;       /* TRUE, if congested */
148     tBTA_JV_PM_CB       *p_pm_cb;   /* ptr to pm control block, NULL: unused */
149 } tBTA_JV_PCB;
150
151 /* JV RFCOMM control block */
152 typedef struct
153 {
154     tBTA_JV_RFCOMM_CBACK *p_cback;  /* the callback function */
155     UINT16              rfc_hdl[BTA_JV_MAX_RFC_SR_SESSION];
156     tBTA_SERVICE_ID     sec_id;     /* service id */
157     UINT8               handle;     /* index: the handle reported to java app */
158     UINT8               scn;        /* the scn of the server */
159     UINT8               max_sess;   /* max sessions */
160     int                 curr_sess;   /* current sessions count*/
161 } tBTA_JV_RFC_CB;
162
163 /* data type for BTA_JV_API_L2CAP_CONNECT_EVT & BTA_JV_API_L2CAP_CONNECT_LE_EVT */
164 typedef struct
165 {
166     BT_HDR              hdr;
167     INT32               type;       /* One of BTA_JV_CONN_TYPE_ */
168     tBTA_SEC            sec_mask;
169     tBTA_JV_ROLE        role;
170     union {
171         UINT16          remote_psm;
172         UINT16          remote_chan;
173     };
174     UINT16              rx_mtu;
175     BD_ADDR             peer_bd_addr;
176     INT32               has_cfg;
177     tL2CAP_CFG_INFO     cfg;
178     INT32               has_ertm_info;
179     tL2CAP_ERTM_INFO    ertm_info;
180     tBTA_JV_L2CAP_CBACK *p_cback;
181     void                *user_data;
182 } tBTA_JV_API_L2CAP_CONNECT;
183
184 /* data type for BTA_JV_API_L2CAP_SERVER_EVT */
185 typedef struct
186 {
187     BT_HDR              hdr;
188     INT32               type;       /* One of BTA_JV_CONN_TYPE_ */
189     tBTA_SEC            sec_mask;
190     tBTA_JV_ROLE        role;
191     union {
192         UINT16          local_psm;
193         UINT16          local_chan;
194     };
195     UINT16              rx_mtu;
196     INT32               has_cfg;
197     tL2CAP_CFG_INFO     cfg;
198     INT32               has_ertm_info;
199     tL2CAP_ERTM_INFO    ertm_info;
200     tBTA_JV_L2CAP_CBACK *p_cback;
201     void                *user_data;
202 } tBTA_JV_API_L2CAP_SERVER;
203
204 /* data type for BTA_JV_API_L2CAP_CLOSE_EVT */
205 typedef struct
206 {
207     BT_HDR          hdr;
208     UINT32          handle;
209     tBTA_JV_L2C_CB  *p_cb;
210 } tBTA_JV_API_L2CAP_CLOSE;
211
212 /* data type for BTA_JV_API_L2CAP_READ_EVT */
213 typedef struct
214 {
215     BT_HDR              hdr;
216     UINT32              handle;
217     UINT32              req_id;
218     tBTA_JV_L2CAP_CBACK *p_cback;
219     UINT8*              p_data;
220     UINT16              len;
221     void                *user_data;
222 } tBTA_JV_API_L2CAP_READ;
223
224 /* data type for BTA_JV_API_L2CAP_WRITE_EVT */
225 typedef struct
226 {
227     BT_HDR              hdr;
228     UINT32              handle;
229     UINT32              req_id;
230     tBTA_JV_L2C_CB      *p_cb;
231     UINT8               *p_data;
232     UINT16              len;
233     void                *user_data;
234 } tBTA_JV_API_L2CAP_WRITE;
235
236 /* data type for BTA_JV_API_L2CAP_WRITE_FIXED_EVT */
237 typedef struct
238 {
239     BT_HDR              hdr;
240     UINT16              channel;
241     BD_ADDR             addr;
242     UINT32              req_id;
243     tBTA_JV_L2CAP_CBACK *p_cback;
244     UINT8               *p_data;
245     UINT16              len;
246     void                *user_data;
247 } tBTA_JV_API_L2CAP_WRITE_FIXED;
248
249 /* data type for BTA_JV_API_RFCOMM_CONNECT_EVT */
250 typedef struct
251 {
252     BT_HDR          hdr;
253     tBTA_SEC        sec_mask;
254     tBTA_JV_ROLE    role;
255     UINT8           remote_scn;
256     BD_ADDR         peer_bd_addr;
257     tBTA_JV_RFCOMM_CBACK *p_cback;
258     void            *user_data;
259 } tBTA_JV_API_RFCOMM_CONNECT;
260
261 /* data type for BTA_JV_API_RFCOMM_SERVER_EVT */
262 typedef struct
263 {
264     BT_HDR          hdr;
265     tBTA_SEC        sec_mask;
266     tBTA_JV_ROLE    role;
267     UINT8           local_scn;
268     UINT8           max_session;
269     UINT32          handle;
270     tBTA_JV_RFCOMM_CBACK *p_cback;
271     void            *user_data;
272 } tBTA_JV_API_RFCOMM_SERVER;
273
274 /* data type for BTA_JV_API_RFCOMM_READ_EVT */
275 typedef struct
276 {
277     BT_HDR          hdr;
278     UINT32          handle;
279     UINT32          req_id;
280     UINT8           *p_data;
281     UINT16          len;
282     tBTA_JV_RFC_CB  *p_cb;
283     tBTA_JV_PCB     *p_pcb;
284 } tBTA_JV_API_RFCOMM_READ;
285
286 /* data type for BTA_JV_API_SET_PM_PROFILE_EVT */
287 typedef struct
288 {
289     BT_HDR              hdr;
290     UINT32              handle;
291     tBTA_JV_PM_ID       app_id;
292     tBTA_JV_CONN_STATE  init_st;
293 } tBTA_JV_API_SET_PM_PROFILE;
294
295 /* data type for BTA_JV_API_PM_STATE_CHANGE_EVT */
296 typedef struct
297 {
298     BT_HDR              hdr;
299     tBTA_JV_PM_CB       *p_cb;
300     tBTA_JV_CONN_STATE  state;
301 } tBTA_JV_API_PM_STATE_CHANGE;
302
303 /* data type for BTA_JV_API_RFCOMM_WRITE_EVT */
304 typedef struct
305 {
306     BT_HDR          hdr;
307     UINT32          handle;
308     UINT32          req_id;
309     UINT8           *p_data;
310     int             len;
311     tBTA_JV_RFC_CB  *p_cb;
312     tBTA_JV_PCB     *p_pcb;
313 } tBTA_JV_API_RFCOMM_WRITE;
314
315 /* data type for BTA_JV_API_RFCOMM_CLOSE_EVT */
316 typedef struct
317 {
318     BT_HDR          hdr;
319     UINT32          handle;
320     tBTA_JV_RFC_CB  *p_cb;
321     tBTA_JV_PCB     *p_pcb;
322     void            *user_data;
323 } tBTA_JV_API_RFCOMM_CLOSE;
324
325 /* data type for BTA_JV_API_CREATE_RECORD_EVT */
326 typedef struct
327 {
328     BT_HDR      hdr;
329     void        *user_data;
330 } tBTA_JV_API_CREATE_RECORD;
331
332 /* data type for BTA_JV_API_ADD_ATTRIBUTE_EVT */
333 typedef struct
334 {
335     BT_HDR      hdr;
336     UINT32      handle;
337     UINT16      attr_id;
338     UINT8       *p_value;
339     INT32       value_size;
340 } tBTA_JV_API_ADD_ATTRIBUTE;
341
342 /* data type for BTA_JV_API_FREE_SCN_EVT */
343 typedef struct
344 {
345     BT_HDR      hdr;
346     INT32       type;       /* One of BTA_JV_CONN_TYPE_ */
347     UINT16      scn;
348 } tBTA_JV_API_FREE_CHANNEL;
349
350 /* data type for BTA_JV_API_ALLOC_CHANNEL_EVT */
351 typedef struct
352 {
353     BT_HDR      hdr;
354     INT32       type;       /* One of BTA_JV_CONN_TYPE_ */
355     INT32       channel;    /* optionally request a specific channel */
356     void        *user_data;
357 } tBTA_JV_API_ALLOC_CHANNEL;
358 /* union of all data types */
359 typedef union
360 {
361     /* GKI event buffer header */
362     BT_HDR                          hdr;
363     tBTA_JV_API_ENABLE              enable;
364     tBTA_JV_API_START_DISCOVERY     start_discovery;
365     tBTA_JV_API_ALLOC_CHANNEL       alloc_channel;
366     tBTA_JV_API_FREE_CHANNEL        free_channel;
367     tBTA_JV_API_CREATE_RECORD       create_record;
368     tBTA_JV_API_ADD_ATTRIBUTE       add_attr;
369     tBTA_JV_API_L2CAP_CONNECT       l2cap_connect;
370     tBTA_JV_API_L2CAP_READ          l2cap_read;
371     tBTA_JV_API_L2CAP_WRITE         l2cap_write;
372     tBTA_JV_API_L2CAP_CLOSE         l2cap_close;
373     tBTA_JV_API_L2CAP_SERVER        l2cap_server;
374     tBTA_JV_API_RFCOMM_CONNECT      rfcomm_connect;
375     tBTA_JV_API_RFCOMM_READ         rfcomm_read;
376     tBTA_JV_API_RFCOMM_WRITE        rfcomm_write;
377     tBTA_JV_API_SET_PM_PROFILE      set_pm;
378     tBTA_JV_API_PM_STATE_CHANGE     change_pm_state;
379     tBTA_JV_API_RFCOMM_CLOSE        rfcomm_close;
380     tBTA_JV_API_RFCOMM_SERVER       rfcomm_server;
381     tBTA_JV_API_L2CAP_WRITE_FIXED   l2cap_write_fixed;
382 } tBTA_JV_MSG;
383
384 /* JV control block */
385 typedef struct
386 {
387     /* the SDP handle reported to JV user is the (index + 1) to sdp_handle[].
388      * if sdp_handle[i]==0, it's not used.
389      * otherwise sdp_handle[i] is the stack SDP handle. */
390     UINT32                  sdp_handle[BTA_JV_MAX_SDP_REC]; /* SDP records created */
391     UINT8                   *p_sel_raw_data;/* the raw data of last service select */
392     tBTA_JV_DM_CBACK        *p_dm_cback;
393     tBTA_JV_L2C_CB          l2c_cb[BTA_JV_MAX_L2C_CONN];    /* index is GAP handle (index) */
394     tBTA_JV_RFC_CB          rfc_cb[BTA_JV_MAX_RFC_CONN];
395     tBTA_JV_PCB             port_cb[MAX_RFC_PORTS];         /* index of this array is
396                                                                the port_handle, */
397     UINT8                   sec_id[BTA_JV_NUM_SERVICE_ID];  /* service ID */
398     BOOLEAN                 scn[BTA_JV_MAX_SCN];            /* SCN allocated by java */
399     UINT16                  free_psm_list[BTA_JV_MAX_L2C_CONN];  /* PSMs freed by java
400                                                                     (can be reused) */
401     UINT8                   sdp_active;                     /* see BTA_JV_SDP_ACT_* */
402     tSDP_UUID               uuid;                           /* current uuid of sdp discovery*/
403     tBTA_JV_PM_CB           pm_cb[BTA_JV_PM_MAX_NUM];       /* PM on a per JV handle bases */
404 } tBTA_JV_CB;
405
406 enum
407 {
408     BTA_JV_SDP_ACT_NONE = 0,
409     BTA_JV_SDP_ACT_YES,     /* waiting for SDP result */
410     BTA_JV_SDP_ACT_CANCEL   /* waiting for cancel complete */
411 };
412
413 /* JV control block */
414 #if BTA_DYNAMIC_MEMORY == FALSE
415 extern tBTA_JV_CB bta_jv_cb;
416 #else
417 extern tBTA_JV_CB *bta_jv_cb_ptr;
418 #define bta_jv_cb (*bta_jv_cb_ptr)
419 #endif
420
421 /* config struct */
422 extern tBTA_JV_CFG *p_bta_jv_cfg;
423
424 extern BOOLEAN bta_jv_sm_execute(BT_HDR *p_msg);
425
426 extern void bta_jv_enable (tBTA_JV_MSG *p_data);
427 extern void bta_jv_disable (tBTA_JV_MSG *p_data);
428 extern void bta_jv_get_channel_id (tBTA_JV_MSG *p_data);
429 extern void bta_jv_free_scn (tBTA_JV_MSG *p_data);
430 extern void bta_jv_start_discovery (tBTA_JV_MSG *p_data);
431 extern void bta_jv_create_record (tBTA_JV_MSG *p_data);
432 extern void bta_jv_delete_record (tBTA_JV_MSG *p_data);
433 extern void bta_jv_l2cap_connect (tBTA_JV_MSG *p_data);
434 extern void bta_jv_l2cap_close (tBTA_JV_MSG *p_data);
435 extern void bta_jv_l2cap_start_server (tBTA_JV_MSG *p_data);
436 extern void bta_jv_l2cap_stop_server (tBTA_JV_MSG *p_data);
437 extern void bta_jv_l2cap_read (tBTA_JV_MSG *p_data);
438 extern void bta_jv_l2cap_write (tBTA_JV_MSG *p_data);
439 extern void bta_jv_rfcomm_connect (tBTA_JV_MSG *p_data);
440 extern void bta_jv_rfcomm_close (tBTA_JV_MSG *p_data);
441 extern void bta_jv_rfcomm_start_server (tBTA_JV_MSG *p_data);
442 extern void bta_jv_rfcomm_stop_server (tBTA_JV_MSG *p_data);
443 extern void bta_jv_rfcomm_read (tBTA_JV_MSG *p_data);
444 extern void bta_jv_rfcomm_write (tBTA_JV_MSG *p_data);
445 extern void bta_jv_set_pm_profile (tBTA_JV_MSG *p_data);
446 extern void bta_jv_change_pm_state(tBTA_JV_MSG *p_data);
447 extern void bta_jv_l2cap_connect_le (tBTA_JV_MSG *p_data);
448 extern void bta_jv_l2cap_start_server_le (tBTA_JV_MSG *p_data);
449 extern void bta_jv_l2cap_stop_server_le (tBTA_JV_MSG *p_data);
450 extern void bta_jv_l2cap_write_fixed (tBTA_JV_MSG *p_data);
451 extern void bta_jv_l2cap_close_fixed (tBTA_JV_MSG *p_data);
452
453 #endif /* BTA_JV_INT_H */