comparison g23m-aci/aci/ati_prs.c @ 0:75a11d740a02

initial import of gsm-fw from freecalypso-sw rev 1033:5ab737ac3ad7
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 Jun 2016 00:02:41 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:75a11d740a02
1 /*
2 +-----------------------------------------------------------------------------
3 | Project : GSM-F&D (8411)
4 | Modul : ATI
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 : AT Command parameter parser
18 +-----------------------------------------------------------------------------
19 */
20
21 #ifndef ATI_PRS_C
22 #define ATI_PRS_C
23
24 #include "config.h"
25 #include "fixedconf.h"
26 #include "condat-features.h"
27 #include "aci_conf.h"
28
29 #include "aci_all.h"
30
31 #include <stdio.h>
32 #include <stdarg.h>
33 #include <ctype.h>
34
35 #include "aci_cmh.h"
36 #include "ati_cmd.h"
37 #include "aci_cmd.h"
38 #include "aci_prs.h"
39
40 #ifdef GPRS
41 #include "gaci_cmh.h"
42 #endif /* GPRS */
43
44 #include "aci_lst.h"
45 #include "ati_int.h"
46
47 #ifdef OPTION_RELATIVE
48 LOCAL ULONG offset;
49 #endif
50
51 static UBYTE parse_index = 0;
52 /*
53 +--------------------------------------------------------------------+
54 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
55 | STATE : code ROUTINE : parseBin |
56 +--------------------------------------------------------------------+
57
58 PURPOSE : parse binary value
59
60 */
61
62 GLOBAL char *parseBin (int digits, char *b, SHORT *i)
63 {
64 int found = 0;
65
66 *i = 0;
67 while (digits-- AND *b >= '0' AND *b <= '1')
68 {
69 found++;
70 *i *= 2;
71 *i += *b - '0';
72 b++;
73 }
74
75 return ((found) ? b : 0);
76 }
77
78
79 /*
80 +--------------------------------------------------------------------+
81 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
82 | STATE : code ROUTINE : parseHex |
83 +--------------------------------------------------------------------+
84
85 PURPOSE : parse hexadecimal value
86
87 */
88
89 GLOBAL char *parseHex (int digits, char *b, UBYTE *i)
90 {
91 int found = 0;
92
93 *i = 0;
94 while (digits-- AND ((*b >= '0' AND *b <= '9') OR
95 (*b >= 'a' AND *b <= 'f') OR
96 (*b >= 'A' AND *b <= 'F')))
97 {
98 found++;
99 *i *= 16;
100 if (*b >= '0' AND *b <= '9')
101 *i += *b - '0';
102 if (*b >= 'a' AND *b <= 'f')
103 *i += *b - 'a' + 10;
104 if (*b >= 'A' AND *b <= 'F')
105 *i += *b - 'A' + 10;
106 b++;
107 }
108
109 return ((found AND found <= 2) ? b : 0);
110 }
111
112 /*
113 +--------------------------------------------------------------------+
114 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
115 | STATE : code ROUTINE : parseHexToLong |
116 +--------------------------------------------------------------------+
117
118 PURPOSE : parse hexadecimal value
119
120 */
121
122 GLOBAL char *parseHexToLong (int digits, char *b, LONG *i)
123 {
124 *i = 0;
125 while (digits-- AND ((*b >= '0' AND *b <= '9') OR
126 (*b >= 'a' AND *b <= 'f') OR
127 (*b >= 'A' AND *b <= 'F')))
128 {
129 *i *= 16;
130 if (*b >= '0' AND *b <= '9')
131 *i += *b - '0';
132 if (*b >= 'a' AND *b <= 'f')
133 *i += *b - 'a' + 10;
134 if (*b >= 'A' AND *b <= 'F')
135 *i += *b - 'A' + 10;
136 b++;
137 }
138
139 return ( digits EQ 0 ? 0 : b );
140 }
141
142 /*
143 +--------------------------------------------------------------------+
144 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
145 | STATE : code ROUTINE : parseEnum |
146 +--------------------------------------------------------------------+
147
148 PURPOSE : parse enum value
149
150 */
151
152 GLOBAL char *parseEnum (int digits, char *b, int *i)
153 {
154 int found = 0;
155
156 *i = 0;
157 while (digits-- AND *b >= '0' AND *b <= '9')
158 {
159 found++;
160 *i *= 10;
161 *i += *b - '0';
162 b++;
163 }
164
165 return ((found) ? b : 0);
166 }
167
168 /*
169 +--------------------------------------------------------------------+
170 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
171 | STATE : code ROUTINE : parseShort |
172 +--------------------------------------------------------------------+
173
174 PURPOSE : parse Short value
175
176 */
177
178 GLOBAL char *parseShort (int digits, char *b, SHORT *i)
179 {
180 int found = 0;
181
182 *i = 0;
183 while (digits-- AND *b >= '0' AND *b <= '9')
184 {
185 found++;
186 *i *= 10;
187 *i += *b - '0';
188 b++;
189 }
190
191 return ((found) ? b : 0);
192 }
193
194 /*
195 +--------------------------------------------------------------------+
196 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
197 | STATE : code ROUTINE : parseStr |
198 +--------------------------------------------------------------------+
199
200 PURPOSE : parse string value
201
202 */
203
204 GLOBAL char *parseStr (int digits, char *b, char *s)
205 {
206 int found = 0;
207
208 *s = 0;
209 if (*b NEQ '"')
210 return 0;
211 b++;
212 while (digits-- AND *b AND *b >= 0x20)
213 {
214 found++;
215 if (*b EQ '"')
216 {
217 *s = 0;
218 b++;
219 break;
220 }
221 if (*b EQ '\\')
222 {
223 b = parseHex(2,b+1,(UBYTE *) s); /* ES!! ZERO ? */
224 if (!b)
225 return 0;
226 s++;
227 }
228 else
229 *s++ = *b++;
230 }
231 if(*(b-1) NEQ '"')
232 return 0;
233 *s = 0; /* zero terminated */
234
235 return ((found) ? b : 0);
236 }
237
238 /*
239 +--------------------------------------------------------------------+
240 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
241 | STATE : code ROUTINE : parseZStr |
242 +--------------------------------------------------------------------+
243
244 PURPOSE : parse string value
245
246 */
247
248 GLOBAL char *parseZStr (int digits, char *b, char *s)
249 {
250 int found = 0;
251
252 *s = 0;
253 if (*b NEQ '"')
254 return 0;
255 b++;
256 while (digits--)
257 {
258 found++;
259 if (*b EQ '"')
260 {
261 *s = 0;
262 b++;
263 break;
264 }
265 if (*b EQ '\\')
266 {
267 b = parseHex(2,b+1,(UBYTE *) s); /* ES!! ZERO ? */
268 if (!b)
269 return 0;
270 s++;
271 }
272 else
273 *s++ = *b++;
274 }
275 if(*(b-1) NEQ '"')
276 return 0;
277 *s = 0; /* zero terminated */
278
279 return ((found) ? b : 0);
280 }
281
282 /*
283 +--------------------------------------------------------------------+
284 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
285 | STATE : code ROUTINE : parseNStr |
286 +--------------------------------------------------------------------+
287
288 PURPOSE : parse string value and if not numeric returns error
289
290 */
291
292 GLOBAL char *parseNStr (int digits, char *b, char *s)
293 {
294 int found = 0;
295
296 *s = 0;
297 if (*b NEQ '"')
298 return 0;
299 b++;
300 while (digits-- AND *b AND *b >= 0x20)
301 {
302 found++;
303 if (*b EQ '"')
304 {
305 *s = 0;
306 b++;
307 break;
308 }
309 if (*b EQ '\\')
310 {
311 b = parseHex(2,b+1,(UBYTE *) s); /* ES!! ZERO ? */
312 if (!b)
313 return 0;
314 s++;
315 }
316 if ( *b > '9' OR *b < '0')
317 return 0; /*check if numeric value*/
318 else
319 *s++ = *b++;
320 }
321 if(*(b-1) NEQ '"')
322 return 0;
323 *s = 0; /* zero terminated */
324
325 return ((found) ? b : 0);
326 }
327
328 /*
329 +--------------------------------------------------------------------+
330 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
331 | STATE : code ROUTINE : parseASCII |
332 +--------------------------------------------------------------------+
333
334 PURPOSE : parse ASCII value
335
336 */
337
338 GLOBAL char *parseASCII (int digits, char *b, char *i)
339 {
340 int found = 0;
341
342 *i = 0;
343 while (digits-- AND *b NEQ ' ' AND *b NEQ ',' AND *b NEQ ';' )
344 {
345 found++;
346 *i = *b;
347 i++;
348 b++;
349 }
350
351 return ((found) ? b : 0);
352 }
353
354 /*
355 +--------------------------------------------------------------------+
356 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
357 | STATE : code ROUTINE : parseQASCII |
358 +--------------------------------------------------------------------+
359
360 PURPOSE : parse ASCII value and terminate with 0
361
362 */
363
364 GLOBAL char *parseQASCII (int digits, char *b, char *i)
365 {
366 int found = 0;
367
368 *i = 0;
369 while (digits-- AND *b NEQ ',' AND *b NEQ ';' AND *b NEQ '\0')
370 {
371 found++;
372 *i = *b;
373 i++;
374 b++;
375 }
376
377 if (found)
378 {
379 *i = 0;
380 return (b);
381 }
382
383 return (NULL);
384 }
385
386
387 /*
388 +--------------------------------------------------------------------+
389 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
390 | STATE : code ROUTINE : parseStrLen |
391 +--------------------------------------------------------------------+
392
393 PURPOSE : parse sting, return length and startpoint
394
395 */
396
397 GLOBAL char *parseStrLen (USHORT *len, char *b, char **p)
398 {
399 *len = 0;
400 if( *b EQ '"' )
401 b++;
402
403 /* Check if the string is a null string like "" */
404 if( *b EQ '"' )
405 {
406 b++;
407
408 /* return new buffer position without setting p, thereby omitting the parameter */
409 return b;
410 }
411
412 *p = b;
413
414 while ( *b NEQ '\0' AND *b NEQ ',' AND *b NEQ ';' AND *b NEQ '"' )
415 {
416 (*len)++;
417 b++;
418 }
419
420 if(*b EQ '"')
421 {
422 b++;
423 }
424
425 return ((*len) ? b : 0);
426 }
427
428
429 #ifdef GPRS
430
431 /*
432 +--------------------------------------------------------------------+
433 | PROJECT : UMTS MODULE : ACI_PRS |
434 | STATE : devellopment ROUTINE : parseExpo |
435 +--------------------------------------------------------------------+
436
437 PURPOSE : parse exponential expresion (ex. 2E3)
438
439 */
440
441 GLOBAL char *parseExpo( int digits, char *b, T_PS_ber *e )
442 {
443 BOOL valid = FALSE;
444
445 e->ratio_mant = 0;
446 e->ratio_exp = 0;
447 if( *b EQ '"' ) /* start of string */
448 {
449 b++;
450 while( digits-- AND *b >= '0' AND *b <= '9' )
451 {
452 e->ratio_mant *= 10;
453 e->ratio_mant += *b - '0';
454 b++;
455 }
456 if( *b EQ 'E' )
457 {
458 b++;
459 while( digits-- AND *b >= '0' AND *b <= '9' )
460 {
461 e->ratio_exp *= 10;
462 e->ratio_exp += *b - '0';
463 b++;
464 valid = TRUE;
465 }
466
467 if( *b EQ '"' ) /* end of string */
468 {
469 b++;
470 }
471 else
472 {
473 valid = FALSE;
474 }
475
476 }
477 else
478 {
479 valid = FALSE;
480 }
481 }
482 else
483 {
484 valid = FALSE;
485 }
486
487 return ((valid) ? b : 0);
488
489 } /* END parseExpo(...) */
490
491 /*
492 +--------------------------------------------------------------------+
493 | PROJECT : UMTS MODULE : ACI_PRS |
494 | STATE : Finished ROUTINE : parseCid_list |
495 +--------------------------------------------------------------------+
496
497 PURPOSE : Parse a list of Cids. If the parsing is sucessfull the
498 number of parsed cids is returned otherwise -1 is returned.
499
500 */
501 GLOBAL char *parseCid_list(char *b, U8 *cid_list_length, U8 *cid_list)
502 {
503 U8 no_of_cids;
504 char *end;
505
506 /* Parse all cids into the cid_list */
507 no_of_cids = 0;
508 do
509 {
510
511 /* If it's not the first cid remove the "," */
512 if( no_of_cids )
513 b++;
514
515 /* Set the entry to omitted. */
516 cid_list[no_of_cids] = PDP_CONTEXT_CID_OMITTED;
517
518 /* Parse the value */
519 cid_list[no_of_cids] = (U8) strtol( b, &end, 10 );
520 b = end;
521
522 /* If a cid is omitted no cids must be specified at all. */
523 if( cid_list[no_of_cids] EQ PDP_CONTEXT_CID_OMITTED )
524 {
525 if( no_of_cids NEQ 0 )
526 {
527 /* Don't accept omitted cids inside if it's not the first (ex. 1,,2,3 is not allowed). */
528 cmdCmeError( CME_ERR_OpNotSupp );
529 return( NULL );
530 }
531 /* Break the while */
532 break;
533 }
534 if( (!b) OR
535 (cid_list[no_of_cids] < PDP_CONTEXT_CID_MIN) OR
536 (cid_list[no_of_cids] > PDP_CONTEXT_CID_MAX) OR
537 (no_of_cids >= PDP_CONTEXT_CID_MAX) )
538 {
539 cmdCmeError( CME_ERR_OpNotSupp );
540 return( NULL );
541 }
542 no_of_cids++;
543 }
544
545 while( *b EQ ',' AND
546 no_of_cids < *cid_list_length );
547
548 cid_list[no_of_cids+1] = PDP_CONTEXT_CID_INVALID;
549
550 *cid_list_length = no_of_cids;
551 return( b );
552
553 }
554
555 #endif /* GPRS */
556
557 /*
558 +----------------------------------------------------------------------+
559 | PROJECT : UMTS MODULE : ATI_PRS |
560 | STATE : - ROUTINE : parsePointerToString |
561 -----------------------------------------------------------------------+
562
563 PURPOSE : Parse pointer to input string. returns pointer to end of string.
564
565 */
566 GLOBAL char *parsePointerToString(char chars, char *b, char **p_begin)
567 {
568 if( b AND *b EQ '"' )
569 {
570 b++;
571 *p_begin = b;
572
573 while (chars-- AND *b AND *b NEQ '"')
574 {
575 b++;
576 }
577 if( *b EQ '"' )
578 {
579 b++;
580 }
581 else
582 {
583 if( !chars )
584 {
585 b = NULL;
586 }
587 }
588 }
589
590 return b;
591 }
592
593 /*
594 +----------------------------------------------------------------------+
595 | PROJECT : UMTS MODULE : ATI_PRS |
596 | STATE : - ROUTINE : StrToU16 |
597 -----------------------------------------------------------------------+
598
599 PURPOSE : Parse string value to U16.
600
601 */
602
603 char *StrToU16(char *p_str, U16 *p_result)
604 {
605 U32 val = 0;
606
607 if( p_str )
608 {
609 if( *p_str >= '0' AND *p_str <= '9' )
610 {
611 while( *p_str >= '0' AND *p_str <= '9' )
612 {
613 val *= 10;
614 val += (int)(*p_str - '0');
615 p_str++;
616 }
617 }
618 }
619
620 if( val <= 0xffff ) /* 0xffff = max value of U16 */
621 *p_result = (U16)(val);
622 else
623 p_str = NULL;
624
625 return p_str;
626
627 }
628
629 /*
630 +---------------------------------------------------------------------+
631 | PROJECT : UMTS MODULE : ATI_PRS |
632 | STATE : - ROUTINE : parseDSNP_U16 |
633 ----------------------------------------------------------------------+
634
635 PURPOSE : parse dot-separated numeric parameters from the
636 input string to an array of U8.
637
638 ex. input p_in = "192.124.13.3"
639 output p_out = {192,124,13,3}
640
641 */
642 GLOBAL char *parseDSNP_U16( char blocks, char *p_in, U16 *p_out )
643 {
644 if( p_in AND p_out )
645 {
646 if( *p_in EQ '.' ) p_in++;
647 while( blocks-- AND *p_in NEQ 0x00 )
648 {
649 p_in = StrToU16(p_in, p_out);
650
651 if( p_in AND blocks AND *p_in EQ '.' )
652 {
653 p_in++;
654 p_out++;
655 }
656 else
657 break;
658 }
659 }
660 return p_in;
661 }
662
663 /*
664 +---------------------------------------------------------------------+
665 | PROJECT : UMTS MODULE : ATI_PRS |
666 | STATE : - ROUTINE : parseIPv4Address |
667 ----------------------------------------------------------------------+
668 */
669 GLOBAL char *parseIPv4Address(char *p_in, U8 * p_ip_addr, U8 * is_ip_valid)
670 {
671 U16 ip_addr[4];
672 char i;
673 char *p_out = NULL;
674
675 if( p_in AND p_ip_addr )
676 {
677 p_out = parseDSNP_U16(4, p_in, ip_addr);
678 for(i=0; i<4; i++)
679 {
680 if(ip_addr[i] <= 255)
681 {
682 p_ip_addr[i] = (U8) ip_addr[i];
683 }
684 else
685 {
686 p_out = NULL;
687 }
688
689 }
690 }
691 * is_ip_valid = (p_out NEQ NULL);
692
693 return p_out;
694 }
695
696 /*
697 +---------------------------------------------------------------------+
698 | PROJECT : UMTS MODULE : ATI_PRS |
699 | STATE : - ROUTINE : parseIPv6Address |
700 ----------------------------------------------------------------------+
701 */
702 GLOBAL char *parseIPv6Address(char *p_in, U8 *p_ip_addr, U8 * is_ip_valid)
703 {
704 U16 ip_addr[16];
705 char i;
706 char *p_out = NULL;
707
708 if( p_in AND p_ip_addr )
709 {
710 p_out = parseDSNP_U16(16, p_in, ip_addr);
711 for(i=0; i<16; i++)
712 {
713 if(ip_addr[i] > 255)
714 p_out = NULL;
715 else
716 p_ip_addr[i] = (U8) ip_addr[i];
717 }
718 }
719
720 * is_ip_valid = (p_out NEQ NULL);
721
722 return p_out;
723 }
724
725 /*
726 +--------------------------------------------------------------------+
727 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
728 | STATE : code ROUTINE : parse |
729 +--------------------------------------------------------------------+
730
731 PURPOSE : parse AT command parameter
732
733 */
734
735 GLOBAL char *parse (char *b, char *f, ...)
736 {
737 char fc;
738 USHORT *i;
739
740 #ifdef GPRS
741 U8 *j;
742 #endif /* GPRS */
743 LONG digits = -1;
744 BOOL value_is_valid;
745 /*lint -e516 -e10*/
746 va_list varpars;
747
748 va_start (varpars, f); /* Initialize variable arguments. */
749
750 parse_index=0;
751 while ((fc = *f++) NEQ 0)
752 {
753 parse_index++; /* Save the position of current parsing item */
754 value_is_valid = TRUE;
755 if (islower(fc))
756 {
757 if (*b EQ 0 OR *b EQ ';')
758 {
759 va_end (varpars); /* Reset variable arguments. */
760 return b;
761 }
762 if (*b EQ ',')
763 {
764 b++;
765 value_is_valid = FALSE;
766 }
767 }
768
769 switch (toupper(fc))
770 {
771 case 'B':
772 if (value_is_valid)
773 b = parseBin(-1,b,va_arg (varpars, short*));
774 else
775 (void)va_arg (varpars, short*);
776 break;
777
778 case 'X':
779 if (value_is_valid)
780 b = parseHex(-1,b,va_arg (varpars, unsigned char*));
781 else
782 (void)va_arg (varpars, short*);
783 break;
784
785 case 'Y':
786 if (value_is_valid)
787 b = parseHexToLong(-1,b,va_arg (varpars, long*));
788 else
789 (void)va_arg (varpars, short*);
790 break;
791
792 case 'D':
793 if (value_is_valid)
794 b = parseEnum(-1,b,va_arg (varpars, int*));
795 else
796 (void)va_arg (varpars, int*);
797 break;
798
799 case 'R':
800 if (value_is_valid)
801 b = parseShort(-1,b,va_arg (varpars, short*));
802 else
803 (void)va_arg (varpars, short*);
804 break;
805
806 case 'S':
807 if (value_is_valid)
808 {
809 digits=va_arg (varpars, long);
810 b = parseStr(digits,b,va_arg (varpars, char*));
811 }
812 else
813 {
814 (void)va_arg (varpars, long);
815 (void)va_arg (varpars, char*);
816 }
817 break;
818
819 case 'N':
820 if (value_is_valid)
821 {
822 digits=va_arg (varpars, long);
823 b = parseNStr(digits,b,va_arg (varpars, char*));
824 }
825 else
826 {
827 (void)va_arg (varpars, long);
828 (void)va_arg (varpars, char*);
829 }
830 break;
831
832 case 'Z':
833 if (value_is_valid)
834 {
835 char* c = b;
836 USHORT* plen = NULL;
837
838 char* cmdPtr;
839 USHORT cmdLen;
840
841 digits = va_arg ( varpars, long );
842 cmdLen = va_arg ( varpars, unsigned );
843 cmdPtr = va_arg ( varpars, char* );
844 plen = va_arg ( varpars, unsigned short*);
845 b = parseZStr
846 ( MINIMUM (digits, cmdLen - ( b - cmdPtr )),
847 b, va_arg ( varpars, char* ) );
848
849 if ( plen NEQ NULL )
850 {
851 if ( b NEQ NULL )
852 *plen = b - c - 2; /* a string always includes two characters '"' */
853 else
854 *plen = 0;
855 }
856 }
857 else
858 {
859 (void)va_arg (varpars, long);
860 (void)va_arg (varpars, unsigned short*);
861 (void)va_arg (varpars, char*);
862 }
863 break;
864
865 case 'A':
866 if (value_is_valid)
867 {
868 digits=va_arg (varpars, long);
869 b = parseASCII(digits,b,va_arg (varpars, char*));
870 }
871 else
872 {
873 (void)va_arg (varpars, long);
874 (void)va_arg (varpars, char*);
875 }
876 break;
877
878 case 'Q':
879 if (value_is_valid)
880 {
881 digits=va_arg (varpars, long);
882 b = parseQASCII(digits,b,va_arg (varpars, char*));
883 }
884 else
885 {
886 (void)va_arg (varpars, long);
887 (void)va_arg (varpars, char*);
888 }
889 break;
890
891 case 'L':
892 if (value_is_valid)
893 {
894 i = va_arg(varpars, unsigned short*);
895 b = parseStrLen (i,b,va_arg(varpars, char**));
896 }
897 else
898 {
899 (void)va_arg (varpars, int*);
900 (void)va_arg (varpars, char**);
901 }
902 break;
903
904 #ifdef GPRS
905
906 case 'E':
907 if (value_is_valid)
908 {/*lint -e78 -e26 -e530*/
909 b = parseExpo( -1, b, va_arg(varpars, T_PS_ber*));
910 }
911 else
912 {
913 (void)va_arg (varpars, T_PS_ber*);
914 }
915 break;
916
917 #endif
918
919 case 'C':
920 if (value_is_valid)
921 {
922 b = parseByte( -1, b, va_arg(varpars, unsigned char*));
923 }
924 else
925 {
926 (void)va_arg (varpars, unsigned char*);
927 }
928 break;
929
930 #ifdef GPRS
931
932 case 'I': /* Parse cid_list */
933 if( value_is_valid )
934 {
935 j = va_arg(varpars, unsigned char*);
936
937 b = parseCid_list( b, j, va_arg(varpars, unsigned char*) );
938 }
939 break;
940 #endif /* GPRS */
941
942 case 'P': /* Parse pointer to string */
943 if( value_is_valid )
944 {
945 b = parsePointerToString( (char)-1, b, va_arg(varpars, char**) );
946 }
947 break;
948
949 case '*': /* Parse '*' */
950 if( value_is_valid )
951 {
952 if( *b NEQ '*' )
953 {
954 return 0;
955 }
956 b++;
957 }
958 break;
959
960 case '#': /* Parse '#' */
961 if( value_is_valid )
962 {
963 if( *b NEQ '#' )
964 {
965 return 0;
966 }
967 b++;
968 }
969 break;
970 }
971 if (!b)
972 {
973 va_end (varpars); /* Reset variable arguments. */
974 return 0;
975 }
976
977 if (*f AND *b EQ ',' AND value_is_valid)
978 {
979 b++;
980 }
981 else if (*b AND *b NEQ ';' AND *b NEQ ',' AND value_is_valid) /* if comma or semicolon is missing */
982 {
983 TRACE_EVENT ("missing separator detected, aborting parse!");
984 va_end (varpars);
985 return 0;
986 }
987 }
988 if (*b AND *b NEQ ';')
989 {
990 va_end (varpars); /* Reset variable arguments. */
991 return 0;
992 }
993 va_end (varpars); /* Reset variable arguments. */
994 /*lint +e516 +e10*/
995 return b;
996 }
997
998
999 /*
1000 +--------------------------------------------------------------------+
1001 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
1002 | STATE : code ROUTINE : parse |
1003 +--------------------------------------------------------------------+
1004
1005 PURPOSE : get last parsed index (to determinate which component was malicious)
1006
1007 */
1008
1009 GLOBAL UBYTE get_parse_index ()
1010 {
1011 return parse_index;
1012 }
1013
1014 /*
1015 +--------------------------------------------------------------------+
1016 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
1017 | STATE : code ROUTINE : parseByte(U8) |
1018 +--------------------------------------------------------------------+
1019
1020 PURPOSE : parse U8 value
1021
1022 */
1023
1024 GLOBAL char *parseByte (int digits, char *b, U8 *i)
1025 {
1026 int found = 0;
1027
1028 *i = 0;
1029 while (digits-- AND *b >= '0' AND *b <= '9')
1030 {
1031 found++;
1032 *i *= 10;
1033 *i += *b - '0';
1034 b++;
1035 }
1036
1037 return ((found) ? b : 0);
1038 }
1039
1040 /*
1041 +--------------------------------------------------------------------+
1042 | PROJECT : GSM-F&D (8411) MODULE : ACI_PRS |
1043 | STATE : code ROUTINE : parseTimeStamp |
1044 +--------------------------------------------------------------------+
1045
1046 PURPOSE : Parse time stamp format in "yy/MM/dd,hh:mm:ss±zz"
1047
1048 */
1049
1050 GLOBAL UBYTE parseTimeStamp( char *p_in,U8 *years,U8 *months,U8 *days,
1051 U8 *hrs, U8 *mins,U8 *secs, char *sign, U8 *time_zone )
1052 {
1053 if( p_in[2] NEQ '/' OR p_in[5] NEQ '/' OR p_in[8] NEQ ',' OR p_in[11] NEQ ':' OR p_in[14] NEQ ':' )
1054 {
1055 return NO_TIME_STAMP_FIELD;
1056 }
1057 if(!parseByte (2, &p_in[0], years))
1058 {
1059 return NO_TIME_STAMP_FIELD;
1060 }
1061 if(!parseByte (2, &p_in[3], months))
1062 {
1063 return NO_TIME_STAMP_FIELD;
1064 }
1065 if(!parseByte (2, &p_in[6], days))
1066 {
1067 return NO_TIME_STAMP_FIELD;
1068 }
1069 if(!parseByte (2, &p_in[9], hrs))
1070 {
1071 return NO_TIME_STAMP_FIELD;
1072 }
1073 if(!parseByte (2, &p_in[12], mins))
1074 {
1075 return NO_TIME_STAMP_FIELD;
1076 }
1077 if(!parseByte (2, &p_in[15], secs))
1078 {
1079 return NO_TIME_STAMP_FIELD;
1080 }
1081 *sign = p_in[17];
1082
1083 if(*sign NEQ '+' AND *sign NEQ '-' )
1084 {
1085 return NO_TIME_STAMP_FIELD;
1086 }
1087 if(!parseByte (2, &p_in[18], time_zone))
1088 {
1089 return NO_TIME_STAMP_FIELD;
1090 }
1091
1092 return MAX_TIME_STAMP_FIELDS;
1093 }
1094
1095 #endif /* ATI_PRS_C */