/*	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_is41AuthenticationDirective_arg(struct MapOprSrv_struct *opr_ptr,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			buf_len=0;
	u32			flag;
	struct IS41_AUTHDIR_ARG *ptr;

	ptr = &opr_ptr->msg_list.authdir_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,(BYTE*)&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;
	}

	is41_debug(IS41DB_ENCODE,"[IS41-Encode] Starting...ESN=%lx%lx%lx%lx,MIN=%ld%ld%ld%ld",
							ptr->esn[0],ptr->esn[1],ptr->esn[2],ptr->esn[3],
							ptr->min[0],ptr->min[1],
							ptr->min[2],ptr->min[3],ptr->min[4]);

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

	if((flag & BIT3_TRUE)>0)		//AuthenticationResponseUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHU,4),3,ptr->authu,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)		//CallHistoryCount
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_COUNT,5),1,&ptr->count,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//DenyAccess
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DENACC,6),1,&ptr->denacc,0x80,&asn_buf);

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

	if((flag & BIT7_TRUE)>0)		//RandomVariableSSD
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDSSD,8),7,ptr->randssd,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)		//RandomVariableUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDU,9),3,ptr->randu,0x80,&asn_buf);

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

	if((flag & BIT10_TRUE)>0)		//SharedSecretData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SSD,11),16,ptr->ssd,0x80,&asn_buf);

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

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


	return buf_len;
}

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

	struct IS41_AUTHDIR_RSP *ptr;

	ptr = &opr_ptr->msg_list.authdir_rsp;

	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)		//CallHistoryCount
		buf_len = AddTLV(IS41PAR_COUNT,1,(BYTE*)&ptr->count,0x80,&asn_buf);
	else
		return 0;

	return buf_len;
}

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

	struct IS41_AUTHDIR_ARG *ptr;

	ptr = &opr_ptr->msg_list.authdir_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,(BYTE*)&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_AAV,1,&ptr->aav,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	if (decode_Is41Parameter(IS41PAR_AUTHU,3,ptr->authu,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	if (decode_Is41Parameter(IS41PAR_DENACC,1,&ptr->denacc,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	if (decode_Is41Parameter(IS41PAR_LOCID,2,ptr->locid,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDSSD,7,ptr->randssd,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDU,8,ptr->randu,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;
	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT9_TRUE;
	}
	if (decode_Is41Parameter(IS41PAR_SSD,16,ptr->ssd,&asn_buf))
		ptr->param_flag |= BIT10_TRUE;
	if (decode_Is41Parameter(IS41PAR_NOSSD,1,&ptr->nossd,&asn_buf))
		ptr->param_flag |= BIT11_TRUE;
	if (decode_Is41Parameter(IS41PAR_UPDCOUNT,1,&ptr->updcount,&asn_buf))
		ptr->param_flag |= BIT12_TRUE;

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

	return 1;
}

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

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

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.AUCDirForw_arg;
	
	flag = ptr->param_flag;
	AsnEncode(buf,256,&asn_buf);
	if((flag & BIT0_TRUE)>0)		//inter MSC CircuitID
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_IMSCCID,1),2,ptr->InterMSCCircuitID,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MSC CID absent!");
		return 0;
	}
	if((flag & BIT1_TRUE)>0)		//min
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_MIN,2),MIN_LEN,ptr->MobileIdentificationNumber,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:MIN absent!");
		return 0;
	}

	is41_debug(IS41DB_ENCODE,"[IS41-Encode] Starting...MSC CID=%x.%x,MIN=%ld%ld%ld%ld",
							ptr->InterMSCCircuitID[0],ptr->InterMSCCircuitID[1],
							ptr->MobileIdentificationNumber[0],ptr->MobileIdentificationNumber[1],
							ptr->MobileIdentificationNumber[2],ptr->MobileIdentificationNumber[3],ptr->MobileIdentificationNumber[4]);

// optional part--->
	if((flag & BIT2_TRUE)>0)		//AuthenticationAlgorithmVersion
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHU,3),3,ptr->AuthenticationResponseUniqueChallenge,0x80,&asn_buf);

	if((flag & BIT3_TRUE)>0)		//RandomVariableUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDU,4),3,ptr->RandomVariableUniqueChallenge,0x80,&asn_buf);

	return buf_len;
}

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

	ptr = &opr_ptr->msg_list.AUCDirForw_arg;

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

	if (decode_Is41Parameter(IS41PAR_IMSCCID,2,(BYTE*)&ptr->InterMSCCircuitID,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MSC ID absent!");
		return 0;
	}

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

//optional part
	if (decode_Is41Parameter(IS41PAR_AUTHU,3,ptr->AuthenticationResponseUniqueChallenge,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDU,3,ptr->RandomVariableUniqueChallenge,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;

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

	return 1;
}

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

	struct IS41_AFREPORT_ARG *ptr;

	ptr = &opr_ptr->msg_list.afreport_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,(BYTE*)&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)		//reportType
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RPTTYP,3),1,&ptr->rpttyp1,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:reportType absent!!");
		return 0;
	}

	if((flag & BIT3_TRUE)>0)		//system access type
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSACCTYPE,4),1,&ptr->sysacctype,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:system access type absent!");
		return 0;
	}
	
	if((flag & BIT4_TRUE)>0)		//system capabilities
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSCAP,5),1,&ptr->syscap,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:system access type absent!");
		return 0;
	}

	is41_debug(IS41DB_ENCODE,"[IS41-Encode] Starting...ESN=%lx%lx%lx%lx,MIN=%ld%ld%ld%ld,ReportType=%d,sysAccType=%d,sysCap=%d",
							ptr->esn[0],ptr->esn[1],ptr->esn[2],ptr->esn[3],
							ptr->min[0],ptr->min[1],
							ptr->min[2],ptr->min[3],ptr->min[4],
							ptr->rpttyp1,ptr->sysacctype,ptr->syscap);

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

	if((flag & BIT6_TRUE)>0)		//CallHistoryCountExpected
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_COUNTEx,7),1,&ptr->countex,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)		//reportType
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RPTTYP,9),1,&ptr->rpttyp2,0x80,&asn_buf);

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

	return buf_len;
}

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

	ptr = &opr_ptr->msg_list.afreport_arg;

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

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,(BYTE*)&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(is41_sequenceTag(IS41PAR_RPTTYP,3),1,&ptr->rpttyp1,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:ReportType absent!");
		return 0;
	}

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

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

// optional part--->
	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	if (decode_Is41Parameter(IS41PAR_COUNTEx,1,&ptr->countex,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	if (decode_Is41Parameter(IS41PAR_MSCID,3,ptr->mscid,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	if (decode_Is41Parameter(is41_sequenceTag(IS41PAR_RPTTYP,9),1,&ptr->rpttyp2,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;
	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT9_TRUE;
	}

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.afreport_rsp;

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

// optional part--->
	if((flag & BIT0_TRUE)>0)		//AuthenticationAlgorithmVersion
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AAV,1),1,&ptr->aav,0x80,&asn_buf);

	if((flag & BIT1_TRUE)>0)		//AuthenticationResponseUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHU,2),3,ptr->authu,0x80,&asn_buf);

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

	if((flag & BIT3_TRUE)>0)		//DenyAccess
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DENACC,4),1,&ptr->denacc,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)		//RandomVariableSSD
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDSSD,5),7,ptr->randssd,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//RandomVariableUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDU,6),3,ptr->randu,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)		//SharedSecretData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SSD,7),16,ptr->ssd,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)		//SSDNotShared
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_NOSSD,8),1,&ptr->nossd,0x80,&asn_buf);

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

	if((flag & BIT9_TRUE)>0)		//UpdateCount
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_UPDCOUNT,10),1,&ptr->updcount,0x80,&asn_buf);

	return buf_len;
}

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

	ptr = &opr_ptr->msg_list.afreport_rsp;

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

	if (decode_Is41Parameter(IS41PAR_AAV,1,&ptr->aav,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	if (decode_Is41Parameter(IS41PAR_AUTHU,3,ptr->authu,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	if (decode_Is41Parameter(IS41PAR_DENACC,1,&ptr->denacc,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDSSD,7,ptr->randssd,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDU,8,ptr->randu,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	if (decode_Is41Parameter(IS41PAR_SSD,16,ptr->ssd,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	if (decode_Is41Parameter(IS41PAR_NOSSD,1,&ptr->nossd,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	if (decode_Is41Parameter(IS41PAR_TERMTYP,1,&ptr->termtyp,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;
	if (decode_Is41Parameter(IS41PAR_UPDCOUNT,1,&ptr->updcount,&asn_buf))
		ptr->param_flag |= BIT9_TRUE;

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.authreq_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,(BYTE*)&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)		//system access type
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSACCTYPE,4),1,&ptr->sysacctype,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:system access type absent!");
		return 0;
	}

	if((flag & BIT4_TRUE)>0)		//system capabilities
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSCAP,5),1,&ptr->syscap,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:system access type absent!");
		return 0;
	}

	is41_debug(IS41DB_ENCODE,"[IS41-Encode] Starting...ESN=%lx%lx%lx%lx,MIN=%ld%ld%ld%ld,MSCID=%d,sysAccType=%d,sysCap=%d",
							ptr->esn[0],ptr->esn[1],ptr->esn[2],ptr->esn[3],
							ptr->min[0],ptr->min[1],
							ptr->min[2],ptr->min[3],ptr->min[4],
							ptr->mscid,ptr->sysacctype,ptr->syscap);

//optional part--->
	if((flag & BIT5_TRUE)>0)		//AuthenticationData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHDATA,6),3,ptr->authdata,0x80,&asn_buf);
	if((flag & BIT6_TRUE)>0)		//AuthenticationResponse
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHR,7),3,ptr->authr,0x80,&asn_buf);
	if((flag & BIT7_TRUE)>0)		//CallHistoryCount
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_COUNT,8),1,&ptr->count,0x80,&asn_buf);
	if((flag & BIT8_TRUE)>0)		//ConfidentialityModes
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CMODES,9),1,&ptr->cmodes,0x80,&asn_buf);
	if((flag & BIT9_TRUE)>0)		//Digits
		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)		//PC_SSN
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_PCSSN,11),5,ptr->pcssn,0x80,&asn_buf);
	if((flag & BIT11_TRUE)>0)		//RandomVariable
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RAND,12),4,ptr->rand,0x80,&asn_buf);
	if((flag & BIT12_TRUE)>0)		//SenderIdentificationNumber
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,13),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);
	if((flag & BIT13_TRUE)>0)		//TerminalType
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_TERMTYP,14),1,&ptr->termtyp,0x80,&asn_buf);

	return buf_len;

}

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

	ptr = &opr_ptr->msg_list.authreq_arg;

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

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,(BYTE*)&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_SYSACCTYPE,1,&ptr->sysacctype,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SystemAccessType absent!");
		return 0;
	}

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

// optional part--->
	if (decode_Is41Parameter(IS41PAR_AUTHDATA,3,ptr->authdata,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	if (decode_Is41Parameter(IS41PAR_AUTHR,3,ptr->authr,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	if (decode_Is41Parameter(IS41PAR_CMODES,1,&ptr->cmodes,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;
	len = decode_Is41Parameter(IS41PAR_DIGITS,32,ptr->digits,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT9_TRUE;
		ptr->DigitsLen = len;
	}
	if (decode_Is41Parameter(IS41PAR_PCSSN,5,ptr->pcssn,&asn_buf))
		ptr->param_flag |= BIT10_TRUE;
	if (decode_Is41Parameter(IS41PAR_RAND,4,ptr->rand,&asn_buf))
		ptr->param_flag |= BIT11_TRUE;
	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT12_TRUE;
	}
	len = decode_Is41Parameter(IS41PAR_TERMTYP,1,&ptr->termtyp,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT13_TRUE;
	}

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

	return 1;
}


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

	ptr = &opr_ptr->msg_list.authreq_rsp;

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

// optional part--->
	if((flag & BIT0_TRUE)>0)		//AuthenticationAlgorithmVersion
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AAV,1),1,&ptr->aav,0x80,&asn_buf);

	if((flag & BIT1_TRUE)>0)		//AuthenticationResponseUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHU,2),3,ptr->authu,0x80,&asn_buf);

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

	if((flag & BIT3_TRUE)>0)		//CDMAPrivateLongCodeMask
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_CDMAPLCM,4),6,ptr->cdmaplcm,0x80,&asn_buf);

	if((flag & BIT4_TRUE)>0)		//DenyAccess
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DENACC,5),1,&ptr->denacc,0x80,&asn_buf);

	if((flag & BIT5_TRUE)>0)		//RandomVariableSSD
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDSSD,6),7,ptr->randssd,0x80,&asn_buf);

	if((flag & BIT6_TRUE)>0)		//RandomVariableUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDU,7),3,ptr->randu,0x80,&asn_buf);

	if((flag & BIT7_TRUE)>0)		//SharedSecretData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SSD,8),16,ptr->ssd,0x80,&asn_buf);

	if((flag & BIT8_TRUE)>0)		//SharedSecretData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SMEKEY,9),8,ptr->smekey,0x80,&asn_buf);

	if((flag & BIT9_TRUE)>0)		//SSDNotShared
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_NOSSD,10),1,&ptr->nossd,0x80,&asn_buf);

	if((flag & BIT10_TRUE)>0)		//UpdateCount
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_UPDCOUNT,11),1,&ptr->updcount,0x80,&asn_buf);

	if((flag & BIT11_TRUE)>0)		//VoicePrivacyMask
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_VPMASK,12),66,ptr->vpmask,0x80,&asn_buf);


	return buf_len;
}

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

	struct IS41_AUTHREQ_RSP *ptr;

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

	if (decode_Is41Parameter(IS41PAR_AAV,1,&ptr->aav,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	if (decode_Is41Parameter(IS41PAR_AUTHU,3,ptr->authu,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	if (decode_Is41Parameter(IS41PAR_CDMAPLCM,6,ptr->cdmaplcm,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	if (decode_Is41Parameter(IS41PAR_DENACC,1,&ptr->denacc,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDSSD,7,ptr->randssd,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDU,3,ptr->randu,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	if (decode_Is41Parameter(IS41PAR_SSD,16,ptr->ssd,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	if (decode_Is41Parameter(IS41PAR_SMEKEY,8,ptr->smekey,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;
	if (decode_Is41Parameter(IS41PAR_NOSSD,1,&ptr->nossd,&asn_buf))
		ptr->param_flag |= BIT9_TRUE;
	if (decode_Is41Parameter(IS41PAR_UPDCOUNT,1,&ptr->updcount,&asn_buf))
		ptr->param_flag |= BIT10_TRUE;
	if (decode_Is41Parameter(IS41PAR_VPMASK,66,ptr->vpmask,&asn_buf))
		ptr->param_flag |= BIT11_TRUE;

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.asreport_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,(BYTE*)&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)		//system capabilities
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SYSCAP,3),1,&ptr->syscap,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:system access type absent!");
		return 0;
	}

	is41_debug(IS41DB_ENCODE,"[IS41-Encode] Starting...ESN=%lx%lx%lx%lx,MIN=%ld%ld%ld%ld,sysCap=%d",
							ptr->esn[0],ptr->esn[1],ptr->esn[2],ptr->esn[3],
							ptr->min[0],ptr->min[1],
							ptr->min[2],ptr->min[3],ptr->min[4],
							ptr->syscap);

//optional part--->
	if((flag & BIT3_TRUE)>0)		//CountUpdateReport
	{
		if (ptr->CntUpdRepLen > 32)
		{
			ptr->CntUpdRepLen = 32;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_COUNTRPT,4),ptr->CntUpdRepLen,ptr->countrpt,0x80,&asn_buf);
	}

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

	if((flag & BIT5_TRUE)>0)		//SSDUpdateReport
	{
		if (ptr->SSDUpdRepLen > 32)
		{
			ptr->SSDUpdRepLen = 32;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SSDURPT,6),ptr->SSDUpdRepLen,ptr->ssdurpt,0x80,&asn_buf);
	}
	
	if((flag & BIT6_TRUE)>0)		//UniqueChallengeReport
	{
		if (ptr->UniChaRepLen > 32)
		{
			ptr->UniChaRepLen = 32;
		}
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_UCHALRPT,7),ptr->UniChaRepLen,ptr->uchalrpt,0x80,&asn_buf);
	}

	return buf_len;

}

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

	ptr = &opr_ptr->msg_list.asreport_arg;

	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_ESN,ESN_LEN,(BYTE*)&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_SYSCAP,1,&ptr->syscap,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:SystemCapabilities absent!");
		return 0;
	}

// optional part--->
	len = decode_Is41Parameter(IS41PAR_COUNTRPT,32,ptr->countrpt,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT3_TRUE;
		ptr->CntUpdRepLen = len;
	}

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

	len = decode_Is41Parameter(IS41PAR_SSDURPT,32,ptr->ssdurpt,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT5_TRUE;
		ptr->SSDUpdRepLen = len;
	}

	len = decode_Is41Parameter(IS41PAR_UCHALRPT,32,ptr->uchalrpt,&asn_buf);
	if (len > 0)
	{
		ptr->param_flag |= BIT6_TRUE;
		ptr->UniChaRepLen = len;
	}

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.asreport_rsp;

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

//optional part--->
	if((flag & BIT0_TRUE)>0)		//AuthenticationAlgorithmVersion
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AAV,1),1,&ptr->aav,0x80,&asn_buf);
	if((flag & BIT1_TRUE)>0)		//AuthenticationResponseUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_AUTHU,2),3,ptr->authu,0x80,&asn_buf);
	if((flag & BIT2_TRUE)>0)		//CallHistoryCount
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_COUNT,3),1,&ptr->count,0x80,&asn_buf);
	if((flag & BIT3_TRUE)>0)		//DenyAccess
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_DENACC,4),1,&ptr->denacc,0x80,&asn_buf);
	if((flag & BIT4_TRUE)>0)		//RandomVariableSSD
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDSSD,5),7,ptr->randssd,0x80,&asn_buf);
	if((flag & BIT5_TRUE)>0)		//RandomVariableUniqueChallenge
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDU,6),3,ptr->randu,0x80,&asn_buf);
	if((flag & BIT6_TRUE)>0)		//SharedSecretData
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SSD,7),16,ptr->ssd,0x80,&asn_buf);
	if((flag & BIT7_TRUE)>0)		//SSDNotShared
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_NOSSD,8),1,&ptr->nossd,0x80,&asn_buf);
	if((flag & BIT8_TRUE)>0)		//UpdateCount
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_UPDCOUNT,9),1,&ptr->updcount,0x80,&asn_buf);

	return buf_len;

}

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

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

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



// optional part--->
	if (decode_Is41Parameter(IS41PAR_AAV,1,&ptr->aav,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	if (decode_Is41Parameter(IS41PAR_AUTHU,3,ptr->authu,&asn_buf))
		ptr->param_flag |= BIT1_TRUE;
	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT2_TRUE;
	if (decode_Is41Parameter(IS41PAR_DENACC,1,&ptr->denacc,&asn_buf))
		ptr->param_flag |= BIT3_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDSSD,7,ptr->randssd,&asn_buf))
		ptr->param_flag |= BIT4_TRUE;
	if (decode_Is41Parameter(IS41PAR_RANDU,8,ptr->randu,&asn_buf))
		ptr->param_flag |= BIT5_TRUE;
	if (decode_Is41Parameter(IS41PAR_SSD,16,ptr->ssd,&asn_buf))
		ptr->param_flag |= BIT6_TRUE;
	if (decode_Is41Parameter(IS41PAR_NOSSD,1,&ptr->nossd,&asn_buf))
		ptr->param_flag |= BIT7_TRUE;
	if (decode_Is41Parameter(IS41PAR_UPDCOUNT,1,&ptr->updcount,&asn_buf))
		ptr->param_flag |= BIT8_TRUE;

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

	return 1;
}


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

	ptr = &opr_ptr->msg_list.bschall_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,(BYTE*)&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)		//randbs
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_RANDBS,3),4,ptr->randbs,0x80,&asn_buf);
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Encode] Stopped,reason:RANDBS absent!!");
		return 0;
	}

//optional part--->
	if((flag & BIT3_TRUE)>0)		//SenderIdentificationNumber
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,13),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	return buf_len;

}

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

	ptr = &opr_ptr->msg_list.bschall_arg;

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

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,(BYTE*)&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_RANDBS,4,ptr->randbs,&asn_buf))
	{
		ptr->param_flag |= BIT2_TRUE;
	}
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:MSCID absent!");
		return 0;
	}


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

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

	return 1;
}


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

	ptr = &opr_ptr->msg_list.bschall_rsp;

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

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


	return buf_len;
}

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

	struct IS41_BSCHALL_RSP *ptr;

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

	if (decode_Is41Parameter(IS41PAR_AUTHBS,4,(BYTE*)&ptr->authbs,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;
	else
	{
		is41_debug(IS41DB_ERR,"[IS41-Decode] Stopped,reason:AUTHBS absent!");
		return 0;
	}

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

	return 1;
}

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

	ptr = &opr_ptr->msg_list.countreq_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,(BYTE*)&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)		//SenderIdentificationNumber
		buf_len = AddTLV(is41_sequenceTag(IS41PAR_SENDERIN,3),ptr->senderinLen & MAX_IS41_VARPAR_LEN_1,ptr->senderin,0x80,&asn_buf);

	return buf_len;

}

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

	ptr = &opr_ptr->msg_list.countreq_arg;

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

	if (decode_Is41Parameter(IS41PAR_ESN,ESN_LEN,(BYTE*)&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 part--->
	len = decode_Is41Parameter(IS41PAR_SENDERIN,MAX_IS41_VARPAR_LEN,ptr->senderin,&asn_buf);
	if (len > 0)
	{
		ptr->senderinLen = len;
		ptr->param_flag |= BIT2_TRUE;
	}

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

	return 1;
}


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

	ptr = &opr_ptr->msg_list.countreq_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,1),1,&ptr->count,0x80,&asn_buf);

	return buf_len;
}

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

	struct IS41_COUNTREQ_RSP *ptr;

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

	if (decode_Is41Parameter(IS41PAR_COUNT,1,&ptr->count,&asn_buf))
		ptr->param_flag |= BIT0_TRUE;

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

	return 1;
}
