 #include "map_includes.h"

 /**************** vlr inquery opr	********************/
/*	+++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding MapDetermineOprUser Arg argument	*/
/*	+++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_MapDetermineOprUserArg(struct MapDetermineOprUser_Arg *dou_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = dou_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,dou_ptr->imsi,0x80,&asn_buf);//add msisdn parameter
	}
	else
	{
		mapp_log_debug("assign MapDetermineOprUserArg loss IMSI");
		return RER;
	}
	if (flag & 0x02)	// has imei
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,IMEI_LEN,dou_ptr->imei,0x80,&asn_buf);//add imei parameter
	}
	else
	{
		mapp_log_debug("assign MapDetermineOprUserArg loss IMEI");
		return RER;
	}
	if (flag & 0x04) //has roamingRestraintFlag
	{
		sprintf(tlv1,"2-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&dou_ptr->roamingRestraintFlag,0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("assign MapDetermineOprUserArg loss roamingRestraintFlag");
		return RER;
	}			
	dou_ptr->param_flag = flag;
	return buf_len;
}

int extract_MapDetermineOprUserArg(struct MapDetermineOprUser_Arg *dou_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	dou_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapDetermineOprUserArg param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(dou_ptr->imsi,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapDetermineOprUserArg:loss IMSI");
		return RER;
	}
	
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len == IMEI_LEN)	// get imei
	{
		flag |= 0x02;
		memcpy(dou_ptr->imei,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapDetermineOprUserArg:loss IMEI");
		return RER;
	}
	
	len = get_tlv("2",temp_buf,&asn_buf);	//get roamingRestraintFlag
	if (len == 1)
	{
		dou_ptr->roamingRestraintFlag = temp_buf[0];
		flag |= 0x04;
	}
	else
	{
		mapp_log_debug("extract MapDetermineOprUserArg:loss roamingRestraintFlag");
		return RER;
	}	
	dou_ptr->param_flag = flag;
	return ROK;
}

/*	+++++++++++++++++++++++++++++++++++++++++++++	*/
/*	encoding/decoding MapDetermineOprUser Response	*/
/*	+++++++++++++++++++++++++++++++++++++++++++++	*/
int assign_MapDetermineOprUserRes(struct MapDetermineOprUser_Res *dou_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = dou_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,dou_ptr->imsi,0x80,&asn_buf);//add msisdn parameter
	}
	else
	{
		mapp_log_debug("assign MapDetermineOprUserRes loss IMSI");
		return RER;
	}
	if (flag & 0x02)	// has imei
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,IMEI_LEN,dou_ptr->imei,0x80,&asn_buf);//add imei parameter
	}
	else
	{
		mapp_log_debug("assign MapDetermineOprUserRes loss IMEI");
		return RER;
	}
	if (flag & 0x04) //has oprFlag
	{
		sprintf(tlv1,"2-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&dou_ptr->oprflag,0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("assign MapDetermineOprUserRes loss oprFlag");
		return RER;
	}	
	if (flag & 0x08) //has msisdn
	{
		sprintf(tlv1,"3-%d",tag1++);
		buf_len = add_tlv(tlv1,dou_ptr->msisdn[0],dou_ptr->msisdn+1,0x80,&asn_buf);//add msisdn parameter
	}		
	dou_ptr->param_flag = flag;
	return buf_len;
}

int extract_MapDetermineOprUserRes(struct MapDetermineOprUser_Res *dou_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	dou_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapDetermineOprUserRes param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(dou_ptr->imsi,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapDetermineOprUserRes:loss IMSI");
		return RER;
	}
	
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len == IMEI_LEN)	// get imei
	{
		flag |= 0x02;
		memcpy(dou_ptr->imei,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapDetermineOprUserRes:loss IMEI");
		return RER;
	}
	
	len = get_tlv("2",temp_buf,&asn_buf);	//get oprflag
	if (len == 1)
	{
		dou_ptr->oprflag = temp_buf[0];
		flag |= 0x04;
	}
	else
	{
		mapp_log_debug("extract MapDetermineOprUserRes:loss oprflag");
		return RER;
	}	
	len = get_tlv("3",temp_buf,&asn_buf);	//get msisdn
	if (len > 1 && len <= ISDN_LEN)
	{
		flag |= 0x08;
		dou_ptr->msisdn[0] = len;
		memcpy(dou_ptr->msisdn+1,temp_buf,len);
	}
	
	dou_ptr->param_flag = flag;
	return buf_len;
}

/**************** opr updataLocation vlr	********************/
int assign_MapVlrUpdateLocationArg(struct MapVlrUpdateLocation_Arg *cuwm_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = cuwm_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,cuwm_ptr->imsi,0x80,&asn_buf);//add msisdn parameter
	}
	else
	{
		mapp_log_debug("assign MapVlrUpdateLocationArg loss IMSI");
		return RER;
	}
	if (flag & 0x02)	// has oprflag
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cuwm_ptr->status,0x80,&asn_buf);//add msisdn parameter
	}			
	else
	{
		mapp_log_debug("assign MapVlrUpdateLocationArg loss status");
		return RER;
	}
	
	cuwm_ptr->param_flag = flag;
	return buf_len;
}


int extract_MapVlrUpdateLocationArg(struct MapVlrUpdateLocation_Arg *cuwm_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	cuwm_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapVlrUpdateLocationArg param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(cuwm_ptr->imsi,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapVlrUpdateLocationArg:loss IMSI");
		return RER;
	}
	len = get_tlv("1",temp_buf,&asn_buf);/*	get status	*/
	if (len == 1)
	{
		flag |= 0x02;
		cuwm_ptr->status = temp_buf[0];	
	}
	else
	{
		mapp_log_debug("extract MapVlrUpdateLocationArg:loss status");
		return RER;
	}
		
	cuwm_ptr->param_flag = flag;
	return buf_len;
}

int assign_MapVlrUpdateLocationRes(struct MapVlrUpdateLocation_Res *cuwm_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = cuwm_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,cuwm_ptr->imsi,0x80,&asn_buf);//add msisdn parameter
	}
	
	if (flag & 0x02)	// has status
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cuwm_ptr->status,0x80,&asn_buf);//add msisdn parameter
	}			
		
	if (flag & 0x04) //has error
	{
		sprintf(tlv1,"2-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cuwm_ptr->error,0x80,&asn_buf);
	}
					
	cuwm_ptr->param_flag = flag;
	return buf_len;
}

int extract_MapVlrUpdateLocationRes(struct MapVlrUpdateLocation_Res *cuwm_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	cuwm_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapVlrUpdateLocationRes param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(cuwm_ptr->imsi,temp_buf,len);
	}
	
	
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len == 1)
	{
		flag |= 0x02;
		cuwm_ptr->status = temp_buf[0];
	}	
	
	len = get_tlv("2",temp_buf,&asn_buf);	//get reult
	if (len == 1)
	{
		cuwm_ptr->error = temp_buf[0];
		flag |= 0x04;
	}
				
	cuwm_ptr->param_flag = flag;
	return buf_len;
}


/**************** opr create hlr	********************/
int assign_MapCreateUserWithMsisdnImsiArg(struct MapCreateUserWithMsisdnImsi_Arg *cuwm_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = cuwm_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,cuwm_ptr->imsi,0x80,&asn_buf);//add msisdn parameter
	}
	else
	{
		mapp_log_debug("assign MapCreateUserWithMsisdnImsiArg loss IMSI");
		return RER;
	}
	if (flag & 0x02)	// has msisdn
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,cuwm_ptr->msisdn[0],cuwm_ptr->msisdn+1,0x80,&asn_buf);//add msisdn parameter
	}			
	else
	{
		mapp_log_debug("assign MapCreateUserWithMsisdnImsiArg loss MSISDN");
		return RER;
	}
	
	if (flag & 0x04) //has imsiFlag
	{
		sprintf(tlv1,"2-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cuwm_ptr->imsiflag,0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("assign MapCreateUserWithMsisdnImsiArg loss imsiFlag");
		return RER;
	}		
	
	if (flag & 0x08) //has camelFlag
	{
		sprintf(tlv1,"3-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cuwm_ptr->camelflag,0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("assign MapCreateUserWithMsisdnImsiArg loss camelflag");
		return RER;
	}			
	cuwm_ptr->param_flag = flag;
	return buf_len;
}


int extract_MapCreateUserWithMsisdnImsiArg(struct MapCreateUserWithMsisdnImsi_Arg *cuwm_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	cuwm_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapCreateUserWithMsisdnImsiArg param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(cuwm_ptr->imsi,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapCreateUserWithMsisdnImsiArg:loss IMSI");
		return RER;
	}
	
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len > 1 && len <= ISDN_LEN)
	{
		flag |= 0x02;
		cuwm_ptr->msisdn[0] = len;
		memcpy(cuwm_ptr->msisdn+1,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapCreateUserWithMsisdnImsiArg:msisdn length error");
		return RER;
	}
	
	len = get_tlv("2",temp_buf,&asn_buf);	//get imsiflag
	if (len == 1)
	{
		cuwm_ptr->imsiflag = temp_buf[0];
		flag |= 0x04;
	}
	else
	{
		mapp_log_debug("extract MapCreateUserWithMsisdnImsiArg:loss roamingRestraintFlag");
		return RER;
	}	
	len = get_tlv("3",temp_buf,&asn_buf);	//get camelflag
	if (len == 1)
	{
		cuwm_ptr->camelflag = temp_buf[0];
		flag |= 0x08;
	}
	else
	{
		mapp_log_debug("extract MapCreateUserWithMsisdnImsiArg:loss camelflag");
		return RER;
	}
	cuwm_ptr->param_flag = flag;
	return buf_len;
}

int assign_MapCreateUserWithMsisdnImsiRes(struct MapCreateUserWithMsisdnImsi_Res *cuwm_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = cuwm_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,cuwm_ptr->imsi,0x80,&asn_buf);//add msisdn parameter
	}
	
	if (flag & 0x02)	// has msisdn
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,cuwm_ptr->msisdn[0],cuwm_ptr->msisdn+1,0x80,&asn_buf);//add msisdn parameter
	}			
	
	
	if (flag & 0x04) //has result
	{
		sprintf(tlv1,"2-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cuwm_ptr->result,0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("assign MapCreateUserWithMsisdnImsiRes loss result");
		return RER;
	}		
	
	if (flag & 0x08) //has cause
	{
		sprintf(tlv1,"3-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cuwm_ptr->cause,0x80,&asn_buf);
	}
	
	cuwm_ptr->param_flag = flag;
	return buf_len;
}

int extract_MapCreateUserWithMsisdnImsiRes(struct MapCreateUserWithMsisdnImsi_Res *cuwm_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	cuwm_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapCreateUserWithMsisdnImsiRes param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(cuwm_ptr->imsi,temp_buf,len);
	}
	
	
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len > 1 && len <= ISDN_LEN)
	{
		flag |= 0x02;
		cuwm_ptr->msisdn[0] = len;
		memcpy(cuwm_ptr->msisdn+1,temp_buf,len);
	}
	
	
	len = get_tlv("2",temp_buf,&asn_buf);	//get reult
	if (len == 1)
	{
		cuwm_ptr->result = temp_buf[0];
		flag |= 0x04;
	}
	else
	{
		mapp_log_debug("extract MapCreateUserWithMsisdnImsiArg:loss result");
		return RER;
	}	
	
	len = get_tlv("3",temp_buf,&asn_buf);	//get cause
	if (len == 1)
	{
		cuwm_ptr->cause = temp_buf[0];
		flag |= 0x08;
	}
	
	cuwm_ptr->param_flag = flag;
	return buf_len;
}



/*********** opr delete hlr ***************************/
int assign_MapDeleteOprUserArg(struct MapDeleteOprUser_Arg *dou_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = dou_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,dou_ptr->imsi,0x80,&asn_buf);//add msisdn parameter
	}
	else
	{
		mapp_log_debug("assign MapDeleteOprUserArg loss IMSI");
		return RER;
	}
	
	if (flag & 0x02)	// has msisdn
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,dou_ptr->msisdn[0],dou_ptr->msisdn+1,0x80,&asn_buf);//add msisdn parameter
	}			
	else
	{
		mapp_log_debug("assign MapDeleteOprUserArg loss MSISDN");
		return RER;
	}
		
	dou_ptr->param_flag = flag;
	return buf_len;
}


int extract_MapDeleteOprUserArg(struct MapDeleteOprUser_Arg *dou_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	dou_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapDeleteOprUserArg param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(dou_ptr->imsi,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapDeleteOprUserArg:loss IMSI");
		return RER;
	}
	
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len > 1 && len <= ISDN_LEN)
	{
		flag |= 0x02;
		dou_ptr->msisdn[0] = len;
		memcpy(dou_ptr->msisdn+1,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapDeleteOprUserArg:msisdn length error");
		return RER;
	}
		
	dou_ptr->param_flag = flag;
	return buf_len;
}

int assign_MapDeleteOprUserRes(struct MapDeleteOprUser_Res	 *dou_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = dou_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,dou_ptr->imsi,0x80,&asn_buf);//add msisdn parameter
	}
	
	if (flag & 0x02)	// has msisdn
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,dou_ptr->msisdn[0],dou_ptr->msisdn+1,0x80,&asn_buf);//add msisdn parameter
	}			
	
	
	if (flag & 0x04) //has result
	{
		sprintf(tlv1,"2-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&dou_ptr->result,0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("assign MapDeleteOprUserRes loss result");
		return RER;
	}		
	
	if (flag & 0x08) //has cause
	{
		sprintf(tlv1,"3-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&dou_ptr->cause,0x80,&asn_buf);
	}
	
	dou_ptr->param_flag = flag;
	return buf_len;
}

int extract_MapDeleteOprUserRes(struct MapDeleteOprUser_Res *dou_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	dou_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapDeleteOprUserRes param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(dou_ptr->imsi,temp_buf,len);
	}
		
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len > 1 && len <= ISDN_LEN)
	{
		flag |= 0x02;
		dou_ptr->msisdn[0] = len;
		memcpy(dou_ptr->msisdn+1,temp_buf,len);
	}
	
	
	len = get_tlv("2",temp_buf,&asn_buf);	//get reult
	if (len == 1)
	{
		dou_ptr->result = temp_buf[0];
		flag |= 0x04;
	}
	else
	{
		mapp_log_debug("extract MapDeleteOprUserRes:loss result");
		return RER;
	}	
	
	len = get_tlv("3",temp_buf,&asn_buf);	//get cause
	if (len == 1)
	{
		dou_ptr->cause = temp_buf[0];
		flag |= 0x08;
	}
	
	dou_ptr->param_flag = flag;
	return buf_len;
}


int assign_MapVlrEnquiryIMDM_Arg(struct MapVlrEnquiryIMDM_Arg *cuwm_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = cuwm_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,cuwm_ptr->imsi,0x80,&asn_buf);//add imsi parameter
	}
	else
	{
		mapp_log_debug("assign MapVlrEnquiryIMDM_Arg loss IMSI");
		return RER;
	}
	if (flag & 0x02)	// has msisdn
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,cuwm_ptr->msisdn[0],cuwm_ptr->msisdn+1,0x80,&asn_buf);//add msisdn parameter
	}			
	else
	{
		mapp_log_debug("assign MapCreateUserWithMsisdnImsiArg loss MSISDN");
		return RER;
	}
		
	cuwm_ptr->param_flag = flag;
	return buf_len;
}


int assign_MapVlrEnquiryIMDM_Res(struct MapVlrEnquiryIMDM_Res *cuwm_ptr,u8 *buf, u8 ver)
{
	ASN_BUF		asn_buf;
	u32			flag;
	int			buf_len=0;
	u8			tag1=1;
	char		tlv1[32];

	asn_encode(buf,&asn_buf);
	flag = cuwm_ptr->param_flag;
	if (flag & 0x01)	// has  imsi
	{
		sprintf(tlv1,"0-%d",tag1++);
		buf_len = add_tlv(tlv1,IMSI_LEN,cuwm_ptr->imsi,0x80,&asn_buf);//add imsi parameter
	}
	
	if (flag & 0x02)	// has msisdn
	{
		sprintf(tlv1,"1-%d",tag1++);
		buf_len = add_tlv(tlv1,cuwm_ptr->msisdn[0],cuwm_ptr->msisdn+1,0x80,&asn_buf);//add msisdn parameter
	}			
	
	if (flag & 0x04)	// has status
	{
		sprintf(tlv1,"2-%d",tag1++);
		buf_len = add_tlv(tlv1,1,&cuwm_ptr->status,0x80,&asn_buf);
	}
	else
	{
		mapp_log_debug("assign MapVlrEnquiryIMDM_Arg loss staus");
		return RER;	
	}
		
	cuwm_ptr->param_flag = flag;
	return buf_len;
}


int extract_MapVlrEnquiryIMDM_Arg(struct MapVlrEnquiryIMDM_Arg *cuwm_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	cuwm_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapVlrEnquiryIMDM_Arg param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(cuwm_ptr->imsi,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapVlrEnquiryIMDM_Arg:loss IMSI");
		return RER;
	}
	
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len > 1 && len <= ISDN_LEN)
	{
		flag |= 0x02;
		cuwm_ptr->msisdn[0] = len;
		memcpy(cuwm_ptr->msisdn+1,temp_buf,len);
	}
	else
	{
		mapp_log_debug("extract MapVlrEnquiryIMDM_Arg:msisdn length error");
		return RER;
	}
		
	cuwm_ptr->param_flag = flag;
	return buf_len;
}

int extract_MapVlrEnquiryIMDM_Res(struct MapVlrEnquiryIMDM_Res *cuwm_ptr,u32 buf_len,u8 *buf)
{
	ASN_BUF		asn_buf;
	int			len;
	u8			temp_buf[256];
	u32			flag=0;
	
	cuwm_ptr->param_flag = 0;
	if (buf_len == 0)
	{
		mapp_log_debug("extract_MapVlrEnquiryIMDM_Res param len is:0");
		return RER;
	}
	if (asn_decode_v3(buf,buf_len,&decErr,&asn_buf) == -1)
		return RER;
	len = get_tlv("0",temp_buf,&asn_buf);	// get imsi
	if (len == IMSI_LEN)
	{
		flag |= 0x01;	
		memcpy(cuwm_ptr->imsi,temp_buf,len);
	}
		
	len = get_tlv("1",temp_buf,&asn_buf);
	if (len > 1 && len <= ISDN_LEN)
	{
		flag |= 0x02;
		cuwm_ptr->msisdn[0] = len;
		memcpy(cuwm_ptr->msisdn+1,temp_buf,len);
	}
	
	len = get_tlv("2",temp_buf,&asn_buf);/*	status	*/
	if (len == 1)
	{
		flag |= 0x04;
		cuwm_ptr->status = temp_buf[0];
	}
	else
	{
		mapp_log_debug("extract MapVlrEnquiryIMDM_Res:status loss");
		return RER;
	}
		
		
	cuwm_ptr->param_flag = flag;
	return buf_len;
}

