comparison src/g23m-fad/fad/fad_rcvp.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_RCVP
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 functions for processing
18 | of incomming primitives for the component
19 | Fax Adaptation 3.45 of the mobile station
20 +-----------------------------------------------------------------------------
21 */
22
23 #ifndef FAD_RCVP_C
24 #define FAD_RCVP_C
25 #endif
26
27 #define ENTITY_FAD
28
29 /*==== INCLUDES ===================================================*/
30
31 #include <string.h>
32 #include "typedefs.h"
33 #include "vsi.h"
34 #include "macdef.h"
35 #include "pconst.cdg"
36 #include "custom.h"
37 #include "gsm.h"
38 #include "cnf_fad.h"
39 #include "mon_fad.h"
40 #include "prim.h"
41 #include "pei.h"
42 #include "tok.h"
43 #include "ccdapi.h"
44 #include "fad.h"
45
46 /*==== CONST =======================================================*/
47
48 /*==== TYPES =======================================================*/
49
50 /*==== VAR EXPORT ==================================================*/
51
52 /*==== VAR LOCAL ===================================================*/
53
54 /*==== FUNCTIONS ===================================================*/
55
56 LOCAL void AlignByte(UBYTE *byte)
57 {
58 const USHORT tbl[] =
59 {
60 0x7E00, /* 01111110 00000000 */
61 0x00FC, /* 00000000 11111100 */
62 0x01F8, /* 00000001 11111000 */
63 0x03F0, /* 00000011 11110000 */
64 0x07E0, /* 00000111 11100000 */
65 0x0FC0, /* 00001111 11000000 */
66 0x1F80, /* 00011111 10000000 */
67 0x3F00, /* 00111111 00000000 */
68 };
69 UBYTE i;
70
71 T_RCV *Rcv = &fad_data->rcv;
72
73 if (Rcv->FlagFound EQ 0) /* initialization */
74 Rcv->AlignWord = *byte;
75
76 Rcv->AlignWord <<= 8;
77 Rcv->AlignWord += *byte;
78 if (Rcv->FlagFound < FLAGFOUND_MIN)
79 {
80 for (i = 0; i < 8; i++)
81 {
82 if (tbl[i] EQ (Rcv->AlignWord & tbl[i]) AND ((UBYTE)(Rcv->AlignWord >> i) EQ HDLC_FLAG))
83 {
84 if (Rcv->AlignShift NEQ i)
85 {
86 Rcv->AlignShift = i;
87 Rcv->FlagFound = 0;
88 }
89 Rcv->FlagFound++;
90 break;
91 }
92 }
93 }
94 if (Rcv->FlagFound EQ FLAGFOUND_MIN)
95 *byte = (UBYTE)(Rcv->AlignWord >> Rcv->AlignShift);
96 }
97
98 LOCAL void align_ra_data_ind(T_FD *pFD)
99 {
100 USHORT i;
101
102 for (i = 0; i < pFD->len >> 1; i++)
103 {
104 AlignByte(&pFD->buf[2*i+1]);
105 }
106 }
107
108 #ifdef _TARGET_
109 void switch_ra_detect_req(UBYTE detect)
110 {
111 T_RA_DETECT_REQ ra_detect_req;
112 ra_detect_req.detect = detect;
113 l1i_ra_detect_req (&ra_detect_req);
114 }
115 #endif
116
117 /*
118 +--------------------------------------------------------------------+
119 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVP |
120 | STATE : code ROUTINE : rcv_ra_data_ind |
121 +--------------------------------------------------------------------+
122
123 PURPOSE : Process primitive RA_DATA_IND received from RA.
124
125 */
126
127 GLOBAL void rcv_ra_data_ind (T_RA_DATA_IND *ra_data_ind)
128 {
129 T_RCV *rcv = &fad_data->rcv;
130 UBYTE frame_type;
131 T_FD *pFD;
132
133 TRACE_FUNCTION ("rcv_ra_data_ind()");
134
135 if (GET_STATE(KER) EQ KER_NULL)
136 return;
137
138 #ifdef _SIMULATION_
139 PACCESS(ra_data_ind);
140
141 if (GET_STATE(KER) NEQ KER_NULL)
142 {
143 pFD = cl_ribu_get_new_frame_desc(fad_data->rbm.ribu);
144 pFD->type = ra_data_ind->fr_type;
145 pFD->len = ra_data_ind->sdu.l_buf >> 3;
146 memcpy(pFD->buf, ra_data_ind->sdu.buf, pFD->len);
147 }
148
149 PFREE (ra_data_ind);
150 #endif
151
152 if (fad_data->rbm.ribu->idx.filled > 1)
153 TRACE_EVENT_P3("rbm: filled=%d; wi=%d; ri=%d", fad_data->rbm.ribu->idx.filled, fad_data->rbm.ribu->idx.wi, fad_data->rbm.ribu->idx.ri);
154
155 pFD = cl_ribu_get(fad_data->rbm.ribu);
156
157 if (pFD->type EQ FR_STATUS)
158 {
159
160 #if defined TRACE_FAD_DL_STATUS || defined _SIMULATION_
161 {
162 char buf[14] = "RS:0x ->0x ";
163 BYTE2HEXSTR(*(pFD->buf+1), &buf[5]);
164 align_ra_data_ind(pFD);
165 BYTE2HEXSTR(*(pFD->buf+1), &buf[11]);
166 TRACE_EVENT(buf);
167 }
168 #else
169 align_ra_data_ind(pFD);
170 #endif
171
172 }
173
174 frame_type = rcv_FrameType(pFD);
175
176 switch (GET_STATE (RCV))
177 {
178 case SYNC_RCV:
179 switch (frame_type)
180 {
181 case FT_PREAMBLE:
182 rcv->bytes_expect = PREAMBLE_BYTES_TI_EXP;
183 rcv->bytes_expect -= pFD->len;
184 SET_STATE (RCV, PREAM_RCV);
185 if (!rcv->data_in_rbm)
186 {
187 sig_rcv_ker_preamble_ind();
188 #ifdef _SIMULATION_
189 TRACE_EVENT ("BCS-TRA:first PREAMBLE FLAG rcvd");
190 #endif
191 }
192 else
193 {
194 rcv->preamble_pending = TRUE;
195 #ifdef _SIMULATION_
196 TRACE_EVENT ("BCS-TRA:first PREAM FLAG rcvd (p)");
197 #endif
198 }
199 break;
200
201 case FR_TRAIN:
202 SET_STATE (RCV, TRAIN_RCV);
203 /*
204 * set READY flag to send first DATA to T30
205 */
206 rcv->t30_req_frames = TRUE;
207 sig_rcv_ker_train_ind();
208 break;
209
210 case FT_TRAIN_RESPONSE:
211 sig_rcv_ker_status_ind();
212 break;
213
214 default:
215 break;
216 }
217 break; /* case SYNC_RCV: */
218
219 case PREAM_RCV:
220 if (frame_type EQ FR_STATUS)
221 {
222 if (rcv->bytes_expect <= pFD->len)
223 {
224 rcv->bytes_expect = 0;
225 SET_STATE (RCVSUB, SUB_PREAMBLE);
226 #ifdef _SIMULATION_
227 TRACE_EVENT ("BCS-TRA:PREAM time elapsed");
228 #endif
229 SET_STATE (RCV, BCS_RCV);
230 }
231 else
232 rcv->bytes_expect -= pFD->len;
233 }
234 break; /* case PREAM_RCV: */
235
236 case BCS_RCV:
237 switch (GET_STATE (RCVSUB))
238 {
239 case SUB_IDLE:
240 if (frame_type EQ FR_SYNC)
241 {
242 if (!rcv->data_in_rbm)
243 {
244 sig_rcv_ker_bcs_ind(rcv->hdlc, rcv->hdlc_len);
245 #ifdef _SIMULATION_
246 TRACE_EVENT ("BCS-TRA:SYNC rec - HDLC compl");
247 #endif
248 }
249 else
250 {
251 rcv->bcs_pending = TRUE;
252 #ifdef _SIMULATION_
253 TRACE_EVENT ("BCS-TRA:SYNC rec - HDLC compl (p)");
254 #endif
255 }
256 rcv_ResetFormatter();
257 SET_STATE (RCV, SYNC_RCV);
258 }
259 break;
260
261 case SUB_DATA:
262 switch (frame_type)
263 {
264 case FR_SYNC:
265 sig_rcv_ker_bcs_ind (rcv->hdlc, rcv->hdlc_len);
266 #ifdef _SIMULATION_
267 TRACE_EVENT ("BCS-TRA:SYNC rec - HDLC compl");
268 #endif
269 rcv_ResetFormatter ();
270 SET_STATE (RCV, SYNC_RCV);
271 break;
272
273 case FR_STATUS:
274 if (rcv->hdlc_len + pFD->len > HDLC_LEN)
275 {
276 SET_STATE (RCVSUB, SUB_IDLE);
277 TRACE_EVENT ("BCS-TRA:HDLC frame too long !!!");
278 break;
279 }
280 rcv_SetHdlcFrame(pFD, &rcv->hdlc[rcv->hdlc_len], &rcv->hdlc_len);
281 break;
282
283 default: /* discard non-HDLC data */
284 break;
285 }
286 break;
287
288 default:
289 break;
290 }
291 break; /* case BCS_RCV: */
292
293 case TCF_RCV:
294 switch (GET_STATE (RCVSUB))
295 {
296 case SUB_IDLE:
297 if (frame_type NEQ FR_SYNC)
298 {
299 rcv->bytes_expect = snd_DurationToBytes (fad_data->snd.trans_rate, TIME_TCF_RCV);
300 rcv->bytes_expect -= pFD->len;
301 rcv->bytes_rcvd = 0;
302 rcv->bytes_good = 0;
303 SET_STATE (RCVSUB, SUB_TCF);
304 TRACE_EVENT("SET_STATE (RCVSUB, SUB_TCF)");
305 }
306 break;
307
308 case SUB_TCF:
309 if (frame_type EQ FR_SYNC)
310 {
311
312 #ifdef BMI_TCF_WORKAROUND
313 if (rcv->bytes_rcvd < rcv->bytes_expect) /* ignore TCF frames which are destroyed by BMI */
314 break;
315 #endif
316
317 sig_rcv_ker_tcf_ind();
318 rcv_ResetFormatter();
319 TRACE_EVENT ("MSG-TRA: rec TCF compl (too short)");
320 SET_STATE (RCV, SYNC_RCV);
321 }
322 else if (frame_type EQ FR_STATUS)
323 {
324 rcv_ResetFormatter();
325 TRACE_EVENT ("MSG-TRA: rec FR_STATUS during SUB_TCF");
326 SET_STATE (KER, IDLE);
327 SET_STATE (RCV, SYNC_RCV);
328 }
329 else /* frame_type NEQ FR_SYNC */
330 {
331 rcv->bytes_rcvd += pFD->len;
332 if (rcv->bytes_expect <= pFD->len)
333 {
334 rcv->bytes_expect = 0;
335 SET_STATE (RCVSUB, SUB_POST_TCF);
336 }
337 else
338 rcv->bytes_expect -= pFD->len;
339
340 rcv_SetErrorRatio(pFD);
341 }
342 break;
343
344 case SUB_POST_TCF:
345 if (frame_type EQ FR_SYNC)
346 {
347 sig_rcv_ker_tcf_ind();
348 rcv_ResetFormatter();
349 TRACE_EVENT ("MSG-TRA:rec TCF compl");
350 SET_STATE (RCV, SYNC_RCV);
351 }
352 else
353 {
354 while (fad_data->rbm.ribu->idx.filled)
355 {
356 cl_ribu_read_index(&fad_data->rbm.ribu->idx);
357 #ifdef _SIMULATION_
358 TRACE_EVENT_P3("ribu: f=%2d - w=%2d - r=%2d - SUB_POST_TCF",
359 fad_data->rbm.ribu->idx.filled,
360 fad_data->rbm.ribu->idx.wi,
361 fad_data->rbm.ribu->idx.ri);
362 #endif
363 }
364 }
365 break;
366
367 default:
368 rcv_ResetFormatter ();
369 SET_STATE (RCV, SYNC_RCV);
370 sig_rcv_ker_error_ind (ERR_FAD_SUB_TCF);
371 break;
372 }
373 break; /* case TCF_RCV: */
374
375 case TRAIN_RCV:
376 switch (frame_type)
377 {
378 case FR_T4DATA:
379 {
380 #ifdef _TARGET_
381 switch_ra_detect_req(DET_NO_STATUS);
382 #else
383 /*
384 * handling of first frame restored
385 */
386 rcv->train_flg = FALSE;
387 rcv->data_incoming = TRUE;
388 if (!rcv_StoreMsgData (pFD, &rcv->prim_ready))
389 {
390 rcv->t30_req_frames = FALSE;
391 rcv_ResetFormatter ();
392 SET_STATE (RCV, SYNC_RCV);
393 sig_rcv_ker_error_ind (ERR_OVERFLOW_BCS_RCV);
394 break;
395 }
396 rcv->data_in_rbm = TRUE;
397 /* check if T30 READY flag set */
398 if (rcv->t30_req_frames)
399 sig_ker_rcv_ready_req ();
400 #endif
401
402 TRACE_EVENT ("MSG-TRA:TRAIN compl");
403 rcv->data_incoming = TRUE;
404 rcv->bytes_expect = REPEAT_FOREVER;
405 rcv->train_flg = TRUE; /*???*/
406 SET_STATE (RCV, MSG_RCV);
407 sig_rcv_ker_train_end_ind (); /* first MSG data received: resume sending SYNCS */
408 break;
409 }
410 default:
411 break;
412 }
413 break; /* case TRAIN_RCV: */
414
415 case MSG_RCV:
416 switch (frame_type)
417 {
418 case FR_SYNC:
419 if (rcv->train_flg EQ FALSE) /*???*/
420 {
421 #ifdef _TARGET_
422 switch_ra_detect_req(DET_STATUS);
423 #endif
424 TRACE_EVENT ("MSG-TRA:DATA compl");
425 rcv->data_incoming = FALSE;
426 if (!fad_data->ker.forward_data)
427 {
428 rcv->t30_req_frames = FALSE;
429 sig_rcv_ker_msg_ind (NULL);
430 }
431 if (rcv->t30_req_frames)
432 rcv_SetFinalBuffer ();
433
434 SET_STATE (RCV, SYNC_RCV);
435 rcv_ResetFormatter ();
436 }
437 break;
438
439 case FR_T4DATA:
440 rcv->train_flg = FALSE;
441 if (!rcv_StoreMsgData (pFD, &rcv->prim_ready))
442 {
443 rcv->t30_req_frames = FALSE;
444 rcv_ResetFormatter ();
445 SET_STATE (RCV, SYNC_RCV);
446 sig_rcv_ker_error_ind (ERR_OVERFLOW_BCS_RCV);
447 break;
448 }
449 rcv->data_in_rbm = TRUE;
450 if (rcv->t30_req_frames) /* check if T30 READY flag set */
451 sig_ker_rcv_ready_req ();
452 break;
453
454 default:
455 break;
456 }
457 break; /* case MSG_RCV: */
458
459 default:
460 break;
461 }
462 }
463
464 #ifdef _TARGET_
465 /*
466 +----------------------------------------------------------------------+
467 | PROJECT : GSM-F&D (8411) MODULE : FAD_RCVP |
468 | STATE : code ROUTINE : fad_rcv_GetDestDescriptor |
469 +----------------------------------------------------------------------+
470
471 PURPOSE : WRAPPER: Get frame descriptor for Layer 1 (TI)
472
473 */
474 GLOBAL T_FD *fad_rbm_get_next_FrameDesc(void)
475 {
476 return (cl_ribu_get_new_frame_desc(fad_data->rbm.ribu));
477 }
478 #endif
479