Adding new commiter to ODU-High repo
[o-du/l2.git] / src / cm / cm_tkns.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18 \f
19 /********************************************************************20**
20   
21      Name:     general layer
22   
23      Type:     C file
24   
25      Desc:     Packing/Unpacking for structures, defined in cm_tkns.x
26    
27      File:     cm_tkns.c
28   
29 *********************************************************************21*/
30 \f
31 /* header include files (.h) */
32
33 #include "envopt.h"        /* environment options */
34 #include "envdep.h"        /* environment dependent */
35 #include "envind.h"        /* environment independent */
36
37 #include "gen.h"           /* general layer */
38 #include "ssi.h"           /* system services */
39 #include "cm_mblk.h"
40 #include "cm_tkns.h"       /* common tokens */
41
42 /* header/extern include files (.x) */
43
44 #include "gen.x"           /* general layer */
45 #include "ssi.x"           /* system services */
46 #include "cm_mblk.x"
47 #include "cm_tkns.x"       /* common tokens */
48
49 \f  
50
51 /*
52  *      PACKING FUNCTIONS
53  */
54
55 \f
56 /*
57  *
58  *      Fun:   cmPkTknS16
59  *
60  *      Desc:  This function unpacks a token S16
61  *
62  *      Ret:   ROK      - ok
63  *
64  *      Notes: None
65  *
66         File:  cm_tkns.c
67  *
68  */
69 S16 cmPkTknS16
70 (
71 TknS16 *tknS16,             /* token S16 */
72 Buffer *mBuf                /* message buffer */
73 )
74 {
75
76    if (tknS16->pres)
77    {
78       /* Value */
79       CMCHKPK(SPkS16, tknS16->val, mBuf);
80    }
81
82    /* Token Header */
83    CMCHKPK(oduUnpackUInt8, tknS16->pres, mBuf);
84
85    return ROK;
86 } /* end of cmPkTknS16 */
87   
88 \f
89 /*
90  *
91  *      Fun:   cmPkTknBStr32
92  *
93  *      Desc:  This function packs a token bit string of size 32
94  *
95  *      Ret:   ROK      - ok
96  *
97  *      Notes: None
98  *
99         File:  cm_tkns.c
100  *
101  */
102   
103 S16 cmPkTknBStr32
104 (
105 TknBStr32 *tknStr,             /* token string */
106 Buffer    *mBuf                /* message buffer */
107 )
108 {
109
110    CMPKTKNBSTR(tknStr, mBuf);
111
112    return ROK;
113
114 } /* end of cmPkTknBStr32 */
115
116 /*
117  *
118  *      Fun:   cmPkTknStr8
119  *
120  *      Desc:  This function packs a token string of size 8
121  *
122  *      Ret:   ROK      - ok
123  *
124  *      Notes: None
125  *
126         File:  cm_tkns.c
127  *
128  */
129   
130 S16 cmPkTknStr8
131 (
132 TknStr8 *tknStr,             /* token string */
133 Buffer  *mBuf                /* message buffer */
134 )
135 {
136
137    CMPKTKNSTR(tknStr, mBuf);
138
139    return ROK;
140
141 } /* end of cmPkTknStr8 */
142
143 \f
144 /*
145  *
146  *      Fun:   cmPkTknStr16
147  *
148  *      Desc:  This function packs a token string of size 16
149  *
150  *      Ret:   ROK      - ok
151  *
152  *      Notes: None
153  *
154         File:  cm_tkns.c
155  *
156  */
157   
158 S16 cmPkTknStr16
159 (
160 TknStr16 *tknStr,             /* token string */
161 Buffer   *mBuf                /* message buffer */
162 )
163 {
164
165    CMPKTKNSTR(tknStr, mBuf);
166
167    return ROK;
168
169 } /* end of cmPkTknStr16 */
170
171 \f
172 /*
173  *
174  *      Fun:   cmPkTknStrOSXL
175  *
176  *      Desc:  This function packs a Long Octet string
177  *
178  *      Ret:   ROK      - ok
179  *
180  *      Notes: None
181  *
182         File:  cm_tkns.c
183  *
184  */
185   
186 S16 cmPkTknStrOSXL
187 (
188 TknStrOSXL *tknStr,             /* token string */
189 Buffer     *mBuf                /* message buffer */
190 )
191 {
192    uint16_t ndx;
193
194
195    if(tknStr->pres)
196    {
197       /* Value */
198       for (ndx = 0; ndx < tknStr->len; ndx++)
199       {
200          CMCHKPK(oduUnpackUInt8, tknStr->val[ndx], mBuf);
201       }
202       /* Length */
203       CMCHKPK(oduUnpackUInt16, tknStr->len, mBuf);
204    }
205    /* Token Header */
206    CMCHKPK(oduUnpackUInt8, tknStr->pres, mBuf);
207
208    return ROK;
209
210 } /* end of cmPkTknStrOSXL */
211
212
213 \f
214 /*
215  *
216  *      Fun:   cmPkTknStrBSXL
217  *
218  *      Desc:  This function packs a Long bit string
219  *
220  *      Ret:   ROK      - ok
221  *
222  *      Notes: None
223  *
224         File:  cm_tkns.c
225  *
226  */
227   
228 S16 cmPkTknStrBSXL
229 (
230 TknStrBSXL *tknStr,             /* token string */
231 Buffer     *mBuf              /* message buffer */
232 )
233 {
234    uint16_t ndx;
235    uint16_t len;
236
237
238    if(tknStr->pres)
239    {
240       if (tknStr->len % 8)
241          len = (tknStr->len/8) + 1;
242       else
243          len = (tknStr->len/8);
244    
245       /* Value */
246       for (ndx = 0; ndx < len; ndx++)
247       {
248          CMCHKPK(oduUnpackUInt8, tknStr->val[ndx], mBuf);
249       }
250       /* Length */
251       CMCHKPK(oduUnpackUInt16, tknStr->len, mBuf);
252    }
253    /* Token Header */
254    CMCHKPK(oduUnpackUInt8, tknStr->pres, mBuf);
255
256    return ROK;
257
258 } /* end of cmPkTknStrBSXL */
259
260 \f  
261 /*
262  *
263  *      Fun:   cmPkTknStrBMP4
264  *
265  *      Desc:  This function packs a BMP token string of size 4
266  *
267  *      Ret:   ROK      - ok
268  *
269  *      Notes: None
270  *
271         File:  cm_tkns.c
272  *
273  */
274   
275 S16 cmPkTknStrBMP4
276 (
277 TknStrBMP4 *tknStr,             /* token string */
278 Buffer     *mBuf                /* message buffer */
279 )
280 {
281    uint8_t ndx;
282
283
284    if(tknStr->pres)
285    {
286       /* Value */
287       for (ndx = 0; ndx < tknStr->len; ndx++)
288       {
289          CMCHKPK(oduUnpackUInt16, tknStr->val[ndx], mBuf);
290       }
291
292       /* Length */
293       CMCHKPK(oduUnpackUInt8, tknStr->len, mBuf);
294    }
295
296    /* Token Header */
297    CMCHKPK(oduUnpackUInt8, tknStr->pres, mBuf);
298
299    return ROK;
300 } /* end of cmPkTknStrBMP4 */
301
302 \f
303 /*
304  *
305  *      Fun:   cmPkTknStrBMPXL
306  *
307  *      Desc:  This function packs a Long BMP Octet string
308  *
309  *      Ret:   ROK      - ok
310  *
311  *      Notes: None
312  *
313         File:  cm_tkns.c
314  *
315  */
316   
317 S16 cmPkTknStrBMPXL
318 (
319 TknStrBMPXL *tknStr,             /* token string */
320 Buffer     *mBuf                /* message buffer */
321 )
322 {
323    uint16_t ndx;
324
325
326    if(tknStr->pres)
327    {
328       /* Value */
329       for (ndx = 0; ndx < tknStr->len; ndx++)
330       {
331          CMCHKPK(oduUnpackUInt16, tknStr->val[ndx], mBuf);
332       }
333       /* Length */
334       CMCHKPK(oduUnpackUInt16, tknStr->len, mBuf);
335    }
336    /* Token Header */
337    CMCHKPK(oduUnpackUInt8, tknStr->pres, mBuf);
338
339    return ROK;
340 } /* end of cmPkTknStrBMPXL */
341
342 \f  
343 /*
344  *
345  *      Fun:   cmPkTknStrUNI4
346  *
347  *      Desc:  This function packs a UNI token string of size 4
348  *
349  *      Ret:   ROK      - ok
350  *
351  *      Notes: None
352  *
353         File:  cm_tkns.c
354  *
355  */
356   
357 S16 cmPkTknStrUNI4
358 (
359 TknStrUNI4 *tknStr,             /* token string */
360 Buffer     *mBuf                /* message buffer */
361 )
362 {
363    uint8_t ndx;
364
365
366    if(tknStr->pres)
367    {
368       /* Value */
369       for (ndx = 0; ndx < tknStr->len; ndx++)
370       {
371          CMCHKPK(oduUnpackUInt32, tknStr->val[ndx], mBuf);
372       }
373
374       /* Length */
375       CMCHKPK(oduUnpackUInt8, tknStr->len, mBuf);
376    }
377
378    /* Token Header */
379    CMCHKPK(oduUnpackUInt8, tknStr->pres, mBuf);
380
381    return ROK;
382 } /* end of cmPkTknStrUNI4 */
383
384 \f
385 /*
386  *
387  *      Fun:   cmPkTknStrUNIXL
388  *
389  *      Desc:  This function packs a Long UNI Octet string
390  *
391  *      Ret:   ROK      - ok
392  *
393  *      Notes: None
394  *
395         File:  cm_tkns.c
396  *
397  */
398   
399 S16 cmPkTknStrUNIXL
400 (
401 TknStrUNIXL *tknStr,             /* token string */
402 Buffer     *mBuf                /* message buffer */
403 )
404 {
405    uint16_t ndx;
406
407
408    if(tknStr->pres)
409    {
410       /* Value */
411       for (ndx = 0; ndx < tknStr->len; ndx++)
412       {
413          CMCHKPK(oduUnpackUInt32, tknStr->val[ndx], mBuf);
414       }
415       /* Length */
416       CMCHKPK(oduUnpackUInt16, tknStr->len, mBuf);
417    }
418    /* Token Header */
419    CMCHKPK(oduUnpackUInt8, tknStr->pres, mBuf);
420
421    return ROK;
422 } /* end of cmPkTknStrUNIXL */
423 \f
424 /*
425  *      UNPACKING FUNCTIONS
426  */
427
428 \f
429 /*
430  *
431  *      Fun:   cmUnpkTknS16
432  *
433  *      Desc:  This function unpacks a token S16
434  *
435  *      Ret:   ROK      - ok
436  *
437  *      Notes: None
438  *
439         File:  cm_tkns.c
440  *
441  */
442 S16 cmUnpkTknS16
443 (
444 TknS16 *tknS16,             /* token S16 */
445 Buffer *mBuf                /* message buffer */
446 )
447 {
448
449    /* Token Header */
450    CMCHKUNPK(oduPackUInt8, &tknS16->pres, mBuf);
451
452    if (tknS16->pres)
453    {
454       /* Value */
455       CMCHKUNPK(SUnpkS16, &tknS16->val, mBuf);
456    }
457
458    return ROK;
459 } /* end of cmUnpkTknS16 */
460   
461 \f
462 /*
463  *
464  *      Fun:   cmUnpkTknBStr32
465  *
466  *      Desc:  This function packs a token bit string of size 32
467  *
468  *      Ret:   ROK      - ok
469  *
470  *      Notes: None
471  *
472         File:  cm_tkns.c
473  *
474  */
475   
476 S16 cmUnpkTknBStr32
477 (
478 TknBStr32 *tknStr,             /* token string */
479 Buffer    *mBuf                /* message buffer */
480 )
481 {
482
483    CMUNPKTKNBSTR(tknStr, mBuf);
484
485    return ROK;
486
487 } /* end of cmUnpkTknBStr32 */
488
489 \f
490 /*
491  *
492  *      Fun:   cmUnpkTknStr8
493  *
494  *      Desc:  This function packs a token string of size 8
495  *
496  *      Ret:   ROK      - ok
497  *
498  *      Notes: None
499  *
500         File:  cm_tkns.c
501  *
502  */
503   
504 S16 cmUnpkTknStr8
505 (
506 TknStr8 *tknStr,             /* token string */
507 Buffer  *mBuf                /* message buffer */
508 )
509 {
510
511    CMUNPKTKNSTR(tknStr, mBuf);
512
513    return ROK;
514
515 } /* end of cmUnpkTknStr8 */
516
517 \f
518 /*
519  *
520  *      Fun:   cmUnpkTknStr16
521  *
522  *      Desc:  This function packs a token string of size 16
523  *
524  *      Ret:   ROK      - ok
525  *
526  *      Notes: None
527  *
528         File:  cm_tkns.c
529  *
530  */
531   
532 S16 cmUnpkTknStr16
533 (
534 TknStr16 *tknStr,             /* token string */
535 Buffer   *mBuf                /* message buffer */
536 )
537 {
538
539    CMUNPKTKNSTR(tknStr, mBuf);
540
541    return ROK;
542
543 } /* end of cmUnpkTknStr16 */
544
545 \f
546 /*
547  *
548  *      Fun:   cmUnpkTknStrOSXL
549  *
550  *      Desc:  This function packs a long octet token string
551  *
552  *      Ret:   ROK      - ok
553  *
554  *      Notes: None
555  *
556         File:  cm_tkns.c
557  *
558  */
559   
560 S16 cmUnpkTknStrOSXL
561 (
562 TknStrOSXL *tknStr,             /* token string */
563 Buffer     *mBuf,               /* message buffer */
564 Ptr         ptr                 /* pointer to memory control block */
565 )
566 {
567    uint16_t ndx;
568
569    CMCHKUNPK(oduPackUInt8, &tknStr->pres, mBuf);
570
571    if(tknStr->pres)
572    {
573       /* Length */
574       CMCHKUNPK(oduPackUInt16, &tknStr->len, mBuf);
575
576       if( cmGetMem(ptr, tknStr->len, (Ptr *)&tknStr->val) != ROK)
577       {
578          return RFAILED;
579       }
580       /* Value */
581       for (ndx = 1; ndx <= tknStr->len; ndx++)
582       {
583          CMCHKUNPK(oduPackUInt8, &tknStr->val[tknStr->len - ndx], mBuf);
584       }
585    }
586
587    return ROK;
588
589 } /* end of cmUnpkTknStrOSXL */
590
591
592 \f
593 /*
594  *
595  *      Fun:   cmUnpkTknStrBSXL
596  *
597  *      Desc:  This function packs a long bit token string
598  *
599  *      Ret:   ROK      - ok
600  *
601  *      Notes: None
602  *
603         File:  cm_tkns.c
604  *
605  */
606   
607 S16 cmUnpkTknStrBSXL
608 (
609 TknStrBSXL *tknStr,             /* token string */
610 Ptr         ptr,                /* pointer to memory control block */
611 Buffer     *mBuf                /* message buffer */
612 )
613 {
614    uint16_t ndx;
615    uint16_t len;
616
617
618    CMCHKUNPK(oduPackUInt8, &tknStr->pres, mBuf);
619
620    if(tknStr->pres)
621    {
622       /* Length */
623       CMCHKUNPK(oduPackUInt16, &tknStr->len, mBuf);
624
625       if (tknStr->len % 8)
626          len = (tknStr->len/8) + 1;
627       else
628          len = (tknStr->len/8);
629          
630       if( cmGetMem(ptr, len, (Ptr *)&tknStr->val) != ROK)
631       {
632          return RFAILED;
633       }
634       /* Value */
635       for (ndx = 1; ndx <= len; ndx++)
636       {
637          CMCHKUNPK(oduPackUInt8, &tknStr->val[len - ndx], mBuf);
638       }
639    }
640
641    return ROK;
642
643 } /* end of cmUnpkTknStrBSXL */
644
645 \f  
646 /*
647  *
648  *      Fun:   cmUnpkTknStrBMP4
649  *
650  *      Desc:  This function unpacks a BMP token string of size 4
651  *
652  *      Ret:   ROK      - ok
653  *
654  *      Notes: None
655  *
656         File:  cm_tkns.c
657  *
658  */
659   
660 S16 cmUnpkTknStrBMP4
661 (
662 TknStrBMP4 *tknStr,             /* token string */
663 Buffer     *mBuf                /* message buffer */
664 )
665 {
666    uint8_t ndx;
667
668
669    /* Token Header */
670    CMCHKUNPK(oduPackUInt8, &tknStr->pres, mBuf);
671
672    if(tknStr->pres)
673    {
674       /* Length */
675       CMCHKUNPK(oduPackUInt8, &tknStr->len, mBuf);
676
677       /* Value */
678       for (ndx = 1; ndx <= tknStr->len; ndx++)
679       {
680          CMCHKUNPK(oduPackUInt16, &tknStr->val[tknStr->len - ndx], mBuf);
681       }
682    }
683
684    return ROK;
685 } /* end of cmUnpkTknStrBMP4 */
686
687 \f
688 /*
689  *
690  *      Fun:   cmUnpkTknStrBMPXL
691  *
692  *      Desc:  This function packs a long octet token string
693  *
694  *      Ret:   ROK      - ok
695  *
696  *      Notes: None
697  *
698         File:  cm_tkns.c
699  *
700  */
701   
702 S16 cmUnpkTknStrBMPXL
703 (
704 TknStrBMPXL *tknStr,             /* token string */
705 Buffer      *mBuf,               /* message buffer */
706 Ptr          ptr                 /* pointer to memory control block */
707 )
708 {
709    uint16_t ndx;
710
711
712    CMCHKUNPK(oduPackUInt8, &tknStr->pres, mBuf);
713
714    if(tknStr->pres)
715    {
716       /* Length */
717       CMCHKUNPK(oduPackUInt16, &tknStr->len, mBuf);
718
719       /* Each BMP Character is 2 octet long */
720       if( cmGetMem(ptr, 2*(tknStr->len), (Ptr *)&tknStr->val) != ROK)
721       {
722          return RFAILED;
723       }
724       /* Value */
725       for (ndx = 1; ndx <= tknStr->len; ndx++)
726       {
727          CMCHKUNPK(oduPackUInt16, &tknStr->val[tknStr->len - ndx], mBuf);
728       }
729    }
730
731    return ROK;
732
733 } /* end of cmUnpkTknStrBMPXL */
734
735 \f  
736 /*
737  *
738  *      Fun:   cmUnpkTknStrUNI4
739  *
740  *      Desc:  This function unpacks a UNI token string of size 4
741  *
742  *      Ret:   ROK      - ok
743  *
744  *      Notes: None
745  *
746         File:  cm_tkns.c
747  *
748  */
749   
750 S16 cmUnpkTknStrUNI4
751 (
752 TknStrUNI4 *tknStr,             /* token string */
753 Buffer     *mBuf                /* message buffer */
754 )
755 {
756    uint8_t ndx;
757
758
759    /* Token Header */
760    CMCHKUNPK(oduPackUInt8, &tknStr->pres, mBuf);
761
762    if(tknStr->pres)
763    {
764       /* Length */
765       CMCHKUNPK(oduPackUInt8, &tknStr->len, mBuf);
766
767       /* Value */
768       for (ndx = 1; ndx <= tknStr->len; ndx++)
769       {
770          CMCHKUNPK(oduPackUInt32, &tknStr->val[tknStr->len - ndx], mBuf);
771       }
772    }
773
774    return ROK;
775 } /* end of cmUnpkTknStrUNI4 */
776
777 \f
778 /*
779  *
780  *      Fun:   cmUnpkTknStrUNIXL
781  *
782  *      Desc:  This function packs a long octet token string
783  *
784  *      Ret:   ROK      - ok
785  *
786  *      Notes: None
787  *
788         File:  cm_tkns.c
789  *
790  */
791   
792 S16 cmUnpkTknStrUNIXL
793 (
794 TknStrUNIXL *tknStr,             /* token string */
795 Buffer      *mBuf,               /* message buffer */
796 Ptr          ptr                 /* pointer to memory control block */
797 )
798 {
799    uint16_t ndx;
800
801
802    CMCHKUNPK(oduPackUInt8, &tknStr->pres, mBuf);
803
804    if(tknStr->pres)
805    {
806       /* Length */
807       CMCHKUNPK(oduPackUInt16, &tknStr->len, mBuf);
808
809       /* Each UNI Character is 4 octets long */
810       if( cmGetMem(ptr, 4*tknStr->len, (Ptr *)&tknStr->val) != ROK)
811       {
812          return RFAILED;
813       }
814       /* Value */
815       for (ndx = 1; ndx <= tknStr->len; ndx++)
816       {
817          CMCHKUNPK(oduPackUInt32, &tknStr->val[tknStr->len - ndx], mBuf);
818       }
819    }
820
821    return ROK;
822
823 } /* end of cmUnpkTknStrUNIXL */
824
825 /**********************************************************************
826          End of file
827 **********************************************************************/