/*	HLR CDMA cdr coding 				*/
/*	Created by daniel:2005-06-21		*/
/*	Modify  by daniel:2005-06-21		*/
/*	--------------------------------	*/

#include "../../public/src/include/asn1.h"
#include "../../public/src/include/includes.h"
#include "../../public/src/include/pub_fmt.h"
#include "../../sccp/src/include/sccp.h"
#include "./mapp/map_const.h"
#include "xap_cdmacdr.h"

// fix multiple definition====================================
struct	xap_vm_struct		*xap_vm_ptr;
struct	xap_inter_struct	*xap_inter_ptr;
//

char *is41_sequenceTag(char *tag,int sequence);

void encode_param_CallLocation(DMH_CallLocation *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;
	u8			temp[8];

	flag = ptr->param_flag;

	*buf_len = AddTLV(tag1,0,temp,0x60,asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_HCOORD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->HcoordinateLen % 3,ptr->Hcoordinate,0x40,asn_buf);
	}
	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NPANXX);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),3,ptr->NPANXX,0x40,asn_buf);
	}
	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_PLNAM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->PlaceNameLen % 20,ptr->PlaceName,0x40,asn_buf);
	}
	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SPNAM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),2,ptr->StateProvinceName,0x40,asn_buf);
	}
	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_VCOORD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->VcoordinateLen % 3,ptr->Vcoordinate,0x40,asn_buf);
	}
	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_LATA);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->LocalAccessTransportAreaLen % 4,ptr->LocalAccessTransportArea,0x40,asn_buf);
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_WCNTRY);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),3,ptr->WorldCountry,0x40,asn_buf);
	}
}

void encode_param_cnvusg(DMH_ConversationUsage *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;
	u8			temp[8];

	flag = ptr->param_flag;

	*buf_len = AddTLV(tag1,0,temp,0x60,asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->durLen % 5,ptr->dur,0x40,asn_buf);
	}
	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->todLen % 4,ptr->tod,0x40,asn_buf);
	}
	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DATE);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),3,ptr->Date,0x40,asn_buf);
	}
	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RELIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->relind,0x40,asn_buf);
	}
	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TDO);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->tdoLen % 3,ptr->tdo,0x40,asn_buf);
	}
	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMOCT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numoctLen % 5,ptr->numoct,0x40,asn_buf);
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMPKT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numpktLen % 5,ptr->numpkt,0x40,asn_buf);
	}
}

void encode_param_swid(DMH_SwitchID *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			temp[8];

	flag = ptr->param_flag;

	*buf_len = AddTLV(tag1,0,temp,0x60,asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SWNO);
		*buf_len = AddTLV(tag,1,&ptr->swno,0x40,asn_buf);
	}
	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SID);
		*buf_len = AddTLV(tag,2,ptr->sid,0x40,asn_buf);
	}
	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_BRI);
		*buf_len = AddTLV(tag,2,ptr->bri,0x40,asn_buf);
	}
	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_MYTYP);
		*buf_len = AddTLV(tag,1,&ptr->mytyp,0x40,asn_buf);
	}
}

void encode_param_bfpath(DMH_BeginForwardPath *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CELLID);
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->cellidLen % 3,ptr->cellid,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_MODIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,2),1,&ptr->modind,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RCHNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,3),ptr->rchnumLen % 3,ptr->rchnum,0x40,asn_buf);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TKNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,4),ptr->tknumLen % 3,ptr->tknum,0x40,asn_buf);
	}

//optional part will be encoded in the future
}

void encode_param_achusg(DMH_AirChannelUsage *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;

	*buf_len = AddTLV(tag,0,temp,0x60,asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->durLen % 5,ptr->dur,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->todLen % 4,ptr->tod,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DATE);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),3,ptr->Date,0x40,asn_buf);
	}

//optional part will be encoded in the future
}

void encode_param_fbusg(DMH_FeatureBridgeUsage *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;

	*buf_len = AddTLV(tag1,0,temp,0x60,asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FBIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->fbind,0x40,asn_buf);
	}
	
	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->durLen % 5,ptr->dur,0x40,asn_buf);
	}
	
	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RLEG);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->rlegLen % 3,ptr->rleg,0x40,asn_buf);
	}
	
	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->todLen % 4,ptr->tod,0x40,asn_buf);
	}

//optional part will be encoded in the future
}

void encode_param_incusg(DMH_IncomingTrunkUsage *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;

	*buf_len = AddTLV(tag1,0,temp,0x60,asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->durLen % 5,ptr->dur,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->todLen % 4,ptr->tod,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TKNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->tknumLen % 3,ptr->tknum,0x40,asn_buf);
	}

//optional part will be encoded in the future
}

void encode_param_ogtusg(DMH_OutgoingTrunkUsage *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;

	*buf_len = AddTLV(tag1,0,temp,0x60,asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->durLen % 5,ptr->dur,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->todLen % 4,ptr->tod,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TKNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->tknumLen % 3,ptr->tknum,0x40,asn_buf);
	}

//optional part will be encoded in the future
}

void encode_param_audsub(DMH_AuditSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;
	u8			temp[8];

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AUDSN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->audsnLen % 5,ptr->audsn,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_ACHDUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->achdurLen % 5,ptr->achdur,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CNVDUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->cnvdurLen % 5,ptr->cnvdur,0x40,asn_buf);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FBDUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->fbdurLen % 5,ptr->fbdur,0x40,asn_buf);
	}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_IECCDUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->ieccdurLen % 5,ptr->ieccdur,0x40,asn_buf);
	}

	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_INCDUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->incdurLen % 5,ptr->incdur,0x40,asn_buf);
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMACT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numactLen % 5,ptr->numact,0x40,asn_buf);
	}

	if (flag & BIT7_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMCHRG);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numchrgLen % 5,ptr->numchrg,0x40,asn_buf);
	}

	if (flag & BIT8_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMEVT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numevtLen % 5,ptr->numevt,0x40,asn_buf);
	}

	if (flag & BIT9_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMLEG);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numlegLen % 5,ptr->numleg,0x40,asn_buf);
	}

	if (flag & BIT10_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMSEG);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numsegLen % 5,ptr->numseg,0x40,asn_buf);
	}

	if (flag & BIT11_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_OGTDUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->ogtdurLen % 5,ptr->ogtdur,0x40,asn_buf);
	}

	if (flag & BIT12_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMFAL);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numfalLen % 5,ptr->numfal,0x40,asn_buf);
	}

	if (flag & BIT13_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMORG);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numorgLen % 8,ptr->numorg,0x40,asn_buf);
	}

	if (flag & BIT14_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMRED);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numredLen % 5,ptr->numred,0x40,asn_buf);
	}

	if (flag & BIT15_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMTRM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numtrmLen % 5,ptr->numtrm,0x40,asn_buf);
	}

	if (flag & BIT16_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMAUX);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numauxLen % 5,ptr->numaux,0x40,asn_buf);
	}

	if (flag & BIT17_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMOCT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numoctLen % 5,ptr->numoct,0x40,asn_buf);
	}

	if (flag & BIT18_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMPKT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numpktLen % 5,ptr->numpkt,0x40,asn_buf);
	}

	if (flag & BIT19_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_IWFDUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->iwfdurLen % 5,ptr->iwfdur,0x40,asn_buf);
	}

	if (flag & BIT20_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FILLIND);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,temp,0x60,asn_buf);

		sprintf(tag,"%s.%d.%d",tag1,DMHPAR_FILLIND,DMHPAR_FPARM);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->fillind.FaultyParameter.ParameterIdentifierLen % 17,ptr->fillind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);

		sprintf(tag,"%s.%d.%d",tag1,DMHPAR_FILLIND,DMHPAR_FILLIC);//FillIndicatorCode
		*buf_len = AddTLV(is41_sequenceTag(tag,2),1,&ptr->fillind.FillIndicatorCode,0x40,asn_buf);
	}

	if (flag & BIT21_TRUE)
	{
		if (ptr->retind.param_flag & 3)
		{
			sprintf(tag,"%s.%d",tag1,DMHPAR_RETIND);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,temp,0x60,asn_buf);
		}

		if (ptr->retind.param_flag & BIT0_TRUE)
		{
			sprintf(tag,"%s.%d.%d",tag1,DMHPAR_RETIND,DMHPAR_RICODE);//ReturnIndicatorCode
			*buf_len = AddTLV(is41_sequenceTag(tag,3),1,&ptr->retind.ReturnIndicatorCode,0x40,asn_buf);
		}
		if (ptr->retind.param_flag & BIT1_TRUE)
		{
			sprintf(tag,"%s.%d.%d",tag1,DMHPAR_RETIND,DMHPAR_FPARM);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,4),ptr->retind.FaultyParameter.ParameterIdentifierLen % 17,ptr->retind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);
		}
	}
}

void encode_param_idsub(DMH_IdentitySubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_DATE,offset++);
		*buf_len = AddTLV(tag,3,ptr->Date,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		if (ptr->Choice1.ChoiceFlag == 0)
		{
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_ESN,offset++);
			*buf_len = AddTLV(tag,4,ptr->Choice1.esn,0x40,asn_buf);
		}
		else
		{
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_IMEI,offset++);
			*buf_len = AddTLV(tag,5,ptr->Choice1.imei,0x40,asn_buf);
		}
	}

	if (flag & BIT2_TRUE)
	{
		switch (ptr->Choice2.ChoiceFlag)
		{
		case 0:
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_MIN,offset++);
			*buf_len = AddTLV(tag,5,ptr->Choice2.min,0x40,asn_buf);
			break;
		case 1:
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_IMSI,offset++);
			*buf_len = AddTLV(tag,8,ptr->Choice2.imsi,0x40,asn_buf);
			break;
		case 2:
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_NEICLNP,offset++);
			*buf_len = AddTLV(tag,19,ptr->Choice2.neiclnp,0x40,asn_buf);
			break;
		case 3:
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_NEIIP,offset++);
			*buf_len = AddTLV(tag,4,ptr->Choice2.neiip,0x40,asn_buf);
			break;
		default:
			break;
		}
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_TDO,offset++);
		*buf_len = AddTLV(tag,ptr->tdoLen % 3,ptr->tdo,0x40,asn_buf);
	}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_TOD,offset++);
		*buf_len = AddTLV(tag,ptr->todLen % 4,ptr->tod,0x40,asn_buf);
	}

	if (flag & BIT5_TRUE)
	{
		switch (ptr->Choice3.ChoiceFlag)
		{
		case 0:
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_ASWID,offset++);
			encode_param_swid(&ptr->Choice3.aswid,asn_buf,buf_len,tag);
			break;
		case 1:
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_OSWID,offset++);
			encode_param_swid(&ptr->Choice3.oswid,asn_buf,buf_len,tag);
			break;
		case 2:
			sprintf(tag,"%s.%d-%d",tag1,DMHPAR_SSWID,offset++);
			encode_param_swid(&ptr->Choice3.sswid,asn_buf,buf_len,tag);
			break;
		default:
			break;
		}
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_BIN,offset++);
		*buf_len = AddTLV(tag,ptr->binLen % 5,ptr->bin,0x40,asn_buf);
	}

	if (flag & BIT7_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_HSWID,offset++);
		encode_param_swid(&ptr->hswid,asn_buf,buf_len,tag);
	}

	if (flag & BIT8_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_MDN,offset++);
		*buf_len = AddTLV(tag,ptr->mdnLen % 9,ptr->mdn,0x40,asn_buf);
	}

	if (flag & BIT9_TRUE)
	{
		sprintf(tag,"%s.%d-%d.%d",tag1,DMHPAR_FILLIND,offset++,DMHPAR_FPARM);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->fillind.FaultyParameter.ParameterIdentifierLen % 17,ptr->fillind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);

		sprintf(tag,"%s.%d-%d.%d",tag1,DMHPAR_FILLIND,offset++,DMHPAR_FILLIC);//FillIndicatorCode
		*buf_len = AddTLV(is41_sequenceTag(tag,2),1,&ptr->fillind.FillIndicatorCode,0x40,asn_buf);
	}

	if (flag & BIT10_TRUE)
	{
		if (ptr->retind.param_flag & BIT0_TRUE)
		{
			sprintf(tag,"%s.%d-%d.%d",tag1,DMHPAR_RETIND,offset++,DMHPAR_RICODE);//ReturnIndicatorCode
			*buf_len = AddTLV(is41_sequenceTag(tag,1),1,&ptr->retind.ReturnIndicatorCode,0x40,asn_buf);
		}
		if (ptr->retind.param_flag & BIT1_TRUE)
		{
			sprintf(tag,"%s.%d-%d.%d",tag1,DMHPAR_RETIND,offset++,DMHPAR_FPARM);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,2),ptr->retind.FaultyParameter.ParameterIdentifierLen % 17,ptr->retind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);
		}
	}
}

void encode_param_evtsub(DMH_EventSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_EVTIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->evtind,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->rinLen % 5,ptr->rin,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_ASWID,offset++);
		encode_param_swid(&ptr->aswid,asn_buf,buf_len,tag);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AUTHCNT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->authcnt,0x40,asn_buf);
	}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AUTHDEN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->authden,0x40,asn_buf);
	}

	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AUTHTYP);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->authtyp,0x40,asn_buf);
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_BIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->binLen % 5,ptr->bin,0x40,asn_buf);
	}

	if (flag & BIT7_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DATE);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),3,ptr->Date,0x40,asn_buf);
	}

	if (flag & BIT8_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DENACC);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->denacc,0x40,asn_buf);
	}

	if (flag & BIT9_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FEATIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->featind,0x40,asn_buf);
	}

	if (flag & BIT10_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FEATOPN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->featopn,0x40,asn_buf);
	}

	if (flag & BIT11_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FRIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->frind,0x40,asn_buf);
	}

	if (flag & BIT12_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_OSWID,offset++);
		encode_param_swid(&ptr->oswid,asn_buf,buf_len,tag);
	}

	if (flag & BIT13_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RBIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->rbinLen % 5,ptr->rbin,0x40,asn_buf);
	}

	if (flag & BIT14_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SRT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->srt,0x40,asn_buf);
	}

	if (flag & BIT15_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_SSWID,offset++);
		encode_param_swid(&ptr->sswid,asn_buf,buf_len,tag);
	}

	if (flag & BIT16_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TDO);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->tdoLen % 5,ptr->tdo,0x40,asn_buf);
	}

	if (flag & BIT17_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->todLen % 4,ptr->tod,0x40,asn_buf);
	}

	if (flag & BIT18_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FILLIND);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,temp,0x60,asn_buf);

		sprintf(tag,"%s.%d.%d",tag1,DMHPAR_FILLIND,DMHPAR_FPARM);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->fillind.FaultyParameter.ParameterIdentifierLen % 17,ptr->fillind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);

		sprintf(tag,"%s.%d.%d",tag1,DMHPAR_FILLIND,DMHPAR_FILLIC);//FillIndicatorCode
		*buf_len = AddTLV(is41_sequenceTag(tag,2),1,&ptr->fillind.FillIndicatorCode,0x40,asn_buf);
	}

	if (flag & BIT19_TRUE)
	{
		if (ptr->retind.param_flag & 3)
		{
			sprintf(tag,"%s.%d",tag1,DMHPAR_RETIND);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,temp,0x60,asn_buf);
		}

		if (ptr->retind.param_flag & BIT0_TRUE)
		{
			sprintf(tag,"%s.%d.%d",tag1,DMHPAR_RETIND,DMHPAR_RICODE);//ReturnIndicatorCode
			*buf_len = AddTLV(is41_sequenceTag(tag,3),1,&ptr->retind.ReturnIndicatorCode,0x40,asn_buf);
		}
		if (ptr->retind.param_flag & BIT1_TRUE)
		{
			sprintf(tag,"%s.%d.%d",tag1,DMHPAR_RETIND,DMHPAR_FPARM);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,4),ptr->retind.FaultyParameter.ParameterIdentifierLen % 17,ptr->retind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);
		}
	}
}

void encode_param_chrgsub(DMH_ChargeSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;
	u8			temp[8];

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGAMT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->chrgamtLen % 5,ptr->chrgamt,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->chrgind,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGTAX);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->chrgtaxLen % 5,ptr->chrgtax,0x40,asn_buf);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGTIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->chrgtind,0x40,asn_buf);
	}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGUNIT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->chrgunit,0x40,asn_buf);
	}

	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->durLen % 5,ptr->dur,0x40,asn_buf);
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_MRPI);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->mrpi,0x40,asn_buf);
	}

	if (flag & BIT7_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_PLNAM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->plnamLen % 21,ptr->plnam,0x40,asn_buf);
	}

	if (flag & BIT8_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RPI);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->rpi,0x40,asn_buf);
	}

	if (flag & BIT9_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SPNAM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),2,ptr->spnam,0x40,asn_buf);
	}

	if (flag & BIT10_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TTIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->ttind,0x40,asn_buf);
	}

	if (flag & BIT11_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_WCNTRY);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),3,ptr->wcntry,0x40,asn_buf);
	}

	if (flag & BIT12_TRUE)
	{
		if (ptr->Choice.ChoiceFlag == 0)
		{
			sprintf(tag,"%s.%d",tag1,DMHPAR_LNUM);
			*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->Choice.lnum,0x40,asn_buf);
		}
		else
		{
			sprintf(tag,"%s.%d",tag1,DMHPAR_SEGNUM);
			*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->Choice.segnum,0x40,asn_buf);
		}
	}

	if (flag & BIT13_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGTCOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->chrgtcodLen % 3,ptr->chrgtcod,0x40,asn_buf);
	}

	if (flag & BIT14_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGTTBL);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->chrgttbl,0x40,asn_buf);
	}

	if (flag & BIT15_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMOCT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numoctLen % 5,ptr->numoct,0x40,asn_buf);
	}

	if (flag & BIT16_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_NUMPKT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->numpktLen % 5,ptr->numpkt,0x40,asn_buf);
	}

	if (flag & BIT17_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SELUSE);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->seluseLen % 101,ptr->seluse,0x40,asn_buf);
	}

	if (flag & BIT18_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SUCOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->sucod,0x40,asn_buf);
	}

	if (flag & BIT19_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TEXIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->texind,0x40,asn_buf);
	}

	if (flag & BIT20_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FILLIND);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,temp,0x60,asn_buf);

		sprintf(tag,"%s.%d.%d",tag1,DMHPAR_FILLIND,DMHPAR_FPARM);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->fillind.FaultyParameter.ParameterIdentifierLen % 17,ptr->fillind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);

		sprintf(tag,"%s.%d.%d",tag1,DMHPAR_FILLIND,DMHPAR_FILLIC);//FillIndicatorCode
		*buf_len = AddTLV(is41_sequenceTag(tag,2),1,&ptr->fillind.FillIndicatorCode,0x40,asn_buf);
	}

	if (flag & BIT21_TRUE)
	{
		if (ptr->retind.param_flag & 3)
		{
			sprintf(tag,"%s.%d",tag1,DMHPAR_RETIND);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,temp,0x60,asn_buf);
		}

		if (ptr->retind.param_flag & BIT0_TRUE)
		{
			sprintf(tag,"%s.%d.%d",tag1,DMHPAR_RETIND,DMHPAR_RICODE);//ReturnIndicatorCode
			*buf_len = AddTLV(is41_sequenceTag(tag,3),1,&ptr->retind.ReturnIndicatorCode,0x40,asn_buf);
		}
		if (ptr->retind.param_flag & BIT1_TRUE)
		{
			sprintf(tag,"%s.%d.%d",tag1,DMHPAR_RETIND,DMHPAR_FPARM);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,4),ptr->retind.FaultyParameter.ParameterIdentifierLen % 17,ptr->retind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);
		}
	}
}

void encode_param_actsub(DMH_ActivitySubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_ACTIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->actind,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->rinLen % 5,ptr->rin,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AUTHDEN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->authden,0x40,asn_buf);
	}

	if (flag & BIT3_TRUE)//BeginForwardPath, encode in the future
	{}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_BIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->binLen % 5,ptr->bin,0x40,asn_buf);
	}

	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DATE);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),3,ptr->Date,0x40,asn_buf);
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DENACC);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->denacc,0x40,asn_buf);
	}

	if (flag & BIT7_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SRT);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->srt,0x40,asn_buf);
	}

	if (flag & BIT8_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_SSWID,offset++);
		encode_param_swid(&ptr->sswid,asn_buf,buf_len,tag);
	}

	if (flag & BIT9_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TDO);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->tdoLen % 3,ptr->tdo,0x40,asn_buf);
	}

	if (flag & BIT10_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TOD);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->todLen % 4,ptr->tod,0x40,asn_buf);
	}

	if (flag & BIT11_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FILLIND);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,temp,0x60,asn_buf);

		sprintf(tag,"%s.%d.%d",tag1,DMHPAR_FILLIND,DMHPAR_FPARM);//FaultyParameter
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->fillind.FaultyParameter.ParameterIdentifierLen % 17,ptr->fillind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);

		sprintf(tag,"%s.%d.%d",tag1,DMHPAR_FILLIND,DMHPAR_FILLIC);//FillIndicatorCode
		*buf_len = AddTLV(is41_sequenceTag(tag,2),1,&ptr->fillind.FillIndicatorCode,0x40,asn_buf);
	}

	if (flag & BIT12_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RSEG);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->rsegLen % 4,ptr->rseg,0x40,asn_buf);
	}

	if (flag & BIT13_TRUE)
	{
		if (ptr->retind.param_flag & 3)
		{
			sprintf(tag,"%s.%d",tag1,DMHPAR_RETIND);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,temp,0x60,asn_buf);
		}

		if (ptr->retind.param_flag & BIT0_TRUE)
		{
			sprintf(tag,"%s.%d.%d",tag1,DMHPAR_RETIND,DMHPAR_RICODE);//ReturnIndicatorCode
			*buf_len = AddTLV(is41_sequenceTag(tag,3),1,&ptr->retind.ReturnIndicatorCode,0x40,asn_buf);
		}
		if (ptr->retind.param_flag & BIT1_TRUE)
		{
			sprintf(tag,"%s.%d.%d",tag1,DMHPAR_RETIND,DMHPAR_FPARM);//FaultyParameter
			*buf_len = AddTLV(is41_sequenceTag(tag,4),ptr->retind.FaultyParameter.ParameterIdentifierLen % 17,ptr->retind.FaultyParameter.ParameterIdentifier,0x40,asn_buf);
		}
	}
}

void encode_param_airssub(DMH_AirSegmentSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_ACHUSG,offset++);
		encode_param_achusg(&ptr->achusg,asn_buf,buf_len,tag);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_SEGNUM,offset++);
		*buf_len = AddTLV(tag,1,&ptr->segnum,0x40,asn_buf);
	}

//optional part will be encoded in the future
}

void encode_param_falsub(DMH_FeatureActivationLegSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DIALDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->dialdgtsLen & 31,ptr->dialdgts,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_LNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->lnum,0x40,asn_buf);
	}
	
//optional part will be encoded in the future
	if (flag & BIT13_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FRIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->frind,0x40,asn_buf);
	}
	
	if (flag & BIT15_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_LLIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),0,&ptr->llind,0x40,asn_buf);
	}
}

void encode_param_olsub(DMH_OriginationLegSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_BILLIND,offset++);
		*buf_len = AddTLV(tag,1,&ptr->billind,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_DIALDGTS,offset++);
		*buf_len = AddTLV(tag,ptr->dialdgtsLen & 31,ptr->dialdgts,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_LNUM,offset++);
		*buf_len = AddTLV(tag,1,&ptr->lnum,0x40,asn_buf);
	}

	if (flag & BIT8_TRUE)
	{//Called Location
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CDLOC,offset++);
		encode_param_CallLocation(&ptr->CalledLocation,asn_buf,buf_len,tag);
	}

	if (flag & BIT11_TRUE)
	{//Calling Location
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CGLOC,offset++);
		encode_param_CallLocation(&ptr->CallingLocation,asn_buf,buf_len,tag);
	}

	if (flag & BIT14_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CNVUSG,offset++);
		encode_param_cnvusg(&ptr->cnvusg,asn_buf,buf_len,tag);
	}
	
	if (flag & BIT16_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_FBUSG,offset++);
		encode_param_fbusg(&ptr->fbusg,asn_buf,buf_len,tag);
	}
	
	if (flag & BIT19_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_LLIND,offset++);
		*buf_len = AddTLV(tag,0,&ptr->llind,0x40,asn_buf);
	}
	if (flag & BIT20_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_OGTUSG,offset++);
		encode_param_ogtusg(&ptr->ogtusg,asn_buf,buf_len,tag);
	}

//optional part will be encoded in the future
}

void encode_param_pacasub(DMH_PACASegmentSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CELLID);
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->cellidLen % 3,ptr->cellid,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DUR);
		*buf_len = AddTLV(is41_sequenceTag(tag,2),ptr->durLen % 5,ptr->dur,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_PACAIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,3),1,&ptr->pacaind,0x40,asn_buf);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SEGNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,4),1,&ptr->segnum,0x40,asn_buf);
	}

//optional part will be encoded in the future
}

void encode_param_rlsub(DMH_RedirectionLegSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_BILLIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->billind,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CDDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->cddgtsLen % 10,ptr->cddgts,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_INCUSG,offset++);
		encode_param_incusg(&ptr->incusg,asn_buf,buf_len,tag);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_LNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->lnum,0x40,asn_buf);
	}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_REDIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),1,&ptr->redind,0x40,asn_buf);
	}

//optional part will be encoded in the future
	if (flag & BIT6_TRUE)
	{//Called Location
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CDLOC,offset++);
		encode_param_CallLocation(&ptr->CalledLocation,asn_buf,buf_len,tag);
	}

	if (flag & BIT8_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CGDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->cgdgtsLen % 10,ptr->cgdgts,0x40,asn_buf);
	}

	if (flag & BIT9_TRUE)
	{//Calling Location
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CGLOC,offset++);
		encode_param_CallLocation(&ptr->CallingLocation,asn_buf,buf_len,tag);
	}
	
	if (flag & BIT12_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CNVUSG,offset++);
		encode_param_cnvusg(&ptr->cnvusg,asn_buf,buf_len,tag);
	}
	
	if (flag & BIT13_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_DESTDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),ptr->destdgtsLen % 10,ptr->destdgts,0x40,asn_buf);
	}
	
	if (flag & BIT18_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_LLIND,offset++);
		*buf_len = AddTLV(tag,0,&ptr->llind,0x40,asn_buf);
	}
	
	if (flag & BIT19_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_OGTUSG,offset++);
		encode_param_ogtusg(&ptr->ogtusg,asn_buf,buf_len,tag);
	}
}

void encode_param_tssub(DMH_TandemSegmentSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_OGTUSG,offset++);
		encode_param_ogtusg(&ptr->ogtusg,asn_buf,buf_len,tag);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_SEGNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,offset++),4,&ptr->segnum,0x40,asn_buf);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_TSWID,offset++);
		encode_param_swid(&ptr->tswid,asn_buf,buf_len,tag);
	}

//optional part will be encoded in the future
}

void encode_param_tlsub(DMH_TerminationLegSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];
	u8			offset=1;

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_BILLIND,offset++);
		*buf_len = AddTLV(tag,1,&ptr->billind,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_LNUM,offset++);
		*buf_len = AddTLV(tag,1,&ptr->lnum,0x40,asn_buf);
	}

//optional part will be encoded in the future
	if (flag & BIT6_TRUE)
	{//Called Location
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CDLOC,offset++);
		encode_param_CallLocation(&ptr->CalledLocation,asn_buf,buf_len,tag);
	}


	if (flag & BIT9_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CGDGTS,offset++);
		*buf_len = AddTLV(tag,ptr->cgdgtsLen,ptr->cgdgts,0x40,asn_buf);
	}

	if (flag & BIT10_TRUE)
	{//Calling Location
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CGLOC,offset++);
		encode_param_CallLocation(&ptr->CallingLocation,asn_buf,buf_len,tag);
	}

	if (flag & BIT13_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_CNVUSG,offset++);
		encode_param_cnvusg(&ptr->cnvusg,asn_buf,buf_len,tag);
	}
	if (flag & BIT16_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_FBUSG,offset++);
		encode_param_fbusg(&ptr->fbusg,asn_buf,buf_len,tag);
	}
	if (flag & BIT17_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_INCUSG,offset++);
		encode_param_incusg(&ptr->incusg,asn_buf,buf_len,tag);
	}
	if (flag & BIT19_TRUE)
	{
		sprintf(tag,"%s.%d-%d",tag1,DMHPAR_LLIND,offset++);
		*buf_len = AddTLV(tag,0,&ptr->llind,0x40,asn_buf);
	}

}

void encode_param_auxlsub(DMH_AuxiliaryLegSubrecord *ptr,ASN_BUF *asn_buf,int *buf_len,char tag1[64])
{
	u32			flag;
	char		tag[64];

	flag = ptr->param_flag;

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_BILLIND);
		*buf_len = AddTLV(is41_sequenceTag(tag,1),1,&ptr->billind,0x40,asn_buf);
	}

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_LNUM);
		*buf_len = AddTLV(is41_sequenceTag(tag,2),1,&ptr->lnum,0x40,asn_buf);
	}

//optional part will be encoded in the future
}

int assign_DMHEventJacket(DMH_EventJacket *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	char		tag[64];
	char		tag1[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

	sprintf(tag,"%d",DMHPAR_EJCKT);
	buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%d.%d-%d",DMHPAR_EJCKT,DMHPAR_AUDSUB,offset++);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);

		encode_param_audsub(&ptr->audsub,&asn_buf,&buf_len,tag);
	}
	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%d.%d-%d",DMHPAR_EJCKT,DMHPAR_IDSUB,offset++);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_idsub(&ptr->idsub,&asn_buf,&buf_len,tag);
	}

	sprintf(tag1,"%d.16-%d",DMHPAR_EJCKT,offset);
	buf_len = AddTLV(tag1,0,temp,0x20,&asn_buf);

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_EVTSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_evtsub(&ptr->evtsub,&asn_buf,&buf_len,tag);
	}
	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_chrgsub(&ptr->chrgsub,&asn_buf,&buf_len,tag);
	}

	return buf_len;
}

int assign_DMH_ActivityJacket(DMH_ActivityJacket *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	char		tag[64];
	char		tag1[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

	sprintf(tag,"%d",DMHPAR_AJCKT);
	buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%d.%d-%d",DMHPAR_AJCKT,DMHPAR_AUDSUB,offset++);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_audsub(&ptr->audsub,&asn_buf,&buf_len,tag);
	}
	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%d.%d-%d",DMHPAR_AJCKT,DMHPAR_IDSUB,offset++);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_idsub(&ptr->idsub,&asn_buf,&buf_len,tag);
	}

	sprintf(tag1,"%d.16-%d",DMHPAR_AJCKT,offset);
	buf_len = AddTLV(tag1,0,temp,0x20,&asn_buf);

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_ACTSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_actsub(&ptr->actsub,&asn_buf,&buf_len,tag);
	}
	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_chrgsub(&ptr->chrgsub,&asn_buf,&buf_len,tag);
	}

	return buf_len;
}

int assign_DMH_CallJacket(DMH_CallJacket *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	char		tag[64];
	char		tag1[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

	sprintf(tag,"%d",DMHPAR_CJCKT);
	buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%d.%d-%d",DMHPAR_CJCKT,DMHPAR_AUDSUB,offset++);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_audsub(&ptr->audsub,&asn_buf,&buf_len,tag);
	}
	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%d.%d-%d",DMHPAR_CJCKT,DMHPAR_IDSUB,offset++);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_idsub(&ptr->idsub,&asn_buf,&buf_len,tag);
	}

	sprintf(tag1,"%d.16-%d",DMHPAR_CJCKT,offset);
	buf_len = AddTLV(tag1,0,temp,0x20,&asn_buf);

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_ACTSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_actsub(&ptr->actsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AIRSSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_airssub(&ptr->airssub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_chrgsub(&ptr->chrgsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FALSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_falsub(&ptr->falsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_OLSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_olsub(&ptr->olsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT7_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_PACASUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_pacasub(&ptr->pacasub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT8_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RLSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_rlsub(&ptr->rlsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT9_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TSSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_tssub(&ptr->tssub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT10_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TLSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_tlsub(&ptr->tlsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT11_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AUXLSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_auxlsub(&ptr->auxlsub,&asn_buf,&buf_len,tag);
	}

	return buf_len;
}

int assign_DMH_LegJacket(DMH_LegJacket *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	char		tag[64];
	char		tag1[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

	sprintf(tag,"%d",DMHPAR_LJCKT);
	buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%d.%d-%d",DMHPAR_LJCKT,DMHPAR_IDSUB,offset++);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_idsub(&ptr->idsub,&asn_buf,&buf_len,tag);
	}

	sprintf(tag1,"%d.16-%d",DMHPAR_LJCKT,offset);
	buf_len = AddTLV(tag1,0,temp,0x20,&asn_buf);

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_chrgsub(&ptr->chrgsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_FALSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_falsub(&ptr->falsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_OLSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_olsub(&ptr->olsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_RLSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_rlsub(&ptr->rlsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TLSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_tlsub(&ptr->tlsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT6_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AUXLSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_auxlsub(&ptr->auxlsub,&asn_buf,&buf_len,tag);
	}

	return buf_len;
}

int assign_DMH_SegmentJacket(DMH_SegmentJacket *ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	char		tag[64];
	char		tag1[64];
	u8			temp[8];
	u8			offset=1;

	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

	sprintf(tag,"%d",DMHPAR_SJCKT);
	buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);

	if (flag & BIT0_TRUE)
	{
		sprintf(tag,"%d.%d-%d",DMHPAR_SJCKT,DMHPAR_IDSUB,offset++);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_idsub(&ptr->idsub,&asn_buf,&buf_len,tag);
	}

	sprintf(tag1,"%d.16-%d",DMHPAR_SJCKT,offset);
	buf_len = AddTLV(tag1,0,temp,0x20,&asn_buf);

	if (flag & BIT1_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_ACTSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_actsub(&ptr->actsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT2_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_AIRSSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_airssub(&ptr->airssub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT3_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_CHRGSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_chrgsub(&ptr->chrgsub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT4_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_PACASUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_pacasub(&ptr->pacasub,&asn_buf,&buf_len,tag);
	}

	if (flag & BIT5_TRUE)
	{
		sprintf(tag,"%s.%d",tag1,DMHPAR_TSSUB);
		buf_len = AddTLV(tag,0,temp,0x60,&asn_buf);
		encode_param_tssub(&ptr->tssub,&asn_buf,&buf_len,tag);
	}

	return buf_len;
}


void encode_DMH_date(u8 *date)
{
	time_t		tick;
	struct tm	*tm_ptr;
	
	time(&tick);
	tm_ptr	= gmtime(&tick);
	date[0]	= tm_ptr->tm_year-84;	//+1900-1984
	date[1]	= tm_ptr->tm_mon+1;
	date[2]	= tm_ptr->tm_mday;
}

u8 encode_DMH_TimeDateOffset(u8 *TimeDateOffset)
{
	struct timeval	tv;
	struct timezone	tz;
	
	gettimeofday(&tv, &tz);
	return encode_integer(TimeDateOffset,tz.tz_minuteswest);
}

u8 encode_DMH_TimeOfDay(u8 *TimeOfDay)
{
	struct timeval	tv;
	struct timezone	tz;
	u32		time;
	
	gettimeofday(&tv, &tz);
	
	time	= (tv.tv_sec%86400)*10+tv.tv_usec/100000;
	
	return encode_integer(TimeOfDay, time);
}
