comparison src/g23m-fad/fad/fad_rcvf.c @ 174:90eb61ecd093

src/g23m-fad: initial import from TCS3.2/LoCosto
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2016 05:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
173:bf64d785238a 174:90eb61ecd093
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : FAD_RCVF
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : This Modul defines the procedures and functions for
18 | the component Fax Adaptation 3.45 of the mobile station
19 +-----------------------------------------------------------------------------
20 */
21
22 #ifndef FAD_RCVF_C
23 #define FAD_RCVF_C
24 #endif
25
26 #define ENTITY_FAD
27
28 /*==== INCLUDES ===================================================*/
29
30 #include <string.h>
31 #include "typedefs.h"
32 #include "vsi.h"
33 #include "macdef.h"
34 #include "pconst.cdg"
35 #include "custom.h"
36 #include "gsm.h"
37 #include "cnf_fad.h"
38 #include "mon_fad.h"
39 #include "prim.h"
40 #include "pei.h"
41 #include "tok.h"
42 #include "ccdapi.h"
43 #include "fad.h"
44
45 /*==== CONST =======================================================*/
46
47 /*==== TYPES =======================================================*/
48
49 /*==== VAR EXPORT ==================================================*/
50
51 /*==== VAR LOCAL ===================================================*/
52
53 /*==== FUNCTIONS ===================================================*/
54
55 /*
56 +--------------------------------------------------------------------+
57 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
58 | STATE : code ROUTINE : rcv_init |
59 +--------------------------------------------------------------------+
60
61 PURPOSE : initialise the fad data for the rcv formatter process
62
63 */
64
65 GLOBAL void rcv_init (void)
66 {
67 T_RCV *rcv = &fad_data->rcv;
68
69 TRACE_FUNCTION ("rcv_init()");
70
71 INIT_STATE (RCV, SYNC_RCV);
72 INIT_STATE (RCVSUB, SUB_IDLE);
73
74 rcv->data_in_rbm = FALSE;
75 rcv->preamble_pending = FALSE;
76 rcv->bcs_pending = TRUE;
77 rcv->FlagFound = 0;
78 rcv->train_flg = FALSE; /*???*/
79
80 rcv_ResetFormatter ();
81 }
82
83 /*
84 +--------------------------------------------------------------------+
85 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
86 | STATE : code ROUTINE : rcv_ResetFormatter |
87 +--------------------------------------------------------------------+
88
89 PURPOSE :
90
91 */
92
93 GLOBAL void rcv_ResetFormatter (void)
94 {
95 T_RCV *rcv = &fad_data->rcv;
96
97 TRACE_FUNCTION ("rcv_ResetFormatter()");
98
99 SET_STATE (RCVSUB, SUB_IDLE);
100
101 rcv->bytes_good = 0;
102 rcv->bytes_expect = 0;
103 rcv->bytes_rcvd = 0;
104 rcv->prim_ready = FALSE;
105 rcv->hdlc_len = 0;
106 rcv->bcs_data_len = 0;
107 rcv->data_bufpos = 0;
108 }
109
110 /*
111 +--------------------------------------------------------------------+
112 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
113 | STATE : code ROUTINE : CheckBcsFrame |
114 +--------------------------------------------------------------------+
115
116 PURPOSE : get number of correct IDENT and data bytes (BCS data)
117
118 */
119
120 LOCAL void CheckBcsFrame (UBYTE *ident_ratio, UBYTE *info_ratio,
121 UBYTE *bcs_data, UBYTE ident,
122 UBYTE info, USHORT bcs_len)
123 {
124 UBYTE i, pream_good = 0, ident_good = 0;
125
126 TRACE_FUNCTION ("CheckBcsFrame()");
127
128 if (!bcs_len)
129 return;
130
131 for (i = 0; i < bcs_len; bcs_data++, i++)
132 {
133 if (i & 0x01)
134 {
135 if (*bcs_data EQ info)
136 pream_good++;
137 }
138 else
139 {
140 if (*bcs_data EQ ident)
141 ident_good++;
142 }
143 }
144 bcs_len >>= 1;
145
146 if (bcs_len)
147 {
148 *ident_ratio = (ident_good * 100) / bcs_len;
149 *info_ratio = (pream_good * 100) / bcs_len;
150 }
151 }
152
153 /*
154 +--------------------------------------------------------------------+
155 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
156 | STATE : code ROUTINE : rcv_FrameType |
157 +--------------------------------------------------------------------+
158
159 PURPOSE :
160
161 */
162
163 GLOBAL UBYTE rcv_FrameType(T_FD *pFD)
164 {
165 UBYTE *bcs_data, fr_type, len, ident_ratio, info_ratio;
166
167 #ifdef _SIMULATION_
168 TRACE_FUNCTION ("rcv_FrameType()");
169 #endif
170
171 fr_type = pFD->type;
172 len = pFD->len;
173 bcs_data = pFD->buf;
174
175 switch (GET_STATE (RCV))
176 {
177 case SYNC_RCV:
178 switch (fr_type)
179 {
180 case FR_STATUS:
181 CheckBcsFrame(&ident_ratio, &info_ratio, bcs_data, IDENT_BCS_REC, HDLC_FLAG, len);
182 if (ident_ratio < BCS_TOLERANCE)
183 return (FT_NONE); /* not a BCS frame */
184 if (info_ratio >= BCS_TOLERANCE)
185 return (FT_PREAMBLE);
186 break;
187
188 case FR_TRAIN:
189 CheckBcsFrame(&ident_ratio, &info_ratio, bcs_data, IDENT_MSG_REC, VAL_TRAIN, len);
190 if (ident_ratio >= TRAIN_TOLERANCE)
191 break; /* STATUS-TRAIN frame */
192
193 CheckBcsFrame(&ident_ratio, &info_ratio, bcs_data, IDENT_MSG_TRA, VAL_TRAIN, len);
194 if (ident_ratio >= TRAIN_TOLERANCE)
195 return (FT_TRAIN_RESPONSE); /* response to TRAINING */
196
197 return (FT_NONE);
198 }
199 break;
200
201 case PREAM_RCV:
202 switch (fr_type)
203 {
204 case FR_STATUS:
205 CheckBcsFrame(&ident_ratio, &info_ratio, bcs_data, IDENT_BCS_REC, VAL_TCF, len);
206 if (ident_ratio < BCS_TOLERANCE)
207 return (FT_NONE); /* not a BCS frame */
208 if (info_ratio >= BCS_TOLERANCE)
209 return (FT_PREAMBLE);
210 break;
211
212 default:
213 return (FT_NONE);
214 }
215 break;
216
217 case BCS_RCV:
218 if (fr_type EQ FR_STATUS)
219 {
220 CheckBcsFrame(&ident_ratio, &info_ratio, bcs_data, IDENT_BCS_REC, HDLC_FLAG, len);
221 if (ident_ratio < BCS_TOLERANCE)
222 return (FT_NONE); /* not a BCS frame */
223
224 if (GET_STATE (RCVSUB) EQ SUB_PREAMBLE)
225 {
226 if (info_ratio EQ 100)
227 return (FT_NONE); /* still receiving PREAMBLE */
228
229 SET_STATE (RCVSUB, SUB_DATA);
230 }
231 }
232 break;
233
234 default:
235 break;
236 }
237 return (fr_type);
238 }
239
240 /*
241 +--------------------------------------------------------------------+
242 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
243 | STATE : code ROUTINE : rcv_SetHdlcFrame |
244 +--------------------------------------------------------------------+
245
246 PURPOSE : set BCS data as HDLC frame for T30/ACI
247
248 */
249
250 GLOBAL void rcv_SetHdlcFrame (T_FD *pFD, UBYTE *hdlc_data, USHORT *hdlc_len)
251 {
252 UBYTE *bcs_data = pFD->buf;
253 USHORT flag_found = 0, i, k;
254
255 #define HDLC_MAX 2
256
257 #ifdef _SIMULATION_
258 TRACE_FUNCTION ("rcv_SetHdlcFrame()");
259 #endif
260
261 for (i = 0; i < pFD->len; i++, bcs_data++)
262 {
263 if (i & 0x0001)
264 {
265 *hdlc_data++ = *bcs_data;
266 (*hdlc_len)++;
267
268 /*
269 * if preamble is disturbed
270 * discard erroneous HDLC data
271 */
272 if (*hdlc_len > HDLC_MAX)
273 {
274 /*
275 * check last HDLC data; allow trailing HDLC flags
276 */
277 for (k = *hdlc_len - HDLC_MAX; k < *hdlc_len; k++)
278 {
279 if (fad_data->rcv.hdlc[k] EQ HDLC_FLAG)
280 {
281 flag_found++;
282 TRACE_EVENT("HDLC flags during SUB_DATA found");
283 }
284 if (flag_found EQ HDLC_MAX)
285 {
286 TRACE_EVENT("HDLC buffer cleared again");
287 hdlc_data = fad_data->rcv.hdlc;
288 *hdlc_len = 0;
289 }
290 }
291 }
292 }
293 }
294 }
295
296 /*
297 +--------------------------------------------------------------------+
298 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
299 | STATE : code ROUTINE : rcv_SetErrorRatio |
300 +--------------------------------------------------------------------+
301
302 PURPOSE : calculate no. of correctly received TCF bytes
303
304 */
305
306 GLOBAL void rcv_SetErrorRatio(T_FD *pFD)
307 {
308 void t30_ker_debug(CHAR *header, UBYTE *buf, USHORT len);
309
310 UBYTE *buf = pFD->buf, i;
311
312 TRACE_FUNCTION ("rcv_SetErrorRatio()");
313
314 #if defined TRACE_FAD_DL_TCF || defined _SIMULATION_
315 t30_ker_debug("TCF", buf, pFD->len);
316 #endif
317
318 for (i = 0; i < pFD->len; i++, buf++)
319 {
320 if (*buf EQ VAL_TCF)
321 {
322 fad_data->rcv.bytes_good++;
323 }
324 }
325 }
326
327
328 /*
329 +--------------------------------------------------------------------+
330 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
331 | STATE : code ROUTINE : rcv_StoreMsgData |
332 +--------------------------------------------------------------------+
333
334 PURPOSE : pass SDU to Receive Buffer Manager (RBM)
335
336 */
337
338 GLOBAL BOOL rcv_StoreMsgData (T_FD *pFD, BOOL *primAvail)
339 {
340 TRACE_FUNCTION ("rcv_StoreMsgData()");
341
342 return rbm_store_frames(pFD, primAvail);
343 }
344
345 /*
346 +--------------------------------------------------------------------+
347 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
348 | STATE : code ROUTINE : rcv_SetFinalBuffer |
349 +--------------------------------------------------------------------+
350
351 PURPOSE : set RBM for final MSG data
352
353 */
354
355 GLOBAL void rcv_SetFinalBuffer (void)
356 {
357 T_FAD_DATA_IND *fad_data_ind;
358
359 TRACE_FUNCTION ("rcv_SetFinalBuffer()");
360
361 rcv_GetMsgData (&fad_data_ind, FALSE);
362 sig_rcv_ker_msg_ind (fad_data_ind);
363 fad_data->rcv.t30_req_frames = FALSE;
364 }
365
366 /*
367 +--------------------------------------------------------------------+
368 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVF |
369 | STATE : code ROUTINE : rcv_GetMsgData |
370 +--------------------------------------------------------------------+
371
372 PURPOSE :
373
374 */
375
376 GLOBAL BOOL rcv_GetMsgData (T_FAD_DATA_IND **fad_data_ind, BOOL data_incoming)
377 {
378 TRACE_FUNCTION ("rcv_GetMsgData()");
379
380 *fad_data_ind = rbm_get_prim ();
381
382 if (data_incoming)
383 {
384 /* MSG data still being received */
385 if (*fad_data_ind EQ NULL)
386 return FALSE;
387
388 (*fad_data_ind)->final = FALSE;
389 }
390 else
391 {
392 /* MSG data no longer being received - SYNC detected */
393
394 if (*fad_data_ind NEQ NULL)
395 (*fad_data_ind)->final = FALSE;
396 else
397 {
398 *fad_data_ind = rbm_get_curr_prim ();
399
400 /* buffer empty - end of MSG phase */
401 fad_data->rcv.data_in_rbm = FALSE;
402
403 if (*fad_data_ind EQ NULL)
404 return FALSE;
405
406 (*fad_data_ind)->final = TRUE;
407 }
408 }
409 return (TRUE);
410 }
411