FreeCalypso > hg > fc-magnetite
comparison src/g23m-fad/ppp/ppp_ftxf.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 : | |
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 (FTX-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 | |
41 #include "ppp_arbf.h" /* to get function interface from arb */ | |
42 | |
43 /*==== CONST ================================================================*/ | |
44 | |
45 /*==== LOCAL VARS ===========================================================*/ | |
46 | |
47 /*==== PRIVATE FUNCTIONS ====================================================*/ | |
48 | |
49 /*==== PUBLIC FUNCTIONS =====================================================*/ | |
50 | |
51 #ifndef PPP_INT_RAM | |
52 /* | |
53 +------------------------------------------------------------------------------ | |
54 | Function : ftx_init | |
55 +------------------------------------------------------------------------------ | |
56 | Description : The function ftx_init() initializes Frame Transmit (FTX) | |
57 | | |
58 | Parameters : no parameters | |
59 | | |
60 +------------------------------------------------------------------------------ | |
61 */ | |
62 GLOBAL void ftx_init () | |
63 { | |
64 USHORT i; | |
65 | |
66 TRACE_FUNCTION( "ftx_init" ); | |
67 | |
68 ppp_data->ftx.acfc = PPP_ACFC_DEFAULT; | |
69 ppp_data->ftx.pfc = PPP_PFC_DEFAULT; | |
70 | |
71 /* | |
72 * inititialise ACCMTAB | |
73 */ | |
74 for(i=0;i<=255;i++) | |
75 { | |
76 if(i<0x20) | |
77 { | |
78 ppp_data->ftx.accmtab[i] = (PPP_ACCM_DEFAULT & (1UL << i)) ? 0xFF : 0x00; | |
79 } | |
80 else if((i EQ PPP_HDLC_FLAG) || | |
81 (i EQ PPP_HDLC_ESCAPE) || | |
82 (i EQ PPP_ASCII_DEL)) | |
83 { | |
84 ppp_data->ftx.accmtab[i] = 0xFF; | |
85 } | |
86 else | |
87 { | |
88 ppp_data->ftx.accmtab[i] = 0x00; | |
89 } | |
90 } | |
91 | |
92 | |
93 INIT_STATE( PPP_SERVICE_FTX , FTX_DEAD ); | |
94 } /* ftx_init() */ | |
95 #endif /* PPP_INT_RAM */ | |
96 | |
97 | |
98 | |
99 #ifndef PPP_FLASH_ROM | |
100 /* | |
101 +------------------------------------------------------------------------------ | |
102 | Function : ftx_get_frame | |
103 +------------------------------------------------------------------------------ | |
104 | Description : The function ftx_get_frame() puts the given packet into a HDLC | |
105 | frame. A FCS is calculated and put at the the end of the | |
106 | packet. After that every byte is examined and preceeded with an | |
107 | escape character when certain condiitions are met. | |
108 | | |
109 | This function has been optimized - FCS calculation and escaping | |
110 | are done in the same loop. | |
111 | | |
112 | Parameters : ptype - packet type | |
113 | packet - pointer to a generic data descriptor | |
114 | ptr_frame - returns a list of generic data descriptors | |
115 | | |
116 +------------------------------------------------------------------------------ | |
117 */ | |
118 GLOBAL void ftx_get_frame (USHORT ptype, T_desc2* packet, T_desc_list2* ptr_frame) | |
119 { | |
120 T_desc2 *temp_desc1, *temp_desc2; | |
121 USHORT calc_fcs; | |
122 USHORT i; | |
123 UBYTE currentByte; | |
124 UBYTE escape; | |
125 | |
126 TRACE_FUNCTION( "ftx_get_frame" ); | |
127 | |
128 /* | |
129 * create a new descriptor for address, control and protocol field and put | |
130 * it in front of the linked descriptor list | |
131 */ | |
132 /* | |
133 * 1 octet address field | |
134 * 1 octet control field | |
135 * 2 octets protocol field (uncompressed) | |
136 *---------- | |
137 * 4 octets | |
138 */ | |
139 MALLOC (temp_desc1, (USHORT)(sizeof(T_desc2) - 1 + 4)); | |
140 temp_desc1->next = (ULONG)packet; | |
141 packet = temp_desc1; | |
142 packet->len = 0; | |
143 /* | |
144 * if no address and control field compression add both | |
145 * in LCP packets we need always address and control field | |
146 */ | |
147 if((ppp_data->ftx.acfc EQ FALSE) || | |
148 (ptype EQ DTI_PID_LCP)) | |
149 { | |
150 packet->buffer[packet->len] = 0xff; | |
151 packet->len++; | |
152 packet->buffer[packet->len] = 0x03; | |
153 packet->len++; | |
154 } | |
155 /* | |
156 * if no protocol field compression add most significant octet | |
157 * of the protocol field | |
158 * in LCP packets we need always uncompressed protocol field | |
159 */ | |
160 if((ppp_data->ftx.pfc EQ FALSE) || | |
161 (ptype > 0x00ff) || | |
162 (ptype EQ DTI_PID_LCP)) | |
163 { | |
164 packet->buffer[packet->len] = (UBYTE)(ptype >> 8); | |
165 packet->len++; | |
166 } | |
167 /* | |
168 * add protocol field least significant octet | |
169 */ | |
170 packet->buffer[packet->len] = (UBYTE)(ptype & 0xff); | |
171 packet->len++; | |
172 | |
173 | |
174 /* | |
175 * create complete frame | |
176 * use async-control-character-map and copy the packet into descriptor with | |
177 * a size of FTX_GET_DESC_SIZE | |
178 */ | |
179 MALLOC (temp_desc1, (USHORT)(sizeof(T_desc2) - 1 + FTX_GET_DESC_SIZE)); | |
180 temp_desc1->next = (ULONG)NULL; | |
181 ptr_frame->first = (ULONG)temp_desc1; | |
182 | |
183 | |
184 /* | |
185 * reset ptr_frame->list_len, it will be incremented by temp_desc1->len | |
186 * when the packet is completely processed, at the end it will contain | |
187 * the length of the whole frame in bytes | |
188 */ | |
189 ptr_frame->list_len = 0; | |
190 | |
191 | |
192 /* | |
193 * insert HDLC-Flag - to mark the start of the frame | |
194 */ | |
195 temp_desc1->len = 1; | |
196 temp_desc1->size = 1; | |
197 temp_desc1->offset = 1; | |
198 temp_desc1->buffer[0] = PPP_HDLC_FLAG; | |
199 escape=FALSE; | |
200 | |
201 | |
202 /* | |
203 * init FCS | |
204 */ | |
205 calc_fcs = PPP_INITFCS; | |
206 | |
207 | |
208 /* | |
209 * ATTENTION: the following two while loops contain equivalent | |
210 * code - if you edit the code make sure you edit BOTH loops | |
211 */ | |
212 if(ptype EQ DTI_PID_LCP) | |
213 { | |
214 while(packet NEQ NULL) | |
215 { | |
216 i=0; | |
217 while(i < packet->len) | |
218 { | |
219 currentByte = packet->buffer[i]; | |
220 | |
221 if(escape EQ TRUE) | |
222 { | |
223 temp_desc1->buffer[temp_desc1->len] = currentByte ^ 0x20; | |
224 | |
225 calc_fcs=(calc_fcs >> 8) ^ | |
226 ppp_data->fcstab[(calc_fcs ^ currentByte) & 0xff]; | |
227 | |
228 escape=FALSE; | |
229 i++; | |
230 } | |
231 | |
232 /* | |
233 * In LCP packets we escape ALL characters below 0x20. | |
234 * In addition to that PPP_HDLC_FLAG, PPP_HDLC_ESCAPE, | |
235 * PPP_ASCII_DEL are escaped too. These characters are marked in | |
236 * in the ACCM table | |
237 */ | |
238 else if((currentByte < 0x20) || ppp_data->ftx.accmtab[currentByte]) | |
239 { | |
240 temp_desc1->buffer[temp_desc1->len] = PPP_HDLC_ESCAPE; | |
241 escape = TRUE; | |
242 } | |
243 | |
244 else | |
245 { | |
246 temp_desc1->buffer[temp_desc1->len] = currentByte; | |
247 | |
248 calc_fcs=(calc_fcs >> 8) ^ | |
249 ppp_data->fcstab[(calc_fcs ^ currentByte) & 0xff]; | |
250 | |
251 i++; | |
252 } | |
253 | |
254 temp_desc1->len++; | |
255 | |
256 if(temp_desc1->len >= FTX_GET_DESC_SIZE) | |
257 { | |
258 ptr_frame->list_len +=temp_desc1->len; | |
259 | |
260 temp_desc2=temp_desc1; | |
261 MALLOC (temp_desc1, | |
262 (USHORT)(sizeof(T_desc2) - 1 + FTX_GET_DESC_SIZE)); | |
263 | |
264 temp_desc1->len=0; | |
265 temp_desc1->next = (ULONG)NULL; | |
266 | |
267 temp_desc2->next=(ULONG)temp_desc1; | |
268 } | |
269 } | |
270 | |
271 temp_desc2=packet; | |
272 packet=(T_desc2*)packet->next; | |
273 MFREE(temp_desc2); | |
274 } | |
275 ptr_frame->list_len +=temp_desc1->len; | |
276 } | |
277 else | |
278 { | |
279 while(packet NEQ NULL) | |
280 { | |
281 i=0; | |
282 while(i < packet->len) | |
283 { | |
284 currentByte = packet->buffer[i]; | |
285 | |
286 if(escape EQ TRUE) | |
287 { | |
288 temp_desc1->buffer[temp_desc1->len] = currentByte ^ 0x20; | |
289 | |
290 calc_fcs=(calc_fcs >> 8) ^ | |
291 ppp_data->fcstab[(calc_fcs ^ currentByte) & 0xff]; | |
292 | |
293 escape=FALSE; | |
294 i++; | |
295 } | |
296 | |
297 /* | |
298 * In packets other than LCP we escape only those characters | |
299 * below 0x20 that are marked in the ACCM table. | |
300 * In addition to that PPP_HDLC_FLAG, PPP_HDLC_ESCAPE, | |
301 * PPP_ASCII_DEL are escaped too. These characters are marked in | |
302 * in the same table. | |
303 */ | |
304 else if(ppp_data->ftx.accmtab[currentByte]) | |
305 { | |
306 temp_desc1->buffer[temp_desc1->len] = PPP_HDLC_ESCAPE; | |
307 escape = TRUE; | |
308 } | |
309 | |
310 else | |
311 { | |
312 temp_desc1->buffer[temp_desc1->len] = currentByte; | |
313 | |
314 calc_fcs=(calc_fcs >> 8) ^ | |
315 ppp_data->fcstab[(calc_fcs ^ currentByte) & 0xff]; | |
316 | |
317 i++; | |
318 } | |
319 | |
320 temp_desc1->len++; | |
321 | |
322 if(temp_desc1->len >= FTX_GET_DESC_SIZE) | |
323 { | |
324 ptr_frame->list_len +=temp_desc1->len; | |
325 | |
326 temp_desc2=temp_desc1; | |
327 MALLOC (temp_desc1, | |
328 (USHORT)(sizeof(T_desc2) - 1 + FTX_GET_DESC_SIZE)); | |
329 temp_desc1->len=0; | |
330 temp_desc1->next = (ULONG)NULL; | |
331 | |
332 temp_desc2->next=(ULONG)temp_desc1; | |
333 } | |
334 } | |
335 | |
336 temp_desc2=packet; | |
337 packet=(T_desc2*)packet->next; | |
338 MFREE(temp_desc2); | |
339 } | |
340 ptr_frame->list_len +=temp_desc1->len; | |
341 } | |
342 | |
343 /* | |
344 * finish FCS calculation | |
345 */ | |
346 calc_fcs ^= 0xffff; | |
347 | |
348 | |
349 /* | |
350 * create a new descriptor for FCS and HDLC-Flag | |
351 * put the descriptor at the end of the descriptor list | |
352 * | |
353 * FCS must be escaped too, allocate two bytes more - just in case | |
354 * 2 for FCS, 2 for PPP_HDLC_ESCAPE, 1 for PPP_HDLC_FLAG | |
355 * | |
356 */ | |
357 if(temp_desc1->len + 5 >= FTX_GET_DESC_SIZE) | |
358 { | |
359 MALLOC (temp_desc2, (USHORT)(sizeof(T_desc2) - 1 + 5)); | |
360 temp_desc2->len = 0; | |
361 temp_desc2->size = 0; | |
362 temp_desc2->offset = 0; | |
363 temp_desc2->next = (ULONG)NULL; | |
364 | |
365 temp_desc1->next = (ULONG)temp_desc2; | |
366 temp_desc1 = temp_desc2; | |
367 } | |
368 | |
369 /* | |
370 * insert the FCS, escape when necessary | |
371 */ | |
372 #ifdef _SIMULATION_ | |
373 temp_desc1->buffer[temp_desc1->len]=(UBYTE)(PPP_GOODFCS >> 8); | |
374 temp_desc1->buffer[temp_desc1->len+1]=(UBYTE)(PPP_GOODFCS & 0x00ff); | |
375 temp_desc1->len += 2; | |
376 ptr_frame->list_len += 2; | |
377 #else /* _SIMULATION_ */ | |
378 /* | |
379 * least significant octet first | |
380 */ | |
381 if(ptype EQ DTI_PID_LCP) | |
382 { | |
383 currentByte = (UBYTE)(calc_fcs & 0x00ff); | |
384 if((currentByte < 0x20) || ppp_data->ftx.accmtab[currentByte]) | |
385 { | |
386 temp_desc1->buffer[temp_desc1->len] = PPP_HDLC_ESCAPE; | |
387 temp_desc1->buffer[temp_desc1->len+1] = currentByte ^ 0x20; | |
388 temp_desc1->len += 2; | |
389 ptr_frame->list_len += 2; | |
390 } | |
391 else | |
392 { | |
393 temp_desc1->buffer[temp_desc1->len] = currentByte; | |
394 temp_desc1->len++; | |
395 ptr_frame->list_len++; | |
396 } | |
397 | |
398 currentByte = (UBYTE)(calc_fcs >> 8); | |
399 if((currentByte < 0x20) || ppp_data->ftx.accmtab[currentByte]) | |
400 { | |
401 temp_desc1->buffer[temp_desc1->len] = PPP_HDLC_ESCAPE; | |
402 temp_desc1->buffer[temp_desc1->len+1] = currentByte ^ 0x20; | |
403 temp_desc1->len += 2; | |
404 ptr_frame->list_len += 2; | |
405 } | |
406 else | |
407 { | |
408 temp_desc1->buffer[temp_desc1->len] = currentByte; | |
409 temp_desc1->len++; | |
410 ptr_frame->list_len++; | |
411 } | |
412 } | |
413 else | |
414 { | |
415 currentByte = (UBYTE)(calc_fcs & 0x00ff); | |
416 if(ppp_data->ftx.accmtab[currentByte]) | |
417 { | |
418 temp_desc1->buffer[temp_desc1->len] = PPP_HDLC_ESCAPE; | |
419 temp_desc1->buffer[temp_desc1->len+1] = currentByte ^ 0x20; | |
420 temp_desc1->len += 2; | |
421 ptr_frame->list_len += 2; | |
422 } | |
423 else | |
424 { | |
425 temp_desc1->buffer[temp_desc1->len] = currentByte; | |
426 temp_desc1->len++; | |
427 ptr_frame->list_len++; | |
428 } | |
429 | |
430 currentByte = (UBYTE)(calc_fcs >> 8); | |
431 if(ppp_data->ftx.accmtab[currentByte]) | |
432 { | |
433 temp_desc1->buffer[temp_desc1->len] = PPP_HDLC_ESCAPE; | |
434 temp_desc1->buffer[temp_desc1->len+1] = currentByte ^ 0x20; | |
435 temp_desc1->len += 2; | |
436 ptr_frame->list_len += 2; | |
437 } | |
438 else | |
439 { | |
440 temp_desc1->buffer[temp_desc1->len] = currentByte; | |
441 temp_desc1->len++; | |
442 ptr_frame->list_len++; | |
443 } | |
444 } | |
445 | |
446 #endif /* _SIMULATION_ */ | |
447 | |
448 /* | |
449 * insert HDLC-Flag - to mark the start of the frame | |
450 */ | |
451 temp_desc1->buffer[temp_desc1->len] = PPP_HDLC_FLAG; | |
452 temp_desc1->len++; | |
453 temp_desc1->size = temp_desc1->len; | |
454 ptr_frame->list_len++; | |
455 | |
456 | |
457 } /* ftx_get_frame() */ | |
458 #endif /* PPP_FLASH_ROM */ | |
459 | |
460 | |
461 | |
462 #ifndef PPP_INT_RAM | |
463 /* | |
464 +------------------------------------------------------------------------------ | |
465 | Function : ftx_check_frame | |
466 +------------------------------------------------------------------------------ | |
467 | Description : The function ftx_check_frame() checks for flag at begin and end | |
468 | of the frame and calculates length of frame. | |
469 | | |
470 | Parameters : ptr_frame - gives just a frame and returns a frame with length | |
471 | | |
472 +------------------------------------------------------------------------------ | |
473 */ | |
474 GLOBAL void ftx_check_frame (T_desc_list2* ptr_frame) | |
475 { | |
476 T_desc2* frame; | |
477 T_desc2* temp_desc; | |
478 UBYTE last_byte; | |
479 | |
480 TRACE_FUNCTION( "ftx_check_frame" ); | |
481 | |
482 frame = (T_desc2*)ptr_frame->first; | |
483 | |
484 while((frame) && (frame->len EQ 0)) | |
485 frame = (T_desc2*)frame->next; | |
486 | |
487 if(frame) | |
488 { | |
489 /* | |
490 * if the first character isnt the HDLC flag then | |
491 * create a new first data descriptor containing just the HDLC flag | |
492 */ | |
493 if(frame->buffer[0] NEQ PPP_HDLC_FLAG) | |
494 { | |
495 MALLOC (frame, (USHORT)(sizeof(T_desc2) - 1 + 1)); | |
496 frame->next = ptr_frame->first; | |
497 frame->len = 1; | |
498 frame->buffer[0] = PPP_HDLC_FLAG; | |
499 ptr_frame->first = (ULONG)frame; | |
500 } | |
501 /* | |
502 * search for the last character and if it isnt the HDLC flag then | |
503 * create a new last data descriptor containing just the HDLC flag. | |
504 * calculate length of whole data. | |
505 */ | |
506 ptr_frame->list_len = 0; | |
507 for(frame = (T_desc2*)ptr_frame->first; | |
508 frame; | |
509 frame = (T_desc2*)frame->next) | |
510 { | |
511 if(frame->len) | |
512 { | |
513 ptr_frame->list_len+= frame->len; | |
514 last_byte = frame->buffer[frame->len - 1]; | |
515 } | |
516 temp_desc = frame; | |
517 } | |
518 if(last_byte NEQ PPP_HDLC_FLAG) /*lint !e644 last_byte may not have been initialized */ | |
519 { | |
520 MALLOC (frame, (USHORT)(sizeof(T_desc2) - 1 + 1)); | |
521 frame->next = (ULONG)NULL; | |
522 frame->len = 1; | |
523 frame->buffer[0] = PPP_HDLC_FLAG; | |
524 temp_desc->next = (ULONG)frame; /*lint !e771 temp_desc conceivably not initialized */ | |
525 } | |
526 } | |
527 else | |
528 { | |
529 /* | |
530 * free the empty frame | |
531 */ | |
532 arb_discard_packet((T_desc2*)ptr_frame->first); | |
533 ptr_frame->first = (ULONG)NULL; | |
534 ptr_frame->list_len = 0; | |
535 } | |
536 } /* ftx_check_frame() */ | |
537 #endif /* PPP_INT_RAM */ |