port_int.h 9.4 KB

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