Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/bin/backend/sys_tool.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/bin/backend/sys_tool.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/bin/backend/sys_tool.c	(working copy)
@@ -200,6 +200,7 @@
 static char *write_aaa_session(char *segment);
 static char *write_aaa_sso(char *segment);
 static char *write_qos(char *segment) ;
+static char *write_h323_nat_config(char *segment) ;
 static char *write_dpi(char *segment);
 static char *write_segment(char *segment);
 /*vxlan_support*/
@@ -1091,6 +1092,12 @@
 	},
 	/* end add zhangjz */
     {
+        write_h323_nat_config,
+        CMD_NORMAL|CMD_ARRAYOS,
+        "#h323 nat configuration"
+    },
+
+    {
         write_qos,
         CMD_NORMAL|CMD_ARRAYOS,
         "#Qos configuration"
@@ -10721,6 +10728,18 @@
 	return 0;
 }
 
+static char *write_h323_nat_config(char *segment) 
+{
+	char *buf = NULL;
+	int  len;
+
+	if (write_h323_nat_config_kern((void **) &buf, &len) < 0) {
+		return NULL;
+	}
+
+	return buf;
+}
+
 /* Bug 14949(QoS), luozy, 20070412 */
 static char *write_qos(char *segment) 
 {
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/ANY.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/ANY.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/ANY.c	(working copy)
@@ -234,7 +234,8 @@
 		return 0;
 	}
 
-	rval = aper_decode(0, td, (void **)&newst, st->buf, st->size, 0, 0);
+        
+	rval = aper_decode(0, td, (void **)&newst, st->buf, st->size, 0, 0, NULL);
 	if(rval.code == RC_OK) {
 		*struct_ptr = newst;
 		return 0;
@@ -269,7 +270,7 @@
 ANY_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                 const asn_TYPE_descriptor_t *td,
                 const asn_per_constraints_t *constraints, void **sptr,
-                asn_per_data_t *pd) {
+                asn_per_data_t *pd, h323_info_t *h323_info) {
     const asn_OCTET_STRING_specifics_t *specs =
         td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
                       : &asn_SPC_ANY_specs;
@@ -360,7 +361,7 @@
 ANY_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                 const asn_TYPE_descriptor_t *td,
                 const asn_per_constraints_t *constraints, void **sptr,
-                asn_per_data_t *pd) {
+                asn_per_data_t *pd, h323_info_t *h323_info) {
     const asn_OCTET_STRING_specifics_t *specs =
         td->specifics ? (const asn_OCTET_STRING_specifics_t *)td->specifics
                       : &asn_SPC_ANY_specs;
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/BIT_STRING.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/BIT_STRING.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/BIT_STRING.c	(working copy)
@@ -322,7 +322,7 @@
 BIT_STRING_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                        const asn_TYPE_descriptor_t *td,
                        const asn_per_constraints_t *constraints, void **sptr,
-                       asn_per_data_t *pd) {
+                       asn_per_data_t *pd, h323_info_t *h323_info) {
     const asn_OCTET_STRING_specifics_t *specs = td->specifics
 		? (const asn_OCTET_STRING_specifics_t *)td->specifics
 		: &asn_SPC_BIT_STRING_specs;
@@ -355,7 +355,7 @@
 		if(!st) RETURN(RC_FAIL);
 	}
 
-	ASN_DEBUG("PER Decoding %s size %ld .. %ld bits %d",
+	ASN_DEBUG("BIT_STRING PER Decoding %s size %ld .. %ld bits %d",
 		csiz->flags & APC_EXTENSIBLE ? "extensible" : "non-extensible",
 		csiz->lower_bound, csiz->upper_bound, csiz->effective_bits);
 
@@ -402,7 +402,7 @@
 		if(raw_len < 0) RETURN(RC_WMORE);
         if(raw_len == 0 && st->buf) break;
 
-		ASN_DEBUG("STR Got PER length eb %ld, len %ld, %s (%s)",
+		ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)",
 			(long)csiz->effective_bits, (long)raw_len,
 			repeat ? "repeat" : "once", td->name);
         len_bits = raw_len;
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/BOOLEAN.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/BOOLEAN.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/BOOLEAN.c	(working copy)
@@ -267,7 +267,7 @@
 BOOLEAN_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                     const asn_TYPE_descriptor_t *td,
                     const asn_per_constraints_t *constraints, void **sptr,
-                    asn_per_data_t *pd) {
+                    asn_per_data_t *pd, h323_info_t *h323_info) {
     asn_dec_rval_t rv;
 	BOOLEAN_t *st = (BOOLEAN_t *)*sptr;
 
@@ -316,7 +316,7 @@
 
 asn_dec_rval_t
 BOOLEAN_decode_aper(const asn_codec_ctx_t *opt_codec_ctx, const asn_TYPE_descriptor_t *td,
-                    const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+                    const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 	asn_dec_rval_t rv;
 	BOOLEAN_t *st = (BOOLEAN_t *)*sptr;
 
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/H2250LogicalChannelParameters.h
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/H2250LogicalChannelParameters.h	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/H2250LogicalChannelParameters.h	(working copy)
@@ -20,6 +20,7 @@
 #include <constr_CHOICE.h>
 #include <constr_SEQUENCE.h>
 
+#include "MULTIMEDIA-SYSTEM-CONTROL_TransportAddress.h"
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -33,7 +34,7 @@
 } H2250LogicalChannelParameters__mediaPacketization_PR;
 
 /* Forward declarations */
-struct TransportAddress;
+//struct TransportAddress;
 struct TerminalLabel;
 struct TransportCapability;
 struct RedundancyEncoding;
@@ -94,7 +95,7 @@
 #endif
 
 /* Referred external types */
-#include "MULTIMEDIA-SYSTEM-CONTROL_TransportAddress.h"
+//#include "MULTIMEDIA-SYSTEM-CONTROL_TransportAddress.h"
 #include "TerminalLabel.h"
 #include "TransportCapability.h"
 #include "RedundancyEncoding.h"
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/INTEGER.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/INTEGER.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/INTEGER.c	(working copy)
@@ -591,7 +591,7 @@
 INTEGER_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                     const asn_TYPE_descriptor_t *td,
                     const asn_per_constraints_t *constraints, void **sptr,
-                    asn_per_data_t *pd) {
+                    asn_per_data_t *pd, h323_info_t *h323_info) {
     const asn_INTEGER_specifics_t *specs =
         (const asn_INTEGER_specifics_t *)td->specifics;
     asn_dec_rval_t rval = { RC_OK, 0 };
@@ -808,7 +808,7 @@
 asn_dec_rval_t
 INTEGER_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                     const asn_TYPE_descriptor_t *td,
-                    const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+                    const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 	const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
 	asn_dec_rval_t rval = { RC_OK, 0 };
 	INTEGER_t *st = (INTEGER_t *)*sptr;
@@ -817,6 +817,9 @@
 
 	(void)opt_codec_ctx;
 
+#ifdef DEBUG_LOG
+        printf ("THIS CALLED INTEGER_decode_aper for port\n\n");
+#endif
 	if(!st) {
 		st = (INTEGER_t *)(*sptr = CALLOC(1, sizeof(*st)));
 		if(!st) ASN__DECODE_FAILED;
@@ -886,7 +889,7 @@
 				        ? asn_uint642INTEGER(st, (unsigned long)value)
 				        : asn_int642INTEGER(st, value))
 					ASN__DECODE_FAILED;
-				ASN_DEBUG("Got value %ld + low %ld",
+				ASN_DEBUG("Got value1 %ld + low %ld",
 				          value, ct->lower_bound);
 			} else {
 				long value = 0;
@@ -910,7 +913,7 @@
 				        ? asn_ulong2INTEGER(st, value)
 				        : asn_long2INTEGER(st, value))
 					ASN__DECODE_FAILED;
-				ASN_DEBUG("Got value %ld + low %ld",
+				ASN_DEBUG("Got value2 %ld + low %ld",
 				          value, ct->lower_bound);
 			}
 			return rval;
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/Makefile
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/Makefile	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/Makefile	(working copy)
@@ -1,25 +1,13 @@
-.include "Makefile.am.libasncodec"
+include Makefile.am.libasncodec
 
-SRCS= ${ASN_MODULE_SRCS}
-LIB= asncodec
+#LIB=  asncodec 
 
-LDADD+= -lm
-CFLAGS+= $(ASN_MODULE_CFLAGS) -DASN_EMIT_DEBUG=1 -DASN_PDU_COLLECTION -I.
-INCS = $(ASN_MODULE_HDRS)
+CFLAGS+=$(ASN_MODULE_CFLAGS) -DASN_EMIT_DEBUG=1 -DDEBUG_LOG -DASN_PDU_COLLECTION
 
-PROG_CFLAGS= -I. -I asn1c_skeletons
-PROG_LDADD= -L. -lasncodec
+.if defined(USTACK)
+CFLAGS+=-g -fPIC
+.endif
 
-TEST1 = test/parse_connect_msg
-TEST2 = test/parse_setup_msg
-$(TEST1): test/parse_connect_msg.c lib$(LIB).a
-	$(CC) -o test/parse_connect_msg test/parse_connect_msg.c $(CFLAGS) $(PROG_CFLAGS) $(PROG_LDADD) $(LDADD)
+CFLAGS+=-I${.CURDIR}
 
-$(TEST2): test/parse_setup_msg.c lib$(LIB).a
-	$(CC) -o test/parse_setup_msg test/parse_setup_msg.c $(CFLAGS) $(PROG_CFLAGS) $(PROG_LDADD) $(LDADD)
-
-all: lib${LIB}.a ${TEST1} $(TEST2)
-
-clean:
-	rm -f lib${LIB}.a ${TEST1} $(TEST2) *.o
 .include <bsd.lib.mk>
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/Makefile.am.libasncodec
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/Makefile.am.libasncodec	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/Makefile.am.libasncodec	(working copy)
@@ -1,4 +1,5 @@
-ASN_MODULE_SRCS=	\
+LIB=    asncodec
+SRCS=	\
 	H323-UserInformation.c	\
 	H323-UU-PDU.c	\
 	StimulusControl.c	\
@@ -483,7 +484,8 @@
 	FlowControlIndication.c	\
 	MobileMultilinkReconfigurationIndication.c
 
-ASN_MODULE_HDRS=	\
+INCS=	\
+	common.h \
 	H323-UserInformation.h	\
 	H323-UU-PDU.h	\
 	StimulusControl.h	\
@@ -968,94 +970,90 @@
 	FlowControlIndication.h	\
 	MobileMultilinkReconfigurationIndication.h
 
-ASN_MODULE_HDRS+=ANY.h
-ASN_MODULE_SRCS+=ANY.c
-ASN_MODULE_HDRS+=OCTET_STRING.h
-ASN_MODULE_HDRS+=OPEN_TYPE.h
-ASN_MODULE_SRCS+=OPEN_TYPE.c
-ASN_MODULE_HDRS+=constr_CHOICE.h
-ASN_MODULE_HDRS+=BMPString.h
-ASN_MODULE_SRCS+=BMPString.c
-ASN_MODULE_HDRS+=UTF8String.h
-ASN_MODULE_HDRS+=BOOLEAN.h
-ASN_MODULE_SRCS+=BOOLEAN.c
-ASN_MODULE_HDRS+=GeneralString.h
-ASN_MODULE_SRCS+=GeneralString.c
-ASN_MODULE_HDRS+=IA5String.h
-ASN_MODULE_SRCS+=IA5String.c
-ASN_MODULE_HDRS+=INTEGER.h
-ASN_MODULE_SRCS+=INTEGER.c
-ASN_MODULE_HDRS+=NULL.h
-ASN_MODULE_SRCS+=NULL.c
-ASN_MODULE_HDRS+=NativeEnumerated.h
-ASN_MODULE_SRCS+=NativeEnumerated.c
-ASN_MODULE_HDRS+=NativeInteger.h
-ASN_MODULE_SRCS+=NativeInteger.c
-ASN_MODULE_HDRS+=NumericString.h
-ASN_MODULE_SRCS+=NumericString.c
-ASN_MODULE_HDRS+=OBJECT_IDENTIFIER.h
-ASN_MODULE_SRCS+=OBJECT_IDENTIFIER.c
-ASN_MODULE_HDRS+=PrintableString.h
-ASN_MODULE_SRCS+=PrintableString.c
-ASN_MODULE_SRCS+=UTF8String.c
-ASN_MODULE_HDRS+=asn_SEQUENCE_OF.h
-ASN_MODULE_SRCS+=asn_SEQUENCE_OF.c
-ASN_MODULE_HDRS+=asn_SET_OF.h
-ASN_MODULE_SRCS+=asn_SET_OF.c
-ASN_MODULE_SRCS+=constr_CHOICE.c
-ASN_MODULE_HDRS+=constr_SEQUENCE.h
-ASN_MODULE_SRCS+=constr_SEQUENCE.c
-ASN_MODULE_HDRS+=constr_SEQUENCE_OF.h
-ASN_MODULE_SRCS+=constr_SEQUENCE_OF.c
-ASN_MODULE_HDRS+=constr_SET_OF.h
-ASN_MODULE_SRCS+=constr_SET_OF.c
-ASN_MODULE_HDRS+=asn_application.h
-ASN_MODULE_SRCS+=asn_application.c
-ASN_MODULE_HDRS+=asn_ioc.h
-ASN_MODULE_HDRS+=asn_system.h
-ASN_MODULE_HDRS+=asn_codecs.h
-ASN_MODULE_HDRS+=asn_internal.h
-ASN_MODULE_SRCS+=asn_internal.c
-ASN_MODULE_HDRS+=asn_random_fill.h
-ASN_MODULE_SRCS+=asn_random_fill.c
-ASN_MODULE_HDRS+=asn_bit_data.h
-ASN_MODULE_SRCS+=asn_bit_data.c
-ASN_MODULE_SRCS+=OCTET_STRING.c
-ASN_MODULE_HDRS+=BIT_STRING.h
-ASN_MODULE_SRCS+=BIT_STRING.c
-ASN_MODULE_SRCS+=asn_codecs_prim.c
-ASN_MODULE_HDRS+=asn_codecs_prim.h
-ASN_MODULE_HDRS+=ber_tlv_length.h
-ASN_MODULE_SRCS+=ber_tlv_length.c
-ASN_MODULE_HDRS+=ber_tlv_tag.h
-ASN_MODULE_SRCS+=ber_tlv_tag.c
-ASN_MODULE_HDRS+=ber_decoder.h
-ASN_MODULE_SRCS+=ber_decoder.c
-ASN_MODULE_HDRS+=der_encoder.h
-ASN_MODULE_SRCS+=der_encoder.c
-ASN_MODULE_HDRS+=constr_TYPE.h
-ASN_MODULE_SRCS+=constr_TYPE.c
-ASN_MODULE_HDRS+=constraints.h
-ASN_MODULE_SRCS+=constraints.c
-ASN_MODULE_HDRS+=xer_support.h
-ASN_MODULE_SRCS+=xer_support.c
-ASN_MODULE_HDRS+=xer_decoder.h
-ASN_MODULE_SRCS+=xer_decoder.c
-ASN_MODULE_HDRS+=xer_encoder.h
-ASN_MODULE_SRCS+=xer_encoder.c
-ASN_MODULE_HDRS+=per_support.h
-ASN_MODULE_SRCS+=per_support.c
-ASN_MODULE_HDRS+=per_decoder.h
-ASN_MODULE_SRCS+=per_decoder.c
-ASN_MODULE_HDRS+=per_encoder.h
-ASN_MODULE_SRCS+=per_encoder.c
-ASN_MODULE_HDRS+=per_opentype.h
-ASN_MODULE_SRCS+=per_opentype.c
+INCS+=ANY.h
+SRCS+=ANY.c
+INCS+=OCTET_STRING.h
+INCS+=OPEN_TYPE.h
+SRCS+=OPEN_TYPE.c
+INCS+=constr_CHOICE.h
+INCS+=BMPString.h
+SRCS+=BMPString.c
+INCS+=UTF8String.h
+INCS+=BOOLEAN.h
+SRCS+=BOOLEAN.c
+INCS+=GeneralString.h
+SRCS+=GeneralString.c
+INCS+=IA5String.h
+SRCS+=IA5String.c
+INCS+=INTEGER.h
+SRCS+=INTEGER.c
+INCS+=NULL.h
+SRCS+=NULL.c
+INCS+=NativeEnumerated.h
+SRCS+=NativeEnumerated.c
+INCS+=NativeInteger.h
+SRCS+=NativeInteger.c
+INCS+=NumericString.h
+SRCS+=NumericString.c
+INCS+=OBJECT_IDENTIFIER.h
+SRCS+=OBJECT_IDENTIFIER.c
+INCS+=PrintableString.h
+SRCS+=PrintableString.c
+SRCS+=UTF8String.c
+INCS+=asn_SEQUENCE_OF.h
+SRCS+=asn_SEQUENCE_OF.c
+INCS+=asn_SET_OF.h
+SRCS+=asn_SET_OF.c
+SRCS+=constr_CHOICE.c
+INCS+=constr_SEQUENCE.h
+SRCS+=constr_SEQUENCE.c
+INCS+=constr_SEQUENCE_OF.h
+SRCS+=constr_SEQUENCE_OF.c
+INCS+=constr_SET_OF.h
+SRCS+=constr_SET_OF.c
+INCS+=asn_application.h
+SRCS+=asn_application.c
+INCS+=asn_ioc.h
+INCS+=asn_system.h
+INCS+=asn_codecs.h
+INCS+=asn_internal.h
+SRCS+=asn_internal.c
+INCS+=asn_random_fill.h
+SRCS+=asn_random_fill.c
+INCS+=asn_bit_data.h
+SRCS+=asn_bit_data.c
+SRCS+=OCTET_STRING.c
+INCS+=BIT_STRING.h
+SRCS+=BIT_STRING.c
+SRCS+=asn_codecs_prim.c
+INCS+=asn_codecs_prim.h
+INCS+=ber_tlv_length.h
+SRCS+=ber_tlv_length.c
+INCS+=ber_tlv_tag.h
+SRCS+=ber_tlv_tag.c
+INCS+=ber_decoder.h
+SRCS+=ber_decoder.c
+INCS+=der_encoder.h
+SRCS+=der_encoder.c
+INCS+=constr_TYPE.h
+SRCS+=constr_TYPE.c
+INCS+=constraints.h
+SRCS+=constraints.c
+INCS+=xer_support.h
+SRCS+=xer_support.c
+INCS+=xer_decoder.h
+SRCS+=xer_decoder.c
+INCS+=xer_encoder.h
+SRCS+=xer_encoder.c
+INCS+=per_support.h
+SRCS+=per_support.c
+INCS+=per_decoder.h
+SRCS+=per_decoder.c
+INCS+=per_encoder.h
+SRCS+=per_encoder.c
+INCS+=per_opentype.h
+SRCS+=per_opentype.c
 
-ASN_MODULE_CFLAGS=-DASN_DISABLE_OER_SUPPORT 
+SRCS+=atcp_h323_integration.c
 
-lib_LTLIBRARIES+=libasncodec.la
-libasncodec_la_SOURCES=$(ASN_MODULE_SRCS) $(ASN_MODULE_HDRS)
-libasncodec_la_CPPFLAGS=-I$(top_srcdir)/
-libasncodec_la_CFLAGS=$(ASN_MODULE_CFLAGS)
-libasncodec_la_LDFLAGS=-lm
+ASN_MODULE_CFLAGS=-DASN_DISABLE_OER_SUPPORT 
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NULL.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NULL.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NULL.c	(working copy)
@@ -185,7 +185,7 @@
 NULL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                  const asn_TYPE_descriptor_t *td,
                  const asn_per_constraints_t *constraints, void **sptr,
-                 asn_per_data_t *pd) {
+                 asn_per_data_t *pd, h323_info_t *h323_info) {
     asn_dec_rval_t rv;
 
 	(void)opt_codec_ctx;
@@ -229,7 +229,7 @@
 asn_dec_rval_t
 NULL_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                  const asn_TYPE_descriptor_t *td,
-                 const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+                 const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 	asn_dec_rval_t rv;
 
 	(void)opt_codec_ctx;
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NativeEnumerated.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NativeEnumerated.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NativeEnumerated.c	(working copy)
@@ -93,7 +93,7 @@
 NativeEnumerated_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                              const asn_TYPE_descriptor_t *td,
                              const asn_per_constraints_t *constraints,
-                             void **sptr, asn_per_data_t *pd) {
+                             void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
     const asn_INTEGER_specifics_t *specs = td->specifics;
     asn_dec_rval_t rval = { RC_OK, 0 };
 	long *native = (long *)*sptr;
@@ -232,7 +232,7 @@
 NativeEnumerated_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                              const asn_TYPE_descriptor_t *td,
                              const asn_per_constraints_t *constraints,
-                             void **sptr, asn_per_data_t *pd) {
+                             void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 	const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
 	asn_dec_rval_t rval = { RC_OK, 0 };
 	long *native = (long *)*sptr;
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NativeInteger.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NativeInteger.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/NativeInteger.c	(working copy)
@@ -260,7 +260,7 @@
 NativeInteger_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                           const asn_TYPE_descriptor_t *td,
                           const asn_per_constraints_t *constraints, void **sptr,
-                          asn_per_data_t *pd) {
+                          asn_per_data_t *pd, h323_info_t *h323_info) {
     const asn_INTEGER_specifics_t *specs =
         (const asn_INTEGER_specifics_t *)td->specifics;
     asn_dec_rval_t rval;
@@ -278,7 +278,7 @@
 
 	memset(&tmpint, 0, sizeof tmpint);
 	rval = INTEGER_decode_uper(opt_codec_ctx, td, constraints,
-				   &tmpintptr, pd);
+				   &tmpintptr, pd, h323_info);
 	if(rval.code == RC_OK) {
 		if((specs&&specs->field_unsigned)
 			? asn_INTEGER2ulong(&tmpint, (unsigned long *)native)
@@ -322,7 +322,7 @@
 asn_dec_rval_t
 NativeInteger_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                           const asn_TYPE_descriptor_t *td,
-                          const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+                          const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 
 	const asn_INTEGER_specifics_t *specs = (const asn_INTEGER_specifics_t *)td->specifics;
 	asn_dec_rval_t rval;
@@ -340,7 +340,7 @@
 
 	memset(&tmpint, 0, sizeof tmpint);
 	rval = INTEGER_decode_aper(opt_codec_ctx, td, constraints,
-	                           &tmpintptr, pd);
+	                           &tmpintptr, pd, h323_info);
 	if(rval.code == RC_OK) {
 		if((specs&&specs->field_unsigned)
 		        ? asn_INTEGER2ulong(&tmpint, (unsigned long *)native)
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/OCTET_STRING.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/OCTET_STRING.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/OCTET_STRING.c	(working copy)
@@ -8,6 +8,8 @@
 #include <BIT_STRING.h>	/* for .bits_unused member */
 #include <errno.h>
 
+
+#define H245_OPEN_CHANNEL_ACK_ADDR_OFFSET 2
 /*
  * OCTET STRING basic type description.
  */
@@ -1220,9 +1222,9 @@
 		size_t units, unsigned int bpc, unsigned int unit_bits,
 		long lb, long ub, const asn_per_constraints_t *pc) {
 	uint8_t *end = buf + units * bpc;
-        int ret;
+        int return_val;
 
-	ASN_DEBUG("thExpanding %d characters into (%ld..%ld):%d",
+	ASN_DEBUG("Expanding %d characters into (%ld..%ld):%d",
 		(int)units, lb, ub, unit_bits);
 
 	/* X.691: 27.5.4 */
@@ -1231,7 +1233,6 @@
 		lb = 0;
 	} else if(pc && pc->code2value) {
 		if(unit_bits > 16)
-                        printf ("return1\n");
 			return 1;	/* FATAL: can't have constrained
 					 * UniversalString with more than
 					 * 16 million code points */
@@ -1244,7 +1245,6 @@
 				ASN_DEBUG("Code %d (0x%02x) is"
 					" not in map (%ld..%ld)",
 					code, code, lb, ub);
-                                printf ("ret here2\n");
 				return 1;	/* FATAL */
 			}
 			switch(bpc) {
@@ -1254,16 +1254,27 @@
 				buf[2] = value >> 8; buf[3] = value; break;
 			}
 		}
-        printf ("this buf2 : %s\n", buf);
+#ifdef DEBUG_LOG
+                ASN_DEBUG("returning here zero\n");
+#endif
 		return 0;
 	}
 
 	/* Shortcut the no-op copying to the aligned structure */
 	if(lb == 0 && (unit_bits == 8 * bpc)) {
-                printf ("return from her\n");
-		ret = per_get_many_bits(po, buf, 0, unit_bits * units); //ACP
-                buf[0] = 0x09;
-                return 0;
+#ifdef DEBUG_LOG
+                ASN_DEBUG("calling per_get_many_bits and returing : unit_bits : %d\n units %d\n", unit_bits, units); //4 units
+                ASN_DEBUG ("before buffer data %x.%x.%x.%x\n", po->buffer[0], po->buffer[1], po->buffer[2], po->buffer[3]);
+#endif
+//DELETE BELOW
+//              po->buffer[1] = 0x12;
+
+		return_val =  per_get_many_bits(po, buf, 0, unit_bits * units);
+#ifdef DEBUG_LOG
+                ASN_DEBUG("received value : %d\n", return_val);
+                ASN_DEBUG ("after buffer data %x.%x.%x.%x\n", po->buffer[-3], po->buffer[-2], po->buffer[-1], po->buffer[0]);
+#endif
+                return return_val;
 	}
 
 	for(; buf < end; buf += bpc) {
@@ -1282,7 +1293,6 @@
 			buf[2] = ch >> 8; buf[3] = ch; break;
 		}
 	}
-        printf ("this buf : %s\n", buf);
 
 	return 0;
 }
@@ -1366,7 +1376,7 @@
 OCTET_STRING_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                          const asn_TYPE_descriptor_t *td,
                          const asn_per_constraints_t *constraints, void **sptr,
-                         asn_per_data_t *pd) {
+                         asn_per_data_t *pd, h323_info_t *h323_info) {
     const asn_OCTET_STRING_specifics_t *specs = td->specifics
 		? (const asn_OCTET_STRING_specifics_t *)td->specifics
 		: &asn_SPC_OCTET_STRING_specs;
@@ -1492,7 +1502,7 @@
 		if(raw_len < 0) RETURN(RC_WMORE);
 		if(raw_len == 0 && st->buf) break;
 
-		ASN_DEBUG("OCT STR Got PER length eb %ld, len %ld, %s (%s)",
+		ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)",
 			(long)csiz->effective_bits, (long)raw_len,
 			repeat ? "repeat" : "once", td->name);
         len_bytes = raw_len * bpc;
@@ -1659,7 +1669,7 @@
 OCTET_STRING_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                          const asn_TYPE_descriptor_t *td,
                          const asn_per_constraints_t *constraints,
-                         void **sptr, asn_per_data_t *pd) {
+                         void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 
 	const asn_OCTET_STRING_specifics_t *specs = td->specifics
 		? (const asn_OCTET_STRING_specifics_t *)td->specifics
@@ -1766,6 +1776,26 @@
 				RETURN(RC_FAIL);
 		}
 		if(bpc) {
+
+                        if (h323_info && h323_info->type == MSG_TYPE_H245_OPEN_CHANNEL_ACK && h323_info->status == ENABLE_H245_OPEN_CHANNEL_ACK_PAYLOAD_UPDATE) {
+
+                            printf ("Decoding H245 OpenLogicChannelAck packet. Replacing 'internal IP' with 'NAT IP' : %x\n", h323_info->ip);
+                            printf ("intenal IP : %x:%x:%x:%x\n", pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET], pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 1], pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 2], pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 3]);
+                            printf ("intenal IP2 : %x:%x:%x:%x\n", pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 7], pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 8], pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 9], pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 10]);
+                            //mediaChannel
+                            pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET] = (h323_info->ip >> 24) & 0xFF;
+                            pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 1] = (h323_info->ip >> 16) & 0xFF;
+                            pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 2] = (h323_info->ip >> 8) & 0xFF;
+                            pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 3] = h323_info->ip  & 0xFF;
+
+                            //mediaControlChannel
+                            pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 7] = (h323_info->ip >> 24) & 0xFF;
+                            pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 8] = (h323_info->ip >> 16) & 0xFF;
+                            pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 9] = (h323_info->ip >> 8) & 0xFF;
+                            pd->buffer[H245_OPEN_CHANNEL_ACK_ADDR_OFFSET + 10] = h323_info->ip  & 0xFF;
+                            h323_info->status = DISABLE_H245_OPEN_CHANNEL_ACK_PAYLOAD_UPDATE;
+                        }
+
 			ASN_DEBUG("Decoding OCTET STRING size %ld",
 				csiz->upper_bound);
 			ret = OCTET_STRING_per_get_characters(pd, st->buf,
@@ -1806,7 +1836,7 @@
 		if(raw_len < 0) RETURN(RC_WMORE);
 		raw_len += csiz->lower_bound;
 
-		ASN_DEBUG("OCT str2 Got PER length eb %ld, len %ld, %s (%s)", //ACP
+		ASN_DEBUG("Got PER length eb %ld, len %ld, %s (%s)",
 			(long)csiz->effective_bits, (long)raw_len,
 			repeat ? "repeat" : "once", td->name);
 
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/OPEN_TYPE.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/OPEN_TYPE.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/OPEN_TYPE.c	(working copy)
@@ -332,7 +332,7 @@
         + elm->type->elements[selected.presence_index - 1].memb_offset;
 
     rv = uper_open_type_get(opt_codec_ctx, selected.type_descriptor, NULL,
-                            &inner_value, pd);
+                            &inner_value, pd, NULL);
     switch(rv.code) {
     case RC_OK:
         if(CHOICE_variant_set_presence(elm->type, *memb_ptr2,
@@ -442,7 +442,7 @@
         + elm->type->elements[selected.presence_index - 1].memb_offset;
 
     rv = aper_open_type_get(opt_codec_ctx, selected.type_descriptor, NULL,
-                            &inner_value, pd);
+                            &inner_value, pd, NULL);
     switch(rv.code) {
     case RC_OK:
         if(CHOICE_variant_set_presence(elm->type, *memb_ptr2,
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_application.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_application.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_application.c	(working copy)
@@ -470,7 +470,7 @@
         errno = ENOENT;
         ASN__DECODE_FAILED;
 #else
-        return aper_decode_complete(opt_codec_ctx, td, sptr, buffer, size);
+        return aper_decode_complete(opt_codec_ctx, td, sptr, buffer, size, NULL);
 #endif
 
     case ATS_BASIC_XER:
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_bit_data.h
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_bit_data.h	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_bit_data.h	(working copy)
@@ -15,7 +15,7 @@
  * This structure describes a position inside an incoming PER bit stream.
  */
 typedef struct asn_bit_data_s {
-  const uint8_t *buffer;  /* Pointer to the octet stream */
+         uint8_t *buffer;  /* Pointer to the octet stream */
          size_t  nboff;   /* Bit offset to the meaningful bit */
          size_t  nbits;   /* Number of bits in the stream */
          size_t  moved;   /* Number of bits moved through this bit stream */
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_bit_data.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_bit_data.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/asn_bit_data.c	(working copy)
@@ -100,7 +100,7 @@
 	pd->nboff += nbits;
 	off = pd->nboff;
 	buf = pd->buffer;
-
+        
 	/*
 	 * Extract specified number of bits.
 	 */
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/atcp_h323_integration.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/atcp_h323_integration.c	(revision 0)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/atcp_h323_integration.c	(working copy)
@@ -0,0 +1,176 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include "Setup-UUIE.h"
+#include "per_decoder.h"
+#include "CallIdentifier.h"
+#include "H323-UserInformation.h"
+#include "OpenLogicalChannel.h"
+#include "OpenLogicalChannelAck.h"
+
+int nat_h323_payload(uint8_t *data, size_t data_len, unsigned long nat_ip, unsigned short nat_port) { 
+
+    h323_info_t h323_info;
+    asn_dec_rval_t rval;
+    int msg_type = MSG_TYPE_INVALID;
+    Setup_UUIE_t *setup_msg = NULL;
+    OpenLogicalChannel_t *open_msg = NULL;
+    H2250LogicalChannelAckParameters_t *open_msg_ack = NULL;
+    int offset = 0;
+    
+    offset = get_h323_offset (data, data_len, &msg_type);
+
+    if (offset >= data_len)
+        return H323_PACKET_NOT_OURS;
+
+    switch (msg_type) {
+        case MSG_TYPE_SETUP:
+            printf ("Decode H225 Setup. Offset at : %d\n", offset);
+            printf ("length to be decoded : %d\n", data_len - offset);
+            h323_info.type = MSG_TYPE_SETUP;
+            h323_info.status = H225_SETUP_STATUS_INIT;
+            h323_info.ip = nat_ip;
+            h323_info.port = nat_port;
+            rval = aper_decode_complete(NULL, &asn_DEF_Setup_UUIE, (void **)&setup_msg, data + offset, data_len - offset, &h323_info);
+            ASN_STRUCT_FREE(asn_DEF_Setup_UUIE, setup_msg);
+            break;
+
+        case MSG_TYPE_H245_OPEN_CHANNEL:
+            printf ("Decode H245 OpenLogicalChannel. Offset at : %d\n", offset);
+            printf ("length to be decoded : %d\n", data_len - offset);
+            h323_info.type = MSG_TYPE_H245_OPEN_CHANNEL;
+            h323_info.status = H245_OPEN_CHANNEL_STATUS_INIT;
+            h323_info.ip = nat_ip;
+            h323_info.port = nat_port;
+            rval = aper_decode_complete(NULL, &asn_DEF_OpenLogicalChannel, (void **)&open_msg, data + offset, data_len - offset, &h323_info);
+            ASN_STRUCT_FREE(asn_DEF_OpenLogicalChannel, open_msg);
+            break;
+
+        case MSG_TYPE_H245_OPEN_CHANNEL_ACK:
+            printf ("Decode H245 OpenLogicalChannelAck. Offset at : %d\n", offset);
+            printf ("length to be decoded : %d\n", data_len - offset);
+            h323_info.type = MSG_TYPE_H245_OPEN_CHANNEL_ACK;
+            h323_info.status = H245_OPEN_CHANNEL_ACK_STATUS_INIT;
+            h323_info.ip = nat_ip;
+            h323_info.port = nat_port;
+            rval = aper_decode_complete(NULL, &asn_DEF_H2250LogicalChannelAckParameters, (void **)&open_msg_ack, data + offset, data_len - offset, &h323_info);
+            ASN_STRUCT_FREE(asn_DEF_H2250LogicalChannelAckParameters, open_msg_ack);
+            break;
+
+        default: printf ("Invalid H323 message.\n");
+            return H323_PACKET_NOT_OURS;
+    }
+
+    if (rval.code == RC_OK) {
+        printf("H.323 message of type : %d processed successfully!\n", msg_type);
+    } else {
+        printf ("H.323 decoder return code : %d\n", rval.code);
+        printf("Failed to decode H.323 message of type : %d.\n", msg_type);
+        return H323_PACKET_NOT_OURS;
+    }
+}
+
+
+int parse_optional(uint8_t hex_data[], int offset, int len)
+{
+        offset++;
+        offset+=hex_data[offset];
+        offset++;
+        return offset;
+}
+int parse_TPKT(uint8_t hex_data[], int offset, int len)
+{
+        if (hex_data[offset] != TPKT_VERSION_3){
+                printf("Error in parsing. TPKT version 3 not found");
+                return H323_PACKET_NOT_OURS;
+        }
+        offset++;
+        if (hex_data[offset] != TPKT_RESERVED){
+                printf("Error in parsing. TPKT reserved field not found");
+                return H323_PACKET_NOT_OURS;
+        }
+        offset += 2;
+        return offset;
+}
+        
+        
+int parse_mandatory_q931_fields(uint8_t hex_data[], int offset, int len, int *msg_type)
+{
+        if (hex_data[offset] != PROT_DISCRIMIATOR_Q931) {
+                printf("Error in parsing. Q.931 not found");
+                return H323_PACKET_NOT_OURS;
+        }
+        offset++;
+        offset += hex_data[offset];
+        offset++; 
+        if (hex_data[offset] == MSG_TYPE_SETUP){
+                printf("Packet has Setup message type\n");
+                *msg_type = MSG_TYPE_SETUP;
+        }
+        else if (hex_data[offset] == MSG_TYPE_CONNECT){
+                printf("Packet has Connect message type\n");
+                *msg_type = MSG_TYPE_CONNECT;
+        }
+        else {
+                printf("Message type is not SetUp or Connect. Value: %x \n",hex_data[offset]);
+                return H323_PACKET_NOT_OURS;
+        }
+        return offset;
+}
+int get_h323_offset(uint8_t hex_data[], int len, int *msg_type)
+{
+        int offset = 0;
+        int field_len = 0;
+        int section_header = 0;
+
+        offset = parse_TPKT(hex_data, offset, len);
+        if (offset == H323_PACKET_NOT_OURS){
+                return H323_PACKET_NOT_OURS;
+        }
+        offset++;
+
+        if (hex_data[offset] == MSG_TYPE_H245_OPEN_CHANNEL) {
+            offset++;
+            *msg_type = MSG_TYPE_H245_OPEN_CHANNEL; 
+            return offset;
+        }
+        if (hex_data[offset] == MSG_TYPE_H245_OPEN_CHANNEL_ACK) {
+                if (hex_data[offset + 7] == H225_LOGICAL_ACK_PARAM1 || hex_data[offset + 7] == H225_LOGICAL_ACK_PARAM2) {
+                    offset += 7;
+                    *msg_type = MSG_TYPE_H245_OPEN_CHANNEL_ACK; 
+                    return offset;
+                } else {
+                    return H323_PACKET_NOT_OURS;
+                }
+        }
+        
+        offset = parse_mandatory_q931_fields(hex_data, offset, len, msg_type);
+        if (offset == H323_PACKET_NOT_OURS){
+                return H323_PACKET_NOT_OURS;
+        }
+        offset++;
+        section_header = hex_data[offset];
+        while(section_header == IE_BEARER_CAPABILITY || section_header == IE_DISPLAY){
+                offset = parse_optional(hex_data, offset, len);
+                section_header = hex_data[offset];
+        }
+        
+        if (hex_data[offset] == CALLED_PARTY_NUM)
+        {
+            printf ("called party no decoded : %0x\n", hex_data[offset]);
+            offset += 1;
+            offset += hex_data[offset]; //len
+            offset += 1;
+        }
+        if (hex_data[offset] != IE_USER_USER) 
+        {
+                printf("Error while parsing. User-User IE not found. %0x",hex_data[offset]);
+                return H323_PACKET_NOT_OURS;
+        }
+        offset += 4;
+#if 1
+        offset += 1; //skip 0x60
+#endif
+        return offset;
+}
+
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/common.h
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/common.h	(revision 0)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/common.h	(working copy)
@@ -0,0 +1,8 @@
+typedef unsigned char uint8_t;
+typedef unsigned short uint16_t;
+typedef unsigned int uint32_t;
+
+typedef long intmax_t;
+typedef unsigned long uintmax_t;
+typedef unsigned long uint64_t;
+
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_CHOICE.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_CHOICE.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_CHOICE.c	(working copy)
@@ -833,7 +833,7 @@
 CHOICE_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                    const asn_TYPE_descriptor_t *td,
                    const asn_per_constraints_t *constraints, void **sptr,
-                   asn_per_data_t *pd) {
+                   asn_per_data_t *pd, h323_info_t *h323_info) {
     const asn_CHOICE_specifics_t *specs =
         (const asn_CHOICE_specifics_t *)td->specifics;
     asn_dec_rval_t rv;
@@ -904,10 +904,10 @@
 
 	if(ct && ct->range_bits >= 0) {
 		rv = elm->type->op->uper_decoder(opt_codec_ctx, elm->type,
-			elm->encoding_constraints.per_constraints, memb_ptr2, pd);
+			elm->encoding_constraints.per_constraints, memb_ptr2, pd, h323_info);
 	} else {
 		rv = uper_open_type_get(opt_codec_ctx, elm->type,
-			elm->encoding_constraints.per_constraints, memb_ptr2, pd);
+			elm->encoding_constraints.per_constraints, memb_ptr2, pd, h323_info);
 	}
 
 	if(rv.code != RC_OK)
@@ -1013,7 +1013,7 @@
 asn_dec_rval_t
 CHOICE_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                    const asn_TYPE_descriptor_t *td,
-                   const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+                   const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 	const asn_CHOICE_specifics_t *specs = (const asn_CHOICE_specifics_t *)td->specifics;
 	asn_dec_rval_t rv;
 	const asn_per_constraint_t *ct;
@@ -1077,14 +1077,15 @@
 		memb_ptr = (char *)st + elm->memb_offset;
 		memb_ptr2 = &memb_ptr;
 	}
-	ASN_DEBUG("Discovered CHOICE %s encodes %s", td->name, elm->name);
+	ASN_DEBUG("APER Discovered CHOICE %s encodes %s", td->name, elm->name);
 
 	if(ct && ct->range_bits >= 0) {
 		rv = elm->type->op->aper_decoder(opt_codec_ctx, elm->type,
-		                                 elm->encoding_constraints.per_constraints, memb_ptr2, pd);
+		                                 elm->encoding_constraints.per_constraints, memb_ptr2, pd, h323_info);
 	} else {
+	    ASN_DEBUG("APER Discovered CHOICE..\n");
 		rv = uper_open_type_get(opt_codec_ctx, elm->type,
-		                        elm->encoding_constraints.per_constraints, memb_ptr2, pd);
+		                        elm->encoding_constraints.per_constraints, memb_ptr2, pd, h323_info);
 	}
 
 	if(rv.code != RC_OK)
@@ -1105,7 +1106,7 @@
 
 	if(!sptr) ASN__ENCODE_FAILED;
 
-	ASN_DEBUG("Encoding %s as CHOICE using ALIGNED PER", td->name);
+	ASN_DEBUG("CHOICE_encode_aper: Encoding %s as CHOICE using ALIGNED PER", td->name);
 
 	if(constraints) ct = &constraints->value;
 	else if(td->encoding_constraints.per_constraints)
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_SEQUENCE.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_SEQUENCE.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_SEQUENCE.c	(working copy)
@@ -3,6 +3,7 @@
  * All rights reserved.
  * Redistribution and modifications are permitted subject to BSD license.
  */
+
 #include <asn_internal.h>
 #include <constr_SEQUENCE.h>
 #include <OPEN_TYPE.h>
@@ -1072,6 +1073,7 @@
 
 #ifndef ASN_DISABLE_PER_SUPPORT
 
+#if 0
 asn_dec_rval_t
 SEQUENCE_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                      const asn_TYPE_descriptor_t *td,
@@ -1299,6 +1301,7 @@
 	rv.code = RC_OK;
 	return rv;
 }
+#endif
 
 static int
 SEQUENCE__handle_extensions(const asn_TYPE_descriptor_t *td, const void *sptr,
@@ -1487,7 +1490,8 @@
 asn_dec_rval_t
 SEQUENCE_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                      const asn_TYPE_descriptor_t *td,
-                     const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+                     const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
+
 	const asn_SEQUENCE_specifics_t *specs = (const asn_SEQUENCE_specifics_t *)td->specifics;
 	void *st = *sptr;	/* Target structure. */
 	int extpresent;		/* Extension additions are present */
@@ -1496,6 +1500,8 @@
 	asn_dec_rval_t rv;
 	size_t edx;
 
+        printf ("calling SEQUENCE_decode_aper addr : %p\n", pd->buffer); //this is correct add, but not all time
+
 	(void)constraints;
 
 	if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx))
@@ -1506,7 +1512,13 @@
 		if(!st) ASN__DECODE_FAILED;
 	}
 
-	ASN_DEBUG("Decoding %s as SEQUENCE (APER)", td->name);
+	ASN_DEBUG("Decoding APER %s as SEQUENCE (APER).", td->name);
+#ifdef DEBUG_LOG
+                if (h323_info == NULL)
+		    ASN_DEBUG("H323_info is not Valid.\n");
+                else
+		    ASN_DEBUG("H323_info is Valid.\n");
+#endif
 
 	/* Handle extensions */
 	if(specs->first_extension < 0) {
@@ -1596,13 +1608,296 @@
 		}
 
 		/* Fetch the member from the stream */
-		ASN_DEBUG("Decoding member22 \"%s\" in %s", elm->name, td->name);
+		ASN_DEBUG("Decoding member \"%s\" in %s", elm->name, td->name);
+                
+                if (h323_info->type == MSG_TYPE_H245_OPEN_CHANNEL_ACK && !strcmp(elm->name, "mediaChannel") &&
+                        !strcmp(td->name, "H2250LogicalChannelAckParameters") &&
+                         h323_info && h323_info->status == H245_OPEN_CHANNEL_ACK_STATUS_INIT) {
+
+                    h323_info->status = ENABLE_H245_OPEN_CHANNEL_ACK_PAYLOAD_UPDATE;
+                }
+                
 
 		if(elm->flags & ATF_OPEN_TYPE) {
+#ifdef DEBUG_LOG
+                        ASN_DEBUG ("calling OPEN_TYPE_aper_get\n");
+#endif
 			rv = OPEN_TYPE_aper_get(opt_codec_ctx, td, st, elm, pd);
 		} else {
+#ifdef DEBUG_LOG
+                        ASN_DEBUG ("calling aper_decoder\n");
+#endif
+                         
 			rv = elm->type->op->aper_decoder(opt_codec_ctx, elm->type,
-					elm->encoding_constraints.per_constraints, memb_ptr2, pd);
+					elm->encoding_constraints.per_constraints, memb_ptr2, pd, h323_info);
+		}
+		if(rv.code != RC_OK) {
+			ASN_DEBUG("Failed decode %s in %s",
+			          elm->name, td->name);
+			FREEMEM(opres);
+			return rv;
+		} 
+	}
+
+	/* Optionality map is not needed anymore */
+#if 1
+	FREEMEM(opres);
+#endif
+
+	/*
+	 * Deal with extensions.
+	 */
+	if(extpresent) {
+		ssize_t bmlength;
+		uint8_t *epres;		/* Presence of extension members */
+		asn_per_data_t epmd;
+
+		bmlength = aper_get_nslength(pd);
+		if(bmlength < 0) ASN__DECODE_STARVED;
+
+		ASN_DEBUG("Extensions %" ASN_PRI_SSIZE " present in %s", bmlength, td->name);
+
+		epres = (uint8_t *)MALLOC((bmlength + 15) >> 3);
+		if(!epres) ASN__DECODE_STARVED;
+
+		/* Get the extensions map */
+		if(per_get_many_bits(pd, epres, 0, bmlength))
+			ASN__DECODE_STARVED;
+
+		memset(&epmd, 0, sizeof(epmd));
+		epmd.buffer = epres;
+		epmd.nbits = bmlength;
+		ASN_DEBUG("Read in extensions bitmap for %s of %ld bits (%x..)",
+		          td->name, bmlength, *epres);
+
+		/* Go over extensions and read them in */
+		for(edx = specs->first_extension; edx < td->elements_count; edx++) {
+			asn_TYPE_member_t *elm = &td->elements[edx];
+			void *memb_ptr;		/* Pointer to the member */
+			void **memb_ptr2;	/* Pointer to that pointer */
+			int present;
+
+			if(!IN_EXTENSION_GROUP(specs, edx)) {
+				ASN_DEBUG("%ld is not extension", edx);
+				continue;
+			}
+
+			/* Fetch the pointer to this member */
+			if(elm->flags & ATF_POINTER) {
+				memb_ptr2 = (void **)((char *)st + elm->memb_offset);
+			} else {
+				memb_ptr = (void *)((char *)st + elm->memb_offset);
+				memb_ptr2 = &memb_ptr;
+			}
+
+			present = per_get_few_bits(&epmd, 1);
+			if(present <= 0) {
+				if(present < 0) break;	/* No more extensions */
+				continue;
+			}
+
+/*
+ *     Decoding member4 sourceCallSignalAddress in Setup-UUIE (nil)
+ *
+ */
+			ASN_DEBUG("Decoding member4 %s in %s %p...", elm->name, td->name, *memb_ptr2);
+#ifdef DEBUG_LOG
+                        if (h323_info)
+			    ASN_DEBUG("h323_info exist\n");
+                        else
+			    ASN_DEBUG("h323_info NOT exist\n");
+#endif
+                            
+                        if (!strcmp(elm->name, "sourceCallSignalAddress") && !strcmp(td->name, "Setup-UUIE") &&
+                                  h323_info && (h323_info->type == MSG_TYPE_SETUP) && h323_info->status == H225_SETUP_STATUS_INIT) {
+			    ASN_DEBUG("decoding sourceCallSignalAddress\n");
+                            h323_info->status = ENABLE_H225_SETUP_PAYLOAD_UPDATE; //PAYLOAD CHANGE required
+                        }
+			rv = aper_open_type_get(opt_codec_ctx, elm->type,
+			                        elm->encoding_constraints.per_constraints, memb_ptr2, pd, h323_info);
+			if(rv.code != RC_OK) {
+			        ASN_DEBUG("failed Decoding member4 %s in %s %p", elm->name, td->name, *memb_ptr2);
+				FREEMEM(epres);
+				return rv;
+			}
+		}
+
+		/* Skip over overflow extensions which aren't present
+		 * in this system's version of the protocol */
+		for(;;) {
+			ASN_DEBUG("Getting overflow extensions");
+			switch(per_get_few_bits(&epmd, 1)) {
+			case -1:
+				break;
+			case 0:
+				continue;
+			default:
+				if(aper_open_type_skip(opt_codec_ctx, pd)) {
+					FREEMEM(epres);
+					ASN__DECODE_STARVED;
+				}
+			}
+			break;
+		}
+
+		FREEMEM(epres);
+	}
+
+	/* Fill DEFAULT members in extensions */
+	for(edx = specs->roms_count; edx < specs->roms_count
+	        + specs->aoms_count; edx++) {
+		asn_TYPE_member_t *elm = &td->elements[edx];
+		void **memb_ptr2;	/* Pointer to member pointer */
+
+		if(!elm->default_value_set) continue;
+
+		/* Fetch the pointer to this member */
+		if(elm->flags & ATF_POINTER) {
+			memb_ptr2 = (void **)((char *)st
+			                      + elm->memb_offset);
+			if(*memb_ptr2) continue;
+		} else {
+			continue;	/* Extensions are all optionals */
+		}
+
+		/* Set default value */
+		if(elm->default_value_set(memb_ptr2)) {
+			ASN__DECODE_FAILED;
+		}
+	}
+
+	rv.consumed = 0;
+	rv.code = RC_OK;
+	return rv;
+}
+
+asn_dec_rval_t
+SEQUENCE_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
+                     const asn_TYPE_descriptor_t *td,
+                     const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
+
+	const asn_SEQUENCE_specifics_t *specs = (const asn_SEQUENCE_specifics_t *)td->specifics;
+	void *st = *sptr;	/* Target structure. */
+	int extpresent;		/* Extension additions are present */
+	uint8_t *opres;		/* Presence of optional root members */
+	asn_per_data_t opmd;
+	asn_dec_rval_t rv;
+	size_t edx;
+
+	(void)constraints;
+
+	if(ASN__STACK_OVERFLOW_CHECK(opt_codec_ctx))
+		ASN__DECODE_FAILED;
+
+	if(!st) {
+		st = *sptr = CALLOC(1, specs->struct_size);
+		if(!st) ASN__DECODE_FAILED;
+	}
+
+	ASN_DEBUG("Decoding %s as SEQUENCE (UPER-APER)", td->name);
+
+	/* Handle extensions */
+	if(specs->first_extension < 0) {
+		extpresent = 0;
+	} else {
+		extpresent = per_get_few_bits(pd, 1);
+		if(extpresent < 0) ASN__DECODE_STARVED;
+	}
+
+	/* Prepare a place and read-in the presence bitmap */
+	memset(&opmd, 0, sizeof(opmd));
+	if(specs->roms_count) {
+		opres = (uint8_t *)MALLOC(((specs->roms_count + 7) >> 3) + 1);
+		if(!opres) ASN__DECODE_FAILED;
+		/* Get the presence map */
+		if(per_get_many_bits(pd, opres, 0, specs->roms_count)) {
+			FREEMEM(opres);
+			ASN__DECODE_STARVED;
+		}
+		opmd.buffer = opres;
+		opmd.nbits = specs->roms_count;
+		ASN_DEBUG("Read in presence bitmap for %s of %d bits (%x..)",
+		          td->name, specs->roms_count, *opres);
+	} else {
+		opres = 0;
+	}
+
+	/*
+	 * Get the sequence ROOT elements.
+	 */
+	for(edx = 0; edx < td->elements_count; edx++) {
+		asn_TYPE_member_t *elm = &td->elements[edx];
+		void *memb_ptr;		/* Pointer to the member */
+		void **memb_ptr2;	/* Pointer to that pointer */
+#if 0
+		int padding;
+#endif
+
+		if(IN_EXTENSION_GROUP(specs, edx))
+			continue;
+
+		/* Fetch the pointer to this member */
+		if(elm->flags & ATF_POINTER) {
+			memb_ptr2 = (void **)((char *)st + elm->memb_offset);
+		} else {
+			memb_ptr = (char *)st + elm->memb_offset;
+			memb_ptr2 = &memb_ptr;
+		}
+#if 0
+		/* Get Padding */
+		padding = (8 - (pd->moved % 8)) % 8;
+		if(padding > 0)
+			ASN_DEBUG("For element %s,offset= %ld Padding bits = %d", td->name, pd->moved, padding);
+#if 0 /* old way of removing padding */
+		per_get_few_bits(pd, padding);
+#else /* Experimental fix proposed by @mhanna123 */
+		if(edx != (td->elements_count-1))
+			per_get_few_bits(pd, padding);
+		else {
+			if(specs->roms_count && (padding > 0))
+				ASN_DEBUG(">>>>> not skipping padding of %d bits for element:%ld out of %d", padding, edx, td->elements_count);
+			else
+				per_get_few_bits(pd, padding);
+		}
+#endif /* dealing with padding */
+#endif
+		/* Deal with optionality */
+		if(elm->optional) {
+			int present = per_get_few_bits(&opmd, 1);
+			ASN_DEBUG("Member %s->%s is optional, p=%d (%d->%d)",
+			          td->name, elm->name, present,
+			          (int)opmd.nboff, (int)opmd.nbits);
+			if(present == 0) {
+				/* This element is not present */
+				if(elm->default_value_set) {
+					/* Fill-in DEFAULT */
+					if(elm->default_value_set(memb_ptr2)) {
+						FREEMEM(opres);
+						ASN__DECODE_FAILED;
+					}
+					ASN_DEBUG("Filled-in default");
+				}
+				/* The member is just not present */
+				continue;
+			}
+			/* Fall through */
+		}
+
+		/* Fetch the member from the stream */
+		ASN_DEBUG("Decoding member3 \"%s\" in %s", elm->name, td->name); //Decoding member3 "port" in ipAddress
+//Decoding member3 "ip" in ipAddress
+
+		if(elm->flags & ATF_OPEN_TYPE) {
+#ifdef DEBUG_LOG
+                        ASN_DEBUG ("called OPEN_TYPE_aper_get\n");
+#endif
+			rv = OPEN_TYPE_aper_get(opt_codec_ctx, td, st, elm, pd);
+		} else {
+#ifdef DEBUG_LOG
+                        ASN_DEBUG ("called OPEN_TYPE_aper_decoder\n");
+#endif
+			rv = elm->type->op->aper_decoder(opt_codec_ctx, elm->type,
+					elm->encoding_constraints.per_constraints, memb_ptr2, pd, h323_info);
 		}
 		if(rv.code != RC_OK) {
 			ASN_DEBUG("Failed decode %s in %s",
@@ -1669,7 +1964,7 @@
 
 			ASN_DEBUG("Decoding member4 %s in %s %p", elm->name, td->name, *memb_ptr2);
 			rv = aper_open_type_get(opt_codec_ctx, elm->type,
-			                        elm->encoding_constraints.per_constraints, memb_ptr2, pd);
+			                        elm->encoding_constraints.per_constraints, memb_ptr2, pd, NULL);
 			if(rv.code != RC_OK) {
 			        ASN_DEBUG("failed Decoding member4 %s in %s %p", elm->name, td->name, *memb_ptr2);
 				FREEMEM(epres);
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_SET_OF.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_SET_OF.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/constr_SET_OF.c	(working copy)
@@ -908,7 +908,7 @@
 SET_OF_decode_uper(const asn_codec_ctx_t *opt_codec_ctx,
                    const asn_TYPE_descriptor_t *td,
                    const asn_per_constraints_t *constraints, void **sptr,
-                   asn_per_data_t *pd) {
+                   asn_per_data_t *pd, h323_info_t *h323_info) {
     asn_dec_rval_t rv;
 	const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics;
     const asn_TYPE_member_t *elm = td->elements; /* Single one */
@@ -966,7 +966,7 @@
 			void *ptr = 0;
 			ASN_DEBUG("SET OF %s decoding", elm->type->name);
 			rv = elm->type->op->uper_decoder(opt_codec_ctx, elm->type,
-				elm->encoding_constraints.per_constraints, &ptr, pd);
+				elm->encoding_constraints.per_constraints, &ptr, pd, h323_info);
 			ASN_DEBUG("%s SET OF %s decoded %d, %p",
 				td->name, elm->type->name, rv.code, ptr);
 			if(rv.code == RC_OK) {
@@ -1100,7 +1100,7 @@
 asn_dec_rval_t
 SET_OF_decode_aper(const asn_codec_ctx_t *opt_codec_ctx,
                    const asn_TYPE_descriptor_t *td,
-                   const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+                   const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 	asn_dec_rval_t rv;
 	const asn_SET_OF_specifics_t *specs = (const asn_SET_OF_specifics_t *)td->specifics;
 	const asn_TYPE_member_t *elm = td->elements; /* Single one */
@@ -1159,7 +1159,7 @@
 			void *ptr = 0;
 			ASN_DEBUG("SET OF %s decoding", elm->type->name);
 			rv = elm->type->op->aper_decoder(opt_codec_ctx, elm->type,
-			                                 elm->encoding_constraints.per_constraints, &ptr, pd);
+			                                 elm->encoding_constraints.per_constraints, &ptr, pd, h323_info);
 			ASN_DEBUG("%s SET OF %s decoded %d, %p",
 			          td->name, elm->type->name, rv.code, ptr);
 			if(rv.code == RC_OK) {
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/converter-example.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/converter-example.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/converter-example.c	(working copy)
@@ -852,7 +852,7 @@
                                    i_bptr, i_size, 0, DynamicBuffer.unbits);
             else
                 rval = aper_decode(opt_codec_ctx, pduType, (void **)&structure,
-                                   i_bptr, i_size, 0, DynamicBuffer.unbits);
+                                   i_bptr, i_size, 0, DynamicBuffer.unbits, NULL);
             /* uper_decode() returns bits! */
             ecbits = rval.consumed % 8; /* Bits consumed from the last byte */
             rval.consumed >>= 3;    /* Convert bits into bytes. */
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_decoder.h
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_decoder.h	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_decoder.h	(working copy)
@@ -12,8 +12,39 @@
 extern "C" {
 #endif
 
+#define IE_BEARER_CAPABILITY                              0x04
+#define IE_DISPLAY                                        0x28
+#define IE_USER_USER                                      0x7E
+#define MSG_TYPE_INVALID                                  0x00
+#define MSG_TYPE_SETUP                                    0x05
+#define MSG_TYPE_CONNECT                                  0x07
+#define MSG_TYPE_H245_OPEN_CHANNEL                        0x03
+#define MSG_TYPE_H245_OPEN_CHANNEL_ACK                    0x22
+#define PROT_DISCRIMIATOR_Q931                            0x08
+#define TPKT_VERSION_3                                    0x03
+#define TPKT_RESERVED                                     0x00
+#define CALLED_PARTY_NUM                                  0x70
+#define H225_LOGICAL_ACK_PARAM1                           0x1C
+#define H225_LOGICAL_ACK_PARAM2                           0x1E
+#define ENABLE_H225_SETUP_PAYLOAD_UPDATE                  1
+#define DISABLE_H225_SETUP_PAYLOAD_UPDATE                 2
+#define H225_SETUP_STATUS_INIT                            0
+#define H245_OPEN_CHANNEL_STATUS_INIT                     0
+#define H323_PACKET_NOT_OURS                             -1
+#define H245_OPEN_CHANNEL_ACK_STATUS_INIT                 0
+#define ENABLE_H245_OPEN_CHANNEL_ACK_PAYLOAD_UPDATE       1
+#define DISABLE_H245_OPEN_CHANNEL_ACK_PAYLOAD_UPDATE      2 
+
 struct asn_TYPE_descriptor_s;	/* Forward declaration */
 
+typedef struct h323_info {
+                int type;
+                int status;
+                unsigned long ip;
+                unsigned short port;
+} h323_info_t;
+
+
 /*
  * Unaligned PER decoder of a "complete encoding" as per X.691 (08/2015) #11.1.
  * On success, this call always returns (.consumed >= 1), as per #11.1.3.
@@ -48,9 +79,10 @@
        const struct asn_codec_ctx_s *opt_codec_ctx,
        const struct asn_TYPE_descriptor_s *type_descriptor,	/* Type to decode */
        void **struct_ptr,	/* Pointer to a target structure's pointer */
-       const void *buffer,	/* Data to be decoded */
-       size_t size		/* Size of data buffer */
-									);
+       void *buffer,	/* Data to be decoded */
+       size_t size,     /* Size of data buffer */
+       h323_info_t *h323_info
+);
 
 /*
  * Aligned PER decoder of any ASN.1 type. May be invoked by the application.
@@ -60,10 +92,11 @@
       const struct asn_codec_ctx_s *opt_codec_ctx,
       const struct asn_TYPE_descriptor_s *type_descriptor,	/* Type to decode */
       void **struct_ptr,	/* Pointer to a target structure's pointer */
-      const void *buffer,	/* Data to be decoded */
+      void *buffer,	/* Data to be decoded */
       size_t size,		/* Size of data buffer */
       int skip_bits,		/* Number of unused leading bits, 0..7 */
-      int unused_bits		/* Number of unused tailing bits, 0..7 */
+      int unused_bits,		/* Number of unused tailing bits, 0..7 */
+       h323_info_t *h323_info
       );
 
 /*
@@ -73,7 +106,7 @@
     const asn_codec_ctx_t *opt_codec_ctx,
     const struct asn_TYPE_descriptor_s *type_descriptor,
     const asn_per_constraints_t *constraints, void **struct_ptr,
-    asn_per_data_t *per_data);
+    asn_per_data_t *per_data, h323_info_t *h323_info);
 
 #ifdef __cplusplus
 }
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_decoder.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_decoder.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_decoder.c	(working copy)
@@ -80,7 +80,7 @@
 	 */
 	if(!td->op->uper_decoder)
 		ASN__DECODE_FAILED;	/* PER is not compiled in */
-	rval = td->op->uper_decoder(opt_codec_ctx, td, 0, sptr, &pd);
+	rval = td->op->uper_decoder(opt_codec_ctx, td, 0, sptr, &pd, NULL);
 	if(rval.code == RC_OK) {
 		/* Return the number of consumed bits */
 		rval.consumed = ((pd.buffer - (const uint8_t *)buffer) << 3)
@@ -98,10 +98,11 @@
 asn_dec_rval_t
 aper_decode_complete(const asn_codec_ctx_t *opt_codec_ctx,
                      const asn_TYPE_descriptor_t *td, void **sptr,
-                     const void *buffer, size_t size) {
+                     void *buffer, size_t size, h323_info_t *h323_info) {
+
 	asn_dec_rval_t rval;
 
-	rval = aper_decode(opt_codec_ctx, td, sptr, buffer, size, 0, 0);
+	rval = aper_decode(opt_codec_ctx, td, sptr, buffer, size, 0, 0, h323_info);
 	if(rval.consumed) {
 		/*
 		 * We've always given 8-aligned data,
@@ -128,8 +129,8 @@
 
 asn_dec_rval_t
 aper_decode(const asn_codec_ctx_t *opt_codec_ctx,
-            const asn_TYPE_descriptor_t *td, void **sptr, const void *buffer,
-            size_t size, int skip_bits, int unused_bits) {
+            const asn_TYPE_descriptor_t *td, void **sptr,  void *buffer,
+            size_t size, int skip_bits, int unused_bits, h323_info_t *h323_info) {
 	asn_codec_ctx_t s_codec_ctx;
 	asn_dec_rval_t rval;
 	asn_per_data_t pd;
@@ -157,7 +158,10 @@
 
 	/* Fill in the position indicator */
 	memset(&pd, 0, sizeof(pd));
-	pd.buffer = (const uint8_t *)buffer;
+	pd.buffer = (uint8_t *)buffer;
+#ifdef DEBUG_LOG
+        printf ("address in aper_decode : %p\n", pd.buffer );
+#endif
 	pd.nboff = skip_bits;
 	pd.nbits = 8 * size - unused_bits; /* 8 is CHAR_BIT from <limits.h> */
 	if(pd.nboff > pd.nbits)
@@ -168,7 +172,9 @@
 	 */
 	if(!td->op->aper_decoder)
 		ASN__DECODE_FAILED;	/* PER is not compiled in */
-		rval = td->op->aper_decoder(opt_codec_ctx, td, 0, sptr, &pd);
+
+	rval = td->op->aper_decoder(opt_codec_ctx, td, 0, sptr, &pd, h323_info);
+
 	if(rval.code == RC_OK) {
 		/* Return the number of consumed bits */
 		rval.consumed = ((pd.buffer - (const uint8_t *)buffer) << 3)
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_opentype.h
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_opentype.h	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_opentype.h	(working copy)
@@ -12,7 +12,7 @@
 asn_dec_rval_t uper_open_type_get(const asn_codec_ctx_t *opt_codec_ctx,
                                   const asn_TYPE_descriptor_t *td,
                                   const asn_per_constraints_t *constraints,
-                                  void **sptr, asn_per_data_t *pd);
+                                  void **sptr, asn_per_data_t *pd, h323_info_t *h323_info);
 
 int uper_open_type_skip(const asn_codec_ctx_t *opt_codec_ctx,
                         asn_per_data_t *pd);
@@ -28,7 +28,7 @@
 asn_dec_rval_t aper_open_type_get(const asn_codec_ctx_t *opt_codec_ctx,
                                   const asn_TYPE_descriptor_t *td,
                                   const asn_per_constraints_t *constraints,
-                                  void **sptr, asn_per_data_t *pd);
+                                  void **sptr, asn_per_data_t *pd, h323_info_t *h323_info);
 
 
 int aper_open_type_skip(const asn_codec_ctx_t *opt_codec_ctx, asn_per_data_t *pd);
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_opentype.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_opentype.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libasn1c/per_opentype.c	(working copy)
@@ -7,6 +7,9 @@
 #include <constr_TYPE.h>
 #include <per_opentype.h>
 
+#define H225_SETUP_IP_ADDR_OFFSET 3
+#define H245_OPEN_CHANNEL_ADDR_OFFSET 6
+
 typedef struct uper_ugot_key {
 	asn_per_data_t oldpd;	/* Old per data source */
 	size_t unclaimed;
@@ -64,6 +67,7 @@
     return 0;
 }
 
+#if 0
 static asn_dec_rval_t
 uper_open_type_get_simple(const asn_codec_ctx_t *ctx,
                           const asn_TYPE_descriptor_t *td,
@@ -80,7 +84,7 @@
 
 	ASN__STACK_OVERFLOW_CHECK(ctx);
 
-	ASN_DEBUG("Getting open type %s...", td->name);
+        ASN_DEBUG("Getting open type %s...", td->name);
 
 	do {
 		chunk_bytes = uper_get_length(pd, -1, 0, &repeat);
@@ -142,6 +146,97 @@
 
 	return rv;
 }
+#endif
+
+
+#if 1
+static asn_dec_rval_t
+uper_open_type_get_simple(const asn_codec_ctx_t *ctx,
+                          const asn_TYPE_descriptor_t *td,
+                          const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
+	asn_dec_rval_t rv;
+	ssize_t chunk_bytes;
+	int repeat;
+	uint8_t *buf = 0;
+	size_t bufLen = 0;
+	size_t bufSize = 0;
+	asn_per_data_t spd;
+	size_t padding;
+
+	ASN__STACK_OVERFLOW_CHECK(ctx);
+
+	ASN_DEBUG("uper-aper_open_type_get_simple. Open type %s. Address %p\n", td->name, pd->buffer);
+        if (h323_info && (h323_info->type == MSG_TYPE_H245_OPEN_CHANNEL) && !strcmp(td->name, "H2250LogicalChannelParameters")) {
+	    printf ("Decoding H245 OpenLogicChannel packet. Replacing 'internal IP' with 'NAT IP' : %x\n", h323_info->ip);
+            printf ("intenal IP : %x:%x:%x:%x\n", pd->buffer[H245_OPEN_CHANNEL_ADDR_OFFSET], pd->buffer[H245_OPEN_CHANNEL_ADDR_OFFSET + 1], pd->buffer[H245_OPEN_CHANNEL_ADDR_OFFSET + 2], pd->buffer[H245_OPEN_CHANNEL_ADDR_OFFSET + 3]);
+	    pd->buffer[H245_OPEN_CHANNEL_ADDR_OFFSET] = (h323_info->ip >> 24) & 0xFF;
+	    pd->buffer[H245_OPEN_CHANNEL_ADDR_OFFSET + 1] = (h323_info->ip >> 16) & 0xFF;
+	    pd->buffer[H245_OPEN_CHANNEL_ADDR_OFFSET + 2] = (h323_info->ip >> 8) & 0xFF;
+	    pd->buffer[H245_OPEN_CHANNEL_ADDR_OFFSET + 3] = h323_info->ip  & 0xFF;
+        }
+
+	do {
+	        chunk_bytes = aper_get_length(pd, -1, -1, &repeat);
+		if(chunk_bytes < 0) {
+			FREEMEM(buf);
+			ASN__DECODE_STARVED;
+		}
+		if(bufLen + chunk_bytes > bufSize) {
+			void *ptr;
+			bufSize = chunk_bytes + (bufSize << 2);
+			ptr = REALLOC(buf, bufSize);
+			if(!ptr) {
+				FREEMEM(buf);
+				ASN__DECODE_FAILED;
+			}
+			buf = ptr;
+		}
+		if(per_get_many_bits(pd, buf + bufLen, 0, chunk_bytes << 3)) {
+			FREEMEM(buf);
+			ASN__DECODE_STARVED;
+		}
+		bufLen += chunk_bytes;
+	} while(repeat);
+
+	ASN_DEBUG("Getting open type %s encoded in %ld bytes", td->name,
+		(long)bufLen);
+
+	memset(&spd, 0, sizeof(spd));
+	spd.buffer = buf;
+	spd.nbits = bufLen << 3;
+
+	ASN_DEBUG_INDENT_ADD(+4);
+	ASN_DEBUG("ami called 44\n");
+	rv = td->op->aper_decoder(ctx, td, constraints, sptr, &spd, h323_info);
+	ASN_DEBUG_INDENT_ADD(-4);
+
+	if(rv.code == RC_OK) {
+		/* Check padding validity */
+		padding = spd.nbits - spd.nboff;
+                if (((padding > 0 && padding < 8) ||
+		/* X.691#10.1.3 */
+		(spd.nboff == 0 && spd.nbits == 8 && spd.buffer == buf)) &&
+                    per_get_few_bits(&spd, padding) == 0) {
+			/* Everything is cool */
+			FREEMEM(buf);
+			return rv;
+		}
+		FREEMEM(buf);
+		if(padding >= 8) {
+			ASN_DEBUG("Too large padding %d in open type", (int)padding);
+			ASN__DECODE_FAILED;
+		} else {
+			ASN_DEBUG("No padding");
+		}
+	} else {
+		FREEMEM(buf);
+		/* rv.code could be RC_WMORE, nonsense in this context */
+		rv.code = RC_FAIL; /* Noone would give us more */
+	}
+
+	return rv;
+}
+#endif
 
 static asn_dec_rval_t CC_NOTUSED
 uper_open_type_get_complex(const asn_codec_ctx_t *ctx,
@@ -166,7 +261,7 @@
 	pd->moved = 0;	/* This now counts the open type size in bits */
 
 	ASN_DEBUG_INDENT_ADD(+4);
-	rv = td->op->uper_decoder(ctx, td, constraints, sptr, pd);
+	rv = td->op->uper_decoder(ctx, td, constraints, sptr, pd, NULL);
 	ASN_DEBUG_INDENT_ADD(-4);
 
 #define	UPDRESTOREPD	do {						\
@@ -258,8 +353,8 @@
 asn_dec_rval_t
 uper_open_type_get(const asn_codec_ctx_t *ctx, const asn_TYPE_descriptor_t *td,
                    const asn_per_constraints_t *constraints, void **sptr,
-                   asn_per_data_t *pd) {
-    return uper_open_type_get_simple(ctx, td, constraints, sptr, pd);
+                   asn_per_data_t *pd, h323_info_t *h323_info) {
+    return uper_open_type_get_simple(ctx, td, constraints, sptr, pd, h323_info);
 }
 
 int
@@ -270,9 +365,9 @@
 
 	s_td.name = "<unknown extension>";
 	s_td.op = &s_op;
-    s_op.uper_decoder = uper_sot_suck;
+        s_op.uper_decoder = uper_sot_suck;
 
-	rv = uper_open_type_get(ctx, &s_td, 0, 0, pd);
+	rv = uper_open_type_get(ctx, &s_td, 0, 0, pd, NULL);
 	if(rv.code != RC_OK)
 		return -1;
 	else
@@ -397,7 +492,7 @@
 static asn_dec_rval_t
 aper_open_type_get_simple(const asn_codec_ctx_t *ctx,
                           const asn_TYPE_descriptor_t *td,
-                          const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd) {
+                          const asn_per_constraints_t *constraints, void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 	asn_dec_rval_t rv;
 	ssize_t chunk_bytes;
 	int repeat;
@@ -409,7 +504,18 @@
 
 	ASN__STACK_OVERFLOW_CHECK(ctx);
 
-	ASN_DEBUG("Getting open type %s...", td->name);
+        ASN_DEBUG("Getting open type %s...", td->name);
+
+        if (!strcmp(td->name, "TransportAddress") && h323_info && (h323_info->type == MSG_TYPE_SETUP) &&
+                     h323_info->status == ENABLE_H225_SETUP_PAYLOAD_UPDATE) {
+	    printf ("Decoding H225 SETUP packet. Replacing 'internal IP' with 'NAT IP' : %x\n", h323_info->ip);
+            printf ("intenal IP : %x:%x:%x:%x\n", pd->buffer[H225_SETUP_IP_ADDR_OFFSET], pd->buffer[H225_SETUP_IP_ADDR_OFFSET + 1], pd->buffer[H225_SETUP_IP_ADDR_OFFSET + 2], pd->buffer[H225_SETUP_IP_ADDR_OFFSET + 3]);
+	    pd->buffer[H225_SETUP_IP_ADDR_OFFSET] = (h323_info->ip >> 24) & 0xFF;
+	    pd->buffer[H225_SETUP_IP_ADDR_OFFSET + 1] = (h323_info->ip >> 16) & 0xFF;
+	    pd->buffer[H225_SETUP_IP_ADDR_OFFSET + 2] = (h323_info->ip >> 8) & 0xFF;
+	    pd->buffer[H225_SETUP_IP_ADDR_OFFSET + 3] = h323_info->ip  & 0xFF;
+	    h323_info->status = DISABLE_H225_SETUP_PAYLOAD_UPDATE;
+        }
 
 	do {
 	        chunk_bytes = aper_get_length(pd, -1, -1, &repeat);
@@ -442,7 +548,10 @@
 	spd.nbits = bufLen << 3;
 
 	ASN_DEBUG_INDENT_ADD(+4);
-	rv = td->op->aper_decoder(ctx, td, constraints, sptr, &spd);
+#ifdef DEBUG_LOG
+        ASN_DEBUG ("aper_open_type_get_simple calling aper_decoder  with addres : %p\n", spd.buffer);
+#endif
+	rv = td->op->aper_decoder(ctx, td, constraints, sptr, &spd, h323_info);
 	ASN_DEBUG_INDENT_ADD(-4);
 
 	if(rv.code == RC_OK) {
@@ -507,9 +616,9 @@
 aper_open_type_get(const asn_codec_ctx_t *ctx,
                    const asn_TYPE_descriptor_t *td,
                    const asn_per_constraints_t *constraints,
-                   void **sptr, asn_per_data_t *pd) {
+                   void **sptr, asn_per_data_t *pd, h323_info_t *h323_info) {
 
-	return aper_open_type_get_simple(ctx, td, constraints, sptr, pd);
+	return aper_open_type_get_simple(ctx, td, constraints, sptr, pd, h323_info);
 }
 
 int
@@ -523,7 +632,7 @@
 	s_td.op = &op_t;
 	s_td.op->aper_decoder = uper_sot_suck;
 
-	rv = aper_open_type_get(ctx, &s_td, 0, 0, pd);
+	rv = aper_open_type_get(ctx, &s_td, 0, 0, pd, NULL);
 	if(rv.code != RC_OK)
 		return -1;
 	else
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libkernelapi/addCommands.pm
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libkernelapi/addCommands.pm	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libkernelapi/addCommands.pm	(working copy)
@@ -3972,6 +3972,13 @@
     },
     {
         cmd_attribute => "CMD_KERN_API|CMD_KAPI_LOCK",
+        function_name => "write_h323_nat_config_kern",
+        function_args => [
+                {type => "OUTDATA"},
+            ],
+    },
+    {
+        cmd_attribute => "CMD_KERN_API|CMD_KAPI_LOCK",
         function_name => "write_qos_kern",
         function_args => [
                 {type => "OUTDATA"},
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libparser/commands.pm
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libparser/commands.pm	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libparser/commands.pm	(working copy)
@@ -22820,6 +22820,58 @@
 # end DPI CLI
 
         {
+                obj_type => "ITEM",
+                name => "h323",
+                menu => "root_show",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+                user_level => "CLI_LEVEL_ENABLE",
+                help_string => "Display H323 nat config",
+                function_name => "show_h323_status_kern",
+                function_args => [],
+        },
+        {
+                obj_type => "MENU",
+                name => "h323",
+                help_string => "Configure H323 natting",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL",
+                user_level => "CLI_LEVEL_CONFIG",
+                parent_menu => ".",
+                uniq_name => "root_h323",
+        },
+
+
+	{
+		obj_type => "MENU",
+		name => "nat",
+		help_string => "enable/disable natting",
+		cmd_attribute =>"CMD_ARRAYOS|CMD_NORMAL",
+		user_level => "CLI_LEVEL_CONFIG",
+		parent_menu => "root_h323",
+		uniq_name => "root_h323_nat",
+	},
+
+
+        {
+                obj_type => "ITEM",
+                name => "enable",
+                menu => "root_h323_nat",
+                help_string => "Enable H323 natting",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+                user_level => "CLI_LEVEL_CONFIG",
+                function_name => "h323_enable_kern",
+                function_args => [],
+        },
+        {
+                obj_type => "ITEM",
+                name => "disable",
+                menu => "root_h323_nat",
+                help_string => "Disable H323 natting",
+                cmd_attribute => "CMD_ARRAYOS|CMD_NORMAL|CMD_GLOBAL|CMD_KERN_API",
+                user_level => "CLI_LEVEL_CONFIG",
+                function_name => "h323_disable_kern",
+                function_args => [],
+        },
+        {
                 obj_type => "MENU",
                 name => "llb",
                 help_string => "Configure link load balancer",
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libuinet-atcp/bin/atcp/Makefile
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libuinet-atcp/bin/atcp/Makefile	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libuinet-atcp/bin/atcp/Makefile	(working copy)
@@ -56,6 +56,7 @@
 	-L${TOPDIR}/../libopenssl-1.1.1 -lcrypto-tls13 \
 	-L${TOPDIR}/../libssl_crypto_common -lssl_crypto_common \
 	-L${TOPDIR}/../libssl_utils -lssl_utils \
+	-L${TOPDIR}/../libasn1c -lasncodec \
 	-L${TOPDIR}/../libqat_common_api -lqat_common_api \
 	-L${TOPDIR}/../libqat_cy_api -lqat_cy_api \
 	-L${TOPDIR}/../libipp -lippcp \
@@ -124,6 +125,7 @@
 	-L${TOPDIR}/../libopenssl-1.1.1 -lcrypto-tls13 \
 	-L${TOPDIR}/../libssl_crypto_common -lssl_crypto_common \
 	-L${TOPDIR}/../libssl_utils -lssl_utils \
+	-L${TOPDIR}/../libasn1c -lasncodec \
 	-L${TOPDIR}/../libproxy_shared_cli -lproxy_shared_cli \
 	-L${TOPDIR}/../libfeactl -lfeactl \
 	-L${TOPDIR}/../libexception -lexception \
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/click/lib/libuinet-atcp/lib/libuinet/Makefile	(working copy)
@@ -33,7 +33,7 @@
 RTE_TARGET=arm64-armv8a-linuxapp-gcc
 endif
 
-HOST_INCLUDES= -I. -I${API_INCLUDES_ROOT} -I../libuinetnv -I${RTE_SDK}/${RTE_TARGET}/include -I${TOPDIR}/../../include -I${TOPDIR}/lib/libev -I${TOPDIR}/../libenv -I${TOPDIR}/../librax -I${TOPDIR}/../libaes_util -I${TOPDIR}/../libepolicy -I${TOPDIR}/../libcautil
+HOST_INCLUDES= -I. -I${API_INCLUDES_ROOT} -I../libuinetnv -I${RTE_SDK}/${RTE_TARGET}/include -I${TOPDIR}/../../include -I${TOPDIR}/lib/libev -I${TOPDIR}/../libenv -I${TOPDIR}/../librax -I${TOPDIR}/../libaes_util -I${TOPDIR}/../libepolicy -I${TOPDIR}/../libcautil -I${TOPDIR}/../libasn1c
 
 ifeq (${ARM64}, yes)
 INCLUDES+= -I${RTE_SDK} -I${S}/dev/cavium -I${S}/dev/sslhw_wrap ${HOST_INCLUDES} 
Index: /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/src/sys/click/netinet/click_input.c
===================================================================
--- /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/src/sys/click/netinet/click_input.c	(revision 39185)
+++ /branches/rel_apv_10_7_2_17_bhel_h323_nat/usr/src/sys/click/netinet/click_input.c	(working copy)
@@ -302,6 +302,7 @@
 extern atcp_zone_t orch_session_node_zone;
 extern int qat_card_count;
 
+
 slb_rs_t *sf_handle_event_slb_find_rs(struct sf_event_data_slb_find_rs *p_event_rs_data);
 
 extern int orch_check_and_handle_pcb_output(clickpcb_t *pcb, struct mbuf *send_m, int is_ipv6);
@@ -314,6 +315,18 @@
 static void clicktcp_conn_chk_timo(void *dummy);
 void ssl_handshake_statistics();
 
+/* H323 Video conference protocol specific */
+#define H225_PORT          1720
+#define TPKT_VER           0x03
+#define TPKT_RES           0x00
+#define H245_OPEN_CHAN     0x03
+#define H245_OPEN_CHAN_ACK 0x22
+
+#define H323_NAT_ENABLE 1
+#define H323_NAT_DISABLE 0
+
+int h323_nat_config = H323_NAT_DISABLE;
+
 #define TICKS_TIMEROUT(now, expected) ((int)((unsigned int)(now) - (unsigned int)(expected)) >= 0)
 
 #ifdef MALLOC_DEFINE
@@ -4861,6 +4874,56 @@
 	HTONS(tcpip->ti_win);
 }
 
+int show_h323_status_kern(void *pcb)
+{
+    if (h323_nat_config == H323_NAT_ENABLE)
+        app_printf(pcb, "H323 natting is enabled.\n");
+    else
+        app_printf(pcb, "H323 natting is disabled.\n");
+    return 0;
+        
+}
+int h323_enable_kern(void *pcb)
+{
+    h323_nat_config = H323_NAT_ENABLE; 
+    return 0;
+}
+int h323_disable_kern(void *pcb)
+{
+    h323_nat_config = H323_NAT_DISABLE; 
+    return 0;
+}
+
+int write_h323_nat_config_kern(void *pcb, void **ptr, int32_t *len)
+{
+        char *buff, *pos;
+        int buff_len;
+
+        if (h323_nat_config == H323_NAT_ENABLE) {
+            buff_len =  strlen ("h323 nat enable\n") + 1;
+            MALLOC(buff, char *, buff_len, M_TEMP, M_NOWAIT);
+        }
+        else {
+            buff_len =  strlen ("h323 nat disable\n") + 1;
+            MALLOC(buff, char *, buff_len, M_TEMP, M_NOWAIT);
+        }
+        if (buff == NULL) {
+                app_printf(pcb, "No enough memory. Failed to write H323 nat config.\n");
+                *ptr = NULL;
+                *len = 0;
+                return -1;
+        }
+        if (h323_nat_config == H323_NAT_ENABLE)
+            sprintf (buff, "h323 nat enable\n");
+        else
+            sprintf (buff, "h323 nat disable\n");
+        
+        
+        *ptr = buff;
+        *len = buff_len;
+
+        return 0;
+}
 /*
  * ClickTCP input routine.  Checksum and byte swap header.  Call
  * appropriate handler function based no current state and flags.
@@ -4881,6 +4944,11 @@
     clickpcb_t *pcb;
     u_char ip_p;
     struct eroute_rule *erule = NULL;
+    uint16_t ip_len;
+    int tcp_paylad_len;
+    uint8_t *tcp_payload_begin;
+
+    uint32_t NAT_IP = 0;
 
     if (vipstats) {
         clickipstat.ips_total++;
@@ -5150,6 +5218,24 @@
 		}
 
 		if (pcb) {
+                        if (ip_p == IPPROTO_TCP && (h323_nat_config == H323_NAT_ENABLE)) {
+                            ip_len = ip->ip_len;
+                            tcp_paylad_len = ip_len - sizeof (struct ip) - (tcph->th_off << 2);
+                            if (tcp_paylad_len > 20 && pcb->splice_data.target)  { //Min 20 bytes tcp payload for H323 protcol 
+                                tcp_payload_begin = (uint8_t *)tcph + (tcph->th_off<<2);
+                                /* H225 Natting */
+                                if (pcb->cp_localport == H225_PORT) {
+                                    NAT_IP = ntohl(pcb->splice_data.target->cp_localip.s_addr);
+                                    nat_h323_payload (tcp_payload_begin, tcp_paylad_len, NAT_IP, 0);
+                                /* H245 Natting */
+                                } else if ((tcp_payload_begin[0] == TPKT_VER) &&
+                                        (tcp_payload_begin[1] == TPKT_RES) && 
+                                        ((tcp_payload_begin[4] == H245_OPEN_CHAN) || (tcp_payload_begin[4] == H245_OPEN_CHAN_ACK))) {
+                                    NAT_IP = ntohl(pcb->splice_data.target->cp_localip.s_addr);
+                                    nat_h323_payload (tcp_payload_begin, tcp_paylad_len, NAT_IP, 0);
+                                }
+			    }
+			}
 			/* bridge packets */
 			erule = pcb->cp_eroute.rule;
 
@@ -12066,6 +12152,7 @@
 							"clicktcp_handler_timewait_ack got bad request "
 							"(%u, %u), %u, %d, %d\n", tcp->th_seq, tcp->th_ack, 
 							pcb->recvnextseq, pcb->cp_remoteport, datalen);
+
 					clicktcp_send_reset(pcb, tcp->th_ack, (RST_APP_ID_TCP | RST_ID_1));
 					clicktcp_leave_func(int, 0);
 				}
@@ -17029,6 +17116,10 @@
 			pcb->cp_localport, pcb->cp_remoteport, idle_timeout,
 			pcb->sendenddata - pcb->sendnextseq,
 			pcb->sendrightwin - pcb->sendnextseq);
+	printf ("%d %d persistence timer (%d) expired, killing data %d win %d\n",
+			pcb->cp_localport, pcb->cp_remoteport, idle_timeout,
+			pcb->sendenddata - pcb->sendnextseq,
+			pcb->sendrightwin - pcb->sendnextseq);
 
 	if (pcb->cp_flags & CLICKPCB_SPLICE_FLAGS) {
 	/* spliced connection */
