• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 2006-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This is the 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 <memory>
28 #include <unordered_set>
29 
30 #include "bta/include/bta_jv_api.h"
31 #include "bta/include/bta_sec_api.h"
32 #include "internal_include/bt_target.h"
33 #include "stack/include/bt_hdr.h"
34 #include "stack/include/rfcdefs.h"
35 #include "stack/include/sdp_status.h"
36 #include "types/bluetooth/uuid.h"
37 #include "types/raw_address.h"
38 
39 /*****************************************************************************
40  *  Constants
41  ****************************************************************************/
42 
43 #ifndef BTA_JV_RFC_EV_MASK
44 #define BTA_JV_RFC_EV_MASK (PORT_EV_RXCHAR | PORT_EV_TXEMPTY | PORT_EV_FC | PORT_EV_FCS)
45 #endif
46 
47 enum {
48   BTA_JV_PM_FREE_ST = 0, /* empty PM slot */
49   BTA_JV_PM_IDLE_ST,
50   BTA_JV_PM_BUSY_ST
51 };
52 
53 /* BTA JV PM control block */
54 typedef struct {
55   uint32_t handle;         /* The connection handle */
56   uint8_t state;           /* state: see above enum */
57   tBTA_JV_PM_ID app_id;    /* JV app specific id indicating power table to use */
58   RawAddress peer_bd_addr; /* Peer BD address */
59 } tBTA_JV_PM_CB;
60 
61 enum {
62   BTA_JV_ST_NONE = 0,
63   BTA_JV_ST_CL_OPENING,
64   BTA_JV_ST_CL_OPEN,
65   BTA_JV_ST_CL_CLOSING,
66   BTA_JV_ST_SR_LISTEN,
67   BTA_JV_ST_SR_OPEN,
68   BTA_JV_ST_SR_CLOSING
69 };
70 typedef uint8_t tBTA_JV_STATE;
71 #define BTA_JV_ST_CL_MAX BTA_JV_ST_CL_CLOSING
72 /* JV L2CAP control block */
73 typedef struct {
74   tBTA_JV_L2CAP_CBACK* p_cback; /* the callback function */
75   uint16_t psm;                 /* the psm used for this server connection */
76   tBTA_JV_STATE state;          /* the state of this control block */
77   tBTA_SERVICE_ID sec_id;       /* service id */
78   uint32_t handle;              /* the handle reported to java app (same as gap handle) */
79   bool cong;                    /* true, if congested */
80   tBTA_JV_PM_CB* p_pm_cb;       /* ptr to pm control block, NULL: unused */
81   uint32_t l2cap_socket_id;
82 } tBTA_JV_L2C_CB;
83 
84 #define BTA_JV_RFC_HDL_MASK 0xFF
85 #define BTA_JV_RFCOMM_MASK 0x80
86 #define BTA_JV_ALL_APP_ID 0xFF
87 #define BTA_JV_RFC_HDL_TO_SIDX(r) (((r) & 0xFF00) >> 8)
88 #define BTA_JV_RFC_H_S_TO_HDL(h, s) ((h) | ((s) << 8))
89 
90 /* port control block */
91 typedef struct {
92   uint32_t handle;      /* the rfcomm session handle at jv */
93   uint16_t port_handle; /* port handle */
94   tBTA_JV_STATE state;  /* the state of this control block */
95   uint8_t max_sess;     /* max sessions */
96   uint32_t rfcomm_slot_id;
97   bool cong;              /* true, if congested */
98   tBTA_JV_PM_CB* p_pm_cb; /* ptr to pm control block, NULL: unused */
99 } tBTA_JV_PCB;
100 
101 /* JV RFCOMM control block */
102 typedef struct {
103   tBTA_JV_RFCOMM_CBACK* p_cback; /* the callback function */
104   uint16_t rfc_hdl[BTA_JV_MAX_RFC_SR_SESSION];
105   tBTA_SERVICE_ID sec_id; /* service id */
106   uint8_t handle;         /* index: the handle reported to java app */
107   uint8_t scn;            /* the scn of the server */
108   uint8_t max_sess;       /* max sessions */
109   int curr_sess;          /* current sessions count*/
110 } tBTA_JV_RFC_CB;
111 
112 /* JV control block */
113 struct tBTA_JV_CB {
114   /* the SDP handle reported to JV user is the (index + 1) to sdp_handle[].
115    * if sdp_handle[i]==0, it's not used.
116    * otherwise sdp_handle[i] is the stack SDP handle. */
117   uint32_t sdp_handle[BTA_JV_MAX_SDP_REC]; /* SDP records created */
118   tBTA_JV_DM_CBACK* p_dm_cback;
119   tBTA_JV_L2C_CB l2c_cb[BTA_JV_MAX_L2C_CONN]; /* index is GAP handle (index) */
120   tBTA_JV_RFC_CB rfc_cb[BTA_JV_MAX_RFC_CONN];
121   tBTA_JV_PCB port_cb[MAX_RFC_PORTS];          /* index of this array is
122                                                   the port_handle, */
123   uint8_t sec_id[BTA_JV_NUM_SERVICE_ID];       /* service ID */
124   uint16_t free_psm_list[BTA_JV_MAX_L2C_CONN]; /* PSMs freed by java
125                                                 (can be reused) */
126   bool scn_in_use[RFCOMM_MAX_SCN];
127   uint8_t scn_search_index; /* used to search for free scns */
128 
129   struct sdp_cb {
130     bool sdp_active{false};
131     RawAddress bd_addr{RawAddress::kEmpty};         // current bd_addr of sdp discovery
132     bluetooth::Uuid uuid{bluetooth::Uuid::kEmpty};  // current uuid of sdp discovery
133   } sdp_cb;
134 
135   tBTA_JV_PM_CB pm_cb[BTA_JV_PM_MAX_NUM]; /* PM on a per JV handle bases */
136 
137   uint16_t dyn_psm; /* Next dynamic PSM value to try to assign */
138 };
139 
140 /* JV control block */
141 extern tBTA_JV_CB bta_jv_cb;
142 
143 extern std::unordered_set<uint16_t> used_l2cap_classic_dynamic_psm;
144 
145 void bta_jv_enable(tBTA_JV_DM_CBACK* p_cback);
146 void bta_jv_disable();
147 void bta_jv_get_channel_id(tBTA_JV_CONN_TYPE type, int32_t channel, uint32_t l2cap_socket_id,
148                            uint32_t rfcomm_slot_id);
149 void bta_jv_free_scn(tBTA_JV_CONN_TYPE type, uint16_t scn);
150 void bta_jv_start_discovery(const RawAddress& bd_addr, uint16_t num_uuid,
151                             bluetooth::Uuid* uuid_list, uint32_t rfcomm_slot_id);
152 void bta_jv_cancel_discovery(uint32_t rfcomm_slot_id);
153 void bta_jv_create_record(uint32_t rfcomm_slot_id);
154 void bta_jv_delete_record(uint32_t handle);
155 void bta_jv_l2cap_connect(tBTA_JV_CONN_TYPE type, tBTA_SEC sec_mask, uint16_t remote_psm,
156                           uint16_t rx_mtu, const RawAddress& peer_bd_addr,
157                           std::unique_ptr<tL2CAP_CFG_INFO> cfg,
158                           std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info, tBTA_JV_L2CAP_CBACK* p_cback,
159                           uint32_t l2cap_socket_id);
160 void bta_jv_l2cap_close(uint32_t handle, tBTA_JV_L2C_CB* p_cb);
161 void bta_jv_l2cap_start_server(tBTA_JV_CONN_TYPE type, tBTA_SEC sec_mask, uint16_t local_psm,
162                                uint16_t rx_mtu, std::unique_ptr<tL2CAP_CFG_INFO> cfg_param,
163                                std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,
164                                tBTA_JV_L2CAP_CBACK* p_cback, uint32_t l2cap_socket_id);
165 void bta_jv_l2cap_stop_server(uint16_t local_psm, uint32_t l2cap_socket_id);
166 void bta_jv_l2cap_write(uint32_t handle, uint32_t req_id, BT_HDR* msg, uint32_t user_id,
167                         tBTA_JV_L2C_CB* p_cb);
168 void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, uint8_t remote_scn, const RawAddress& peer_bd_addr,
169                            tBTA_JV_RFCOMM_CBACK* p_cback, uint32_t rfcomm_slot_id,
170                            RfcommCfgInfo cfg, uint32_t app_uid, uint64_t sdp_duration_ms);
171 void bta_jv_rfcomm_close(uint32_t handle, uint32_t rfcomm_slot_id);
172 void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, uint8_t local_scn, uint8_t max_session,
173                                 tBTA_JV_RFCOMM_CBACK* p_cback, uint32_t rfcomm_slot_id,
174                                 RfcommCfgInfo cfg, uint32_t app_uid);
175 void bta_jv_rfcomm_stop_server(uint32_t handle, uint32_t rfcomm_slot_id);
176 void bta_jv_rfcomm_write(uint32_t handle, uint32_t req_id, tBTA_JV_RFC_CB* p_cb,
177                          tBTA_JV_PCB* p_pcb);
178 void bta_jv_set_pm_profile(uint32_t handle, tBTA_JV_PM_ID app_id, tBTA_JV_CONN_STATE init_st);
179 
180 void bta_jv_l2cap_stop_server_le(uint16_t local_chan);
181 
182 namespace bluetooth::legacy::testing {
183 void bta_jv_start_discovery_cback(uint32_t rfcomm_slot_id, const RawAddress& bd_addr,
184                                   tSDP_RESULT result);
185 }  // namespace bluetooth::legacy::testing
186 
187 #endif /* BTA_JV_INT_H */
188