/*	is41 coding smsc service file		*/
/*	written by daniel zhang 2004-07-10	*/
/*  modified by daniel on 2004-07-10	*/
/*	--------------------------------	*/

#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);

int	encode_Is41ParBearerData(IS41ParBearerData *ptr, u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	
	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);
	
	if ((flag & BIT0_TRUE) > 0)
		buf_len = AddTLV("0",3,ptr->MessageId,0x80,&asn_buf);
	
	if ((flag & BIT1_TRUE) > 0)
		buf_len = AddTLV("1",ptr->UserDataLen & 31,ptr->UserData,0x80,&asn_buf);
	
	if ((flag & BIT2_TRUE) > 0)
		buf_len = AddTLV("2",1,&ptr->UserRespondingCode,0x80,&asn_buf);
		
	if ((flag & BIT3_TRUE) > 0)
		buf_len = AddTLV("3",6,ptr->MessageCenterTimeStamp,0x80,&asn_buf);
		
	if ((flag & BIT4_TRUE) > 0)
		buf_len = AddTLV("4",6,ptr->ValidityPeriod_Absolute,0x80,&asn_buf);
	if ((flag & BIT5_TRUE) > 0)
		buf_len = AddTLV("5",1,&ptr->ValidityPeriod_Relative,0x80,&asn_buf);
	if ((flag & BIT6_TRUE) > 0)
		buf_len = AddTLV("6",6,ptr->DeferredDeliveryTime_Absolute,0x80,&asn_buf);
	if ((flag & BIT7_TRUE) > 0)
		buf_len = AddTLV("7",1,&ptr->DeferredDeliveryTime_Relative,0x80,&asn_buf);
	if ((flag & BIT8_TRUE) > 0)
		buf_len = AddTLV("8",1,&ptr->PriorityIndicator,0x80,&asn_buf);
	if ((flag & BIT9_TRUE) > 0)
		buf_len = AddTLV("9",1,&ptr->PrivacyIndicator,0x80,&asn_buf);
	if ((flag & BIT10_TRUE) > 0)
		buf_len = AddTLV("10",1,&ptr->ReplyOption,0x80,&asn_buf);
	if ((flag & BIT11_TRUE) > 0)
		buf_len = AddTLV("11",1,&ptr->NumberOfMessages,0x80,&asn_buf);
	if ((flag & BIT12_TRUE) > 0)
		buf_len = AddTLV("12",1,&ptr->AlertOnMessageDelivery,0x80,&asn_buf);
	if ((flag & BIT13_TRUE) > 0)
		buf_len = AddTLV("13",1,&ptr->LanguageIndicator,0x80,&asn_buf);
	if ((flag & BIT14_TRUE) > 0)
		buf_len = AddTLV("14",ptr->CallBackNumberLen & 31,ptr->CallBackNumber,0x80,&asn_buf);
	if ((flag & BIT15_TRUE) > 0)
		buf_len = AddTLV("15",1,&ptr->MessageDisplayMode,0x80,&asn_buf);
	if ((flag & BIT16_TRUE) > 0)
		buf_len = AddTLV("16",ptr->MultipleEncodingUserDataLen & 31,ptr->MultipleEncodingUserData,0x80,&asn_buf);
		
	if ((flag & BIT17_TRUE) > 0)
		buf_len = AddTLV("20",1,&ptr->MessageStatus,0x80,&asn_buf);
	if ((flag & BIT18_TRUE) > 0)
		buf_len = AddTLV("21",1,&ptr->TPFailureCause,0x80,&asn_buf);

	
	return buf_len;
}

int decode_Is41ParBearerData(IS41ParBearerData *ptr, u32 buf_len,u8 *buf)
{
	ASN_BUF	asn_buf;
	int		len;
	
	if(AsnDecode(buf,buf_len,19,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;
	
	if (decode_Is41Parameter("0",3,ptr->MessageId,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	
	len = decode_Is41Parameter("1",128,ptr->UserData,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT1_TRUE;
		ptr->UserDataLen = len & 127;
	}
	if (decode_Is41Parameter("2",1,&ptr->UserRespondingCode,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	if (decode_Is41Parameter("3",6,ptr->MessageCenterTimeStamp,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	if (decode_Is41Parameter("4",6,ptr->ValidityPeriod_Absolute,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	if (decode_Is41Parameter("5",1,&ptr->ValidityPeriod_Relative,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	if (decode_Is41Parameter("6",6,ptr->DeferredDeliveryTime_Absolute,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	if (decode_Is41Parameter("7",1,&ptr->DeferredDeliveryTime_Relative,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	if (decode_Is41Parameter("8",1,&ptr->PriorityIndicator,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;
	if (decode_Is41Parameter("9",1,&ptr->PrivacyIndicator,&asn_buf))
		ptr->param_flag |= BIT9_TRUE;
	if (decode_Is41Parameter("10",1,&ptr->ReplyOption,&asn_buf))
		ptr->param_flag |= BIT10_TRUE;
	if (decode_Is41Parameter("11",1,&ptr->NumberOfMessages,&asn_buf))
		ptr->param_flag |= BIT11_TRUE;
	if (decode_Is41Parameter("12",1,&ptr->AlertOnMessageDelivery,&asn_buf))
		ptr->param_flag |= BIT12_TRUE;
	if (decode_Is41Parameter("13",1,&ptr->LanguageIndicator,&asn_buf))
		ptr->param_flag |= BIT13_TRUE;
	len = decode_Is41Parameter("14",MAX_IS41_VARPAR_LEN,ptr->CallBackNumber,&asn_buf);
	if (len > 0)
	{
		ptr->CallBackNumberLen = len & MAX_IS41_VARPAR_LEN_1;
		ptr->param_flag |= BIT14_TRUE;
	}
	if (decode_Is41Parameter("15",1,&ptr->MessageDisplayMode,&asn_buf))
		ptr->param_flag |= BIT15_TRUE;
	len = decode_Is41Parameter("16",MAX_IS41_VARPAR_LEN,ptr->MultipleEncodingUserData,&asn_buf);
	if (len > 0)
	{
		ptr->MultipleEncodingUserDataLen = len & MAX_IS41_VARPAR_LEN_1;
		ptr->param_flag |= BIT16_TRUE;
	}
	if (decode_Is41Parameter("20",1,&ptr->MessageStatus,&asn_buf))
		ptr->param_flag |= BIT17_TRUE;
	if (decode_Is41Parameter("21",1,&ptr->TPFailureCause,&asn_buf))
		ptr->param_flag |= BIT18_TRUE;
	return 1;

}

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

	struct IS41_SMDBACK_ARG *ptr;

	ptr = &opr_ptr->msg_list.smdback_arg;
	
	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_IMSCCID,1),2,(BYTE*)&ptr->imsccid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:InterMSCCID 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)		//SMS_BearerData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSBD,3),ptr->BearerDataLen,ptr->BearerData,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:SMS_BearerData absent!!");
		return 0;
	}

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


// optional part--->
	if((flag & BIT4_TRUE)>0)		//ElectronicSerialNumber
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,5),ESN_LEN,ptr->esn,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//SMS_ChargeIndicator
	{
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSCID,6),ptr->smscidLen & MAX_IS41_VARPAR_LEN_1,ptr->smscid,0x80,&asn_buf);
	}

	if((flag & BIT6_TRUE)>0)		//SMS_DestinationAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSDA,7),ptr->smsdaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsda,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)		//SMS_OriginalDestinationAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSODA,8),ptr->smsodaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoda,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)		//SMS_OriginalDestinationSubaddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSODS,9),ptr->smsodsLen & MAX_IS41_VARPAR_LEN_1,ptr->smsods,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)		//SMS_OriginalOriginatingAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOOA,10),ptr->smsooaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsooa,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)		//SMS_OriginalOriginatingSubaddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOOS,11),ptr->smsoosLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoos,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)		//smsoa
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOA,12),ptr->smsoaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoa,0x80,&asn_buf);

	return buf_len;
}

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

	struct IS41_SMDBACK_ARG *ptr;

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

	if (decode_Is41Parameter(IS41PAR_IMSCCID,2,ptr->imsccid,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:InterMSCCID absent!");

	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!");

	if ((ptr->BearerDataLen=decode_Is41Parameter(IS41PAR_SMSBD,256,ptr->BearerData,&asn_buf))>0)
		ptr->param_flag |= BIT2_TRUE;
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_BearerData absent!");

	len = decode_Is41Parameter(IS41PAR_SMSTID,MAX_IS41_VARPAR_LEN,ptr->smstid,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->smstidLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:IS41PAR_SMSTID absent!");


//optional par--->
	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;

	len = decode_Is41Parameter(IS41PAR_SMSCID,MAX_IS41_VARPAR_LEN,ptr->smscid,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->smscidLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSDA,MAX_IS41_VARPAR_LEN,ptr->smsda,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->smsdaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSODA,MAX_IS41_VARPAR_LEN,ptr->smsoda,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->smsodaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSODS,MAX_IS41_VARPAR_LEN,ptr->smsods,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->smsodsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOOA,MAX_IS41_VARPAR_LEN,ptr->smsooa,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->smsooaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOOS,MAX_IS41_VARPAR_LEN,ptr->smsoos,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->smsoosLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOA,MAX_IS41_VARPAR_LEN,ptr->smsoa,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->smsoaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

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

	return 1;
}

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

	struct IS41_SMDBACK_RSP *ptr;

	ptr = &opr_ptr->msg_list.smdback_rsp;
	
	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

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

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

	return buf_len;
}


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

	struct IS41_SMDBACK_RSP *ptr;

	ptr = &opr_ptr->msg_list.smdback_rsp;

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

	if ((ptr->BearerDataLen=decode_Is41Parameter(IS41PAR_SMSBD,256,ptr->BearerData,&asn_buf))>0)
		ptr->param_flag |= BIT0_TRUE;
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_BearerData absent!");

	len = decode_Is41Parameter(IS41PAR_SMSCC,MAX_IS41_VARPAR_LEN,ptr->smscc,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT1_TRUE;
		ptr->smsccLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_CauseCode absent!");

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.smdfwd_arg;

	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)		//esn
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_IMSCCID,1),2,(BYTE*)&ptr->imsccid,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:InterMSCCID 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)		//SMS_BearerData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSBD,3),ptr->BearerDataLen,ptr->BearerData,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:SMS_BearerData absent!!");
		return 0;
	}

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


// optional part--->
	if((flag & BIT4_TRUE)>0)		//ElectronicSerialNumber
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,5),ESN_LEN,ptr->esn,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//SMS_ChargeIndicator
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSCID,6),ptr->smscidLen & MAX_IS41_VARPAR_LEN_1,ptr->smscid,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)		//SMS_DestinationAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSDA,7),ptr->smsdaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsda,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)		//SMS_OriginalDestinationAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSODA,8),ptr->smsodaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoda,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)		//SMS_OriginalDestinationSubaddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSODS,9),ptr->smsodsLen & MAX_IS41_VARPAR_LEN_1,ptr->smsods,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)		//SMS_OriginalOriginatingAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOOA,10),ptr->smsooaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsooa,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)		//SMS_OriginalOriginatingSubaddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOOS,11),ptr->smsoosLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoos,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)		//SMS_OriginatingAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOA,12),ptr->smsoaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoa,0x80,&asn_buf);

	return buf_len;
}

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

	struct IS41_SMDFWD_ARG *ptr;

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

	if (decode_Is41Parameter(IS41PAR_IMSCCID,2,ptr->imsccid,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:InterMSCCID absent!");

	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!");

	if ((ptr->BearerDataLen=decode_Is41Parameter(IS41PAR_SMSBD,256,ptr->BearerData,&asn_buf))>0)
		ptr->param_flag |= BIT2_TRUE;
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_BearerData absent!");

	len = decode_Is41Parameter(IS41PAR_SMSTID,MAX_IS41_VARPAR_LEN,ptr->smstid,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->smstidLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:IS41PAR_SMSTID absent!");


//optional par--->
	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;

	len = decode_Is41Parameter(IS41PAR_SMSCID,MAX_IS41_VARPAR_LEN,ptr->smscid,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->smscidLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSDA,MAX_IS41_VARPAR_LEN,ptr->smsda,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->smsdaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSODA,MAX_IS41_VARPAR_LEN,ptr->smsoda,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->smsodaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSODS,MAX_IS41_VARPAR_LEN,ptr->smsods,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->smsodsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOOA,MAX_IS41_VARPAR_LEN,ptr->smsooa,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->smsooaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOOS,MAX_IS41_VARPAR_LEN,ptr->smsoos,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->smsoosLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOA,MAX_IS41_VARPAR_LEN,ptr->smsoa,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->smsoaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

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

	return 1;
}

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

	struct IS41_SMDFWD_RSP *ptr;

	ptr = &opr_ptr->msg_list.smdfwd_rsp;
	
	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

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

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

	return buf_len;
}


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

	struct IS41_SMDFWD_RSP *ptr;

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

	if ((ptr->BearerDataLen=decode_Is41Parameter(IS41PAR_SMSBD,256,ptr->BearerData,&asn_buf))>0)
		ptr->param_flag |= BIT0_TRUE;
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_BearerData absent!");

	len = decode_Is41Parameter(IS41PAR_SMSCC,MAX_IS41_VARPAR_LEN,ptr->smscc,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT1_TRUE;
		ptr->smsccLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_CauseCode absent!");

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

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

	struct IS41_SMDPP_ARG *ptr;

	ptr = &opr_ptr->msg_list.smdpp_arg;
	
	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

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

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


// optional part--->
	if((flag & BIT2_TRUE)>0)		//ElectronicSerialNumber
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,3),ESN_LEN,ptr->esn,0x80,&asn_buf);

	if((flag & BIT3_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,4),MIN_LEN,ptr->min,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)		//SMS_ChargeIndicator
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSCID,5),ptr->smscidLen & MAX_IS41_VARPAR_LEN_1,ptr->smscid,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//SMS_DestinationAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSDA,6),ptr->smsdaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsda,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)		//SMS_MessageCount
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSMSGCNT,7),ptr->smsmsgcntLen & MAX_IS41_VARPAR_LEN_1,ptr->smsmsgcnt,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)		//SMS_NotificationIndicator
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSNOTIND,8),ptr->smsnotindLen & MAX_IS41_VARPAR_LEN_1,ptr->smsnotind,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)		//SMS_OriginalDestinationAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSODA,9),ptr->smsodaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoda,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)		//SMS_OriginalDestinationSubaddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSODS,10),ptr->smsodsLen & MAX_IS41_VARPAR_LEN_1,ptr->smsods,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)		//SMS_OriginalOriginatingAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOOA,11),ptr->smsooaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsooa,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)		//SMS_OriginalOriginatingSubaddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOOS,12),ptr->smsoosLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoos,0x80,&asn_buf);

	if((flag & BIT12_TRUE)>0)		//SMS_OriginatingAddress
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSOA,13),ptr->smsoaLen & MAX_IS41_VARPAR_LEN_1,ptr->smsoa,0x80,&asn_buf);

	return buf_len;
}

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

	ptr = &opr_ptr->msg_list.smdpp_arg;

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

	if ((ptr->BearerDataLen=decode_Is41Parameter(IS41PAR_SMSBD,256,ptr->BearerData,&asn_buf))>0)
		ptr->param_flag |= BIT0_TRUE;
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_BearerData absent!");

	len = decode_Is41Parameter(IS41PAR_SMSTID,MAX_IS41_VARPAR_LEN,ptr->smstid,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT1_TRUE;
		ptr->smstidLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:IS41PAR_SMSTID absent!");


//optional par--->
	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,ptr->esn,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;

	if (decode_Is41Parameter(IS41PAR_MIN,MIN_LEN,ptr->min,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;

	len = decode_Is41Parameter(IS41PAR_SMSCID,MAX_IS41_VARPAR_LEN,ptr->smscid,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT4_TRUE;
		ptr->smscidLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSDA,MAX_IS41_VARPAR_LEN,ptr->smsda,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->smsdaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSMSGCNT,MAX_IS41_VARPAR_LEN,ptr->smsmsgcnt,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->smsmsgcntLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSNOTIND,MAX_IS41_VARPAR_LEN,ptr->smsnotind,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT7_TRUE;
		ptr->smsnotindLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSODA,MAX_IS41_VARPAR_LEN,ptr->smsoda,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT8_TRUE;
		ptr->smsodaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSODS,MAX_IS41_VARPAR_LEN,ptr->smsods,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->smsodsLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOOA,MAX_IS41_VARPAR_LEN,ptr->smsooa,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT10_TRUE;
		ptr->smsooaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOOS,MAX_IS41_VARPAR_LEN,ptr->smsoos,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT11_TRUE;
		ptr->smsoosLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSOA,MAX_IS41_VARPAR_LEN,ptr->smsoa,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT12_TRUE;
		ptr->smsoaLen = len & MAX_IS41_VARPAR_LEN_1;
	}

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.smdpp_rsp;

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

	if((flag & BIT0_TRUE)>0)		//SMS_BearerData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSBD,1),ptr->BearerDataLen,ptr->BearerData,0x80,&asn_buf);

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

	return buf_len;
}


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

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

	if (buf_len == 0)
		return 1;
	if(AsnDecode(buf,buf_len,13,&decErr,&asn_buf) == -1)
		return 0;

	if ((ptr->BearerDataLen=decode_Is41Parameter(IS41PAR_SMSBD,256,ptr->BearerData,&asn_buf))>0)
		ptr->param_flag |= BIT0_TRUE;
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_BearerData absent!");

	len = decode_Is41Parameter(IS41PAR_SMSCC,MAX_IS41_VARPAR_LEN,ptr->smscc,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT1_TRUE;
		ptr->smsccLen = len & MAX_IS41_VARPAR_LEN_1;
	}
	else
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SMS_CauseCode absent!");

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

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

	ptr = &opr_ptr->msg_list.smsnot_arg;

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

	if((flag & BIT0_TRUE)>0)		//ElectronicSerialNumber
		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)		//SMS_AccessDeniedReason
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSACCDEN,3),ptr->smsaccdenLen & MAX_IS41_VARPAR_LEN_1,ptr->smsaccden,0x80,&asn_buf);

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

	return buf_len;
}

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

	ptr = &opr_ptr->msg_list.smsnot_arg;

	if (buf_len == 0)
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:buffer len=0!");
		return 0;
	}
	if(AsnDecode(buf,buf_len,13,&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!");

	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!");

//optional par--->
	len = decode_Is41Parameter(IS41PAR_SMSACCDEN,MAX_IS41_VARPAR_LEN,ptr->smsaccden,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT2_TRUE;
		ptr->smsaccdenLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSADDR,MAX_IS41_VARPAR_LEN,ptr->smsaddr,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->smsaddrLen = len & MAX_IS41_VARPAR_LEN_1;
	}

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

	return 1;
}

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

	struct IS41_SMSNOT_RSP *ptr;

	ptr = &opr_ptr->msg_list.smsnot_rsp;
	
	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

	return buf_len;
}

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

	struct IS41_SMSNOT_RSP *ptr;

	ptr = &opr_ptr->msg_list.smsnot_rsp;
		
	if(AsnDecode(buf,buf_len,13,&decErr,&asn_buf) == -1)
		return 0;
	ptr->param_flag = 0;


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

	return 1;
}

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

	struct IS41_SMSREQ_ARG *ptr;

	ptr = &opr_ptr->msg_list.smsreq_arg;
	
	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);

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

// optional part--->
	if((flag & BIT1_TRUE)>0)		//ElectronicSerialNumber
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,2),ESN_LEN,ptr->esn,0x80,&asn_buf);

	if((flag & BIT2_TRUE)>0)		//SMS_NotificationIndicator
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSNOTIND,3),ptr->smsnotindLen & MAX_IS41_VARPAR_LEN_1,ptr->smsnotind,0x80,&asn_buf);

	if((flag & BIT3_TRUE)>0)		//SMS_TeleserviceIdentifier
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSTID,4),ptr->smstidLen & MAX_IS41_VARPAR_LEN_1,ptr->smstid,0x80,&asn_buf);

	return buf_len;
}

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

	ptr = &opr_ptr->msg_list.smsreq_arg;

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

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

//optional par--->
	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!");
	
	len = decode_Is41Parameter(IS41PAR_SMSNOTIND,MAX_IS41_VARPAR_LEN,ptr->smsnotind,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT2_TRUE;
		ptr->smsnotindLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSTID,MAX_IS41_VARPAR_LEN,ptr->smstid,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->smstidLen = len & MAX_IS41_VARPAR_LEN_1;
	}

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.smsreq_rsp;

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

// optional part--->
	if((flag & BIT0_TRUE)>0)		//ElectronicSerialNumber
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_ESN,1),ESN_LEN,ptr->esn,0x80,&asn_buf);

	if((flag & BIT1_TRUE)>0)		//SMS_AccessDeniedReason
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMSACCDEN,2),ptr->smsaccdenLen & MAX_IS41_VARPAR_LEN_1,ptr->smsaccden,0x80,&asn_buf);

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

	return buf_len;
}

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

	ptr = &opr_ptr->msg_list.smsreq_rsp;

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


//optional par--->
	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!");
	
	len = decode_Is41Parameter(IS41PAR_SMSACCDEN,MAX_IS41_VARPAR_LEN,ptr->smsaccden,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT1_TRUE;
		ptr->smsaccdenLen = len & MAX_IS41_VARPAR_LEN_1;
	}

	len = decode_Is41Parameter(IS41PAR_SMSADDR,MAX_IS41_VARPAR_LEN,ptr->smsaddr,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT2_TRUE;
		ptr->smsaddrLen = len & MAX_IS41_VARPAR_LEN_1;
	}

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

	return 1;
}
