port_int.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 1999-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 file contains definitions internal to the PORT unit
  21. *
  22. *****************************************************************************/
  23. #ifndef PORT_INT_H
  24. #define PORT_INT_H
  25. #include "bt_target.h"
  26. #include "gki.h"
  27. #include "rfcdefs.h"
  28. #include "port_api.h"
  29. /* Local events passed when application event is sent from the api to PORT */
  30. /* ???*/
  31. #define PORT_EVENT_OPEN (1 | BT_EVT_TO_BTU_SP_EVT)
  32. #define PORT_EVENT_CONTROL (2 | BT_EVT_TO_BTU_SP_EVT)
  33. #define PORT_EVENT_SET_STATE (3 | BT_EVT_TO_BTU_SP_EVT)
  34. #define PORT_EVENT_SET_CALLBACK (5 | BT_EVT_TO_BTU_SP_EVT)
  35. #define PORT_EVENT_WRITE (6 | BT_EVT_TO_BTU_SP_EVT)
  36. #define PORT_EVENT_PURGE (7 | BT_EVT_TO_BTU_SP_EVT)
  37. #define PORT_EVENT_SEND_ERROR (8 | BT_EVT_TO_BTU_SP_EVT)
  38. #define PORT_EVENT_FLOW_CONTROL (9 | BT_EVT_TO_BTU_SP_EVT)
  39. /*
  40. ** Flow control configuration values for the mux
  41. */
  42. #define PORT_FC_UNDEFINED 0 /* mux flow control mechanism not defined yet */
  43. #define PORT_FC_TS710 1 /* use TS 07.10 flow control */
  44. #define PORT_FC_CREDIT 2 /* use RFCOMM credit based flow control */
  45. /*
  46. ** Define Port Data Transfere control block
  47. */
  48. typedef struct {
  49. BUFFER_Q queue; /* Queue of buffers waiting to be sent */
  50. BOOLEAN peer_fc; /* TRUE if flow control is set based on peer's request */
  51. BOOLEAN user_fc; /* TRUE if flow control is set based on user's request */
  52. UINT32 queue_size; /* Number of data bytes in the queue */
  53. tPORT_CALLBACK *p_callback; /* Address of the callback function */
  54. } tPORT_DATA;
  55. /*
  56. ** Port control structure used to pass modem info
  57. */
  58. typedef struct {
  59. #define MODEM_SIGNAL_DTRDSR 0x01
  60. #define MODEM_SIGNAL_RTSCTS 0x02
  61. #define MODEM_SIGNAL_RI 0x04
  62. #define MODEM_SIGNAL_DCD 0x08
  63. UINT8 modem_signal; /* [DTR/DSR | RTS/CTS | RI | DCD ] */
  64. UINT8 break_signal; /* 0-3 s in steps of 200 ms */
  65. UINT8 discard_buffers; /* 0 - do not discard, 1 - discard */
  66. #define RFCOMM_CTRL_BREAK_ASAP 0
  67. #define RFCOMM_CTRL_BREAK_IN_SEQ 1
  68. UINT8 break_signal_seq; /* as soon as possible | in sequence (default) */
  69. BOOLEAN fc; /* TRUE when the device is unable to accept frames */
  70. } tPORT_CTRL;
  71. /*
  72. ** RFCOMM multiplexer Control Block
  73. */
  74. typedef struct {
  75. TIMER_LIST_ENT tle; /* Timer list entry */
  76. BUFFER_Q cmd_q; /* Queue for command messages on this mux */
  77. UINT8 port_inx[RFCOMM_MAX_DLCI + 1]; /* Array for quick access to */
  78. /* tPORT based on dlci */
  79. BD_ADDR bd_addr; /* BD ADDR of the peer if initiator */
  80. UINT16 lcid; /* Local cid used for this channel */
  81. UINT16 peer_l2cap_mtu; /* Max frame that can be sent to peer L2CAP */
  82. UINT8 state; /* Current multiplexer channel state */
  83. UINT8 is_initiator; /* TRUE if this side sends SABME (dlci=0) */
  84. BOOLEAN local_cfg_sent;
  85. BOOLEAN peer_cfg_rcvd;
  86. BOOLEAN restart_required; /* TRUE if has to restart channel after disc */
  87. BOOLEAN peer_ready; /* True if other side can accept frames */
  88. UINT8 flow; /* flow control mechanism for this mux */
  89. BOOLEAN l2cap_congested; /* TRUE if L2CAP is congested */
  90. BOOLEAN is_disc_initiator; /* TRUE if initiated disc of port */
  91. UINT16 pending_lcid; /* store LCID for incoming connection while connecting */
  92. UINT8 pending_id; /* store l2cap ID for incoming connection while connecting */
  93. } tRFC_MCB;
  94. /*
  95. ** RFCOMM Port Connection Control Block
  96. */
  97. struct t_rfc_port {
  98. #define RFC_PORT_STATE_IDLE 0
  99. #define RFC_PORT_STATE_WAIT_START 1
  100. #define RFC_PORT_STATE_OPENING 2
  101. #define RFC_PORT_STATE_OPENED 3
  102. #define RFC_PORT_STATE_CLOSING 4
  103. UINT8 state; /* Current state of the connection */
  104. #define RFC_RSP_PN 0x01
  105. #define RFC_RSP_RPN_REPLY 0x02
  106. #define RFC_RSP_RPN 0x04
  107. #define RFC_RSP_MSC 0x08
  108. #define RFC_RSP_RLS 0x10
  109. UINT8 expected_rsp;
  110. tRFC_MCB *p_mcb;
  111. TIMER_LIST_ENT tle; /* Timer list entry */
  112. };
  113. typedef struct t_rfc_port tRFC_PORT;
  114. /*
  115. ** Define control block containing information about PORT connection
  116. */
  117. struct t_port_info {
  118. UINT8 inx; /* Index of this control block in the port_info array */
  119. BOOLEAN in_use; /* True when structure is allocated */
  120. #define PORT_STATE_CLOSED 0
  121. #define PORT_STATE_OPENING 1
  122. #define PORT_STATE_OPENED 2
  123. #define PORT_STATE_CLOSING 3
  124. UINT8 state; /* State of the application */
  125. UINT8 scn; /* Service channel number */
  126. UINT16 uuid; /* Service UUID */
  127. BD_ADDR bd_addr; /* BD ADDR of the device for the multiplexer channel */
  128. BOOLEAN is_server; /* TRUE if the server application */
  129. UINT8 dlci; /* DLCI of the connection */
  130. UINT8 error; /* Last error detected */
  131. UINT8 line_status; /* Line status as reported by peer */
  132. UINT8 default_signal_state; /* Initial signal state depending on uuid */
  133. UINT16 mtu; /* Max MTU that port can receive */
  134. UINT16 peer_mtu; /* Max MTU that port can send */
  135. tPORT_DATA tx; /* Control block for data from app to peer */
  136. tPORT_DATA rx; /* Control block for data from peer to app */
  137. tPORT_STATE user_port_pars; /* Port parameters for user connection */
  138. tPORT_STATE peer_port_pars; /* Port parameters for user connection */
  139. tPORT_CTRL local_ctrl;
  140. tPORT_CTRL peer_ctrl;
  141. #define PORT_CTRL_REQ_SENT 0x01
  142. #define PORT_CTRL_REQ_CONFIRMED 0x02
  143. #define PORT_CTRL_IND_RECEIVED 0x04
  144. #define PORT_CTRL_IND_RESPONDED 0x08
  145. UINT8 port_ctrl; /* Modem Status Command */
  146. BOOLEAN rx_flag_ev_pending; /* RXFLAG Character is received */
  147. tRFC_PORT rfc; /* RFCOMM port control block */
  148. UINT32 ev_mask; /* Event mask for the callback */
  149. tPORT_CALLBACK *p_callback; /* Pointer to users callback function */
  150. tPORT_CALLBACK *p_mgmt_callback; /* Callback function to receive connection up/down */
  151. tPORT_DATA_CALLBACK *p_data_callback; /* Callback function to receive data indications */
  152. tPORT_DATA_CO_CALLBACK *p_data_co_callback; /* Callback function with callouts and flowctrl */
  153. UINT16 credit_tx; /* Flow control credits for tx path */
  154. UINT16 credit_rx; /* Flow control credits for rx path, this is */
  155. /* number of buffers peer is allowed to sent */
  156. UINT16 credit_rx_max; /* Max number of credits we will allow this guy to sent */
  157. UINT16 credit_rx_low; /* Number of credits when we send credit update */
  158. UINT16 rx_buf_critical; /* port receive queue critical watermark level */
  159. BOOLEAN keep_port_handle; /* TRUE if port is not deallocated when closing */
  160. /* it is set to TRUE for server when allocating port */
  161. UINT16 keep_mtu; /* Max MTU that port can receive by server */
  162. };
  163. typedef struct t_port_info tPORT;
  164. /* Define the PORT/RFCOMM control structure
  165. */
  166. typedef struct {
  167. tPORT port[MAX_RFC_PORTS]; /* Port info pool */
  168. tRFC_MCB rfc_mcb[MAX_BD_CONNECTIONS]; /* RFCOMM bd_connections pool */
  169. } tPORT_CB;
  170. #ifdef __cplusplus
  171. extern "C" {
  172. #endif
  173. /*
  174. ** Functions provided by the port_utils.c
  175. */
  176. extern tPORT *port_allocate_port (UINT8 dlci, BD_ADDR bd_addr);
  177. extern void port_set_defaults (tPORT *p_port);
  178. extern void port_select_mtu (tPORT *p_port);
  179. extern void port_release_port (tPORT *p_port);
  180. extern tPORT *port_find_mcb_dlci_port (tRFC_MCB *p_mcb, UINT8 dlci);
  181. extern tRFC_MCB *port_find_mcb (BD_ADDR bd_addr);
  182. extern tPORT *port_find_dlci_port (UINT8 dlci);
  183. extern tPORT *port_find_port (UINT8 dlci, BD_ADDR bd_addr);
  184. extern UINT32 port_get_signal_changes (tPORT *p_port, UINT8 old_signals, UINT8 signal);
  185. extern UINT32 port_flow_control_user (tPORT *p_port);
  186. extern void port_flow_control_peer(tPORT *p_port, BOOLEAN enable, UINT16 count);
  187. /*
  188. ** Functions provided by the port_rfc.c
  189. */
  190. extern int port_open_continue (tPORT *p_port);
  191. extern void port_start_port_open (tPORT *p_port);
  192. extern void port_start_par_neg (tPORT *p_port);
  193. extern void port_start_control (tPORT *p_port);
  194. extern void port_start_close (tPORT *p_port);
  195. extern void port_rfc_closed (tPORT *p_port, UINT8 res);
  196. #ifdef __cplusplus
  197. }
  198. #endif
  199. #endif