Memory handling fixes
[o-du/l2.git] / src / cm / cm_tpt.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:     HCT Interface
22   
23      Type:     C file
24   
25      Desc:     This file contains the packing/unpacking functions
26                for the H.225 primitives on hct interface
27
28      File:     cm_tpt.c
29
30 *********************************************************************21*/
31 \f
32 /* header include files (.h) */
33
34 #include "envopt.h"        /* environment options */  
35 #include "envdep.h"        /* environment dependent */
36 #include "envind.h"        /* environment independent */
37
38 #include "gen.h"           /* general layer */
39 #include "ssi.h"           /* system service interface */
40
41 #include "cm_tpt.h"
42
43 /* header/extern include files (.x) */
44
45 #include "gen.x"           /* general layer */
46 #include "ssi.x"           /* system service interface */
47
48 /*#include "cm_tkns.x"*/
49 #include "cm_tpt.x"
50
51 \f
52 /* local defines */
53
54 /* local typedefs */
55
56 /* local externs */
57   
58 /* forward references */
59
60 /* local function definition */
61
62 /* functions in other modules */
63
64 /* public variable declarations */
65
66 /* control variables for testing */
67
68 /* private variable declarations */
69
70 /*
71  * support functions
72  */
73
74 /*  cm_tpt_c_001.main_17 - Guarded under LCEGT and LCLEG */
75 /*  cm_tpt_c_001.main_18 - Guarded under LWLCEGT */
76 \f
77 #if    (   defined(LCHCT) || defined (LWLCHCT) || defined(LCHIT) \
78         || defined(LCLHC) || defined(TRIL_HZ) \
79         || defined(LCHRT) || defined(LCLHR)   \
80         || defined(LCLMG) || defined(LCMGT)   \
81         || defined(LCLHG) || defined(LCHGT)   \
82         || defined(LCSCT) || defined(LCLSB)   \
83         || defined(LCLNT) || defined(LCLLN)   \
84         || defined(LCLSO) || defined(LCSOT)   \
85         || defined(LCEGT) || defined(LCLEG)   || defined(LWLCEGT) \
86         || defined(CM_COMPRESS)   \
87        )
88
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
92    /* Add prototypes here  (MB) */
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 \f  
99
100 /*
101  *      PACKING FUNCTIONS
102  */
103 /* Moving IPv4 address packing functions from cm_inet.c */
104 /*
105 *
106 *       Fun:   cmPkCmIpv4TptAddr
107 *
108 *       Desc:  This function packs the IPv4 address 
109 *
110 *       Ret:   ROK
111 *
112 *       Notes: None
113 *
114 *       File:  cm_tpt.c
115 *
116 */
117 S16 cmPkCmIpv4TptAddr
118 (
119 CmIpv4TptAddr            *pkParam,  /* IPv4 Address structure */
120 Buffer                   *mBuf      /* message buffer */
121 )
122 {
123
124    CMCHKPK(cmPkCmIpv4NetAddr, pkParam->address, mBuf);
125    CMCHKPK(oduUnpackUInt16, pkParam->port, mBuf);
126
127    return ROK;
128 } /* cmPkCmIpv4TptAddr */
129
130 /*
131 *
132 *       Fun:   cmPkCmIpv6NetAddr
133 *
134 *       Desc:  This function packs the 16 bytes of IPv6 address 
135 *
136 *       Ret:   ROK
137 *
138 *       Notes: None
139 *
140 *       File:  cm_tpt.c
141 *
142 */
143 static S16 cmPkCmIpv6NetAddr
144 (
145 CmIpv6NetAddr  *pkParam,     
146 Buffer         *mBuf         /* message buffer */
147 )
148 {
149    uint8_t num;
150    uint8_t *ptr = (uint8_t*)pkParam;
151
152
153    for(num = 0; num < CM_IPV6ADDR_SIZE; num++)
154    {
155       CMCHKPK(oduUnpackUInt8, *(ptr+num), mBuf);
156    }
157
158    return ROK;
159 } /* end of cmPkCmIpv6NetAddr */
160
161 \f
162 /*
163 *
164 *       Fun:   cmPkCmIpv6TptAddr
165 *
166 *       Desc:  This function packs the IPv6 transport address
167 *
168 *       Ret:   ROK
169 *
170 *       Notes: None
171 *
172 *       File:  cm_tpt.c
173 *
174 */
175 static S16 cmPkCmIpv6TptAddr
176 (
177 CmIpv6TptAddr  *pkParam,     /* IPv6 transport address */
178 Buffer         *mBuf         /* message buffer */
179 )
180 {
181
182    CMCHKPK(cmPkCmIpv6NetAddr, &pkParam->ipv6NetAddr, mBuf);
183    CMCHKPK(oduUnpackUInt16, pkParam->port, mBuf);
184
185    return ROK;
186 }   /* cmPkCmIpv6TptAddr */
187
188 \f
189 /*
190 *
191 *       Fun:   cmPkCmNetAddrTbl
192 *
193 *       Desc:  This function packs the 
194 *
195 *       Ret:   ROK
196 *
197 *       Notes: None
198 *
199 *       File:  cm_tpt.c
200 *
201 */
202 S16 cmPkCmNetAddrTbl
203 (
204 CmNetAddrTbl   *pkParam,      /* Network Address Table */
205 Buffer         *mBuf          /* message buffer */
206 )
207 {
208    uint16_t    idx;           /* Loop Index */
209    CmNetAddr   *netAddr;      /* Network Address */
210
211
212    if (pkParam->count > CM_MAX_NET_ADDR)
213       return RFAILED;
214
215    /* Pack All the addresses */
216    for (idx = pkParam->count; idx; idx--)
217    {
218       netAddr = &(pkParam->netAddr[idx - 1]);
219
220       if ((cmPkCmNetAddr(netAddr, mBuf)) != ROK)
221          return RFAILED;
222    }
223
224    /* Pack the total number of addresses present in the table */
225    CMCHKPK(oduUnpackUInt16, pkParam->count, mBuf);
226
227    return ROK;
228
229 } /* end of cmPkCmNetAddrTbl() */
230
231 /*
232 *
233 *       Fun:   cmPkCmNetAddr
234 *
235 *       Desc:  This function packs the 
236 *
237 *       Ret:   ROK
238 *
239 *       Notes: None
240 *
241 *       File:  cm_tpt.c
242 *
243 */
244 S16 cmPkCmNetAddr
245 (
246 CmNetAddr  *pkParam,     
247 Buffer     *mBuf         /* message buffer */
248 )
249 {
250
251    switch (pkParam->type)
252    {
253       case CM_NETADDR_NOTPRSNT:
254          break;
255
256       case CM_NETADDR_IPV4:
257          CMCHKPK(cmPkCmIpv4NetAddr, pkParam->u.ipv4NetAddr, mBuf);
258          break;
259
260       case CM_NETADDR_IPV6:
261          CMCHKPK(cmPkCmIpv6NetAddr, &pkParam->u.ipv6NetAddr, mBuf);
262          break;
263
264       default:
265          return RFAILED;
266    }
267    CMCHKPK(oduUnpackUInt8, pkParam->type, mBuf);
268
269    return ROK;
270 }   /* cmPkCmNetAddr */
271
272 \f
273 /*
274 *
275 *       Fun:   cmPkCmTptAddr
276 *
277 *       Desc:  This function packs the 
278 *
279 *       Ret:   ROK
280 *
281 *       Notes: None
282 *
283 *       File:  cm_tpt.c
284 *
285 */
286 S16 cmPkCmTptAddr
287 (
288 CmTptAddr  *pkParam,     
289 Buffer     *mBuf         /* message buffer */
290 )
291 {
292
293    switch (pkParam->type)
294    {
295       case CM_TPTADDR_NOTPRSNT:
296          break;
297
298       case CM_TPTADDR_IPV4:
299          CMCHKPK(cmPkCmIpv4TptAddr, &pkParam->u.ipv4TptAddr, mBuf);
300          break;
301
302       case CM_TPTADDR_IPV6:
303          CMCHKPK(cmPkCmIpv6TptAddr, &pkParam->u.ipv6TptAddr, mBuf);
304          break;
305    
306       default:
307          return RFAILED;
308    }
309    CMCHKPK(oduUnpackUInt8, pkParam->type, mBuf);
310
311    return ROK;
312 }   /* cmPkCmTptAddr */
313
314 /* added new packing functions */
315 #ifdef LOCAL_INTF
316 /*
317 *
318 *       Fun:   cmPkCmTptLocalInf
319 *
320 *       Desc:  This function packs the local interface info on which IPV4/IPV6
321 *              packet was received on.
322 *
323 *       Ret:   ROK
324 *
325 *       Notes: None
326 *
327 *       File:  cm_tpt.c
328 *
329 */
330 S16 cmPkCmTptLocalInf
331 (
332 CmTptLocalInf  *pkParam,   /* local interface info */
333 Buffer         *mBuf       /* message buffer */
334 )
335 {
336
337    if (pkParam->intfPrsnt == TRUE)
338    {  
339       /* pack the actual interface address */ 
340       CMCHKPK(cmPkCmNetAddr, &pkParam->localIfAddr, mBuf); 
341       /* pack the interface index value */
342       CMCHKPK(oduUnpackUInt32, pkParam->localIf, mBuf);
343    }
344    /* pack the boll which indicates if valid local intf is present or not */
345    CMCHKPK(oduUnpackUInt8, pkParam->intfPrsnt, mBuf);
346    return ROK;
347 }   /* cmPkCmTptLocalInf */
348 #endif /* LOCAL_INTF */
349
350 /* Moving IPv6 multicast information packing functions from cm_inet.c */
351 #ifdef IPV6_SUPPORTED
352 /*
353 *
354 *       Fun:   cmPkCmNetMCastInf6
355 *
356 *       Desc:  This function packs the IPv6 multicast information 
357 *
358 *       Ret:   ROK
359 *
360 *       Notes: None
361 *
362 *       File:  cm_tpt.c
363 *
364 */
365 S16 cmPkCmNetMCastInf6
366 (
367 CmNetMCastInf6  *pkParam,     /* IPv6 multicast information */
368 Buffer          *mBuf         /* message buffer */
369 )
370 {
371
372    CMCHKPK(cmPkCmIpv6NetAddr, &pkParam->mCastAddr, mBuf);
373    CMCHKPK(oduUnpackUInt32, pkParam->localInf, mBuf);
374
375    return ROK;
376 }   /* cmPkCmNetMCastInf6 */
377 #endif /* IPV6_SUPPORTED */
378
379 \f
380 /*
381 *
382 *       Fun:   cmPkCmSockOpts
383 *
384 *       Desc:  This function packs the 
385 *
386 *       Ret:   ROK
387 *
388 *       Notes: None
389 *
390 *       File:  cm_tpt.c
391 *
392 */
393 static S16 cmPkCmSockOpts
394 (
395 CmSockOpts *pkParam,     
396 Buffer     *mBuf         /* message buffer */
397 )
398 {
399
400    switch (pkParam->option)
401    {
402       case CM_SOCKOPT_OPT_ADD_MCAST_MBR:
403       case CM_SOCKOPT_OPT_DRP_MCAST_MBR:
404 #ifdef CM_INET2
405          CMCHKPK(cmPkCmNetAddr, &pkParam->optVal.mCastInfo.mCastAddr, mBuf);
406          CMCHKPK(cmPkCmNetAddr, &pkParam->optVal.mCastInfo.localAddr, mBuf);
407 #else
408          CMCHKPK(cmPkCmNetAddr, &pkParam->optVal.mCastAddr, mBuf);
409 #endif /* CM_INET2 */
410          break;
411
412       case CM_SOCKOPT_OPT_MCAST_IF:
413          CMCHKPK(cmPkCmNetAddr, &pkParam->optVal.lclAddr, mBuf);
414          break;
415
416 #ifdef IPV6_SUPPORTED
417       case CM_SOCKOPT_OPT_ADD_MCAST6_MBR:
418       case CM_SOCKOPT_OPT_DRP_MCAST6_MBR:
419          CMCHKPK(cmPkCmNetMCastInf6, &pkParam->optVal.mCastInfo6, mBuf);
420          break;
421
422       case CM_SOCKOPT_OPT_MCAST6_IF:
423          CMCHKPK(oduUnpackUInt32, pkParam->optVal.infId, mBuf);
424          break;
425
426 #endif /* IPV6_SUPPORTED */
427
428       default:
429          CMCHKPK(oduUnpackUInt32, pkParam->optVal.value, mBuf);
430          break;
431    }
432    CMCHKPK(oduUnpackUInt32, pkParam->option, mBuf);
433    CMCHKPK(oduUnpackUInt32, pkParam->level, mBuf);
434
435    return ROK;
436 }   /* cmPkCmSockOpts */
437
438 \f
439 /*
440 *
441 *       Fun:   cmPkCmSockParam
442 *
443 *       Desc:  This function packs the 
444 *
445 *       Ret:   ROK
446 *
447 *       Notes: None
448 *
449 *       File:  cm_tpt.c
450 *
451 */
452 static S16 cmPkCmSockParam
453 (
454 CmSockParam *pkParam,     
455 Buffer      *mBuf         /* message buffer */
456 )
457 {
458    uint32_t num;
459
460
461    if( pkParam->numOpts > CM_MAX_SOCK_OPTS)
462    {
463       return RFAILED;
464    }
465    for(num = 0; num < pkParam->numOpts; num++)
466    {
467       CMCHKPK(cmPkCmSockOpts, &pkParam->sockOpts[num], mBuf);
468    }
469    CMCHKPK(oduUnpackUInt8, pkParam->numOpts, mBuf);
470    CMCHKPK(oduUnpackUInt8, pkParam->listenQSize, mBuf);
471
472    return ROK;
473 }   /* cmPkCmSockParam */
474
475 \f
476 #ifdef CM_TLS
477 /*
478 *
479 *       Fun:   cmPkTlsTptParam
480 *
481 *       Desc:  This function packs the 
482 *
483 *       Ret:   ROK
484 *
485 *       Notes: None
486 *
487 *       File:  cm_tpt.c
488 *
489 */
490 static S16 cmPkTlsTptParam
491 (
492 TlsTptParam *pkParam,     /**/
493 Buffer      *mBuf         /* message buffer */
494 )
495 {
496    uint32_t num;
497
498
499    if( pkParam->numOpts > CM_MAX_SOCK_OPTS)
500    {
501       return RFAILED;
502    }
503    for(num = 0; num < pkParam->numOpts; num++)
504    {
505       CMCHKPK(cmPkCmSockOpts, &pkParam->sockOpts[num], mBuf);
506    }
507    CMCHKPK(oduUnpackUInt8, pkParam->numOpts, mBuf);
508    CMCHKPK(oduUnpackUInt8, pkParam->listenQSize, mBuf);
509    CMCHKPK(SPkS16, pkParam->ctxId, mBuf);
510
511    return ROK;
512 }  /* cmPkTlsTptParam */
513
514 #endif  /* CM_TLS */
515
516 \f
517 /*
518 *
519 *       Fun:   cmPkCmTptParam
520 *
521 *       Desc:  This function packs the 
522 *
523 *       Ret:   ROK
524 *
525 *       Notes: None
526 *
527 *       File:  cm_tpt.c
528 *
529 */
530 S16 cmPkCmTptParam
531 (
532 CmTptParam *pkParam,     
533 Buffer     *mBuf         /* message buffer */
534 )
535 {
536
537    switch (pkParam->type)
538    {
539       case CM_TPTPARAM_NOTPRSNT:
540          break;
541
542       case CM_TPTPARAM_SOCK:
543          CMCHKPK(cmPkCmSockParam, &pkParam->u.sockParam, mBuf);
544          break;
545
546 #ifdef CM_AAL
547       case CM_TPTPARAM_AAL:
548          CMCHKPK(cmPkAalConParam, &pkParam->u.aalParam, mBuf);
549          break;
550 #endif
551
552 #ifdef CM_TLS
553       case CM_TPTPARAM_TLS:
554          CMCHKPK(cmPkTlsTptParam, &pkParam->u.tlsParam, mBuf);
555          break;
556 #endif
557
558       default:
559          return RFAILED;
560    }
561
562    CMCHKPK(oduUnpackUInt8, pkParam->type, mBuf);
563
564    return ROK;
565 }   /* cmPkCmTptParam */
566
567 \f  
568 /*
569  *      UNPACKING FUNCTIONS
570  */
571
572 /* Moving IPv4 address un-packing functions from cm_inet.c file */
573
574 /*
575 *
576 *       Fun:   cmUnpkCmIpv4TptAddr
577 *
578 *       Desc:  This function unpacks the IPv4 address
579 *
580 *       Ret:   ROK
581 *
582 *       Notes: None
583 *
584 *       File:  cm_tpt.c
585 *
586 */
587 S16 cmUnpkCmIpv4TptAddr 
588 (
589 CmIpv4TptAddr *unpkParam,     /* IPv4 Address */
590 Buffer        *mBuf           /* message buffer */
591 )
592 {
593
594    CMCHKUNPK(oduPackUInt16, &unpkParam->port, mBuf);
595    CMCHKUNPK(cmUnpkCmIpv4NetAddr, &unpkParam->address, mBuf);
596
597    return ROK;
598 }   /* cmUnpkCmIpv4TptAddr */
599
600 \f
601 /*
602 *
603 *       Fun:   cmUnpkCmIpv6NetAddr
604 *
605 *       Desc:  This function unpacks the 16 bytes of IPv6 address 
606 *
607 *       Ret:   ROK
608 *
609 *       Notes: None
610 *
611 *       File:  cm_tpt.c
612 *
613 */
614 static S16 cmUnpkCmIpv6NetAddr
615 (
616 CmIpv6NetAddr  *unpkParam,   /* IPv6 address */
617 Buffer         *mBuf         /* message buffer */
618 )
619 {
620    uint32_t num;
621    uint8_t *ptr = (uint8_t*)unpkParam;
622
623
624    ptr += (CM_INET_IPV6ADDR_SIZE - 1);
625
626    for(num = 0; num < CM_IPV6ADDR_SIZE; num++)
627    {
628       CMCHKUNPK(oduPackUInt8, (ptr-num), mBuf);
629    }
630
631    return ROK;
632 } /* end of cmUnpkCmIpv6NetAddr */
633
634 \f
635 /*
636 *
637 *       Fun:   cmUnpkCmIpv6TptAddr
638 *
639 *       Desc:  This function unpacks the IPv6 transport address
640 *
641 *       Ret:   ROK
642 *
643 *       Notes: None
644 *
645 *       File:  cm_tpt.c
646 *
647 */
648 static S16 cmUnpkCmIpv6TptAddr
649 (
650 CmIpv6TptAddr  *unpkParam,   /* IPv6 transport address */
651 Buffer         *mBuf         /* message buffer */
652 )
653 {
654
655    CMCHKUNPK(oduPackUInt16, &unpkParam->port, mBuf);
656    CMCHKUNPK(cmUnpkCmIpv6NetAddr, &unpkParam->ipv6NetAddr, mBuf);
657
658    return ROK;
659 }   /* cmUnpkCmIpv6TptAddr */
660
661 \f
662 /*
663 *
664 *       Fun:   cmUnpkCmNetAddrTbl
665 *
666 *       Desc:  This function unpacks the 
667 *
668 *       Ret:   ROK
669 *
670 *       Notes: None
671 *
672 *       File:  cm_tpt.c
673 *
674 */
675 S16 cmUnpkCmNetAddrTbl
676 (
677 CmNetAddrTbl  *unpkParam,    /* Network Address Table */
678 Buffer        *mBuf          /* message buffer */
679 )
680 {
681    uint16_t   idx;           /* Loop Index */
682    CmNetAddr  *netAddr;      /* Network Address */
683    
684    /* Unpack the count */
685    CMCHKUNPK(oduPackUInt16, &(unpkParam->count), mBuf);
686
687    /* Unpack the addresses */
688    for (idx = 0; idx < unpkParam->count; idx++)
689    {
690       netAddr = &(unpkParam->netAddr[idx]);
691
692       if ((cmUnpkCmNetAddr(netAddr, mBuf)) != ROK)
693          return RFAILED;
694    }
695
696    return ROK;
697
698 } /* end of cmUnpkCmNetAddrTbl() */
699
700 \f
701 /*
702 *
703 *       Fun:   cmUnpkCmNetAddr
704 *
705 *       Desc:  This function unpacks the network address
706 *
707 *       Ret:   ROK
708 *
709 *       Notes: None
710 *
711 *       File:  cm_tpt.c
712 *
713 */
714 S16 cmUnpkCmNetAddr
715 (
716 CmNetAddr *unpkParam,   
717 Buffer    *mBuf         /* message buffer */
718 )
719 {
720
721    CMCHKUNPK(oduPackUInt8, &unpkParam->type, mBuf);
722
723    switch (unpkParam->type)
724    {
725       case CM_NETADDR_NOTPRSNT:
726          break;
727
728       case CM_NETADDR_IPV4:
729          CMCHKUNPK(cmUnpkCmIpv4NetAddr, &unpkParam->u.ipv4NetAddr, mBuf);
730          break;
731
732       case CM_NETADDR_IPV6:
733          CMCHKUNPK(cmUnpkCmIpv6NetAddr, &unpkParam->u.ipv6NetAddr, mBuf);
734          break;
735
736       default:
737          return RFAILED;
738    }
739
740    return ROK;
741 }   /* cmUnpkCmNetAddr */
742
743 \f
744 /*
745 *
746 *       Fun:   cmUnpkCmTptAddr
747 *
748 *       Desc:  This function unpacks the 
749 *
750 *       Ret:   ROK
751 *
752 *       Notes: None
753 *
754 *       File:  cm_tpt.c
755 *
756 */
757 S16 cmUnpkCmTptAddr
758 (
759 CmTptAddr *unpkParam,   
760 Buffer    *mBuf         /* message buffer */
761 )
762 {
763
764    CMCHKUNPK(oduPackUInt8, &unpkParam->type, mBuf);
765
766    switch (unpkParam->type)
767    {
768       case CM_TPTADDR_NOTPRSNT:
769          break;
770
771       case CM_TPTADDR_IPV4:
772          CMCHKUNPK(cmUnpkCmIpv4TptAddr, &unpkParam->u.ipv4TptAddr, mBuf);
773          break;
774
775       case CM_TPTADDR_IPV6:
776          CMCHKUNPK(cmUnpkCmIpv6TptAddr, &unpkParam->u.ipv6TptAddr, mBuf);
777          break;
778
779       default:
780          return RFAILED;
781    }
782
783    return ROK;
784 }   /* cmUnpkCmTptAddr */
785
786 /* Moving IPv6 multicast information unpacking functions from cm_inet.c */
787 #ifdef IPV6_SUPPORTED
788 \f
789 /*
790 *
791 *       Fun:   cmUnpkCmNetMCastInf6
792 *
793 *       Desc:  This function unpacks the IPv6 multicast information 
794 *
795 *       Ret:   ROK
796 *
797 *       Notes: None
798 *
799 *       File:  cm_tpt.c
800 *
801 */
802 S16 cmUnpkCmNetMCastInf6
803 (
804 CmNetMCastInf6 *unpkParam,   /* IPv6 multicast information */
805 Buffer         *mBuf         /* message buffer */
806 )
807 {
808
809     CMCHKUNPK(oduPackUInt32, &unpkParam->localInf, mBuf);
810     CMCHKUNPK(cmUnpkCmIpv6NetAddr, &unpkParam->mCastAddr, mBuf);
811
812    return ROK;
813 }   /* cmUnpkCmNetMCastInf6 */
814 #endif /* IPV6_SUPPORTED */
815
816 \f
817 /*
818 *
819 *       Fun:   cmUnpkCmSockOpts
820 *
821 *       Desc:  This function unpacks the socket options
822 *
823 *       Ret:   ROK
824 *
825 *       Notes: None
826 *
827 *       File:  cm_tpt.c
828 *
829 */
830 static S16 cmUnpkCmSockOpts
831 (
832 CmSockOpts *unpkParam,   /* socket options */
833 Buffer     *mBuf         /* message buffer */
834 )
835 {
836
837    CMCHKUNPK(oduPackUInt32, &unpkParam->level, mBuf);
838    CMCHKUNPK(oduPackUInt32, &unpkParam->option, mBuf);
839
840    switch (unpkParam->option)
841    {
842       case CM_SOCKOPT_OPT_ADD_MCAST_MBR:
843       case CM_SOCKOPT_OPT_DRP_MCAST_MBR:
844 #ifdef CM_INET2
845          CMCHKUNPK(cmUnpkCmNetAddr, &unpkParam->optVal.mCastInfo.localAddr, 
846                    mBuf);
847          CMCHKUNPK(cmUnpkCmNetAddr, &unpkParam->optVal.mCastInfo.mCastAddr, 
848                    mBuf);
849 #else
850          CMCHKUNPK(cmUnpkCmNetAddr, &unpkParam->optVal.mCastAddr, mBuf);
851 #endif /* CM_INET2 */
852          break;
853
854       case CM_SOCKOPT_OPT_MCAST_IF:
855          CMCHKUNPK(cmUnpkCmNetAddr, &unpkParam->optVal.lclAddr, mBuf);
856          break;
857
858 #ifdef IPV6_SUPPORTED
859       case CM_SOCKOPT_OPT_ADD_MCAST6_MBR:
860       case CM_SOCKOPT_OPT_DRP_MCAST6_MBR:
861          CMCHKUNPK(cmUnpkCmNetMCastInf6, &unpkParam->optVal.mCastInfo6, mBuf);
862          break;
863
864       case CM_SOCKOPT_OPT_MCAST6_IF:
865          CMCHKUNPK(oduPackUInt32, &unpkParam->optVal.infId, mBuf);
866          break;
867 #endif /* IPV6_SUPPORTED */
868
869       default:
870          CMCHKUNPK(oduPackUInt32, &unpkParam->optVal.value, mBuf);
871          break;
872    }
873
874    return ROK;
875 }   /* cmUnpkCmSockOpts */
876
877 \f
878 /*
879 *
880 *       Fun:   cmUnpkCmSockParam
881 *
882 *       Desc:  This function unpacks the socket parameters
883 *
884 *       Ret:   ROK
885 *
886 *       Notes: None
887 *
888 *       File:  cm_tpt.c
889 *
890 */
891 static S16 cmUnpkCmSockParam
892 (
893 CmSockParam *unpkParam,   /* socket parameters */
894 Buffer      *mBuf         /* message buffer */
895 )
896 {
897    uint32_t num;
898
899
900    CMCHKUNPK(oduPackUInt8, &unpkParam->listenQSize, mBuf);
901    CMCHKUNPK(oduPackUInt8, &unpkParam->numOpts, mBuf);
902
903    if( unpkParam->numOpts > CM_MAX_SOCK_OPTS)
904    {
905       return RFAILED;
906    }
907
908    for(num = 0; num < unpkParam->numOpts; num++)
909    {
910       CMCHKUNPK(cmUnpkCmSockOpts, &unpkParam->sockOpts[num], mBuf);
911    }
912
913    return ROK;
914 }   /* cmUnpkCmSockParam */
915
916 \f
917 #ifdef CM_TLS
918 /*
919 *
920 *       Fun:   cmUnpkTlsTptParam
921 *
922 *       Desc:  This function unpacks the socket parameters
923 *
924 *       Ret:   ROK
925 *
926 *       Notes: None
927 *
928 *       File:  cm_tpt.c
929 *
930 */
931 static S16 cmUnpkTlsTptParam
932 (
933 TlsTptParam *unpkParam,   /* TLS parameters */
934 Buffer      *mBuf         /* message buffer */
935 )
936 {
937    uint32_t num;
938
939
940    CMCHKUNPK(SUnpkS16, &unpkParam->ctxId, mBuf);
941    CMCHKUNPK(oduPackUInt8, &unpkParam->listenQSize, mBuf);
942    CMCHKUNPK(oduPackUInt8, &unpkParam->numOpts, mBuf);
943
944    if( unpkParam->numOpts > CM_MAX_SOCK_OPTS)
945    {
946       return RFAILED;
947    }
948
949    for(num = 0; num < unpkParam->numOpts; num++)
950    {
951       CMCHKUNPK(cmUnpkCmSockOpts, &unpkParam->sockOpts[num], mBuf);
952    }
953
954    return ROK;
955 }  /* cmUnpkTlsTptParam */
956
957 #endif  /* CM_TLS */
958
959 \f
960 /*
961 *
962 *       Fun:   cmUnpkCmTptParam
963 *
964 *       Desc:  This function unpacks the transport parameters 
965 *
966 *       Ret:   ROK
967 *
968 *       Notes: None
969 *
970 *       File:  cm_tpt.c
971 *
972 */
973 S16 cmUnpkCmTptParam
974 (
975 CmTptParam  *unpkParam,   /* transport parameters */
976 Buffer      *mBuf         /* message buffer */
977 )
978 {
979
980    CMCHKUNPK(oduPackUInt8, &unpkParam->type, mBuf);
981
982    switch (unpkParam->type)
983    {
984       case CM_TPTPARAM_NOTPRSNT:
985          break;
986
987       case CM_TPTPARAM_SOCK:
988          CMCHKUNPK(cmUnpkCmSockParam, &unpkParam->u.sockParam, mBuf);
989          break;
990
991 #ifdef CM_AAL
992       case CM_TPTPARAM_AAL:
993          CMCHKUNPK(cmUnpkAalConParam, &unpkParam->u.aalParam, mBuf);
994          break;
995 #endif
996
997 #ifdef CM_TLS
998       case CM_TPTPARAM_TLS:
999          CMCHKUNPK(cmUnpkTlsTptParam, &unpkParam->u.tlsParam, mBuf);
1000          break;
1001 #endif
1002
1003       default:
1004          return RFAILED;
1005    }
1006
1007    return ROK;
1008 }   /* cmUnpkCmTptParam */
1009
1010
1011 #ifdef CM_INET2  
1012 \f
1013 /*
1014 *
1015 *       Fun:   cmPkCmIpHdrParm
1016 *
1017 *       Desc:  This function packs the the IP hedear parameters for both 
1018 *              IPV4 and IPV6. 
1019 *
1020 *       Ret:   ROK
1021 *
1022 *       Notes: None
1023 *
1024 *       File:  cm_tpt.c
1025 *
1026 */
1027 S16 cmPkCmIpHdrParm
1028 (
1029 CmIpHdrParm *pkParam,   /* IP hdr parameters */ 
1030 Buffer      *mBuf       /* message buffer */
1031 )
1032 {
1033
1034    switch (pkParam->type)
1035    {
1036       case CM_HDRPARM_NOTPRSNT:
1037       case CM_HDRPARM_ICMP6:
1038          break;
1039
1040       case CM_HDRPARM_IPV4:
1041
1042          /* call to pack ipv4 options */
1043 #ifdef IPV4_OPTS_SUPPORTED
1044          /* ipv4 IP options */
1045          CMCHKPK(cmPkTknStr64, &pkParam->u.hdrParmIpv4.ipv4HdrOpt, mBuf);
1046 #endif /* IPV4_OPTS_SUPPORTED */
1047          
1048          CMCHKPK(cmPkTknUInt8, &pkParam->u.hdrParmIpv4.ttl, mBuf);
1049          CMCHKPK(cmPkTknUInt8, &pkParam->u.hdrParmIpv4.tos, mBuf);
1050          CMCHKPK(cmPkTknUInt8, &pkParam->u.hdrParmIpv4.dfBit, mBuf); 
1051          CMCHKPK(cmPkTknUInt8, &pkParam->u.hdrParmIpv4.proto, mBuf);
1052          break;
1053
1054       case CM_HDRPARM_IPV6:
1055 #ifdef IPV6_SUPPORTED    
1056          /* call to pack ipv6 extn hdrs */
1057 #ifdef IPV6_OPTS_SUPPORTED 
1058          /* pack IPV6 extension headers */
1059          CMCHKPK(cmPkCmIpv6ExtHdr, &pkParam->u.hdrParmIpv6.ipv6ExtHdr, mBuf);
1060 #endif /* IPV6_OPTS_SUPPORTED */
1061          CMCHKPK(cmPkCmNetAddr, &pkParam->u.hdrParmIpv6.srcAddr6, mBuf); 
1062          CMCHKPK(cmPkTknUInt8, &pkParam->u.hdrParmIpv6.ttl, mBuf);          
1063 #endif /* IPV6_SUPPORTED */ 
1064          break;
1065    
1066       default:
1067          return RFAILED;
1068    }
1069    CMCHKPK(oduUnpackUInt8, pkParam->type, mBuf);
1070
1071    return ROK;
1072 }   /* End of cmPkCmIpHdrParm */
1073
1074 \f
1075 /* added new unpack function for local interface */
1076 #ifdef LOCAL_INTF
1077 /*
1078 *
1079 *       Fun:   cmUnpkCmTptLocalInf
1080 *
1081 *       Desc:  This function unpacks the local interface info on which 
1082 *              IPV4/IPV6 packet was received on.
1083 *
1084 *       Ret:   ROK
1085 *
1086 *       Notes: None
1087 *
1088 *       File:  cm_tpt.c
1089 *
1090 */
1091 S16 cmUnpkCmTptLocalInf
1092 (
1093 CmTptLocalInf *unpkParam, /* local interface info */
1094 Buffer        *mBuf       /* message buffer */
1095 )
1096 {
1097
1098    /* first unpack the bool intfPrsnt value which is always packed */
1099    CMCHKUNPK(oduUnpackBool, &unpkParam->intfPrsnt, mBuf);
1100    
1101    /* if the above unpacked bool is TRUE then we have to unpack further
1102     * to get the local intf index and intf address */   
1103    if (unpkParam->intfPrsnt == TRUE)
1104    {   
1105       CMCHKUNPK(oduPackUInt32, &unpkParam->localIf, mBuf);
1106       CMCHKUNPK(cmUnpkCmNetAddr, &unpkParam->localIfAddr, mBuf); 
1107    }
1108    return ROK;
1109 }   /* cmUnpkCmTptLocalInf */
1110 #endif /* LOCAL_INTF */
1111
1112 \f
1113 /* added new functions */
1114 #ifdef IPV6_OPTS_SUPPORTED 
1115 /*
1116 *       Fun:   cmPkCmIpv6ExtHdr
1117 *
1118 *       Desc:  This function packs the IPV6 extension headers
1119 *
1120 *       Ret:   ROK
1121 *
1122 *       Notes: None
1123 *
1124 *       File:  cm_tpt.c
1125 *
1126 */
1127 S16 cmPkCmIpv6ExtHdr
1128 (
1129 CmIpv6ExtHdr *pkParam,   /* IPV6 extension hdrs */
1130 Buffer       *mBuf       /* message buffer */
1131 )
1132 {
1133
1134    /* pack first Route hdr */   
1135    if (pkParam->rtOptsPrsnt)
1136       CMCHKPK(cmPkCmIpv6RtHdr, &pkParam->rtOpts, mBuf);  
1137    CMCHKPK(oduPackBool, pkParam->rtOptsPrsnt, mBuf);  
1138
1139    /* pack Dest Opt hdr */
1140    if (pkParam->destOptsPrsnt)
1141       CMCHKPK(cmPkCmIpv6DestOptsArr, &pkParam->destOptsArr, mBuf);  
1142    CMCHKPK(oduPackBool, pkParam->destOptsPrsnt, mBuf);  
1143
1144    /* pack HBH hdr */
1145    if (pkParam->hbhHdrPrsnt)
1146       CMCHKPK(cmPkCmIpv6HBHHdrArr, &pkParam->hbhOptsArr, mBuf);  
1147    CMCHKPK(oduPackBool, pkParam->hbhHdrPrsnt, mBuf);  
1148
1149    return ROK;
1150 } /* end of cmPkCmIpv6ExtHdr */
1151
1152 \f
1153 /*
1154 *
1155 *       Fun:   cmPkCmIpv6RtHdr
1156 *
1157 *       Desc:  This function packs the IPV6 route header
1158 *
1159 *       Ret:   ROK
1160 *
1161 *       Notes: None
1162 *
1163 *       File:  cm_tpt.c
1164 *
1165 */
1166 S16 cmPkCmIpv6RtHdr
1167 (
1168 CmIpv6RtHdr *pkParam,   /* IPV6 Route hdr */
1169 Buffer      *mBuf      /* message buffer */
1170 )
1171 {
1172    uint8_t idx;
1173    
1174
1175    /* pack all IPV6 addrs in the route hdr */
1176    for(idx = 0; idx < pkParam->numAddrs; idx++)
1177    {
1178       CMCHKPK(cmPkCmIpv6NetAddr, &pkParam->ipv6Addrs[idx], mBuf);
1179    }
1180    /* pack reserve byte & strict/loose bit map */
1181    CMCHKPK(oduUnpackUInt32, pkParam->slMap, mBuf);
1182    CMCHKPK(oduUnpackUInt8, pkParam->numAddrs, mBuf);  
1183
1184    return ROK;
1185 } /* end of cmPkCmIpv6RtHdr */
1186
1187 \f
1188 /*
1189 *
1190 *       Fun:   cmUnpkCmIpv6RtHdr
1191 *
1192 *       Desc:  This function unpacks the IPV6 route header
1193 *
1194 *       Ret:   ROK
1195 *              ROUTRES - out of resources
1196 *
1197 *       Notes: None
1198 *
1199 *       File:  cm_tpt.c
1200 *
1201 */
1202 S16 cmUnpkCmIpv6RtHdr
1203 (
1204 CmIpv6RtHdr *unpkParam,  /* IPV6 Route hdr */
1205 Buffer      *mBuf,       /* message buffer */
1206 Mem         *memInfo     /* meminfo to allocate for Route hdr */
1207 )
1208 {
1209    uint8_t idx;  /* array index */
1210    S32 retVal; /* temporary return value */
1211    
1212    
1213    CMCHKUNPK(oduPackUInt8, &unpkParam->numAddrs, mBuf);
1214    
1215    /* unpack reserve byte & strict/loose bit map */
1216    CMCHKUNPK(oduPackUInt32, &unpkParam->slMap, mBuf);
1217    
1218    retVal = SGetSBufNewForDebug(__FILE__,__FUNCTION__,__LINE__,memInfo->region,    
1219                   memInfo->pool,                     
1220                  (Data **)&unpkParam->ipv6Addrs, 
1221                  (unpkParam->numAddrs * 16));
1222       
1223    if (retVal != ROK)
1224    {
1225       return (ROUTRES);
1226    }
1227    
1228    /* unpack all IPV6 addrs in the route hdr */
1229    for(idx = 0; idx < unpkParam->numAddrs; idx++)
1230    {
1231       CMCHKUNPK(cmUnpkCmIpv6NetAddr, &unpkParam->ipv6Addrs[idx], mBuf);
1232    }
1233
1234    return ROK;
1235 } /* end of cmUnpkCmIpv6RtHdr */
1236
1237 \f
1238 /*
1239 *
1240 *       Fun:   cmUnpkCmIpv6ExtHdr
1241 *
1242 *       Desc:  This function unpacks the IPv6 extension header
1243 *
1244 *       Ret:   ROK
1245 *
1246 *       Notes: None
1247 *
1248 *       File:  cm_tpt.c
1249 *
1250 */
1251 S16 cmUnpkCmIpv6ExtHdr
1252 (
1253 CmIpv6ExtHdr *unpkParam,  /* IPV6 extension hdrs */
1254 Buffer       *mBuf,       /* message buffer */
1255 Mem          *memInfo     /* meminfo to allocate for IPV6 ext hdr */
1256 )
1257 {
1258       
1259    /* unpack HBH hdr first */
1260    CMCHKUNPK(oduUnpackBool, &unpkParam->hbhHdrPrsnt, mBuf); 
1261    if (unpkParam->hbhHdrPrsnt)
1262       cmUnpkCmIpv6HBHHdrArr(&unpkParam->hbhOptsArr, mBuf, memInfo);         
1263                                                          
1264    /* unpack DEST opt hdr */
1265    CMCHKUNPK(oduUnpackBool, &unpkParam->destOptsPrsnt, mBuf);
1266    if (unpkParam->destOptsPrsnt)
1267       cmUnpkCmIpv6DestOptsArr(&unpkParam->destOptsArr, mBuf, memInfo);   
1268
1269    /* unpack Route hdr last */
1270    CMCHKUNPK(oduUnpackBool, &unpkParam->rtOptsPrsnt, mBuf); 
1271    if (unpkParam->rtOptsPrsnt)
1272       cmUnpkCmIpv6RtHdr(&unpkParam->rtOpts, mBuf, memInfo);  
1273                                                         
1274    return ROK;
1275 } /* end of cmUnpkCmIpv6ExtHdr */
1276
1277 \f
1278 /*
1279 *
1280 *       Fun:   cmPkCmIpv6DestOptsArr
1281 *
1282 *       Desc:  This function packs the IPV6 Destination Option array
1283 *
1284 *       Ret:   ROK
1285 *
1286 *       Notes: None
1287 *
1288 *       File:  cm_tpt.c
1289 *
1290 */
1291 S16 cmPkCmIpv6DestOptsArr
1292 (
1293 CmIpv6DestOptsArr *pkParam,  /* IPV6 Dest hdr array */
1294 Buffer            *mBuf      /* message buffer */
1295 )
1296 {
1297
1298    uint8_t numOptions;
1299
1300    
1301    /* pack all HBH options */
1302    for(numOptions = 0; numOptions<pkParam->numDestOpts; numOptions++)  
1303       CMCHKPK(cmPkCmIpv6DestOptsHdr, &pkParam->destOpts[numOptions], mBuf);
1304    CMCHKPK(oduUnpackUInt8, pkParam->numDestOpts, mBuf);  
1305
1306    return ROK;
1307 } /* end of cmPkCmIpv6DestOptsArr */
1308
1309 \f
1310 /*
1311 *
1312 *       Fun:   cmPkCmIpv6DestOptsHdr
1313 *
1314 *       Desc:  This function packs individua IPV6 Destination Option
1315 *
1316 *       Ret:   ROK
1317 *
1318 *       Notes: None
1319 *
1320 *       File:  cm_tpt.c
1321 *
1322 */
1323 S16 cmPkCmIpv6DestOptsHdr
1324 (
1325 CmIpv6DestOptsHdr *pkParam,  /* IPV6 Dest opt */
1326 Buffer            *mBuf      /* message buffer */
1327 )
1328 {
1329    uint8_t optLen;
1330    
1331
1332    for(optLen = 0; optLen < pkParam->length; optLen++)
1333    {
1334       CMCHKPK(oduUnpackUInt8, pkParam->value[optLen], mBuf);
1335    }
1336    CMCHKPK(oduUnpackUInt8, pkParam->length, mBuf);  
1337    CMCHKPK(oduUnpackUInt8, pkParam->type, mBuf);  
1338
1339    return ROK;
1340 } /* end of cmPkCmIpv6DestOptsHdr */
1341
1342 \f
1343 /*
1344 *
1345 *       Fun:   cmUnpkCmIpv6DestOptsHdr
1346 *
1347 *       Desc:  This function unpacks individual IPV6 Dest Option
1348 *
1349 *       Ret:   ROK
1350 *
1351 *       Notes: None
1352 *
1353 *       File:  cm_tpt.c
1354 *
1355 */
1356 S16 cmUnpkCmIpv6DestOptsHdr
1357 (
1358 CmIpv6DestOptsHdr *unpkParam,/* IPV6 Dest Option */
1359 Buffer            *mBuf,     /* message buffer */
1360 Mem               *memInfo   /* meminfo to allocate mem for dest opt */
1361 )
1362 {
1363    S32 retVal;                        /* temporary return value */
1364    uint8_t optLen;                      /* length of value field */
1365
1366   
1367    /* unpack type, length */
1368    CMCHKUNPK(oduPackUInt8, &unpkParam->type, mBuf);  
1369    CMCHKUNPK(oduPackUInt8, &unpkParam->length, mBuf);
1370
1371    /* allocate static memory to hold the unpacked values */
1372    retVal = SGetSBufNewForDebug(__FILE__,__FUNCTION__,__LINE__,memInfo->region,                   
1373                   memInfo->pool,                     
1374                   (Data **)&unpkParam->value, (Size)unpkParam->length);
1375    if (retVal != ROK)
1376    {
1377       return (ROUTRES);
1378    }
1379       
1380    /* unpack value fieldof this option */
1381    for(optLen = 0; optLen<unpkParam->length; optLen++)
1382    {
1383       CMCHKUNPK(oduPackUInt8, &unpkParam->value[optLen], mBuf);  
1384    }    
1385    
1386    return ROK;
1387 } /* end of cmUnpkCmIpv6DestOptsHdr */
1388
1389 \f
1390 /*
1391 *
1392 *       Fun:   cmUnpkCmIpv6DestOptsArr
1393 *
1394 *       Desc:  This function unpacks the IPV6 Destination Option array
1395 *
1396 *       Ret:   ROK
1397 *
1398 *       Notes: None
1399 *
1400 *       File:  cm_tpt.c
1401 *
1402 */
1403 S16 cmUnpkCmIpv6DestOptsArr
1404 (
1405 CmIpv6DestOptsArr *unpkParam, /* all IPV6 Destination Options */
1406 Buffer            *mBuf,      /* message buffer */
1407 Mem               *memInfo    /* meminfo to allocate mem for dest opts */
1408 )
1409 {
1410    uint8_t numOptions;
1411    S16 retVal;
1412    
1413
1414    CMCHKUNPK(oduPackUInt8, &unpkParam->numDestOpts, mBuf); 
1415    if (unpkParam->numDestOpts)
1416    {
1417       /* allocate mem to hold all dest options */
1418       retVal = SGetSBufNewForDebug(__FILE__,__FUNCTION__,__LINE__,memInfo->region,    
1419                      memInfo->pool,                     
1420                      (Data **)&unpkParam->destOpts, 
1421                      (unpkParam->numDestOpts * sizeof(CmIpv6DestOptsHdr)));
1422       
1423       if (retVal != ROK)
1424       {
1425          return (ROUTRES);
1426       }
1427    
1428       /* unpack all dest options */
1429       for(numOptions = 0; numOptions<unpkParam->numDestOpts; numOptions++)
1430          if ((retVal = cmUnpkCmIpv6DestOptsHdr(&unpkParam->destOpts[numOptions],
1431                                             mBuf, memInfo)) != ROK)
1432             return RFAILED;   
1433    
1434    }                                             
1435    return ROK;
1436 } /* end of cmUnpkCmIpv6DestOptsArr */
1437
1438 \f
1439 /*
1440 *
1441 *       Fun:   cmPkCmIpv6HBHHdrArr
1442 *
1443 *       Desc:  This function packs the all IPV6 HopByHop options
1444 *
1445 *       Ret:   ROK
1446 *
1447 *       Notes: None
1448 *
1449 *       File:  cm_tpt.c
1450 *
1451 */
1452 S16 cmPkCmIpv6HBHHdrArr
1453 (
1454 CmIpv6HBHHdrArr *pkParam,  /* all IPV6 HopByHop options */
1455 Buffer          *mBuf      /* message buffer */
1456 )
1457 {
1458    uint8_t numOptions;
1459    
1460
1461    for(numOptions = 0; numOptions<pkParam->numHBHOpts; numOptions++)
1462       CMCHKPK(cmPkCmIpv6HBHHdr, &pkParam->hbhOpts[numOptions], mBuf);
1463                           
1464    CMCHKPK(oduUnpackUInt8, pkParam->numHBHOpts, mBuf);  
1465
1466    return ROK;
1467 } /* end of cmPkCmIpv6HBHHdrArr */
1468
1469 \f
1470 /*
1471 *
1472 *       Fun:   cmPkCmIpv6HBHHdr
1473 *
1474 *       Desc:  This function packs individual IPV6 HBH options
1475 *
1476 *       Ret:   ROK
1477 *
1478 *       Notes: None
1479 *
1480 *       File:  cm_tpt.c
1481 *
1482 */
1483 S16 cmPkCmIpv6HBHHdr
1484 (
1485 CmIpv6HBHHdr *pkParam,  /* individual IPV6 HBH options */
1486 Buffer       *mBuf      /* message buffer */
1487 )
1488 {
1489    uint8_t optLen;
1490
1491
1492    /* pack value field */
1493    for(optLen = 0; optLen<pkParam->length; optLen++)
1494    {
1495       CMCHKPK(oduUnpackUInt8, pkParam->value[optLen], mBuf);
1496    }
1497
1498    /* pack type, length fields */
1499    CMCHKPK(oduUnpackUInt8, pkParam->length, mBuf);  
1500    CMCHKPK(oduUnpackUInt8, pkParam->type, mBuf);  
1501
1502    return ROK;
1503 } /* end of cmPkCmIpv6HBHHdr */
1504
1505 \f
1506 /*
1507 *
1508 *       Fun:   cmUnpkCmIpv6HBHHdr
1509 *
1510 *       Desc:  This function unpacks individual IPV6 HBH Option
1511 *
1512 *       Ret:   ROK
1513 *
1514 *       Notes: None
1515 *
1516 *       File:  cm_tpt.c
1517 *
1518 */
1519 S16 cmUnpkCmIpv6HBHHdr
1520 (
1521 CmIpv6HBHHdr *unpkParam,/* individual IPV6 HBH Option */
1522 Buffer       *mBuf,     /* message buffer */
1523 Mem          *memInfo   /* meminfo to allocate mem for HBH opt */
1524 )
1525 {
1526    S32 retVal;                     /* temporary return value */
1527    uint8_t optLen;                      /* length of value field */
1528    
1529    CMCHKUNPK(oduPackUInt8, &unpkParam->type, mBuf);   
1530    CMCHKUNPK(oduPackUInt8, &unpkParam->length, mBuf);
1531
1532    /* allocate static memory to hold the unpacked values */
1533    if (unpkParam->length)
1534    {
1535       retVal = SGetSBufNewForDebug(__FILE__,__FUNCTION__,__LINE__,memInfo->region,                   
1536                      memInfo->pool,                     
1537                      (Data **)&unpkParam->value, (Size)unpkParam->length); 
1538       if (retVal != ROK)
1539       {
1540          return (ROUTRES);
1541       }
1542
1543       for(optLen = 0; optLen<unpkParam->length; optLen++)
1544          CMCHKUNPK(oduPackUInt8, &unpkParam->value[optLen], mBuf);  
1545    } 
1546       
1547    return ROK;
1548 } /* end of cmUnpkCmIpv6HBHHdr */
1549
1550 \f
1551 /*
1552 *
1553 *       Fun:   cmUnpkCmIpv6HBHHdrArr
1554 *
1555 *       Desc:  This function unpacks all IPV6 HopByHop options
1556 *
1557 *       Ret:   ROK
1558 *
1559 *       Notes: None
1560 *
1561 *       File:  cm_tpt.c
1562 *
1563 */
1564 S16 cmUnpkCmIpv6HBHHdrArr
1565 (
1566 CmIpv6HBHHdrArr *unpkParam,  /* all HBH options */
1567 Buffer          *mBuf,       /* message buffer */
1568 Mem             *memInfo     /* meminfo to allocate space for HBH opt */
1569 )
1570 {
1571    uint8_t numOptions; 
1572    S16 retVal;
1573
1574
1575    CMCHKUNPK(oduPackUInt8, &unpkParam->numHBHOpts, mBuf);   
1576    if (unpkParam->numHBHOpts)
1577    {
1578       /*  allocate space for all HBH options */
1579       retVal = SGetSBufNewForDebug(__FILE__,__FUNCTION__,__LINE__,memInfo->region,    
1580                      memInfo->pool,                     
1581                      (Data **)&unpkParam->hbhOpts, 
1582                      (unpkParam->numHBHOpts * sizeof(CmIpv6HBHHdr)));
1583       
1584       if (retVal != ROK)
1585       {
1586          return (ROUTRES);
1587       }
1588
1589       for(numOptions = 0; numOptions<unpkParam->numHBHOpts; numOptions++)
1590          cmUnpkCmIpv6HBHHdr(&unpkParam->hbhOpts[numOptions], mBuf, memInfo);
1591    }                                              
1592    return ROK;
1593 } /* end of cmUnpkCmIpv6HBHHdrArr */
1594 #endif /* IPV6_OPTS_SUPPORTED */
1595
1596 \f  
1597 /*
1598 *
1599 *       Fun:   cmUnpkCmIPHdrParm
1600 *
1601 *       Desc:  This function unpacks the IP header parameters
1602 *
1603 *       Ret:   ROK
1604 *
1605 *       Notes: None
1606 *
1607 *       File:  cm_tpt.c
1608 *
1609 */
1610 /* added */
1611 #ifdef IPV6_OPTS_SUPPORTED
1612 S16 cmUnpkCmIpHdrParm
1613 (
1614 CmIpHdrParm              *unpkParam,/* ip hdr parameters */
1615 Buffer                   *mBuf,     /* message buffer */
1616 Mem                      *memInfo   /* meminfo to allocate mem for ipHdrParam */
1617 )
1618 #else
1619 S16 cmUnpkCmIpHdrParm
1620 (
1621 CmIpHdrParm              *unpkParam,/* ip hdr parameters */
1622 Buffer                   *mBuf     /* message buffer */
1623 )
1624 #endif /* IPV6_OPTS_SUPPORTED */
1625 {
1626
1627    CMCHKUNPK(oduPackUInt8, &unpkParam->type, mBuf);
1628
1629    switch (unpkParam->type)
1630    {
1631       case CM_HDRPARM_NOTPRSNT:
1632       case CM_HDRPARM_ICMP6:
1633          break;
1634
1635       case CM_HDRPARM_IPV4:
1636          CMCHKUNPK(cmUnpkTknUInt8, &unpkParam->u.hdrParmIpv4.proto, mBuf);
1637          CMCHKUNPK(cmUnpkTknUInt8, &unpkParam->u.hdrParmIpv4.dfBit, mBuf);
1638          CMCHKUNPK(cmUnpkTknUInt8, &unpkParam->u.hdrParmIpv4.tos, mBuf);
1639          CMCHKUNPK(cmUnpkTknUInt8, &unpkParam->u.hdrParmIpv4.ttl, mBuf);
1640 #ifdef IPV4_OPTS_SUPPORTED
1641          CMCHKUNPK(cmUnpkTknStr64, &unpkParam->u.hdrParmIpv4.ipv4HdrOpt, mBuf);
1642 #endif /* IPV4_OPTS_SUPPORTED */
1643          break;
1644
1645       case CM_HDRPARM_IPV6:
1646 #ifdef IPV6_SUPPORTED         
1647          CMCHKUNPK(cmUnpkTknUInt8, &unpkParam->u.hdrParmIpv6.ttl, mBuf);
1648    
1649          CMCHKUNPK(cmUnpkCmNetAddr, 
1650                    &unpkParam->u.hdrParmIpv6.srcAddr6, mBuf);
1651  
1652 #ifdef IPV6_OPTS_SUPPORTED
1653          /* memInfo is passed forward to alloc mem to hold unpacked 
1654           * IPV6 etx hdr data */
1655          cmUnpkCmIpv6ExtHdr(&unpkParam->u.hdrParmIpv6.ipv6ExtHdr, 
1656                             mBuf, memInfo);
1657 #endif /* IPV6_OPTS_SUPPORTED */         
1658 #endif /* IPV6_SUPPORTED */
1659          break;
1660    
1661       default:
1662          return RFAILED;
1663    }
1664    
1665    return ROK;
1666 }   /* End of cmUnpkCmIpHdrParm */
1667
1668 \f
1669 /*
1670 *
1671 *       Fun:   cmPkCmIcmpFilter
1672 *
1673 *       Desc:  This function packs the ICMP filter parameters
1674 *
1675 *       Ret:   ROK
1676 *
1677 *       Notes: None
1678 *
1679 *       File:  cm_tpt.c
1680 *
1681 */
1682 S16 cmPkCmIcmpFilter
1683 (
1684 CmIcmpFilter *pkParam,   
1685 Buffer       *mBuf       /* message buffer */
1686 )
1687 {
1688    /* Variable declaration */
1689    S16   idx;
1690   
1691
1692    switch (pkParam->type)
1693    {
1694       case CM_ICMP_NO_FILTER:
1695          break;
1696
1697       case CM_ICMPVER4_FILTER:
1698          for(idx = (pkParam->u.icmpv4Filter.num-1); idx >= 0; idx--)
1699          {
1700             CMCHKPK(oduUnpackUInt32, pkParam->u.icmpv4Filter.icmpError[idx].errCodeMask,
1701                     mBuf);
1702             CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv4Filter.icmpError[idx].errType,
1703                     mBuf);
1704          }
1705          CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv4Filter.num, mBuf);
1706          CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv4Filter.protocol, mBuf);
1707          CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv4Filter.allMsg, mBuf);
1708          CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv4Filter.icmpMsgFlag, mBuf);
1709          break;
1710
1711       case CM_ICMPVER6_FILTER:
1712      /* The structure is yet to be decided */
1713      /* CMCHKPK(cmPkCmIpv6HdrParm, &pkParam->u.ipv6HdrParm, mBuf); */
1714 #ifdef IPV6_SUPPORTED
1715          for(idx = (pkParam->u.icmpv6Filter.num - 1); idx >= 0; idx--)
1716          {
1717             CMCHKPK(oduUnpackUInt32, pkParam->u.icmpv6Filter.icmpError[idx].errCodeMask,
1718                     mBuf);
1719             CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv6Filter.icmpError[idx].errType,
1720                     mBuf);
1721          }
1722          CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv6Filter.num, mBuf);
1723          CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv4Filter.allMsg, mBuf); 
1724          CMCHKPK(oduUnpackUInt8, pkParam->u.icmpv4Filter.icmpMsgFlag, mBuf);
1725 #endif /* IPV6_SUPPORTED */
1726          break;
1727    
1728       default:
1729          return RFAILED;
1730    }
1731    CMCHKPK(oduUnpackUInt8, pkParam->type, mBuf);
1732
1733    return ROK;
1734 }
1735
1736 \f  
1737 /*
1738 *
1739 *       Fun:   cmUnpkCmIcmpFilter
1740 *
1741 *       Desc:  This function unpacks the 
1742 *
1743 *       Ret:   ROK
1744 *
1745 *       Notes: None
1746 *
1747 *       File:  cm_tpt.c
1748 *
1749 */
1750 S16 cmUnpkCmIcmpFilter
1751 (
1752 CmIcmpFilter *unpkParam,   
1753 Buffer       *mBuf         /* message buffer */
1754 )
1755 {
1756    /* Variable declaration */ 
1757    S16     idx;
1758
1759    CMCHKUNPK(oduPackUInt8, &unpkParam->type, mBuf);
1760
1761    switch (unpkParam->type)
1762    {
1763       case CM_ICMP_NO_FILTER:
1764          break;
1765
1766       case CM_ICMPVER4_FILTER:
1767          CMCHKUNPK(oduPackUInt8, &unpkParam->u.icmpv4Filter.icmpMsgFlag, mBuf);
1768          CMCHKUNPK(oduPackUInt8, &unpkParam->u.icmpv4Filter.allMsg, mBuf);
1769          CMCHKUNPK(oduPackUInt8, &unpkParam->u.icmpv4Filter.protocol, mBuf);
1770          CMCHKUNPK(oduPackUInt8, &unpkParam->u.icmpv4Filter.num, mBuf);
1771
1772          for(idx = 0; idx < (unpkParam->u.icmpv4Filter.num); idx++)
1773          {
1774             CMCHKUNPK(oduPackUInt8, 
1775                       &unpkParam->u.icmpv4Filter.icmpError[idx].errType, mBuf);
1776             CMCHKUNPK(oduPackUInt32, 
1777                       &unpkParam->u.icmpv4Filter.icmpError[idx].errCodeMask, 
1778                       mBuf);
1779          }
1780          break;
1781
1782       case CM_ICMPVER6_FILTER:
1783 #ifdef IPV6_SUPPORTED
1784          CMCHKUNPK(oduPackUInt8, &unpkParam->u.icmpv6Filter.icmpMsgFlag, mBuf);
1785          CMCHKUNPK(oduPackUInt8, &unpkParam->u.icmpv6Filter.allMsg, mBuf); 
1786          CMCHKUNPK(oduPackUInt8, &unpkParam->u.icmpv6Filter.num, mBuf);
1787
1788          for(idx = 0; idx < (unpkParam->u.icmpv6Filter.num); idx++)
1789          {
1790             CMCHKUNPK(oduPackUInt8, 
1791                       &unpkParam->u.icmpv6Filter.icmpError[idx].errType, mBuf);
1792             CMCHKUNPK(oduPackUInt32, 
1793                       &unpkParam->u.icmpv6Filter.icmpError[idx].errCodeMask, 
1794                       mBuf);
1795          }
1796 #endif /* IPV6_SUPPORTED */
1797          break;
1798    
1799       default:
1800          return RFAILED;
1801
1802    }
1803    
1804    return ROK;
1805 }   /* End of cmUnpkCmIcmpFilter */
1806
1807 #endif  /* CM_INET2 */ 
1808
1809 \f  
1810 #endif /* if(LCHCT || LCHIT || LCLHC || LCHRT || LCLHR) */
1811
1812 \f  
1813 /********************************************************************30**
1814          End of file
1815 *********************************************************************31*/