/*	is41 coding auc service file		*/
/*	written by daniel zhang 2004-06-16	*/
/*  modified by daniel on 2004-07-09	*/
/*	--------------------------------	*/

#include "map_includes.h"
/* external functions */
void is41_log(char *info);
void is41_debug(DWORD mask, const char *fmt, ...);
void is41_showbuf(DWORD mask, BYTE *buf, int len);
int	decode_Is41Parameter(char *tag,int len,BYTE *value,ASN_BUF *asn_buf);
char *is41_sequenceTag(char *tag,int sequence);

/*	+++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding security triplets argument	*/
/*	+++++++++++++++++++++++++++++++++++++++++++++	*/

int assign_is41RegistrationNotification_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag,flag1;
	struct		IS41_REGNOT_ARG 	*ptr;
	struct		IS41_PAR_WIN_CAP	*ptr1;
	char		tag[64];
	
	ptr = &opr_ptr->msg_list.regnot_arg;
	
	flag = ptr->param_flag;
	
	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,1),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}
	if((flag & BIT1_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,2),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

	if((flag & BIT2_TRUE)>0)		//MSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCID,3),3,ptr->mscid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MSCID absent!!");
		return 0;
	}

	if((flag & BIT3_TRUE)>0)		//QualificationInformationCode
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_QUALCODE,4),1,&ptr->qualcode,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:QUALCODE absent!!");
		return 0;
	}

	if((flag & BIT4_TRUE)>0)		//SystemMyTypeCode
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MYTYP,5),1,&ptr->mytyp,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MYTYP absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT5_TRUE)>0)		//Availability Type
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AVTYP,6),1,&ptr->avtyp,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)		//BorderCellAccess
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BORDACC,7),1,&ptr->bordacc,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)		//ControlChannelData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CCDATA,8),4,ptr->ccdata,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)		//ExtendedMSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_EXTMSCID,9),4,ptr->extmscid,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)		//LocationAreaID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_LOCID,10),2,ptr->locid,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)		//pcssn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PCSSN,11),5,ptr->pcssn,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)		//ReceivedSignalQuality
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSIGQUAL,12),1,&ptr->rsigqual,0x80,&asn_buf);

	if((flag & BIT12_TRUE)>0)		//rpttyp
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RPTTYP,13),1,&ptr->rpttyp,0x80,&asn_buf);

	if((flag & BIT13_TRUE)>0)		//senderin
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,14),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	if((flag & BIT14_TRUE)>0)		//SMS_DestinationAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSADDR,15),ptr->smsaddrLen & MAX_IS41_VARPAR_LEN_1,ptr->smsaddr,0x80,&asn_buf);

	if((flag & BIT15_TRUE)>0)		//smsmwi
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSMWI,16),0,&ptr->smsmwi,0x80,&asn_buf);

	if((flag & BIT16_TRUE)>0)		//sysaccdata
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSACCDATA,16),5,ptr->sysaccdata,0x80,&asn_buf);

	if((flag & BIT17_TRUE)>0)		//sysacctype
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSACCTYPE,17),1,&ptr->sysacctype,0x80,&asn_buf);

	if((flag & BIT18_TRUE)>0)		//syscap
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSCAP,18),1,&ptr->syscap,0x80,&asn_buf);

	if((flag & BIT19_TRUE)>0)		//termtyp
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTYP,19),1,&ptr->termtyp,0x80,&asn_buf);

	if((flag & BIT20_TRUE)>0)		//transcap
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TRANSCAP,20),ptr->transcapLen & MAX_IS41_VARPAR_LEN_1,ptr->transcap,0x80,&asn_buf);

	if((flag & BIT21_TRUE)>0)		//wincap
	{
		ptr1 = &ptr->wincap;
		flag1 = ptr1->param_flag;
		if (!(flag1 & 0x03))
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:wincap no content!!");
			return 0;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_WINCAP,21),0,NULL,0xA0,&asn_buf);
		if((flag1 & BIT0_TRUE)>0)		//triggercapability
		{
			sprintf(tag,"%s.%s",IS41PAR_WINCAP,IS41PAR_TRIGCAP);
			buf_len = AddTLV(is41_sequenceTag(tag,1),ptr1->triggercapLen & MAX_IS41_VARPAR_LEN_1,ptr1->triggercap,0x80,&asn_buf);
		}
		if((flag1 & BIT1_TRUE)>0)		//winoperationscapability
		{
			sprintf(tag,"%s.%s",IS41PAR_WINCAP,IS41PAR_WINOPRCAP);
			buf_len = AddTLV(is41_sequenceTag(tag,2),ptr1->winoprcapLen & MAX_IS41_VARPAR_LEN_1,ptr1->winoprcap,0x80,&asn_buf);
		}
	}
	
	return buf_len;
}

int decode_param_profile(IS41_PAR_PROFILE *ptr,ASN_BUF *asn_buf)
{
	int		len,i,count;
	char	tag[64];
	IS41_PAR_TRIGGER_LIST	*ptr1;
	
	ptr->param_flag = 0;

	len = decode_Is41Parameter(IS41PAR_AUTHCAP,MAX_IS41_VARPAR_LEN,ptr->authcap,asn_buf);
	if (len > 0)
	{
		ptr->authcapLen = len;
		ptr->param_flag |= BIT0_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_CFI,MAX_IS41_VARPAR_LEN,ptr->cfi,asn_buf);
	if (len > 0)
	{
		ptr->cfiLen = len;
		ptr->param_flag |= BIT1_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_CARDGTS,MAX_IS41_VARPAR_LEN,ptr->cardgts,asn_buf);
	if (len > 0)
	{
		ptr->cardgtsLen = len;
		ptr->param_flag |= BIT2_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_ACDGTS,MAX_IS41_VARPAR_LEN,ptr->acdgts,asn_buf);
	if (len > 0)
	{
		ptr->acdgtsLen = len;
		ptr->param_flag |= BIT3_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_ABDGTS,MAX_IS41_VARPAR_LEN,ptr->abdgts,asn_buf);
	if (len > 0)
	{
		ptr->abdgtsLen = len;
		ptr->param_flag |= BIT4_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_BILLDGTS,MAX_IS41_VARPAR_LEN,ptr->billdgts,asn_buf);
	if (len > 0)
	{
		ptr->billdgtsLen = len;
		ptr->param_flag |= BIT5_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_GEOAUTH,MAX_IS41_VARPAR_LEN,ptr->geoauth,asn_buf);
	if (len > 0)
	{
		ptr->geoauthLen = len;
		ptr->param_flag |= BIT6_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_MWNCOUNT,MAX_IS41_VARPAR_LEN,ptr->mwncount,asn_buf);
	if (len > 0)
	{
		ptr->mwncountLen = len;
		ptr->param_flag |= BIT7_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_MWNCOUNT,MAX_IS41_VARPAR_LEN,ptr->mwncount,asn_buf);
	if (len > 0)
	{
		ptr->mwncountLen = len;
		ptr->param_flag |= BIT8_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_MDN,MAX_IS41_VARPAR_LEN,ptr->mdn,asn_buf);
	if (len > 0)
	{
		ptr->mdnLen = len;
		ptr->param_flag |= BIT9_TRUE;
	}

	if (decode_Is41Parameter(IS41PAR_ORIGIND,1,&ptr->origind,asn_buf))
		ptr->param_flag |= BIT10_TRUE;

	len = decode_Is41Parameter(IS41PAR_ORIGTRIG,MAX_IS41_VARPAR_LEN,ptr->origtrig,asn_buf);
	if (len > 0)
	{
		ptr->origtrigLen = len;
		ptr->param_flag |= BIT11_TRUE;
	}

	if (decode_Is41Parameter(IS41PAR_PACAIND,1,&ptr->pacaind,asn_buf))
		ptr->param_flag |= BIT12_TRUE;

	if (decode_Is41Parameter(IS41PAR_PLIND,1,&ptr->plind,asn_buf))
		ptr->param_flag |= BIT13_TRUE;

	len = decode_Is41Parameter(IS41PAR_RESDGTS,MAX_IS41_VARPAR_LEN,ptr->resdgts,asn_buf);
	if (len > 0)
	{
		ptr->resdgtsLen = len;
		ptr->param_flag |= BIT14_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_ROUTDGTS,MAX_IS41_VARPAR_LEN,ptr->routdgts,asn_buf);
	if (len > 0)
	{
		ptr->routdgtsLen = len;
		ptr->param_flag |= BIT15_TRUE;
	}

	if (decode_Is41Parameter(IS41PAR_SMSORGRES,1,&ptr->smsorgres,asn_buf))
		ptr->param_flag |= BIT16_TRUE;

	if (decode_Is41Parameter(IS41PAR_SMSTERMRES,1,&ptr->smstermres,asn_buf))
		ptr->param_flag |= BIT17_TRUE;

	len = decode_Is41Parameter(IS41PAR_SPINIPIN,MAX_IS41_VARPAR_LEN,ptr->spinipin,asn_buf);
	if (len > 0)
	{
		ptr->spinipinLen = len;
		ptr->param_flag |= BIT18_TRUE;
	}

	len = decode_Is41Parameter(IS41PAR_SPINITRIG,MAX_IS41_VARPAR_LEN,ptr->spinitrig,asn_buf);
	if (len > 0)
	{
		ptr->spinitrigLen = len;
		ptr->param_flag |= BIT19_TRUE;
	}

	if (decode_Is41Parameter(IS41PAR_TERMRES,1,&ptr->termres,asn_buf))
		ptr->param_flag |= BIT20_TRUE;

	len = decode_Is41Parameter(IS41PAR_TERMTRIG,MAX_IS41_VARPAR_LEN,ptr->termtrig,asn_buf);
	if (len > 0)
	{
		ptr->termtrigLen = len;
		ptr->param_flag |= BIT21_TRUE;
	}
	
	ptr->triggerlistnum = 0;
	for (i = 0; i < MAX_IS41_TRIG_LIST_NUM; i++)
	{
		ptr1 = &ptr->triggerlist[i];
		count = 0;
		sprintf(tag, "%s.%s-%d.%s", IS41PAR_TRIGADRLIST, IS41PAR_TRIGLIST, i+1, IS41PAR_GLOBALTITLE);
		len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr1->destaddr,asn_buf);
		if (len > 0)
		{
			ptr1->param_flag |= BIT0_TRUE;
			ptr1->destaddrLen = len & MAX_IS41_VARPAR_LEN_1;
			count++;
		}
		sprintf(tag, "%s.%s-%d.%s", IS41PAR_TRIGADRLIST, IS41PAR_TRIGLIST, i+1, IS41PAR_WINTRIGLIST);
		if (get_null(tag,asn_buf))
		{
			len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr1->wintriglist,asn_buf);
			if (len >= 0)
			{
				ptr1->param_flag |= BIT1_TRUE;
				ptr1->wintriglistLen = len & MAX_IS41_VARPAR_LEN_1;
				count++;
			}
		}
		if (count == 2)
		{
			ptr->triggerlistnum++;
			ptr->param_flag |= BIT22_TRUE;
		}
		else if (count == 1)
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:triggerlist lacks mandatory info!!");
			return 0;
		}
		else if (!count)
			break;
	}
	
	if (ptr->param_flag>0)
		return 1;
	return 0;
}

int encode_param_profile(struct IS41_PAR_PROFILE *ptr,u32 flag,ASN_BUF *asn_buf,int *buf_len)
{
	u32			flag1;
	struct		IS41_PAR_TRIGGER_LIST	*ptr1;
	u8			i,triglistnum;
	char		tag[64];
	
	if((flag & BIT0_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHCAP,1),ptr->authcapLen & MAX_IS41_VARPAR_LEN_1,ptr->authcap,0x80,asn_buf);
	if((flag & BIT1_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_CFI,2),ptr->cfiLen & MAX_IS41_VARPAR_LEN_1,ptr->cfi,0x80,asn_buf);
	if((flag & BIT2_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_CARDGTS,3),ptr->cardgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->cardgts,0x80,asn_buf);
	if((flag & BIT3_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACDGTS,4),ptr->acdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->acdgts,0x80,asn_buf);
	if((flag & BIT4_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_ABDGTS,5),ptr->abdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->abdgts,0x80,asn_buf);
	if((flag & BIT5_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLDGTS,6),ptr->billdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->billdgts,0x80,asn_buf);
	if((flag & BIT6_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_GEOAUTH,7),ptr->geoauthLen & MAX_IS41_VARPAR_LEN_1,ptr->geoauth,0x80,asn_buf);
	if((flag & BIT7_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_MWNCOUNT,8),ptr->mwncountLen & MAX_IS41_VARPAR_LEN_1,ptr->mwncount,0x80,asn_buf);
	if((flag & BIT8_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_MWNTYPE,9),ptr->mwntypeLen & MAX_IS41_VARPAR_LEN_1,ptr->mwntype,0x80,asn_buf);
	if((flag & BIT9_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_MDN,10),ptr->mdnLen & MAX_IS41_VARPAR_LEN_1,ptr->mdn,0x80,asn_buf);
	if((flag & BIT10_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_ORIGIND,11),1,&ptr->origind,0x80,asn_buf);
	if((flag & BIT11_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_ORIGTRIG,12),ptr->origtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->origtrig,0x80,asn_buf);
	if((flag & BIT12_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_PACAIND,13),1,&ptr->pacaind,0x80,asn_buf);
	if((flag & BIT13_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_PLIND,14),1,&ptr->plind,0x80,asn_buf);
	if((flag & BIT14_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_RESDGTS,15),ptr->resdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->resdgts,0x80,asn_buf);
	if((flag & BIT15_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_ROUTDGTS,16),ptr->routdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->routdgts,0x80,asn_buf);
	if((flag & BIT16_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSORGRES,17),1,&ptr->smsorgres,0x80,asn_buf);
	if((flag & BIT17_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSTERMRES,18),1,&ptr->smstermres,0x80,asn_buf);
	if((flag & BIT18_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_SPINIPIN,19),ptr->spinipinLen & MAX_IS41_VARPAR_LEN_1,ptr->spinipin,0x80,asn_buf);
	if((flag & BIT19_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_SPINITRIG,20),ptr->spinitrigLen & MAX_IS41_VARPAR_LEN_1,ptr->spinitrig,0x80,asn_buf);
	if((flag & BIT20_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMRES,21),1,&ptr->termres,0x80,asn_buf);
	if((flag & BIT21_TRUE)>0)
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTRIG,22),ptr->termtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrig,0x80,asn_buf);
	
	if((flag & BIT22_TRUE)>0)		//TriggerAddressList
	{
		triglistnum = ptr->triggerlistnum & MAX_IS41_TRIG_LIST_NUM_1;
		if (!triglistnum)
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:TriggerAddressList no content!!");
			return 0;
		}
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_TRIGADRLIST,23),0,NULL,0xA0,asn_buf);
		for (i = 0; i < triglistnum; i++)
		{
			ptr1 = &ptr->triggerlist[i];
			flag1 = ptr1->param_flag;
			if ((flag1 & 0x03) != 0x03)
			{
				is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:triggerlist lacks mandatory info!!");
				return 0;
			}
			sprintf(tag,"%s.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST);
			*buf_len = AddTLV(is41_sequenceTag(tag,i+1),0,NULL,0xA0,asn_buf);
			if((flag1 & BIT0_TRUE)>0)		//destinationaddress -- choice global title
			{
				sprintf(tag,"%s.%s-%d.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST,i+1,IS41PAR_GLOBALTITLE);
				*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr1->destaddrLen & MAX_IS41_VARPAR_LEN_1,ptr1->destaddr,0x80,asn_buf);
			}
			if((flag1 & BIT1_TRUE)>0)		//winoperationscapability
			{
				sprintf(tag,"%s.%s-%d.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST,i+1,IS41PAR_WINTRIGLIST);
				*buf_len = AddTLV(is41_sequenceTag(tag,2),ptr1->wintriglistLen & MAX_IS41_VARPAR_LEN_1,ptr1->wintriglist,0x80,asn_buf);
			}
		}
	}
	
	return 1;
}

int encode_param_isterm(struct IS41_PAR_ISTERM *ptr,u32 flag,ASN_BUF *asn_buf,int *buf_len)
{
	char		tag[64];

	if((flag & BIT0_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_DESTDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->destdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->destdgts,0x80,asn_buf);
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:DestinationDigits absent!!");
		return 0;
	}
	if((flag & BIT1_TRUE)>0)		//MSCID
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_MSCID);
		*buf_len = AddTLV(is41_sequenceTag(tag,2),3,ptr->mscid,0x80,asn_buf);
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MSCID absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT2_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_ACCDEN);
		*buf_len = AddTLV(is41_sequenceTag(tag,3),1,&ptr->accden,0x80,asn_buf);
	}
	if((flag & BIT3_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_CARDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,4),ptr->cardgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->cardgts,0x80,asn_buf);
	}
	if((flag & BIT4_TRUE)>0)		//esn
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_ESN);
		*buf_len = AddTLV(is41_sequenceTag(tag,5),ESN_LEN,ptr->esn,0x80,asn_buf);
	}
	if((flag & BIT5_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_LEGINFO);
		*buf_len = AddTLV(is41_sequenceTag(tag,6),ptr->leginfoLen & MAX_IS41_VARPAR_LEN_1,ptr->leginfo,0x80,asn_buf);
	}
	if((flag & BIT6_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_MDN);
		*buf_len = AddTLV(is41_sequenceTag(tag,7),ptr->mdnLen & MAX_IS41_VARPAR_LEN_1,ptr->mdn,0x80,asn_buf);
	}
	if((flag & BIT7_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_MSCIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,8),ptr->mscinLen & MAX_IS41_VARPAR_LEN_1,ptr->mscin,0x80,asn_buf);
	}
	if((flag & BIT8_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_ROUTDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,9),ptr->routdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->routdgts,0x80,asn_buf);
	}
	if((flag & BIT9_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_TERMTRIG);
		*buf_len = AddTLV(is41_sequenceTag(tag,10),ptr->termtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrig,0x80,asn_buf);
	}
	return 1;
}

int encode_param_locterm(struct IS41_PAR_LOCTERM *ptr,u32 flag,ASN_BUF *asn_buf,int *buf_len)
{
	char		tag[64];

	if((flag & BIT0_TRUE)>0)		//esn
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_ESN);
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ESN_LEN,ptr->esn,0x80,asn_buf);
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}
	if((flag & BIT1_TRUE)>0)		//min
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_MIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,2),MIN_LEN,ptr->min,0x80,asn_buf);
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}
	if((flag & BIT2_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_TERMTRMT);
		*buf_len = AddTLV(is41_sequenceTag(tag,3),ptr->termtrmtLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrmt,0x80,asn_buf);
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:termtrmt absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT3_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_ALRTCODE);
		*buf_len = AddTLV(is41_sequenceTag(tag,4),ptr->alrtcodeLen & MAX_IS41_VARPAR_LEN_1,ptr->alrtcode,0x80,asn_buf);
	}
	if((flag & BIT4_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_CARDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,5),ptr->cardgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->cardgts,0x80,asn_buf);
	}
	if((flag & BIT5_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_DESTDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,6),ptr->destdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->destdgts,0x80,asn_buf);
	}
	if((flag & BIT6_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_LEGINFO);
		*buf_len = AddTLV(is41_sequenceTag(tag,7),ptr->leginfoLen & MAX_IS41_VARPAR_LEN_1,ptr->leginfo,0x80,asn_buf);
	}
	if((flag & BIT7_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_MDN);
		*buf_len = AddTLV(is41_sequenceTag(tag,8),ptr->mdnLen & MAX_IS41_VARPAR_LEN_1,ptr->mdn,0x80,asn_buf);
	}
	if((flag & BIT8_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_OTFI);
		*buf_len = AddTLV(is41_sequenceTag(tag,9),ptr->otfiLen & MAX_IS41_VARPAR_LEN_1,ptr->otfi,0x80,asn_buf);
	}
	if((flag & BIT9_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_ROUTDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,10),ptr->routdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->routdgts,0x80,asn_buf);
	}
	if((flag & BIT10_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_TERMTRIG);
		*buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTRIG,11),ptr->termtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrig,0x80,asn_buf);
	}
	if((flag & BIT11_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_VMSPIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,12),ptr->vmspinLen & MAX_IS41_VARPAR_LEN_1,ptr->vmspin,0x80,asn_buf);
	}
	if((flag & BIT12_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_VMBOX);
		*buf_len = AddTLV(is41_sequenceTag(tag,13),ptr->vmboxLen & MAX_IS41_VARPAR_LEN_1,ptr->vmbox,0x80,asn_buf);
	}
	return 1;
}

int encode_param_pstnterm(struct IS41_PAR_PSTNTERM *ptr,u32 flag,ASN_BUF *asn_buf,int *buf_len)
{
	char		tag[64];

	if((flag & BIT0_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_DESTDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,1),ptr->destdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->destdgts,0x80,asn_buf);
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:DestinationDigits absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT1_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_CARDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,2),ptr->cardgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->cardgts,0x80,asn_buf);
	}

	if((flag & BIT2_TRUE)>0)		//esn
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_ESN);
		*buf_len = AddTLV(is41_sequenceTag(tag,3),ESN_LEN,ptr->esn,0x80,asn_buf);
	}
	if((flag & BIT3_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_LEGINFO);
		*buf_len = AddTLV(is41_sequenceTag(tag,4),ptr->leginfoLen & MAX_IS41_VARPAR_LEN_1,ptr->leginfo,0x80,asn_buf);
	}

	if((flag & BIT4_TRUE)>0)		//min
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_MIN);
		*buf_len = AddTLV(is41_sequenceTag(tag,5),MIN_LEN,ptr->min,0x80,asn_buf);
	}
	if((flag & BIT5_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_ROUTDGTS);
		*buf_len = AddTLV(is41_sequenceTag(tag,6),ptr->routdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->routdgts,0x80,asn_buf);
	}
	if((flag & BIT6_TRUE)>0)
	{
		sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_TERMTRIG);
		*buf_len = AddTLV(is41_sequenceTag(tag,7),ptr->termtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrig,0x80,asn_buf);
	}

	return 1;
}

int encode_param_termlist(struct IS41_PAR_TERMLIST *ptr,u32 flag,ASN_BUF *asn_buf,int *buf_len)
{	
	if ((flag & BIT0_TRUE) > 0)
	{
		if (!encode_param_isterm(&ptr->isterm,ptr->isterm.param_flag,asn_buf,buf_len))
			return 0;
	}
	
	if ((flag & BIT1_TRUE) > 0)
	{
		if (!encode_param_locterm(&ptr->locterm,ptr->locterm.param_flag,asn_buf,buf_len))
			return 0;
	}

	if ((flag & BIT2_TRUE) > 0)
	{
		if (!encode_param_pstnterm(&ptr->pstnterm,ptr->pstnterm.param_flag,asn_buf,buf_len))
			return 0;
	}

	return 1;
}

int decode_param_isterm(IS41_PAR_ISTERM *ptr,ASN_BUF *asn_buf)
{
	int		len;
	char	tag[64];

	ptr->param_flag = 0;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_DESTDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->destdgts,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT0_TRUE;
		ptr->destdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:DestinationDigits absent!");
		return 0;
	}

	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_MSCID);
	if (decode_Is41Parameter(tag,3,ptr->mscid,asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MSCID absent!");
		return 0;
	}

//optional
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_ACCDEN);
	if (decode_Is41Parameter(tag,1,&ptr->accden,asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_BILLID);
	if (decode_Is41Parameter(tag,7,ptr->billid,asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_CARDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->cardgts,asn_buf);
	if (len > 0)
	{
		ptr->cardgtsLen = len;
		ptr->param_flag |= BIT4_TRUE;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_ESN);
	if (decode_Is41Parameter(tag,ESN_LEN,ptr->esn,asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_LEGINFO);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->leginfo,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->leginfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_MDN);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->mdn,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->mdnLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_MIN);
	if (decode_Is41Parameter(tag,MIN_LEN,ptr->min,asn_buf))
		ptr->param_flag |= BIT8_TRUE;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_MSCIN);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->mscin,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->mscinLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_ROUTDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->routdgts,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->routdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_ISTERM,IS41PAR_TERMTRIG);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->termtrig,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->termtrigLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	if (ptr->param_flag>0)
		return 1;
	return 0;
}

int decode_param_locterm(IS41_PAR_LOCTERM *ptr,ASN_BUF *asn_buf)
{
	int		len;
	char	tag[64];

	ptr->param_flag = 0;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_ESN);
	if (decode_Is41Parameter(tag,ESN_LEN,ptr->esn,asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_MIN);
	if (decode_Is41Parameter(tag,MIN_LEN,ptr->min,asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_TERMTRMT);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->termtrmt,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT2_TRUE;
		ptr->termtrmtLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:termtrmt absent!");
		return 0;
	}

//optional
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_ALRTCODE);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->alrtcode,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->alrtcodeLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_CARDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->cardgts,asn_buf);
	if (len > 0)
	{
		ptr->cardgtsLen = len;
		ptr->param_flag |= BIT4_TRUE;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_DESTDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->destdgts,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->destdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_LEGINFO);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->leginfo,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->leginfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_MDN);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->mdn,asn_buf);
	if (len > 0)
	{
		ptr->mdnLen = len;
		ptr->param_flag |= BIT7_TRUE;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_OTFI);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->otfi,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->otfiLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_ROUTDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->routdgts,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->routdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_TERMTRIG);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->termtrig,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->termtrigLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_VMSPIN);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->vmspin,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->vmspinLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_LOCTERM,IS41PAR_VMBOX);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->vmbox,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT12_TRUE;
		ptr->vmboxLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	if (ptr->param_flag>0)
		return 1;
	return 0;
}

int decode_param_pstnterm(IS41_PAR_PSTNTERM *ptr,ASN_BUF *asn_buf)
{
	int		len;
	char	tag[64];
	
	ptr->param_flag = 0;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_DESTDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->destdgts,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT0_TRUE;
		ptr->destdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:DestinationDigits absent!");
		return 0;
	}

//optional

	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_CARDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->cardgts,asn_buf);
	if (len > 0)
	{
		ptr->cardgtsLen = len;
		ptr->param_flag |= BIT1_TRUE;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_ESN);
	if (decode_Is41Parameter(tag,ESN_LEN,ptr->esn,asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_LEGINFO);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->leginfo,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->leginfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_MIN);
	if (decode_Is41Parameter(tag,MIN_LEN,ptr->min,asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_ROUTDGTS);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->routdgts,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->routdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	sprintf(tag,"%s.%s.%s",IS41PAR_TERMLIST,IS41PAR_PSTNTERM,IS41PAR_TERMTRIG);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->termtrig,asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->termtrigLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	if (ptr->param_flag>0)
		return 1;
	return 0;
}

int decode_param_termlist(IS41_PAR_TERMLIST *ptr,ASN_BUF *asn_buf)
{	
	u8	count=0;

	ptr->param_flag = 0;

	if (decode_param_isterm(&ptr->isterm,asn_buf) > 0)
		ptr->param_flag |= BIT0_TRUE;
	else
		count ++;

	if (decode_param_locterm(&ptr->locterm,asn_buf) > 0)
		ptr->param_flag |= BIT1_TRUE;
	else
		count ++;

	if (decode_param_pstnterm(&ptr->pstnterm,asn_buf) > 0)
		ptr->param_flag |= BIT2_TRUE;
	else
		count ++;

	if (count > 0)
		return 1;
	return 0;
}


int assign_is41RegistrationNotification_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	u32			flag;
	ASN_BUF		asn_buf;
	int			buf_len=0;
	struct 		IS41_REGNOT_RSP 		*ptr;

	ptr = &opr_ptr->msg_list.regnot_rsp;

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

	if((flag & BIT0_TRUE)>0)		//SystemMyTypeCode
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MYTYP,1),1,&ptr->mytyp,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MYTYP absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT1_TRUE)>0)		//AuthorizationDenied
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHDEN,2),1,&ptr->authden,0x80,&asn_buf);

	if((flag & BIT2_TRUE)>0)		//AuthorizationPeriod
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHPER,3),2,ptr->authper,0x80,&asn_buf);

	if((flag & BIT3_TRUE)>0)		//ControlChannelData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CCDATA,4),4,ptr->ccdata,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)		//DeniedAuthorizationPeriod
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DENAUTHPER,5),ptr->denauthperLen & MAX_IS41_VARPAR_LEN_1,ptr->denauthper,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//Digits carrier
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,6),ptr->digitsCarrierLen & MAX_IS41_VARPAR_LEN_1,ptr->digitsCarrier,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)		//Digits Destination
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,7),ptr->digitsDestLen & MAX_IS41_VARPAR_LEN_1,ptr->digitsDest,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)		//MSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCID,8),3,ptr->mscid,0x80,&asn_buf);

/* Profile **macro** */
	if ((flag & BIT8_TRUE) > 0)
	{
		if (!encode_param_profile(&ptr->profile,ptr->profile.param_flag,&asn_buf,&buf_len))
			return 0;
	}
/* Profile **macro** */

	if((flag & BIT9_TRUE)>0)		//ReceivedSignalQuality
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSIGQUAL,9),1,&ptr->rsigqual,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)		//senderin
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,10),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)		//smsmwi
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSMWI,11),0,ptr->senderin,0x80,&asn_buf);

	if((flag & BIT12_TRUE)>0)		//sysaccdata
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSACCDATA,12),5,ptr->sysaccdata,0x80,&asn_buf);
	
	return buf_len;
}

int extract_is41RegistrationNotification_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_REGNOT_ARG *ptr;
	int		len;
	char	tag[64];

	ptr = &opr_ptr->msg_list.regnot_arg;

		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,24,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MSCID absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_QUALCODE,1,&ptr->qualcode,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:QUALCODE absent!");
		return 0;
	}
	
	if (decode_Is41Parameter(IS41PAR_MYTYP,1,&ptr->mytyp,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MYTYP absent!");
		return 0;
	}



//optional par--->
	if (decode_Is41Parameter(IS41PAR_AVTYP,1,&ptr->avtyp,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	if (decode_Is41Parameter(IS41PAR_BORDACC,1,&ptr->bordacc,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	if (decode_Is41Parameter(IS41PAR_CCDATA,4,ptr->ccdata,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	if (decode_Is41Parameter(IS41PAR_EXTMSCID,4,ptr->extmscid,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;
	if (decode_Is41Parameter(IS41PAR_LOCID,2,ptr->locid,&asn_buf))
		ptr->param_flag |= BIT9_TRUE;
	if (decode_Is41Parameter(IS41PAR_PCSSN,5,ptr->pcssn,&asn_buf))
		ptr->param_flag |= BIT10_TRUE;
	if (decode_Is41Parameter(IS41PAR_RSIGQUAL,1,&ptr->rsigqual,&asn_buf))
		ptr->param_flag |= BIT11_TRUE;
	if (decode_Is41Parameter(IS41PAR_RPTTYP,1,&ptr->rpttyp,&asn_buf))
		ptr->param_flag |= BIT12_TRUE;
	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT13_TRUE;
	}
	len = decode_Is41Parameter(IS41PAR_SMSADDR,MAX_IS41_VARPAR_LEN,ptr->smsaddr,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT14_TRUE;
		ptr->smsaddrLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	//smsmwi

	if (decode_Is41Parameter(IS41PAR_SYSACCDATA,5,ptr->sysaccdata,&asn_buf))
		ptr->param_flag |= BIT16_TRUE;
	if (decode_Is41Parameter(IS41PAR_SYSACCTYPE,1,&ptr->sysacctype,&asn_buf))
		ptr->param_flag |= BIT17_TRUE;
	if (decode_Is41Parameter(IS41PAR_SYSCAP,1,&ptr->syscap,&asn_buf))
		ptr->param_flag |= BIT18_TRUE;
	if (decode_Is41Parameter(IS41PAR_TERMTYP,1,&ptr->termtyp,&asn_buf))
		ptr->param_flag |= BIT19_TRUE;
	len = decode_Is41Parameter(IS41PAR_TRANSCAP,MAX_IS41_VARPAR_LEN,ptr->transcap,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT20_TRUE;
		ptr->transcapLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	sprintf(tag, "%s.%s", IS41PAR_WINCAP, IS41PAR_TRIGCAP);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->wincap.triggercap,&asn_buf);
	if (len > 0)
	{
		ptr->wincap.param_flag |= BIT0_TRUE;
		ptr->wincap.triggercapLen = len & MAX_IS41_VARPAR_LEN_1;
		ptr->param_flag |= BIT21_TRUE;
	}
	sprintf(tag, "%s.%s", IS41PAR_WINCAP, IS41PAR_WINOPRCAP);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->wincap.winoprcap,&asn_buf);
	if (len > 0)
	{
		ptr->wincap.param_flag |= BIT1_TRUE;
		ptr->wincap.winoprcapLen = len & MAX_IS41_VARPAR_LEN_1;
		ptr->param_flag |= BIT21_TRUE;
	}
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);
	
	return 1;
}

int extract_is41RegistrationNotification_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_REGNOT_RSP *ptr;
	int		len;

	ptr = &opr_ptr->msg_list.regnot_rsp;
		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}

	if(AsnDecode(buf,buf_len,43,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_MYTYP,1,&ptr->mytyp,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MYTYP absent!");
		return 0;
	}

//optional par--->
	if (decode_Is41Parameter(IS41PAR_AUTHDEN,1,&ptr->authden,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	if (decode_Is41Parameter(IS41PAR_AUTHPER,2,ptr->authper,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	if (decode_Is41Parameter(IS41PAR_CCDATA,4,ptr->ccdata,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	len = decode_Is41Parameter(IS41PAR_DENAUTHPER,MAX_IS41_VARPAR_LEN,ptr->denauthper,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->denauthperLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digitsCarrier,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->digitsCarrierLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digitsDest,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->digitsDestLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
		
/* Profile **macro** */
	if (decode_param_profile(&ptr->profile,&asn_buf) > 0)
		ptr->param_flag |= BIT8_TRUE;
/* Profile **macro** */
		
		
	if (decode_Is41Parameter(IS41PAR_RSIGQUAL,1,&ptr->rsigqual,&asn_buf))
		ptr->param_flag |= BIT9_TRUE;
	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT10_TRUE;
	}

	//smsmwi

	if (decode_Is41Parameter(IS41PAR_SYSACCDATA,5,ptr->sysaccdata,&asn_buf))
		ptr->param_flag |= BIT12_TRUE;

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}

int assign_is41RegistrationCancellation_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	struct		IS41_REGCANC_ARG 	*ptr;
	
	ptr = &opr_ptr->msg_list.regcanc_arg;
	
	flag = ptr->param_flag;
	
	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,1),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}
	if((flag & BIT1_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,2),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT2_TRUE)>0)		//Cancellation Type
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CANTP,3),ptr->canctyplen & 3,ptr->canctyp,0x80,&asn_buf);

	if((flag & BIT3_TRUE)>0)		//ControlChannelData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CCDATA,4),4,ptr->ccdata,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)		//ReceivedSignalQuality
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSIGQUAL,5),1,&ptr->rsigqual,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//senderin
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,6),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)		//sysaccdata
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSACCDATA,7),5,ptr->sysaccdata,0x80,&asn_buf);

	return buf_len;
}

int assign_is41RegistrationCancellation_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	u32			flag;
	ASN_BUF		asn_buf;
	int			buf_len=0;
	struct 		IS41_REGCANC_RSP 		*ptr;

	ptr = &opr_ptr->msg_list.regcanc_rsp;

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

// optional part--->
	if((flag & BIT0_TRUE)>0)		//CallHistoryCount
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_COUNT,3),1,&ptr->count,0x80,&asn_buf);

	if((flag & BIT1_TRUE)>0)		//CancellationDenied
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CANCD,3),1,&ptr->cancdenied,0x80,&asn_buf);

	if((flag & BIT2_TRUE)>0)		//ControlChannelData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CCDATA,4),4,ptr->ccdata,0x80,&asn_buf);
	
	if((flag & BIT3_TRUE)>0)		//ReceivedSignalQuality
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSIGQUAL,5),1,&ptr->rsigqual,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)		//smsmwi
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSMWI,16),0,&ptr->smsmwi,0x80,&asn_buf);
	
	if((flag & BIT5_TRUE)>0)		//sysaccdata
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSACCDATA,7),5,ptr->sysaccdata,0x80,&asn_buf);
	
	return buf_len;
}

int extract_is41RegistrationCancellation_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_REGCANC_ARG *ptr;
	int		len;

	ptr = &opr_ptr->msg_list.regcanc_arg;
		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,24,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

//optional par--->
	if (decode_Is41Parameter(IS41PAR_CANTP,4,ptr->canctyp,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	if (decode_Is41Parameter(IS41PAR_CCDATA,4,ptr->ccdata,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	if (decode_Is41Parameter(IS41PAR_RSIGQUAL,1,&ptr->rsigqual,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT5_TRUE;
	}
	if (decode_Is41Parameter(IS41PAR_SYSACCDATA,5,ptr->sysaccdata,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);
	
	return 1;
}

int extract_is41RegistrationCancellation_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_REGCANC_RSP *ptr;

	ptr = &opr_ptr->msg_list.regcanc_rsp;

	if(AsnDecode(buf,buf_len,43,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

//optional par--->
	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	if (decode_Is41Parameter(IS41PAR_CANCD,2,&ptr->cancdenied,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	if (decode_Is41Parameter(IS41PAR_CCDATA,4,ptr->ccdata,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
		
	if (decode_Is41Parameter(IS41PAR_RSIGQUAL,1,&ptr->rsigqual,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;

	if (decode_Is41Parameter(IS41PAR_SMSMWI,0,ptr->sysaccdata,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;

	if (decode_Is41Parameter(IS41PAR_SYSACCDATA,5,ptr->sysaccdata,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}

int assign_is41LocationRequest_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag,flag1;
	struct		IS41_LOCREQ_ARG *ptr;
	struct		IS41_PAR_WIN_CAP	*ptr1;
	char		tag[64];
	
	ptr = &opr_ptr->msg_list.locreq_arg;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLID,1),7,ptr->billid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:BILLID absent!!");
		return 0;
	}
	if((flag & BIT1_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,2),ptr->digitsLen & MAX_IS41_VARPAR_LEN_1,ptr->digits,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:Digits absent!!");
		return 0;
	}

	if((flag & BIT2_TRUE)>0)		//MSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCID,3),3,ptr->mscid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MSCID absent!!");
		return 0;
	}

	if((flag & BIT3_TRUE)>0)		//SystemMyTypeCode
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MYTYP,4),1,&ptr->mytyp,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MYTYP absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT4_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNDGTS1,5),ptr->cpndgts1Len & MAX_IS41_VARPAR_LEN_1,ptr->cpndgts1,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNDGTS2,6),ptr->cpndgts2Len & MAX_IS41_VARPAR_LEN_1,ptr->cpndgts2,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPSUB,7),ptr->cpsubLen & MAX_IS41_VARPAR_LEN_1,ptr->cpsub,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCIN,8),ptr->mscinLen & MAX_IS41_VARPAR_LEN_1,ptr->mscin,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PCSSN,9),5,ptr->pcssn,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RNDGTS,10),ptr->rndgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->rndgts,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSUB,11),ptr->rsubLen & MAX_IS41_VARPAR_LEN_1,ptr->rsub,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TAT,12),1,&ptr->tat,0x80,&asn_buf);

	if((flag & BIT12_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TRANSCAP,13),ptr->transcapLen & MAX_IS41_VARPAR_LEN_1,ptr->transcap,0x80,&asn_buf);
	
	if((flag & BIT13_TRUE)>0)		//wincap
	{
		ptr1 = &ptr->wincap;
		flag1 = ptr1->param_flag;
		if (!(flag1 & 0x03))
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:wincap no content!!");
			return 0;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_WINCAP,14),0,NULL,0xA0,&asn_buf);
		if((flag1 & BIT0_TRUE)>0)		//triggercapability
		{
			sprintf(tag,"%s.%s",IS41PAR_WINCAP,IS41PAR_TRIGCAP);
			buf_len = AddTLV(is41_sequenceTag(tag,1),ptr1->triggercapLen & MAX_IS41_VARPAR_LEN_1,ptr1->triggercap,0x80,&asn_buf);
		}
		if((flag1 & BIT1_TRUE)>0)		//winoperationscapability
		{
			sprintf(tag,"%s.%s",IS41PAR_WINCAP,IS41PAR_WINOPRCAP);
			buf_len = AddTLV(is41_sequenceTag(tag,2),ptr1->winoprcapLen & MAX_IS41_VARPAR_LEN_1,ptr1->winoprcap,0x80,&asn_buf);
		}
	}
	
	return buf_len;
}

int extract_is41LocationRequest_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct 	IS41_LOCREQ_ARG *ptr;
	int		len;
	char 	tag[64];
	
	ptr = &opr_ptr->msg_list.locreq_arg;

	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,17,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_BILLID,7,ptr->billid,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:BILLID absent!");
		return 0;
	}

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digits,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT1_TRUE;
		ptr->digitsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:Digits absent!!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MSCID absent!");
		return 0;
	}
	
	if (decode_Is41Parameter(IS41PAR_MYTYP,1,&ptr->mytyp,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MYTYP absent!");
		return 0;
	}

//optional par--->
	len = decode_Is41Parameter(IS41PAR_CPNDGTS1,MAX_IS41_VARPAR_LEN,ptr->cpndgts1,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->cpndgts1Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPNDGTS2,MAX_IS41_VARPAR_LEN,ptr->cpndgts2,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->cpndgts2Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPSUB,MAX_IS41_VARPAR_LEN,ptr->cpsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->cpsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_MSCIN,MAX_IS41_VARPAR_LEN,ptr->mscin,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->mscinLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_Is41Parameter(IS41PAR_PCSSN,5,ptr->pcssn,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;

	len = decode_Is41Parameter(IS41PAR_RNDGTS,MAX_IS41_VARPAR_LEN,ptr->rndgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->rndgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RSUB,MAX_IS41_VARPAR_LEN,ptr->rsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->rsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	if (decode_Is41Parameter(IS41PAR_TAT,1,&ptr->tat,&asn_buf))
		ptr->param_flag |= BIT11_TRUE;
	
	len = decode_Is41Parameter(IS41PAR_TRANSCAP,MAX_IS41_VARPAR_LEN,ptr->transcap,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT12_TRUE;
		ptr->transcapLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	sprintf(tag, "%s.%s", IS41PAR_WINCAP, IS41PAR_TRIGCAP);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->wincap.triggercap,&asn_buf);
	if (len > 0)
	{
		ptr->wincap.param_flag |= BIT0_TRUE;
		ptr->wincap.triggercapLen = len & MAX_IS41_VARPAR_LEN_1;
		ptr->param_flag |= BIT13_TRUE;
	}
	sprintf(tag, "%s.%s", IS41PAR_WINCAP, IS41PAR_WINOPRCAP);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->wincap.winoprcap,&asn_buf);
	if (len > 0)
	{
		ptr->wincap.param_flag |= BIT1_TRUE;
		ptr->wincap.winoprcapLen = len & MAX_IS41_VARPAR_LEN_1;
		ptr->param_flag |= BIT14_TRUE;
	}
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}


int assign_is41LocationRequest_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag,flag1;
	struct		IS41_LOCREQ_RSP *ptr;
	struct		IS41_PAR_TRIGGER_LIST	*ptr1;
	u8			i,triglistnum;
	char		tag[64];
	
	ptr = &opr_ptr->msg_list.locreq_rsp;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,1),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}
	if((flag & BIT1_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,2),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

	if((flag & BIT2_TRUE)>0)		//MSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCID,3),3,ptr->mscid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MSCID absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT3_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACCDEN,4),1,&ptr->accden,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ANNLIST,5),ptr->annlistLen & MAX_IS41_VARPAR_LEN_1,ptr->annlist,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNSTRG1,6),ptr->cpnstrg1Len & MAX_IS41_VARPAR_LEN_1,ptr->cpnstrg1,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNSTRG2,7),ptr->cpnstrg2Len & MAX_IS41_VARPAR_LEN_1,ptr->cpnstrg2,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,8),ptr->digitsCarrierLen & MAX_IS41_VARPAR_LEN_1,ptr->digitsCarrier,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,9),ptr->digitsDestLen & MAX_IS41_VARPAR_LEN_1,ptr->digitsDest,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACDGTS,10),ptr->acdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->acdgts,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ABDGTS,11),ptr->abdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->abdgts,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLDGTS,12),ptr->billdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->billdgts,0x80,&asn_buf);

	if((flag & BIT12_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_REDIND,13),ptr->redindLen & MAX_IS41_VARPAR_LEN_1,ptr->redind,0x80,&asn_buf);

	if((flag & BIT13_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_GRPINFO,14),ptr->grpinfoLen & MAX_IS41_VARPAR_LEN_1,ptr->grpinfo,0x80,&asn_buf);

//	if((flag & BIT11_TRUE)>0)
	//	buf_len = AddTLV(is41_sequenceTag(IS41PAR_TAT,12),1,&ptr->tat,0x80,&asn_buf);

	if((flag & BIT14_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MDN,15),ptr->mdnLen & MAX_IS41_VARPAR_LEN_1,ptr->mdn,0x80,&asn_buf);

	if((flag & BIT15_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_NATIME,16),ptr->natimeLen & MAX_IS41_VARPAR_LEN_1,ptr->natime,0x80,&asn_buf);
		
	if((flag & BIT16_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_OTFI,17),ptr->otfiLen & MAX_IS41_VARPAR_LEN_1,ptr->otfi,0x80,&asn_buf);

	if((flag & BIT17_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PCSSN,18),5,ptr->pcssn,0x80,&asn_buf);
		
	if((flag & BIT18_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RNDGTS,19),ptr->rndgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->rndgts,0x80,&asn_buf);

	if((flag & BIT19_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RNSTRING,20),ptr->rnstringLen & MAX_IS41_VARPAR_LEN_1,ptr->rnstring,0x80,&asn_buf);

	if((flag & BIT20_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSUB,21),ptr->rsubLen & MAX_IS41_VARPAR_LEN_1,ptr->rsub,0x80,&asn_buf);
		
	if((flag & BIT21_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ROUTDGTS,22),ptr->routdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->routdgts,0x80,&asn_buf);

	if ((flag & BIT22_TRUE) > 0)
	{
		if (!encode_param_termlist(&ptr->termlist,ptr->termlist.param_flag,&asn_buf,&buf_len))
			return 0;
	}

	if((flag & BIT23_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTRIG,24),ptr->termtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrig,0x80,&asn_buf);

	if((flag & BIT24_TRUE)>0)		//TriggerAddressList
	{
		triglistnum = ptr->triggerlistnum & MAX_IS41_TRIG_LIST_NUM_1;
		if (!triglistnum)
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:TriggerAddressList no content!!");
			return 0;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TRIGADRLIST,25),0,NULL,0xA0,&asn_buf);
		for (i = 0; i < triglistnum; i++)
		{
			ptr1 = &ptr->triggerlist[i];
			flag1 = ptr1->param_flag;
			if ((flag1 & 0x03) != 0x03)
			{
				is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:triggerlist lacks mandatory info!!");
				return 0;
			}
			sprintf(tag,"%s.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST);
			buf_len = AddTLV(is41_sequenceTag(tag,i+1),0,NULL,0xA0,&asn_buf);
			if((flag1 & BIT0_TRUE)>0)		//destinationaddress -- choice global title
			{
				sprintf(tag,"%s.%s-%d.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST,i+1,IS41PAR_GLOBALTITLE);
				buf_len = AddTLV(is41_sequenceTag(tag,1),ptr1->destaddrLen & MAX_IS41_VARPAR_LEN_1,ptr1->destaddr,0x80,&asn_buf);
			}
			if((flag1 & BIT1_TRUE)>0)		//winoperationscapability
			{
				sprintf(tag,"%s.%s-%d.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST,i+1,IS41PAR_WINTRIGLIST);
				buf_len = AddTLV(is41_sequenceTag(tag,2),ptr1->wintriglistLen & MAX_IS41_VARPAR_LEN_1,ptr1->wintriglist,0x80,&asn_buf);
			}
		}
	}
	
	return buf_len;
}

int extract_is41LocationRequest_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_LOCREQ_RSP  *ptr;
	IS41_PAR_TRIGGER_LIST	*ptr1;
	int		len,i,count;
	char 	tag[64];
	
	ptr = &opr_ptr->msg_list.locreq_rsp;

		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,33,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MSCID absent!");
		return 0;
	}

//optional par--->
	if (decode_Is41Parameter(IS41PAR_ACCDEN,1,&ptr->accden,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;

	len = decode_Is41Parameter(IS41PAR_ANNLIST,MAX_IS41_VARPAR_LEN,ptr->annlist,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->annlistLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPNSTRG1,MAX_IS41_VARPAR_LEN,ptr->cpnstrg1,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->cpnstrg1Len = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_CPNSTRG2,MAX_IS41_VARPAR_LEN,ptr->cpnstrg2,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->cpnstrg2Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digitsCarrier,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->digitsCarrierLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digitsDest,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->digitsDestLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_ACDGTS,MAX_IS41_VARPAR_LEN,ptr->acdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->acdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_ABDGTS,MAX_IS41_VARPAR_LEN,ptr->abdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->abdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_BILLDGTS,MAX_IS41_VARPAR_LEN,ptr->billdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->billdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_REDIND,MAX_IS41_VARPAR_LEN,ptr->redind,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT12_TRUE;
		ptr->redindLen = len & MAX_IS41_VARPAR_LEN_1;
	}	

	len = decode_Is41Parameter(IS41PAR_GRPINFO,MAX_IS41_VARPAR_LEN,ptr->grpinfo,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT13_TRUE;
		ptr->grpinfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}	
	
	len = decode_Is41Parameter(IS41PAR_MDN,MAX_IS41_VARPAR_LEN,ptr->mdn,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT14_TRUE;
		ptr->mdnLen = len & MAX_IS41_VARPAR_LEN_1;
	}	

	len = decode_Is41Parameter(IS41PAR_NATIME,MAX_IS41_VARPAR_LEN,ptr->natime,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT15_TRUE;
		ptr->natimeLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_OTFI,MAX_IS41_VARPAR_LEN,ptr->otfi,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT16_TRUE;
		ptr->otfiLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_Is41Parameter(IS41PAR_PCSSN,5,ptr->pcssn,&asn_buf))
		ptr->param_flag |= BIT17_TRUE;

	len = decode_Is41Parameter(IS41PAR_RNDGTS,MAX_IS41_VARPAR_LEN,ptr->rndgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT18_TRUE;
		ptr->rndgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RNSTRING,MAX_IS41_VARPAR_LEN,ptr->rnstring,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT19_TRUE;
		ptr->rnstringLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RSUB,MAX_IS41_VARPAR_LEN,ptr->rsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT20_TRUE;
		ptr->rsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_ROUTDGTS,MAX_IS41_VARPAR_LEN,ptr->routdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT21_TRUE;
		ptr->routdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_param_termlist(&ptr->termlist,&asn_buf) > 0)
		ptr->param_flag |= BIT22_TRUE;

	len = decode_Is41Parameter(IS41PAR_TERMTRIG,MAX_IS41_VARPAR_LEN,ptr->termtrig,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT23_TRUE;
		ptr->termtrigLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	ptr->triggerlistnum = 0;
	for (i = 0; i < MAX_IS41_TRIG_LIST_NUM; i++)
	{
		ptr1 = &ptr->triggerlist[i];
		count = 0;
		sprintf(tag, "%s.%s-%d.%s", IS41PAR_TRIGADRLIST, IS41PAR_TRIGLIST, i+1, IS41PAR_GLOBALTITLE);
		len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr1->destaddr,&asn_buf);
		if (len > 0)
		{
			ptr1->param_flag |= BIT0_TRUE;
			ptr1->destaddrLen = len & MAX_IS41_VARPAR_LEN_1;
			count++;
		}
		sprintf(tag, "%s.%s-%d.%s", IS41PAR_TRIGADRLIST, IS41PAR_TRIGLIST, i+1, IS41PAR_WINTRIGLIST);
		len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr1->wintriglist,&asn_buf);
		if (len > 0)
		{
			ptr1->param_flag |= BIT1_TRUE;
			ptr1->wintriglistLen = len & MAX_IS41_VARPAR_LEN_1;
			count++;
		}
		if (count == 2)
		{
			ptr->triggerlistnum++;
			ptr->param_flag |= BIT24_TRUE;
		}
		else if (count == 1)
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:triggerlist lacks mandatory info!!");
			return 0;
		}
		else if (!count)
			break;
	}
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}

int assign_is41RoutingRequest_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	struct		IS41_ROUTREQ_ARG *ptr;

	ptr = &opr_ptr->msg_list.routreq_arg;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLID,1),7,ptr->billid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:BILLID absent!!");
		return 0;
	}
	
	if((flag & BIT1_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,2),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}
	if((flag & BIT2_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,3),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

	if((flag & BIT3_TRUE)>0)		//MSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCID,4),3,ptr->mscid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MSCID absent!!");
		return 0;
	}

	if((flag & BIT4_TRUE)>0)		//SystemMyTypeCode
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MYTYP,5),1,&ptr->mytyp,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MYTYP absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ALRTCODE,6),ptr->alrtcodeLen & MAX_IS41_VARPAR_LEN_1,ptr->alrtcode,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNSTRG1,7),ptr->cpnstrg1Len & MAX_IS41_VARPAR_LEN_1,ptr->cpnstrg1,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNSTRG2,8),ptr->cpnstrg2Len & MAX_IS41_VARPAR_LEN_1,ptr->cpnstrg2,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPSUB,9),ptr->cpsubLen & MAX_IS41_VARPAR_LEN_1,ptr->cpsub,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DESTDGTS,10),ptr->destdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->destdgts,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACDGTS,11),ptr->acdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->acdgts,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ABDGTS,12),ptr->abdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->abdgts,0x80,&asn_buf);

	if((flag & BIT12_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLDGTS,13),ptr->billdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->billdgts,0x80,&asn_buf);

	if((flag & BIT13_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_LEGINFO,14),ptr->leginfoLen & MAX_IS41_VARPAR_LEN_1,ptr->leginfo,0x80,&asn_buf);

	if((flag & BIT14_TRUE)>0)		//LocationAreaID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_LOCID,15),2,ptr->locid,0x80,&asn_buf);

	if((flag & BIT15_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MDN,16),ptr->mdnLen & MAX_IS41_VARPAR_LEN_1,ptr->mdn,0x80,&asn_buf);

	if((flag & BIT16_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCIN,17),ptr->mscinLen & MAX_IS41_VARPAR_LEN_1,ptr->mscin,0x80,&asn_buf);

	if((flag & BIT17_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_NATIME,18),ptr->natimeLen & MAX_IS41_VARPAR_LEN_1,ptr->natime,0x80,&asn_buf);

	if((flag & BIT18_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_OTFI,19),ptr->otfiLen & MAX_IS41_VARPAR_LEN_1,ptr->otfi,0x80,&asn_buf);

	if((flag & BIT19_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PCSSN,20),5,ptr->pcssn,0x80,&asn_buf);

	if((flag & BIT20_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PILOTBID,21),7,ptr->pilotbid,0x80,&asn_buf);

	if((flag & BIT21_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PILOT,22),ptr->pilotLen & MAX_IS41_VARPAR_LEN_1,ptr->pilot,0x80,&asn_buf);

	if((flag & BIT22_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RNSTRING,23),ptr->rnstringLen & MAX_IS41_VARPAR_LEN_1,ptr->rnstring,0x80,&asn_buf);

	if((flag & BIT23_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSUB,24),ptr->rsubLen & MAX_IS41_VARPAR_LEN_1,ptr->rsub,0x80,&asn_buf);

	if((flag & BIT24_TRUE)>0)		//senderin
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,25),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	if((flag & BIT25_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTRMT,26),ptr->termtrmtLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrmt,0x80,&asn_buf);

	if((flag & BIT26_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTRIG,27),ptr->termtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrig,0x80,&asn_buf);

	if((flag & BIT27_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_VMBOX,28),ptr->vmboxLen & MAX_IS41_VARPAR_LEN_1,ptr->vmbox,0x80,&asn_buf);

	if((flag & BIT28_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_VMSPIN,29),ptr->vmspinLen & MAX_IS41_VARPAR_LEN_1,ptr->vmspin,0x80,&asn_buf);

	return buf_len;
}

int extract_is41RoutingRequest_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_ROUTREQ_ARG *ptr;
	int		len;

	ptr = &opr_ptr->msg_list.routreq_arg;

		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,29,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_BILLID,7,ptr->billid,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:BILLID absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MSCID absent!");
		return 0;
	}
	
	if (decode_Is41Parameter(IS41PAR_MYTYP,1,&ptr->mytyp,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MYTYP absent!");
		return 0;
	}

//optional par--->
	len = decode_Is41Parameter(IS41PAR_ALRTCODE,MAX_IS41_VARPAR_LEN,ptr->alrtcode,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->alrtcodeLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_CPNSTRG1,MAX_IS41_VARPAR_LEN,ptr->cpnstrg1,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->cpnstrg1Len = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_CPNSTRG2,MAX_IS41_VARPAR_LEN,ptr->cpnstrg2,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->cpnstrg2Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPSUB,MAX_IS41_VARPAR_LEN,ptr->cpsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->cpsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_DESTDGTS,MAX_IS41_VARPAR_LEN,ptr->destdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->destdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_ACDGTS,MAX_IS41_VARPAR_LEN,ptr->acdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->acdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_ABDGTS,MAX_IS41_VARPAR_LEN,ptr->abdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->abdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_BILLDGTS,MAX_IS41_VARPAR_LEN,ptr->billdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT12_TRUE;
		ptr->billdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_LEGINFO,MAX_IS41_VARPAR_LEN,ptr->leginfo,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT13_TRUE;
		ptr->leginfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_Is41Parameter(IS41PAR_LOCID,2,ptr->locid,&asn_buf))
		ptr->param_flag |= BIT14_TRUE;

	len = decode_Is41Parameter(IS41PAR_MDN,MAX_IS41_VARPAR_LEN,ptr->mdn,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT15_TRUE;
		ptr->mdnLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_MSCIN,MAX_IS41_VARPAR_LEN,ptr->mscin,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT16_TRUE;
		ptr->mscinLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_NATIME,MAX_IS41_VARPAR_LEN,ptr->natime,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT17_TRUE;
		ptr->natimeLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_OTFI,MAX_IS41_VARPAR_LEN,ptr->otfi,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT18_TRUE;
		ptr->otfiLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_Is41Parameter(IS41PAR_PCSSN,5,ptr->pcssn,&asn_buf))
		ptr->param_flag |= BIT19_TRUE;

	if (decode_Is41Parameter(IS41PAR_PILOTBID,7,ptr->pilotbid,&asn_buf))
		ptr->param_flag |= BIT20_TRUE;

	len = decode_Is41Parameter(IS41PAR_PILOT,MAX_IS41_VARPAR_LEN,ptr->pilot,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT21_TRUE;
		ptr->pilotLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RNSTRING,MAX_IS41_VARPAR_LEN,ptr->rnstring,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT22_TRUE;
		ptr->rnstringLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RSUB,MAX_IS41_VARPAR_LEN,ptr->rsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT23_TRUE;
		ptr->rsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT24_TRUE;
	}
	
	len = decode_Is41Parameter(IS41PAR_TERMTRMT,MAX_IS41_VARPAR_LEN,ptr->termtrmt,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT25_TRUE;
		ptr->termtrmtLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_TERMTRIG,MAX_IS41_VARPAR_LEN,ptr->termtrig,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT26_TRUE;
		ptr->termtrigLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_VMBOX,MAX_IS41_VARPAR_LEN,ptr->vmbox,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT27_TRUE;
		ptr->vmboxLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_VMSPIN,MAX_IS41_VARPAR_LEN,ptr->vmspin,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT28_TRUE;
		ptr->vmspinLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}

int assign_is41RoutingRequest_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	struct		IS41_ROUTREQ_RSP *ptr;

	ptr = &opr_ptr->msg_list.routreq_rsp;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);

	if((flag & BIT0_TRUE)>0)		//MSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCID,1),3,ptr->mscid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MSCID absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT1_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACCDEN,2),1,&ptr->accden,0x80,&asn_buf);

	if((flag & BIT2_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLID,3),7,ptr->billid,0x80,&asn_buf);

	if((flag & BIT3_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CDEN,4),1,&ptr->cden,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,5),ptr->digitsLen & MAX_IS41_VARPAR_LEN_1,ptr->digits,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCIN,6),ptr->mscinLen & MAX_IS41_VARPAR_LEN_1,ptr->mscin,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PCSSN,7),5,ptr->pcssn,0x80,&asn_buf);

	return buf_len;
}

int extract_is41RoutingRequest_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_ROUTREQ_RSP *ptr;
	int		len;

	ptr = &opr_ptr->msg_list.routreq_rsp;
		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}

	if(AsnDecode(buf,buf_len,7,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MSCID absent!");
		return 0;
	}

//optional par--->
	if (decode_Is41Parameter(IS41PAR_ACCDEN,1,&ptr->accden,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;

	if (decode_Is41Parameter(IS41PAR_BILLID,7,ptr->billid,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;

	if (decode_Is41Parameter(IS41PAR_CDEN,1,&ptr->cden,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digits,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->digitsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_MSCIN,MAX_IS41_VARPAR_LEN,ptr->mscin,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->mscinLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_Is41Parameter(IS41PAR_PCSSN,5,ptr->pcssn,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}


int assign_is41MSInactive_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	struct		IS41_MSINACT_ARG *ptr;

	ptr = &opr_ptr->msg_list.msinact_arg;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);

	if((flag & BIT0_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,1),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}
	if((flag & BIT1_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,2),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT2_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_COUNT,3),1,&ptr->count,0x80,&asn_buf);

	if((flag & BIT3_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DEREG,4),1,&ptr->dereg,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)		//LocationAreaID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_LOCID,5),2,ptr->locid,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//senderin
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,6),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	return buf_len;
}

int extract_is41MSInactive_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_MSINACT_ARG *ptr;
	u8		len;

	ptr = &opr_ptr->msg_list.msinact_arg;
		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}

	if(AsnDecode(buf,buf_len,6,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

//optional par--->
	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;

	if (decode_Is41Parameter(IS41PAR_DEREG,1,&ptr->dereg,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;

	if (decode_Is41Parameter(IS41PAR_LOCID,2,ptr->locid,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;

	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT5_TRUE;
	}

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}

int assign_is41MSInactive_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;

	struct IS41_MSINACT_RSP *ptr;

	ptr = &opr_ptr->msg_list.msinact_rsp;

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

	return buf_len;
}

int extract_is41MSInactive_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	struct IS41_MSINACT_RSP *ptr;

	ptr = &opr_ptr->msg_list.msinact_rsp;
	ptr->param_flag = 0;

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}

int	assign_is41QualificationDirective_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	struct		IS41_QUALDIR_ARG *ptr;

	ptr = &opr_ptr->msg_list.qualdir_arg;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);

	if((flag & BIT0_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,1),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}

	if((flag & BIT1_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,2),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

	if((flag & BIT2_TRUE)>0)		//QualificationInformationCode
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_QUALCODE,3),1,&ptr->qualcode,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:QUALCODE absent!!");
		return 0;
	}

	if((flag & BIT3_TRUE)>0)		//SystemMyTypeCode
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MYTYP,4),1,&ptr->mytyp,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MYTYP absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT4_TRUE)>0)		//AuthorizationDenied
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHDEN,5),1,&ptr->authden,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//AuthorizationPeriod
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHPER,6),2,ptr->authper,0x80,&asn_buf);
	if((flag & BIT6_TRUE)>0)		//DeniedAuthorizationPeriod
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DENAUTHPER,7),ptr->denauthperLen & MAX_IS41_VARPAR_LEN_1,ptr->denauthper,0x80,&asn_buf);
	if((flag & BIT7_TRUE)>0)		//Digits carrier
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,8),ptr->digitsCarrierLen & MAX_IS41_VARPAR_LEN_1,ptr->digitsCarrier,0x80,&asn_buf);
	if((flag & BIT8_TRUE)>0)		//Digits Destination
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,9),ptr->digitsDestLen & MAX_IS41_VARPAR_LEN_1,ptr->digitsDest,0x80,&asn_buf);
	if((flag & BIT9_TRUE)>0)		//LocationAreaID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_LOCID,10),2,ptr->locid,0x80,&asn_buf);

/* Profile **macro** */
	if ((flag & BIT10_TRUE) > 0)
	{
		if (!encode_param_profile(&ptr->profile,ptr->profile.param_flag,&asn_buf,&buf_len))
			return 0;
	}
/* Profile **macro** */

	if((flag & BIT11_TRUE)>0)		//senderin
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,11),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	return buf_len;
}

int extract_is41QualificationDirective_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_QUALDIR_ARG *ptr;
	int		len;

	ptr = &opr_ptr->msg_list.qualdir_arg;
		
	if (buf_len == 0) 
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,24,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_QUALCODE,1,&ptr->qualcode,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:QUALCODE absent!");
		return 0;
	}
	
	if (decode_Is41Parameter(IS41PAR_MYTYP,1,&ptr->mytyp,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MYTYP absent!");
		return 0;
	}



//optional par--->
	if (decode_Is41Parameter(IS41PAR_AUTHDEN,1,&ptr->authden,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	if (decode_Is41Parameter(IS41PAR_AUTHPER,2,ptr->authper,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	len = decode_Is41Parameter(IS41PAR_DENAUTHPER,MAX_IS41_VARPAR_LEN,ptr->denauthper,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->denauthperLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digitsCarrier,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->digitsCarrierLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digitsDest,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->digitsDestLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	if (decode_Is41Parameter(IS41PAR_LOCID,2,ptr->locid,&asn_buf))
		ptr->param_flag |= BIT9_TRUE;

/* Profile **macro** */
	if (decode_param_profile(&ptr->profile,&asn_buf) > 0)
		ptr->param_flag |= BIT10_TRUE;
/* Profile **macro** */

	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT11_TRUE;
	}
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);
	
	return 1;
}

int assign_is41QualificationDirective_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;

	struct IS41_QUALDIR_RSP *ptr;

	ptr = &opr_ptr->msg_list.qualdir_rsp;

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

	return buf_len;
}

int extract_is41QualificationDirective_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	struct IS41_QUALDIR_RSP *ptr;

	ptr = &opr_ptr->msg_list.qualdir_rsp;
	ptr->param_flag = 0;

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}

int	assign_is41FeatureRequest_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	struct		IS41_FEATREQ_ARG *ptr;

	ptr = &opr_ptr->msg_list.featreq_arg;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);

	if((flag & BIT0_TRUE)>0)		//Dialed Digits
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,1),ptr->digitsLen & MAX_IS41_VARPAR_LEN_1,ptr->digits,0x80,&asn_buf);

	if((flag & BIT1_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,2),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}

	if((flag & BIT2_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,3),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

//optional
	if((flag & BIT3_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLID,4),7,ptr->billid,0x80,&asn_buf);
	if((flag & BIT4_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNDGTS1,5),ptr->cpndgts1Len & MAX_IS41_VARPAR_LEN_1,ptr->cpndgts1,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNDGTS2,6),ptr->cpndgts2Len & MAX_IS41_VARPAR_LEN_1,ptr->cpndgts2,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPSUB,7),ptr->cpsubLen & MAX_IS41_VARPAR_LEN_1,ptr->cpsub,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CCI,8),ptr->cciLen & MAX_IS41_VARPAR_LEN_1,ptr->cci,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MDN,9),ptr->mdnLen & MAX_IS41_VARPAR_LEN_1,ptr->mdn,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)		//MSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCID,10),3,ptr->mscid,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCIN,11),ptr->mscinLen & MAX_IS41_VARPAR_LEN_1,ptr->mscin,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_OTFI,12),ptr->otfiLen & MAX_IS41_VARPAR_LEN_1,ptr->otfi,0x80,&asn_buf);

	if((flag & BIT12_TRUE)>0)		//pcssn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PCSSN,13),5,ptr->pcssn,0x80,&asn_buf);

	if((flag & BIT13_TRUE)>0)		//senderin
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,14),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	if((flag & BIT14_TRUE)>0)		//transcap
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TRANSCAP,15),ptr->transcapLen & MAX_IS41_VARPAR_LEN_1,ptr->transcap,0x80,&asn_buf);

	return buf_len;
}

int extract_is41FeatureRequest_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_FEATREQ_ARG *ptr;
	int		len;

	ptr = &opr_ptr->msg_list.featreq_arg;
		
	if (buf_len == 0) 
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,24,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digits,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT0_TRUE;
		ptr->digitsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:Digits absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

//optional
	if (decode_Is41Parameter(IS41PAR_BILLID,7,ptr->billid,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	len = decode_Is41Parameter(IS41PAR_CPNDGTS1,MAX_IS41_VARPAR_LEN,ptr->cpndgts1,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->cpndgts1Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPNDGTS2,MAX_IS41_VARPAR_LEN,ptr->cpndgts2,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->cpndgts2Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPSUB,MAX_IS41_VARPAR_LEN,ptr->cpsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->cpsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}	
	len = decode_Is41Parameter(IS41PAR_CCI,MAX_IS41_VARPAR_LEN,ptr->cci,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->cciLen = len & MAX_IS41_VARPAR_LEN_1;
	}	
	len = decode_Is41Parameter(IS41PAR_MDN,MAX_IS41_VARPAR_LEN,ptr->mdn,&asn_buf);
	if (len > 0)
	{
		ptr->mdnLen = len;
		ptr->param_flag |= BIT8_TRUE;
	}
	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT9_TRUE;
	len = decode_Is41Parameter(IS41PAR_MSCIN,MAX_IS41_VARPAR_LEN,ptr->mscin,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->mscinLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	len = decode_Is41Parameter(IS41PAR_OTFI,MAX_IS41_VARPAR_LEN,ptr->otfi,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->otfiLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	if (decode_Is41Parameter(IS41PAR_PCSSN,5,ptr->pcssn,&asn_buf))
		ptr->param_flag |= BIT12_TRUE;
	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT13_TRUE;
	}
	len = decode_Is41Parameter(IS41PAR_TRANSCAP,MAX_IS41_VARPAR_LEN,ptr->transcap,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT14_TRUE;
		ptr->transcapLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);
	
	return 1;
}

int assign_is41FeatureRequest_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag,flag1;
	u8			i,triglistnum;
	IS41_PAR_TRIGGER_LIST	*ptr1;
	char		tag[64];

	struct IS41_FEATREQ_RSP *ptr;

	ptr = &opr_ptr->msg_list.featreq_rsp;

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

	if((flag & BIT0_TRUE)>0)		//feature result
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_FEATRESULT,1),1,&ptr->featresult,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:Feature result absent!!");
		return 0;
	}

//optional
	if((flag & BIT1_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACCDEN,2),1,&ptr->accden,0x80,&asn_buf);
	if((flag & BIT2_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACTCODE,3),ptr->actcodeLen & MAX_IS41_VARPAR_LEN_1,ptr->actcode,0x80,&asn_buf);
	if((flag & BIT3_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ANNLIST,4),ptr->annlistLen & MAX_IS41_VARPAR_LEN_1,ptr->annlist,0x80,&asn_buf);
	if((flag & BIT4_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNDGTS1,5),ptr->cpndgts1Len & MAX_IS41_VARPAR_LEN_1,ptr->cpndgts1,0x80,&asn_buf);
	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNDGTS2,6),ptr->cpndgts2Len & MAX_IS41_VARPAR_LEN_1,ptr->cpndgts2,0x80,&asn_buf);
	if((flag & BIT6_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPSUB,7),ptr->cpsubLen & MAX_IS41_VARPAR_LEN_1,ptr->cpsub,0x80,&asn_buf);
	if((flag & BIT7_TRUE)>0)		//Digits carrier
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,8),ptr->digitsCarrierLen & MAX_IS41_VARPAR_LEN_1,ptr->digitsCarrier,0x80,&asn_buf);
	if((flag & BIT8_TRUE)>0)		//ConferenceCallingIndicator
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CCI,9),ptr->cciLen & MAX_IS41_VARPAR_LEN_1,ptr->cci,0x80,&asn_buf);
	if((flag & BIT9_TRUE)>0)		//Digits carrier
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,10),ptr->digitsLen & MAX_IS41_VARPAR_LEN_1,ptr->digits,0x80,&asn_buf);
/*	if((flag & BIT10_TRUE)>0)		//display text
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DISPTEXT,11),ptr->disptextLen & MAX_IS41_VARPAR_LEN_1,ptr->disptext,0x80,&asn_buf);*/
	if((flag & BIT11_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACDGTS,12),ptr->acdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->acdgts,0x80,&asn_buf);
	if((flag & BIT12_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ABDGTS,13),ptr->abdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->abdgts,0x80,&asn_buf);
	if((flag & BIT13_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLDGTS,14),ptr->billdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->billdgts,0x80,&asn_buf);
	if((flag & BIT14_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_REDIND,15),ptr->redindLen & MAX_IS41_VARPAR_LEN_1,ptr->redind,0x80,&asn_buf);	
	if((flag & BIT15_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_GRPINFO,16),ptr->grpinfoLen & MAX_IS41_VARPAR_LEN_1,ptr->grpinfo,0x80,&asn_buf);
	if((flag & BIT16_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MDN,17),ptr->mdnLen & MAX_IS41_VARPAR_LEN_1,ptr->mdn,0x80,&asn_buf);
	if((flag & BIT17_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_NATIME,18),ptr->natimeLen & MAX_IS41_VARPAR_LEN_1,ptr->natime,0x80,&asn_buf);		
	if((flag & BIT18_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_OTFI,19),ptr->otfiLen & MAX_IS41_VARPAR_LEN_1,ptr->otfi,0x80,&asn_buf);
	if((flag & BIT19_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PACAIND,20),1,&ptr->pacaind,0x80,&asn_buf);
	if((flag & BIT20_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PILOT,21),ptr->pilotLen & MAX_IS41_VARPAR_LEN_1,ptr->pilot,0x80,&asn_buf);
	if((flag & BIT21_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RNDGTS,22),ptr->rndgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->rndgts,0x80,&asn_buf);
	if((flag & BIT22_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RNSTRING,23),ptr->rnstringLen & MAX_IS41_VARPAR_LEN_1,ptr->rnstring,0x80,&asn_buf);
	if((flag & BIT23_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSUB,24),ptr->rsubLen & MAX_IS41_VARPAR_LEN_1,ptr->rsub,0x80,&asn_buf);
	if((flag & BIT24_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RESUMEPIC,25),1,&ptr->resumepic,0x80,&asn_buf);
	if((flag & BIT25_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ROUTDGTS,26),ptr->routdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->routdgts,0x80,&asn_buf);
	if ((flag & BIT26_TRUE) > 0)
	{
		if (!encode_param_termlist(&ptr->termlist,ptr->termlist.param_flag,&asn_buf,&buf_len))
			return 0;
	}
	if((flag & BIT27_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTRIG,28),ptr->termtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrig,0x80,&asn_buf);

	if((flag & BIT28_TRUE)>0)		//TriggerAddressList
	{
		triglistnum = ptr->triggerlistnum & MAX_IS41_TRIG_LIST_NUM_1;
		if (!triglistnum)
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:TriggerAddressList no content!!");
			return 0;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TRIGADRLIST,29),0,NULL,0xA0,&asn_buf);
		for (i = 0; i < triglistnum; i++)
		{
			ptr1 = &ptr->triggerlist[i];
			flag1 = ptr1->param_flag;
			if ((flag1 & 0x03) != 0x03)
			{
				is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:triggerlist lacks mandatory info!!");
				return 0;
			}
			sprintf(tag,"%s.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST);
			buf_len = AddTLV(is41_sequenceTag(tag,i+1),0,NULL,0xA0,&asn_buf);
			if((flag1 & BIT0_TRUE)>0)		//destinationaddress -- choice global title
			{
				sprintf(tag,"%s.%s-%d.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST,i+1,IS41PAR_GLOBALTITLE);
				buf_len = AddTLV(is41_sequenceTag(tag,1),ptr1->destaddrLen & MAX_IS41_VARPAR_LEN_1,ptr1->destaddr,0x80,&asn_buf);
			}
			if((flag1 & BIT1_TRUE)>0)		//winoperationscapability
			{
				sprintf(tag,"%s.%s-%d.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST,i+1,IS41PAR_WINTRIGLIST);
				buf_len = AddTLV(is41_sequenceTag(tag,2),ptr1->wintriglistLen & MAX_IS41_VARPAR_LEN_1,ptr1->wintriglist,0x80,&asn_buf);
			}
		}
	}

	return buf_len;
}

int extract_is41FeatureRequest_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_FEATREQ_RSP  *ptr;
	IS41_PAR_TRIGGER_LIST	*ptr1;
	int		len,i,count;
	char 	tag[64];
	
	ptr = &opr_ptr->msg_list.featreq_rsp;

		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,33,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_FEATRESULT,1,&ptr->featresult,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

//optional par--->
	if (decode_Is41Parameter(IS41PAR_ACCDEN,1,&ptr->accden,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;

	len = decode_Is41Parameter(IS41PAR_ACTCODE,MAX_IS41_VARPAR_LEN,ptr->actcode,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT2_TRUE;
		ptr->actcodeLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_ANNLIST,MAX_IS41_VARPAR_LEN,ptr->annlist,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->annlistLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPNDGTS1,MAX_IS41_VARPAR_LEN,ptr->cpndgts1,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->cpndgts1Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPNDGTS2,MAX_IS41_VARPAR_LEN,ptr->cpndgts2,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->cpndgts2Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPSUB,MAX_IS41_VARPAR_LEN,ptr->cpsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->cpsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digitsCarrier,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->digitsCarrierLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_CCI,MAX_IS41_VARPAR_LEN,ptr->cci,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->cciLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digits,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->digitsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

/*	len = decode_Is41Parameter(IS41PAR_DISPTEXT,MAX_IS41_VARPAR_LEN,ptr->disptext,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->disptextLen = len & MAX_IS41_VARPAR_LEN_1;
	}*/
	
	len = decode_Is41Parameter(IS41PAR_ACDGTS,MAX_IS41_VARPAR_LEN,ptr->acdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->acdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_ABDGTS,MAX_IS41_VARPAR_LEN,ptr->abdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT12_TRUE;
		ptr->abdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_BILLDGTS,MAX_IS41_VARPAR_LEN,ptr->billdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT13_TRUE;
		ptr->billdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_REDIND,MAX_IS41_VARPAR_LEN,ptr->redind,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT14_TRUE;
		ptr->redindLen = len & MAX_IS41_VARPAR_LEN_1;
	}	

	len = decode_Is41Parameter(IS41PAR_GRPINFO,MAX_IS41_VARPAR_LEN,ptr->grpinfo,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT15_TRUE;
		ptr->grpinfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}	
	
	len = decode_Is41Parameter(IS41PAR_MDN,MAX_IS41_VARPAR_LEN,ptr->mdn,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT16_TRUE;
		ptr->mdnLen = len & MAX_IS41_VARPAR_LEN_1;
	}	

	len = decode_Is41Parameter(IS41PAR_NATIME,MAX_IS41_VARPAR_LEN,ptr->natime,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT17_TRUE;
		ptr->natimeLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_OTFI,MAX_IS41_VARPAR_LEN,ptr->otfi,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT18_TRUE;
		ptr->otfiLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_Is41Parameter(IS41PAR_PACAIND,1,&ptr->pacaind,&asn_buf))
		ptr->param_flag |= BIT19_TRUE;

	len = decode_Is41Parameter(IS41PAR_PILOT,MAX_IS41_VARPAR_LEN,ptr->pilot,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT20_TRUE;
		ptr->pilotLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_RNDGTS,MAX_IS41_VARPAR_LEN,ptr->rndgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT21_TRUE;
		ptr->rndgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RNSTRING,MAX_IS41_VARPAR_LEN,ptr->rnstring,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT22_TRUE;
		ptr->rnstringLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RSUB,MAX_IS41_VARPAR_LEN,ptr->rsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT23_TRUE;
		ptr->rsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	if (decode_Is41Parameter(IS41PAR_RESUMEPIC,1,&ptr->resumepic,&asn_buf))
		ptr->param_flag |= BIT24_TRUE;

	len = decode_Is41Parameter(IS41PAR_ROUTDGTS,MAX_IS41_VARPAR_LEN,ptr->routdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT25_TRUE;
		ptr->routdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_param_termlist(&ptr->termlist,&asn_buf) > 0)
		ptr->param_flag |= BIT26_TRUE;

	len = decode_Is41Parameter(IS41PAR_TERMTRIG,MAX_IS41_VARPAR_LEN,ptr->termtrig,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT27_TRUE;
		ptr->termtrigLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	ptr->triggerlistnum = 0;
	for (i = 0; i < MAX_IS41_TRIG_LIST_NUM; i++)
	{
		ptr1 = &ptr->triggerlist[i];
		count = 0;
		sprintf(tag, "%s.%s-%d.%s", IS41PAR_TRIGADRLIST, IS41PAR_TRIGLIST, i+1, IS41PAR_GLOBALTITLE);
		len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr1->destaddr,&asn_buf);
		if (len > 0)
		{
			ptr1->param_flag |= BIT0_TRUE;
			ptr1->destaddrLen = len & MAX_IS41_VARPAR_LEN_1;
			count++;
		}
		sprintf(tag, "%s.%s-%d.%s", IS41PAR_TRIGADRLIST, IS41PAR_TRIGLIST, i+1, IS41PAR_WINTRIGLIST);
		len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr1->wintriglist,&asn_buf);
		if (len > 0)
		{
			ptr1->param_flag |= BIT1_TRUE;
			ptr1->wintriglistLen = len & MAX_IS41_VARPAR_LEN_1;
			count++;
		}
		if (count == 2)
		{
			ptr->triggerlistnum++;
			ptr->param_flag |= BIT28_TRUE;
		}
		else if (count == 1)
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:triggerlist lacks mandatory info!!");
			return 0;
		}
		else if (!count)
			break;
	}
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}


int	assign_is41TransferToNumberRequest_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag,flag1;
	struct		IS41_TRANUMREQ_ARG *ptr;
	struct		IS41_PAR_WIN_CAP	*ptr1;
	char		tag[64];

	ptr = &opr_ptr->msg_list.tranumreq_arg;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);

	if((flag & BIT0_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,1),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}

	if((flag & BIT1_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,2),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

	if((flag & BIT2_TRUE)>0)		//REDIRECTION REASON
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_REDREASON,3),1,&ptr->redreason,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:redreason absent!!");
		return 0;
	}

	if((flag & BIT3_TRUE)>0)		//SystemMyTypeCode
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MYTYP,4),1,&ptr->mytyp,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MYTYP absent!!");
		return 0;
	}

// optional part--->
	if((flag & BIT4_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLID,5),7,ptr->billid,0x80,&asn_buf);
	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_GRPINFO,6),ptr->grpinfoLen & MAX_IS41_VARPAR_LEN_1,ptr->grpinfo,0x80,&asn_buf);
	if((flag & BIT6_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_LEGINFO,7),ptr->leginfoLen & MAX_IS41_VARPAR_LEN_1,ptr->leginfo,0x80,&asn_buf);
	if((flag & BIT7_TRUE)>0)		//MSCID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCID,8),3,ptr->mscid,0x80,&asn_buf);
	if((flag & BIT8_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCIN,9),ptr->mscinLen & MAX_IS41_VARPAR_LEN_1,ptr->mscin,0x80,&asn_buf);
	if((flag & BIT9_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PILOTBID,10),7,ptr->pilotbid,0x80,&asn_buf);
	if((flag & BIT10_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PILOT,11),ptr->pilotLen & MAX_IS41_VARPAR_LEN_1,ptr->pilot,0x80,&asn_buf);
	if((flag & BIT11_TRUE)>0)		//transcap
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TRANSCAP,12),ptr->transcapLen & MAX_IS41_VARPAR_LEN_1,ptr->transcap,0x80,&asn_buf);

	if((flag & BIT12_TRUE)>0)		//wincap
	{
		ptr1 = &ptr->wincap;
		flag1 = ptr1->param_flag;
		if (!(flag1 & 0x03))
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:wincap no content!!");
			return 0;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_WINCAP,21),0,NULL,0xA0,&asn_buf);
		if((flag1 & BIT0_TRUE)>0)		//triggercapability
		{
			sprintf(tag,"%s.%s",IS41PAR_WINCAP,IS41PAR_TRIGCAP);
			buf_len = AddTLV(is41_sequenceTag(tag,1),ptr1->triggercapLen & MAX_IS41_VARPAR_LEN_1,ptr1->triggercap,0x80,&asn_buf);
		}
		if((flag1 & BIT1_TRUE)>0)		//winoperationscapability
		{
			sprintf(tag,"%s.%s",IS41PAR_WINCAP,IS41PAR_WINOPRCAP);
			buf_len = AddTLV(is41_sequenceTag(tag,2),ptr1->winoprcapLen & MAX_IS41_VARPAR_LEN_1,ptr1->winoprcap,0x80,&asn_buf);
		}
	}

	return buf_len;
}

int extract_is41TransferToNumberRequest_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_TRANUMREQ_ARG *ptr;
	int		len;
	char	tag[64];

	ptr = &opr_ptr->msg_list.tranumreq_arg;
		
	if (buf_len == 0) 
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,24,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}	

	if (decode_Is41Parameter(IS41PAR_REDREASON,1,&ptr->redreason,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:redreason absent!");
		return 0;
	}	

	if (decode_Is41Parameter(IS41PAR_MYTYP,1,&ptr->mytyp,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MYTYP absent!");
		return 0;
	}

//optional par--->
	if (decode_Is41Parameter(IS41PAR_BILLID,7,ptr->billid,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	len = decode_Is41Parameter(IS41PAR_GRPINFO,MAX_IS41_VARPAR_LEN,ptr->grpinfo,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->grpinfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	len = decode_Is41Parameter(IS41PAR_LEGINFO,MAX_IS41_VARPAR_LEN,ptr->leginfo,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->leginfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	len = decode_Is41Parameter(IS41PAR_MSCIN,MAX_IS41_VARPAR_LEN,ptr->mscin,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->mscinLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	if (decode_Is41Parameter(IS41PAR_PILOTBID,7,ptr->pilotbid,&asn_buf))
		ptr->param_flag |= BIT9_TRUE;

	len = decode_Is41Parameter(IS41PAR_PILOT,MAX_IS41_VARPAR_LEN,ptr->pilot,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->pilotLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	len = decode_Is41Parameter(IS41PAR_TRANSCAP,MAX_IS41_VARPAR_LEN,ptr->transcap,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->transcapLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	sprintf(tag, "%s.%s", IS41PAR_WINCAP, IS41PAR_TRIGCAP);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->wincap.triggercap,&asn_buf);
	if (len > 0)
	{
		ptr->wincap.param_flag |= BIT0_TRUE;
		ptr->wincap.triggercapLen = len & MAX_IS41_VARPAR_LEN_1;
		ptr->param_flag |= BIT12_TRUE;
	}
	sprintf(tag, "%s.%s", IS41PAR_WINCAP, IS41PAR_WINOPRCAP);
	len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr->wincap.winoprcap,&asn_buf);
	if (len > 0)
	{
		ptr->wincap.param_flag |= BIT1_TRUE;
		ptr->wincap.winoprcapLen = len & MAX_IS41_VARPAR_LEN_1;
		ptr->param_flag |= BIT12_TRUE;
	}

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);
	
	return 1;
}

int assign_is41TransferToNumberRequest_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag,flag1;
	u8			i,triglistnum;
	IS41_PAR_TRIGGER_LIST	*ptr1;
	char		tag[64];

	struct IS41_TRANUMREQ_RSP *ptr;

	ptr = &opr_ptr->msg_list.tranumreq_rsp;

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

	if((flag & BIT0_TRUE)>0)		//Digits(Destination)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,1),ptr->digitsLen & MAX_IS41_VARPAR_LEN_1,ptr->digits,0x80,&asn_buf);
/*	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:Feature result absent!!");
		return 0;
	}*/

//optional
	if((flag & BIT1_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACCDEN,2),1,&ptr->accden,0x80,&asn_buf);
	if((flag & BIT2_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACTCODE,3),ptr->actcodeLen & MAX_IS41_VARPAR_LEN_1,ptr->actcode,0x80,&asn_buf);
	if((flag & BIT3_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ANNLIST,4),ptr->annlistLen & MAX_IS41_VARPAR_LEN_1,ptr->annlist,0x80,&asn_buf);
	if((flag & BIT4_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNSTRG1,5),ptr->cpnstrg1Len & MAX_IS41_VARPAR_LEN_1,ptr->cpnstrg1,0x80,&asn_buf);
	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPNSTRG2,6),ptr->cpnstrg2Len & MAX_IS41_VARPAR_LEN_1,ptr->cpnstrg2,0x80,&asn_buf);
	if((flag & BIT6_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CPSUB,7),ptr->cpsubLen & MAX_IS41_VARPAR_LEN_1,ptr->cpsub,0x80,&asn_buf);
	if((flag & BIT7_TRUE)>0)		//Digits carrier
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DIGITS,8),ptr->digitsCarrierLen & MAX_IS41_VARPAR_LEN_1,ptr->digitsCarrier,0x80,&asn_buf);
	if((flag & BIT8_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ACDGTS,9),ptr->acdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->acdgts,0x80,&asn_buf);
	if((flag & BIT9_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ABDGTS,10),ptr->abdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->abdgts,0x80,&asn_buf);
	if((flag & BIT10_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLDGTS,11),ptr->billdgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->billdgts,0x80,&asn_buf);
	if((flag & BIT11_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_REDIND,12),ptr->redindLen & MAX_IS41_VARPAR_LEN_1,ptr->redind,0x80,&asn_buf);	
	if((flag & BIT12_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DMH_SVCID,13),ptr->dmh_svcidLen & MAX_IS41_VARPAR_LEN_1,ptr->dmh_svcid,0x80,&asn_buf);
	if((flag & BIT13_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_GRPINFO,14),ptr->grpinfoLen & MAX_IS41_VARPAR_LEN_1,ptr->grpinfo,0x80,&asn_buf);
	if((flag & BIT14_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MDN,15),ptr->mdnLen & MAX_IS41_VARPAR_LEN_1,ptr->mdn,0x80,&asn_buf);
	if((flag & BIT15_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_NATIME,16),ptr->natimeLen & MAX_IS41_VARPAR_LEN_1,ptr->natime,0x80,&asn_buf);		
	if((flag & BIT16_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PLIND,17),1,&ptr->plind,0x80,&asn_buf);

	if((flag & BIT17_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RNDGTS,18),ptr->rndgtsLen & MAX_IS41_VARPAR_LEN_1,ptr->rndgts,0x80,&asn_buf);
	if((flag & BIT18_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RNSTRING,19),ptr->rnstringLen & MAX_IS41_VARPAR_LEN_1,ptr->rnstring,0x80,&asn_buf);
	if((flag & BIT19_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RSUB,20),ptr->rsubLen & MAX_IS41_VARPAR_LEN_1,ptr->rsub,0x80,&asn_buf);

	if ((flag & BIT20_TRUE) > 0)
	{
		if (!encode_param_termlist(&ptr->termlist,ptr->termlist.param_flag,&asn_buf,&buf_len))
			return 0;
	}
	if((flag & BIT21_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTRIG,22),ptr->termtrigLen & MAX_IS41_VARPAR_LEN_1,ptr->termtrig,0x80,&asn_buf);

	if((flag & BIT22_TRUE)>0)		//TriggerAddressList
	{
		triglistnum = ptr->triggerlistnum & MAX_IS41_TRIG_LIST_NUM_1;
		if (!triglistnum)
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:TriggerAddressList no content!!");
			return 0;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TRIGADRLIST,23),0,NULL,0xA0,&asn_buf);
		for (i = 0; i < triglistnum; i++)
		{
			ptr1 = &ptr->triggerlist[i];
			flag1 = ptr1->param_flag;
			if ((flag1 & 0x03) != 0x03)
			{
				is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:triggerlist lacks mandatory info!!");
				return 0;
			}
			sprintf(tag,"%s.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST);
			buf_len = AddTLV(is41_sequenceTag(tag,i+1),0,NULL,0xA0,&asn_buf);
			if((flag1 & BIT0_TRUE)>0)		//destinationaddress -- choice global title
			{
				sprintf(tag,"%s.%s-%d.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST,i+1,IS41PAR_GLOBALTITLE);
				buf_len = AddTLV(is41_sequenceTag(tag,1),ptr1->destaddrLen & MAX_IS41_VARPAR_LEN_1,ptr1->destaddr,0x80,&asn_buf);
			}
			if((flag1 & BIT1_TRUE)>0)		//winoperationscapability
			{
				sprintf(tag,"%s.%s-%d.%s",IS41PAR_TRIGADRLIST,IS41PAR_TRIGLIST,i+1,IS41PAR_WINTRIGLIST);
				buf_len = AddTLV(is41_sequenceTag(tag,2),ptr1->wintriglistLen & MAX_IS41_VARPAR_LEN_1,ptr1->wintriglist,0x80,&asn_buf);
			}
		}
	}

	return buf_len;
}

int extract_is41TransferToNumberRequest_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_TRANUMREQ_RSP  *ptr;
	IS41_PAR_TRIGGER_LIST	*ptr1;
	int		len,i,count;
	char 	tag[64];
	
	ptr = &opr_ptr->msg_list.tranumreq_rsp;

		
	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,33,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digits,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT0_TRUE;
		ptr->digitsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
/*	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:Digits absent!");
		return 0;
	}*/

//optional par--->
	if (decode_Is41Parameter(IS41PAR_ACCDEN,1,&ptr->accden,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;

	len = decode_Is41Parameter(IS41PAR_ACTCODE,MAX_IS41_VARPAR_LEN,ptr->actcode,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT2_TRUE;
		ptr->actcodeLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_ANNLIST,MAX_IS41_VARPAR_LEN,ptr->annlist,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->annlistLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPNSTRG1,MAX_IS41_VARPAR_LEN,ptr->cpnstrg1,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->cpnstrg1Len = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_CPNSTRG2,MAX_IS41_VARPAR_LEN,ptr->cpnstrg2,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->cpnstrg2Len = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_CPSUB,MAX_IS41_VARPAR_LEN,ptr->cpsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->cpsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_DIGITS,MAX_IS41_VARPAR_LEN,ptr->digitsCarrier,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->digitsCarrierLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_ACDGTS,MAX_IS41_VARPAR_LEN,ptr->acdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->acdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_ABDGTS,MAX_IS41_VARPAR_LEN,ptr->abdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->abdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_BILLDGTS,MAX_IS41_VARPAR_LEN,ptr->billdgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->billdgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_REDIND,MAX_IS41_VARPAR_LEN,ptr->redind,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->redindLen = len & MAX_IS41_VARPAR_LEN_1;
	}	

	len = decode_Is41Parameter(IS41PAR_DMH_SVCID,MAX_IS41_VARPAR_LEN,ptr->dmh_svcid,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT12_TRUE;
		ptr->dmh_svcidLen = len & MAX_IS41_VARPAR_LEN_1;
	}	

	len = decode_Is41Parameter(IS41PAR_GRPINFO,MAX_IS41_VARPAR_LEN,ptr->grpinfo,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT13_TRUE;
		ptr->grpinfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}	
	
	len = decode_Is41Parameter(IS41PAR_MDN,MAX_IS41_VARPAR_LEN,ptr->mdn,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT14_TRUE;
		ptr->mdnLen = len & MAX_IS41_VARPAR_LEN_1;
	}	

	len = decode_Is41Parameter(IS41PAR_NATIME,MAX_IS41_VARPAR_LEN,ptr->natime,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT15_TRUE;
		ptr->natimeLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	if (decode_Is41Parameter(IS41PAR_PLIND,1,&ptr->plind,&asn_buf))
		ptr->param_flag |= BIT16_TRUE;

	len = decode_Is41Parameter(IS41PAR_RNDGTS,MAX_IS41_VARPAR_LEN,ptr->rndgts,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT17_TRUE;
		ptr->rndgtsLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RNSTRING,MAX_IS41_VARPAR_LEN,ptr->rnstring,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT18_TRUE;
		ptr->rnstringLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	len = decode_Is41Parameter(IS41PAR_RSUB,MAX_IS41_VARPAR_LEN,ptr->rsub,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT19_TRUE;
		ptr->rsubLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	if (decode_param_termlist(&ptr->termlist,&asn_buf) > 0)
		ptr->param_flag |= BIT20_TRUE;

	len = decode_Is41Parameter(IS41PAR_TERMTRIG,MAX_IS41_VARPAR_LEN,ptr->termtrig,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT21_TRUE;
		ptr->termtrigLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	ptr->triggerlistnum = 0;
	for (i = 0; i < MAX_IS41_TRIG_LIST_NUM; i++)
	{
		ptr1 = &ptr->triggerlist[i];
		count = 0;
		sprintf(tag, "%s.%s-%d.%s", IS41PAR_TRIGADRLIST, IS41PAR_TRIGLIST, i+1, IS41PAR_GLOBALTITLE);
		len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr1->destaddr,&asn_buf);
		if (len > 0)
		{
			ptr1->param_flag |= BIT0_TRUE;
			ptr1->destaddrLen = len & MAX_IS41_VARPAR_LEN_1;
			count++;
		}
		sprintf(tag, "%s.%s-%d.%s", IS41PAR_TRIGADRLIST, IS41PAR_TRIGLIST, i+1, IS41PAR_WINTRIGLIST);
		len = decode_Is41Parameter(tag,MAX_IS41_VARPAR_LEN,ptr1->wintriglist,&asn_buf);
		if (len > 0)
		{
			ptr1->param_flag |= BIT1_TRUE;
			ptr1->wintriglistLen = len & MAX_IS41_VARPAR_LEN_1;
			count++;
		}
		if (count == 2)
		{
			ptr->triggerlistnum++;
			ptr->param_flag |= BIT22_TRUE;
		}
		else if (count == 1)
		{
			is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:triggerlist lacks mandatory info!!");
			return 0;
		}
		else if (!count)
			break;
	}
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}

int	assign_is41RedirectionRequest_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	struct		IS41_REDREQ_ARG *ptr;

	ptr = &opr_ptr->msg_list.redreq_arg;

	flag = ptr->param_flag;

	AsnEncode(buf,256,&asn_buf);

	if((flag & BIT0_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_BILLID,1),7,ptr->billid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:BILLID absent!!");
		return 0;
	}

	if((flag & BIT1_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,2),ESN_LEN,ptr->esn,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:ESN absent!!");
		return 0;
	}

	if((flag & BIT2_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,3),MIN_LEN,ptr->min,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!!");
		return 0;
	}

	if((flag & BIT3_TRUE)>0)		//REDIRECTION REASON
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_REDREASON,4),1,&ptr->redreason,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:redreason absent!!");
		return 0;
	}


// optional part--->
	if((flag & BIT4_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_LEGINFO,5),ptr->leginfoLen & MAX_IS41_VARPAR_LEN_1,ptr->leginfo,0x80,&asn_buf);
	if((flag & BIT5_TRUE)>0)
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MSCIN,6),ptr->mscinLen & MAX_IS41_VARPAR_LEN_1,ptr->mscin,0x80,&asn_buf);

	return buf_len;
}

int extract_is41RedirectionRequest_arg(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	struct IS41_REDREQ_ARG *ptr;
	int		len;

	ptr = &opr_ptr->msg_list.redreq_arg;
		
	if (buf_len == 0) 
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,24,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;

	if (decode_Is41Parameter(IS41PAR_BILLID,7,ptr->billid,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:BILLID absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ESN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MIN absent!");
		return 0;
	}

	if (decode_Is41Parameter(IS41PAR_REDREASON,1,&ptr->redreason,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:redreason absent!");
		return 0;
	}	


//optional par--->
	len = decode_Is41Parameter(IS41PAR_LEGINFO,MAX_IS41_VARPAR_LEN,ptr->leginfo,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->leginfoLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_MSCIN,MAX_IS41_VARPAR_LEN,ptr->mscin,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->mscinLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	
	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);
	
	return 1;
}

int assign_is41RedirectionRequest_rsp(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;

	struct IS41_REDREQ_RSP *ptr;

	ptr = &opr_ptr->msg_list.redreq_rsp;

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

	return buf_len;
}

int extract_is41RedirectionRequest_rsp(struct MapOprSrv_struct *opr_ptr,u32 buf_len,u8 *buf)
{
	struct IS41_REDREQ_RSP *ptr;

	ptr = &opr_ptr->msg_list.redreq_rsp;
	ptr->param_flag = 0;

	is41_debug(IS41DB_DECODE,"[IS41-Decode]Completed, flag=0x%lx",ptr->param_flag);

	return 1;
}
