comparison src/g23m-fad/ppp/ppp_frxf.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul :
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 is part of the entity PPP and implements all
18 | procedures and functions as described in the
19 | SDL-documentation (FRX-statemachine)
20 +-----------------------------------------------------------------------------
21 */
22
23 #define ENTITY_PPP
24
25 /*==== INCLUDES =============================================================*/
26
27 #include "typedefs.h" /* to get Condat data types */
28 #include "vsi.h" /* to get a lot of macros */
29 #include "macdef.h" /* to get a lot of macros */
30 #include "custom.h" /* to get a lot of macros */
31 /*lint -efile(766,gsm.h) */
32 #include "gsm.h" /* to get a lot of macros */
33 /*lint -efile(766,cnf_ppp.h) */
34 #include "cnf_ppp.h" /* to get cnf-definitions */
35 /*lint -efile(766,mon_ppp.h) */
36 #include "mon_ppp.h" /* to get mon-definitions */
37 #include "prim.h" /* to get the definitions of used SAP and directions */
38 #include "dti.h" /* to get the DTILIB definitions */
39 #include "ppp.h" /* to get the global entity definitions */
40 #include "ppp_ptxs.h" /* to get signal interface from ptx */
41
42 #include "ppp_arbf.h" /* to get arb functions */
43
44 #include <string.h> /* to get memcpy */
45
46 #ifdef PPP_HDLC_TRACE
47 #include <stdio.h> /* to get sprintf */
48 #endif /* PPP_HDLC_TRACE */
49 /*==== CONST ================================================================*/
50
51 /*==== LOCAL VARS ===========================================================*/
52
53 /*==== PRIVATE FUNCTIONS ====================================================*/
54
55 /*==== PUBLIC FUNCTIONS =====================================================*/
56
57
58
59 #ifndef PPP_INT_RAM
60 /*
61 +------------------------------------------------------------------------------
62 | Function : frx_init
63 +------------------------------------------------------------------------------
64 | Description : The function frx_init() initializes Frame Receive (FRX)
65 |
66 | Parameters : no parameters
67 |
68 +------------------------------------------------------------------------------
69 */
70 GLOBAL void frx_init ()
71 {
72 TRACE_FUNCTION( "frx_init" );
73
74 ppp_data->frx.frame_complete = FALSE;
75 ppp_data->frx.stored_packet = NULL;
76 ppp_data->frx.received_data = NULL;
77 ppp_data->frx.store_state = FRX_ADD_ERROR;
78 ppp_data->frx.data_flow_state = FRX_DATA_FLOW_DEAD;
79
80 #ifdef PPP_HDLC_TRACE
81 ppp_data->frx.hdlc_frame = NULL;
82 #endif /* PPP_HDLC_TRACE */
83
84 INIT_STATE( PPP_SERVICE_FRX , FRX_DEAD );
85 } /* frx_init() */
86 #endif /* PPP_INT_RAM */
87
88
89 #ifndef PPP_FLASH_ROM
90 /*
91 +------------------------------------------------------------------------------
92 | Function : frx_add_desc
93 +------------------------------------------------------------------------------
94 | Description : The function frx_add_desc() appends the given
95 | generic data descriptor to the already received descriptors.
96 | The function removes transparent characters and calculates
97 | the fcs.
98 |
99 | Parameters : no parameters
100 |
101 +------------------------------------------------------------------------------
102 */
103 GLOBAL void frx_add_desc ()
104 {
105 UBYTE store_state;
106 UBYTE currentbyte;
107 USHORT fcs;
108 UBYTE escape;
109 USHORT s_offset;
110 USHORT s_size;
111 UBYTE* destination;
112 USHORT d_offset;
113 USHORT d_size;
114 USHORT* fcstab;
115 T_desc2* source_desc;
116 T_desc2* temp_desc;
117 USHORT packet_len;
118 #ifdef PPP_HDLC_TRACE
119 T_desc2* trace_desc;
120 T_desc2* trace_desc2;
121 T_desc2* trace_desc3;
122 USHORT trace_pos;
123 char buf[100];
124 USHORT i;
125 #endif /* PPP_HDLC_TRACE */
126
127 TRACE_FUNCTION( "frx_add_desc" );
128
129 #ifdef PPP_HDLC_TRACE
130 /*
131 * trace HDLC frame
132 * the goal is to trace out only erroneous PPP frames
133 * if a correct PPP frame is received
134 * we just release the stored copy of this frame without tracing
135 */
136 /*
137 * set source pointer
138 */
139 trace_desc = ppp_data->frx.received_data;
140 trace_pos = ppp_data->frx.proceed_data;
141 switch(ppp_data->frx.store_state)
142 {
143 case FRX_ADD_ERROR:
144 /*
145 * we trace out each byte til the first HDLC flag
146 */
147 /*
148 * release old stored HDLC frame
149 * this should not be necessary
150 */
151 MFREE_DESC2(ppp_data->frx.hdlc_frame);
152 ppp_data->frx.hdlc_frame = NULL;
153 /*
154 * trace incomming data until the first HDLC flag
155 */
156 while((trace_desc) && (trace_pos >= trace_desc->len))
157 {
158 trace_desc = (T_desc2*)trace_desc->next;
159 trace_pos = 0;
160 }
161 if((trace_desc) &&
162 (trace_desc->buffer[trace_pos] NEQ PPP_HDLC_FLAG))
163 {
164 TRACE_EVENT("waiting for next HDLC flag:");
165 i = 0;
166 do
167 {
168 i+= sprintf(&buf[i], "0x%02x, ", trace_desc->buffer[trace_pos]);
169 trace_pos++;
170 while((trace_desc) && (trace_pos >= trace_desc->len))
171 {
172 trace_desc = (T_desc2*)trace_desc->next;
173 trace_pos = 0;
174 }
175 if(i > 80)
176 {
177 TRACE_EVENT( buf );
178 i = 0;
179 }
180 }
181 while((trace_desc) &&
182 (trace_desc->buffer[trace_pos] NEQ PPP_HDLC_FLAG));
183 if(i > 0)
184 {
185 TRACE_EVENT( buf );
186 i = 0;
187 }
188 }
189 break;
190
191 case FRX_ADD_HDLC_BEGIN:
192 /*
193 * we store just the first HDLC flag and fall through
194 * to the default case to store the complete PPP frame
195 */
196 /*
197 * release old stored HDLC frame
198 */
199 MFREE_DESC2(ppp_data->frx.hdlc_frame);
200 ppp_data->frx.hdlc_frame = NULL;
201
202 if(trace_desc)
203 {
204 /*
205 * allocate first descriptor to store new HDLC frame
206 */
207 MALLOC(trace_desc2,
208 (USHORT)(sizeof(T_desc2) - 1 + FRX_ADD_SMALL_PACKET_SIZE));
209 trace_desc2->len = 0;
210 trace_desc2->next = (ULONG)NULL;
211 ppp_data->frx.hdlc_frame = trace_desc2;
212
213 /*
214 * store first HDLC flag
215 */
216 TRACE_EVENT_P2("start flag found in desc=0x%08x: pos=%d",
217 trace_desc,
218 trace_pos);
219 trace_desc2->buffer[trace_desc2->len] = trace_desc->buffer[trace_pos];
220 trace_desc2->len++;
221 trace_pos++;
222 while((trace_desc) && (trace_pos >= trace_desc->len))
223 {
224 trace_desc = (T_desc2*)trace_desc->next;
225 trace_pos = 0;
226 }
227 }
228 /* fall through */
229 default:
230 /*
231 * to store the complete PPP frame
232 */
233 /*
234 * set destination pointer
235 */
236 trace_desc2 = ppp_data->frx.hdlc_frame;
237 while(trace_desc2->next NEQ (ULONG)NULL)
238 {
239 trace_desc2 = (T_desc2*)trace_desc2->next;
240 }
241
242 /*
243 * set source pointer
244 */
245 while((trace_desc) && (trace_pos >= trace_desc->len))
246 {
247 trace_desc = (T_desc2*)trace_desc->next;
248 trace_pos = 0;
249 }
250
251 if(trace_desc)
252 {
253 /*
254 * store HDLC frame
255 */
256 while((trace_desc) &&
257 (trace_desc->buffer[trace_pos] NEQ PPP_HDLC_FLAG))
258 {
259 if(trace_desc2->len >= FRX_ADD_SMALL_PACKET_SIZE)
260 {
261 MALLOC(trace_desc3, (USHORT)(sizeof(T_desc2) - 1 +
262 FRX_ADD_SMALL_PACKET_SIZE));
263 trace_desc3->len = 0;
264 trace_desc3->next = (ULONG)NULL;
265 trace_desc2->next = (ULONG)trace_desc3;
266 trace_desc2 = trace_desc3;
267 }
268 trace_desc2->buffer[trace_desc2->len] =
269 trace_desc->buffer[trace_pos];
270 trace_desc2->len++;
271 trace_pos++;
272 while((trace_desc) && (trace_pos >= trace_desc->len))
273 {
274 trace_desc = (T_desc2*)trace_desc->next;
275 trace_pos = 0;
276 }
277 }
278 /*
279 * store last HDLC flag
280 */
281 if(trace_desc)
282 {
283 if(trace_desc2->len >= FRX_ADD_SMALL_PACKET_SIZE)
284 {
285 MALLOC(trace_desc3, (USHORT)(sizeof(T_desc2) - 1 +
286 FRX_ADD_SMALL_PACKET_SIZE));
287 trace_desc3->len = 0;
288 trace_desc3->next = (ULONG)NULL;
289 trace_desc2->next = (ULONG)trace_desc3;
290 trace_desc2 = trace_desc3;
291 }
292 TRACE_EVENT_P2("stop flag found in desc=0x%08x pos=%d",
293 trace_desc,
294 trace_pos);
295 trace_desc2->buffer[trace_desc2->len] =
296 trace_desc->buffer[trace_pos];
297 trace_desc2->len++;
298 trace_pos++;
299 }
300 }
301 break;
302 }
303 #endif /* PPP_HDLC_TRACE */
304 /*
305 * copy all important values into local variables
306 */
307 store_state = ppp_data->frx.store_state;
308 fcs = ppp_data->frx.calc_fcs;
309 escape = ppp_data->frx.escape;
310 source_desc = ppp_data->frx.received_data;
311 s_offset = ppp_data->frx.proceed_data;
312 fcstab = ppp_data->fcstab;
313 /*
314 * set destination pointer
315 */
316 destination = NULL;
317 d_offset = 0;
318 d_size = 0;
319 switch(store_state)
320 {
321 case FRX_ADD_INFORMATION:
322 case FRX_ADD_FCS1:
323 case FRX_ADD_FCS2:
324 destination = ppp_data->frx.cur_desc->buffer;
325 d_offset = ppp_data->frx.cur_desc->len;
326 d_size = ppp_data->frx.cur_desc_size;
327 break;
328 } /*lint !e744 switch statement has no default */
329 /*
330 * while there is still data to analyze and
331 * a complete packet is not yet received
332 */
333 while((source_desc) && (ppp_data->frx.frame_complete EQ FALSE))
334 {
335 /*
336 * while the current descriptor is not yet complete analyzed.
337 * if a complete packet is analyzed we leave the loop via break command
338 */
339 for(s_size = source_desc->len; s_offset < s_size; s_offset++)
340 {
341 /*
342 * set current byte
343 */
344 currentbyte = source_desc->buffer[s_offset];
345 /*
346 * detect HDLC flag
347 */
348 if(currentbyte EQ PPP_HDLC_FLAG)
349 {
350 if(store_state EQ FRX_ADD_ERROR)
351 {
352 #ifdef PPP_HDLC_TRACE
353 /*
354 * store next HDLC frame
355 */
356 /*
357 * release old stored HDLC frame
358 */
359 MFREE_DESC2(ppp_data->frx.hdlc_frame);
360 ppp_data->frx.hdlc_frame = NULL;
361 /*
362 * set source pointer
363 */
364 trace_desc = source_desc;
365 trace_pos = s_offset;
366 /*
367 * allocate first descriptor to store new HDLC frame
368 */
369 MALLOC(trace_desc2, (USHORT)(sizeof(T_desc2) - 1 +
370 FRX_ADD_SMALL_PACKET_SIZE));
371 trace_desc2->len = 0;
372 trace_desc2->next = (ULONG)NULL;
373 ppp_data->frx.hdlc_frame = trace_desc2;
374
375 /*
376 * store first HDLC flag
377 */
378 TRACE_EVENT_P2("start flag found in desc=0x%08x pos=%d",
379 trace_desc,
380 trace_pos);
381 trace_desc2->buffer[trace_desc2->len] =
382 trace_desc->buffer[trace_pos];
383 trace_desc2->len++;
384 trace_pos++;
385 while((trace_desc) && (trace_pos >= trace_desc->len))
386 {
387 trace_desc = (T_desc2*)trace_desc->next;
388 trace_pos = 0;
389 }
390 if(trace_desc)
391 {
392 /*
393 * store HDLC frame
394 */
395 while((trace_desc) &&
396 (trace_desc->buffer[trace_pos] NEQ PPP_HDLC_FLAG))
397 {
398 if(trace_desc2->len >= FRX_ADD_SMALL_PACKET_SIZE)
399 {
400 MALLOC(trace_desc3, (USHORT)(sizeof(T_desc2) - 1 +
401 FRX_ADD_SMALL_PACKET_SIZE));
402 trace_desc3->len = 0;
403 trace_desc3->next = (ULONG)NULL;
404 trace_desc2->next = (ULONG)trace_desc3;
405 trace_desc2 = trace_desc3;
406 }
407 trace_desc2->buffer[trace_desc2->len] =
408 trace_desc->buffer[trace_pos];
409 trace_desc2->len++;
410 trace_pos++;
411 while((trace_desc) && (trace_pos >= trace_desc->len))
412 {
413 trace_desc = (T_desc2*)trace_desc->next;
414 trace_pos = 0;
415 }
416 }
417 /*
418 * store last HDLC flag
419 */
420 if(trace_desc)
421 {
422 if(trace_desc2->len >= FRX_ADD_SMALL_PACKET_SIZE)
423 {
424 MALLOC(trace_desc3, (USHORT)(sizeof(T_desc2) - 1 +
425 FRX_ADD_SMALL_PACKET_SIZE));
426 trace_desc3->len = 0;
427 trace_desc3->next = (ULONG)NULL;
428 trace_desc2->next = (ULONG)trace_desc3;
429 trace_desc2 = trace_desc3;
430 }
431 TRACE_EVENT_P2("stop flag found in desc=0x%08x pos=%d",
432 trace_desc,
433 trace_pos);
434 trace_desc2->buffer[trace_desc2->len] =
435 trace_desc->buffer[trace_pos];
436 trace_desc2->len++;
437 trace_pos++;
438 }
439 }
440 #endif /* PPP_HDLC_TRACE */
441 store_state = FRX_ADD_HDLC_BEGIN;
442 }
443 /*
444 * begin of frame detected
445 */
446 if(store_state EQ FRX_ADD_HDLC_BEGIN)
447 {
448 /*
449 * initialize new packet
450 */
451 ppp_data->frx.stored_len = 0;
452 d_offset = 0;
453 ppp_data->frx.stored_ptype = 0x0000;
454 fcs = PPP_INITFCS;
455 escape = FALSE;
456 store_state = FRX_ADD_ADDRESS;
457 }
458 /*
459 * end of frame detected
460 * no error occured, frame complete
461 * if we are in INFORMATION state we have to keep in mind the FCS at MRU check
462 */
463 else if(((ppp_data->frx.stored_len + d_offset) >= 4) &&
464 (((ppp_data->frx.stored_len + d_offset) <= ppp_data->mru) ||
465 (((ppp_data->frx.stored_len + d_offset) <=
466 (ppp_data->mru + 2)) &&
467 (store_state EQ FRX_ADD_INFORMATION))) &&
468 (fcs EQ PPP_GOODFCS))
469 {
470 /*
471 * determine the length of the packet
472 */
473 packet_len = 0;
474 ppp_data->frx.stored_len += d_offset;
475 ppp_data->frx.cur_desc->len = d_offset;
476 switch(store_state)
477 {
478 case FRX_ADD_INFORMATION:
479 packet_len = ppp_data->frx.stored_len - 2;
480 break;
481
482 case FRX_ADD_FCS1:
483 packet_len = ppp_data->frx.stored_len - 1;
484 break;
485
486 case FRX_ADD_FCS2:
487 packet_len = ppp_data->frx.stored_len;
488 break;
489 } /*lint !e744 switch statement has no default */
490 if(packet_len < ppp_data->frx.stored_len)
491 {
492 /*
493 * remove FCS
494 */
495 ppp_data->frx.stored_len = packet_len;
496 temp_desc = ppp_data->frx.stored_packet;
497 while(packet_len > temp_desc->len)
498 {
499 packet_len-= temp_desc->len;
500 temp_desc = (T_desc2*)temp_desc->next;
501 }
502 temp_desc->len = packet_len;
503 /*
504 * free the rest of packet
505 */
506 arb_discard_packet((T_desc2*)temp_desc->next);
507 temp_desc->next = (ULONG)NULL;
508 }
509 #ifdef PPP_HDLC_TRACE
510 /*
511 * remove stored HDLC frame because of correct reception
512 * the storage of the next PPP frame is done
513 * in the next call of frx_add_desc()
514 */
515 MFREE_DESC2(ppp_data->frx.hdlc_frame);
516 ppp_data->frx.hdlc_frame = NULL;
517 #endif /* PPP_HDLC_TRACE */
518 /*
519 * esape loop
520 */
521 ppp_data->frx.frame_complete = TRUE;
522 store_state = FRX_ADD_HDLC_BEGIN;
523 break;
524 }
525 /*
526 * end of frame detected
527 * error occured, discard frame
528 */
529 else
530 {
531 /*
532 * error traces
533 */
534 if(((ppp_data->frx.stored_len + d_offset) >= 4) &&
535 (fcs NEQ PPP_GOODFCS))
536 {
537 TRACE_EVENT("ERROR HDLC PACKET PPP FCS FAULT");
538 }
539 else if((ppp_data->frx.stored_len + d_offset) > ppp_data->mru)
540 {
541 TRACE_EVENT_P3("ERROR PPP PACKET TO LONG stored_len=%d d_offset=%d mru=%d",
542 ppp_data->frx.stored_len,
543 d_offset,
544 ppp_data->mru);
545 }
546 #ifdef PPP_HDLC_TRACE
547 if((ppp_data->frx.stored_len + d_offset) > 0)
548 {
549 /*
550 * trace HDLC frame and store next frame
551 */
552 TRACE_EVENT("wrong HDLC frame:");
553 i = 0;
554 trace_pos = 0;
555 trace_desc2 = ppp_data->frx.hdlc_frame;
556 while(trace_desc2)
557 {
558 i+= sprintf(&buf[i],
559 "0x%02x, ",
560 trace_desc2->buffer[trace_pos]);
561 trace_pos++;
562 if(trace_desc2->len <= trace_pos)
563 {
564 trace_desc2 = (T_desc2*)trace_desc2->next;
565 trace_pos = 0;
566 }
567 if(i > 80)
568 {
569 TRACE_EVENT( buf );
570 i = 0;
571 }
572 }
573 if(i > 0)
574 {
575 TRACE_EVENT( buf );
576 i = 0;
577 }
578 }
579 /*
580 * release stored HDLC frame
581 */
582 MFREE_DESC2(ppp_data->frx.hdlc_frame);
583 ppp_data->frx.hdlc_frame = NULL;
584 /*
585 * store next HDLC frame
586 */
587 /*
588 * set source pointer
589 */
590 trace_desc = source_desc;
591 trace_pos = s_offset;
592 /*
593 * allocate first descriptor to store new HDLC frame
594 */
595 MALLOC(trace_desc2, (USHORT)(sizeof(T_desc2) - 1 +
596 FRX_ADD_SMALL_PACKET_SIZE));
597 trace_desc2->len = 0;
598 trace_desc2->next = (ULONG)NULL;
599 ppp_data->frx.hdlc_frame = trace_desc2;
600
601 /*
602 * store first HDLC flag
603 */
604 TRACE_EVENT_P2("start flag found in desc=0x%08x pos=%d",
605 trace_desc,
606 trace_pos);
607 trace_desc2->buffer[trace_desc2->len] =
608 trace_desc->buffer[trace_pos];
609 trace_desc2->len++;
610 trace_pos++;
611 while((trace_desc) && (trace_pos >= trace_desc->len))
612 {
613 trace_desc = (T_desc2*)trace_desc->next;
614 trace_pos = 0;
615 }
616 if(trace_desc)
617 {
618 /*
619 * store HDLC frame
620 */
621 while((trace_desc) &&
622 (trace_desc->buffer[trace_pos] NEQ PPP_HDLC_FLAG))
623 {
624 if(trace_desc2->len >= FRX_ADD_SMALL_PACKET_SIZE)
625 {
626 MALLOC(trace_desc3, (USHORT)(sizeof(T_desc2) - 1 +
627 FRX_ADD_SMALL_PACKET_SIZE));
628 trace_desc3->len = 0;
629 trace_desc3->next = (ULONG)NULL;
630 trace_desc2->next = (ULONG)trace_desc3;
631 trace_desc2 = trace_desc3;
632 }
633 trace_desc2->buffer[trace_desc2->len] =
634 trace_desc->buffer[trace_pos];
635 trace_desc2->len++;
636 trace_pos++;
637 while((trace_desc) && (trace_pos >= trace_desc->len))
638 {
639 trace_desc = (T_desc2*)trace_desc->next;
640 trace_pos = 0;
641 }
642 }
643 /*
644 * store last HDLC flag
645 */
646 if(trace_desc)
647 {
648 if(trace_desc2->len >= FRX_ADD_SMALL_PACKET_SIZE)
649 {
650 MALLOC(trace_desc3, (USHORT)(sizeof(T_desc2) - 1 +
651 FRX_ADD_SMALL_PACKET_SIZE));
652 trace_desc3->len = 0;
653 trace_desc3->next = (ULONG)NULL;
654 trace_desc2->next = (ULONG)trace_desc3;
655 trace_desc2 = trace_desc3;
656 }
657 TRACE_EVENT_P2("stop flag found in desc=0x%08x pos=%d",
658 trace_desc,
659 trace_pos);
660 trace_desc2->buffer[trace_desc2->len] =
661 trace_desc->buffer[trace_pos];
662 trace_desc2->len++;
663 trace_pos++;
664 }
665 }
666 #endif /* PPP_HDLC_TRACE */
667 /*
668 * remove receiced packet because of an error
669 * decrease source offset beacause the HDLC end flag
670 * can also be the HDLC start flag of the next frame
671 */
672 s_offset--;
673 arb_discard_packet(ppp_data->frx.stored_packet);
674 ppp_data->frx.stored_packet = NULL;
675 store_state = FRX_ADD_HDLC_BEGIN;
676 }
677 }
678 /*
679 * detect Control Escape octet
680 */
681 else if((currentbyte EQ PPP_HDLC_ESCAPE) && (escape EQ FALSE))
682 {
683 escape = TRUE;
684 }
685 /*
686 * usual octet
687 */
688 else
689 {
690 /*
691 * bit 5 complement for the octet followed by Control Escape
692 */
693 if(escape EQ TRUE)
694 {
695 currentbyte^= 0x20;
696 escape = FALSE;
697 }
698 /*
699 * calculate FCS
700 */
701 #ifdef _SIMULATION_
702 fcs = (fcs << 8) + currentbyte; /*lint !e734 Loss of precision */
703 #else /* _SIMULATION_ */
704 fcs = (fcs >> 8) ^ fcstab[(fcs ^ currentbyte) & 0xff];
705 #endif /* _SIMULATION_ */
706 /*
707 * store the packet and determine the protocol
708 */
709 switch(store_state)
710 {
711 case FRX_ADD_INFORMATION:
712 if(d_offset >= d_size)
713 {
714 if((ppp_data->frx.stored_len + d_offset) < ppp_data->mru)
715 {
716 /*
717 * allocate new descriptor
718 */
719 switch(ppp_data->frx.stored_ptype)
720 {
721 case DTI_PID_LCP:
722 case DTI_PID_PAP:
723 case DTI_PID_CHAP:
724 case DTI_PID_IPCP:
725 /*
726 * allocate a big descriptor, copy the data into the new
727 * one and free the small descriptor
728 */
729 MALLOC (ppp_data->frx.stored_packet,
730 (USHORT)(sizeof(T_desc2) - 1 + ppp_data->mru));
731 memcpy(ppp_data->frx.stored_packet->buffer,
732 destination,
733 d_offset); /*lint !e668 Possibly passing a null pointer */
734 MFREE(ppp_data->frx.cur_desc);
735 ppp_data->frx.cur_desc = ppp_data->frx.stored_packet;
736 ppp_data->frx.cur_desc->next = (ULONG)NULL;
737 destination = ppp_data->frx.cur_desc->buffer;
738 d_size = ppp_data->mru;
739 break;
740
741 default:
742 /*
743 * allocate a new small descriptor
744 */
745 MALLOC (temp_desc, (USHORT)(sizeof(T_desc2) - 1 +
746 FRX_ADD_SMALL_PACKET_SIZE));
747 ppp_data->frx.cur_desc->next = (ULONG)temp_desc;
748 ppp_data->frx.cur_desc->len = d_offset;
749 ppp_data->frx.cur_desc = temp_desc;
750 ppp_data->frx.cur_desc->next = (ULONG)NULL;
751 ppp_data->frx.stored_len += d_offset;
752 destination = ppp_data->frx.cur_desc->buffer;
753 d_offset = 0;
754 d_size = FRX_ADD_SMALL_PACKET_SIZE;
755 break;
756 }
757 }
758 else if((ppp_data->frx.stored_len + d_offset) >=
759 (ppp_data->mru + 2))
760 {
761 /*
762 * remove receiced packet because it is to long
763 */
764 arb_discard_packet(ppp_data->frx.stored_packet);
765 ppp_data->frx.stored_packet = NULL;
766 store_state = FRX_ADD_ERROR;
767
768 TRACE_EVENT("ERROR PPP: HDLC packet to long");
769 #ifdef PPP_HDLC_TRACE
770 /*
771 * trace HDLC frame
772 */
773 TRACE_EVENT("wrong HDLC frame:");
774 i = 0;
775 trace_pos = 0;
776 trace_desc2 = ppp_data->frx.hdlc_frame;
777 while(trace_desc2)
778 {
779 i+= sprintf(&buf[i],
780 "0x%02x, ",
781 trace_desc2->buffer[trace_pos]);
782 trace_pos++;
783 if(trace_desc2->len <= trace_pos)
784 {
785 trace_desc2 = (T_desc2*)trace_desc2->next;
786 trace_pos = 0;
787 }
788 if(i > 80)
789 {
790 TRACE_EVENT( buf );
791 i = 0;
792 }
793 }
794 if(i > 0)
795 {
796 TRACE_EVENT( buf );
797 i = 0;
798 }
799 /*
800 * release stored HDLC frame
801 */
802 MFREE_DESC2(ppp_data->frx.hdlc_frame);
803 ppp_data->frx.hdlc_frame = NULL;
804 #endif /* PPP_HDLC_TRACE */
805 break;
806 }
807 else if((ppp_data->frx.stored_len + d_offset) >=
808 (ppp_data->mru + 1))
809 {
810 d_offset--;
811 store_state = FRX_ADD_FCS2;
812 break;
813 }
814 else
815 {
816 store_state = FRX_ADD_FCS1;
817 break;
818 }
819 }
820 /*
821 * copy data
822 */
823 destination[d_offset] = currentbyte; /*lint !e613 Possible use of null pointer */
824 /*
825 * increase destination offset
826 */
827 d_offset++;
828 break;
829
830 case FRX_ADD_CONTROL:
831 if(currentbyte EQ 0x03)
832 store_state = FRX_ADD_PROTOCOL1;
833 else
834 {
835 TRACE_EVENT("ERROR PPP: wrong HDLC control field");
836 #ifdef PPP_HDLC_TRACE
837 /*
838 * trace HDLC frame
839 */
840 TRACE_EVENT("wrong HDLC frame:");
841 i = 0;
842 trace_pos = 0;
843 trace_desc2 = ppp_data->frx.hdlc_frame;
844 while(trace_desc2)
845 {
846 i+= sprintf(&buf[i], "0x%02x, ", trace_desc2->buffer[trace_pos]);
847 trace_pos++;
848 if(trace_desc2->len <= trace_pos)
849 {
850 trace_desc2 = (T_desc2*)trace_desc2->next;
851 trace_pos = 0;
852 }
853 if(i > 80)
854 {
855 TRACE_EVENT( buf );
856 i = 0;
857 }
858 }
859 if(i > 0)
860 {
861 TRACE_EVENT( buf );
862 i = 0;
863 }
864 /*
865 * release stored HDLC frame
866 */
867 MFREE_DESC2(ppp_data->frx.hdlc_frame);
868 ppp_data->frx.hdlc_frame = NULL;
869 #endif /* PPP_HDLC_TRACE */
870 store_state = FRX_ADD_ERROR;
871 }
872 break;
873
874 case FRX_ADD_ADDRESS:
875 if(currentbyte EQ 0xff)
876 {
877 store_state = FRX_ADD_CONTROL;
878 break;
879 }
880 /*
881 * address and control field compression detected
882 */
883 /* fall through */
884 case FRX_ADD_PROTOCOL1:
885 if((currentbyte & 0x01) EQ 0)
886 {
887 ppp_data->frx.stored_ptype = currentbyte;
888 ppp_data->frx.stored_ptype = (ppp_data->frx.stored_ptype << 8); /*lint !e734 Loss of precision */
889 store_state = FRX_ADD_PROTOCOL2;
890 break;
891 }
892 /*
893 * protocol field compression detected
894 */
895 /* fall through */
896 case FRX_ADD_PROTOCOL2:
897 if(currentbyte & 0x01)
898 {
899 /*
900 * store protocol
901 */
902 ppp_data->frx.stored_ptype|= currentbyte;
903 /*
904 * allocate new packet
905 */
906 d_size = FRX_ADD_SMALL_PACKET_SIZE;
907 /*
908 * Allocate the necessary size for the data descriptor.
909 * The size is calculated as follows:
910 * - take the size of a descriptor structure
911 * - subtract one because of the array buffer[1] to get
912 * the size of descriptor control information
913 * - add number of octets of descriptor data
914 */
915 MALLOC (ppp_data->frx.stored_packet,
916 (USHORT)(sizeof(T_desc2) - 1 + d_size));
917 ppp_data->frx.cur_desc = ppp_data->frx.stored_packet;
918 ppp_data->frx.cur_desc->next = (ULONG)NULL;
919 destination = ppp_data->frx.cur_desc->buffer;
920 d_offset = 0;
921 store_state = FRX_ADD_INFORMATION;
922 }
923 else
924 {
925 TRACE_EVENT("ERROR PPP: wrong HDLC protocol field");
926 #ifdef PPP_HDLC_TRACE
927 /*
928 * trace HDLC frame
929 */
930 TRACE_EVENT("wrong HDLC frame:");
931 i = 0;
932 trace_pos = 0;
933 trace_desc2 = ppp_data->frx.hdlc_frame;
934 while(trace_desc2)
935 {
936 i+= sprintf(&buf[i], "0x%02x, ", trace_desc2->buffer[trace_pos]);
937 trace_pos++;
938 if(trace_desc2->len <= trace_pos)
939 {
940 trace_desc2 = (T_desc2*)trace_desc2->next;
941 trace_pos = 0;
942 }
943 if(i > 80)
944 {
945 TRACE_EVENT( buf );
946 i = 0;
947 }
948 }
949 if(i > 0)
950 {
951 TRACE_EVENT( buf );
952 i = 0;
953 }
954 /*
955 * release stored HDLC frame
956 */
957 MFREE_DESC2(ppp_data->frx.hdlc_frame);
958 ppp_data->frx.hdlc_frame = NULL;
959 #endif /* PPP_HDLC_TRACE */
960 store_state = FRX_ADD_ERROR;
961 }
962 break;
963
964 case FRX_ADD_FCS1:
965 store_state = FRX_ADD_FCS2;
966 break;
967
968 case FRX_ADD_FCS2:
969 /*
970 * remove receiced packet because its to long
971 */
972 arb_discard_packet(ppp_data->frx.stored_packet);
973 ppp_data->frx.stored_packet = NULL;
974 store_state = FRX_ADD_ERROR;
975
976 TRACE_EVENT("ERROR PPP: HDLC packet to long");
977 #ifdef PPP_HDLC_TRACE
978 /*
979 * trace HDLC frame
980 */
981 TRACE_EVENT("wrong HDLC frame:");
982 i = 0;
983 trace_pos = 0;
984 trace_desc2 = ppp_data->frx.hdlc_frame;
985 while(trace_desc2)
986 {
987 i+= sprintf(&buf[i], "0x%02x, ", trace_desc2->buffer[trace_pos]);
988 trace_pos++;
989 if(trace_desc2->len <= trace_pos)
990 {
991 trace_desc2 = (T_desc2*)trace_desc2->next;
992 trace_pos = 0;
993 }
994 if(i > 80)
995 {
996 TRACE_EVENT( buf );
997 i = 0;
998 }
999 }
1000 if(i > 0)
1001 {
1002 TRACE_EVENT( buf );
1003 i = 0;
1004 }
1005 /*
1006 * release stored HDLC frame
1007 */
1008 MFREE_DESC2(ppp_data->frx.hdlc_frame);
1009 ppp_data->frx.hdlc_frame = NULL;
1010 #endif /* PPP_HDLC_TRACE */
1011 break;
1012
1013 case FRX_ADD_ERROR:
1014 /*
1015 * we wait for the next HDLC flag
1016 */
1017 break;
1018
1019 case FRX_ADD_HDLC_BEGIN:
1020 TRACE_ERROR("ERROR: frx_add_desc(): in FRX_ADD_HDLC_BEGIN state without HDLC flag");
1021 break;
1022
1023 default:
1024 TRACE_ERROR("ERROR: frx_add_desc(): wrong state");
1025 break;
1026 }
1027 }
1028 }
1029 /*
1030 * check if current descriptor is complete analyzed
1031 */
1032 if(s_offset >= s_size)
1033 {
1034 temp_desc = (T_desc2*)source_desc->next;
1035 MFREE(source_desc);
1036 source_desc = temp_desc;
1037 s_offset = 0;
1038 }
1039 }
1040 /*
1041 * store important values in global variables
1042 */
1043 switch(store_state)
1044 {
1045 case FRX_ADD_INFORMATION:
1046 case FRX_ADD_FCS1:
1047 case FRX_ADD_FCS2:
1048 ppp_data->frx.cur_desc->len = d_offset;
1049 break;
1050 } /*lint !e744 switch statement has no default */
1051 ppp_data->frx.store_state = store_state;
1052 ppp_data->frx.calc_fcs = fcs;
1053 ppp_data->frx.escape = escape;
1054 ppp_data->frx.received_data = source_desc;
1055 ppp_data->frx.cur_desc_size = d_size;
1056 ppp_data->frx.proceed_data = s_offset;
1057 } /*lint !e550 fcstab not accessed in _SIMULATION_ frx_add_desc() */
1058 #endif /* PPP_FLASH_ROM */
1059
1060
1061
1062 #ifndef PPP_INT_RAM
1063 /*
1064 +------------------------------------------------------------------------------
1065 | Function : frx_detect_frame
1066 +------------------------------------------------------------------------------
1067 | Description : The function frx_detect_frame() detects begin and end of
1068 | PPP frames.
1069 |
1070 | Parameters : no parameters
1071 |
1072 +------------------------------------------------------------------------------
1073 */
1074 GLOBAL void frx_detect_frame ()
1075 {
1076 UBYTE* source;
1077 UBYTE* destination;
1078 T_desc2* temp_desc1;
1079 T_desc2* temp_desc2;
1080
1081 TRACE_FUNCTION( "frx_detect_frame" );
1082
1083 /*
1084 * copy received data stream pointer
1085 */
1086 temp_desc1 = ppp_data->frx.received_data;
1087 /*
1088 * set destination pointer if necessary
1089 */
1090 if(ppp_data->frx.store_state EQ FRX_ADD_INFORMATION)
1091 {
1092 /*
1093 * to avoid erroneuos code generation of target compiler,
1094 * it is written in two lines instead of one
1095 */
1096 destination = ppp_data->frx.cur_desc->buffer;
1097 destination+= ppp_data->frx.cur_desc->len;
1098 }
1099
1100 /*
1101 * while there is still data to analyze and
1102 * a complete frame is not yet received
1103 */
1104 while((temp_desc1) && (ppp_data->frx.frame_complete EQ FALSE))
1105 {
1106 /*
1107 * set source pointer
1108 */
1109 source = &temp_desc1->buffer[ppp_data->frx.proceed_data];
1110 /*
1111 * We count down the length of the current descriptor.
1112 * while the current descriptor is not yet complete analyzed and
1113 * a complete frame is not yet received
1114 */
1115 while((temp_desc1->len) && (ppp_data->frx.frame_complete EQ FALSE))
1116 {
1117 switch(ppp_data->frx.store_state)
1118 {
1119 case FRX_ADD_ERROR:
1120 /*
1121 * search for next HDLC flag
1122 */
1123 while((temp_desc1->len) &&
1124 (*source NEQ PPP_HDLC_FLAG))
1125 {
1126 /*
1127 * increase source pointer
1128 */
1129 source++;
1130 temp_desc1->len--;
1131 ppp_data->frx.proceed_data++;
1132 }
1133 if(temp_desc1->len EQ 0) /*lint !e661 Possible access of out-of-bounds pointer */
1134 /*
1135 * end of descriptor reached
1136 * analyze next descriptor
1137 */
1138 break;
1139 ppp_data->frx.store_state = FRX_ADD_HDLC_BEGIN;
1140 /* fall through */
1141 case FRX_ADD_HDLC_BEGIN:
1142 /*
1143 * create new packet (frame) to store detected frame
1144 */
1145 ppp_data->frx.stored_len = 0;
1146 ppp_data->frx.stored_ptype = DTI_PID_UOS;
1147 ppp_data->frx.cur_desc_size = FRX_ADD_SMALL_PACKET_SIZE;
1148 /*
1149 * Allocate the necessary size for the data descriptor. The size is
1150 * calculated as follows:
1151 * - take the size of a descriptor structure
1152 * - subtract one because of the array buffer[1] to get the size of
1153 * descriptor control information
1154 * - add number of octets of descriptor data
1155 */
1156 MALLOC (ppp_data->frx.stored_packet,
1157 (USHORT)(sizeof(T_desc2) - 1 + FRX_ADD_SMALL_PACKET_SIZE));
1158 ppp_data->frx.cur_desc = ppp_data->frx.stored_packet;
1159 ppp_data->frx.cur_desc->len = 0;
1160 ppp_data->frx.cur_desc->next = (ULONG)NULL;
1161 destination = ppp_data->frx.cur_desc->buffer;
1162
1163 *destination = *source; /*lint !e613 Possible use of null pointer */
1164 /*
1165 * increase source pointer
1166 */
1167 source++; /*lint !e613 Possible use of null pointer */
1168 temp_desc1->len--;
1169 ppp_data->frx.proceed_data++;
1170 /*
1171 * increase destination pointer
1172 */
1173 ppp_data->frx.stored_len++;
1174 destination++;
1175 ppp_data->frx.cur_desc->len++;
1176
1177 ppp_data->frx.store_state = FRX_ADD_INFORMATION;
1178 break;
1179
1180 case FRX_ADD_INFORMATION:
1181 /*
1182 * copy data
1183 */
1184 while((temp_desc1->len) &&
1185 (ppp_data->frx.stored_len < ppp_data->mru) &&
1186 (ppp_data->frx.cur_desc->len < ppp_data->frx.cur_desc_size) &&
1187 (*source NEQ PPP_HDLC_FLAG))
1188 {
1189 /*
1190 * copy data
1191 */
1192 *destination = *source; /*lint !e644 destination may not have been initialized */
1193 /*
1194 * increase source pointer
1195 */
1196 source++;
1197 temp_desc1->len--;
1198 ppp_data->frx.proceed_data++;
1199 /*
1200 * increase destination pointer
1201 */
1202 ppp_data->frx.stored_len++;
1203 destination++;
1204 ppp_data->frx.cur_desc->len++;
1205 }
1206 /*
1207 * analyze why the loop is left
1208 */
1209 if(ppp_data->frx.stored_len < ppp_data->mru) /*lint !e661 Possible access of out-of-bounds pointer */
1210 {
1211 if(ppp_data->frx.cur_desc->len >= ppp_data->frx.cur_desc_size)
1212 {
1213 /*
1214 * allocate a new small descriptor
1215 */
1216 MALLOC (temp_desc2, (USHORT)(sizeof(T_desc2) - 1 +
1217 FRX_ADD_SMALL_PACKET_SIZE));
1218 ppp_data->frx.cur_desc->next = (ULONG)temp_desc2;
1219 ppp_data->frx.cur_desc =
1220 (T_desc2*)ppp_data->frx.cur_desc->next;
1221 ppp_data->frx.cur_desc->len = 0;
1222 ppp_data->frx.cur_desc->size = 0;
1223 ppp_data->frx.cur_desc->offset = 0;
1224 ppp_data->frx.cur_desc->next = (ULONG)NULL;
1225 ppp_data->frx.cur_desc_size = FRX_ADD_SMALL_PACKET_SIZE;
1226 destination = ppp_data->frx.cur_desc->buffer;
1227 }
1228 if((temp_desc1->len) &&
1229 (*source EQ PPP_HDLC_FLAG)) /*lint !e613 Possible use of null pointer */
1230 {
1231 /*
1232 * end of frame detected
1233 */
1234 ppp_data->frx.store_state = FRX_ADD_HDLC_BEGIN;
1235 /*
1236 * copy HDLC flag
1237 */
1238 *destination = *source; /*lint !e613 Possible use of null pointer */
1239 /*
1240 * increase length values
1241 */
1242 ppp_data->frx.stored_len++;
1243 ppp_data->frx.cur_desc->len++;
1244 /*
1245 * check for correct length
1246 */
1247 if(ppp_data->frx.stored_len > 2)
1248 {
1249 /*
1250 * no error occured, frame complete
1251 */
1252 ppp_data->frx.frame_complete = TRUE;
1253 }
1254 else
1255 {
1256 /*
1257 * remove receiced packet because its to short
1258 */
1259 arb_discard_packet(ppp_data->frx.stored_packet);
1260 ppp_data->frx.stored_packet = NULL;
1261 }
1262 }
1263 }
1264 else
1265 {
1266 /*
1267 * remove receiced packet because its to long
1268 */
1269 arb_discard_packet(ppp_data->frx.stored_packet);
1270 ppp_data->frx.stored_packet = NULL;
1271 ppp_data->frx.store_state = FRX_ADD_ERROR;
1272 }
1273 break;
1274 } /*lint !e744 switch statement has no default */
1275 }
1276 if(temp_desc1->len EQ 0)
1277 {
1278 temp_desc2 = (T_desc2*)temp_desc1->next;
1279 MFREE(temp_desc1);
1280 temp_desc1 = temp_desc2;
1281 ppp_data->frx.proceed_data = 0;
1282 }
1283 }
1284 /*
1285 * store received data stream pointer
1286 */
1287 ppp_data->frx.received_data = temp_desc1;
1288 } /* frx_detect_frame() */
1289
1290
1291
1292 /*
1293 +------------------------------------------------------------------------------
1294 | Function : frx_send_pack_ready_mode()
1295 +------------------------------------------------------------------------------
1296 | Description : send as many packets to ptx as can be extracted from received frame.
1297 | Frx is in ready mode.
1298 |
1299 | Parameters : no parameters
1300 |
1301 +------------------------------------------------------------------------------
1302 */
1303
1304 GLOBAL void frx_send_pack_ready_mode ()
1305 {
1306 T_desc2* temp_desc;
1307
1308 TRACE_FUNCTION( "frx_send_pack_ready_mode ()" );
1309
1310 while( ppp_data->frx.frame_complete EQ TRUE AND
1311 ppp_data->frx.data_flow_state EQ FRX_DATA_FLOW_READY)
1312 {
1313 /*
1314 * to avoid any side effects
1315 * first reset all necessary variables and then call the signal
1316 */
1317 ppp_data->frx.frame_complete = FALSE;
1318 temp_desc = ppp_data->frx.stored_packet;
1319 ppp_data->frx.stored_packet = NULL;
1320 sig_frx_ptx_packet_ind(ppp_data->frx.stored_ptype,
1321 ppp_data->frx.stored_len,
1322 temp_desc);
1323 frx_add_desc();
1324 }
1325 }
1326
1327
1328 /*
1329 +------------------------------------------------------------------------------
1330 | Function : frx_send_pack_transp_mode
1331 +------------------------------------------------------------------------------
1332 | Description : send as many packets to ptx as can be extracted from received frame.
1333 | Frx is in transparent mode .
1334 |
1335 | Parameters : no parameters
1336 |
1337 +------------------------------------------------------------------------------
1338 */
1339
1340 GLOBAL void frx_send_pack_transp_mode ()
1341 {
1342 T_desc2* temp_desc;
1343
1344 TRACE_FUNCTION( "frx_send_pack_transp_mode ()" );
1345
1346 while( ppp_data->frx.frame_complete EQ TRUE AND
1347 ppp_data->frx.data_flow_state EQ FRX_DATA_FLOW_READY)
1348 {
1349 /*
1350 * to avoid any side effects
1351 * first reset all necessary variables and then call the signal
1352 */
1353 ppp_data->frx.frame_complete = FALSE;
1354 temp_desc = ppp_data->frx.stored_packet;
1355 ppp_data->frx.stored_packet = NULL;
1356 sig_frx_ptx_packet_ind(ppp_data->frx.stored_ptype,
1357 ppp_data->frx.stored_len,
1358 temp_desc);
1359 frx_detect_frame();
1360 }
1361
1362 }
1363
1364 #endif /* PPP_INT_RAM */
1365