bta_jv_int.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. * This is the private interface file for the BTA Java I/F
  21. *
  22. ******************************************************************************/
  23. #ifndef BTA_JV_INT_H
  24. #define BTA_JV_INT_H
  25. #include "bta_api.h"
  26. #include "bta_jv_api.h"
  27. #include "bta_sys.h"
  28. #include "port_api.h"
  29. #include "rfcdefs.h"
  30. #include <memory>
  31. /*****************************************************************************
  32. * Constants
  33. ****************************************************************************/
  34. #ifndef BTA_JV_RFC_EV_MASK
  35. #define BTA_JV_RFC_EV_MASK \
  36. (PORT_EV_RXCHAR | PORT_EV_TXEMPTY | PORT_EV_FC | PORT_EV_FCS)
  37. #endif
  38. enum {
  39. BTA_JV_PM_FREE_ST = 0, /* empty PM slot */
  40. BTA_JV_PM_IDLE_ST,
  41. BTA_JV_PM_BUSY_ST
  42. };
  43. /* BTA JV PM control block */
  44. typedef struct {
  45. uint32_t handle; /* The connection handle */
  46. uint8_t state; /* state: see above enum */
  47. tBTA_JV_PM_ID app_id; /* JV app specific id indicating power table to use */
  48. RawAddress peer_bd_addr; /* Peer BD address */
  49. } tBTA_JV_PM_CB;
  50. enum {
  51. BTA_JV_ST_NONE = 0,
  52. BTA_JV_ST_CL_OPENING,
  53. BTA_JV_ST_CL_OPEN,
  54. BTA_JV_ST_CL_CLOSING,
  55. BTA_JV_ST_SR_LISTEN,
  56. BTA_JV_ST_SR_OPEN,
  57. BTA_JV_ST_SR_CLOSING
  58. };
  59. typedef uint8_t tBTA_JV_STATE;
  60. #define BTA_JV_ST_CL_MAX BTA_JV_ST_CL_CLOSING
  61. /* JV L2CAP control block */
  62. typedef struct {
  63. tBTA_JV_L2CAP_CBACK* p_cback; /* the callback function */
  64. uint16_t psm; /* the psm used for this server connection */
  65. tBTA_JV_STATE state; /* the state of this control block */
  66. tBTA_SERVICE_ID sec_id; /* service id */
  67. uint32_t handle; /* the handle reported to java app (same as gap handle) */
  68. bool cong; /* true, if congested */
  69. tBTA_JV_PM_CB* p_pm_cb; /* ptr to pm control block, NULL: unused */
  70. uint32_t l2cap_socket_id;
  71. } tBTA_JV_L2C_CB;
  72. #define BTA_JV_RFC_HDL_MASK 0xFF
  73. #define BTA_JV_RFCOMM_MASK 0x80
  74. #define BTA_JV_ALL_APP_ID 0xFF
  75. #define BTA_JV_RFC_HDL_TO_SIDX(r) (((r)&0xFF00) >> 8)
  76. #define BTA_JV_RFC_H_S_TO_HDL(h, s) ((h) | ((s) << 8))
  77. /* port control block */
  78. typedef struct {
  79. uint32_t handle; /* the rfcomm session handle at jv */
  80. uint16_t port_handle; /* port handle */
  81. tBTA_JV_STATE state; /* the state of this control block */
  82. uint8_t max_sess; /* max sessions */
  83. uint32_t rfcomm_slot_id;
  84. bool cong; /* true, if congested */
  85. tBTA_JV_PM_CB* p_pm_cb; /* ptr to pm control block, NULL: unused */
  86. } tBTA_JV_PCB;
  87. /* JV RFCOMM control block */
  88. typedef struct {
  89. tBTA_JV_RFCOMM_CBACK* p_cback; /* the callback function */
  90. uint16_t rfc_hdl[BTA_JV_MAX_RFC_SR_SESSION];
  91. tBTA_SERVICE_ID sec_id; /* service id */
  92. uint8_t handle; /* index: the handle reported to java app */
  93. uint8_t scn; /* the scn of the server */
  94. uint8_t max_sess; /* max sessions */
  95. int curr_sess; /* current sessions count*/
  96. } tBTA_JV_RFC_CB;
  97. /* JV control block */
  98. typedef struct {
  99. /* the SDP handle reported to JV user is the (index + 1) to sdp_handle[].
  100. * if sdp_handle[i]==0, it's not used.
  101. * otherwise sdp_handle[i] is the stack SDP handle. */
  102. uint32_t sdp_handle[BTA_JV_MAX_SDP_REC]; /* SDP records created */
  103. uint8_t* p_sel_raw_data; /* the raw data of last service select */
  104. tBTA_JV_DM_CBACK* p_dm_cback;
  105. tBTA_JV_L2C_CB l2c_cb[BTA_JV_MAX_L2C_CONN]; /* index is GAP handle (index) */
  106. tBTA_JV_RFC_CB rfc_cb[BTA_JV_MAX_RFC_CONN];
  107. tBTA_JV_PCB port_cb[MAX_RFC_PORTS]; /* index of this array is
  108. the port_handle, */
  109. uint8_t sec_id[BTA_JV_NUM_SERVICE_ID]; /* service ID */
  110. bool scn[BTA_JV_MAX_SCN]; /* SCN allocated by java */
  111. uint16_t free_psm_list[BTA_JV_MAX_L2C_CONN]; /* PSMs freed by java
  112. (can be reused) */
  113. uint8_t sdp_active; /* see BTA_JV_SDP_ACT_* */
  114. bluetooth::Uuid uuid; /* current uuid of sdp discovery*/
  115. tBTA_JV_PM_CB pm_cb[BTA_JV_PM_MAX_NUM]; /* PM on a per JV handle bases */
  116. } tBTA_JV_CB;
  117. enum {
  118. BTA_JV_SDP_ACT_NONE = 0,
  119. BTA_JV_SDP_ACT_YES, /* waiting for SDP result */
  120. BTA_JV_SDP_ACT_CANCEL /* waiting for cancel complete */
  121. };
  122. /* JV control block */
  123. extern tBTA_JV_CB bta_jv_cb;
  124. /* config struct */
  125. extern tBTA_JV_CFG* p_bta_jv_cfg;
  126. extern void bta_jv_enable(tBTA_JV_DM_CBACK* p_cback);
  127. extern void bta_jv_disable();
  128. extern void bta_jv_get_channel_id(int32_t type, int32_t channel,
  129. uint32_t l2cap_socket_id,
  130. uint32_t rfcomm_slot_id);
  131. extern void bta_jv_free_scn(int32_t type, uint16_t scn);
  132. extern void bta_jv_start_discovery(const RawAddress& bd_addr, uint16_t num_uuid,
  133. bluetooth::Uuid* uuid_list,
  134. uint32_t rfcomm_slot_id);
  135. extern void bta_jv_create_record(uint32_t rfcomm_slot_id);
  136. extern void bta_jv_delete_record(uint32_t handle);
  137. extern void bta_jv_l2cap_connect(int32_t type, tBTA_SEC sec_mask,
  138. tBTA_JV_ROLE role, uint16_t remote_psm,
  139. uint16_t rx_mtu,
  140. const RawAddress& peer_bd_addr,
  141. std::unique_ptr<tL2CAP_CFG_INFO> cfg,
  142. std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info,
  143. tBTA_JV_L2CAP_CBACK* p_cback,
  144. uint32_t l2cap_socket_id);
  145. extern void bta_jv_l2cap_close(uint32_t handle, tBTA_JV_L2C_CB* p_cb);
  146. extern void bta_jv_l2cap_start_server(
  147. int32_t type, tBTA_SEC sec_mask, tBTA_JV_ROLE role, uint16_t local_psm,
  148. uint16_t rx_mtu, std::unique_ptr<tL2CAP_CFG_INFO> cfg_param,
  149. std::unique_ptr<tL2CAP_ERTM_INFO> ertm_info, tBTA_JV_L2CAP_CBACK* p_cback,
  150. uint32_t l2cap_socket_id);
  151. extern void bta_jv_l2cap_stop_server(uint16_t local_psm,
  152. uint32_t l2cap_socket_id);
  153. extern void bta_jv_l2cap_write(uint32_t handle, uint32_t req_id, BT_HDR* msg,
  154. uint32_t user_id, tBTA_JV_L2C_CB* p_cb);
  155. extern void bta_jv_rfcomm_connect(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
  156. uint8_t remote_scn,
  157. const RawAddress& peer_bd_addr,
  158. tBTA_JV_RFCOMM_CBACK* p_cback,
  159. uint32_t rfcomm_slot_id);
  160. extern void bta_jv_rfcomm_close(uint32_t handle, uint32_t rfcomm_slot_id);
  161. extern void bta_jv_rfcomm_start_server(tBTA_SEC sec_mask, tBTA_JV_ROLE role,
  162. uint8_t local_scn, uint8_t max_session,
  163. tBTA_JV_RFCOMM_CBACK* p_cback,
  164. uint32_t rfcomm_slot_id);
  165. extern void bta_jv_rfcomm_stop_server(uint32_t handle, uint32_t rfcomm_slot_id);
  166. extern void bta_jv_rfcomm_write(uint32_t handle, uint32_t req_id,
  167. tBTA_JV_RFC_CB* p_cb, tBTA_JV_PCB* p_pcb);
  168. extern void bta_jv_set_pm_profile(uint32_t handle, tBTA_JV_PM_ID app_id,
  169. tBTA_JV_CONN_STATE init_st);
  170. extern void bta_jv_l2cap_connect_le(uint16_t remote_chan,
  171. const RawAddress& peer_bd_addr,
  172. tBTA_JV_L2CAP_CBACK* p_cback,
  173. uint32_t l2cap_socket_id);
  174. extern void bta_jv_l2cap_start_server_le(uint16_t local_chan,
  175. tBTA_JV_L2CAP_CBACK* p_cback,
  176. uint32_t l2cap_socket_id);
  177. extern void bta_jv_l2cap_stop_server_le(uint16_t local_chan);
  178. extern void bta_jv_l2cap_write_fixed(uint16_t channel, const RawAddress& addr,
  179. uint32_t req_id, BT_HDR* msg,
  180. uint32_t user_id,
  181. tBTA_JV_L2CAP_CBACK* p_cback);
  182. extern void bta_jv_l2cap_close_fixed(uint32_t handle);
  183. #endif /* BTA_JV_INT_H */