rfc_int.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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 RFC unit
  21. *
  22. *****************************************************************************/
  23. #ifndef RFC_INT_H
  24. #define RFC_INT_H
  25. #include "stack/l2c_api.h"
  26. #include "port_int.h"
  27. /*
  28. ** Define RFCOMM result codes
  29. */
  30. #define RFCOMM_SUCCESS 0
  31. #define RFCOMM_ERROR 1
  32. #define RFCOMM_LOW_RESOURCES 2
  33. #define RFCOMM_TRY_LATER 3
  34. #define RFCOMM_USER_ERR 111
  35. #define RFCOMM_SECURITY_ERR 112
  36. /*
  37. ** Define max and min RFCOMM MTU (N1)
  38. */
  39. #define RFCOMM_MIN_MTU 23
  40. #define RFCOMM_MAX_MTU 32767
  41. extern void RFCOMM_StartReq (tRFC_MCB *p_mcb);
  42. extern void RFCOMM_StartRsp (tRFC_MCB *p_mcb, UINT16 result);
  43. extern void RFCOMM_DlcEstablishReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu);
  44. extern void RFCOMM_DlcEstablishRsp (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT16 result);
  45. extern void RFCOMM_DataReq (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf);
  46. extern void RFCOMM_DlcReleaseReq (tRFC_MCB *p_mcb, UINT8 dlci);
  47. extern void RFCOMM_ParNegReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu);
  48. extern void RFCOMM_ParNegRsp (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT8 cl, UINT8 k);
  49. extern void RFCOMM_TestReq (UINT8 *p_data, UINT16 len);
  50. #define RFCOMM_FLOW_STATE_DISABLE 0
  51. #define RFCOMM_FLOW_STATE_ENABLE 1
  52. extern void RFCOMM_FlowReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT8 state);
  53. extern void RFCOMM_PortNegReq (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_STATE *p_pars);
  54. extern void RFCOMM_PortNegRsp (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_STATE *p_pars, UINT16 param_mask);
  55. extern void RFCOMM_ControlReq (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_CTRL *p_pars);
  56. extern void RFCOMM_ControlRsp (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_CTRL *p_pars);
  57. extern void RFCOMM_LineStatusReq (tRFC_MCB *p_mcb, UINT8 dlci, UINT8 line_status);
  58. /*
  59. ** Define logical struct used for sending and decoding MX frames
  60. */
  61. typedef struct {
  62. UINT8 dlci;
  63. UINT8 type;
  64. UINT8 cr;
  65. UINT8 ea;
  66. UINT8 pf;
  67. UINT8 credit;
  68. union {
  69. struct {
  70. UINT8 dlci;
  71. UINT8 frame_type;
  72. UINT8 conv_layer;
  73. UINT8 priority;
  74. UINT8 t1;
  75. UINT16 mtu;
  76. UINT8 n2;
  77. UINT8 k;
  78. } pn;
  79. struct {
  80. UINT8 *p_data;
  81. UINT16 data_len;
  82. } test;
  83. struct {
  84. UINT8 dlci;
  85. UINT8 signals;
  86. UINT8 break_present;
  87. UINT8 break_duration;
  88. } msc;
  89. struct {
  90. UINT8 ea;
  91. UINT8 cr;
  92. UINT8 type;
  93. } nsc;
  94. struct {
  95. UINT8 dlci;
  96. UINT8 is_request;
  97. UINT8 baud_rate;
  98. UINT8 byte_size;
  99. UINT8 stop_bits;
  100. UINT8 parity;
  101. UINT8 parity_type;
  102. UINT8 fc_type;
  103. UINT8 xon_char;
  104. UINT8 xoff_char;
  105. UINT16 param_mask;
  106. } rpn;
  107. struct {
  108. UINT8 dlci;
  109. UINT8 line_status;
  110. } rls;
  111. } u;
  112. } MX_FRAME;
  113. #define LINE_STATUS_NO_ERROR 0x00
  114. #define LINE_STATUS_OVERRUN 0x02 /* Receive Overrun Error */
  115. #define LINE_STATUS_RXPARITY 0x04 /* Receive Parity Error */
  116. #define LINE_STATUS_FRAME 0x08 /* Receive Framing error */
  117. #define LINE_STATUS_FAILED 0x10 /* Connection Failed */
  118. /*
  119. ** Define states and events for the RFC multiplexer state machine
  120. */
  121. #define RFC_MX_STATE_IDLE 0
  122. #define RFC_MX_STATE_WAIT_CONN_CNF 1
  123. #define RFC_MX_STATE_CONFIGURE 2
  124. #define RFC_MX_STATE_SABME_WAIT_UA 3
  125. #define RFC_MX_STATE_WAIT_SABME 4
  126. #define RFC_MX_STATE_CONNECTED 5
  127. #define RFC_MX_STATE_DISC_WAIT_UA 6
  128. /*
  129. ** Define port states
  130. */
  131. #define RFC_STATE_CLOSED 0
  132. #define RFC_STATE_SABME_WAIT_UA 1
  133. #define RFC_STATE_ORIG_WAIT_SEC_CHECK 2
  134. #define RFC_STATE_TERM_WAIT_SEC_CHECK 3
  135. #define RFC_STATE_OPENED 4
  136. #define RFC_STATE_DISC_WAIT_UA 5
  137. /*
  138. ** Events that can be received by multiplexer as well as port state machines
  139. */
  140. #define RFC_EVENT_SABME 0
  141. #define RFC_EVENT_UA 1
  142. #define RFC_EVENT_DM 2
  143. #define RFC_EVENT_DISC 3
  144. #define RFC_EVENT_UIH 4
  145. #define RFC_EVENT_TIMEOUT 5
  146. #define RFC_EVENT_BAD_FRAME 50
  147. /*
  148. ** Multiplexer events
  149. */
  150. #define RFC_MX_EVENT_START_REQ 6
  151. #define RFC_MX_EVENT_START_RSP 7
  152. #define RFC_MX_EVENT_CLOSE_REQ 8
  153. #define RFC_MX_EVENT_CONN_CNF 9
  154. #define RFC_MX_EVENT_CONN_IND 10
  155. #define RFC_MX_EVENT_CONF_CNF 11
  156. #define RFC_MX_EVENT_CONF_IND 12
  157. #define RFC_MX_EVENT_QOS_VIOLATION_IND 13
  158. #define RFC_MX_EVENT_DISC_IND 14
  159. #define RFC_MX_EVENT_TEST_CMD 15
  160. #define RFC_MX_EVENT_TEST_RSP 16
  161. #define RFC_MX_EVENT_FCON_CMD 17
  162. #define RFC_MX_EVENT_FCOFF_CMD 18
  163. #define RFC_MX_EVENT_NSC 19
  164. #define RFC_MX_EVENT_NSC_RSP 20
  165. /*
  166. ** Port events
  167. */
  168. #define RFC_EVENT_OPEN 9
  169. #define RFC_EVENT_ESTABLISH_RSP 11
  170. #define RFC_EVENT_CLOSE 12
  171. #define RFC_EVENT_CLEAR 13
  172. #define RFC_EVENT_DATA 14
  173. #define RFC_EVENT_SEC_COMPLETE 15
  174. // btla-specific ++
  175. #define RFC_T1_TIMEOUT 20 /* seconds to wait for reply with Poll bit */
  176. #define RFC_PORT_T1_TIMEOUT 60 /* seconds to wait for reply with Poll bit other than MX */
  177. #define RFC_T2_TIMEOUT 20 /* timeout to wait for Mx UIH */
  178. // btla-specific --
  179. #define RFC_DISC_TIMEOUT 3 /* If something goes wrong and we send DISC we should not wait for min */
  180. #define RFC_CLOSE_TIMEOUT 10
  181. #define RFCOMM_CONN_TIMEOUT 120 /* first connection to be established on Mx */
  182. /* Define RFComm control block
  183. */
  184. typedef struct {
  185. MX_FRAME rx_frame;
  186. tL2CAP_APPL_INFO reg_info; /* L2CAP Registration info */
  187. tRFC_MCB *p_rfc_lcid_mcb[MAX_L2CAP_CHANNELS]; /* MCB based on the L2CAP's lcid */
  188. BOOLEAN peer_rx_disabled; /* If TRUE peer sent FCOFF */
  189. UINT8 last_mux; /* Last mux allocated */
  190. UINT8 last_port; /* Last port allocated */
  191. } tRFCOMM_CB;
  192. /* Main Control Block for the RFCOMM Layer (PORT and RFC) */
  193. typedef struct {
  194. tRFCOMM_CB rfc;
  195. tPORT_CB port;
  196. UINT8 trace_level;
  197. } tRFC_CB;
  198. #if RFC_DYNAMIC_MEMORY == FALSE
  199. extern tRFC_CB rfc_cb;
  200. #else
  201. extern tRFC_CB *rfc_cb_ptr;
  202. #define rfc_cb (*rfc_cb_ptr)
  203. #endif
  204. /* Timer running on the multiplexor channel while no DLCI connection is opened */
  205. #define RFC_MCB_INIT_INACT_TIMER 60 /* in seconds */
  206. /* Timer running on the multiplexor channel after last DLCI is released */
  207. #define RFC_MCB_RELEASE_INACT_TIMER 2 /* in seconds */
  208. /*
  209. ** Define RFCOMM frame processing errors
  210. */
  211. #define RFCOMM_ERR_BAD_SABME 1
  212. #define RFCOMM_ERR_BAD_UA 2
  213. #define RFCOMM_ERR_BAD_DM 3
  214. #define RFCOMM_ERR_BAD_DISC 4
  215. #define RFCOMM_ERR_BAD_UIH 5
  216. #ifdef RFCOMM_PRECALC_FCS
  217. #define RFCOMM_SABME_FCS(p_data, cr, dlci) rfc_sabme_fcs[cr][dlci]
  218. #define RFCOMM_UA_FCS(p_data, cr, dlci) rfc_ua_fcs[cr][dlci]
  219. #define RFCOMM_DM_FCS(p_data, cr, dlci) rfc_dm_fcs[cr][dlci]
  220. #define RFCOMM_DISC_FCS(p_data, cr, dlci) rfc_disc_fcs[cr][dlci]
  221. #define RFCOMM_UIH_FCS(p_data, dlci) rfc_uih_fcs[dlci]
  222. #else
  223. extern UINT8 rfc_calc_fcs (UINT16 len, UINT8 *p);
  224. #define RFCOMM_SABME_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data)
  225. #define RFCOMM_UA_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data)
  226. #define RFCOMM_DM_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data)
  227. #define RFCOMM_DISC_FCS(p_data, cr, dlci) rfc_calc_fcs(3, p_data)
  228. #define RFCOMM_UIH_FCS(p_data, dlci) rfc_calc_fcs(2, p_data)
  229. #endif
  230. #ifdef __cplusplus
  231. extern "C" {
  232. #endif
  233. extern void rfc_mx_sm_execute (tRFC_MCB *p_mcb, UINT16 event, void *p_data);
  234. /*
  235. ** Functions provided by the rfc_port_fsm.c
  236. */
  237. extern void rfc_port_sm_execute (tPORT *p_port, UINT16 event, void *p_data);
  238. extern void rfc_process_pn (tRFC_MCB *p_rfc_mcb, BOOLEAN is_command, MX_FRAME *p_frame);
  239. extern void rfc_process_msc (tRFC_MCB *p_rfc_mcb, BOOLEAN is_command, MX_FRAME *p_frame);
  240. extern void rfc_process_rpn (tRFC_MCB *p_rfc_mcb, BOOLEAN is_command, BOOLEAN is_request, MX_FRAME *p_frame);
  241. extern void rfc_process_rls (tRFC_MCB *p_rfc_mcb, BOOLEAN is_command, MX_FRAME *p_frame);
  242. extern void rfc_process_nsc (tRFC_MCB *p_rfc_mcb, MX_FRAME *p_frame);
  243. extern void rfc_process_test_rsp (tRFC_MCB *p_rfc_mcb, BT_HDR *p_buf);
  244. extern void rfc_process_fcon (tRFC_MCB *p_rfc_mcb, BOOLEAN is_command);
  245. extern void rfc_process_fcoff (tRFC_MCB *p_rfc_mcb, BOOLEAN is_command);
  246. extern void rfc_process_l2cap_congestion (tRFC_MCB *p_mcb, BOOLEAN is_congested);
  247. /*
  248. ** Functions provided by the rfc_utils.c
  249. */
  250. tRFC_MCB *rfc_alloc_multiplexer_channel (BD_ADDR bd_addr, BOOLEAN is_initiator);
  251. extern void rfc_release_multiplexer_channel (tRFC_MCB *p_rfc_mcb);
  252. extern void rfc_timer_start (tRFC_MCB *p_rfc_mcb, UINT16 timeout);
  253. extern void rfc_timer_stop (tRFC_MCB *p_rfc_mcb);
  254. extern void rfc_timer_free (tRFC_MCB *p_rfc_mcb);
  255. extern void rfc_port_timer_start (tPORT *p_port, UINT16 tout);
  256. extern void rfc_port_timer_stop (tPORT *p_port);
  257. extern void rfc_port_timer_free (tPORT *p_port);
  258. BOOLEAN rfc_check_uih_fcs (UINT8 dlci, UINT8 received_fcs);
  259. BOOLEAN rfc_check_fcs (UINT16 len, UINT8 *p, UINT8 received_fcs);
  260. tRFC_MCB *rfc_find_lcid_mcb (UINT16 lcid);
  261. extern void rfc_save_lcid_mcb (tRFC_MCB *p_rfc_mcb, UINT16 lcid);
  262. extern void rfc_check_mcb_active (tRFC_MCB *p_mcb);
  263. extern void rfc_port_closed (tPORT *p_port);
  264. extern void rfc_sec_check_complete (BD_ADDR bd_addr, tBT_TRANSPORT transport, void *p_ref_data, UINT8 res);
  265. extern void rfc_inc_credit (tPORT *p_port, UINT8 credit);
  266. extern void rfc_dec_credit (tPORT *p_port);
  267. extern void rfc_check_send_cmd(tRFC_MCB *p_mcb, BT_HDR *p_buf);
  268. /*
  269. ** Functions provided by the rfc_ts_frames.c
  270. */
  271. extern void rfc_send_sabme (tRFC_MCB *p_rfc_mcb, UINT8 dlci);
  272. extern void rfc_send_ua (tRFC_MCB *p_rfc_mcb, UINT8 dlci);
  273. extern void rfc_send_dm (tRFC_MCB *p_rfc_mcb, UINT8 dlci, BOOLEAN pf);
  274. extern void rfc_send_disc (tRFC_MCB *p_rfc_mcb, UINT8 dlci);
  275. extern void rfc_send_pn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT16 mtu,
  276. UINT8 cl, UINT8 k);
  277. extern void rfc_send_test (tRFC_MCB *p_rfc_mcb, BOOLEAN is_command, BT_HDR *p_buf);
  278. extern void rfc_send_msc (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command,
  279. tPORT_CTRL *p_pars);
  280. extern void rfc_send_rls (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command, UINT8 status);
  281. extern void rfc_send_rpn (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN is_command,
  282. tPORT_STATE *p_pars, UINT16 mask);
  283. extern void rfc_send_fcon (tRFC_MCB *p_mcb, BOOLEAN is_command);
  284. extern void rfc_send_fcoff (tRFC_MCB *p_mcb, BOOLEAN is_command);
  285. extern void rfc_send_buf_uih (tRFC_MCB *p_rfc_mcb, UINT8 dlci, BT_HDR *p_buf);
  286. extern void rfc_send_credit(tRFC_MCB *p_mcb, UINT8 dlci, UINT8 credit);
  287. extern void rfc_process_mx_message (tRFC_MCB *p_rfc_mcb, BT_HDR *p_buf);
  288. extern UINT8 rfc_parse_data (tRFC_MCB *p_rfc_mcb, MX_FRAME *p_frame, BT_HDR *p_buf);
  289. /*
  290. ** Functions provided by the rfc_disp.c
  291. */
  292. /* Call back functions from RFCOMM */
  293. extern void rfcomm_l2cap_if_init (void);
  294. extern void PORT_StartInd (tRFC_MCB *p_mcb);
  295. extern void PORT_StartCnf (tRFC_MCB *p_mcb, UINT16 result);
  296. extern void PORT_CloseInd (tRFC_MCB *p_mcb);
  297. extern void Port_TimeOutCloseMux (tRFC_MCB *p_mcb);
  298. extern void PORT_DlcEstablishInd (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu);
  299. extern void PORT_DlcEstablishCnf (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT16 result);
  300. extern void PORT_DataInd (tRFC_MCB *p_mcb, UINT8 dlci, BT_HDR *p_buf);
  301. extern void PORT_DlcReleaseInd (tRFC_MCB *p_mcb, UINT8 dlci);
  302. extern void PORT_ParNegInd (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT8 cl, UINT8 k);
  303. extern void PORT_ParNegCnf (tRFC_MCB *p_mcb, UINT8 dlci, UINT16 mtu, UINT8 cl, UINT8 k);
  304. extern void PORT_TestCnf (tRFC_MCB *p_mcb, UINT8 *p_data, UINT16 len);
  305. extern void PORT_FlowInd (tRFC_MCB *p_mcb, UINT8 dlci, BOOLEAN fc);
  306. extern void PORT_PortNegInd (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_STATE *p_pars, UINT16 param_mask);
  307. extern void PORT_PortNegCnf (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_STATE *p_pars, UINT16 result);
  308. extern void PORT_ControlInd (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_CTRL *p_pars);
  309. extern void PORT_ControlCnf (tRFC_MCB *p_mcb, UINT8 dlci, tPORT_CTRL *p_pars);
  310. extern void PORT_LineStatusInd (tRFC_MCB *p_mcb, UINT8 dlci, UINT8 line_status);
  311. #ifdef __cplusplus
  312. }
  313. #endif
  314. #endif