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